5 #include "../core/nsmalloc.h"
6 #include "../lib/version.h"
14 unsigned long trusts_lasttrustgroupid
;
15 unsigned long trusts_lasttrusthostid
;
16 unsigned long trusts_lasttrustblockid
;
17 int trusts_loaded
= 0;
20 static void trusts_status(int hooknum
, void *arg
);
21 void trustsfinishinit(int hooknum
, void *arg
);
26 tgh_ext
= registernodeext("trusthost");
27 if ( tgh_ext
== -1 ) {
28 Error("trusts", ERR_FATAL
, "Could not register a required node extension (trusthost)");
32 tgb_ext
= registernodeext("trustblock");
33 if ( tgb_ext
== -1 ) {
34 Error("trusts", ERR_FATAL
, "Could not register a required node extension (trustblock)");
38 tgn_ext
= registernickext("trustnick");
39 if ( tgn_ext
== -1 ) {
40 Error("trusts", ERR_FATAL
, "Could not register a required nick extension (trustnick)");
44 registerhook(HOOK_TRUSTS_DBLOADED
, trustsfinishinit
);
46 if ( !trusts_load_db()) {
51 trustsfinishinit(HOOK_TRUSTS_DBLOADED
, NULL
);
54 void trustsfinishinit(int hooknum
, void *arg
) {
55 registerhook(HOOK_NICK_NEWNICK
, &trusts_hook_newuser
);
56 registerhook(HOOK_NICK_LOSTNICK
, &trusts_hook_lostuser
);
58 registerhook(HOOK_CORE_STATSREQUEST
, trusts_status
);
63 trustgroupidentcount_t
*t
;
67 deregisterhook(HOOK_TRUSTS_DBLOADED
, trustsfinishinit
);
69 if ( trusts_loaded
) {
70 deregisterhook(HOOK_NICK_NEWNICK
, &trusts_hook_newuser
);
71 deregisterhook(HOOK_NICK_LOSTNICK
, &trusts_hook_lostuser
);
73 deregisterhook(HOOK_CORE_STATSREQUEST
, trusts_status
);
76 for ( i
= 0; i
< TRUSTS_HASH_IDENTSIZE
; i
++ ) {
77 for ( t
= trustgroupidentcounttable
[i
]; t
; t
= t
-> next
) {
79 freesstring(t
->ident
);
84 patricia_node_t
*node
;
85 PATRICIA_WALK_CLEAR(iptree
->head
,node
) {
86 if (node
&& node
->exts
[tgb_ext
]) {
87 trustblock_free(node
->exts
[tgb_ext
]);
88 node
->exts
[tgb_ext
] = NULL
;
90 } PATRICIA_WALK_CLEAR_END
;
93 releasenodeext(tgh_ext
);
95 releasenodeext(tgb_ext
);
97 releasenickext(tgn_ext
);
103 nsfreeall(POOL_TRUSTS
);
106 void increment_trust_ipnode(patricia_node_t
*node
) {
107 patricia_node_t
*parent
;
108 trusthost_t
*tgh
= NULL
;
109 time_t curtime
= getnettime();
112 if(parent
->exts
&& parent
->exts
[tgh_ext
]) {
113 /* update the trusted hosts themselves */
114 tgh
= (trusthost_t
*)parent
->exts
[tgh_ext
];
115 tgh
->lastused
= curtime
;
116 if (tgh
->node
->usercount
> tgh
->maxused
) { tgh
->maxused
= tgh
->node
->usercount
; }
118 /* update the trustgroup itself */
119 tgh
->trustgroup
->currenton
++;
120 tgh
->trustgroup
->lastused
= curtime
;
121 if (tgh
->trustgroup
->currenton
> tgh
->trustgroup
->maxusage
) { tgh
->trustgroup
->maxusage
= tgh
->trustgroup
->currenton
; }
123 parent
= parent
->parent
;
127 void decrement_trust_ipnode(patricia_node_t
*node
) {
128 patricia_node_t
*parent
;
129 trusthost_t
*tgh
= NULL
;
130 time_t curtime
= getnettime();
134 if(parent
->exts
&& parent
->exts
[tgh_ext
]) {
135 tgh
= (trusthost_t
*)parent
->exts
[tgh_ext
];
136 tgh
->trustgroup
->currenton
--;
137 tgh
->lastused
= curtime
;
139 tgh
->trustgroup
->lastused
= curtime
;
141 parent
= parent
->parent
;
145 static void trusts_status(int hooknum
, void *arg
) {
148 int tgcount
= 0, thcount
= 0;
149 trustgroup_t
*tg
; trusthost_t
* thptr
; int i
;
151 for ( i
= 0; i
< TRUSTS_HASH_GROUPSIZE
; i
++ ) {
152 for ( tg
= trustgroupidtable
[i
]; tg
; tg
= tg
-> nextbyid
) {
157 for ( i
= 0; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
158 for ( thptr
= trusthostidtable
[i
]; thptr
; thptr
= thptr
-> nextbyid
) {
162 snprintf(message
, sizeof(message
), "Trusts :%7d groups, %7d hosts", tgcount
, thcount
);
163 triggerhook(HOOK_CORE_STATSREPLY
, message
);
167 int trusts_ignore_np(nick
*np
) {
168 if(SIsService(&serverlist
[homeserver(np
->numeric
)])) {
169 /* ANY user created by a server (nterface,fakeusers,Q) are ignored in relation to trusts */
170 /* NOTE: we might need to review this if we ever used newserv to handle client/user connections in some way */