comparison libpurple/protocols/jabber/disco.c @ 25124:ba362a67278c

propagate from branch 'im.pidgin.pidgin' (head 2747d5e0324ca6b81e83bbb8b75e1efebcbbad6e) to branch 'im.pidgin.soc.2008.xmpp' (head 72d6870ed2c62423a05ed89822db25d9916ecf2b)
author Tobias Markmann <tfar@soc.pidgin.im>
date Sun, 03 Aug 2008 23:16:24 +0000
parents 10382f1e1353 2a6a37c7970b
children 1225f3dcf5ab
comparison
equal deleted inserted replaced
23640:58bb7fc244e4 25124:ba362a67278c
86 86
87 87
88 void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) { 88 void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) {
89 const char *from = xmlnode_get_attrib(packet, "from"); 89 const char *from = xmlnode_get_attrib(packet, "from");
90 const char *type = xmlnode_get_attrib(packet, "type"); 90 const char *type = xmlnode_get_attrib(packet, "type");
91
92 if(!from || !type) 91 if(!from || !type)
93 return; 92 return;
94 93
95 if(!strcmp(type, "get")) { 94 if(!strcmp(type, "get")) {
96 xmlnode *query, *identity, *feature; 95 xmlnode *query, *identity, *feature;
97 JabberIq *iq; 96 JabberIq *iq;
98 97
99 xmlnode *in_query; 98 xmlnode *in_query;
100 const char *node = NULL; 99 const char *node = NULL;
100 const char *node_uri = NULL;
101
102 // create custom caps node URI
103 node_uri = g_strconcat(CAPS0115_NODE, "#", jabber_caps_get_own_hash(), NULL);
101 104
102 if((in_query = xmlnode_get_child(packet, "query"))) { 105 if((in_query = xmlnode_get_child(packet, "query"))) {
103 node = xmlnode_get_attrib(in_query, "node"); 106 node = xmlnode_get_attrib(in_query, "node");
104 } 107 }
105 108
113 query = xmlnode_get_child(iq->node, "query"); 116 query = xmlnode_get_child(iq->node, "query");
114 117
115 if(node) 118 if(node)
116 xmlnode_set_attrib(query, "node", node); 119 xmlnode_set_attrib(query, "node", node);
117 120
118 if(!node || !strcmp(node, CAPS0115_NODE "#" VERSION)) { 121
119 identity = xmlnode_new_child(query, "identity"); 122 if(!node || !strcmp(node, node_uri)) {
120 xmlnode_set_attrib(identity, "category", "client"); 123 GList *identities;
121 xmlnode_set_attrib(identity, "type", "pc"); /* XXX: bot, console, 124 for(identities = jabber_identities; identities; identities = identities->next) {
122 * handheld, pc, phone, 125 JabberIdentity *ident = (JabberIdentity*)identities->data;
123 * web */ 126 identity = xmlnode_new_child(query, "identity");
124 xmlnode_set_attrib(identity, "name", PACKAGE); 127 xmlnode_set_attrib(identity, "category", ident->category);
125 128 xmlnode_set_attrib(identity, "type", ident->type);
126 SUPPORT_FEATURE("jabber:iq:last") 129 if (ident->name != 0) xmlnode_set_attrib(identity, "name", ident->name);
127 SUPPORT_FEATURE("jabber:iq:oob") 130 }
128 SUPPORT_FEATURE("jabber:iq:time") 131 GList *features;
129 SUPPORT_FEATURE("xmpp:urn:time") 132 for(features = jabber_features; features; features = features->next) {
130 SUPPORT_FEATURE("jabber:iq:version") 133 JabberFeature *feat = (JabberFeature*)features->data;
131 SUPPORT_FEATURE("jabber:x:conference") 134 if(feat->is_enabled == NULL || feat->is_enabled(js, feat->namespace) == TRUE) {
132 SUPPORT_FEATURE("http://jabber.org/protocol/bytestreams") 135 feature = xmlnode_new_child(query, "feature");
133 SUPPORT_FEATURE("http://jabber.org/protocol/disco#info") 136 xmlnode_set_attrib(feature, "var", feat->namespace);
134 SUPPORT_FEATURE("http://jabber.org/protocol/disco#items") 137 }
135 #if 0
136 SUPPORT_FEATURE("http://jabber.org/protocol/ibb")
137 #endif
138 SUPPORT_FEATURE("http://jabber.org/protocol/muc")
139 SUPPORT_FEATURE("http://jabber.org/protocol/muc#user")
140 SUPPORT_FEATURE("http://jabber.org/protocol/si")
141 SUPPORT_FEATURE("http://jabber.org/protocol/si/profile/file-transfer")
142 SUPPORT_FEATURE("http://jabber.org/protocol/xhtml-im")
143 SUPPORT_FEATURE("urn:xmpp:ping")
144 SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0199.html#ns")
145
146 if(!node) { /* non-caps disco#info, add all enabled extensions */
147 GList *features;
148 for(features = jabber_features; features; features = features->next) {
149 JabberFeature *feat = (JabberFeature*)features->data;
150 if(feat->is_enabled == NULL || feat->is_enabled(js, feat->shortname, feat->namespace) == TRUE)
151 SUPPORT_FEATURE(feat->namespace);
152 }
153 } 138 }
154 } else { 139 } else {
155 const char *ext = NULL; 140 xmlnode *error, *inf;
156 unsigned pos;
157 unsigned nodelen = strlen(node);
158 unsigned capslen = strlen(CAPS0115_NODE);
159 /* do a basic plausability check */
160 if(nodelen > capslen+1) {
161 /* verify that the string is CAPS0115#<ext> and get the pointer to the ext part */
162 for(pos = 0; pos < capslen+1; ++pos) {
163 if(pos == capslen) {
164 if(node[pos] == '#')
165 ext = &node[pos+1];
166 else
167 break;
168 } else if(node[pos] != CAPS0115_NODE[pos])
169 break;
170 }
171 141
172 if(ext != NULL) { 142 /* XXX: gross hack, implement jabber_iq_set_type or something */
173 /* look for that ext */ 143 xmlnode_set_attrib(iq->node, "type", "error");
174 GList *features; 144 iq->type = JABBER_IQ_ERROR;
175 for(features = jabber_features; features; features = features->next) {
176 JabberFeature *feat = (JabberFeature*)features->data;
177 if(!strcmp(feat->shortname, ext)) {
178 SUPPORT_FEATURE(feat->namespace);
179 break;
180 }
181 }
182 if(features == NULL)
183 ext = NULL;
184 }
185 }
186 145
187 if(ext == NULL) { 146 error = xmlnode_new_child(query, "error");
188 xmlnode *error, *inf; 147 xmlnode_set_attrib(error, "code", "404");
189 148 xmlnode_set_attrib(error, "type", "cancel");
190 /* XXX: gross hack, implement jabber_iq_set_type or something */ 149 inf = xmlnode_new_child(error, "item-not-found");
191 xmlnode_set_attrib(iq->node, "type", "error"); 150 xmlnode_set_namespace(inf, "urn:ietf:params:xml:ns:xmpp-stanzas");
192 iq->type = JABBER_IQ_ERROR; 151 }
193 152 g_free(node_uri);
194 error = xmlnode_new_child(query, "error");
195 xmlnode_set_attrib(error, "code", "404");
196 xmlnode_set_attrib(error, "type", "cancel");
197 inf = xmlnode_new_child(error, "item-not-found");
198 xmlnode_set_namespace(inf, "urn:ietf:params:xml:ns:xmpp-stanzas");
199 }
200 }
201
202 jabber_iq_send(iq); 153 jabber_iq_send(iq);
203 } else if(!strcmp(type, "result")) { 154 } else if(!strcmp(type, "result")) {
204 xmlnode *query = xmlnode_get_child(packet, "query"); 155 xmlnode *query = xmlnode_get_child(packet, "query");
205 xmlnode *child; 156 xmlnode *child;
206 JabberID *jid; 157 JabberID *jid;