libpurple/protocols/jabber/iq.c

branch
cpw.darkrain42.xmpp.iq-handlers
changeset 25818
d087a2754595
parent 25817
09d6a40a341d
child 25819
4dbe0c6eaf6d
equal deleted inserted replaced
25817:09d6a40a341d 25818:d087a2754595
181 char *idle_time; 181 char *idle_time;
182 182
183 if(type == JABBER_IQ_GET) { 183 if(type == JABBER_IQ_GET) {
184 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:last"); 184 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:last");
185 jabber_iq_set_id(iq, id); 185 jabber_iq_set_id(iq, id);
186 xmlnode_set_attrib(iq->node, "to", from); 186 if (from)
187 xmlnode_set_attrib(iq->node, "to", from);
187 188
188 query = xmlnode_get_child(iq->node, "query"); 189 query = xmlnode_get_child(iq->node, "query");
189 190
190 idle_time = g_strdup_printf("%ld", js->idle ? time(NULL) - js->idle : 0); 191 idle_time = g_strdup_printf("%ld", js->idle ? time(NULL) - js->idle : 0);
191 xmlnode_set_attrib(query, "seconds", idle_time); 192 xmlnode_set_attrib(query, "seconds", idle_time);
213 xmlnode *utc; 214 xmlnode *utc;
214 const char *date, *tz, *display; 215 const char *date, *tz, *display;
215 216
216 iq = jabber_iq_new(js, JABBER_IQ_RESULT); 217 iq = jabber_iq_new(js, JABBER_IQ_RESULT);
217 jabber_iq_set_id(iq, id); 218 jabber_iq_set_id(iq, id);
218 xmlnode_set_attrib(iq->node, "to", from); 219 if (from)
220 xmlnode_set_attrib(iq->node, "to", from);
219 221
220 child = xmlnode_new_child(iq->node, child->name); 222 child = xmlnode_new_child(iq->node, child->name);
221 xmlnode_set_namespace(child, xmlns); 223 xmlnode_set_namespace(child, xmlns);
222 utc = xmlnode_new_child(child, "utc"); 224 utc = xmlnode_new_child(child, "utc");
223 225
262 osinfo.machine); 264 osinfo.machine);
263 } 265 }
264 #endif 266 #endif
265 267
266 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:version"); 268 iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, "jabber:iq:version");
267 xmlnode_set_attrib(iq->node, "to", from); 269 if (from)
270 xmlnode_set_attrib(iq->node, "to", from);
268 jabber_iq_set_id(iq, id); 271 jabber_iq_set_id(iq, id);
269 272
270 query = xmlnode_get_child(iq->node, "query"); 273 query = xmlnode_get_child(iq->node, "query");
271 274
272 ui_info = purple_core_get_ui_info(); 275 ui_info = purple_core_get_ui_info();
349 if(type == JABBER_IQ_SET || type == JABBER_IQ_GET) { 352 if(type == JABBER_IQ_SET || type == JABBER_IQ_GET) {
350 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); 353 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR);
351 354
352 xmlnode_free(iq->node); 355 xmlnode_free(iq->node);
353 iq->node = xmlnode_copy(packet); 356 iq->node = xmlnode_copy(packet);
354 xmlnode_set_attrib(iq->node, "to", from); 357 if (from) {
355 xmlnode_remove_attrib(iq->node, "from"); 358 xmlnode_set_attrib(iq->node, "to", from);
359 xmlnode_remove_attrib(iq->node, "from");
360 }
361
356 xmlnode_set_attrib(iq->node, "type", "error"); 362 xmlnode_set_attrib(iq->node, "type", "error");
357 /* This id is clearly not useful, but we must put something there for a valid stanza */ 363 /* This id is clearly not useful, but we must put something there for a valid stanza */
358 iq->id = jabber_get_next_id(js); 364 iq->id = jabber_get_next_id(js);
359 xmlnode_set_attrib(iq->node, "id", iq->id); 365 xmlnode_set_attrib(iq->node, "id", iq->id);
360 error = xmlnode_new_child(iq->node, "error"); 366 error = xmlnode_new_child(iq->node, "error");
397 if(type == JABBER_IQ_SET || type == JABBER_IQ_GET) { 403 if(type == JABBER_IQ_SET || type == JABBER_IQ_GET) {
398 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); 404 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR);
399 405
400 xmlnode_free(iq->node); 406 xmlnode_free(iq->node);
401 iq->node = xmlnode_copy(packet); 407 iq->node = xmlnode_copy(packet);
402 xmlnode_set_attrib(iq->node, "to", from); 408 if (from) {
403 xmlnode_remove_attrib(iq->node, "from"); 409 xmlnode_set_attrib(iq->node, "to", from);
410 xmlnode_remove_attrib(iq->node, "from");
411 }
412
404 xmlnode_set_attrib(iq->node, "type", "error"); 413 xmlnode_set_attrib(iq->node, "type", "error");
405 error = xmlnode_new_child(iq->node, "error"); 414 error = xmlnode_new_child(iq->node, "error");
406 xmlnode_set_attrib(error, "type", "cancel"); 415 xmlnode_set_attrib(error, "type", "cancel");
407 xmlnode_set_attrib(error, "code", "501"); 416 xmlnode_set_attrib(error, "code", "501");
408 x = xmlnode_new_child(error, "feature-not-implemented"); 417 x = xmlnode_new_child(error, "feature-not-implemented");

mercurial