Mon, 25 Jun 2007 19:08:16 +0000
The server's ad-hoc commands are now listed in the account's action menu. Note that this requires an additional field in the _PurplePluginAction struct. There's no other way, since there was no way to supply user_data, and dynamically created functions are not supported by C. This should be fine, since that struct is only malloced in purple_plugin_action_new, which is part of the core. Applications have to either pass the struct unmodified, or restore the user_data pointer if the action is recreated when necessary (as is the case in Adium).
| 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" |
|
17816
1b7362b4a7a2
Implemented ad-hoc commands for the buddy action menu (untested), implemented the receiving end of XEP-0115: Entity Capabilities. Note that this seems not to be reliable right now, since some clients seem to have a very broken [read: completely non-functional] implementation (most notably Gajim and the py-transports).
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
34 | #include "adhoccommands.h" |
|
1b7362b4a7a2
Implemented ad-hoc commands for the buddy action menu (untested), implemented the receiving end of XEP-0115: Entity Capabilities. Note that this seems not to be reliable right now, since some clients seem to have a very broken [read: completely non-functional] implementation (most notably Gajim and the py-transports).
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
35 | |
| 8312 | 36 | |
| 37 | struct _jabber_disco_info_cb_data { | |
| 38 | gpointer data; | |
| 39 | JabberDiscoInfoCallback *callback; | |
| 40 | }; | |
| 41 | ||
|
17783
2687df1ca202
PEP publishing features are now only announced in disco#info when PEP is supported by the server.
Andreas Monitzer <am@adiumx.com>
parents:
17773
diff
changeset
|
42 | #define SUPPORT_FEATURE(x) { \ |
| 8312 | 43 | feature = xmlnode_new_child(query, "feature"); \ |
|
17783
2687df1ca202
PEP publishing features are now only announced in disco#info when PEP is supported by the server.
Andreas Monitzer <am@adiumx.com>
parents:
17773
diff
changeset
|
44 | xmlnode_set_attrib(feature, "var", x); \ |
|
2687df1ca202
PEP publishing features are now only announced in disco#info when PEP is supported by the server.
Andreas Monitzer <am@adiumx.com>
parents:
17773
diff
changeset
|
45 | } |
| 8312 | 46 | |
| 47 | ||
| 48 | void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) { | |
| 49 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 50 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 51 | ||
| 52 | if(!from || !type) | |
| 53 | return; | |
| 54 | ||
| 55 | if(!strcmp(type, "get")) { | |
| 56 | xmlnode *query, *identity, *feature; | |
| 13385 | 57 | JabberIq *iq; |
| 58 | ||
| 59 | xmlnode *in_query; | |
| 60 | const char *node = NULL; | |
| 61 | ||
| 62 | if((in_query = xmlnode_get_child(packet, "query"))) { | |
| 63 | node = xmlnode_get_attrib(in_query, "node"); | |
| 64 | } | |
| 65 | ||
| 66 | ||
| 67 | iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, | |
| 8312 | 68 | "http://jabber.org/protocol/disco#info"); |
| 69 | ||
| 70 | jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); | |
| 71 | ||
| 72 | xmlnode_set_attrib(iq->node, "to", from); | |
| 73 | query = xmlnode_get_child(iq->node, "query"); | |
| 74 | ||
| 13385 | 75 | if(node) |
| 76 | xmlnode_set_attrib(query, "node", node); | |
| 77 | ||
| 78 | if(!node || !strcmp(node, CAPS0115_NODE "#" VERSION)) { | |
| 79 | identity = xmlnode_new_child(query, "identity"); | |
| 80 | xmlnode_set_attrib(identity, "category", "client"); | |
| 81 | xmlnode_set_attrib(identity, "type", "pc"); /* XXX: bot, console, | |
| 82 | * handheld, pc, phone, | |
| 83 | * web */ | |
| 13704 | 84 | xmlnode_set_attrib(identity, "name", PACKAGE); |
| 8312 | 85 | |
| 13385 | 86 | SUPPORT_FEATURE("jabber:iq:last") |
| 87 | SUPPORT_FEATURE("jabber:iq:oob") | |
| 88 | SUPPORT_FEATURE("jabber:iq:time") | |
| 89 | SUPPORT_FEATURE("jabber:iq:version") | |
| 90 | SUPPORT_FEATURE("jabber:x:conference") | |
| 91 | SUPPORT_FEATURE("http://jabber.org/protocol/bytestreams") | |
| 92 | SUPPORT_FEATURE("http://jabber.org/protocol/disco#info") | |
| 93 | SUPPORT_FEATURE("http://jabber.org/protocol/disco#items") | |
| 8312 | 94 | #if 0 |
| 13385 | 95 | SUPPORT_FEATURE("http://jabber.org/protocol/ibb") |
| 8312 | 96 | #endif |
| 13385 | 97 | SUPPORT_FEATURE("http://jabber.org/protocol/muc") |
| 98 | SUPPORT_FEATURE("http://jabber.org/protocol/muc#user") | |
| 99 | SUPPORT_FEATURE("http://jabber.org/protocol/si") | |
| 100 | SUPPORT_FEATURE("http://jabber.org/protocol/si/profile/file-transfer") | |
| 101 | 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
|
102 | 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
|
103 | |
|
17783
2687df1ca202
PEP publishing features are now only announced in disco#info when PEP is supported by the server.
Andreas Monitzer <am@adiumx.com>
parents:
17773
diff
changeset
|
104 | if(!node) { /* non-caps disco#info, add all enabled extensions */ |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
105 | 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
|
106 | 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
|
107 | JabberFeature *feat = (JabberFeature*)features->data; |
|
17783
2687df1ca202
PEP publishing features are now only announced in disco#info when PEP is supported by the server.
Andreas Monitzer <am@adiumx.com>
parents:
17773
diff
changeset
|
108 | if(feat->is_enabled == NULL || feat->is_enabled(js, feat->shortname, feat->namespace) == TRUE) |
|
2687df1ca202
PEP publishing features are now only announced in disco#info when PEP is supported by the server.
Andreas Monitzer <am@adiumx.com>
parents:
17773
diff
changeset
|
109 | SUPPORT_FEATURE(feat->namespace); |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
110 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
111 | } |
| 13385 | 112 | } else { |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
113 | const char *ext = NULL; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
114 | unsigned pos; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
115 | unsigned nodelen = strlen(node); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
116 | unsigned capslen = strlen(CAPS0115_NODE); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
117 | /* do a basic plausability check */ |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
118 | if(nodelen > capslen+1) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
119 | /* 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
|
120 | 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
|
121 | if(pos == capslen) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
122 | if(node[pos] == '#') |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
123 | ext = &node[pos+1]; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
124 | else |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
125 | break; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
126 | } 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
|
127 | break; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
128 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
129 | |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
130 | if(ext != NULL) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
131 | /* look for that ext */ |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
132 | 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
|
133 | 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
|
134 | JabberFeature *feat = (JabberFeature*)features->data; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
135 | if(!strcmp(feat->shortname, ext)) { |
|
17783
2687df1ca202
PEP publishing features are now only announced in disco#info when PEP is supported by the server.
Andreas Monitzer <am@adiumx.com>
parents:
17773
diff
changeset
|
136 | SUPPORT_FEATURE(feat->namespace); |
|
2687df1ca202
PEP publishing features are now only announced in disco#info when PEP is supported by the server.
Andreas Monitzer <am@adiumx.com>
parents:
17773
diff
changeset
|
137 | break; |
|
17770
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 | if(features == NULL) |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
141 | ext = NULL; |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
142 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
143 | } |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
144 | |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
145 | if(ext == NULL) { |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
146 | xmlnode *error, *inf; |
| 13385 | 147 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
148 | /* 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
|
149 | 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
|
150 | iq->type = JABBER_IQ_ERROR; |
| 13385 | 151 | |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
152 | error = xmlnode_new_child(query, "error"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
153 | xmlnode_set_attrib(error, "code", "404"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
154 | xmlnode_set_attrib(error, "type", "cancel"); |
|
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17769
diff
changeset
|
155 | 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
|
156 | 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
|
157 | } |
| 13385 | 158 | } |
| 8312 | 159 | |
| 160 | jabber_iq_send(iq); | |
| 161 | } else if(!strcmp(type, "result")) { | |
| 162 | xmlnode *query = xmlnode_get_child(packet, "query"); | |
| 163 | xmlnode *child; | |
| 164 | JabberID *jid; | |
| 165 | JabberBuddy *jb; | |
| 166 | JabberBuddyResource *jbr = NULL; | |
| 167 | JabberCapabilities capabilities = JABBER_CAP_NONE; | |
| 168 | struct _jabber_disco_info_cb_data *jdicd; | |
| 169 | ||
| 170 | if((jid = jabber_id_new(from))) { | |
| 171 | if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE))) | |
| 172 | jbr = jabber_buddy_find_resource(jb, jid->resource); | |
| 173 | jabber_id_free(jid); | |
| 174 | } | |
| 175 | ||
| 176 | if(jbr) | |
| 177 | capabilities = jbr->capabilities; | |
| 178 | ||
| 179 | for(child = query->child; child; child = child->next) { | |
| 180 | if(child->type != XMLNODE_TYPE_TAG) | |
| 181 | continue; | |
| 182 | ||
| 183 | if(!strcmp(child->name, "identity")) { | |
| 184 | const char *category = xmlnode_get_attrib(child, "category"); | |
| 185 | const char *type = xmlnode_get_attrib(child, "type"); | |
| 186 | if(!category || !type) | |
| 187 | continue; | |
| 188 | ||
| 11675 | 189 | if(!strcmp(category, "conference") && !strcmp(type, "text")) { |
| 190 | /* we found a groupchat or MUC server, add it to the list */ | |
| 191 | /* XXX: actually check for protocol/muc or gc-1.0 support */ | |
| 8312 | 192 | js->chat_servers = g_list_append(js->chat_servers, g_strdup(from)); |
| 11675 | 193 | } else if(!strcmp(category, "directory") && !strcmp(type, "user")) { |
| 194 | /* we found a JUD */ | |
| 195 | js->user_directories = g_list_append(js->user_directories, g_strdup(from)); | |
| 196 | } | |
| 8312 | 197 | |
| 198 | } else if(!strcmp(child->name, "feature")) { | |
| 199 | const char *var = xmlnode_get_attrib(child, "var"); | |
| 200 | if(!var) | |
| 201 | continue; | |
| 202 | ||
| 203 | if(!strcmp(var, "http://jabber.org/protocol/si")) | |
| 204 | capabilities |= JABBER_CAP_SI; | |
| 205 | else if(!strcmp(var, "http://jabber.org/protocol/si/profile/file-transfer")) | |
| 206 | capabilities |= JABBER_CAP_SI_FILE_XFER; | |
| 207 | else if(!strcmp(var, "http://jabber.org/protocol/bytestreams")) | |
| 208 | capabilities |= JABBER_CAP_BYTESTREAMS; | |
| 11675 | 209 | else if(!strcmp(var, "jabber:iq:search")) |
| 210 | capabilities |= JABBER_CAP_IQ_SEARCH; | |
| 211 | else if(!strcmp(var, "jabber:iq:register")) | |
| 212 | capabilities |= JABBER_CAP_IQ_REGISTER; | |
|
17769
69d98a4da006
applied patch for supporting XEP-0199: XMPP Ping
Andreas Monitzer <am@adiumx.com>
parents:
17768
diff
changeset
|
213 | 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
|
214 | capabilities |= JABBER_CAP_PING; |
|
17816
1b7362b4a7a2
Implemented ad-hoc commands for the buddy action menu (untested), implemented the receiving end of XEP-0115: Entity Capabilities. Note that this seems not to be reliable right now, since some clients seem to have a very broken [read: completely non-functional] implementation (most notably Gajim and the py-transports).
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
215 | else if(!strcmp(var, "http://jabber.org/protocol/commands")) { |
|
1b7362b4a7a2
Implemented ad-hoc commands for the buddy action menu (untested), implemented the receiving end of XEP-0115: Entity Capabilities. Note that this seems not to be reliable right now, since some clients seem to have a very broken [read: completely non-functional] implementation (most notably Gajim and the py-transports).
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
216 | capabilities |= JABBER_CAP_ADHOC; |
|
1b7362b4a7a2
Implemented ad-hoc commands for the buddy action menu (untested), implemented the receiving end of XEP-0115: Entity Capabilities. Note that this seems not to be reliable right now, since some clients seem to have a very broken [read: completely non-functional] implementation (most notably Gajim and the py-transports).
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
217 | } |
| 8312 | 218 | } |
| 219 | } | |
| 220 | ||
| 221 | capabilities |= JABBER_CAP_RETRIEVED; | |
| 222 | ||
| 223 | if(jbr) | |
| 224 | jbr->capabilities = capabilities; | |
| 225 | ||
| 226 | if((jdicd = g_hash_table_lookup(js->disco_callbacks, from))) { | |
| 227 | jdicd->callback(js, from, capabilities, jdicd->data); | |
| 228 | g_hash_table_remove(js->disco_callbacks, from); | |
| 229 | } | |
| 230 | } else if(!strcmp(type, "error")) { | |
| 231 | JabberID *jid; | |
| 232 | JabberBuddy *jb; | |
| 233 | JabberBuddyResource *jbr = NULL; | |
| 234 | JabberCapabilities capabilities = JABBER_CAP_NONE; | |
| 235 | struct _jabber_disco_info_cb_data *jdicd; | |
| 236 | ||
| 237 | if(!(jdicd = g_hash_table_lookup(js->disco_callbacks, from))) | |
| 238 | return; | |
| 239 | ||
| 240 | if((jid = jabber_id_new(from))) { | |
| 241 | if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE))) | |
| 242 | jbr = jabber_buddy_find_resource(jb, jid->resource); | |
| 243 | jabber_id_free(jid); | |
| 244 | } | |
| 245 | ||
| 246 | if(jbr) | |
| 247 | capabilities = jbr->capabilities; | |
| 248 | ||
| 249 | jdicd->callback(js, from, capabilities, jdicd->data); | |
| 250 | g_hash_table_remove(js->disco_callbacks, from); | |
| 251 | } | |
| 252 | } | |
| 253 | ||
| 254 | void jabber_disco_items_parse(JabberStream *js, xmlnode *packet) { | |
| 255 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 256 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 257 | ||
| 14356 | 258 | if(type && !strcmp(type, "get")) { |
| 8312 | 259 | JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, |
| 260 | "http://jabber.org/protocol/disco#items"); | |
| 261 | ||
| 262 | jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); | |
| 263 | ||
| 264 | xmlnode_set_attrib(iq->node, "to", from); | |
| 265 | jabber_iq_send(iq); | |
| 266 | } | |
| 267 | } | |
| 268 | ||
| 269 | static void | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
270 | jabber_disco_finish_server_info_result_cb(JabberStream *js) |
| 15197 | 271 | { |
| 15884 | 272 | PurplePresence *gpresence; |
| 273 | PurpleStatus *status; | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
274 | |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
275 | if (!(js->server_caps & JABBER_CAP_GOOGLE_ROSTER)) { |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
276 | /* 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
|
277 | jabber_roster_request(js); |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
278 | } |
| 17421 | 279 | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
280 | /* Send initial presence; this will trigger receipt of presence for contacts on the roster */ |
| 15884 | 281 | gpresence = purple_account_get_presence(js->gc->account); |
| 282 | status = purple_presence_get_active_status(gpresence); | |
| 17421 | 283 | jabber_presence_send(js->gc->account, status); |
|
17817
8e0f271aab78
The server's ad-hoc commands are now listed in the account's action menu. Note that this requires an additional field in the _PurplePluginAction struct. There's no other way, since there was no way to supply user_data, and dynamically created functions are not supported by C. This should be fine, since that struct is only malloced in purple_plugin_action_new, which is part of the core. Applications have to either pass the struct unmodified, or restore the user_data pointer if the action is recreated when necessary (as is the case in Adium).
Andreas Monitzer <am@adiumx.com>
parents:
17816
diff
changeset
|
284 | |
|
8e0f271aab78
The server's ad-hoc commands are now listed in the account's action menu. Note that this requires an additional field in the _PurplePluginAction struct. There's no other way, since there was no way to supply user_data, and dynamically created functions are not supported by C. This should be fine, since that struct is only malloced in purple_plugin_action_new, which is part of the core. Applications have to either pass the struct unmodified, or restore the user_data pointer if the action is recreated when necessary (as is the case in Adium).
Andreas Monitzer <am@adiumx.com>
parents:
17816
diff
changeset
|
285 | if (js->server_caps & JABBER_CAP_ADHOC) { |
|
8e0f271aab78
The server's ad-hoc commands are now listed in the account's action menu. Note that this requires an additional field in the _PurplePluginAction struct. There's no other way, since there was no way to supply user_data, and dynamically created functions are not supported by C. This should be fine, since that struct is only malloced in purple_plugin_action_new, which is part of the core. Applications have to either pass the struct unmodified, or restore the user_data pointer if the action is recreated when necessary (as is the case in Adium).
Andreas Monitzer <am@adiumx.com>
parents:
17816
diff
changeset
|
286 | /* The server supports ad-hoc commands, so let's request the list */ |
|
8e0f271aab78
The server's ad-hoc commands are now listed in the account's action menu. Note that this requires an additional field in the _PurplePluginAction struct. There's no other way, since there was no way to supply user_data, and dynamically created functions are not supported by C. This should be fine, since that struct is only malloced in purple_plugin_action_new, which is part of the core. Applications have to either pass the struct unmodified, or restore the user_data pointer if the action is recreated when necessary (as is the case in Adium).
Andreas Monitzer <am@adiumx.com>
parents:
17816
diff
changeset
|
287 | jabber_adhoc_server_get_list(js); |
|
8e0f271aab78
The server's ad-hoc commands are now listed in the account's action menu. Note that this requires an additional field in the _PurplePluginAction struct. There's no other way, since there was no way to supply user_data, and dynamically created functions are not supported by C. This should be fine, since that struct is only malloced in purple_plugin_action_new, which is part of the core. Applications have to either pass the struct unmodified, or restore the user_data pointer if the action is recreated when necessary (as is the case in Adium).
Andreas Monitzer <am@adiumx.com>
parents:
17816
diff
changeset
|
288 | } |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
289 | } |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
290 | |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
291 | static void |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
292 | 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
|
293 | { |
| 17421 | 294 | xmlnode *query, *child; |
| 15197 | 295 | const char *from = xmlnode_get_attrib(packet, "from"); |
| 296 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 297 | ||
|
15358
c8179e0a5483
[gaim-migrate @ 18087]
Evan Schoenberg <evands@pidgin.im>
parents:
15355
diff
changeset
|
298 | if((!from || !type) || |
|
c8179e0a5483
[gaim-migrate @ 18087]
Evan Schoenberg <evands@pidgin.im>
parents:
15355
diff
changeset
|
299 | (strcmp(from, js->user->domain))) { |
|
c8179e0a5483
[gaim-migrate @ 18087]
Evan Schoenberg <evands@pidgin.im>
parents:
15355
diff
changeset
|
300 | jabber_disco_finish_server_info_result_cb(js); |
| 15197 | 301 | return; |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
302 | } |
| 15197 | 303 | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
304 | if(strcmp(type, "result")) { |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
305 | /* 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
|
306 | jabber_disco_finish_server_info_result_cb(js); |
| 15197 | 307 | return; |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
308 | } |
| 15197 | 309 | |
| 310 | query = xmlnode_get_child(packet, "query"); | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
311 | |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
312 | if (!query) { |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
313 | jabber_disco_finish_server_info_result_cb(js); |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
314 | return; |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
315 | } |
|
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
316 | |
| 17421 | 317 | for (child = xmlnode_get_child(query, "identity"); child; |
| 15197 | 318 | child = xmlnode_get_next_twin(child)) { |
| 319 | const char *category, *type, *name; | |
| 320 | category = xmlnode_get_attrib(child, "category"); | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17423
diff
changeset
|
321 | 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
|
322 | 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
|
323 | js->pep = TRUE; |
| 15197 | 324 | if (!category || strcmp(category, "server")) |
| 325 | continue; | |
| 326 | if (!type || strcmp(type, "im")) | |
| 327 | continue; | |
| 17421 | 328 | |
| 15197 | 329 | name = xmlnode_get_attrib(child, "name"); |
| 330 | if (!name) | |
| 331 | continue; | |
| 332 | ||
| 333 | g_free(js->server_name); | |
| 334 | 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
|
335 | if (!strcmp(name, "Google Talk")) { |
| 15884 | 336 | 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
|
337 | js->googletalk = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
338 | } |
| 15197 | 339 | } |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
340 | |
| 17421 | 341 | for (child = xmlnode_get_child(query, "feature"); child; |
| 15225 | 342 | child = xmlnode_get_next_twin(child)) { |
| 343 | const char *var; | |
| 344 | var = xmlnode_get_attrib(child, "var"); | |
| 345 | if (!var) | |
| 346 | continue; | |
| 347 | ||
| 348 | if (!strcmp("google:mail:notify", var)) { | |
| 349 | js->server_caps |= JABBER_CAP_GMAIL_NOTIFY; | |
| 350 | jabber_gmail_init(js); | |
| 15265 | 351 | } else if (!strcmp("google:roster", var)) { |
| 352 | js->server_caps |= JABBER_CAP_GOOGLE_ROSTER; | |
| 353 | jabber_google_roster_init(js); | |
|
17817
8e0f271aab78
The server's ad-hoc commands are now listed in the account's action menu. Note that this requires an additional field in the _PurplePluginAction struct. There's no other way, since there was no way to supply user_data, and dynamically created functions are not supported by C. This should be fine, since that struct is only malloced in purple_plugin_action_new, which is part of the core. Applications have to either pass the struct unmodified, or restore the user_data pointer if the action is recreated when necessary (as is the case in Adium).
Andreas Monitzer <am@adiumx.com>
parents:
17816
diff
changeset
|
354 | } else if (!strcmp("http://jabber.org/protocol/commands", var)) { |
|
8e0f271aab78
The server's ad-hoc commands are now listed in the account's action menu. Note that this requires an additional field in the _PurplePluginAction struct. There's no other way, since there was no way to supply user_data, and dynamically created functions are not supported by C. This should be fine, since that struct is only malloced in purple_plugin_action_new, which is part of the core. Applications have to either pass the struct unmodified, or restore the user_data pointer if the action is recreated when necessary (as is the case in Adium).
Andreas Monitzer <am@adiumx.com>
parents:
17816
diff
changeset
|
355 | js->server_caps |= JABBER_CAP_ADHOC; |
| 15225 | 356 | } |
| 357 | } | |
| 15265 | 358 | |
|
15355
1ce281d16071
[gaim-migrate @ 18084]
Evan Schoenberg <evands@pidgin.im>
parents:
15344
diff
changeset
|
359 | jabber_disco_finish_server_info_result_cb(js); |
| 15197 | 360 | } |
| 361 | ||
| 362 | static void | |
| 363 | jabber_disco_server_items_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 8312 | 364 | { |
| 365 | xmlnode *query, *child; | |
| 366 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 367 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 368 | ||
| 369 | if(!from || !type) | |
| 370 | return; | |
| 371 | ||
| 372 | if(strcmp(from, js->user->domain)) | |
| 373 | return; | |
| 374 | ||
| 375 | if(strcmp(type, "result")) | |
| 376 | return; | |
| 377 | ||
| 378 | while(js->chat_servers) { | |
| 379 | g_free(js->chat_servers->data); | |
| 380 | js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers); | |
| 381 | } | |
| 382 | ||
| 383 | query = xmlnode_get_child(packet, "query"); | |
| 384 | ||
| 385 | for(child = xmlnode_get_child(query, "item"); child; | |
| 386 | child = xmlnode_get_next_twin(child)) { | |
| 387 | 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
|
388 | const char *jid, *node; |
| 8312 | 389 | |
| 390 | if(!(jid = xmlnode_get_attrib(child, "jid"))) | |
| 391 | continue; | |
| 392 | ||
|
17423
1f3a88fda48e
skip some unneeded queries that we don't particularly need or want
Nathan Walp <nwalp@pidgin.im>
parents:
17421
diff
changeset
|
393 | /* 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
|
394 | * 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
|
395 | 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
|
396 | continue; |
|
1f3a88fda48e
skip some unneeded queries that we don't particularly need or want
Nathan Walp <nwalp@pidgin.im>
parents:
17421
diff
changeset
|
397 | |
| 8312 | 398 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info"); |
| 399 | xmlnode_set_attrib(iq->node, "to", jid); | |
| 400 | jabber_iq_send(iq); | |
| 401 | } | |
| 402 | } | |
| 403 | ||
| 404 | void jabber_disco_items_server(JabberStream *js) | |
| 405 | { | |
| 406 | JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET, | |
| 407 | "http://jabber.org/protocol/disco#items"); | |
| 408 | ||
| 409 | xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
| 410 | ||
| 15197 | 411 | jabber_iq_set_callback(iq, jabber_disco_server_items_result_cb, NULL); |
| 412 | jabber_iq_send(iq); | |
| 413 | ||
| 414 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, | |
| 415 | "http://jabber.org/protocol/disco#info"); | |
| 416 | xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
| 417 | jabber_iq_set_callback(iq, jabber_disco_server_info_result_cb, NULL); | |
| 8312 | 418 | jabber_iq_send(iq); |
| 419 | } | |
| 420 | ||
| 421 | void jabber_disco_info_do(JabberStream *js, const char *who, JabberDiscoInfoCallback *callback, gpointer data) | |
| 422 | { | |
| 423 | JabberID *jid; | |
| 424 | JabberBuddy *jb; | |
| 425 | JabberBuddyResource *jbr = NULL; | |
| 426 | struct _jabber_disco_info_cb_data *jdicd; | |
| 427 | JabberIq *iq; | |
| 428 | ||
| 429 | if((jid = jabber_id_new(who))) { | |
| 430 | if(jid->resource && (jb = jabber_buddy_find(js, who, TRUE))) | |
| 431 | jbr = jabber_buddy_find_resource(jb, jid->resource); | |
| 432 | jabber_id_free(jid); | |
| 433 | } | |
| 434 | ||
| 435 | if(jbr && jbr->capabilities & JABBER_CAP_RETRIEVED) { | |
| 436 | callback(js, who, jbr->capabilities, data); | |
| 437 | return; | |
| 438 | } | |
| 439 | ||
| 440 | jdicd = g_new0(struct _jabber_disco_info_cb_data, 1); | |
| 441 | jdicd->data = data; | |
| 442 | jdicd->callback = callback; | |
| 443 | ||
| 444 | g_hash_table_insert(js->disco_callbacks, g_strdup(who), jdicd); | |
| 445 | ||
| 446 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info"); | |
| 447 | xmlnode_set_attrib(iq->node, "to", who); | |
| 448 | ||
| 449 | jabber_iq_send(iq); | |
| 450 | } | |
| 451 | ||
| 452 |