]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Seperate out db from main module.
authorChris Porter <redacted>
Sat, 4 Oct 2008 00:36:54 +0000 (01:36 +0100)
committerChris Porter <redacted>
Sat, 4 Oct 2008 00:36:54 +0000 (01:36 +0100)
trusts/Makefile.in
trusts/data.c
trusts/trusts.c
trusts/trusts_db.c [moved from trusts/db.c with 95% similarity]

index 1d1028b0679e574a2ba9e1fbce307f5eec48c9df..7f8d2a36fbcdbd7cdfdb49fa39928a41bb435d1c 100644 (file)
@@ -4,9 +4,11 @@ TRUSTSDIRS=newsearch
 
 .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
 
index 456699a68009bc500a95baaf83a0a249b3b5faa9..df943a7ab69092303e7f788e7837815f8511042c 100644 (file)
@@ -261,7 +261,7 @@ void th_getsuperandsubsets(uint32_t ip, uint32_t mask, trusthost **superset, tru
   *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);
@@ -270,13 +270,13 @@ void trusts_flush(void) {
     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);
     }
   }
 }
index 73ba9c25f68e33f98bc67ba5967c0a6bce99ddfe..d2f811aa3e306214a847178b3932d5154c1110b0 100644 (file)
@@ -10,10 +10,10 @@ void trusts_deregisterevents(void);
 
 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");
@@ -29,10 +29,6 @@ void _init(void) {
     return;
   }
 
-  if(!trusts_loaddb())
-    return;
-  loaded = 1;
-
   registerhook(HOOK_CORE_STATSREQUEST, statusfn);
   trusts_registerevents();
 }
@@ -43,12 +39,8 @@ void _fini(void) {
     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);
 }
similarity index 95%
rename from trusts/db.c
rename to trusts/trusts_db.c
index ae4af07eb79727538b07d2c9d097985a0e2bc52e..48b4fe9b1641467f7cf6f3f1d3b8d13267b5640c 100644 (file)
@@ -9,11 +9,11 @@ static int tgmaxid, thmaxid;
 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;
@@ -36,7 +36,7 @@ void createtrusttables(int migration) {
 }
 
 static void flushdatabase(void *arg) {
-  trusts_flush();
+  trusts_flush(th_dbupdatecounts, tg_dbupdatecounts);
 }
 
 static void triggerdbloaded(void *arg) {
@@ -220,11 +220,11 @@ void trusts_closedb(int closeconnection) {
   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);
 }
 
@@ -269,3 +269,11 @@ trustgroup *tg_new(char *name, unsigned int trustedfor, int mode, unsigned int m
 
   return tg;
 }
+
+void _init(void) {
+  trusts_loaddb();
+}
+
+void _fini(void) {
+  trusts_closedb(1);
+}