summaryrefslogtreecommitdiff
path: root/src/plugins/xfer/xfer-network.c
diff options
context:
space:
mode:
authorMario Campos <mario-campos@github.com>2023-08-22 18:59:59 -0500
committerSébastien Helleu <flashcode@flashtux.org>2023-09-06 14:11:35 +0200
commit7f0f947667ec6ed22b30e205627da51dffe620c4 (patch)
tree0aa2cdac02e136220bd6d2f1b95c6990d52ca962 /src/plugins/xfer/xfer-network.c
parent23d70b5101f8a8ca9cac92e25b783c8259ab14df (diff)
downloadweechat-7f0f947667ec6ed22b30e205627da51dffe620c4.zip
xfer: add passive DCC support.
This commit also includes support for passive DCC RESUME. There was also a potential segfault with calling `atoi(pos_token)` when `pos_token` is NULL, so `token` is set to be stored as a string. Although it is an integer, we don't need to store it as such. That's really more of an implementation detail.
Diffstat (limited to 'src/plugins/xfer/xfer-network.c')
-rw-r--r--src/plugins/xfer/xfer-network.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/plugins/xfer/xfer-network.c b/src/plugins/xfer/xfer-network.c
index 02b0991d2..d69c43cf1 100644
--- a/src/plugins/xfer/xfer-network.c
+++ b/src/plugins/xfer/xfer-network.c
@@ -498,7 +498,7 @@ xfer_network_fd_cb (const void *pointer, void *data, int fd)
if (xfer->status == XFER_STATUS_CONNECTING)
{
- if (xfer->type == XFER_TYPE_FILE_SEND_PASSIVE)
+ if (XFER_IS_PASSIVE(xfer->type))
{
xfer->last_activity = time (NULL);
sock = accept (xfer->sock,
@@ -546,7 +546,22 @@ xfer_network_fd_cb (const void *pointer, void *data, int fd)
xfer->status = XFER_STATUS_ACTIVE;
xfer->start_transfer = time (NULL);
xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE);
- xfer_network_send_file_fork (xfer);
+ switch (xfer->type)
+ {
+ case XFER_TYPE_FILE_SEND_PASSIVE:
+ xfer_network_send_file_fork (xfer);
+ break;
+ case XFER_TYPE_FILE_RECV_PASSIVE:
+ xfer_network_recv_file_fork (xfer);
+ break;
+ default:
+ weechat_printf (NULL,
+ _("%s%s: encountered unexpected xfer type (%d)"),
+ weechat_prefix ("error"), XFER_PLUGIN_NAME, xfer->type);
+ xfer_close (xfer, XFER_STATUS_FAILED);
+ xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE);
+ return WEECHAT_RC_OK;
+ }
}
}
@@ -787,7 +802,7 @@ xfer_network_connect (struct t_xfer *xfer)
else
xfer->status = XFER_STATUS_CONNECTING;
- if (XFER_IS_SEND(xfer->type))
+ if (XFER_IS_SEND(xfer->type) || (xfer->type == XFER_TYPE_FILE_RECV_PASSIVE))
{
/* create socket */
if (xfer->sock < 0)
@@ -822,6 +837,10 @@ xfer_network_connect (struct t_xfer *xfer)
&xfer_network_timer_cb,
xfer, NULL);
}
+
+ /* send signal if type is file or chat "send" */
+ if ((xfer->type == XFER_TYPE_FILE_RECV_PASSIVE) && !XFER_HAS_ENDED(xfer->status))
+ xfer_send_signal (xfer, "xfer_send_ready");
}
/* for chat receiving, connect to listening host */
@@ -854,7 +873,7 @@ xfer_network_connect_init (struct t_xfer *xfer)
else
{
/* for a file: launch child process */
- if (XFER_IS_FILE(xfer->type))
+ if (XFER_IS_FILE(xfer->type) && XFER_IS_ACTIVE(xfer->type))
xfer_network_recv_file_fork (xfer);
xfer->status = XFER_STATUS_CONNECTING;