2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
dcc.c : irssi
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "commands.h"
|
|
|
|
#include "network.h"
|
2000-07-23 09:43:42 -04:00
|
|
|
#include "net-sendbuffer.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "line-split.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#include "masks.h"
|
|
|
|
#include "irc.h"
|
|
|
|
|
|
|
|
#include "dcc.h"
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void dcc_chat_init(void);
|
|
|
|
void dcc_chat_deinit(void);
|
|
|
|
|
|
|
|
void dcc_files_init(void);
|
|
|
|
void dcc_files_deinit(void);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
#define DCC_TYPES 5
|
|
|
|
|
2000-07-10 19:00:56 -04:00
|
|
|
static const char *dcc_types[] = {
|
2000-06-03 21:36:07 -04:00
|
|
|
"CHAT",
|
|
|
|
"SEND",
|
|
|
|
"GET",
|
|
|
|
"RESUME",
|
|
|
|
"ACCEPT"
|
2000-04-26 04:03:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
GSList *dcc_conns;
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
static int dcc_timeouttag;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
/* Create new DCC record */
|
2000-06-03 21:36:07 -04:00
|
|
|
DCC_REC *dcc_create(int type, int handle, const char *nick, const char *arg,
|
|
|
|
IRC_SERVER_REC *server, DCC_REC *chat)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
DCC_REC *dcc;
|
|
|
|
|
|
|
|
g_return_val_if_fail(nick != NULL, NULL);
|
|
|
|
g_return_val_if_fail(arg != NULL, NULL);
|
|
|
|
|
|
|
|
dcc = g_new0(DCC_REC, 1);
|
|
|
|
dcc->mirc_ctcp = settings_get_bool("dcc_mirc_ctcp");
|
|
|
|
dcc->created = time(NULL);
|
|
|
|
dcc->chat = chat;
|
|
|
|
dcc->type = type;
|
|
|
|
dcc->arg = g_strdup(arg);
|
|
|
|
dcc->nick = g_strdup(nick);
|
|
|
|
dcc->handle = handle;
|
|
|
|
dcc->fhandle = -1;
|
2000-07-15 09:04:03 -04:00
|
|
|
dcc->tagconn = dcc->tagread = dcc->tagwrite = -1;
|
2000-06-03 21:36:07 -04:00
|
|
|
dcc->server = server;
|
|
|
|
dcc->mynick = g_strdup(server != NULL ? server->nick :
|
|
|
|
chat != NULL ? chat->nick : "??");
|
|
|
|
|
|
|
|
dcc->ircnet = server == NULL ?
|
|
|
|
(chat == NULL || chat->ircnet == NULL ? NULL : g_strdup(chat->ircnet)) :
|
|
|
|
(server->connrec->ircnet == NULL ? NULL : g_strdup(server->connrec->ircnet));
|
|
|
|
dcc_conns = g_slist_append(dcc_conns, dcc);
|
|
|
|
|
|
|
|
signal_emit("dcc created", 1, dcc);
|
|
|
|
return dcc;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
static void dcc_remove_chat_refs(DCC_REC *dcc)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
GSList *tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
g_return_if_fail(dcc != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
|
|
|
DCC_REC *rec = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
if (rec->chat == dcc)
|
|
|
|
rec->chat = NULL;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
/* Destroy DCC record */
|
|
|
|
void dcc_destroy(DCC_REC *dcc)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
g_return_if_fail(dcc != NULL);
|
|
|
|
if (dcc->destroyed) return;
|
|
|
|
|
|
|
|
dcc_conns = g_slist_remove(dcc_conns, dcc);
|
|
|
|
dcc_remove_chat_refs(dcc);
|
|
|
|
|
|
|
|
dcc->destroyed = TRUE;
|
|
|
|
signal_emit("dcc destroyed", 1, dcc);
|
|
|
|
|
|
|
|
if (dcc->fhandle != -1) close(dcc->fhandle);
|
|
|
|
if (dcc->handle != -1) net_disconnect(dcc->handle);
|
2000-07-15 09:04:03 -04:00
|
|
|
if (dcc->tagconn != -1) g_source_remove(dcc->tagconn);
|
2000-06-03 21:36:07 -04:00
|
|
|
if (dcc->tagread != -1) g_source_remove(dcc->tagread);
|
|
|
|
if (dcc->tagwrite != -1) g_source_remove(dcc->tagwrite);
|
2000-07-23 09:43:42 -04:00
|
|
|
if (dcc->sendbuf != NULL) net_sendbuffer_destroy(dcc->sendbuf, FALSE);
|
2000-06-03 21:36:07 -04:00
|
|
|
|
|
|
|
if (dcc->type == DCC_TYPE_CHAT)
|
|
|
|
line_split_free((LINEBUF_REC *) dcc->databuf);
|
|
|
|
else if (dcc->databuf != NULL)
|
|
|
|
g_free(dcc->databuf);
|
|
|
|
|
|
|
|
g_free_not_null(dcc->file);
|
|
|
|
g_free_not_null(dcc->ircnet);
|
|
|
|
g_free(dcc->mynick);
|
|
|
|
g_free(dcc->nick);
|
|
|
|
g_free(dcc->arg);
|
|
|
|
g_free(dcc);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
void dcc_make_address(IPADDR *ip, char *host)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
if (is_ipv6_addr(ip)) {
|
|
|
|
/* IPv6 */
|
|
|
|
net_ip2host(ip, host);
|
|
|
|
} else {
|
|
|
|
memcpy(&addr, &ip->addr, 4);
|
|
|
|
sprintf(host, "%lu", (unsigned long) htonl(addr));
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find DCC record, arg can be NULL */
|
2000-06-03 21:36:07 -04:00
|
|
|
DCC_REC *dcc_find_item(int type, const char *nick, const char *arg)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
DCC_REC *dcc;
|
|
|
|
GSList *tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
g_return_val_if_fail(nick != NULL, NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
|
|
|
dcc = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
if (dcc->type == type && g_strcasecmp(dcc->nick, nick) == 0 &&
|
|
|
|
(arg == NULL || strcmp(dcc->arg, arg) == 0))
|
|
|
|
return dcc;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
return NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find DCC record by port # */
|
2000-06-03 21:36:07 -04:00
|
|
|
DCC_REC *dcc_find_by_port(const char *nick, int port)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
DCC_REC *dcc;
|
|
|
|
GSList *tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
|
|
|
dcc = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
if ((dcc->type == DCC_TYPE_GET || dcc->type == DCC_TYPE_SEND) &&
|
|
|
|
dcc->port == port && g_strcasecmp(dcc->nick, nick) == 0)
|
|
|
|
return dcc;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
return NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
const char *dcc_type2str(int type)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
g_return_val_if_fail(type >= 1 && type <= DCC_TYPES, NULL);
|
|
|
|
|
|
|
|
return dcc_types[type-1];
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
int dcc_str2type(const char *type)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
int num;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
for (num = 0; num < DCC_TYPES; num++) {
|
|
|
|
if (g_strcasecmp(dcc_types[num], type) == 0)
|
|
|
|
return num+1;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
return 0;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
void dcc_ctcp_message(const char *target, IRC_SERVER_REC *server, DCC_REC *chat, int notice, const char *msg)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (chat != NULL) {
|
|
|
|
/* send it via open DCC chat */
|
|
|
|
str = g_strdup_printf("%s\001%s\001", chat->mirc_ctcp ? "" :
|
|
|
|
notice ? "CTCP_REPLY " : "CTCP_MESSAGE ", msg);
|
|
|
|
dcc_chat_send(chat, str);
|
|
|
|
} else {
|
|
|
|
str = g_strdup_printf("%s %s :\001%s\001",
|
|
|
|
notice ? "NOTICE" : "PRIVMSG", target, msg);
|
|
|
|
irc_send_cmd(server, str);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
g_free(str);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Server connected, check if there's any open dcc sessions for this ircnet.. */
|
|
|
|
static void dcc_server_connected(IRC_SERVER_REC *server)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
g_return_if_fail(server != NULL);
|
|
|
|
|
|
|
|
if (server->connrec->ircnet == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
|
|
|
DCC_REC *dcc = tmp->data;
|
|
|
|
|
|
|
|
if (dcc->server == NULL && dcc->ircnet != NULL &&
|
|
|
|
g_strcasecmp(dcc->ircnet, server->connrec->ircnet) == 0) {
|
|
|
|
dcc->server = server;
|
|
|
|
g_free(dcc->mynick);
|
|
|
|
dcc->mynick = g_strdup(server->nick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Server disconnected, remove it from all dcc records */
|
|
|
|
static void dcc_server_disconnected(IRC_SERVER_REC *server)
|
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
GSList *tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
g_return_if_fail(server != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
|
|
|
DCC_REC *dcc = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
if (dcc->server != server)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dcc->ircnet == NULL)
|
|
|
|
dcc->server = NULL;
|
|
|
|
else {
|
|
|
|
dcc->server = (IRC_SERVER_REC *) server_find_ircnet(dcc->ircnet);
|
|
|
|
if (dcc->server != NULL) {
|
|
|
|
g_free(dcc->mynick);
|
|
|
|
dcc->mynick = g_strdup(dcc->server->nick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
static void dcc_get_address(const char *str, IPADDR *ip)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
if (strchr(str, ':') == NULL) {
|
|
|
|
/* normal IPv4 address in 32bit number form */
|
2000-06-06 15:12:19 -04:00
|
|
|
addr = strtoul(str, NULL, 10);
|
2000-06-03 21:36:07 -04:00
|
|
|
ip->family = AF_INET;
|
|
|
|
addr = (unsigned long) ntohl(addr);
|
|
|
|
memcpy(&ip->addr, &addr, 4);
|
|
|
|
} else {
|
|
|
|
/* IPv6 - in standard form */
|
|
|
|
net_host2ip(str, ip);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle incoming DCC CTCP messages */
|
2000-06-03 21:36:07 -04:00
|
|
|
static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char *sendaddr, char *target, DCC_REC *chat)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-17 21:18:12 -04:00
|
|
|
char *type, *arg, *addrstr, *portstr, *sizestr, *str;
|
|
|
|
void *free_arg;
|
2000-04-26 04:03:38 -04:00
|
|
|
const char *cstr;
|
|
|
|
DCC_REC *dcc;
|
2000-07-10 19:00:56 -04:00
|
|
|
long size;
|
2000-06-03 21:36:07 -04:00
|
|
|
int port;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
g_return_if_fail(sender != NULL);
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
if (!cmd_get_params(data, &free_arg, 5 | PARAM_FLAG_NOQUOTES,
|
|
|
|
&type, &arg, &addrstr, &portstr, &sizestr))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
if (sscanf(portstr, "%d", &port) != 1) port = 0;
|
2000-07-10 19:00:56 -04:00
|
|
|
if (sscanf(sizestr, "%ld", &size) != 1) size = 0;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
dcc = dcc_create(SWAP_SENDGET(dcc_str2type(type)), -1, sender, arg, server, chat);
|
|
|
|
dcc_get_address(addrstr, &dcc->addr);
|
|
|
|
net_ip2host(&dcc->addr, dcc->addrstr);
|
|
|
|
dcc->port = port;
|
|
|
|
dcc->size = size;
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
switch (dcc->type)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
case DCC_TYPE_GET:
|
|
|
|
cstr = settings_get_str("dcc_autoget_masks");
|
|
|
|
/* check that autoget masks match */
|
2000-05-04 06:32:42 -04:00
|
|
|
if (settings_get_bool("dcc_autoget") && (*cstr == '\0' || irc_masks_match(cstr, sender, sendaddr)) &&
|
2000-04-26 04:03:38 -04:00
|
|
|
/* check file size limit, FIXME: it's possible to send a bogus file size and then just send what ever sized file.. */
|
|
|
|
(settings_get_int("dcc_max_autoget_size") <= 0 || (settings_get_int("dcc_max_autoget_size") > 0 && size <= settings_get_int("dcc_max_autoget_size")*1024)))
|
|
|
|
{
|
|
|
|
/* automatically get */
|
|
|
|
str = g_strdup_printf("GET %s %s", dcc->nick, dcc->arg);
|
|
|
|
signal_emit("command dcc", 2, str, server);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* send request */
|
|
|
|
signal_emit("dcc request", 1, dcc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DCC_TYPE_CHAT:
|
|
|
|
cstr = settings_get_str("dcc_autochat_masks");
|
|
|
|
if (*cstr != '\0' && irc_masks_match(cstr, sender, sendaddr))
|
|
|
|
{
|
|
|
|
/* automatically accept chat */
|
|
|
|
str = g_strdup_printf("CHAT %s", dcc->nick);
|
|
|
|
signal_emit("command dcc", 2, str, server);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* send request */
|
|
|
|
signal_emit("dcc request", 1, dcc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DCC_TYPE_RESUME:
|
|
|
|
case DCC_TYPE_ACCEPT:
|
|
|
|
/* handle this in dcc-files.c */
|
|
|
|
dcc_destroy(dcc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* unknown DCC command */
|
|
|
|
signal_emit("dcc unknown ctcp", 3, data, sender, sendaddr);
|
|
|
|
dcc_destroy(dcc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle incoming DCC CTCP replies */
|
2000-06-03 21:36:07 -04:00
|
|
|
static void dcc_ctcp_reply(char *data, IRC_SERVER_REC *server, char *sender, char *sendaddr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-17 21:18:12 -04:00
|
|
|
char *cmd, *subcmd, *args;
|
|
|
|
void *free_arg;
|
2000-06-03 21:36:07 -04:00
|
|
|
int type;
|
2000-04-26 04:03:38 -04:00
|
|
|
DCC_REC *dcc;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
g_return_if_fail(sender != NULL);
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &cmd, &subcmd, &args))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
if (g_strcasecmp(cmd, "REJECT") == 0)
|
|
|
|
{
|
|
|
|
type = dcc_str2type(subcmd);
|
|
|
|
dcc = dcc_find_item(type, sender, type == DCC_TYPE_CHAT ? NULL : args);
|
|
|
|
if (dcc != NULL)
|
|
|
|
{
|
|
|
|
signal_emit("dcc closed", 1, dcc);
|
|
|
|
dcc_destroy(dcc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* unknown dcc ctcp reply */
|
|
|
|
signal_emit("dcc unknown reply", 3, data, sender, sendaddr);
|
|
|
|
}
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dcc_reject(DCC_REC *dcc, IRC_SERVER_REC *server)
|
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
char *str;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_return_if_fail(dcc != NULL);
|
|
|
|
|
|
|
|
if (dcc->server != NULL) server = dcc->server;
|
2000-06-03 21:36:07 -04:00
|
|
|
if (server != NULL && (dcc->type != DCC_TYPE_CHAT || dcc->starttime == 0))
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
signal_emit("dcc rejected", 1, dcc);
|
|
|
|
str = g_strdup_printf("NOTICE %s :\001DCC REJECT %s %s\001",
|
2000-06-03 21:36:07 -04:00
|
|
|
dcc->nick, dcc_type2str(SWAP_SENDGET(dcc->type)), dcc->arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
irc_send_cmd(server, str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
signal_emit("dcc closed", 1, dcc);
|
|
|
|
dcc_destroy(dcc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* command: DCC CLOSE */
|
2000-06-03 21:36:07 -04:00
|
|
|
static void cmd_dcc_close(char *data, IRC_SERVER_REC *server)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
DCC_REC *dcc;
|
|
|
|
GSList *tmp, *next;
|
2000-06-17 21:18:12 -04:00
|
|
|
char *type, *nick, *arg;
|
|
|
|
void *free_arg;
|
2000-04-26 04:03:38 -04:00
|
|
|
gboolean found;
|
2000-06-03 21:36:07 -04:00
|
|
|
int itype;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
if (!cmd_get_params(data, &free_arg, 3, &type, &nick, &arg))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_strup(type);
|
|
|
|
itype = dcc_str2type(type);
|
|
|
|
if (itype == 0)
|
|
|
|
{
|
|
|
|
signal_emit("dcc error unknown type", 1, type);
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dcc = NULL; found = FALSE;
|
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = next)
|
|
|
|
{
|
|
|
|
dcc = tmp->data;
|
|
|
|
next = tmp->next;
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
if (dcc->type == itype && g_strcasecmp(nick, dcc->nick) == 0)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
dcc_reject(dcc, server);
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
signal_emit("dcc error close not found", 3, type, nick, arg);
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cmd_dcc(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
|
|
|
|
{
|
|
|
|
command_runsub("dcc", data, server, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dcc_timeout_func(void)
|
|
|
|
{
|
|
|
|
GSList *tmp, *next;
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
now = time(NULL)-settings_get_int("dcc_timeout");
|
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = next)
|
|
|
|
{
|
|
|
|
DCC_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
next = tmp->next;
|
|
|
|
if (rec->tagread == -1 && now > rec->created)
|
|
|
|
{
|
|
|
|
/* timed out. */
|
|
|
|
dcc_reject(rec, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
static void event_no_such_nick(char *data, IRC_SERVER_REC *server)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-03 21:36:07 -04:00
|
|
|
char *params, *nick;
|
2000-04-26 04:03:38 -04:00
|
|
|
GSList *tmp, *next;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
params = event_get_params(data, 2, NULL, &nick);
|
|
|
|
|
|
|
|
/* check if we've send any dcc requests to this nick.. */
|
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = next)
|
|
|
|
{
|
|
|
|
DCC_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
next = tmp->next;
|
|
|
|
if (g_strcasecmp(rec->nick, nick) == 0 && rec->starttime == 0)
|
|
|
|
{
|
|
|
|
/* timed out. */
|
|
|
|
signal_emit("dcc closed", 1, rec);
|
|
|
|
dcc_destroy(rec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(params);
|
|
|
|
}
|
|
|
|
|
2000-05-25 07:30:47 -04:00
|
|
|
void irc_dcc_init(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
dcc_conns = NULL;
|
|
|
|
dcc_timeouttag = g_timeout_add(1000, (GSourceFunc) dcc_timeout_func, NULL);
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
settings_add_bool("dcc", "dcc_autorename", FALSE);
|
|
|
|
settings_add_bool("dcc", "dcc_autoget", FALSE);
|
2000-04-26 04:03:38 -04:00
|
|
|
settings_add_int("dcc", "dcc_max_autoget_size", 1000);
|
|
|
|
settings_add_str("dcc", "dcc_download_path", "~");
|
|
|
|
settings_add_int("dcc", "dcc_file_create_mode", 644);
|
|
|
|
settings_add_str("dcc", "dcc_autoget_masks", "");
|
|
|
|
settings_add_str("dcc", "dcc_autochat_masks", "");
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
settings_add_bool("dcc", "dcc_fast_send", TRUE);
|
2000-04-26 04:03:38 -04:00
|
|
|
settings_add_str("dcc", "dcc_upload_path", "~");
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
settings_add_bool("dcc", "dcc_mirc_ctcp", FALSE);
|
|
|
|
settings_add_bool("dcc", "dcc_autodisplay_dialog", TRUE);
|
2000-04-26 04:03:38 -04:00
|
|
|
settings_add_int("dcc", "dcc_block_size", 2048);
|
|
|
|
settings_add_int("dcc", "dcc_port", 0);
|
|
|
|
settings_add_int("dcc", "dcc_timeout", 300);
|
|
|
|
|
|
|
|
signal_add("server connected", (SIGNAL_FUNC) dcc_server_connected);
|
|
|
|
signal_add("server disconnected", (SIGNAL_FUNC) dcc_server_disconnected);
|
|
|
|
signal_add("ctcp reply dcc", (SIGNAL_FUNC) dcc_ctcp_reply);
|
|
|
|
signal_add("ctcp msg dcc", (SIGNAL_FUNC) dcc_ctcp_msg);
|
|
|
|
command_bind("dcc", NULL, (SIGNAL_FUNC) cmd_dcc);
|
|
|
|
command_bind("dcc close", NULL, (SIGNAL_FUNC) cmd_dcc_close);
|
|
|
|
signal_add("event 401", (SIGNAL_FUNC) event_no_such_nick);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
dcc_chat_init();
|
|
|
|
dcc_files_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-25 07:30:47 -04:00
|
|
|
void irc_dcc_deinit(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
dcc_chat_deinit();
|
|
|
|
dcc_files_deinit();
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("server connected", (SIGNAL_FUNC) dcc_server_connected);
|
|
|
|
signal_remove("server disconnected", (SIGNAL_FUNC) dcc_server_disconnected);
|
|
|
|
signal_remove("ctcp reply dcc", (SIGNAL_FUNC) dcc_ctcp_reply);
|
|
|
|
signal_remove("ctcp msg dcc", (SIGNAL_FUNC) dcc_ctcp_msg);
|
|
|
|
command_unbind("dcc", (SIGNAL_FUNC) cmd_dcc);
|
|
|
|
command_unbind("dcc close", (SIGNAL_FUNC) cmd_dcc_close);
|
|
|
|
signal_remove("event 401", (SIGNAL_FUNC) event_no_such_nick);
|
|
|
|
|
|
|
|
g_source_remove(dcc_timeouttag);
|
|
|
|
|
|
|
|
while (dcc_conns != NULL)
|
|
|
|
dcc_destroy(dcc_conns->data);
|
|
|
|
}
|