annotate src/protocols/jabber/si.c @ 12508:5cfc53ead482

[gaim-migrate @ 14820] patch from Simon Wilkinson to add Cyrus SASL support for jabber Give him credit if it works flawlessly. Blame me if it doesn't, as the patch was against 1.3.1 (yeah, I've been sitting on it for that long), and I had to merge it to HEAD, and clean up a bunch of warnings committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 17 Dec 2005 02:24:05 +0000
parents cbebda5f019c
children d5b8f4dc1622
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * gaim - Jabber Protocol Plugin
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 *
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 *
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 */
9030
7ab20f829190 [gaim-migrate @ 9806]
Mark Doliner <mark@kingant.net>
parents: 8838
diff changeset
21
7ab20f829190 [gaim-migrate @ 9806]
Mark Doliner <mark@kingant.net>
parents: 8838
diff changeset
22 #include "blist.h"
7ab20f829190 [gaim-migrate @ 9806]
Mark Doliner <mark@kingant.net>
parents: 8838
diff changeset
23
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "internal.h"
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents: 10112
diff changeset
25 #include "cipher.h"
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 #include "debug.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "ft.h"
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents: 8135
diff changeset
28 #include "network.h"
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "notify.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 #include "buddy.h"
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
32 #include "disco.h"
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 #include "jabber.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 #include "iq.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 #include "si.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 #include "si.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
39 struct bytestreams_streamhost {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
40 char *jid;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
41 char *host;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
42 int port;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
43 };
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
44
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
45 typedef struct _JabberSIXfer {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
46 JabberStream *js;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
47
10940
999555fbbbd9 [gaim-migrate @ 12730]
Nathan Walp <nwalp@pidgin.im>
parents: 10939
diff changeset
48 gboolean accepted;
999555fbbbd9 [gaim-migrate @ 12730]
Nathan Walp <nwalp@pidgin.im>
parents: 10939
diff changeset
49
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
50 char *stream_id;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
51 char *iq_id;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
52
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
53 enum {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
54 STREAM_METHOD_UNKNOWN = 0,
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
55 STREAM_METHOD_BYTESTREAMS = 2 << 1,
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
56 STREAM_METHOD_IBB = 2 << 2,
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
57 STREAM_METHOD_UNSUPPORTED = 2 << 31
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
58 } stream_method;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
59
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
60 GList *streamhosts;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
61 GaimProxyInfo *gpi;
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
62
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
63 char *rxqueue;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
64 size_t rxlen;
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
65 } JabberSIXfer;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
66
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
67 static GaimXfer*
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
68 jabber_si_xfer_find(JabberStream *js, const char *sid, const char *from)
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 GList *xfers;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
72 if(!sid || !from)
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 return NULL;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 for(xfers = js->file_transfers; xfers; xfers = xfers->next) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76 GaimXfer *xfer = xfers->data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 JabberSIXfer *jsx = xfer->data;
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
78 if(jsx->stream_id && xfer->who &&
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
79 !strcmp(jsx->stream_id, sid) && !strcmp(xfer->who, from))
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 return xfer;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 return NULL;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
86
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
87 static void jabber_si_bytestreams_attempt_connect(GaimXfer *xfer);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
88
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
89 static void jabber_si_bytestreams_connect_cb(gpointer data, gint source, GaimInputCondition cond)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
90 {
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 GaimXfer *xfer = data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 JabberSIXfer *jsx = xfer->data;
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
93 JabberIq *iq;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
94 xmlnode *query, *su;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
95 struct bytestreams_streamhost *streamhost = jsx->streamhosts->data;
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
97 gaim_proxy_info_destroy(jsx->gpi);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
98
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
99 if(source < 0) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
100 jsx->streamhosts = g_list_remove(jsx->streamhosts, streamhost);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
101 g_free(streamhost->jid);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
102 g_free(streamhost->host);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
103 g_free(streamhost);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
104 jabber_si_bytestreams_attempt_connect(xfer);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
105 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
106 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
107
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
108 iq = jabber_iq_new_query(jsx->js, JABBER_IQ_RESULT, "http://jabber.org/protocol/bytestreams");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
109 xmlnode_set_attrib(iq->node, "to", xfer->who);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
110 jabber_iq_set_id(iq, jsx->iq_id);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
111 query = xmlnode_get_child(iq->node, "query");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
112 su = xmlnode_new_child(query, "streamhost-used");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
113 xmlnode_set_attrib(su, "jid", streamhost->jid);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
114
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
115 jabber_iq_send(iq);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
116
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
117 gaim_xfer_start(xfer, source, NULL, -1);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
118 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
119
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
120 static void jabber_si_bytestreams_attempt_connect(GaimXfer *xfer)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
121 {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
122 JabberSIXfer *jsx = xfer->data;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
123 struct bytestreams_streamhost *streamhost;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
124 char *dstaddr, *p;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
125 int i;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
126 unsigned char hashval[20];
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
127
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
128 if(!jsx->streamhosts) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
129 JabberIq *iq = jabber_iq_new(jsx->js, JABBER_IQ_ERROR);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
130 xmlnode *error, *condition;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
131
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
132 if(jsx->iq_id)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
133 jabber_iq_set_id(iq, jsx->iq_id);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
134
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
135 xmlnode_set_attrib(iq->node, "to", xfer->who);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
136 error = xmlnode_new_child(iq->node, "error");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
137 xmlnode_set_attrib(error, "code", "404");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
138 xmlnode_set_attrib(error, "type", "cancel");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
139 condition = xmlnode_new_child(error, "condition");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
140 xmlnode_set_attrib(condition, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
141 xmlnode_new_child(condition, "item-not-found");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
142
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
143 jabber_iq_send(iq);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
144
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
145 gaim_xfer_cancel_local(xfer);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
146
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
147 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
148 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
149
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
150 streamhost = jsx->streamhosts->data;
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
152 jsx->gpi = gaim_proxy_info_new();
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
153 gaim_proxy_info_set_type(jsx->gpi, GAIM_PROXY_SOCKS5);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
154 gaim_proxy_info_set_host(jsx->gpi, streamhost->host);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
155 gaim_proxy_info_set_port(jsx->gpi, streamhost->port);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
156
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
157 dstaddr = g_strdup_printf("%s%s%s@%s/%s", jsx->stream_id, xfer->who, jsx->js->user->node,
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
158 jsx->js->user->domain, jsx->js->user->resource);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents: 10112
diff changeset
159
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 10940
diff changeset
160 gaim_cipher_digest_region("sha1", (guchar *)dstaddr, strlen(dstaddr),
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
161 sizeof(hashval), hashval, NULL);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
162 g_free(dstaddr);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
163 dstaddr = g_malloc(41);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
164 p = dstaddr;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
165 for(i=0; i<20; i++, p+=2)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
166 snprintf(p, 3, "%02x", hashval[i]);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
167
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
168 gaim_proxy_connect_socks5(jsx->gpi, dstaddr, 0, jabber_si_bytestreams_connect_cb, xfer);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
169 g_free(dstaddr);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
170 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
171
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
172 void jabber_bytestreams_parse(JabberStream *js, xmlnode *packet)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
173 {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
174 GaimXfer *xfer;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
175 JabberSIXfer *jsx;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
176 xmlnode *query, *streamhost;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
177 const char *sid, *from;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
178
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
179 if(!(from = xmlnode_get_attrib(packet, "from")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
180 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
181
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
182 if(!(query = xmlnode_get_child(packet, "query")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
183 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
184
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
185 if(!(sid = xmlnode_get_attrib(query, "sid")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
186 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
187
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
188 if(!(xfer = jabber_si_xfer_find(js, sid, from)))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
189 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
190
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
191 jsx = xfer->data;
10940
999555fbbbd9 [gaim-migrate @ 12730]
Nathan Walp <nwalp@pidgin.im>
parents: 10939
diff changeset
192
999555fbbbd9 [gaim-migrate @ 12730]
Nathan Walp <nwalp@pidgin.im>
parents: 10939
diff changeset
193 if(!jsx->accepted)
999555fbbbd9 [gaim-migrate @ 12730]
Nathan Walp <nwalp@pidgin.im>
parents: 10939
diff changeset
194 return;
999555fbbbd9 [gaim-migrate @ 12730]
Nathan Walp <nwalp@pidgin.im>
parents: 10939
diff changeset
195
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
196 if(jsx->iq_id)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
197 g_free(jsx->iq_id);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
198 jsx->iq_id = g_strdup(xmlnode_get_attrib(packet, "id"));
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
199
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
200 for(streamhost = xmlnode_get_child(query, "streamhost"); streamhost;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
201 streamhost = xmlnode_get_next_twin(streamhost)) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
202 const char *jid, *host, *port;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
203 int portnum;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
204
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
205 if((jid = xmlnode_get_attrib(streamhost, "jid")) &&
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
206 (host = xmlnode_get_attrib(streamhost, "host")) &&
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
207 (port = xmlnode_get_attrib(streamhost, "port")) &&
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
208 (portnum = atoi(port))) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
209 struct bytestreams_streamhost *sh = g_new0(struct bytestreams_streamhost, 1);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
210 sh->jid = g_strdup(jid);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
211 sh->host = g_strdup(host);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
212 sh->port = portnum;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
213 jsx->streamhosts = g_list_append(jsx->streamhosts, sh);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
214 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
215 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
216
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
217 jabber_si_bytestreams_attempt_connect(xfer);
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
220 static void
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
221 jabber_si_xfer_bytestreams_send_read_again_cb(gpointer data, gint source,
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
222 GaimInputCondition cond)
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
223 {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
224 GaimXfer *xfer = data;
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
225 JabberSIXfer *jsx = xfer->data;
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
226 int i;
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
227 char buffer[256];
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
228 int len;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
229 char *dstaddr, *p;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
230 unsigned char hashval[20];
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
231 const char *host;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
232
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
233 gaim_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_again_cb\n");
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
234
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
235 if(jsx->rxlen < 5) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
236 gaim_debug_info("jabber", "reading the first 5 bytes\n");
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
237 if((len = read(source, buffer, 5 - jsx->rxlen)) <= 0) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
238 gaim_input_remove(xfer->watcher);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
239 xfer->watcher = 0;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
240 close(source);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
241 gaim_xfer_cancel_remote(xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
242 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
243 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
244 jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
245 memcpy(jsx->rxqueue + jsx->rxlen, buffer, len);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
246 jsx->rxlen += len;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
247 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
248 } else if(jsx->rxqueue[0] != 0x05 || jsx->rxqueue[1] != 0x01 ||
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
249 jsx->rxqueue[3] != 0x03) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
250 gaim_debug_info("jabber", "invalid socks5 stuff\n");
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
251 gaim_input_remove(xfer->watcher);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
252 xfer->watcher = 0;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
253 close(source);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
254 gaim_xfer_cancel_remote(xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
255 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
256 } else if(jsx->rxlen - 5 < jsx->rxqueue[4] + 2) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
257 gaim_debug_info("jabber", "reading umpteen more bytes\n");
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
258 if((len = read(source, buffer, jsx->rxqueue[4] + 5 + 2 - jsx->rxlen)) <= 0) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
259 gaim_input_remove(xfer->watcher);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
260 xfer->watcher = 0;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
261 close(source);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
262 gaim_xfer_cancel_remote(xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
263 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
264 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
265 jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
266 memcpy(jsx->rxqueue + jsx->rxlen, buffer, len);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
267 jsx->rxlen += len;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
268 }
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
269
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
270 if(jsx->rxlen - 5 < jsx->rxqueue[4] + 2)
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
271 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
272
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
273 gaim_input_remove(xfer->watcher);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
274 xfer->watcher = 0;
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
275
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
276 dstaddr = g_strdup_printf("%s%s@%s/%s%s", jsx->stream_id,
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
277 jsx->js->user->node, jsx->js->user->domain,
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
278 jsx->js->user->resource, xfer->who);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents: 10112
diff changeset
279
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 10940
diff changeset
280 gaim_cipher_digest_region("sha1", (guchar *)dstaddr, strlen(dstaddr),
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
281 sizeof(hashval), hashval, NULL);
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
282 g_free(dstaddr);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
283 dstaddr = g_malloc(41);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
284 p = dstaddr;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
285 for(i=0; i<20; i++, p+=2)
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
286 snprintf(p, 3, "%02x", hashval[i]);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
287
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
288 if(jsx->rxqueue[4] != 40 || strncmp(dstaddr, jsx->rxqueue+5, 40) ||
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
289 jsx->rxqueue[45] != 0x00 || jsx->rxqueue[46] != 0x00) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
290 gaim_debug_error("jabber", "someone connected with the wrong info!\n");
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
291 close(source);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
292 gaim_xfer_cancel_remote(xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
293 return;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
294 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
295
8838
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8343
diff changeset
296 host = gaim_network_get_my_ip(jsx->js->fd);
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
297
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
298 buffer[0] = 0x05;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
299 buffer[1] = 0x00;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
300 buffer[2] = 0x00;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
301 buffer[3] = 0x03;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
302 buffer[4] = strlen(host);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
303 memcpy(buffer + 5, host, strlen(host));
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
304 buffer[5+strlen(host)] = 0x00;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
305 buffer[6+strlen(host)] = 0x00;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
306
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
307 write(source, buffer, strlen(host)+7);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
308
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
309 gaim_xfer_start(xfer, source, NULL, -1);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
310 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
311
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
312 static void
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
313 jabber_si_xfer_bytestreams_send_read_cb(gpointer data, gint source,
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
314 GaimInputCondition cond)
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
315 {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
316 GaimXfer *xfer = data;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
317 JabberSIXfer *jsx = xfer->data;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
318 int i;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
319 int len;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
320 char buffer[256];
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
321
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
322 gaim_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_cb\n");
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
323
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
324 xfer->fd = source;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
325
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
326 if(jsx->rxlen < 2) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
327 gaim_debug_info("jabber", "reading those first two bytes\n");
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
328 if((len = read(source, buffer, 2 - jsx->rxlen)) <= 0) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
329 gaim_input_remove(xfer->watcher);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
330 xfer->watcher = 0;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
331 close(source);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
332 gaim_xfer_cancel_remote(xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
333 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
334 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
335 jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
336 memcpy(jsx->rxqueue + jsx->rxlen, buffer, len);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
337 jsx->rxlen += len;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
338 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
339 } else if(jsx->rxlen - 2 < jsx->rxqueue[1]) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
340 gaim_debug_info("jabber", "reading the next umpteen bytes\n");
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
341 if((len = read(source, buffer, jsx->rxqueue[1] + 2 - jsx->rxlen)) <= 0) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
342 gaim_input_remove(xfer->watcher);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
343 xfer->watcher = 0;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
344 close(source);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
345 gaim_xfer_cancel_remote(xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
346 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
347 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
348 jsx->rxqueue = g_realloc(jsx->rxqueue, len + jsx->rxlen);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
349 memcpy(jsx->rxqueue + jsx->rxlen, buffer, len);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
350 jsx->rxlen += len;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
351 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
352
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
353 if(jsx->rxlen -2 < jsx->rxqueue[1])
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
354 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
355
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
356 gaim_input_remove(xfer->watcher);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
357 xfer->watcher = 0;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
358
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
359
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
360 gaim_debug_info("jabber", "checking to make sure we're socks FIVE\n");
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
361
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
362 if(jsx->rxqueue[0] != 0x05) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
363 close(source);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
364 gaim_xfer_cancel_remote(xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
365 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
366 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
367
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
368 gaim_debug_info("jabber", "going to test %hhu different methods\n", jsx->rxqueue[1]);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
369
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
370 for(i=0; i<jsx->rxqueue[1]; i++) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
371
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
372 gaim_debug_info("jabber", "testing %hhu\n", jsx->rxqueue[i+2]);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
373 if(jsx->rxqueue[i+2] == 0x00) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
374 buffer[0] = 0x05;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
375 buffer[1] = 0x00;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
376 write(source, buffer, 2);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
377 xfer->watcher = gaim_input_add(source, GAIM_INPUT_READ,
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
378 jabber_si_xfer_bytestreams_send_read_again_cb, xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
379 g_free(jsx->rxqueue);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
380 jsx->rxqueue = NULL;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
381 jsx->rxlen = 0;
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
382 return;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
383 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
384 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
385
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
386 buffer[0] = 0x05;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
387 buffer[1] = 0xFF;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
388 write(source, buffer, 2);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
389 close(source);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
390 g_free(jsx->rxqueue);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
391 jsx->rxqueue = NULL;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
392 jsx->rxlen = 0;
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
393 gaim_xfer_cancel_remote(xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
394 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
395
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
396 static void
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
397 jabber_si_xfer_bytestreams_send_connected_cb(gpointer data, gint source,
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
398 GaimInputCondition cond)
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
399 {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
400 GaimXfer *xfer = data;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
401 int acceptfd;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
402
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
403 gaim_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_connected_cb\n");
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
404
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
405 if((acceptfd = accept(source, NULL, 0)) == -1) {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
406 gaim_debug_warning("jabber", "accept: %s\n", strerror(errno));
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
407 return;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
408 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
409
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
410 gaim_input_remove(xfer->watcher);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
411 close(source);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
412
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
413 xfer->watcher = gaim_input_add(acceptfd, GAIM_INPUT_READ,
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
414 jabber_si_xfer_bytestreams_send_read_cb, xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
415 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
416
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
417
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
418 static void
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
419 jabber_si_xfer_bytestreams_send_init(GaimXfer *xfer)
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
420 {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
421 JabberSIXfer *jsx = xfer->data;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
422 JabberIq *iq;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
423 xmlnode *query, *streamhost;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
424 char *jid, *port;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
425 int fd;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
426
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
427 iq = jabber_iq_new_query(jsx->js, JABBER_IQ_SET,
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
428 "http://jabber.org/protocol/bytestreams");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
429 xmlnode_set_attrib(iq->node, "to", xfer->who);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
430 query = xmlnode_get_child(iq->node, "query");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
431
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
432 xmlnode_set_attrib(query, "sid", jsx->stream_id);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
433
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
434 streamhost = xmlnode_new_child(query, "streamhost");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
435 jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node, jsx->js->user->domain, jsx->js->user->resource);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
436 xmlnode_set_attrib(streamhost, "jid", jid);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
437 g_free(jid);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
438
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
439 if((fd = gaim_network_listen_range(0, 0)) < 0) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
440 /* XXX: couldn't open a port, we're fscked */
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
441 return;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
442 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
443
8838
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8343
diff changeset
444 xmlnode_set_attrib(streamhost, "host", gaim_network_get_my_ip(jsx->js->fd));
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
445 xfer->local_port = gaim_network_get_port_from_fd(fd);
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
446 port = g_strdup_printf("%hu", xfer->local_port);
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
447 xmlnode_set_attrib(streamhost, "port", port);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
448 g_free(port);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
449
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
450 xfer->watcher = gaim_input_add(fd, GAIM_INPUT_READ,
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
451 jabber_si_xfer_bytestreams_send_connected_cb, xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
452
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
453 /* XXX: insert proxies here */
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
454
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
455 /* XXX: callback to find out which streamhost they used, or see if they
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
456 * screwed it up */
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
457 jabber_iq_send(iq);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
458 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
459
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
460 static void jabber_si_xfer_send_method_cb(JabberStream *js, xmlnode *packet,
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
461 gpointer data)
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
462 {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
463 GaimXfer *xfer = data;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
464 xmlnode *si, *feature, *x, *field, *value;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
465
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
466 if(!(si = xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si"))) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
467 gaim_xfer_cancel_remote(xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
468 return;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
469 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
470
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
471 if(!(feature = xmlnode_get_child_with_namespace(si, "feature", "http://jabber.org/protocol/feature-neg"))) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
472 gaim_xfer_cancel_remote(xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
473 return;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
474 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
475
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
476 if(!(x = xmlnode_get_child_with_namespace(feature, "x", "jabber:x:data"))) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
477 gaim_xfer_cancel_remote(xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
478 return;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
479 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
480
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
481 for(field = xmlnode_get_child(x, "field"); field; field = xmlnode_get_next_twin(field)) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
482 const char *var = xmlnode_get_attrib(field, "var");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
483
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
484 if(var && !strcmp(var, "stream-method")) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
485 if((value = xmlnode_get_child(field, "value"))) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
486 char *val = xmlnode_get_data(value);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
487 if(val && !strcmp(val, "http://jabber.org/protocol/bytestreams")) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
488 jabber_si_xfer_bytestreams_send_init(xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
489 g_free(val);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
490 return;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
491 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
492 g_free(val);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
493 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
494 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
495 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
496 gaim_xfer_cancel_remote(xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
497 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
498
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
499 static void jabber_si_xfer_send_request(GaimXfer *xfer)
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
500 {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
501 JabberSIXfer *jsx = xfer->data;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
502 JabberIq *iq;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
503 xmlnode *si, *file, *feature, *x, *field, *option, *value;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
504 char buf[32];
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
505
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
506 xfer->filename = g_path_get_basename(xfer->local_filename);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
507
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
508 iq = jabber_iq_new(jsx->js, JABBER_IQ_SET);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
509 xmlnode_set_attrib(iq->node, "to", xfer->who);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
510 si = xmlnode_new_child(iq->node, "si");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
511 xmlnode_set_attrib(si, "xmlns", "http://jabber.org/protocol/si");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
512 jsx->stream_id = jabber_get_next_id(jsx->js);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
513 xmlnode_set_attrib(si, "id", jsx->stream_id);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
514 xmlnode_set_attrib(si, "profile",
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
515 "http://jabber.org/protocol/si/profile/file-transfer");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
516
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
517 file = xmlnode_new_child(si, "file");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
518 xmlnode_set_attrib(file, "xmlns",
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
519 "http://jabber.org/protocol/si/profile/file-transfer");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
520 xmlnode_set_attrib(file, "name", xfer->filename);
11656
f9c5480ad0ce [gaim-migrate @ 13940]
Richard Laager <rlaager@wiktel.com>
parents: 11183
diff changeset
521 g_snprintf(buf, sizeof(buf), "%" G_GSIZE_FORMAT, xfer->size);
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
522 xmlnode_set_attrib(file, "size", buf);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
523 /* maybe later we'll do hash and date attribs */
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
524
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
525 feature = xmlnode_new_child(si, "feature");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
526 xmlnode_set_attrib(feature, "xmlns",
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
527 "http://jabber.org/protocol/feature-neg");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
528 x = xmlnode_new_child(feature, "x");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
529 xmlnode_set_attrib(x, "xmlns", "jabber:x:data");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
530 xmlnode_set_attrib(x, "type", "form");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
531 field = xmlnode_new_child(x, "field");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
532 xmlnode_set_attrib(field, "var", "stream-method");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
533 xmlnode_set_attrib(field, "type", "list-single");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
534 option = xmlnode_new_child(field, "option");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
535 value = xmlnode_new_child(option, "value");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
536 xmlnode_insert_data(value, "http://jabber.org/protocol/bytestreams",
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
537 -1);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
538 /*
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
539 option = xmlnode_new_child(field, "option");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
540 value = xmlnode_new_child(option, "value");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
541 xmlnode_insert_data(value, "http://jabber.org/protocol/ibb", -1);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
542 */
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
543
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
544 jabber_iq_set_callback(iq, jabber_si_xfer_send_method_cb, xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
545
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
546 jabber_iq_send(iq);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
547 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
548
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
549 static void jabber_si_xfer_free(GaimXfer *xfer)
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
550 {
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
551 JabberSIXfer *jsx = xfer->data;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
552 JabberStream *js = jsx->js;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
553
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
554 js->file_transfers = g_list_remove(js->file_transfers, xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
555
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
556 g_free(jsx->stream_id);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
557 g_free(jsx->iq_id);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
558 /* XXX: free other stuff */
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
559 g_free(jsx);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
560 xfer->data = NULL;
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
561 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
562
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
563 static void jabber_si_xfer_cancel_send(GaimXfer *xfer)
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
564 {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
565 jabber_si_xfer_free(xfer);
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
566 gaim_debug(GAIM_DEBUG_INFO, "jabber", "in jabber_si_xfer_cancel_send\n");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
567 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
568
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
569
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
570 static void jabber_si_xfer_cancel_recv(GaimXfer *xfer)
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
571 {
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
572 jabber_si_xfer_free(xfer);
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
573 gaim_debug(GAIM_DEBUG_INFO, "jabber", "in jabber_si_xfer_cancel_recv\n");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
574 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
575
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
576
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
577 static void jabber_si_xfer_end(GaimXfer *xfer)
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
578 {
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
579 jabber_si_xfer_free(xfer);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
580 }
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
581
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
582
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
583 static void jabber_si_xfer_send_disco_cb(JabberStream *js, const char *who,
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
584 JabberCapabilities capabilities, gpointer data)
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
585 {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
586 GaimXfer *xfer = data;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
587
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
588 if(capabilities & JABBER_CAP_SI_FILE_XFER) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
589 jabber_si_xfer_send_request(xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
590 } else {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
591 char *msg = g_strdup_printf(_("Unable to send file to %s, user does not support file transfers"), who);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
592 gaim_notify_error(js->gc, _("File Send Failed"),
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
593 _("File Send Failed"), msg);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
594 g_free(msg);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
595 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
596 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
597
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
598 static void jabber_si_xfer_init(GaimXfer *xfer)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
599 {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
600 JabberSIXfer *jsx = xfer->data;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
601 JabberIq *iq;
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
602 if(gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
603 JabberBuddy *jb;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
604 JabberBuddyResource *jbr = NULL;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
605
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
606 jb = jabber_buddy_find(jsx->js, xfer->who, TRUE);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
607 /* XXX */
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
608 if(!jb)
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
609 return;
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
610
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
611 /* XXX: for now, send to the first resource available */
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
612 if(g_list_length(jb->resources) >= 1) {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
613 char *who;
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
614 jbr = jabber_buddy_find_resource(jb, NULL);
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
615 who = g_strdup_printf("%s/%s", xfer->who, jbr->name);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
616 g_free(xfer->who);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
617 xfer->who = who;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
618 jabber_disco_info_do(jsx->js, who,
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
619 jabber_si_xfer_send_disco_cb, xfer);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
620 } else {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
621 return; /* XXX: ick */
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
622 }
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
623 } else {
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
624 xmlnode *si, *feature, *x, *field, *value;
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
625
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
626 iq = jabber_iq_new(jsx->js, JABBER_IQ_RESULT);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
627 xmlnode_set_attrib(iq->node, "to", xfer->who);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
628 if(jsx->iq_id)
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
629 jabber_iq_set_id(iq, jsx->iq_id);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
630
10940
999555fbbbd9 [gaim-migrate @ 12730]
Nathan Walp <nwalp@pidgin.im>
parents: 10939
diff changeset
631 jsx->accepted = TRUE;
999555fbbbd9 [gaim-migrate @ 12730]
Nathan Walp <nwalp@pidgin.im>
parents: 10939
diff changeset
632
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
633 si = xmlnode_new_child(iq->node, "si");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
634 xmlnode_set_attrib(si, "xmlns", "http://jabber.org/protocol/si");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
635
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
636 feature = xmlnode_new_child(si, "feature");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
637 xmlnode_set_attrib(feature, "xmlns", "http://jabber.org/protocol/feature-neg");
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
638
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
639 x = xmlnode_new_child(feature, "x");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
640 xmlnode_set_attrib(x, "xmlns", "jabber:x:data");
8343
46df38515dc7 [gaim-migrate @ 9067]
Nathan Walp <nwalp@pidgin.im>
parents: 8316
diff changeset
641 xmlnode_set_attrib(x, "type", "submit");
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
642
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
643 field = xmlnode_new_child(x, "field");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
644 xmlnode_set_attrib(field, "var", "stream-method");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
645
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
646 value = xmlnode_new_child(field, "value");
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
647 if(jsx->stream_method & STREAM_METHOD_BYTESTREAMS)
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
648 xmlnode_insert_data(value, "http://jabber.org/protocol/bytestreams", -1);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
649 /*
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
650 else if(jsx->stream_method & STREAM_METHOD_IBB)
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
651 xmlnode_insert_data(value, "http://jabber.org/protocol/ibb", -1);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
652 */
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
653
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
654 jabber_iq_send(iq);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
655 }
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
656 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
657
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
658 GaimXfer *jabber_si_new_xfer(GaimConnection *gc, const char *who)
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
659 {
9030
7ab20f829190 [gaim-migrate @ 9806]
Mark Doliner <mark@kingant.net>
parents: 8838
diff changeset
660 JabberStream *js;
7ab20f829190 [gaim-migrate @ 9806]
Mark Doliner <mark@kingant.net>
parents: 8838
diff changeset
661
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
662 GaimXfer *xfer;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
663 JabberSIXfer *jsx;
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
664
9030
7ab20f829190 [gaim-migrate @ 9806]
Mark Doliner <mark@kingant.net>
parents: 8838
diff changeset
665 js = gc->proto_data;
7ab20f829190 [gaim-migrate @ 9806]
Mark Doliner <mark@kingant.net>
parents: 8838
diff changeset
666
9466
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9030
diff changeset
667 xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
668
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
669 xfer->data = jsx = g_new0(JabberSIXfer, 1);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
670 jsx->js = js;
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
671
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
672 gaim_xfer_set_init_fnc(xfer, jabber_si_xfer_init);
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
673 gaim_xfer_set_cancel_send_fnc(xfer, jabber_si_xfer_cancel_send);
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
674 gaim_xfer_set_end_fnc(xfer, jabber_si_xfer_end);
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
675
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
676 js->file_transfers = g_list_append(js->file_transfers, xfer);
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
677
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
678 return xfer;
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
679 }
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
680
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
681 void jabber_si_xfer_send(GaimConnection *gc, const char *who, const char *file)
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
682 {
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
683 JabberStream *js;
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
684
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
685 GaimXfer *xfer;
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
686
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
687 js = gc->proto_data;
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
688
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
689 if(!gaim_find_buddy(gc->account, who) || !jabber_buddy_find(js, who, FALSE))
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
690 return;
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
691
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
692 xfer = jabber_si_new_xfer(gc, who);
8312
ba12d8b12ab0 [gaim-migrate @ 9036]
Nathan Walp <nwalp@pidgin.im>
parents: 8262
diff changeset
693
9466
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9030
diff changeset
694 if (file)
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9030
diff changeset
695 gaim_xfer_request_accepted(xfer, file);
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9030
diff changeset
696 else
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9030
diff changeset
697 gaim_xfer_request(xfer);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
698 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
699
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
700 void jabber_si_parse(JabberStream *js, xmlnode *packet)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
701 {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
702 JabberSIXfer *jsx;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
703 GaimXfer *xfer;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
704 xmlnode *si, *file, *feature, *x, *field, *option, *value;
10939
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
705 const char *stream_id, *filename, *filesize_c, *profile, *from;
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
706 size_t filesize = 0;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
707
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
708 if(!(si = xmlnode_get_child(packet, "si")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
709 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
710
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
711 if(!(profile = xmlnode_get_attrib(si, "profile")) ||
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
712 strcmp(profile, "http://jabber.org/protocol/si/profile/file-transfer"))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
713 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
714
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
715 if(!(stream_id = xmlnode_get_attrib(si, "id")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
716 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
717
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
718 if(!(file = xmlnode_get_child(si, "file")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
719 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
720
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
721 if(!(filename = xmlnode_get_attrib(file, "name")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
722 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
723
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
724 if((filesize_c = xmlnode_get_attrib(file, "size")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
725 filesize = atoi(filesize_c);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
726
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
727 if(!(feature = xmlnode_get_child(si, "feature")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
728 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
729
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
730 if(!(x = xmlnode_get_child_with_namespace(feature, "x", "jabber:x:data")))
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
731 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
732
10939
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
733 if(!(from = xmlnode_get_attrib(packet, "from")))
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
734 return;
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
735
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
736 /* if they've already sent us this file transfer with the same damn id
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
737 * then we're gonna ignore it, until I think of something better to do
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
738 * with it */
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
739 if((xfer = jabber_si_xfer_find(js, stream_id, from)))
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
740 return;
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
741
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
742 jsx = g_new0(JabberSIXfer, 1);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
743
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
744 for(field = xmlnode_get_child(x, "field"); field; field = xmlnode_get_next_twin(field)) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
745 const char *var = xmlnode_get_attrib(field, "var");
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
746 if(var && !strcmp(var, "stream-method")) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
747 for(option = xmlnode_get_child(field, "option"); option;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
748 option = xmlnode_get_next_twin(option)) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
749 if((value = xmlnode_get_child(option, "value"))) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
750 char *val;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
751 if((val = xmlnode_get_data(value))) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
752 if(!strcmp(val, "http://jabber.org/protocol/bytestreams")) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
753 jsx->stream_method |= STREAM_METHOD_BYTESTREAMS;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
754 /*
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
755 } else if(!strcmp(val, "http://jabber.org/protocol/ibb")) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
756 jsx->stream_method |= STREAM_METHOD_IBB;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
757 */
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
758 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
759 g_free(val);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
760 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
761 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
762 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
763 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
764 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
765
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
766 if(jsx->stream_method == STREAM_METHOD_UNKNOWN) {
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
767 g_free(jsx);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
768 return;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
769 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
770
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
771 jsx->js = js;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
772 jsx->stream_id = g_strdup(stream_id);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
773 jsx->iq_id = g_strdup(xmlnode_get_attrib(packet, "id"));
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
774
10939
45598096d197 [gaim-migrate @ 12729]
Nathan Walp <nwalp@pidgin.im>
parents: 10687
diff changeset
775 xfer = gaim_xfer_new(js->gc->account, GAIM_XFER_RECEIVE, from);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
776 xfer->data = jsx;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
777
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
778 gaim_xfer_set_filename(xfer, filename);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
779 if(filesize > 0)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
780 gaim_xfer_set_size(xfer, filesize);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
781
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
782 gaim_xfer_set_init_fnc(xfer, jabber_si_xfer_init);
8316
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
783 gaim_xfer_set_cancel_recv_fnc(xfer, jabber_si_xfer_cancel_recv);
cf84056fed27 [gaim-migrate @ 9040]
Nathan Walp <nwalp@pidgin.im>
parents: 8312
diff changeset
784 gaim_xfer_set_end_fnc(xfer, jabber_si_xfer_end);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
785
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
786 js->file_transfers = g_list_append(js->file_transfers, xfer);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
787
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
788 gaim_xfer_request(xfer);
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
789 }
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8231
diff changeset
790
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
791