Fri, 09 Sep 2005 04:40:21 +0000
[gaim-migrate @ 13717]
merging gaim-doodle/whiteboard/whatever you like to call it.
Needs some cleanups and doxygen comments, but has basic functionality
| 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 | ||
| 36 | ||
| 37 | struct yahoo_xfer_data { | |
| 38 | gchar *host; | |
| 39 | gchar *path; | |
| 40 | int port; | |
| 41 | GaimConnection *gc; | |
| 42 | long expires; | |
| 43 | gboolean started; | |
| 44 | gchar *rxqueue; | |
| 45 | guint rxlen; | |
| 46 | }; | |
| 47 | ||
| 48 | static void yahoo_xfer_data_free(struct yahoo_xfer_data *xd) | |
| 49 | { | |
| 50 | if (xd->host) | |
| 51 | g_free(xd->host); | |
| 52 | if (xd->path) | |
| 53 | g_free(xd->path); | |
| 54 | g_free(xd); | |
| 55 | } | |
| 56 | ||
| 57 | static void yahoo_receivefile_connected(gpointer data, gint source, GaimInputCondition condition) | |
| 58 | { | |
| 59 | GaimXfer *xfer; | |
| 60 | struct yahoo_xfer_data *xd; | |
| 61 | gchar *buf; | |
| 62 | ||
| 63 | gaim_debug(GAIM_DEBUG_INFO, "yahoo", | |
| 64 | "AAA - in yahoo_receivefile_connected\n"); | |
| 65 | if (!(xfer = data)) | |
| 66 | return; | |
| 67 | if (!(xd = xfer->data)) | |
| 68 | return; | |
| 69 | if (source < 0) { | |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
70 | gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), |
|
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
71 | xfer->who, _("Unable to connect.")); |
| 7805 | 72 | gaim_xfer_cancel_remote(xfer); |
| 7651 | 73 | return; |
| 74 | } | |
| 75 | ||
| 76 | xfer->fd = source; | |
| 77 | gaim_xfer_start(xfer, source, NULL, 0); | |
| 78 | ||
| 10651 | 79 | buf = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n", |
| 80 | xd->path, xd->host); | |
| 7651 | 81 | write(xfer->fd, buf, strlen(buf)); |
| 82 | g_free(buf); | |
| 83 | ||
| 84 | return; | |
| 85 | } | |
| 86 | ||
| 87 | static void yahoo_sendfile_connected(gpointer data, gint source, GaimInputCondition condition) | |
| 88 | { | |
| 89 | GaimXfer *xfer; | |
| 90 | struct yahoo_xfer_data *xd; | |
| 91 | struct yahoo_packet *pkt; | |
| 92 | gchar *size, *post, *buf; | |
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10575
diff
changeset
|
93 | const char *host; |
|
10575
f360d2dc8a1c
[gaim-migrate @ 11968]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
94 | int content_length, port; |
| 7651 | 95 | GaimConnection *gc; |
| 96 | GaimAccount *account; | |
| 97 | struct yahoo_data *yd; | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
98 | char *filename, *encoded_filename; |
| 7651 | 99 | |
| 100 | gaim_debug(GAIM_DEBUG_INFO, "yahoo", | |
| 101 | "AAA - in yahoo_sendfile_connected\n"); | |
| 102 | if (!(xfer = data)) | |
| 103 | return; | |
| 104 | if (!(xd = xfer->data)) | |
| 105 | return; | |
| 106 | ||
| 107 | gc = xd->gc; | |
| 108 | account = gaim_connection_get_account(gc); | |
| 109 | yd = gc->proto_data; | |
| 110 | ||
| 111 | ||
| 112 | ||
| 113 | if (source < 0) { | |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
114 | gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), |
|
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
115 | xfer->who, _("Unable to connect.")); |
| 7805 | 116 | gaim_xfer_cancel_remote(xfer); |
| 7651 | 117 | return; |
| 118 | } | |
| 119 | ||
| 120 | xfer->fd = source; | |
| 121 | gaim_xfer_start(xfer, source, NULL, 0); | |
| 122 | ||
| 123 | ||
| 124 | pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, YAHOO_STATUS_AVAILABLE, yd->session_id); | |
| 125 | ||
| 10111 | 126 | size = g_strdup_printf("%" G_GSIZE_FORMAT, gaim_xfer_get_size(xfer)); |
| 7805 | 127 | filename = g_path_get_basename(gaim_xfer_get_local_filename(xfer)); |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
128 | encoded_filename = yahoo_string_encode(gc, filename, NULL); |
| 10394 | 129 | |
| 130 | yahoo_packet_hash(pkt, "sssss", 0, gaim_connection_get_display_name(gc), | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
131 | 5, xfer->who, 14, "", 27, encoded_filename, 28, size); |
| 7651 | 132 | |
| 133 | content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); | |
| 134 | ||
| 135 | buf = g_strdup_printf("Y=%s; T=%s", yd->cookie_y, yd->cookie_t); | |
| 136 | ||
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10575
diff
changeset
|
137 | host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
|
10575
f360d2dc8a1c
[gaim-migrate @ 11968]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
138 | port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); |
|
f360d2dc8a1c
[gaim-migrate @ 11968]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10394
diff
changeset
|
139 | post = g_strdup_printf("POST http://%s:%d/notifyft HTTP/1.0\r\n" |
| 10111 | 140 | "Content-length: %" G_GSIZE_FORMAT "\r\n" |
| 7651 | 141 | "Host: %s:%d\r\n" |
| 142 | "Cookie: %s\r\n" | |
| 143 | "\r\n", | |
|
10576
ce7a6c585bc6
[gaim-migrate @ 11970]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10575
diff
changeset
|
144 | host, port, content_length + 4 + gaim_xfer_get_size(xfer), host, port, buf); |
| 7651 | 145 | write(xfer->fd, post, strlen(post)); |
| 146 | ||
| 10392 | 147 | yahoo_packet_send_special(pkt, xfer->fd, 8); |
| 7651 | 148 | yahoo_packet_free(pkt); |
| 149 | ||
| 150 | write(xfer->fd, "29\xc0\x80", 4); | |
| 151 | ||
| 152 | g_free(size); | |
| 153 | g_free(post); | |
| 154 | g_free(buf); | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
155 | g_free(encoded_filename); |
| 7805 | 156 | g_free(filename); |
| 7651 | 157 | } |
| 158 | ||
| 159 | static void yahoo_xfer_init(GaimXfer *xfer) | |
| 160 | { | |
| 161 | struct yahoo_xfer_data *xfer_data; | |
| 162 | GaimConnection *gc; | |
| 163 | GaimAccount *account; | |
| 7827 | 164 | struct yahoo_data *yd; |
| 7651 | 165 | |
| 166 | xfer_data = xfer->data; | |
| 167 | gc = xfer_data->gc; | |
| 7827 | 168 | yd = gc->proto_data; |
| 7651 | 169 | account = gaim_connection_get_account(gc); |
| 170 | ||
| 171 | if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) { | |
|
10937
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
172 | if (yd->jp) { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
173 | 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
|
174 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
175 | yahoo_sendfile_connected, xfer) == -1) |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
176 | { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
177 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
178 | _("Unable to establish file descriptor.")); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
179 | gaim_xfer_cancel_remote(xfer); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
180 | } |
| 8282 | 181 | } else { |
|
10937
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
182 | 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
|
183 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
184 | yahoo_sendfile_connected, xfer) == -1) |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
185 | { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
186 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
187 | _("Unable to establish file descriptor.")); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
188 | gaim_xfer_cancel_remote(xfer); |
| 8282 | 189 | } |
| 7651 | 190 | } |
| 191 | } else { | |
| 192 | xfer->fd = gaim_proxy_connect(account, xfer_data->host, xfer_data->port, | |
| 193 | yahoo_receivefile_connected, xfer); | |
| 194 | if (xfer->fd == -1) { | |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
195 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
| 7651 | 196 | _("Unable to establish file descriptor.")); |
| 197 | gaim_xfer_cancel_remote(xfer); | |
| 198 | } | |
| 199 | } | |
| 200 | } | |
| 201 | ||
| 202 | static void yahoo_xfer_start(GaimXfer *xfer) | |
| 203 | { | |
| 204 | /* We don't need to do anything here, do we? */ | |
| 205 | } | |
| 206 | ||
| 207 | static void yahoo_xfer_end(GaimXfer *xfer) | |
| 208 | { | |
| 209 | GaimAccount *account; | |
| 210 | struct yahoo_xfer_data *xfer_data; | |
| 211 | ||
| 212 | account = gaim_xfer_get_account(xfer); | |
| 213 | xfer_data = xfer->data; | |
| 214 | ||
| 215 | ||
| 216 | if (xfer_data) | |
| 217 | yahoo_xfer_data_free(xfer_data); | |
| 218 | xfer->data = NULL; | |
| 219 | ||
| 220 | } | |
| 221 | ||
| 222 | guint calculate_length(const gchar *l, size_t len) | |
| 223 | { | |
| 224 | int i; | |
| 225 | ||
| 226 | for (i = 0; i < len; i++) { | |
| 227 | if (!g_ascii_isdigit(l[i])) | |
| 228 | continue; | |
| 229 | return strtol(l + i, NULL, 10); | |
| 230 | } | |
| 231 | return 0; | |
| 232 | } | |
| 233 | ||
| 234 | ||
|
11159
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10976
diff
changeset
|
235 | ssize_t yahoo_xfer_read(guchar **buffer, GaimXfer *xfer) |
| 7651 | 236 | { |
| 7710 | 237 | gchar buf[4096]; |
| 7682 | 238 | ssize_t len; |
| 7651 | 239 | gchar *start = NULL; |
| 240 | gchar *length; | |
| 241 | gchar *end; | |
| 7710 | 242 | int filelen; |
| 7651 | 243 | struct yahoo_xfer_data *xd = xfer->data; |
| 244 | ||
| 245 | if (gaim_xfer_get_type(xfer) != GAIM_XFER_RECEIVE) { | |
| 246 | return 0; | |
| 247 | } | |
| 248 | ||
| 249 | len = read(xfer->fd, buf, sizeof(buf)); | |
| 250 | ||
| 7682 | 251 | if (len <= 0) { |
| 7710 | 252 | if ((gaim_xfer_get_size(xfer) > 0) && |
| 9798 | 253 | (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer))) { |
| 7682 | 254 | gaim_xfer_set_completed(xfer, TRUE); |
| 9798 | 255 | return 0; |
| 256 | } else | |
| 257 | return -1; | |
| 7651 | 258 | } |
| 259 | ||
| 260 | ||
| 261 | if (!xd->started) { | |
| 262 | xd->rxqueue = g_realloc(xd->rxqueue, len + xd->rxlen); | |
| 263 | memcpy(xd->rxqueue + xd->rxlen, buf, len); | |
| 264 | xd->rxlen += len; | |
| 265 | ||
| 266 | length = g_strstr_len(xd->rxqueue, len, "Content-length:"); | |
|
10579
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
267 | /* some proxies re-write this header, changing the capitalization :( |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
268 | * technically that's allowed since headers are case-insensitive |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
269 | * [RFC 2616, section 4.2] */ |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
270 | if (length == NULL) |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
271 | length = g_strstr_len(xd->rxqueue, len, "Content-Length:"); |
| 7651 | 272 | if (length) { |
| 273 | end = g_strstr_len(length, length - xd->rxqueue, "\r\n"); | |
| 274 | if (!end) | |
| 275 | return 0; | |
| 7710 | 276 | if ((filelen = calculate_length(length, len - (length - xd->rxqueue)))) |
| 277 | gaim_xfer_set_size(xfer, filelen); | |
| 7651 | 278 | } |
| 279 | start = g_strstr_len(xd->rxqueue, len, "\r\n\r\n"); | |
| 280 | if (start) | |
| 281 | start += 4; | |
| 282 | if (!start || start > (xd->rxqueue + len)) | |
| 283 | return 0; | |
| 284 | xd->started = TRUE; | |
| 285 | ||
| 286 | len -= (start - xd->rxqueue); | |
| 287 | ||
| 288 | *buffer = g_malloc(len); | |
| 289 | memcpy(*buffer, start, len); | |
| 290 | g_free(xd->rxqueue); | |
| 291 | xd->rxqueue = NULL; | |
| 292 | xd->rxlen = 0; | |
| 293 | } else { | |
| 294 | *buffer = g_malloc(len); | |
| 295 | memcpy(*buffer, buf, len); | |
| 296 | } | |
| 297 | ||
| 298 | return len; | |
| 299 | } | |
| 300 | ||
|
11159
76ef02141bcb
[gaim-migrate @ 13246]
Mark Doliner <markdoliner@pidgin.im>
parents:
10976
diff
changeset
|
301 | ssize_t yahoo_xfer_write(const guchar *buffer, size_t size, GaimXfer *xfer) |
| 7651 | 302 | { |
| 7710 | 303 | ssize_t len; |
| 7651 | 304 | struct yahoo_xfer_data *xd = xfer->data; |
| 305 | ||
| 306 | if (!xd) | |
| 9798 | 307 | return -1; |
| 7651 | 308 | |
| 309 | if (gaim_xfer_get_type(xfer) != GAIM_XFER_SEND) { | |
| 9798 | 310 | return -1; |
| 7651 | 311 | } |
| 312 | ||
| 313 | len = write(xfer->fd, buffer, size); | |
| 314 | ||
| 7710 | 315 | if (len == -1) { |
| 316 | if (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer)) | |
| 317 | gaim_xfer_set_completed(xfer, TRUE); | |
| 318 | if ((errno != EAGAIN) && (errno != EINTR)) | |
| 9798 | 319 | return -1; |
| 7710 | 320 | return 0; |
| 321 | } | |
| 322 | ||
| 323 | if ((gaim_xfer_get_bytes_sent(xfer) + len) >= gaim_xfer_get_size(xfer)) | |
| 7651 | 324 | gaim_xfer_set_completed(xfer, TRUE); |
| 325 | ||
| 326 | return len; | |
| 327 | } | |
| 328 | ||
| 329 | static void yahoo_xfer_cancel_send(GaimXfer *xfer) | |
| 330 | { | |
| 331 | GaimAccount *account; | |
| 332 | struct yahoo_xfer_data *xfer_data; | |
| 333 | ||
| 334 | xfer_data = xfer->data; | |
| 335 | account = gaim_xfer_get_account(xfer); | |
| 336 | ||
| 337 | if (xfer_data) | |
| 338 | yahoo_xfer_data_free(xfer_data); | |
| 339 | xfer->data = NULL; | |
| 340 | } | |
| 341 | ||
| 342 | static void yahoo_xfer_cancel_recv(GaimXfer *xfer) | |
| 343 | { | |
| 344 | GaimAccount *account; | |
| 345 | struct yahoo_xfer_data *xfer_data; | |
| 346 | ||
| 347 | account = gaim_xfer_get_account(xfer); | |
| 348 | xfer_data = xfer->data; | |
| 349 | ||
| 350 | if (xfer_data) | |
| 351 | yahoo_xfer_data_free(xfer_data); | |
| 352 | xfer->data = NULL; | |
| 353 | } | |
| 354 | ||
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
355 | void yahoo_process_p2pfilexfer( GaimConnection *gc, struct yahoo_packet *pkt ) |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
356 | { |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
357 | GSList *l = pkt->hash; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
358 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
359 | char *me = NULL; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
360 | char *from = NULL; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
361 | char *service = NULL; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
362 | char *message = NULL; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
363 | char *command = NULL; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
364 | char *imv = NULL; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
365 | char *unknown = NULL; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
366 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
367 | // Get all the necessary values from this new packet |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
368 | while( l ) |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
369 | { |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
370 | struct yahoo_pair *pair = l->data; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
371 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
372 | if( pair->key == 5 ) // Get who the packet is for |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
373 | me = pair->value; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
374 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
375 | if( pair->key == 4 ) // Get who the packet is from |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
376 | from = pair->value; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
377 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
378 | if( pair->key == 49 ) // Get the type of service |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
379 | service = pair->value; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
380 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
381 | if( pair->key == 14 ) // Get the 'message' of the packet |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
382 | message = pair->value; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
383 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
384 | if( pair->key == 13 ) // Get the command associated with this packet |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
385 | command = pair->value; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
386 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
387 | if( pair->key == 63 ) // IMVironment name and version |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
388 | imv = pair->value; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
389 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
390 | if( pair->key == 64 ) // Not sure, but it does vary with initialization of Doodle |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
391 | unknown = pair->value; // So, I'll keep it (for a little while atleast) |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
392 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
393 | l = l->next; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
394 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
395 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
396 | // If this packet is an IMVIRONMENT, handle it accordingly |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
397 | if( !strcmp( service, "IMVIRONMENT" ) ) |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
398 | { |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
399 | // Check for a Doodle packet and handle it accordingly |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
400 | if( !strcmp( imv, "doodle;11" ) ) |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
401 | yahoo_doodle_process( gc, me, from, command, message ); |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
402 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
403 | // If an IMVIRONMENT packet comes without a specific imviroment name |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
404 | if( !strcmp( imv, ";0" ) ) |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
405 | { |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
406 | // It is unfortunately time to close all IMVironments with remote client |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
407 | yahoo_doodle_command_got_shutdown( gc, from ); |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
408 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
409 | |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
410 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
411 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
412 | |
| 7651 | 413 | void yahoo_process_filetransfer(GaimConnection *gc, struct yahoo_packet *pkt) |
| 414 | { | |
| 415 | char *from = NULL; | |
| 416 | char *to = NULL; | |
| 417 | char *msg = NULL; | |
| 418 | char *url = NULL; | |
| 419 | long expires = 0; | |
| 420 | GaimXfer *xfer; | |
| 421 | struct yahoo_xfer_data *xfer_data; | |
| 422 | ||
| 423 | char *service = NULL; | |
| 424 | ||
| 425 | char *filename = NULL; | |
| 426 | unsigned long filesize = 0L; | |
| 427 | ||
| 428 | GSList *l; | |
| 429 | ||
| 430 | for (l = pkt->hash; l; l = l->next) { | |
| 431 | struct yahoo_pair *pair = l->data; | |
| 432 | ||
| 433 | if (pair->key == 4) | |
| 434 | from = pair->value; | |
| 435 | if (pair->key == 5) | |
| 436 | to = pair->value; | |
| 437 | if (pair->key == 14) | |
| 438 | msg = pair->value; | |
| 439 | if (pair->key == 20) | |
| 440 | url = pair->value; | |
| 441 | if (pair->key == 38) | |
| 442 | expires = strtol(pair->value, NULL, 10); | |
| 443 | ||
| 444 | if (pair->key == 27) | |
| 445 | filename = pair->value; | |
| 446 | if (pair->key == 28) | |
| 447 | filesize = atol(pair->value); | |
| 448 | ||
| 449 | if (pair->key == 49) | |
| 450 | service = pair->value; | |
| 451 | } | |
| 452 | ||
| 453 | if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { | |
| 10261 | 454 | if (service && (strcmp("FILEXFER", service) != 0)) { |
| 7651 | 455 | gaim_debug_misc("yahoo", "unhandled service 0x%02x", pkt->service); |
| 456 | return; | |
| 457 | } | |
| 458 | } | |
| 459 | ||
| 460 | if (msg) { | |
| 461 | char *tmp; | |
| 462 | tmp = strchr(msg, '\006'); | |
| 463 | if (tmp) | |
| 464 | *tmp = '\0'; | |
| 465 | } | |
| 466 | ||
| 467 | if (!url || !from) | |
| 468 | return; | |
| 469 | ||
| 470 | ||
| 471 | /* Setup the Yahoo-specific file transfer data */ | |
| 472 | xfer_data = g_new0(struct yahoo_xfer_data, 1); | |
| 473 | xfer_data->gc = gc; | |
| 9227 | 474 | if (!gaim_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) { |
| 7651 | 475 | g_free(xfer_data); |
| 476 | return; | |
| 477 | } | |
| 478 | ||
| 479 | gaim_debug_misc("yahoo_filexfer", "Host is %s, port is %d, path is %s, and the full url was %s.\n", | |
| 480 | xfer_data->host, xfer_data->port, xfer_data->path, url); | |
| 481 | ||
| 482 | /* Build the file transfer handle. */ | |
| 483 | xfer = gaim_xfer_new(gc->account, GAIM_XFER_RECEIVE, from); | |
| 484 | xfer->data = xfer_data; | |
| 485 | ||
| 486 | /* Set the info about the incoming file. */ | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
487 | if (filename) { |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
488 | char *utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
489 | gaim_xfer_set_filename(xfer, utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
490 | g_free(utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
491 | } else { |
| 7651 | 492 | gchar *start, *end; |
| 493 | start = g_strrstr(xfer_data->path, "/"); | |
| 494 | if (start) | |
| 495 | start++; | |
| 496 | end = g_strrstr(xfer_data->path, "?"); | |
| 497 | if (start && *start && end) { | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
498 | char *utf8_filename; |
| 7651 | 499 | filename = g_strndup(start, end - start); |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
500 | utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
| 7651 | 501 | g_free(filename); |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
502 | gaim_xfer_set_filename(xfer, utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
503 | g_free(utf8_filename); |
| 7651 | 504 | filename = NULL; |
| 505 | } | |
| 506 | } | |
| 507 | ||
| 508 | gaim_xfer_set_size(xfer, filesize); | |
| 509 | ||
| 510 | /* Setup our I/O op functions */ | |
| 511 | gaim_xfer_set_init_fnc(xfer, yahoo_xfer_init); | |
| 512 | gaim_xfer_set_start_fnc(xfer, yahoo_xfer_start); | |
| 513 | gaim_xfer_set_end_fnc(xfer, yahoo_xfer_end); | |
| 514 | gaim_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); | |
| 515 | gaim_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); | |
| 516 | gaim_xfer_set_read_fnc(xfer, yahoo_xfer_read); | |
| 517 | gaim_xfer_set_write_fnc(xfer, yahoo_xfer_write); | |
| 518 | ||
| 519 | /* Now perform the request */ | |
| 520 | gaim_xfer_request(xfer); | |
| 521 | } | |
| 522 | ||
| 523 | void yahoo_send_file(GaimConnection *gc, const char *who, const char *file) | |
| 524 | { | |
| 525 | GaimXfer *xfer; | |
| 526 | struct yahoo_xfer_data *xfer_data; | |
| 527 | ||
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
528 | if (!who) |
| 7651 | 529 | return; |
| 530 | ||
| 531 | xfer_data = g_new0(struct yahoo_xfer_data, 1); | |
| 532 | xfer_data->gc = gc; | |
| 533 | ||
| 534 | ||
| 535 | /* Build the file transfer handle. */ | |
| 536 | xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who); | |
| 537 | xfer->data = xfer_data; | |
| 538 | ||
| 539 | /* Setup our I/O op functions */ | |
| 540 | gaim_xfer_set_init_fnc(xfer, yahoo_xfer_init); | |
| 541 | gaim_xfer_set_start_fnc(xfer, yahoo_xfer_start); | |
| 542 | gaim_xfer_set_end_fnc(xfer, yahoo_xfer_end); | |
| 543 | gaim_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); | |
| 544 | gaim_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); | |
| 545 | gaim_xfer_set_read_fnc(xfer, yahoo_xfer_read); | |
| 546 | gaim_xfer_set_write_fnc(xfer, yahoo_xfer_write); | |
| 547 | ||
| 548 | /* Now perform the request */ | |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
549 | if (file) |
|
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
550 | gaim_xfer_request_accepted(xfer, file); |
|
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
551 | else |
|
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
552 | gaim_xfer_request(xfer); |
| 7651 | 553 | } |