ref: 4b27eadd45e9d157374782d164e8a79faf08575c
dir: /client.c/
#include <u.h>
#include <libc.h>
#include <String.h>
#include "dat.h"
#include "fns.h"
#include "ll.h"
static Linked *clients = nil;
Client*
addclient(ulong fid)
{
Client *n;
n = mallocz(sizeof(Client), 1);
n->fid = fid;
n->replies.reply = s_new();
ladd(&clients, n);
return n;
}
static void
freeclient(void *ptr)
{
String *s;
Client *c = ptr;
s = c->replies.reply;
s_free(s);
free(c);
}
void
delclient(Client *c)
{
ldel(&clients, c, freeclient);
}
static int
findbyfid(void *ptr, void *aux)
{
ulong *fid = aux;
Client *c = ptr;
return *fid == c->fid;
}
Client*
findclient(ulong fid)
{
Client *c = lfind(&clients, findbyfid, &fid);
return c;
}
static int
findbynick(void *ptr, void *aux)
{
char *nick = aux;
Client *c = ptr;
return c->nick && strcmp(c->nick, nick) == 0;
}
Client*
findnick(char *nick)
{
return lfind(&clients, findbynick, nick);
}