|
From: <the...@us...> - 2006-08-11 08:13:44
|
Revision: 16706 Author: thekingant Date: 2006-08-11 01:13:38 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16706&view=rev Log Message: ----------- Backport SVN revisions 16703 through 16705 from HEAD to v2_0_0 Original commit messages: Don't use the same callback for both gaim_proxy_connect() and gaim_input_add(). Aside from being a little confusing, it's hindering some changes I want to make to gaim_proxy_connect(). #if 0 some of the MSN listen-for-connection code for file transfers. It wasn't being used Modified Paths: -------------- branches/v2_0_0/src/protocols/msn/directconn.c branches/v2_0_0/src/protocols/msn/directconn.h branches/v2_0_0/src/protocols/yahoo/yahoo.c branches/v2_0_0/src/protocols/yahoo/yahoo_filexfer.c branches/v2_0_0/src/protocols/yahoo/yahoochat.c branches/v2_0_0/src/util.c Modified: branches/v2_0_0/src/protocols/msn/directconn.c =================================================================== --- branches/v2_0_0/src/protocols/msn/directconn.c 2006-08-11 08:08:19 UTC (rev 16705) +++ branches/v2_0_0/src/protocols/msn/directconn.c 2006-08-11 08:13:38 UTC (rev 16706) @@ -76,6 +76,7 @@ * Connection Functions **************************************************************************/ +#if 0 static int create_listener(int port) { @@ -159,6 +160,7 @@ return fd; } +#endif static size_t msn_directconn_write(MsnDirectConn *directconn, @@ -447,6 +449,7 @@ return FALSE; } +#if 0 void msn_directconn_listen(MsnDirectConn *directconn) { @@ -466,6 +469,7 @@ directconn->port = port; directconn->c = 0; } +#endif MsnDirectConn* msn_directconn_new(MsnSlpLink *slplink) Modified: branches/v2_0_0/src/protocols/msn/directconn.h =================================================================== --- branches/v2_0_0/src/protocols/msn/directconn.h 2006-08-11 08:08:19 UTC (rev 16705) +++ branches/v2_0_0/src/protocols/msn/directconn.h 2006-08-11 08:13:38 UTC (rev 16706) @@ -50,7 +50,9 @@ MsnDirectConn *msn_directconn_new(MsnSlpLink *slplink); gboolean msn_directconn_connect(MsnDirectConn *directconn, const char *host, int port); +#if 0 void msn_directconn_listen(MsnDirectConn *directconn); +#endif void msn_directconn_send_msg(MsnDirectConn *directconn, MsnMessage *msg); void msn_directconn_parse_nonce(MsnDirectConn *directconn, const char *nonce); void msn_directconn_destroy(MsnDirectConn *directconn); Modified: branches/v2_0_0/src/protocols/yahoo/yahoo.c =================================================================== --- branches/v2_0_0/src/protocols/yahoo/yahoo.c 2006-08-11 08:08:19 UTC (rev 16705) +++ branches/v2_0_0/src/protocols/yahoo/yahoo.c 2006-08-11 08:13:38 UTC (rev 16706) @@ -2354,19 +2354,17 @@ } } -static void yahoo_got_cookies(gpointer data, gint source, GaimInputCondition cond) +static void yahoo_got_cookies_send_cb(gpointer data, gint source, GaimInputCondition cond) { - GaimConnection *gc = data; - struct yahoo_data *yd = gc->proto_data; - int written, total_len; + GaimConnection *gc; + struct yahoo_data *yd; + int written, remaining; - if (source < 0) { - gaim_connection_error(gc, _("Unable to connect.")); - return; - } + gc = data; + yd = gc->proto_data; - total_len = strlen(yd->auth) - yd->auth_written; - written = write(source, yd->auth + yd->auth_written, total_len); + remaining = strlen(yd->auth) - yd->auth_written; + written = write(source, yd->auth + yd->auth_written, remaining); if (written < 0 && errno == EAGAIN) written = 0; @@ -2380,22 +2378,35 @@ return; } - if (written < total_len) { + if (written < remaining) { yd->auth_written += written; - if (!gc->inpa) - gc->inpa = gaim_input_add(source, GAIM_INPUT_WRITE, - yahoo_got_cookies, gc); return; } g_free(yd->auth); yd->auth = NULL; yd->auth_written = 0; - if (gc->inpa) - gaim_input_remove(gc->inpa); + gaim_input_remove(gc->inpa); gc->inpa = gaim_input_add(source, GAIM_INPUT_READ, yahoo_web_pending, gc); } +static void yahoo_got_cookies(gpointer data, gint source, GaimInputCondition cond) +{ + GaimConnection *gc = data; + + if (source < 0) { + gaim_connection_error(gc, _("Unable to connect.")); + return; + } + + if (gc->inpa == 0) + { + gc->inpa = gaim_input_add(source, GAIM_INPUT_WRITE, + yahoo_got_cookies_send_cb, gc); + yahoo_got_cookies_send_cb(gc, source, GAIM_INPUT_WRITE); + } +} + static void yahoo_login_page_hash_iter(const char *key, const char *val, GString *url) { if (!strcmp(key, "passwd")) Modified: branches/v2_0_0/src/protocols/yahoo/yahoo_filexfer.c =================================================================== --- branches/v2_0_0/src/protocols/yahoo/yahoo_filexfer.c 2006-08-11 08:08:19 UTC (rev 16705) +++ branches/v2_0_0/src/protocols/yahoo/yahoo_filexfer.c 2006-08-11 08:13:38 UTC (rev 16706) @@ -57,11 +57,45 @@ g_free(xd); } +static void yahoo_receivefile_send_cb(gpointer data, gint source, GaimInputCondition condition) +{ + GaimXfer *xfer; + struct yahoo_xfer_data *xd; + int remaining, written; + + xfer = data; + xd = xfer->data; + + remaining = xd->txbuflen - xd->txbuf_written; + written = write(xfer->fd, xd->txbuf + xd->txbuf_written, remaining); + + if (written < 0 && errno == EAGAIN) + written = 0; + else if (written <= 0) { + gaim_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); + gaim_xfer_cancel_remote(xfer); + return; + } + + if (written < remaining) { + xd->txbuf_written += written; + return; + } + + gaim_input_remove(xd->tx_handler); + xd->tx_handler = 0; + g_free(xd->txbuf); + xd->txbuf = NULL; + xd->txbuflen = 0; + + gaim_xfer_start(xfer, source, NULL, 0); + +} + static void yahoo_receivefile_connected(gpointer data, gint source, GaimInputCondition condition) { GaimXfer *xfer; struct yahoo_xfer_data *xd; - int total_len, written; gaim_debug(GAIM_DEBUG_INFO, "yahoo", "AAA - in yahoo_receivefile_connected\n"); @@ -76,6 +110,8 @@ return; } + xfer->fd = source; + /* The first time we get here, assemble the tx buffer */ if (xd->txbuflen == 0) { xd->txbuf = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n", @@ -84,12 +120,26 @@ xd->txbuf_written = 0; } - total_len = xd->txbuflen - xd->txbuf_written; + if (!xd->tx_handler) + { + xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, + yahoo_receivefile_send_cb, xfer); + yahoo_receivefile_send_cb(xfer, source, GAIM_INPUT_WRITE); + } +} - xfer->fd = source; +static void yahoo_sendfile_send_cb(gpointer data, gint source, GaimInputCondition condition) +{ + GaimXfer *xfer; + struct yahoo_xfer_data *xd; + int written, remaining; - written = write(xfer->fd, xd->txbuf + xd->txbuf_written, total_len); + xfer = data; + xd = xfer->data; + remaining = xd->txbuflen - xd->txbuf_written; + written = write(xfer->fd, xd->txbuf + xd->txbuf_written, remaining); + if (written < 0 && errno == EAGAIN) written = 0; else if (written <= 0) { @@ -98,31 +148,33 @@ return; } - if (written < total_len) { - if (!xd->tx_handler) - xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, - yahoo_receivefile_connected, xfer); + if (written < remaining) { xd->txbuf_written += written; return; } - if (xd->tx_handler) - gaim_input_remove(xd->tx_handler); + gaim_input_remove(xd->tx_handler); xd->tx_handler = 0; g_free(xd->txbuf); xd->txbuf = NULL; xd->txbuflen = 0; gaim_xfer_start(xfer, source, NULL, 0); - } - static void yahoo_sendfile_connected(gpointer data, gint source, GaimInputCondition condition) { GaimXfer *xfer; struct yahoo_xfer_data *xd; - int written, total_len; + struct yahoo_packet *pkt; + gchar *size, *filename, *encoded_filename, *header; + guchar *pkt_buf; + const char *host; + int port; + size_t content_length, header_len, pkt_buf_len; + GaimConnection *gc; + GaimAccount *account; + struct yahoo_data *yd; gaim_debug(GAIM_DEBUG_INFO, "yahoo", "AAA - in yahoo_sendfile_connected\n"); @@ -131,7 +183,6 @@ if (!(xd = xfer->data)) return; - if (source < 0) { gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), xfer->who, _("Unable to connect.")); @@ -139,96 +190,61 @@ return; } - /* The first time we get here, assemble the tx buffer */ - if (xd->txbuflen == 0) { - struct yahoo_packet *pkt; - gchar *size, *filename, *encoded_filename, *header; - guchar *pkt_buf; - const char *host; - int port; - size_t content_length, header_len, pkt_buf_len; - GaimConnection *gc; - GaimAccount *account; - struct yahoo_data *yd; + xfer->fd = source; - gc = xd->gc; - account = gaim_connection_get_account(gc); - yd = gc->proto_data; + /* Assemble the tx buffer */ + gc = xd->gc; + account = gaim_connection_get_account(gc); + yd = gc->proto_data; - pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, - YAHOO_STATUS_AVAILABLE, yd->session_id); + pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, + YAHOO_STATUS_AVAILABLE, yd->session_id); - size = g_strdup_printf("%" G_GSIZE_FORMAT, gaim_xfer_get_size(xfer)); - filename = g_path_get_basename(gaim_xfer_get_local_filename(xfer)); - encoded_filename = yahoo_string_encode(gc, filename, NULL); + size = g_strdup_printf("%" G_GSIZE_FORMAT, gaim_xfer_get_size(xfer)); + filename = g_path_get_basename(gaim_xfer_get_local_filename(xfer)); + encoded_filename = yahoo_string_encode(gc, filename, NULL); - yahoo_packet_hash(pkt, "sssss", 0, gaim_connection_get_display_name(gc), - 5, xfer->who, 14, "", 27, encoded_filename, 28, size); - g_free(size); - g_free(encoded_filename); - g_free(filename); + yahoo_packet_hash(pkt, "sssss", 0, gaim_connection_get_display_name(gc), + 5, xfer->who, 14, "", 27, encoded_filename, 28, size); + g_free(size); + g_free(encoded_filename); + g_free(filename); - content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); + content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); - pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, &pkt_buf); - yahoo_packet_free(pkt); + pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, &pkt_buf); + yahoo_packet_free(pkt); - host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); - port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); - header = g_strdup_printf( - "POST http://%s:%d/notifyft HTTP/1.0\r\n" - "Content-length: %" G_GSIZE_FORMAT "\r\n" - "Host: %s:%d\r\n" - "Cookie: Y=%s; T=%s\r\n" - "\r\n", - host, port, content_length + 4 + gaim_xfer_get_size(xfer), - host, port, yd->cookie_y, yd->cookie_t); + host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); + port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); + header = g_strdup_printf( + "POST http://%s:%d/notifyft HTTP/1.0\r\n" + "Content-length: %" G_GSIZE_FORMAT "\r\n" + "Host: %s:%d\r\n" + "Cookie: Y=%s; T=%s\r\n" + "\r\n", + host, port, content_length + 4 + gaim_xfer_get_size(xfer), + host, port, yd->cookie_y, yd->cookie_t); + header_len = strlen(header); - header_len = strlen(header); + xd->txbuflen = header_len + pkt_buf_len + 4; + xd->txbuf = g_malloc(xd->txbuflen); - xd->txbuflen = header_len + pkt_buf_len + 4; - xd->txbuf = g_malloc(xd->txbuflen); + memcpy(xd->txbuf, header, header_len); + g_free(header); + memcpy(xd->txbuf + header_len, pkt_buf, pkt_buf_len); + g_free(pkt_buf); + memcpy(xd->txbuf + header_len + pkt_buf_len, "29\xc0\x80", 4); - memcpy(xd->txbuf, header, header_len); - g_free(header); - memcpy(xd->txbuf + header_len, pkt_buf, pkt_buf_len); - g_free(pkt_buf); - memcpy(xd->txbuf + header_len + pkt_buf_len, "29\xc0\x80", 4); + xd->txbuf_written = 0; - xd->txbuf_written = 0; + if (xd->tx_handler == 0) + { + xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, + yahoo_sendfile_send_cb, xfer); + yahoo_sendfile_send_cb(xfer, source, GAIM_INPUT_WRITE); } - - total_len = xd->txbuflen - xd->txbuf_written; - - xfer->fd = source; - - written = write(xfer->fd, xd->txbuf + xd->txbuf_written, total_len); - - if (written < 0 && errno == EAGAIN) - written = 0; - else if (written <= 0) { - gaim_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); - gaim_xfer_cancel_remote(xfer); - return; - } - - if (written < total_len) { - if (!xd->tx_handler) - xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, - yahoo_sendfile_connected, xfer); - xd->txbuf_written += written; - return; - } - - if (xd->tx_handler) - gaim_input_remove(xd->tx_handler); - xd->tx_handler = 0; - g_free(xd->txbuf); - xd->txbuf = NULL; - xd->txbuflen = 0; - - gaim_xfer_start(xfer, source, NULL, 0); } static void yahoo_xfer_init(GaimXfer *xfer) Modified: branches/v2_0_0/src/protocols/yahoo/yahoochat.c =================================================================== --- branches/v2_0_0/src/protocols/yahoo/yahoochat.c 2006-08-11 08:08:19 UTC (rev 16705) +++ branches/v2_0_0/src/protocols/yahoo/yahoochat.c 2006-08-11 08:13:38 UTC (rev 16706) @@ -1335,38 +1335,22 @@ yrl->rxlen = 0; } -static void yahoo_roomlist_got_connected(gpointer data, gint source, GaimInputCondition cond) +static void yahoo_roomlist_send_cb(gpointer data, gint source, GaimInputCondition cond) { - struct yahoo_roomlist *yrl = data; - GaimRoomlist *list = yrl->list; - struct yahoo_data *yd = gaim_account_get_connection(list->account)->proto_data; - int written, total_len; + struct yahoo_roomlist *yrl; + GaimRoomlist *list; + int written, remaining; - if (source < 0) { - gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); - yahoo_roomlist_cleanup(list, yrl); - return; - } + yrl = data; + list = yrl->list; - if (yrl->txbuf == NULL) { - yrl->fd = source; + remaining = strlen(yrl->txbuf) - yrl->tx_written; + written = write(yrl->fd, yrl->txbuf + yrl->tx_written, remaining); - yrl->txbuf = g_strdup_printf( - "GET http://%s/%s HTTP/1.0\r\n" - "Host: %s\r\n" - "Cookie: Y=%s; T=%s\r\n\r\n", - yrl->host, yrl->path, yrl->host, yd->cookie_y, - yd->cookie_t); - } - - total_len = strlen(yrl->txbuf) - yrl->tx_written; - written = write(yrl->fd, yrl->txbuf + yrl->tx_written, total_len); - if (written < 0 && errno == EAGAIN) written = 0; else if (written <= 0) { - if (yrl->inpa) - gaim_input_remove(yrl->inpa); + gaim_input_remove(yrl->inpa); yrl->inpa = 0; g_free(yrl->txbuf); yrl->txbuf = NULL; @@ -1375,24 +1359,47 @@ return; } - if (written < total_len) { - if (!yrl->inpa) - yrl->inpa = gaim_input_add(yrl->fd, - GAIM_INPUT_WRITE, yahoo_roomlist_got_connected, - yrl); + if (written < remaining) { yrl->tx_written += written; return; } g_free(yrl->txbuf); yrl->txbuf = NULL; - if (yrl->inpa) - gaim_input_remove(yrl->inpa); + + gaim_input_remove(yrl->inpa); yrl->inpa = gaim_input_add(yrl->fd, GAIM_INPUT_READ, - yahoo_roomlist_pending, yrl); + yahoo_roomlist_pending, yrl); } +static void yahoo_roomlist_got_connected(gpointer data, gint source, GaimInputCondition cond) +{ + struct yahoo_roomlist *yrl = data; + GaimRoomlist *list = yrl->list; + struct yahoo_data *yd = gaim_account_get_connection(list->account)->proto_data; + + if (source < 0) { + gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); + yahoo_roomlist_cleanup(list, yrl); + return; + } + + yrl->fd = source; + + yrl->txbuf = g_strdup_printf( + "GET http://%s/%s HTTP/1.0\r\n" + "Host: %s\r\n" + "Cookie: Y=%s; T=%s\r\n\r\n", + yrl->host, yrl->path, yrl->host, yd->cookie_y, + yd->cookie_t); + + + yrl->inpa = gaim_input_add(yrl->fd, GAIM_INPUT_WRITE, + yahoo_roomlist_send_cb, yrl); + yahoo_roomlist_send_cb(yrl, yrl->fd, GAIM_INPUT_WRITE); +} + GaimRoomlist *yahoo_roomlist_get_list(GaimConnection *gc) { struct yahoo_roomlist *yrl; Modified: branches/v2_0_0/src/util.c =================================================================== --- branches/v2_0_0/src/util.c 2006-08-11 08:08:19 UTC (rev 16705) +++ branches/v2_0_0/src/util.c 2006-08-11 08:13:38 UTC (rev 16706) @@ -3202,7 +3202,7 @@ static void -url_fetched_cb(gpointer url_data, gint sock, GaimInputCondition cond) +url_fetch_recv_cb(gpointer url_data, gint source, GaimInputCondition cond) { GaimFetchUrlData *gfud = url_data; int len; @@ -3210,7 +3210,7 @@ char *data_cursor; gboolean got_eof = FALSE; - while((len = read(sock, buf, sizeof(buf))) > 0) { + while((len = read(source, buf, sizeof(buf))) > 0) { /* If we've filled up our butfer, make it bigger */ if((gfud->len + len) >= gfud->data_len) { while((gfud->len + len) >= gfud->data_len) @@ -3240,7 +3240,7 @@ header_len, gfud->webdata); /* See if we can find a redirect. */ - if(parse_redirect(gfud->webdata, header_len, sock, gfud)) + if(parse_redirect(gfud->webdata, header_len, source, gfud)) return; gfud->got_headers = TRUE; @@ -3273,7 +3273,7 @@ gaim_debug_error("gaim_url_fetch", "Failed to allocate %u bytes: %s\n", content_len, strerror(errno)); gaim_input_remove(gfud->inpa); - close(sock); + close(source); gfud->callback(gfud->user_data, NULL, 0); destroy_fetch_url_data(gfud); @@ -3310,7 +3310,7 @@ got_eof = TRUE; } else { gaim_input_remove(gfud->inpa); - close(sock); + close(source); gfud->callback(gfud->user_data, NULL, 0); @@ -3326,7 +3326,7 @@ /* gaim_debug_misc("gaim_url_fetch", "Received: '%s'\n", gfud->webdata); */ gaim_input_remove(gfud->inpa); - close(sock); + close(source); gfud->callback(gfud->user_data, gfud->webdata, gfud->len); destroy_fetch_url_data(gfud); @@ -3334,17 +3334,54 @@ } static void -url_fetch_connect_cb(gpointer url_data, gint sock, GaimInputCondition cond) { - GaimFetchUrlData *gfud = url_data; +url_fetch_send_cb(gpointer data, gint source, GaimInputCondition cond) +{ + GaimFetchUrlData *gfud; int len, total_len; - if(sock == -1) { + gfud = data; + + total_len = strlen(gfud->request); + + len = write(source, gfud->request + gfud->request_written, + total_len - gfud->request_written); + + if(len < 0 && errno == EAGAIN) + return; + else if(len < 0) { + gaim_input_remove(gfud->inpa); + close(source); gfud->callback(gfud->user_data, NULL, 0); destroy_fetch_url_data(gfud); return; } + gfud->request_written += len; - if (!gfud->request) { + if(gfud->request_written != total_len) + return; + + /* We're done writing, now start reading */ + gaim_input_remove(gfud->inpa); + gfud->inpa = gaim_input_add(source, GAIM_INPUT_READ, url_fetch_recv_cb, + gfud); +} + +static void +url_fetch_connect_cb(gpointer url_data, gint source, GaimInputCondition cond) +{ + GaimFetchUrlData *gfud; + + gfud = url_data; + + if (source == -1) + { + gfud->callback(gfud->user_data, NULL, 0); + destroy_fetch_url_data(gfud); + return; + } + + if (!gfud->request) + { if (gfud->user_agent) { /* Host header is not forbidden in HTTP/1.0 requests, and HTTP/1.1 * clients must know how to handle the "chunked" transfer encoding. @@ -3374,33 +3411,9 @@ gaim_debug_misc("gaim_url_fetch", "Request: '%s'\n", gfud->request); - if(!gfud->inpa) - gfud->inpa = gaim_input_add(sock, GAIM_INPUT_WRITE, - url_fetch_connect_cb, gfud); - - total_len = strlen(gfud->request); - - len = write(sock, gfud->request + gfud->request_written, - total_len - gfud->request_written); - - if(len < 0 && errno == EAGAIN) - return; - else if(len < 0) { - gaim_input_remove(gfud->inpa); - close(sock); - gfud->callback(gfud->user_data, NULL, 0); - destroy_fetch_url_data(gfud); - return; - } - gfud->request_written += len; - - if(gfud->request_written != total_len) - return; - - gaim_input_remove(gfud->inpa); - - gfud->inpa = gaim_input_add(sock, GAIM_INPUT_READ, url_fetched_cb, - gfud); + gfud->inpa = gaim_input_add(source, GAIM_INPUT_WRITE, + url_fetch_send_cb, gfud); + url_fetch_send_cb(gfud, source, GAIM_INPUT_WRITE); } void This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |