diff options
Diffstat (limited to 'src/irc/dcc/dcc-get.c')
-rw-r--r-- | src/irc/dcc/dcc-get.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/irc/dcc/dcc-get.c b/src/irc/dcc/dcc-get.c index 8eee81b3..73c1b864 100644 --- a/src/irc/dcc/dcc-get.c +++ b/src/irc/dcc/dcc-get.c @@ -30,6 +30,8 @@ #include "dcc-get.h" #include "dcc-send.h" +static char *dcc_get_recv_buffer; + GET_DCC_REC *dcc_get_create(IRC_SERVER_REC *server, CHAT_DCC_REC *chat, const char *nick, const char *arg) { @@ -139,14 +141,20 @@ static void sig_dccget_send(GET_DCC_REC *dcc) dcc_get_send_received(dcc); } +#define DCC_GET_RECV_BUFFER_SIZE 32768 + /* input function: DCC GET received data */ static void sig_dccget_receive(GET_DCC_REC *dcc) { - char buffer[512]; int ret; + if (dcc_get_recv_buffer == NULL) { + dcc_get_recv_buffer = g_malloc(DCC_GET_RECV_BUFFER_SIZE); + } + for (;;) { - ret = net_receive(dcc->handle, buffer, sizeof(buffer)); + ret = net_receive(dcc->handle, dcc_get_recv_buffer, + DCC_GET_RECV_BUFFER_SIZE); if (ret == 0) break; if (ret < 0) { @@ -156,7 +164,7 @@ static void sig_dccget_receive(GET_DCC_REC *dcc) return; } - if (write(dcc->fhandle, buffer, ret) != ret) { + if (write(dcc->fhandle, dcc_get_recv_buffer, ret) != ret) { /* most probably out of disk space */ signal_emit("dcc error write", 2, dcc, g_strerror(errno)); @@ -226,6 +234,8 @@ void sig_dccget_connected(GET_DCC_REC *dcc) else ret = fchmod(temphandle, dcc_file_create_mode); + close(temphandle); + if (ret != -1) { ret = link(tempfname, dcc->file); @@ -249,7 +259,6 @@ void sig_dccget_connected(GET_DCC_REC *dcc) /* close/remove the temp file */ ret_errno = errno; - close(temphandle); unlink(tempfname); g_free(tempfname); @@ -422,7 +431,7 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data, /* SEND <file name> <address> <port> <size> [...] */ /* SEND <file name> <address> 0 <size> <id> (DCC SEND passive protocol) */ params = g_strsplit(data, " ", -1); - paramcount = strarray_length(params); + paramcount = g_strv_length(params); if (paramcount < 4) { signal_emit("dcc error ctcp", 5, "SEND", data, @@ -454,7 +463,7 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data, g_memmove(fname, fname+1, len); quoted = TRUE; } - + if (passive && port != 0) { /* This is NOT a DCC SEND request! This is a reply to our passive request. We MUST check the IDs and then connect to @@ -472,8 +481,8 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data, net_ip2host(&temp_dcc->addr, temp_dcc->addrstr); else { /* with IPv6, show it to us as it was sent */ - strocpy(temp_dcc->addrstr, address, - sizeof(temp_dcc->addrstr)); + g_strlcpy(temp_dcc->addrstr, address, + sizeof(temp_dcc->addrstr)); } /* This new signal is added to let us invoke @@ -501,13 +510,13 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data, if (passive && port == 0) dcc->pasv_id = p_id; /* Assign the ID to the DCC */ - + memcpy(&dcc->addr, &ip, sizeof(ip)); if (dcc->addr.family == AF_INET) net_ip2host(&dcc->addr, dcc->addrstr); else { /* with IPv6, show it to us as it was sent */ - strocpy(dcc->addrstr, address, sizeof(dcc->addrstr)); + g_strlcpy(dcc->addrstr, address, sizeof(dcc->addrstr)); } dcc->port = port; dcc->size = size; @@ -525,14 +534,14 @@ void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept_func, { GET_DCC_REC *dcc; GSList *tmp, *next; - char *nick, *fname; + char *nick, *arg, *fname; void *free_arg; int found; g_return_if_fail(data != NULL); - if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, - &nick, &fname)) + if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | + PARAM_FLAG_STRIP_TRAILING_WS, &nick, &arg)) return; if (*nick == '\0') { @@ -547,6 +556,8 @@ void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept_func, return; } + fname = cmd_get_quoted_param(&arg); + found = FALSE; for (tmp = dcc_conns; tmp != NULL; tmp = next) { GET_DCC_REC *dcc = tmp->data; @@ -554,7 +565,7 @@ void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept_func, next = tmp->next; if (IS_DCC_GET(dcc) && g_ascii_strcasecmp(dcc->nick, nick) == 0 && (dcc_is_waiting_user(dcc) || dcc->from_dccserver) && - (*fname == '\0' || strcmp(dcc->arg, fname) == 0)) { + (*fname == '\0' || g_strcmp0(dcc->arg, fname) == 0)) { found = TRUE; if (!dcc_is_passive(dcc)) accept_func(dcc); @@ -593,4 +604,5 @@ void dcc_get_deinit(void) signal_remove("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed); signal_remove("ctcp msg dcc send", (SIGNAL_FUNC) ctcp_msg_dcc_send); command_unbind("dcc get", (SIGNAL_FUNC) cmd_dcc_get); + g_free_and_null(dcc_get_recv_buffer); } |