Mercurial > pidgin
comparison src/protocols/yahoo/yahoo_filexfer.c @ 11644:f4e58e94ced3
[gaim-migrate @ 13922]
Yahoo! whitespace cleanup from Peter Lawler
Gracias!
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 12 Oct 2005 04:02:46 +0000 |
parents | 7fab28c991f3 |
children | 81806e9241be |
comparison
equal
deleted
inserted
replaced
11643:eb14bbcf7249 | 11644:f4e58e94ced3 |
---|---|
30 #include "yahoo.h" | 30 #include "yahoo.h" |
31 #include "yahoo_packet.h" | 31 #include "yahoo_packet.h" |
32 #include "yahoo_filexfer.h" | 32 #include "yahoo_filexfer.h" |
33 #include "yahoo_doodle.h" | 33 #include "yahoo_doodle.h" |
34 | 34 |
35 | |
36 | |
37 struct yahoo_xfer_data { | 35 struct yahoo_xfer_data { |
38 gchar *host; | 36 gchar *host; |
39 gchar *path; | 37 gchar *path; |
40 int port; | 38 int port; |
41 GaimConnection *gc; | 39 GaimConnection *gc; |
106 | 104 |
107 gc = xd->gc; | 105 gc = xd->gc; |
108 account = gaim_connection_get_account(gc); | 106 account = gaim_connection_get_account(gc); |
109 yd = gc->proto_data; | 107 yd = gc->proto_data; |
110 | 108 |
111 | |
112 | |
113 if (source < 0) { | 109 if (source < 0) { |
114 gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), | 110 gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), |
115 xfer->who, _("Unable to connect.")); | 111 xfer->who, _("Unable to connect.")); |
116 gaim_xfer_cancel_remote(xfer); | 112 gaim_xfer_cancel_remote(xfer); |
117 return; | 113 return; |
118 } | 114 } |
119 | 115 |
120 xfer->fd = source; | 116 xfer->fd = source; |
121 gaim_xfer_start(xfer, source, NULL, 0); | 117 gaim_xfer_start(xfer, source, NULL, 0); |
122 | 118 |
123 | |
124 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, YAHOO_STATUS_AVAILABLE, yd->session_id); | 119 pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, YAHOO_STATUS_AVAILABLE, yd->session_id); |
125 | 120 |
126 size = g_strdup_printf("%" G_GSIZE_FORMAT, gaim_xfer_get_size(xfer)); | 121 size = g_strdup_printf("%" G_GSIZE_FORMAT, gaim_xfer_get_size(xfer)); |
127 filename = g_path_get_basename(gaim_xfer_get_local_filename(xfer)); | 122 filename = g_path_get_basename(gaim_xfer_get_local_filename(xfer)); |
128 encoded_filename = yahoo_string_encode(gc, filename, NULL); | 123 encoded_filename = yahoo_string_encode(gc, filename, NULL); |
129 | 124 |
130 yahoo_packet_hash(pkt, "sssss", 0, gaim_connection_get_display_name(gc), | 125 yahoo_packet_hash(pkt, "sssss", 0, gaim_connection_get_display_name(gc), |
131 5, xfer->who, 14, "", 27, encoded_filename, 28, size); | 126 5, xfer->who, 14, "", 27, encoded_filename, 28, size); |
132 | 127 |
133 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); | 128 content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); |
134 | 129 |
139 post = g_strdup_printf("POST http://%s:%d/notifyft HTTP/1.0\r\n" | 134 post = g_strdup_printf("POST http://%s:%d/notifyft HTTP/1.0\r\n" |
140 "Content-length: %" G_GSIZE_FORMAT "\r\n" | 135 "Content-length: %" G_GSIZE_FORMAT "\r\n" |
141 "Host: %s:%d\r\n" | 136 "Host: %s:%d\r\n" |
142 "Cookie: %s\r\n" | 137 "Cookie: %s\r\n" |
143 "\r\n", | 138 "\r\n", |
144 host, port, content_length + 4 + gaim_xfer_get_size(xfer), host, port, buf); | 139 host, port, content_length + 4 + gaim_xfer_get_size(xfer), |
140 host, port, buf); | |
145 write(xfer->fd, post, strlen(post)); | 141 write(xfer->fd, post, strlen(post)); |
146 | 142 |
147 yahoo_packet_send_special(pkt, xfer->fd, 8); | 143 yahoo_packet_send_special(pkt, xfer->fd, 8); |
148 yahoo_packet_free(pkt); | 144 yahoo_packet_free(pkt); |
149 | 145 |
210 struct yahoo_xfer_data *xfer_data; | 206 struct yahoo_xfer_data *xfer_data; |
211 | 207 |
212 account = gaim_xfer_get_account(xfer); | 208 account = gaim_xfer_get_account(xfer); |
213 xfer_data = xfer->data; | 209 xfer_data = xfer->data; |
214 | 210 |
215 | |
216 if (xfer_data) | 211 if (xfer_data) |
217 yahoo_xfer_data_free(xfer_data); | 212 yahoo_xfer_data_free(xfer_data); |
218 xfer->data = NULL; | 213 xfer->data = NULL; |
219 | 214 |
220 } | 215 } |
228 continue; | 223 continue; |
229 return strtol(l + i, NULL, 10); | 224 return strtol(l + i, NULL, 10); |
230 } | 225 } |
231 return 0; | 226 return 0; |
232 } | 227 } |
233 | |
234 | 228 |
235 ssize_t yahoo_xfer_read(guchar **buffer, GaimXfer *xfer) | 229 ssize_t yahoo_xfer_read(guchar **buffer, GaimXfer *xfer) |
236 { | 230 { |
237 gchar buf[4096]; | 231 gchar buf[4096]; |
238 ssize_t len; | 232 ssize_t len; |
254 gaim_xfer_set_completed(xfer, TRUE); | 248 gaim_xfer_set_completed(xfer, TRUE); |
255 return 0; | 249 return 0; |
256 } else | 250 } else |
257 return -1; | 251 return -1; |
258 } | 252 } |
259 | |
260 | 253 |
261 if (!xd->started) { | 254 if (!xd->started) { |
262 xd->rxqueue = g_realloc(xd->rxqueue, len + xd->rxlen); | 255 xd->rxqueue = g_realloc(xd->rxqueue, len + xd->rxlen); |
263 memcpy(xd->rxqueue + xd->rxlen, buf, len); | 256 memcpy(xd->rxqueue + xd->rxlen, buf, len); |
264 xd->rxlen += len; | 257 xd->rxlen += len; |
353 } | 346 } |
354 | 347 |
355 void yahoo_process_p2pfilexfer( GaimConnection *gc, struct yahoo_packet *pkt ) | 348 void yahoo_process_p2pfilexfer( GaimConnection *gc, struct yahoo_packet *pkt ) |
356 { | 349 { |
357 GSList *l = pkt->hash; | 350 GSList *l = pkt->hash; |
358 | 351 |
359 char *me = NULL; | 352 char *me = NULL; |
360 char *from = NULL; | 353 char *from = NULL; |
361 char *service = NULL; | 354 char *service = NULL; |
362 char *message = NULL; | 355 char *message = NULL; |
363 char *command = NULL; | 356 char *command = NULL; |
364 char *imv = NULL; | 357 char *imv = NULL; |
365 char *unknown = NULL; | 358 char *unknown = NULL; |
366 | 359 |
367 // Get all the necessary values from this new packet | 360 // Get all the necessary values from this new packet |
368 while( l ) | 361 while( l ) |
369 { | 362 { |
370 struct yahoo_pair *pair = l->data; | 363 struct yahoo_pair *pair = l->data; |
371 | 364 |
372 if( pair->key == 5 ) // Get who the packet is for | 365 if( pair->key == 5 ) // Get who the packet is for |
373 me = pair->value; | 366 me = pair->value; |
374 | 367 |
375 if( pair->key == 4 ) // Get who the packet is from | 368 if( pair->key == 4 ) // Get who the packet is from |
376 from = pair->value; | 369 from = pair->value; |
377 | 370 |
378 if( pair->key == 49 ) // Get the type of service | 371 if( pair->key == 49 ) // Get the type of service |
379 service = pair->value; | 372 service = pair->value; |
380 | 373 |
381 if( pair->key == 14 ) // Get the 'message' of the packet | 374 if( pair->key == 14 ) // Get the 'message' of the packet |
382 message = pair->value; | 375 message = pair->value; |
383 | 376 |
384 if( pair->key == 13 ) // Get the command associated with this packet | 377 if( pair->key == 13 ) // Get the command associated with this packet |
385 command = pair->value; | 378 command = pair->value; |
386 | 379 |
387 if( pair->key == 63 ) // IMVironment name and version | 380 if( pair->key == 63 ) // IMVironment name and version |
388 imv = pair->value; | 381 imv = pair->value; |
389 | 382 |
390 if( pair->key == 64 ) // Not sure, but it does vary with initialization of Doodle | 383 if( pair->key == 64 ) // Not sure, but it does vary with initialization of Doodle |
391 unknown = pair->value; // So, I'll keep it (for a little while atleast) | 384 unknown = pair->value; // So, I'll keep it (for a little while atleast) |
392 | 385 |
393 l = l->next; | 386 l = l->next; |
394 } | 387 } |
395 | 388 |
396 // If this packet is an IMVIRONMENT, handle it accordingly | 389 // If this packet is an IMVIRONMENT, handle it accordingly |
397 if( !strcmp( service, "IMVIRONMENT" ) ) | 390 if( !strcmp( service, "IMVIRONMENT" ) ) |
398 { | 391 { |
399 // Check for a Doodle packet and handle it accordingly | 392 // Check for a Doodle packet and handle it accordingly |
400 if( !strcmp( imv, "doodle;11" ) ) | 393 if( !strcmp( imv, "doodle;11" ) ) |
401 yahoo_doodle_process( gc, me, from, command, message ); | 394 yahoo_doodle_process( gc, me, from, command, message ); |
402 | 395 |
403 // If an IMVIRONMENT packet comes without a specific imviroment name | 396 // If an IMVIRONMENT packet comes without a specific imviroment name |
404 if( !strcmp( imv, ";0" ) ) | 397 if( !strcmp( imv, ";0" ) ) |
405 { | 398 { |
406 // It is unfortunately time to close all IMVironments with remote client | 399 // It is unfortunately time to close all IMVironments with remote client |
407 yahoo_doodle_command_got_shutdown( gc, from ); | 400 yahoo_doodle_command_got_shutdown( gc, from ); |
408 } | 401 } |
409 | |
410 } | 402 } |
411 } | 403 } |
412 | 404 |
413 void yahoo_process_filetransfer(GaimConnection *gc, struct yahoo_packet *pkt) | 405 void yahoo_process_filetransfer(GaimConnection *gc, struct yahoo_packet *pkt) |
414 { | 406 { |
417 char *msg = NULL; | 409 char *msg = NULL; |
418 char *url = NULL; | 410 char *url = NULL; |
419 long expires = 0; | 411 long expires = 0; |
420 GaimXfer *xfer; | 412 GaimXfer *xfer; |
421 struct yahoo_xfer_data *xfer_data; | 413 struct yahoo_xfer_data *xfer_data; |
422 | |
423 char *service = NULL; | 414 char *service = NULL; |
424 | |
425 char *filename = NULL; | 415 char *filename = NULL; |
426 unsigned long filesize = 0L; | 416 unsigned long filesize = 0L; |
427 | |
428 GSList *l; | 417 GSList *l; |
429 | 418 |
430 for (l = pkt->hash; l; l = l->next) { | 419 for (l = pkt->hash; l; l = l->next) { |
431 struct yahoo_pair *pair = l->data; | 420 struct yahoo_pair *pair = l->data; |
432 | 421 |
438 msg = pair->value; | 427 msg = pair->value; |
439 if (pair->key == 20) | 428 if (pair->key == 20) |
440 url = pair->value; | 429 url = pair->value; |
441 if (pair->key == 38) | 430 if (pair->key == 38) |
442 expires = strtol(pair->value, NULL, 10); | 431 expires = strtol(pair->value, NULL, 10); |
443 | |
444 if (pair->key == 27) | 432 if (pair->key == 27) |
445 filename = pair->value; | 433 filename = pair->value; |
446 if (pair->key == 28) | 434 if (pair->key == 28) |
447 filesize = atol(pair->value); | 435 filesize = atol(pair->value); |
448 | |
449 if (pair->key == 49) | 436 if (pair->key == 49) |
450 service = pair->value; | 437 service = pair->value; |
451 } | 438 } |
452 | 439 |
453 if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { | 440 if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { |
464 *tmp = '\0'; | 451 *tmp = '\0'; |
465 } | 452 } |
466 | 453 |
467 if (!url || !from) | 454 if (!url || !from) |
468 return; | 455 return; |
469 | |
470 | 456 |
471 /* Setup the Yahoo-specific file transfer data */ | 457 /* Setup the Yahoo-specific file transfer data */ |
472 xfer_data = g_new0(struct yahoo_xfer_data, 1); | 458 xfer_data = g_new0(struct yahoo_xfer_data, 1); |
473 xfer_data->gc = gc; | 459 xfer_data->gc = gc; |
474 if (!gaim_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) { | 460 if (!gaim_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) { |
529 return; | 515 return; |
530 | 516 |
531 xfer_data = g_new0(struct yahoo_xfer_data, 1); | 517 xfer_data = g_new0(struct yahoo_xfer_data, 1); |
532 xfer_data->gc = gc; | 518 xfer_data->gc = gc; |
533 | 519 |
534 | |
535 /* Build the file transfer handle. */ | 520 /* Build the file transfer handle. */ |
536 xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who); | 521 xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who); |
537 xfer->data = xfer_data; | 522 xfer->data = xfer_data; |
538 | 523 |
539 /* Setup our I/O op functions */ | 524 /* Setup our I/O op functions */ |