Sat, 10 Nov 2007 04:52:20 +0000
propagate from branch 'im.pidgin.pidgin.next.minor' (head 2f91b326b3f073672c2475a8c30a06826da9b82f)
to branch 'im.pidgin.pidgin' (head 326d5b91950b3d78c445722f6d726cfa6b1c525d)
| 7395 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7395 | 3 | * |
| 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
14 | * |
| 7395 | 15 | * GNU General Public License for more details. |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * 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:
19853
diff
changeset
|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7395 | 20 | * |
| 21 | */ | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8838
diff
changeset
|
22 | |
|
18273
e61c53184c52
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17643
diff
changeset
|
23 | #include "internal.h" |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8838
diff
changeset
|
24 | |
|
18273
e61c53184c52
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17643
diff
changeset
|
25 | #include "blist.h" |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10112
diff
changeset
|
26 | #include "cipher.h" |
| 7395 | 27 | #include "debug.h" |
| 28 | #include "ft.h" | |
|
17424
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
29 | #include "request.h" |
| 8231 | 30 | #include "network.h" |
| 7395 | 31 | #include "notify.h" |
| 32 | ||
| 33 | #include "buddy.h" | |
| 8312 | 34 | #include "disco.h" |
| 7395 | 35 | #include "jabber.h" |
| 36 | #include "iq.h" | |
| 37 | #include "si.h" | |
| 38 | ||
| 39 | #include "si.h" | |
| 40 | ||
| 8262 | 41 | struct bytestreams_streamhost { |
| 42 | char *jid; | |
| 43 | char *host; | |
| 44 | int port; | |
| 45 | }; | |
| 46 | ||
| 47 | typedef struct _JabberSIXfer { | |
| 48 | JabberStream *js; | |
| 49 | ||
| 15884 | 50 | PurpleProxyConnectData *connect_data; |
| 51 | PurpleNetworkListenData *listen_data; | |
|
14175
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
52 | |
| 10940 | 53 | gboolean accepted; |
| 54 | ||
| 8262 | 55 | char *stream_id; |
| 56 | char *iq_id; | |
| 57 | ||
| 58 | enum { | |
| 59 | STREAM_METHOD_UNKNOWN = 0, | |
| 60 | STREAM_METHOD_BYTESTREAMS = 2 << 1, | |
| 61 | STREAM_METHOD_IBB = 2 << 2, | |
| 62 | STREAM_METHOD_UNSUPPORTED = 2 << 31 | |
| 63 | } stream_method; | |
| 64 | ||
| 65 | GList *streamhosts; | |
| 15884 | 66 | PurpleProxyInfo *gpi; |
| 8316 | 67 | |
| 68 | char *rxqueue; | |
| 69 | size_t rxlen; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
70 | gsize rxmaxlen; |
| 8262 | 71 | } JabberSIXfer; |
| 72 | ||
| 15884 | 73 | static PurpleXfer* |
| 8262 | 74 | jabber_si_xfer_find(JabberStream *js, const char *sid, const char *from) |
| 7395 | 75 | { |
| 76 | GList *xfers; | |
| 77 | ||
| 8262 | 78 | if(!sid || !from) |
| 7395 | 79 | return NULL; |
| 80 | ||
| 81 | for(xfers = js->file_transfers; xfers; xfers = xfers->next) { | |
| 15884 | 82 | PurpleXfer *xfer = xfers->data; |
| 7395 | 83 | JabberSIXfer *jsx = xfer->data; |
| 8316 | 84 | if(jsx->stream_id && xfer->who && |
| 85 | !strcmp(jsx->stream_id, sid) && !strcmp(xfer->who, from)) | |
| 7395 | 86 | return xfer; |
| 87 | } | |
| 88 | ||
| 89 | return NULL; | |
| 90 | } | |
| 91 | ||
| 8262 | 92 | |
| 15884 | 93 | static void jabber_si_bytestreams_attempt_connect(PurpleXfer *xfer); |
| 8262 | 94 | |
|
14175
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
95 | static void |
|
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
96 | jabber_si_bytestreams_connect_cb(gpointer data, gint source, const gchar *error_message) |
| 8262 | 97 | { |
| 15884 | 98 | PurpleXfer *xfer = data; |
| 7395 | 99 | JabberSIXfer *jsx = xfer->data; |
| 8262 | 100 | JabberIq *iq; |
| 101 | xmlnode *query, *su; | |
| 102 | struct bytestreams_streamhost *streamhost = jsx->streamhosts->data; | |
| 7395 | 103 | |
| 15884 | 104 | purple_proxy_info_destroy(jsx->gpi); |
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
105 | jsx->connect_data = NULL; |
| 8262 | 106 | |
| 107 | if(source < 0) { | |
|
17643
870d08f93965
Better error message for when a Jabber connection fails
Mark Doliner <markdoliner@pidgin.im>
parents:
17424
diff
changeset
|
108 | purple_debug_warning("jabber", |
|
870d08f93965
Better error message for when a Jabber connection fails
Mark Doliner <markdoliner@pidgin.im>
parents:
17424
diff
changeset
|
109 | "si connection failed, jid was %s, host was %s, error was %s\n", |
|
870d08f93965
Better error message for when a Jabber connection fails
Mark Doliner <markdoliner@pidgin.im>
parents:
17424
diff
changeset
|
110 | streamhost->jid, streamhost->host, error_message); |
| 8262 | 111 | jsx->streamhosts = g_list_remove(jsx->streamhosts, streamhost); |
| 112 | g_free(streamhost->jid); | |
| 113 | g_free(streamhost->host); | |
| 114 | g_free(streamhost); | |
| 115 | jabber_si_bytestreams_attempt_connect(xfer); | |
| 116 | return; | |
| 117 | } | |
| 118 | ||
| 119 | iq = jabber_iq_new_query(jsx->js, JABBER_IQ_RESULT, "http://jabber.org/protocol/bytestreams"); | |
| 120 | xmlnode_set_attrib(iq->node, "to", xfer->who); | |
| 121 | jabber_iq_set_id(iq, jsx->iq_id); | |
| 122 | query = xmlnode_get_child(iq->node, "query"); | |
| 123 | su = xmlnode_new_child(query, "streamhost-used"); | |
| 124 | xmlnode_set_attrib(su, "jid", streamhost->jid); | |
| 125 | ||
| 126 | jabber_iq_send(iq); | |
| 127 | ||
| 15884 | 128 | purple_xfer_start(xfer, source, NULL, -1); |
| 8262 | 129 | } |
| 130 | ||
| 15884 | 131 | static void jabber_si_bytestreams_attempt_connect(PurpleXfer *xfer) |
| 8262 | 132 | { |
| 133 | JabberSIXfer *jsx = xfer->data; | |
| 134 | struct bytestreams_streamhost *streamhost; | |
| 135 | char *dstaddr, *p; | |
| 136 | int i; | |
| 137 | unsigned char hashval[20]; | |
| 14561 | 138 | JabberID *dstjid; |
| 8262 | 139 | |
| 140 | if(!jsx->streamhosts) { | |
| 141 | JabberIq *iq = jabber_iq_new(jsx->js, JABBER_IQ_ERROR); | |
| 14740 | 142 | xmlnode *error, *inf; |
| 8262 | 143 | |
| 144 | if(jsx->iq_id) | |
| 145 | jabber_iq_set_id(iq, jsx->iq_id); | |
| 146 | ||
| 147 | xmlnode_set_attrib(iq->node, "to", xfer->who); | |
| 148 | error = xmlnode_new_child(iq->node, "error"); | |
| 149 | xmlnode_set_attrib(error, "code", "404"); | |
| 150 | xmlnode_set_attrib(error, "type", "cancel"); | |
| 14740 | 151 | inf = xmlnode_new_child(error, "item-not-found"); |
| 152 | xmlnode_set_namespace(inf, "urn:ietf:params:xml:ns:xmpp-stanzas"); | |
| 8262 | 153 | |
| 154 | jabber_iq_send(iq); | |
| 155 | ||
| 15884 | 156 | purple_xfer_cancel_local(xfer); |
| 8262 | 157 | |
| 158 | return; | |
| 159 | } | |
| 160 | ||
| 161 | streamhost = jsx->streamhosts->data; | |
| 7395 | 162 | |
| 14561 | 163 | dstjid = jabber_id_new(xfer->who); |
| 8262 | 164 | |
| 14561 | 165 | if(dstjid != NULL) { |
| 15884 | 166 | jsx->gpi = purple_proxy_info_new(); |
| 167 | purple_proxy_info_set_type(jsx->gpi, PURPLE_PROXY_SOCKS5); | |
| 168 | purple_proxy_info_set_host(jsx->gpi, streamhost->host); | |
| 169 | purple_proxy_info_set_port(jsx->gpi, streamhost->port); | |
| 14561 | 170 | |
| 171 | ||
| 172 | ||
| 173 | dstaddr = g_strdup_printf("%s%s@%s/%s%s@%s/%s", jsx->stream_id, dstjid->node, dstjid->domain, dstjid->resource, jsx->js->user->node, | |
| 174 | jsx->js->user->domain, jsx->js->user->resource); | |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10112
diff
changeset
|
175 | |
| 15884 | 176 | purple_cipher_digest_region("sha1", (guchar *)dstaddr, strlen(dstaddr), |
| 14561 | 177 | sizeof(hashval), hashval, NULL); |
| 178 | g_free(dstaddr); | |
| 179 | dstaddr = g_malloc(41); | |
| 180 | p = dstaddr; | |
| 181 | for(i=0; i<20; i++, p+=2) | |
| 182 | snprintf(p, 3, "%02x", hashval[i]); | |
| 8262 | 183 | |
| 15884 | 184 | jsx->connect_data = purple_proxy_connect_socks5(NULL, jsx->gpi, |
|
14899
c65f0b4fb351
[gaim-migrate @ 17606]
Mark Doliner <markdoliner@pidgin.im>
parents:
14740
diff
changeset
|
185 | dstaddr, 0, |
| 14561 | 186 | jabber_si_bytestreams_connect_cb, xfer); |
| 187 | g_free(dstaddr); | |
| 188 | ||
| 189 | jabber_id_free(dstjid); | |
| 190 | } | |
|
14175
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
191 | |
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
192 | if (jsx->connect_data == NULL) |
|
14175
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
193 | { |
|
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
194 | jsx->streamhosts = g_list_remove(jsx->streamhosts, streamhost); |
|
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
195 | g_free(streamhost->jid); |
|
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
196 | g_free(streamhost->host); |
|
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
197 | g_free(streamhost); |
|
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
198 | jabber_si_bytestreams_attempt_connect(xfer); |
|
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
199 | } |
| 8262 | 200 | } |
| 201 | ||
| 202 | void jabber_bytestreams_parse(JabberStream *js, xmlnode *packet) | |
| 203 | { | |
| 15884 | 204 | PurpleXfer *xfer; |
| 8262 | 205 | JabberSIXfer *jsx; |
| 206 | xmlnode *query, *streamhost; | |
| 14356 | 207 | const char *sid, *from, *type; |
| 208 | ||
| 209 | if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "set")) | |
| 210 | return; | |
| 8262 | 211 | |
| 212 | if(!(from = xmlnode_get_attrib(packet, "from"))) | |
| 213 | return; | |
| 214 | ||
| 215 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 216 | return; | |
| 217 | ||
| 218 | if(!(sid = xmlnode_get_attrib(query, "sid"))) | |
| 219 | return; | |
| 220 | ||
| 221 | if(!(xfer = jabber_si_xfer_find(js, sid, from))) | |
| 222 | return; | |
| 223 | ||
| 224 | jsx = xfer->data; | |
| 10940 | 225 | |
| 226 | if(!jsx->accepted) | |
| 227 | return; | |
| 228 | ||
| 8262 | 229 | if(jsx->iq_id) |
| 230 | g_free(jsx->iq_id); | |
| 231 | jsx->iq_id = g_strdup(xmlnode_get_attrib(packet, "id")); | |
| 232 | ||
| 233 | for(streamhost = xmlnode_get_child(query, "streamhost"); streamhost; | |
| 234 | streamhost = xmlnode_get_next_twin(streamhost)) { | |
| 235 | const char *jid, *host, *port; | |
| 236 | int portnum; | |
| 237 | ||
| 238 | if((jid = xmlnode_get_attrib(streamhost, "jid")) && | |
| 239 | (host = xmlnode_get_attrib(streamhost, "host")) && | |
| 240 | (port = xmlnode_get_attrib(streamhost, "port")) && | |
| 241 | (portnum = atoi(port))) { | |
| 242 | struct bytestreams_streamhost *sh = g_new0(struct bytestreams_streamhost, 1); | |
| 243 | sh->jid = g_strdup(jid); | |
| 244 | sh->host = g_strdup(host); | |
| 245 | sh->port = portnum; | |
| 246 | jsx->streamhosts = g_list_append(jsx->streamhosts, sh); | |
| 247 | } | |
| 248 | } | |
| 249 | ||
| 250 | jabber_si_bytestreams_attempt_connect(xfer); | |
| 7395 | 251 | } |
| 252 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
253 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
254 | static void |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
255 | jabber_si_xfer_bytestreams_send_read_again_resp_cb(gpointer data, gint source, |
| 15884 | 256 | PurpleInputCondition cond) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
257 | { |
| 15884 | 258 | PurpleXfer *xfer = data; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
259 | JabberSIXfer *jsx = xfer->data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
260 | int len; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
261 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
262 | len = write(source, jsx->rxqueue + jsx->rxlen, jsx->rxmaxlen - jsx->rxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
263 | if (len < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
264 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
265 | else if (len < 0) { |
| 15884 | 266 | purple_input_remove(xfer->watcher); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
267 | xfer->watcher = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
268 | g_free(jsx->rxqueue); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
269 | jsx->rxqueue = NULL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
270 | close(source); |
| 15884 | 271 | purple_xfer_cancel_remote(xfer); |
| 13441 | 272 | return; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
273 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
274 | jsx->rxlen += len; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
275 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
276 | if (jsx->rxlen < jsx->rxmaxlen) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
277 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
278 | |
| 15884 | 279 | purple_input_remove(xfer->watcher); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
280 | xfer->watcher = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
281 | g_free(jsx->rxqueue); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
282 | jsx->rxqueue = NULL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
283 | |
| 15884 | 284 | purple_xfer_start(xfer, source, NULL, -1); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
285 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
286 | |
| 8312 | 287 | static void |
| 8316 | 288 | jabber_si_xfer_bytestreams_send_read_again_cb(gpointer data, gint source, |
| 15884 | 289 | PurpleInputCondition cond) |
| 8312 | 290 | { |
| 15884 | 291 | PurpleXfer *xfer = data; |
| 8316 | 292 | JabberSIXfer *jsx = xfer->data; |
| 8312 | 293 | int i; |
| 8316 | 294 | char buffer[256]; |
| 295 | int len; | |
| 296 | char *dstaddr, *p; | |
| 297 | unsigned char hashval[20]; | |
| 298 | const char *host; | |
| 299 | ||
| 15884 | 300 | purple_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_again_cb\n"); |
| 8312 | 301 | |
| 8316 | 302 | if(jsx->rxlen < 5) { |
| 15884 | 303 | purple_debug_info("jabber", "reading the first 5 bytes\n"); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
304 | len = read(source, buffer, 5 - jsx->rxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
305 | if(len < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
306 | return; |
|
13788
019bc2080927
[gaim-migrate @ 16198]
Daniel Atallah <datallah@pidgin.im>
parents:
13493
diff
changeset
|
307 | else if(len <= 0) { |
| 15884 | 308 | purple_input_remove(xfer->watcher); |
| 8316 | 309 | xfer->watcher = 0; |
| 310 | close(source); | |
| 15884 | 311 | purple_xfer_cancel_remote(xfer); |
| 8316 | 312 | return; |
| 313 | } | |
| 314 | jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen); | |
| 315 | memcpy(jsx->rxqueue + jsx->rxlen, buffer, len); | |
| 316 | jsx->rxlen += len; | |
| 317 | return; | |
| 318 | } else if(jsx->rxqueue[0] != 0x05 || jsx->rxqueue[1] != 0x01 || | |
| 319 | jsx->rxqueue[3] != 0x03) { | |
| 15884 | 320 | purple_debug_info("jabber", "invalid socks5 stuff\n"); |
| 321 | purple_input_remove(xfer->watcher); | |
| 8316 | 322 | xfer->watcher = 0; |
| 323 | close(source); | |
| 15884 | 324 | purple_xfer_cancel_remote(xfer); |
| 8316 | 325 | return; |
| 326 | } else if(jsx->rxlen - 5 < jsx->rxqueue[4] + 2) { | |
| 15884 | 327 | purple_debug_info("jabber", "reading umpteen more bytes\n"); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
328 | len = read(source, buffer, jsx->rxqueue[4] + 5 + 2 - jsx->rxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
329 | if(len < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
330 | return; |
|
13788
019bc2080927
[gaim-migrate @ 16198]
Daniel Atallah <datallah@pidgin.im>
parents:
13493
diff
changeset
|
331 | else if(len <= 0) { |
| 15884 | 332 | purple_input_remove(xfer->watcher); |
| 8316 | 333 | xfer->watcher = 0; |
| 334 | close(source); | |
| 15884 | 335 | purple_xfer_cancel_remote(xfer); |
| 8316 | 336 | return; |
| 337 | } | |
| 338 | jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen); | |
| 339 | memcpy(jsx->rxqueue + jsx->rxlen, buffer, len); | |
| 340 | jsx->rxlen += len; | |
| 341 | } | |
| 8312 | 342 | |
| 8316 | 343 | if(jsx->rxlen - 5 < jsx->rxqueue[4] + 2) |
| 344 | return; | |
| 345 | ||
| 15884 | 346 | purple_input_remove(xfer->watcher); |
| 8316 | 347 | xfer->watcher = 0; |
| 8312 | 348 | |
| 8316 | 349 | dstaddr = g_strdup_printf("%s%s@%s/%s%s", jsx->stream_id, |
| 350 | jsx->js->user->node, jsx->js->user->domain, | |
| 351 | jsx->js->user->resource, xfer->who); | |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10112
diff
changeset
|
352 | |
| 15884 | 353 | purple_cipher_digest_region("sha1", (guchar *)dstaddr, strlen(dstaddr), |
| 10687 | 354 | sizeof(hashval), hashval, NULL); |
| 8316 | 355 | g_free(dstaddr); |
| 356 | dstaddr = g_malloc(41); | |
| 357 | p = dstaddr; | |
| 358 | for(i=0; i<20; i++, p+=2) | |
| 359 | snprintf(p, 3, "%02x", hashval[i]); | |
| 360 | ||
| 361 | if(jsx->rxqueue[4] != 40 || strncmp(dstaddr, jsx->rxqueue+5, 40) || | |
| 362 | jsx->rxqueue[45] != 0x00 || jsx->rxqueue[46] != 0x00) { | |
| 15884 | 363 | purple_debug_error("jabber", "someone connected with the wrong info!\n"); |
| 8312 | 364 | close(source); |
| 15884 | 365 | purple_xfer_cancel_remote(xfer); |
| 8312 | 366 | return; |
| 367 | } | |
| 368 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
369 | g_free(jsx->rxqueue); |
| 15884 | 370 | host = purple_network_get_my_ip(jsx->js->fd); |
| 8316 | 371 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
372 | jsx->rxmaxlen = 5 + strlen(host) + 2; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
373 | jsx->rxqueue = g_malloc(jsx->rxmaxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
374 | jsx->rxlen = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
375 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
376 | jsx->rxqueue[0] = 0x05; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
377 | jsx->rxqueue[1] = 0x00; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
378 | jsx->rxqueue[2] = 0x00; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
379 | jsx->rxqueue[3] = 0x03; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
380 | jsx->rxqueue[4] = strlen(host); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
381 | memcpy(jsx->rxqueue + 5, host, strlen(host)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
382 | jsx->rxqueue[5+strlen(host)] = 0x00; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
383 | jsx->rxqueue[6+strlen(host)] = 0x00; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
384 | |
| 15884 | 385 | xfer->watcher = purple_input_add(source, PURPLE_INPUT_WRITE, |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
386 | jabber_si_xfer_bytestreams_send_read_again_resp_cb, xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
387 | jabber_si_xfer_bytestreams_send_read_again_resp_cb(xfer, source, |
| 15884 | 388 | PURPLE_INPUT_WRITE); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
389 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
390 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
391 | static void |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
392 | jabber_si_xfer_bytestreams_send_read_response_cb(gpointer data, gint source, |
| 15884 | 393 | PurpleInputCondition cond) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
394 | { |
| 15884 | 395 | PurpleXfer *xfer = data; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
396 | JabberSIXfer *jsx = xfer->data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
397 | int len; |
| 8316 | 398 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
399 | len = write(source, jsx->rxqueue + jsx->rxlen, jsx->rxmaxlen - jsx->rxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
400 | if (len < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
401 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
402 | else if (len < 0) { |
| 15884 | 403 | purple_input_remove(xfer->watcher); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
404 | xfer->watcher = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
405 | g_free(jsx->rxqueue); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
406 | jsx->rxqueue = NULL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
407 | close(source); |
| 15884 | 408 | purple_xfer_cancel_remote(xfer); |
|
13493
598d8f618a31
[gaim-migrate @ 15868]
Richard Laager <rlaager@pidgin.im>
parents:
13441
diff
changeset
|
409 | return; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
410 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
411 | jsx->rxlen += len; |
| 8316 | 412 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
413 | if (jsx->rxlen < jsx->rxmaxlen) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
414 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
415 | |
| 15884 | 416 | purple_input_remove(xfer->watcher); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
417 | xfer->watcher = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
418 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
419 | if (jsx->rxqueue[1] == 0x00) { |
| 15884 | 420 | xfer->watcher = purple_input_add(source, PURPLE_INPUT_READ, |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
421 | jabber_si_xfer_bytestreams_send_read_again_cb, xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
422 | g_free(jsx->rxqueue); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
423 | jsx->rxqueue = NULL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
424 | } else { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
425 | close(source); |
| 15884 | 426 | purple_xfer_cancel_remote(xfer); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
427 | } |
| 8316 | 428 | } |
| 429 | ||
| 430 | static void | |
| 431 | jabber_si_xfer_bytestreams_send_read_cb(gpointer data, gint source, | |
| 15884 | 432 | PurpleInputCondition cond) |
| 8316 | 433 | { |
| 15884 | 434 | PurpleXfer *xfer = data; |
| 8316 | 435 | JabberSIXfer *jsx = xfer->data; |
| 436 | int i; | |
| 437 | int len; | |
| 438 | char buffer[256]; | |
| 439 | ||
| 15884 | 440 | purple_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_cb\n"); |
| 8316 | 441 | |
| 442 | xfer->fd = source; | |
| 443 | ||
| 444 | if(jsx->rxlen < 2) { | |
| 15884 | 445 | purple_debug_info("jabber", "reading those first two bytes\n"); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
446 | len = read(source, buffer, 2 - jsx->rxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
447 | if(len < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
448 | return; |
|
13788
019bc2080927
[gaim-migrate @ 16198]
Daniel Atallah <datallah@pidgin.im>
parents:
13493
diff
changeset
|
449 | else if(len <= 0) { |
| 15884 | 450 | purple_input_remove(xfer->watcher); |
| 8316 | 451 | xfer->watcher = 0; |
| 452 | close(source); | |
| 15884 | 453 | purple_xfer_cancel_remote(xfer); |
| 8316 | 454 | return; |
| 455 | } | |
| 456 | jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen); | |
| 457 | memcpy(jsx->rxqueue + jsx->rxlen, buffer, len); | |
| 458 | jsx->rxlen += len; | |
| 459 | return; | |
| 460 | } else if(jsx->rxlen - 2 < jsx->rxqueue[1]) { | |
| 15884 | 461 | purple_debug_info("jabber", "reading the next umpteen bytes\n"); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
462 | len = read(source, buffer, jsx->rxqueue[1] + 2 - jsx->rxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
463 | if(len < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
464 | return; |
|
13788
019bc2080927
[gaim-migrate @ 16198]
Daniel Atallah <datallah@pidgin.im>
parents:
13493
diff
changeset
|
465 | else if(len <= 0) { |
| 15884 | 466 | purple_input_remove(xfer->watcher); |
| 8316 | 467 | xfer->watcher = 0; |
| 468 | close(source); | |
| 15884 | 469 | purple_xfer_cancel_remote(xfer); |
| 8316 | 470 | return; |
| 471 | } | |
| 472 | jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen); | |
| 473 | memcpy(jsx->rxqueue + jsx->rxlen, buffer, len); | |
| 474 | jsx->rxlen += len; | |
| 475 | } | |
| 476 | ||
| 477 | if(jsx->rxlen -2 < jsx->rxqueue[1]) | |
| 478 | return; | |
| 479 | ||
| 15884 | 480 | purple_input_remove(xfer->watcher); |
| 8316 | 481 | xfer->watcher = 0; |
| 482 | ||
| 15884 | 483 | purple_debug_info("jabber", "checking to make sure we're socks FIVE\n"); |
| 8316 | 484 | |
| 485 | if(jsx->rxqueue[0] != 0x05) { | |
| 486 | close(source); | |
| 15884 | 487 | purple_xfer_cancel_remote(xfer); |
| 8316 | 488 | return; |
| 489 | } | |
| 490 | ||
| 15884 | 491 | purple_debug_info("jabber", "going to test %hhu different methods\n", jsx->rxqueue[1]); |
| 8316 | 492 | |
| 493 | for(i=0; i<jsx->rxqueue[1]; i++) { | |
| 494 | ||
| 15884 | 495 | purple_debug_info("jabber", "testing %hhu\n", jsx->rxqueue[i+2]); |
| 8316 | 496 | if(jsx->rxqueue[i+2] == 0x00) { |
| 497 | g_free(jsx->rxqueue); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
498 | jsx->rxlen = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
499 | jsx->rxmaxlen = 2; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
500 | jsx->rxqueue = g_malloc(jsx->rxmaxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
501 | jsx->rxqueue[0] = 0x05; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
502 | jsx->rxqueue[1] = 0x00; |
| 15884 | 503 | xfer->watcher = purple_input_add(source, PURPLE_INPUT_WRITE, |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
504 | jabber_si_xfer_bytestreams_send_read_response_cb, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
505 | xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
506 | jabber_si_xfer_bytestreams_send_read_response_cb(xfer, |
| 15884 | 507 | source, PURPLE_INPUT_WRITE); |
| 8316 | 508 | jsx->rxqueue = NULL; |
| 509 | jsx->rxlen = 0; | |
| 8312 | 510 | return; |
| 511 | } | |
| 512 | } | |
| 513 | ||
| 8316 | 514 | g_free(jsx->rxqueue); |
| 515 | jsx->rxlen = 0; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
516 | jsx->rxmaxlen = 2; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
517 | jsx->rxqueue = g_malloc(jsx->rxmaxlen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
518 | jsx->rxqueue[0] = 0x05; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
519 | jsx->rxqueue[1] = 0xFF; |
| 15884 | 520 | xfer->watcher = purple_input_add(source, PURPLE_INPUT_WRITE, |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
521 | jabber_si_xfer_bytestreams_send_read_response_cb, xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
522 | jabber_si_xfer_bytestreams_send_read_response_cb(xfer, |
| 15884 | 523 | source, PURPLE_INPUT_WRITE); |
| 8312 | 524 | } |
| 525 | ||
| 526 | static void | |
| 8316 | 527 | jabber_si_xfer_bytestreams_send_connected_cb(gpointer data, gint source, |
| 15884 | 528 | PurpleInputCondition cond) |
| 8316 | 529 | { |
| 15884 | 530 | PurpleXfer *xfer = data; |
| 8316 | 531 | int acceptfd; |
| 532 | ||
| 15884 | 533 | purple_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_connected_cb\n"); |
| 8316 | 534 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
535 | acceptfd = accept(source, NULL, 0); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
536 | if(acceptfd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
537 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
538 | else if(acceptfd == -1) { |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
19859
diff
changeset
|
539 | purple_debug_warning("jabber", "accept: %s\n", g_strerror(errno)); |
| 8316 | 540 | return; |
| 541 | } | |
| 542 | ||
| 15884 | 543 | purple_input_remove(xfer->watcher); |
| 8316 | 544 | close(source); |
| 545 | ||
| 15884 | 546 | xfer->watcher = purple_input_add(acceptfd, PURPLE_INPUT_READ, |
| 8316 | 547 | jabber_si_xfer_bytestreams_send_read_cb, xfer); |
| 548 | } | |
| 549 | ||
| 550 | static void | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
551 | jabber_si_xfer_bytestreams_listen_cb(int sock, gpointer data) |
| 8312 | 552 | { |
| 15884 | 553 | PurpleXfer *xfer = data; |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
554 | JabberSIXfer *jsx; |
| 8312 | 555 | JabberIq *iq; |
| 556 | xmlnode *query, *streamhost; | |
| 557 | char *jid, *port; | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
558 | |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
559 | jsx = xfer->data; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
560 | jsx->listen_data = NULL; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
561 | |
| 15884 | 562 | if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL) { |
| 563 | purple_xfer_unref(xfer); | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
564 | return; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
565 | } |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
566 | |
| 15884 | 567 | purple_xfer_unref(xfer); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
568 | |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
569 | if (sock < 0) { |
| 15884 | 570 | purple_xfer_cancel_local(xfer); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
571 | return; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
572 | } |
| 8312 | 573 | |
| 574 | iq = jabber_iq_new_query(jsx->js, JABBER_IQ_SET, | |
| 575 | "http://jabber.org/protocol/bytestreams"); | |
| 576 | xmlnode_set_attrib(iq->node, "to", xfer->who); | |
| 577 | query = xmlnode_get_child(iq->node, "query"); | |
| 578 | ||
| 579 | xmlnode_set_attrib(query, "sid", jsx->stream_id); | |
| 580 | ||
| 581 | streamhost = xmlnode_new_child(query, "streamhost"); | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
582 | jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
583 | jsx->js->user->domain, jsx->js->user->resource); |
| 8312 | 584 | xmlnode_set_attrib(streamhost, "jid", jid); |
| 585 | g_free(jid); | |
| 586 | ||
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
587 | /* XXX: shouldn't we use the public IP or something? here */ |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
588 | xmlnode_set_attrib(streamhost, "host", |
| 15884 | 589 | purple_network_get_my_ip(jsx->js->fd)); |
| 590 | xfer->local_port = purple_network_get_port_from_fd(sock); | |
| 8316 | 591 | port = g_strdup_printf("%hu", xfer->local_port); |
| 8312 | 592 | xmlnode_set_attrib(streamhost, "port", port); |
| 593 | g_free(port); | |
| 594 | ||
| 15884 | 595 | xfer->watcher = purple_input_add(sock, PURPLE_INPUT_READ, |
| 8312 | 596 | jabber_si_xfer_bytestreams_send_connected_cb, xfer); |
| 597 | ||
| 598 | /* XXX: insert proxies here */ | |
| 599 | ||
| 600 | /* XXX: callback to find out which streamhost they used, or see if they | |
| 601 | * screwed it up */ | |
| 602 | jabber_iq_send(iq); | |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
603 | |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
604 | } |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
605 | |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
606 | static void |
| 15884 | 607 | jabber_si_xfer_bytestreams_send_init(PurpleXfer *xfer) |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
608 | { |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
609 | JabberSIXfer *jsx; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
610 | |
| 15884 | 611 | purple_xfer_ref(xfer); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
612 | |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
613 | jsx = xfer->data; |
| 15884 | 614 | jsx->listen_data = purple_network_listen_range(0, 0, SOCK_STREAM, |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
615 | jabber_si_xfer_bytestreams_listen_cb, xfer); |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
616 | if (jsx->listen_data == NULL) { |
| 15884 | 617 | purple_xfer_unref(xfer); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
618 | /* XXX: couldn't open a port, we're fscked */ |
| 15884 | 619 | purple_xfer_cancel_local(xfer); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
620 | return; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
621 | } |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
622 | |
| 8312 | 623 | } |
| 624 | ||
| 625 | static void jabber_si_xfer_send_method_cb(JabberStream *js, xmlnode *packet, | |
| 626 | gpointer data) | |
| 627 | { | |
| 15884 | 628 | PurpleXfer *xfer = data; |
| 8312 | 629 | xmlnode *si, *feature, *x, *field, *value; |
| 630 | ||
| 631 | if(!(si = xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si"))) { | |
| 15884 | 632 | purple_xfer_cancel_remote(xfer); |
| 8312 | 633 | return; |
| 634 | } | |
| 635 | ||
| 636 | if(!(feature = xmlnode_get_child_with_namespace(si, "feature", "http://jabber.org/protocol/feature-neg"))) { | |
| 15884 | 637 | purple_xfer_cancel_remote(xfer); |
| 8312 | 638 | return; |
| 639 | } | |
| 640 | ||
| 641 | if(!(x = xmlnode_get_child_with_namespace(feature, "x", "jabber:x:data"))) { | |
| 15884 | 642 | purple_xfer_cancel_remote(xfer); |
| 8312 | 643 | return; |
| 644 | } | |
| 645 | ||
| 646 | for(field = xmlnode_get_child(x, "field"); field; field = xmlnode_get_next_twin(field)) { | |
| 647 | const char *var = xmlnode_get_attrib(field, "var"); | |
| 648 | ||
| 649 | if(var && !strcmp(var, "stream-method")) { | |
| 650 | if((value = xmlnode_get_child(field, "value"))) { | |
| 651 | char *val = xmlnode_get_data(value); | |
| 652 | if(val && !strcmp(val, "http://jabber.org/protocol/bytestreams")) { | |
| 653 | jabber_si_xfer_bytestreams_send_init(xfer); | |
| 654 | g_free(val); | |
| 655 | return; | |
| 656 | } | |
| 657 | g_free(val); | |
| 658 | } | |
| 659 | } | |
| 660 | } | |
| 15884 | 661 | purple_xfer_cancel_remote(xfer); |
| 8312 | 662 | } |
| 663 | ||
| 15884 | 664 | static void jabber_si_xfer_send_request(PurpleXfer *xfer) |
| 8312 | 665 | { |
| 666 | JabberSIXfer *jsx = xfer->data; | |
| 667 | JabberIq *iq; | |
| 668 | xmlnode *si, *file, *feature, *x, *field, *option, *value; | |
| 669 | char buf[32]; | |
| 670 | ||
| 671 | xfer->filename = g_path_get_basename(xfer->local_filename); | |
| 672 | ||
| 673 | iq = jabber_iq_new(jsx->js, JABBER_IQ_SET); | |
| 674 | xmlnode_set_attrib(iq->node, "to", xfer->who); | |
| 675 | si = xmlnode_new_child(iq->node, "si"); | |
| 13808 | 676 | xmlnode_set_namespace(si, "http://jabber.org/protocol/si"); |
| 8312 | 677 | jsx->stream_id = jabber_get_next_id(jsx->js); |
| 678 | xmlnode_set_attrib(si, "id", jsx->stream_id); | |
| 679 | xmlnode_set_attrib(si, "profile", | |
| 680 | "http://jabber.org/protocol/si/profile/file-transfer"); | |
| 681 | ||
| 682 | file = xmlnode_new_child(si, "file"); | |
| 13808 | 683 | xmlnode_set_namespace(file, |
| 8312 | 684 | "http://jabber.org/protocol/si/profile/file-transfer"); |
| 685 | xmlnode_set_attrib(file, "name", xfer->filename); | |
|
11656
56f5e598dc6c
[gaim-migrate @ 13940]
Richard Laager <rlaager@pidgin.im>
parents:
11183
diff
changeset
|
686 | g_snprintf(buf, sizeof(buf), "%" G_GSIZE_FORMAT, xfer->size); |
| 8312 | 687 | xmlnode_set_attrib(file, "size", buf); |
| 688 | /* maybe later we'll do hash and date attribs */ | |
| 689 | ||
| 690 | feature = xmlnode_new_child(si, "feature"); | |
| 13808 | 691 | xmlnode_set_namespace(feature, |
| 8312 | 692 | "http://jabber.org/protocol/feature-neg"); |
| 693 | x = xmlnode_new_child(feature, "x"); | |
| 13808 | 694 | xmlnode_set_namespace(x, "jabber:x:data"); |
| 8312 | 695 | xmlnode_set_attrib(x, "type", "form"); |
| 696 | field = xmlnode_new_child(x, "field"); | |
| 697 | xmlnode_set_attrib(field, "var", "stream-method"); | |
| 698 | xmlnode_set_attrib(field, "type", "list-single"); | |
| 699 | option = xmlnode_new_child(field, "option"); | |
| 700 | value = xmlnode_new_child(option, "value"); | |
| 701 | xmlnode_insert_data(value, "http://jabber.org/protocol/bytestreams", | |
| 702 | -1); | |
| 703 | /* | |
| 704 | option = xmlnode_new_child(field, "option"); | |
| 705 | value = xmlnode_new_child(option, "value"); | |
| 706 | xmlnode_insert_data(value, "http://jabber.org/protocol/ibb", -1); | |
| 707 | */ | |
| 708 | ||
| 709 | jabber_iq_set_callback(iq, jabber_si_xfer_send_method_cb, xfer); | |
| 710 | ||
|
19853
389f6a0d4347
Unregister the iq callback listener when the transfer is freed. Fixes #1804. It doesn't seem correct to me that nothing is sent to the recipient when the sender cancels the ft request, but that is a different issue.
Daniel Atallah <datallah@pidgin.im>
parents:
18273
diff
changeset
|
711 | /* Store the IQ id so that we can cancel the callback */ |
|
389f6a0d4347
Unregister the iq callback listener when the transfer is freed. Fixes #1804. It doesn't seem correct to me that nothing is sent to the recipient when the sender cancels the ft request, but that is a different issue.
Daniel Atallah <datallah@pidgin.im>
parents:
18273
diff
changeset
|
712 | g_free(jsx->iq_id); |
|
389f6a0d4347
Unregister the iq callback listener when the transfer is freed. Fixes #1804. It doesn't seem correct to me that nothing is sent to the recipient when the sender cancels the ft request, but that is a different issue.
Daniel Atallah <datallah@pidgin.im>
parents:
18273
diff
changeset
|
713 | jsx->iq_id = g_strdup(iq->id); |
|
389f6a0d4347
Unregister the iq callback listener when the transfer is freed. Fixes #1804. It doesn't seem correct to me that nothing is sent to the recipient when the sender cancels the ft request, but that is a different issue.
Daniel Atallah <datallah@pidgin.im>
parents:
18273
diff
changeset
|
714 | |
| 8312 | 715 | jabber_iq_send(iq); |
| 716 | } | |
| 717 | ||
| 15884 | 718 | static void jabber_si_xfer_free(PurpleXfer *xfer) |
| 8312 | 719 | { |
| 8316 | 720 | JabberSIXfer *jsx = xfer->data; |
| 721 | JabberStream *js = jsx->js; | |
| 722 | ||
| 723 | js->file_transfers = g_list_remove(js->file_transfers, xfer); | |
| 724 | ||
|
14324
8cbedd82b6ac
[gaim-migrate @ 16944]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
725 | if (jsx->connect_data != NULL) |
| 15884 | 726 | purple_proxy_connect_cancel(jsx->connect_data); |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14324
diff
changeset
|
727 | if (jsx->listen_data != NULL) |
| 15884 | 728 | purple_network_listen_cancel(jsx->listen_data); |
|
19853
389f6a0d4347
Unregister the iq callback listener when the transfer is freed. Fixes #1804. It doesn't seem correct to me that nothing is sent to the recipient when the sender cancels the ft request, but that is a different issue.
Daniel Atallah <datallah@pidgin.im>
parents:
18273
diff
changeset
|
729 | if (jsx->iq_id != NULL) |
|
389f6a0d4347
Unregister the iq callback listener when the transfer is freed. Fixes #1804. It doesn't seem correct to me that nothing is sent to the recipient when the sender cancels the ft request, but that is a different issue.
Daniel Atallah <datallah@pidgin.im>
parents:
18273
diff
changeset
|
730 | jabber_iq_remove_callback_by_id(js, jsx->iq_id); |
|
14175
2bc5a80c5071
[gaim-migrate @ 16747]
Mark Doliner <markdoliner@pidgin.im>
parents:
14170
diff
changeset
|
731 | |
| 8316 | 732 | g_free(jsx->stream_id); |
| 733 | g_free(jsx->iq_id); | |
| 734 | /* XXX: free other stuff */ | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13146
diff
changeset
|
735 | g_free(jsx->rxqueue); |
| 8316 | 736 | g_free(jsx); |
| 737 | xfer->data = NULL; | |
| 738 | } | |
| 739 | ||
| 15884 | 740 | static void jabber_si_xfer_cancel_send(PurpleXfer *xfer) |
| 8316 | 741 | { |
| 742 | jabber_si_xfer_free(xfer); | |
| 15884 | 743 | purple_debug(PURPLE_DEBUG_INFO, "jabber", "in jabber_si_xfer_cancel_send\n"); |
| 8312 | 744 | } |
| 745 | ||
| 746 | ||
| 15884 | 747 | static void jabber_si_xfer_request_denied(PurpleXfer *xfer) |
| 13146 | 748 | { |
| 749 | jabber_si_xfer_free(xfer); | |
| 15884 | 750 | purple_debug(PURPLE_DEBUG_INFO, "jabber", "in jabber_si_xfer_request_denied\n"); |
| 13146 | 751 | } |
| 752 | ||
| 753 | ||
| 15884 | 754 | static void jabber_si_xfer_cancel_recv(PurpleXfer *xfer) |
| 8312 | 755 | { |
| 8316 | 756 | jabber_si_xfer_free(xfer); |
| 15884 | 757 | purple_debug(PURPLE_DEBUG_INFO, "jabber", "in jabber_si_xfer_cancel_recv\n"); |
| 8312 | 758 | } |
| 759 | ||
| 760 | ||
| 15884 | 761 | static void jabber_si_xfer_end(PurpleXfer *xfer) |
| 8316 | 762 | { |
| 763 | jabber_si_xfer_free(xfer); | |
| 764 | } | |
| 765 | ||
| 766 | ||
| 8312 | 767 | static void jabber_si_xfer_send_disco_cb(JabberStream *js, const char *who, |
| 768 | JabberCapabilities capabilities, gpointer data) | |
| 769 | { | |
| 15884 | 770 | PurpleXfer *xfer = data; |
| 8312 | 771 | |
| 772 | if(capabilities & JABBER_CAP_SI_FILE_XFER) { | |
| 773 | jabber_si_xfer_send_request(xfer); | |
| 774 | } else { | |
| 775 | char *msg = g_strdup_printf(_("Unable to send file to %s, user does not support file transfers"), who); | |
| 15884 | 776 | purple_notify_error(js->gc, _("File Send Failed"), |
| 8312 | 777 | _("File Send Failed"), msg); |
| 778 | g_free(msg); | |
| 779 | } | |
| 780 | } | |
| 781 | ||
|
17424
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
782 | static void resource_select_cancel_cb(PurpleXfer *xfer, PurpleRequestFields *fields) |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
783 | { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
784 | purple_xfer_cancel_local(xfer); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
785 | } |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
786 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
787 | static void do_transfer_send(PurpleXfer *xfer, const char *resource) |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
788 | { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
789 | JabberSIXfer *jsx = xfer->data; |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
790 | char **who_v = g_strsplit(xfer->who, "/", 2); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
791 | char *who; |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
792 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
793 | who = g_strdup_printf("%s/%s", who_v[0], resource); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
794 | g_strfreev(who_v); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
795 | g_free(xfer->who); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
796 | xfer->who = who; |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
797 | jabber_disco_info_do(jsx->js, who, |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
798 | jabber_si_xfer_send_disco_cb, xfer); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
799 | } |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
800 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
801 | static void resource_select_ok_cb(PurpleXfer *xfer, PurpleRequestFields *fields) |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
802 | { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
803 | PurpleRequestField *field = purple_request_fields_get_field(fields, "resource"); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
804 | int selected_id = purple_request_field_choice_get_value(field); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
805 | GList *labels = purple_request_field_choice_get_labels(field); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
806 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
807 | const char *selected_label = g_list_nth_data(labels, selected_id); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
808 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
809 | do_transfer_send(xfer, selected_label); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
810 | } |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
811 | |
| 15884 | 812 | static void jabber_si_xfer_init(PurpleXfer *xfer) |
| 8262 | 813 | { |
| 814 | JabberSIXfer *jsx = xfer->data; | |
| 815 | JabberIq *iq; | |
| 15884 | 816 | if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { |
| 8312 | 817 | JabberBuddy *jb; |
| 818 | JabberBuddyResource *jbr = NULL; | |
|
17424
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
819 | char *resource; |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
820 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
821 | if(NULL != (resource = jabber_get_resource(xfer->who))) { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
822 | /* they've specified a resource, no need to ask or |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
823 | * default or anything, just do it */ |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
824 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
825 | do_transfer_send(xfer, resource); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
826 | g_free(resource); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
827 | } |
| 8312 | 828 | |
| 829 | jb = jabber_buddy_find(jsx->js, xfer->who, TRUE); | |
|
17424
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
830 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
831 | if(!jb || !jb->resources) { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
832 | /* no resources online, we're trying to send to someone |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
833 | * whose presence we're not subscribed to, or |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
834 | * someone who is offline. Let's inform the user */ |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
835 | char *msg; |
| 8262 | 836 | |
|
17424
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
837 | if(!jb) { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
838 | msg = g_strdup_printf(_("Unable to send file to %s, invalid JID"), xfer->who); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
839 | } else if(jb->subscription & JABBER_SUB_TO) { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
840 | msg = g_strdup_printf(_("Unable to send file to %s, user is not online"), xfer->who); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
841 | } else { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
842 | msg = g_strdup_printf(_("Unable to send file to %s, not subscribed to user presence"), xfer->who); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
843 | } |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
844 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
845 | purple_notify_error(jsx->js->gc, _("File Send Failed"), _("File Send Failed"), msg); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
846 | g_free(msg); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
847 | } else if(g_list_length(jb->resources) == 1) { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
848 | /* only 1 resource online (probably our most common case) |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
849 | * so no need to ask who to send to */ |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
850 | jbr = jb->resources->data; |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
851 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
852 | do_transfer_send(xfer, jbr->name); |
|
12935
b2d60d1890cc
[gaim-migrate @ 15288]
Richard Laager <rlaager@pidgin.im>
parents:
12909
diff
changeset
|
853 | |
| 8312 | 854 | } else { |
|
17424
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
855 | /* we've got multiple resources, we need to pick one to send to */ |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
856 | GList *l; |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
857 | char *msg = g_strdup_printf(_("Please select which resource of %s you would like to send a file to"), xfer->who); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
858 | PurpleRequestFields *fields = purple_request_fields_new(); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
859 | PurpleRequestField *field = purple_request_field_choice_new("resource", _("Resource"), 0); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
860 | PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
861 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
862 | for(l = jb->resources; l; l = l->next) |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
863 | { |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
864 | jbr = l->data; |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
865 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
866 | purple_request_field_choice_add(field, jbr->name); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
867 | } |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
868 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
869 | purple_request_field_group_add_field(group, field); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
870 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
871 | purple_request_fields_add_group(fields, group); |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
872 | |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
873 | purple_request_fields_with_hint(jsx->js->gc, _("Select a Resource"), msg, NULL, fields, |
|
17424
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
874 | _("Send File"), G_CALLBACK(resource_select_ok_cb), _("Cancel"), G_CALLBACK(resource_select_cancel_cb), |
|
21233
e75de8db4f2b
Re-namespace the #defines to all be PURPLE_REQUEST_UI_HINT_*. I see no
Richard Laager <rlaager@pidgin.im>
parents:
21225
diff
changeset
|
875 | jsx->js->gc->account, xfer->who, NULL, PURPLE_REQUEST_UI_HINT_XFER, xfer); |
|
17424
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
876 | |
|
3fd87c1c0320
if there are multiple resources available, ask the user which resource to
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
877 | g_free(msg); |
| 8312 | 878 | } |
| 879 | } else { | |
| 880 | xmlnode *si, *feature, *x, *field, *value; | |
| 8262 | 881 | |
| 8312 | 882 | iq = jabber_iq_new(jsx->js, JABBER_IQ_RESULT); |
| 883 | xmlnode_set_attrib(iq->node, "to", xfer->who); | |
| 884 | if(jsx->iq_id) | |
| 885 | jabber_iq_set_id(iq, jsx->iq_id); | |
| 886 | ||
| 10940 | 887 | jsx->accepted = TRUE; |
| 888 | ||
| 8312 | 889 | si = xmlnode_new_child(iq->node, "si"); |
| 13808 | 890 | xmlnode_set_namespace(si, "http://jabber.org/protocol/si"); |
| 8312 | 891 | |
| 892 | feature = xmlnode_new_child(si, "feature"); | |
| 13808 | 893 | xmlnode_set_namespace(feature, "http://jabber.org/protocol/feature-neg"); |
| 8262 | 894 | |
| 8312 | 895 | x = xmlnode_new_child(feature, "x"); |
| 13808 | 896 | xmlnode_set_namespace(x, "jabber:x:data"); |
| 8343 | 897 | xmlnode_set_attrib(x, "type", "submit"); |
| 8262 | 898 | |
| 8312 | 899 | field = xmlnode_new_child(x, "field"); |
| 900 | xmlnode_set_attrib(field, "var", "stream-method"); | |
| 901 | ||
| 902 | value = xmlnode_new_child(field, "value"); | |
| 903 | if(jsx->stream_method & STREAM_METHOD_BYTESTREAMS) | |
| 904 | xmlnode_insert_data(value, "http://jabber.org/protocol/bytestreams", -1); | |
| 905 | /* | |
| 906 | else if(jsx->stream_method & STREAM_METHOD_IBB) | |
| 8262 | 907 | xmlnode_insert_data(value, "http://jabber.org/protocol/ibb", -1); |
| 908 | */ | |
| 909 | ||
| 8312 | 910 | jabber_iq_send(iq); |
| 911 | } | |
| 8262 | 912 | } |
| 913 | ||
| 15884 | 914 | PurpleXfer *jabber_si_new_xfer(PurpleConnection *gc, const char *who) |
| 8312 | 915 | { |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8838
diff
changeset
|
916 | JabberStream *js; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8838
diff
changeset
|
917 | |
| 15884 | 918 | PurpleXfer *xfer; |
| 8312 | 919 | JabberSIXfer *jsx; |
| 920 | ||
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8838
diff
changeset
|
921 | js = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8838
diff
changeset
|
922 | |
| 15884 | 923 | xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who); |
|
15345
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
924 | if (xfer) |
|
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
925 | { |
|
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
926 | xfer->data = jsx = g_new0(JabberSIXfer, 1); |
|
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
927 | jsx->js = js; |
| 8262 | 928 | |
| 15884 | 929 | purple_xfer_set_init_fnc(xfer, jabber_si_xfer_init); |
| 930 | purple_xfer_set_cancel_send_fnc(xfer, jabber_si_xfer_cancel_send); | |
| 931 | purple_xfer_set_end_fnc(xfer, jabber_si_xfer_end); | |
| 8312 | 932 | |
|
15345
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
933 | js->file_transfers = g_list_append(js->file_transfers, xfer); |
|
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
934 | } |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
935 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
936 | return xfer; |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
937 | } |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
938 | |
| 15884 | 939 | void jabber_si_xfer_send(PurpleConnection *gc, const char *who, const char *file) |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
940 | { |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
941 | JabberStream *js; |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
942 | |
| 15884 | 943 | PurpleXfer *xfer; |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
944 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
945 | js = gc->proto_data; |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
946 | |
| 15884 | 947 | if(!purple_find_buddy(gc->account, who) || !jabber_buddy_find(js, who, FALSE)) |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
948 | return; |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
949 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
950 | xfer = jabber_si_new_xfer(gc, who); |
| 8312 | 951 | |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9030
diff
changeset
|
952 | if (file) |
| 15884 | 953 | purple_xfer_request_accepted(xfer, file); |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9030
diff
changeset
|
954 | else |
| 15884 | 955 | purple_xfer_request(xfer); |
| 8262 | 956 | } |
| 957 | ||
| 958 | void jabber_si_parse(JabberStream *js, xmlnode *packet) | |
| 959 | { | |
| 960 | JabberSIXfer *jsx; | |
| 15884 | 961 | PurpleXfer *xfer; |
| 8262 | 962 | xmlnode *si, *file, *feature, *x, *field, *option, *value; |
| 10939 | 963 | const char *stream_id, *filename, *filesize_c, *profile, *from; |
| 8262 | 964 | size_t filesize = 0; |
| 965 | ||
| 966 | if(!(si = xmlnode_get_child(packet, "si"))) | |
| 967 | return; | |
| 968 | ||
| 969 | if(!(profile = xmlnode_get_attrib(si, "profile")) || | |
| 970 | strcmp(profile, "http://jabber.org/protocol/si/profile/file-transfer")) | |
| 971 | return; | |
| 972 | ||
| 973 | if(!(stream_id = xmlnode_get_attrib(si, "id"))) | |
| 974 | return; | |
| 975 | ||
| 976 | if(!(file = xmlnode_get_child(si, "file"))) | |
| 977 | return; | |
| 978 | ||
| 979 | if(!(filename = xmlnode_get_attrib(file, "name"))) | |
| 980 | return; | |
| 981 | ||
| 982 | if((filesize_c = xmlnode_get_attrib(file, "size"))) | |
| 983 | filesize = atoi(filesize_c); | |
| 984 | ||
| 985 | if(!(feature = xmlnode_get_child(si, "feature"))) | |
| 986 | return; | |
| 987 | ||
| 988 | if(!(x = xmlnode_get_child_with_namespace(feature, "x", "jabber:x:data"))) | |
| 989 | return; | |
| 990 | ||
| 10939 | 991 | if(!(from = xmlnode_get_attrib(packet, "from"))) |
| 992 | return; | |
| 993 | ||
| 994 | /* if they've already sent us this file transfer with the same damn id | |
| 995 | * then we're gonna ignore it, until I think of something better to do | |
| 996 | * with it */ | |
| 997 | if((xfer = jabber_si_xfer_find(js, stream_id, from))) | |
| 998 | return; | |
| 999 | ||
| 8262 | 1000 | jsx = g_new0(JabberSIXfer, 1); |
| 1001 | ||
| 1002 | for(field = xmlnode_get_child(x, "field"); field; field = xmlnode_get_next_twin(field)) { | |
| 1003 | const char *var = xmlnode_get_attrib(field, "var"); | |
| 1004 | if(var && !strcmp(var, "stream-method")) { | |
| 1005 | for(option = xmlnode_get_child(field, "option"); option; | |
| 1006 | option = xmlnode_get_next_twin(option)) { | |
| 1007 | if((value = xmlnode_get_child(option, "value"))) { | |
| 1008 | char *val; | |
| 1009 | if((val = xmlnode_get_data(value))) { | |
| 1010 | if(!strcmp(val, "http://jabber.org/protocol/bytestreams")) { | |
| 1011 | jsx->stream_method |= STREAM_METHOD_BYTESTREAMS; | |
| 1012 | /* | |
| 1013 | } else if(!strcmp(val, "http://jabber.org/protocol/ibb")) { | |
| 1014 | jsx->stream_method |= STREAM_METHOD_IBB; | |
| 1015 | */ | |
| 1016 | } | |
| 1017 | g_free(val); | |
| 1018 | } | |
| 1019 | } | |
| 1020 | } | |
| 1021 | } | |
| 1022 | } | |
| 1023 | ||
| 1024 | if(jsx->stream_method == STREAM_METHOD_UNKNOWN) { | |
| 1025 | g_free(jsx); | |
| 1026 | return; | |
| 1027 | } | |
| 1028 | ||
| 1029 | jsx->js = js; | |
| 1030 | jsx->stream_id = g_strdup(stream_id); | |
| 1031 | jsx->iq_id = g_strdup(xmlnode_get_attrib(packet, "id")); | |
| 1032 | ||
| 15884 | 1033 | xfer = purple_xfer_new(js->gc->account, PURPLE_XFER_RECEIVE, from); |
|
15345
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
1034 | if (xfer) |
|
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
1035 | { |
|
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
1036 | xfer->data = jsx; |
| 8262 | 1037 | |
| 15884 | 1038 | purple_xfer_set_filename(xfer, filename); |
|
15345
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
1039 | if(filesize > 0) |
| 15884 | 1040 | purple_xfer_set_size(xfer, filesize); |
| 8262 | 1041 | |
| 15884 | 1042 | purple_xfer_set_init_fnc(xfer, jabber_si_xfer_init); |
| 1043 | purple_xfer_set_request_denied_fnc(xfer, jabber_si_xfer_request_denied); | |
| 1044 | purple_xfer_set_cancel_recv_fnc(xfer, jabber_si_xfer_cancel_recv); | |
| 1045 | purple_xfer_set_end_fnc(xfer, jabber_si_xfer_end); | |
| 8262 | 1046 | |
|
15345
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
1047 | js->file_transfers = g_list_append(js->file_transfers, xfer); |
| 8262 | 1048 | |
| 15884 | 1049 | purple_xfer_request(xfer); |
|
15345
797936e968ff
[gaim-migrate @ 18073]
Evan Schoenberg <evands@pidgin.im>
parents:
14899
diff
changeset
|
1050 | } |
| 8262 | 1051 | } |
| 1052 | ||
| 7395 | 1053 |