2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
dcc.c : irssi
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
Copyright (C) 1999-2001 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"
|
|
|
|
#include "line-split.h"
|
2001-02-09 21:02:26 -05:00
|
|
|
#include "misc.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "settings.h"
|
2001-11-19 15:16:24 -05:00
|
|
|
#include "ignore.h"
|
|
|
|
#include "levels.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-11-01 20:05:14 -05:00
|
|
|
#include "irc-servers.h"
|
2001-11-25 12:35:47 -05:00
|
|
|
#include "servers-setup.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
#include "dcc-chat.h"
|
|
|
|
#include "dcc-get.h"
|
2001-02-09 21:02:26 -05:00
|
|
|
#include "dcc-send.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
void dcc_resume_init(void);
|
|
|
|
void dcc_resume_deinit(void);
|
|
|
|
|
|
|
|
void dcc_autoget_init(void);
|
|
|
|
void dcc_autoget_deinit(void);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
GSList *dcc_conns;
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
static GSList *dcc_types;
|
2000-06-03 21:36:07 -04:00
|
|
|
static int dcc_timeouttag;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
void dcc_register_type(const char *type)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-02-09 21:02:26 -05:00
|
|
|
dcc_types = g_slist_append(dcc_types, g_strdup(type));
|
|
|
|
}
|
2000-06-03 21:36:07 -04:00
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
void dcc_unregister_type(const char *type)
|
|
|
|
{
|
|
|
|
GSList *pos;
|
|
|
|
|
|
|
|
pos = gslist_find_string(dcc_types, type);
|
|
|
|
if (pos != NULL) {
|
|
|
|
dcc_types = g_slist_remove(dcc_types, pos->data);
|
2002-12-10 15:30:03 -05:00
|
|
|
g_free(pos->data);
|
2001-02-09 21:02:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int dcc_str2type(const char *str)
|
|
|
|
{
|
|
|
|
if (gslist_find_string(dcc_types, str) == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return module_get_uniq_id_str("DCC", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize DCC record */
|
|
|
|
void dcc_init_rec(DCC_REC *dcc, IRC_SERVER_REC *server, CHAT_DCC_REC *chat,
|
|
|
|
const char *nick, const char *arg)
|
|
|
|
{
|
|
|
|
g_return_if_fail(dcc != NULL);
|
|
|
|
g_return_if_fail(nick != NULL);
|
|
|
|
g_return_if_fail(arg != NULL);
|
|
|
|
g_return_if_fail(server != NULL || chat != NULL);
|
2000-06-03 21:36:07 -04:00
|
|
|
|
2001-06-30 06:11:33 -04:00
|
|
|
MODULE_DATA_INIT(dcc);
|
2000-06-03 21:36:07 -04:00
|
|
|
dcc->created = time(NULL);
|
|
|
|
dcc->chat = chat;
|
|
|
|
dcc->arg = g_strdup(arg);
|
|
|
|
dcc->nick = g_strdup(nick);
|
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 : "??");
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
dcc->servertag = server != NULL ? g_strdup(server->tag) :
|
|
|
|
(chat == NULL ? NULL : g_strdup(chat->servertag));
|
2000-06-03 21:36:07 -04:00
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
dcc_conns = g_slist_append(dcc_conns, dcc);
|
2000-06-03 21:36:07 -04:00
|
|
|
signal_emit("dcc created", 1, dcc);
|
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->destroyed = TRUE;
|
|
|
|
signal_emit("dcc destroyed", 1, dcc);
|
|
|
|
|
2000-12-04 17:57:18 -05:00
|
|
|
if (dcc->handle != NULL) 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);
|
|
|
|
|
2001-06-30 06:11:33 -04:00
|
|
|
MODULE_DATA_DEINIT(dcc);
|
2001-02-09 21:02:26 -05:00
|
|
|
g_free_not_null(dcc->servertag);
|
2001-01-17 21:30:59 -05:00
|
|
|
g_free_not_null(dcc->target);
|
2000-06-03 21:36:07 -04:00
|
|
|
g_free(dcc->mynick);
|
|
|
|
g_free(dcc->nick);
|
|
|
|
g_free(dcc->arg);
|
|
|
|
g_free(dcc);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
DCC_REC *dcc_find_request_latest(int type)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-17 21:30:59 -05:00
|
|
|
DCC_REC *latest;
|
|
|
|
GSList *tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
latest = NULL;
|
2000-06-03 21:36:07 -04:00
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
2001-01-17 21:30:59 -05:00
|
|
|
DCC_REC *dcc = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
if (dcc->type == type && dcc_is_waiting_user(dcc))
|
|
|
|
latest = dcc;
|
2000-06-03 21:36:07 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
return latest;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
DCC_REC *dcc_find_request(int type, const char *nick, const char *arg)
|
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
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
g_return_val_if_fail(nick != NULL, NULL);
|
|
|
|
|
2000-06-03 21:36:07 -04:00
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
2001-01-17 21:30:59 -05:00
|
|
|
DCC_REC *dcc = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
if (dcc->type == type && !dcc_is_connected(dcc) &&
|
|
|
|
g_strcasecmp(dcc->nick, nick) == 0 &&
|
|
|
|
(arg == NULL || strcmp(dcc->arg, arg) == 0))
|
2000-06-03 21:36:07 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
void dcc_ip2str(IPADDR *ip, char *host)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-05-21 20:16:38 -04:00
|
|
|
IPADDR temp_ip;
|
2002-09-14 03:29:48 -04:00
|
|
|
guint32 addr;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-05-21 20:16:38 -04:00
|
|
|
if (*settings_get_str("dcc_own_ip") != '\0') {
|
|
|
|
/* overridden IP address */
|
|
|
|
net_host2ip(settings_get_str("dcc_own_ip"), &temp_ip);
|
|
|
|
ip = &temp_ip;
|
|
|
|
}
|
|
|
|
|
2001-03-03 20:47:13 -05:00
|
|
|
if (IPADDR_IS_V6(ip)) {
|
2001-02-09 21:02:26 -05:00
|
|
|
/* IPv6 */
|
|
|
|
net_ip2host(ip, host);
|
|
|
|
} else {
|
2002-09-13 20:42:37 -04:00
|
|
|
memcpy(&addr, &ip->ip, sizeof(addr));
|
2001-02-09 21:02:26 -05:00
|
|
|
g_snprintf(host, MAX_IP_LEN, "%lu",
|
|
|
|
(unsigned long) htonl(addr));
|
2000-06-03 21:36:07 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
void dcc_str2ip(const char *str, IPADDR *ip)
|
2001-01-17 21:30:59 -05:00
|
|
|
{
|
2002-09-14 03:29:48 -04:00
|
|
|
guint32 addr;
|
2001-01-17 21:30:59 -05:00
|
|
|
|
|
|
|
if (strchr(str, ':') == NULL) {
|
|
|
|
/* normal IPv4 address in 32bit number form */
|
|
|
|
addr = strtoul(str, NULL, 10);
|
|
|
|
ip->family = AF_INET;
|
2002-09-13 20:36:20 -04:00
|
|
|
addr = (guint32) ntohl(addr);
|
2002-09-13 20:42:37 -04:00
|
|
|
memcpy(&ip->ip, &addr, sizeof(addr));
|
2001-01-17 21:30:59 -05:00
|
|
|
} else {
|
|
|
|
/* IPv6 - in standard form */
|
|
|
|
net_host2ip(str, ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
/* Start listening for incoming connections */
|
2001-02-28 14:26:21 -05:00
|
|
|
GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-09-10 16:21:05 -04:00
|
|
|
GIOChannel *handle;
|
2001-09-12 08:19:59 -04:00
|
|
|
const char *dcc_port, *p;
|
2001-09-10 16:21:05 -04:00
|
|
|
int first, last;
|
|
|
|
|
2001-02-28 14:26:21 -05:00
|
|
|
if (net_getsockname(iface, ip, NULL) == -1)
|
2001-11-25 12:35:47 -05:00
|
|
|
return NULL;
|
2001-02-09 21:02:26 -05:00
|
|
|
|
2001-09-10 16:21:05 -04:00
|
|
|
/* get first port */
|
|
|
|
dcc_port = settings_get_str("dcc_port");
|
|
|
|
first = atoi(dcc_port);
|
|
|
|
if (first == 0) {
|
|
|
|
/* random port */
|
|
|
|
*port = 0;
|
2002-03-31 14:40:40 -05:00
|
|
|
return net_listen(NULL, port);
|
2001-09-10 16:21:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get last port */
|
2001-09-12 08:19:59 -04:00
|
|
|
p = strchr(dcc_port, ' ');
|
|
|
|
if (p == NULL) p = strchr(dcc_port, '-');
|
|
|
|
|
|
|
|
dcc_port = p;
|
2001-09-10 16:21:05 -04:00
|
|
|
if (dcc_port == NULL)
|
|
|
|
last = first;
|
|
|
|
else {
|
|
|
|
last = atoi(dcc_port+1);
|
|
|
|
if (last == 0)
|
|
|
|
last = first;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use the first available port */
|
|
|
|
for (*port = first; *port <= last; (*port)++) {
|
2002-03-31 14:40:40 -05:00
|
|
|
handle = net_listen(NULL, port);
|
2001-09-10 16:21:05 -04:00
|
|
|
if (handle != NULL)
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-11-25 12:35:47 -05:00
|
|
|
/* Connect to specified IP address using the correct own_ip. */
|
|
|
|
GIOChannel *dcc_connect_ip(IPADDR *ip, int port)
|
|
|
|
{
|
|
|
|
IPADDR *own_ip, temp_ip;
|
|
|
|
|
|
|
|
if (*settings_get_str("dcc_own_ip") == '\0') {
|
|
|
|
own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4;
|
|
|
|
} else {
|
|
|
|
/* use the specified interface for connecting */
|
|
|
|
net_host2ip(settings_get_str("dcc_own_ip"), &temp_ip);
|
|
|
|
own_ip = &temp_ip;
|
|
|
|
}
|
|
|
|
|
2002-08-26 15:05:14 -04:00
|
|
|
return net_connect_ip(ip, port, own_ip);
|
2001-11-25 12:35:47 -05:00
|
|
|
}
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
/* Server connected - update server for DCC records that have
|
|
|
|
the same server tag */
|
2002-11-13 08:02:29 -05:00
|
|
|
static void sig_connected(IRC_SERVER_REC *server)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
g_return_if_fail(server != NULL);
|
|
|
|
|
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
|
|
|
DCC_REC *dcc = tmp->data;
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
if (dcc->server == NULL && dcc->servertag != NULL &&
|
|
|
|
g_strcasecmp(dcc->servertag, server->tag) == 0) {
|
2000-04-26 04:03:38 -04:00
|
|
|
dcc->server = server;
|
|
|
|
g_free(dcc->mynick);
|
|
|
|
dcc->mynick = g_strdup(server->nick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
/* Server disconnected, remove it from all DCC records */
|
|
|
|
static void sig_server_disconnected(IRC_SERVER_REC *server)
|
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(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
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
if (dcc->server == server)
|
|
|
|
dcc->server = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Your nick changed, change nick in all DCC records */
|
|
|
|
static void sig_server_nick_changed(IRC_SERVER_REC *server)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
if (!IS_IRC_SERVER(server)) return;
|
2000-06-03 21:36:07 -04:00
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
|
|
|
|
DCC_REC *dcc = tmp->data;
|
|
|
|
|
|
|
|
if (dcc->server == server) {
|
2001-01-17 21:30:59 -05:00
|
|
|
g_free(dcc->mynick);
|
2001-02-09 21:02:26 -05:00
|
|
|
dcc->mynick = g_strdup(server->nick);
|
2000-06-03 21:36:07 -04:00
|
|
|
}
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-11-19 15:16:24 -05:00
|
|
|
/* handle emitting "ctcp msg dcc" signal - don't use it directly because
|
|
|
|
with /IGNORE * CTCPS we'd be ignored */
|
|
|
|
static void ctcp_msg(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr, const char *target)
|
|
|
|
{
|
|
|
|
if (g_strncasecmp(data, "dcc ", 4) != 0)
|
|
|
|
return;
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
signal_emit("ctcp msg dcc", 5, server, data, nick, addr, target);
|
|
|
|
signal_stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle emitting "ctcp reply dcc" signal - don't use it directly because
|
|
|
|
with /IGNORE * CTCPS we'd be ignored */
|
|
|
|
static void ctcp_reply(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr, const char *target)
|
|
|
|
{
|
|
|
|
if (g_strncasecmp(data, "dcc ", 4) != 0)
|
|
|
|
return;
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
signal_emit("ctcp reply dcc", 5, server, data, nick, addr, target);
|
|
|
|
signal_stop();
|
|
|
|
}
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
/* Handle incoming DCC CTCP messages - either from IRC server or DCC chat */
|
|
|
|
static void ctcp_msg_dcc(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target, DCC_REC *chat)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-17 21:30:59 -05:00
|
|
|
char *args, *str;
|
2000-06-03 21:36:07 -04:00
|
|
|
|
2001-11-19 15:16:24 -05:00
|
|
|
if (ignore_check(SERVER(server), nick, addr, target, data, MSGLEVEL_DCC))
|
|
|
|
return;
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
str = g_strconcat("ctcp msg dcc ", data, NULL);
|
|
|
|
args = strchr(str+13, ' ');
|
|
|
|
if (args != NULL) *args++ = '\0'; else args = "";
|
|
|
|
|
|
|
|
g_strdown(str+13);
|
|
|
|
if (!signal_emit(str, 6, server, args, nick, addr, target, chat)) {
|
|
|
|
signal_emit("default ctcp msg dcc", 6,
|
|
|
|
server, data, nick, addr, target, chat);
|
2000-06-03 21:36:07 -04:00
|
|
|
}
|
2001-01-17 21:30:59 -05:00
|
|
|
g_free(str);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
/* Handle incoming DCC CTCP replies - either from IRC server or DCC chat */
|
|
|
|
static void ctcp_reply_dcc(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-17 21:30:59 -05:00
|
|
|
char *args, *str;
|
|
|
|
|
2001-11-19 15:16:24 -05:00
|
|
|
if (ignore_check(SERVER(server), nick, addr, target, data, MSGLEVEL_DCC))
|
|
|
|
return;
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
str = g_strconcat("ctcp reply dcc ", data, NULL);
|
|
|
|
args = strchr(str+15, ' ');
|
|
|
|
if (args != NULL) *args++ = '\0'; else args = "";
|
|
|
|
|
|
|
|
g_strdown(str+15);
|
|
|
|
if (!signal_emit(str, 5, server, args, nick, addr, target)) {
|
|
|
|
signal_emit("default ctcp reply dcc", 5,
|
|
|
|
server, data, nick, addr, target);
|
|
|
|
}
|
|
|
|
g_free(str);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
/* CTCP REPLY: REJECT */
|
|
|
|
static void ctcp_reply_dcc_reject(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
DCC_REC *chat)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-17 21:30:59 -05:00
|
|
|
DCC_REC *dcc;
|
2001-02-09 21:02:26 -05:00
|
|
|
char *type, *args;
|
2001-01-17 21:30:59 -05:00
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
type = g_strdup(data);
|
|
|
|
args = strchr(type, ' ');
|
2001-01-17 21:30:59 -05:00
|
|
|
if (args != NULL) *args++ = '\0'; else args = "";
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
dcc = dcc_find_request(dcc_str2type(type), nick, args);
|
|
|
|
if (dcc != NULL) dcc_close(dcc);
|
|
|
|
|
|
|
|
g_free(type);
|
|
|
|
}
|
2001-01-17 21:30:59 -05:00
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
void dcc_close(DCC_REC *dcc)
|
|
|
|
{
|
|
|
|
signal_emit("dcc closed", 1, dcc);
|
|
|
|
dcc_destroy(dcc);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
/* Reject a DCC request */
|
2001-01-02 11:14:19 -05:00
|
|
|
void dcc_reject(DCC_REC *dcc, IRC_SERVER_REC *server)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-17 21:30:59 -05:00
|
|
|
g_return_if_fail(dcc != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2002-05-10 14:47:49 -04:00
|
|
|
signal_emit("dcc rejected", 1, dcc);
|
|
|
|
|
|
|
|
if (dcc->server != NULL)
|
|
|
|
server = dcc->server;
|
|
|
|
|
2002-05-12 07:20:02 -04:00
|
|
|
if (server != NULL && !dcc_is_connected(dcc)) {
|
2001-01-17 21:30:59 -05:00
|
|
|
irc_send_cmdv(server, "NOTICE %s :\001DCC REJECT %s %s\001",
|
2001-02-09 21:02:26 -05:00
|
|
|
dcc->nick, dcc_type2str(dcc->orig_type),
|
2001-01-17 21:30:59 -05:00
|
|
|
dcc->arg);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
dcc_close(dcc);
|
2001-01-17 21:30:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dcc_timeout_func(void)
|
|
|
|
{
|
|
|
|
GSList *tmp, *next;
|
|
|
|
time_t now;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2002-12-28 12:54:13 -05:00
|
|
|
now = time(NULL)-settings_get_time("dcc_timeout")/1000;
|
2001-01-17 21:30:59 -05:00
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = next) {
|
2001-02-09 21:02:26 -05:00
|
|
|
DCC_REC *dcc = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
next = tmp->next;
|
2001-02-09 21:02:26 -05:00
|
|
|
if (dcc->tagread == -1 && now > dcc->created) {
|
|
|
|
/* Timed out - don't send DCC REJECT CTCP so CTCP
|
|
|
|
flooders won't affect us and it really doesn't
|
|
|
|
matter that much anyway if the other side doen't
|
|
|
|
get it.. */
|
|
|
|
dcc_close(dcc);
|
2001-01-17 21:30:59 -05:00
|
|
|
}
|
|
|
|
}
|
2001-02-09 21:02:26 -05:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
return 1;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
static void event_no_such_nick(IRC_SERVER_REC *server, char *data)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-17 21:30:59 -05:00
|
|
|
char *params, *nick;
|
|
|
|
GSList *tmp, *next;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
params = event_get_params(data, 2, NULL, &nick);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
/* check if we've send any dcc requests to this nick.. */
|
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = next) {
|
|
|
|
DCC_REC *dcc = tmp->data;
|
2000-11-16 21:45:04 -05:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
next = tmp->next;
|
|
|
|
if (!dcc_is_connected(dcc) && dcc->server == server &&
|
2001-02-09 21:02:26 -05:00
|
|
|
g_strcasecmp(dcc->nick, nick) == 0)
|
|
|
|
dcc_close(dcc);
|
2001-01-17 21:30:59 -05:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
/* SYNTAX: DCC CLOSE <type> <nick> [<file>] */
|
|
|
|
static void cmd_dcc_close(char *data, IRC_SERVER_REC *server)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-17 21:30:59 -05:00
|
|
|
GSList *tmp, *next;
|
|
|
|
char *typestr, *nick, *arg;
|
|
|
|
void *free_arg;
|
|
|
|
int found, type;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
2001-02-09 21:02:26 -05:00
|
|
|
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
|
|
|
|
&typestr, &nick, &arg))
|
2001-01-17 21:30:59 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
|
|
|
g_strup(typestr);
|
|
|
|
type = dcc_str2type(typestr);
|
2001-02-09 21:02:26 -05:00
|
|
|
if (type == -1) {
|
2001-01-17 21:30:59 -05:00
|
|
|
signal_emit("dcc error unknown type", 1, typestr);
|
|
|
|
cmd_params_free(free_arg);
|
|
|
|
return;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
found = FALSE;
|
|
|
|
for (tmp = dcc_conns; tmp != NULL; tmp = next) {
|
|
|
|
DCC_REC *dcc = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
next = tmp->next;
|
2001-02-09 21:02:26 -05:00
|
|
|
if (dcc->type == type && g_strcasecmp(dcc->nick, nick) == 0 &&
|
2001-01-17 21:30:59 -05:00
|
|
|
(*arg == '\0' || strcmp(dcc->arg, arg) == 0)) {
|
|
|
|
dcc_reject(dcc, server);
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
if (!found) {
|
|
|
|
signal_emit("dcc error close not found", 3,
|
|
|
|
typestr, nick, arg);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
cmd_params_free(free_arg);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
static void cmd_dcc(const char *data, IRC_SERVER_REC *server, void *item)
|
|
|
|
{
|
|
|
|
command_runsub("dcc", data, server, item);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-25 07:30:47 -04:00
|
|
|
void irc_dcc_init(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-17 21:30:59 -05:00
|
|
|
dcc_conns = NULL;
|
|
|
|
dcc_timeouttag = g_timeout_add(1000, (GSourceFunc) dcc_timeout_func, NULL);
|
|
|
|
|
2001-09-10 16:21:05 -04:00
|
|
|
settings_add_str("dcc", "dcc_port", "0");
|
2002-12-28 12:54:13 -05:00
|
|
|
settings_add_time("dcc", "dcc_timeout", "5min");
|
2001-05-21 20:16:38 -04:00
|
|
|
settings_add_str("dcc", "dcc_own_ip", "");
|
2001-01-17 21:30:59 -05:00
|
|
|
|
2002-11-13 08:02:29 -05:00
|
|
|
signal_add("event connected", (SIGNAL_FUNC) sig_connected);
|
2001-02-09 21:02:26 -05:00
|
|
|
signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
|
|
|
|
signal_add("server nick changed", (SIGNAL_FUNC) sig_server_nick_changed);
|
2001-11-19 15:16:24 -05:00
|
|
|
signal_add("ctcp msg", (SIGNAL_FUNC) ctcp_msg);
|
|
|
|
signal_add("ctcp reply", (SIGNAL_FUNC) ctcp_reply);
|
2001-01-17 21:30:59 -05:00
|
|
|
signal_add("ctcp msg dcc", (SIGNAL_FUNC) ctcp_msg_dcc);
|
|
|
|
signal_add("ctcp reply dcc", (SIGNAL_FUNC) ctcp_reply_dcc);
|
|
|
|
signal_add("ctcp reply dcc reject", (SIGNAL_FUNC) ctcp_reply_dcc_reject);
|
2001-02-09 21:02:26 -05:00
|
|
|
signal_add("event 401", (SIGNAL_FUNC) event_no_such_nick);
|
2001-01-17 21:30:59 -05:00
|
|
|
command_bind("dcc", NULL, (SIGNAL_FUNC) cmd_dcc);
|
|
|
|
command_bind("dcc close", NULL, (SIGNAL_FUNC) cmd_dcc_close);
|
|
|
|
|
|
|
|
dcc_chat_init();
|
|
|
|
dcc_get_init();
|
|
|
|
dcc_send_init();
|
|
|
|
dcc_resume_init();
|
|
|
|
dcc_autoget_init();
|
2001-08-13 20:41:59 -04:00
|
|
|
|
|
|
|
module_register("dcc", "irc");
|
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
|
|
|
{
|
2001-02-09 21:02:26 -05:00
|
|
|
while (dcc_conns != NULL)
|
|
|
|
dcc_destroy(dcc_conns->data);
|
|
|
|
|
2001-01-17 21:30:59 -05:00
|
|
|
dcc_chat_deinit();
|
|
|
|
dcc_get_deinit();
|
|
|
|
dcc_send_deinit();
|
|
|
|
dcc_resume_deinit();
|
|
|
|
dcc_autoget_deinit();
|
|
|
|
|
2002-11-13 08:02:29 -05:00
|
|
|
signal_remove("event connected", (SIGNAL_FUNC) sig_connected);
|
2001-02-09 21:02:26 -05:00
|
|
|
signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
|
|
|
|
signal_remove("server nick changed", (SIGNAL_FUNC) sig_server_nick_changed);
|
2001-11-19 15:16:24 -05:00
|
|
|
signal_remove("ctcp msg", (SIGNAL_FUNC) ctcp_msg);
|
|
|
|
signal_remove("ctcp reply", (SIGNAL_FUNC) ctcp_reply);
|
2001-01-17 21:30:59 -05:00
|
|
|
signal_remove("ctcp msg dcc", (SIGNAL_FUNC) ctcp_msg_dcc);
|
|
|
|
signal_remove("ctcp reply dcc", (SIGNAL_FUNC) ctcp_reply_dcc);
|
|
|
|
signal_remove("ctcp reply dcc reject", (SIGNAL_FUNC) ctcp_reply_dcc_reject);
|
2001-02-09 21:02:26 -05:00
|
|
|
signal_remove("event 401", (SIGNAL_FUNC) event_no_such_nick);
|
2001-01-17 21:30:59 -05:00
|
|
|
command_unbind("dcc", (SIGNAL_FUNC) cmd_dcc);
|
|
|
|
command_unbind("dcc close", (SIGNAL_FUNC) cmd_dcc_close);
|
|
|
|
|
|
|
|
g_source_remove(dcc_timeouttag);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|