]> jfr.im git - irc/quakenet/newserv.git/blob - trusts2/trusts_groups.c
add my version of trusts, trusts_newsearch, trusts_search modules
[irc/quakenet/newserv.git] / trusts2 / trusts_groups.c
1 #include "trusts.h"
2
3 trustgroup_t *createtrustgroupfromdb(unsigned long id,
4 unsigned long maxusage, unsigned long maxclones, unsigned long maxperident, unsigned short maxperip, int enforceident, time_t startdate, time_t lastused, time_t expire, unsigned long ownerid, int type, time_t created, time_t modified){
5 trustgroup_t *tg = createtrustgroup(id, maxclones, maxperident, maxperip, enforceident, expire, ownerid,type);
6 tg->maxusage = maxusage;
7 // currenton
8 tg->startdate = startdate;
9 tg->lastused = lastused;
10 tg->created = created;
11 tg->modified = modified;
12 return tg;
13 }
14 trustgroup_t *createtrustgroup(unsigned long id, unsigned long maxclones, unsigned long maxperident, unsigned short maxperip, int enforceident, time_t expire, unsigned long ownerid, int type) {
15 trustgroup_t *tg = newtrustgroup();
16
17 time_t timenow = getnettime();
18
19 tg->id = id;
20 tg->maxusage = 0;
21 tg->currenton = 0;
22 tg->maxclones = maxclones;
23 tg->maxperident = maxperident;
24 tg->maxperip = maxperip;
25 tg->enforceident = enforceident;
26 tg->startdate = timenow;
27 tg->lastused = 0;
28 tg->expire = expire;
29 tg->ownerid = ownerid;
30 tg->type = type;
31 tg->created = timenow;
32 tg->modified = timenow;
33 trusts_addtrustgrouptohash(tg);
34 return tg;
35 }
36
37 void trustgroup_free(trustgroup_t* t)
38 {
39 trusts_removetrustgroupfromhash(t);
40 freetrustgroup(t);
41 }
42
43 void trustgroup_expire (trustgroup_t *tg) {
44 trusthost_t *thptr, *nthptr;
45 /* set expire to 0 so we can call trusthost_expire without it bouncing back */
46 tg->expire = 0;
47
48 /* first expiry any trust hosts */
49 int hash = trusts_gettrusthostgroupidhash(tg->id);
50 thptr = trusthostgroupidtable[hash];
51 while (thptr) {
52 nthptr = thptr;
53 thptr=thptr->nextbygroupid;
54 if(nthptr->trustgroup == tg) {
55 trusthost_expire(nthptr);
56 }
57 }
58
59 /* secondly expire trust group */
60 controlwall(NO_OPER, NL_TRUSTS, "expired trustgroup #%lu",tg->id);
61 trustsdb_deletetrustgroup(tg);
62 trustgroup_free(tg);
63 }