cpw.malu.xmpp.ibb_ft: 95e1ae61: Standardize all the IBB stream cleanup
malu at pidgin.im
malu at pidgin.im
Tue Dec 16 14:20:56 EST 2008
-----------------------------------------------------------------
Revision: 95e1ae61eda292e6ca5f636d5fc76bac8262940b
Ancestor: b86843136452cd6bd27f4efc1457e53e54108e6b
Author: paul at aurich.com
Date: 2008-12-16T19:17:44
Branch: im.pidgin.cpw.malu.xmpp.ibb_ft
URL: http://d.pidgin.im/viewmtn/revision/info/95e1ae61eda292e6ca5f636d5fc76bac8262940b
Modified files:
libpurple/protocols/jabber/si.c
ChangeLog:
Standardize all the IBB stream cleanup
It all goes through purple_xfer_cancel_(remote|local) and purple_xfer_end.
Those functions call ..._cancel_(send|recv), ..._request_denied, and
..._end, which will close the IBB and free the SI data.
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/si.c 15e4fb8a07347b931b228393052c2181bdb7b399
+++ libpurple/protocols/jabber/si.c dbb250a80fdf7f556d7ba080ffa2ded30cd1605f
@@ -205,8 +205,8 @@ jabber_si_bytestreams_ibb_timeout_cb(gpo
purple_debug_info("jabber",
"jabber_si_bytestreams_ibb_timeout called and IBB session not set "
" up yet, cancel transfer");
- purple_xfer_cancel_local(xfer);
jabber_si_bytestreams_ibb_timeout_remove(jsx);
+ purple_xfer_cancel_local(xfer);
}
return FALSE;
@@ -240,8 +240,8 @@ static void jabber_si_bytestreams_attemp
purple_debug_info("jabber",
"jabber_si_bytestreams_attempt_connect: "
"no streamhosts found, trying IBB\n");
- /* if we are the sender, open an IBB session. But not if we already
- done it, since we could have received the error <iq/> from the
+ /* if we are the sender, open an IBB session, but not if we already
+ did it, since we could have received the error <iq/> from the
receiver already... */
if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND
&& !jsx->ibb_session) {
@@ -952,11 +952,6 @@ jabber_si_xfer_bytestreams_send_init(Pur
}
-/* forward declare some functions here... */
-static void jabber_si_xfer_cancel_recv(PurpleXfer *xfer);
-static void jabber_si_xfer_cancel_send(PurpleXfer *xfer);
-static void jabber_si_xfer_free(PurpleXfer *xfer);
-
static void
jabber_si_xfer_ibb_error_cb(JabberIBBSession *sess)
{
@@ -969,7 +964,7 @@ jabber_si_xfer_ibb_error_cb(JabberIBBSes
purple_xfer_error(purple_xfer_get_type(xfer), account,
jabber_ibb_session_get_who(sess),
_("An error occured on the in-band bytestream transfer\n"));
- purple_xfer_end(xfer);
+ purple_xfer_cancel_remote(xfer);
}
static void
@@ -984,11 +979,11 @@ jabber_si_xfer_ibb_closed_cb(JabberIBBSe
if (purple_xfer_get_bytes_remaining(xfer) > 0) {
purple_xfer_error(purple_xfer_get_type(xfer), account,
jabber_ibb_session_get_who(sess), _("Transfer was closed."));
+ purple_xfer_cancel_remote(xfer);
} else {
purple_xfer_set_completed(xfer, TRUE);
+ purple_xfer_end(xfer);
}
- jabber_si_xfer_free(xfer);
- purple_xfer_end(xfer);
}
static void
@@ -1003,7 +998,7 @@ jabber_si_xfer_ibb_recv_data_cb(JabberIB
size);
if(!fwrite(data, size, 1, jsx->fp)) {
purple_debug_error("jabber", "error writing to file\n");
- jabber_si_xfer_cancel_recv(xfer);
+ purple_xfer_cancel_remote(xfer);
return;
}
purple_xfer_set_bytes_sent(xfer, purple_xfer_get_bytes_sent(xfer) + size);
@@ -1011,7 +1006,6 @@ jabber_si_xfer_ibb_recv_data_cb(JabberIB
if (purple_xfer_get_bytes_remaining(xfer) == 0) {
purple_xfer_set_completed(xfer, TRUE);
- jabber_si_xfer_free(xfer);
purple_xfer_end(xfer);
}
} else {
@@ -1019,8 +1013,7 @@ jabber_si_xfer_ibb_recv_data_cb(JabberIB
reject transfer to protect against malicious behaviour */
purple_debug_error("jabber",
"IBB file transfer send more data than expected\n");
- jabber_si_xfer_cancel_recv(xfer);
- purple_xfer_end(xfer);
+ purple_xfer_cancel_remote(xfer);
}
}
@@ -1038,6 +1031,8 @@ jabber_si_xfer_ibb_open_cb(JabberStream
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);
@@ -1065,12 +1060,9 @@ jabber_si_xfer_ibb_open_cb(JabberStream
} else {
/* failed to create IBB session */
purple_debug_error("jabber", "failed to create IBB session\n");
- jabber_si_xfer_cancel_recv(xfer);
- purple_xfer_end(xfer);
+ purple_xfer_cancel_remote(xfer);
return FALSE;
}
-
- jabber_si_bytestreams_ibb_timeout_remove(jsx);
} else {
/* we got an IBB <open/> for an unknown file transfer, pass along... */
purple_debug_info("jabber",
@@ -1102,7 +1094,7 @@ jabber_si_xfer_ibb_send_data(JabberIBBSe
} else {
purple_debug_error("jabber",
"jabber_si_xfer_ibb_send_data: error reading from file\n");
- jabber_si_xfer_cancel_send(xfer);
+ purple_xfer_cancel_local(xfer);
}
}
@@ -1116,7 +1108,6 @@ jabber_si_xfer_ibb_sent_cb(JabberIBBSess
/* close the session */
jabber_ibb_session_close(sess);
purple_xfer_set_completed(xfer, TRUE);
- jabber_si_xfer_free(xfer);
purple_xfer_end(xfer);
} else {
/* send more... */
@@ -1139,21 +1130,19 @@ jabber_si_xfer_ibb_opened_cb(JabberIBBSe
if (jsx->fp == NULL) {
purple_debug_error("jabber", "Failed to open file %s for reading: %s\n",
filename, g_strerror(errno));
- jabber_si_xfer_free(xfer);
purple_xfer_error(purple_xfer_get_type(xfer), account,
jabber_ibb_session_get_who(sess),
_("Failed to open the file"));
- purple_xfer_end(xfer);
- } else {
- /* XXX: Shouldn't this specify a valid file descriptor? */
- purple_xfer_start(xfer, 0, NULL, 0);
- purple_xfer_set_bytes_sent(xfer, 0);
- purple_xfer_update_progress(xfer);
- jabber_si_xfer_ibb_send_data(sess);
+ purple_xfer_cancel_local(xfer);
+ return;
}
+
+ purple_xfer_start(xfer, 0, NULL, 0);
+ purple_xfer_set_bytes_sent(xfer, 0);
+ purple_xfer_update_progress(xfer);
+ jabber_si_xfer_ibb_send_data(sess);
} else {
/* error */
- jabber_si_xfer_free(xfer);
purple_xfer_error(purple_xfer_get_type(xfer), account,
jabber_ibb_session_get_who(sess),
_("Failed to open in-band bytestream"));
@@ -1189,8 +1178,7 @@ jabber_si_xfer_ibb_send_init(JabberStrea
/* failed to create IBB session */
purple_debug_error("jabber",
"failed to initiate IBB session for file transfer\n");
- jabber_si_xfer_cancel_send(xfer);
- purple_xfer_unref(xfer);
+ purple_xfer_cancel_local(xfer);
}
}
@@ -1349,7 +1337,11 @@ static void jabber_si_xfer_free(PurpleXf
}
}
-
+/*
+ * These four functions should only be called from the PurpleXfer functions
+ * (typically purple_xfer_cancel_(remote|local), purple_xfer_end, or
+ * purple_xfer_request_denied.
+ */
static void jabber_si_xfer_cancel_send(PurpleXfer *xfer)
{
JabberSIXfer *jsx = (JabberSIXfer *) xfer->data;
More information about the Commits
mailing list