]>
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); | |
4f2ce270 | 34 | |
e2527cba P |
35 | derefnode(iptree,t->node); |
36 | freetrusthost(t); | |
37 | } | |
38 | ||
39 | trusthost_t* trusthostadd(patricia_node_t *node, trustgroup_t* tg, time_t expire) { | |
40 | trusthost_t* tgh = createtrusthost(++trusts_lasttrusthostid, node, expire, tg); | |
41 | patricia_node_t *inode; | |
42 | nick *np; | |
43 | patricianick_t *pnp; | |
44 | int i; | |
45 | time_t timenow; | |
46 | ||
47 | if(!tgh) { | |
4f2ce270 | 48 | Error("trusts", ERR_FATAL, "trusthostadd failed to createtrusthost"); |
e2527cba P |
49 | return NULL; |
50 | } | |
51 | ||
52 | timenow = getnettime(); | |
53 | if(node->usercount >0){ | |
54 | tgh->lastused = timenow; | |
55 | tg->currenton += node->usercount; | |
56 | tg->lastused = timenow; | |
57 | } | |
58 | tgh->expire = expire; | |
59 | ||
60 | PATRICIA_WALK(node, inode) | |
61 | { | |
62 | pnp = inode->exts[pnode_ext]; | |
63 | if (pnp ) { | |
64 | for (i = 0; i < PATRICIANICK_HASHSIZE; i++) { | |
65 | for (np = pnp->identhash[i]; np; np=np->exts[pnick_ext]) { | |
4f2ce270 P |
66 | if (trusts_ignore_np(np)) { |
67 | continue; | |
68 | } | |
e2527cba P |
69 | increment_ident_count(np, tg); |
70 | } | |
71 | } | |
72 | } | |
73 | } | |
74 | PATRICIA_WALK_END; | |
75 | ||
76 | node->exts[tgh_ext] = tgh; | |
77 | ||
78 | return tgh; | |
79 | } | |
80 | ||
81 | void trusthost_addcounters(trusthost_t* tgh) { | |
82 | patricia_node_t *inode; | |
83 | nick *np; | |
84 | patricianick_t *pnp; | |
85 | int i; | |
86 | ||
87 | trustgroup_t* tg = tgh->trustgroup; | |
88 | if(tgh->node->usercount >0){ | |
89 | tg->currenton += tgh->node->usercount; | |
90 | } | |
91 | ||
92 | PATRICIA_WALK(tgh->node, inode) | |
93 | { | |
94 | pnp = inode->exts[pnode_ext]; | |
95 | if (pnp ) { | |
96 | for (i = 0; i < PATRICIANICK_HASHSIZE; i++) { | |
97 | for (np = pnp->identhash[i]; np; np=np->exts[pnick_ext]) { | |
4f2ce270 P |
98 | if (trusts_ignore_np(np)) { |
99 | continue; | |
100 | } | |
e2527cba | 101 | increment_ident_count(np, tg); |
4f2ce270 | 102 | np->exts[tgn_ext] = tgh; |
e2527cba P |
103 | } |
104 | } | |
105 | } | |
106 | } | |
107 | PATRICIA_WALK_END; | |
108 | ||
109 | tgh->node->exts[tgh_ext] = tgh; | |
110 | } | |
111 | ||
112 | ||
113 | void trusthost_expire( trusthost_t *th) { | |
114 | trustgroup_t *tg = th->trustgroup; | |
115 | ||
116 | if(tg->expire && (tg->expire <= getnettime())) { | |
117 | /* check if trustgroup also expires */ | |
118 | trustgroup_expire(tg); | |
119 | } else { | |
120 | 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); | |
121 | trustsdb_deletetrusthost(th->node->exts[tgh_ext]); | |
122 | trusthost_free(th->node->exts[tgh_ext]); | |
123 | th->node->exts[tgh_ext] = NULL; | |
124 | } | |
125 | } |