Wed, 08 Mar 2006 21:29:51 +0000
[gaim-migrate @ 15841]
This debug message should end with a newline.
| 7651 | 1 | /* |
| 2 | * @file yahoo_filexfer.c Yahoo Filetransfer | |
| 3 | * | |
| 8046 | 4 | * Gaim is the legal property of its developers, whose names are too numerous |
| 5 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 | * source distribution. | |
| 7651 | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
| 22 | ||
| 23 | #include "prpl.h" | |
| 24 | #include "internal.h" | |
| 25 | #include "util.h" | |
| 26 | #include "debug.h" | |
| 27 | #include "notify.h" | |
| 28 | #include "proxy.h" | |
| 29 | #include "ft.h" | |
| 30 | #include "yahoo.h" | |
| 10392 | 31 | #include "yahoo_packet.h" |
| 7651 | 32 | #include "yahoo_filexfer.h" |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
33 | #include "yahoo_doodle.h" |
| 7651 | 34 | |
| 35 | struct yahoo_xfer_data { | |
| 36 | gchar *host; | |
| 37 | gchar *path; | |
| 38 | int port; | |
| 39 | GaimConnection *gc; | |
| 40 | long expires; | |
| 41 | gboolean started; | |
|
13272
fd4f3356640f
[gaim-migrate @ 15637]
Daniel Atallah <datallah@pidgin.im>
parents:
13201
diff
changeset
|
42 | gchar *txbuf; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
43 | gsize txbuflen; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
44 | gsize txbuf_written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
45 | guint tx_handler; |
| 7651 | 46 | gchar *rxqueue; |
| 47 | guint rxlen; | |
| 48 | }; | |
| 49 | ||
| 50 | static void yahoo_xfer_data_free(struct yahoo_xfer_data *xd) | |
| 51 | { | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
52 | g_free(xd->host); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
53 | g_free(xd->path); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
54 | g_free(xd->txbuf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
55 | if (xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
56 | gaim_input_remove(xd->tx_handler); |
| 7651 | 57 | g_free(xd); |
| 58 | } | |
| 59 | ||
| 60 | static void yahoo_receivefile_connected(gpointer data, gint source, GaimInputCondition condition) | |
| 61 | { | |
| 62 | GaimXfer *xfer; | |
| 63 | struct yahoo_xfer_data *xd; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
64 | int total_len, written; |
| 7651 | 65 | |
| 66 | gaim_debug(GAIM_DEBUG_INFO, "yahoo", | |
| 67 | "AAA - in yahoo_receivefile_connected\n"); | |
| 68 | if (!(xfer = data)) | |
| 69 | return; | |
| 70 | if (!(xd = xfer->data)) | |
| 71 | return; | |
|
13144
e8c3eafab5f8
[gaim-migrate @ 15506]
Evan Schoenberg <evands@pidgin.im>
parents:
12412
diff
changeset
|
72 | if ((source < 0) || (xd->path == NULL) || (xd->host == NULL)) { |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
73 | gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), |
|
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
74 | xfer->who, _("Unable to connect.")); |
| 7805 | 75 | gaim_xfer_cancel_remote(xfer); |
| 7651 | 76 | return; |
| 77 | } | |
| 78 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
79 | /* The first time we get here, assemble the tx buffer */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
80 | if (xd->txbuflen == 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
81 | xd->txbuf = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n", |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
82 | xd->path, xd->host); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
83 | xd->txbuflen = strlen(xd->txbuf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
84 | xd->txbuf_written = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
85 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
86 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
87 | total_len = xd->txbuflen - xd->txbuf_written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
88 | |
| 7651 | 89 | xfer->fd = source; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
90 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
91 | written = write(xfer->fd, xd->txbuf + xd->txbuf_written, total_len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
92 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
93 | if (written < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
94 | written = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
95 | else if (written <= 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
96 | gaim_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
97 | gaim_xfer_cancel_remote(xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
98 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
99 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
100 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
101 | if (written < total_len) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
102 | if (!xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
103 | xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
104 | yahoo_receivefile_connected, xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
105 | xd->txbuf_written += written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
106 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
107 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
108 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
109 | if (xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
110 | gaim_input_remove(xd->tx_handler); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
111 | xd->tx_handler = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
112 | g_free(xd->txbuf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
113 | xd->txbuf = NULL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
114 | xd->txbuflen = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
115 | |
| 7651 | 116 | gaim_xfer_start(xfer, source, NULL, 0); |
| 117 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
118 | } |
| 7651 | 119 | |
| 120 | ||
| 121 | static void yahoo_sendfile_connected(gpointer data, gint source, GaimInputCondition condition) | |
| 122 | { | |
| 123 | GaimXfer *xfer; | |
| 124 | struct yahoo_xfer_data *xd; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
125 | int written, total_len; |
| 7651 | 126 | |
| 127 | gaim_debug(GAIM_DEBUG_INFO, "yahoo", | |
| 128 | "AAA - in yahoo_sendfile_connected\n"); | |
| 129 | if (!(xfer = data)) | |
| 130 | return; | |
| 131 | if (!(xd = xfer->data)) | |
| 132 | return; | |
| 133 | ||
| 134 | ||
| 135 | if (source < 0) { | |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
136 | gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), |
|
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
137 | xfer->who, _("Unable to connect.")); |
| 7805 | 138 | gaim_xfer_cancel_remote(xfer); |
| 7651 | 139 | return; |
| 140 | } | |
| 141 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
142 | /* The first time we get here, assemble the tx buffer */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
143 | if (xd->txbuflen == 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
144 | struct yahoo_packet *pkt; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
145 | gchar *size, *filename, *encoded_filename, *header; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
146 | guchar *pkt_buf; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
147 | const char *host; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
148 | int port; |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13272
diff
changeset
|
149 | size_t content_length, header_len, pkt_buf_len; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
150 | GaimConnection *gc; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
151 | GaimAccount *account; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
152 | struct yahoo_data *yd; |
| 7651 | 153 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
154 | gc = xd->gc; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
155 | account = gaim_connection_get_account(gc); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
156 | yd = gc->proto_data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
157 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
158 | pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
159 | YAHOO_STATUS_AVAILABLE, yd->session_id); |
| 7651 | 160 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
161 | size = g_strdup_printf("%" G_GSIZE_FORMAT, gaim_xfer_get_size(xfer)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
162 | filename = g_path_get_basename(gaim_xfer_get_local_filename(xfer)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
163 | encoded_filename = yahoo_string_encode(gc, filename, NULL); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
164 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
165 | yahoo_packet_hash(pkt, "sssss", 0, gaim_connection_get_display_name(gc), |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
166 | 5, xfer->who, 14, "", 27, encoded_filename, 28, size); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
167 | g_free(size); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
168 | g_free(encoded_filename); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
169 | g_free(filename); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
170 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
171 | content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
172 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
173 | pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, &pkt_buf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
174 | yahoo_packet_free(pkt); |
| 7651 | 175 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
176 | host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
177 | port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
178 | header = g_strdup_printf( |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
179 | "POST http://%s:%d/notifyft HTTP/1.0\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
180 | "Content-length: %" G_GSIZE_FORMAT "\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
181 | "Host: %s:%d\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
182 | "Cookie: Y=%s; T=%s\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
183 | "\r\n", |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
184 | host, port, content_length + 4 + gaim_xfer_get_size(xfer), |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
185 | host, port, yd->cookie_y, yd->cookie_t); |
| 7651 | 186 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
187 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
188 | header_len = strlen(header); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
189 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
190 | xd->txbuflen = header_len + pkt_buf_len + 4; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
191 | xd->txbuf = g_malloc(xd->txbuflen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
192 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
193 | memcpy(xd->txbuf, header, header_len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
194 | g_free(header); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
195 | memcpy(xd->txbuf + header_len, pkt_buf, pkt_buf_len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
196 | g_free(pkt_buf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
197 | memcpy(xd->txbuf + header_len + pkt_buf_len, "29\xc0\x80", 4); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
198 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
199 | xd->txbuf_written = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
200 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
201 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
202 | total_len = xd->txbuflen - xd->txbuf_written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
203 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
204 | xfer->fd = source; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
205 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
206 | written = write(xfer->fd, xd->txbuf + xd->txbuf_written, total_len); |
| 7651 | 207 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
208 | if (written < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
209 | written = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
210 | else if (written <= 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
211 | gaim_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
212 | gaim_xfer_cancel_remote(xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
213 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
214 | } |
| 7651 | 215 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
216 | if (written < total_len) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
217 | if (!xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
218 | xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
219 | yahoo_sendfile_connected, xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
220 | xd->txbuf_written += written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
221 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
222 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
223 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
224 | if (xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
225 | gaim_input_remove(xd->tx_handler); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
226 | xd->tx_handler = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
227 | g_free(xd->txbuf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
228 | xd->txbuf = NULL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
229 | xd->txbuflen = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
230 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
231 | gaim_xfer_start(xfer, source, NULL, 0); |
| 7651 | 232 | } |
| 233 | ||
| 234 | static void yahoo_xfer_init(GaimXfer *xfer) | |
| 235 | { | |
| 236 | struct yahoo_xfer_data *xfer_data; | |
| 237 | GaimConnection *gc; | |
| 238 | GaimAccount *account; | |
| 7827 | 239 | struct yahoo_data *yd; |
| 7651 | 240 | |
| 241 | xfer_data = xfer->data; | |
| 242 | gc = xfer_data->gc; | |
| 7827 | 243 | yd = gc->proto_data; |
| 7651 | 244 | account = gaim_connection_get_account(gc); |
| 245 | ||
| 246 | if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) { | |
|
10937
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
247 | if (yd->jp) { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
248 | if (gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
249 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
250 | yahoo_sendfile_connected, xfer) == -1) |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
251 | { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
252 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
253 | _("Unable to establish file descriptor.")); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
254 | gaim_xfer_cancel_remote(xfer); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
255 | } |
| 8282 | 256 | } else { |
|
10937
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
257 | if (gaim_proxy_connect(account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
258 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
259 | yahoo_sendfile_connected, xfer) == -1) |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
260 | { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
261 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
262 | _("Unable to establish file descriptor.")); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
263 | gaim_xfer_cancel_remote(xfer); |
| 8282 | 264 | } |
| 7651 | 265 | } |
| 266 | } else { | |
| 267 | xfer->fd = gaim_proxy_connect(account, xfer_data->host, xfer_data->port, | |
| 268 | yahoo_receivefile_connected, xfer); | |
| 269 | if (xfer->fd == -1) { | |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
270 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
| 7651 | 271 | _("Unable to establish file descriptor.")); |
| 272 | gaim_xfer_cancel_remote(xfer); | |
| 273 | } | |
| 274 | } | |
| 275 | } | |
| 276 | ||
| 277 | static void yahoo_xfer_start(GaimXfer *xfer) | |
| 278 | { | |
| 279 | /* We don't need to do anything here, do we? */ | |
| 280 | } | |
| 281 | ||
| 282 | static void yahoo_xfer_end(GaimXfer *xfer) | |
| 283 | { | |
| 284 | GaimAccount *account; | |
| 285 | struct yahoo_xfer_data *xfer_data; | |
| 286 | ||
| 287 | account = gaim_xfer_get_account(xfer); | |
| 288 | xfer_data = xfer->data; | |
| 289 | ||
| 290 | if (xfer_data) | |
| 291 | yahoo_xfer_data_free(xfer_data); | |
| 292 | xfer->data = NULL; | |
| 293 | ||
| 294 | } | |
| 295 | ||
|
11897
10853b830964
[gaim-migrate @ 14188]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11801
diff
changeset
|
296 | static guint calculate_length(const gchar *l, size_t len) |
| 7651 | 297 | { |
| 298 | int i; | |
| 299 | ||
| 300 | for (i = 0; i < len; i++) { | |
| 301 | if (!g_ascii_isdigit(l[i])) | |
| 302 | continue; | |
| 303 | return strtol(l + i, NULL, 10); | |
| 304 | } | |
| 305 | return 0; | |
| 306 | } | |
| 307 | ||
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12151
diff
changeset
|
308 | static gssize yahoo_xfer_read(guchar **buffer, GaimXfer *xfer) |
| 7651 | 309 | { |
| 7710 | 310 | gchar buf[4096]; |
|
12151
8002bb57756b
[gaim-migrate @ 14452]
Richard Laager <rlaager@pidgin.im>
parents:
12143
diff
changeset
|
311 | gssize len; |
| 7651 | 312 | gchar *start = NULL; |
| 313 | gchar *length; | |
| 314 | gchar *end; | |
| 7710 | 315 | int filelen; |
| 7651 | 316 | struct yahoo_xfer_data *xd = xfer->data; |
| 317 | ||
| 318 | if (gaim_xfer_get_type(xfer) != GAIM_XFER_RECEIVE) { | |
| 319 | return 0; | |
| 320 | } | |
| 321 | ||
| 322 | len = read(xfer->fd, buf, sizeof(buf)); | |
| 323 | ||
| 7682 | 324 | if (len <= 0) { |
| 7710 | 325 | if ((gaim_xfer_get_size(xfer) > 0) && |
| 9798 | 326 | (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer))) { |
| 7682 | 327 | gaim_xfer_set_completed(xfer, TRUE); |
| 9798 | 328 | return 0; |
| 329 | } else | |
| 330 | return -1; | |
| 7651 | 331 | } |
| 332 | ||
| 333 | if (!xd->started) { | |
| 334 | xd->rxqueue = g_realloc(xd->rxqueue, len + xd->rxlen); | |
| 335 | memcpy(xd->rxqueue + xd->rxlen, buf, len); | |
| 336 | xd->rxlen += len; | |
| 337 | ||
| 338 | length = g_strstr_len(xd->rxqueue, len, "Content-length:"); | |
|
10579
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
339 | /* some proxies re-write this header, changing the capitalization :( |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
340 | * technically that's allowed since headers are case-insensitive |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
341 | * [RFC 2616, section 4.2] */ |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
342 | if (length == NULL) |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
343 | length = g_strstr_len(xd->rxqueue, len, "Content-Length:"); |
| 7651 | 344 | if (length) { |
| 345 | end = g_strstr_len(length, length - xd->rxqueue, "\r\n"); | |
| 346 | if (!end) | |
| 347 | return 0; | |
| 7710 | 348 | if ((filelen = calculate_length(length, len - (length - xd->rxqueue)))) |
| 349 | gaim_xfer_set_size(xfer, filelen); | |
| 7651 | 350 | } |
| 351 | start = g_strstr_len(xd->rxqueue, len, "\r\n\r\n"); | |
| 352 | if (start) | |
| 353 | start += 4; | |
| 354 | if (!start || start > (xd->rxqueue + len)) | |
| 355 | return 0; | |
| 356 | xd->started = TRUE; | |
| 357 | ||
| 358 | len -= (start - xd->rxqueue); | |
| 359 | ||
| 360 | *buffer = g_malloc(len); | |
| 361 | memcpy(*buffer, start, len); | |
| 362 | g_free(xd->rxqueue); | |
| 363 | xd->rxqueue = NULL; | |
| 364 | xd->rxlen = 0; | |
| 365 | } else { | |
| 366 | *buffer = g_malloc(len); | |
| 367 | memcpy(*buffer, buf, len); | |
| 368 | } | |
| 369 | ||
| 370 | return len; | |
| 371 | } | |
| 372 | ||
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12151
diff
changeset
|
373 | static gssize yahoo_xfer_write(const guchar *buffer, size_t size, GaimXfer *xfer) |
| 7651 | 374 | { |
|
12151
8002bb57756b
[gaim-migrate @ 14452]
Richard Laager <rlaager@pidgin.im>
parents:
12143
diff
changeset
|
375 | gssize len; |
| 7651 | 376 | struct yahoo_xfer_data *xd = xfer->data; |
| 377 | ||
| 378 | if (!xd) | |
| 9798 | 379 | return -1; |
| 7651 | 380 | |
| 381 | if (gaim_xfer_get_type(xfer) != GAIM_XFER_SEND) { | |
| 9798 | 382 | return -1; |
| 7651 | 383 | } |
| 384 | ||
| 385 | len = write(xfer->fd, buffer, size); | |
| 386 | ||
| 7710 | 387 | if (len == -1) { |
| 388 | if (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer)) | |
| 389 | gaim_xfer_set_completed(xfer, TRUE); | |
| 390 | if ((errno != EAGAIN) && (errno != EINTR)) | |
| 9798 | 391 | return -1; |
| 7710 | 392 | return 0; |
| 393 | } | |
| 394 | ||
| 395 | if ((gaim_xfer_get_bytes_sent(xfer) + len) >= gaim_xfer_get_size(xfer)) | |
| 7651 | 396 | gaim_xfer_set_completed(xfer, TRUE); |
| 397 | ||
| 398 | return len; | |
| 399 | } | |
| 400 | ||
| 401 | static void yahoo_xfer_cancel_send(GaimXfer *xfer) | |
| 402 | { | |
| 403 | GaimAccount *account; | |
| 404 | struct yahoo_xfer_data *xfer_data; | |
| 405 | ||
| 406 | xfer_data = xfer->data; | |
| 407 | account = gaim_xfer_get_account(xfer); | |
| 408 | ||
| 409 | if (xfer_data) | |
| 410 | yahoo_xfer_data_free(xfer_data); | |
| 411 | xfer->data = NULL; | |
| 412 | } | |
| 413 | ||
| 414 | static void yahoo_xfer_cancel_recv(GaimXfer *xfer) | |
| 415 | { | |
| 416 | GaimAccount *account; | |
| 417 | struct yahoo_xfer_data *xfer_data; | |
| 418 | ||
| 419 | account = gaim_xfer_get_account(xfer); | |
| 420 | xfer_data = xfer->data; | |
| 421 | ||
| 422 | if (xfer_data) | |
| 423 | yahoo_xfer_data_free(xfer_data); | |
| 424 | xfer->data = NULL; | |
| 425 | } | |
| 426 | ||
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
427 | void yahoo_process_p2pfilexfer(GaimConnection *gc, struct yahoo_packet *pkt) |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
428 | { |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
429 | GSList *l = pkt->hash; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
430 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
431 | char *me = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
432 | char *from = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
433 | char *service = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
434 | char *message = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
435 | char *command = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
436 | char *imv = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
437 | char *unknown = NULL; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
438 | |
|
11801
c19b37ac661b
[gaim-migrate @ 14092]
Gary Kramlich <grim@reaperworld.com>
parents:
11644
diff
changeset
|
439 | /* Get all the necessary values from this new packet */ |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
440 | while(l != NULL) |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
441 | { |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
442 | struct yahoo_pair *pair = l->data; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
443 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
444 | if(pair->key == 5) /* Get who the packet is for */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
445 | me = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
446 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
447 | if(pair->key == 4) /* Get who the packet is from */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
448 | from = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
449 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
450 | if(pair->key == 49) /* Get the type of service */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
451 | service = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
452 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
453 | if(pair->key == 14) /* Get the 'message' of the packet */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
454 | message = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
455 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
456 | if(pair->key == 13) /* Get the command associated with this packet */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
457 | command = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
458 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
459 | if(pair->key == 63) /* IMVironment name and version */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
460 | imv = pair->value; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
461 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
462 | if(pair->key == 64) /* Not sure, but it does vary with initialization of Doodle */ |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
463 | unknown = pair->value; /* So, I'll keep it (for a little while atleast) */ |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
464 | |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
465 | l = l->next; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
466 | } |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
467 | |
|
11801
c19b37ac661b
[gaim-migrate @ 14092]
Gary Kramlich <grim@reaperworld.com>
parents:
11644
diff
changeset
|
468 | /* If this packet is an IMVIRONMENT, handle it accordingly */ |
|
13459
c20f00df92e5
[gaim-migrate @ 15833]
Daniel Atallah <datallah@pidgin.im>
parents:
13277
diff
changeset
|
469 | if(service != NULL && imv != NULL && !strcmp(service, "IMVIRONMENT")) |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
470 | { |
|
11801
c19b37ac661b
[gaim-migrate @ 14092]
Gary Kramlich <grim@reaperworld.com>
parents:
11644
diff
changeset
|
471 | /* Check for a Doodle packet and handle it accordingly */ |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
472 | if(!strcmp(imv, "doodle;11")) |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
473 | yahoo_doodle_process(gc, me, from, command, message); |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
474 | |
|
11801
c19b37ac661b
[gaim-migrate @ 14092]
Gary Kramlich <grim@reaperworld.com>
parents:
11644
diff
changeset
|
475 | /* If an IMVIRONMENT packet comes without a specific imviroment name */ |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
476 | if(!strcmp(imv, ";0")) |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
477 | { |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
478 | /* It is unfortunately time to close all IMVironments with the remote client */ |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
479 | yahoo_doodle_command_got_shutdown(gc, from); |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
480 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
481 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
482 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
483 | |
| 7651 | 484 | void yahoo_process_filetransfer(GaimConnection *gc, struct yahoo_packet *pkt) |
| 485 | { | |
| 486 | char *from = NULL; | |
| 487 | char *to = NULL; | |
| 488 | char *msg = NULL; | |
| 489 | char *url = NULL; | |
| 490 | long expires = 0; | |
| 491 | GaimXfer *xfer; | |
| 492 | struct yahoo_xfer_data *xfer_data; | |
| 493 | char *service = NULL; | |
| 494 | char *filename = NULL; | |
| 495 | unsigned long filesize = 0L; | |
| 496 | GSList *l; | |
| 497 | ||
| 498 | for (l = pkt->hash; l; l = l->next) { | |
| 499 | struct yahoo_pair *pair = l->data; | |
| 500 | ||
| 501 | if (pair->key == 4) | |
| 502 | from = pair->value; | |
| 503 | if (pair->key == 5) | |
| 504 | to = pair->value; | |
| 505 | if (pair->key == 14) | |
| 506 | msg = pair->value; | |
| 507 | if (pair->key == 20) | |
| 508 | url = pair->value; | |
| 509 | if (pair->key == 38) | |
| 510 | expires = strtol(pair->value, NULL, 10); | |
| 511 | if (pair->key == 27) | |
| 512 | filename = pair->value; | |
| 513 | if (pair->key == 28) | |
| 514 | filesize = atol(pair->value); | |
| 515 | if (pair->key == 49) | |
| 516 | service = pair->value; | |
| 517 | } | |
| 518 | ||
| 519 | if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { | |
| 10261 | 520 | if (service && (strcmp("FILEXFER", service) != 0)) { |
|
13467
f86303a455ae
[gaim-migrate @ 15841]
Richard Laager <rlaager@pidgin.im>
parents:
13459
diff
changeset
|
521 | gaim_debug_misc("yahoo", "unhandled service 0x%02x\n", pkt->service); |
| 7651 | 522 | return; |
| 523 | } | |
| 524 | } | |
| 525 | ||
| 526 | if (msg) { | |
| 527 | char *tmp; | |
| 528 | tmp = strchr(msg, '\006'); | |
| 529 | if (tmp) | |
| 530 | *tmp = '\0'; | |
| 531 | } | |
| 532 | ||
| 533 | if (!url || !from) | |
| 534 | return; | |
| 535 | ||
| 536 | /* Setup the Yahoo-specific file transfer data */ | |
| 537 | xfer_data = g_new0(struct yahoo_xfer_data, 1); | |
| 538 | xfer_data->gc = gc; | |
| 9227 | 539 | if (!gaim_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) { |
| 7651 | 540 | g_free(xfer_data); |
| 541 | return; | |
| 542 | } | |
| 543 | ||
| 544 | gaim_debug_misc("yahoo_filexfer", "Host is %s, port is %d, path is %s, and the full url was %s.\n", | |
| 545 | xfer_data->host, xfer_data->port, xfer_data->path, url); | |
| 546 | ||
| 547 | /* Build the file transfer handle. */ | |
| 548 | xfer = gaim_xfer_new(gc->account, GAIM_XFER_RECEIVE, from); | |
| 549 | xfer->data = xfer_data; | |
| 550 | ||
| 551 | /* Set the info about the incoming file. */ | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
552 | if (filename) { |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
553 | char *utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
554 | gaim_xfer_set_filename(xfer, utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
555 | g_free(utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
556 | } else { |
| 7651 | 557 | gchar *start, *end; |
| 558 | start = g_strrstr(xfer_data->path, "/"); | |
| 559 | if (start) | |
| 560 | start++; | |
| 561 | end = g_strrstr(xfer_data->path, "?"); | |
| 562 | if (start && *start && end) { | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
563 | char *utf8_filename; |
| 7651 | 564 | filename = g_strndup(start, end - start); |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
565 | utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
| 7651 | 566 | g_free(filename); |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
567 | gaim_xfer_set_filename(xfer, utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
568 | g_free(utf8_filename); |
| 7651 | 569 | filename = NULL; |
| 570 | } | |
| 571 | } | |
| 572 | ||
| 573 | gaim_xfer_set_size(xfer, filesize); | |
| 574 | ||
| 575 | /* Setup our I/O op functions */ | |
| 576 | gaim_xfer_set_init_fnc(xfer, yahoo_xfer_init); | |
| 577 | gaim_xfer_set_start_fnc(xfer, yahoo_xfer_start); | |
| 578 | gaim_xfer_set_end_fnc(xfer, yahoo_xfer_end); | |
| 579 | gaim_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); | |
| 580 | gaim_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); | |
| 581 | gaim_xfer_set_read_fnc(xfer, yahoo_xfer_read); | |
| 582 | gaim_xfer_set_write_fnc(xfer, yahoo_xfer_write); | |
| 583 | ||
| 584 | /* Now perform the request */ | |
| 585 | gaim_xfer_request(xfer); | |
| 586 | } | |
| 587 | ||
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
588 | GaimXfer *yahoo_new_xfer(GaimConnection *gc, const char *who) |
| 7651 | 589 | { |
| 590 | GaimXfer *xfer; | |
| 591 | struct yahoo_xfer_data *xfer_data; | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
592 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
593 | g_return_val_if_fail(who != NULL, NULL); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
594 | |
| 7651 | 595 | xfer_data = g_new0(struct yahoo_xfer_data, 1); |
| 596 | xfer_data->gc = gc; | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
597 | |
| 7651 | 598 | /* Build the file transfer handle. */ |
| 599 | xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who); | |
| 600 | xfer->data = xfer_data; | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
601 | |
| 7651 | 602 | /* Setup our I/O op functions */ |
| 603 | gaim_xfer_set_init_fnc(xfer, yahoo_xfer_init); | |
| 604 | gaim_xfer_set_start_fnc(xfer, yahoo_xfer_start); | |
| 605 | gaim_xfer_set_end_fnc(xfer, yahoo_xfer_end); | |
| 606 | gaim_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); | |
| 607 | gaim_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); | |
| 608 | gaim_xfer_set_read_fnc(xfer, yahoo_xfer_read); | |
| 609 | gaim_xfer_set_write_fnc(xfer, yahoo_xfer_write); | |
| 610 | ||
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
611 | return xfer; |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
612 | } |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
613 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
614 | void yahoo_send_file(GaimConnection *gc, const char *who, const char *file) |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
615 | { |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
616 | GaimXfer *xfer = yahoo_new_xfer(gc, who); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
617 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
618 | g_return_if_fail(xfer != NULL); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
619 | |
| 7651 | 620 | /* Now perform the request */ |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
621 | if (file) |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
622 | gaim_xfer_request_accepted(xfer, file); |
|
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
623 | else |
|
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
624 | gaim_xfer_request(xfer); |
| 7651 | 625 | } |