Wed, 06 Jun 2007 02:07:53 +0000
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
| 8312 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 8312 | 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 | ||
| 22 | #include "internal.h" | |
| 23 | #include "prefs.h" | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
24 | #include "debug.h" |
| 8312 | 25 | |
| 26 | #include "buddy.h" | |
| 15225 | 27 | #include "google.h" |
| 8312 | 28 | #include "iq.h" |
| 29 | #include "disco.h" | |
| 13385 | 30 | #include "jabber.h" |
|
15344
34b7f4e55861
[gaim-migrate @ 18072]
Evan Schoenberg <evands@pidgin.im>
parents:
15323
diff
changeset
|
31 | #include "presence.h" |
| 15265 | 32 | #include "roster.h" |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17423
diff
changeset
|
33 | #include "pep.h" |
| 8312 | 34 | |
| 35 | struct _jabber_disco_info_cb_data { | |
| 36 | gpointer data; | |
| 37 | JabberDiscoInfoCallback *callback; | |
| 38 | }; | |
| 39 | ||
| 40 | #define SUPPORT_FEATURE(x) \ | |
| 41 | feature = xmlnode_new_child(query, "feature"); \ | |
| 42 | xmlnode_set_attrib(feature, "var", x); | |
| 43 | ||
| 44 | ||
| 45 | void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) { | |
| 46 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 47 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 48 | ||
| 49 | if(!from || !type) | |
| 50 | return; | |
| 51 | ||
| 52 | if(!strcmp(type, "get")) { | |
| 53 | xmlnode *query, *identity, *feature; | |
| 13385 | 54 | JabberIq *iq; |
| 55 | ||
| 56 | xmlnode *in_query; | |
| 57 | const char *node = NULL; | |
| 58 | ||
| 59 | if((in_query = xmlnode_get_child(packet, "query"))) { | |
| 60 | node = xmlnode_get_attrib(in_query, "node"); | |
| 61 | } | |
| 62 | ||
| 63 | ||
| 64 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, | |
| 8312 | 65 | "http://jabber.org/protocol/disco#info"); |
| 66 | ||
| 67 | jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); | |
| 68 | ||
| 69 | xmlnode_set_attrib(iq->node, "to", from); | |
| 70 | query = xmlnode_get_child(iq->node, "query"); | |
| 71 | ||
| 13385 | 72 | if(node) |
| 73 | xmlnode_set_attrib(query, "node", node); | |
| 74 | ||
| 75 | if(!node || !strcmp(node, CAPS0115_NODE "#" VERSION)) { | |
| 76 | identity = xmlnode_new_child(query, "identity"); | |
| 77 | xmlnode_set_attrib(identity, "category", "client"); | |
| 78 | xmlnode_set_attrib(identity, "type", "pc"); /* XXX: bot, console, | |
| 79 | * handheld, pc, phone, | |
| 80 | * web */ | |
| 13704 | 81 | xmlnode_set_attrib(identity, "name", PACKAGE); |
| 8312 | 82 | |
| 13385 | 83 | SUPPORT_FEATURE("jabber:iq:last") |
| 84 | SUPPORT_FEATURE("jabber:iq:oob") | |
| 85 | SUPPORT_FEATURE("jabber:iq:time") | |
| 86 | SUPPORT_FEATURE("jabber:iq:version") | |
| 87 | SUPPORT_FEATURE("jabber:x:conference") | |
| 88 | SUPPORT_FEATURE("http://jabber.org/protocol/bytestreams") | |
| 89 | SUPPORT_FEATURE("http://jabber.org/protocol/disco#info") | |
| 90 | SUPPORT_FEATURE("http://jabber.org/protocol/disco#items") | |
| 8312 | 91 | #if 0 |
| 13385 | 92 | SUPPORT_FEATURE("http://jabber.org/protocol/ibb") |
| 8312 | 93 | #endif |
| 13385 | 94 | SUPPORT_FEATURE("http://jabber.org/protocol/muc") |
| 95 | SUPPORT_FEATURE("http://jabber.org/protocol/muc#user") | |
| 96 | SUPPORT_FEATURE("http://jabber.org/protocol/si") | |
| 97 | SUPPORT_FEATURE("http://jabber.org/protocol/si/profile/file-transfer") | |
| 98 | SUPPORT_FEATURE("http://jabber.org/protocol/xhtml-im") | |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
17768
diff
changeset
|
99 | SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0199.html#ns") |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
100 | |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
101 | if(!node) { /* non-caps disco#info, add all extensions */ |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
102 | GList *features; |
|
17773
6956b763b3d1
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
103 | for(features = jabber_features; features; features = features->next) { |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
104 | JabberFeature *feat = (JabberFeature*)features->data; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
105 | SUPPORT_FEATURE(feat->namespace); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
106 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
107 | } |
| 13385 | 108 | } else { |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
109 | const char *ext = NULL; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
110 | unsigned pos; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
111 | unsigned nodelen = strlen(node); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
112 | unsigned capslen = strlen(CAPS0115_NODE); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
113 | /* do a basic plausability check */ |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
114 | if(nodelen > capslen+1) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
115 | /* verify that the string is CAPS0115#<ext> and get the pointer to the ext part */ |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
116 | for(pos = 0; pos < capslen+1; ++pos) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
117 | if(pos == capslen) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
118 | if(node[pos] == '#') |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
119 | ext = &node[pos+1]; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
120 | else |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
121 | break; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
122 | } else if(node[pos] != CAPS0115_NODE[pos]) |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
123 | break; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
124 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
125 | |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
126 | if(ext != NULL) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
127 | /* look for that ext */ |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
128 | GList *features; |
|
17773
6956b763b3d1
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
129 | for(features = jabber_features; features; features = features->next) { |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
130 | JabberFeature *feat = (JabberFeature*)features->data; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
131 | if(!strcmp(feat->shortname, ext)) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
132 | SUPPORT_FEATURE(feat->namespace); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
133 | break; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
134 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
135 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
136 | if(features == NULL) |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
137 | ext = NULL; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
138 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
139 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
140 | |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
141 | if(ext == NULL) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
142 | xmlnode *error, *inf; |
| 13385 | 143 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
144 | /* XXX: gross hack, implement jabber_iq_set_type or something */ |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
145 | xmlnode_set_attrib(iq->node, "type", "error"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
146 | iq->type = JABBER_IQ_ERROR; |
| 13385 | 147 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
148 | error = xmlnode_new_child(query, "error"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
149 | xmlnode_set_attrib(error, "code", "404"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
150 | xmlnode_set_attrib(error, "type", "cancel"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
151 | inf = xmlnode_new_child(error, "item-not-found"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
152 | xmlnode_set_namespace(inf, "urn:ietf:params:xml:ns:xmpp-stanzas"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
153 | } |
| 13385 | 154 | } |
| 8312 | 155 | |
| 156 | jabber_iq_send(iq); | |
| 157 | } else if(!strcmp(type, "result")) { | |
| 158 | xmlnode *query = xmlnode_get_child(packet, "query"); | |
| 159 | xmlnode *child; | |
| 160 | JabberID *jid; | |
| 161 | JabberBuddy *jb; | |
| 162 | JabberBuddyResource *jbr = NULL; | |
| 163 | JabberCapabilities capabilities = JABBER_CAP_NONE; | |
| 164 | struct _jabber_disco_info_cb_data *jdicd; | |
| 165 | ||
| 166 | if((jid = jabber_id_new(from))) { | |
| 167 | if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE))) | |
| 168 | jbr = jabber_buddy_find_resource(jb, jid->resource); | |
| 169 | jabber_id_free(jid); | |
| 170 | } | |
| 171 | ||
| 172 | if(jbr) | |
| 173 | capabilities = jbr->capabilities; | |
| 174 | ||
| 175 | for(child = query->child; child; child = child->next) { | |
| 176 | if(child->type != XMLNODE_TYPE_TAG) | |
| 177 | continue; | |
| 178 | ||
| 179 | if(!strcmp(child->name, "identity")) { | |
| 180 | const char *category = xmlnode_get_attrib(child, "category"); | |
| 181 | const char *type = xmlnode_get_attrib(child, "type"); | |
| 182 | if(!category || !type) | |
| 183 | continue; | |
| 184 | ||
| 11675 | 185 | if(!strcmp(category, "conference") && !strcmp(type, "text")) { |
| 186 | /* we found a groupchat or MUC server, add it to the list */ | |
| 187 | /* XXX: actually check for protocol/muc or gc-1.0 support */ | |
| 8312 | 188 | js->chat_servers = g_list_append(js->chat_servers, g_strdup(from)); |
| 11675 | 189 | } else if(!strcmp(category, "directory") && !strcmp(type, "user")) { |
| 190 | /* we found a JUD */ | |
| 191 | js->user_directories = g_list_append(js->user_directories, g_strdup(from)); | |
| 192 | } | |
| 8312 | 193 | |
| 194 | } else if(!strcmp(child->name, "feature")) { | |
| 195 | const char *var = xmlnode_get_attrib(child, "var"); | |
| 196 | if(!var) | |
| 197 | continue; | |
| 198 | ||
| 199 | if(!strcmp(var, "http://jabber.org/protocol/si")) | |
| 200 | capabilities |= JABBER_CAP_SI; | |
| 201 | else if(!strcmp(var, "http://jabber.org/protocol/si/profile/file-transfer")) | |
| 202 | capabilities |= JABBER_CAP_SI_FILE_XFER; | |
| 203 | else if(!strcmp(var, "http://jabber.org/protocol/bytestreams")) | |
| 204 | capabilities |= JABBER_CAP_BYTESTREAMS; | |
| 11675 | 205 | else if(!strcmp(var, "jabber:iq:search")) |
| 206 | capabilities |= JABBER_CAP_IQ_SEARCH; | |
| 207 | else if(!strcmp(var, "jabber:iq:register")) | |
| 208 | capabilities |= JABBER_CAP_IQ_REGISTER; | |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
17768
diff
changeset
|
209 | else if(!strcmp(var, "http://www.xmpp.org/extensions/xep-0199.html#ns")) |
|
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
17768
diff
changeset
|
210 | capabilities |= JABBER_CAP_PING; |
| 8312 | 211 | } |
| 212 | } | |
| 213 | ||
| 214 | capabilities |= JABBER_CAP_RETRIEVED; | |
| 215 | ||
| 216 | if(jbr) | |
| 217 | jbr->capabilities = capabilities; | |
| 218 | ||
| 219 | if((jdicd = g_hash_table_lookup(js->disco_callbacks, from))) { | |
| 220 | jdicd->callback(js, from, capabilities, jdicd->data); | |
| 221 | g_hash_table_remove(js->disco_callbacks, from); | |
| 222 | } | |
| 223 | } else if(!strcmp(type, "error")) { | |
| 224 | JabberID *jid; | |
| 225 | JabberBuddy *jb; | |
| 226 | JabberBuddyResource *jbr = NULL; | |
| 227 | JabberCapabilities capabilities = JABBER_CAP_NONE; | |
| 228 | struct _jabber_disco_info_cb_data *jdicd; | |
| 229 | ||
| 230 | if(!(jdicd = g_hash_table_lookup(js->disco_callbacks, from))) | |
| 231 | return; | |
| 232 | ||
| 233 | if((jid = jabber_id_new(from))) { | |
| 234 | if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE))) | |
| 235 | jbr = jabber_buddy_find_resource(jb, jid->resource); | |
| 236 | jabber_id_free(jid); | |
| 237 | } | |
| 238 | ||
| 239 | if(jbr) | |
| 240 | capabilities = jbr->capabilities; | |
| 241 | ||
| 242 | jdicd->callback(js, from, capabilities, jdicd->data); | |
| 243 | g_hash_table_remove(js->disco_callbacks, from); | |
| 244 | } | |
| 245 | } | |
| 246 | ||
| 247 | void jabber_disco_items_parse(JabberStream *js, xmlnode *packet) { | |
| 248 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 249 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 250 | ||
| 14356 | 251 | if(type && !strcmp(type, "get")) { |
| 8312 | 252 | JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, |
| 253 | "http://jabber.org/protocol/disco#items"); | |
| 254 | ||
| 255 | jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); | |
| 256 | ||
| 257 | xmlnode_set_attrib(iq->node, "to", from); | |
| 258 | jabber_iq_send(iq); | |
| 259 | } | |
| 260 | } | |
| 261 | ||
| 262 | static void | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
263 | jabber_disco_finish_server_info_result_cb(JabberStream *js) |
| 15197 | 264 | { |
| 15884 | 265 | PurplePresence *gpresence; |
| 266 | PurpleStatus *status; | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
267 | |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
268 | if (!(js->server_caps & JABBER_CAP_GOOGLE_ROSTER)) { |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
269 | /* If the server supports JABBER_CAP_GOOGLE_ROSTER; we will have already requested it */ |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
270 | jabber_roster_request(js); |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
271 | } |
| 17421 | 272 | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
273 | /* Send initial presence; this will trigger receipt of presence for contacts on the roster */ |
| 15884 | 274 | gpresence = purple_account_get_presence(js->gc->account); |
| 275 | status = purple_presence_get_active_status(gpresence); | |
| 17421 | 276 | jabber_presence_send(js->gc->account, status); |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
277 | } |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
278 | |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
279 | static void |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
280 | jabber_disco_server_info_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
281 | { |
| 17421 | 282 | xmlnode *query, *child; |
| 15197 | 283 | const char *from = xmlnode_get_attrib(packet, "from"); |
| 284 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 285 | ||
|
15358
c8179e0a5483
[gaim-migrate @ 18087]
Evan Schoenberg <evands@pidgin.im>
parents:
15355
diff
changeset
|
286 | if((!from || !type) || |
|
c8179e0a5483
[gaim-migrate @ 18087]
Evan Schoenberg <evands@pidgin.im>
parents:
15355
diff
changeset
|
287 | (strcmp(from, js->user->domain))) { |
|
c8179e0a5483
[gaim-migrate @ 18087]
Evan Schoenberg <evands@pidgin.im>
parents:
15355
diff
changeset
|
288 | jabber_disco_finish_server_info_result_cb(js); |
| 15197 | 289 | return; |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
290 | } |
| 15197 | 291 | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
292 | if(strcmp(type, "result")) { |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
293 | /* A common way to get here is for the server not to support xmlns http://jabber.org/protocol/disco#info */ |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
294 | jabber_disco_finish_server_info_result_cb(js); |
| 15197 | 295 | return; |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
296 | } |
| 15197 | 297 | |
| 298 | query = xmlnode_get_child(packet, "query"); | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
299 | |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
300 | if (!query) { |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
301 | jabber_disco_finish_server_info_result_cb(js); |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
302 | return; |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
303 | } |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
304 | |
| 17421 | 305 | for (child = xmlnode_get_child(query, "identity"); child; |
| 15197 | 306 | child = xmlnode_get_next_twin(child)) { |
| 307 | const char *category, *type, *name; | |
| 308 | category = xmlnode_get_attrib(child, "category"); | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17423
diff
changeset
|
309 | type = xmlnode_get_attrib(child, "type"); |
|
17773
6956b763b3d1
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
310 | if(category && type && !strcmp(category, "pubsub") && !strcmp(type,"pep")) |
|
6956b763b3d1
Implemented adding callbacks for PEP events. Moved the feature list to be application-global instead of per-connection (makes more sense).
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
311 | js->pep = TRUE; |
| 15197 | 312 | if (!category || strcmp(category, "server")) |
| 313 | continue; | |
| 314 | if (!type || strcmp(type, "im")) | |
| 315 | continue; | |
| 17421 | 316 | |
| 15197 | 317 | name = xmlnode_get_attrib(child, "name"); |
| 318 | if (!name) | |
| 319 | continue; | |
| 320 | ||
| 321 | g_free(js->server_name); | |
| 322 | js->server_name = g_strdup(name); | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
323 | if (!strcmp(name, "Google Talk")) { |
| 15884 | 324 | purple_debug_info("jabber", "Google Talk!"); |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
325 | js->googletalk = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
326 | } |
| 15197 | 327 | } |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
328 | |
| 17421 | 329 | for (child = xmlnode_get_child(query, "feature"); child; |
| 15225 | 330 | child = xmlnode_get_next_twin(child)) { |
| 331 | const char *var; | |
| 332 | var = xmlnode_get_attrib(child, "var"); | |
| 333 | if (!var) | |
| 334 | continue; | |
| 335 | ||
| 336 | if (!strcmp("google:mail:notify", var)) { | |
| 337 | js->server_caps |= JABBER_CAP_GMAIL_NOTIFY; | |
| 338 | jabber_gmail_init(js); | |
| 15265 | 339 | } else if (!strcmp("google:roster", var)) { |
| 340 | js->server_caps |= JABBER_CAP_GOOGLE_ROSTER; | |
| 341 | jabber_google_roster_init(js); | |
| 15225 | 342 | } |
| 343 | } | |
| 15265 | 344 | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
345 | jabber_disco_finish_server_info_result_cb(js); |
| 15197 | 346 | } |
| 347 | ||
| 348 | static void | |
| 349 | jabber_disco_server_items_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 8312 | 350 | { |
| 351 | xmlnode *query, *child; | |
| 352 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 353 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 354 | ||
| 355 | if(!from || !type) | |
| 356 | return; | |
| 357 | ||
| 358 | if(strcmp(from, js->user->domain)) | |
| 359 | return; | |
| 360 | ||
| 361 | if(strcmp(type, "result")) | |
| 362 | return; | |
| 363 | ||
| 364 | while(js->chat_servers) { | |
| 365 | g_free(js->chat_servers->data); | |
| 366 | js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers); | |
| 367 | } | |
| 368 | ||
| 369 | query = xmlnode_get_child(packet, "query"); | |
| 370 | ||
| 371 | for(child = xmlnode_get_child(query, "item"); child; | |
| 372 | child = xmlnode_get_next_twin(child)) { | |
| 373 | JabberIq *iq; | |
|
17423
1f3a88fda48e
skip some unneeded queries that we don't particularly need or want
Nathan Walp <nwalp@pidgin.im>
parents:
17421
diff
changeset
|
374 | const char *jid, *node; |
| 8312 | 375 | |
| 376 | if(!(jid = xmlnode_get_attrib(child, "jid"))) | |
| 377 | continue; | |
| 378 | ||
|
17423
1f3a88fda48e
skip some unneeded queries that we don't particularly need or want
Nathan Walp <nwalp@pidgin.im>
parents:
17421
diff
changeset
|
379 | /* we don't actually care about the specific nodes, |
|
1f3a88fda48e
skip some unneeded queries that we don't particularly need or want
Nathan Walp <nwalp@pidgin.im>
parents:
17421
diff
changeset
|
380 | * so we won't query them */ |
|
1f3a88fda48e
skip some unneeded queries that we don't particularly need or want
Nathan Walp <nwalp@pidgin.im>
parents:
17421
diff
changeset
|
381 | if((node = xmlnode_get_attrib(child, "node"))) |
|
1f3a88fda48e
skip some unneeded queries that we don't particularly need or want
Nathan Walp <nwalp@pidgin.im>
parents:
17421
diff
changeset
|
382 | continue; |
|
1f3a88fda48e
skip some unneeded queries that we don't particularly need or want
Nathan Walp <nwalp@pidgin.im>
parents:
17421
diff
changeset
|
383 | |
| 8312 | 384 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info"); |
| 385 | xmlnode_set_attrib(iq->node, "to", jid); | |
| 386 | jabber_iq_send(iq); | |
| 387 | } | |
| 388 | } | |
| 389 | ||
| 390 | void jabber_disco_items_server(JabberStream *js) | |
| 391 | { | |
| 392 | JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET, | |
| 393 | "http://jabber.org/protocol/disco#items"); | |
| 394 | ||
| 395 | xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
| 396 | ||
| 15197 | 397 | jabber_iq_set_callback(iq, jabber_disco_server_items_result_cb, NULL); |
| 398 | jabber_iq_send(iq); | |
| 399 | ||
| 400 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, | |
| 401 | "http://jabber.org/protocol/disco#info"); | |
| 402 | xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
| 403 | jabber_iq_set_callback(iq, jabber_disco_server_info_result_cb, NULL); | |
| 8312 | 404 | jabber_iq_send(iq); |
| 405 | } | |
| 406 | ||
| 407 | void jabber_disco_info_do(JabberStream *js, const char *who, JabberDiscoInfoCallback *callback, gpointer data) | |
| 408 | { | |
| 409 | JabberID *jid; | |
| 410 | JabberBuddy *jb; | |
| 411 | JabberBuddyResource *jbr = NULL; | |
| 412 | struct _jabber_disco_info_cb_data *jdicd; | |
| 413 | JabberIq *iq; | |
| 414 | ||
| 415 | if((jid = jabber_id_new(who))) { | |
| 416 | if(jid->resource && (jb = jabber_buddy_find(js, who, TRUE))) | |
| 417 | jbr = jabber_buddy_find_resource(jb, jid->resource); | |
| 418 | jabber_id_free(jid); | |
| 419 | } | |
| 420 | ||
| 421 | if(jbr && jbr->capabilities & JABBER_CAP_RETRIEVED) { | |
| 422 | callback(js, who, jbr->capabilities, data); | |
| 423 | return; | |
| 424 | } | |
| 425 | ||
| 426 | jdicd = g_new0(struct _jabber_disco_info_cb_data, 1); | |
| 427 | jdicd->data = data; | |
| 428 | jdicd->callback = callback; | |
| 429 | ||
| 430 | g_hash_table_insert(js->disco_callbacks, g_strdup(who), jdicd); | |
| 431 | ||
| 432 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info"); | |
| 433 | xmlnode_set_attrib(iq->node, "to", who); | |
| 434 | ||
| 435 | jabber_iq_send(iq); | |
| 436 | } | |
| 437 | ||
| 438 |