]>
Commit | Line | Data |
---|---|---|
e2527cba P |
1 | /* |
2 | ||
3 | * trust.h: | |
4 | * Top level data structures and function prototypes for the | |
5 | * trusts service module | |
6 | */ | |
7 | ||
8 | #ifndef __TRUST_H | |
9 | #define __TRUST_H | |
10 | ||
11 | #include <string.h> | |
12 | ||
13 | #include "../lib/irc_ipv6.h" | |
14 | #include "../core/schedule.h" | |
15 | #include "../lib/irc_string.h" | |
16 | #include "../localuser/localuserchannel.h" | |
17 | #include "../control/control.h" | |
18 | #include "../patricia/patricia.h" | |
19 | #include "../dbapi/dbapi.h" | |
20 | #include "../patricianick/patricianick.h" | |
21 | #include "../nick/nick.h" | |
22 | ||
23 | #define TRUSTS_HASH_GROUPSIZE 500 | |
24 | #define TRUSTS_HASH_HOSTSIZE 1000 | |
25 | #define TRUSTS_HASH_IDENTSIZE 50 | |
26 | ||
27 | #define TRUSTS_MAXGROUPNAMELEN 20 | |
28 | ||
29 | extern int tgh_ext; | |
ef9fab2e | 30 | extern int tgb_ext; |
9a8ffb84 P |
31 | extern int removeusers; |
32 | extern int trusts_loaded; | |
e2527cba P |
33 | |
34 | typedef struct trusthost_s { | |
35 | /* Details */ | |
36 | unsigned long id; | |
37 | patricia_node_t* node; | |
38 | time_t startdate; | |
39 | time_t lastused; | |
40 | time_t expire; | |
41 | unsigned long maxused; | |
42 | ||
43 | /* Trust group */ | |
44 | struct trustgroup_s* trustgroup; | |
45 | ||
46 | time_t created; | |
47 | time_t modified; | |
48 | ||
49 | /* Hash table */ | |
50 | struct trusthost_s* nextbyid; | |
51 | struct trusthost_s* nextbygroupid; | |
52 | } trusthost_t; | |
53 | ||
54 | typedef struct trustgroup_s { | |
55 | /* Details */ | |
56 | unsigned long id; | |
57 | unsigned long maxusage, currenton; | |
58 | unsigned long maxclones, maxperident; | |
59 | unsigned short maxperip; | |
60 | int enforceident; | |
61 | time_t startdate,lastused, expire; | |
62 | unsigned long ownerid; | |
63 | int type; | |
64 | ||
65 | time_t created; | |
66 | time_t modified; | |
67 | ||
68 | /* Hash table */ | |
69 | struct trustgroup_s* nextbyid; | |
70 | } trustgroup_t; | |
71 | ||
72 | typedef struct trustgroupidentcount_s { | |
73 | /* Ident */ | |
74 | sstring *ident; | |
75 | ||
76 | /* Trust group */ | |
77 | struct trustgroup_s* trustgroup; | |
78 | ||
79 | /* Counter */ | |
80 | unsigned long currenton; | |
81 | ||
82 | /* Hash table */ | |
83 | struct trustgroupidentcount_s* next; | |
84 | } trustgroupidentcount_t; | |
85 | ||
86 | typedef struct trustblock_s { | |
87 | unsigned long id; | |
88 | patricia_node_t* node; | |
89 | unsigned long ownerid; | |
90 | time_t expire; | |
91 | time_t startdate; | |
92 | sstring* reason_private; | |
93 | sstring* reason_public; | |
94 | struct trustblock_s* next; | |
95 | } trustblock_t; | |
96 | ||
97 | /* trusts hash tables */ | |
98 | extern trustgroup_t *trustgroupidtable[TRUSTS_HASH_GROUPSIZE]; | |
99 | extern trustgroup_t *trustgroupnametable[TRUSTS_HASH_GROUPSIZE]; | |
100 | extern trusthost_t *trusthostidtable[TRUSTS_HASH_HOSTSIZE]; | |
101 | extern trusthost_t *trusthostgroupidtable[TRUSTS_HASH_HOSTSIZE]; | |
102 | extern trustgroupidentcount_t *trustgroupidentcounttable[TRUSTS_HASH_IDENTSIZE]; | |
103 | ||
104 | #define trusts_gettrustgroupidhash(x) ((x)%TRUSTS_HASH_GROUPSIZE) | |
105 | #define trusts_gettrustgroupnamehash(x) ((crc32i(x))%TRUSTS_HASH_GROUPSIZE) | |
106 | #define trusts_gettrusthostidhash(x) ((x)%TRUSTS_HASH_HOSTSIZE) | |
107 | #define trusts_gettrusthostgroupidhash(x) ((x)%TRUSTS_HASH_HOSTSIZE) | |
108 | #define trusts_gettrustgroupidenthash(x) ((crc32i(x))%TRUSTS_HASH_IDENTSIZE) | |
109 | ||
110 | /* trusts_hash.c */ | |
111 | void trusts_hash_init(); | |
112 | void trusts_hash_fini(); | |
113 | ||
114 | void trusts_addtrusthosttohash(trusthost_t *newhost); | |
115 | void trusts_removetrusthostfromhash(trusthost_t *t); | |
116 | ||
117 | void trusts_addtrustgrouptohash(trustgroup_t *newgroup); | |
118 | void trusts_removetrustgroupfromhash(trustgroup_t *t); | |
119 | ||
120 | void trusts_addtrustgroupidenttohash(trustgroupidentcount_t *newident); | |
121 | void trusts_removetrustgroupidentfromhash(trustgroupidentcount_t *t); | |
122 | ||
123 | trustgroup_t* findtrustgroupbyid(int id); | |
124 | trustgroup_t* findtrustgroupbyownerid(int ownerid); | |
125 | ||
126 | trustgroupidentcount_t* findtrustgroupcountbyident(char *ident, trustgroup_t *t); | |
127 | ||
128 | trustgroupidentcount_t *getnewtrustgroupidentcount(trustgroup_t *tg, char *ident); | |
129 | ||
9a8ffb84 | 130 | extern unsigned long trusts_lasttrustgroupid, trusts_lasttrusthostid, trusts_lasttrustblockid; |
e2527cba P |
131 | |
132 | void trust_debug(char *format, ...); | |
133 | ||
134 | /* trusts alloc */ | |
135 | trustgroup_t *newtrustgroup(); | |
136 | void freetrustgroup (trustgroup_t *trustgroup); | |
137 | trusthost_t *newtrusthost(); | |
138 | void freetrusthost (trusthost_t *trusthost); | |
139 | trustgroupidentcount_t *newtrustgroupidentcount(); | |
140 | void freetrustgroupidentcount (trustgroupidentcount_t *trustgroupidentcount); | |
141 | trustblock_t *newtrustblock(); | |
142 | void freetrustblock (trustblock_t *trustblock); | |
143 | ||
144 | /* trusts db */ | |
145 | int trusts_load_db(void); | |
146 | void trusts_create_tables(void); | |
147 | void trusts_cleanup_db(void); | |
148 | void trusts_loadtrustgroups(DBConn *dbconn, void *arg); | |
149 | void trusts_loadtrusthosts(DBConn *dbconn, void *arg); | |
150 | void trusts_loadtrustblocks(DBConn *dbconn, void *arg); | |
151 | void trustsdb_addtrustgroup(trustgroup_t *t); | |
152 | void trustsdb_updatetrustgroup(trustgroup_t *t); | |
153 | void trustsdb_deletetrustgroup(trustgroup_t *t); | |
154 | void trustsdb_addtrusthost(trusthost_t *th); | |
155 | void trustsdb_updatetrusthost(trusthost_t *th); | |
156 | void trustsdb_deletetrusthost(trusthost_t *th); | |
157 | void trustsdb_addtrustblock(trustblock_t *tb); | |
158 | void trustsdb_updatetrustblock(trustblock_t *tb); | |
159 | void trustsdb_deletetrustblock(trustblock_t *tb); | |
160 | void trustsdb_logmessage(trustgroup_t *tg, unsigned long userid, int type, char *message); | |
161 | ||
162 | /* trusts handlers */ | |
163 | void trusts_hook_newuser(int hook, void *arg); | |
164 | void trusts_hook_lostuser(int hook, void *arg); | |
165 | ||
166 | /* trusts groups */ | |
167 | ||
168 | trustgroup_t *createtrustgroupfromdb(unsigned long id, unsigned long maxusage, unsigned long maxclones, unsigned long maxperident, unsigned short maxperip, int enforceident, time_t startdate, time_t lastused, time_t expire, unsigned long ownerid, int type, time_t created, time_t modified); | |
169 | trustgroup_t *createtrustgroup(unsigned long id, unsigned long maxclones, unsigned long maxperident, unsigned short maxperip, int enforceident, time_t expire, unsigned long ownerid, int type); | |
170 | void trustgroup_expire (trustgroup_t *tg); | |
171 | void trustgroup_free(trustgroup_t* t); | |
172 | ||
173 | /* trusts hosts */ | |
174 | trusthost_t *createtrusthostfromdb(unsigned long id, patricia_node_t* node, time_t startdate, time_t lastused, time_t expire, unsigned long maxused, trustgroup_t* trustgroup, time_t created, time_t modified); | |
175 | trusthost_t *createtrusthost(unsigned long id, patricia_node_t* node, time_t expire, trustgroup_t *trustgroup); | |
176 | void trusthost_free(trusthost_t* t); | |
177 | void trusthost_addcounters(trusthost_t* tgh); | |
178 | trusthost_t* trusthostadd(patricia_node_t *node, trustgroup_t* tg, time_t expire); | |
179 | void trusthost_expire ( trusthost_t *th); | |
180 | ||
ef9fab2e P |
181 | /* trusts blocks */ |
182 | trustblock_t *createtrustblock(unsigned long id, patricia_node_t* node, unsigned long ownerid, time_t expire, char *reason_private, char *reason_public); | |
183 | trustblock_t *createtrustblockfromdb(unsigned long id, patricia_node_t* node, unsigned long ownerid, time_t expire, time_t startdate, char *reason_private, char *reason_public); | |
184 | void trustblock_free(trustblock_t* t); | |
185 | void trustblock_expire( trustblock_t *tb); | |
186 | ||
e2527cba P |
187 | /* trusts idents */ |
188 | void increment_ident_count(nick *np, trustgroup_t *tg); | |
189 | void decrement_ident_count(nick *np, trustgroup_t *tg); | |
190 | ||
191 | /* trusts */ | |
192 | void decrement_trust_ipnode(patricia_node_t *node); | |
193 | void increment_trust_ipnode(patricia_node_t *node); | |
194 | ||
195 | /* trusts cmds */ | |
196 | void trusts_cmdinit(); | |
197 | void trusts_cmdfini(); | |
198 | ||
ef9fab2e P |
199 | int trust_groupadd(void *source, int cargc, char **cargv); |
200 | int trust_groupmodify(void *source, int cargc, char **cargv); | |
201 | int trust_groupdel(void *source, int cargc, char **cargv); | |
202 | int trust_denyadd(void *source, int cargc, char **cargv); | |
203 | int trust_denycomment(void *source, int cargc, char **cargv); | |
204 | int trust_denydel(void *source, int cargc, char **cargv); | |
205 | int trust_del(void *source, int cargc, char **cargv); | |
206 | int trust_add(void *source, int cargc, char **cargv); | |
207 | int trust_comment(void *source, int cargc, char **cargv); | |
e2527cba P |
208 | |
209 | int trust_stats(void *source, int cargc, char **cargv); | |
ef9fab2e | 210 | int trust_dump(void *source, int cargc, char **cargv); |
e2527cba P |
211 | #endif |
212 |