Mercurial > pidgin.yaz
comparison libpurple/protocols/yahoo/yahoo_filexfer.c @ 32799:5bd5e024c977
Yahoo: Use file-transfer accessor functions.
author | andrew.victor@mxit.com |
---|---|
date | Sun, 30 Oct 2011 16:00:14 +0000 |
parents | 2ec94166be43 |
children | 4a34689eeb33 |
comparison
equal
deleted
inserted
replaced
32798:c7a6b7b6c32f | 32799:5bd5e024c977 |
---|---|
167 purple_xfer_get_remote_user(xfer), _("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 gchar *header = 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); |
248 purple_xfer_get_remote_user(xfer), _("Unable to connect.")); | 248 purple_xfer_get_remote_user(xfer), _("Unable to connect.")); |
249 purple_xfer_cancel_remote(xfer); | 249 purple_xfer_cancel_remote(xfer); |
250 return; | 250 return; |
251 } | 251 } |
252 | 252 |
253 xfer->fd = source; | 253 purple_xfer_set_fd(xfer, source); |
254 | 254 |
255 /* Assemble the tx buffer */ | 255 /* Assemble the tx buffer */ |
256 gc = xd->gc; | 256 gc = xd->gc; |
257 account = purple_connection_get_account(gc); | 257 account = purple_connection_get_account(gc); |
258 yd = purple_connection_get_protocol_data(gc); | 258 yd = purple_connection_get_protocol_data(gc); |
338 _("Unable to establish file descriptor.")); | 338 _("Unable to establish file descriptor.")); |
339 purple_xfer_cancel_remote(xfer); | 339 purple_xfer_cancel_remote(xfer); |
340 } | 340 } |
341 } | 341 } |
342 } else { | 342 } else { |
343 xfer->fd = -1; | 343 purple_xfer_set_fd(xfer, -1); |
344 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, |
345 yahoo_receivefile_connected, xfer) == NULL) { | 345 yahoo_receivefile_connected, xfer) == NULL) { |
346 purple_notify_error(gc, NULL, _("File Transfer Failed"), | 346 purple_notify_error(gc, NULL, _("File Transfer Failed"), |
347 _("Unable to establish file descriptor.")); | 347 _("Unable to establish file descriptor.")); |
348 purple_xfer_cancel_remote(xfer); | 348 purple_xfer_cancel_remote(xfer); |
435 | 435 |
436 if (purple_xfer_get_type(xfer) != PURPLE_XFER_RECEIVE) { | 436 if (purple_xfer_get_type(xfer) != PURPLE_XFER_RECEIVE) { |
437 return 0; | 437 return 0; |
438 } | 438 } |
439 | 439 |
440 len = read(xfer->fd, buf, sizeof(buf)); | 440 len = read(purple_xfer_get_fd(xfer), buf, sizeof(buf)); |
441 | 441 |
442 if (len <= 0) { | 442 if (len <= 0) { |
443 if ((purple_xfer_get_size(xfer) > 0) && | 443 if ((purple_xfer_get_size(xfer) > 0) && |
444 (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer))) { | 444 (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer))) { |
445 purple_xfer_set_completed(xfer, TRUE); | 445 purple_xfer_set_completed(xfer, TRUE); |
498 | 498 |
499 if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) { | 499 if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) { |
500 return -1; | 500 return -1; |
501 } | 501 } |
502 | 502 |
503 len = write(xfer->fd, buffer, size); | 503 len = write(purple_xfer_get_fd(xfer), buffer, size); |
504 | 504 |
505 if (len == -1) { | 505 if (len == -1) { |
506 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)) |
507 purple_xfer_set_completed(xfer, TRUE); | 507 purple_xfer_set_completed(xfer, TRUE); |
508 if ((errno != EAGAIN) && (errno != EINTR)) | 508 if ((errno != EAGAIN) && (errno != EINTR)) |
610 /* Send HTTP OK after receiving file */ | 610 /* Send HTTP OK after receiving file */ |
611 static void yahoo_p2p_ft_server_send_OK(PurpleXfer *xfer) | 611 static void yahoo_p2p_ft_server_send_OK(PurpleXfer *xfer) |
612 { | 612 { |
613 char *tx = NULL; | 613 char *tx = NULL; |
614 int written; | 614 int written; |
615 int fd = purple_xfer_get_fd(xfer); | |
615 | 616 |
616 tx = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: application/octet-stream\r\nConnection: close\r\n\r\n"; | 617 tx = "HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: application/octet-stream\r\nConnection: close\r\n\r\n"; |
617 written = write(xfer->fd, tx, strlen(tx)); | 618 written = write(fd, tx, strlen(tx)); |
618 | 619 |
619 if (written < 0 && errno == EAGAIN) | 620 if (written < 0 && errno == EAGAIN) |
620 written = 0; | 621 written = 0; |
621 else if (written <= 0) | 622 else if (written <= 0) |
622 purple_debug_info("yahoo", "p2p filetransfer: Unable to write HTTP OK"); | 623 purple_debug_info("yahoo", "p2p filetransfer: Unable to write HTTP OK"); |
623 | 624 |
624 /* close connection */ | 625 /* close connection */ |
625 close(xfer->fd); | 626 close(fd); |
626 xfer->fd = -1; | 627 purple_xfer_set_fd(xfer, -1); |
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; |
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 ); |
1193 yahoo_xfer_recv_cb_15(xfer, source, PURPLE_INPUT_READ); | 1194 yahoo_xfer_recv_cb_15(xfer, source, PURPLE_INPUT_READ); |
1194 } | 1195 } |
1195 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) |
1196 { | 1197 { |
1197 xd->status_15 = TRANSFER_PHASE; | 1198 xd->status_15 = TRANSFER_PHASE; |
1198 xfer->fd = source; | 1199 purple_xfer_set_fd(xfer, source); |
1199 purple_xfer_start(xfer, source, NULL, 0); | 1200 purple_xfer_start(xfer, source, NULL, 0); |
1200 } | 1201 } |
1201 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) ) |
1202 { | 1203 { |
1203 xd->status_15 = TRANSFER_PHASE; | 1204 xd->status_15 = TRANSFER_PHASE; |
1204 xfer->fd = source; | 1205 purple_xfer_set_fd(xfer, source); |
1205 /* Remove Read event */ | 1206 /* Remove Read event */ |
1206 purple_input_remove(xd->input_event); | 1207 purple_input_remove(xd->input_event); |
1207 xd->input_event = 0; | 1208 xd->input_event = 0; |
1208 purple_xfer_start(xfer, source, NULL, 0); | 1209 purple_xfer_start(xfer, source, NULL, 0); |
1209 } | 1210 } |
1212 xd->status_15 = P2P_HEAD_REPLIED; | 1213 xd->status_15 = P2P_HEAD_REPLIED; |
1213 /* Remove Read event and close descriptor */ | 1214 /* Remove Read event and close descriptor */ |
1214 purple_input_remove(xd->input_event); | 1215 purple_input_remove(xd->input_event); |
1215 xd->input_event = 0; | 1216 xd->input_event = 0; |
1216 close(source); | 1217 close(source); |
1217 xfer->fd = -1; | 1218 purple_xfer_set_fd(xfer, -1); |
1218 /* start local server, listen for connections */ | 1219 /* start local server, listen for connections */ |
1219 purple_network_listen(xd->yahoo_local_p2p_ft_server_port, AF_UNSPEC, SOCK_STREAM, TRUE, 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); |
1220 } | 1221 } |
1221 else | 1222 else |
1222 { | 1223 { |
1375 return; | 1376 return; |
1376 } | 1377 } |
1377 | 1378 |
1378 purple_input_remove(xd->input_event); | 1379 purple_input_remove(xd->input_event); |
1379 xd->status_15 = TRANSFER_PHASE; | 1380 xd->status_15 = TRANSFER_PHASE; |
1380 xfer->fd = source; | 1381 purple_xfer_set_fd(xfer, source); |
1381 purple_xfer_start(xfer, source, NULL, 0); | 1382 purple_xfer_start(xfer, source, NULL, 0); |
1382 } | 1383 } |
1383 | 1384 |
1384 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) |
1385 { | 1386 { |
1476 /* remove watcher and close p2p ft server */ | 1477 /* remove watcher and close p2p ft server */ |
1477 purple_input_remove(xd->yahoo_p2p_ft_server_watcher); | 1478 purple_input_remove(xd->yahoo_p2p_ft_server_watcher); |
1478 close(xd->yahoo_local_p2p_ft_server_fd); | 1479 close(xd->yahoo_local_p2p_ft_server_fd); |
1479 | 1480 |
1480 /* Add an Input Read event to the file descriptor */ | 1481 /* Add an Input Read event to the file descriptor */ |
1481 xfer->fd = acceptfd; | 1482 purple_xfer_set_fd(xfer, acceptfd); |
1482 if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) | 1483 if(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) |
1483 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); |
1484 else | 1485 else |
1485 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); |
1486 } | 1487 } |