Mercurial > pidgin
comparison src/ft.c @ 4150:1bd663beada5
[gaim-migrate @ 4369]
potato chip
file receive in msn
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Sat, 28 Dec 2002 05:15:43 +0000 |
parents | a20bf3d247ff |
children | d3c8d2b40494 |
comparison
equal
deleted
inserted
replaced
4149:baf9d94e0128 | 4150:1bd663beada5 |
---|---|
569 static void ft_callback(gpointer data, gint source, | 569 static void ft_callback(gpointer data, gint source, |
570 GaimInputCondition condition) | 570 GaimInputCondition condition) |
571 { | 571 { |
572 struct file_transfer *xfer = (struct file_transfer *)data; | 572 struct file_transfer *xfer = (struct file_transfer *)data; |
573 int rt, i; | 573 int rt, i; |
574 char buf[FT_BUFFER_SIZE]; | 574 char *buf = NULL; |
575 | 575 |
576 if (condition & GAIM_INPUT_READ) { | 576 if (condition & GAIM_INPUT_READ) { |
577 rt = read(xfer->fd, buf, MIN(xfer->bytesleft, FT_BUFFER_SIZE)); | 577 if (xfer->gc->prpl->file_transfer_read) |
578 rt = xfer->gc->prpl->file_transfer_read(xfer->gc, xfer, | |
579 xfer->fd, &buf); | |
580 else { | |
581 buf = g_new0(char, MIN(xfer->bytesleft, FT_BUFFER_SIZE)); | |
582 rt = read(xfer->fd, buf, MIN(xfer->bytesleft, FT_BUFFER_SIZE)); | |
583 } | |
584 | |
578 /* XXX What if the transfer is interrupted while we | 585 /* XXX What if the transfer is interrupted while we |
579 * are inside read()? How can this be handled safely? | 586 * are inside read()? How can this be handled safely? |
580 * -- wtm | 587 * -- wtm |
581 */ | 588 */ |
582 if (rt > 0) { | 589 if (rt > 0) { |
583 xfer->bytesleft -= rt; | 590 xfer->bytesleft -= rt; |
584 for (i = 0; i < rt; i++) { | 591 fwrite(buf, 1, rt, xfer->file); |
585 fprintf(xfer->file, "%c", buf[i]); | |
586 } | |
587 } | 592 } |
588 | 593 |
589 } | 594 } |
590 else /* (condition & GAIM_INPUT_WRITE) */ { | 595 else /* (condition & GAIM_INPUT_WRITE) */ { |
591 int remain = MIN(xfer->bytesleft, FT_BUFFER_SIZE); | 596 int remain = MIN(xfer->bytesleft, FT_BUFFER_SIZE); |
592 | 597 |
593 for (i = 0; i < remain; i++) | 598 buf = g_new0(char, remain); |
594 fscanf(xfer->file, "%c", &buf[i]); | 599 |
595 | 600 fread(buf, 1, remain, xfer->file); |
596 rt = write(xfer->fd, buf, remain); | 601 |
602 if (xfer->gc->prpl->file_transfer_write) | |
603 rt = xfer->gc->prpl->file_transfer_write(xfer->gc, xfer, xfer->fd, | |
604 buf, remain); | |
605 else | |
606 rt = write(xfer->fd, buf, remain); | |
607 | |
597 if (rt > 0) | 608 if (rt > 0) |
598 xfer->bytesleft -= rt; | 609 xfer->bytesleft -= rt; |
599 } | 610 } |
600 | 611 |
601 if (rt < 0) | 612 if (rt < 0) { |
613 if (buf != NULL) | |
614 g_free(buf); | |
615 | |
602 return; | 616 return; |
617 } | |
603 | 618 |
604 xfer->bytessent += rt; | 619 xfer->bytessent += rt; |
605 | 620 |
606 if (xfer->gc->prpl->file_transfer_data_chunk) | 621 if (xfer->gc->prpl->file_transfer_data_chunk) |
607 xfer->gc->prpl->file_transfer_data_chunk(xfer->gc, xfer, buf, rt); | 622 xfer->gc->prpl->file_transfer_data_chunk(xfer->gc, xfer, buf, rt); |
612 xfer->watcher = 0; | 627 xfer->watcher = 0; |
613 fclose(xfer->file); | 628 fclose(xfer->file); |
614 xfer->file = 0; | 629 xfer->file = 0; |
615 ft_nextfile(xfer); | 630 ft_nextfile(xfer); |
616 } | 631 } |
632 | |
633 if (buf != NULL) | |
634 g_free(buf); | |
617 } | 635 } |
618 | 636 |
619 static void ft_nextfile(struct file_transfer *xfer) | 637 static void ft_nextfile(struct file_transfer *xfer) |
620 { | 638 { |
621 debug_printf("file transfer %d of %d done\n", | 639 debug_printf("file transfer %d of %d done\n", |