/soc/2013/ankitkv/gobjectification: 01edebf55111: Renamed Bonjou...

Ankit Vani a at nevitus.org
Thu Sep 12 14:59:33 EDT 2013


Changeset: 01edebf551112629d87d10a94548e345e0840345
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-12 21:56 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/01edebf55111

Description:

Renamed BonjourData to BonjourConnection, which now inherits PurpleConnection. added bonjour_connection_new().

diffstat:

 libpurple/protocols/bonjour/bonjour.c     |  60 +++++++++++++++++++++++-------
 libpurple/protocols/bonjour/bonjour.h     |  23 ++++++++++-
 libpurple/protocols/bonjour/bonjour_ft.c  |  34 ++++++++--------
 libpurple/protocols/bonjour/jabber.c      |  12 +++---
 libpurple/protocols/bonjour/mdns_avahi.c  |   2 +-
 libpurple/protocols/bonjour/mdns_common.c |   2 +-
 6 files changed, 91 insertions(+), 42 deletions(-)

diffs (truncated from 435 to 300 lines):

diff --git a/libpurple/protocols/bonjour/bonjour.c b/libpurple/protocols/bonjour/bonjour.c
--- a/libpurple/protocols/bonjour/bonjour.c
+++ b/libpurple/protocols/bonjour/bonjour.c
@@ -54,7 +54,7 @@ const char *
 bonjour_get_jid(PurpleAccount *account)
 {
 	PurpleConnection *conn = purple_account_get_connection(account);
-	BonjourData *bd = purple_connection_get_protocol_data(conn);
+	BonjourConnection *bd = BONJOUR_CONNECTION(conn);
 	return bd->jid;
 }
 
@@ -91,7 +91,7 @@ static void
 bonjour_login(PurpleAccount *account)
 {
 	PurpleConnection *gc = purple_account_get_connection(account);
-	BonjourData *bd;
+	BonjourConnection *bd;
 	PurpleStatus *status;
 	PurplePresence *presence;
 
@@ -107,8 +107,7 @@ bonjour_login(PurpleAccount *account)
 #endif /* _WIN32 */
 
 	purple_connection_set_flags(gc, PURPLE_CONNECTION_FLAG_HTML);
-	bd = g_new0(BonjourData, 1);
-	purple_connection_set_protocol_data(gc, bd);
+	bd = BONJOUR_CONNECTION(gc);
 
 	/* Start waiting for jabber connections (iChat style) */
 	bd->jabber_data = g_new0(BonjourJabber, 1);
@@ -162,7 +161,7 @@ static void
 bonjour_close(PurpleConnection *connection)
 {
 	PurpleGroup *bonjour_group;
-	BonjourData *bd = purple_connection_get_protocol_data(connection);
+	BonjourConnection *bd = BONJOUR_CONNECTION(connection);
 
 	bonjour_group = purple_blist_find_group(BONJOUR_GROUP_NAME);
 
@@ -196,8 +195,6 @@ bonjour_close(PurpleConnection *connecti
 
 	if (bd != NULL)
 		g_free(bd->jid);
-	g_free(bd);
-	purple_connection_set_protocol_data(connection, NULL);
 }
 
 static const char *
@@ -209,7 +206,7 @@ bonjour_list_icon(PurpleAccount *account
 static int
 bonjour_send_im(PurpleConnection *connection, const char *to, const char *msg, PurpleMessageFlags flags)
 {
-	BonjourData *bd = purple_connection_get_protocol_data(connection);
+	BonjourConnection *bd = BONJOUR_CONNECTION(connection);
 
 	if(!to || !msg)
 		return 0;
@@ -221,13 +218,13 @@ static void
 bonjour_set_status(PurpleAccount *account, PurpleStatus *status)
 {
 	PurpleConnection *gc;
-	BonjourData *bd;
+	BonjourConnection *bd;
 	PurplePresence *presence;
 	const char *message, *bonjour_status;
 	gchar *stripped;
 
 	gc = purple_account_get_connection(account);
-	bd = purple_connection_get_protocol_data(gc);
+	bd = BONJOUR_CONNECTION(gc);
 	presence = purple_account_get_presence(account);
 
 	message = purple_status_get_attr_string(status, "message");
@@ -332,7 +329,7 @@ bonjour_convo_closed(PurpleConnection *c
 static
 void bonjour_set_buddy_icon(PurpleConnection *conn, PurpleStoredImage *img)
 {
-	BonjourData *bd = purple_connection_get_protocol_data(conn);
+	BonjourConnection *bd = BONJOUR_CONNECTION(conn);
 	bonjour_dns_sd_update_buddy_icon(bd->dns_sd_data);
 }
 
@@ -630,6 +627,32 @@ initialize_default_account_values(void)
 }
 
 static void
+bonjour_connection_init(GObject *object)
+{
+}
+
+static void
+bonjour_connection_class_init(GObjectClass *klass)
+{
+}
+
+static PurpleConnection *
+bonjour_connection_new(PurpleProtocol *protocol, PurpleAccount *account, const char *password)
+{
+	g_return_val_if_fail(protocol != NULL, NULL);
+	g_return_val_if_fail(account != NULL, NULL);
+
+	return g_object_new(BONJOUR_TYPE_CONNECTION,
+	                    "protocol",  protocol,
+	                    "account",   account,
+	                    "password",  password,
+	                    NULL);
+}
+
+PURPLE_DEFINE_TYPE(BonjourConnection, bonjour_connection,
+                   PURPLE_TYPE_CONNECTION);
+
+static void
 bonjour_protocol_init(PurpleProtocol *protocol)
 {
 	PurpleAccountOption *option;
@@ -669,6 +692,7 @@ bonjour_protocol_class_init(PurpleProtoc
 static void
 bonjour_protocol_interface_init(PurpleProtocolInterface *iface)
 {
+	iface->connection_new       = bonjour_connection_new;
 	iface->list_icon            = bonjour_list_icon;
 	iface->status_text          = bonjour_status_text;
 	iface->tooltip_text         = bonjour_tooltip_text;
@@ -689,6 +713,12 @@ bonjour_protocol_interface_init(PurplePr
 	iface->get_max_message_size = bonjour_get_max_message_size;
 }
 
+PURPLE_DEFINE_TYPE_EXTENDED(
+	BonjourProtocol, bonjour_protocol, PURPLE_TYPE_PROTOCOL, 0,
+	PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_INTERFACE,
+	                                  bonjour_protocol_interface_init)
+);
+
 static PurplePluginInfo *
 plugin_query(GError **error)
 {
@@ -710,6 +740,9 @@ plugin_query(GError **error)
 static gboolean
 plugin_load(PurplePlugin *plugin, GError **error)
 {
+	bonjour_connection_register_type(plugin);
+	bonjour_protocol_register_type(plugin);
+
 	my_protocol = purple_protocols_add(BONJOUR_TYPE_PROTOCOL, error);
 	if (!my_protocol)
 		return FALSE;
@@ -731,7 +764,4 @@ plugin_unload(PurplePlugin *plugin, GErr
 	return TRUE;
 }
 
-static PurplePlugin *my_plugin;
-PURPLE_PROTOCOL_DEFINE(my_plugin, BonjourProtocol, bonjour_protocol);
-PURPLE_PLUGIN_INIT_VAL(my_plugin, bonjour, plugin_query, plugin_load,
-                       plugin_unload);
+PURPLE_PLUGIN_INIT(bonjour, plugin_query, plugin_load, plugin_unload);
diff --git a/libpurple/protocols/bonjour/bonjour.h b/libpurple/protocols/bonjour/bonjour.h
--- a/libpurple/protocols/bonjour/bonjour.h
+++ b/libpurple/protocols/bonjour/bonjour.h
@@ -42,6 +42,13 @@
 
 #define BONJOUR_DEFAULT_PORT 5298
 
+#define BONJOUR_TYPE_CONNECTION             (bonjour_connection_get_type())
+#define BONJOUR_CONNECTION(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), BONJOUR_TYPE_CONNECTION, BonjourConnection))
+#define BONJOUR_CONNECTION_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), BONJOUR_TYPE_CONNECTION, BonjourConnectionClass))
+#define BONJOUR_IS_CONNECTION(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), BONJOUR_TYPE_CONNECTION))
+#define BONJOUR_IS_CONNECTION_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), BONJOUR_TYPE_CONNECTION))
+#define BONJOUR_CONNECTION_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), BONJOUR_TYPE_CONNECTION, BonjourConnectionClass))
+
 #define BONJOUR_TYPE_PROTOCOL             (bonjour_protocol_get_type())
 #define BONJOUR_PROTOCOL(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), BONJOUR_TYPE_PROTOCOL, BonjourProtocol))
 #define BONJOUR_PROTOCOL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), BONJOUR_TYPE_PROTOCOL, BonjourProtocolClass))
@@ -59,13 +66,20 @@ typedef struct _BonjourProtocolClass
 	PurpleProtocolClass parent_class;
 } BonjourProtocolClass;
 
-typedef struct _BonjourData
+typedef struct _BonjourConnection
 {
+	PurpleConnection parent;
+
 	BonjourDnsSd *dns_sd_data;
 	BonjourJabber *jabber_data;
 	GSList *xfer_lists;
 	gchar *jid;
-} BonjourData;
+} BonjourConnection;
+
+typedef struct _BonjourConnectionClass
+{
+	PurpleConnectionClass parent_class;
+} BonjourConnectionClass;
 
 /**
  * Returns the GType for the BonjourProtocol object.
@@ -73,6 +87,11 @@ typedef struct _BonjourData
 GType bonjour_protocol_get_type(void);
 
 /**
+ * Returns the GType for the BonjourConnection object.
+ */
+GType bonjour_connection_get_type(void);
+
+/**
  *  This will always be username at machinename
  */
 const char *bonjour_get_jid(PurpleAccount *account);
diff --git a/libpurple/protocols/bonjour/bonjour_ft.c b/libpurple/protocols/bonjour/bonjour_ft.c
--- a/libpurple/protocols/bonjour/bonjour_ft.c
+++ b/libpurple/protocols/bonjour/bonjour_ft.c
@@ -45,7 +45,7 @@ static void bonjour_free_xfer(PurpleXfer
 static unsigned int next_id = 0;
 
 static void
-xep_ft_si_reject(BonjourData *bd, const char *id, const char *to, const char *error_code, const char *error_type)
+xep_ft_si_reject(BonjourConnection *bd, const char *id, const char *to, const char *error_code, const char *error_type)
 {
 	PurpleXmlNode *error_node;
 	XepIq *iq;
@@ -146,7 +146,7 @@ static void bonjour_xfer_end(PurpleXfer 
 }
 
 static PurpleXfer*
-bonjour_si_xfer_find(BonjourData *bd, const char *sid, const char *from)
+bonjour_si_xfer_find(BonjourConnection *bd, const char *sid, const char *from)
 {
 	GSList *xfers;
 	PurpleXfer *xfer;
@@ -181,7 +181,7 @@ xep_ft_si_offer(PurpleXfer *xfer, const 
 	PurpleXmlNode *si_node, *feature, *field, *file, *x;
 	XepIq *iq;
 	XepXfer *xf = purple_xfer_get_protocol_data(xfer);
-	BonjourData *bd = NULL;
+	BonjourConnection *bd = NULL;
 	char buf[32];
 
 	if(!xf)
@@ -245,7 +245,7 @@ xep_ft_si_result(PurpleXfer *xfer, const
 	PurpleXmlNode *si_node, *feature, *field, *value, *x;
 	XepIq *iq;
 	XepXfer *xf;
-	BonjourData *bd;
+	BonjourConnection *bd;
 
 	if(!to || !xfer)
 		return;
@@ -313,7 +313,7 @@ bonjour_free_xfer(PurpleXfer *xfer)
 
 	xf = purple_xfer_get_protocol_data(xfer);
 	if(xf != NULL) {
-		BonjourData *bd = (BonjourData*)xf->data;
+		BonjourConnection *bd = (BonjourConnection*)xf->data;
 		if(bd != NULL) {
 			bd->xfer_lists = g_slist_remove(bd->xfer_lists, xfer);
 			purple_debug_misc("bonjour", "B free xfer from lists(%p).\n", bd->xfer_lists);
@@ -344,13 +344,13 @@ bonjour_new_xfer(PurpleConnection *gc, c
 {
 	PurpleXfer *xfer;
 	XepXfer *xep_xfer;
-	BonjourData *bd;
+	BonjourConnection *bd;
 
 	if(who == NULL || gc == NULL)
 		return NULL;
 
 	purple_debug_info("bonjour", "Bonjour-new-xfer to %s.\n", who);
-	bd = purple_connection_get_protocol_data(gc);
+	bd = BONJOUR_CONNECTION(gc);
 	if(bd == NULL)
 		return NULL;
 
@@ -431,7 +431,7 @@ void
 xep_si_parse(PurpleConnection *pc, PurpleXmlNode *packet, PurpleBuddy *pb)
 {
 	const char *type, *id;
-	BonjourData *bd;
+	BonjourConnection *bd;
 	PurpleXfer *xfer;
 	const gchar *name = NULL;
 
@@ -439,7 +439,7 @@ xep_si_parse(PurpleConnection *pc, Purpl
 	g_return_if_fail(packet != NULL);
 	g_return_if_fail(pb != NULL);
 
-	bd = purple_connection_get_protocol_data(pc);
+	bd = BONJOUR_CONNECTION(pc);
 	if(bd == NULL)
 		return;
 
@@ -484,7 +484,7 @@ xep_si_parse(PurpleConnection *pc, Purpl
 		}
 
 		if (!parsed_receive) {
-			BonjourData *bd = purple_connection_get_protocol_data(pc);
+			BonjourConnection *bd = BONJOUR_CONNECTION(pc);
 
 			purple_debug_info("bonjour", "rejecting unrecognized si SET offer.\n");
 			xep_ft_si_reject(bd, id, name, "403", "cancel");
@@ -496,7 +496,7 @@ xep_si_parse(PurpleConnection *pc, Purpl



More information about the Commits mailing list