X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ffnet-adc.c;h=19141a21df5374cb0713193a8116c471eeccb7aa;hb=28a3ef5280f4533ae00590965639453bc5275dba;hp=a72935b17b10acf9b12695f2b40ae1ace5a62481;hpb=0d6c5363e8da57e184e5db8306dd4d2a703f5888;p=doldaconnect.git diff --git a/daemon/fnet-adc.c b/daemon/fnet-adc.c index a72935b..19141a2 100644 --- a/daemon/fnet-adc.c +++ b/daemon/fnet-adc.c @@ -1,6 +1,6 @@ /* * Dolda Connect - Modular multiuser Direct Connect-style client - * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com) + * Copyright (C) 2004 Fredrik Tolf * * 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 @@ -58,7 +58,13 @@ struct qcmd { wchar_t **args; }; +struct qcmdqueue { + struct qcmd *f, *l; + int size; +}; + struct adchub { + struct socket *sk; char *inbuf; size_t inbufdata, inbufsize; wchar_t *sid; @@ -68,7 +74,7 @@ struct adchub { iconv_t ich; int state; struct wcspair *hubinf; - struct qcmd *queue; + struct qcmdqueue queue; }; static wchar_t *eoc; @@ -162,26 +168,31 @@ static void sendadc(struct socket *sk, int sep, ...) va_end(args); } -static struct qcmd *newqcmd(struct qcmd **queue, wchar_t **args) +static struct qcmd *newqcmd(struct qcmdqueue *queue, wchar_t **args) { struct qcmd *new; - while(*queue != NULL) - queue = &((*queue)->next); new = smalloc(sizeof(*new)); new->next = NULL; new->args = args; - *queue = new; + if(queue->l == NULL) + queue->f = new; + else + queue->l->next = new; + queue->l = new; + queue->size++; return(new); } -static struct qcmd *ulqcmd(struct qcmd **queue) +static struct qcmd *ulqcmd(struct qcmdqueue *queue) { struct qcmd *ret; - if((ret = *queue) == NULL) + if((ret = queue->f) == NULL) return(NULL); - *queue = ret->next; + if((queue->f = ret->next) == NULL) + queue->l = NULL; + queue->size--; return(ret); } @@ -193,14 +204,13 @@ static void freeqcmd(struct qcmd *qcmd) #define ADC_CMDFN(name) static void name(struct fnetnode *fn, wchar_t *command, wchar_t *sender, int argc, wchar_t **argv) #ifdef __GNUC__ -#define ADC_CMDCOM \ - struct socket *sk __attribute__ ((unused)) = fn->sk; \ - struct adchub *hub __attribute__ ((unused)) = fn->data; +#define UNUSED __attribute__ ((unused)) #else -#define ADC_CMDCOM \ - struct socket *sk = fn->sk; \ - struct adchub *hub = fn->data; +#define UNUSED #endif +#define ADC_CMDCOM \ + struct adchub *hub UNUSED = fn->data; \ + struct socket *sk UNUSED = hub->sk; ADC_CMDFN(cmd_sup) { @@ -352,32 +362,31 @@ static void huberr(struct socket *sk, int err, struct fnetnode *fn) 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); @@ -386,6 +395,14 @@ static void hubdestroy(struct fnetnode *fn) 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); @@ -399,6 +416,7 @@ static int hubreqconn(struct fnetpeer *peer) static struct fnet adcnet_store = { .connect = hubconnect, .destroy = hubdestroy, + .kill = hubkill, .setnick = hubsetnick, .reqconn = hubreqconn, .name = L"adc" @@ -421,7 +439,7 @@ static int run(void) 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;