diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-05-07 13:34:04 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-05-07 13:34:04 +0200 |
commit | b0e88590b9910c08b14820618cce86249bea91b4 (patch) | |
tree | c08e10be89b77e6f36eaecfa4c95b1570efa1c37 /src | |
parent | 3751d6565f0e8914528d2fa2f95fd498a269315d (diff) | |
download | weechat-b0e88590b9910c08b14820618cce86249bea91b4.zip |
Xfer file resume (for DCC protocol) is back
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/irc/irc-dcc.c | 47 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 62 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 112 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 5 | ||||
-rw-r--r-- | src/plugins/irc/irc.c | 2 | ||||
-rw-r--r-- | src/plugins/xfer/xfer-buffer.c | 21 | ||||
-rw-r--r-- | src/plugins/xfer/xfer-file.c | 4 | ||||
-rw-r--r-- | src/plugins/xfer/xfer-network.c | 10 | ||||
-rw-r--r-- | src/plugins/xfer/xfer.c | 200 |
9 files changed, 367 insertions, 96 deletions
diff --git a/src/plugins/irc/irc-dcc.c b/src/plugins/irc/irc-dcc.c index 7557941f1..0cd4aab7b 100644 --- a/src/plugins/irc/irc-dcc.c +++ b/src/plugins/irc/irc-dcc.c @@ -47,25 +47,6 @@ struct t_irc_dcc *irc_last_dcc = NULL; /* last DCC in list */ /* - * irc_dcc_chat_remove_channel: remove a buffer for DCC chat - */ - /* -void -irc_dcc_chat_remove_channel (struct t_irc_channel *channel) -{ - struct t_irc_dcc *ptr_dcc; - - if (!channel) - return; - - for (ptr_dcc = irc_dcc_list; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc) - { - if (ptr_dcc->channel == channel) - ptr_dcc->channel = NULL; - } -} -*/ -/* * irc_dcc_accept_resume: accepts a resume and inform the receiver */ /* @@ -105,31 +86,3 @@ irc_dcc_accept_resume (struct t_irc_server *server, char *filename, int port, WEECHAT_ERROR, filename, port, pos_start); } */ -/* - * irc_dcc_start_resume: called when "DCC ACCEPT" is received - * (resume accepted by sender) - */ -/* -void -irc_dcc_start_resume (struct t_irc_server *server, char *filename, int port, - unsigned long pos_start) -{ - struct t_irc_dcc *ptr_dcc; - - ptr_dcc = irc_dcc_search (server, IRC_DCC_FILE_RECV, IRC_DCC_CONNECTING, - port); - if (ptr_dcc) - { - ptr_dcc->pos = pos_start; - ptr_dcc->ack = pos_start; - ptr_dcc->start_resume = pos_start; - ptr_dcc->last_check_pos = pos_start; - irc_dcc_recv_connect_init (ptr_dcc); - } - else - gui_chat_printf (server->buffer, - _("%s can't resume file \"%s\" (port: %d, start " - "position: %u): DCC not found or ended\n"), - WEECHAT_ERROR, filename, port, pos_start); -} -*/ diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 82657b11d..b084cf056 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1742,12 +1742,6 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, char *command, weechat_infolist_free (infolist); } - /* TODO: add DCC file */ - //irc_dcc_add (server, IRC_DCC_FILE_RECV, - // strtoul (pos_addr, NULL, 10), - // atoi (pos_port), nick, -1, pos_file, NULL, - // strtoul (pos_size, NULL, 10)); - weechat_hook_signal_send ("irc_dcc", WEECHAT_HOOK_SIGNAL_STRING, argv_eol[0]); @@ -1827,11 +1821,29 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, char *command, pos--; } pos[1] = '\0'; - - /* TODO: accept DCC resume */ - //irc_dcc_accept_resume (server, pos_file, atoi (pos_port), - // strtoul (pos_start_resume, NULL, 10)); - + + /* accept resume via xfer plugin */ + infolist = weechat_infolist_new (); + if (infolist) + { + item = weechat_infolist_new_item (infolist); + if (item) + { + weechat_infolist_new_var_string (item, "plugin_name", weechat_plugin->name); + snprintf (plugin_id, sizeof (plugin_id), + "%x", (unsigned int)server); + weechat_infolist_new_var_string (item, "plugin_id", plugin_id); + weechat_infolist_new_var_string (item, "type", "file_recv"); + weechat_infolist_new_var_string (item, "filename", pos_file); + weechat_infolist_new_var_integer (item, "port", atoi (pos_port)); + weechat_infolist_new_var_string (item, "start_resume", pos_start_resume); + weechat_hook_signal_send ("xfer_accept_resume", + WEECHAT_HOOK_SIGNAL_POINTER, + infolist); + } + weechat_infolist_free (infolist); + } + weechat_hook_signal_send ("irc_dcc", WEECHAT_HOOK_SIGNAL_STRING, argv_eol[0]); @@ -1911,11 +1923,29 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, char *command, pos--; } pos[1] = '\0'; - - /* TODO: resume DCC */ - //irc_dcc_start_resume (server, pos_file, atoi (pos_port), - // strtoul (pos_start_resume, NULL, 10)); - + + /* resume file via xfer plugin */ + infolist = weechat_infolist_new (); + if (infolist) + { + item = weechat_infolist_new_item (infolist); + if (item) + { + weechat_infolist_new_var_string (item, "plugin_name", weechat_plugin->name); + snprintf (plugin_id, sizeof (plugin_id), + "%x", (unsigned int)server); + weechat_infolist_new_var_string (item, "plugin_id", plugin_id); + weechat_infolist_new_var_string (item, "type", "file_recv"); + weechat_infolist_new_var_string (item, "filename", pos_file); + weechat_infolist_new_var_integer (item, "port", atoi (pos_port)); + weechat_infolist_new_var_string (item, "start_resume", pos_start_resume); + weechat_hook_signal_send ("xfer_start_resume", + WEECHAT_HOOK_SIGNAL_POINTER, + infolist); + } + weechat_infolist_free (infolist); + } + weechat_hook_signal_send ("irc_dcc", WEECHAT_HOOK_SIGNAL_STRING, argv_eol[0]); diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 9cd9dbded..f3c9bb6bd 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -2863,6 +2863,118 @@ irc_server_xfer_send_ready_cb (void *data, char *signal, char *type_data, } /* + * irc_server_xfer_resume_ready_cb: callback called when user receives a file + * and that resume is possible (file is partially + * received) + * in that case, irc plugin send message to + * remote nick with resume position + */ + +int +irc_server_xfer_resume_ready_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + struct t_plugin_infolist *infolist; + struct t_irc_server *server, *ptr_server; + char *plugin_name, *plugin_id, *filename; + int spaces_in_name; + + /* make C compiler happy */ + (void) data; + (void) signal; + (void) type_data; + + infolist = (struct t_plugin_infolist *)signal_data; + + if (weechat_infolist_next (infolist)) + { + plugin_name = weechat_infolist_string (infolist, "plugin_name"); + plugin_id = weechat_infolist_string (infolist, "plugin_id"); + if (plugin_name && (strcmp (plugin_name, "irc") == 0) && plugin_id) + { + sscanf (plugin_id, "%x", (unsigned int *)&server); + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server == server) + break; + } + if (ptr_server) + { + filename = weechat_infolist_string (infolist, "filename"); + spaces_in_name = (strchr (filename, ' ') != NULL); + irc_server_sendf (server, + "PRIVMSG %s :\01DCC RESUME %s%s%s %d %s\01", + weechat_infolist_string (infolist, "remote_nick"), + (spaces_in_name) ? "\"" : "", + filename, + (spaces_in_name) ? "\"" : "", + weechat_infolist_integer (infolist, "port"), + weechat_infolist_string (infolist, "start_resume")); + } + } + } + + return WEECHAT_RC_OK; +} + +/* + * irc_server_xfer_send_accept_resume_cb: callback called when xfer plugin + * accepted resume request from receiver + * in that case, irc plugin send accept + * message to remote nick with resume + * position + */ + +int +irc_server_xfer_send_accept_resume_cb (void *data, char *signal, + char *type_data, void *signal_data) +{ + struct t_plugin_infolist *infolist; + struct t_irc_server *server, *ptr_server; + char *plugin_name, *plugin_id, *filename; + int spaces_in_name; + + /* make C compiler happy */ + (void) data; + (void) signal; + (void) type_data; + + infolist = (struct t_plugin_infolist *)signal_data; + + if (weechat_infolist_next (infolist)) + { + plugin_name = weechat_infolist_string (infolist, "plugin_name"); + plugin_id = weechat_infolist_string (infolist, "plugin_id"); + if (plugin_name && (strcmp (plugin_name, "irc") == 0) && plugin_id) + { + sscanf (plugin_id, "%x", (unsigned int *)&server); + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (ptr_server == server) + break; + } + if (ptr_server) + { + filename = weechat_infolist_string (infolist, "filename"); + spaces_in_name = (strchr (filename, ' ') != NULL); + irc_server_sendf (server, + "PRIVMSG %s :\01DCC ACCEPT %s%s%s %d %s\01", + weechat_infolist_string (infolist, "remote_nick"), + (spaces_in_name) ? "\"" : "", + filename, + (spaces_in_name) ? "\"" : "", + weechat_infolist_integer (infolist, "port"), + weechat_infolist_string (infolist, "start_resume")); + } + } + } + + return WEECHAT_RC_OK; +} + +/* * irc_server_print_log: print server infos in log (usually for crash dump) */ diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 1593f3425..c1903d903 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -188,6 +188,11 @@ extern void irc_server_free (struct t_irc_server *server); extern void irc_server_free_data (struct t_irc_server *server); extern int irc_server_xfer_send_ready_cb (void *data, char *signal, char *type_data, void *signal_data); +extern int irc_server_xfer_resume_ready_cb (void *data, char *signal, + char *type_data, void *signal_data); +extern int irc_server_xfer_send_accept_resume_cb (void *data, char *signal, + char *type_data, + void *signal_data); extern void irc_server_print_log (); #endif /* irc-server.h */ diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index 70dae0e2d..05c4f0ea4 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -106,6 +106,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) irc_debug_init (); weechat_hook_signal ("quit", &irc_signal_quit_cb, NULL); weechat_hook_signal ("xfer_send_ready", &irc_server_xfer_send_ready_cb, NULL); + weechat_hook_signal ("xfer_resume_ready", &irc_server_xfer_resume_ready_cb, NULL); + weechat_hook_signal ("xfer_send_accept_resume", &irc_server_xfer_send_accept_resume_cb, NULL); /* hook completions */ irc_completion_init (); diff --git a/src/plugins/xfer/xfer-buffer.c b/src/plugins/xfer/xfer-buffer.c index d0e9093a0..ab43e52bf 100644 --- a/src/plugins/xfer/xfer-buffer.c +++ b/src/plugins/xfer/xfer-buffer.c @@ -42,8 +42,8 @@ void xfer_buffer_refresh (char *hotlist) { struct t_xfer *ptr_xfer, *xfer_selected; - char str_color[256], status[64], date[128], *progress_bar, format[128]; - char format_per_sec[128], bytes_per_sec[256], eta[128]; + char str_color[256], suffix[32], status[64], date[128], *progress_bar; + char format[128], format_per_sec[128], bytes_per_sec[256], eta[128]; int i, length, line, progress_bar_size, num_bars, num_unit; int num_unit_per_sec; unsigned long pct_complete; @@ -60,8 +60,9 @@ xfer_buffer_refresh (char *hotlist) if (xfer_selected) { weechat_printf_y (xfer_buffer, 0, - "%sActions (letter+enter):%s%s%s%s%s%s", + "%s%s%s%s%s%s%s%s", weechat_color("green"), + _("Actions (letter+enter):"), weechat_color("lightgreen"), /* accept */ (XFER_IS_RECV(xfer_selected->type) @@ -80,6 +81,13 @@ xfer_buffer_refresh (char *hotlist) } for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer) { + suffix[0] = '\0'; + if (ptr_xfer->filename_suffix >= 0) + { + snprintf (suffix, sizeof (suffix), + " (.%d)", ptr_xfer->filename_suffix); + } + snprintf (str_color, sizeof (str_color), "%s,%s", (line == xfer_buffer_selected_line) ? @@ -89,7 +97,7 @@ xfer_buffer_refresh (char *hotlist) /* display first line with remote nick and filename */ weechat_printf_y (xfer_buffer, (line * 2) + 2, - "%s%s%-24s %s%s%s", + "%s%s%-24s %s%s%s%s", weechat_color(str_color), (line == xfer_buffer_selected_line) ? "*** " : " ", @@ -97,8 +105,9 @@ xfer_buffer_refresh (char *hotlist) (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : "", (XFER_IS_FILE(ptr_xfer->type)) ? ptr_xfer->filename : _("xfer chat"), - (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : ""); - + (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : "", + suffix); + snprintf (status, sizeof (status), "%s", _(xfer_status_string[ptr_xfer->status])); length = weechat_utf8_strlen_screen (status); diff --git a/src/plugins/xfer/xfer-file.c b/src/plugins/xfer/xfer-file.c index e43729bd7..fd72a8840 100644 --- a/src/plugins/xfer/xfer-file.c +++ b/src/plugins/xfer/xfer-file.c @@ -56,8 +56,8 @@ xfer_file_resume (struct t_xfer *xfer, char *filename) if ((unsigned long) st.st_size < xfer->size) { xfer->start_resume = (unsigned long) st.st_size; - xfer->pos = st.st_size; - xfer->last_check_pos = st.st_size; + xfer->pos = xfer->start_resume; + xfer->last_check_pos = xfer->start_resume; return 1; } } diff --git a/src/plugins/xfer/xfer-network.c b/src/plugins/xfer/xfer-network.c index e0f26e0b7..e09272c86 100644 --- a/src/plugins/xfer/xfer-network.c +++ b/src/plugins/xfer/xfer-network.c @@ -544,15 +544,7 @@ xfer_network_accept (struct t_xfer *xfer) if (XFER_IS_FILE(xfer->type) && (xfer->start_resume > 0)) { xfer->status = XFER_STATUS_CONNECTING; - xfer_send_signal (xfer, "xfer_accepted"); - /* - irc_server_sendf (dcc->server, - (strchr (dcc->filename, ' ')) ? - "PRIVMSG %s :\01DCC RESUME \"%s\" %d %u\01\n" : - "PRIVMSG %s :\01DCC RESUME %s %d %u\01", - dcc->nick, dcc->filename, - dcc->port, dcc->start_resume); - */ + xfer_send_signal (xfer, "xfer_resume_ready"); xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); } else diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c index 86a8cec19..eee29bcc2 100644 --- a/src/plugins/xfer/xfer.c +++ b/src/plugins/xfer/xfer.c @@ -140,13 +140,16 @@ xfer_search_protocol (char *protocol) */ struct t_xfer * -xfer_search (enum t_xfer_type type, enum t_xfer_status status, int port) +xfer_search (char *plugin_name, char *plugin_id, enum t_xfer_type type, + enum t_xfer_status status, int port) { struct t_xfer *ptr_xfer; for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer) { - if ((ptr_xfer->type == type) + if ((weechat_strcasecmp (ptr_xfer->plugin_name, plugin_name) == 0) + && (weechat_strcasecmp (ptr_xfer->plugin_id, plugin_id) == 0) + && (ptr_xfer->type == type) && (ptr_xfer->status = status) && (ptr_xfer->port == port)) return ptr_xfer; @@ -319,6 +322,9 @@ xfer_send_signal (struct t_xfer *xfer, char *signal) snprintf (str_long, sizeof (str_long), "%lu", xfer->size); weechat_infolist_new_var_string (item, "size", str_long); + snprintf (str_long, sizeof (str_long), "%lu", xfer->start_resume); + weechat_infolist_new_var_string (item, "start_resume", + str_long); snprintf (str_long, sizeof (str_long), "%lu", xfer->address); weechat_infolist_new_var_string (item, "address", str_long); @@ -510,7 +516,7 @@ xfer_new (char *plugin_name, char *plugin_id, enum t_xfer_type type, { weechat_printf (NULL, _("%s: file %s (local filename: %s) " - "will be resumed at position %u"), + "will be resumed at position %lu"), "xfer", new_xfer->filename, new_xfer->local_filename, @@ -620,15 +626,11 @@ xfer_add_cb (void *data, char *signal, char *type_data, void *signal_data) (void) signal; (void) type_data; - filename2 = NULL; - short_filename = NULL; - spaces = 0; - if (!signal_data) { weechat_printf (NULL, - _("%s%s: missing arguments"), - weechat_prefix ("error"), "xfer"); + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_add"); return WEECHAT_RC_ERROR; } @@ -637,10 +639,14 @@ xfer_add_cb (void *data, char *signal, char *type_data, void *signal_data) if (!weechat_infolist_next (infolist)) { weechat_printf (NULL, - _("%s%s: missing arguments"), - weechat_prefix ("error"), "xfer"); + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_add"); return WEECHAT_RC_ERROR; } + + filename2 = NULL; + short_filename = NULL; + spaces = 0; plugin_name = weechat_infolist_string (infolist, "plugin_name"); plugin_id = weechat_infolist_string (infolist, "plugin_id"); @@ -654,8 +660,8 @@ xfer_add_cb (void *data, char *signal, char *type_data, void *signal_data) if (!plugin_name || !plugin_id || !str_type || !remote_nick || !local_nick) { weechat_printf (NULL, - _("%s%s: missing arguments"), - weechat_prefix ("error"), "xfer"); + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_add"); return WEECHAT_RC_ERROR; } @@ -671,8 +677,8 @@ xfer_add_cb (void *data, char *signal, char *type_data, void *signal_data) if (XFER_IS_FILE(type) && (!filename || !str_protocol)) { weechat_printf (NULL, - _("%s%s: missing arguments"), - weechat_prefix ("error"), "xfer"); + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_add"); return WEECHAT_RC_ERROR; } @@ -930,7 +936,7 @@ xfer_add_cb (void *data, char *signal, char *type_data, void *signal_data) } /* send signal if type is file or chat "send" */ - if (XFER_IS_SEND(ptr_xfer->type)) + if (XFER_IS_SEND(ptr_xfer->type) && !XFER_HAS_ENDED(ptr_xfer->status)) xfer_send_signal (ptr_xfer, "xfer_send_ready"); if (short_filename) @@ -942,6 +948,166 @@ xfer_add_cb (void *data, char *signal, char *type_data, void *signal_data) } /* + * xfer_start_resume_cb: callback called when resume is accepted by sender + */ + +int +xfer_start_resume_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + struct t_plugin_infolist *infolist; + struct t_xfer *ptr_xfer; + char *plugin_name, *plugin_id, *filename, *str_start_resume; + int port; + unsigned long start_resume; + + /* make C compiler happy */ + (void) data; + (void) signal; + (void) type_data; + + if (!signal_data) + { + weechat_printf (NULL, + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_start_resume"); + return WEECHAT_RC_ERROR; + } + + infolist = (struct t_plugin_infolist *)signal_data; + + if (!weechat_infolist_next (infolist)) + { + weechat_printf (NULL, + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_start_resume"); + return WEECHAT_RC_ERROR; + } + + plugin_name = weechat_infolist_string (infolist, "plugin_name"); + plugin_id = weechat_infolist_string (infolist, "plugin_id"); + filename = weechat_infolist_string (infolist, "filename"); + port = weechat_infolist_integer (infolist, "port"); + str_start_resume = weechat_infolist_string (infolist, "start_resume"); + + if (!plugin_name || !plugin_id || !filename || !str_start_resume) + { + weechat_printf (NULL, + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_start_resume"); + return WEECHAT_RC_ERROR; + } + + sscanf (str_start_resume, "%lu", &start_resume); + + ptr_xfer = xfer_search (plugin_name, plugin_id, XFER_TYPE_FILE_RECV, + XFER_STATUS_CONNECTING, port); + if (ptr_xfer) + { + ptr_xfer->pos = start_resume; + ptr_xfer->ack = start_resume; + ptr_xfer->start_resume = start_resume; + ptr_xfer->last_check_pos = start_resume; + xfer_network_connect_init (ptr_xfer); + } + else + { + weechat_printf (NULL, + _("%s%s: unable to resume file \"%s\" (port: %d, " + "start position: %lu): xfer not found or not ready " + "for transfert"), + weechat_prefix ("error"), "xfer", filename, port, + start_resume); + } + + return WEECHAT_RC_OK; +} + +/* + * xfer_accept_resume_cb: callback called when sender receives resume request + * from recever + */ + +int +xfer_accept_resume_cb (void *data, char *signal, char *type_data, + void *signal_data) +{ + struct t_plugin_infolist *infolist; + struct t_xfer *ptr_xfer; + char *plugin_name, *plugin_id, *filename, *str_start_resume; + int port; + unsigned long start_resume; + + /* make C compiler happy */ + (void) data; + (void) signal; + (void) type_data; + + if (!signal_data) + { + weechat_printf (NULL, + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_accept_resume"); + return WEECHAT_RC_ERROR; + } + + infolist = (struct t_plugin_infolist *)signal_data; + + if (!weechat_infolist_next (infolist)) + { + weechat_printf (NULL, + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_accept_resume"); + return WEECHAT_RC_ERROR; + } + + plugin_name = weechat_infolist_string (infolist, "plugin_name"); + plugin_id = weechat_infolist_string (infolist, "plugin_id"); + filename = weechat_infolist_string (infolist, "filename"); + port = weechat_infolist_integer (infolist, "port"); + str_start_resume = weechat_infolist_string (infolist, "start_resume"); + + if (!plugin_name || !plugin_id || !filename || !str_start_resume) + { + weechat_printf (NULL, + _("%s%s: missing arguments (%s)"), + weechat_prefix ("error"), "xfer", "xfer_accept_resume"); + return WEECHAT_RC_ERROR; + } + + sscanf (str_start_resume, "%lu", &start_resume); + + ptr_xfer = xfer_search (plugin_name, plugin_id, XFER_TYPE_FILE_SEND, + XFER_STATUS_CONNECTING, port); + if (ptr_xfer) + { + ptr_xfer->pos = start_resume; + ptr_xfer->ack = start_resume; + ptr_xfer->start_resume = start_resume; + ptr_xfer->last_check_pos = start_resume; + xfer_send_signal (ptr_xfer, "xfer_send_accept_resume"); + + weechat_printf (NULL, + _("%s: file %s resumed at position %lu"), + "xfer", + ptr_xfer->filename, + ptr_xfer->start_resume); + xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); + } + else + { + weechat_printf (NULL, + _("%s%s: unable to accept resume file \"%s\" (port: %d, " + "start position: %lu): xfer not found or not ready " + "for transfert"), + weechat_prefix ("error"), "xfer", filename, port, + start_resume); + } + + return WEECHAT_RC_OK; +} + +/* * xfer_print_log: print DCC infos in log (usually for crash dump) */ @@ -1042,6 +1208,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin) xfer_command_init (); weechat_hook_signal ("xfer_add", &xfer_add_cb, NULL); + weechat_hook_signal ("xfer_start_resume", &xfer_start_resume_cb, NULL); + weechat_hook_signal ("xfer_accept_resume", &xfer_accept_resume_cb, NULL); weechat_hook_signal ("debug_dump", &xfer_debug_dump_cb, NULL); return WEECHAT_RC_OK; |