summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-02-10 02:02:26 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-02-10 02:02:26 +0000
commite4f7d55ce941bf33b1d23d7c21e6beb9fb69aba0 (patch)
treeb69359528adf2716cf3d4a765d3f0f7767565be7 /src/irc
parent118f9a11ebfc521198d39fd3048ad462ace696ed (diff)
downloadirssi-e4f7d55ce941bf33b1d23d7c21e6beb9fb69aba0.zip
DCC cleanups - split DCC_REC to CHAT|GET|SEND_DCC_RECs. Plugins should
now be able to add whatever new DCC types. Nick changes affect DCC chats. /WHOIS without parameters works properly in DCC CHAT queries. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1194 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/dcc/Makefile.am4
-rw-r--r--src/irc/dcc/dcc-autoget.c5
-rw-r--r--src/irc/dcc/dcc-chat.c347
-rw-r--r--src/irc/dcc/dcc-chat.h31
-rw-r--r--src/irc/dcc/dcc-file-rec.h9
-rw-r--r--src/irc/dcc/dcc-file.h10
-rw-r--r--src/irc/dcc/dcc-get.c77
-rw-r--r--src/irc/dcc/dcc-get.h26
-rw-r--r--src/irc/dcc/dcc-rec.h28
-rw-r--r--src/irc/dcc/dcc-resume.c41
-rw-r--r--src/irc/dcc/dcc-send.c63
-rw-r--r--src/irc/dcc/dcc-send.h28
-rw-r--r--src/irc/dcc/dcc.c280
-rw-r--r--src/irc/dcc/dcc.h119
14 files changed, 671 insertions, 397 deletions
diff --git a/src/irc/dcc/Makefile.am b/src/irc/dcc/Makefile.am
index d8274173..a1f07c7d 100644
--- a/src/irc/dcc/Makefile.am
+++ b/src/irc/dcc/Makefile.am
@@ -15,7 +15,11 @@ libirc_dcc_la_SOURCES = \
dcc-autoget.c
noinst_HEADERS = \
+ dcc-rec.h \
+ dcc-file-rec.h \
dcc.h \
+ dcc-file.h \
dcc-chat.h \
dcc-get.h \
+ dcc-send.h \
module.h
diff --git a/src/irc/dcc/dcc-autoget.c b/src/irc/dcc/dcc-autoget.c
index cb25ecf8..59e01c7b 100644
--- a/src/irc/dcc/dcc-autoget.c
+++ b/src/irc/dcc/dcc-autoget.c
@@ -25,15 +25,14 @@
#include "dcc-get.h"
-static void sig_dcc_request(DCC_REC *dcc, const char *nickaddr)
+static void sig_dcc_request(GET_DCC_REC *dcc, const char *nickaddr)
{
struct stat statbuf;
const char *masks;
char *str, *file;
int max_size;
- g_return_if_fail(dcc != NULL);
- if (dcc->type != DCC_TYPE_GET) return;
+ if (!IS_DCC_GET(dcc)) return;
/* check if we want to autoget file offer */
if (!settings_get_bool("dcc_autoget") &&
diff --git a/src/irc/dcc/dcc-chat.c b/src/irc/dcc/dcc-chat.c
index 6fa9b19e..eda25211 100644
--- a/src/irc/dcc/dcc-chat.c
+++ b/src/irc/dcc/dcc-chat.c
@@ -1,7 +1,7 @@
/*
dcc-chat.c : irssi
- Copyright (C) 1999-2000 Timo Sirainen
+ Copyright (C) 1999-2001 Timo Sirainen
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
@@ -33,51 +33,108 @@
#include "servers-setup.h"
#include "irc-queries.h"
-#include "dcc.h"
+#include "dcc-chat.h"
-DCC_REC *dcc_chat_find_id(const char *id)
+static char *dcc_chat_get_new_id(const char *nick)
+{
+ char *id;
+ int num;
+
+ g_return_val_if_fail(nick != NULL, NULL);
+
+ if (dcc_chat_find_id(nick) == NULL) {
+ /* same as nick, good */
+ return g_strdup(nick);
+ }
+
+ /* keep adding numbers after nick until some of them isn't found */
+ for (num = 2;; num++) {
+ id = g_strdup_printf("%s%d", nick, num);
+ if (dcc_chat_find_id(id) == NULL)
+ return id;
+ g_free(id);
+ }
+}
+
+static CHAT_DCC_REC *dcc_chat_create(IRC_SERVER_REC *server,
+ CHAT_DCC_REC *chat,
+ const char *nick, const char *arg)
+{
+ CHAT_DCC_REC *dcc;
+
+ dcc = g_new0(CHAT_DCC_REC, 1);
+ dcc->orig_type = dcc->type = DCC_CHAT_TYPE;
+ dcc->mirc_ctcp = settings_get_bool("dcc_mirc_ctcp");
+ dcc->id = dcc_chat_get_new_id(nick);
+
+ dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ return dcc;
+}
+
+static void dcc_remove_chat_refs(CHAT_DCC_REC *dcc)
+{
+ GSList *tmp;
+
+ g_return_if_fail(dcc != NULL);
+
+ for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
+ DCC_REC *rec = tmp->data;
+
+ if (rec->chat == dcc)
+ rec->chat = NULL;
+ }
+}
+
+static void sig_dcc_destroyed(CHAT_DCC_REC *dcc)
+{
+ if (!IS_DCC_CHAT(dcc)) return;
+
+ dcc_remove_chat_refs(dcc);
+
+ if (dcc->sendbuf != NULL) net_sendbuffer_destroy(dcc->sendbuf, FALSE);
+ line_split_free((LINEBUF_REC *) dcc->databuf);
+ dcc->databuf = NULL;
+ g_free(dcc->id);
+}
+
+CHAT_DCC_REC *dcc_chat_find_id(const char *id)
{
GSList *tmp;
g_return_val_if_fail(id != NULL, NULL);
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
- DCC_REC *dcc = tmp->data;
+ CHAT_DCC_REC *dcc = tmp->data;
- if (dcc->type == DCC_TYPE_CHAT && dcc->chat_id != NULL &&
- g_strcasecmp(dcc->chat_id, id) == 0)
+ if (IS_DCC_CHAT(dcc) && g_strcasecmp(dcc->id, id) == 0)
return dcc;
}
return NULL;
}
-static void dcc_chat_set_id(DCC_REC *dcc)
+static CHAT_DCC_REC *dcc_chat_find_nick(IRC_SERVER_REC *server,
+ const char *nick)
{
- char *id;
- int num;
+ GSList *tmp;
- if (dcc_chat_find_id(dcc->nick) == NULL) {
- /* same as nick, good */
- dcc->chat_id = g_strdup(dcc->nick);
- return;
- }
+ g_return_val_if_fail(nick != NULL, NULL);
- /* keep adding numbers after nick until some of them isn't found */
- for (num = 2;; num++) {
- id = g_strdup_printf("%s%d", dcc->nick, num);
- if (dcc_chat_find_id(id) == NULL) {
- dcc->chat_id = id;
- break;
- }
- g_free(id);
+ for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
+ CHAT_DCC_REC *dcc = tmp->data;
+
+ if (IS_DCC_CHAT(dcc) && dcc->server == server &&
+ g_strcasecmp(dcc->nick, nick) == 0)
+ return dcc;
}
+
+ return NULL;
}
/* Send `data' to dcc chat. */
-void dcc_chat_send(DCC_REC *dcc, const char *data)
+void dcc_chat_send(CHAT_DCC_REC *dcc, const char *data)
{
- g_return_if_fail(dcc != NULL);
+ g_return_if_fail(IS_DCC_CHAT(dcc));
g_return_if_fail(dcc->sendbuf != NULL);
g_return_if_fail(data != NULL);
@@ -85,8 +142,28 @@ void dcc_chat_send(DCC_REC *dcc, const char *data)
net_sendbuffer_send(dcc->sendbuf, "\n", 1);
}
+/* Send a CTCP message/notify to target.
+ Send the CTCP via DCC chat if `chat' is specified. */
+void dcc_ctcp_message(IRC_SERVER_REC *server, const char *target,
+ CHAT_DCC_REC *chat, int notice, const char *msg)
+{
+ char *str;
+
+ if (chat != NULL && chat->sendbuf != 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);
+ g_free(str);
+ } else {
+ irc_send_cmdv(server, "%s %s :\001%s\001",
+ notice ? "NOTICE" : "PRIVMSG", target, msg);
+ }
+}
+
/* If `item' is a query of a =nick, return DCC chat record of nick */
-DCC_REC *item_get_dcc(WI_ITEM_REC *item)
+CHAT_DCC_REC *item_get_dcc(WI_ITEM_REC *item)
{
QUERY_REC *query;
@@ -100,7 +177,7 @@ DCC_REC *item_get_dcc(WI_ITEM_REC *item)
/* Send text to DCC chat */
static void cmd_msg(const char *data)
{
- DCC_REC *dcc;
+ CHAT_DCC_REC *dcc;
char *text, *target;
void *free_arg;
@@ -111,10 +188,11 @@ static void cmd_msg(const char *data)
return;
}
- if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &text))
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
+ &target, &text))
return;
- dcc = dcc_chat_find_id(++target);
+ dcc = dcc_chat_find_id(target+1);
if (dcc != NULL && dcc->sendbuf != NULL)
dcc_chat_send(dcc, text);
@@ -124,7 +202,7 @@ static void cmd_msg(const char *data)
static void cmd_me(const char *data, IRC_SERVER_REC *server, QUERY_REC *item)
{
- DCC_REC *dcc;
+ CHAT_DCC_REC *dcc;
char *str;
g_return_if_fail(data != NULL);
@@ -141,7 +219,7 @@ static void cmd_me(const char *data, IRC_SERVER_REC *server, QUERY_REC *item)
static void cmd_action(const char *data, IRC_SERVER_REC *server)
{
- DCC_REC *dcc;
+ CHAT_DCC_REC *dcc;
char *target, *text, *str;
void *free_arg;
@@ -152,9 +230,11 @@ static void cmd_action(const char *data, IRC_SERVER_REC *server)
return;
}
- if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &target, &text))
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
+ &target, &text))
return;
- if (*target == '\0' || *text == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+ if (*target == '\0' || *text == '\0')
+ cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
dcc = dcc_chat_find_id(target+1);
if (dcc != NULL) {
@@ -169,16 +249,19 @@ static void cmd_action(const char *data, IRC_SERVER_REC *server)
static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
{
- DCC_REC *dcc;
+ CHAT_DCC_REC *dcc;
char *target, *ctcpcmd, *ctcpdata, *str;
void *free_arg;
g_return_if_fail(data != NULL);
- if (server == NULL || !server->connected) cmd_return_error(CMDERR_NOT_CONNECTED);
+ if (server == NULL || !server->connected)
+ cmd_return_error(CMDERR_NOT_CONNECTED);
- if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &target, &ctcpcmd, &ctcpdata))
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
+ &target, &ctcpcmd, &ctcpdata))
return;
- if (*target == '\0' || *ctcpcmd == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+ if (*target == '\0' || *ctcpcmd == '\0')
+ cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (*target != '=') {
/* handle only DCC CTCPs */
@@ -200,12 +283,12 @@ static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
}
/* input function: DCC CHAT received some data.. */
-static void dcc_chat_input(DCC_REC *dcc)
+static void dcc_chat_input(CHAT_DCC_REC *dcc)
{
char tmpbuf[512], *str;
int recvlen, ret;
- g_return_if_fail(dcc != NULL);
+ g_return_if_fail(IS_DCC_CHAT(dcc));
do {
recvlen = net_receive(dcc->handle, tmpbuf, sizeof(tmpbuf));
@@ -214,8 +297,7 @@ static void dcc_chat_input(DCC_REC *dcc)
if (ret == -1) {
/* connection lost */
dcc->connection_lost = TRUE;
- signal_emit("dcc closed", 1, dcc);
- dcc_destroy(dcc);
+ dcc_close(DCC(dcc));
break;
}
@@ -227,13 +309,13 @@ static void dcc_chat_input(DCC_REC *dcc)
}
/* input function: DCC CHAT - someone tried to connect to our socket */
-static void dcc_chat_listen(DCC_REC *dcc)
+static void dcc_chat_listen(CHAT_DCC_REC *dcc)
{
IPADDR ip;
GIOChannel *handle;
int port;
- g_return_if_fail(dcc != NULL);
+ g_return_if_fail(IS_DCC_CHAT(dcc));
/* accept connection */
handle = net_accept(dcc->handle, &ip, &port);
@@ -258,14 +340,14 @@ static void dcc_chat_listen(DCC_REC *dcc)
}
/* callback: DCC CHAT - net_connect_nonblock() finished */
-static void sig_chat_connected(DCC_REC *dcc)
+static void sig_chat_connected(CHAT_DCC_REC *dcc)
{
- g_return_if_fail(dcc != NULL);
+ g_return_if_fail(IS_DCC_CHAT(dcc));
if (net_geterror(dcc->handle) != 0) {
/* error connecting */
signal_emit("dcc error connect", 1, dcc);
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
return;
}
@@ -279,9 +361,9 @@ static void sig_chat_connected(DCC_REC *dcc)
signal_emit("dcc connected", 1, dcc);
}
-static void dcc_chat_connect(DCC_REC *dcc)
+static void dcc_chat_connect(CHAT_DCC_REC *dcc)
{
- g_return_if_fail(dcc != NULL);
+ g_return_if_fail(IS_DCC_CHAT(dcc));
if (dcc->addrstr[0] == '\0' ||
dcc->starttime != 0 || dcc->handle != NULL) {
@@ -298,7 +380,7 @@ static void dcc_chat_connect(DCC_REC *dcc)
} else {
/* error connecting */
signal_emit("dcc error connect", 1, dcc);
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
}
}
@@ -306,7 +388,7 @@ static void dcc_chat_connect(DCC_REC *dcc)
static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
{
void *free_arg;
- DCC_REC *dcc;
+ CHAT_DCC_REC *dcc;
IPADDR own_ip;
GIOChannel *handle;
char *nick, host[MAX_IP_LEN];
@@ -318,7 +400,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
return;
if (*nick == '\0') {
- dcc = dcc_find_request_latest(DCC_TYPE_CHAT);
+ dcc = DCC_CHAT(dcc_find_request_latest(DCC_CHAT_TYPE));
if (dcc != NULL)
dcc_chat_connect(dcc);
cmd_params_free(free_arg);
@@ -338,7 +420,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
dcc->server == server) {
/* sending request again even while old request is
still waiting, remove it. */
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
}
/* start listening */
@@ -350,14 +432,13 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
if (handle == NULL)
cmd_param_error(CMDERR_ERRNO);
- dcc = dcc_create(DCC_TYPE_CHAT, nick, "chat", server, NULL);
- dcc_chat_set_id(dcc);
+ dcc = dcc_chat_create(server, NULL, nick, "chat");
dcc->handle = handle;
dcc->tagconn = g_input_add(dcc->handle, G_INPUT_READ,
(GInputFunction) dcc_chat_listen, dcc);
/* send the chat request */
- dcc_make_address(&own_ip, host);
+ dcc_ip2str(&own_ip, host);
irc_send_cmdv(server, "PRIVMSG %s :\001DCC CHAT CHAT %s %d\001",
nick, host, port);
@@ -368,7 +449,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
static void cmd_mircdcc(const char *data, IRC_SERVER_REC *server,
QUERY_REC *item)
{
- DCC_REC *dcc;
+ CHAT_DCC_REC *dcc;
g_return_if_fail(data != NULL);
@@ -376,7 +457,65 @@ static void cmd_mircdcc(const char *data, IRC_SERVER_REC *server,
if (dcc == NULL) return;
dcc->mirc_ctcp = toupper(*data) != 'N' &&
- g_strncasecmp(data, "OF", 3) != 0;
+ g_strncasecmp(data, "OF", 2) != 0;
+}
+
+/* DCC CLOSE CHAT <nick> - check only from chat_ids in open DCC chats,
+ the default handler will check from DCC chat requests */
+static void cmd_dcc_close(char *data, IRC_SERVER_REC *server)
+{
+ GSList *tmp, *next;
+ char *nick;
+ void *free_arg;
+ int found;
+
+ g_return_if_fail(data != NULL);
+
+ if (g_strncasecmp(data, "CHAT ", 5) != 0 ||
+ !cmd_get_params(data, &free_arg, 2, NULL, &nick))
+ return;
+
+ if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+ found = FALSE;
+ for (tmp = dcc_conns; tmp != NULL; tmp = next) {
+ CHAT_DCC_REC *dcc = tmp->data;
+
+ next = tmp->next;
+ if (IS_DCC_CHAT(dcc) && dcc->id != NULL &&
+ g_strcasecmp(dcc->id, nick) == 0) {
+ found = TRUE;
+ if (!dcc_is_connected(dcc))
+ dcc_reject(DCC(dcc), server);
+ else {
+ /* don't send DCC REJECT after DCC chat
+ is already open */
+ dcc_close(DCC(dcc));
+ }
+ }
+ }
+
+ if (found) signal_stop();
+
+ cmd_params_free(free_arg);
+}
+
+static void cmd_whois(const char *data, IRC_SERVER_REC *server,
+ WI_ITEM_REC *item)
+{
+ CHAT_DCC_REC *dcc;
+
+ g_return_if_fail(data != NULL);
+
+ /* /WHOIS without target in DCC CHAT query? */
+ if (*data == '\0') {
+ dcc = item_get_dcc(item);
+ if (dcc != NULL) {
+ signal_emit("command whois", 3,
+ dcc->nick, server, item);
+ signal_stop();
+ }
+ }
}
#define DCC_AUTOACCEPT_PORT(dcc) \
@@ -391,9 +530,9 @@ static void cmd_mircdcc(const char *data, IRC_SERVER_REC *server,
/* CTCP: DCC CHAT */
static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *addr,
- const char *target, DCC_REC *chat)
+ const char *target, CHAT_DCC_REC *chat)
{
- DCC_REC *dcc;
+ CHAT_DCC_REC *dcc;
char **params;
int paramcount;
int autoallow = FALSE;
@@ -407,25 +546,24 @@ static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
return;
}
- dcc = dcc_find_request(DCC_TYPE_CHAT, nick, NULL);
+ dcc = DCC_CHAT(dcc_find_request(DCC_CHAT_TYPE, nick, NULL));
if (dcc != NULL) {
if (dcc_is_listening(dcc)) {
/* we requested dcc chat, they requested
dcc chat from us .. allow it. */
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
autoallow = TRUE;
} else {
/* we already have one dcc chat request
from this nick, remove it. */
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
}
}
- dcc = dcc_create(DCC_TYPE_CHAT, nick, params[0], server, chat);
- dcc_chat_set_id(dcc);
+ dcc = dcc_chat_create(server, chat, nick, params[0]);
dcc->target = g_strdup(target);
dcc->port = atoi(params[2]);
- dcc_get_address(params[1], &dcc->addr);
+ dcc_str2ip(params[1], &dcc->addr);
net_ip2host(&dcc->addr, dcc->addrstr);
signal_emit("dcc request", 2, dcc, addr);
@@ -437,12 +575,12 @@ static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
}
/* DCC CHAT: text received */
-static void dcc_chat_msg(DCC_REC *dcc, const char *msg)
+static void dcc_chat_msg(CHAT_DCC_REC *dcc, const char *msg)
{
char *cmd, *ptr;
int reply;
- g_return_if_fail(dcc != NULL);
+ g_return_if_fail(IS_DCC_CHAT(dcc));
g_return_if_fail(msg != NULL);
reply = FALSE;
@@ -481,26 +619,84 @@ static void dcc_chat_msg(DCC_REC *dcc, const char *msg)
signal_stop();
}
-static void dcc_ctcp_redirect(const char *msg, DCC_REC *dcc)
+static void dcc_ctcp_redirect(const char *msg, CHAT_DCC_REC *dcc)
{
g_return_if_fail(msg != NULL);
- g_return_if_fail(dcc != NULL);
+ g_return_if_fail(IS_DCC_CHAT(dcc));
signal_emit("ctcp msg dcc", 6, dcc->server, msg,
dcc->nick, "dcc", dcc->mynick, dcc);
}
-static void dcc_ctcp_reply_redirect(const char *msg, DCC_REC *dcc)
+static void dcc_ctcp_reply_redirect(const char *msg, CHAT_DCC_REC *dcc)
{
g_return_if_fail(msg != NULL);
- g_return_if_fail(dcc != NULL);
+ g_return_if_fail(IS_DCC_CHAT(dcc));
signal_emit("ctcp reply dcc", 6, dcc->server, msg,
dcc->nick, "dcc", dcc->mynick, dcc);
}
+/* 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)
+{
+ DCC_REC *dcc;
+
+ /* default REJECT handler checks args too -
+ we don't care about it in DCC chats. */
+ if (g_strncasecmp(data, "CHAT", 4) == 0 &&
+ (data[4] == '\0' || data[4] == ' ')) {
+ dcc = dcc_find_request(DCC_CHAT_TYPE, nick, NULL);
+ if (dcc != NULL) dcc_close(dcc);
+ signal_stop();
+ }
+}
+
+static void event_nick(IRC_SERVER_REC *server, const char *data,
+ const char *orignick)
+{
+ QUERY_REC *query;
+ CHAT_DCC_REC *dcc;
+ char *params, *nick, *tag;
+
+ g_return_if_fail(data != NULL);
+
+ params = event_get_params(data, 1, &nick);
+ if (g_strcasecmp(nick, orignick) == 0) {
+ /* shouldn't happen, but just to be sure irssi doesn't
+ get into infinite loop */
+ g_free(params);
+ return;
+ }
+
+ while ((dcc = dcc_chat_find_nick(server, orignick)) != NULL) {
+ g_free(dcc->nick);
+ dcc->nick = g_strdup(nick);
+
+ tag = g_strconcat("=", dcc->id, NULL);
+ query = irc_query_find(server, tag);
+ g_free(tag);
+
+ /* change the id too */
+ g_free(dcc->id);
+ dcc->id = dcc_chat_get_new_id(nick);
+
+ if (query != NULL) {
+ tag = g_strconcat("=", dcc->id, NULL);
+ query_change_nick(query, tag);
+ g_free(tag);
+ }
+ }
+
+ g_free(params);
+}
+
void dcc_chat_init(void)
{
+ dcc_register_type("CHAT");
+ settings_add_bool("dcc", "dcc_mirc_ctcp", FALSE);
settings_add_str("dcc", "dcc_autochat_masks", "");
command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg);
@@ -509,22 +705,33 @@ void dcc_chat_init(void)
command_bind("ctcp", NULL, (SIGNAL_FUNC) cmd_ctcp);
command_bind("dcc chat", NULL, (SIGNAL_FUNC) cmd_dcc_chat);
command_bind("mircdcc", NULL, (SIGNAL_FUNC) cmd_mircdcc);
+ command_bind("dcc close", NULL, (SIGNAL_FUNC) cmd_dcc_close);
+ command_bind("whois", NULL, (SIGNAL_FUNC) cmd_whois);
+ signal_add("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed);
signal_add("ctcp msg dcc chat", (SIGNAL_FUNC) ctcp_msg_dcc_chat);
signal_add_first("dcc chat message", (SIGNAL_FUNC) dcc_chat_msg);
signal_add("dcc ctcp dcc", (SIGNAL_FUNC) dcc_ctcp_redirect);
signal_add("dcc reply dcc", (SIGNAL_FUNC) dcc_ctcp_reply_redirect);
+ signal_add("ctcp reply dcc reject", (SIGNAL_FUNC) ctcp_reply_dcc_reject);
+ signal_add("event nick", (SIGNAL_FUNC) event_nick);
}
void dcc_chat_deinit(void)
{
+ dcc_unregister_type("CHAT");
command_unbind("msg", (SIGNAL_FUNC) cmd_msg);
command_unbind("me", (SIGNAL_FUNC) cmd_me);
command_unbind("action", (SIGNAL_FUNC) cmd_action);
command_unbind("ctcp", (SIGNAL_FUNC) cmd_ctcp);
command_unbind("dcc chat", (SIGNAL_FUNC) cmd_dcc_chat);
command_unbind("mircdcc", (SIGNAL_FUNC) cmd_mircdcc);
+ command_unbind("dcc close", (SIGNAL_FUNC) cmd_dcc_close);
+ command_unbind("whois", (SIGNAL_FUNC) cmd_whois);
+ signal_remove("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed);
signal_remove("ctcp msg dcc chat", (SIGNAL_FUNC) ctcp_msg_dcc_chat);
signal_remove("dcc chat message", (SIGNAL_FUNC) dcc_chat_msg);
signal_remove("dcc ctcp dcc", (SIGNAL_FUNC) dcc_ctcp_redirect);
signal_remove("dcc reply dcc", (SIGNAL_FUNC) dcc_ctcp_reply_redirect);
+ signal_remove("ctcp reply dcc reject", (SIGNAL_FUNC) ctcp_reply_dcc_reject);
+ signal_remove("event nick", (SIGNAL_FUNC) event_nick);
}
diff --git a/src/irc/dcc/dcc-chat.h b/src/irc/dcc/dcc-chat.h
index e1ea6f1b..c8f2cea9 100644
--- a/src/irc/dcc/dcc-chat.h
+++ b/src/irc/dcc/dcc-chat.h
@@ -3,7 +3,36 @@
#include "dcc.h"
-DCC_REC *dcc_chat_find_id(const char *id);
+#define DCC_CHAT(dcc) \
+ MODULE_CHECK_CAST_MODULE(dcc, CHAT_DCC_REC, type, "DCC", "CHAT")
+
+#define IS_DCC_CHAT(dcc) \
+ (DCC_CHAT(dcc) ? TRUE : FALSE)
+
+struct CHAT_DCC_REC {
+#include "dcc-rec.h"
+
+ char *id; /* unique identifier - usually same as nick. */
+ NET_SENDBUF_REC *sendbuf;
+
+ unsigned int mirc_ctcp:1; /* Send CTCPs without the CTCP_MESSAGE prefix */
+ unsigned int connection_lost:1; /* other side closed connection */
+};
+
+#define DCC_CHAT_TYPE module_get_uniq_id_str("DCC", "CHAT")
+
+CHAT_DCC_REC *dcc_chat_find_id(const char *id);
+
+/* Send `data' to dcc chat. */
+void dcc_chat_send(CHAT_DCC_REC *dcc, const char *data);
+
+/* Send a CTCP message/notify to target.
+ Send the CTCP via DCC chat if `chat' is specified. */
+void dcc_ctcp_message(IRC_SERVER_REC *server, const char *target,
+ CHAT_DCC_REC *chat, int notice, const char *msg);
+
+/* If `item' is a query of a =nick, return DCC chat record of nick */
+CHAT_DCC_REC *item_get_dcc(WI_ITEM_REC *item);
void dcc_chat_init(void);
void dcc_chat_deinit(void);
diff --git a/src/irc/dcc/dcc-file-rec.h b/src/irc/dcc/dcc-file-rec.h
new file mode 100644
index 00000000..32663481
--- /dev/null
+++ b/src/irc/dcc/dcc-file-rec.h
@@ -0,0 +1,9 @@
+#include "dcc-rec.h"
+
+unsigned long size, skipped; /* file size / skipped at start */
+int fhandle; /* file handle */
+
+/* counter buffer */
+char count_buf[4];
+int count_pos;
+
diff --git a/src/irc/dcc/dcc-file.h b/src/irc/dcc/dcc-file.h
new file mode 100644
index 00000000..4ff4a2e9
--- /dev/null
+++ b/src/irc/dcc/dcc-file.h
@@ -0,0 +1,10 @@
+#ifndef __DCC_FILE_H
+#define __DCC_FILE_H
+
+#include "dcc.h"
+
+typedef struct {
+#include "dcc-file-rec.h"
+} FILE_DCC_REC;
+
+#endif
diff --git a/src/irc/dcc/dcc-get.c b/src/irc/dcc/dcc-get.c
index 36da43f4..c1596afa 100644
--- a/src/irc/dcc/dcc-get.c
+++ b/src/irc/dcc/dcc-get.c
@@ -30,6 +30,28 @@
static int dcc_file_create_mode;
+static GET_DCC_REC *dcc_get_create(IRC_SERVER_REC *server, CHAT_DCC_REC *chat,
+ const char *nick, const char *arg)
+{
+ GET_DCC_REC *dcc;
+
+ dcc = g_new0(GET_DCC_REC, 1);
+ dcc->orig_type = module_get_uniq_id_str("DCC", "SEND");
+ dcc->type = module_get_uniq_id_str("DCC", "GET");
+ dcc->fhandle = -1;
+
+ dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ return dcc;
+}
+
+static void sig_dcc_destroyed(GET_DCC_REC *dcc)
+{
+ if (!IS_DCC_GET(dcc)) return;
+
+ g_free_not_null(dcc->file);
+ if (dcc->fhandle != -1) close(dcc->fhandle);
+}
+
char *dcc_get_download_path(const char *fname)
{
char *str, *downpath;
@@ -60,9 +82,9 @@ static char *dcc_get_rename_file(const char *fname)
return ret;
}
-static void sig_dccget_send(DCC_REC *dcc);
+static void sig_dccget_send(GET_DCC_REC *dcc);
-void dcc_get_send_received(DCC_REC *dcc)
+void dcc_get_send_received(GET_DCC_REC *dcc)
{
guint32 recd;
@@ -86,7 +108,7 @@ void dcc_get_send_received(DCC_REC *dcc)
}
/* input function: DCC GET is free to send data */
-static void sig_dccget_send(DCC_REC *dcc)
+static void sig_dccget_send(GET_DCC_REC *dcc)
{
guint32 recd;
int ret;
@@ -115,12 +137,10 @@ static void sig_dccget_send(DCC_REC *dcc)
}
/* input function: DCC GET received data */
-static void sig_dccget_receive(DCC_REC *dcc)
+static void sig_dccget_receive(GET_DCC_REC *dcc)
{
int ret;
- g_return_if_fail(dcc != NULL);
-
for (;;) {
ret = net_receive(dcc->handle, dcc->databuf, dcc->databufsize);
if (ret == 0) break;
@@ -128,8 +148,7 @@ static void sig_dccget_receive(DCC_REC *dcc)
if (ret < 0) {
/* socket closed - transmit complete,
or other side died.. */
- signal_emit("dcc closed", 1, dcc);
- dcc_destroy(dcc);
+ dcc_close(DCC(dcc));
return;
}
@@ -145,17 +164,15 @@ static void sig_dccget_receive(DCC_REC *dcc)
}
/* callback: net_connect() finished for DCC GET */
-static void sig_dccget_connected(DCC_REC *dcc)
+static void sig_dccget_connected(GET_DCC_REC *dcc)
{
struct stat statbuf;
char *fname;
- g_return_if_fail(dcc != NULL);
-
if (net_geterror(dcc->handle) != 0) {
/* error connecting */
signal_emit("dcc error connect", 1, dcc);
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
return;
}
@@ -181,7 +198,7 @@ static void sig_dccget_connected(DCC_REC *dcc)
if (dcc->fhandle == -1) {
signal_emit("dcc error file create", 2,
dcc, dcc->file);
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
return;
}
}
@@ -196,7 +213,7 @@ static void sig_dccget_connected(DCC_REC *dcc)
signal_emit("dcc connected", 1, dcc);
}
-void dcc_get_connect(DCC_REC *dcc)
+void dcc_get_connect(GET_DCC_REC *dcc)
{
if (dcc->get_type == DCC_GET_DEFAULT) {
dcc->get_type = settings_get_bool("dcc_autorename") ?
@@ -215,7 +232,7 @@ void dcc_get_connect(DCC_REC *dcc)
} else {
/* error connecting */
signal_emit("dcc error connect", 1, dcc);
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
}
}
@@ -258,9 +275,9 @@ int get_file_params_count(char **params, int paramcount)
/* CTCP: DCC SEND */
static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *addr,
- const char *target, DCC_REC *chat)
+ const char *target, CHAT_DCC_REC *chat)
{
- DCC_REC *dcc;
+ GET_DCC_REC *dcc;
IPADDR ip;
char **params, *fname;
int paramcount, fileparams;
@@ -280,7 +297,7 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data,
fileparams = get_file_params_count(params, paramcount);
- dcc_get_address(params[fileparams], &ip);
+ dcc_str2ip(params[fileparams], &ip);
port = atoi(params[fileparams+1]);
size = atol(params[fileparams+2]);
@@ -296,13 +313,13 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data,
quoted = TRUE;
}
- dcc = dcc_find_request(DCC_TYPE_GET, nick, fname);
+ dcc = DCC_GET(dcc_find_request(DCC_GET_TYPE, nick, fname));
if (dcc != NULL) {
/* same DCC request offered again, remove the old one */
- dcc_destroy(dcc);
+ dcc_destroy(DCC(dcc));
}
- dcc = dcc_create(DCC_TYPE_GET, nick, fname, server, chat);
+ dcc = dcc_get_create(server, chat, nick, fname);
dcc->target = g_strdup(target);
memcpy(&dcc->addr, &ip, sizeof(ip));
net_ip2host(&dcc->addr, dcc->addrstr);
@@ -316,9 +333,9 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data,
}
/* handle receiving DCC - GET/RESUME. */
-void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept)
+void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept_func)
{
- DCC_REC *dcc;
+ GET_DCC_REC *dcc;
GSList *tmp, *next;
char *nick, *fname;
void *free_arg;
@@ -331,23 +348,23 @@ void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept)
return;
if (*nick == '\0') {
- dcc = dcc_find_request_latest(DCC_TYPE_GET);
+ dcc = DCC_GET(dcc_find_request_latest(DCC_GET_TYPE));
if (dcc != NULL)
- accept(dcc);
+ accept_func(dcc);
cmd_params_free(free_arg);
return;
}
found = FALSE;
for (tmp = dcc_conns; tmp != NULL; tmp = next) {
- DCC_REC *dcc = tmp->data;
+ GET_DCC_REC *dcc = tmp->data;
next = tmp->next;
- if (dcc_is_waiting_get(dcc) &&
+ if (IS_DCC_GET(dcc) && dcc_is_waiting_user(dcc) &&
g_strcasecmp(dcc->nick, nick) == 0 &&
(*fname == '\0' || strcmp(dcc->arg, fname) == 0)) {
found = TRUE;
- accept(dcc);
+ accept_func(dcc);
}
}
@@ -371,11 +388,13 @@ static void read_settings(void)
void dcc_get_init(void)
{
+ dcc_register_type("GET");
settings_add_bool("dcc", "dcc_autorename", FALSE);
settings_add_str("dcc", "dcc_download_path", "~");
settings_add_int("dcc", "dcc_file_create_mode", 644);
read_settings();
+ signal_add("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed);
signal_add("ctcp msg dcc send", (SIGNAL_FUNC) ctcp_msg_dcc_send);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
command_bind("dcc get", NULL, (SIGNAL_FUNC) cmd_dcc_get);
@@ -383,6 +402,8 @@ void dcc_get_init(void)
void dcc_get_deinit(void)
{
+ dcc_unregister_type("GET");
+ signal_remove("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed);
signal_remove("ctcp msg dcc send", (SIGNAL_FUNC) ctcp_msg_dcc_send);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
command_unbind("dcc get", (SIGNAL_FUNC) cmd_dcc_get);
diff --git a/src/irc/dcc/dcc-get.h b/src/irc/dcc/dcc-get.h
index f103b2ae..65f5b682 100644
--- a/src/irc/dcc/dcc-get.h
+++ b/src/irc/dcc/dcc-get.h
@@ -3,6 +3,12 @@
#include "dcc.h"
+#define DCC_GET(dcc) \
+ MODULE_CHECK_CAST_MODULE(dcc, GET_DCC_REC, type, "DCC", "GET")
+
+#define IS_DCC_GET(dcc) \
+ (DCC_GET(dcc) ? TRUE : FALSE)
+
enum {
DCC_GET_DEFAULT,
@@ -11,17 +17,25 @@ enum {
DCC_GET_RESUME
};
-typedef void (*DCC_GET_FUNC) (DCC_REC *);
+typedef struct {
+#include "dcc-file-rec.h"
+
+ int get_type; /* what to do if file exists? */
+ char *file; /* file name we're really moving, arg is just the reference */
+
+ unsigned int file_quoted:1; /* file name was received quoted ("file name") */
+} GET_DCC_REC;
+
+#define DCC_GET_TYPE module_get_uniq_id_str("DCC", "GET")
+
+typedef void (*DCC_GET_FUNC) (GET_DCC_REC *);
/* handle receiving DCC - GET/RESUME. */
-void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept);
+void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept_func);
-void dcc_get_connect(DCC_REC *dcc);
+void dcc_get_connect(GET_DCC_REC *dcc);
char *dcc_get_download_path(const char *fname);
-#define dcc_is_waiting_get(dcc) \
- ((dcc)->type == DCC_TYPE_GET && dcc_is_waiting_user(dcc))
-
void dcc_get_init(void);
void dcc_get_deinit(void);
diff --git a/src/irc/dcc/dcc-rec.h b/src/irc/dcc/dcc-rec.h
new file mode 100644
index 00000000..5f6d5178
--- /dev/null
+++ b/src/irc/dcc/dcc-rec.h
@@ -0,0 +1,28 @@
+int type;
+int orig_type; /* original DCC type that was sent to us - same as type except GET and SEND are swapped */
+time_t created;
+
+IRC_SERVER_REC *server;
+char *servertag; /* for resetting server later if we get disconnected */
+char *mynick; /* my current nick */
+char *nick;
+
+CHAT_DCC_REC *chat; /* if the request came through DCC chat */
+char *target; /* who the request was sent to - your nick, channel or NULL if you sent the request */
+char *arg;
+
+IPADDR addr; /* address we're connected in */
+char addrstr[MAX_IP_LEN]; /* in readable form */
+int port; /* port we're connected in */
+
+GIOChannel *handle; /* socket handle */
+int tagconn, tagread, tagwrite;
+time_t starttime; /* transfer start time */
+unsigned long transfd; /* bytes transferred */
+
+unsigned int destroyed:1; /* We're about to destroy this DCC recond */
+
+char *databuf; /* buffer for receiving/transmitting data */
+int databufsize;
+
+GHashTable *module_data;
diff --git a/src/irc/dcc/dcc-resume.c b/src/irc/dcc/dcc-resume.c
index 3404a092..ae1415e1 100644
--- a/src/irc/dcc/dcc-resume.c
+++ b/src/irc/dcc/dcc-resume.c
@@ -24,14 +24,17 @@
#include "network.h"
#include "misc.h"
+#include "dcc-file.h"
#include "dcc-get.h"
+#include "dcc-send.h"
+#include "dcc-chat.h"
-static DCC_REC *dcc_resume_find(int type, const char *nick, int port)
+static FILE_DCC_REC *dcc_resume_find(int type, const char *nick, int port)
{
GSList *tmp;
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
- DCC_REC *dcc = tmp->data;
+ FILE_DCC_REC *dcc = tmp->data;
if (dcc->type == type && !dcc_is_connected(dcc) &&
dcc->port == port && g_strcasecmp(dcc->nick, nick) == 0)
@@ -42,7 +45,7 @@ static DCC_REC *dcc_resume_find(int type, const char *nick, int port)
}
static int dcc_ctcp_resume_parse(int type, const char *data, const char *nick,
- DCC_REC **dcc, long *size)
+ FILE_DCC_REC **dcc, long *size)
{
char **params;
int paramcount;
@@ -56,23 +59,22 @@ static int dcc_ctcp_resume_parse(int type, const char *data, const char *nick,
port = atoi(params[paramcount-2]);
*size = atol(params[paramcount-1]);
- type = type == DCC_TYPE_RESUME ? DCC_TYPE_SEND : DCC_TYPE_GET;
*dcc = dcc_resume_find(type, nick, port);
}
g_strfreev(params);
return paramcount >= 3;
}
-static int dcc_resume_file_check(DCC_REC *dcc, IRC_SERVER_REC *server,
+static int dcc_resume_file_check(FILE_DCC_REC *dcc, IRC_SERVER_REC *server,
long size)
{
- if (lseek(dcc->fhandle, 0, SEEK_END) == dcc->size) {
+ if (size >= dcc->size) {
/* whole file sent */
dcc->starttime = time(NULL);
- dcc_reject(dcc, server);
+ dcc_reject(DCC(dcc), server);
} else if (lseek(dcc->fhandle, size, SEEK_SET) != size) {
/* error, or trying to seek after end of file */
- dcc_reject(dcc, server);
+ dcc_reject(DCC(dcc), server);
} else {
dcc->transfd = dcc->skipped = size;
return TRUE;
@@ -81,20 +83,20 @@ static int dcc_resume_file_check(DCC_REC *dcc, IRC_SERVER_REC *server,
return FALSE;
}
-/* CTCP: DCC RESUME */
+/* CTCP: DCC RESUME - requesting to resume DCC SEND */
static void ctcp_msg_dcc_resume(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *addr,
const char *target, DCC_REC *chat)
{
- DCC_REC *dcc;
+ FILE_DCC_REC *dcc;
char *str;
long size;
- if (!dcc_ctcp_resume_parse(DCC_TYPE_RESUME, data, nick, &dcc, &size)) {
+ if (!dcc_ctcp_resume_parse(DCC_SEND_TYPE, data, nick, &dcc, &size)) {
signal_emit("dcc error ctcp", 5, "RESUME", data,
nick, addr, target);
} else if (dcc != NULL && dcc_resume_file_check(dcc, server, size)) {
- str = g_strdup_printf(dcc->file_quoted ?
+ str = g_strdup_printf(DCC_SEND(dcc)->file_quoted ?
"DCC ACCEPT \"%s\" %d %lu" :
"DCC ACCEPT %s %d %lu",
dcc->arg, dcc->port, dcc->transfd);
@@ -104,23 +106,24 @@ static void ctcp_msg_dcc_resume(IRC_SERVER_REC *server, const char *data,
}
}
-/* CTCP: DCC ACCEPT */
+/* CTCP: DCC ACCEPT - accept resuming DCC GET */
static void ctcp_msg_dcc_accept(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *addr,
const char *target, DCC_REC *chat)
{
- DCC_REC *dcc;
+ FILE_DCC_REC *dcc;
long size;
- if (!dcc_ctcp_resume_parse(DCC_TYPE_ACCEPT, data, nick, &dcc, &size) ||
- (dcc != NULL && dcc->get_type != DCC_GET_RESUME)) {
+ if (!dcc_ctcp_resume_parse(DCC_GET_TYPE, data, nick, &dcc, &size) ||
+ (dcc != NULL && DCC_GET(dcc)->get_type != DCC_GET_RESUME)) {
signal_emit("dcc error ctcp", 5, "ACCEPT", data,
nick, addr, target);
} else if (dcc != NULL && dcc_resume_file_check(dcc, server, size))
- dcc_get_connect(dcc);
+ dcc_get_connect(DCC_GET(dcc));
}
-static void dcc_send_resume(DCC_REC *dcc)
+/* Resume a DCC GET */
+static void dcc_send_resume(GET_DCC_REC *dcc)
{
char *str;
@@ -142,7 +145,7 @@ static void dcc_send_resume(DCC_REC *dcc)
if (dcc->skipped == dcc->size) {
/* already received whole file */
dcc->starttime = time(NULL);
- dcc_reject(dcc, NULL);
+ dcc_reject(DCC(dcc), NULL);
} else {
str = g_strdup_printf(dcc->file_quoted ?
"DCC RESUME \"%s\" %d %lu" :
diff --git a/src/irc/dcc/dcc-send.c b/src/irc/dcc/dcc-send.c
index 2ad66b25..828b12e3 100644
--- a/src/irc/dcc/dcc-send.c
+++ b/src/irc/dcc/dcc-send.c
@@ -26,15 +26,36 @@
#include "misc.h"
#include "settings.h"
-#include "dcc.h"
+#include "dcc-send.h"
+#include "dcc-chat.h"
+
+static SEND_DCC_REC *dcc_send_create(IRC_SERVER_REC *server,
+ CHAT_DCC_REC *chat,
+ const char *nick, const char *arg)
+{
+ SEND_DCC_REC *dcc;
+
+ dcc = g_new0(SEND_DCC_REC, 1);
+ dcc->orig_type = module_get_uniq_id_str("DCC", "GET");
+ dcc->type = module_get_uniq_id_str("DCC", "SEND");
+ dcc->fhandle = -1;
+
+ dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ return dcc;
+}
+
+static void sig_dcc_destroyed(SEND_DCC_REC *dcc)
+{
+ if (!IS_DCC_SEND(dcc)) return;
+
+ if (dcc->fhandle != -1) close(dcc->fhandle);
+}
/* input function: DCC SEND - we're ready to send more data */
-static void dcc_send_data(DCC_REC *dcc)
+static void dcc_send_data(SEND_DCC_REC *dcc)
{
int ret;
- g_return_if_fail(dcc != NULL);
-
if (!dcc->fastsend && !dcc->gotalldata) {
/* haven't received everything we've send there yet.. */
return;
@@ -43,15 +64,14 @@ static void dcc_send_data(DCC_REC *dcc)
ret = read(dcc->fhandle, dcc->databuf, dcc->databufsize);
if (ret <= 0) {
/* end of file .. or some error .. */
- if (dcc->fastsend) {
+ if (!dcc->fastsend)
+ dcc_close(DCC(dcc));
+ else {
/* no need to call this function anymore..
in fact it just eats all the cpu.. */
dcc->waitforend = TRUE;
g_source_remove(dcc->tagwrite);
dcc->tagwrite = -1;
- } else {
- signal_emit("dcc closed", 1, dcc);
- dcc_destroy(dcc);
}
return;
}
@@ -66,13 +86,11 @@ static void dcc_send_data(DCC_REC *dcc)
}
/* input function: DCC SEND - received some data */
-static void dcc_send_read_size(DCC_REC *dcc)
+static void dcc_send_read_size(SEND_DCC_REC *dcc)
{
guint32 bytes;
int ret;
- g_return_if_fail(dcc != NULL);
-
if (dcc->count_pos == 4)
return;
@@ -80,8 +98,7 @@ static void dcc_send_read_size(DCC_REC *dcc)
ret = net_receive(dcc->handle, dcc->count_buf+dcc->count_pos,
4-dcc->count_pos);
if (ret == -1) {
- signal_emit("dcc closed", 1, dcc);
- dcc_destroy(dcc);
+ dcc_close(DCC(dcc));
return;
}
@@ -103,20 +120,17 @@ static void dcc_send_read_size(DCC_REC *dcc)
if (dcc->waitforend && dcc->gotalldata) {
/* file is sent */
- signal_emit("dcc closed", 1, dcc);
- dcc_destroy(dcc);
+ dcc_close(DCC(dcc));
}
}
/* input function: DCC SEND - someone tried to connect to our socket */
-static void dcc_send_connected(DCC_REC *dcc)
+static void dcc_send_connected(SEND_DCC_REC *dcc)
{
GIOChannel *handle;
IPADDR addr;
int port;
- g_return_if_fail(dcc != NULL);
-
/* accept connection */
handle = net_accept(dcc->handle, &addr, &port);
if (handle == NULL)
@@ -181,7 +195,8 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server,
char host[MAX_IP_LEN];
int hfile, port;
long fsize;
- DCC_REC *dcc, *chat;
+ SEND_DCC_REC *dcc;
+ CHAT_DCC_REC *chat;
IPADDR own_ip;
GIOChannel *handle;
@@ -203,7 +218,7 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server,
if ((server == NULL || !server->connected) && chat == NULL)
cmd_param_error(CMDERR_NOT_CONNECTED);
- if (dcc_find_request(DCC_TYPE_SEND, target, fname)) {
+ if (dcc_find_request(DCC_SEND_TYPE, target, fname)) {
signal_emit("dcc error send exists", 2, target, fname);
cmd_params_free(free_arg);
return;
@@ -232,7 +247,7 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server,
fname = g_basename(fname);
- dcc = dcc_create(DCC_TYPE_SEND, target, fname, server, chat);
+ dcc = dcc_send_create(server, chat, target, fname);
dcc->handle = handle;
dcc->port = port;
dcc->size = fsize;
@@ -242,7 +257,7 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server,
(GInputFunction) dcc_send_connected, dcc);
/* send DCC request */
- dcc_make_address(&own_ip, host);
+ dcc_ip2str(&own_ip, host);
str = g_strdup_printf(dcc->file_quoted ?
"DCC SEND \"%s\" %s %d %lu" :
"DCC SEND %s %s %d %lu",
@@ -255,13 +270,17 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server,
void dcc_send_init(void)
{
+ dcc_register_type("SEND");
settings_add_bool("dcc", "dcc_fast_send", TRUE);
settings_add_str("dcc", "dcc_upload_path", "~");
+ signal_add("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed);
command_bind("dcc send", NULL, (SIGNAL_FUNC) cmd_dcc_send);
}
void dcc_send_deinit(void)
{
+ dcc_unregister_type("SEND");
+ signal_remove("dcc destroyed", (SIGNAL_FUNC) sig_dcc_destroyed);
command_unbind("dcc send", (SIGNAL_FUNC) cmd_dcc_send);
}
diff --git a/src/irc/dcc/dcc-send.h b/src/irc/dcc/dcc-send.h
new file mode 100644
index 00000000..493b4cd8
--- /dev/null
+++ b/src/irc/dcc/dcc-send.h
@@ -0,0 +1,28 @@
+#ifndef __DCC_SEND_H
+#define __DCC_SEND_H
+
+#include "dcc.h"
+
+#define DCC_SEND(dcc) \
+ MODULE_CHECK_CAST_MODULE(dcc, SEND_DCC_REC, type, "DCC", "SEND")
+
+#define IS_DCC_SEND(dcc) \
+ (DCC_SEND(dcc) ? TRUE : FALSE)
+
+typedef struct {
+#include "dcc-file-rec.h"
+
+ unsigned int file_quoted:1; /* file name was received quoted ("file name") */
+
+ /* fastsending: */
+ unsigned int fastsend:1;
+ unsigned int waitforend:1; /* file is sent, just wait for the replies from the other side */
+ unsigned int gotalldata:1; /* got all acks from the other end (needed to make sure the end of transfer works right) */
+} SEND_DCC_REC;
+
+#define DCC_SEND_TYPE module_get_uniq_id_str("DCC", "SEND")
+
+void dcc_send_init(void);
+void dcc_send_deinit(void);
+
+#endif
diff --git a/src/irc/dcc/dcc.c b/src/irc/dcc/dcc.c
index 8e5cee14..93a51b7a 100644
--- a/src/irc/dcc/dcc.c
+++ b/src/irc/dcc/dcc.c
@@ -22,17 +22,15 @@
#include "signals.h"
#include "commands.h"
#include "network.h"
-#include "net-sendbuffer.h"
#include "line-split.h"
+#include "misc.h"
#include "settings.h"
#include "irc.h"
#include "dcc-chat.h"
#include "dcc-get.h"
-
-void dcc_send_init(void);
-void dcc_send_deinit(void);
+#include "dcc-send.h"
void dcc_resume_init(void);
void dcc_resume_deinit(void);
@@ -40,63 +38,58 @@ void dcc_resume_deinit(void);
void dcc_autoget_init(void);
void dcc_autoget_deinit(void);
-#define DCC_TYPES 5
-
-static const char *dcc_types[] = {
- "CHAT",
- "SEND",
- "GET",
- "RESUME",
- "ACCEPT"
-};
-
GSList *dcc_conns;
+static GSList *dcc_types;
static int dcc_timeouttag;
-/* Create new DCC record */
-DCC_REC *dcc_create(int type, const char *nick, const char *arg,
- IRC_SERVER_REC *server, DCC_REC *chat)
+void dcc_register_type(const char *type)
{
- DCC_REC *dcc;
+ dcc_types = g_slist_append(dcc_types, g_strdup(type));
+}
- g_return_val_if_fail(nick != NULL, NULL);
- g_return_val_if_fail(arg != NULL, NULL);
+void dcc_unregister_type(const char *type)
+{
+ GSList *pos;
+
+ pos = gslist_find_string(dcc_types, type);
+ if (pos != NULL) {
+ g_free(pos->data);
+ dcc_types = g_slist_remove(dcc_types, pos->data);
+ }
+}
+
+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);
- 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->fhandle = -1;
dcc->tagconn = dcc->tagread = dcc->tagwrite = -1;
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->chatnet == NULL ? NULL : g_strdup(server->connrec->chatnet));
- dcc_conns = g_slist_append(dcc_conns, dcc);
+ dcc->servertag = server != NULL ? g_strdup(server->tag) :
+ (chat == NULL ? NULL : g_strdup(chat->servertag));
+ dcc_conns = g_slist_append(dcc_conns, dcc);
signal_emit("dcc created", 1, dcc);
- return dcc;
-}
-
-static void dcc_remove_chat_refs(DCC_REC *dcc)
-{
- GSList *tmp;
-
- g_return_if_fail(dcc != NULL);
-
- for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
- DCC_REC *rec = tmp->data;
-
- if (rec->chat == dcc)
- rec->chat = NULL;
- }
}
/* Destroy DCC record */
@@ -106,47 +99,24 @@ void dcc_destroy(DCC_REC *dcc)
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 != NULL) net_disconnect(dcc->handle);
if (dcc->tagconn != -1) g_source_remove(dcc->tagconn);
if (dcc->tagread != -1) g_source_remove(dcc->tagread);
if (dcc->tagwrite != -1) g_source_remove(dcc->tagwrite);
- if (dcc->sendbuf != NULL) net_sendbuffer_destroy(dcc->sendbuf, FALSE);
- 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_not_null(dcc->chat_id);
+ g_free_not_null(dcc->servertag);
g_free_not_null(dcc->target);
+ g_free_not_null(dcc->databuf);
g_free(dcc->mynick);
g_free(dcc->nick);
g_free(dcc->arg);
g_free(dcc);
}
-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);
- g_snprintf(host, MAX_IP_LEN, "%lu",
- (unsigned long) htonl(addr));
- }
-}
-
DCC_REC *dcc_find_request_latest(int type)
{
DCC_REC *latest;
@@ -181,35 +151,21 @@ DCC_REC *dcc_find_request(int type, const char *nick, const char *arg)
return NULL;
}
-const char *dcc_type2str(int type)
-{
- g_return_val_if_fail(type >= 1 && type <= DCC_TYPES, NULL);
-
- return dcc_types[type-1];
-}
-
-int dcc_str2type(const char *type)
+void dcc_ip2str(IPADDR *ip, char *host)
{
- int num;
+ unsigned long addr;
- for (num = 0; num < DCC_TYPES; num++) {
- if (g_strcasecmp(dcc_types[num], type) == 0)
- return num+1;
+ if (is_ipv6_addr(ip)) {
+ /* IPv6 */
+ net_ip2host(ip, host);
+ } else {
+ memcpy(&addr, &ip->addr, 4);
+ g_snprintf(host, MAX_IP_LEN, "%lu",
+ (unsigned long) htonl(addr));
}
-
- return 0;
}
-GIOChannel *dcc_listen(GIOChannel *interface, IPADDR *ip, int *port)
-{
- if (net_getsockname(interface, ip, NULL) == -1)
- return NULL;
-
- *port = settings_get_int("dcc_port");
- return net_listen(ip, port);
-}
-
-void dcc_get_address(const char *str, IPADDR *ip)
+void dcc_str2ip(const char *str, IPADDR *ip)
{
unsigned long addr;
@@ -225,39 +181,29 @@ void dcc_get_address(const char *str, IPADDR *ip)
}
}
-void dcc_ctcp_message(IRC_SERVER_REC *server, const char *target,
- DCC_REC *chat, int notice, const char *msg)
+/* Start listening for incoming connections */
+GIOChannel *dcc_listen(GIOChannel *interface, IPADDR *ip, int *port)
{
- char *str;
-
- if (chat != NULL && chat->sendbuf != 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);
- g_free(str);
- } else {
- irc_send_cmdv(server, "%s %s :\001%s\001",
- notice ? "NOTICE" : "PRIVMSG", target, msg);
- }
+ if (net_getsockname(interface, ip, NULL) == -1)
+ return NULL;
+
+ *port = settings_get_int("dcc_port");
+ return net_listen(ip, port);
}
-/* Server connected, check if there's any open dcc sessions for this ircnet.. */
-static void dcc_server_connected(IRC_SERVER_REC *server)
+/* Server connected - update server for DCC records that have
+ the same server tag */
+static void sig_server_connected(IRC_SERVER_REC *server)
{
GSList *tmp;
g_return_if_fail(server != NULL);
- if (server->connrec->chatnet == 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->chatnet) == 0) {
+ if (dcc->server == NULL && dcc->servertag != NULL &&
+ g_strcasecmp(dcc->servertag, server->tag) == 0) {
dcc->server = server;
g_free(dcc->mynick);
dcc->mynick = g_strdup(server->nick);
@@ -265,8 +211,8 @@ static void dcc_server_connected(IRC_SERVER_REC *server)
}
}
-/* Server disconnected, remove it from all dcc records */
-static void dcc_server_disconnected(IRC_SERVER_REC *server)
+/* Server disconnected, remove it from all DCC records */
+static void sig_server_disconnected(IRC_SERVER_REC *server)
{
GSList *tmp;
@@ -275,14 +221,24 @@ static void dcc_server_disconnected(IRC_SERVER_REC *server)
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
DCC_REC *dcc = tmp->data;
- if (dcc->server != server)
- continue;
+ 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;
- dcc->server = dcc->ircnet == NULL ? NULL :
- IRC_SERVER(server_find_chatnet(dcc->ircnet));
- if (dcc->server != NULL) {
+ for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
+ DCC_REC *dcc = tmp->data;
+
+ if (dcc->server == server) {
g_free(dcc->mynick);
- dcc->mynick = g_strdup(dcc->server->nick);
+ dcc->mynick = g_strdup(server->nick);
}
}
}
@@ -331,22 +287,22 @@ static void ctcp_reply_dcc_reject(IRC_SERVER_REC *server, const char *data,
DCC_REC *chat)
{
DCC_REC *dcc;
- char *typestr, *args;
- int type;
+ char *type, *args;
- typestr = g_strdup(data);
- args = strchr(typestr, ' ');
+ type = g_strdup(data);
+ args = strchr(type, ' ');
if (args != NULL) *args++ = '\0'; else args = "";
- type = dcc_str2type(typestr);
- dcc = dcc_find_request(type, nick,
- type == DCC_TYPE_CHAT ? NULL : args);
- if (dcc != NULL) {
- signal_emit("dcc closed", 1, dcc);
- dcc_destroy(dcc);
- }
+ dcc = dcc_find_request(dcc_str2type(type), nick, args);
+ if (dcc != NULL) dcc_close(dcc);
+
+ g_free(type);
+}
- g_free(typestr);
+void dcc_close(DCC_REC *dcc)
+{
+ signal_emit("dcc closed", 1, dcc);
+ dcc_destroy(dcc);
}
/* Reject a DCC request */
@@ -355,16 +311,14 @@ void dcc_reject(DCC_REC *dcc, IRC_SERVER_REC *server)
g_return_if_fail(dcc != NULL);
if (dcc->server != NULL) server = dcc->server;
- if (server != NULL && (dcc->type != DCC_TYPE_CHAT ||
- dcc->starttime == 0)) {
+ if (server != NULL) {
signal_emit("dcc rejected", 1, dcc);
irc_send_cmdv(server, "NOTICE %s :\001DCC REJECT %s %s\001",
- dcc->nick, dcc_type2str(SWAP_SENDGET(dcc->type)),
+ dcc->nick, dcc_type2str(dcc->orig_type),
dcc->arg);
}
- signal_emit("dcc closed", 1, dcc);
- dcc_destroy(dcc);
+ dcc_close(dcc);
}
static int dcc_timeout_func(void)
@@ -374,14 +328,18 @@ static int dcc_timeout_func(void)
now = time(NULL)-settings_get_int("dcc_timeout");
for (tmp = dcc_conns; tmp != NULL; tmp = next) {
- DCC_REC *rec = tmp->data;
+ DCC_REC *dcc = tmp->data;
next = tmp->next;
- if (rec->tagread == -1 && now > rec->created) {
- /* timed out. */
- dcc_reject(rec, NULL);
+ 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);
}
}
+
return 1;
}
@@ -400,10 +358,8 @@ static void event_no_such_nick(IRC_SERVER_REC *server, char *data)
next = tmp->next;
if (!dcc_is_connected(dcc) && dcc->server == server &&
- g_strcasecmp(dcc->nick, nick) == 0) {
- signal_emit("dcc closed", 1, dcc);
- dcc_destroy(dcc);
- }
+ g_strcasecmp(dcc->nick, nick) == 0)
+ dcc_close(dcc);
}
g_free(params);
@@ -419,14 +375,15 @@ static void cmd_dcc_close(char *data, IRC_SERVER_REC *server)
g_return_if_fail(data != NULL);
- if (!cmd_get_params(data, &free_arg, 3, &typestr, &nick, &arg))
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
+ &typestr, &nick, &arg))
return;
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
g_strup(typestr);
type = dcc_str2type(typestr);
- if (type == 0) {
+ if (type == -1) {
signal_emit("dcc error unknown type", 1, typestr);
cmd_params_free(free_arg);
return;
@@ -437,9 +394,7 @@ static void cmd_dcc_close(char *data, IRC_SERVER_REC *server)
DCC_REC *dcc = tmp->data;
next = tmp->next;
- if (dcc->type == type &&
- g_strcasecmp(dcc->chat_id != NULL ?
- dcc->chat_id : dcc->nick, nick) == 0 &&
+ if (dcc->type == type && g_strcasecmp(dcc->nick, nick) == 0 &&
(*arg == '\0' || strcmp(dcc->arg, arg) == 0)) {
dcc_reject(dcc, server);
found = TRUE;
@@ -464,19 +419,19 @@ void irc_dcc_init(void)
dcc_conns = NULL;
dcc_timeouttag = g_timeout_add(1000, (GSourceFunc) dcc_timeout_func, NULL);
- settings_add_bool("dcc", "dcc_mirc_ctcp", FALSE);
settings_add_int("dcc", "dcc_port", 0);
settings_add_int("dcc", "dcc_timeout", 300);
settings_add_int("dcc", "dcc_block_size", 2048);
- signal_add("server connected", (SIGNAL_FUNC) dcc_server_connected);
- signal_add("server disconnected", (SIGNAL_FUNC) dcc_server_disconnected);
+ signal_add("server connected", (SIGNAL_FUNC) sig_server_connected);
+ signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
+ signal_add("server nick changed", (SIGNAL_FUNC) sig_server_nick_changed);
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);
+ signal_add("event 401", (SIGNAL_FUNC) event_no_such_nick);
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);
dcc_chat_init();
dcc_get_init();
@@ -487,23 +442,24 @@ void irc_dcc_init(void)
void irc_dcc_deinit(void)
{
+ while (dcc_conns != NULL)
+ dcc_destroy(dcc_conns->data);
+
dcc_chat_deinit();
dcc_get_deinit();
dcc_send_deinit();
dcc_resume_deinit();
dcc_autoget_deinit();
- signal_remove("server connected", (SIGNAL_FUNC) dcc_server_connected);
- signal_remove("server disconnected", (SIGNAL_FUNC) dcc_server_disconnected);
+ signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected);
+ signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
+ signal_remove("server nick changed", (SIGNAL_FUNC) sig_server_nick_changed);
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);
+ signal_remove("event 401", (SIGNAL_FUNC) event_no_such_nick);
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);
}
diff --git a/src/irc/dcc/dcc.h b/src/irc/dcc/dcc.h
index eabbef68..59647746 100644
--- a/src/irc/dcc/dcc.h
+++ b/src/irc/dcc/dcc.h
@@ -1,114 +1,61 @@
#ifndef __DCC_H
#define __DCC_H
+#include "modules.h"
#include "network.h"
#include "irc-servers.h"
-enum {
- DCC_TYPE_CHAT = 1,
- DCC_TYPE_SEND,
- DCC_TYPE_GET,
- DCC_TYPE_RESUME,
- DCC_TYPE_ACCEPT
-};
+#define DCC(dcc) ((DCC_REC *) (dcc))
-#define SWAP_SENDGET(a) ((a) == DCC_TYPE_SEND ? DCC_TYPE_GET : \
- (a) == DCC_TYPE_GET ? DCC_TYPE_SEND : (a))
+typedef struct CHAT_DCC_REC CHAT_DCC_REC;
-typedef struct DCC_REC {
- int type;
- time_t created;
-
- IRC_SERVER_REC *server;
- char *chat_id; /* unique identifier for dcc chat. usually same as nick. */
- char *nick;
- char *target; /* who the request was sent to - your nick, channel or NULL if you sent the request */
-
- struct DCC_REC *chat; /* if the request came through DCC chat */
-
- char *ircnet;
- char *mynick;
-
- char *arg;
- char *file; /* file name we're really moving, arg is just the reference.. */
-
- IPADDR addr; /* address we're connected in */
- char addrstr[MAX_IP_LEN]; /* in readable form */
- int port; /* port we're connected in */
-
- long size, transfd, skipped; /* file size / bytes transferred / skipped at start */
- GIOChannel *handle; /* socket handle */
- NET_SENDBUF_REC *sendbuf;
- int tagconn, tagread, tagwrite;
- int fhandle; /* file handle */
- time_t starttime; /* transfer start time */
- int trans_bytes;
-
- int get_type; /* DCC get: what to do if file exists? */
+typedef struct {
+#include "dcc-rec.h"
+} DCC_REC;
- unsigned int fastsend:1; /* fastsending (just in case that global fastsend toggle changes while transferring..) */
- unsigned int waitforend:1; /* DCC fast send: file is sent, just wait for the replies from the other side */
- unsigned int gotalldata:1; /* DCC fast send: got all acks from the other end (needed to make sure the end of transfer works right) */
+/* fully connected? */
+#define dcc_is_connected(dcc) \
+ ((dcc)->starttime != 0)
- unsigned int file_quoted:1; /* file name was received quoted ("file name") */
- unsigned int mirc_ctcp:1; /* DCC chat: Send CTCPs without the CTCP_MESSAGE prefix */
- unsigned int connection_lost:1; /* DCC chat: other side closed connection */
- unsigned int destroyed:1; /* We're about to destroy this DCC recond */
+/* not connected, we're waiting for other side to connect */
+#define dcc_is_listening(dcc) \
+ ((dcc)->handle != NULL && (dcc)->starttime == 0)
- /* read/write counter buffer */
- char count_buf[4];
- int count_pos;
+/* not connected, waiting for user to accept it */
+#define dcc_is_waiting_user(dcc) \
+ ((dcc)->handle == NULL)
- char *databuf; /* buffer for receiving/transmitting data */
- int databufsize;
+extern GSList *dcc_conns;
- GHashTable *module_data;
-} DCC_REC;
+void dcc_register_type(const char *type);
+void dcc_unregister_type(const char *type);
-extern GSList *dcc_conns;
+int dcc_str2type(const char *str);
+#define dcc_type2str(type) (module_find_id_str("DCC", type))
-void dcc_init(void);
-void dcc_deinit(void);
+/* Initialize DCC record */
+void dcc_init_rec(DCC_REC *dcc, IRC_SERVER_REC *server, CHAT_DCC_REC *chat,
+ const char *nick, const char *arg);
+void dcc_destroy(DCC_REC *dcc);
/* Find waiting DCC requests (non-connected) */
DCC_REC *dcc_find_request_latest(int type);
DCC_REC *dcc_find_request(int type, const char *nick, const char *arg);
-const char *dcc_type2str(int type);
-int dcc_str2type(const char *type);
-void dcc_make_address(IPADDR *ip, char *host);
-
-DCC_REC *dcc_create(int type, const char *nick, const char *arg,
- IRC_SERVER_REC *server, DCC_REC *chat);
-void dcc_destroy(DCC_REC *dcc);
+/* IP <-> string for DCC CTCP messages.
+ `str' must be at least MAX_IP_LEN bytes */
+void dcc_ip2str(IPADDR *ip, char *str);
+void dcc_str2ip(const char *str, IPADDR *ip);
+/* Start listening for incoming connections */
GIOChannel *dcc_listen(GIOChannel *interface, IPADDR *ip, int *port);
-void dcc_get_address(const char *str, IPADDR *ip);
-
-/* Send a CTCP message/notify to target. Send the CTCP via DCC chat if
- `chat' is specified. */
-void dcc_ctcp_message(IRC_SERVER_REC *server, const char *target,
- DCC_REC *chat, int notice, const char *msg);
-
-/* Send `data' to dcc chat. */
-void dcc_chat_send(DCC_REC *dcc, const char *data);
-/* If `item' is a query of a =nick, return DCC chat record of nick */
-DCC_REC *item_get_dcc(WI_ITEM_REC *item);
-
+/* Close DCC - sends "dcc closed" signal and calls dcc_destroy() */
+void dcc_close(DCC_REC *dcc);
/* Reject a DCC request */
void dcc_reject(DCC_REC *dcc, IRC_SERVER_REC *server);
-/* fully connected? */
-#define dcc_is_connected(dcc) \
- ((dcc)->starttime != 0)
-
-/* not connected, we're waiting for other side to connect */
-#define dcc_is_listening(dcc) \
- ((dcc)->handle != NULL && (dcc)->starttime == 0)
-
-/* not connected, waiting for user to accept it */
-#define dcc_is_waiting_user(dcc) \
- ((dcc)->handle == NULL)
+void dcc_init(void);
+void dcc_deinit(void);
#endif