/soc/2013/ankitkv/gobjectification: 21017b84a070: Refactored jab...

Ankit Vani a at nevitus.org
Thu Sep 5 13:24:52 EDT 2013


Changeset: 21017b84a070e2ff13bb41ce670207b0d8d68062
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-05 22:54 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/21017b84a070

Description:

Refactored jabber to use the GObject xfer API.
Added purple_xfer_set_remote_user().

diffstat:

 libpurple/protocols/jabber/oob.c |  20 +++++++++++++-----
 libpurple/protocols/jabber/si.c  |  42 +++++++++++++++++++++++++++++----------
 libpurple/xfer.h                 |   8 +++++++
 3 files changed, 53 insertions(+), 17 deletions(-)

diffs (149 lines):

diff --git a/libpurple/protocols/jabber/oob.c b/libpurple/protocols/jabber/oob.c
--- a/libpurple/protocols/jabber/oob.c
+++ b/libpurple/protocols/jabber/oob.c
@@ -168,6 +168,19 @@ static void jabber_oob_xfer_recv_cancell
 	jabber_oob_xfer_recv_error(xfer, "404");
 }
 
+static PurpleXferIoOps recieve_ops =
+{
+	jabber_oob_xfer_init,            /* init */
+	jabber_oob_xfer_recv_denied,     /* request_denied */
+	jabber_oob_xfer_start,           /* start */
+	jabber_oob_xfer_end,             /* end */
+	NULL,                            /* cancel_send */
+	jabber_oob_xfer_recv_cancelled,  /* cancel_recv */
+	NULL,                            /* read */
+	NULL,                            /* write */
+	NULL,                            /* ack */
+};
+
 void jabber_oob_parse(JabberStream *js, const char *from, JabberIqType type,
 	const char *id, xmlnode *querynode) {
 	JabberOOBXfer *jox;
@@ -208,12 +221,7 @@ void jabber_oob_parse(JabberStream *js, 
 	else
 		filename = slash + 1;
 	purple_xfer_set_filename(xfer, filename);
-
-	purple_xfer_set_init_fnc(xfer, jabber_oob_xfer_init);
-	purple_xfer_set_end_fnc(xfer, jabber_oob_xfer_end);
-	purple_xfer_set_request_denied_fnc(xfer, jabber_oob_xfer_recv_denied);
-	purple_xfer_set_cancel_recv_fnc(xfer, jabber_oob_xfer_recv_cancelled);
-	purple_xfer_set_start_fnc(xfer, jabber_oob_xfer_start);
+	purple_xfer_set_io_ops(xfer, &recieve_ops);
 
 	js->oob_file_transfers = g_list_append(js->oob_file_transfers, xfer);
 
diff --git a/libpurple/protocols/jabber/si.c b/libpurple/protocols/jabber/si.c
--- a/libpurple/protocols/jabber/si.c
+++ b/libpurple/protocols/jabber/si.c
@@ -1072,7 +1072,7 @@ jabber_si_xfer_ibb_open_cb(JabberStream 
 				purple_circular_buffer_new(jabber_ibb_session_get_block_size(sess));
 
 			/* set up read function */
-			purple_xfer_set_read_fnc(xfer, jabber_si_xfer_ibb_read);
+			purple_xfer_get_io_ops(xfer)->read = jabber_si_xfer_ibb_read;
 
 			/* start the transfer */
 			purple_xfer_start(xfer, -1, NULL, 0);
@@ -1154,7 +1154,7 @@ jabber_si_xfer_ibb_send_init(JabberStrea
 		jabber_ibb_session_set_error_callback(jsx->ibb_session,
 			jabber_si_xfer_ibb_error_cb);
 
-		purple_xfer_set_write_fnc(xfer, jabber_si_xfer_ibb_write);
+		purple_xfer_get_io_ops(xfer)->write = jabber_si_xfer_ibb_write;
 
 		jsx->ibb_buffer =
 			purple_circular_buffer_new(jabber_ibb_session_get_max_data_size(jsx->ibb_session));
@@ -1459,8 +1459,7 @@ static void do_transfer_send(PurpleXfer 
 
 	who = g_strdup_printf("%s/%s", who_v[0], resource);
 	g_strfreev(who_v);
-	g_free(xfer->who);
-	xfer->who = who;
+	purple_xfer_set_remote_user(xfer, who);
 
 	if (jbr && jabber_resource_know_capabilities(jbr)) {
 		char *msg;
@@ -1617,6 +1616,19 @@ static void jabber_si_xfer_init(PurpleXf
 	}
 }
 
+static PurpleXferIoOps send_ops =
+{
+	jabber_si_xfer_init,         /* init */
+	NULL,                        /* request_denied */
+	NULL,                        /* start */
+	jabber_si_xfer_end,          /* end */
+	jabber_si_xfer_cancel_send,  /* cancel_send */
+	NULL,                        /* cancel_recv */
+	NULL,                        /* read */
+	NULL,                        /* write */
+	NULL,                        /* ack */
+};
+
 PurpleXfer *jabber_si_new_xfer(PurpleConnection *gc, const char *who)
 {
 	JabberStream *js;
@@ -1636,9 +1648,7 @@ PurpleXfer *jabber_si_new_xfer(PurpleCon
 
 		jsx->ibb_session = NULL;
 
-		purple_xfer_set_init_fnc(xfer, jabber_si_xfer_init);
-		purple_xfer_set_cancel_send_fnc(xfer, jabber_si_xfer_cancel_send);
-		purple_xfer_set_end_fnc(xfer, jabber_si_xfer_end);
+		purple_xfer_set_io_ops(xfer, &send_ops);
 
 		js->file_transfers = g_list_append(js->file_transfers, xfer);
 	}
@@ -1675,6 +1685,19 @@ jabber_si_thumbnail_cb(JabberData *data,
 }
 #endif
 
+static PurpleXferIoOps recieve_ops =
+{
+	jabber_si_xfer_init,            /* init */
+	jabber_si_xfer_request_denied,  /* request_denied */
+	NULL,                           /* start */
+	jabber_si_xfer_end,             /* end */
+	NULL,                           /* cancel_send */
+	jabber_si_xfer_cancel_recv,     /* cancel_recv */
+	NULL,                           /* read */
+	NULL,                           /* write */
+	NULL,                           /* ack */
+};
+
 void jabber_si_parse(JabberStream *js, const char *from, JabberIqType type,
                      const char *id, xmlnode *si)
 {
@@ -1761,10 +1784,7 @@ void jabber_si_parse(JabberStream *js, c
 	if(filesize > 0)
 		purple_xfer_set_size(xfer, filesize);
 
-	purple_xfer_set_init_fnc(xfer, jabber_si_xfer_init);
-	purple_xfer_set_request_denied_fnc(xfer, jabber_si_xfer_request_denied);
-	purple_xfer_set_cancel_recv_fnc(xfer, jabber_si_xfer_cancel_recv);
-	purple_xfer_set_end_fnc(xfer, jabber_si_xfer_end);
+	purple_xfer_set_io_ops(xfer, &recieve_ops);
 
 	js->file_transfers = g_list_append(js->file_transfers, xfer);
 
diff --git a/libpurple/xfer.h b/libpurple/xfer.h
--- a/libpurple/xfer.h
+++ b/libpurple/xfer.h
@@ -267,6 +267,14 @@ PurpleXferType purple_xfer_get_xfer_type
  */
 PurpleAccount *purple_xfer_get_account(const PurpleXfer *xfer);
 
+/** TODO g_free(xfer->who); xfer->who = who;
+ * Sets the name of the remote user.
+ *
+ * @param xfer The file transfer.
+ * @param who  The name of the remote user.
+ */
+void purple_xfer_set_remote_user(PurpleXfer *xfer, const char *who);
+
 /**
  * Returns the name of the remote user.
  *



More information about the Commits mailing list