297 GSList *features = NULL; |
297 GSList *features = NULL; |
298 caps_foreach_feature (hash, disco_features_cb, &features); |
298 caps_foreach_feature (hash, disco_features_cb, &features); |
299 handler (identities, features, userdata); |
299 handler (identities, features, userdata); |
300 if (notify) |
300 if (notify) |
301 notify (userdata); |
301 notify (userdata); |
302 return; |
302 return NULL; |
303 } |
303 } |
304 } |
304 } |
305 } |
305 } |
306 |
306 |
307 { // send request |
307 { // send request |
308 LmMessage *request; |
308 LmMessage *request; |
309 LmMessageNode *node; |
309 LmMessageNode *node; |
310 GError *error = NULL; |
310 LmMessageHandler *lhandler; |
|
311 GError *error = NULL; |
311 |
312 |
312 request = lm_message_new_with_sub_type (jid, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET); |
313 request = lm_message_new_with_sub_type (jid, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET); |
313 node = lm_message_get_node (request); |
314 node = lm_message_get_node (request); |
314 node = lm_message_node_add_child (node, "query", NULL); |
315 node = lm_message_node_add_child (node, "query", NULL); |
315 lm_message_node_set_attribute (node, "xmlns", NS_DISCO_INFO); |
316 lm_message_node_set_attribute (node, "xmlns", NS_DISCO_INFO); |
316 if (dnode) |
317 if (dnode) |
317 lm_message_node_set_attribute (node, "node", dnode); |
318 lm_message_node_set_attribute (node, "node", dnode); |
318 |
319 |
319 { |
320 { |
320 disco_info_reply_handler_t *cb = g_new (disco_info_reply_handler_t, 1); |
321 disco_info_reply_handler_t *cb = g_new (disco_info_reply_handler_t, 1); |
321 LmMessageHandler *lhandler = lm_message_handler_new (disco_info_reply_handler, cb, disco_info_reply_handler_destroy_notify); |
322 |
|
323 lhandler = lm_message_handler_new (disco_info_reply_handler, cb, disco_info_reply_handler_destroy_notify); |
322 |
324 |
323 cb -> handler = handler; |
325 cb -> handler = handler; |
324 cb -> data = userdata; |
326 cb -> data = userdata; |
325 cb -> notify = notify; |
327 cb -> notify = notify; |
326 |
328 |
327 reply_handlers = g_slist_append (reply_handlers, lhandler); |
329 reply_handlers = g_slist_append (reply_handlers, lhandler); |
328 |
330 |
329 lm_connection_send_with_reply (lconnection, request, lhandler, &error); |
331 lm_connection_send_with_reply (lconnection, request, lhandler, &error); |
330 |
332 |
331 if (error) { |
333 if (error) { |
|
334 // XXX destroy handler and return NULL? |
332 scr_LogPrint (LPRINT_DEBUG, "disco: Error sending disco request: %s.", error -> message); |
335 scr_LogPrint (LPRINT_DEBUG, "disco: Error sending disco request: %s.", error -> message); |
333 g_error_free (error); |
336 g_error_free (error); |
334 } |
337 } |
335 |
338 |
336 lm_message_handler_unref (lhandler); |
339 lm_message_handler_unref (lhandler); |
337 } |
340 } |
338 |
341 |
339 lm_message_unref (request); |
342 lm_message_unref (request); |
340 } |
343 |
341 |
344 return lhandler; |
342 return; |
345 } |
343 } |
346 } |
344 |
347 |
345 void disco_items_request (const gchar *jid, const gchar *dnode, disco_items_handler_t handler, gpointer userdata, GDestroyNotify notify) |
348 gpointer disco_items_request (const gchar *jid, const gchar *dnode, disco_items_handler_t handler, gpointer userdata, GDestroyNotify notify) |
346 { |
349 { |
347 if (!handler || !xmpp_is_online ()) { |
350 if (!handler || !xmpp_is_online ()) { |
348 if (notify) |
351 if (notify) |
349 notify (userdata); |
352 notify (userdata); |
350 return; |
353 return NULL; |
351 } |
354 } |
352 |
355 |
353 { // send request |
356 { // send request |
354 LmMessage *request; |
357 LmMessage *request; |
355 LmMessageNode *node; |
358 LmMessageNode *node; |
356 GError *error = NULL; |
359 GError *error = NULL; |
|
360 LmMessageHandler *lhandler; |
357 |
361 |
358 request = lm_message_new_with_sub_type (jid, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET); |
362 request = lm_message_new_with_sub_type (jid, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET); |
359 node = lm_message_get_node (request); |
363 node = lm_message_get_node (request); |
360 node = lm_message_node_add_child (node, "query", NULL); |
364 node = lm_message_node_add_child (node, "query", NULL); |
361 lm_message_node_set_attribute (node, "xmlns", NS_DISCO_ITEMS); |
365 lm_message_node_set_attribute (node, "xmlns", NS_DISCO_ITEMS); |
362 if (dnode) |
366 if (dnode) |
363 lm_message_node_set_attribute (node, "node", dnode); |
367 lm_message_node_set_attribute (node, "node", dnode); |
364 |
368 |
365 { |
369 { |
366 disco_items_reply_handler_t *cb = g_new (disco_items_reply_handler_t, 1); |
370 disco_items_reply_handler_t *cb = g_new (disco_items_reply_handler_t, 1); |
367 LmMessageHandler *lhandler = lm_message_handler_new (disco_items_reply_handler, cb, disco_items_reply_handler_destroy_notify); |
371 |
|
372 lhandler = lm_message_handler_new (disco_items_reply_handler, cb, disco_items_reply_handler_destroy_notify); |
368 |
373 |
369 cb -> handler = handler; |
374 cb -> handler = handler; |
370 cb -> data = userdata; |
375 cb -> data = userdata; |
371 cb -> notify = notify; |
376 cb -> notify = notify; |
372 |
377 |
373 reply_handlers = g_slist_append (reply_handlers, lhandler); |
378 reply_handlers = g_slist_append (reply_handlers, lhandler); |
374 |
379 |
375 lm_connection_send_with_reply (lconnection, request, lhandler, &error); |
380 lm_connection_send_with_reply (lconnection, request, lhandler, &error); |
376 |
381 |
377 if (error) { |
382 if (error) { |
|
383 // XXX destroy handler and return NULL? |
378 scr_LogPrint (LPRINT_DEBUG, "disco: Error sending disco request: %s.", error -> message); |
384 scr_LogPrint (LPRINT_DEBUG, "disco: Error sending disco request: %s.", error -> message); |
379 g_error_free (error); |
385 g_error_free (error); |
380 } |
386 } |
381 |
387 |
382 lm_message_handler_unref (lhandler); |
388 lm_message_handler_unref (lhandler); |
383 } |
389 } |
384 |
390 |
385 lm_message_unref (request); |
391 lm_message_unref (request); |
|
392 |
|
393 return lhandler; |
|
394 } |
|
395 } |
|
396 |
|
397 void disco_cancel_request (gpointer id) |
|
398 { |
|
399 GSList *hel; |
|
400 |
|
401 for (hel = reply_handlers; hel; hel = hel -> next) { |
|
402 if (hel -> data == id) { |
|
403 LmMessageHandler *handler = id; |
|
404 reply_handlers = g_slist_remove (reply_handlers, handler); |
|
405 lm_message_handler_invalidate (handler); |
|
406 #ifdef HAVE_LM_CONNECTION_UNREGISTER_REPLY_HANDLER |
|
407 if (lconnection) |
|
408 lm_connection_unregister_reply_handler (lconnection, handler); |
|
409 #endif |
|
410 return; |
|
411 } |
386 } |
412 } |
387 |
413 |
388 return; |
414 return; |
389 } |
415 } |
390 |
416 |