libpurple/protocols/jabber/oob.c

Thu, 05 Sep 2013 22:54:12 +0530

author
Ankit Vani <a@nevitus.org>
date
Thu, 05 Sep 2013 22:54:12 +0530
branch
soc.2013.gobjectification
changeset 34913
21017b84a070
parent 34910
60502558e400
child 34920
2df7191f56ea
permissions
-rw-r--r--

Refactored jabber to use the GObject xfer API.
Added purple_xfer_set_remote_user().

7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2 * purple - Jabber Protocol Plugin
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
28322
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28206
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28206
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 28206
diff changeset
6 * source distribution.
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 *
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 *
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 *
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 15884
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 *
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22 */
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "internal.h"
7234
a4900df91d90 [gaim-migrate @ 7806]
Nathan Walp <nwalp@pidgin.im>
parents: 7170
diff changeset
24 #include "debug.h"
34910
60502558e400 Replacements for the GObject Xfer API
Ankit Vani <a@nevitus.org>
parents: 34287
diff changeset
25 #include "xfer.h"
34219
eee308def583 HTTP: get rid of purple_url_parse
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34218
diff changeset
26 #include "http.h"
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "util.h"
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "jabber.h"
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 #include "iq.h"
12324
caf9784f2405 [gaim-migrate @ 14628]
Richard Laager <rlaager@pidgin.im>
parents: 12323
diff changeset
31 #include "oob.h"
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 typedef struct _JabberOOBXfer {
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 JabberStream *js;
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
35 gchar *iq_id;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
36 gchar *url;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
37 PurpleHttpConnection *hc;
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 } JabberOOBXfer;
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
40 static void jabber_oob_xfer_init(PurpleXfer *xfer)
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 {
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
42 purple_xfer_start(xfer, -1, NULL, 0);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 }
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
45 static void jabber_oob_xfer_free(PurpleXfer *xfer)
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 {
32245
6e7b93c200fe Convert the jabber prpl to use the new API.
Andrew Victor <andrew.victor@mxit.com>
parents: 30708
diff changeset
47 JabberOOBXfer *jox = purple_xfer_get_protocol_data(xfer);
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
48
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
49 purple_xfer_set_protocol_data(xfer, NULL);
7395
e5595e8e13e4 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7234
diff changeset
50 jox->js->oob_file_transfers = g_list_remove(jox->js->oob_file_transfers,
e5595e8e13e4 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7234
diff changeset
51 xfer);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 g_free(jox->iq_id);
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
54 g_free(jox->url);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 g_free(jox);
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56 }
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
58 static void jabber_oob_xfer_end(PurpleXfer *xfer)
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 {
32245
6e7b93c200fe Convert the jabber prpl to use the new API.
Andrew Victor <andrew.victor@mxit.com>
parents: 30708
diff changeset
60 JabberOOBXfer *jox = purple_xfer_get_protocol_data(xfer);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 JabberIq *iq;
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 iq = jabber_iq_new(jox->js, JABBER_IQ_RESULT);
32270
028a4b3c0402 Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents: 32245
diff changeset
64 xmlnode_set_attrib(iq->node, "to", purple_xfer_get_remote_user(xfer));
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 jabber_iq_set_id(iq, jox->iq_id);
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 jabber_iq_send(iq);
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 jabber_oob_xfer_free(xfer);
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 }
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
72 static void
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
73 jabber_oob_xfer_got(PurpleHttpConnection *hc, PurpleHttpResponse *response,
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
74 gpointer _xfer)
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
75 {
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
76 PurpleXfer *xfer = _xfer;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
77 JabberOOBXfer *jox;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12324
diff changeset
78
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
79 if (purple_xfer_is_cancelled(xfer))
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12324
diff changeset
80 return;
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
81
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
82 jox = purple_xfer_get_protocol_data(xfer);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
83 jox->hc = NULL;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
84
34287
6cd0c77b1f6a HTTP: successful is spelled with one l
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34286
diff changeset
85 if (!purple_http_response_is_successful(response) ||
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
86 purple_xfer_get_bytes_remaining(xfer) > 0)
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
87 {
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
88 purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
89 purple_xfer_end(xfer);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
90 } else {
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
91 purple_xfer_set_completed(xfer, TRUE);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
92 purple_xfer_end(xfer);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12324
diff changeset
93 }
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
94 }
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
95
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
96 static void
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
97 jabber_oob_xfer_progress_watcher(PurpleHttpConnection *hc,
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
98 gboolean reading_state, int processed, int total, gpointer _xfer)
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
99 {
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
100 PurpleXfer *xfer = _xfer;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
101
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
102 if (!reading_state)
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
103 return;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12324
diff changeset
104
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
105 purple_xfer_set_size(xfer, total);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
106 purple_xfer_update_progress(xfer);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
107 }
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
108
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
109 static gboolean
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
110 jabber_oob_xfer_writer(PurpleHttpConnection *http_conn,
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
111 PurpleHttpResponse *response, const gchar *buffer, size_t offset,
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
112 size_t length, gpointer _xfer)
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
113 {
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
114 PurpleXfer *xfer = _xfer;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
115
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
116 return purple_xfer_write_file(xfer, (const guchar*)buffer, length);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12324
diff changeset
117 }
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12324
diff changeset
118
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
119 static void jabber_oob_xfer_start(PurpleXfer *xfer)
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 {
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
121 PurpleHttpRequest *req;
32245
6e7b93c200fe Convert the jabber prpl to use the new API.
Andrew Victor <andrew.victor@mxit.com>
parents: 30708
diff changeset
122 JabberOOBXfer *jox = purple_xfer_get_protocol_data(xfer);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
124 req = purple_http_request_new(jox->url);
34286
8d0979967d05 HTTP: removing extra yahoo HTTP implementations - file transfer (and small improvements to libpurple http and ft code)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34272
diff changeset
125 purple_http_request_set_timeout(req, -1);
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
126 purple_http_request_set_max_len(req, -1);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
127 purple_http_request_set_response_writer(req, jabber_oob_xfer_writer,
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
128 xfer);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
129 jox->hc = purple_http_request(jox->js->gc, req, jabber_oob_xfer_got,
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
130 xfer);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
132 purple_http_conn_set_progress_watcher(jox->hc,
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
133 jabber_oob_xfer_progress_watcher, xfer, -1);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134 }
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
136 static void jabber_oob_xfer_recv_error(PurpleXfer *xfer, const char *code) {
32245
6e7b93c200fe Convert the jabber prpl to use the new API.
Andrew Victor <andrew.victor@mxit.com>
parents: 30708
diff changeset
137 JabberOOBXfer *jox = purple_xfer_get_protocol_data(xfer);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 JabberIq *iq;
8399
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
139 xmlnode *y, *z;
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 iq = jabber_iq_new(jox->js, JABBER_IQ_ERROR);
32270
028a4b3c0402 Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents: 32245
diff changeset
142 xmlnode_set_attrib(iq->node, "to", purple_xfer_get_remote_user(xfer));
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 jabber_iq_set_id(iq, jox->iq_id);
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 y = xmlnode_new_child(iq->node, "error");
8399
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
145 xmlnode_set_attrib(y, "code", code);
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
146 if(!strcmp(code, "406")) {
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
147 z = xmlnode_new_child(y, "not-acceptable");
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
148 xmlnode_set_attrib(y, "type", "modify");
28984
1d84517d56eb jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
149 xmlnode_set_namespace(z, NS_XMPP_STANZAS);
8399
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
150 } else if(!strcmp(code, "404")) {
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
151 z = xmlnode_new_child(y, "not-found");
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
152 xmlnode_set_attrib(y, "type", "cancel");
28984
1d84517d56eb jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
153 xmlnode_set_namespace(z, NS_XMPP_STANZAS);
8399
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
154 }
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 jabber_iq_send(iq);
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157 jabber_oob_xfer_free(xfer);
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 }
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
160 static void jabber_oob_xfer_recv_denied(PurpleXfer *xfer) {
8399
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
161 jabber_oob_xfer_recv_error(xfer, "406");
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
162 }
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
163
30708
535bec1e66fb Standardize on "cancelled".
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 28984
diff changeset
164 static void jabber_oob_xfer_recv_cancelled(PurpleXfer *xfer) {
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
165 JabberOOBXfer *jox = purple_xfer_get_protocol_data(xfer);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
166
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
167 purple_http_conn_cancel(jox->hc);
8399
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
168 jabber_oob_xfer_recv_error(xfer, "404");
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
169 }
c49159589f7e [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
170
34913
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
171 static PurpleXferIoOps recieve_ops =
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
172 {
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
173 jabber_oob_xfer_init, /* init */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
174 jabber_oob_xfer_recv_denied, /* request_denied */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
175 jabber_oob_xfer_start, /* start */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
176 jabber_oob_xfer_end, /* end */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
177 NULL, /* cancel_send */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
178 jabber_oob_xfer_recv_cancelled, /* cancel_recv */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
179 NULL, /* read */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
180 NULL, /* write */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
181 NULL, /* ack */
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
182 };
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
183
25817
09d6a40a341d Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
184 void jabber_oob_parse(JabberStream *js, const char *from, JabberIqType type,
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
185 const char *id, xmlnode *querynode) {
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186 JabberOOBXfer *jox;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
187 PurpleXfer *xfer;
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
188 const gchar *filename, *slash;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
189 gchar *url;
25817
09d6a40a341d Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
190 xmlnode *urlnode;
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191
25817
09d6a40a341d Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents: 19859
diff changeset
192 if(type != JABBER_IQ_SET)
14356
7f4abf922cfa [gaim-migrate @ 16984]
Nathan Walp <nwalp@pidgin.im>
parents: 14254
diff changeset
193 return;
7f4abf922cfa [gaim-migrate @ 16984]
Nathan Walp <nwalp@pidgin.im>
parents: 14254
diff changeset
194
25818
d087a2754595 Avoid assertion failures on NULL 'from' attributes
Paul Aurich <darkrain42@pidgin.im>
parents: 25817
diff changeset
195 if(!from)
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
196 return;
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 if(!(urlnode = xmlnode_get_child(querynode, "url")))
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199 return;
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
201 url = xmlnode_get_data(urlnode);
34219
eee308def583 HTTP: get rid of purple_url_parse
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34218
diff changeset
202 if (!url)
eee308def583 HTTP: get rid of purple_url_parse
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34218
diff changeset
203 return;
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
205 xfer = purple_xfer_new(purple_connection_get_account(js->gc),
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
206 PURPLE_XFER_RECEIVE, from);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
207 if (!xfer) {
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
208 g_free(url);
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
209 return;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
210 }
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
211
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 jox = g_new0(JabberOOBXfer, 1);
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
213 jox->iq_id = g_strdup(id);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 jox->js = js;
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
215 jox->url = url;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
216 purple_xfer_set_protocol_data(xfer, jox);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
218 slash = strrchr(url, '/');
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
219 if (slash == NULL)
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
220 filename = url;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
221 else
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
222 filename = slash + 1;
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
223 purple_xfer_set_filename(xfer, filename);
34913
21017b84a070 Refactored jabber to use the GObject xfer API.
Ankit Vani <a@nevitus.org>
parents: 34910
diff changeset
224 purple_xfer_set_io_ops(xfer, &recieve_ops);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
226 js->oob_file_transfers = g_list_append(js->oob_file_transfers, xfer);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227
34272
8df870b218ca HTTP: chop off another HTTP implementation (for xmpp oob file transfers)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34219
diff changeset
228 purple_xfer_request(xfer);
7170
93a12931a1fd [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229 }

mercurial