1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 17:53:13 +02:00

- added DCC timeout

- fixed FIFO pipe (command now authorized on a buffer not connected to an IRC server)
- fixed Perl bug with info reading functions
This commit is contained in:
Sebastien Helleu
2005-07-12 17:05:01 +00:00
parent 8a6d35cf12
commit 6b12f19083
16 changed files with 638 additions and 596 deletions
+3 -19
View File
@@ -112,16 +112,8 @@ fifo_exec (char *text)
if (text[0] == '*')
{
pos_msg = text + 1;
ptr_server = SERVER(gui_current_window->buffer);
ptr_buffer = gui_current_window->buffer;
if (!ptr_server)
{
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL, _("%s invalid buffer for displaying text via FIFO pipe\n"),
WEECHAT_WARNING);
return;
}
ptr_buffer = (gui_current_window->buffer->dcc) ? gui_buffers : gui_current_window->buffer;
ptr_server = SERVER(ptr_buffer);
}
else
{
@@ -172,20 +164,12 @@ fifo_exec (char *text)
}
}
if (!ptr_server)
{
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL, _("%s invalid text received on FIFO pipe\n"),
WEECHAT_WARNING);
return;
}
if (!ptr_buffer)
{
if (ptr_channel)
ptr_buffer = ptr_channel->buffer;
else
ptr_buffer = ptr_server->buffer;
ptr_buffer = gui_buffers;
}
user_command (ptr_server, ptr_buffer, pos_msg);
+35 -12
View File
@@ -229,6 +229,14 @@ dcc_close (t_irc_dcc *ptr_dcc, int status)
}
}
/* remove empty file if received file failed and nothing was transfered */
if (((status == DCC_FAILED) || (status == DCC_ABORTED))
&& DCC_IS_FILE(ptr_dcc->type)
&& DCC_IS_RECV(ptr_dcc->type)
&& ptr_dcc->local_filename
&& ptr_dcc->pos == 0)
unlink (ptr_dcc->local_filename);
if (DCC_IS_CHAT(ptr_dcc->type))
channel_remove_dcc (ptr_dcc);
@@ -418,6 +426,7 @@ dcc_add (t_irc_server *server, int type, unsigned long addr, int port, char *nic
new_dcc->last_check_time = 0;
new_dcc->last_check_pos = 0;
new_dcc->bytes_per_sec = 0;
new_dcc->last_activity = time (NULL);
new_dcc->prev_dcc = NULL;
new_dcc->next_dcc = dcc_list;
if (dcc_list)
@@ -844,6 +853,17 @@ dcc_handle ()
for (ptr_dcc = dcc_list; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
{
/* check DCC timeout */
if (DCC_IS_FILE(ptr_dcc->type) && !DCC_ENDED(ptr_dcc->status))
{
if ((cfg_dcc_timeout != 0) && (time (NULL) > ptr_dcc->last_activity + cfg_dcc_timeout))
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
continue;
}
}
if (ptr_dcc->status == DCC_CONNECTING)
{
if (ptr_dcc->type == DCC_FILE_SEND)
@@ -858,6 +878,7 @@ dcc_handle ()
{
if (FD_ISSET (ptr_dcc->sock, &read_fd))
{
ptr_dcc->last_activity = time (NULL);
length = sizeof (addr);
sock = accept (ptr_dcc->sock, (struct sockaddr *) &addr, &length);
close (ptr_dcc->sock);
@@ -866,14 +887,14 @@ dcc_handle ()
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
ptr_dcc->sock = sock;
if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);
ptr_dcc->status = DCC_ACTIVE;
@@ -907,14 +928,14 @@ dcc_handle ()
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
ptr_dcc->sock = sock;
if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);
ptr_dcc->status = DCC_ACTIVE;
@@ -950,15 +971,16 @@ dcc_handle ()
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
if (write (ptr_dcc->file, buffer, num_read) == -1)
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
ptr_dcc->last_activity = time (NULL);
ptr_dcc->pos += (unsigned long) num_read;
pos = htonl (ptr_dcc->pos);
send (ptr_dcc->sock, (char *) &pos, 4, 0);
@@ -983,7 +1005,7 @@ dcc_handle ()
sizeof (buffer));
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
if (ptr_dcc->pos > ptr_dcc->ack)
{
@@ -995,10 +1017,10 @@ dcc_handle ()
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
if (num_read < 4)
return;
continue;
recv (ptr_dcc->sock, (char *) &pos, 4, 0);
ptr_dcc->ack = ntohl (pos);
@@ -1007,7 +1029,7 @@ dcc_handle ()
{
dcc_close (ptr_dcc, DCC_DONE);
dcc_redraw (1);
return;
continue;
}
}
}
@@ -1019,15 +1041,16 @@ dcc_handle ()
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
num_sent = send (ptr_dcc->sock, buffer, num_read, 0);
if (num_sent < 0)
{
dcc_close (ptr_dcc, DCC_FAILED);
dcc_redraw (1);
return;
continue;
}
ptr_dcc->last_activity = time (NULL);
ptr_dcc->pos += (unsigned long) num_sent;
dcc_calculate_speed (ptr_dcc, 0);
dcc_redraw (0);
+2 -1
View File
@@ -98,7 +98,7 @@ struct t_irc_nick
int is_chanowner; /* chan owner? (specific to unrealircd) */
int is_chanadmin; /* chan admin? (specific to unrealircd) */
int is_op; /* operator privileges? */
int is_halfop; /* half operaor privileges? */
int is_halfop; /* half operator privileges? */
int has_voice; /* nick has voice? */
int is_away; /* = 1 if nick is away, otherwise 0 */
int color; /* color for nickname in chat window */
@@ -245,6 +245,7 @@ struct t_irc_dcc
time_t last_check_time; /* last time we looked at bytes sent/rcv*/
unsigned long last_check_pos; /* bytes sent/recv at last check */
unsigned long bytes_per_sec; /* bytes per second */
time_t last_activity; /* time of last byte received/sent */
t_irc_dcc *prev_dcc; /* link to previous dcc file/chat */
t_irc_dcc *next_dcc; /* link to next dcc file/chat */
};
+11 -16
View File
@@ -354,7 +354,7 @@ static XS (XS_IRC_add_command_handler)
static XS (XS_IRC_get_info)
{
char *arg, *info = NULL, *server;
char *arg, *info = NULL, *server_name;
t_irc_server *ptr_server;
int integer;
dXSARGS;
@@ -364,13 +364,9 @@ static XS (XS_IRC_get_info)
if (items == 2)
{
server = SvPV (ST (0), integer);
server_name = SvPV (ST (0), integer);
arg = SvPV (ST (1), integer);
for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server)
{
if (strcasecmp (ptr_server->name, server) == 0)
break;
}
ptr_server = server_search (server_name);
if (!ptr_server)
{
irc_display_prefix (NULL, PREFIX_ERROR);
@@ -720,19 +716,18 @@ static XS (XS_weechat_get_info)
{
server_name = SvPV (ST (1), integer);
ptr_server = server_search (server_name);
if (!ptr_server)
{
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("%s error: server not found for \"%s\" function\n"),
"Perl", "get_info");
XSRETURN_NO;
}
}
else
ptr_server = SERVER(gui_current_window->buffer);
if (!ptr_server)
{
irc_display_prefix (NULL, PREFIX_ERROR);
gui_printf (NULL,
_("%s error: server not found for \"%s\" function\n"),
"Perl", "get_info");
XSRETURN_NO;
}
arg = SvPV (ST (0), integer);
if (arg)
{