/*
* Dolda Connect - Modular multiuser Direct Connect-style client
- * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
+ * Copyright (C) 2004 Fredrik Tolf <fredrik@dolda2000.com>
*
* 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
};
struct adchub {
+ struct socket *sk;
char *inbuf;
size_t inbufdata, inbufsize;
wchar_t *sid;
#define UNUSED
#endif
#define ADC_CMDCOM \
- struct socket *sk UNUSED = fn->sk; \
- struct adchub *hub UNUSED = fn->data;
+ struct adchub *hub UNUSED = fn->data; \
+ struct socket *sk UNUSED = hub->sk;
ADC_CMDFN(cmd_sup)
{
killfnetnode(fn);
}
-static void hubconnect(struct fnetnode *fn)
+static void hubconnect(struct fnetnode *fn, struct socket *sk)
{
struct adchub *hub;
- fn->sk->readcb = (void (*)(struct socket *, void *))hubread;
- fn->sk->errcb = (void (*)(struct socket *, int, void *))huberr;
- fn->sk->data = fn;
- getfnetnode(fn);
+ sk->readcb = (void (*)(struct socket *, void *))hubread;
+ sk->errcb = (void (*)(struct socket *, int, void *))huberr;
+ sk->data = fn;
hub = smalloc(sizeof(*hub));
memset(hub, 0, sizeof(*hub));
+ getsock(hub->sk = sk);
if((hub->ich = iconv_open("wchar_t", "utf-8")) == (iconv_t)-1) {
flog(LOG_CRIT, "iconv cannot handle UTF-8: %s", strerror(errno));
killfnetnode(fn);
return;
}
fn->data = hub;
- sendadc(fn->sk, 0, L"HSUP", L"ADBASE", eoc, NULL);
+ sendadc(sk, 0, L"HSUP", L"ADBASE", eoc, NULL);
}
static void hubdestroy(struct fnetnode *fn)
{
struct adchub *hub;
- if((hub = fn->data) == NULL)
- return;
+ hub = fn->data;
iconv_close(hub->ich);
if(hub->inbuf != NULL)
free(hub->inbuf);
free(hub);
}
+static void hubkill(struct fnetnode *fn)
+{
+ struct adchub *hub;
+
+ hub = fn->data;
+ hub->sk->close = 1;
+}
+
static int hubsetnick(struct fnetnode *fn, wchar_t *newnick)
{
return(0);
static struct fnet adcnet_store = {
.connect = hubconnect,
.destroy = hubdestroy,
+ .kill = hubkill,
.setnick = hubsetnick,
.reqconn = hubreqconn,
.name = L"adc"
if((hub = fn->data) == NULL)
continue;
if((qcmd = ulqcmd(&hub->queue)) != NULL) {
- if((fn->sk != NULL) && (fn->sk->state == SOCK_EST))
+ if((hub->sk != NULL) && (hub->sk->state == SOCK_EST))
dispatch(qcmd, fn);
freeqcmd(qcmd);
ret = 1;