/soc/2013/ashmew2/filetransferX: f02d8c795ea6: Relocated and Ind...
Ashish Gupta
ashmew2 at gmail.com
Tue Aug 20 19:07:21 EDT 2013
Changeset: f02d8c795ea6010186cb855c3da45126f27cce48
Author: Ashish Gupta <ashmew2 at gmail.com>
Date: 2013-08-21 00:37 +0530
Branch: filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/f02d8c795ea6
Description:
Relocated and Indented things
diffstat:
libpurple/protocols/jabber/google/google_session.c | 127 ++++++++++----------
libpurple/protocols/jabber/google/google_session.h | 2 +-
2 files changed, 67 insertions(+), 62 deletions(-)
diffs (189 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
@@ -483,7 +483,7 @@ jabber_google_relay_response_session_ini
}
nice_agent_attach_recv(agent, stream_id, 1, g_main_context_default(),
- cb_nice_recv, session);
+ cb_nice_recv, share_session);
g_signal_connect(G_OBJECT(agent), "candidate-gathering-done",
G_CALLBACK(cb_candidate_gathering_done), session);
@@ -1730,7 +1730,7 @@ gtalk_xfer_read(guchar **out_buffer, Pur
{
GoogleSession *session = (GoogleSession *) xfer->data;
GoogleAVSessionData *session_data =
- (GoogleShareSessionData *) session->session_data;
+ (GoogleAVSessionData *) session->session_data;
GoogleXferSessionData *share_session = session_data->share_session;
guchar *buffer;
@@ -1740,10 +1740,10 @@ gtalk_xfer_read(guchar **out_buffer, Pur
size = share_session->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);
+ 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(session_data->buffer, tmp);
+ purple_circ_buffer_mark_read(share_session->buffer, tmp);
}
return size;
@@ -1755,65 +1755,69 @@ cb_nice_recv(NiceAgent *agent, guint str
{
/*The overall process is to first send a GET Request. Then wait for the response headers . Then, once the response headers are received,
The actual file starts to flow. At that time, we simply start our xfer to read the inbound data!*/
- purple_debug_info("google_session", "Received : \n%s\n", buf);
-
- if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) {
- if (session_data->channel_state ==
- GTALK_XFER_CHANNEL_SENT_HTTP_GET) {
- gchar *tmp;
- gsize read_len;
+ GoogleXferSessionData *share_session = (GoogleXferSessionData *)data;
+ PurpleXfer *xfer = share_session->xfer;
+ gchar *curr = buf;
+
+ purple_debug_info("google_session", "Received : \n%s\n", buf);
+
+ if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) {
+ if (share_session->channel_state ==
+ GTALK_XFER_CHANNEL_SENT_HTTP_GET) {
+ gchar *tmp;
+ gsize read_len;
+
+ do {
+ tmp = http_read_line(curr, len);
+ read_len = tmp - curr;
- do {
- tmp = http_read_line(curr, len);
- read_len = tmp - curr;
+ purple_debug_info("google_session", "HTTP response header received : %s\n", curr);
- purple_debug_info("google_session", "HTTP response header received : %s\n", curr);
+ len -= read_len;
+ curr += read_len;
+
+ if (g_ascii_strncasecmp(curr, "HTTP/1.1", 8)) {
+ if (purple_strequal(curr + 9, "404")) {
+ /* got a 404 (file not found) stop... */
+ /* TODO: Terminate the session gracefully as 404 happened? That means source_url
+ is bugged. Starting the Xfer over again might be the only option. */
+ }
+ }
+ /* TODO: check Content-Length and other headers too? */
+
+ } while (curr[0] != '\0' && len > 0);
+
+ if (curr[0] == '\0') {
+ /* we found the end of the headers */
+ purple_debug_info("google_session", "Headers End here..(Blank Line encountered)\n");
+
+ share_session->channel_state =
+ GTALK_XFER_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 */
+
+ } else if (share_session->channel_state ==
+ GTALK_XFER_CHANNEL_PARSED_HTTP_RESPONSE_HEADER) {
+ /* write data to transfer */
+ purple_debug_info("google-share",
+ "got %d bytes to write to transfer\n", len);
- len -= read_len;
- curr += read_len;
+ if (len <= purple_xfer_get_bytes_remaining(xfer)) {
+ purple_circ_buffer_append(share_session->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 {
+ /*TODO: Something to do*/
+ }
+}
- if (g_ascii_strncasecmp(curr, "HTTP/1.1", 8)) {
- if (purple_strequal(curr + 9, "404")) {
- /* got a 404 (file not found) stop... */
- /* TODO: Terminate the session gracefully as 404 happened? That means source_url
- is bugged. Starting the Xfer over again might be the only option. */
- }
- }
- /* TODO: check Content-Length and other headers too? */
-
- } while (curr[0] != '\0' && len > 0);
-
- if (curr[0] == '\0') {
- /* we found the end of the headers */
- purple_debug_info("google_session", "Headers End here..(Blank Line encountered)\n");
-
- session_data->channel_state =
- GTALK_XFER_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 */
-
- } else if (session_data->channel_state ==
- GOOGLE_SHARE_CHANNEL_PARSED_HTTP_RESPONSE_HEADER) {
- /* 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 {
-
- }
-}
-}
char *nice_component_state_to_str(guint state)
{
@@ -2031,7 +2035,7 @@ This will most probably end in successfu
*/
nice_agent_attach_recv (share_session->share_agent, share_session->stream_id, 1,
- g_main_context_default(), cb_nice_recv, NULL);
+ g_main_context_default(), cb_nice_recv, share_session);
/* TODO: REMOVE ME. Trying g_main_context_default () instead of gloop.*/
/*
@@ -2282,6 +2286,7 @@ void
gtalk_xfer_request_denied(PurpleXfer *xfer)
{
purple_debug_info("google_session", "Request denied by user..\n");
+ /*TODO: Session should end here but Not prematurely!*/
}
void
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
@@ -56,7 +56,7 @@ void jabber_google_session_parse(JabberS
void gtalk_xfer_send(PurpleConnection *gc, const char *who, const char*file);
void gtalk_xfer_init(PurpleXfer *xfer);
void gtalk_xfer_request_denied(PurpleXfer *xfer);
-void gtalk_xfer_read(PurpleXfer *xfer);
+gssize gtalk_xfer_read(guchar **out_buffer, PurpleXfer *xfer);
void gtalk_xfer_start(PurpleXfer *xfer);
void gtalk_xfer_send_transport_accept(JabberStream *js, GoogleSession *session);
void gtalk_xfer_send_accept(JabberStream *js, GoogleSession *session);
More information about the Commits
mailing list