Mon, 02 Mar 2009 06:37:05 +0000
Remove some extra trailing whitespace I noticed after merging mlundblad's
xmpp branches.
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 3 | * |
| 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18443
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7014 | 19 | * |
| 20 | */ | |
| 21 | #include "internal.h" | |
|
18441
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
22 | #include "core.h" |
| 7014 | 23 | #include "debug.h" |
| 24 | #include "prefs.h" | |
| 10941 | 25 | #include "util.h" |
| 7014 | 26 | |
| 7395 | 27 | #include "buddy.h" |
| 8312 | 28 | #include "disco.h" |
| 15225 | 29 | #include "google.h" |
| 7014 | 30 | #include "iq.h" |
| 7170 | 31 | #include "oob.h" |
| 7014 | 32 | #include "roster.h" |
| 7395 | 33 | #include "si.h" |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
34 | #include "ping.h" |
|
17805
5bd417a1c847
Implemented XEP-0050: Ad-Hoc Commands. Note that this XEP requires sending an initial command to the peer, which is not implemented in libpurple itself (since this requires a discovery browser or equivalent).
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
35 | #include "adhoccommands.h" |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
36 | #include "data.h" |
|
24372
830701cec96f
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
37 | #include "ibb.h" |
| 7014 | 38 | |
|
7058
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
39 | #ifdef _WIN32 |
|
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
40 | #include "utsname.h" |
|
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
41 | #endif |
| 7014 | 42 | |
| 14356 | 43 | GHashTable *iq_handlers = NULL; |
| 44 | ||
| 45 | ||
| 7014 | 46 | JabberIq *jabber_iq_new(JabberStream *js, JabberIqType type) |
| 47 | { | |
| 48 | JabberIq *iq; | |
| 49 | ||
| 50 | iq = g_new0(JabberIq, 1); | |
| 51 | ||
| 52 | iq->type = type; | |
| 53 | ||
| 54 | iq->node = xmlnode_new("iq"); | |
| 55 | switch(iq->type) { | |
| 56 | case JABBER_IQ_SET: | |
| 57 | xmlnode_set_attrib(iq->node, "type", "set"); | |
| 58 | break; | |
| 59 | case JABBER_IQ_GET: | |
| 60 | xmlnode_set_attrib(iq->node, "type", "get"); | |
| 61 | break; | |
| 62 | case JABBER_IQ_ERROR: | |
| 63 | xmlnode_set_attrib(iq->node, "type", "error"); | |
| 64 | break; | |
| 65 | case JABBER_IQ_RESULT: | |
| 66 | xmlnode_set_attrib(iq->node, "type", "result"); | |
| 67 | break; | |
| 68 | case JABBER_IQ_NONE: | |
| 69 | /* this shouldn't ever happen */ | |
| 70 | break; | |
| 71 | } | |
| 72 | ||
| 73 | iq->js = js; | |
| 74 | ||
| 75 | if(type == JABBER_IQ_GET || type == JABBER_IQ_SET) { | |
| 76 | iq->id = jabber_get_next_id(js); | |
| 77 | xmlnode_set_attrib(iq->node, "id", iq->id); | |
| 78 | } | |
| 79 | ||
| 80 | return iq; | |
| 81 | } | |
| 82 | ||
| 83 | JabberIq *jabber_iq_new_query(JabberStream *js, JabberIqType type, | |
| 84 | const char *xmlns) | |
| 85 | { | |
| 86 | JabberIq *iq = jabber_iq_new(js, type); | |
| 87 | xmlnode *query; | |
| 88 | ||
| 89 | query = xmlnode_new_child(iq->node, "query"); | |
| 13808 | 90 | xmlnode_set_namespace(query, xmlns); |
| 7014 | 91 | |
| 92 | return iq; | |
| 93 | } | |
| 94 | ||
| 7395 | 95 | typedef struct _JabberCallbackData { |
| 96 | JabberIqCallback *callback; | |
| 97 | gpointer data; | |
| 98 | } JabberCallbackData; | |
| 99 | ||
| 100 | void | |
| 101 | jabber_iq_set_callback(JabberIq *iq, JabberIqCallback *callback, gpointer data) | |
| 7014 | 102 | { |
| 103 | iq->callback = callback; | |
| 7395 | 104 | iq->callback_data = data; |
| 7014 | 105 | } |
| 106 | ||
| 107 | void jabber_iq_set_id(JabberIq *iq, const char *id) | |
| 108 | { | |
|
24520
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
109 | g_free(iq->id); |
| 7014 | 110 | |
| 111 | if(id) { | |
| 112 | xmlnode_set_attrib(iq->node, "id", id); | |
| 113 | iq->id = g_strdup(id); | |
| 114 | } else { | |
| 115 | xmlnode_remove_attrib(iq->node, "id"); | |
| 116 | iq->id = NULL; | |
| 117 | } | |
| 118 | } | |
| 119 | ||
| 120 | void jabber_iq_send(JabberIq *iq) | |
| 121 | { | |
| 7395 | 122 | JabberCallbackData *jcd; |
| 7014 | 123 | g_return_if_fail(iq != NULL); |
| 124 | ||
| 125 | jabber_send(iq->js, iq->node); | |
| 126 | ||
| 7395 | 127 | if(iq->id && iq->callback) { |
| 128 | jcd = g_new0(JabberCallbackData, 1); | |
| 129 | jcd->callback = iq->callback; | |
| 130 | jcd->data = iq->callback_data; | |
| 8312 | 131 | g_hash_table_insert(iq->js->iq_callbacks, g_strdup(iq->id), jcd); |
| 7395 | 132 | } |
| 7014 | 133 | |
| 134 | jabber_iq_free(iq); | |
| 135 | } | |
| 136 | ||
| 137 | void jabber_iq_free(JabberIq *iq) | |
| 138 | { | |
| 139 | g_return_if_fail(iq != NULL); | |
| 140 | ||
| 141 | g_free(iq->id); | |
| 142 | xmlnode_free(iq->node); | |
| 143 | g_free(iq); | |
| 144 | } | |
| 145 | ||
| 8312 | 146 | static void jabber_iq_last_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 147 | { |
| 148 | JabberIq *iq; | |
| 8006 | 149 | const char *type; |
| 7014 | 150 | const char *from; |
| 151 | const char *id; | |
| 152 | xmlnode *query; | |
|
14453
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
153 | char *idle_time; |
| 7014 | 154 | |
| 8006 | 155 | type = xmlnode_get_attrib(packet, "type"); |
| 7014 | 156 | from = xmlnode_get_attrib(packet, "from"); |
| 157 | id = xmlnode_get_attrib(packet, "id"); | |
| 158 | ||
| 8006 | 159 | if(type && !strcmp(type, "get")) { |
| 160 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:last"); | |
| 161 | jabber_iq_set_id(iq, id); | |
| 162 | xmlnode_set_attrib(iq->node, "to", from); | |
| 7014 | 163 | |
| 8006 | 164 | query = xmlnode_get_child(iq->node, "query"); |
| 7014 | 165 | |
|
14453
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
166 | idle_time = g_strdup_printf("%ld", js->idle ? time(NULL) - js->idle : 0); |
|
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
167 | xmlnode_set_attrib(query, "seconds", idle_time); |
|
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
168 | g_free(idle_time); |
| 7401 | 169 | |
| 8006 | 170 | jabber_iq_send(iq); |
| 171 | } | |
| 7014 | 172 | } |
| 173 | ||
| 8312 | 174 | static void jabber_iq_time_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 175 | { |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
176 | const char *type, *from, *id, *xmlns; |
| 7014 | 177 | JabberIq *iq; |
| 178 | xmlnode *query; | |
| 179 | time_t now_t; | |
|
9709
2e73f176cc80
[gaim-migrate @ 10570]
Mark Doliner <markdoliner@pidgin.im>
parents:
8315
diff
changeset
|
180 | struct tm *now; |
|
9722
c1072806bcae
[gaim-migrate @ 10583]
Mark Doliner <markdoliner@pidgin.im>
parents:
9709
diff
changeset
|
181 | |
| 7014 | 182 | time(&now_t); |
|
9709
2e73f176cc80
[gaim-migrate @ 10570]
Mark Doliner <markdoliner@pidgin.im>
parents:
8315
diff
changeset
|
183 | now = localtime(&now_t); |
| 7014 | 184 | |
| 8006 | 185 | type = xmlnode_get_attrib(packet, "type"); |
| 7014 | 186 | from = xmlnode_get_attrib(packet, "from"); |
| 187 | id = xmlnode_get_attrib(packet, "id"); | |
| 188 | ||
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
189 | /* we're gonna throw this away in a moment, but we need it |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
190 | * to get the xmlns, so we can figure out if this is |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
191 | * jabber:iq:time or urn:xmpp:time */ |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
192 | query = xmlnode_get_child(packet, "query"); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
193 | xmlns = xmlnode_get_namespace(query); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
194 | |
| 8006 | 195 | if(type && !strcmp(type, "get")) { |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
196 | xmlnode *utc; |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
12284
diff
changeset
|
197 | const char *date; |
| 7014 | 198 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
199 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, xmlns); |
| 8006 | 200 | jabber_iq_set_id(iq, id); |
| 201 | xmlnode_set_attrib(iq->node, "to", from); | |
| 202 | ||
| 203 | query = xmlnode_get_child(iq->node, "query"); | |
| 7014 | 204 | |
| 15884 | 205 | date = purple_utf8_strftime("%Y%m%dT%T", now); |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
206 | utc = xmlnode_new_child(query, "utc"); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
207 | xmlnode_insert_data(utc, date, -1); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
208 | |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
209 | if(!strcmp("urn:xmpp:time", xmlns)) { |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
210 | xmlnode_insert_data(utc, "Z", 1); /* of COURSE the thing that is the same is different */ |
| 10941 | 211 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
212 | date = purple_get_tzoff_str(now, TRUE); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
213 | xmlnode_insert_data(xmlnode_new_child(query, "tzo"), date, -1); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
214 | } else { /* jabber:iq:time */ |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
215 | date = purple_utf8_strftime("%Z", now); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
216 | xmlnode_insert_data(xmlnode_new_child(query, "tz"), date, -1); |
| 10941 | 217 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
218 | date = purple_utf8_strftime("%d %b %Y %T", now); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
219 | xmlnode_insert_data(xmlnode_new_child(query, "display"), date, -1); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
220 | } |
| 7014 | 221 | |
| 8006 | 222 | jabber_iq_send(iq); |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
223 | } |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
224 | } |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
225 | |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
226 | static void urn_xmpp_ping_parse(JabberStream *js, xmlnode *packet) |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
227 | { |
|
18194
5365792ac81f
i'm an idiot. now we have real support for replying to XMPP pings
Nathan Walp <nwalp@pidgin.im>
parents:
18184
diff
changeset
|
228 | const char *type, *id, *from; |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
229 | JabberIq *iq; |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
230 | |
|
18194
5365792ac81f
i'm an idiot. now we have real support for replying to XMPP pings
Nathan Walp <nwalp@pidgin.im>
parents:
18184
diff
changeset
|
231 | type = xmlnode_get_attrib(packet, "type"); |
|
5365792ac81f
i'm an idiot. now we have real support for replying to XMPP pings
Nathan Walp <nwalp@pidgin.im>
parents:
18184
diff
changeset
|
232 | from = xmlnode_get_attrib(packet, "from"); |
|
5365792ac81f
i'm an idiot. now we have real support for replying to XMPP pings
Nathan Walp <nwalp@pidgin.im>
parents:
18184
diff
changeset
|
233 | id = xmlnode_get_attrib(packet, "id"); |
|
5365792ac81f
i'm an idiot. now we have real support for replying to XMPP pings
Nathan Walp <nwalp@pidgin.im>
parents:
18184
diff
changeset
|
234 | |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
235 | if(type && !strcmp(type, "get")) { |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
236 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "urn:xmpp:ping"); |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
237 | |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
238 | jabber_iq_set_id(iq, id); |
|
18194
5365792ac81f
i'm an idiot. now we have real support for replying to XMPP pings
Nathan Walp <nwalp@pidgin.im>
parents:
18184
diff
changeset
|
239 | xmlnode_set_attrib(iq->node, "to", from); |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
240 | |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
241 | jabber_iq_send(iq); |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
242 | } else { |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
243 | /* XXX: error */ |
| 8006 | 244 | } |
| 7014 | 245 | } |
| 246 | ||
| 8312 | 247 | static void jabber_iq_version_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 248 | { |
| 249 | JabberIq *iq; | |
| 8006 | 250 | const char *type, *from, *id; |
| 7014 | 251 | xmlnode *query; |
| 252 | ||
| 8006 | 253 | type = xmlnode_get_attrib(packet, "type"); |
| 254 | ||
| 255 | if(type && !strcmp(type, "get")) { | |
|
18441
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
256 | GHashTable *ui_info; |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
257 | const char *ui_name = NULL, *ui_version = NULL; |
|
20116
9952c317df4c
applied changes from 8543caa9958f323a231c630bebd65c74dec3401f
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
258 | #if 0 |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20116
diff
changeset
|
259 | char *os = NULL; |
| 15884 | 260 | if(!purple_prefs_get_bool("/plugins/prpl/jabber/hide_os")) { |
| 8006 | 261 | struct utsname osinfo; |
| 7014 | 262 | |
| 8006 | 263 | uname(&osinfo); |
| 264 | os = g_strdup_printf("%s %s %s", osinfo.sysname, osinfo.release, | |
| 265 | osinfo.machine); | |
| 266 | } | |
|
20116
9952c317df4c
applied changes from 8543caa9958f323a231c630bebd65c74dec3401f
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
267 | #endif |
| 8006 | 268 | from = xmlnode_get_attrib(packet, "from"); |
| 269 | id = xmlnode_get_attrib(packet, "id"); | |
| 7014 | 270 | |
| 8006 | 271 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:version"); |
| 272 | xmlnode_set_attrib(iq->node, "to", from); | |
| 273 | jabber_iq_set_id(iq, id); | |
| 7014 | 274 | |
| 8006 | 275 | query = xmlnode_get_child(iq->node, "query"); |
| 7014 | 276 | |
|
18441
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
277 | ui_info = purple_core_get_ui_info(); |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
278 | |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
279 | if(NULL != ui_info) { |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
280 | ui_name = g_hash_table_lookup(ui_info, "name"); |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
281 | ui_version = g_hash_table_lookup(ui_info, "version"); |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
282 | } |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
283 | |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
284 | if(NULL != ui_name && NULL != ui_version) { |
| 18443 | 285 | char *version_complete = g_strdup_printf("%s (libpurple " VERSION ")", ui_version); |
| 286 | xmlnode_insert_data(xmlnode_new_child(query, "name"), ui_name, -1); | |
| 287 | xmlnode_insert_data(xmlnode_new_child(query, "version"), version_complete, -1); | |
| 288 | g_free(version_complete); | |
|
18441
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
289 | } else { |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
290 | xmlnode_insert_data(xmlnode_new_child(query, "name"), "libpurple", -1); |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
291 | xmlnode_insert_data(xmlnode_new_child(query, "version"), VERSION, -1); |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
292 | } |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
293 | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20116
diff
changeset
|
294 | #if 0 |
| 8006 | 295 | if(os) { |
| 296 | xmlnode_insert_data(xmlnode_new_child(query, "os"), os, -1); | |
| 297 | g_free(os); | |
| 298 | } | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20116
diff
changeset
|
299 | #endif |
| 10941 | 300 | |
| 8006 | 301 | jabber_iq_send(iq); |
| 7014 | 302 | } |
| 303 | } | |
| 304 | ||
| 13794 | 305 | void jabber_iq_remove_callback_by_id(JabberStream *js, const char *id) |
| 306 | { | |
| 307 | g_hash_table_remove(js->iq_callbacks, id); | |
| 308 | } | |
| 309 | ||
| 7014 | 310 | void jabber_iq_parse(JabberStream *js, xmlnode *packet) |
| 311 | { | |
| 7395 | 312 | JabberCallbackData *jcd; |
|
26037
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
313 | xmlnode *query, *error, *x; |
| 7014 | 314 | const char *xmlns; |
| 8135 | 315 | const char *type, *id, *from; |
| 14356 | 316 | JabberIqHandler *jih; |
| 7014 | 317 | |
| 318 | query = xmlnode_get_child(packet, "query"); | |
| 8043 | 319 | type = xmlnode_get_attrib(packet, "type"); |
| 8135 | 320 | from = xmlnode_get_attrib(packet, "from"); |
| 8312 | 321 | id = xmlnode_get_attrib(packet, "id"); |
| 322 | ||
|
24520
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
323 | if(type == NULL || !(!strcmp(type, "get") || !strcmp(type, "set") |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
324 | || !strcmp(type, "result") || !strcmp(type, "error"))) { |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
325 | purple_debug_error("jabber", "IQ with invalid type ('%s') - ignoring.\n", |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
326 | type ? type : "(null)"); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
327 | return; |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
328 | } |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
329 | |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
330 | /* All IQs must have an ID, so send an error for a set/get that doesn't */ |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
331 | if(!id || !*id) { |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
332 | |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
333 | if(!strcmp(type, "set") || !strcmp(type, "get")) { |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
334 | JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
335 | |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
336 | xmlnode_free(iq->node); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
337 | iq->node = xmlnode_copy(packet); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
338 | xmlnode_set_attrib(iq->node, "to", from); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
339 | xmlnode_remove_attrib(iq->node, "from"); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
340 | xmlnode_set_attrib(iq->node, "type", "error"); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
341 | /* This id is clearly not useful, but we must put something there for a valid stanza */ |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
342 | iq->id = jabber_get_next_id(js); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
343 | xmlnode_set_attrib(iq->node, "id", iq->id); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
344 | error = xmlnode_new_child(iq->node, "error"); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
345 | xmlnode_set_attrib(error, "type", "modify"); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
346 | x = xmlnode_new_child(error, "bad-request"); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
347 | xmlnode_set_namespace(x, "urn:ietf:params:xml:ns:xmpp-stanzas"); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
348 | |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
349 | jabber_iq_send(iq); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
350 | } else |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
351 | purple_debug_error("jabber", "IQ of type '%s' missing id - ignoring.\n", type); |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
352 | |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
353 | return; |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
354 | } |
|
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
355 | |
| 8312 | 356 | /* First, lets see if a special callback got registered */ |
| 357 | ||
|
24520
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
358 | if(!strcmp(type, "result") || !strcmp(type, "error")) { |
| 8312 | 359 | if(id && *id && (jcd = g_hash_table_lookup(js->iq_callbacks, id))) { |
| 360 | jcd->callback(js, packet, jcd->data); | |
| 13794 | 361 | jabber_iq_remove_callback_by_id(js, id); |
| 8314 | 362 | return; |
| 8312 | 363 | } |
| 364 | } | |
| 365 | ||
| 366 | /* Apparently not, so lets see if we have a pre-defined handler */ | |
| 7014 | 367 | |
|
24520
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
368 | if(query && (xmlns = xmlnode_get_namespace(query))) { |
| 14356 | 369 | if((jih = g_hash_table_lookup(iq_handlers, xmlns))) { |
| 370 | jih(js, packet); | |
| 8262 | 371 | return; |
| 372 | } | |
| 7395 | 373 | } |
| 374 | ||
|
26037
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
375 | if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) { |
|
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
376 | jabber_si_parse(js, packet); |
| 14356 | 377 | return; |
| 378 | } | |
| 379 | ||
|
26037
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
380 | if(xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) { |
|
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
381 | jabber_gmail_poke(js, packet); |
| 15225 | 382 | return; |
| 383 | } | |
|
24520
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
384 | |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
385 | purple_debug_info("jabber", "jabber_iq_parse\n"); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
386 | |
|
26037
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
387 | if(xmlnode_get_child_with_namespace(packet, "ping", "urn:xmpp:ping")) { |
|
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
388 | jabber_ping_parse(js, packet); |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
389 | return; |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
390 | } |
| 15225 | 391 | |
|
26037
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
392 | if (xmlnode_get_child_with_namespace(packet, "data", XEP_0231_NAMESPACE)) { |
|
5c3f5fca3fe6
propagate from branch 'im.pidgin.pidgin' (head a8bc9676ea5266e1cfd46544b57ba6207f6beb2a)
Marcus Lundblad <malu@pidgin.im>
parents:
26036
diff
changeset
|
393 | jabber_data_parse(js, packet); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
394 | return; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
395 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
396 | |
|
24372
830701cec96f
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
397 | if (xmlnode_get_child_with_namespace(packet, "data", XEP_0047_NAMESPACE) |
|
830701cec96f
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
398 | || xmlnode_get_child_with_namespace(packet, "close", XEP_0047_NAMESPACE) |
|
830701cec96f
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
399 | || xmlnode_get_child_with_namespace(packet, "open", XEP_0047_NAMESPACE)) { |
|
830701cec96f
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
400 | jabber_ibb_parse(js, packet); |
|
830701cec96f
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
401 | return; |
|
830701cec96f
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
402 | } |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
26037
diff
changeset
|
403 | |
| 8312 | 404 | /* If we get here, send the default error reply mandated by XMPP-CORE */ |
|
24520
726138a1c69b
Perform some sanity checking on inbound IQs and send an error / drop as needed.
Daniel Atallah <datallah@pidgin.im>
parents:
24254
diff
changeset
|
405 | if(!strcmp(type, "set") || !strcmp(type, "get")) { |
| 8315 | 406 | JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); |
| 8135 | 407 | |
| 8315 | 408 | xmlnode_free(iq->node); |
| 409 | iq->node = xmlnode_copy(packet); | |
| 410 | xmlnode_set_attrib(iq->node, "to", from); | |
|
11825
fe23dc05a8a6
[gaim-migrate @ 14116]
Mark Doliner <markdoliner@pidgin.im>
parents:
11822
diff
changeset
|
411 | xmlnode_remove_attrib(iq->node, "from"); |
| 8315 | 412 | xmlnode_set_attrib(iq->node, "type", "error"); |
| 413 | error = xmlnode_new_child(iq->node, "error"); | |
| 414 | xmlnode_set_attrib(error, "type", "cancel"); | |
| 415 | xmlnode_set_attrib(error, "code", "501"); | |
| 416 | x = xmlnode_new_child(error, "feature-not-implemented"); | |
| 13808 | 417 | xmlnode_set_namespace(x, "urn:ietf:params:xml:ns:xmpp-stanzas"); |
| 8169 | 418 | |
| 8315 | 419 | jabber_iq_send(iq); |
| 420 | } | |
| 7014 | 421 | } |
| 422 | ||
|
23076
e415fa270dfe
Fix jabber_iq_register_handler() to match header.
Daniel Atallah <datallah@pidgin.im>
parents:
21688
diff
changeset
|
423 | void jabber_iq_register_handler(const char *xmlns, JabberIqHandler *handlerfunc) |
| 14356 | 424 | { |
| 425 | g_hash_table_replace(iq_handlers, g_strdup(xmlns), handlerfunc); | |
| 426 | } | |
| 427 | ||
| 428 | void jabber_iq_init(void) | |
| 429 | { | |
| 430 | iq_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
| 431 | ||
| 432 | jabber_iq_register_handler("jabber:iq:roster", jabber_roster_parse); | |
| 433 | jabber_iq_register_handler("jabber:iq:oob", jabber_oob_parse); | |
| 434 | jabber_iq_register_handler("http://jabber.org/protocol/bytestreams", jabber_bytestreams_parse); | |
| 435 | jabber_iq_register_handler("jabber:iq:last", jabber_iq_last_parse); | |
| 436 | jabber_iq_register_handler("jabber:iq:time", jabber_iq_time_parse); | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
437 | jabber_iq_register_handler("urn:xmpp:time", jabber_iq_time_parse); |
| 14356 | 438 | jabber_iq_register_handler("jabber:iq:version", jabber_iq_version_parse); |
| 439 | jabber_iq_register_handler("http://jabber.org/protocol/disco#info", jabber_disco_info_parse); | |
| 440 | jabber_iq_register_handler("http://jabber.org/protocol/disco#items", jabber_disco_items_parse); | |
| 441 | jabber_iq_register_handler("jabber:iq:register", jabber_register_parse); | |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
442 | jabber_iq_register_handler("urn:xmpp:ping", urn_xmpp_ping_parse); |
| 14356 | 443 | } |
| 444 | ||
| 445 | void jabber_iq_uninit(void) | |
| 446 | { | |
| 447 | g_hash_table_destroy(iq_handlers); | |
|
21688
a16385b34219
Implement more of XEP-0065 to support sending files through a proxy. To avoid adding strings this close to a release, it only supports using a proxy that is discovered from the server, but we'll include an account option to manually specify a ft proxy in the next release. Lots of this is based on a patch from galt - Fixes #3730, #116, #1768
Daniel Atallah <datallah@pidgin.im>
parents:
20225
diff
changeset
|
448 | iq_handlers = NULL; |
| 14356 | 449 | } |
| 450 |