]> jfr.im git - irc/quakenet/newserv.git/blame - trusts/trusts.h
JOINFLOOD: add support for glining of ident for trusted users.
[irc/quakenet/newserv.git] / trusts / trusts.h
CommitLineData
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
28struct trustmigration;
29
1bbe1ac3
CP
30struct trusthost;
31
be2823bc 32typedef 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
51typedef 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 */
80extern int trusts_thext, trusts_nextuserext;
2129448c
CP
81int findtgext(const char *);
82int registertgext(const char *);
83void releasetgext(int);
82a316e7 84int trusts_fullyonline(void);
45e8ce62 85
8a95d3e4
CP
86/* formats.c */
87char *trusts_timetostr(time_t);
65f34016
CP
88int trusts_parsecidr(const char *, uint32_t *, short *);
89int trusts_str2cidr(const char *, uint32_t *, uint32_t *);
90char *trusts_cidr2str(uint32_t, uint32_t);
82a316e7
CP
91char *dumpth(trusthost *, int);
92char *dumptg(trustgroup *, int);
93int parseth(char *, trusthost *, unsigned int *, int);
94int parsetg(char *, trustgroup *, int);
95char *rtrim(char *);
5ada3782
CP
96
97/* data.c */
be2823bc 98extern trustgroup *tglist;
5ada3782
CP
99trustgroup *tg_getbyid(unsigned int);
100void th_free(trusthost *);
82a316e7 101trusthost *th_add(trusthost *);
2ab0a1e7 102void tg_free(trustgroup *, int);
82a316e7 103trustgroup *tg_add(trustgroup *);
d2c08930 104trusthost *th_getbyhost(uint32_t);
9097ab05
CP
105trusthost *th_getbyhostandmask(uint32_t, uint32_t);
106trusthost *th_getsmallestsupersetbyhost(uint32_t, uint32_t);
107trustgroup *tg_strtotg(char *);
108void th_adjusthosts(trusthost *th, trusthost *, trusthost *);
109void th_getsuperandsubsets(uint32_t, uint32_t, trusthost **, trusthost **);
b76fd8e6
CP
110trusthost *th_getsubsetbyhost(uint32_t ip, uint32_t mask);
111trusthost *th_getnextsubsetbyhost(trusthost *th, uint32_t ip, uint32_t mask);
112void th_linktree(void);
6ebeb438
CP
113unsigned int nexttgmarker(void);
114unsigned int nextthmarker(void);
2ab0a1e7
CP
115trusthost *th_getbyid(unsigned int);
116int tg_modify(trustgroup *, trustgroup *);
5ada3782
CP
117
118/* migration.c */
82a316e7
CP
119typedef void (*TrustMigrationGroup)(void *, trustgroup *);
120typedef void (*TrustMigrationHost)(void *, trusthost *, unsigned int);
5ada3782 121typedef void (*TrustMigrationFini)(void *, int);
2b6e02e2 122
2ab0a1e7
CP
123/* trusts_db.c */
124extern int trustsdbloaded;
125int trusts_loaddb(void);
126void trusts_closedb(int);
127trustgroup *tg_new(trustgroup *);
128trusthost *th_new(trustgroup *, char *);
129void trustsdb_insertth(char *, trusthost *, unsigned int);
130void trustsdb_inserttg(char *, trustgroup *);
131trustgroup *tg_copy(trustgroup *);
132trusthost *th_copy(trusthost *);
133void tg_update(trustgroup *);
134void tg_delete(trustgroup *);
135void th_delete(trusthost *);
136
5ada3782
CP
137typedef 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 148typedef void (*TrustDBMigrationCallback)(int, void *);
2d4ba67d 149
9097ab05
CP
150/* events.c */
151void trusts_newnick(nick *, int);
152void trusts_lostnick(nick *, int);
153
813c5b73
CP
154/* trusts_api.c */
155int istrusted(nick *);
156
2b6e02e2 157#endif