-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.h
420 lines (344 loc) · 16.6 KB
/
common.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/* ************************************************************************
*
* common header file
*
* (c) 1994-2019 by Markus Reschke
*
* ************************************************************************ */
/* ************************************************************************
* common includes
* ************************************************************************ */
/* basic stuff */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
/* time */
#include <time.h>
/* ************************************************************************
* constants
* ************************************************************************ */
/*
* defaults for this program
*/
/* about */
#define PROJECT "mfreq"
#define VERSION "v3.19"
#define VERSION_MAJOR 3
#define VERSION_MINOR 19
#define COPYRIGHT "(c) 1994-2019 by Markus Reschke"
/* default paths */
#define DEFAULT_CFG_PATH "/etc/fido/mfreq"
#define DEFAULT_TMP_PATH "/var/tmp"
/* buffer size (must not exceed the maximum value of an Integer */
#define DEFAULT_BUFFER_SIZE 4096 /* standard buffer size */
/* fileindex */
#define SUFFIX_DATA "data"
#define SUFFIX_LOOKUP "lookup"
#define SUFFIX_ALIAS "alias"
#define SUFFIX_OFFSET "offset"
/*
* just to be sure :-)
*/
/* boolean */
#define FALSE 0
#define False 0
#define TRUE 1
#define True 1
/*
* global values
*/
/* log types */
#define L_INFO 1 /* information */
#define L_DEBUG 2 /* debugging output */
#define L_WARN 3 /* warning */
#define L_ERR 4 /* error */
/* cfg switches (bitmask, 16 bits) */
/* common */
#define SW_NONE 0b0000000000000000 /* no switch set */
#define SW_BINARY_SEARCH 0b0000000000000001 /* binary search */
#define SW_ANY_CASE 0b0000000000000010 /* case-insensitive file matching */
#define SW_SI_UNITS 0b0000000000000100 /* enable SI units (input) */
#define SW_IEC_UNITS 0b0000000000001000 /* enable IEC units (output) */
/* index */
#define SW_PATH_ALIASES 0b0000000000010000 /* create path aliases */
/* frequest */
#define SW_DELETE_REQUEST 0b0000000100000000 /* delete request file (.req) */
#define SW_SEND_NETMAIL 0b0000001000000000 /* send respone netmail */
#define SW_TYPE_2 0b0000010000000000 /* packet type-2 */
#define SW_TYPE_2PLUS 0b0000100000000000 /* packet type-2+ */
#define SW_SEND_TEXT 0b0001000000000000 /* send response text file */
#define SW_LOG_REQUEST 0b0010000000000000 /* extensive logging */
/* file flags (bitmask, 16 bits) */
#define FILE_NONE 0b0000000000000000 /* no flag set */
#define FILE_SKIP 0b0000000000000001 /* skip file */
/* frequest flags (bitmask, 16 bits) */
#define REQ_NONE 0b0000000000000000 /* no flag set */
#define REQ_PROTECTED 0b0000000000000001 /* protected FTS session */
#define REQ_UNPROTECTED 0b0000000000000010 /* unprotected FTS session */
#define REQ_LISTED 0b0000000000000100 /* listed system */
#define REQ_UNLISTED 0b0000000000001000 /* unlisted system */
/* file info status (bitmask, 16 bits) */
#define FINFO_NONE 0b0000000000000000 /* no status */
#define FINFO_OK 0b0000000000000001 /* ok to list */
#define FINFO_NOT_FOUND 0b0000000000000010 /* file deleted / not found */
#define FINFO_EXCLUDED 0b0000000000000100 /* file excluded */
#define FINFO_CHANGED 0b0000000000001000 /* some value changed */
/* file response status (bitmask, 16 bits) */
#define RESP_NONE 0b0000000000000000 /* no status */
#define RESP_OK 0b0000000000000001 /* ok to send */
#define RESP_PWERROR 0b0000000000000010 /* password error */
#define RESP_OFFLINE 0b0000000000000100 /* not available right now */
#define RESP_DUPE 0b0000000000001000 /* duplicate file */
#define RESP_INTDUPE 0b0000000000010000 /* internal dupe */
/* file request status (bitmask, 16 bits) */
#define FREQ_NONE 0b0000000000000000 /* no status */
#define FREQ_NO_FILE 0b0000000000000001 /* no file found */
#define FREQ_FOUND_FILE 0b0000000000000010 /* found file(s) */
#define FREQ_LIMIT 0b0000000000010000 /* any limits exceeded */
#define FREQ_FILELIMIT 0b0000000000100000 /* file limit exceeded */
#define FREQ_BYTELIMIT 0b0000000001000000 /* byte limit exceeded */
#define FREQ_PWLIMIT 0b0000000010000000 /* bad PW limit exceeded */
#define FREQ_FREQLIMIT 0b0000000100000000 /* frequests (filename patterns) */
/* file info modes (bitmask, 16 bits) */
#define INFO_NONE 0b0000000000000000 /* no mode */
#define INFO_UPDATE 0b0000000000000001 /* update description file */
#define INFO_STRICT 0b0000000000000010 /* strict syntax checking */
#define INFO_SKIPS 0b0000000000000100 /* allow missing data fields */
#define INFO_RELAX 0b0000000000001000 /* ignore syntax errors */
#define INFO_DIR_BBS 0b0000000000010000 /* dir.bbs */
#define INFO_FILES_BBS 0b0000000000100000 /* files.bbs */
#define INFO_DESCRIPT_ION 0b0000000001000000 /* descript.ion */
/* file info fields */
#define FIELD_NONE 0 /* no type */
#define FIELD_NAME 1 /* name */
#define FIELD_SIZE 2 /* size */
#define FIELD_DATE 3 /* date */
#define FIELD_COUNTER 4 /* download counter */
#define FIELD_DESC 5 /* description */
/* field alignments */
#define ALIGN_NONE 0 /* unset */
#define ALIGN_LEFT 1 /* align left */
#define ALIGN_RIGHT 2 /* align right */
/* field formats */
#define FIELD_FORM_NONE 0 /* unset */
/* name */
#define FIELD_FORM_DOS 1 /* dos style 8.3 */
#define FIELD_FORM_LONG 2 /* long filename */
/* size */
#define FIELD_FORM_BYTES 1 /* number of bytes */
#define FIELD_FORM_UNIT 2 /* number and unit */
#define FIELD_FORM_SHORT 3 /* number and short unit */
/* date */
#define FIELD_FORM_US 1 /* MM-DD-YY */
#define FIELD_FORM_ISO 2 /* YYYY-MM-DD */
/* download counter */
#define FIELD_FORM_SQUARE 1 /* [...] */
/* description */
#define FIELD_FORM_SINGLE 1 /* single line */
#define FIELD_FORM_MULTI 2 /* multiple lines */
/* ************************************************************************
* types
* ************************************************************************ */
/* tokens (linked list) */
typedef struct token_type
{
char *String; /* contains single token */
struct token_type *Next; /* pointer to next element */
} Token_Type;
/* file details (linked list) */
typedef struct file_type
{
char *Name; /* filename */
time_t Time; /* time of last file modifaction */
unsigned short Flags; /* additional flags/conditions */
struct file_type *Next; /* pointer to next element */
} File_Type;
/* file data for file index (linked list) */
typedef struct index_data
{
char *Name; /* frequest name */
char *Filepath; /* file path */
char *PW; /* frequest password */
struct index_data *Next; /* pointer to next element */
} IndexData_Type;
/* lookup data for file index (linked list) */
typedef struct index_lookup
{
char Letter; /* initial letter */
off_t Offset; /* data file offset */
unsigned int Start; /* start line# */
unsigned int Stop; /* stop line# */
struct index_lookup *Next; /* pointer to next element */
} IndexLookup_Type;
/* path aliases for file index (linked list) */
typedef struct index_alias
{
unsigned int Number; /* alias number */
char *Path; /* path */
off_t Offset; /* file offset */
struct index_alias *Next; /* pointer to next element */
} IndexAlias_Type;
/* files to exclude (linked list) */
typedef struct exclude
{
char *Name; /* file name / pattern */
/* todo: add conditions */
struct exclude *Next; /* pointer to next element */
} Exclude_Type;
/* FTS address / AKA (linked list) */
/* adressing based on FRL-1002 and FSC-0039 */
typedef struct aka
{
char *Address; /* address string */
unsigned short Zone; /* zone number (1 - 65535) */
unsigned short Net; /* net number (1 - 65535) */
unsigned short Node; /* node number (0 - 65535) */
unsigned short Point; /* point number (0 - 65535) */
char *Domain; /* domain (max. 8 characters) */
struct aka *Next; /* pointer to next element */
} AKA_Type;
/* index definition (linked list) */
typedef struct index
{
char *Filepath; /* filepath of file index */
char *MountingPoint; /* mounting point */
struct index *Next; /* pointer to next element */
} Index_Type;
/* request limit (linked list) */
typedef struct limit
{
char *Address; /* FTS address pattern */
long Files; /* number of files */
long long Bytes; /* sum of bytes (twice as long as off_t) */
int BadPWs; /* number of bad passwords */
int Freqs; /* number of frequests (file patterns) */
unsigned short Flags; /* additional flags/conditions */
struct limit *Next; /* pointer to next element */
} Limit_Type;
/* file found (linked list) */
typedef struct response
{
char *Filepath; /* filepath */
off_t Size; /* filesize */
unsigned short Status; /* file status */
struct response *Next; /* pointer to next element */
} Response_Type;
/* requested file (linked list) */
typedef struct request
{
char *Name; /* requested filename or pattern */
char *SearchName; /* filename pattern to search for */
char *PW; /* password */
unsigned short Status; /* request status */
Response_Type *Files; /* files to send (linked list) */
Response_Type *LastFile; /* pointer to last element in list */
struct request *Next; /* pointer to next element */
} Request_Type;
/* file information (linked list) */
typedef struct info
{
char *Name; /* file name */
off_t Size; /* file size */
time_t Time; /* time of last file modifaction */
unsigned short Counter; /* download counter */
unsigned short Status; /* file status */
Token_Type *Infos; /* file decription (linked list) */
Token_Type *LastInfo; /* pointer to last element in list */
struct info *Next; /* pointer to next element */
} Info_Type;
/* data field for file description file (linked list) */
typedef struct field
{
unsigned short Type; /* type ID */
unsigned short Line; /* line number */
unsigned short Pos; /* position */
unsigned short Width; /* width (max. size) */
unsigned short Align; /* alignment */
unsigned short Format; /* format ID */
struct field *Next; /* pointer to next element */
} Field_Type;
/* global environment */
typedef struct
{
/* basic filepaths */
char *CfgFilepath; /* configuration filepath */
char *LogFilepath; /* log filepath */
/* process */
char *CWD; /* current working directory */
pid_t PID; /* process ID */
/* global time */
time_t UnixTime;
struct tm DateTime;
/* file streams */
FILE *Log; /* log file */
FILE *List; /* filelist */
/* program control */
_Bool Run; /* stop/keep running */
unsigned short ConfigDepth; /* depth of cfg files (includes) */
char *CfgInUse; /* cfg currently parsed */
unsigned int CfgLinenumber; /* line number currently parsed */
/* common configuration */
unsigned short CfgSwitches; /* several cfg switches */
/* file index */
IndexData_Type *DataList; /* index data (linked list) */
IndexData_Type *LastData; /* pointer to last element in list */
IndexLookup_Type *LookupList; /* index lookup (linked list) */
IndexLookup_Type *LastLookup; /* pointer to last element in list */
IndexAlias_Type *AliasList; /* index lookup (linked list) */
IndexAlias_Type *LastAlias; /* pointer to last element in list */
Exclude_Type *ExcludeList; /* file exclusion (linked list) */
Exclude_Type *LastExclude; /* pointer to last element in list */
File_Type *FileList; /* file details (linked list) */
File_Type *LastFile; /* pointer to last element in list */
/* frequest configuration */
char *MailPath; /* path of response mail */
Token_Type *MailHeader; /* mail header (linked list) */
Token_Type *LastHeader; /* pointer to last element in list */
Token_Type *MailFooter; /* mail footer (linked list) */
Token_Type *LastFooter; /* pointer to last element in list */
AKA_Type *AKA; /* my AKAs (linked list) */
AKA_Type *LastAKA; /* pointer to last element in list */
Index_Type *IndexList; /* index files (linked list) */
Index_Type *LastIndex; /* pointer to last element in list */
Limit_Type *LimitList; /* request limits (linked list) */
Limit_Type *LastLimit; /* pointer to last element in list */
/* frequest filepaths */
char *SRIF_Filepath; /* filepath of SRIF file */
char *RequestFilepath; /* filepath of request */
char *ResponseFilepath; /* filepath of response */
char *MailFilepath; /* filepath of netmail */
char *TextFilepath; /* filepath of textmail */
/* frequest(er) details */
char *Sysop; /* sysop name */
AKA_Type *ReqAKA; /* requesters AKAs (linked list) */
AKA_Type *ReqLastAKA; /* pointer to last element in list */
AKA_Type *CalledAKA; /* which AKA is called */
long BPS; /* speed (in bps) of connection */
long ReqTime; /* time (in minutes) allowed */
unsigned short ReqFlags; /* session/system flags */
char *CallerID; /* caller ID */
char *SessionType; /* session type */
Request_Type *RequestList; /* request list (linked list) */
Request_Type *LastRequest; /* pointer to last element in list */
/* frequest runtime stuff */
Limit_Type *ActiveLimit; /* limits to use for requester */
long Files; /* file counter */
long long Bytes; /* byte counter (twice as long as off_t) */
unsigned short FreqStatus; /* status of frequest */
AKA_Type *ActiveLocalAKA; /* local AKA to be used */
AKA_Type *ActiveRemoteAKA; /* remote AKA to be used */
/* filelist */
char *ListFilepath; /* filepath of filelist */
unsigned short InfoMode; /* file info mode */
Info_Type *InfoList; /* file information list (linked list) */
Info_Type *LastInfo; /* pointer to last element in list */
/* file description fields (linked list) */
Field_Type *Fields_filelist; /* for filelist */
Field_Type *Fields_files_bbs; /* for files.bbs */
} Env_Type;
/* ************************************************************************
* EOF
* ************************************************************************ */