5 #include "../core/nsmalloc.h"
11 unsigned long trusts_lasttrustgroupid
;
12 unsigned long trusts_lasttrusthostid
;
13 unsigned long trusts_lasttrustblockid
;
14 int trusts_loaded
= 0;
17 static void trusts_status(int hooknum
, void *arg
);
18 void trustsfinishinit(int hooknum
, void *arg
);
23 tgh_ext
= registernodeext("trusthost");
24 if ( tgh_ext
== -1 ) {
25 Error("trusts", ERR_FATAL
, "Could not register a required node extension (trusthost)");
29 tgb_ext
= registernodeext("trustblock");
30 if ( tgb_ext
== -1 ) {
31 Error("trusts", ERR_FATAL
, "Could not register a required node extension (trustblock)");
35 tgn_ext
= registernickext("trustnick");
36 if ( tgn_ext
== -1 ) {
37 Error("trusts", ERR_FATAL
, "Could not register a required nick extension (trustnick)");
41 registerhook(HOOK_TRUSTS_DBLOADED
, trustsfinishinit
);
43 if ( !trusts_load_db()) {
48 trustsfinishinit(HOOK_TRUSTS_DBLOADED
, NULL
);
51 void trustsfinishinit(int hooknum
, void *arg
) {
52 registerhook(HOOK_NICK_NEWNICK
, &trusts_hook_newuser
);
53 registerhook(HOOK_NICK_LOSTNICK
, &trusts_hook_lostuser
);
55 registerhook(HOOK_CORE_STATSREQUEST
, trusts_status
);
60 trustgroupidentcount_t
*t
;
64 deregisterhook(HOOK_TRUSTS_DBLOADED
, trustsfinishinit
);
66 if ( trusts_loaded
) {
67 deregisterhook(HOOK_NICK_NEWNICK
, &trusts_hook_newuser
);
68 deregisterhook(HOOK_NICK_LOSTNICK
, &trusts_hook_lostuser
);
70 deregisterhook(HOOK_CORE_STATSREQUEST
, trusts_status
);
73 for ( i
= 0; i
< TRUSTS_HASH_IDENTSIZE
; i
++ ) {
74 for ( t
= trustgroupidentcounttable
[i
]; t
; t
= t
-> next
) {
76 freesstring(t
->ident
);
81 patricia_node_t
*node
;
82 PATRICIA_WALK_CLEAR(iptree
->head
,node
) {
83 if (node
&& node
->exts
[tgb_ext
]) {
84 trustblock_free(node
->exts
[tgb_ext
]);
85 node
->exts
[tgb_ext
] = NULL
;
87 } PATRICIA_WALK_CLEAR_END
;
90 releasenodeext(tgh_ext
);
92 releasenodeext(tgb_ext
);
94 releasenodeext(tgn_ext
);
100 nsfreeall(POOL_TRUSTS
);
103 void increment_trust_ipnode(patricia_node_t
*node
) {
104 patricia_node_t
*parent
;
105 trusthost_t
*tgh
= NULL
;
106 time_t curtime
= getnettime();
109 if(parent
->exts
&& parent
->exts
[tgh_ext
]) {
110 /* update the trusted hosts themselves */
111 tgh
= (trusthost_t
*)parent
->exts
[tgh_ext
];
112 tgh
->lastused
= curtime
;
113 if (tgh
->node
->usercount
> tgh
->maxused
) { tgh
->maxused
= tgh
->node
->usercount
; }
115 /* update the trustgroup itself */
116 tgh
->trustgroup
->currenton
++;
117 tgh
->trustgroup
->lastused
= curtime
;
118 if (tgh
->trustgroup
->currenton
> tgh
->trustgroup
->maxusage
) { tgh
->trustgroup
->maxusage
= tgh
->trustgroup
->currenton
; }
120 parent
= parent
->parent
;
124 void decrement_trust_ipnode(patricia_node_t
*node
) {
125 patricia_node_t
*parent
;
126 trusthost_t
*tgh
= NULL
;
127 time_t curtime
= getnettime();
131 if(parent
->exts
&& parent
->exts
[tgh_ext
]) {
132 tgh
= (trusthost_t
*)parent
->exts
[tgh_ext
];
133 tgh
->trustgroup
->currenton
--;
134 tgh
->lastused
= curtime
;
136 tgh
->trustgroup
->lastused
= curtime
;
138 parent
= parent
->parent
;
142 static void trusts_status(int hooknum
, void *arg
) {
145 int tgcount
= 0, thcount
= 0;
146 trustgroup_t
*tg
; trusthost_t
* thptr
; int i
;
148 for ( i
= 0; i
< TRUSTS_HASH_GROUPSIZE
; i
++ ) {
149 for ( tg
= trustgroupidtable
[i
]; tg
; tg
= tg
-> nextbyid
) {
154 for ( i
= 0; i
< TRUSTS_HASH_HOSTSIZE
; i
++ ) {
155 for ( thptr
= trusthostidtable
[i
]; thptr
; thptr
= thptr
-> nextbyid
) {
159 snprintf(message
, sizeof(message
), "Trusts :%7d groups, %7d hosts", tgcount
, thcount
);
160 triggerhook(HOOK_CORE_STATSREPLY
, message
);
164 int trusts_ignore_np(nick
*np
) {
165 if(SIsService(&serverlist
[homeserver(np
->numeric
)])) {
166 /* ANY user created by a server (nterface,fakeusers,Q) are ignored in relation to trusts */
167 /* NOTE: we might need to review this if we ever used newserv to handle client/user connections in some way */