/soc/2013/ankitkv/gobjectification: e77919ff5e74: Refactored osc...

Ankit Vani a at nevitus.org
Tue Aug 27 18:09:46 EDT 2013


Changeset: e77919ff5e74d5e6c751fe9dcc813352c0b661e8
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-28 03:37 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/e77919ff5e74

Description:

Refactored oscar to use the new protocol API

diffstat:

 libpurple/protocols/oscar/libaim.c      |  128 ++++++++++-------------------
 libpurple/protocols/oscar/libaim.h      |   53 ++++++++++++
 libpurple/protocols/oscar/libicq.c      |  133 +++++++++++--------------------
 libpurple/protocols/oscar/libicq.h      |   53 ++++++++++++
 libpurple/protocols/oscar/oscar.c       |  108 ++++++++++++++++++-------
 libpurple/protocols/oscar/oscar.h       |   22 +++++
 libpurple/protocols/oscar/oscarcommon.h |    3 +-
 7 files changed, 297 insertions(+), 203 deletions(-)

diffs (truncated from 700 to 300 lines):

diff --git a/libpurple/protocols/oscar/libaim.c b/libpurple/protocols/oscar/libaim.c
--- a/libpurple/protocols/oscar/libaim.c
+++ b/libpurple/protocols/oscar/libaim.c
@@ -24,96 +24,46 @@
  * which contains all the shared implementation code with libicq
  */
 
+#include "core.h"
 #include "plugins.h"
+#include "signals.h"
 
+#include "libaim.h"
 #include "oscarcommon.h"
-#include "oscar.h"
 
-static PurpleProtocol protocol =
+static PurpleProtocol *my_protocol = NULL;
+
+static void
+aim_protocol_base_init(AIMProtocolClass *klass)
 {
-	"prpl-aim",				/* id */
-	"AIM",					/* name */
-	sizeof(PurpleProtocol),       /* struct_size */
-	OPT_PROTO_MAIL_CHECK | OPT_PROTO_IM_IMAGE | OPT_PROTO_INVITE_MESSAGE | OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE,
-	NULL,					/* user_splits */
-	NULL,					/* protocol_options */
-	{"gif,jpeg,bmp,ico", 0, 0, 64, 64, 7168, PURPLE_ICON_SCALE_SEND | PURPLE_ICON_SCALE_DISPLAY}, /* icon_spec */
-	oscar_get_actions,		/* get_actions */
-	oscar_list_icon_aim,	/* list_icon */
-	oscar_list_emblem,		/* list_emblems */
-	oscar_status_text,		/* status_text */
-	oscar_tooltip_text,		/* tooltip_text */
-	oscar_status_types,		/* status_types */
-	oscar_blist_node_menu,	/* blist_node_menu */
-	oscar_chat_info,		/* chat_info */
-	oscar_chat_info_defaults, /* chat_info_defaults */
-	oscar_login,			/* login */
-	oscar_close,			/* close */
-	oscar_send_im,			/* send_im */
-	oscar_set_info,			/* set_info */
-	oscar_send_typing,		/* send_typing */
-	oscar_get_info,			/* get_info */
-	oscar_set_status,		/* set_status */
-	oscar_set_idle,			/* set_idle */
-	oscar_change_passwd,	/* change_passwd */
-	oscar_add_buddy,		/* add_buddy */
-	NULL,					/* add_buddies */
-	oscar_remove_buddy,		/* remove_buddy */
-	NULL,					/* remove_buddies */
-	oscar_add_permit,		/* add_permit */
-	oscar_add_deny,			/* add_deny */
-	oscar_rem_permit,		/* rem_permit */
-	oscar_rem_deny,			/* rem_deny */
-	oscar_set_aim_permdeny,	/* set_permit_deny */
-	oscar_join_chat,		/* join_chat */
-	NULL,					/* reject_chat */
-	oscar_get_chat_name,	/* get_chat_name */
-	oscar_chat_invite,		/* chat_invite */
-	oscar_chat_leave,		/* chat_leave */
-	NULL,					/* chat_whisper */
-	oscar_send_chat,		/* chat_send */
-	oscar_keepalive,		/* keepalive */
-	NULL,					/* register_user */
-	NULL,					/* get_cb_info */
-	oscar_alias_buddy,		/* alias_buddy */
-	oscar_move_buddy,		/* group_buddy */
-	oscar_rename_group,		/* rename_group */
-	NULL,					/* buddy_free */
-	oscar_convo_closed,		/* convo_closed */
-	oscar_normalize,		/* normalize */
-	oscar_set_icon,			/* set_buddy_icon */
-	oscar_remove_group,		/* remove_group */
-	NULL,					/* get_cb_real_name */
-	NULL,					/* set_chat_topic */
-	NULL,					/* find_blist_chat */
-	NULL,					/* roomlist_get_list */
-	NULL,					/* roomlist_cancel */
-	NULL,					/* roomlist_expand_category */
-	oscar_can_receive_file,	/* can_receive_file */
-	oscar_send_file,		/* send_file */
-	oscar_new_xfer,			/* new_xfer */
-	oscar_offline_message,	/* offline_message */
-	NULL,					/* whiteboard_protocol_ops */
-	NULL,					/* send_raw */
-	NULL,					/* roomlist_room_serialize */
-	NULL,					/* unregister_user */
-	NULL,					/* send_attention */
-	NULL,					/* get_attention_types */
-	NULL,					/* get_account_text_table */
-	NULL,					/* initiate_media */
-	NULL,					/* get_media_caps */
-	NULL,					/* get_moods */
-	NULL,					/* set_public_alias */
-	NULL,					/* get_public_alias */
-	oscar_get_max_message_size		/* get_max_message_size */
-};
+	PurpleProtocolClass *proto_class = PURPLE_PROTOCOL_CLASS(klass);
+	PurpleAccountOption *option;
+
+	proto_class->id        = AIM_ID;
+	proto_class->name      = AIM_NAME;
+
+	option = purple_account_option_string_new(_("Server"), "server", oscar_get_login_server(FALSE, TRUE));
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
+}
+
+static void
+aim_protocol_interface_init(PurpleProtocolInterface *iface)
+{
+	iface->list_icon            = oscar_list_icon_aim;
+	iface->add_permit           = oscar_add_permit;
+	iface->rem_permit           = oscar_rem_permit;
+	iface->set_permit_deny      = oscar_set_aim_permdeny;
+	iface->get_max_message_size = oscar_get_max_message_size;
+}
+
+static void aim_protocol_base_finalize(AIMProtocolClass *klass) { }
 
 static PurplePluginInfo *
 plugin_query(GError **error)
 {
 	return purple_plugin_info_new(
-		"id",           "prpl-aim",
-		"name",         "AIM",
+		"id",           AIM_ID,
+		"name",         AIM_NAME,
 		"version",      DISPLAY_VERSION,
 		"category",     N_("Protocol"),
 		"summary",      N_("AIM Protocol Plugin"),
@@ -129,8 +79,14 @@ plugin_query(GError **error)
 static gboolean
 plugin_load(PurplePlugin *plugin, GError **error)
 {
-	oscar_init(&protocol, FALSE);
-	purple_protocols_add(&protocol);
+	my_protocol = purple_protocols_add(AIM_TYPE_PROTOCOL);
+	if (!my_protocol) {
+		g_set_error(error, AIM_DOMAIN, 0, _("Failed to add aim protocol"));
+		return FALSE;
+	}
+
+	purple_signal_connect(purple_get_core(), "uri-handler", my_protocol,
+		PURPLE_CALLBACK(oscar_uri_handler), NULL);
 
 	return TRUE;
 }
@@ -138,9 +94,15 @@ plugin_load(PurplePlugin *plugin, GError
 static gboolean
 plugin_unload(PurplePlugin *plugin, GError **error)
 {
-	purple_protocols_remove(&protocol);
+	if (!purple_protocols_remove(my_protocol)) {
+		g_set_error(error, AIM_DOMAIN, 0, _("Failed to remove aim protocol"));
+		return FALSE;
+	}
 
 	return TRUE;
 }
 
+PURPLE_PROTOCOL_DEFINE_EXTENDED(AIMProtocol, aim_protocol,
+                                OSCAR_TYPE_PROTOCOL, 0);
+
 PURPLE_PLUGIN_INIT(aim, plugin_query, plugin_load, plugin_unload);
diff --git a/libpurple/protocols/oscar/libaim.h b/libpurple/protocols/oscar/libaim.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/oscar/libaim.h
@@ -0,0 +1,53 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ *
+ */
+#ifndef _LIBAIM_H_
+#define _LIBAIM_H_
+
+#include "oscar.h"
+
+#define AIM_ID     "prpl-aim"
+#define AIM_NAME   "AIM"
+#define AIM_DOMAIN (g_quark_from_static_string(AIM_ID))
+
+#define AIM_TYPE_PROTOCOL             (aim_protocol_get_type())
+#define AIM_PROTOCOL(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), AIM_TYPE_PROTOCOL, AIMProtocol))
+#define AIM_PROTOCOL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), AIM_TYPE_PROTOCOL, AIMProtocolClass))
+#define AIM_IS_PROTOCOL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), AIM_TYPE_PROTOCOL))
+#define AIM_IS_PROTOCOL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), AIM_TYPE_PROTOCOL))
+#define AIM_PROTOCOL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), AIM_TYPE_PROTOCOL, AIMProtocolClass))
+
+typedef struct _AIMProtocol
+{
+	OscarProtocol parent;
+} AIMProtocol;
+
+typedef struct _AIMProtocolClass
+{
+	OscarProtocolClass parent_class;
+} AIMProtocolClass;
+
+/**
+ * Returns the GType for the AIMProtocol object.
+ */
+GType aim_protocol_get_type(void);
+
+#endif /* _LIBAIM_H_ */
diff --git a/libpurple/protocols/oscar/libicq.c b/libpurple/protocols/oscar/libicq.c
--- a/libpurple/protocols/oscar/libicq.c
+++ b/libpurple/protocols/oscar/libicq.c
@@ -24,10 +24,15 @@
  * which contains all the shared implementation code with libaim
  */
 
+#include "core.h"
 #include "plugins.h"
+#include "signals.h"
 
+#include "libicq.h"
 #include "oscarcommon.h"
 
+static PurpleProtocol *my_protocol = NULL;
+
 static GHashTable *
 icq_get_account_text_table(PurpleAccount *account)
 {
@@ -44,91 +49,39 @@ icq_get_max_message_size(PurpleConnectio
 	return 2346;
 }
 
-static PurpleProtocol protocol =
+static void
+icq_protocol_base_init(ICQProtocolClass *klass)
 {
-	"prpl-icq",				/* id */
-	"ICQ",					/* name */
-	sizeof(PurpleProtocol),       /* struct_size */
-	OPT_PROTO_MAIL_CHECK | OPT_PROTO_IM_IMAGE | OPT_PROTO_INVITE_MESSAGE | OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE,
-	NULL,					/* user_splits */
-	NULL,					/* protocol_options */
-	{"gif,jpeg,bmp,ico", 0, 0, 64, 64, 7168, PURPLE_ICON_SCALE_SEND | PURPLE_ICON_SCALE_DISPLAY}, /* icon_spec */
-	oscar_get_actions,		/* get_actions */
-	oscar_list_icon_icq,	/* list_icon */
-	oscar_list_emblem,		/* list_emblems */
-	oscar_status_text,		/* status_text */
-	oscar_tooltip_text,		/* tooltip_text */
-	oscar_status_types,		/* status_types */
-	oscar_blist_node_menu,	/* blist_node_menu */
-	oscar_chat_info,		/* chat_info */
-	oscar_chat_info_defaults, /* chat_info_defaults */
-	oscar_login,			/* login */
-	oscar_close,			/* close */
-	oscar_send_im,			/* send_im */
-	oscar_set_info,			/* set_info */
-	oscar_send_typing,		/* send_typing */
-	oscar_get_info,			/* get_info */
-	oscar_set_status,		/* set_status */
-	oscar_set_idle,			/* set_idle */
-	oscar_change_passwd,	/* change_passwd */
-	oscar_add_buddy,		/* add_buddy */
-	NULL,					/* add_buddies */
-	oscar_remove_buddy,		/* remove_buddy */
-	NULL,					/* remove_buddies */
-	NULL,		/* add_permit */
-	oscar_add_deny,			/* add_deny */
-	NULL,		/* rem_permit */
-	oscar_rem_deny,			/* rem_deny */
-	NULL,	/* set_permit_deny */
-	oscar_join_chat,		/* join_chat */
-	NULL,					/* reject_chat */
-	oscar_get_chat_name,	/* get_chat_name */
-	oscar_chat_invite,		/* chat_invite */
-	oscar_chat_leave,		/* chat_leave */
-	NULL,					/* chat_whisper */
-	oscar_send_chat,		/* chat_send */
-	oscar_keepalive,		/* keepalive */
-	NULL,					/* register_user */
-	NULL,					/* get_cb_info */
-	oscar_alias_buddy,		/* alias_buddy */
-	oscar_move_buddy,		/* group_buddy */
-	oscar_rename_group,		/* rename_group */
-	NULL,					/* buddy_free */
-	oscar_convo_closed,		/* convo_closed */
-	oscar_normalize,		/* normalize */
-	oscar_set_icon,			/* set_buddy_icon */



More information about the Commits mailing list