]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/db.c
fix indentation
[irc/quakenet/newserv.git] / trusts / db.c
index 3ac1689fc0cdcb3bc6fec92e72302da21972e903..ae4af07eb79727538b07d2c9d097985a0e2bc52e 100644 (file)
@@ -48,6 +48,7 @@ static void loadcomplete(void) {
   if(loaderror)
     return;
 
+  th_linktree();
   trustsdbloaded = 1;
   flushschedule = schedulerecurring(time(NULL) + 300, 0, 300, flushdatabase, NULL);
 
@@ -226,3 +227,45 @@ void th_dbupdatecounts(trusthost *th) {
 void tg_dbupdatecounts(trustgroup *tg) {
   trustsdb->squery(trustsdb, "UPDATE ? SET lastseen = ?, maxusage = ? WHERE id = ?", "Ttuu", "groups", tg->lastseen, tg->maxusage, tg->id);
 }
+
+trusthost *th_new(trustgroup *tg, char *host) {
+  trusthost *th, *superset, *subset;
+  u_int32_t ip, mask;
+
+  /* ugh */
+  if(!trusts_str2cidr(host, &ip, &mask))
+    return NULL;
+
+  th_getsuperandsubsets(ip, mask, &superset, &subset);
+
+  th = th_add(tg, thmaxid + 1, host, 0, 0);
+  if(!th)
+    return NULL;
+
+  thmaxid++;
+
+  trustsdb->squery(trustsdb,
+    "INSERT INTO ? (id, groupid, host, maxusage, lastseen) VALUES (?, ?, ?, ?, ?)",
+    "Tuusut", "hosts", th->id, tg->id, trusts_cidr2str(th->ip, th->mask), th->maxusage, th->lastseen
+  );
+
+  th_adjusthosts(th, subset, superset);
+
+  th_linktree();
+  return th;
+}
+
+trustgroup *tg_new(char *name, unsigned int trustedfor, int mode, unsigned int maxperident, time_t expires, char *createdby, char *contact, char *comment) {
+  trustgroup *tg = tg_add(tgmaxid + 1, name, trustedfor, mode, maxperident, 0, expires, 0, 0, createdby, contact, comment);
+  if(!tg)
+    return NULL;
+
+  tgmaxid++;
+
+  trustsdb->squery(trustsdb,
+    "INSERT INTO ? (id, name, trustedfor, mode, maxperident, maxusage, expires, lastseen, lastmaxuserreset, createdby, contact, comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+    "Tusuuuutttsss", "groups", tg->id, tg->name->content, tg->trustedfor, tg->mode, tg->maxperident, tg->maxusage, tg->expires, tg->lastseen, tg->lastmaxuserreset, tg->createdby->content, tg->contact->content, tg->comment->content
+  );
+
+  return tg;
+}