]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts2/trusts_hosts.c
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
);
6 th
-> startdate
= startdate
;
7 th
-> lastused
= lastused
;
10 th
-> modified
= modified
;
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
));
18 time_t timenow
= getnettime ();
23 th
-> trustgroup
= trustgroup
;
24 th
-> created
= timenow
;
25 th
-> modified
= timenow
;
27 trusts_addtrusthosttohash ( th
);
31 void trusthost_free ( trusthost_t
* t
)
33 trusts_removetrusthostfromhash ( t
);
34 derefnode ( iptree
, t
-> node
);
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
;
50 timenow
= getnettime ();
51 if ( node
-> usercount
> 0 ){
52 tgh
-> lastused
= timenow
;
53 tg
-> currenton
+= node
-> usercount
;
54 tg
-> lastused
= timenow
;
58 PATRICIA_WALK ( node
, inode
)
60 pnp
= inode
-> exts
[ pnode_ext
];
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
);
71 node
-> exts
[ tgh_ext
] = tgh
;
76 void trusthost_addcounters ( trusthost_t
* tgh
) {
77 patricia_node_t
* inode
;
82 trustgroup_t
* tg
= tgh
-> trustgroup
;
83 if ( tgh
-> node
-> usercount
> 0 ){
84 tg
-> currenton
+= tgh
-> node
-> usercount
;
87 PATRICIA_WALK ( tgh
-> node
, inode
)
89 pnp
= inode
-> exts
[ pnode_ext
];
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
);
100 tgh
-> node
-> exts
[ tgh_ext
] = tgh
;
104 void trusthost_expire ( trusthost_t
* th
) {
105 trustgroup_t
* tg
= th
-> trustgroup
;
107 if ( tg
-> expire
&& ( tg
-> expire
<= getnettime ())) {
108 /* check if trustgroup also expires */
109 trustgroup_expire ( tg
);
111 controlwall ( NO_OPER
, NL_TRUSTS
, " %s / %d expired from trustgroup # %l u" , 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
;