changeset 25768:dbba20fb7c39

Make the IBB-handling code in si.c "steal" the dest_fp from PurpleXfer in the same manner as is done the MSN prpl. This saves having to open the same file twice and risking a duplicate fclose.
author Marcus Lundblad <ml@update.uu.se>
date Wed, 14 Jan 2009 18:42:17 +0000
parents 930e58241014
children 5456120de480
files libpurple/protocols/jabber/si.c
diffstat 1 files changed, 8 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/si.c	Tue Jan 13 18:37:45 2009 +0000
+++ b/libpurple/protocols/jabber/si.c	Wed Jan 14 18:42:17 2009 +0000
@@ -1029,21 +1029,14 @@
 		JabberSIXfer *jsx = (JabberSIXfer *) xfer->data;
 		JabberIBBSession *sess = 
 			jabber_ibb_session_create_from_xmlnode(js, packet, xfer);
-		const char *filename;
 
 		jabber_si_bytestreams_ibb_timeout_remove(jsx);
 
 		if (sess) {
-			/* open the file to write to */
-			filename = purple_xfer_get_local_filename(xfer);
-			jsx->fp = g_fopen(filename, "wb");
-			if (jsx->fp == NULL) {
-				purple_debug_error("jabber", "failed to open file %s for writing: %s\n",
-					filename, g_strerror(errno));
-				purple_xfer_cancel_remote(xfer);
-				return FALSE;
-			}
-
+			jsx->fp = xfer->dest_fp;
+			xfer->dest_fp = NULL;
+			/* the FD we get from xfer should never be NULL (see ft.c) */
+			
 			/* setup callbacks here...*/
 			jabber_ibb_session_set_data_received_callback(sess,
 				jabber_si_xfer_ibb_recv_data_cb);
@@ -1125,18 +1118,10 @@
 	PurpleAccount *account = purple_connection_get_account(gc);
 
 	if (jabber_ibb_session_get_state(sess) == JABBER_IBB_SESSION_OPENED) {
-		const char *filename = purple_xfer_get_local_filename(xfer);
-		jsx->fp = g_fopen(filename, "rb");
-		if (jsx->fp == NULL) {
-			purple_debug_error("jabber", "Failed to open file %s for reading: %s\n",
-				filename, g_strerror(errno));
-			purple_xfer_error(purple_xfer_get_type(xfer), account,
-				jabber_ibb_session_get_who(sess),
-				_("Failed to open the file"));
-			purple_xfer_cancel_local(xfer);
-			return;
-		}
-
+		jsx->fp = xfer->dest_fp;
+		xfer->dest_fp = NULL; /* disable double fclose */
+		/* the FD we get from xfer should never be NULL (see ft.c) */
+		
 		purple_xfer_start(xfer, 0, NULL, 0);
 		purple_xfer_set_bytes_sent(xfer, 0);
 		purple_xfer_update_progress(xfer);