/soc/2013/ankitkv/gobjectification: 37c56498c80f: Register and u...

Ankit Vani a at nevitus.org
Tue Sep 3 19:22:39 EDT 2013


Changeset: 37c56498c80f88c45dfcd3e54faffcd225ef4b32
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-04 03:27 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/37c56498c80f

Description:

Register and unregister yahoo commands in plugin load/unload

diffstat:

 libpurple/protocols/yahoo/util.c    |   7 -------
 libpurple/protocols/yahoo/yahoo.c   |  22 ++++++++++++----------
 libpurple/protocols/yahoo/yahoojp.c |  13 ++++---------
 libpurple/protocols/yahoo/yahoojp.h |   3 +++
 4 files changed, 19 insertions(+), 26 deletions(-)

diffs (135 lines):

diff --git a/libpurple/protocols/yahoo/util.c b/libpurple/protocols/yahoo/util.c
--- a/libpurple/protocols/yahoo/util.c
+++ b/libpurple/protocols/yahoo/util.c
@@ -223,13 +223,9 @@ char *yahoo_convert_to_numeric(const cha
 
 static GHashTable *esc_codes_ht = NULL;
 static GHashTable *tags_ht = NULL;
-static gint ref_count = 0;
 
 void yahoo_init_colorht()
 {
-	if (ref_count++)
-		return;
-
 	if (esc_codes_ht != NULL)
 		/* Hash table has already been initialized */
 		return;
@@ -351,9 +347,6 @@ void yahoo_init_colorht()
 
 void yahoo_dest_colorht()
 {
-	if (--ref_count)
-		return;
-
 	if (esc_codes_ht == NULL)
 		/* Hash table has already been destroyed */
 		return;
diff --git a/libpurple/protocols/yahoo/yahoo.c b/libpurple/protocols/yahoo/yahoo.c
--- a/libpurple/protocols/yahoo/yahoo.c
+++ b/libpurple/protocols/yahoo/yahoo.c
@@ -249,16 +249,6 @@ yahoo_protocol_base_init(YahooProtocolCl
 	option = purple_account_option_string_new(_("Chat room list URL"), "room_list", YAHOO_ROOMLIST_URL);
 	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
 #endif
-
-	yahoo_register_commands();
-	yahoo_init_colorht();
-}
-
-static void
-yahoo_protocol_base_finalize(YahooProtocolClass *klass)
-{
-	yahoo_dest_colorht();
-	yahoo_unregister_commands();
 }
 
 static void
@@ -309,6 +299,8 @@ yahoo_protocol_interface_init(PurpleProt
 	iface->get_max_message_size     = yahoo_get_max_message_size;
 }
 
+static void yahoo_protocol_base_finalize(YahooProtocolClass *klass) { }
+
 static PurplePluginInfo *
 plugin_query(GError **error)
 {
@@ -338,6 +330,11 @@ plugin_load(PurplePlugin *plugin, GError
 	if (!yahoojp_protocol)
 		return FALSE;
 
+	yahoo_init_colorht();
+
+	yahoo_register_commands();
+	yahoojp_register_commands();
+
 	purple_signal_connect(purple_get_core(), "uri-handler", yahoo_protocol,
 		PURPLE_CALLBACK(yahoo_uri_handler), NULL);
 
@@ -347,6 +344,11 @@ plugin_load(PurplePlugin *plugin, GError
 static gboolean
 plugin_unload(PurplePlugin *plugin, GError **error)
 {
+	yahoojp_unregister_commands();
+	yahoo_unregister_commands();
+
+	yahoo_dest_colorht();
+
 	if (!purple_protocols_remove(yahoojp_protocol, error))
 		return FALSE;
 
diff --git a/libpurple/protocols/yahoo/yahoojp.c b/libpurple/protocols/yahoo/yahoojp.c
--- a/libpurple/protocols/yahoo/yahoojp.c
+++ b/libpurple/protocols/yahoo/yahoojp.c
@@ -36,7 +36,7 @@
 
 static GSList *cmds = NULL;
 
-static void yahoojp_register_commands(void)
+void yahoojp_register_commands(void)
 {
 	PurpleCmdId id;
 
@@ -67,7 +67,7 @@ static void yahoojp_register_commands(vo
 	cmds = g_slist_prepend(cmds, GUINT_TO_POINTER(id));
 }
 
-static void yahoojp_unregister_commands(void)
+void yahoojp_unregister_commands(void)
 {
 	while (cmds) {
 		PurpleCmdId id = GPOINTER_TO_UINT(cmds->data);
@@ -117,13 +117,6 @@ yahoojp_protocol_base_init(YahooJPProtoc
 
 	option = purple_account_option_bool_new(_("Ignore conference and chatroom invitations"), "ignore_invites", FALSE);
 	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
-
-	yahoojp_register_commands();
-}
-
-static void yahoojp_protocol_base_finalize(YahooJPProtocolClass *klass)
-{
-	yahoojp_unregister_commands();
 }
 
 static void
@@ -135,6 +128,8 @@ yahoojp_protocol_interface_init(PurplePr
 	iface->can_receive_file         = NULL;
 }
 
+static void yahoojp_protocol_base_finalize(YahooJPProtocolClass *klass) { }
+
 extern PurplePlugin *_yahoo_plugin;
 PURPLE_PROTOCOL_DEFINE_EXTENDED(_yahoo_plugin, YahooJPProtocol,
                                 yahoojp_protocol, YAHOO_TYPE_PROTOCOL, 0);
diff --git a/libpurple/protocols/yahoo/yahoojp.h b/libpurple/protocols/yahoo/yahoojp.h
--- a/libpurple/protocols/yahoo/yahoojp.h
+++ b/libpurple/protocols/yahoo/yahoojp.h
@@ -46,4 +46,7 @@ typedef struct _YahooJPProtocolClass
  */
 GType yahoojp_protocol_get_type(void);
 
+void yahoojp_register_commands(void);
+void yahoojp_unregister_commands(void);
+
 #endif /* _YAHOOJP_H_ */



More information about the Commits mailing list