/soc/2013/ankitkv/gobjectification: 095b9c85c45c: Refactored jab...
Ankit Vani
a at nevitus.org
Mon Aug 26 18:38:32 EDT 2013
Changeset: 095b9c85c45c14f10686cf709a9d0758437a6cf2
Author: Ankit Vani <a at nevitus.org>
Date: 2013-08-27 04:08 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/095b9c85c45c
Description:
Refactored jabber to use the new protocol API.
XMPPProtocol, GTalkProtocol and FacebookProtocol inherit JabberProtocol.
diffstat:
libpurple/protocols/jabber/jabber.c | 82 ++++++++-
libpurple/protocols/jabber/jabber.h | 27 ++-
libpurple/protocols/jabber/libfacebook.c | 304 ++++++++++++------------------
libpurple/protocols/jabber/libfacebook.h | 53 +++++
libpurple/protocols/jabber/libgtalk.c | 215 +++++++--------------
libpurple/protocols/jabber/libgtalk.h | 53 +++++
libpurple/protocols/jabber/libxmpp.c | 202 ++++++--------------
libpurple/protocols/jabber/libxmpp.h | 53 +++++
8 files changed, 518 insertions(+), 471 deletions(-)
diffs (truncated from 1295 to 300 lines):
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -3932,7 +3932,7 @@ jabber_do_uninit(void)
jabber_cmds = NULL;
}
-void jabber_plugin_init(PurpleProtocol *protocol)
+void jabber_protocol_init(PurpleProtocol *protocol)
{
++plugin_ref;
@@ -4045,7 +4045,7 @@ void jabber_plugin_init(PurpleProtocol *
PURPLE_TYPE_XMLNODE);
}
-void jabber_plugin_uninit(PurpleProtocol *protocol)
+void jabber_protocol_uninit(PurpleProtocol *protocol)
{
g_return_if_fail(plugin_ref > 0);
@@ -4059,3 +4059,81 @@ void jabber_plugin_uninit(PurpleProtocol
if (plugin_ref == 0)
jabber_do_uninit();
}
+
+static void
+jabber_protocol_base_init(JabberProtocolClass *klass)
+{
+ PurpleProtocolClass *proto_class = PURPLE_PROTOCOL_CLASS(klass);
+
+ proto_class->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME |
+ OPT_PROTO_MAIL_CHECK |
+#ifdef HAVE_CYRUS_SASL
+ OPT_PROTO_PASSWORD_OPTIONAL |
+#endif
+ OPT_PROTO_SLASH_COMMANDS_NATIVE;
+
+ proto_class->icon_spec = (PurpleBuddyIconSpec) {"png", 32, 32, 96, 96, 0,
+ PURPLE_ICON_SCALE_SEND |
+ PURPLE_ICON_SCALE_DISPLAY};
+}
+
+static void
+jabber_protocol_interface_init(PurpleProtocolInterface *iface)
+{
+ iface->get_actions = jabber_get_actions;
+ iface->list_icon = jabber_list_icon;
+ iface->list_emblem = jabber_list_emblem;
+ iface->status_text = jabber_status_text;
+ iface->tooltip_text = jabber_tooltip_text;
+ iface->status_types = jabber_status_types;
+ iface->blist_node_menu = jabber_blist_node_menu;
+ iface->chat_info = jabber_chat_info;
+ iface->chat_info_defaults = jabber_chat_info_defaults;
+ iface->login = jabber_login;
+ iface->close = jabber_close;
+ iface->send_im = jabber_message_send_im;
+ iface->set_info = jabber_set_info;
+ iface->send_typing = jabber_send_typing;
+ iface->get_info = jabber_buddy_get_info;
+ iface->set_status = jabber_set_status;
+ iface->set_idle = jabber_idle_set;
+ iface->add_buddy = jabber_roster_add_buddy;
+ iface->remove_buddy = jabber_roster_remove_buddy;
+ iface->add_deny = jabber_add_deny;
+ iface->rem_deny = jabber_rem_deny;
+ iface->join_chat = jabber_chat_join;
+ iface->get_chat_name = jabber_get_chat_name;
+ iface->chat_invite = jabber_chat_invite;
+ iface->chat_leave = jabber_chat_leave;
+ iface->chat_send = jabber_message_send_chat;
+ iface->keepalive = jabber_keepalive;
+ iface->register_user = jabber_register_account;
+ iface->unregister_user = jabber_unregister_account;
+ iface->alias_buddy = jabber_roster_alias_change;
+ iface->group_buddy = jabber_roster_group_change;
+ iface->rename_group = jabber_roster_group_rename;
+ iface->convo_closed = jabber_convo_closed;
+ iface->normalize = jabber_normalize;
+ iface->set_buddy_icon = jabber_set_buddy_icon;
+ iface->get_cb_real_name = jabber_chat_user_real_name;
+ iface->set_chat_topic = jabber_chat_set_topic;
+ iface->find_blist_chat = jabber_find_blist_chat;
+ iface->roomlist_get_list = jabber_roomlist_get_list;
+ iface->roomlist_cancel = jabber_roomlist_cancel;
+ iface->can_receive_file = jabber_can_receive_file;
+ iface->send_file = jabber_si_xfer_send;
+ iface->new_xfer = jabber_si_new_xfer;
+ iface->offline_message = jabber_offline_message;
+ iface->send_raw = jabber_protocol_send_raw;
+ iface->roomlist_room_serialize = jabber_roomlist_room_serialize;
+ iface->send_attention = jabber_send_attention;
+ iface->get_attention_types = jabber_attention_types;
+ iface->initiate_media = jabber_initiate_media;
+ iface->get_media_caps = jabber_get_media_caps;
+ iface->get_moods = jabber_get_moods;
+}
+
+static void jabber_protocol_base_finalize(JabberProtocolClass *klass) { }
+
+PURPLE_PROTOCOL_DEFINE_EXTENDED (JabberProtocol, jabber_protocol,
+ PURPLE_TYPE_PROTOCOL, G_TYPE_FLAG_ABSTRACT);
diff --git a/libpurple/protocols/jabber/jabber.h b/libpurple/protocols/jabber/jabber.h
--- a/libpurple/protocols/jabber/jabber.h
+++ b/libpurple/protocols/jabber/jabber.h
@@ -63,6 +63,7 @@ typedef struct _JabberStream JabberStrea
#include "http.h"
#include "media.h"
#include "mediamanager.h"
+#include "protocol.h"
#include "roomlist.h"
#include "sslconn.h"
@@ -81,6 +82,13 @@ typedef struct _JabberStream JabberStrea
#define CAPS0115_NODE "https://pidgin.im/"
+#define JABBER_TYPE_PROTOCOL (jabber_protocol_get_type())
+#define JABBER_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), JABBER_TYPE_PROTOCOL, JabberProtocol))
+#define JABBER_PROTOCOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), JABBER_TYPE_PROTOCOL, JabberProtocolClass))
+#define JABBER_IS_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), JABBER_TYPE_PROTOCOL))
+#define JABBER_IS_PROTOCOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), JABBER_TYPE_PROTOCOL))
+#define JABBER_PROTOCOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), JABBER_TYPE_PROTOCOL, JabberProtocolClass))
+
#define JABBER_DEFAULT_REQUIRE_TLS "require_starttls"
#define JABBER_DEFAULT_FT_PROXIES "proxy.eu.jabber.org"
@@ -97,6 +105,16 @@ typedef enum {
JABBER_STREAM_CONNECTED
} JabberStreamState;
+typedef struct _JabberProtocol
+{
+ PurpleProtocol parent;
+} JabberProtocol;
+
+typedef struct _JabberProtocolClass
+{
+ PurpleProtocolClass parent_class;
+} JabberProtocolClass;
+
struct _JabberStream
{
int fd;
@@ -309,6 +327,11 @@ extern GList *jabber_features;
*/
extern GList *jabber_identities;
+/**
+ * Returns the GType for the JabberProtocol object.
+ */
+GType jabber_protocol_get_type(void);
+
void jabber_stream_features_parse(JabberStream *js, xmlnode *packet);
void jabber_process_packet(JabberStream *js, xmlnode **packet);
void jabber_send(JabberStream *js, xmlnode *data);
@@ -412,7 +435,7 @@ gboolean jabber_initiate_media(PurpleAcc
PurpleMediaCaps jabber_get_media_caps(PurpleAccount *account, const char *who);
gboolean jabber_can_receive_file(PurpleConnection *gc, const gchar *who);
-void jabber_plugin_init(PurpleProtocol *protocol);
-void jabber_plugin_uninit(PurpleProtocol *protocol);
+void jabber_protocol_init(PurpleProtocol *protocol);
+void jabber_protocol_uninit(PurpleProtocol *protocol);
#endif /* PURPLE_JABBER_H_ */
diff --git a/libpurple/protocols/jabber/libfacebook.c b/libpurple/protocols/jabber/libfacebook.c
--- a/libpurple/protocols/jabber/libfacebook.c
+++ b/libpurple/protocols/jabber/libfacebook.c
@@ -26,120 +26,14 @@
*/
#include "internal.h"
+#include "chat.h"
+#include "core.h"
+#include "plugins.h"
-#include "accountopt.h"
-#include "core.h"
-#include "debug.h"
-#include "version.h"
-
-#include "iq.h"
-#include "jabber.h"
-#include "chat.h"
-#include "disco.h"
-#include "message.h"
-#include "roster.h"
-#include "si.h"
-#include "message.h"
-#include "plugins.h"
-#include "presence.h"
-#include "google/google.h"
-#include "pep.h"
-#include "usermood.h"
-#include "usertune.h"
-#include "caps.h"
-#include "data.h"
-#include "ibb.h"
-
-static const char *
-facebook_list_icon(PurpleAccount *a, PurpleBuddy *b)
-{
- return "facebook";
-}
+#include "libfacebook.h"
static PurpleProtocol *my_protocol = NULL;
-static PurpleProtocol protocol =
-{
- "prpl-facebook-xmpp", /* id */
- "Facebook (XMPP)", /* name */
- sizeof(PurpleProtocol), /* struct_size */
- OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_MAIL_CHECK |
-#ifdef HAVE_CYRUS_SASL
- OPT_PROTO_PASSWORD_OPTIONAL |
-#endif
- OPT_PROTO_SLASH_COMMANDS_NATIVE,
- NULL, /* user_splits */
- NULL, /* protocol_options */
- {"png", 32, 32, 96, 96, 0, PURPLE_ICON_SCALE_SEND | PURPLE_ICON_SCALE_DISPLAY}, /* icon_spec */
- jabber_get_actions, /* get_actions */
- facebook_list_icon, /* list_icon */
- jabber_list_emblem, /* list_emblems */
- jabber_status_text, /* status_text */
- jabber_tooltip_text, /* tooltip_text */
- jabber_status_types, /* status_types */
- jabber_blist_node_menu, /* blist_node_menu */
- jabber_chat_info, /* chat_info */
- jabber_chat_info_defaults, /* chat_info_defaults */
- jabber_login, /* login */
- jabber_close, /* close */
- jabber_message_send_im, /* send_im */
- jabber_set_info, /* set_info */
- jabber_send_typing, /* send_typing */
- jabber_buddy_get_info, /* get_info */
- jabber_set_status, /* set_status */
- jabber_idle_set, /* set_idle */
- NULL, /* change_passwd */
- NULL, /* add_buddy */
- NULL, /* add_buddies */
- NULL, /* remove_buddy */
- NULL, /* remove_buddies */
- NULL, /* add_permit */
- NULL, /* add_deny */
- NULL, /* rem_permit */
- NULL, /* rem_deny */
- NULL, /* set_permit_deny */
- jabber_chat_join, /* join_chat */
- NULL, /* reject_chat */
- jabber_get_chat_name, /* get_chat_name */
- jabber_chat_invite, /* chat_invite */
- jabber_chat_leave, /* chat_leave */
- NULL, /* chat_whisper */
- jabber_message_send_chat, /* chat_send */
- jabber_keepalive, /* keepalive */
- NULL, /* register_user */
- NULL, /* get_cb_info */
- NULL, /* alias_buddy */
- NULL, /* group_buddy */
- NULL, /* rename_group */
- NULL, /* buddy_free */
- jabber_convo_closed, /* convo_closed */
- jabber_normalize, /* normalize */
- jabber_set_buddy_icon, /* set_buddy_icon */
- NULL, /* remove_group */
- jabber_chat_user_real_name, /* get_cb_real_name */
- jabber_chat_set_topic, /* set_chat_topic */
- jabber_find_blist_chat, /* find_blist_chat */
- jabber_roomlist_get_list, /* roomlist_get_list */
- jabber_roomlist_cancel, /* roomlist_cancel */
- NULL, /* roomlist_expand_category */
- NULL, /* can_receive_file */
- NULL, /* send_file */
- NULL, /* new_xfer */
- jabber_offline_message, /* offline_message */
- NULL, /* whiteboard_protocol_ops */
- jabber_protocol_send_raw, /* send_raw */
- jabber_roomlist_room_serialize, /* roomlist_room_serialize */
- NULL, /* unregister_user */
- NULL, /* send_attention */
- NULL, /* 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 */
-};
-
static PurpleAccount *find_acct(const char *prpl, const char *acct_id)
{
PurpleAccount *acct = NULL;
@@ -172,7 +66,7 @@ static gboolean xmpp_uri_handler(const c
if (g_ascii_strcasecmp(proto, "xmpp"))
return FALSE;
- acct = find_acct(my_protocol->id, acct_id);
More information about the Commits
mailing list