forked from kofany/psotnic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-ent.h
355 lines (303 loc) · 9.67 KB
/
class-ent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#ifndef PKS_CLASS_ENT_H
#define PKS_CLASS_ENT_H 1
#include "pstring.h"
#include "ptrlist.h"
#include "prots.h"
#include "common.h"
class ent;
class inetconn;
class options
{
public:
class event
{
public:
pstring<> reason;
bool ok;
bool notFound;
ent *entity;
void setOk(ent *e, const char *format, ...);
void setError(ent *e, const char *format, ...);
void setError(ent *e);
void setNotFound(const char *format, ...);
event();
};
ptrlist<ent> list;
options();
event *setVariable(const char *var, const char *value);
const char *getValue(const char *var);
void sendToOwner(const char *owner, const char *var, const char *prefix);
bool parseUser(const char *from, const char *var, const char *value, const char *prefix, const char *prefix2="");
void reset();
void sendToFile(inetconn *c, pstring<> prefix);
#ifdef HAVE_DEBUG
void display();
#endif
protected:
void registerObject(const ent &e);
int maxVarLen;
};
class ent
{
public:
const char *name;
static options::event _event;
bool dontPrintIfDefault;
bool readOnly;
ent(const char *n=NULL) : name(n), dontPrintIfDefault(false), readOnly(false) { };
virtual options::event *setValue(const char *arg1, const char *arg2, const bool justTest=0) = 0;
virtual options::event *set(const char *arg, const bool justTest=0);
virtual const char *getValue() const = 0 ;
virtual const char *getName() const;
virtual const char *print(const int n=0) const;
virtual void reset() = 0;
virtual bool isDefault() const = 0;
virtual bool isPrintable() const;
virtual bool isReadOnly() const { return readOnly; };
virtual void setDontPrintIfDefault(bool value) { dontPrintIfDefault = value; };
virtual void setReadOnly(bool value) { readOnly = value; };
bool operator<(const ent &e) const;
bool operator==(const ent &e) const;
//virtual ~ent();
};
class entBool : public ent
{
public:
int value;
int defaultValue;
virtual options::event *setValue(const char *arg1, const char *arg2="", const bool justTest=0);
operator int() const;
entBool() : ent(NULL), value(false), defaultValue(false) { };
entBool(const char *n, const bool def) : ent(n), value(def), defaultValue(def) { };
bool str2int(const char *str, bool &ok) const;
virtual const char *getValue() const;
virtual void reset();
virtual bool isDefault() const;
int operator=(int n) { value = (n == 1); return value; };
virtual ~entBool() { };
};
class entInt : public entBool
{
public:
int min, max;
virtual options::event *setValue(const char *arg1, const char *arg2, const bool justTest=0);
virtual int str2int(const char *str, bool &ok) const;
entInt() : min(0), max(0) { name = NULL; };
entInt(const char *n, const int minimum, const int maximum, const int def)
: min(minimum), max(maximum) { name = n, value = defaultValue = def; };
virtual const char *getValue() const;
virtual const char *getMin() const;
virtual const char *getMax() const;
operator int() const;
int operator==(int n) const;
virtual ~entInt() { };
};
class entTime : public entInt
{
public:
entTime() : entInt() { };
entTime(const char *n, const int minimum, const int maximum, const int def) :
entInt(n, minimum, maximum, def) { };
virtual int str2int(const char *str, bool &ok) const;
virtual const char *getValue() const;
virtual const char *getMin() const;
virtual const char *getMax() const;
virtual ~entTime() { };
};
class entPerc : public entInt
{
public:
entPerc() : entInt() { };
entPerc(const char *n, const int minimum, const int maximum, const int def) :
entInt(n, minimum, maximum, def) { };
virtual int str2int(const char *str, bool &ok) const;
virtual const char *getValue() const;
virtual const char *getMin() const;
virtual const char *getMax() const;
virtual ~entPerc() { };
};
class entHost : public ent
{
protected:
int typesAllowed;
public:
pstring<8> ip;
pstring<16> connectionString;
enum types { ipv4 = 0x01, ipv6 = 0x02, bindCheck = 0x04, domain = 0x08, use_ssl = 0xf0};
entHost(const char *n="", const int t=ipv4) : ent(n), typesAllowed(t), ip("0.0.0.0"), connectionString("0.0.0.0") { };
virtual options::event *setValue(const char *arg1, const char *arg2, const bool justTest=0);
virtual const char *getValue() const;
virtual void reset();
virtual bool isDefault() const;
virtual operator const char*() const;
virtual operator unsigned int() const;
virtual ~entHost() { };
bool isSSL() { return getConnectionStringType(connectionString) & use_ssl; };
bool isIpv6() { return getConnectionStringType(connectionString) & ipv6; };
int getConnectionStringType(const char *str=0) const;
};
class entString : public ent
{
public:
int min, max;
pstring <16> string;
pstring <16> defaultString;
virtual options::event *setValue(const char *arg1, const char *arg2, const bool justTest=0);
virtual const char *getValue() const;
virtual void reset();
virtual bool isDefault() const;
virtual operator const char*() const;
virtual int getLen() const;
entString(const char *n="", const int minimum=0, const int maximum=MAX_INT, const char *def="") :
ent(n), min(minimum), max(maximum), string(def), defaultString(def) { }
virtual ~entString() { };
};
class entWord : public entString
{
public:
virtual options::event *setValue(const char *arg1, const char *arg2, const bool justTest=0);
entWord(const char *n="", const int minimum=0, const int maximum=MAX_INT, const char *def="")
: entString(n, minimum, maximum, def) { };
virtual ~entWord() { };
};
class entMD5Hash : public entWord
{
public:
unsigned char hash[16];
public:
entMD5Hash(const char *n="") : entWord(n) { memset(hash, 0, 16); };
virtual options::event *setValue(const char *arg1, const char *arg2, const bool justTest=0);
virtual void reset();
virtual bool isDefault() const;
virtual const unsigned char *getHash() const;
virtual operator const unsigned char*() const;
virtual ~entMD5Hash() { };
};
class entHPPH : public ent //host port password handle
{
protected:
entHost *_host;
entInt *_port;
entWord *_pass;
entWord *_handle;
virtual options::event *_setValue(const char *arg1, const char *arg2, const char *arg3, const char *arg4, const char *arg5, const bool justTest);
public:
virtual options::event *setValue(const char *arg1, const char *arg2, const bool justTest=0);
entHPPH(const char *n="", entHost *host=0, entInt *port=0, entWord *pass=0, entWord *handle=0) :
ent(n), _host(host), _port(port), _pass(pass), _handle(handle) { };
virtual const char *getValue() const;
virtual ~entHPPH();
virtual entHost &getHost() { return *_host; };
virtual entInt &getPort() { return *_port; };
virtual entWord &getPass() { return *_pass; };
virtual entWord &getHandle(){ return *_handle; };
virtual entHPPH &operator=(const entHPPH &e);
virtual void reset();
virtual bool isDefault() const;
friend class CONFIG;
virtual bool isSSL() const { return _host->isSSL(); };
};
class entHub : public entHPPH
{
private:
public:
int failures;
entHub(const char *n="", entHost *host=0, entInt *port=0, entMD5Hash *pass=0, entWord *handle=0) :
entHPPH(n, host, port, pass, handle), failures(0) { };
virtual ~entHub() { };
};
class entServer : public entHPPH
{
public:
entServer(const char *n="", entHost *ip=0, entInt *port=0, entWord *pass=0) :
entHPPH(n, ip, port, pass, 0) { };
virtual options::event *set(const char *ip, const char *port, const char *pass="", const bool justTest=0);
virtual ~entServer() { };
};
class entMult : public ent
{
private:
ptrlist<ent> list;
public:
entMult(const char *n=""): ent(n) { };
virtual options::event *setValue(const char *arg1, const char *arg2, bool justTest=0);
virtual const char *getValue() const { return NULL; };
virtual void reset();
virtual bool isDefault() const { return 1; };
virtual bool isPrintable() const { return 0; };
virtual void add(ent *e);
virtual ~entMult() { };
};
class entLoadModules : public ent
{
private:
pstring<> file;
pstring<> md5sum;
bool md5;
virtual options::event *_setValue(const char *arg1, const char *arg2, const char *arg3, bool justTest=0);
public:
entLoadModules(const char *n="", bool needValidMD5=1) : ent(n), md5(needValidMD5) { };
virtual ~entLoadModules() { };
virtual options::event *setValue(const char *arg1, const char *arg2, bool justTest=0);
virtual const char *getValue() const;
virtual void reset();
virtual bool isDefault() const;
virtual entLoadModules &operator=(const entLoadModules &e);
ptrlist<module>::iterator findModule(const char *str);
//bool rehash
bool unload(const char *str);
};
class entChattr : public ent
{
private:
int checkArg(const char *args);
/* generated by checkArg() (p/m)Flags, key and limit */
char gmFlags[32];
char gpFlags[32];
char gKey[CHAN_LEN];
long int gLimit;
/* current key/limit */
char Key[CHAN_LEN];
long int Limit;
/* default flags */
char dKey[CHAN_LEN];
long int dLimit;
char dmFlags[32];
char dpFlags[32];
void setFlags();
void setFlag(int plusFlag, const char flag);
public:
char mFlags[32];
char pFlags[32];
bool hasFlag(int minusFlag, const char flag, int Gen) const;
const char *getKey() const;
long int getLimit() const;
virtual options::event *setValue(const char *arg1, const char *arg2, const bool justTest=0);
virtual const char *getValue() const;
virtual void reset();
virtual bool isDefault() const;
entChattr(const char *n="", const char *modes="") : ent(n)
{
memset(pFlags, 0, sizeof(pFlags));
memset(mFlags, 0, sizeof(mFlags));
memset(Key, 0, sizeof(Key));
Limit = 0;
if(strlen(modes))
{
setValue(n, modes, 1);
strcpy(dpFlags, pFlags);
strcpy(dmFlags, mFlags);
strcpy(dKey, Key);
dLimit = Limit;
}
else
{
memset(dpFlags, 0, sizeof(dpFlags));
memset(dmFlags, 0, sizeof(dmFlags));
memset(dKey, 0, sizeof(dKey));
dLimit = 0;
}
}
virtual ~entChattr() { };
};
#endif