.PHONY: all dirs $(TRUSTSDIRS) clean distclean
-all: trusts.so trusts_commands.so trusts_policy.so dirs
+all: trusts.so trusts_commands.so trusts_policy.so trusts_migration.so trusts_db.so dirs
-trusts.so: trusts.o db-migration.o data.o formats.o events.o
+trusts.so: trusts.o data.o formats.o events.o
+
+trusts_db.so: trusts_db.o
trusts_commands.so: trusts_commands.o
*subset = th_getsubsetbyhost(ip, mask);
}
-void trusts_flush(void) {
+void trusts_flush(void (*thflush)(trusthost *), void (*tgflush)(trustgroup *)) {
trustgroup *tg;
trusthost *th;
time_t t = time(NULL);
if(tg->count > 0)
tg->lastseen = t;
- tg_dbupdatecounts(tg);
+ tgflush(tg);
for(th=tg->hosts;th;th=th->next) {
if(th->count > 0)
th->lastseen = t;
- th_dbupdatecounts(th);
+ thflush(th);
}
}
}
static void statusfn(int, void *);
-static int loaded;
static sstring *tgextnames[MAXTGEXTS];
int trusts_thext, trusts_nextuserext;
+int trustsdbloaded;
void _init(void) {
trusts_thext = registernickext("trustth");
return;
}
- if(!trusts_loaddb())
- return;
- loaded = 1;
-
registerhook(HOOK_CORE_STATSREQUEST, statusfn);
trusts_registerevents();
}
releasenickext(trusts_nextuserext);
}
- if(loaded) {
- deregisterhook(HOOK_CORE_STATSREQUEST, statusfn);
- trusts_deregisterevents();
- }
-
- trusts_closedb(1);
+ deregisterhook(HOOK_CORE_STATSREQUEST, statusfn);
+ trusts_deregisterevents();
nscheckfreeall(POOL_TRUSTS);
}
static int loaderror;
static void *flushschedule;
-int trustsdbloaded;
-
void createtrusttables(int migration);
-void trusts_flush(void);
+void trusts_flush(void (*)(trusthost *), void (*)(trustgroup *));
void trusts_freeall(void);
+static void th_dbupdatecounts(trusthost *th);
+static void tg_dbupdatecounts(trustgroup *tg);
void createtrusttables(int migration) {
char *groups, *hosts;
}
static void flushdatabase(void *arg) {
- trusts_flush();
+ trusts_flush(th_dbupdatecounts, tg_dbupdatecounts);
}
static void triggerdbloaded(void *arg) {
triggerhook(HOOK_TRUSTS_DB_CLOSED, NULL);
}
-void th_dbupdatecounts(trusthost *th) {
+static void th_dbupdatecounts(trusthost *th) {
trustsdb->squery(trustsdb, "UPDATE ? SET lastseen = ?, maxusage = ? WHERE id = ?", "Ttuu", "hosts", th->lastseen, th->maxusage, th->id);
}
-void tg_dbupdatecounts(trustgroup *tg) {
+static void tg_dbupdatecounts(trustgroup *tg) {
trustsdb->squery(trustsdb, "UPDATE ? SET lastseen = ?, maxusage = ? WHERE id = ?", "Ttuu", "groups", tg->lastseen, tg->maxusage, tg->id);
}
return tg;
}
+
+void _init(void) {
+ trusts_loaddb();
+}
+
+void _fini(void) {
+ trusts_closedb(1);
+}