X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Frecv.c;h=9d27fb7f3647dc3e0cc422c7e149b38f491a9833;hp=e444a6d077874338067f2583d7ae21521e986a64;hb=309b87a3d8b8835d403c5455b436abe6c4adfb74;hpb=036b63d8fc5a8c6e1ff150737226122c174c39cb diff --git a/src/recv.c b/src/recv.c index e444a6d07..9d27fb7f3 100644 --- a/src/recv.c +++ b/src/recv.c @@ -33,7 +33,10 @@ #define BUFFSIZE 8192 -gint recv_write_to_file(gint sock, const gchar *filename) +static RecvUIFunc recv_ui_func; +static gpointer recv_ui_func_data; + +gint recv_write_to_file(SockInfo *sock, const gchar *filename) { FILE *fp; @@ -63,7 +66,7 @@ gint recv_write_to_file(gint sock, const gchar *filename) return 0; } -gint recv_bytes_write_to_file(gint sock, glong size, const gchar *filename) +gint recv_bytes_write_to_file(SockInfo *sock, glong size, const gchar *filename) { FILE *fp; @@ -93,7 +96,7 @@ gint recv_bytes_write_to_file(gint sock, glong size, const gchar *filename) return 0; } -gint recv_write(gint sock, FILE *fp) +gint recv_write(SockInfo *sock, FILE *fp) { gchar buf[BUFFSIZE]; gint len; @@ -115,13 +118,17 @@ gint recv_write(gint sock, FILE *fp) if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') { buf[len - 2] = '\n'; buf[len - 1] = '\0'; + len--; } if (buf[0] == '.' && buf[1] == '.') - memmove(buf, buf + 1, strlen(buf)); + memmove(buf, buf + 1, len--); if (!strncmp(buf, ">From ", 6)) - memmove(buf, buf + 1, strlen(buf)); + memmove(buf, buf + 1, len--); + + if (recv_ui_func) + recv_ui_func(sock, len, recv_ui_func_data); if (fp && fputs(buf, fp) == EOF) { perror("fputs"); @@ -137,7 +144,7 @@ gint recv_write(gint sock, FILE *fp) return 0; } -gint recv_bytes_write(gint sock, glong size, FILE *fp) +gint recv_bytes_write(SockInfo *sock, glong size, FILE *fp) { gchar *buf; gboolean nb; @@ -152,7 +159,8 @@ gint recv_bytes_write(gint sock, glong size, FILE *fp) do { size_t read_count; - read_count = read(sock, buf + count, size - count); + /* FIXME: put this into socket.c :WK: */ + read_count = fd_read(sock->sock, buf + count, size - count); if (read_count < 0) { if (nb) sock_set_nonblocking_mode(sock, TRUE); return -1; @@ -186,3 +194,9 @@ gint recv_bytes_write(gint sock, glong size, FILE *fp) if (nb) sock_set_nonblocking_mode(sock, TRUE); return 0; } + +void recv_set_ui_func(RecvUIFunc func, gpointer data) +{ + recv_ui_func = func; + recv_ui_func_data = data; +}