Sun, 12 Aug 2007 02:11:05 +0000
Use -1 as length with g_convert() functions instead of strlen()
| 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 | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 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" |
| 7014 | 34 | |
|
7058
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
35 | #ifdef _WIN32 |
|
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
36 | #include "utsname.h" |
|
c62db98b7a2a
[gaim-migrate @ 7621]
Herman Bloggs <herman@bluedigits.com>
parents:
7014
diff
changeset
|
37 | #endif |
| 7014 | 38 | |
| 14356 | 39 | GHashTable *iq_handlers = NULL; |
| 40 | ||
| 41 | ||
| 7014 | 42 | JabberIq *jabber_iq_new(JabberStream *js, JabberIqType type) |
| 43 | { | |
| 44 | JabberIq *iq; | |
| 45 | ||
| 46 | iq = g_new0(JabberIq, 1); | |
| 47 | ||
| 48 | iq->type = type; | |
| 49 | ||
| 50 | iq->node = xmlnode_new("iq"); | |
| 51 | switch(iq->type) { | |
| 52 | case JABBER_IQ_SET: | |
| 53 | xmlnode_set_attrib(iq->node, "type", "set"); | |
| 54 | break; | |
| 55 | case JABBER_IQ_GET: | |
| 56 | xmlnode_set_attrib(iq->node, "type", "get"); | |
| 57 | break; | |
| 58 | case JABBER_IQ_ERROR: | |
| 59 | xmlnode_set_attrib(iq->node, "type", "error"); | |
| 60 | break; | |
| 61 | case JABBER_IQ_RESULT: | |
| 62 | xmlnode_set_attrib(iq->node, "type", "result"); | |
| 63 | break; | |
| 64 | case JABBER_IQ_NONE: | |
| 65 | /* this shouldn't ever happen */ | |
| 66 | break; | |
| 67 | } | |
| 68 | ||
| 69 | iq->js = js; | |
| 70 | ||
| 71 | if(type == JABBER_IQ_GET || type == JABBER_IQ_SET) { | |
| 72 | iq->id = jabber_get_next_id(js); | |
| 73 | xmlnode_set_attrib(iq->node, "id", iq->id); | |
| 74 | } | |
| 75 | ||
| 76 | return iq; | |
| 77 | } | |
| 78 | ||
| 79 | JabberIq *jabber_iq_new_query(JabberStream *js, JabberIqType type, | |
| 80 | const char *xmlns) | |
| 81 | { | |
| 82 | JabberIq *iq = jabber_iq_new(js, type); | |
| 83 | xmlnode *query; | |
| 84 | ||
| 85 | query = xmlnode_new_child(iq->node, "query"); | |
| 13808 | 86 | xmlnode_set_namespace(query, xmlns); |
| 7014 | 87 | |
| 88 | return iq; | |
| 89 | } | |
| 90 | ||
| 7395 | 91 | typedef struct _JabberCallbackData { |
| 92 | JabberIqCallback *callback; | |
| 93 | gpointer data; | |
| 94 | } JabberCallbackData; | |
| 95 | ||
| 96 | void | |
| 97 | jabber_iq_set_callback(JabberIq *iq, JabberIqCallback *callback, gpointer data) | |
| 7014 | 98 | { |
| 99 | iq->callback = callback; | |
| 7395 | 100 | iq->callback_data = data; |
| 7014 | 101 | } |
| 102 | ||
| 103 | void jabber_iq_set_id(JabberIq *iq, const char *id) | |
| 104 | { | |
| 105 | if(iq->id) | |
| 106 | g_free(iq->id); | |
| 107 | ||
| 108 | if(id) { | |
| 109 | xmlnode_set_attrib(iq->node, "id", id); | |
| 110 | iq->id = g_strdup(id); | |
| 111 | } else { | |
| 112 | xmlnode_remove_attrib(iq->node, "id"); | |
| 113 | iq->id = NULL; | |
| 114 | } | |
| 115 | } | |
| 116 | ||
| 117 | void jabber_iq_send(JabberIq *iq) | |
| 118 | { | |
| 7395 | 119 | JabberCallbackData *jcd; |
| 7014 | 120 | g_return_if_fail(iq != NULL); |
| 121 | ||
| 122 | jabber_send(iq->js, iq->node); | |
| 123 | ||
| 7395 | 124 | if(iq->id && iq->callback) { |
| 125 | jcd = g_new0(JabberCallbackData, 1); | |
| 126 | jcd->callback = iq->callback; | |
| 127 | jcd->data = iq->callback_data; | |
| 8312 | 128 | g_hash_table_insert(iq->js->iq_callbacks, g_strdup(iq->id), jcd); |
| 7395 | 129 | } |
| 7014 | 130 | |
| 131 | jabber_iq_free(iq); | |
| 132 | } | |
| 133 | ||
| 134 | void jabber_iq_free(JabberIq *iq) | |
| 135 | { | |
| 136 | g_return_if_fail(iq != NULL); | |
| 137 | ||
| 138 | g_free(iq->id); | |
| 139 | xmlnode_free(iq->node); | |
| 140 | g_free(iq); | |
| 141 | } | |
| 142 | ||
| 8312 | 143 | static void jabber_iq_last_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 144 | { |
| 145 | JabberIq *iq; | |
| 8006 | 146 | const char *type; |
| 7014 | 147 | const char *from; |
| 148 | const char *id; | |
| 149 | xmlnode *query; | |
|
14453
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
150 | char *idle_time; |
| 7014 | 151 | |
| 8006 | 152 | type = xmlnode_get_attrib(packet, "type"); |
| 7014 | 153 | from = xmlnode_get_attrib(packet, "from"); |
| 154 | id = xmlnode_get_attrib(packet, "id"); | |
| 155 | ||
| 8006 | 156 | if(type && !strcmp(type, "get")) { |
| 157 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:last"); | |
| 158 | jabber_iq_set_id(iq, id); | |
| 159 | xmlnode_set_attrib(iq->node, "to", from); | |
| 7014 | 160 | |
| 8006 | 161 | query = xmlnode_get_child(iq->node, "query"); |
| 7014 | 162 | |
|
14453
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
163 | 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
|
164 | xmlnode_set_attrib(query, "seconds", idle_time); |
|
1cc75906700c
[gaim-migrate @ 17098]
Mark Doliner <markdoliner@pidgin.im>
parents:
14375
diff
changeset
|
165 | g_free(idle_time); |
| 7401 | 166 | |
| 8006 | 167 | jabber_iq_send(iq); |
| 168 | } | |
| 7014 | 169 | } |
| 170 | ||
| 8312 | 171 | static void jabber_iq_time_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 172 | { |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
173 | const char *type, *from, *id, *xmlns; |
| 7014 | 174 | JabberIq *iq; |
| 175 | xmlnode *query; | |
| 176 | time_t now_t; | |
|
9709
2e73f176cc80
[gaim-migrate @ 10570]
Mark Doliner <markdoliner@pidgin.im>
parents:
8315
diff
changeset
|
177 | struct tm *now; |
|
9722
c1072806bcae
[gaim-migrate @ 10583]
Mark Doliner <markdoliner@pidgin.im>
parents:
9709
diff
changeset
|
178 | |
| 7014 | 179 | time(&now_t); |
|
9709
2e73f176cc80
[gaim-migrate @ 10570]
Mark Doliner <markdoliner@pidgin.im>
parents:
8315
diff
changeset
|
180 | now = localtime(&now_t); |
| 7014 | 181 | |
| 8006 | 182 | type = xmlnode_get_attrib(packet, "type"); |
| 7014 | 183 | from = xmlnode_get_attrib(packet, "from"); |
| 184 | id = xmlnode_get_attrib(packet, "id"); | |
| 185 | ||
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
186 | /* 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
|
187 | * 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
|
188 | * jabber:iq:time or urn:xmpp:time */ |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
189 | query = xmlnode_get_child(packet, "query"); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
190 | xmlns = xmlnode_get_namespace(query); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
191 | |
| 8006 | 192 | if(type && !strcmp(type, "get")) { |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
193 | xmlnode *utc; |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
12284
diff
changeset
|
194 | const char *date; |
| 7014 | 195 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
196 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, xmlns); |
| 8006 | 197 | jabber_iq_set_id(iq, id); |
| 198 | xmlnode_set_attrib(iq->node, "to", from); | |
| 199 | ||
| 200 | query = xmlnode_get_child(iq->node, "query"); | |
| 7014 | 201 | |
| 15884 | 202 | 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
|
203 | utc = xmlnode_new_child(query, "utc"); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
204 | xmlnode_insert_data(utc, date, -1); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
205 | |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
206 | if(!strcmp("urn:xmpp:time", xmlns)) { |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
207 | xmlnode_insert_data(utc, "Z", 1); /* of COURSE the thing that is the same is different */ |
| 10941 | 208 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
209 | date = purple_get_tzoff_str(now, TRUE); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
210 | 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
|
211 | } else { /* jabber:iq:time */ |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
212 | date = purple_utf8_strftime("%Z", now); |
|
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
213 | xmlnode_insert_data(xmlnode_new_child(query, "tz"), date, -1); |
| 10941 | 214 | |
|
18317
6c814e134e56
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18194
diff
changeset
|
215 | 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
|
216 | 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
|
217 | } |
| 7014 | 218 | |
| 8006 | 219 | jabber_iq_send(iq); |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
220 | } |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
221 | } |
|
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 | 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
|
224 | { |
|
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
|
225 | const char *type, *id, *from; |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
226 | JabberIq *iq; |
|
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 | 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
|
229 | 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
|
230 | 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
|
231 | |
|
18181
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
232 | if(type && !strcmp(type, "get")) { |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
233 | 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
|
234 | |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
235 | 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
|
236 | 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
|
237 | |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
238 | jabber_iq_send(iq); |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
239 | } else { |
|
736c6abf62f4
respond to XEP-0199 queries (XMPP ping)
Nathan Walp <nwalp@pidgin.im>
parents:
17753
diff
changeset
|
240 | /* XXX: error */ |
| 8006 | 241 | } |
| 7014 | 242 | } |
| 243 | ||
| 8312 | 244 | static void jabber_iq_version_parse(JabberStream *js, xmlnode *packet) |
| 7014 | 245 | { |
| 246 | JabberIq *iq; | |
| 8006 | 247 | const char *type, *from, *id; |
| 7014 | 248 | xmlnode *query; |
| 10941 | 249 | char *os = NULL; |
| 7014 | 250 | |
| 8006 | 251 | type = xmlnode_get_attrib(packet, "type"); |
| 252 | ||
| 253 | 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
|
254 | GHashTable *ui_info; |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
255 | const char *ui_name = NULL, *ui_version = NULL; |
| 10941 | 256 | |
| 15884 | 257 | if(!purple_prefs_get_bool("/plugins/prpl/jabber/hide_os")) { |
| 8006 | 258 | struct utsname osinfo; |
| 7014 | 259 | |
| 8006 | 260 | uname(&osinfo); |
| 261 | os = g_strdup_printf("%s %s %s", osinfo.sysname, osinfo.release, | |
| 262 | osinfo.machine); | |
| 263 | } | |
| 10941 | 264 | |
| 8006 | 265 | from = xmlnode_get_attrib(packet, "from"); |
| 266 | id = xmlnode_get_attrib(packet, "id"); | |
| 7014 | 267 | |
| 8006 | 268 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:version"); |
| 269 | xmlnode_set_attrib(iq->node, "to", from); | |
| 270 | jabber_iq_set_id(iq, id); | |
| 7014 | 271 | |
| 8006 | 272 | query = xmlnode_get_child(iq->node, "query"); |
| 7014 | 273 | |
|
18441
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
274 | 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
|
275 | |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
276 | 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
|
277 | 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
|
278 | 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
|
279 | } |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
280 | |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
281 | if(NULL != ui_name && NULL != ui_version) { |
| 18443 | 282 | char *version_complete = g_strdup_printf("%s (libpurple " VERSION ")", ui_version); |
| 283 | xmlnode_insert_data(xmlnode_new_child(query, "name"), ui_name, -1); | |
| 284 | xmlnode_insert_data(xmlnode_new_child(query, "version"), version_complete, -1); | |
| 285 | 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
|
286 | } else { |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
287 | 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
|
288 | 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
|
289 | } |
|
d255d04c0aa1
core support for UI info...now to do the UI piece
Nathan Walp <nwalp@pidgin.im>
parents:
18317
diff
changeset
|
290 | |
| 8006 | 291 | if(os) { |
| 292 | xmlnode_insert_data(xmlnode_new_child(query, "os"), os, -1); | |
| 293 | g_free(os); | |
| 294 | } | |
| 10941 | 295 | |
| 8006 | 296 | jabber_iq_send(iq); |
| 7014 | 297 | } |
| 298 | } | |
| 299 | ||
| 13794 | 300 | void jabber_iq_remove_callback_by_id(JabberStream *js, const char *id) |
| 301 | { | |
| 302 | g_hash_table_remove(js->iq_callbacks, id); | |
| 303 | } | |
| 304 | ||
| 7014 | 305 | void jabber_iq_parse(JabberStream *js, xmlnode *packet) |
| 306 | { | |
| 7395 | 307 | JabberCallbackData *jcd; |
| 8169 | 308 | xmlnode *query, *error, *x; |
| 7014 | 309 | const char *xmlns; |
| 8135 | 310 | const char *type, *id, *from; |
| 14356 | 311 | JabberIqHandler *jih; |
| 7014 | 312 | |
| 313 | query = xmlnode_get_child(packet, "query"); | |
| 8043 | 314 | type = xmlnode_get_attrib(packet, "type"); |
| 8135 | 315 | from = xmlnode_get_attrib(packet, "from"); |
| 8312 | 316 | id = xmlnode_get_attrib(packet, "id"); |
| 317 | ||
| 318 | /* First, lets see if a special callback got registered */ | |
| 319 | ||
| 320 | if(type && (!strcmp(type, "result") || !strcmp(type, "error"))) { | |
| 321 | if(id && *id && (jcd = g_hash_table_lookup(js->iq_callbacks, id))) { | |
| 322 | jcd->callback(js, packet, jcd->data); | |
| 13794 | 323 | jabber_iq_remove_callback_by_id(js, id); |
| 8314 | 324 | return; |
| 8312 | 325 | } |
| 326 | } | |
| 327 | ||
| 328 | /* Apparently not, so lets see if we have a pre-defined handler */ | |
| 7014 | 329 | |
| 13808 | 330 | if(type && query && (xmlns = xmlnode_get_namespace(query))) { |
| 14356 | 331 | if((jih = g_hash_table_lookup(iq_handlers, xmlns))) { |
| 332 | jih(js, packet); | |
| 8262 | 333 | return; |
| 334 | } | |
| 7395 | 335 | } |
| 336 | ||
| 14356 | 337 | if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) { |
| 338 | jabber_si_parse(js, packet); | |
| 339 | return; | |
| 340 | } | |
| 341 | ||
| 15225 | 342 | if(xmlnode_get_child_with_namespace(packet, "new-mail", "google:mail:notify")) { |
| 343 | jabber_gmail_poke(js, packet); | |
| 344 | return; | |
| 345 | } | |
| 346 | ||
| 8312 | 347 | /* If we get here, send the default error reply mandated by XMPP-CORE */ |
| 8315 | 348 | if(type && (!strcmp(type, "set") || !strcmp(type, "get"))) { |
| 349 | JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); | |
| 8135 | 350 | |
| 8315 | 351 | xmlnode_free(iq->node); |
| 352 | iq->node = xmlnode_copy(packet); | |
| 353 | xmlnode_set_attrib(iq->node, "to", from); | |
|
11825
fe23dc05a8a6
[gaim-migrate @ 14116]
Mark Doliner <markdoliner@pidgin.im>
parents:
11822
diff
changeset
|
354 | xmlnode_remove_attrib(iq->node, "from"); |
| 8315 | 355 | xmlnode_set_attrib(iq->node, "type", "error"); |
| 356 | error = xmlnode_new_child(iq->node, "error"); | |
| 357 | xmlnode_set_attrib(error, "type", "cancel"); | |
| 358 | xmlnode_set_attrib(error, "code", "501"); | |
| 359 | x = xmlnode_new_child(error, "feature-not-implemented"); | |
| 13808 | 360 | xmlnode_set_namespace(x, "urn:ietf:params:xml:ns:xmpp-stanzas"); |
| 8169 | 361 | |
| 8315 | 362 | jabber_iq_send(iq); |
| 363 | } | |
| 7014 | 364 | } |
| 365 | ||
| 14356 | 366 | void jabber_iq_register_handler(const char *xmlns, JabberIqHandler handlerfunc) |
| 367 | { | |
| 368 | g_hash_table_replace(iq_handlers, g_strdup(xmlns), handlerfunc); | |
| 369 | } | |
| 370 | ||
| 371 | void jabber_iq_init(void) | |
| 372 | { | |
| 373 | iq_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
| 374 | ||
| 375 | jabber_iq_register_handler("jabber:iq:roster", jabber_roster_parse); | |
| 376 | jabber_iq_register_handler("jabber:iq:oob", jabber_oob_parse); | |
| 377 | jabber_iq_register_handler("http://jabber.org/protocol/bytestreams", jabber_bytestreams_parse); | |
| 378 | jabber_iq_register_handler("jabber:iq:last", jabber_iq_last_parse); | |
| 379 | 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
|
380 | jabber_iq_register_handler("urn:xmpp:time", jabber_iq_time_parse); |
| 14356 | 381 | jabber_iq_register_handler("jabber:iq:version", jabber_iq_version_parse); |
| 382 | jabber_iq_register_handler("http://jabber.org/protocol/disco#info", jabber_disco_info_parse); | |
| 383 | jabber_iq_register_handler("http://jabber.org/protocol/disco#items", jabber_disco_items_parse); | |
| 384 | 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
|
385 | jabber_iq_register_handler("urn:xmpp:ping", urn_xmpp_ping_parse); |
| 14356 | 386 | } |
| 387 | ||
| 388 | void jabber_iq_uninit(void) | |
| 389 | { | |
| 390 | g_hash_table_destroy(iq_handlers); | |
| 391 | } | |
| 392 |