/soc/2013/ashmew2/filetransferY: ebca46ce2eb5: Migrated to new X...
Ashish Gupta
ashmew2 at gmail.com
Wed Feb 12 02:38:14 EST 2014
Changeset: ebca46ce2eb5972dfd8c31d2954196619de16ed8
Author: Ashish Gupta <ashmew2 at gmail.com>
Date: 2014-02-04 23:58 +0530
Branch: default
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferY/rev/ebca46ce2eb5
Description:
Migrated to new Xfer API
diffstat:
libpurple/protocols/jabber/google/google_session.c | 2 +-
libpurple/protocols/jabber/google/google_session.h | 4 +-
libpurple/protocols/jabber/google/google_share.c | 106 ++++++++++++--------
libpurple/xfer.c | 2 +-
4 files changed, 65 insertions(+), 49 deletions(-)
diffs (truncated from 362 to 300 lines):
diff --git a/libpurple/protocols/jabber/google/google_session.c b/libpurple/protocols/jabber/google/google_session.c
--- a/libpurple/protocols/jabber/google/google_session.c
+++ b/libpurple/protocols/jabber/google/google_session.c
@@ -101,7 +101,7 @@ google_session_destroy(GoogleSession *se
g_object_unref(share_session->share_agent);
}
- purple_circ_buffer_destroy(share_session->buffer);
+ g_byte_array_unref(share_session->buffer);
for (temp = share_session->remote_share_candidates; temp; temp =
g_slist_delete_link(temp, temp)) {
diff --git a/libpurple/protocols/jabber/google/google_session.h b/libpurple/protocols/jabber/google/google_session.h
--- a/libpurple/protocols/jabber/google/google_session.h
+++ b/libpurple/protocols/jabber/google/google_session.h
@@ -49,7 +49,7 @@ typedef struct {
*/
gchar *channel_name;
NiceComponentState agent_state;
- PurpleCircBuffer *buffer;
+ GByteArray *buffer;
GoogleXferChannelState channel_state;
gint stream_id;
gboolean candidates_gathered;
@@ -139,4 +139,4 @@ void jabber_google_session_parse(JabberS
PurpleXmlNode *session);
void google_session_destroy(GoogleSession *session);
-#endif /* PURPLE_JABBER_GOOGLE_SESSION_H_ */
\ No newline at end of file
+#endif /* PURPLE_JABBER_GOOGLE_SESSION_H_ */
diff --git a/libpurple/protocols/jabber/google/google_share.c b/libpurple/protocols/jabber/google/google_share.c
--- a/libpurple/protocols/jabber/google/google_share.c
+++ b/libpurple/protocols/jabber/google/google_share.c
@@ -63,12 +63,13 @@ gtalk_get_temporary_url(void)
static void
gtalk_xfer_send_reject(PurpleXfer *xfer)
{
- GoogleSession *session = (GoogleSession *) xfer->data;
+ GoogleSession *session =
+ (GoogleSession *) purple_xfer_get_protocol_data(xfer);
JabberStream *js = session->js;
JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
PurpleXmlNode *session_node;
- if(purple_xfer_get_type(xfer) != PURPLE_XFER_RECEIVE)
+ if(purple_xfer_get_xfer_type(xfer) != PURPLE_XFER_TYPE_RECEIVE)
return;
purple_xmlnode_set_attrib(iq->node, "to", session->remote_jid);
@@ -116,7 +117,7 @@ cb_nice_recv(NiceAgent *agent, guint str
PurpleXfer *xfer = share_session->xfer;
gchar *curr = buf;
- if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) {
+ if(purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_SEND) {
/*Maybe Add a parser to make sure it's not bad data?*/
/*We should send back a 200 OK now*/
@@ -126,7 +127,7 @@ cb_nice_recv(NiceAgent *agent, guint str
"Connection: Keep-Alive\r\n"
"Content-Length: %" G_GSIZE_FORMAT "\r\n"
"Content-Type: application/octet-stream\r\n\r\n",
- xfer->size);
+ purple_xfer_get_size(xfer));
share_session->channel_state = GTALK_XFER_CHANNEL_HTTP_GET_RECEIVED;
send_ret = nice_agent_send(share_session->share_agent,
@@ -136,7 +137,7 @@ cb_nice_recv(NiceAgent *agent, guint str
share_session->channel_state = GTALK_XFER_CHANNEL_HTTP_OK_SENT;
share_session->file_to_send =
- fopen(share_session->xfer->local_filename, "rb");
+ fopen(purple_xfer_get_local_filename(share_session->xfer), "rb");
if(share_session->agent_state == NICE_COMPONENT_STATE_READY) {
share_session->channel_state = GTALK_XFER_CHANNEL_HTTP_SENDING;
@@ -145,7 +146,7 @@ cb_nice_recv(NiceAgent *agent, guint str
share_session->stream_id, 1, share_session);
}
}
- else if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) {
+ else if (purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_RECEIVE) {
if (share_session->channel_state ==
GTALK_XFER_CHANNEL_SENT_HTTP_GET) {
gchar *tmp;
@@ -196,8 +197,7 @@ cb_nice_recv(NiceAgent *agent, guint str
curlen+=len;
if (len <= purple_xfer_get_bytes_remaining(xfer)) {
- purple_circ_buffer_append(share_session->buffer,
- curr, len);
+ g_byte_array_append(share_session->buffer, curr, len);
purple_xfer_prpl_ready(xfer);
} else {
purple_debug_error("google-share",
@@ -238,8 +238,9 @@ gtalk_xfer_accept_cb(JabberStream *js, c
(GoogleXferSessionData *)session->session_data;
if (type != JABBER_IQ_RESULT) {
- share_session->xfer->status = PURPLE_XFER_STATUS_CANCEL_REMOTE;
- google_session_destroy(share_session->xfer->data);
+ purple_xfer_set_status(share_session->xfer,
+ PURPLE_XFER_STATUS_CANCEL_REMOTE);
+ google_session_destroy(session);
}
else {
/*Send a channel*/
@@ -321,7 +322,8 @@ gtalk_xfer_send_initiate_cb(JabberStream
static void
gtalk_xfer_send_session_initiate(PurpleXfer *xfer)
{
- GoogleSession *session = xfer->data;
+ GoogleSession *session =
+ (GoogleSession *)purple_xfer_get_protocol_data(xfer);
JabberStream *js = session->js;
JabberIq *iq;
PurpleXmlNode *session_node, *description_node, *file_node, *manifest_node;
@@ -350,10 +352,12 @@ gtalk_xfer_send_session_initiate(PurpleX
manifest_node = purple_xmlnode_new_child(description_node, "manifest");
file_node = purple_xmlnode_new_child(manifest_node, "file");
purple_xmlnode_set_attrib(file_node, "size",
- g_strdup_printf("%" G_GSIZE_FORMAT,xfer->size));
+ g_strdup_printf("%" G_GSIZE_FORMAT,
+ purple_xfer_get_size(xfer)));
name_node = purple_xmlnode_new_child(file_node, "name");
- purple_xmlnode_insert_data(name_node,xfer->filename,strlen(xfer->filename));
+ purple_xmlnode_insert_data(name_node,purple_xfer_get_filename(xfer),
+ strlen(purple_xfer_get_filename(xfer)));
protocol_node = purple_xmlnode_new_child(description_node, "protocol");
http_node = purple_xmlnode_new_child(protocol_node, "http");
@@ -399,7 +403,8 @@ gtalk_xfer_send_transport_accept(JabberS
static void
gtalk_xfer_send_terminate(PurpleXfer *xfer)
{
- GoogleSession *session = (GoogleSession *) xfer->data;
+ GoogleSession *session =
+ (GoogleSession *) purple_xfer_get_protocol_data(xfer);
JabberStream *js = session->js;
JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
PurpleXmlNode *session_node;
@@ -423,7 +428,8 @@ gtalk_xfer_send_terminate(PurpleXfer *xf
static void
gtalk_xfer_cancel_xfer(PurpleXfer *xfer)
{
- GoogleSession *session = (GoogleSession *)xfer->data;
+ GoogleSession *session =
+ (GoogleSession *) purple_xfer_get_protocol_data(xfer);
if(session->state == TERMINATED)
return;
@@ -434,15 +440,16 @@ gtalk_xfer_cancel_xfer(PurpleXfer *xfer)
static void
gtalk_xfer_init(PurpleXfer *xfer)
{
- GoogleSession *session = (GoogleSession *)(xfer->data);
+ GoogleSession *session =
+ (GoogleSession *) purple_xfer_get_protocol_data(xfer);
JabberStream *js = session->js;
js->google_share_sessions = g_list_prepend(js->google_share_sessions, session);
- if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE)
+ if(purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_RECEIVE)
gtalk_xfer_send_transport_accept(js, session);
- if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND)
+ if(purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_SEND)
gtalk_xfer_send_session_initiate(xfer);
}
@@ -643,7 +650,7 @@ gtalk_xfer_handle_reject(JabberStream *j
purple_debug_info("google_session", "The remote user Rejected the Xfer.\n");
- share_session->xfer->status = PURPLE_XFER_STATUS_CANCEL_REMOTE;
+ purple_xfer_set_status(share_session->xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE);
session->state = TERMINATED;
google_session_destroy(session);
}
@@ -744,12 +751,13 @@ cb_candidate_gathering_done(NiceAgent *a
static void
gtalk_xfer_end(PurpleXfer *xfer)
{
- GoogleSession *session = (GoogleSession *) xfer->data;
+ GoogleSession *session =
+ (GoogleSession *) purple_xfer_get_protocol_data(xfer);
JabberStream *js = session->js;
JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
PurpleXmlNode *complete_node, *session_node;
- if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) {
+ if(purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_RECEIVE) {
purple_xmlnode_set_attrib(iq->node, "to", session->remote_jid);
session_node = purple_xmlnode_new_child(iq->node, "session");
purple_xmlnode_set_attrib(session_node, "type", "info");
@@ -763,7 +771,7 @@ gtalk_xfer_end(PurpleXfer *xfer)
gtalk_xfer_send_terminate(xfer);
}
- else if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) {
+ else if(purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_SEND) {
purple_debug_info("google_session", "Gtalk XFER_SEND Ended\n");
}
}
@@ -771,7 +779,8 @@ gtalk_xfer_end(PurpleXfer *xfer)
static gssize
gtalk_xfer_read(guchar **out_buffer, PurpleXfer *xfer)
{
- GoogleSession *session = (GoogleSession *) xfer->data;
+ GoogleSession *session =
+ (GoogleSession *) purple_xfer_get_protocol_data(xfer);
GoogleXferSessionData *share_session =
(GoogleXferSessionData *)session->session_data;
@@ -779,13 +788,17 @@ gtalk_xfer_read(guchar **out_buffer, Pur
gsize size;
gsize tmp;
- size = share_session->buffer->bufused;
-
+ /* size = share_session->buffer->bufused;*/
+ size = g_bytes_get_size(share_session->buffer);
*out_buffer = buffer = g_malloc(size);
- while ((tmp = purple_circ_buffer_get_max_read(share_session->buffer))) {
- memcpy(buffer, share_session->buffer->outptr, tmp);
- buffer += tmp;
- purple_circ_buffer_mark_read(share_session->buffer, tmp);
+ gsize total_read = 0;
+ while (total_read<size) {
+ gsize dsize;
+ gconstpointer *read_ptr = g_bytes_get_data(share_session->buffer, &dsize);
+ memcpy(buffer, read_ptr, dsize);
+ total_read += dsize;
+ buffer+=dsize;
+ g_byte_array_remove_range(share_session->buffer, 0, dsize);
}
return size;
@@ -889,7 +902,7 @@ void cb_nice_component_state_changed(Nic
purple_debug_info("google_session", "***********\n");
- if(purple_xfer_get_type(share_session->xfer) == PURPLE_XFER_SEND &&
+ if(purple_xfer_get_xfer_type(share_session->xfer) == PURPLE_XFER_TYPE_SEND &&
share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_OK_SENT) {
share_session->channel_state = GTALK_XFER_CHANNEL_HTTP_SENDING;
cb_nice_component_writable(share_session->share_agent,
@@ -898,7 +911,7 @@ void cb_nice_component_state_changed(Nic
}
if(state == NICE_COMPONENT_STATE_READY &&
- purple_xfer_get_type(share_session->xfer) == PURPLE_XFER_RECEIVE) {
+ purple_xfer_get_xfer_type(share_session->xfer) == PURPLE_XFER_TYPE_RECEIVE) {
gint send_ret;
gchar *raw_filename = purple_strreplace(share_session->filename,
@@ -959,7 +972,8 @@ void cb_nice_component_writable(NiceAgen
if(share_session->channel_state == GTALK_XFER_CHANNEL_HTTP_GET_NOT_SENT) {
gint send_ret;
- GoogleSession *session = (GoogleSession *)xfer->data;
+ GoogleSession *session =
+ (GoogleSession *) purple_xfer_get_protocol_data(xfer);
gchar *raw_filename = purple_strreplace(share_session->filename,
" ","%20");
gchar *url = g_strdup_printf("%s%s",
@@ -1006,8 +1020,10 @@ void cb_nice_component_writable(NiceAgen
break;
}
else { //proper send_ret value
- xfer->bytes_sent += send_ret;
- xfer->bytes_remaining -= send_ret;
+ purple_xfer_set_bytes_sent(xfer,
+ purple_xfer_get_bytes_sent(xfer) + send_ret);
+ /* purple_xfer_set_bytes_remaining(xfer,
+ purple_xfer_get_bytes_remaining(xfer) - send_ret); Not sure about this???TODO*/
purple_xfer_update_progress(xfer);
share_session->file_buf_sent += send_ret;
}
@@ -1053,9 +1069,10 @@ gtalk_xfer_start(PurpleXfer *xfer)
{
purple_debug_info("google_session", "Inside gtalk_xfer_start()\n");
- if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) {
- guchar *buffer = g_malloc( xfer->bytes_remaining );
- int wrote = purple_xfer_write( xfer, buffer, xfer->bytes_remaining );
+ if(purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_SEND) {
+ guchar *buffer = g_malloc(purple_xfer_get_bytes_remaining(xfer));
+ int wrote = purple_xfer_write(xfer, buffer,
+ purple_xfer_get_bytes_remaining(xfer));
if ( wrote > 0 )
purple_xfer_set_bytes_sent( xfer, wrote );
@@ -1092,7 +1109,7 @@ gtalk_xfer_new_session(JabberStream *js,
jid = g_strdup(who);
}
More information about the Commits
mailing list