]>
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 CP |
16 | #define CREATEDBYLEN NICKLEN + 1 |
17 | ||
2129448c | 18 | #define MAXTGEXTS 5 |
2b6e02e2 | 19 | |
2ab0a1e7 CP |
20 | #define MAXTRUSTEDFOR 50000 |
21 | #define MAXDURATION 365 * 86400 * 20 | |
22 | #define MAXPERIDENT 1000 | |
23 | ||
35449aa5 CP |
24 | #define TABLES_REGULAR 0 |
25 | #define TABLES_MIGRATION 1 | |
26 | #define TABLES_REPLICATION 2 | |
27 | ||
2b6e02e2 CP |
28 | struct trustmigration; |
29 | ||
1bbe1ac3 CP |
30 | struct trusthost; |
31 | ||
be2823bc | 32 | typedef struct trusthost { |
9bf9e8a1 CP |
33 | unsigned int id; |
34 | ||
65f34016 | 35 | uint32_t ip, mask; |
4be1aaf2 | 36 | unsigned int maxusage; |
be2823bc CP |
37 | time_t lastseen; |
38 | ||
1bbe1ac3 CP |
39 | nick *users; |
40 | struct trustgroup *group; | |
41 | ||
42 | unsigned int count; | |
43 | ||
b76fd8e6 | 44 | struct trusthost *parent, *children; |
6ebeb438 | 45 | unsigned int marker; |
b76fd8e6 | 46 | |
6ebeb438 | 47 | struct trusthost *nextbychild; |
be2823bc CP |
48 | struct trusthost *next; |
49 | } trusthost; | |
50 | ||
2b6e02e2 CP |
51 | typedef struct trustgroup { |
52 | unsigned int id; | |
53 | ||
54 | sstring *name; | |
55 | unsigned int trustedfor; | |
56 | int mode; | |
57 | unsigned int maxperident; | |
4be1aaf2 | 58 | unsigned int maxusage; |
2b6e02e2 | 59 | time_t expires; |
be2823bc | 60 | time_t lastseen; |
1f685425 | 61 | time_t lastmaxusereset; |
2b6e02e2 CP |
62 | sstring *createdby, *contact, *comment; |
63 | ||
be2823bc | 64 | trusthost *hosts; |
1bbe1ac3 CP |
65 | unsigned int count; |
66 | ||
6ebeb438 CP |
67 | unsigned int marker; |
68 | ||
2b6e02e2 | 69 | struct trustgroup *next; |
2129448c CP |
70 | |
71 | void *exts[MAXTGEXTS]; | |
2b6e02e2 CP |
72 | } trustgroup; |
73 | ||
1bbe1ac3 CP |
74 | #define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext]) |
75 | #define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext]) | |
76 | #define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y) | |
77 | #define settrusthost(x, y) (x)->exts[trusts_thext] = (y) | |
78 | ||
45e8ce62 CP |
79 | /* trusts.c */ |
80 | extern int trusts_thext, trusts_nextuserext; | |
2129448c CP |
81 | int findtgext(const char *); |
82 | int registertgext(const char *); | |
83 | void releasetgext(int); | |
82a316e7 | 84 | int trusts_fullyonline(void); |
45e8ce62 | 85 | |
8a95d3e4 CP |
86 | /* formats.c */ |
87 | char *trusts_timetostr(time_t); | |
65f34016 CP |
88 | int trusts_parsecidr(const char *, uint32_t *, short *); |
89 | int trusts_str2cidr(const char *, uint32_t *, uint32_t *); | |
90 | char *trusts_cidr2str(uint32_t, uint32_t); | |
82a316e7 CP |
91 | char *dumpth(trusthost *, int); |
92 | char *dumptg(trustgroup *, int); | |
93 | int parseth(char *, trusthost *, unsigned int *, int); | |
94 | int parsetg(char *, trustgroup *, int); | |
95 | char *rtrim(char *); | |
5ada3782 CP |
96 | |
97 | /* data.c */ | |
be2823bc | 98 | extern trustgroup *tglist; |
5ada3782 CP |
99 | trustgroup *tg_getbyid(unsigned int); |
100 | void th_free(trusthost *); | |
82a316e7 | 101 | trusthost *th_add(trusthost *); |
2ab0a1e7 | 102 | void tg_free(trustgroup *, int); |
82a316e7 | 103 | trustgroup *tg_add(trustgroup *); |
d2c08930 | 104 | trusthost *th_getbyhost(uint32_t); |
9097ab05 CP |
105 | trusthost *th_getbyhostandmask(uint32_t, uint32_t); |
106 | trusthost *th_getsmallestsupersetbyhost(uint32_t, uint32_t); | |
107 | trustgroup *tg_strtotg(char *); | |
108 | void th_adjusthosts(trusthost *th, trusthost *, trusthost *); | |
109 | void th_getsuperandsubsets(uint32_t, uint32_t, trusthost **, trusthost **); | |
b76fd8e6 CP |
110 | trusthost *th_getsubsetbyhost(uint32_t ip, uint32_t mask); |
111 | trusthost *th_getnextsubsetbyhost(trusthost *th, uint32_t ip, uint32_t mask); | |
112 | void th_linktree(void); | |
6ebeb438 CP |
113 | unsigned int nexttgmarker(void); |
114 | unsigned int nextthmarker(void); | |
2ab0a1e7 CP |
115 | trusthost *th_getbyid(unsigned int); |
116 | int tg_modify(trustgroup *, trustgroup *); | |
5ada3782 CP |
117 | |
118 | /* migration.c */ | |
82a316e7 CP |
119 | typedef void (*TrustMigrationGroup)(void *, trustgroup *); |
120 | typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int); | |
5ada3782 | 121 | typedef void (*TrustMigrationFini)(void *, int); |
2b6e02e2 | 122 | |
2ab0a1e7 CP |
123 | /* trusts_db.c */ |
124 | extern int trustsdbloaded; | |
125 | int trusts_loaddb(void); | |
126 | void trusts_closedb(int); | |
127 | trustgroup *tg_new(trustgroup *); | |
128 | trusthost *th_new(trustgroup *, char *); | |
129 | void trustsdb_insertth(char *, trusthost *, unsigned int); | |
130 | void trustsdb_inserttg(char *, trustgroup *); | |
131 | trustgroup *tg_copy(trustgroup *); | |
132 | trusthost *th_copy(trusthost *); | |
133 | void tg_update(trustgroup *); | |
134 | void tg_delete(trustgroup *); | |
135 | void th_delete(trusthost *); | |
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 | ||
2b6e02e2 | 154 | #endif |