}
}
void sendbuf_chan_caps(struct channel *chan, unsigned positive, unsigned negative) {
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &chan->members) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &chan->members) == 1)
do {
struct client_data *cl = f->value;
if (!(~cl->caps & positive) && !(cl->caps & negative))
sendbuf(cl);
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
}
void sendbuf_chan(struct channel *chan) {
sendbuf_chan_caps(chan, 0, 0);
}
void sendbuf_list_sans_self_caps(struct client_data *client, map_t *ls, int cookie, int positive, int negative) {
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, ls) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, ls) == 1)
do {
struct client_data *cl = f->value;
if (client != cl) {
if (!(~cl->caps & positive) && !(cl->caps & negative))
sendbuf(cl);
}
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
}
void sendbuf_list_sans_self(struct client_data *client, map_t *ls, int cookie) {
sendbuf_list_sans_self_caps(client, ls, cookie, 0, 0);
static int cookie = 0;
if (++cookie == 0) {
// handle overflow
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &client_map) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &client_map) == 1)
do {
struct client_data *cl = f->value;
cl->cookie = 0;
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
cookie++;
}
return cookie;
}
void sendbuf_visible_caps(struct client_data *client, int positive, int negative) {
int cookie = get_cookie();
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &client->channels) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &client->channels) == 1)
do {
struct channel *chan = f->value;
sendbuf_list_sans_self_caps(client, &chan->members, cookie, positive, negative);
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
}
void sendbuf_visible(struct client_data *client) {
sendbuf_visible_caps(client, 0, 0);
}
int match_list(struct client_data *cl, map_t *list)
{
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, list) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, list) == 1)
do {
if (irc_glob(cl->nuh, f->key)) {
- free(f);
+ map_findfree(&f);
return 1;
}
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
return 0;
}
int parsePacket(struct client_data *client) {
if (!(client->umode & UMODE_OPER))
return err_noprivileges(client), sendbuf(client), 0;
msg_wallops(client, args[0]);
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &client_map) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &client_map) == 1)
do {
struct client_data *cl = f->value;
if (cl->umode & UMODE_WALLOPS)
sendbuf(cl);
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
} else if(strcmp(command, "KILL") == 0) {
if (!is_registered(client))
return err_notregistered(client), sendbuf(client), 0;
if (client == cl)
return 0; // FIXME: error message
msg_kill(client, cl, args[1] ? args[1] : "(no reason)");
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &client_map) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &client_map) == 1)
do {
struct client_data *cl2 = f->value;
if (cl2->umode & UMODE_OPER)
sendbuf(cl2);
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
// FIXME: add appropraite QUIT message
killConnection(cl, 0);
} else if(strcmp(command, "JEDGAR") == 0) {
if (!args[0])
return err_needmoreparams(client, command), sendbuf(client), 0;
if (!strcmp(args[0], "0")) {
- struct trie_find *f = NULL;
- while (trie_findfirst(&f, &client->channels) == 1) {
+ map_find_t f = {0};
+ while (map_findfirst(&f, &client->channels) == 1) {
struct channel *chan = f->value;
channel_part(client, chan, "I fell for a classic prank", NULL);
}
- free(f);
+ map_findfree(&f);
return 0;
}
char *p = args[0];
return err_notregistered(client), sendbuf(client), 0;
if (!args[0]) {
// List pending invites
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &client->invites) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &client->invites) == 1)
do {
struct channel *chan = f->value;
rpl_invitelist(client, chan), sendbuf(client);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
return rpl_endofinvitelist(client), sendbuf(client), 0;
}
if (!args[1])
if (!map_get(&chan->o, client->key))
return 0; // TODO: error
if (argc == 2) { // Type A channel modes
- struct trie_find *f = NULL;
+ map_find_t f = {0};
int all = !strcmp(args[1], "+0");
int any = 0;
if (all) {
any = 1;
}
if (all || !strcmp(args[1], "+b") || !strcmp(args[1], "b")) {
- if (trie_findfirst(&f, &chan->listb) == 1)
+ if (map_findfirst(&f, &chan->listb) == 1)
do {
rpl_banlist(client, chan, f->key), sendbuf(client);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
rpl_endofbanlist(client, chan), sendbuf(client);
any = 1;
}
if (all || !strcmp(args[1], "+e") || !strcmp(args[1], "e")) {
- if (trie_findfirst(&f, &chan->liste) == 1)
+ if (map_findfirst(&f, &chan->liste) == 1)
do {
rpl_exceptlist(client, chan, f->key), sendbuf(client);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
rpl_endofexceptlist(client, chan), sendbuf(client);
any = 1;
}
if (all || !strcmp(args[1], "+I") || !strcmp(args[1], "I")) {
- if (trie_findfirst(&f, &chan->listI) == 1)
+ if (map_findfirst(&f, &chan->listI) == 1)
do {
rpl_invexlist(client, chan, f->key), sendbuf(client);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
rpl_endofinvexlist(client, chan), sendbuf(client);
any = 1;
}
if (all || !strcmp(args[1], "+q") || !strcmp(args[1], "q")) {
- if (trie_findfirst(&f, &chan->listq) == 1)
+ if (map_findfirst(&f, &chan->listq) == 1)
do {
rpl_quietlist(client, chan, f->key), sendbuf(client);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
rpl_endofquietlist(client, chan), sendbuf(client);
any = 1;
}
if (all || !strcmp(args[1], "+w") || !strcmp(args[1], "w")) {
- if (trie_findfirst(&f, &chan->listwo) == 1)
+ if (map_findfirst(&f, &chan->listwo) == 1)
do {
rpl_accesslist(client, chan, 'o', f->key), sendbuf(client);
- } while(trie_findnext(&f) == 1);
- if (trie_findfirst(&f, &chan->listwv) == 1)
+ } while(map_findnext(&f) == 1);
+ if (map_findfirst(&f, &chan->listwv) == 1)
do {
rpl_accesslist(client, chan, 'v', f->key), sendbuf(client);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
rpl_endofaccesslist(client, chan), sendbuf(client);
any = 1;
}
if (!is_registered(client))
return err_notregistered(client), sendbuf(client), 0;
rpl_liststart(client), sendbuf(client);
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &channel_map) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &channel_map) == 1)
do {
struct channel *chan = f->value;
if (!(chan->dmode & DMODE_SECRET) || map_get(&chan->members, client->key))
rpl_list(client, chan), sendbuf(client);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
rpl_listend(client), sendbuf(client);
} else if(strcmp(command, "NAMES") == 0) {
if (!is_registered(client))
struct channel *chan = findChannel(args[0]);
// TODO: handle chanmode +s, umode +i
if (chan) {
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &chan->members) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &chan->members) == 1)
do {
struct client_data *cl = f->value;
rpl_whoreply(client, cl, chan), sendbuf(client);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
}
} else {
struct client_data *cl = findClient(args[0]);
rpl_whoisidle(client, cl), sendbuf(client);
if (cl->away)
rpl_away(client, cl), sendbuf(client);
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &cl->channels) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &cl->channels) == 1)
do {
struct channel *chan = f->value;
if ((cl->umode & UMODE_INVISIBLE || chan->dmode & DMODE_SECRET) && !map_get(&chan->members, client->key))
continue;
rpl_whoischannels(client, cl, chan), sendbuf(client);
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
if (cl->umode & UMODE_REGISTERED)
rpl_whoisaccount(client, cl), sendbuf(client);
if (client == cl || client->umode & UMODE_OPER)
sendLUSERS(client);
rpl_umodeis(client), sendbuf(client);
sendMOTD(client);
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &autojoin) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &autojoin) == 1)
do {
channel_join(client, f->key, NULL);
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
}
void sendLUSERS(struct client_data *client)
{
int invisible = 0;
int ops = 0;
int channels = 0;
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &client_map) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &client_map) == 1)
do {
struct client_data *cl = f->value;
registered++;
invisible++;
if (cl->umode & UMODE_OPER)
ops++;
- } while (trie_findnext(&f) == 1);
- if (trie_findfirst(&f, &client_map) == 1)
+ } while (map_findnext(&f) == 1);
+ if (map_findfirst(&f, &client_map) == 1)
do {
channels++;
- } while (trie_findnext(&f) == 1);
+ } while (map_findnext(&f) == 1);
for (struct client_data *cl = clients; cl; cl = cl->next)
total++;
sendbuf(client);
sendbuf_visible(client);
map_unset(&client_map, client->key, NULL);
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &client->channels) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &client->channels) == 1)
do {
struct channel *chan = f->value;
map_unset(&chan->members, client->key, NULL);
if (old)
if (map_set(&chan->v, key, client, NULL) == -1)
abort();
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
free(client->nick);
free(client->key);
}
}
void channel_sendnames(struct client_data *client, struct channel *chan)
{
- struct trie_find *f = NULL;
+ map_find_t f = {0};
databuf.len = 0;
- if (trie_findfirst(&f, &chan->members) == 1)
+ if (map_findfirst(&f, &chan->members) == 1)
do {
struct client_data *cl = f->value;
if (rpl_namreply(client, chan, cl)) {
databuf.len = 0;
rpl_namreply(client, chan, cl);
}
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
if (rpl_namreply(client, chan, NULL))
sendbuf(client);
rpl_endofnames(client, chan->name);
void channel_kill(struct channel *chan)
{
map_unset(&channel_map, chan->key, NULL);
- struct trie_find *f = NULL;
- if (trie_findfirst(&f, &chan->invitees) == 1)
+ map_find_t f = {0};
+ if (map_findfirst(&f, &chan->invitees) == 1)
do {
struct client_data *cl = f->value;
map_unset(&cl->invites, chan->key, NULL);
- } while(trie_findnext(&f) == 1);
+ } while(map_findnext(&f) == 1);
free(chan->key);
free(chan->name);
free(chan->topic);