]>
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 | |
24 | ||
35449aa5 CP |
25 | #define TABLES_REGULAR 0 |
26 | #define TABLES_MIGRATION 1 | |
27 | #define TABLES_REPLICATION 2 | |
28 | ||
caf2d02a GB |
29 | #define CLEANUP_TH_INACTIVE 30 |
30 | ||
2b6e02e2 CP |
31 | struct trustmigration; |
32 | ||
1bbe1ac3 CP |
33 | struct trusthost; |
34 | ||
be2823bc | 35 | typedef struct trusthost { |
9bf9e8a1 CP |
36 | unsigned int id; |
37 | ||
caf2d02a | 38 | |
65f34016 | 39 | uint32_t ip, mask; |
4be1aaf2 | 40 | unsigned int maxusage; |
caf2d02a | 41 | time_t created; |
be2823bc CP |
42 | time_t lastseen; |
43 | ||
1bbe1ac3 CP |
44 | nick *users; |
45 | struct trustgroup *group; | |
46 | ||
47 | unsigned int count; | |
48 | ||
be2823bc CP |
49 | struct trusthost *next; |
50 | } trusthost; | |
51 | ||
2b6e02e2 CP |
52 | typedef struct trustgroup { |
53 | unsigned int id; | |
54 | ||
55 | sstring *name; | |
56 | unsigned int trustedfor; | |
57 | int mode; | |
58 | unsigned int maxperident; | |
4be1aaf2 | 59 | unsigned int maxusage; |
2b6e02e2 | 60 | time_t expires; |
be2823bc | 61 | time_t lastseen; |
1f685425 | 62 | time_t lastmaxusereset; |
2b6e02e2 CP |
63 | sstring *createdby, *contact, *comment; |
64 | ||
be2823bc | 65 | trusthost *hosts; |
1bbe1ac3 CP |
66 | unsigned int count; |
67 | ||
2b6e02e2 | 68 | struct trustgroup *next; |
2129448c CP |
69 | |
70 | void *exts[MAXTGEXTS]; | |
2b6e02e2 CP |
71 | } trustgroup; |
72 | ||
1bbe1ac3 CP |
73 | #define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext]) |
74 | #define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext]) | |
75 | #define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y) | |
76 | #define settrusthost(x, y) (x)->exts[trusts_thext] = (y) | |
77 | ||
45e8ce62 CP |
78 | /* trusts.c */ |
79 | extern int trusts_thext, trusts_nextuserext; | |
2129448c CP |
80 | int findtgext(const char *); |
81 | int registertgext(const char *); | |
82 | void releasetgext(int); | |
82a316e7 | 83 | int trusts_fullyonline(void); |
45e8ce62 | 84 | |
8a95d3e4 CP |
85 | /* formats.c */ |
86 | char *trusts_timetostr(time_t); | |
65f34016 CP |
87 | int trusts_parsecidr(const char *, uint32_t *, short *); |
88 | int trusts_str2cidr(const char *, uint32_t *, uint32_t *); | |
89 | char *trusts_cidr2str(uint32_t, uint32_t); | |
82a316e7 CP |
90 | char *dumpth(trusthost *, int); |
91 | char *dumptg(trustgroup *, int); | |
92 | int parseth(char *, trusthost *, unsigned int *, int); | |
93 | int parsetg(char *, trustgroup *, int); | |
94 | char *rtrim(char *); | |
5ada3782 CP |
95 | |
96 | /* data.c */ | |
be2823bc | 97 | extern trustgroup *tglist; |
5ada3782 CP |
98 | trustgroup *tg_getbyid(unsigned int); |
99 | void th_free(trusthost *); | |
82a316e7 | 100 | trusthost *th_add(trusthost *); |
2ab0a1e7 | 101 | void tg_free(trustgroup *, int); |
82a316e7 | 102 | trustgroup *tg_add(trustgroup *); |
d2c08930 | 103 | trusthost *th_getbyhost(uint32_t); |
9097ab05 CP |
104 | trusthost *th_getbyhostandmask(uint32_t, uint32_t); |
105 | trusthost *th_getsmallestsupersetbyhost(uint32_t, uint32_t); | |
106 | trustgroup *tg_strtotg(char *); | |
107 | void th_adjusthosts(trusthost *th, trusthost *, trusthost *); | |
108 | void th_getsuperandsubsets(uint32_t, uint32_t, trusthost **, trusthost **); | |
b76fd8e6 CP |
109 | trusthost *th_getsubsetbyhost(uint32_t ip, uint32_t mask); |
110 | trusthost *th_getnextsubsetbyhost(trusthost *th, uint32_t ip, uint32_t mask); | |
2ab0a1e7 CP |
111 | trusthost *th_getbyid(unsigned int); |
112 | int tg_modify(trustgroup *, trustgroup *); | |
5ada3782 CP |
113 | |
114 | /* migration.c */ | |
82a316e7 CP |
115 | typedef void (*TrustMigrationGroup)(void *, trustgroup *); |
116 | typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int); | |
5ada3782 | 117 | typedef void (*TrustMigrationFini)(void *, int); |
2b6e02e2 | 118 | |
2ab0a1e7 CP |
119 | /* trusts_db.c */ |
120 | extern int trustsdbloaded; | |
121 | int trusts_loaddb(void); | |
122 | void trusts_closedb(int); | |
123 | trustgroup *tg_new(trustgroup *); | |
124 | trusthost *th_new(trustgroup *, char *); | |
125 | void trustsdb_insertth(char *, trusthost *, unsigned int); | |
126 | void trustsdb_inserttg(char *, trustgroup *); | |
127 | trustgroup *tg_copy(trustgroup *); | |
128 | trusthost *th_copy(trusthost *); | |
129 | void tg_update(trustgroup *); | |
130 | void tg_delete(trustgroup *); | |
131 | void th_delete(trusthost *); | |
1467e9a4 GB |
132 | void trustlog(trustgroup *tg, const char *user, const char *format, ...); |
133 | void trustlogspewid(nick *np, unsigned int groupid, unsigned int limit); | |
134 | void trustlogspewname(nick *np, const char *groupname, unsigned int limit); | |
01bd21d3 | 135 | void trustloggrep(nick *np, const char *pattern, unsigned int limit); |
2ab0a1e7 | 136 | |
5ada3782 CP |
137 | typedef struct trustmigration { |
138 | int count, cur; | |
139 | void *schedule; | |
140 | void *tag; | |
141 | ||
142 | TrustMigrationGroup group; | |
143 | TrustMigrationHost host; | |
144 | TrustMigrationFini fini; | |
145 | } trustmigration; | |
146 | ||
147 | /* db-migration.c */ | |
5ada3782 | 148 | typedef void (*TrustDBMigrationCallback)(int, void *); |
2d4ba67d | 149 | |
9097ab05 CP |
150 | /* events.c */ |
151 | void trusts_newnick(nick *, int); | |
152 | void trusts_lostnick(nick *, int); | |
153 | ||
813c5b73 CP |
154 | /* trusts_api.c */ |
155 | int istrusted(nick *); | |
ac3af088 GB |
156 | int trustgline(trustgroup *tg, const char *ident, int duration, const char *reason); |
157 | int trustungline(trustgroup *tg, const char *ident, int duration, const char *reason); | |
813c5b73 | 158 | |
2b6e02e2 | 159 | #endif |