Mercurial > pidgin
comparison libpurple/plugins/signals-test.c @ 27004:60cb86295f08
Examples for the namespace-(un)registering of IQs and added IPC versions
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 03 Jun 2009 05:51:51 +0000 |
parents | 74c9f4f79825 |
children | 8502d69e45ed |
comparison
equal
deleted
inserted
replaced
27003:61d817c4c935 | 27004:60cb86295f08 |
---|---|
657 purple_debug_misc("signals test", "jabber presence (type=%s, from=%s) %p\n", | 657 purple_debug_misc("signals test", "jabber presence (type=%s, from=%s) %p\n", |
658 type ? type : "(null)", from ? from : "(null)", presence); | 658 type ? type : "(null)", from ? from : "(null)", presence); |
659 | 659 |
660 /* We don't want the plugin to stop processing */ | 660 /* We don't want the plugin to stop processing */ |
661 return FALSE; | 661 return FALSE; |
662 } | |
663 | |
664 static gboolean | |
665 jabber_watched_iq(PurpleConnection *pc, const char *type, const char *id, | |
666 const char *from, xmlnode *child) | |
667 { | |
668 purple_debug_misc("signals test", "jabber watched IQ (type=%s, id=%s, from=%s)\n" | |
669 "child %p name=%s, namespace=%s\n", | |
670 type, id, from, child, child->name, | |
671 xmlnode_get_namespace(child)); | |
672 | |
673 if (g_str_equal(type, "get") || g_str_equal(type, "set")) { | |
674 PurplePlugin *prpl; | |
675 PurplePluginProtocolInfo *prpl_info; | |
676 char *str; | |
677 | |
678 /* Send the requisite reply */ | |
679 xmlnode *iq = xmlnode_new("iq"); | |
680 xmlnode_set_attrib(iq, "to", from); | |
681 xmlnode_set_attrib(iq, "id", id); | |
682 xmlnode_set_attrib(iq, "type", "result"); | |
683 | |
684 str = xmlnode_to_str(iq, NULL); | |
685 prpl = purple_connection_get_prpl(pc); | |
686 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
687 prpl_info->send_raw(pc, str, -1); | |
688 g_free(str); | |
689 } | |
690 | |
691 /* Cookie monster eats IQ stanzas; the prpl shouldn't keep processing */ | |
692 return TRUE; | |
662 } | 693 } |
663 | 694 |
664 /************************************************************************** | 695 /************************************************************************** |
665 * Plugin stuff | 696 * Plugin stuff |
666 **************************************************************************/ | 697 **************************************************************************/ |
828 PURPLE_CALLBACK(jabber_iq_received), NULL); | 859 PURPLE_CALLBACK(jabber_iq_received), NULL); |
829 purple_signal_connect(jabber_handle, "jabber-receiving-message", plugin, | 860 purple_signal_connect(jabber_handle, "jabber-receiving-message", plugin, |
830 PURPLE_CALLBACK(jabber_message_received), NULL); | 861 PURPLE_CALLBACK(jabber_message_received), NULL); |
831 purple_signal_connect(jabber_handle, "jabber-receiving-presence", plugin, | 862 purple_signal_connect(jabber_handle, "jabber-receiving-presence", plugin, |
832 PURPLE_CALLBACK(jabber_presence_received), NULL); | 863 PURPLE_CALLBACK(jabber_presence_received), NULL); |
864 | |
865 /* IQ namespace signals */ | |
866 purple_signal_emit(jabber_handle, "jabber-register-namespace-watcher", | |
867 "bogus_node", "super-duper-namespace"); | |
868 /* The above is equivalent to doing: | |
869 int result = GPOINTER_TO_INT(purple_plugin_ipc_call(jabber_handle, "register_namespace_watcher", &ok, "bogus_node", "super-duper-namespace")); | |
870 */ | |
871 | |
872 purple_signal_connect(jabber_handle, "jabber-watched-iq", plugin, | |
873 PURPLE_CALLBACK(jabber_watched_iq), NULL); | |
833 } | 874 } |
834 | 875 |
835 return TRUE; | 876 return TRUE; |
836 } | 877 } |
837 | 878 |
838 static gboolean | 879 static gboolean |
839 plugin_unload(PurplePlugin *plugin) | 880 plugin_unload(PurplePlugin *plugin) |
840 { | 881 { |
882 void *jabber_handle = purple_plugins_find_with_id("prpl-jabber"); | |
883 | |
841 purple_signals_disconnect_by_handle(plugin); | 884 purple_signals_disconnect_by_handle(plugin); |
885 | |
886 if (jabber_handle) { | |
887 /* Unregister watched namespaces */ | |
888 purple_signal_emit(jabber_handle, "jabber-unregister-namespace-watcher", | |
889 "bogus_node", "super-duper-namespace"); | |
890 /* The above is equivalent to doing: | |
891 int result = GPOINTER_TO_INT(purple_plugin_ipc_call(jabber_handle, "unregister_namespace_watcher", &ok, "bogus_node", "super-duper-namespace")); | |
892 */ | |
893 } | |
842 | 894 |
843 return TRUE; | 895 return TRUE; |
844 } | 896 } |
845 | 897 |
846 static PurplePluginInfo info = | 898 static PurplePluginInfo info = |