]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/data.c
4 #include "../lib/sstring.h"
5 #include "../core/hooks.h"
10 void th_dbupdatecounts ( trusthost
*);
11 void tg_dbupdatecounts ( trustgroup
*);
13 void trusts_freeall ( void ) {
17 for ( tg
= tglist
; tg
; tg
= ntg
) {
19 for ( th
= tg
-> hosts
; th
; th
= nth
) {
31 trustgroup
* tg_getbyid ( unsigned int id
) {
34 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
41 void th_free ( trusthost
* th
) {
45 int th_add ( trustgroup
* tg
, unsigned int id
, char * host
, unsigned int maxusage
, time_t lastseen
) {
49 if (! trusts_str2cidr ( host
, & ip
, & mask
))
52 th
= malloc ( sizeof ( trusthost
));
57 th
-> maxusage
= maxusage
;
58 th
-> lastseen
= lastseen
;
72 void tg_free ( trustgroup
* tg
) {
73 triggerhook ( HOOK_TRUSTS_LOSTGROUP
, tg
);
75 freesstring ( tg
-> name
);
76 freesstring ( tg
-> createdby
);
77 freesstring ( tg
-> contact
);
78 freesstring ( tg
-> comment
);
82 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
) {
83 trustgroup
* tg
= malloc ( sizeof ( trustgroup
));
87 tg
-> name
= getsstring ( name
, TRUSTNAMELEN
);
88 tg
-> createdby
= getsstring ( createdby
, NICKLEN
);
89 tg
-> contact
= getsstring ( contact
, CONTACTLEN
);
90 tg
-> comment
= getsstring ( comment
, COMMENTLEN
);
91 if (! tg
-> name
|| ! tg
-> createdby
|| ! tg
-> contact
|| ! tg
-> comment
) {
97 tg
-> trustedfor
= trustedfor
;
99 tg
-> maxperident
= maxperident
;
100 tg
-> maxusage
= maxusage
;
101 tg
-> expires
= expires
;
102 tg
-> lastseen
= lastseen
;
103 tg
-> lastmaxuserreset
= lastmaxuserreset
;
108 memset ( tg
-> exts
, 0 , sizeof ( tg
-> exts
));
113 triggerhook ( HOOK_TRUSTS_NEWGROUP
, tg
);
118 trusthost
* th_getbyhost ( uint32_t host
) {
122 for ( tg
= tglist
; tg
; tg
= tg
-> next
)
123 for ( th
= tg
-> hosts
; th
; th
= th
-> next
)
124 if (( host
& th
-> mask
) == th
-> ip
)
130 void trusts_flush ( void ) {
133 time_t t
= time ( NULL
);
135 for ( tg
= tglist
; tg
; tg
= tg
-> next
) {
139 tg_dbupdatecounts ( tg
);
141 for ( th
= tg
-> hosts
; th
; th
= th
-> next
) {
145 th_dbupdatecounts ( th
);