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
This commit is contained in:
Timo Sirainen 2001-02-10 02:02:26 +00:00 committed by cras
commit e4f7d55ce9
20 changed files with 1398 additions and 912 deletions

View file

@ -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" :