Fri, 14 Nov 2008 19:58:32 +0000
String changes. I'm kind of blindly making changes to the qq strings
| 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" |
| 7014 | 37 | |
|
7058
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
38 | #ifdef _WIN32 |
|
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
39 | #include "utsname.h" |
|
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
40 | #endif |
| 7014 | 41 | |
| 14356 | 42 | GHashTable *iq_handlers = NULL; |
| 43 | ||
| 44 | ||
| 7014 | 45 | JabberIq *jabber_iq_new(JabberStream *js, JabberIqType type) |
| 46 | { | |
| 47 | JabberIq *iq; | |
| 48 | ||
| 49 | iq = g_new0(JabberIq, 1); | |
| 50 | ||
| 51 | iq->type = type; | |
| 52 | ||
| 53 | iq->node = xmlnode_new("iq"); | |
| 54 | switch(iq->type) { | |
| 55 | case JABBER_IQ_SET: | |
| 56 | xmlnode_set_attrib(iq->node, "type", "set"); | |
| 57 | break; | |
| 58 | case JABBER_IQ_GET: | |
| 59 | xmlnode_set_attrib(iq->node, "type", "get"); | |
| 60 | break; | |
| 61 | case JABBER_IQ_ERROR: | |
| 62 | xmlnode_set_attrib(iq->node, "type", "error"); | |
| 63 | break; | |
| 64 | case JABBER_IQ_RESULT: | |
| 65 | xmlnode_set_attrib(iq->node, "type", "result"); | |
| 66 | break; | |
| 67 | case JABBER_IQ_NONE: | |
| 68 | /* this shouldn't ever happen */ | |
| 69 | break; | |
| 70 | } | |
| 71 | ||
| 72 | iq->js = js; | |
| 73 | ||
| 74 | if(type == JABBER_IQ_GET || type == JABBER_IQ_SET) { | |
| 75 | iq->id = jabber_get_next_id(js); | |
| 76 | xmlnode_set_attrib(iq->node, "id", iq->id); | |
| 77 | } | |
| 78 | ||
| 79 | return iq; | |
| 80 | } | |
| 81 | ||
| 82 | JabberIq *jabber_iq_new_query(JabberStream *js, JabberIqType type, | |
| 83 | const char *xmlns) | |
| 84 | { | |
| 85 | JabberIq *iq = jabber_iq_new(js, type); | |
| 86 | xmlnode *query; | |
| 87 | ||
| 88 | query = xmlnode_new_child(iq->node, "query"); | |
| 13808 | 89 | xmlnode_set_namespace(query, xmlns); |
| 7014 | 90 | |
| 91 | return iq; | |
| 92 | } | |
| 93 | ||
| 7395 | 94 | typedef struct _JabberCallbackData { |
| 95 | JabberIqCallback *callback; | |
| 96 | gpointer data; | |
| 97 | } JabberCallbackData; | |
| 98 | ||
| 99 | void | |
| 100 | jabber_iq_set_callback(JabberIq *iq, JabberIqCallback *callback, gpointer data) | |
| 7014 | 101 | { |
| 102 | iq->callback = callback; | |
| 7395 | 103 | iq->callback_data = data; |
| 7014 | 104 | } |
| 105 | ||
| 106 | void jabber_iq_set_id(JabberIq *iq, const char *id) | |
| 107 | { | |
|
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
|
108 | g_free(iq->id); |
| 7014 | 109 | |
| 110 | if(id) { | |
| 111 | xmlnode_set_attrib(iq->node, "id", id); | |
| 112 | iq->id = g_strdup(id); | |
| 113 | } else { | |
| 114 | xmlnode_remove_attrib(iq->node, "id"); | |
| 115 | iq->id = NULL; | |
| 116 | } | |
| 117 | } | |
| 118 | ||
| 119 | void jabber_iq_send(JabberIq *iq) | |
| 120 | { | |
| 7395 | 121 | JabberCallbackData *jcd; |
| 7014 | 122 | g_return_if_fail(iq != NULL); |
| 123 | ||
| 124 | jabber_send(iq->js, iq->node); | |
| 125 | ||
| 7395 | 126 | if(iq->id && iq->callback) { |
| 127 | jcd = g_new0(JabberCallbackData, 1); | |
| 128 | jcd->callback = iq->callback; | |
| 129 | jcd->data = iq->callback_data; | |
| 8312 | 130 | g_hash_table_insert(iq->js->iq_callbacks, g_strdup(iq->id), jcd); |
| 7395 | 131 | } |
| 7014 | 132 | |
| 133 | jabber_iq_free(iq); | |
| 134 | } | |
| 135 | ||
| 136 | void jabber_iq_free(JabberIq *iq) | |
| 137 | { | |
| 138 | g_return_if_fail(iq != NULL); | |
| 139 | ||
| 140 | g_free(iq->id); | |
| 141 | xmlnode_free(iq->node); | |
| 142 | g_free(iq); | |
| 143 | } | |
| 144 | ||
| 8312 | 145 | static void jabber_iq_last_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 146 | { |
| 147 | JabberIq *iq; | |
| 8006 | 148 | const char *type; |
| 7014 | 149 | const char *from; |
| 150 | const char *id; | |
| 151 | xmlnode *query; | |
|
14453
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
152 | char *idle_time; |
| 7014 | 153 | |
| 8006 | 154 | type = xmlnode_get_attrib(packet, "type"); |
| 7014 | 155 | from = xmlnode_get_attrib(packet, "from"); |
| 156 | id = xmlnode_get_attrib(packet, "id"); | |
| 157 | ||
| 8006 | 158 | if(type && !strcmp(type, "get")) { |
| 159 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:last"); | |
| 160 | jabber_iq_set_id(iq, id); | |
| 161 | xmlnode_set_attrib(iq->node, "to", from); | |
| 7014 | 162 | |
| 8006 | 163 | query = xmlnode_get_child(iq->node, "query"); |
| 7014 | 164 | |
|
14453
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
165 | 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
|
166 | xmlnode_set_attrib(query, "seconds", idle_time); |
|
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
167 | g_free(idle_time); |
| 7401 | 168 | |
| 8006 | 169 | jabber_iq_send(iq); |
| 170 | } | |
| 7014 | 171 | } |
| 172 | ||
| 8312 | 173 | static void jabber_iq_time_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 174 | { |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
175 | const char *type, *from, *id, *xmlns; |
| 7014 | 176 | JabberIq *iq; |
| 177 | xmlnode *query; | |
| 178 | time_t now_t; | |
|
9709
2e73f176cc80
[gaim-migrate @ 10570]
Mark Doliner <markdoliner@pidgin.im>
parents:
8315
diff
changeset
|
179 | struct tm *now; |
|
9722
c1072806bcae
[gaim-migrate @ 10583]
Mark Doliner <markdoliner@pidgin.im>
parents:
9709
diff
changeset
|
180 | |
| 7014 | 181 | time(&now_t); |
|
9709
2e73f176cc80
[gaim-migrate @ 10570]
Mark Doliner <markdoliner@pidgin.im>
parents:
8315
diff
changeset
|
182 | now = localtime(&now_t); |
| 7014 | 183 | |
| 8006 | 184 | type = xmlnode_get_attrib(packet, "type"); |
| 7014 | 185 | from = xmlnode_get_attrib(packet, "from"); |
| 186 | id = xmlnode_get_attrib(packet, "id"); | |
| 187 | ||
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
188 | /* 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
|
189 | * 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
|
190 | * jabber:iq:time or urn:xmpp:time */ |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
191 | query = xmlnode_get_child(packet, "query"); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
192 | xmlns = xmlnode_get_namespace(query); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
193 | |
| 8006 | 194 | if(type && !strcmp(type, "get")) { |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
195 | xmlnode *utc; |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
12284
diff
changeset
|
196 | const char *date; |
| 7014 | 197 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
198 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, xmlns); |
| 8006 | 199 | jabber_iq_set_id(iq, id); |
| 200 | xmlnode_set_attrib(iq->node, "to", from); | |
| 201 | ||
| 202 | query = xmlnode_get_child(iq->node, "query"); | |
| 7014 | 203 | |
| 15884 | 204 | 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
|
205 | utc = xmlnode_new_child(query, "utc"); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
206 | xmlnode_insert_data(utc, date, -1); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
207 | |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
208 | if(!strcmp("urn:xmpp:time", xmlns)) { |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
209 | xmlnode_insert_data(utc, "Z", 1); /* of COURSE the thing that is the same is different */ |
| 10941 | 210 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
211 | date = purple_get_tzoff_str(now, TRUE); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
212 | 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
|
213 | } else { /* jabber:iq:time */ |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
214 | date = purple_utf8_strftime("%Z", now); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
215 | xmlnode_insert_data(xmlnode_new_child(query, "tz"), date, -1); |
| 10941 | 216 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
217 | 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
|
218 | 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
|
219 | } |
| 7014 | 220 | |
| 8006 | 221 | jabber_iq_send(iq); |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
222 | } |
|
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 | 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
|
226 | { |
|
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
|
227 | const char *type, *id, *from; |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
228 | JabberIq *iq; |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
229 | |
|
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
|
230 | 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
|
231 | 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
|
232 | 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
|
233 | |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
234 | if(type && !strcmp(type, "get")) { |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
235 | 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
|
236 | |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
237 | 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
|
238 | 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
|
239 | |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
240 | jabber_iq_send(iq); |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
241 | } else { |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
242 | /* XXX: error */ |
| 8006 | 243 | } |
| 7014 | 244 | } |
| 245 | ||
| 8312 | 246 | static void jabber_iq_version_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 247 | { |
| 248 | JabberIq *iq; | |
| 8006 | 249 | const char *type, *from, *id; |
| 7014 | 250 | xmlnode *query; |
| 251 | ||
| 8006 | 252 | type = xmlnode_get_attrib(packet, "type"); |
| 253 | ||
| 254 | 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
|
255 | GHashTable *ui_info; |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
256 | const char *ui_name = NULL, *ui_version = NULL; |
|
20116
9952c317df4c
applied changes from 8543caa9958f323a231c630bebd65c74dec3401f
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
257 | #if 0 |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20116
diff
changeset
|
258 | char *os = NULL; |
| 15884 | 259 | if(!purple_prefs_get_bool("/plugins/prpl/jabber/hide_os")) { |
| 8006 | 260 | struct utsname osinfo; |
| 7014 | 261 | |
| 8006 | 262 | uname(&osinfo); |
| 263 | os = g_strdup_printf("%s %s %s", osinfo.sysname, osinfo.release, | |
| 264 | osinfo.machine); | |
| 265 | } | |
|
20116
9952c317df4c
applied changes from 8543caa9958f323a231c630bebd65c74dec3401f
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
266 | #endif |
| 8006 | 267 | from = xmlnode_get_attrib(packet, "from"); |
| 268 | id = xmlnode_get_attrib(packet, "id"); | |
| 7014 | 269 | |
| 8006 | 270 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:version"); |
| 271 | xmlnode_set_attrib(iq->node, "to", from); | |
| 272 | jabber_iq_set_id(iq, id); | |
| 7014 | 273 | |
| 8006 | 274 | query = xmlnode_get_child(iq->node, "query"); |
| 7014 | 275 | |
|
18441
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
276 | 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
|
277 | |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
278 | 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
|
279 | 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
|
280 | 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
|
281 | } |
|
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 | if(NULL != ui_name && NULL != ui_version) { |
| 18443 | 284 | char *version_complete = g_strdup_printf("%s (libpurple " VERSION ")", ui_version); |
| 285 | xmlnode_insert_data(xmlnode_new_child(query, "name"), ui_name, -1); | |
| 286 | xmlnode_insert_data(xmlnode_new_child(query, "version"), version_complete, -1); | |
| 287 | 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
|
288 | } else { |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
289 | 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
|
290 | 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
|
291 | } |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
292 | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20116
diff
changeset
|
293 | #if 0 |
| 8006 | 294 | if(os) { |
| 295 | xmlnode_insert_data(xmlnode_new_child(query, "os"), os, -1); | |
| 296 | g_free(os); | |
| 297 | } | |
|
20225
684334efdc19
applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents:
20116
diff
changeset
|
298 | #endif |
| 10941 | 299 | |
| 8006 | 300 | jabber_iq_send(iq); |
| 7014 | 301 | } |
| 302 | } | |
| 303 | ||
| 13794 | 304 | void jabber_iq_remove_callback_by_id(JabberStream *js, const char *id) |
| 305 | { | |
| 306 | g_hash_table_remove(js->iq_callbacks, id); | |
| 307 | } | |
| 308 | ||
| 7014 | 309 | void jabber_iq_parse(JabberStream *js, xmlnode *packet) |
| 310 | { | |
| 7395 | 311 | JabberCallbackData *jcd; |
| 8169 | 312 | xmlnode *query, *error, *x; |
| 7014 | 313 | const char *xmlns; |
| 8135 | 314 | const char *type, *id, *from; |
| 14356 | 315 | JabberIqHandler *jih; |
| 7014 | 316 | |
| 317 | query = xmlnode_get_child(packet, "query"); | |
| 8043 | 318 | type = xmlnode_get_attrib(packet, "type"); |
| 8135 | 319 | from = xmlnode_get_attrib(packet, "from"); |
| 8312 | 320 | id = xmlnode_get_attrib(packet, "id"); |
| 321 | ||
|
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
|
322 | 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
|
323 | || !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
|
324 | 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
|
325 | 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
|
326 | 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
|
327 | } |
|
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 | /* 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
|
330 | 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
|
331 | |
|
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 | 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
|
333 | 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
|
334 | |
|
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 | 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
|
336 | 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
|
337 | 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
|
338 | 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
|
339 | 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
|
340 | /* 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
|
341 | 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
|
342 | 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
|
343 | 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
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | |
|
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 | 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
|
349 | } 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
|
350 | 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
|
351 | |
|
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 | 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
|
353 | } |
|
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 | |
| 8312 | 355 | /* First, lets see if a special callback got registered */ |
| 356 | ||
|
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
|
357 | if(!strcmp(type, "result") || !strcmp(type, "error")) { |
| 8312 | 358 | if(id && *id && (jcd = g_hash_table_lookup(js->iq_callbacks, id))) { |
| 359 | jcd->callback(js, packet, jcd->data); | |
| 13794 | 360 | jabber_iq_remove_callback_by_id(js, id); |
| 8314 | 361 | return; |
| 8312 | 362 | } |
| 363 | } | |
| 364 | ||
| 365 | /* Apparently not, so lets see if we have a pre-defined handler */ | |
| 7014 | 366 | |
|
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
|
367 | if(query && (xmlns = xmlnode_get_namespace(query))) { |
| 14356 | 368 | if((jih = g_hash_table_lookup(iq_handlers, xmlns))) { |
| 369 | jih(js, packet); | |
| 8262 | 370 | return; |
| 371 | } | |
| 7395 | 372 | } |
| 373 | ||
| 14356 | 374 | if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) { |
| 375 | jabber_si_parse(js, packet); | |
| 376 | return; | |
| 377 | } | |
| 378 | ||
| 15225 | 379 | if(xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) { |
| 380 | jabber_gmail_poke(js, packet); | |
| 381 | return; | |
| 382 | } | |
|
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
|
383 | |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
384 | 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
|
385 | |
|
18911
34ae89bfee24
Updated the XEP-0199 namespace according to the XEP.
Andreas Monitzer <am@adiumx.com>
parents:
18718
diff
changeset
|
386 | if(xmlnode_get_child_with_namespace(packet, "ping", "urn:xmpp:ping")) { |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
387 | jabber_ping_parse(js, packet); |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
388 | return; |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
389 | } |
| 15225 | 390 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23626
diff
changeset
|
391 | if (xmlnode_get_child_with_namespace(packet, "data", XEP_0231_NAMESPACE)) { |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
392 | jabber_data_parse(js, packet); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
393 | return; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
394 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23076
diff
changeset
|
395 | |
| 8312 | 396 | /* 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
|
397 | if(!strcmp(type, "set") || !strcmp(type, "get")) { |
| 8315 | 398 | JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); |
| 8135 | 399 | |
| 8315 | 400 | xmlnode_free(iq->node); |
| 401 | iq->node = xmlnode_copy(packet); | |
| 402 | xmlnode_set_attrib(iq->node, "to", from); | |
|
11825
fe23dc05a8a6
[gaim-migrate @ 14116]
Mark Doliner <markdoliner@pidgin.im>
parents:
11822
diff
changeset
|
403 | xmlnode_remove_attrib(iq->node, "from"); |
| 8315 | 404 | xmlnode_set_attrib(iq->node, "type", "error"); |
| 405 | error = xmlnode_new_child(iq->node, "error"); | |
| 406 | xmlnode_set_attrib(error, "type", "cancel"); | |
| 407 | xmlnode_set_attrib(error, "code", "501"); | |
| 408 | x = xmlnode_new_child(error, "feature-not-implemented"); | |
| 13808 | 409 | xmlnode_set_namespace(x, "urn:ietf:params:xml:ns:xmpp-stanzas"); |
| 8169 | 410 | |
| 8315 | 411 | jabber_iq_send(iq); |
| 412 | } | |
| 7014 | 413 | } |
| 414 | ||
|
23076
e415fa270dfe
Fix jabber_iq_register_handler() to match header.
Daniel Atallah <datallah@pidgin.im>
parents:
21688
diff
changeset
|
415 | void jabber_iq_register_handler(const char *xmlns, JabberIqHandler *handlerfunc) |
| 14356 | 416 | { |
| 417 | g_hash_table_replace(iq_handlers, g_strdup(xmlns), handlerfunc); | |
| 418 | } | |
| 419 | ||
| 420 | void jabber_iq_init(void) | |
| 421 | { | |
| 422 | iq_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
| 423 | ||
| 424 | jabber_iq_register_handler("jabber:iq:roster", jabber_roster_parse); | |
| 425 | jabber_iq_register_handler("jabber:iq:oob", jabber_oob_parse); | |
| 426 | jabber_iq_register_handler("http://jabber.org/protocol/bytestreams", jabber_bytestreams_parse); | |
| 427 | jabber_iq_register_handler("jabber:iq:last", jabber_iq_last_parse); | |
| 428 | 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
|
429 | jabber_iq_register_handler("urn:xmpp:time", jabber_iq_time_parse); |
| 14356 | 430 | jabber_iq_register_handler("jabber:iq:version", jabber_iq_version_parse); |
| 431 | jabber_iq_register_handler("http://jabber.org/protocol/disco#info", jabber_disco_info_parse); | |
| 432 | jabber_iq_register_handler("http://jabber.org/protocol/disco#items", jabber_disco_items_parse); | |
| 433 | 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
|
434 | jabber_iq_register_handler("urn:xmpp:ping", urn_xmpp_ping_parse); |
| 14356 | 435 | } |
| 436 | ||
| 437 | void jabber_iq_uninit(void) | |
| 438 | { | |
| 439 | 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
|
440 | iq_handlers = NULL; |
| 14356 | 441 | } |
| 442 |