int tract:1;
int trprog:1;
int srch:1;
+ int msg:1;
} b;
int w;
} notify;
wchar_t *username;
struct uiuser *userinfo;
+ int id;
+ wchar_t *regname;
uid_t uid;
struct notif *fnotif, *lnotif;
char *fcmdbuf;
size_t inbufsize, indata;
/* Wordset storage */
wchar_t **argv;
- int argc, args;
+ size_t argc, args;
/* WCS conversation stuff */
wchar_t *cb; /* Conversation buffer */
size_t cbsize, cbdata;
size_t cwsize, cwdata;
};
+static int uiread(struct socket *sk, struct uidata *data);
+static int uierror(struct socket *sk, int err, struct uidata *data);
static int srcheta(struct search *srch, void *uudata);
static int srchcommit(struct search *srch, void *uudata);
static int srchres(struct search *srch, struct srchres *sr, void *uudata);
+static struct notif *newnotif(struct uidata *data, int code, ...);
+static void notifappend(struct notif *notif, ...);
struct uiuser *users = NULL;
struct uidata *actives = NULL;
struct socket *uisocket = NULL;
+static time_t starttime;
static wchar_t *quoteword(wchar_t *word)
{
haveargs(3);
havepriv(PERM_FNETCTL);
+ for(i = 0, fn = fnetnodes; fn != NULL; i++, fn = fn->next);
+ if((confgetint("fnet", "maxnodes") > 0) && (i >= confgetint("fnet", "maxnodes"))) {
+ sq(sk, 0, L"515", L"Too many fnetnodes connected already", NULL);
+ return;
+ }
if((buf = icwcstombs(argv[2], NULL)) == NULL)
{
sq(sk, 0, L"504", L"Could not convert data to locale charset", NULL);
args = NULL;
for(i = 3; i < argc - 1; i += 2)
newwcspair(argv[i], argv[i + 1], &args);
- fn = fnetinitconnect(argv[1], buf, args);
+ fn = fnetinitconnect(argv[1], data->userinfo->name, buf, args);
err = errno;
free(buf);
if(fn == NULL)
}
linkfnetnode(fn);
fnetsetname(fn, argv[2]);
+ sq(sk, 0, L"200", L"%%i", fn->id, L"Connection under way", NULL);
putfnetnode(fn);
- sq(sk, 0, L"200", L"Connection under way", NULL);
}
static void cmd_lsnodes(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
sq(sk, 0, L"510", L"No such node", NULL);
return;
}
+ if(wpfind(fn->args, L"locked") && !((data->userinfo->perms & PERM_ADMIN) || !wcscmp(data->userinfo->name, fn->owner)))
+ {
+ sq(sk, 0, L"502", L"This node is locked and you are neither administrator nor its owner", NULL);
+ return;
+ }
killfnetnode(fn);
unlinkfnetnode(fn);
}
} else {
for(peer = fn->peers; peer != NULL; peer = peer->next)
{
- sq(sk, 2 | ((peer->next != NULL)?1:0), L"200", peer->id, peer->nick, NULL);
+ sq(sk, 2 | ((peer->next != NULL)?1:0), L"200", L"%%s", peer->id, L"%%s", peer->nick, NULL);
for(i = 0; i < peer->dinum; i++)
{
if(peer->peerdi[i].datum->datatype == FNPD_INT)
sq(sk, 2, peer->peerdi[i].datum->id, buf, NULL);
}
if((peer->peerdi[i].datum->datatype == FNPD_STR) && (peer->peerdi[i].data.str != NULL))
- sq(sk, 2, peer->peerdi[i].datum->id, peer->peerdi[i].data.str, NULL);
+ sq(sk, 2, peer->peerdi[i].datum->id, L"%%s", peer->peerdi[i].data.str, NULL);
}
sq(sk, 0, NULL);
}
data->notify.b.trprog = val;
} else if(!wcscasecmp(argv[i], L"srch:act")) {
data->notify.b.srch = val;
+ } else if(!wcscasecmp(argv[i], L"msg")) {
+ data->notify.b.msg = val;
}
}
sq(sk, 0, L"200", L"Notification alteration succeeded", NULL);
sq(sk, 0, L"200", L"Search cancelled", NULL);
}
-static void fcmdread(struct socket *sk, struct uidata *data)
+static int fcmdread(struct socket *sk, struct uidata *data)
{
char *buf;
size_t bufsize;
if((buf = sockgetinbuf(sk, &bufsize)) == NULL)
- return;
+ return(0);
bufcat(data->fcmdbuf, buf, bufsize);
free(buf);
+ return(0);
}
-static void fcmderr(struct socket *sk, int err, struct uidata *data)
+static int fcmderr(struct socket *sk, int err, struct uidata *data)
{
wchar_t *wbuf, *p, *p2;
}
data->fcmdbufsize = data->fcmdbufdata = 0;
sq(data->sk, 0, L"505", L"An error occurred on the pipe to the filtercmd", L"%%s", strerror(err), NULL);
- return;
+ return(0);
}
putsock(data->fcmdsk);
data->fcmdsk = NULL;
if(wbuf == NULL)
{
sq(data->sk, 0, L"504", L"Filtercmd sent data which could not be converted from the local charset", NULL);
- return;
+ return(0);
}
p = wbuf;
for(p2 = wcschr(p, L'\n'); p2 != NULL; p2 = wcschr(p, L'\n'))
sq(data->sk, 0, L"200", L"%%ls", p, NULL);
}
free(wbuf);
+ return(0);
}
static void cmd_filtercmd(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
sq(sk, 0, L"505", L"System error - Could not fork session", "Internal error", NULL);
return;
}
- if((filtercmd = findfile(icswcstombs(confgetstr("ui", "filtercmd"), NULL, NULL), "dcdl-filtercmd", pwent->pw_dir)) == NULL)
+ if((filtercmd = findfile(icswcstombs(confgetstr("ui", "filtercmd"), NULL, NULL), "dcdl-filtercmd", pwent->pw_dir, 0)) == NULL)
{
flog(LOG_WARNING, "could not find filtercmd executable for user %s", pwent->pw_name);
sq(sk, 0, L"505", L"System error - Could not fork session", L"Could not find filtercmd executable", NULL);
data->fcmdbuf = NULL;
}
data->fcmdbufsize = data->fcmdbufdata = 0;
- data->fcmdsk->data = data;
- data->fcmdsk->readcb = (void (*)(struct socket *, void *))fcmdread;
- data->fcmdsk->errcb = (void (*)(struct socket *, int, void *))fcmderr;
+ CBREG(data->fcmdsk, socket_read, (int (*)(struct socket *, void *))fcmdread, NULL, NULL);
+ CBREG(data->fcmdsk, socket_err, (int (*)(struct socket *, int, void *))fcmderr, NULL, NULL);
}
static void cmd_lstrarg(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
free(buf2);
}
+static void cmd_register(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
+{
+ struct uidata *d2;
+
+ haveargs(2);
+ if(data->userinfo == NULL) {
+ sq(sk, 0, L"502", L"Must be logged in", NULL);
+ return;
+ }
+ if(argv[1][0] == L'#') {
+ sq(sk, 0, L"509", L"Name must not begin with a hash sign", NULL);
+ return;
+ }
+ for(d2 = actives; d2 != NULL; d2 = d2->next) {
+ if((d2 != data) && (d2->userinfo == data->userinfo) && d2->regname && !wcscmp(d2->regname, argv[1])) {
+ sq(sk, 0, L"516", L"Name already in use", NULL);
+ return;
+ }
+ }
+ if(data->regname != NULL)
+ free(data->regname);
+ data->regname = swcsdup(argv[1]);
+ sq(sk, 0, L"200", L"Registered", NULL);
+}
+
+static void cmd_sendmsg(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
+{
+ int i, rcptid;
+ struct uidata *rcpt;
+ wchar_t *myname;
+ struct notif *notif;
+
+ haveargs(2);
+ if(data->userinfo == NULL) {
+ sq(sk, 0, L"502", L"Must be logged in", NULL);
+ return;
+ }
+ if(argv[1][0] == L'#') {
+ rcptid = wcstol(argv[1] + 1, NULL, 0);
+ for(rcpt = actives; rcpt != NULL; rcpt = rcpt->next) {
+ if((rcpt->userinfo == data->userinfo) && (rcpt->id == rcptid))
+ break;
+ }
+ } else {
+ for(rcpt = actives; rcpt != NULL; rcpt = rcpt->next) {
+ if((rcpt->userinfo == data->userinfo) && rcpt->regname && !wcscmp(rcpt->regname, argv[1]))
+ break;
+ }
+ }
+ if(rcpt == NULL) {
+ sq(sk, 0, L"517", L"No such recipient", NULL);
+ return;
+ }
+ if(!rcpt->notify.b.msg) {
+ sq(sk, 0, L"518", L"Recipient not listening for messages", NULL);
+ return;
+ }
+ if(data->regname != NULL)
+ myname = swcsdup(data->regname);
+ else
+ myname = swprintf2(L"#%i", data->id);
+ notif = newnotif(rcpt, 640, NOTIF_STR, myname, NOTIF_END);
+ for(i = 2; i < argc; i++)
+ notifappend(notif, NOTIF_STR, argv[i], NOTIF_END);
+ sq(sk, 0, L"200", L"Message sent", NULL);
+}
+
+static void cmd_uptime(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
+{
+ sq(sk, 0, L"200", L"%%i", time(NULL) - starttime, NULL);
+}
+
#undef haveargs
#undef havepriv
{L"lstrarg", cmd_lstrarg},
{L"hashstatus", cmd_hashstatus},
{L"transstatus", cmd_transstatus},
+ {L"register", cmd_register},
+ {L"sendmsg", cmd_sendmsg},
+ {L"uptime", cmd_uptime},
{NULL, NULL}
};
data->prev->next = data->next;
if(data == actives)
actives = data->next;
- data->sk->readcb = NULL;
- data->sk->errcb = NULL;
+ CBUNREG(data->sk, socket_read, uiread, data);
+ CBUNREG(data->sk, socket_err, uierror, data);
putsock(data->sk);
while((qcmd = unlinkqcmd(data)) != NULL)
freequeuecmd(qcmd);
}
if(data->auth != NULL)
authputhandle(data->auth);
+ if(data->regname != NULL)
+ free(data->regname);
if(data->username != NULL)
{
if(data->userinfo != NULL)
static struct uidata *newuidata(struct socket *sk)
{
struct uidata *data;
+ static int curid = 0;
data = smalloc(sizeof(*data));
memset(data, 0, sizeof(*data));
+ data->id = curid++;
data->sk = sk;
getsock(sk);
data->inbuf = smalloc(1024);
return(data);
}
-static void uiread(struct socket *sk, struct uidata *data)
+static int uiread(struct socket *sk, struct uidata *data)
{
int ret, done;
char *newbuf;
if(data->indata > 1024)
data->indata = 0;
if((newbuf = sockgetinbuf(sk, &datalen)) == NULL)
- return;
+ return(0);
sizebuf(&data->inbuf, &data->inbufsize, data->indata + datalen, 1, 1);
memcpy(data->inbuf + data->indata, newbuf, datalen);
free(newbuf);
break;
}
}
+ return(0);
}
-static void uierror(struct socket *sk, int err, struct uidata *data)
+static int uierror(struct socket *sk, int err, struct uidata *data)
{
if(err)
flog(LOG_WARNING, "error occurred on UI socket: %s", strerror(err));
freeuidata(data);
+ return(0);
}
-static void uiaccept(struct socket *sk, struct socket *newsk, void *data)
+static int uiaccept(struct socket *sk, struct socket *newsk, void *data)
{
struct uidata *uidata;
- newsk->data = uidata = newuidata(newsk);
+ uidata = newuidata(newsk);
socksettos(newsk, confgetint("ui", "uitos"));
if(uidata == NULL)
- return;
- newsk->errcb = (void (*)(struct socket *, int, void *))uierror;
- newsk->readcb = (void (*)(struct socket *, void *))uiread;
+ return(0);
+ CBREG(newsk, socket_err, (int (*)(struct socket *, int, void *))uierror, NULL, data);
+ CBREG(newsk, socket_read, (int (*)(struct socket *, void *))uiread, NULL, data);
queuecmd(uidata, &commands[0], 0, NULL);
+ return(0);
}
static int srcheta(struct search *srch, void *uudata)
}
if(!hup)
{
+ starttime = time(NULL);
if(uisocket != NULL)
putsock(uisocket);
if((uisocket = netcstcplisten(confgetint("ui", "port"), 1, uiaccept, NULL)) == NULL)