/soc/2013/ankitkv/gobjectification: 2961685df856: Made XepXfer i...

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


Changeset: 2961685df856975bf5e152e5c397555c9adfff71
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-13 00:27 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/2961685df856

Description:

Made XepXfer inherit PurpleXfer in bonjour protocol

diffstat:

 libpurple/protocols/bonjour/bonjour.c    |   2 +
 libpurple/protocols/bonjour/bonjour_ft.c |  59 +++++++++++++++++++++----------
 libpurple/protocols/bonjour/bonjour_ft.h |  31 ++++++++++++++++
 3 files changed, 73 insertions(+), 19 deletions(-)

diffs (249 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
@@ -693,6 +693,7 @@ static void
 bonjour_protocol_interface_init(PurpleProtocolInterface *iface)
 {
 	iface->connection_new       = bonjour_connection_new;
+	iface->xfer_new             = xep_xfer_new;
 	iface->list_icon            = bonjour_list_icon;
 	iface->status_text          = bonjour_status_text;
 	iface->tooltip_text         = bonjour_tooltip_text;
@@ -742,6 +743,7 @@ plugin_load(PurplePlugin *plugin, GError
 {
 	bonjour_connection_register_type(plugin);
 	bonjour_protocol_register_type(plugin);
+	xep_xfer_register_type(plugin);
 
 	my_protocol = purple_protocols_add(BONJOUR_TYPE_PROTOCOL, error);
 	if (!my_protocol)
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,6 +45,32 @@ static void bonjour_free_xfer(PurpleXfer
 static unsigned int next_id = 0;
 
 static void
+xep_xfer_init(GObject *object)
+{
+}
+
+static void
+xep_xfer_class_init(GObjectClass *klass)
+{
+}
+
+PurpleXfer *
+xep_xfer_new(PurpleAccount *account, PurpleXferType type, const char *who)
+{
+	g_return_val_if_fail(type    != PURPLE_XFER_TYPE_UNKNOWN, NULL);
+	g_return_val_if_fail(account != NULL, NULL);
+	g_return_val_if_fail(who     != NULL, NULL);
+
+	return g_object_new(XEP_TYPE_XFER,
+	                    "account",      account,
+	                    "type",         type,
+	                    "remote-user",  who,
+	                    NULL);
+}
+
+PURPLE_DEFINE_TYPE(XepXfer, xep_xfer, PURPLE_TYPE_XFER);
+
+static void
 xep_ft_si_reject(BonjourConnection *bd, const char *id, const char *to, const char *error_code, const char *error_type)
 {
 	PurpleXmlNode *error_node;
@@ -90,7 +116,7 @@ static void bonjour_xfer_cancel_send(Pur
 
 static void bonjour_xfer_request_denied(PurpleXfer *xfer)
 {
-	XepXfer *xf = purple_xfer_get_protocol_data(xfer);
+	XepXfer *xf = XEP_XFER(xfer);
 
 	purple_debug_info("bonjour", "Bonjour-xfer-request-denied.\n");
 
@@ -162,7 +188,7 @@ bonjour_si_xfer_find(BonjourConnection *
 		xfer = xfers->data;
 		if(xfer == NULL)
 			break;
-		xf = purple_xfer_get_protocol_data(xfer);
+		xf = XEP_XFER(xfer);
 		if(xf == NULL)
 			break;
 		if(xf->sid && purple_xfer_get_remote_user(xfer) && !strcmp(xf->sid, sid) &&
@@ -180,7 +206,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);
+	XepXfer *xf = XEP_XFER(xfer);
 	BonjourConnection *bd = NULL;
 	char buf[32];
 
@@ -249,7 +275,7 @@ xep_ft_si_result(PurpleXfer *xfer, const
 
 	if(!to || !xfer)
 		return;
-	xf = purple_xfer_get_protocol_data(xfer);
+	xf = XEP_XFER(xfer);
 	if(!xf)
 		return;
 
@@ -311,7 +337,7 @@ bonjour_free_xfer(PurpleXfer *xfer)
 
 	purple_debug_misc("bonjour", "bonjour-free-xfer-%p.\n", xfer);
 
-	xf = purple_xfer_get_protocol_data(xfer);
+	xf = XEP_XFER(xfer);
 	if(xf != NULL) {
 		BonjourConnection *bd = (BonjourConnection*)xf->data;
 		if(bd != NULL) {
@@ -331,9 +357,6 @@ bonjour_free_xfer(PurpleXfer *xfer)
 		g_free(xf->sid);
 
 		purple_xmlnode_free_tree(xf->streamhost);
-
-		g_free(xf);
-		purple_xfer_set_protocol_data(xfer, NULL);
 	}
 
 	purple_debug_misc("bonjour", "Need close socket.\n");
@@ -356,8 +379,7 @@ bonjour_new_xfer(PurpleConnection *gc, c
 
 	/* Build the file transfer handle */
 	xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_TYPE_SEND, who);
-	xep_xfer = g_new0(XepXfer, 1);
-	purple_xfer_set_protocol_data(xfer, xep_xfer);
+	xep_xfer = XEP_XFER(xfer);
 	xep_xfer->data = bd;
 
 	purple_debug_info("bonjour", "Bonjour-new-xfer bd=%p data=%p.\n", bd, xep_xfer->data);
@@ -402,7 +424,7 @@ bonjour_xfer_init(PurpleXfer *xfer)
 	BonjourBuddy *bb;
 	XepXfer *xf;
 
-	xf = purple_xfer_get_protocol_data(xfer);
+	xf = XEP_XFER(xfer);
 	if(xf == NULL)
 		return;
 
@@ -657,7 +679,7 @@ static gboolean
 	char *tmp_iq_id;
 	const char *jid, *host, *port;
 	int portnum;
-	XepXfer *xf = purple_xfer_get_protocol_data(xfer);
+	XepXfer *xf = XEP_XFER(xfer);
 
 	for(; streamhost; streamhost = purple_xmlnode_get_next_twin(streamhost)) {
 		if(!(jid = purple_xmlnode_get_attrib(streamhost, "jid")) ||
@@ -762,8 +784,7 @@ bonjour_xfer_receive(PurpleConnection *p
 
 	/* Build the file transfer handle */
 	xfer = purple_xfer_new(purple_connection_get_account(pc), PURPLE_XFER_TYPE_RECEIVE, from);
-	xf = g_new0(XepXfer, 1);
-	purple_xfer_set_protocol_data(xfer, xf);
+	xf = XEP_XFER(xfer);
 	xf->data = bd;
 	purple_xfer_set_filename(xfer, filename);
 	xf->iq_id = g_strdup(id);
@@ -785,7 +806,7 @@ static void
 bonjour_sock5_request_cb(gpointer data, gint source, PurpleInputCondition cond)
 {
 	PurpleXfer *xfer = data;
-	XepXfer *xf = purple_xfer_get_protocol_data(xfer);
+	XepXfer *xf = XEP_XFER(xfer);
 	int acceptfd;
 	int len = 0;
 
@@ -921,7 +942,7 @@ bonjour_bytestreams_listen(int sock, gpo
 
 	purple_xfer_set_watcher(xfer, purple_input_add(sock, PURPLE_INPUT_READ,
 					 bonjour_sock5_request_cb, xfer));
-	xf = purple_xfer_get_protocol_data(xfer);
+	xf = XEP_XFER(xfer);
 	xf->listen_data = NULL;
 
 	bd = xf->data;
@@ -959,7 +980,7 @@ bonjour_bytestreams_init(PurpleXfer *xfe
 		return;
 
 	purple_debug_info("bonjour", "Bonjour-bytestreams-init.\n");
-	xf = purple_xfer_get_protocol_data(xfer);
+	xf = XEP_XFER(xfer);
 
 	xf->listen_data = purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, FALSE,
 						      bonjour_bytestreams_listen, xfer);
@@ -973,7 +994,7 @@ static void
 bonjour_bytestreams_connect_cb(gpointer data, gint source, const gchar *error_message)
 {
 	PurpleXfer *xfer = data;
-	XepXfer *xf = purple_xfer_get_protocol_data(xfer);
+	XepXfer *xf = XEP_XFER(xfer);
 	XepIq *iq;
 	PurpleXmlNode *q_node, *tmp_node;
 	BonjourConnection *bd;
@@ -1031,7 +1052,7 @@ bonjour_bytestreams_connect(PurpleXfer *
 
 	purple_debug_info("bonjour", "bonjour-bytestreams-connect.\n");
 
-	xf = purple_xfer_get_protocol_data(xfer);
+	xf = XEP_XFER(xfer);
 	if(!xf)
 		return;
 
diff --git a/libpurple/protocols/bonjour/bonjour_ft.h b/libpurple/protocols/bonjour/bonjour_ft.h
--- a/libpurple/protocols/bonjour/bonjour_ft.h
+++ b/libpurple/protocols/bonjour/bonjour_ft.h
@@ -23,7 +23,16 @@
 #define _BONJOUR_FT_H_
 #include "network.h"
 #include "proxy.h"
+
+#define XEP_TYPE_XFER             (xep_xfer_get_type())
+#define XEP_XFER(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XEP_TYPE_XFER, XepXfer))
+#define XEP_XFER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), XEP_TYPE_XFER, XepXferClass))
+#define XEP_IS_XFER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), XEP_TYPE_XFER))
+#define XEP_IS_XFER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), XEP_TYPE_XFER))
+#define XEP_XFER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), XEP_TYPE_XFER, XepXferClass))
 typedef struct _XepXfer XepXfer;
+typedef struct _XepXferClass XepXferClass;
+
 typedef enum {
 	XEP_BYTESTREAMS = 1,
 	XEP_IBB = 2,
@@ -32,6 +41,8 @@ typedef enum {
 
 struct _XepXfer
 {
+	PurpleXfer parent;
+
 	void *data;
 	char *filename;
 	int filesize;
@@ -54,6 +65,26 @@ struct _XepXfer
 	PurpleBuddy *pb;
 };
 
+struct _XepXferClass
+{
+	PurpleXferClass parent_class;
+};
+
+/**
+ * Registers the type for XepXfer in the type system.
+ */
+void xep_xfer_register_type(PurplePlugin *plugin);
+
+/**
+ * Returns the GType for the XepXfer object.
+ */
+GType xep_xfer_get_type(void);
+
+/**
+ * Returns a new XepXfer instance.
+ */
+PurpleXfer *xep_xfer_new(PurpleAccount *account, PurpleXferType type, const char *who);
+
 /**
  * Create a new PurpleXfer
  *



More information about the Commits mailing list