]>
Commit | Line | Data |
---|---|---|
2b6e02e2 CP |
1 | #ifndef __TRUSTS_H |
2 | #define __TRUSTS_H | |
3 | ||
4 | #include <time.h> | |
65f34016 | 5 | #include <stdint.h> |
1bbe1ac3 | 6 | #include "../nick/nick.h" |
2b6e02e2 CP |
7 | #include "../lib/sstring.h" |
8 | ||
9 | #define MIGRATION_STOPPED -1 | |
83bccee3 | 10 | #define MIGRATION_LASTERROR -2 |
2b6e02e2 CP |
11 | |
12 | #define CONTACTLEN 100 | |
13 | #define COMMENTLEN 300 | |
be2823bc CP |
14 | #define TRUSTNAMELEN 100 |
15 | #define TRUSTHOSTLEN 100 | |
1f685425 | 16 | #define CREATEDBYLEN NICKLEN + 1 |
01bd21d3 | 17 | #define TRUSTLOGLEN 200 |
1f685425 | 18 | |
2129448c | 19 | #define MAXTGEXTS 5 |
2b6e02e2 | 20 | |
2ab0a1e7 CP |
21 | #define MAXTRUSTEDFOR 50000 |
22 | #define MAXDURATION 365 * 86400 * 20 | |
23 | #define MAXPERIDENT 1000 | |
c1da06f9 | 24 | #define MAXPERNODE 1000 |
2ab0a1e7 | 25 | |
35449aa5 CP |
26 | #define TABLES_REGULAR 0 |
27 | #define TABLES_MIGRATION 1 | |
28 | #define TABLES_REPLICATION 2 | |
29 | ||
caf2d02a GB |
30 | #define CLEANUP_TH_INACTIVE 30 |
31 | ||
1961b117 GB |
32 | #define POLICY_GLINE_DURATION 18 |
33 | ||
2b6e02e2 CP |
34 | struct trustmigration; |
35 | ||
1bbe1ac3 CP |
36 | struct trusthost; |
37 | ||
be2823bc | 38 | typedef struct trusthost { |
9bf9e8a1 CP |
39 | unsigned int id; |
40 | ||
6e6e98da GB |
41 | struct irc_in_addr ip; |
42 | unsigned char bits; | |
4be1aaf2 | 43 | unsigned int maxusage; |
caf2d02a | 44 | time_t created; |
be2823bc CP |
45 | time_t lastseen; |
46 | ||
1bbe1ac3 CP |
47 | nick *users; |
48 | struct trustgroup *group; | |
49 | ||
50 | unsigned int count; | |
51 | ||
cebc4cab GB |
52 | int maxpernode; |
53 | int nodebits; | |
54 | ||
34e3de85 GB |
55 | struct trusthost *parent, *children; |
56 | unsigned int marker; | |
57 | ||
58 | struct trusthost *nextbychild; | |
be2823bc CP |
59 | struct trusthost *next; |
60 | } trusthost; | |
61 | ||
2b6e02e2 CP |
62 | typedef struct trustgroup { |
63 | unsigned int id; | |
64 | ||
65 | sstring *name; | |
66 | unsigned int trustedfor; | |
67 | int mode; | |
68 | unsigned int maxperident; | |
4be1aaf2 | 69 | unsigned int maxusage; |
2b6e02e2 | 70 | time_t expires; |
be2823bc | 71 | time_t lastseen; |
1f685425 | 72 | time_t lastmaxusereset; |
2b6e02e2 CP |
73 | sstring *createdby, *contact, *comment; |
74 | ||
be2823bc | 75 | trusthost *hosts; |
1bbe1ac3 CP |
76 | unsigned int count; |
77 | ||
34e3de85 GB |
78 | unsigned int marker; |
79 | ||
2b6e02e2 | 80 | struct trustgroup *next; |
2129448c CP |
81 | |
82 | void *exts[MAXTGEXTS]; | |
2b6e02e2 CP |
83 | } trustgroup; |
84 | ||
1bbe1ac3 CP |
85 | #define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext]) |
86 | #define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext]) | |
87 | #define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y) | |
88 | #define settrusthost(x, y) (x)->exts[trusts_thext] = (y) | |
89 | ||
45e8ce62 CP |
90 | /* trusts.c */ |
91 | extern int trusts_thext, trusts_nextuserext; | |
2129448c CP |
92 | int findtgext(const char *); |
93 | int registertgext(const char *); | |
94 | void releasetgext(int); | |
82a316e7 | 95 | int trusts_fullyonline(void); |
45e8ce62 | 96 | |
8a95d3e4 CP |
97 | /* formats.c */ |
98 | char *trusts_timetostr(time_t); | |
6e6e98da | 99 | char *trusts_cidr2str(struct irc_in_addr *ip, unsigned char); |
82a316e7 CP |
100 | char *dumpth(trusthost *, int); |
101 | char *dumptg(trustgroup *, int); | |
102 | int parseth(char *, trusthost *, unsigned int *, int); | |
103 | int parsetg(char *, trustgroup *, int); | |
104 | char *rtrim(char *); | |
5ada3782 CP |
105 | |
106 | /* data.c */ | |
be2823bc | 107 | extern trustgroup *tglist; |
5ada3782 CP |
108 | trustgroup *tg_getbyid(unsigned int); |
109 | void th_free(trusthost *); | |
82a316e7 | 110 | trusthost *th_add(trusthost *); |
2ab0a1e7 | 111 | void tg_free(trustgroup *, int); |
82a316e7 | 112 | trustgroup *tg_add(trustgroup *); |
6e6e98da GB |
113 | trusthost *th_getbyhost(struct irc_in_addr *); |
114 | trusthost *th_getbyhostandmask(struct irc_in_addr *, uint32_t); | |
115 | trusthost *th_getsmallestsupersetbyhost(struct irc_in_addr *, uint32_t); | |
9097ab05 CP |
116 | trustgroup *tg_strtotg(char *); |
117 | void th_adjusthosts(trusthost *th, trusthost *, trusthost *); | |
6e6e98da GB |
118 | void th_getsuperandsubsets(struct irc_in_addr *, uint32_t, trusthost **, trusthost **); |
119 | trusthost *th_getsubsetbyhost(struct irc_in_addr *ip, uint32_t mask); | |
120 | trusthost *th_getnextsubsetbyhost(trusthost *th, struct irc_in_addr *ip, uint32_t mask); | |
34e3de85 GB |
121 | void th_linktree(void); |
122 | unsigned int nexttgmarker(void); | |
123 | unsigned int nextthmarker(void); | |
2ab0a1e7 CP |
124 | trusthost *th_getbyid(unsigned int); |
125 | int tg_modify(trustgroup *, trustgroup *); | |
058f68c5 | 126 | int th_modify(trusthost *, trusthost *); |
5ada3782 CP |
127 | |
128 | /* migration.c */ | |
82a316e7 CP |
129 | typedef void (*TrustMigrationGroup)(void *, trustgroup *); |
130 | typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int); | |
5ada3782 | 131 | typedef void (*TrustMigrationFini)(void *, int); |
2b6e02e2 | 132 | |
2ab0a1e7 CP |
133 | /* trusts_db.c */ |
134 | extern int trustsdbloaded; | |
135 | int trusts_loaddb(void); | |
136 | void trusts_closedb(int); | |
137 | trustgroup *tg_new(trustgroup *); | |
138 | trusthost *th_new(trustgroup *, char *); | |
139 | void trustsdb_insertth(char *, trusthost *, unsigned int); | |
140 | void trustsdb_inserttg(char *, trustgroup *); | |
141 | trustgroup *tg_copy(trustgroup *); | |
142 | trusthost *th_copy(trusthost *); | |
143 | void tg_update(trustgroup *); | |
144 | void tg_delete(trustgroup *); | |
c1da06f9 | 145 | void th_update(trusthost *); |
2ab0a1e7 | 146 | void th_delete(trusthost *); |
1467e9a4 GB |
147 | void trustlog(trustgroup *tg, const char *user, const char *format, ...); |
148 | void trustlogspewid(nick *np, unsigned int groupid, unsigned int limit); | |
149 | void trustlogspewname(nick *np, const char *groupname, unsigned int limit); | |
01bd21d3 | 150 | void trustloggrep(nick *np, const char *pattern, unsigned int limit); |
2ab0a1e7 | 151 | |
5ada3782 CP |
152 | typedef struct trustmigration { |
153 | int count, cur; | |
154 | void *schedule; | |
155 | void *tag; | |
156 | ||
157 | TrustMigrationGroup group; | |
158 | TrustMigrationHost host; | |
159 | TrustMigrationFini fini; | |
160 | } trustmigration; | |
161 | ||
162 | /* db-migration.c */ | |
5ada3782 | 163 | typedef void (*TrustDBMigrationCallback)(int, void *); |
2d4ba67d | 164 | |
9097ab05 CP |
165 | /* events.c */ |
166 | void trusts_newnick(nick *, int); | |
167 | void trusts_lostnick(nick *, int); | |
168 | ||
813c5b73 CP |
169 | /* trusts_api.c */ |
170 | int istrusted(nick *); | |
ac3af088 GB |
171 | int trustgline(trustgroup *tg, const char *ident, int duration, const char *reason); |
172 | int trustungline(trustgroup *tg, const char *ident, int duration, const char *reason); | |
a473a1be | 173 | unsigned char getnodebits(struct irc_in_addr *ip); |
813c5b73 | 174 | |
2b6e02e2 | 175 | #endif |