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