]>
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
);
35 derefnode ( iptree
, t
-> node
);
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
;
48 Error ( "trusts" , ERR_FATAL
, "trusthostadd failed to createtrusthost" );
52 timenow
= getnettime ();
53 if ( node
-> usercount
> 0 ){
54 tgh
-> lastused
= timenow
;
55 tg
-> currenton
+= node
-> usercount
;
56 tg
-> lastused
= timenow
;
60 PATRICIA_WALK ( node
, inode
)
62 pnp
= inode
-> exts
[ pnode_ext
];
64 for ( i
= 0 ; i
< PATRICIANICK_HASHSIZE
; i
++) {
65 for ( np
= pnp
-> identhash
[ i
]; np
; np
= np
-> exts
[ pnick_ext
]) {
66 if ( trusts_ignore_np ( np
)) {
69 increment_ident_count ( np
, tg
);
76 node
-> exts
[ tgh_ext
] = tgh
;
81 void trusthost_addcounters ( trusthost_t
* tgh
) {
82 patricia_node_t
* inode
;
87 trustgroup_t
* tg
= tgh
-> trustgroup
;
88 if ( tgh
-> node
-> usercount
> 0 ){
89 tg
-> currenton
+= tgh
-> node
-> usercount
;
92 PATRICIA_WALK ( tgh
-> node
, inode
)
94 pnp
= inode
-> exts
[ pnode_ext
];
96 for ( i
= 0 ; i
< PATRICIANICK_HASHSIZE
; i
++) {
97 for ( np
= pnp
-> identhash
[ i
]; np
; np
= np
-> exts
[ pnick_ext
]) {
98 if ( trusts_ignore_np ( np
)) {
101 increment_ident_count ( np
, tg
);
102 np
-> exts
[ tgn_ext
] = tgh
;
109 tgh
-> node
-> exts
[ tgh_ext
] = tgh
;
113 void trusthost_expire ( trusthost_t
* th
) {
114 trustgroup_t
* tg
= th
-> trustgroup
;
116 if ( tg
-> expire
&& ( tg
-> expire
<= getnettime ())) {
117 /* check if trustgroup also expires */
118 trustgroup_expire ( tg
);
120 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
);
121 trustsdb_deletetrusthost ( th
-> node
-> exts
[ tgh_ext
]);
122 trusthost_free ( th
-> node
-> exts
[ tgh_ext
]);
123 th
-> node
-> exts
[ tgh_ext
] = NULL
;