]>
Commit | Line | Data |
---|---|---|
e2527cba P |
1 | #include "trusts.h" |
2 | ||
3 | trusthost_t *createtrusthostfromdb(unsigned long id, patricia_node_t* node, time_t startdate, time_t lastused, time_t expire, unsigned long maxused, trustgroup_t* trustgroup, time_t created, time_t modified){ | |
4 | trusthost_t *th = createtrusthost(id,node,expire,trustgroup); | |
5 | ||
6 | th->startdate=startdate; | |
7 | th->lastused = lastused; | |
8 | th->maxused = maxused; | |
9 | th->created = created; | |
10 | th->modified = modified; | |
11 | return th; | |
12 | } | |
13 | ||
14 | trusthost_t *createtrusthost(unsigned long id, patricia_node_t* node, time_t expire, trustgroup_t *trustgroup) { | |
15 | trusthost_t *th = newtrusthost(); | |
16 | memset(th, 0, sizeof(trusthost_t)); | |
17 | ||
18 | time_t timenow = getnettime(); | |
19 | ||
20 | th->id = id; | |
21 | th->node = node; | |
22 | th->expire = expire; | |
23 | th->trustgroup = trustgroup; | |
24 | th->created = timenow; | |
25 | th->modified = timenow; | |
26 | th->lastused = 0; | |
27 | trusts_addtrusthosttohash(th); | |
28 | return th; | |
29 | } | |
30 | ||
31 | void trusthost_free(trusthost_t* t) | |
32 | { | |
33 | trusts_removetrusthostfromhash(t); | |
34 | derefnode(iptree,t->node); | |
35 | freetrusthost(t); | |
36 | } | |
37 | ||
38 | trusthost_t* trusthostadd(patricia_node_t *node, trustgroup_t* tg, time_t expire) { | |
39 | trusthost_t* tgh = createtrusthost(++trusts_lasttrusthostid, node, expire, tg); | |
40 | patricia_node_t *inode; | |
41 | nick *np; | |
42 | patricianick_t *pnp; | |
43 | int i; | |
44 | time_t timenow; | |
45 | ||
46 | if(!tgh) { | |
47 | return NULL; | |
48 | } | |
49 | ||
50 | timenow = getnettime(); | |
51 | if(node->usercount >0){ | |
52 | tgh->lastused = timenow; | |
53 | tg->currenton += node->usercount; | |
54 | tg->lastused = timenow; | |
55 | } | |
56 | tgh->expire = expire; | |
57 | ||
58 | PATRICIA_WALK(node, inode) | |
59 | { | |
60 | pnp = inode->exts[pnode_ext]; | |
61 | if (pnp ) { | |
62 | for (i = 0; i < PATRICIANICK_HASHSIZE; i++) { | |
63 | for (np = pnp->identhash[i]; np; np=np->exts[pnick_ext]) { | |
64 | increment_ident_count(np, tg); | |
65 | } | |
66 | } | |
67 | } | |
68 | } | |
69 | PATRICIA_WALK_END; | |
70 | ||
71 | node->exts[tgh_ext] = tgh; | |
72 | ||
73 | return tgh; | |
74 | } | |
75 | ||
76 | void trusthost_addcounters(trusthost_t* tgh) { | |
77 | patricia_node_t *inode; | |
78 | nick *np; | |
79 | patricianick_t *pnp; | |
80 | int i; | |
81 | ||
82 | trustgroup_t* tg = tgh->trustgroup; | |
83 | if(tgh->node->usercount >0){ | |
84 | tg->currenton += tgh->node->usercount; | |
85 | } | |
86 | ||
87 | PATRICIA_WALK(tgh->node, inode) | |
88 | { | |
89 | pnp = inode->exts[pnode_ext]; | |
90 | if (pnp ) { | |
91 | for (i = 0; i < PATRICIANICK_HASHSIZE; i++) { | |
92 | for (np = pnp->identhash[i]; np; np=np->exts[pnick_ext]) { | |
93 | increment_ident_count(np, tg); | |
94 | } | |
95 | } | |
96 | } | |
97 | } | |
98 | PATRICIA_WALK_END; | |
99 | ||
100 | tgh->node->exts[tgh_ext] = tgh; | |
101 | } | |
102 | ||
103 | ||
104 | void trusthost_expire( trusthost_t *th) { | |
105 | trustgroup_t *tg = th->trustgroup; | |
106 | ||
107 | if(tg->expire && (tg->expire <= getnettime())) { | |
108 | /* check if trustgroup also expires */ | |
109 | trustgroup_expire(tg); | |
110 | } else { | |
111 | controlwall(NO_OPER, NL_TRUSTS, "%s/%d expired from trustgroup #%lu",IPtostr(th->node->prefix->sin),irc_bitlen(&(th->node->prefix->sin),th->node->prefix->bitlen),tg->id); | |
112 | trustsdb_deletetrusthost(th->node->exts[tgh_ext]); | |
113 | trusthost_free(th->node->exts[tgh_ext]); | |
114 | th->node->exts[tgh_ext] = NULL; | |
115 | } | |
116 | } |