annotate src/protocols/jabber/si.c @ 7616:a4acf41898c1

[gaim-migrate @ 8240] wouldn't it be cool if logging just worked? If it didn't leak, and didn't crash, and sort-by-log-size worked as an added bonus? i should have gotten a bounty declared on this first ;-) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 23 Nov 2003 22:55:41 +0000
parents b250288fa948
children 8f4ce853e685
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 */
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22 #include "debug.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "ft.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "notify.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "util.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "buddy.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 #include "jabber.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "iq.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 #include "si.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 #include "si.h"
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 static GaimXfer *jabber_si_xfer_find_by_id(JabberStream *js, const char *id)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 GList *xfers;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 if(!id)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 return NULL;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 for(xfers = js->file_transfers; xfers; xfers = xfers->next) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 GaimXfer *xfer = xfers->data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 JabberSIXfer *jsx = xfer->data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 if(!strcmp(jsx->id, id))
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 return xfer;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 return NULL;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 static void
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 jabber_si_xfer_ibb_start(JabberStream *js, xmlnode *packet, gpointer data) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 GaimXfer *xfer = data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 JabberSIXfer *jsx = xfer->data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 /* Make sure we didn't get an error back */
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 /* XXX: OK, here we need to set up a g_idle thing to send messages
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 * until our eyes bleed, but do it without interfering with normal
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 * gaim operations. When we're done, we have to send a <close> like
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 * we sent the <open> to start this damn thing. If we're really
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 * fortunate, Exodus or someone else will implement something to test
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64 * against soon */
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 void jabber_si_parse(JabberStream *js, xmlnode *packet)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 GaimXfer *xfer;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 JabberSIXfer *jsx;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 xmlnode *si, *feature, *x, *field, *value;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 si = xmlnode_get_child(packet, "si");
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 xfer = jabber_si_xfer_find_by_id(js, xmlnode_get_attrib(si, "id"));
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 if(!xfer)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 return;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 jsx = xfer->data;
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 if(!(feature = xmlnode_get_child(si, "feature")))
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 return;
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 for(x = feature->child; x; x = x->next) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 const char *xmlns;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 if(x->type != NODE_TYPE_TAG)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 continue;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 if(!(xmlns = xmlnode_get_attrib(x, "xmlns")))
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 continue;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 if(strcmp(xmlns, "jabber:x:data"))
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 continue;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 for(field = x->child; field; field = field->next) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94 const char *var;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 if(field->type != NODE_TYPE_TAG)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96 continue;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 if(!(var = xmlnode_get_attrib(field, "var")))
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 continue;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 if(!strcmp(var, "stream-method")) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 if((value = xmlnode_get_child(field, "value"))) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 char *val_data = xmlnode_get_data(value);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 if(!val_data)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 jsx->stream_method = STREAM_METHOD_UNKNOWN;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 else if(!strcmp(val_data,
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 "http://jabber.org/protocol/bytestreams"))
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 jsx->stream_method = STREAM_METHOD_BYTESTREAMS;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 else if(!strcmp(val_data, "http://jabber.org/protocol/ibb"))
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 jsx->stream_method = STREAM_METHOD_IBB;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109 else
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 jsx->stream_method = STREAM_METHOD_UNSUPPORTED;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111 g_free(val_data);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116 if(jsx->stream_method == STREAM_METHOD_UNKNOWN) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 /* XXX */
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 } else if(jsx->stream_method == STREAM_METHOD_UNSUPPORTED) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 /* XXX */
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 } else if(jsx->stream_method == STREAM_METHOD_BYTESTREAMS) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 /* XXX: open the port and stuff */
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 char *buf;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 xmlnode *query, *streamhost;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_SET,
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125 "http://jabber.org/protocol/bytestreams");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 buf = g_strdup_printf("%s/%s", xfer->who, jsx->resource);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128 xmlnode_set_attrib(iq->node, "to", buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 g_free(buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 query = xmlnode_get_child(iq->node, "query");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 xmlnode_set_attrib(query, "sid", jsx->id);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
133 streamhost = xmlnode_new_child(query, "streamhost");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134 xmlnode_set_attrib(streamhost, "jid",
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 gaim_account_get_username(js->gc->account));
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 xmlnode_set_attrib(streamhost, "host", xfer->local_ip);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 buf = g_strdup_printf("%d", xfer->local_port);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 xmlnode_set_attrib(streamhost, "port", buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139 g_free(buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140 jabber_iq_send(iq);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 } else if(jsx->stream_method == STREAM_METHOD_IBB) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142 char *buf;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 xmlnode *open;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 buf = g_strdup_printf("%s/%s", xfer->who, jsx->resource);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 xmlnode_set_attrib(iq->node, "to", buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 g_free(buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 open = xmlnode_new_child(iq->node, "open");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 xmlnode_set_attrib(open, "xmlns", "http://jabber.org/protocol/ibb");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 xmlnode_set_attrib(open, "sid", jsx->id);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 jabber_iq_set_callback(iq, jabber_si_xfer_ibb_start, xfer);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 jabber_iq_send(iq);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 static void jabber_si_xfer_send_request(GaimXfer *xfer)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162 JabberSIXfer *jsx = xfer->data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 JabberIq *iq;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 xmlnode *si, *file, *feature, *x, *field, *option, *value;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 char buf[32];
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 char *to;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 xfer->filename = g_path_get_basename(xfer->local_filename);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170 iq = jabber_iq_new(jsx->js, JABBER_IQ_SET);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171 to = g_strdup_printf("%s/%s", xfer->who, jsx->resource);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
172 xmlnode_set_attrib(iq->node, "to", to);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
173 g_free(to);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
174 si = xmlnode_new_child(iq->node, "si");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 xmlnode_set_attrib(si, "xmlns", "http://jabber.org/protocol/si");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176 jsx->id = jabber_get_next_id(jsx->js);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
177 xmlnode_set_attrib(si, "id", jsx->id);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
178 xmlnode_set_attrib(si, "profile",
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
179 "http://jabber.org/protocol/si/profile/file-transfer");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
180
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
181 file = xmlnode_new_child(si, "file");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
182 xmlnode_set_attrib(file, "xmlns",
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
183 "http://jabber.org/protocol/si/profile/file-transfer");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184 xmlnode_set_attrib(file, "name", xfer->filename);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
185 g_snprintf(buf, sizeof(buf), "%d", xfer->size);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186 xmlnode_set_attrib(file, "size", buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
187 /* maybe later we'll do hash and date attribs */
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
188
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
189 feature = xmlnode_new_child(si, "feature");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
190 xmlnode_set_attrib(feature, "xmlns",
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191 "http://jabber.org/protocol/feature-neg");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
192 x = xmlnode_new_child(feature, "x");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
193 xmlnode_set_attrib(x, "xmlns", "jabber:x:data");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
194 xmlnode_set_attrib(x, "type", "form");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195 field = xmlnode_new_child(x, "field");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
196 xmlnode_set_attrib(field, "var", "stream-method");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 xmlnode_set_attrib(field, "type", "list-single");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 option = xmlnode_new_child(field, "option");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199 value = xmlnode_new_child(option, "value");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 xmlnode_insert_data(value, "http://jabber.org/protocol/bytestreams",
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 -1);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202 option = xmlnode_new_child(field, "option");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
203 value = xmlnode_new_child(option, "value");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204 xmlnode_insert_data(value, "http://jabber.org/protocol/ibb", -1);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206 jabber_iq_send(iq);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 void jabber_si_xfer_init(GaimXfer *xfer)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 JabberSIXfer *jsx = xfer->data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 if(gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 JabberBuddy *jb;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 JabberBuddyResource *jbr = NULL;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 GList *resources;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 GList *xfer_resources = NULL;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218 jb = jabber_buddy_find(jsx->js, xfer->who, TRUE);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 if(!jb)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 return;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 for(resources = jb->resources; resources; resources = resources->next) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 jbr = resources->data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224 if(jbr->capabilities & JABBER_CAP_SI_FILE_XFER)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225 xfer_resources = g_list_append(xfer_resources, jbr);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228 if(g_list_length(xfer_resources) == 1) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229 jbr = xfer_resources->data;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230 jsx->resource = g_strdup(jbr->name);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231 jabber_si_xfer_send_request(xfer);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 } else if(g_list_length(xfer_resources) == 0) {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 char *buf = g_strdup_printf(_("Could not send %s to %s, protocol not supported."), xfer->filename, xfer->who);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234 gaim_notify_error(jsx->js->gc, _("File Send Failed"),
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235 _("File Send Failed"), buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 g_free(buf);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 } else {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 /* XXX: ask which resource to send to! */
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 g_list_free(xfer_resources);
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 void jabber_si_xfer_start(GaimXfer *xfer)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 gaim_debug(GAIM_DEBUG_INFO, "jabber", "in jabber_si_xfer_start\n");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 void jabber_si_xfer_end(GaimXfer *xfer)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 gaim_debug(GAIM_DEBUG_INFO, "jabber", "in jabber_si_xfer_end\n");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 void jabber_si_xfer_cancel_send(GaimXfer *xfer)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 gaim_debug(GAIM_DEBUG_INFO, "jabber", "in jabber_si_xfer_cancel_send\n");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 void jabber_si_xfer_cancel_recv(GaimXfer *xfer)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 gaim_debug(GAIM_DEBUG_INFO, "jabber", "in jabber_si_xfer_cancel_recv\n");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 void jabber_si_xfer_ack(GaimXfer *xfer, const char *buffer, size_t size)
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267 {
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 gaim_debug(GAIM_DEBUG_INFO, "jabber", "in jabber_si_xfer_ack\n");
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270