Mercurial > pidgin
comparison libpurple/protocols/yahoo/yahoo_filexfer.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | 5bd5e024c977 |
children |
comparison
equal
deleted
inserted
replaced
32818:01ff09d4a463 | 32819:2c6510167895 |
---|---|
41 gchar *path; | 41 gchar *path; |
42 int port; | 42 int port; |
43 PurpleConnection *gc; | 43 PurpleConnection *gc; |
44 long expires; | 44 long expires; |
45 gboolean started; | 45 gboolean started; |
46 gchar *txbuf; | 46 guchar *txbuf; |
47 gsize txbuflen; | 47 gsize txbuflen; |
48 gsize txbuf_written; | 48 gsize txbuf_written; |
49 guint tx_handler; | 49 guint tx_handler; |
50 gchar *rxqueue; | 50 gchar *rxqueue; |
51 guint rxlen; | 51 guint rxlen; |
83 YahooData *yd; | 83 YahooData *yd; |
84 PurpleXfer *xfer; | 84 PurpleXfer *xfer; |
85 GSList *l; | 85 GSList *l; |
86 | 86 |
87 gc = xd->gc; | 87 gc = xd->gc; |
88 yd = gc->proto_data; | 88 yd = purple_connection_get_protocol_data(gc); |
89 | 89 |
90 /* remove entry from map */ | 90 /* remove entry from map */ |
91 if(xd->xfer_peer_idstring) { | 91 if(xd->xfer_peer_idstring) { |
92 xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xd->xfer_peer_idstring); | 92 xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xd->xfer_peer_idstring); |
93 if(xfer) | 93 if(xfer) |
118 | 118 |
119 static void yahoo_receivefile_send_cb(gpointer data, gint source, PurpleInputCondition condition) | 119 static void yahoo_receivefile_send_cb(gpointer data, gint source, PurpleInputCondition condition) |
120 { | 120 { |
121 PurpleXfer *xfer; | 121 PurpleXfer *xfer; |
122 struct yahoo_xfer_data *xd; | 122 struct yahoo_xfer_data *xd; |
123 int remaining, written; | 123 gssize remaining, written; |
124 | 124 |
125 xfer = data; | 125 xfer = data; |
126 xd = xfer->data; | 126 xd = purple_xfer_get_protocol_data(xfer); |
127 | 127 |
128 remaining = xd->txbuflen - xd->txbuf_written; | 128 remaining = xd->txbuflen - xd->txbuf_written; |
129 written = write(xfer->fd, xd->txbuf + xd->txbuf_written, remaining); | 129 written = purple_xfer_write(xfer, xd->txbuf + xd->txbuf_written, remaining); |
130 | 130 |
131 if (written < 0 && errno == EAGAIN) | 131 if (written < 0 && errno == EAGAIN) |
132 written = 0; | 132 written = 0; |
133 else if (written <= 0) { | 133 else if (written <= 0) { |
134 purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); | 134 purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); |
158 | 158 |
159 purple_debug_info("yahoo", "in yahoo_receivefile_connected\n"); | 159 purple_debug_info("yahoo", "in yahoo_receivefile_connected\n"); |
160 | 160 |
161 if (!(xfer = data)) | 161 if (!(xfer = data)) |
162 return; | 162 return; |
163 if (!(xd = xfer->data)) | 163 if (!(xd = purple_xfer_get_protocol_data(xfer))) |
164 return; | 164 return; |
165 if ((source < 0) || (xd->path == NULL) || (xd->host == NULL)) { | 165 if ((source < 0) || (xd->path == NULL) || (xd->host == NULL)) { |
166 purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), | 166 purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), |
167 xfer->who, _("Unable to connect.")); | 167 purple_xfer_get_remote_user(xfer), _("Unable to connect.")); |
168 purple_xfer_cancel_remote(xfer); | 168 purple_xfer_cancel_remote(xfer); |
169 return; | 169 return; |
170 } | 170 } |
171 | 171 |
172 xfer->fd = source; | 172 purple_xfer_set_fd(xfer, source); |
173 | 173 |
174 /* The first time we get here, assemble the tx buffer */ | 174 /* The first time we get here, assemble the tx buffer */ |
175 if (xd->txbuflen == 0) { | 175 if (xd->txbuflen == 0) { |
176 xd->txbuf = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n", | 176 gchar *header = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n", |
177 xd->path, xd->host); | 177 xd->path, xd->host); |
178 xd->txbuflen = strlen(xd->txbuf); | 178 xd->txbuf = (guchar*) header; |
179 xd->txbuflen = strlen(header); | |
179 xd->txbuf_written = 0; | 180 xd->txbuf_written = 0; |
180 } | 181 } |
181 | 182 |
182 if (!xd->tx_handler) | 183 if (!xd->tx_handler) |
183 { | 184 { |
189 | 190 |
190 static void yahoo_sendfile_send_cb(gpointer data, gint source, PurpleInputCondition condition) | 191 static void yahoo_sendfile_send_cb(gpointer data, gint source, PurpleInputCondition condition) |
191 { | 192 { |
192 PurpleXfer *xfer; | 193 PurpleXfer *xfer; |
193 struct yahoo_xfer_data *xd; | 194 struct yahoo_xfer_data *xd; |
194 int written, remaining; | 195 gssize written, remaining; |
195 | 196 |
196 xfer = data; | 197 xfer = data; |
197 xd = xfer->data; | 198 xd = purple_xfer_get_protocol_data(xfer); |
198 | 199 |
199 remaining = xd->txbuflen - xd->txbuf_written; | 200 remaining = xd->txbuflen - xd->txbuf_written; |
200 written = write(xfer->fd, xd->txbuf + xd->txbuf_written, remaining); | 201 written = purple_xfer_write(xfer, xd->txbuf + xd->txbuf_written, remaining); |
201 | 202 |
202 if (written < 0 && errno == EAGAIN) | 203 if (written < 0 && errno == EAGAIN) |
203 written = 0; | 204 written = 0; |
204 else if (written <= 0) { | 205 else if (written <= 0) { |
205 purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); | 206 purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); |
237 | 238 |
238 purple_debug_info("yahoo", "in yahoo_sendfile_connected\n"); | 239 purple_debug_info("yahoo", "in yahoo_sendfile_connected\n"); |
239 | 240 |
240 if (!(xfer = data)) | 241 if (!(xfer = data)) |
241 return; | 242 return; |
242 if (!(xd = xfer->data)) | 243 if (!(xd = purple_xfer_get_protocol_data(xfer))) |
243 return; | 244 return; |
244 | 245 |
245 if (source < 0) { | 246 if (source < 0) { |
246 purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), | 247 purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), |
247 xfer->who, _("Unable to connect.")); | 248 purple_xfer_get_remote_user(xfer), _("Unable to connect.")); |
248 purple_xfer_cancel_remote(xfer); | 249 purple_xfer_cancel_remote(xfer); |
249 return; | 250 return; |
250 } | 251 } |
251 | 252 |
252 xfer->fd = source; | 253 purple_xfer_set_fd(xfer, source); |
253 | 254 |
254 /* Assemble the tx buffer */ | 255 /* Assemble the tx buffer */ |
255 gc = xd->gc; | 256 gc = xd->gc; |
256 account = purple_connection_get_account(gc); | 257 account = purple_connection_get_account(gc); |
257 yd = gc->proto_data; | 258 yd = purple_connection_get_protocol_data(gc); |
258 | 259 |
259 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, | 260 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, |
260 YAHOO_STATUS_AVAILABLE, yd->session_id); | 261 YAHOO_STATUS_AVAILABLE, yd->session_id); |
261 | 262 |
262 size = g_strdup_printf("%" G_GSIZE_FORMAT, purple_xfer_get_size(xfer)); | 263 size = g_strdup_printf("%" G_GOFFSET_FORMAT, purple_xfer_get_size(xfer)); |
263 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); | 264 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); |
264 encoded_filename = yahoo_string_encode(gc, filename, NULL); | 265 encoded_filename = yahoo_string_encode(gc, filename, NULL); |
265 | 266 |
266 yahoo_packet_hash(pkt, "sssss", 0, purple_connection_get_display_name(gc), | 267 yahoo_packet_hash(pkt, "sssss", 0, purple_connection_get_display_name(gc), |
267 5, xfer->who, 14, "", 27, encoded_filename, 28, size); | 268 5, purple_xfer_get_remote_user(xfer), 14, "", 27, encoded_filename, 28, size); |
268 g_free(size); | 269 g_free(size); |
269 g_free(encoded_filename); | 270 g_free(encoded_filename); |
270 g_free(filename); | 271 g_free(filename); |
271 | 272 |
272 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); | 273 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); |
276 | 277 |
277 host = purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); | 278 host = purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
278 port = purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); | 279 port = purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); |
279 header = g_strdup_printf( | 280 header = g_strdup_printf( |
280 "POST http://%s:%d/notifyft HTTP/1.0\r\n" | 281 "POST http://%s:%d/notifyft HTTP/1.0\r\n" |
281 "Content-length: %" G_GSIZE_FORMAT "\r\n" | 282 "Content-length: %" G_GOFFSET_FORMAT "\r\n" |
282 "Host: %s:%d\r\n" | 283 "Host: %s:%d\r\n" |
283 "Cookie: Y=%s; T=%s\r\n" | 284 "Cookie: Y=%s; T=%s\r\n" |
284 "\r\n", | 285 "\r\n", |
285 host, port, content_length + 4 + purple_xfer_get_size(xfer), | 286 host, port, content_length + 4 + purple_xfer_get_size(xfer), |
286 host, port, yd->cookie_y, yd->cookie_t); | 287 host, port, yd->cookie_y, yd->cookie_t); |
311 struct yahoo_xfer_data *xfer_data; | 312 struct yahoo_xfer_data *xfer_data; |
312 PurpleConnection *gc; | 313 PurpleConnection *gc; |
313 PurpleAccount *account; | 314 PurpleAccount *account; |
314 YahooData *yd; | 315 YahooData *yd; |
315 | 316 |
316 xfer_data = xfer->data; | 317 xfer_data = purple_xfer_get_protocol_data(xfer); |
317 gc = xfer_data->gc; | 318 gc = xfer_data->gc; |
318 yd = gc->proto_data; | 319 yd = purple_connection_get_protocol_data(gc); |
319 account = purple_connection_get_account(gc); | 320 account = purple_connection_get_account(gc); |
320 | 321 |
321 if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { | 322 if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { |
322 if (yd->jp) { | 323 if (yd->jp) { |
323 if (purple_proxy_connect(gc, account, purple_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), | 324 if (purple_proxy_connect(gc, account, purple_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), |
337 _("Unable to establish file descriptor.")); | 338 _("Unable to establish file descriptor.")); |
338 purple_xfer_cancel_remote(xfer); | 339 purple_xfer_cancel_remote(xfer); |
339 } | 340 } |
340 } | 341 } |
341 } else { | 342 } else { |
342 xfer->fd = -1; | 343 purple_xfer_set_fd(xfer, -1); |
343 if (purple_proxy_connect(gc, account, xfer_data->host, xfer_data->port, | 344 if (purple_proxy_connect(gc, account, xfer_data->host, xfer_data->port, |
344 yahoo_receivefile_connected, xfer) == NULL) { | 345 yahoo_receivefile_connected, xfer) == NULL) { |
345 purple_notify_error(gc, NULL, _("File Transfer Failed"), | 346 purple_notify_error(gc, NULL, _("File Transfer Failed"), |
346 _("Unable to establish file descriptor.")); | 347 _("Unable to establish file descriptor.")); |
347 purple_xfer_cancel_remote(xfer); | 348 purple_xfer_cancel_remote(xfer); |
355 PurpleConnection *gc; | 356 PurpleConnection *gc; |
356 PurpleAccount *account; | 357 PurpleAccount *account; |
357 YahooData *yd; | 358 YahooData *yd; |
358 struct yahoo_packet *pkt; | 359 struct yahoo_packet *pkt; |
359 | 360 |
360 xfer_data = xfer->data; | 361 xfer_data = purple_xfer_get_protocol_data(xfer); |
361 gc = xfer_data->gc; | 362 gc = xfer_data->gc; |
362 yd = gc->proto_data; | 363 yd = purple_connection_get_protocol_data(gc); |
363 account = purple_connection_get_account(gc); | 364 account = purple_connection_get_account(gc); |
364 | 365 |
365 if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { | 366 if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { |
366 gchar *filename; | 367 gchar *filename; |
367 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); | 368 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); |
368 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, | 369 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, |
369 YAHOO_STATUS_AVAILABLE, | 370 YAHOO_STATUS_AVAILABLE, |
370 yd->session_id); | 371 yd->session_id); |
371 yahoo_packet_hash(pkt, "sssiiiisiii", | 372 yahoo_packet_hash(pkt, "sssiiiisiii", |
372 1, purple_normalize(account, purple_account_get_username(account)), | 373 1, purple_normalize(account, purple_account_get_username(account)), |
373 5, xfer->who, | 374 5, purple_xfer_get_remote_user(xfer), |
374 265, xfer_data->xfer_peer_idstring, | 375 265, xfer_data->xfer_peer_idstring, |
375 222, 1, | 376 222, 1, |
376 266, 1, | 377 266, 1, |
377 302, 268, | 378 302, 268, |
378 300, 268, | 379 300, 268, |
379 27, filename, | 380 27, filename, |
380 28, xfer->size, | 381 28, (int)purple_xfer_get_size(xfer), |
381 301, 268, | 382 301, 268, |
382 303, 268); | 383 303, 268); |
383 g_free(filename); | 384 g_free(filename); |
384 } else { | 385 } else { |
385 if(xfer_data->firstoflist == TRUE) { | 386 if(xfer_data->firstoflist == TRUE) { |
386 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, | 387 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, |
387 YAHOO_STATUS_AVAILABLE, yd->session_id); | 388 YAHOO_STATUS_AVAILABLE, yd->session_id); |
388 | 389 |
389 yahoo_packet_hash(pkt, "sssi", | 390 yahoo_packet_hash(pkt, "sssi", |
390 1, purple_normalize(account, purple_account_get_username(account)), | 391 1, purple_normalize(account, purple_account_get_username(account)), |
391 5, xfer->who, | 392 5, purple_xfer_get_remote_user(xfer), |
392 265, xfer_data->xfer_peer_idstring, | 393 265, xfer_data->xfer_peer_idstring, |
393 222, 3); | 394 222, 3); |
394 } else { | 395 } else { |
395 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15, | 396 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15, |
396 YAHOO_STATUS_AVAILABLE, yd->session_id); | 397 YAHOO_STATUS_AVAILABLE, yd->session_id); |
397 | 398 |
398 yahoo_packet_hash(pkt, "sssi", | 399 yahoo_packet_hash(pkt, "sssi", |
399 1, purple_normalize(account, purple_account_get_username(account)), | 400 1, purple_normalize(account, purple_account_get_username(account)), |
400 5, xfer->who, | 401 5, purple_xfer_get_remote_user(xfer), |
401 265, xfer_data->xfer_peer_idstring, | 402 265, xfer_data->xfer_peer_idstring, |
402 271, 1); | 403 271, 1); |
403 } | 404 } |
404 } | 405 } |
405 yahoo_packet_send_and_free(pkt, yd); | 406 yahoo_packet_send_and_free(pkt, yd); |
408 static void yahoo_xfer_start(PurpleXfer *xfer) | 409 static void yahoo_xfer_start(PurpleXfer *xfer) |
409 { | 410 { |
410 /* We don't need to do anything here, do we? */ | 411 /* We don't need to do anything here, do we? */ |
411 } | 412 } |
412 | 413 |
413 static guint calculate_length(const gchar *l, size_t len) | 414 static goffset calculate_length(const gchar *l, size_t len) |
414 { | 415 { |
415 int i; | 416 int i; |
416 | 417 |
417 for (i = 0; i < len; i++) { | 418 for (i = 0; i < len; i++) { |
418 if (!g_ascii_isdigit(l[i])) | 419 if (!g_ascii_isdigit(l[i])) |
419 continue; | 420 continue; |
420 return strtol(l + i, NULL, 10); | 421 return g_ascii_strtoll(l + i, NULL, 10); |
421 } | 422 } |
422 return 0; | 423 return 0; |
423 } | 424 } |
424 | 425 |
425 static gssize yahoo_xfer_read(guchar **buffer, PurpleXfer *xfer) | 426 static gssize yahoo_xfer_read(guchar **buffer, PurpleXfer *xfer) |
427 gchar buf[4096]; | 428 gchar buf[4096]; |
428 gssize len; | 429 gssize len; |
429 gchar *start = NULL; | 430 gchar *start = NULL; |
430 gchar *length; | 431 gchar *length; |
431 gchar *end; | 432 gchar *end; |
432 int filelen; | 433 goffset filelen; |
433 struct yahoo_xfer_data *xd = xfer->data; | 434 struct yahoo_xfer_data *xd = purple_xfer_get_protocol_data(xfer); |
434 | 435 |
435 if (purple_xfer_get_type(xfer) != PURPLE_XFER_RECEIVE) { | 436 if (purple_xfer_get_type(xfer) != PURPLE_XFER_RECEIVE) { |
436 return 0; | 437 return 0; |
437 } | 438 } |
438 | 439 |
439 len = read(xfer->fd, buf, sizeof(buf)); | 440 len = read(purple_xfer_get_fd(xfer), buf, sizeof(buf)); |
440 | 441 |
441 if (len <= 0) { | 442 if (len <= 0) { |
442 if ((purple_xfer_get_size(xfer) > 0) && | 443 if ((purple_xfer_get_size(xfer) > 0) && |
443 (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer))) { | 444 (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer))) { |
444 purple_xfer_set_completed(xfer, TRUE); | 445 purple_xfer_set_completed(xfer, TRUE); |
488 } | 489 } |
489 | 490 |
490 static gssize yahoo_xfer_write(const guchar *buffer, size_t size, PurpleXfer *xfer) | 491 static gssize yahoo_xfer_write(const guchar *buffer, size_t size, PurpleXfer *xfer) |
491 { | 492 { |
492 gssize len; | 493 gssize len; |
493 struct yahoo_xfer_data *xd = xfer->data; | 494 struct yahoo_xfer_data *xd = purple_xfer_get_protocol_data(xfer); |
494 | 495 |
495 if (!xd) | 496 if (!xd) |
496 return -1; | 497 return -1; |
497 | 498 |
498 if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) { | 499 if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) { |
499 return -1; | 500 return -1; |
500 } | 501 } |
501 | 502 |
502 len = write(xfer->fd, buffer, size); | 503 len = write(purple_xfer_get_fd(xfer), buffer, size); |
503 | 504 |
504 if (len == -1) { | 505 if (len == -1) { |
505 if (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer)) | 506 if (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer)) |
506 purple_xfer_set_completed(xfer, TRUE); | 507 purple_xfer_set_completed(xfer, TRUE); |
507 if ((errno != EAGAIN) && (errno != EINTR)) | 508 if ((errno != EAGAIN) && (errno != EINTR)) |
514 | 515 |
515 static void yahoo_xfer_cancel_send(PurpleXfer *xfer) | 516 static void yahoo_xfer_cancel_send(PurpleXfer *xfer) |
516 { | 517 { |
517 struct yahoo_xfer_data *xfer_data; | 518 struct yahoo_xfer_data *xfer_data; |
518 | 519 |
519 xfer_data = xfer->data; | 520 xfer_data = purple_xfer_get_protocol_data(xfer); |
520 | 521 |
521 if(purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL && xfer_data->version == 15) | 522 if(purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL && xfer_data->version == 15) |
522 { | 523 { |
523 PurpleConnection *gc; | 524 PurpleConnection *gc; |
524 PurpleAccount *account; | 525 PurpleAccount *account; |
525 YahooData *yd; | 526 YahooData *yd; |
526 struct yahoo_packet *pkt; | 527 struct yahoo_packet *pkt; |
527 | 528 |
528 gc = xfer_data->gc; | 529 gc = xfer_data->gc; |
529 yd = gc->proto_data; | 530 yd = purple_connection_get_protocol_data(gc); |
530 account = purple_connection_get_account(gc); | 531 account = purple_connection_get_account(gc); |
531 if(xfer_data->xfer_idstring_for_relay) /* hack to see if file trans acc/info packet has been received */ | 532 if(xfer_data->xfer_idstring_for_relay) /* hack to see if file trans acc/info packet has been received */ |
532 { | 533 { |
533 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, | 534 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, |
534 YAHOO_STATUS_DISCONNECTED, | 535 YAHOO_STATUS_DISCONNECTED, |
535 yd->session_id); | 536 yd->session_id); |
536 yahoo_packet_hash(pkt, "sssi", | 537 yahoo_packet_hash(pkt, "sssi", |
537 1, purple_normalize(account, purple_account_get_username(account)), | 538 1, purple_normalize(account, purple_account_get_username(account)), |
538 5, xfer->who, | 539 5, purple_xfer_get_remote_user(xfer), |
539 265, xfer_data->xfer_peer_idstring, | 540 265, xfer_data->xfer_peer_idstring, |
540 66, -1); | 541 66, -1); |
541 } | 542 } |
542 else | 543 else |
543 { | 544 { |
544 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, | 545 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, |
545 YAHOO_STATUS_AVAILABLE, | 546 YAHOO_STATUS_AVAILABLE, |
546 yd->session_id); | 547 yd->session_id); |
547 yahoo_packet_hash(pkt, "sssi", | 548 yahoo_packet_hash(pkt, "sssi", |
548 1, purple_normalize(account, purple_account_get_username(account)), | 549 1, purple_normalize(account, purple_account_get_username(account)), |
549 5, xfer->who, | 550 5, purple_xfer_get_remote_user(xfer), |
550 265, xfer_data->xfer_peer_idstring, | 551 265, xfer_data->xfer_peer_idstring, |
551 222, 2); | 552 222, 2); |
552 } | 553 } |
553 yahoo_packet_send_and_free(pkt, yd); | 554 yahoo_packet_send_and_free(pkt, yd); |
554 } | 555 } |
555 | 556 |
556 | 557 |
557 if (xfer_data) | 558 if (xfer_data) |
558 yahoo_xfer_data_free(xfer_data); | 559 yahoo_xfer_data_free(xfer_data); |
559 xfer->data = NULL; | 560 purple_xfer_set_protocol_data(xfer, NULL); |
560 } | 561 } |
561 | 562 |
562 static void yahoo_xfer_cancel_recv(PurpleXfer *xfer) | 563 static void yahoo_xfer_cancel_recv(PurpleXfer *xfer) |
563 { | 564 { |
564 struct yahoo_xfer_data *xfer_data; | 565 struct yahoo_xfer_data *xfer_data; |
565 | 566 |
566 xfer_data = xfer->data; | 567 xfer_data = purple_xfer_get_protocol_data(xfer); |
567 | 568 |
568 if(purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL && xfer_data->version == 15) | 569 if(purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL && xfer_data->version == 15) |
569 { | 570 { |
570 | 571 |
571 PurpleConnection *gc; | 572 PurpleConnection *gc; |
572 PurpleAccount *account; | 573 PurpleAccount *account; |
573 YahooData *yd; | 574 YahooData *yd; |
574 struct yahoo_packet *pkt; | 575 struct yahoo_packet *pkt; |
575 | 576 |
576 gc = xfer_data->gc; | 577 gc = xfer_data->gc; |
577 yd = gc->proto_data; | 578 yd = purple_connection_get_protocol_data(gc); |
578 account = purple_connection_get_account(gc); | 579 account = purple_connection_get_account(gc); |
579 if(!xfer_data->xfer_idstring_for_relay) /* hack to see if file trans acc/info packet has been received */ | 580 if(!xfer_data->xfer_idstring_for_relay) /* hack to see if file trans acc/info packet has been received */ |
580 { | 581 { |
581 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, | 582 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, |
582 YAHOO_STATUS_AVAILABLE, | 583 YAHOO_STATUS_AVAILABLE, |
583 yd->session_id); | 584 yd->session_id); |
584 yahoo_packet_hash(pkt, "sssi", | 585 yahoo_packet_hash(pkt, "sssi", |
585 1, purple_normalize(account, purple_account_get_username(account)), | 586 1, purple_normalize(account, purple_account_get_username(account)), |
586 5, xfer->who, | 587 5, purple_xfer_get_remote_user(xfer), |
587 265, xfer_data->xfer_peer_idstring, | 588 265, xfer_data->xfer_peer_idstring, |
588 222, 4); | 589 222, 4); |
589 } | 590 } |
590 else | 591 else |
591 { | 592 { |
592 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, | 593 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, |
593 YAHOO_STATUS_DISCONNECTED, | 594 YAHOO_STATUS_DISCONNECTED, |
594 yd->session_id); | 595 yd->session_id); |
595 yahoo_packet_hash(pkt, "sssi", | 596 yahoo_packet_hash(pkt, "sssi", |
596 1, purple_normalize(account, purple_account_get_username(account)), | 597 1, purple_normalize(account, purple_account_get_username(account)), |
597 5, xfer->who, | 598 5, purple_xfer_get_remote_user(xfer), |
598 265, xfer_data->xfer_peer_idstring, | 599 265, xfer_data->xfer_peer_idstring, |
599 66, -1); | 600 66, -1); |
600 } | 601 } |
601 yahoo_packet_send_and_free(pkt, yd); | 602 yahoo_packet_send_and_free(pkt, yd); |
602 } | 603 } |
603 | 604 |
604 if (xfer_data) | 605 if (xfer_data) |
605 yahoo_xfer_data_free(xfer_data); | 606 yahoo_xfer_data_free(xfer_data); |
606 xfer->data = NULL; | 607 purple_xfer_set_protocol_data(xfer, NULL); |
607 } | 608 } |
608 | 609 |
609 /* Send HTTP OK after receiving file */ | 610 /* Send HTTP OK after receiving file */ |
610 static void yahoo_p2p_ft_server_send_OK(PurpleXfer *xfer) | 611 static void yahoo_p2p_ft_server_send_OK(PurpleXfer *xfer) |
611 { | 612 { |
612 char *tx = NULL; | 613 char *tx = NULL; |
613 int written; | 614 int written; |
614 | 615 int fd = purple_xfer_get_fd(xfer); |
615 tx = g_strdup_printf("HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: application/octet-stream\r\nConnection: close\r\n\r\n"); | 616 |
616 written = write(xfer->fd, tx, strlen(tx)); | 617 tx = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: application/octet-stream\r\nConnection: close\r\n\r\n"; |
618 written = write(fd, tx, strlen(tx)); | |
617 | 619 |
618 if (written < 0 && errno == EAGAIN) | 620 if (written < 0 && errno == EAGAIN) |
619 written = 0; | 621 written = 0; |
620 else if (written <= 0) | 622 else if (written <= 0) |
621 purple_debug_info("yahoo", "p2p filetransfer: Unable to write HTTP OK"); | 623 purple_debug_info("yahoo", "p2p filetransfer: Unable to write HTTP OK"); |
622 | 624 |
623 /* close connection */ | 625 /* close connection */ |
624 close(xfer->fd); | 626 close(fd); |
625 xfer->fd = -1; | 627 purple_xfer_set_fd(xfer, -1); |
626 g_free(tx); | |
627 } | 628 } |
628 | 629 |
629 static void yahoo_xfer_end(PurpleXfer *xfer_old) | 630 static void yahoo_xfer_end(PurpleXfer *xfer_old) |
630 { | 631 { |
631 struct yahoo_xfer_data *xfer_data; | 632 struct yahoo_xfer_data *xfer_data; |
632 PurpleXfer *xfer = NULL; | 633 PurpleXfer *xfer = NULL; |
633 PurpleConnection *gc; | 634 PurpleConnection *gc; |
634 YahooData *yd; | 635 YahooData *yd; |
635 | 636 |
636 xfer_data = xfer_old->data; | 637 xfer_data = purple_xfer_get_protocol_data(xfer_old); |
637 if(xfer_data && xfer_data->version == 15 | 638 if(xfer_data && xfer_data->version == 15 |
638 && purple_xfer_get_type(xfer_old) == PURPLE_XFER_RECEIVE | 639 && purple_xfer_get_type(xfer_old) == PURPLE_XFER_RECEIVE |
639 && xfer_data->filename_list) { | 640 && xfer_data->filename_list) { |
640 | 641 |
641 /* Send HTTP OK in case of p2p transfer, when we act as server */ | 642 /* Send HTTP OK in case of p2p transfer, when we act as server */ |
642 if((xfer_data->xfer_url != NULL) && (xfer_old->fd >=0) && (purple_xfer_get_status(xfer_old) == PURPLE_XFER_STATUS_DONE)) | 643 if((xfer_data->xfer_url != NULL) && (purple_xfer_get_fd(xfer_old) >=0) && (purple_xfer_get_status(xfer_old) == PURPLE_XFER_STATUS_DONE)) |
643 yahoo_p2p_ft_server_send_OK(xfer_old); | 644 yahoo_p2p_ft_server_send_OK(xfer_old); |
644 | 645 |
645 /* removing top of filename & size list completely */ | 646 /* removing top of filename & size list completely */ |
646 g_free( xfer_data->filename_list->data ); | 647 g_free( xfer_data->filename_list->data ); |
647 g_free( xfer_data->size_list->data ); | 648 g_free( xfer_data->size_list->data ); |
654 | 655 |
655 /* if there are still more files */ | 656 /* if there are still more files */ |
656 if(xfer_data->filename_list) | 657 if(xfer_data->filename_list) |
657 { | 658 { |
658 gchar* filename; | 659 gchar* filename; |
659 long filesize; | 660 goffset filesize; |
660 | 661 |
661 filename = xfer_data->filename_list->data; | 662 filename = xfer_data->filename_list->data; |
662 filesize = atol( xfer_data->size_list->data ); | 663 filesize = g_ascii_strtoll( xfer_data->size_list->data, NULL, 10 ); |
663 | 664 |
664 gc = xfer_data->gc; | 665 gc = xfer_data->gc; |
665 yd = gc->proto_data; | 666 yd = purple_connection_get_protocol_data(gc); |
666 | 667 |
667 /* setting up xfer_data for next file's tranfer */ | 668 /* setting up xfer_data for next file's tranfer */ |
668 g_free(xfer_data->host); | 669 g_free(xfer_data->host); |
669 g_free(xfer_data->path); | 670 g_free(xfer_data->path); |
670 g_free(xfer_data->txbuf); | 671 g_free(xfer_data->txbuf); |
687 xfer_data->info_val_249 = 0; | 688 xfer_data->info_val_249 = 0; |
688 xfer_data->status_15 = STARTED; | 689 xfer_data->status_15 = STARTED; |
689 xfer_data->firstoflist = FALSE; | 690 xfer_data->firstoflist = FALSE; |
690 | 691 |
691 /* Dereference xfer_data from old xfer */ | 692 /* Dereference xfer_data from old xfer */ |
692 xfer_old->data = NULL; | 693 purple_xfer_set_protocol_data(xfer_old, NULL); |
693 | 694 |
694 /* Build the file transfer handle. */ | 695 /* Build the file transfer handle. */ |
695 xfer = purple_xfer_new(gc->account, PURPLE_XFER_RECEIVE, xfer_old->who); | 696 xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_RECEIVE, purple_xfer_get_remote_user(xfer_old)); |
696 | 697 |
697 | 698 |
698 if (xfer) { | 699 if (xfer) { |
699 /* Set the info about the incoming file. */ | 700 /* Set the info about the incoming file. */ |
700 char *utf8_filename = yahoo_string_decode(gc, filename, TRUE); | 701 char *utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
701 purple_xfer_set_filename(xfer, utf8_filename); | 702 purple_xfer_set_filename(xfer, utf8_filename); |
702 g_free(utf8_filename); | 703 g_free(utf8_filename); |
703 purple_xfer_set_size(xfer, filesize); | 704 purple_xfer_set_size(xfer, filesize); |
704 | 705 |
705 xfer->data = xfer_data; | 706 purple_xfer_set_protocol_data(xfer, xfer_data); |
706 | 707 |
707 /* Setup our I/O op functions */ | 708 /* Setup our I/O op functions */ |
708 purple_xfer_set_init_fnc(xfer, yahoo_xfer_init_15); | 709 purple_xfer_set_init_fnc(xfer, yahoo_xfer_init_15); |
709 purple_xfer_set_start_fnc(xfer, yahoo_xfer_start); | 710 purple_xfer_set_start_fnc(xfer, yahoo_xfer_start); |
710 purple_xfer_set_end_fnc(xfer, yahoo_xfer_end); | 711 purple_xfer_set_end_fnc(xfer, yahoo_xfer_end); |
724 return; | 725 return; |
725 } | 726 } |
726 } | 727 } |
727 if (xfer_data) | 728 if (xfer_data) |
728 yahoo_xfer_data_free(xfer_data); | 729 yahoo_xfer_data_free(xfer_data); |
729 xfer_old->data = NULL; | 730 purple_xfer_set_protocol_data(xfer_old, NULL); |
730 | |
731 } | 731 } |
732 | 732 |
733 void yahoo_process_p2pfilexfer(PurpleConnection *gc, struct yahoo_packet *pkt) | 733 void yahoo_process_p2pfilexfer(PurpleConnection *gc, struct yahoo_packet *pkt) |
734 { | 734 { |
735 GSList *l = pkt->hash; | 735 GSList *l = pkt->hash; |
801 PurpleXfer *xfer; | 801 PurpleXfer *xfer; |
802 YahooData *yd; | 802 YahooData *yd; |
803 struct yahoo_xfer_data *xfer_data; | 803 struct yahoo_xfer_data *xfer_data; |
804 char *service = NULL; | 804 char *service = NULL; |
805 char *filename = NULL; | 805 char *filename = NULL; |
806 unsigned long filesize = 0L; | 806 goffset filesize = G_GOFFSET_CONSTANT(0); |
807 GSList *l; | 807 GSList *l; |
808 | 808 |
809 yd = gc->proto_data; | 809 yd = purple_connection_get_protocol_data(gc); |
810 | 810 |
811 for (l = pkt->hash; l; l = l->next) { | 811 for (l = pkt->hash; l; l = l->next) { |
812 struct yahoo_pair *pair = l->data; | 812 struct yahoo_pair *pair = l->data; |
813 | 813 |
814 switch (pair->key) { | 814 switch (pair->key) { |
829 break; | 829 break; |
830 case 27: | 830 case 27: |
831 filename = pair->value; | 831 filename = pair->value; |
832 break; | 832 break; |
833 case 28: | 833 case 28: |
834 filesize = atol(pair->value); | 834 filesize = g_ascii_strtoll(pair->value, NULL, 10); |
835 break; | 835 break; |
836 case 49: | 836 case 49: |
837 service = pair->value; | 837 service = pair->value; |
838 break; | 838 break; |
839 case 63: | 839 case 63: |
878 | 878 |
879 purple_debug_misc("yahoo_filexfer", "Host is %s, port is %d, path is %s, and the full url was %s.\n", | 879 purple_debug_misc("yahoo_filexfer", "Host is %s, port is %d, path is %s, and the full url was %s.\n", |
880 xfer_data->host, xfer_data->port, xfer_data->path, url); | 880 xfer_data->host, xfer_data->port, xfer_data->path, url); |
881 | 881 |
882 /* Build the file transfer handle. */ | 882 /* Build the file transfer handle. */ |
883 xfer = purple_xfer_new(gc->account, PURPLE_XFER_RECEIVE, from); | 883 xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_RECEIVE, from); |
884 if (xfer == NULL) { | 884 if (xfer == NULL) { |
885 g_free(xfer_data); | 885 g_free(xfer_data); |
886 g_return_if_reached(); | 886 g_return_if_reached(); |
887 } | 887 } |
888 | 888 |
889 xfer->data = xfer_data; | 889 purple_xfer_set_protocol_data(xfer, xfer_data); |
890 | 890 |
891 /* Set the info about the incoming file. */ | 891 /* Set the info about the incoming file. */ |
892 if (filename) { | 892 if (filename) { |
893 char *utf8_filename = yahoo_string_decode(gc, filename, TRUE); | 893 char *utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
894 purple_xfer_set_filename(xfer, utf8_filename); | 894 purple_xfer_set_filename(xfer, utf8_filename); |
934 | 934 |
935 xfer_data = g_new0(struct yahoo_xfer_data, 1); | 935 xfer_data = g_new0(struct yahoo_xfer_data, 1); |
936 xfer_data->gc = gc; | 936 xfer_data->gc = gc; |
937 | 937 |
938 /* Build the file transfer handle. */ | 938 /* Build the file transfer handle. */ |
939 xfer = purple_xfer_new(gc->account, PURPLE_XFER_SEND, who); | 939 xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_SEND, who); |
940 if (xfer == NULL) | 940 if (xfer == NULL) |
941 { | 941 { |
942 g_free(xfer_data); | 942 g_free(xfer_data); |
943 g_return_val_if_reached(NULL); | 943 g_return_val_if_reached(NULL); |
944 } | 944 } |
945 | 945 |
946 xfer->data = xfer_data; | 946 purple_xfer_set_protocol_data(xfer, xfer_data); |
947 | 947 |
948 /* Setup our I/O op functions */ | 948 /* Setup our I/O op functions */ |
949 purple_xfer_set_init_fnc(xfer, yahoo_xfer_init); | 949 purple_xfer_set_init_fnc(xfer, yahoo_xfer_init); |
950 purple_xfer_set_start_fnc(xfer, yahoo_xfer_start); | 950 purple_xfer_set_start_fnc(xfer, yahoo_xfer_start); |
951 purple_xfer_set_end_fnc(xfer, yahoo_xfer_end); | 951 purple_xfer_set_end_fnc(xfer, yahoo_xfer_end); |
991 gchar *url; | 991 gchar *url; |
992 gchar *filename; | 992 gchar *filename; |
993 | 993 |
994 if (!(xfer = data)) | 994 if (!(xfer = data)) |
995 return; | 995 return; |
996 if (!(xd = xfer->data)) | 996 if (!(xd = purple_xfer_get_protocol_data(xfer))) |
997 return; | 997 return; |
998 gc = xd->gc; | 998 gc = xd->gc; |
999 account = purple_connection_get_account(gc); | 999 account = purple_connection_get_account(gc); |
1000 yd = gc->proto_data; | 1000 yd = purple_connection_get_protocol_data(gc); |
1001 | 1001 |
1002 if(!hosts) | 1002 if(!hosts) |
1003 { | 1003 { |
1004 purple_debug_error("yahoo", "Unable to find an IP address for relay.msg.yahoo.com\n"); | 1004 purple_debug_error("yahoo", "Unable to find an IP address for relay.msg.yahoo.com\n"); |
1005 purple_xfer_cancel_remote(xfer); | 1005 purple_xfer_cancel_remote(xfer); |
1055 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, YAHOO_STATUS_AVAILABLE, yd->session_id); | 1055 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, YAHOO_STATUS_AVAILABLE, yd->session_id); |
1056 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); | 1056 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); |
1057 | 1057 |
1058 yahoo_packet_hash(pkt, "ssssis", | 1058 yahoo_packet_hash(pkt, "ssssis", |
1059 1, purple_normalize(account, purple_account_get_username(account)), | 1059 1, purple_normalize(account, purple_account_get_username(account)), |
1060 5, xfer->who, | 1060 5, purple_xfer_get_remote_user(xfer), |
1061 265, xd->xfer_peer_idstring, | 1061 265, xd->xfer_peer_idstring, |
1062 27, filename, | 1062 27, filename, |
1063 249, 3, | 1063 249, 3, |
1064 250, xd->host); | 1064 250, xd->host); |
1065 | 1065 |
1075 } | 1075 } |
1076 | 1076 |
1077 void yahoo_send_file(PurpleConnection *gc, const char *who, const char *file) | 1077 void yahoo_send_file(PurpleConnection *gc, const char *who, const char *file) |
1078 { | 1078 { |
1079 struct yahoo_xfer_data *xfer_data; | 1079 struct yahoo_xfer_data *xfer_data; |
1080 YahooData *yd = gc->proto_data; | 1080 YahooData *yd = purple_connection_get_protocol_data(gc); |
1081 PurpleXfer *xfer = yahoo_new_xfer(gc, who); | 1081 PurpleXfer *xfer = yahoo_new_xfer(gc, who); |
1082 | 1082 |
1083 g_return_if_fail(xfer != NULL); | 1083 g_return_if_fail(xfer != NULL); |
1084 | 1084 |
1085 /* if we don't have a p2p connection, try establishing it now */ | 1085 /* if we don't have a p2p connection, try establishing it now */ |
1086 if( !g_hash_table_lookup(yd->peers, who) ) | 1086 if( !g_hash_table_lookup(yd->peers, who) ) |
1087 yahoo_send_p2p_pkt(gc, who, 0); | 1087 yahoo_send_p2p_pkt(gc, who, 0); |
1088 | 1088 |
1089 xfer_data = xfer->data; | 1089 xfer_data = purple_xfer_get_protocol_data(xfer); |
1090 xfer_data->status_15 = STARTED; | 1090 xfer_data->status_15 = STARTED; |
1091 purple_xfer_set_init_fnc(xfer, yahoo_xfer_init_15); | 1091 purple_xfer_set_init_fnc(xfer, yahoo_xfer_init_15); |
1092 xfer_data->version = 15; | 1092 xfer_data->version = 15; |
1093 xfer_data->xfer_peer_idstring = yahoo_xfer_new_xfer_id(); | 1093 xfer_data->xfer_peer_idstring = yahoo_xfer_new_xfer_id(); |
1094 g_hash_table_insert(yd->xfer_peer_idstring_map, xfer_data->xfer_peer_idstring, xfer); | 1094 g_hash_table_insert(yd->xfer_peer_idstring_map, xfer_data->xfer_peer_idstring, xfer); |
1106 static void yahoo_xfer_recv_cb_15(gpointer data, gint source, PurpleInputCondition condition) | 1106 static void yahoo_xfer_recv_cb_15(gpointer data, gint source, PurpleInputCondition condition) |
1107 { | 1107 { |
1108 PurpleXfer *xfer; | 1108 PurpleXfer *xfer; |
1109 struct yahoo_xfer_data *xd; | 1109 struct yahoo_xfer_data *xd; |
1110 int did; | 1110 int did; |
1111 gchar* buf; | 1111 guchar buf[1000]; |
1112 gchar* t; | |
1113 PurpleAccount *account; | 1112 PurpleAccount *account; |
1114 PurpleConnection *gc; | 1113 PurpleConnection *gc; |
1115 | 1114 |
1116 xfer = data; | 1115 xfer = data; |
1117 xd = xfer->data; | 1116 xd = purple_xfer_get_protocol_data(xfer); |
1118 account = purple_connection_get_account(xd->gc); | 1117 account = purple_connection_get_account(xd->gc); |
1119 gc = xd->gc; | 1118 gc = xd->gc; |
1120 | 1119 |
1121 buf=g_strnfill(1000, 0); | 1120 while((did = read(source, buf, sizeof(buf))) > 0) |
1122 while((did = read(source, buf, 998)) > 0) | 1121 { |
1123 { | 1122 /* TODO: Convert to circ buffer, this all is pretty horrible */ |
1123 xd->txbuf = g_realloc(xd->txbuf, xd->txbuflen + did); | |
1124 g_memmove(xd->txbuf + xd->txbuflen, buf, did); | |
1124 xd->txbuflen += did; | 1125 xd->txbuflen += did; |
1125 buf[did] = '\0'; | 1126 } |
1126 t = xd->txbuf; | |
1127 xd->txbuf = g_strconcat(t,buf,NULL); | |
1128 g_free(t); | |
1129 } | |
1130 g_free(buf); | |
1131 | 1127 |
1132 if (did < 0 && errno == EAGAIN) | 1128 if (did < 0 && errno == EAGAIN) |
1133 return; | 1129 return; |
1134 else if (did < 0) { | 1130 else if (did < 0) { |
1135 purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); | 1131 purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); |
1165 PurpleXfer *xfer; | 1161 PurpleXfer *xfer; |
1166 struct yahoo_xfer_data *xd; | 1162 struct yahoo_xfer_data *xd; |
1167 int remaining, written; | 1163 int remaining, written; |
1168 | 1164 |
1169 xfer = data; | 1165 xfer = data; |
1170 xd = xfer->data; | 1166 xd = purple_xfer_get_protocol_data(xfer); |
1171 remaining = xd->txbuflen - xd->txbuf_written; | 1167 remaining = xd->txbuflen - xd->txbuf_written; |
1172 written = write(source, xd->txbuf + xd->txbuf_written, remaining); | 1168 written = write(source, xd->txbuf + xd->txbuf_written, remaining); |
1173 | 1169 |
1174 if (written < 0 && errno == EAGAIN) | 1170 if (written < 0 && errno == EAGAIN) |
1175 written = 0; | 1171 written = 0; |
1198 yahoo_xfer_recv_cb_15(xfer, source, PURPLE_INPUT_READ); | 1194 yahoo_xfer_recv_cb_15(xfer, source, PURPLE_INPUT_READ); |
1199 } | 1195 } |
1200 else if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE && xd->status_15 == HEAD_REPLY_RECEIVED) | 1196 else if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE && xd->status_15 == HEAD_REPLY_RECEIVED) |
1201 { | 1197 { |
1202 xd->status_15 = TRANSFER_PHASE; | 1198 xd->status_15 = TRANSFER_PHASE; |
1203 xfer->fd = source; | 1199 purple_xfer_set_fd(xfer, source); |
1204 purple_xfer_start(xfer, source, NULL, 0); | 1200 purple_xfer_start(xfer, source, NULL, 0); |
1205 } | 1201 } |
1206 else if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND && (xd->status_15 == ACCEPTED || xd->status_15 == P2P_GET_REQUESTED) ) | 1202 else if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND && (xd->status_15 == ACCEPTED || xd->status_15 == P2P_GET_REQUESTED) ) |
1207 { | 1203 { |
1208 xd->status_15 = TRANSFER_PHASE; | 1204 xd->status_15 = TRANSFER_PHASE; |
1209 xfer->fd = source; | 1205 purple_xfer_set_fd(xfer, source); |
1210 /* Remove Read event */ | 1206 /* Remove Read event */ |
1211 purple_input_remove(xd->input_event); | 1207 purple_input_remove(xd->input_event); |
1212 xd->input_event = 0; | 1208 xd->input_event = 0; |
1213 purple_xfer_start(xfer, source, NULL, 0); | 1209 purple_xfer_start(xfer, source, NULL, 0); |
1214 } | 1210 } |
1217 xd->status_15 = P2P_HEAD_REPLIED; | 1213 xd->status_15 = P2P_HEAD_REPLIED; |
1218 /* Remove Read event and close descriptor */ | 1214 /* Remove Read event and close descriptor */ |
1219 purple_input_remove(xd->input_event); | 1215 purple_input_remove(xd->input_event); |
1220 xd->input_event = 0; | 1216 xd->input_event = 0; |
1221 close(source); | 1217 close(source); |
1222 xfer->fd = -1; | 1218 purple_xfer_set_fd(xfer, -1); |
1223 /* start local server, listen for connections */ | 1219 /* start local server, listen for connections */ |
1224 purple_network_listen(xd->yahoo_local_p2p_ft_server_port, SOCK_STREAM, yahoo_p2p_ft_server_listen_cb, xfer); | 1220 purple_network_listen(xd->yahoo_local_p2p_ft_server_port, AF_UNSPEC, SOCK_STREAM, TRUE, yahoo_p2p_ft_server_listen_cb, xfer); |
1225 } | 1221 } |
1226 else | 1222 else |
1227 { | 1223 { |
1228 purple_debug_error("yahoo", "Unrecognized yahoo file transfer mode and stage (ymsg15):%d,%d\n", purple_xfer_get_type(xfer), xd->status_15); | 1224 purple_debug_error("yahoo", "Unrecognized yahoo file transfer mode and stage (ymsg15):%d,%d\n", purple_xfer_get_type(xfer), xd->status_15); |
1229 return; | 1225 return; |
1237 PurpleAccount *account; | 1233 PurpleAccount *account; |
1238 PurpleConnection *gc; | 1234 PurpleConnection *gc; |
1239 | 1235 |
1240 if (!(xfer = data)) | 1236 if (!(xfer = data)) |
1241 return; | 1237 return; |
1242 if (!(xd = xfer->data)) | 1238 if (!(xd = purple_xfer_get_protocol_data(xfer))) |
1243 return; | 1239 return; |
1244 gc = xd->gc; | 1240 gc = xd->gc; |
1245 account = purple_connection_get_account(gc); | 1241 account = purple_connection_get_account(gc); |
1246 if ((source < 0) || (xd->path == NULL) || (xd->host == NULL)) { | 1242 if ((source < 0) || (xd->path == NULL) || (xd->host == NULL)) { |
1247 purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), | 1243 purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), |
1248 xfer->who, _("Unable to connect.")); | 1244 purple_xfer_get_remote_user(xfer), _("Unable to connect.")); |
1249 purple_xfer_cancel_remote(xfer); | 1245 purple_xfer_cancel_remote(xfer); |
1250 return; | 1246 return; |
1251 } | 1247 } |
1252 /* The first time we get here, assemble the tx buffer */ | 1248 /* The first time we get here, assemble the tx buffer */ |
1253 if (xd->txbuflen == 0) | 1249 if (xd->txbuflen == 0) |
1254 { | 1250 { |
1255 gchar* cookies; | 1251 gchar* cookies; |
1256 YahooData *yd = gc->proto_data; | 1252 gchar* initial_buffer; |
1253 YahooData *yd = purple_connection_get_protocol_data(gc); | |
1257 | 1254 |
1258 /* cookies = yahoo_get_cookies(gc); | 1255 /* cookies = yahoo_get_cookies(gc); |
1259 * This doesn't seem to be working. The function is returning NULL, which yahoo servers don't like | 1256 * This doesn't seem to be working. The function is returning NULL, which yahoo servers don't like |
1260 * For now let us not use this function */ | 1257 * For now let us not use this function */ |
1261 | 1258 |
1264 if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND && xd->status_15 == ACCEPTED) | 1261 if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND && xd->status_15 == ACCEPTED) |
1265 { | 1262 { |
1266 if(xd->info_val_249 == 2) | 1263 if(xd->info_val_249 == 2) |
1267 { | 1264 { |
1268 /* sending file via p2p, we are connected as client */ | 1265 /* sending file via p2p, we are connected as client */ |
1269 xd->txbuf = g_strdup_printf("POST /%s HTTP/1.1\r\n" | 1266 initial_buffer = g_strdup_printf("POST /%s HTTP/1.1\r\n" |
1270 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" | 1267 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" |
1271 "Host: %s\r\n" | 1268 "Host: %s\r\n" |
1272 "Content-Length: %ld\r\n" | 1269 "Content-Length: %" G_GOFFSET_FORMAT "\r\n" |
1273 "Cache-Control: no-cache\r\n\r\n", | 1270 "Cache-Control: no-cache\r\n\r\n", |
1274 xd->path, | 1271 xd->path, |
1275 xd->host, | 1272 xd->host, |
1276 (long int)xfer->size); /* to do, add Referer */ | 1273 purple_xfer_get_size(xfer)); /* to do, add Referer */ |
1277 } | 1274 } |
1278 else | 1275 else |
1279 { | 1276 { |
1280 /* sending file via relaying */ | 1277 /* sending file via relaying */ |
1281 xd->txbuf = g_strdup_printf("POST /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n" | 1278 initial_buffer = g_strdup_printf("POST /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n" |
1282 "Cookie:%s\r\n" | 1279 "Cookie:%s\r\n" |
1283 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" | 1280 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" |
1284 "Host: %s\r\n" | 1281 "Host: %s\r\n" |
1285 "Content-Length: %ld\r\n" | 1282 "Content-Length: %" G_GOFFSET_FORMAT "\r\n" |
1286 "Cache-Control: no-cache\r\n\r\n", | 1283 "Cache-Control: no-cache\r\n\r\n", |
1287 purple_url_encode(xd->xfer_idstring_for_relay), | 1284 purple_url_encode(xd->xfer_idstring_for_relay), |
1288 purple_normalize(account, purple_account_get_username(account)), | 1285 purple_normalize(account, purple_account_get_username(account)), |
1289 xfer->who, | 1286 purple_xfer_get_remote_user(xfer), |
1290 cookies, | 1287 cookies, |
1291 xd->host, | 1288 xd->host, |
1292 (long int)xfer->size); | 1289 purple_xfer_get_size(xfer)); /* to do, add Referer */ |
1293 } | 1290 } |
1294 } | 1291 } |
1295 else if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE && xd->status_15 == STARTED) | 1292 else if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE && xd->status_15 == STARTED) |
1296 { | 1293 { |
1297 if(xd->info_val_249 == 1) | 1294 if(xd->info_val_249 == 1) |
1298 { | 1295 { |
1299 /* receiving file via p2p, connected as client */ | 1296 /* receiving file via p2p, connected as client */ |
1300 xd->txbuf = g_strdup_printf("HEAD /%s HTTP/1.1\r\n" | 1297 initial_buffer = g_strdup_printf("HEAD /%s HTTP/1.1\r\n" |
1301 "Accept: */*\r\n" | 1298 "Accept: */*\r\n" |
1302 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" | 1299 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" |
1303 "Host: %s\r\n" | 1300 "Host: %s\r\n" |
1304 "Content-Length: 0\r\n" | 1301 "Content-Length: 0\r\n" |
1305 "Cache-Control: no-cache\r\n\r\n", | 1302 "Cache-Control: no-cache\r\n\r\n", |
1306 xd->path,xd->host); | 1303 xd->path,xd->host); |
1307 } | 1304 } |
1308 else | 1305 else |
1309 { | 1306 { |
1310 /* receiving file via relaying */ | 1307 /* receiving file via relaying */ |
1311 xd->txbuf = g_strdup_printf("HEAD /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n" | 1308 initial_buffer = g_strdup_printf("HEAD /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n" |
1312 "Accept: */*\r\n" | 1309 "Accept: */*\r\n" |
1313 "Cookie: %s\r\n" | 1310 "Cookie: %s\r\n" |
1314 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" | 1311 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" |
1315 "Host: %s\r\n" | 1312 "Host: %s\r\n" |
1316 "Content-Length: 0\r\n" | 1313 "Content-Length: 0\r\n" |
1317 "Cache-Control: no-cache\r\n\r\n", | 1314 "Cache-Control: no-cache\r\n\r\n", |
1318 purple_url_encode(xd->xfer_idstring_for_relay), | 1315 purple_url_encode(xd->xfer_idstring_for_relay), |
1319 purple_normalize(account, purple_account_get_username(account)), | 1316 purple_normalize(account, purple_account_get_username(account)), |
1320 xfer->who, | 1317 purple_xfer_get_remote_user(xfer), |
1321 cookies, | 1318 cookies, |
1322 xd->host); | 1319 xd->host); |
1323 } | 1320 } |
1324 } | 1321 } |
1325 else if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE && xd->status_15 == HEAD_REPLY_RECEIVED) | 1322 else if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE && xd->status_15 == HEAD_REPLY_RECEIVED) |
1326 { | 1323 { |
1327 if(xd->info_val_249 == 1) | 1324 if(xd->info_val_249 == 1) |
1328 { | 1325 { |
1329 /* receiving file via p2p, connected as client */ | 1326 /* receiving file via p2p, connected as client */ |
1330 xd->txbuf = g_strdup_printf("GET /%s HTTP/1.1\r\n" | 1327 initial_buffer = g_strdup_printf("GET /%s HTTP/1.1\r\n" |
1331 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" | 1328 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" |
1332 "Host: %s\r\n" | 1329 "Host: %s\r\n" |
1333 "Connection: Keep-Alive\r\n\r\n", | 1330 "Connection: Keep-Alive\r\n\r\n", |
1334 xd->path, xd->host); | 1331 xd->path, xd->host); |
1335 } | 1332 } |
1336 else | 1333 else |
1337 { | 1334 { |
1338 /* receiving file via relaying */ | 1335 /* receiving file via relaying */ |
1339 xd->txbuf = g_strdup_printf("GET /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n" | 1336 initial_buffer = g_strdup_printf("GET /relay?token=%s&sender=%s&recver=%s HTTP/1.1\r\n" |
1340 "Cookie: %s\r\n" | 1337 "Cookie: %s\r\n" |
1341 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" | 1338 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" |
1342 "Host: %s\r\n" | 1339 "Host: %s\r\n" |
1343 "Connection: Keep-Alive\r\n\r\n", | 1340 "Connection: Keep-Alive\r\n\r\n", |
1344 purple_url_encode(xd->xfer_idstring_for_relay), | 1341 purple_url_encode(xd->xfer_idstring_for_relay), |
1345 purple_normalize(account, purple_account_get_username(account)), | 1342 purple_normalize(account, purple_account_get_username(account)), |
1346 xfer->who, | 1343 purple_xfer_get_remote_user(xfer), |
1347 cookies, | 1344 cookies, |
1348 xd->host); | 1345 xd->host); |
1349 } | 1346 } |
1350 } | 1347 } |
1351 else | 1348 else |
1352 { | 1349 { |
1353 purple_debug_error("yahoo", "Unrecognized yahoo file transfer mode and stage (ymsg15):%d,%d\n", purple_xfer_get_type(xfer), xd->status_15); | 1350 purple_debug_error("yahoo", "Unrecognized yahoo file transfer mode and stage (ymsg15):%d,%d\n", purple_xfer_get_type(xfer), xd->status_15); |
1354 g_free(cookies); | 1351 g_free(cookies); |
1355 return; | 1352 return; |
1356 } | 1353 } |
1357 xd->txbuflen = strlen(xd->txbuf); | 1354 xd->txbuf = (guchar*) initial_buffer; |
1355 xd->txbuflen = strlen(initial_buffer); | |
1358 xd->txbuf_written = 0; | 1356 xd->txbuf_written = 0; |
1359 g_free(cookies); | 1357 g_free(cookies); |
1360 } | 1358 } |
1361 | 1359 |
1362 if (!xd->tx_handler) | 1360 if (!xd->tx_handler) |
1371 { | 1369 { |
1372 PurpleXfer *xfer; | 1370 PurpleXfer *xfer; |
1373 struct yahoo_xfer_data *xd; | 1371 struct yahoo_xfer_data *xd; |
1374 | 1372 |
1375 xfer = data; | 1373 xfer = data; |
1376 if (!(xd = xfer->data)) { | 1374 if (!(xd = purple_xfer_get_protocol_data(xfer))) { |
1377 purple_xfer_cancel_remote(xfer); | 1375 purple_xfer_cancel_remote(xfer); |
1378 return; | 1376 return; |
1379 } | 1377 } |
1380 | 1378 |
1381 purple_input_remove(xd->input_event); | 1379 purple_input_remove(xd->input_event); |
1382 xd->status_15 = TRANSFER_PHASE; | 1380 xd->status_15 = TRANSFER_PHASE; |
1383 xfer->fd = source; | 1381 purple_xfer_set_fd(xfer, source); |
1384 purple_xfer_start(xfer, source, NULL, 0); | 1382 purple_xfer_start(xfer, source, NULL, 0); |
1385 } | 1383 } |
1386 | 1384 |
1387 static void yahoo_p2p_ft_HEAD_GET_cb(gpointer data, gint source, PurpleInputCondition cond) | 1385 static void yahoo_p2p_ft_HEAD_GET_cb(gpointer data, gint source, PurpleInputCondition cond) |
1388 { | 1386 { |
1394 char *url_get; | 1392 char *url_get; |
1395 time_t unix_time; | 1393 time_t unix_time; |
1396 char *time_str; | 1394 char *time_str; |
1397 | 1395 |
1398 xfer = data; | 1396 xfer = data; |
1399 if (!(xd = xfer->data)) { | 1397 if (!(xd = purple_xfer_get_protocol_data(xfer))) { |
1400 purple_xfer_cancel_remote(xfer); | 1398 purple_xfer_cancel_remote(xfer); |
1401 return; | 1399 return; |
1402 } | 1400 } |
1403 | 1401 |
1404 len = read(source, buf, sizeof(buf)); | 1402 len = read(source, buf, sizeof(buf)); |
1429 unix_time = time(NULL); | 1427 unix_time = time(NULL); |
1430 time_str = ctime(&unix_time); | 1428 time_str = ctime(&unix_time); |
1431 time_str[strlen(time_str) - 1] = '\0'; | 1429 time_str[strlen(time_str) - 1] = '\0'; |
1432 | 1430 |
1433 if (xd->txbuflen == 0) { | 1431 if (xd->txbuflen == 0) { |
1434 xd->txbuf = g_strdup_printf("HTTP/1.0 200 OK\r\n" | 1432 gchar *initial_buffer = g_strdup_printf("HTTP/1.0 200 OK\r\n" |
1435 "Date: %s GMT\r\n" | 1433 "Date: %s GMT\r\n" |
1436 "Server: Y!/1.0\r\n" | 1434 "Server: Y!/1.0\r\n" |
1437 "MIME-version: 1.0\r\n" | 1435 "MIME-version: 1.0\r\n" |
1438 "Last-modified: %s GMT\r\n" | 1436 "Last-modified: %s GMT\r\n" |
1439 "Content-length: %" G_GSIZE_FORMAT "\r\n\r\n", | 1437 "Content-length: %" G_GOFFSET_FORMAT "\r\n\r\n", |
1440 time_str, time_str, xfer->size); | 1438 time_str, time_str, purple_xfer_get_size(xfer)); |
1441 xd->txbuflen = strlen(xd->txbuf); | 1439 xd->txbuf = (guchar *)initial_buffer; |
1440 xd->txbuflen = strlen(initial_buffer); | |
1442 xd->txbuf_written = 0; | 1441 xd->txbuf_written = 0; |
1443 } | 1442 } |
1444 | 1443 |
1445 if (!xd->tx_handler) { | 1444 if (!xd->tx_handler) { |
1446 xd->tx_handler = purple_input_add(source, PURPLE_INPUT_WRITE, yahoo_xfer_send_cb_15, xfer); | 1445 xd->tx_handler = purple_input_add(source, PURPLE_INPUT_WRITE, yahoo_xfer_send_cb_15, xfer); |
1456 int acceptfd; | 1455 int acceptfd; |
1457 PurpleXfer *xfer; | 1456 PurpleXfer *xfer; |
1458 struct yahoo_xfer_data *xd; | 1457 struct yahoo_xfer_data *xd; |
1459 | 1458 |
1460 xfer = data; | 1459 xfer = data; |
1461 if (!(xd = xfer->data)) { | 1460 if (!(xd = purple_xfer_get_protocol_data(xfer))) { |
1462 purple_xfer_cancel_remote(xfer); | 1461 purple_xfer_cancel_remote(xfer); |
1463 return; | 1462 return; |
1464 } | 1463 } |
1465 | 1464 |
1466 acceptfd = accept(source, NULL, 0); | 1465 acceptfd = accept(source, NULL, 0); |
1478 /* remove watcher and close p2p ft server */ | 1477 /* remove watcher and close p2p ft server */ |
1479 purple_input_remove(xd->yahoo_p2p_ft_server_watcher); | 1478 purple_input_remove(xd->yahoo_p2p_ft_server_watcher); |
1480 close(xd->yahoo_local_p2p_ft_server_fd); | 1479 close(xd->yahoo_local_p2p_ft_server_fd); |
1481 | 1480 |
1482 /* Add an Input Read event to the file descriptor */ | 1481 /* Add an Input Read event to the file descriptor */ |
1483 xfer->fd = acceptfd; | 1482 purple_xfer_set_fd(xfer, acceptfd); |
1484 if(xfer->type == PURPLE_XFER_RECEIVE) | 1483 if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) |
1485 xd->input_event = purple_input_add(acceptfd, PURPLE_INPUT_READ, yahoo_p2p_ft_POST_cb, data); | 1484 xd->input_event = purple_input_add(acceptfd, PURPLE_INPUT_READ, yahoo_p2p_ft_POST_cb, data); |
1486 else | 1485 else |
1487 xd->input_event = purple_input_add(acceptfd, PURPLE_INPUT_READ, yahoo_p2p_ft_HEAD_GET_cb, data); | 1486 xd->input_event = purple_input_add(acceptfd, PURPLE_INPUT_READ, yahoo_p2p_ft_HEAD_GET_cb, data); |
1488 } | 1487 } |
1489 | 1488 |
1498 const char *local_ip; | 1497 const char *local_ip; |
1499 gchar *url_to_send = NULL; | 1498 gchar *url_to_send = NULL; |
1500 char *filename_without_spaces = NULL; | 1499 char *filename_without_spaces = NULL; |
1501 | 1500 |
1502 xfer = data; | 1501 xfer = data; |
1503 if (!(xd = xfer->data) || (listenfd == -1)) { | 1502 if (!(xd = purple_xfer_get_protocol_data(xfer)) || (listenfd == -1)) { |
1504 purple_debug_warning("yahoo","p2p: error starting server for p2p file transfer\n"); | 1503 purple_debug_warning("yahoo","p2p: error starting server for p2p file transfer\n"); |
1505 purple_xfer_cancel_remote(xfer); | 1504 purple_xfer_cancel_remote(xfer); |
1506 return; | 1505 return; |
1507 } | 1506 } |
1508 | 1507 |
1509 if( (xfer->type == PURPLE_XFER_RECEIVE) || (xd->status_15 != P2P_HEAD_REPLIED) ) { | 1508 if( (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) || (xd->status_15 != P2P_HEAD_REPLIED) ) { |
1510 yd = xd->gc->proto_data; | 1509 yd = purple_connection_get_protocol_data(xd->gc); |
1511 account = purple_connection_get_account(xd->gc); | 1510 account = purple_connection_get_account(xd->gc); |
1512 local_ip = purple_network_get_my_ip(listenfd); | 1511 local_ip = purple_network_get_my_ip(listenfd); |
1513 xd->yahoo_local_p2p_ft_server_port = purple_network_get_port_from_fd(listenfd); | 1512 xd->yahoo_local_p2p_ft_server_port = purple_network_get_port_from_fd(listenfd); |
1514 | 1513 |
1515 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); | 1514 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); |
1516 filename_without_spaces = g_strdup(filename); | 1515 filename_without_spaces = g_strdup(filename); |
1517 purple_util_chrreplace(filename_without_spaces, ' ', '+'); | 1516 purple_util_chrreplace(filename_without_spaces, ' ', '+'); |
1518 xd->xfer_url = g_strdup_printf("/Messenger.%s.%d000%s?AppID=Messenger&UserID=%s&K=lc9lu2u89gz1llmplwksajkjx", xfer->who, (int)time(NULL), filename_without_spaces, xfer->who); | 1517 xd->xfer_url = g_strdup_printf("/Messenger.%s.%d000%s?AppID=Messenger&UserID=%s&K=lc9lu2u89gz1llmplwksajkjx", purple_xfer_get_remote_user(xfer), (int)time(NULL), filename_without_spaces, purple_xfer_get_remote_user(xfer)); |
1519 url_to_send = g_strdup_printf("http://%s:%d%s", local_ip, xd->yahoo_local_p2p_ft_server_port, xd->xfer_url); | 1518 url_to_send = g_strdup_printf("http://%s:%d%s", local_ip, xd->yahoo_local_p2p_ft_server_port, xd->xfer_url); |
1520 | 1519 |
1521 if(xfer->type == PURPLE_XFER_RECEIVE) { | 1520 if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) { |
1522 xd->info_val_249 = 2; /* 249=2: we are p2p server, and receiving file */ | 1521 xd->info_val_249 = 2; /* 249=2: we are p2p server, and receiving file */ |
1523 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15, | 1522 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15, |
1524 YAHOO_STATUS_AVAILABLE, yd->session_id); | 1523 YAHOO_STATUS_AVAILABLE, yd->session_id); |
1525 yahoo_packet_hash(pkt, "ssssis", | 1524 yahoo_packet_hash(pkt, "ssssis", |
1526 1, purple_normalize(account, purple_account_get_username(account)), | 1525 1, purple_normalize(account, purple_account_get_username(account)), |
1527 5, xfer->who, | 1526 5, purple_xfer_get_remote_user(xfer), |
1528 265, xd->xfer_peer_idstring, | 1527 265, xd->xfer_peer_idstring, |
1529 27, xfer->filename, | 1528 27, purple_xfer_get_filename(xfer), |
1530 249, 2, | 1529 249, 2, |
1531 250, url_to_send); | 1530 250, url_to_send); |
1532 } | 1531 } |
1533 else { | 1532 else { |
1534 xd->info_val_249 = 1; /* 249=1: we are p2p server, and sending file */ | 1533 xd->info_val_249 = 1; /* 249=1: we are p2p server, and sending file */ |
1535 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, YAHOO_STATUS_AVAILABLE, yd->session_id); | 1534 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, YAHOO_STATUS_AVAILABLE, yd->session_id); |
1536 yahoo_packet_hash(pkt, "ssssis", | 1535 yahoo_packet_hash(pkt, "ssssis", |
1537 1, purple_normalize(account, purple_account_get_username(account)), | 1536 1, purple_normalize(account, purple_account_get_username(account)), |
1538 5, xfer->who, | 1537 5, purple_xfer_get_remote_user(xfer), |
1539 265, xd->xfer_peer_idstring, | 1538 265, xd->xfer_peer_idstring, |
1540 27, filename, | 1539 27, filename, |
1541 249, 1, | 1540 249, 1, |
1542 250, url_to_send); | 1541 250, url_to_send); |
1543 } | 1542 } |
1562 PurpleAccount *account; | 1561 PurpleAccount *account; |
1563 YahooData *yd; | 1562 YahooData *yd; |
1564 gchar *filename; | 1563 gchar *filename; |
1565 struct yahoo_p2p_data *p2p_data; | 1564 struct yahoo_p2p_data *p2p_data; |
1566 | 1565 |
1567 if (!(xd = xfer->data)) | 1566 if (!(xd = purple_xfer_get_protocol_data(xfer))) |
1568 return; | 1567 return; |
1569 | 1568 |
1570 account = purple_connection_get_account(gc); | 1569 account = purple_connection_get_account(gc); |
1571 yd = gc->proto_data; | 1570 yd = purple_connection_get_protocol_data(gc); |
1572 | 1571 |
1573 p2p_data = g_hash_table_lookup(yd->peers, xfer->who); | 1572 p2p_data = g_hash_table_lookup(yd->peers, purple_xfer_get_remote_user(xfer)); |
1574 if( p2p_data->connection_type == YAHOO_P2P_WE_ARE_SERVER ) | 1573 if( p2p_data->connection_type == YAHOO_P2P_WE_ARE_SERVER ) |
1575 if(purple_network_listen_range(0, 0, SOCK_STREAM, yahoo_p2p_ft_server_listen_cb, xfer)) | 1574 if(purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, TRUE, yahoo_p2p_ft_server_listen_cb, xfer)) |
1576 return; | 1575 return; |
1577 | 1576 |
1578 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, YAHOO_STATUS_AVAILABLE, yd->session_id); | 1577 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_INFO_15, YAHOO_STATUS_AVAILABLE, yd->session_id); |
1579 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); | 1578 filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); |
1580 | 1579 |
1581 yahoo_packet_hash(pkt, "ssssi", | 1580 yahoo_packet_hash(pkt, "ssssi", |
1582 1, purple_normalize(account, purple_account_get_username(account)), | 1581 1, purple_normalize(account, purple_account_get_username(account)), |
1583 5, xfer->who, | 1582 5, purple_xfer_get_remote_user(xfer), |
1584 265, xd->xfer_peer_idstring, | 1583 265, xd->xfer_peer_idstring, |
1585 27, filename, | 1584 27, filename, |
1586 249, 2); /* 249=2: we are p2p client */ | 1585 249, 2); /* 249=2: we are p2p client */ |
1587 xd->info_val_249 = 2; | 1586 xd->info_val_249 = 2; |
1588 yahoo_packet_send_and_free(pkt, yd); | 1587 yahoo_packet_send_and_free(pkt, yd); |
1601 struct yahoo_xfer_data *xfer_data; | 1600 struct yahoo_xfer_data *xfer_data; |
1602 char *service = NULL; | 1601 char *service = NULL; |
1603 char *filename = NULL; | 1602 char *filename = NULL; |
1604 char *xfer_peer_idstring = NULL; | 1603 char *xfer_peer_idstring = NULL; |
1605 char *utf8_filename; | 1604 char *utf8_filename; |
1606 unsigned long filesize = 0L; | 1605 goffset filesize = G_GOFFSET_CONSTANT(0); |
1607 GSList *l; | 1606 GSList *l; |
1608 GSList *filename_list = NULL; | 1607 GSList *filename_list = NULL; |
1609 GSList *size_list = NULL; | 1608 GSList *size_list = NULL; |
1610 int nooffiles = 0; | 1609 int nooffiles = 0; |
1611 | 1610 |
1612 yd = gc->proto_data; | 1611 yd = purple_connection_get_protocol_data(gc); |
1613 | 1612 |
1614 for (l = pkt->hash; l; l = l->next) { | 1613 for (l = pkt->hash; l; l = l->next) { |
1615 struct yahoo_pair *pair = l->data; | 1614 struct yahoo_pair *pair = l->data; |
1616 | 1615 |
1617 switch (pair->key) { | 1616 switch (pair->key) { |
1681 } | 1680 } |
1682 | 1681 |
1683 account = purple_connection_get_account(gc); | 1682 account = purple_connection_get_account(gc); |
1684 if (yd->jp) | 1683 if (yd->jp) |
1685 { | 1684 { |
1686 purple_dnsquery_a_account(account, YAHOOJP_XFER_RELAY_HOST, | 1685 purple_dnsquery_a(account, YAHOOJP_XFER_RELAY_HOST, |
1687 YAHOOJP_XFER_RELAY_PORT, | 1686 YAHOOJP_XFER_RELAY_PORT, |
1688 yahoo_xfer_dns_connected_15, xfer); | 1687 yahoo_xfer_dns_connected_15, xfer); |
1689 } | 1688 } |
1690 else | 1689 else |
1691 { | 1690 { |
1692 purple_dnsquery_a_account(account, YAHOO_XFER_RELAY_HOST, | 1691 purple_dnsquery_a(account, YAHOO_XFER_RELAY_HOST, |
1693 YAHOO_XFER_RELAY_PORT, | 1692 YAHOO_XFER_RELAY_PORT, |
1694 yahoo_xfer_dns_connected_15, xfer); | 1693 yahoo_xfer_dns_connected_15, xfer); |
1695 } | 1694 } |
1696 return; | 1695 return; |
1697 } | 1696 } |
1718 return; | 1717 return; |
1719 /* have to change list into order in which client at other end sends */ | 1718 /* have to change list into order in which client at other end sends */ |
1720 filename_list = g_slist_reverse(filename_list); | 1719 filename_list = g_slist_reverse(filename_list); |
1721 size_list = g_slist_reverse(size_list); | 1720 size_list = g_slist_reverse(size_list); |
1722 filename = filename_list->data; | 1721 filename = filename_list->data; |
1723 filesize = atol(size_list->data); | 1722 filesize = g_ascii_strtoll(size_list->data, NULL, 10); |
1724 | 1723 |
1725 if(!from) return; | 1724 if(!from) return; |
1726 xfer_data = g_new0(struct yahoo_xfer_data, 1); | 1725 xfer_data = g_new0(struct yahoo_xfer_data, 1); |
1727 xfer_data->version = 15; | 1726 xfer_data->version = 15; |
1728 xfer_data->firstoflist = TRUE; | 1727 xfer_data->firstoflist = TRUE; |
1730 xfer_data->xfer_peer_idstring = g_strdup(xfer_peer_idstring); | 1729 xfer_data->xfer_peer_idstring = g_strdup(xfer_peer_idstring); |
1731 xfer_data->filename_list = filename_list; | 1730 xfer_data->filename_list = filename_list; |
1732 xfer_data->size_list = size_list; | 1731 xfer_data->size_list = size_list; |
1733 | 1732 |
1734 /* Build the file transfer handle. */ | 1733 /* Build the file transfer handle. */ |
1735 xfer = purple_xfer_new(gc->account, PURPLE_XFER_RECEIVE, from); | 1734 xfer = purple_xfer_new(purple_connection_get_account(gc), PURPLE_XFER_RECEIVE, from); |
1736 if (xfer == NULL) | 1735 if (xfer == NULL) |
1737 { | 1736 { |
1738 g_free(xfer_data); | 1737 g_free(xfer_data); |
1739 g_return_if_reached(); | 1738 g_return_if_reached(); |
1740 } | 1739 } |
1741 | |
1742 xfer->message = NULL; | |
1743 | 1740 |
1744 /* Set the info about the incoming file. */ | 1741 /* Set the info about the incoming file. */ |
1745 utf8_filename = yahoo_string_decode(gc, filename, TRUE); | 1742 utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
1746 purple_xfer_set_filename(xfer, utf8_filename); | 1743 purple_xfer_set_filename(xfer, utf8_filename); |
1747 g_free(utf8_filename); | 1744 g_free(utf8_filename); |
1748 purple_xfer_set_size(xfer, filesize); | 1745 purple_xfer_set_size(xfer, filesize); |
1749 | 1746 |
1750 xfer->data = xfer_data; | 1747 purple_xfer_set_protocol_data(xfer, xfer_data); |
1751 | 1748 |
1752 /* Setup our I/O op functions */ | 1749 /* Setup our I/O op functions */ |
1753 purple_xfer_set_init_fnc(xfer, yahoo_xfer_init_15); | 1750 purple_xfer_set_init_fnc(xfer, yahoo_xfer_init_15); |
1754 purple_xfer_set_start_fnc(xfer, yahoo_xfer_start); | 1751 purple_xfer_set_start_fnc(xfer, yahoo_xfer_start); |
1755 purple_xfer_set_end_fnc(xfer, yahoo_xfer_end); | 1752 purple_xfer_set_end_fnc(xfer, yahoo_xfer_end); |
1763 xfer_data->xfer_peer_idstring, | 1760 xfer_data->xfer_peer_idstring, |
1764 xfer); | 1761 xfer); |
1765 | 1762 |
1766 if(nooffiles > 1) { | 1763 if(nooffiles > 1) { |
1767 gchar* message; | 1764 gchar* message; |
1768 message = g_strdup_printf(_("%s is trying to send you a group of %d files.\n"), xfer->who, nooffiles); | 1765 message = g_strdup_printf(_("%s is trying to send you a group of %d files.\n"), purple_xfer_get_remote_user(xfer), nooffiles); |
1769 purple_xfer_conversation_write(xfer, message, FALSE); | 1766 purple_xfer_conversation_write(xfer, message, FALSE); |
1770 g_free(message); | 1767 g_free(message); |
1771 } | 1768 } |
1772 /* Now perform the request */ | 1769 /* Now perform the request */ |
1773 purple_xfer_request(xfer); | 1770 purple_xfer_request(xfer); |
1788 char *xfer_idstring_for_relay = NULL; | 1785 char *xfer_idstring_for_relay = NULL; |
1789 GSList *l; | 1786 GSList *l; |
1790 struct yahoo_packet *pkt_to_send; | 1787 struct yahoo_packet *pkt_to_send; |
1791 struct yahoo_p2p_data *p2p_data; | 1788 struct yahoo_p2p_data *p2p_data; |
1792 | 1789 |
1793 yd = gc->proto_data; | 1790 yd = purple_connection_get_protocol_data(gc); |
1794 | 1791 |
1795 for (l = pkt->hash; l; l = l->next) { | 1792 for (l = pkt->hash; l; l = l->next) { |
1796 struct yahoo_pair *pair = l->data; | 1793 struct yahoo_pair *pair = l->data; |
1797 | 1794 |
1798 switch (pair->key) { | 1795 switch (pair->key) { |
1835 { | 1832 { |
1836 purple_xfer_cancel_remote(xfer); | 1833 purple_xfer_cancel_remote(xfer); |
1837 return; | 1834 return; |
1838 } | 1835 } |
1839 | 1836 |
1840 xfer_data = xfer->data; | 1837 xfer_data = purple_xfer_get_protocol_data(xfer); |
1841 | 1838 |
1842 xfer_data->info_val_249 = val_249; | 1839 xfer_data->info_val_249 = val_249; |
1843 xfer_data->xfer_idstring_for_relay = g_strdup(xfer_idstring_for_relay); | 1840 xfer_data->xfer_idstring_for_relay = g_strdup(xfer_idstring_for_relay); |
1844 if(val_249 == 1 || val_249 == 3) { | 1841 if(val_249 == 1 || val_249 == 3) { |
1845 PurpleAccount *account; | 1842 PurpleAccount *account; |
1852 | 1849 |
1853 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15, | 1850 pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15, |
1854 YAHOO_STATUS_AVAILABLE, yd->session_id); | 1851 YAHOO_STATUS_AVAILABLE, yd->session_id); |
1855 yahoo_packet_hash(pkt_to_send, "ssssis", | 1852 yahoo_packet_hash(pkt_to_send, "ssssis", |
1856 1, purple_normalize(account, purple_account_get_username(account)), | 1853 1, purple_normalize(account, purple_account_get_username(account)), |
1857 5, xfer->who, | 1854 5, purple_xfer_get_remote_user(xfer), |
1858 265, xfer_data->xfer_peer_idstring, | 1855 265, xfer_data->xfer_peer_idstring, |
1859 27, xfer->filename, | 1856 27, purple_xfer_get_filename(xfer), |
1860 249, xfer_data->info_val_249, | 1857 249, xfer_data->info_val_249, |
1861 251, xfer_data->xfer_idstring_for_relay); | 1858 251, xfer_data->xfer_idstring_for_relay); |
1862 | 1859 |
1863 yahoo_packet_send_and_free(pkt_to_send, yd); | 1860 yahoo_packet_send_and_free(pkt_to_send, yd); |
1864 | 1861 |
1868 _("Unable to establish file descriptor.")); | 1865 _("Unable to establish file descriptor.")); |
1869 purple_xfer_cancel_remote(xfer); | 1866 purple_xfer_cancel_remote(xfer); |
1870 } | 1867 } |
1871 } | 1868 } |
1872 else if(val_249 == 2) { | 1869 else if(val_249 == 2) { |
1873 p2p_data = g_hash_table_lookup(yd->peers, xfer->who); | 1870 p2p_data = g_hash_table_lookup(yd->peers, purple_xfer_get_remote_user(xfer)); |
1874 if( !( p2p_data && (p2p_data->connection_type == YAHOO_P2P_WE_ARE_SERVER) ) ) { | 1871 if( !( p2p_data && (p2p_data->connection_type == YAHOO_P2P_WE_ARE_SERVER) ) ) { |
1875 purple_xfer_cancel_remote(xfer); | 1872 purple_xfer_cancel_remote(xfer); |
1876 return; | 1873 return; |
1877 } | 1874 } |
1878 if(!purple_network_listen_range(0, 0, SOCK_STREAM, yahoo_p2p_ft_server_listen_cb, xfer)) { | 1875 if(!purple_network_listen_range(0, 0, AF_UNSPEC, SOCK_STREAM, TRUE, yahoo_p2p_ft_server_listen_cb, xfer)) { |
1879 purple_xfer_cancel_remote(xfer); | 1876 purple_xfer_cancel_remote(xfer); |
1880 return; | 1877 return; |
1881 } | 1878 } |
1882 } | 1879 } |
1883 } | 1880 } |
1894 PurpleAccount *account; | 1891 PurpleAccount *account; |
1895 long val_66 = 0; | 1892 long val_66 = 0; |
1896 gchar *url = NULL; | 1893 gchar *url = NULL; |
1897 int val_249 = 0; | 1894 int val_249 = 0; |
1898 | 1895 |
1899 yd = gc->proto_data; | 1896 yd = purple_connection_get_protocol_data(gc); |
1900 for (l = pkt->hash; l; l = l->next) { | 1897 for (l = pkt->hash; l; l = l->next) { |
1901 struct yahoo_pair *pair = l->data; | 1898 struct yahoo_pair *pair = l->data; |
1902 | 1899 |
1903 switch (pair->key) { | 1900 switch (pair->key) { |
1904 case 251: | 1901 case 251: |
1932 { | 1929 { |
1933 purple_xfer_cancel_remote(xfer); | 1930 purple_xfer_cancel_remote(xfer); |
1934 return; | 1931 return; |
1935 } | 1932 } |
1936 | 1933 |
1937 xfer_data = xfer->data; | 1934 xfer_data = purple_xfer_get_protocol_data(xfer); |
1938 if(url) | 1935 if(url) |
1939 purple_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL); | 1936 purple_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL); |
1940 | 1937 |
1941 xfer_data->xfer_idstring_for_relay = g_strdup(xfer_idstring_for_relay); | 1938 xfer_data->xfer_idstring_for_relay = g_strdup(xfer_idstring_for_relay); |
1942 xfer_data->status_15 = ACCEPTED; | 1939 xfer_data->status_15 = ACCEPTED; |