disco.c
changeset 29 58001297bb7b
parent 28 ff36ae7e2b1e
child 30 060c59f6f3de
equal deleted inserted replaced
28:ff36ae7e2b1e 29:58001297bb7b
    46 
    46 
    47 #define DESCRIPTION ( "Service discovery requests\nProvides command /disco" )
    47 #define DESCRIPTION ( "Service discovery requests\nProvides command /disco" )
    48 
    48 
    49 static module_info_t info_disco_experimental = {
    49 static module_info_t info_disco_experimental = {
    50 	.branch      = "experimental",
    50 	.branch      = "experimental",
    51 	.api         = 5,
    51 	.api         = 10,
    52 	.version     = PROJECT_VERSION,
    52 	.version     = PROJECT_VERSION,
    53 	.description = DESCRIPTION,
    53 	.description = DESCRIPTION,
    54 	.requires    = NULL,
    54 	.requires    = NULL,
    55 	.init        = disco_init,
    55 	.init        = disco_init,
    56 	.uninit      = disco_uninit,
    56 	.uninit      = disco_uninit,
    57 	.next        = NULL,
    57 	.next        = NULL,
    58 };
    58 };
    59 
    59 
    60 module_info_t info_disco = {
    60 module_info_t info_disco = {
    61 	.branch      = "dev",
    61 	.branch      = "dev",
    62 	.api         = 4,
    62 	.api         = 11,
    63 	.version     = PROJECT_VERSION,
    63 	.version     = PROJECT_VERSION,
    64 	.description = DESCRIPTION,
    64 	.description = DESCRIPTION,
    65 	.requires    = NULL,
    65 	.requires    = NULL,
    66 	.init        = disco_init,
    66 	.init        = disco_init,
    67 	.uninit      = disco_uninit,
    67 	.uninit      = disco_uninit,
    95 //
    95 //
    96 // globals
    96 // globals
    97 //
    97 //
    98 
    98 
    99 static guint   disco_cid      = 0;
    99 static guint   disco_cid      = 0;
       
   100 static guint   disco_hid      = 0;
   100 static GSList *reply_handlers = NULL;
   101 static GSList *reply_handlers = NULL;
   101 
   102 
   102 //
   103 //
   103 // destroyers
   104 // destroyers
   104 //
   105 //
   200 				reason = node->children->name;
   201 				reason = node->children->name;
   201 			else
   202 			else
   202 				reason = "undefined";
   203 				reason = "undefined";
   203 
   204 
   204 			// XXX: we need to inform user, but do we really need to print this on every possible error?
   205 			// XXX: we need to inform user, but do we really need to print this on every possible error?
   205 			scr_LogPrint (LPRINT_LOGNORM, "disco: Service info discovery for %s failed: %s - %s", from, type, reason);
   206 			scr_log_print (LPRINT_LOGNORM, "disco: Service info discovery for %s failed: %s - %s", from, type, reason);
   206 
   207 
   207 			cb -> handler (NULL, NULL, cb -> data);
   208 			cb -> handler (NULL, NULL, cb -> data);
   208 		}
   209 		}
   209 
   210 
   210 		break;
   211 		break;
   278 				reason = node->children->name;
   279 				reason = node->children->name;
   279 			else
   280 			else
   280 				reason = "undefined";
   281 				reason = "undefined";
   281 
   282 
   282 			// XXX: we need to inform user, but do we really need to print this on every possible error?
   283 			// XXX: we need to inform user, but do we really need to print this on every possible error?
   283 			scr_LogPrint (LPRINT_LOGNORM, "disco: Service items discovery for %s failed: %s - %s", from, type, reason);
   284 			scr_log_print (LPRINT_LOGNORM, "disco: Service items discovery for %s failed: %s - %s", from, type, reason);
   284 
   285 
   285 			cb -> handler (NULL, cb -> data);
   286 			cb -> handler (NULL, cb -> data);
   286 		}
   287 		}
   287 
   288 
   288 		break;
   289 		break;
   361 
   362 
   362 			lm_connection_send_with_reply (lconnection, request, lhandler, &error);
   363 			lm_connection_send_with_reply (lconnection, request, lhandler, &error);
   363 
   364 
   364 			if (error) {
   365 			if (error) {
   365 				// XXX destroy handler and return NULL?
   366 				// XXX destroy handler and return NULL?
   366 				scr_LogPrint (LPRINT_DEBUG, "disco: Error sending disco request: %s.", error -> message);
   367 				scr_log_print (LPRINT_DEBUG, "disco: Error sending disco request: %s.", error -> message);
   367 				g_error_free (error);
   368 				g_error_free (error);
   368 			}
   369 			}
   369 
   370 
   370 			lm_message_handler_unref (lhandler);
   371 			lm_message_handler_unref (lhandler);
   371 		}
   372 		}
   410 
   411 
   411 			lm_connection_send_with_reply (lconnection, request, lhandler, &error);
   412 			lm_connection_send_with_reply (lconnection, request, lhandler, &error);
   412 
   413 
   413 			if (error) {
   414 			if (error) {
   414 				// XXX destroy handler and return NULL?
   415 				// XXX destroy handler and return NULL?
   415 				scr_LogPrint (LPRINT_DEBUG, "disco: Error sending disco request: %s.", error -> message);
   416 				scr_log_print (LPRINT_DEBUG, "disco: Error sending disco request: %s.", error -> message);
   416 				g_error_free (error);
   417 				g_error_free (error);
   417 			}
   418 			}
   418 
   419 
   419 			lm_message_handler_unref (lhandler);
   420 			lm_message_handler_unref (lhandler);
   420 		}
   421 		}
   491 	}
   492 	}
   492 
   493 
   493 	{ // print to buddy's buffer
   494 	{ // print to buddy's buffer
   494 		gchar *bjid = jidtodisp (cb -> jid);
   495 		gchar *bjid = jidtodisp (cb -> jid);
   495 
   496 
   496 		scr_WriteIncomingMessage (bjid, info -> str, 0, HBB_PREFIX_INFO, 0); // NO conversion from utf-8
   497 		scr_write_incoming_message (bjid, info -> str, 0, HBB_PREFIX_INFO, 0); // NO conversion from utf-8
   497 
   498 
   498 		g_free (bjid);
   499 		g_free (bjid);
   499 	}
   500 	}
   500 
   501 
   501 	g_string_free (info, TRUE);
   502 	g_string_free (info, TRUE);
   532 	}
   533 	}
   533 
   534 
   534 	{ // print to buddy's buffer
   535 	{ // print to buddy's buffer
   535 		gchar *bjid = jidtodisp (cb -> jid);
   536 		gchar *bjid = jidtodisp (cb -> jid);
   536 
   537 
   537 		scr_WriteIncomingMessage (bjid, info -> str, 0, HBB_PREFIX_INFO, 0); // NO conversion from utf-8
   538 		scr_write_incoming_message (bjid, info -> str, 0, HBB_PREFIX_INFO, 0); // NO conversion from utf-8
   538 
   539 
   539 		g_free (bjid);
   540 		g_free (bjid);
   540 	}
   541 	}
   541 
   542 
   542 	g_string_free (info, TRUE);
   543 	g_string_free (info, TRUE);
   556 	if (!args[0] || !strcmp (args[0], "info"))
   557 	if (!args[0] || !strcmp (args[0], "info"))
   557 		info = 1;
   558 		info = 1;
   558 	else if (!strcmp (args[0], "items"))
   559 	else if (!strcmp (args[0], "items"))
   559 		info = 0;
   560 		info = 0;
   560 	else
   561 	else
   561 		scr_LogPrint (LPRINT_NORMAL, "Unknown subcomand.");
   562 		scr_log_print (LPRINT_NORMAL, "Unknown subcomand.");
   562 
   563 
   563 	if (info != -1) {
   564 	if (info != -1) {
   564 		char *to    = NULL;
   565 		char *to    = NULL;
   565 		char *dnode = NULL;
   566 		char *dnode = NULL;
   566 		
   567 		
   621 	reply_handlers = NULL;
   622 	reply_handlers = NULL;
   622 
   623 
   623 	return;
   624 	return;
   624 }
   625 }
   625 
   626 
   626 static void disco_hh (guint32 htype, hk_arg_t *args, gpointer ignore)
   627 static guint disco_hh (const gchar *htype, hk_arg_t *args, gpointer ignore)
   627 {
   628 {
   628 	disco_unregister_handlers ();
   629 	disco_unregister_handlers ();
   629 	return;
   630 	return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
   630 }
   631 }
   631 
   632 
   632 static void disco_init (void)
   633 static void disco_init (void)
   633 {
   634 {
   634 	// completion
   635 	// completion
   637 		compl_add_category_word (disco_cid, "info");
   638 		compl_add_category_word (disco_cid, "info");
   638 		compl_add_category_word (disco_cid, "items");
   639 		compl_add_category_word (disco_cid, "items");
   639 	}
   640 	}
   640 
   641 
   641 	// hook handler
   642 	// hook handler
   642 	hk_add_handler (disco_hh, HOOK_PRE_DISCONNECT, NULL);
   643 	disco_hid = hk_add_handler (disco_hh, HOOK_PRE_DISCONNECT, G_PRIORITY_DEFAULT, NULL);
   643 
   644 
   644 	// command
   645 	// command
   645 	cmd_add ("disco", "", disco_cid, COMPL_JID, do_disco, NULL);
   646 	cmd_add ("disco", "", disco_cid, COMPL_JID, do_disco, NULL);
   646 
   647 
   647 	return;
   648 	return;
   655 	// completion
   656 	// completion
   656 	if (disco_cid)
   657 	if (disco_cid)
   657 		compl_del_category (disco_cid);
   658 		compl_del_category (disco_cid);
   658 	
   659 	
   659 	// hook handler
   660 	// hook handler
   660 	hk_del_handler (disco_hh, NULL);
   661 	hk_del_handler (HOOK_PRE_DISCONNECT, disco_hid);
   661 
   662 
   662 	// unregister handlers
   663 	// unregister handlers
   663 	disco_unregister_handlers ();
   664 	disco_unregister_handlers ();
   664 
   665 
   665 	return;
   666 	return;