#include "../core/hooks.h"
+#include "../irc/irc.h"
#include "trusts.h"
-static void __newnick(int hooknum, void *arg) {
- nick *sender = arg;
- uint32_t host;
+static void __counthandler(int hooknum, void *arg);
+
+void trusts_newnick(nick *sender, int moving) {
trusthost *th;
+ void *arg[2];
+ struct irc_in_addr ipaddress;
+
+ ip_canonicalize_tunnel(&ipaddress, &sender->p_ipaddr);
- host = irc_in_addr_v4_to_int(&sender->p_ipaddr);
- th = th_getbyhost(host);
+ th = th_getbyhost(&ipaddress);
settrusthost(sender, th);
if(!th) {
setnextbytrust(sender, NULL);
- return;
+ } else {
+ setnextbytrust(sender, th->users);
+ th->users = sender;
}
- setnextbytrust(sender, th->users);
- th->users = sender;
+ arg[0] = sender;
+ arg[1] = (void *)(long)moving;
- triggerhook(HOOK_TRUSTS_NEWNICK, sender);
+ /* sucks we have to do this, at least until we get priority hooks */
+ __counthandler(HOOK_TRUSTS_NEWNICK, arg);
+
+ triggerhook(HOOK_TRUSTS_NEWNICK, arg);
}
-static void __lostnick(int hooknum, void *arg) {
- nick *sender = arg, *np, *lp;
+static void __newnick(int hooknum, void *arg) {
+ trusts_newnick(arg, 0);
+}
+
+void trusts_lostnick(nick *sender, int moving) {
+ nick *np, *lp;
trusthost *th = gettrusthost(sender);
+ void *arg[2];
+
+ arg[0] = sender;
+ arg[1] = (void *)(long)moving;
+
+ __counthandler(HOOK_TRUSTS_LOSTNICK, arg);
+ triggerhook(HOOK_TRUSTS_LOSTNICK, arg);
if(!th)
return;
- triggerhook(HOOK_TRUSTS_LOSTNICK, sender);
-
/*
* we need to erase this nick from the trusthost list
* stored in the ->nextbytrust (ext) pointers in each nick
}
}
+static void __lostnick(int hooknum, void *arg) {
+ trusts_lostnick(arg, 0);
+}
+
static void __counthandler(int hooknum, void *arg) {
- time_t t = time(NULL);
- trusthost *th = gettrusthost((nick *)arg);
- trustgroup *tg = th->group;
+ time_t t = getnettime();
+ void **args = arg;
+ trusthost *th = gettrusthost((nick *)args[0]);
+ trustgroup *tg;
+
+ if(!th)
+ return;
+ tg = th->group;
tg->lastseen = th->lastseen = t;
if(hooknum == HOOK_TRUSTS_NEWNICK) {
th->count++;
}
}
+static int hooksregistered;
+
static void __dbloaded(int hooknum, void *arg) {
int i;
nick *np;
+ if(hooksregistered)
+ return;
+ hooksregistered = 1;
+
registerhook(HOOK_NICK_NEWNICK, __newnick);
registerhook(HOOK_NICK_LOSTNICK, __lostnick);
- registerhook(HOOK_TRUSTS_NEWNICK, __counthandler);
+/* registerhook(HOOK_TRUSTS_NEWNICK, __counthandler);
registerhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
+*/
/* we could do it by host, but hosts and ips are not bijective :( */
for(i=0;i<NICKHASHSIZE;i++)
__newnick(0, np);
}
-void trusts_registerevents(void) {
- registerhook(HOOK_TRUSTS_DB_LOADED, __dbloaded);
+static void __dbclosed(int hooknum, void *arg) {
+ if(!hooksregistered)
+ return;
+ hooksregistered = 0;
- if(trustsdbloaded)
- __dbloaded(0, NULL);
+ deregisterhook(HOOK_NICK_NEWNICK, __newnick);
+ deregisterhook(HOOK_NICK_LOSTNICK, __lostnick);
+
+/*
+ deregisterhook(HOOK_TRUSTS_NEWNICK, __counthandler);
+ deregisterhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
+*/
}
void trusts_deregisterevents(void) {
- if(trustsdbloaded) {
- deregisterhook(HOOK_NICK_NEWNICK, __newnick);
- deregisterhook(HOOK_NICK_LOSTNICK, __lostnick);
+ deregisterhook(HOOK_TRUSTS_DB_LOADED, __dbloaded);
+ deregisterhook(HOOK_TRUSTS_DB_CLOSED, __dbclosed);
- deregisterhook(HOOK_TRUSTS_NEWNICK, __counthandler);
- deregisterhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
- }
+ __dbclosed(0, NULL);
+}
- deregisterhook(HOOK_TRUSTS_DB_LOADED, __dbloaded);
+void trusts_registerevents(void) {
+ registerhook(HOOK_TRUSTS_DB_LOADED, __dbloaded);
+ registerhook(HOOK_TRUSTS_DB_CLOSED, __dbclosed);
+
+ if(trustsdbloaded)
+ __dbloaded(0, NULL);
}