]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/trusts_db.c
Implement removing TGs and THs.
[irc/quakenet/newserv.git] / trusts / trusts_db.c
index 2ed5dc38abb44867fc56a4a50ab8ee8f10079b0e..7f6b63d866060a84283773b947270470fa7a62ae 100644 (file)
@@ -321,12 +321,52 @@ void tg_update(trustgroup *tg) {
   );
 }
 
+void trustsdb_deletetg(char *table, trustgroup *tg)  {
+  trustsdb->squery(trustsdb,
+    "DELETE FROM ? WHERE id = ?",
+    "Tu", "groups", tg->id);
+}
+
 void tg_delete(trustgroup *tg) {
-  /* TODO */
+  trustgroup **pnext;
+
+  for(pnext=&tglist;*pnext;pnext=&((*pnext)->next)) {
+    if(*pnext == tg) {
+      *pnext = tg->next;
+      break;
+    }
+  }
+
+  trustsdb_deletetg("groups", tg);
+  tg_free(tg, 1);
+}
+
+void trustsdb_deleteth(char *table, trusthost *th) {
+  trustsdb->squery(trustsdb,
+    "DELETE FROM ? WHERE id = ?",
+    "Tu", "hosts", th->id); 
 }
 
 void th_delete(trusthost *th) {
-  /* TODO */
+  trusthost **pnext;
+  nick *np;
+
+  for(pnext=&(th->group->hosts);*pnext;pnext=&((*pnext)->next)) {
+    if(*pnext == th) {
+      *pnext = th->next;
+      break;
+    }
+  }
+
+  for(np=th->users;np;np=nextbytrust(np))
+    settrusthost(np, NULL);
+
+  th->group->count -= th->count;
+
+  trustsdb_deleteth("hosts", th);
+  th_free(th);
+
+  th_linktree();
 }
 
 void _init(void) {