#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include <fcntl.h>
#include <stdarg.h>
#include <string.h>
#include <netinet/in.h>
wchar_t **args;
};
+struct qcmdqueue {
+ struct qcmd *f, *l;
+ int size;
+};
+
struct adchub {
struct socket *sk;
char *inbuf;
iconv_t ich;
int state;
struct wcspair *hubinf;
- struct qcmd *queue;
+ struct qcmdqueue queue;
};
static wchar_t *eoc;
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);
}
if(!wcscmp(cmd->name, qcmd->args[0] + 1)) {
if(argc < cmd->minargs)
return;
- cmd->func(fn, cmdnm, sender, argc, qcmd->args);
+ cmd->func(fn, cmdnm, sender, argc, argv);
return;
}
}
{
struct adchub *hub;
- getsock(hub->sk = sk);
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(sk, 0, L"HSUP", L"ADBASE", eoc, NULL);
+ sendadc(sk, 0, L"HSUP", L"ADBASE", L"ADTIGR", eoc, NULL);
}
static void hubdestroy(struct fnetnode *fn)
regfnet(adcnet);
}
-static int init(int hup)
+static void makepid(char *idbuf)
{
int i;
+ int fd, ret;
+
+ i = 0;
+ if((fd = open("/dev/urandom", O_RDONLY)) >= 0) {
+ for(i = 0; i < 24; i += ret) {
+ if((ret = read(fd, idbuf + i, 24 - i)) <= 0) {
+ flog(LOG_WARNING, "could not read random data from /dev/urandom for ADC PID: %s", (errno == 0)?"EOF":strerror(errno));
+ break;
+ }
+ }
+ close(fd);
+ } else {
+ flog(LOG_WARNING, "could not open /dev/urandom: %s", strerror(errno));
+ }
+ if(i != 24) {
+ for(i = 0; i < sizeof(idbuf); i++)
+ idbuf[i] = rand() % 256;
+ }
+}
+
+static int init(int hup)
+{
char idbuf[24], *id32;
struct tigerhash th;
eoc = swcsdup(L"");
if((privid = fetchvar("adc.pid", NULL)) == NULL) {
- for(i = 0; i < sizeof(idbuf); i++)
- idbuf[i] = rand() % 256;
+ makepid(idbuf);
id32 = base32encode(idbuf, sizeof(idbuf));
id32[39] = 0;
privid = icmbstowcs(id32, "us-ascii");