cpw.malu.xmpp.google_ft: d594b68a: can now receive a file from gtalk :)
malu at pidgin.im
malu at pidgin.im
Mon Sep 27 17:55:42 EDT 2010
----------------------------------------------------------------------
Revision: d594b68acb5780476888fbabb2ea92800fd25570
Parent: 6bcdd5538deecf01186a2878484f5613f2438e97
Author: malu at pidgin.im
Date: 09/27/10 17:52:22
Branch: im.pidgin.cpw.malu.xmpp.google_ft
URL: http://d.pidgin.im/viewmtn/revision/info/d594b68acb5780476888fbabb2ea92800fd25570
Changelog:
can now receive a file from gtalk :)
Changes against parent 6bcdd5538deecf01186a2878484f5613f2438e97
patched libpurple/protocols/jabber/google/google_share.c
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google/google_share.c cb4b0cf1dc129ddf51e220fb26761d7c9d73f117
+++ libpurple/protocols/jabber/google/google_share.c 10a91c29c007290bd330274089a46fbd188a414f
@@ -47,6 +47,7 @@ typedef struct {
gboolean candidate_gathering_done;
NiceComponentState state;
GoogleShareChannelState channel_state;
+ PurpleCircBuffer *buffer;
} GoogleShareSessionData;
static void
@@ -320,6 +321,28 @@ google_share_candidate_gathering_done_cb
}
}
+
+static gssize
+google_share_read(guchar **out_buffer, PurpleXfer *xfer)
+{
+ GoogleSession *session = (GoogleSession *) xfer->data;
+ GoogleShareSessionData *session_data =
+ (GoogleShareSessionData *) session->session_data;
+ guchar *buffer;
+ gsize size;
+ gsize tmp;
+
+ size = session_data->buffer->bufused;
+ *out_buffer = buffer = g_malloc(size);
+ while ((tmp = purple_circ_buffer_get_max_read(session_data->buffer))) {
+ memcpy(buffer, session_data->buffer->outptr, tmp);
+ buffer += tmp;
+ purple_circ_buffer_mark_read(session_data->buffer, tmp);
+ }
+
+ return size;
+}
+
/* If buffer contains a line ending, 0-terminate the first line and
* return a pointer to the beginning of the next line. Otherwise
* return NULL. */
@@ -355,10 +378,11 @@ google_share_data_received_cb(NiceAgent
if (session_data->channel_state ==
GOOGLE_SHARE_CHANNEL_SENT_HTTP_CONTENT_GET) {
gchar *tmp;
+ gsize read_len;
do {
tmp = http_read_line(curr, len);
- gsize read_len = tmp - curr;
+ read_len = tmp - curr;
purple_debug_info("google-share",
"found HTTP response header: %s\n", curr);
@@ -382,6 +406,7 @@ google_share_data_received_cb(NiceAgent
session_data->channel_state =
GOOGLE_SHARE_CHANNEL_PARSED_HTTP_RESPONSE_HEADER;
+ purple_xfer_start(xfer, -1, NULL, 0);
}
/* otherwise the remaining headers would come in the next package
not sure if this will ever happen */
@@ -391,6 +416,15 @@ google_share_data_received_cb(NiceAgent
/* write data to transfer */
purple_debug_info("google-share",
"got %d bytes to write to transfer\n", len);
+
+ if (len <= purple_xfer_get_bytes_remaining(xfer)) {
+ purple_circ_buffer_append(session_data->buffer, curr, len);
+ purple_xfer_prpl_ready(xfer);
+ } else {
+ purple_debug_error("google-share",
+ "trying to write past end of file\n");
+ purple_xfer_cancel_remote(xfer);
+ }
}
} else {
@@ -591,7 +625,9 @@ void google_share_handle_initiate(Jabber
purple_xfer_set_init_fnc(session_data->xfer, google_share_init);
purple_xfer_set_request_denied_fnc(session_data->xfer,
google_share_request_denied);
+ purple_xfer_set_read_fnc(session_data->xfer, google_share_read);
session_data->xfer->data = session;
+ session_data->buffer = purple_circ_buffer_new(65536);
session->session_data = session_data;
session->handle_transport_info_cb = google_share_handle_transport_info;
More information about the Commits
mailing list