/soc/2013/ankitkv/gobjectification: cd3ea761181c: Refactored mxi...
Ankit Vani
a at nevitus.org
Tue Aug 27 07:04:59 EDT 2013
Changeset: cd3ea761181c53dd2d2e756ae8a41571169e1506
Author: Ankit Vani <a at nevitus.org>
Date: 2013-08-27 16:34 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/cd3ea761181c
Description:
Refactored mxit to use the new protocol API
diffstat:
libpurple/protocols/mxit/mxit.c | 212 +++++++++++++++++++++------------------
libpurple/protocols/mxit/mxit.h | 23 ++++
2 files changed, 138 insertions(+), 97 deletions(-)
diffs (truncated from 310 to 300 lines):
diff --git a/libpurple/protocols/mxit/mxit.c b/libpurple/protocols/mxit/mxit.c
--- a/libpurple/protocols/mxit/mxit.c
+++ b/libpurple/protocols/mxit/mxit.c
@@ -48,6 +48,7 @@ static void *(*mxit_pidgin_uri_cb)(const
static PurpleNotifyUiOps* mxit_nots_override_original;
static PurpleNotifyUiOps mxit_nots_override;
static int not_link_ref_count = 0;
+static PurpleProtocol *my_protocol = NULL;
/*------------------------------------------------------------------------
@@ -717,89 +718,107 @@ static unsigned int mxit_send_typing( Pu
/*========================================================================================================================*/
-static PurpleProtocol proto_info = {
- MXIT_PLUGIN_ID, /* protocol id (must be unique) */
- MXIT_PLUGIN_NAME, /* protocol name (this will be displayed in the UI) */
- sizeof( PurpleProtocol ), /* struct_size */
- OPT_PROTO_REGISTER_NOSCREENNAME | OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_IM_IMAGE | OPT_PROTO_INVITE_MESSAGE | OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE, /* options */
- NULL, /* user_splits */
- NULL, /* protocol_options */
- { /* icon_spec */
+/*------------------------------------------------------------------------
+ * Initializing the MXit class.
+ *
+ * @param klass The MXit class
+ */
+static void
+mxit_protocol_base_init( MXitProtocolClass *klass )
+{
+ PurpleProtocolClass *proto_class = PURPLE_PROTOCOL_CLASS(klass);
+ PurpleAccountOption *option;
+
+ proto_class->id = MXIT_PLUGIN_ID;
+ proto_class->name = MXIT_PLUGIN_NAME;
+ proto_class->options = OPT_PROTO_REGISTER_NOSCREENNAME |
+ OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_IM_IMAGE |
+ OPT_PROTO_INVITE_MESSAGE |
+ OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE;
+ proto_class->icon_spec = (PurpleBuddyIconSpec)
+ {
"png,jpeg,bmp", /* supported formats */
32, 32, /* min width & height */
800, 800, /* max width & height */
CP_MAX_FILESIZE, /* max filesize */
PURPLE_ICON_SCALE_SEND | PURPLE_ICON_SCALE_DISPLAY /* scaling rules */
- },
- mxit_get_actions, /* get_actions [actions.c] */
- mxit_list_icon, /* list_icon */
- mxit_list_emblem, /* list_emblem */
- mxit_status_text, /* status_text */
- mxit_tooltip, /* tooltip_text */
- mxit_status_types, /* status types [roster.c] */
- mxit_blist_menu, /* blist_node_menu */
- mxit_chat_info, /* chat_info [multimx.c] */
- mxit_chat_info_defaults,/* chat_info_defaults */
- mxit_login, /* login [login.c] */
- mxit_close, /* close */
- mxit_send_im, /* send_im */
- NULL, /* set_info */
- mxit_send_typing, /* send_typing */
- mxit_get_info, /* get_info */
- mxit_set_status, /* set_status */
- NULL, /* set_idle */
- NULL, /* change_passwd */
- mxit_add_buddy, /* add_buddy [roster.c] */
- NULL, /* add_buddies */
- mxit_remove_buddy, /* remove_buddy [roster.c] */
- NULL, /* remove_buddies */
- NULL, /* add_permit */
- NULL, /* add_deny */
- NULL, /* rem_permit */
- NULL, /* rem_deny */
- NULL, /* set_permit_deny */
- mxit_chat_join, /* join_chat [multimx.c] */
- mxit_chat_reject, /* reject chat invite [multimx.c] */
- mxit_chat_name, /* get_chat_name [multimx.c] */
- mxit_chat_invite, /* chat_invite [multimx.c] */
- mxit_chat_leave, /* chat_leave [multimx.c] */
- NULL, /* chat_whisper */
- mxit_chat_send, /* chat_send [multimx.c] */
- mxit_keepalive, /* keepalive */
- mxit_register, /* register_user */
- NULL, /* get_cb_info */
- mxit_buddy_alias, /* alias_buddy [roster.c] */
- mxit_buddy_group, /* group_buddy [roster.c] */
- mxit_rename_group, /* rename_group [roster.c] */
- mxit_free_buddy, /* buddy_free */
- NULL, /* convo_closed */
- NULL, /* normalize */
- mxit_set_buddy_icon, /* set_buddy_icon */
- NULL, /* remove_group */ // TODO: Add function to move all contacts out of this group (cmd=30 - 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 */
- mxit_xfer_enabled, /* can_receive_file [filexfer.c] */
- mxit_xfer_tx, /* send_file [filexfer.c */
- mxit_xfer_new, /* new_xfer [filexfer.c] */
- mxit_offline_message, /* offline_message */
- NULL, /* whiteboard_protocol_ops */
- NULL, /* send_raw */
- NULL, /* roomlist_room_serialize */
- NULL, /* unregister_user */
- NULL, /* send_attention */
- NULL, /* attention_types */
- mxit_get_text_table, /* get_account_text_table */
- mxit_media_initiate, /* initiate_media */
- mxit_media_caps, /* get_media_caps */
- mxit_get_moods, /* get_moods */
- NULL, /* set_public_alias */
- NULL, /* get_public_alias */
- NULL /* get_max_message_size */
-};
+ };
+
+ /* Configuration options */
+
+ /* WAP server (reference: "libpurple/accountopt.h") */
+ option = purple_account_option_string_new( _( "WAP Server" ), MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE );
+ proto_class->protocol_options = g_list_append( proto_class->protocol_options, option );
+
+ option = purple_account_option_bool_new( _( "Connect via HTTP" ), MXIT_CONFIG_USE_HTTP, FALSE );
+ proto_class->protocol_options = g_list_append( proto_class->protocol_options, option );
+
+ option = purple_account_option_bool_new( _( "Enable splash-screen popup" ), MXIT_CONFIG_SPLASHPOPUP, FALSE );
+ proto_class->protocol_options = g_list_append( proto_class->protocol_options, option );
+}
+
+
+/*------------------------------------------------------------------------
+ * Initializing the MXit protocol interface.
+ *
+ * @param iface The protocol interface
+ */
+static void
+mxit_protocol_interface_init( PurpleProtocolInterface *iface )
+{
+ iface->get_actions = mxit_get_actions; /* [actions.c] */
+ iface->list_icon = mxit_list_icon;
+ iface->list_emblem = mxit_list_emblem;
+ iface->status_text = mxit_status_text;
+ iface->tooltip_text = mxit_tooltip;
+ iface->status_types = mxit_status_types; /* [roster.c] */
+ iface->blist_node_menu = mxit_blist_menu;
+ iface->chat_info = mxit_chat_info; /* [multimx.c] */
+ iface->chat_info_defaults = mxit_chat_info_defaults;
+ iface->login = mxit_login; /* [login.c] */
+ iface->close = mxit_close;
+ iface->send_im = mxit_send_im;
+ iface->send_typing = mxit_send_typing;
+ iface->get_info = mxit_get_info;
+ iface->set_status = mxit_set_status;
+ iface->add_buddy = mxit_add_buddy; /* [roster.c] */
+ iface->remove_buddy = mxit_remove_buddy; /* [roster.c] */
+ iface->join_chat = mxit_chat_join; /* [multimx.c] */
+ iface->reject_chat = mxit_chat_reject; /* [multimx.c] */
+ iface->get_chat_name = mxit_chat_name; /* [multimx.c] */
+ iface->chat_invite = mxit_chat_invite; /* [multimx.c] */
+ iface->chat_leave = mxit_chat_leave; /* [multimx.c] */
+ iface->chat_send = mxit_chat_send; /* [multimx.c] */
+ iface->keepalive = mxit_keepalive;
+ iface->register_user = mxit_register;
+ iface->alias_buddy = mxit_buddy_alias; /* [roster.c] */
+ iface->group_buddy = mxit_buddy_group; /* [roster.c] */
+ iface->rename_group = mxit_rename_group; /* [roster.c] */
+ iface->buddy_free = mxit_free_buddy;
+ iface->set_buddy_icon = mxit_set_buddy_icon;
+ iface->can_receive_file = mxit_xfer_enabled; /* [filexfer.c] */
+ iface->send_file = mxit_xfer_tx; /* [filexfer.c] */
+ iface->new_xfer = mxit_xfer_new; /* [filexfer.c] */
+ iface->offline_message = mxit_offline_message;
+ iface->get_account_text_table = mxit_get_text_table;
+ iface->initiate_media = mxit_media_initiate;
+ iface->get_media_caps = mxit_media_caps;
+ iface->get_moods = mxit_get_moods;
+
+ /* TODO: Add function to move all contacts out of this group (cmd=30 - remove group)? */
+ iface->remove_group = NULL;
+}
+
+
+/*------------------------------------------------------------------------
+ * Finalizing the MXit class.
+ *
+ * @param klass The MXit class
+ */
+static void
+mxit_protocol_base_finalize( MXitProtocolClass *klass )
+{
+}
/*------------------------------------------------------------------------
@@ -807,7 +826,8 @@ static PurpleProtocol proto_info = {
*
* @param error Query error (if any)
*/
-static PurplePluginInfo *plugin_query( GError **error )
+static PurplePluginInfo *
+plugin_query( GError **error )
{
return purple_plugin_info_new(
"id", MXIT_PLUGIN_ID, /* plugin id (must be unique) */
@@ -832,23 +852,15 @@ static PurplePluginInfo *plugin_query( G
* @param plugin The plugin object
* @param error Load error (if any)
*/
-static gboolean plugin_load( PurplePlugin* plugin, GError **error )
+static gboolean
+plugin_load( PurplePlugin *plugin, GError **error )
{
- PurpleAccountOption* option;
+ my_protocol = purple_protocols_add(MXIT_TYPE_PROTOCOL);
- /* Configuration options */
-
- /* WAP server (reference: "libpurple/accountopt.h") */
- option = purple_account_option_string_new( _( "WAP Server" ), MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE );
- proto_info.protocol_options = g_list_append( proto_info.protocol_options, option );
-
- option = purple_account_option_bool_new( _( "Connect via HTTP" ), MXIT_CONFIG_USE_HTTP, FALSE );
- proto_info.protocol_options = g_list_append( proto_info.protocol_options, option );
-
- option = purple_account_option_bool_new( _( "Enable splash-screen popup" ), MXIT_CONFIG_SPLASHPOPUP, FALSE );
- proto_info.protocol_options = g_list_append( proto_info.protocol_options, option );
-
- purple_protocols_add( &proto_info );
+ if (!my_protocol) {
+ g_set_error(error, MXIT_PLUGIN_DOMAIN, 0, _("Failed to add mxit protocol"));
+ return FALSE;
+ }
return TRUE;
}
@@ -860,12 +872,18 @@ static gboolean plugin_load( PurplePlugi
* @param plugin The plugin object
* @param error Unload error (if any)
*/
-static gboolean plugin_unload( PurplePlugin* plugin, GError **error )
+static gboolean
+plugin_unload( PurplePlugin *plugin, GError **error )
{
- purple_protocols_remove( &proto_info );
+ if (!purple_protocols_remove(my_protocol)) {
+ g_set_error(error, MXIT_PLUGIN_DOMAIN, 0, _("Failed to remove mxit protocol"));
+ return FALSE;
+ }
return TRUE;
}
-PURPLE_PLUGIN_INIT( mxit, plugin_query, plugin_load, plugin_unload );
+PURPLE_PROTOCOL_DEFINE ( MXitProtocol, mxit_protocol );
+PURPLE_PLUGIN_INIT ( mxit, plugin_query, plugin_load, plugin_unload );
+
diff --git a/libpurple/protocols/mxit/mxit.h b/libpurple/protocols/mxit/mxit.h
--- a/libpurple/protocols/mxit/mxit.h
+++ b/libpurple/protocols/mxit/mxit.h
@@ -70,9 +70,20 @@
#define MXIT_PLUGIN_SUMMARY "MXit Protocol Plugin"
#define MXIT_PLUGIN_DESC "MXit"
+#define MXIT_PLUGIN_DOMAIN (g_quark_from_static_string(MXIT_PLUGIN_ID))
+
#define MXIT_HTTP_USERAGENT "libpurple-"DISPLAY_VERSION
+/* protocol type macros */
+#define MXIT_TYPE_PROTOCOL (mxit_protocol_get_type())
+#define MXIT_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MXIT_TYPE_PROTOCOL, MXitProtocol))
+#define MXIT_PROTOCOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), MXIT_TYPE_PROTOCOL, MXitProtocolClass))
+#define MXIT_IS_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MXIT_TYPE_PROTOCOL))
+#define MXIT_IS_PROTOCOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MXIT_TYPE_PROTOCOL))
+#define MXIT_PROTOCOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), MXIT_TYPE_PROTOCOL, MXitProtocolClass))
+
+
/* default connection settings */
#define DEFAULT_SERVER "stream.mxit.co.za"
#define DEFAULT_PORT 9119
@@ -125,6 +136,17 @@
#define ARRAY_SIZE( x ) ( sizeof( x ) / sizeof( x[0] ) )
+typedef struct _MXitProtocol
+{
+ PurpleProtocol parent;
+} MXitProtocol;
+
+typedef struct _MXitProtocolClass
+{
+ PurpleProtocolClass parent_class;
+} MXitProtocolClass;
+
+
/*
More information about the Commits
mailing list