]>
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 | |
2129448c | 16 | #define MAXTGEXTS 5 |
2b6e02e2 | 17 | |
2ab0a1e7 CP |
18 | #define MAXTRUSTEDFOR 50000 |
19 | #define MAXDURATION 365 * 86400 * 20 | |
20 | #define MAXPERIDENT 1000 | |
21 | ||
35449aa5 CP |
22 | #define TABLES_REGULAR 0 |
23 | #define TABLES_MIGRATION 1 | |
24 | #define TABLES_REPLICATION 2 | |
25 | ||
2b6e02e2 CP |
26 | struct trustmigration; |
27 | ||
1bbe1ac3 CP |
28 | struct trusthost; |
29 | ||
be2823bc | 30 | typedef struct trusthost { |
9bf9e8a1 CP |
31 | unsigned int id; |
32 | ||
65f34016 | 33 | uint32_t ip, mask; |
4be1aaf2 | 34 | unsigned int maxusage; |
be2823bc CP |
35 | time_t lastseen; |
36 | ||
1bbe1ac3 CP |
37 | nick *users; |
38 | struct trustgroup *group; | |
39 | ||
40 | unsigned int count; | |
41 | ||
6ebeb438 | 42 | |
b76fd8e6 | 43 | struct trusthost *parent, *children; |
6ebeb438 | 44 | unsigned int marker; |
b76fd8e6 | 45 | |
6ebeb438 | 46 | struct trusthost *nextbychild; |
be2823bc CP |
47 | struct trusthost *next; |
48 | } trusthost; | |
49 | ||
2b6e02e2 CP |
50 | typedef struct trustgroup { |
51 | unsigned int id; | |
52 | ||
53 | sstring *name; | |
54 | unsigned int trustedfor; | |
55 | int mode; | |
56 | unsigned int maxperident; | |
4be1aaf2 | 57 | unsigned int maxusage; |
2b6e02e2 | 58 | time_t expires; |
be2823bc | 59 | time_t lastseen; |
2b6e02e2 | 60 | time_t lastmaxuserreset; |
2b6e02e2 CP |
61 | sstring *createdby, *contact, *comment; |
62 | ||
be2823bc | 63 | trusthost *hosts; |
1bbe1ac3 CP |
64 | unsigned int count; |
65 | ||
6ebeb438 CP |
66 | unsigned int marker; |
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); | |
111 | void th_linktree(void); | |
6ebeb438 CP |
112 | unsigned int nexttgmarker(void); |
113 | unsigned int nextthmarker(void); | |
2ab0a1e7 CP |
114 | trusthost *th_getbyid(unsigned int); |
115 | int tg_modify(trustgroup *, trustgroup *); | |
5ada3782 CP |
116 | |
117 | /* migration.c */ | |
82a316e7 CP |
118 | typedef void (*TrustMigrationGroup)(void *, trustgroup *); |
119 | typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int); | |
5ada3782 | 120 | typedef void (*TrustMigrationFini)(void *, int); |
2b6e02e2 | 121 | |
2ab0a1e7 CP |
122 | /* trusts_db.c */ |
123 | extern int trustsdbloaded; | |
124 | int trusts_loaddb(void); | |
125 | void trusts_closedb(int); | |
126 | trustgroup *tg_new(trustgroup *); | |
127 | trusthost *th_new(trustgroup *, char *); | |
128 | void trustsdb_insertth(char *, trusthost *, unsigned int); | |
129 | void trustsdb_inserttg(char *, trustgroup *); | |
130 | trustgroup *tg_copy(trustgroup *); | |
131 | trusthost *th_copy(trusthost *); | |
132 | void tg_update(trustgroup *); | |
133 | void tg_delete(trustgroup *); | |
134 | void th_delete(trusthost *); | |
135 | ||
5ada3782 CP |
136 | typedef struct trustmigration { |
137 | int count, cur; | |
138 | void *schedule; | |
139 | void *tag; | |
140 | ||
141 | TrustMigrationGroup group; | |
142 | TrustMigrationHost host; | |
143 | TrustMigrationFini fini; | |
144 | } trustmigration; | |
145 | ||
146 | /* db-migration.c */ | |
5ada3782 | 147 | typedef void (*TrustDBMigrationCallback)(int, void *); |
2d4ba67d | 148 | |
9097ab05 CP |
149 | /* events.c */ |
150 | void trusts_newnick(nick *, int); | |
151 | void trusts_lostnick(nick *, int); | |
152 | ||
2b6e02e2 | 153 | #endif |