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