5 #include "../core/nsmalloc.h"
8 static int trusts_loaded
;
10 static void trusts_status(int hooknum
, void *arg
);
15 tgh_ext
= registernodeext("trusthost");
17 Error("trusts", ERR_FATAL
, "Could not register a required node extension");
21 if ( !trusts_load_db()) {
28 registerhook(HOOK_NICK_NEWNICK
, &trusts_hook_newuser
);
29 registerhook(HOOK_NICK_LOSTNICK
, &trusts_hook_lostuser
);
31 registerhook(HOOK_CORE_STATSREQUEST
, trusts_status
);
36 trustgroupidentcount_t
*t
;
38 for ( i
= 0; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
39 for ( thptr
= trusthostidtable
[i
]; thptr
; thptr
= thptr
-> nextbyid
) {
40 derefnode(iptree
,thptr
->node
);
43 releasenodeext(tgh_ext
);
45 if ( trusts_loaded
) {
48 deregisterhook(HOOK_NICK_NEWNICK
, &trusts_hook_newuser
);
49 deregisterhook(HOOK_NICK_LOSTNICK
, &trusts_hook_lostuser
);
51 deregisterhook(HOOK_CORE_STATSREQUEST
, trusts_status
);
54 for ( i
= 0; i
< TRUSTS_HASH_IDENTSIZE
; i
++ ) {
55 for ( t
= trustgroupidentcounttable
[i
]; t
; t
= t
-> next
) {
57 freesstring(t
->ident
);
66 nsfreeall(POOL_TRUSTS
);
69 void increment_trust_ipnode(patricia_node_t
*node
) {
70 patricia_node_t
*parent
;
71 trusthost_t
*tgh
= NULL
;
72 time_t curtime
= getnettime();
75 if(parent
->exts
&& parent
->exts
[tgh_ext
]) {
76 /* update the trusted hosts themselves */
77 tgh
= (trusthost_t
*)parent
->exts
[tgh_ext
];
78 tgh
->lastused
= curtime
;
79 if (tgh
->node
->usercount
> tgh
->maxused
) { tgh
->maxused
= tgh
->node
->usercount
; }
81 /* update the trustgroup itself */
82 tgh
->trustgroup
->currenton
++;
83 tgh
->trustgroup
->lastused
= curtime
;
84 if (tgh
->trustgroup
->currenton
> tgh
->trustgroup
->maxusage
) { tgh
->trustgroup
->maxusage
= tgh
->trustgroup
->currenton
; }
86 parent
= parent
->parent
;
90 void decrement_trust_ipnode(patricia_node_t
*node
) {
91 patricia_node_t
*parent
;
92 trusthost_t
*tgh
= NULL
;
93 time_t curtime
= getnettime();
97 if(parent
->exts
&& parent
->exts
[tgh_ext
]) {
98 tgh
= (trusthost_t
*)parent
->exts
[tgh_ext
];
99 tgh
->trustgroup
->currenton
--;
100 tgh
->lastused
= curtime
;
102 tgh
->trustgroup
->lastused
= curtime
;
104 parent
= parent
->parent
;
108 void trust_debug(char *format
, ...) {
111 channel
*debugcp
= findchannel("#qnet.trusts");
113 va_start(va
, format
);
114 vsnprintf(buf
, sizeof(buf
), format
, va
);
116 controlchanmsg(debugcp
,buf
);
120 static void trusts_status(int hooknum
, void *arg
) {
123 int tgcount
= 0, thcount
= 0;
124 trustgroup_t
*tg
; trusthost_t
* thptr
; int i
;
126 for ( i
= 0; i
< TRUSTS_HASH_GROUPSIZE
; i
++ ) {
127 for ( tg
= trustgroupidtable
[i
]; tg
; tg
= tg
-> nextbyid
) {
132 for ( i
= 0; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
133 for ( thptr
= trusthostidtable
[i
]; thptr
; thptr
= thptr
-> nextbyid
) {
137 snprintf(message
, sizeof(message
), "Trusts :%7d groups, %7d hosts", tgcount
, thcount
);
138 triggerhook(HOOK_CORE_STATSREPLY
, message
);