]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/data.c
4 #include "../lib/sstring.h"
5 #include "../core/hooks.h"
6 #include "../core/nsmalloc.h"
11 void th_dbupdatecounts ( trusthost
*);
12 void tg_dbupdatecounts ( trustgroup
*);
14 void trusts_freeall ( void ) {
18 for ( tg
= tglist
; tg
; tg
= ntg
) {
20 for ( th
= tg
-> hosts
; th
; th
= nth
) {
32 trustgroup
* tg_getbyid ( unsigned int id
) {
35 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
42 void th_free ( trusthost
* th
) {
43 nsfree ( POOL_TRUSTS
, th
);
46 int th_add ( trustgroup
* tg
, unsigned int id
, char * host
, unsigned int maxusage
, time_t lastseen
) {
50 if (! trusts_str2cidr ( host
, & ip
, & mask
))
53 th
= nsmalloc ( POOL_TRUSTS
, sizeof ( trusthost
));
58 th
-> maxusage
= maxusage
;
59 th
-> lastseen
= lastseen
;
73 void tg_free ( trustgroup
* tg
) {
74 triggerhook ( HOOK_TRUSTS_LOSTGROUP
, tg
);
76 freesstring ( tg
-> name
);
77 freesstring ( tg
-> createdby
);
78 freesstring ( tg
-> contact
);
79 freesstring ( tg
-> comment
);
80 nsfree ( POOL_TRUSTS
, tg
);
83 int tg_add ( unsigned int id
, char * name
, unsigned int trustedfor
, int mode
, unsigned int maxperident
, unsigned int maxusage
, time_t expires
, time_t lastseen
, time_t lastmaxuserreset
, char * createdby
, char * contact
, char * comment
) {
84 trustgroup
* tg
= nsmalloc ( POOL_TRUSTS
, sizeof ( trustgroup
));
88 tg
-> name
= getsstring ( name
, TRUSTNAMELEN
);
89 tg
-> createdby
= getsstring ( createdby
, NICKLEN
);
90 tg
-> contact
= getsstring ( contact
, CONTACTLEN
);
91 tg
-> comment
= getsstring ( comment
, COMMENTLEN
);
92 if (! tg
-> name
|| ! tg
-> createdby
|| ! tg
-> contact
|| ! tg
-> comment
) {
98 tg
-> trustedfor
= trustedfor
;
100 tg
-> maxperident
= maxperident
;
101 tg
-> maxusage
= maxusage
;
102 tg
-> expires
= expires
;
103 tg
-> lastseen
= lastseen
;
104 tg
-> lastmaxuserreset
= lastmaxuserreset
;
109 memset ( tg
-> exts
, 0 , sizeof ( tg
-> exts
));
114 triggerhook ( HOOK_TRUSTS_NEWGROUP
, tg
);
119 trusthost
* th_getbyhost ( uint32_t host
) {
123 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
124 for ( th
= tg
-> hosts
; th
; th
= th
-> next
)
125 if (( host
& th
-> mask
) == th
-> ip
)
131 void trusts_flush ( void ) {
134 time_t t
= time ( NULL
);
136 for ( tg
= tglist
; tg
; tg
= tg
-> next
) {
140 tg_dbupdatecounts ( tg
);
142 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
146 th_dbupdatecounts ( th
);