/soc/2013/ankitkv/gobjectification: 8b46f11b9e7e: Refactored bon...

Ankit Vani a at nevitus.org
Thu Sep 5 13:03:34 EDT 2013


Changeset: 8b46f11b9e7ef320482e0d39f25ae102080466c3
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-05 22:26 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/8b46f11b9e7e

Description:

Refactored bonjour and irc to use the GObject xfer API

diffstat:

 libpurple/protocols/bonjour/bonjour.c    |   2 +-
 libpurple/protocols/bonjour/bonjour_ft.c |  39 ++++++++++++++++++++------
 libpurple/protocols/bonjour/jabber.c     |   2 +-
 libpurple/protocols/irc/dcc_send.c       |  47 +++++++++++++++++++++----------
 4 files changed, 64 insertions(+), 26 deletions(-)

diffs (207 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
@@ -42,7 +42,7 @@
 #include "mdns_common.h"
 #include "jabber.h"
 #include "buddy.h"
-#include "bonjour_xfer.h"
+#include "bonjour_ft.h"
 
 static char *default_firstname;
 static char *default_lastname;
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
@@ -27,7 +27,7 @@
 #include "xfer.h"
 #include "buddy.h"
 #include "bonjour.h"
-#include "bonjour_xfer.h"
+#include "bonjour_ft.h"
 #include "ciphers/sha1hash.h"
 
 static void
@@ -339,6 +339,19 @@ bonjour_free_xfer(PurpleXfer *xfer)
 	purple_debug_misc("bonjour", "Need close socket.\n");
 }
 
+static PurpleXferIoOps send_ops =
+{
+	bonjour_xfer_init,         /* init */
+	NULL,                      /* request_denied */
+	NULL,                      /* start */
+	bonjour_xfer_end,          /* end */
+	bonjour_xfer_cancel_send,  /* cancel_send */
+	NULL,                      /* cancel_recv */
+	NULL,                      /* read */
+	NULL,                      /* write */
+	NULL,                      /* ack */
+};
+
 PurpleXfer *
 bonjour_new_xfer(PurpleConnection *gc, const char *who)
 {
@@ -367,9 +380,7 @@ bonjour_new_xfer(PurpleConnection *gc, c
 	xep_xfer->mode = XEP_BYTESTREAMS;
 	xep_xfer->sid = NULL;
 
-	purple_xfer_set_init_fnc(xfer, bonjour_xfer_init);
-	purple_xfer_set_cancel_send_fnc(xfer, bonjour_xfer_cancel_send);
-	purple_xfer_set_end_fnc(xfer, bonjour_xfer_end);
+	purple_xfer_set_io_ops(xfer, &send_ops);
 
 	bd->xfer_lists = g_slist_append(bd->xfer_lists, xfer);
 
@@ -740,9 +751,22 @@ xep_bytestreams_parse(PurpleConnection *
 	purple_debug_error("bonjour", "Didn't find an acceptable streamhost.\n");
 
 	if (iq_id && xfer != NULL)
-		xep_ft_si_reject(bd, iq_id, xfer->who, "404", "cancel");
+		xep_ft_si_reject(bd, iq_id, purple_xfer_get_remote_user(xfer), "404", "cancel");
 }
 
+static PurpleXferIoOps recieve_ops =
+{
+	bonjour_xfer_init,            /* init */
+	bonjour_xfer_request_denied,  /* request_denied */
+	NULL,                         /* start */
+	bonjour_xfer_end,             /* end */
+	NULL,                         /* cancel_send */
+	bonjour_xfer_cancel_recv,     /* cancel_recv */
+	NULL,                         /* read */
+	NULL,                         /* write */
+	NULL,                         /* ack */
+};
+
 static void
 bonjour_xfer_receive(PurpleConnection *pc, const char *id, const char *sid, const char *from,
 		     const goffset filesize, const char *filename, int option)
@@ -771,10 +795,7 @@ bonjour_xfer_receive(PurpleConnection *p
 
 	if(filesize > 0)
 		purple_xfer_set_size(xfer, filesize);
-	purple_xfer_set_init_fnc(xfer, bonjour_xfer_init);
-	purple_xfer_set_request_denied_fnc(xfer, bonjour_xfer_request_denied);
-	purple_xfer_set_cancel_recv_fnc(xfer, bonjour_xfer_cancel_recv);
-	purple_xfer_set_end_fnc(xfer, bonjour_xfer_end);
+	purple_xfer_set_io_ops(xfer, &recieve_ops);
 
 	bd->xfer_lists = g_slist_append(bd->xfer_lists, xfer);
 
diff --git a/libpurple/protocols/bonjour/jabber.c b/libpurple/protocols/bonjour/jabber.c
--- a/libpurple/protocols/bonjour/jabber.c
+++ b/libpurple/protocols/bonjour/jabber.c
@@ -62,7 +62,7 @@
 #include "parser.h"
 #include "bonjour.h"
 #include "buddy.h"
-#include "bonjour_xfer.h"
+#include "bonjour_ft.h"
 
 #ifdef _SIZEOF_ADDR_IFREQ
 #  define HX_SIZE_OF_IFREQ(a) _SIZEOF_ADDR_IFREQ(a)
diff --git a/libpurple/protocols/irc/dcc_send.c b/libpurple/protocols/irc/dcc_send.c
--- a/libpurple/protocols/irc/dcc_send.c
+++ b/libpurple/protocols/irc/dcc_send.c
@@ -70,6 +70,19 @@ static void irc_dccsend_recv_init(Purple
 	xd->ip = NULL;
 }
 
+static PurpleXferIoOps recieve_ops =
+{
+	irc_dccsend_recv_init,     /* init */
+	irc_dccsend_recv_destroy,  /* request_denied */
+	NULL,                      /* start */
+	irc_dccsend_recv_destroy,  /* end */
+	NULL,                      /* cancel_send */
+	irc_dccsend_recv_destroy,  /* cancel_recv */
+	NULL,                      /* read */
+	NULL,                      /* write */
+	irc_dccsend_recv_ack,      /* ack */
+};
+
 /* This function makes the necessary arrangements for receiving files */
 void irc_dccsend_recv(struct irc_conn *irc, const char *from, const char *msg) {
 	PurpleXfer *xfer;
@@ -131,12 +144,7 @@ void irc_dccsend_recv(struct irc_conn *i
 			     filename->str, xd->ip);
 		purple_xfer_set_size(xfer, token[i+2] ? atoi(token[i+2]) : 0);
 
-		purple_xfer_set_init_fnc(xfer, irc_dccsend_recv_init);
-		purple_xfer_set_ack_fnc(xfer, irc_dccsend_recv_ack);
-
-		purple_xfer_set_end_fnc(xfer, irc_dccsend_recv_destroy);
-		purple_xfer_set_request_denied_fnc(xfer, irc_dccsend_recv_destroy);
-		purple_xfer_set_cancel_recv_fnc(xfer, irc_dccsend_recv_destroy);
+		purple_xfer_set_io_ops(xfer, &recieve_ops);
 
 		purple_xfer_request(xfer);
 	}
@@ -291,7 +299,7 @@ irc_dccsend_network_listen_cb(int sock, 
 
 	if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL
 			|| purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_REMOTE) {
-		purple_xfer_unref(xfer);
+		g_object_unref(xfer);
 		return;
 	}
 
@@ -299,7 +307,7 @@ irc_dccsend_network_listen_cb(int sock, 
 	gc = purple_account_get_connection(purple_xfer_get_account(xfer));
 	irc = purple_connection_get_protocol_data(gc);
 
-	purple_xfer_unref(xfer);
+	g_object_unref(xfer);
 
 	if (sock < 0) {
 		purple_notify_error(gc, NULL, _("File Transfer Failed"),
@@ -336,13 +344,13 @@ static void irc_dccsend_send_init(Purple
 
 	purple_xfer_set_filename(xfer, g_path_get_basename(purple_xfer_get_local_filename(xfer)));
 
-	purple_xfer_ref(xfer);
+	g_object_ref(xfer);
 
 	/* Create a listening socket */
 	xd->listen_data = purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, TRUE,
 			irc_dccsend_network_listen_cb, xfer);
 	if (xd->listen_data == NULL) {
-		purple_xfer_unref(xfer);
+		g_object_unref(xfer);
 		purple_notify_error(gc, NULL, _("File Transfer Failed"),
 		                    _("Unable to open a listening port."));
 		purple_xfer_cancel_local(xfer);
@@ -350,6 +358,19 @@ static void irc_dccsend_send_init(Purple
 
 }
 
+static PurpleXferIoOps send_ops =
+{
+	irc_dccsend_send_init,     /* init */
+	irc_dccsend_send_destroy,  /* request_denied */
+	NULL,                      /* start */
+	irc_dccsend_send_destroy,  /* end */
+	irc_dccsend_send_destroy,  /* cancel_send */
+	NULL,                      /* cancel_recv */
+	NULL,                      /* read */
+	irc_dccsend_send_write,    /* write */
+	NULL,                      /* ack */
+};
+
 PurpleXfer *irc_dccsend_new_xfer(PurpleConnection *gc, const char *who) {
 	PurpleXfer *xfer;
 	struct irc_xfer_send_data *xd;
@@ -363,11 +384,7 @@ PurpleXfer *irc_dccsend_new_xfer(PurpleC
 		purple_xfer_set_protocol_data(xfer, xd);
 
 		/* Setup our I/O op functions */
-		purple_xfer_set_init_fnc(xfer, irc_dccsend_send_init);
-		purple_xfer_set_write_fnc(xfer, irc_dccsend_send_write);
-		purple_xfer_set_end_fnc(xfer, irc_dccsend_send_destroy);
-		purple_xfer_set_request_denied_fnc(xfer, irc_dccsend_send_destroy);
-		purple_xfer_set_cancel_send_fnc(xfer, irc_dccsend_send_destroy);
+		purple_xfer_set_io_ops(xfer, &send_ops);
 	}
 
 	return xfer;



More information about the Commits mailing list