6 #include "../nick/nick.h"
7 #include "../lib/sstring.h"
9 #define MIGRATION_STOPPED -1
10 #define MIGRATION_LASTERROR -2
12 #define CONTACTLEN 100
13 #define COMMENTLEN 300
14 #define TRUSTNAMELEN 100
15 #define TRUSTHOSTLEN 100
16 #define CREATEDBYLEN NICKLEN + 1
17 #define TRUSTLOGLEN 200
21 #define MAXTRUSTEDFOR 50000
22 #define MAXDURATION 365 * 86400 * 20
23 #define MAXPERIDENT 1000
25 #define TABLES_REGULAR 0
26 #define TABLES_MIGRATION 1
27 #define TABLES_REPLICATION 2
29 struct trustmigration
;
33 typedef struct trusthost
{
37 unsigned int maxusage
;
41 struct trustgroup
*group
;
45 struct trusthost
*parent
, *children
;
48 struct trusthost
*nextbychild
;
49 struct trusthost
*next
;
52 typedef struct trustgroup
{
56 unsigned int trustedfor
;
58 unsigned int maxperident
;
59 unsigned int maxusage
;
62 time_t lastmaxusereset
;
63 sstring
*createdby
, *contact
, *comment
;
70 struct trustgroup
*next
;
72 void *exts
[MAXTGEXTS
];
75 #define nextbytrust(x) (nick *)((x)->exts[trusts_nextuserext])
76 #define gettrusthost(x) (trusthost *)((x)->exts[trusts_thext])
77 #define setnextbytrust(x, y) (x)->exts[trusts_nextuserext] = (y)
78 #define settrusthost(x, y) (x)->exts[trusts_thext] = (y)
81 extern int trusts_thext
, trusts_nextuserext
;
82 int findtgext(const char *);
83 int registertgext(const char *);
84 void releasetgext(int);
85 int trusts_fullyonline(void);
88 char *trusts_timetostr(time_t);
89 int trusts_parsecidr(const char *, uint32_t *, short *);
90 int trusts_str2cidr(const char *, uint32_t *, uint32_t *);
91 char *trusts_cidr2str(uint32_t, uint32_t);
92 char *dumpth(trusthost
*, int);
93 char *dumptg(trustgroup
*, int);
94 int parseth(char *, trusthost
*, unsigned int *, int);
95 int parsetg(char *, trustgroup
*, int);
99 extern trustgroup
*tglist
;
100 trustgroup
*tg_getbyid(unsigned int);
101 void th_free(trusthost
*);
102 trusthost
*th_add(trusthost
*);
103 void tg_free(trustgroup
*, int);
104 trustgroup
*tg_add(trustgroup
*);
105 trusthost
*th_getbyhost(uint32_t);
106 trusthost
*th_getbyhostandmask(uint32_t, uint32_t);
107 trusthost
*th_getsmallestsupersetbyhost(uint32_t, uint32_t);
108 trustgroup
*tg_strtotg(char *);
109 void th_adjusthosts(trusthost
*th
, trusthost
*, trusthost
*);
110 void th_getsuperandsubsets(uint32_t, uint32_t, trusthost
**, trusthost
**);
111 trusthost
*th_getsubsetbyhost(uint32_t ip
, uint32_t mask
);
112 trusthost
*th_getnextsubsetbyhost(trusthost
*th
, uint32_t ip
, uint32_t mask
);
113 void th_linktree(void);
114 unsigned int nexttgmarker(void);
115 unsigned int nextthmarker(void);
116 trusthost
*th_getbyid(unsigned int);
117 int tg_modify(trustgroup
*, trustgroup
*);
120 typedef void (*TrustMigrationGroup
)(void *, trustgroup
*);
121 typedef void (*TrustMigrationHost
)(void *, trusthost
*, unsigned int);
122 typedef void (*TrustMigrationFini
)(void *, int);
125 extern int trustsdbloaded
;
126 int trusts_loaddb(void);
127 void trusts_closedb(int);
128 trustgroup
*tg_new(trustgroup
*);
129 trusthost
*th_new(trustgroup
*, char *);
130 void trustsdb_insertth(char *, trusthost
*, unsigned int);
131 void trustsdb_inserttg(char *, trustgroup
*);
132 trustgroup
*tg_copy(trustgroup
*);
133 trusthost
*th_copy(trusthost
*);
134 void tg_update(trustgroup
*);
135 void tg_delete(trustgroup
*);
136 void th_delete(trusthost
*);
137 void trustlog(unsigned int groupid
, const char *user
, const char *format
, ...);
138 void trustlogspew(nick
*np
, unsigned int groupid
, unsigned int limit
);
139 void trustloggrep(nick
*np
, const char *pattern
, unsigned int limit
);
141 typedef struct trustmigration
{
146 TrustMigrationGroup group
;
147 TrustMigrationHost host
;
148 TrustMigrationFini fini
;
152 typedef void (*TrustDBMigrationCallback
)(int, void *);
155 void trusts_newnick(nick
*, int);
156 void trusts_lostnick(nick
*, int);
159 int istrusted(nick
*);
160 int trustgline(trustgroup
*tg
, const char *ident
, int duration
, const char *reason
);
161 int trustungline(trustgroup
*tg
, const char *ident
, int duration
, const char *reason
);