}
trustsdb->createtable(trustsdb, NULL, NULL,
- "CREATE TABLE ? (id INT PRIMARY KEY, name VARCHAR(?), trustedfor INT, mode INT, maxperident INT, maxusage INT, expires INT, lastseen INT, lastmaxuserreset INT, createdby VARCHAR(?), contact VARCHAR(?), comment VARCHAR(?))",
- "Tdddd", groups, TRUSTNAMELEN, NICKLEN, CONTACTLEN, COMMENTLEN
+ "CREATE TABLE ? (id INT PRIMARY KEY, name VARCHAR(?), trustedfor INT, mode INT, maxperident INT, maxusage INT, expires INT, lastseen INT, lastmaxusereset INT, createdby VARCHAR(?), contact VARCHAR(?), comment VARCHAR(?))",
+ "Tdddd", groups, TRUSTNAMELEN, CREATEDBYLEN, CONTACTLEN, COMMENTLEN
);
/* I'd like multiple keys here but that's not gonna happen on a cross-database platform :( */
tg.maxusage = strtoul(result->get(result, 5), NULL, 10);
tg.expires = (time_t)strtoul(result->get(result, 6), NULL, 10);
tg.lastseen = (time_t)strtoul(result->get(result, 7), NULL, 10);
- tg.lastmaxuserreset = (time_t)strtoul(result->get(result, 8), NULL, 10);
- tg.createdby = getsstring(rtrim(result->get(result, 9)), NICKLEN);
+ tg.lastmaxusereset = (time_t)strtoul(result->get(result, 8), NULL, 10);
+ tg.createdby = getsstring(rtrim(result->get(result, 9)), CREATEDBYLEN);
tg.contact = getsstring(rtrim(result->get(result, 10)), CONTACTLEN);
tg.comment = getsstring(rtrim(result->get(result, 11)), COMMENTLEN);
itg->id = tgmaxid + 1;
itg->maxusage = 0;
itg->lastseen = 0;
- itg->lastmaxuserreset = 0;
+ itg->lastmaxusereset = 0;
tg = tg_copy(itg);
if(!tg)
void trustsdb_inserttg(char *table, trustgroup *tg) {
trustsdb->squery(trustsdb,
- "INSERT INTO ? (id, name, trustedfor, mode, maxperident, maxusage, expires, lastseen, lastmaxuserreset, createdby, contact, comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- "Tusuuuutttsss", table, 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
+ "INSERT INTO ? (id, name, trustedfor, mode, maxperident, maxusage, expires, lastseen, lastmaxusereset, createdby, contact, comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ "Tusuuuutttsss", table, tg->id, tg->name->content, tg->trustedfor, tg->mode, tg->maxperident, tg->maxusage, tg->expires, tg->lastseen, tg->lastmaxusereset, tg->createdby->content, tg->contact->content, tg->comment->content
);
}
+void tg_update(trustgroup *tg) {
+ trustsdb->squery(trustsdb,
+ "UPDATE ? SET name = ?, trustedfor = ?, maxperident = ?, maxusage = ?, expires = ?, lastseen = ?, lastmaxusereset = ?, createdby = ?, contact = ?, comment = ? WHERE id = ?",
+ "Tsuuuutttsssu", "groups", tg->name->content, tg->trustedfor, tg->mode, tg->maxperident, tg->maxusage, tg->expires, tg->lastseen, tg->lastmaxusereset, tg->createdby->content, tg->contact->content, tg->comment->content, tg->id
+ );
+}
+
+void trustsdb_deletetg(char *table, trustgroup *tg) {
+ trustsdb->squery(trustsdb,
+ "DELETE FROM ? WHERE id = ?",
+ "Tu", "groups", tg->id);
+}
+
+void tg_delete(trustgroup *tg) {
+ 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) {
+ 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) {
trusts_connectdb();
}