Mercurial > pidgin.yaz
diff libpurple/protocols/yahoo/yahoo_filexfer.c @ 15823:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | b8572b937c09 |
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/yahoo_filexfer.c Mon Mar 19 06:11:46 2007 +0000 +++ b/libpurple/protocols/yahoo/yahoo_filexfer.c Mon Mar 19 07:01:17 2007 +0000 @@ -1,7 +1,7 @@ /* * @file yahoo_filexfer.c Yahoo Filetransfer * - * Gaim is the legal property of its developers, whose names are too numerous + * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * @@ -36,7 +36,7 @@ gchar *host; gchar *path; int port; - GaimConnection *gc; + PurpleConnection *gc; long expires; gboolean started; gchar *txbuf; @@ -53,13 +53,13 @@ g_free(xd->path); g_free(xd->txbuf); if (xd->tx_handler) - gaim_input_remove(xd->tx_handler); + purple_input_remove(xd->tx_handler); g_free(xd); } -static void yahoo_receivefile_send_cb(gpointer data, gint source, GaimInputCondition condition) +static void yahoo_receivefile_send_cb(gpointer data, gint source, PurpleInputCondition condition) { - GaimXfer *xfer; + PurpleXfer *xfer; struct yahoo_xfer_data *xd; int remaining, written; @@ -72,8 +72,8 @@ 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); + purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); + purple_xfer_cancel_remote(xfer); return; } @@ -82,31 +82,31 @@ return; } - gaim_input_remove(xd->tx_handler); + purple_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); + purple_xfer_start(xfer, source, NULL, 0); } static void yahoo_receivefile_connected(gpointer data, gint source, const gchar *error_message) { - GaimXfer *xfer; + PurpleXfer *xfer; struct yahoo_xfer_data *xd; - gaim_debug(GAIM_DEBUG_INFO, "yahoo", + purple_debug(PURPLE_DEBUG_INFO, "yahoo", "AAA - in yahoo_receivefile_connected\n"); if (!(xfer = data)) return; if (!(xd = xfer->data)) return; if ((source < 0) || (xd->path == NULL) || (xd->host == NULL)) { - gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), + purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), xfer->who, _("Unable to connect.")); - gaim_xfer_cancel_remote(xfer); + purple_xfer_cancel_remote(xfer); return; } @@ -122,15 +122,15 @@ if (!xd->tx_handler) { - xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, + xd->tx_handler = purple_input_add(source, PURPLE_INPUT_WRITE, yahoo_receivefile_send_cb, xfer); - yahoo_receivefile_send_cb(xfer, source, GAIM_INPUT_WRITE); + yahoo_receivefile_send_cb(xfer, source, PURPLE_INPUT_WRITE); } } -static void yahoo_sendfile_send_cb(gpointer data, gint source, GaimInputCondition condition) +static void yahoo_sendfile_send_cb(gpointer data, gint source, PurpleInputCondition condition) { - GaimXfer *xfer; + PurpleXfer *xfer; struct yahoo_xfer_data *xd; int written, remaining; @@ -143,8 +143,8 @@ 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); + purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); + purple_xfer_cancel_remote(xfer); return; } @@ -153,18 +153,18 @@ return; } - gaim_input_remove(xd->tx_handler); + purple_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); + purple_xfer_start(xfer, source, NULL, 0); } static void yahoo_sendfile_connected(gpointer data, gint source, const gchar *error_message) { - GaimXfer *xfer; + PurpleXfer *xfer; struct yahoo_xfer_data *xd; struct yahoo_packet *pkt; gchar *size, *filename, *encoded_filename, *header; @@ -172,11 +172,11 @@ const char *host; int port; size_t content_length, header_len, pkt_buf_len; - GaimConnection *gc; - GaimAccount *account; + PurpleConnection *gc; + PurpleAccount *account; struct yahoo_data *yd; - gaim_debug(GAIM_DEBUG_INFO, "yahoo", + purple_debug(PURPLE_DEBUG_INFO, "yahoo", "AAA - in yahoo_sendfile_connected\n"); if (!(xfer = data)) return; @@ -184,9 +184,9 @@ return; if (source < 0) { - gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), + purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), xfer->who, _("Unable to connect.")); - gaim_xfer_cancel_remote(xfer); + purple_xfer_cancel_remote(xfer); return; } @@ -194,17 +194,17 @@ /* Assemble the tx buffer */ gc = xd->gc; - account = gaim_connection_get_account(gc); + account = purple_connection_get_account(gc); yd = gc->proto_data; 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)); + size = g_strdup_printf("%" G_GSIZE_FORMAT, purple_xfer_get_size(xfer)); + filename = g_path_get_basename(purple_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), + yahoo_packet_hash(pkt, "sssss", 0, purple_connection_get_display_name(gc), 5, xfer->who, 14, "", 27, encoded_filename, 28, size); g_free(size); g_free(encoded_filename); @@ -215,15 +215,15 @@ pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, yd->jp, &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); + host = purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); + port = purple_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, content_length + 4 + purple_xfer_get_size(xfer), host, port, yd->cookie_y, yd->cookie_t); header_len = strlen(header); @@ -241,65 +241,65 @@ if (xd->tx_handler == 0) { - xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, + xd->tx_handler = purple_input_add(source, PURPLE_INPUT_WRITE, yahoo_sendfile_send_cb, xfer); - yahoo_sendfile_send_cb(xfer, source, GAIM_INPUT_WRITE); + yahoo_sendfile_send_cb(xfer, source, PURPLE_INPUT_WRITE); } } -static void yahoo_xfer_init(GaimXfer *xfer) +static void yahoo_xfer_init(PurpleXfer *xfer) { struct yahoo_xfer_data *xfer_data; - GaimConnection *gc; - GaimAccount *account; + PurpleConnection *gc; + PurpleAccount *account; struct yahoo_data *yd; xfer_data = xfer->data; gc = xfer_data->gc; yd = gc->proto_data; - account = gaim_connection_get_account(gc); + account = purple_connection_get_account(gc); - if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) { + if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { if (yd->jp) { - if (gaim_proxy_connect(NULL, account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), - gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), + if (purple_proxy_connect(NULL, account, purple_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), + purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), yahoo_sendfile_connected, xfer) == NULL) { - gaim_notify_error(gc, NULL, _("File Transfer Failed"), + purple_notify_error(gc, NULL, _("File Transfer Failed"), _("Unable to establish file descriptor.")); - gaim_xfer_cancel_remote(xfer); + purple_xfer_cancel_remote(xfer); } } else { - if (gaim_proxy_connect(NULL, account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), - gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), + if (purple_proxy_connect(NULL, account, purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), + purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), yahoo_sendfile_connected, xfer) == NULL) { - gaim_notify_error(gc, NULL, _("File Transfer Failed"), + purple_notify_error(gc, NULL, _("File Transfer Failed"), _("Unable to establish file descriptor.")); - gaim_xfer_cancel_remote(xfer); + purple_xfer_cancel_remote(xfer); } } } else { /* TODO: Using xfer->fd like this is probably a bad thing... */ - if (gaim_proxy_connect(NULL, account, xfer_data->host, xfer_data->port, + if (purple_proxy_connect(NULL, account, xfer_data->host, xfer_data->port, yahoo_receivefile_connected, xfer) == NULL) xfer->fd = -1; else xfer->fd = 0; if (xfer->fd == -1) { - gaim_notify_error(gc, NULL, _("File Transfer Failed"), + purple_notify_error(gc, NULL, _("File Transfer Failed"), _("Unable to establish file descriptor.")); - gaim_xfer_cancel_remote(xfer); + purple_xfer_cancel_remote(xfer); } } } -static void yahoo_xfer_start(GaimXfer *xfer) +static void yahoo_xfer_start(PurpleXfer *xfer) { /* We don't need to do anything here, do we? */ } -static void yahoo_xfer_end(GaimXfer *xfer) +static void yahoo_xfer_end(PurpleXfer *xfer) { struct yahoo_xfer_data *xfer_data; @@ -323,7 +323,7 @@ return 0; } -static gssize yahoo_xfer_read(guchar **buffer, GaimXfer *xfer) +static gssize yahoo_xfer_read(guchar **buffer, PurpleXfer *xfer) { gchar buf[4096]; gssize len; @@ -333,16 +333,16 @@ int filelen; struct yahoo_xfer_data *xd = xfer->data; - if (gaim_xfer_get_type(xfer) != GAIM_XFER_RECEIVE) { + if (purple_xfer_get_type(xfer) != PURPLE_XFER_RECEIVE) { return 0; } len = read(xfer->fd, buf, sizeof(buf)); if (len <= 0) { - if ((gaim_xfer_get_size(xfer) > 0) && - (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer))) { - gaim_xfer_set_completed(xfer, TRUE); + if ((purple_xfer_get_size(xfer) > 0) && + (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer))) { + purple_xfer_set_completed(xfer, TRUE); return 0; } else return -1; @@ -364,7 +364,7 @@ if (!end) return 0; if ((filelen = calculate_length(length, len - (length - xd->rxqueue)))) - gaim_xfer_set_size(xfer, filelen); + purple_xfer_set_size(xfer, filelen); } start = g_strstr_len(xd->rxqueue, len, "\r\n\r\n"); if (start) @@ -388,7 +388,7 @@ return len; } -static gssize yahoo_xfer_write(const guchar *buffer, size_t size, GaimXfer *xfer) +static gssize yahoo_xfer_write(const guchar *buffer, size_t size, PurpleXfer *xfer) { gssize len; struct yahoo_xfer_data *xd = xfer->data; @@ -396,27 +396,27 @@ if (!xd) return -1; - if (gaim_xfer_get_type(xfer) != GAIM_XFER_SEND) { + if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) { return -1; } len = write(xfer->fd, buffer, size); if (len == -1) { - if (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer)) - gaim_xfer_set_completed(xfer, TRUE); + if (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer)) + purple_xfer_set_completed(xfer, TRUE); if ((errno != EAGAIN) && (errno != EINTR)) return -1; return 0; } - if ((gaim_xfer_get_bytes_sent(xfer) + len) >= gaim_xfer_get_size(xfer)) - gaim_xfer_set_completed(xfer, TRUE); + if ((purple_xfer_get_bytes_sent(xfer) + len) >= purple_xfer_get_size(xfer)) + purple_xfer_set_completed(xfer, TRUE); return len; } -static void yahoo_xfer_cancel_send(GaimXfer *xfer) +static void yahoo_xfer_cancel_send(PurpleXfer *xfer) { struct yahoo_xfer_data *xfer_data; @@ -427,7 +427,7 @@ xfer->data = NULL; } -static void yahoo_xfer_cancel_recv(GaimXfer *xfer) +static void yahoo_xfer_cancel_recv(PurpleXfer *xfer) { struct yahoo_xfer_data *xfer_data; @@ -438,7 +438,7 @@ xfer->data = NULL; } -void yahoo_process_p2pfilexfer(GaimConnection *gc, struct yahoo_packet *pkt) +void yahoo_process_p2pfilexfer(PurpleConnection *gc, struct yahoo_packet *pkt) { GSList *l = pkt->hash; @@ -495,7 +495,7 @@ } } -void yahoo_process_filetransfer(GaimConnection *gc, struct yahoo_packet *pkt) +void yahoo_process_filetransfer(PurpleConnection *gc, struct yahoo_packet *pkt) { char *from = NULL; char *to = NULL; @@ -503,7 +503,7 @@ char *url = NULL; char *imv = NULL; long expires = 0; - GaimXfer *xfer; + PurpleXfer *xfer; struct yahoo_data *yd; struct yahoo_xfer_data *xfer_data; char *service = NULL; @@ -547,7 +547,7 @@ if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { if (service && (strcmp("FILEXFER", service) != 0)) { - gaim_debug_misc("yahoo", "unhandled service 0x%02x\n", pkt->service); + purple_debug_misc("yahoo", "unhandled service 0x%02x\n", pkt->service); return; } } @@ -565,16 +565,16 @@ /* Setup the Yahoo-specific file transfer data */ xfer_data = g_new0(struct yahoo_xfer_data, 1); xfer_data->gc = gc; - if (!gaim_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) { + if (!purple_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) { g_free(xfer_data); return; } - gaim_debug_misc("yahoo_filexfer", "Host is %s, port is %d, path is %s, and the full url was %s.\n", + purple_debug_misc("yahoo_filexfer", "Host is %s, port is %d, path is %s, and the full url was %s.\n", xfer_data->host, xfer_data->port, xfer_data->path, url); /* Build the file transfer handle. */ - xfer = gaim_xfer_new(gc->account, GAIM_XFER_RECEIVE, from); + xfer = purple_xfer_new(gc->account, PURPLE_XFER_RECEIVE, from); if (xfer) { xfer->data = xfer_data; @@ -582,7 +582,7 @@ /* Set the info about the incoming file. */ if (filename) { char *utf8_filename = yahoo_string_decode(gc, filename, TRUE); - gaim_xfer_set_filename(xfer, utf8_filename); + purple_xfer_set_filename(xfer, utf8_filename); g_free(utf8_filename); } else { gchar *start, *end; @@ -595,31 +595,31 @@ filename = g_strndup(start, end - start); utf8_filename = yahoo_string_decode(gc, filename, TRUE); g_free(filename); - gaim_xfer_set_filename(xfer, utf8_filename); + purple_xfer_set_filename(xfer, utf8_filename); g_free(utf8_filename); filename = NULL; } } - gaim_xfer_set_size(xfer, filesize); + purple_xfer_set_size(xfer, filesize); /* Setup our I/O op functions */ - gaim_xfer_set_init_fnc(xfer, yahoo_xfer_init); - gaim_xfer_set_start_fnc(xfer, yahoo_xfer_start); - gaim_xfer_set_end_fnc(xfer, yahoo_xfer_end); - gaim_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); - gaim_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); - gaim_xfer_set_read_fnc(xfer, yahoo_xfer_read); - gaim_xfer_set_write_fnc(xfer, yahoo_xfer_write); + purple_xfer_set_init_fnc(xfer, yahoo_xfer_init); + purple_xfer_set_start_fnc(xfer, yahoo_xfer_start); + purple_xfer_set_end_fnc(xfer, yahoo_xfer_end); + purple_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); + purple_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); + purple_xfer_set_read_fnc(xfer, yahoo_xfer_read); + purple_xfer_set_write_fnc(xfer, yahoo_xfer_write); /* Now perform the request */ - gaim_xfer_request(xfer); + purple_xfer_request(xfer); } } -GaimXfer *yahoo_new_xfer(GaimConnection *gc, const char *who) +PurpleXfer *yahoo_new_xfer(PurpleConnection *gc, const char *who) { - GaimXfer *xfer; + PurpleXfer *xfer; struct yahoo_xfer_data *xfer_data; g_return_val_if_fail(who != NULL, NULL); @@ -628,33 +628,33 @@ xfer_data->gc = gc; /* Build the file transfer handle. */ - xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who); + xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who); if (xfer) { xfer->data = xfer_data; /* Setup our I/O op functions */ - gaim_xfer_set_init_fnc(xfer, yahoo_xfer_init); - gaim_xfer_set_start_fnc(xfer, yahoo_xfer_start); - gaim_xfer_set_end_fnc(xfer, yahoo_xfer_end); - gaim_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); - gaim_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); - gaim_xfer_set_read_fnc(xfer, yahoo_xfer_read); - gaim_xfer_set_write_fnc(xfer, yahoo_xfer_write); + purple_xfer_set_init_fnc(xfer, yahoo_xfer_init); + purple_xfer_set_start_fnc(xfer, yahoo_xfer_start); + purple_xfer_set_end_fnc(xfer, yahoo_xfer_end); + purple_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); + purple_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); + purple_xfer_set_read_fnc(xfer, yahoo_xfer_read); + purple_xfer_set_write_fnc(xfer, yahoo_xfer_write); } return xfer; } -void yahoo_send_file(GaimConnection *gc, const char *who, const char *file) +void yahoo_send_file(PurpleConnection *gc, const char *who, const char *file) { - GaimXfer *xfer = yahoo_new_xfer(gc, who); + PurpleXfer *xfer = yahoo_new_xfer(gc, who); g_return_if_fail(xfer != NULL); /* Now perform the request */ if (file) - gaim_xfer_request_accepted(xfer, file); + purple_xfer_request_accepted(xfer, file); else - gaim_xfer_request(xfer); + purple_xfer_request(xfer); }