1 unit fidoconf;
2 {: FIDOCONFIG --- library for fidonet configs
3 
4    Copyright (C) 1998-1999
5 
6    Matthias Tichy
7 
8    Fido:     2:2433/1245 2:2433/1247 2:2432/605.14
9    Internet: mtt@tichy.de
10 
11    Grimmestr. 12         Buchholzer Weg 4
12    33098 Paderborn       40472 Duesseldorf
13    Germany               Germany
14 
15    This file is part of FIDOCONFIG.
16 
17    This library is free software; you can redistribute it and/or
18    modify it under the terms of the GNU Library General Public
19    License as published by the Free Software Foundation; either
20    version 2 of the License, or (at your option) any later version.
21 
22    This library is distributed in the hope that it will be useful,
23    but WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25    Library General Public License for more details.
26 
27    You should have received a copy of the GNU Library General Public
28    License along with this library; see file COPYING. If not, write to the Free
29    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA }
30 
31 {: NOTE: Unfortunately it turned out that the structures that are passed
32          between fidoconfig and any calling programs are in no way align
33          controlled, that is, how they are aligned is left to the compiler.
34          That means that if you are not using the same compiler for your
35          program that was used to compile the libraries, chances are that
36          you will have an alignment problem resulting in fields of the
37          structures being out of sync, e.g. you are reading something totally
38          different from what the library put there.
39          Because of this and because I don't want to chase a moving target
40          like this, I will stop maintaining smapi.pas and fidoconf.pas.
41          That probably means that husky has now become a project that can
42          only be used by C programmers, unless somebody else wants
43          to go through the trouble.
44          One possible solution I can think of, would be having an interface
45          layer that converts the randomly aligned structures to other
46          structures that are fixed. I might do it, maybe, if I don't find
47          anything else to waste my time on. But this is rather unlikely,
48          because it has to be done in C and that is definitely not my
49          favourite programming language.
50          Please leave this comment in here, so nobody else will waste time
51          trying to figure out why the data his programs reads is wrong.
52          2001-07-22 twm }
53 
54 
55 interface
56 
57 { C default packing is dword }
58 { TODO -otwm -ccheck : Check whether this is necessary. }
59 // {$PACKRECORDS 4}
60 {$MINENUMSIZE 4} // minimum enum size
61 
62 const
63   LIB_FIDOCONFIG_NAME = 'libfidoconfig.so';
64 
65 const
66   MSGTYPE_PASSTHROUGH = $04;
67 
68 const
69 {$IFDEF UNIX}
70   PATH_DELIM = '/';
71 {$ELSE}
72   PATH_DELIM = '\';
73 {$ENDIF}
74 
75 { TODO -otwm -ccheck : Check these variables. }
76 //    var
77 //       actualLine : PChar;cvar;external;
78 //     actualLineNr : longint;cvar;external;
79 //       wasError : char;cvar;external;
80 
striptwhitenull81 function striptwhite(_Str: PChar): PChar;
82 
83 type
84   dword = longword;
85 
86 type
87   PAddress = ^TAddress;
88   TAddress = packed record
89     zone: dword;
90     net: dword;
91     node: dword;
92     point: dword;
93     domain: PChar;
94   end;
95 
96   PPacker = ^TPacker;
97   TPacker = packed record
98     packer: PChar;
99     call: PChar;
100   end;
101 
102   PExecOnFile = ^TExecOnFile;
103   TExecOnFile = packed record
104     filearea: PChar;
105     filename: PChar;
106     command: PChar;
107   end;
108 
109   TFlavourEnum = (normal, hold, crash, direct, immediate);
110   TForwardEnum = (fOff, fSecure, fOn);
111   TEmptyPktPwdEnum = (eOff, eSecure, eOn);
112   TPktHeaderDifferEnum = (pdOff, pdOn);
113   TNameCaseEnum = (eLower, eUpper);
114   TNameCaseConvEnum = (cLower, cUpper, cDontTouch);
115 
116   PLink = ^TLink;
117   TLink = packed record
118     hisAka: TAddress;
119     ourAka: PAddress;
120     name: PChar;
121     defaultPwd: PChar;
122     pktPwd: PChar;
123     ticPwd: PChar;
124     areaFixPwd: PChar;
125     fileFixPwd: PChar;
126     bbsPwd: PChar;
127     sessionPwd: PChar;
128     handle: PChar;              // nickname
129     email: PChar;
130     autoAreaCreate: dword;      // 0 if not allowed for autoareacreate
131     autoFileCreate: dword;      // 0 if not allowed for autofilecreate
132     AreaFix: dword;             // 0 if not allowed for areafix
133     FileFix: dword;             // 0 if not allowed for filefix
134     forwardRequests: dword;     // 0 if not allowed forward requests
135     forwardFileRequests: dword; // 0 if not allowed forward requests for file areas
136     fReqFromUpLink: dword;      // 0 - ignore added unknown area (no area in cfg)
137     allowEmptyPktPwd: longint;
138     allowPktAddrDiffer: longint;
139     forwardPkts: TForwardEnum;
140     pktFile: PChar;
141     packFile: PChar;
142     floFile: PChar;
143     bsyFile: PChar;
144     packerDef: PPacker;
145     echoMailFlavour: TFlavourEnum;
146     fileEchoFlavour: TFlavourEnum;
147     LinkGrp: PChar;
148     AccessGrp: ^PChar;
149     NumAccessGrp: dword;
150     autoAreaCreateFile: PChar;
151     autoFileCreateFile: PChar;
152     autoAreaCreateDefaults: PChar;
153     autoFileCreateDefaults: PChar;
154     forwardRequestFile: PChar;
155     forwardAreaPriority: dword;
156     RemoteRobotName: PChar;
157     forwardFileRequestFile: PChar;
158     forwardFilePriority: dword;
159     RemoteFileRobotName: PChar;
160     msg: pointer;
161     noTic: dword;
162     Pause: longint;
163     autoPause: dword;
164     level: dword;
165     arcmailSize: dword;
166     pktSize: dword;
167     export: PChar;
168     import: PChar;
169     mandatory: PChar;
170     optGrp: ^PChar;
171     NumOptGrp: dword;
172     delNotReceivedTic: dword;         //1 - if file not recieved, then remove TIC
173   end;
174 
175   TRoutingEnum = (route_zero, host, hub, boss, noroute, nopack, route_extern);
176 
177   { if target = NULL use }
178   { this }
179   PRoute = ^TRoute;
180   TRoute = packed record
181     flavour: TFlavourEnum;
182     enc: char;
183     target: PLink;
184     routeVia: TRoutingEnum;
185     pattern: PChar;
186     viaStr: PChar;
187   end;
188 
189   TDupeCheckEnum = (dcOff, dcMove, dcDel);
190 
191   TDupeCheckTypeEnum = (hashDupes,   // Base bild from crc32
192                   hashDupesWmsgid,   // Base bild from crc32+MSGID
193                         textDupes,   // Base bild from FromName+ToName+Subj+MSGID
194                    commonDupeBase);  // Common base for all areas bild from crc32
195 
196 
197   PAreaLink = ^TAreaLink;
198   TAreaLink = packed record
199     link: PLink;
200     export: char;
201     import: char;
202     mandatory: char;
203   end;
204 
205   PArea = ^TArea;
206   TArea = packed record
207     areaName: PChar;
208     fileName: PChar;
209     description: PChar;
210 
211     msgbType: longint;  // MSGTYPE_SDM, MSGTYPE_SQUISH, MSGTYPE_JAM or MSGTYPE_PASSTHROUGH
212 
213     useAka: PAddress;
214 
215     downlinks: ^PAreaLink;
216     downlinkCount: dword;
217 
218     purge: dword;
219     max: dword;
220     dupeHistory: dword;
221     keepUnread: char;
222     killRead: char;
223 
224     filler1: array[0..1] of char; // correct alignment
225 
226     dupeCheck: TDupeCheckEnum;
227     tinySB: char;
228     killSB: char;
229     hide: char;
230     noPause: char;
231     mandatory: char;
232     DOSFile: char;
233 
234     filler2: array[0..1] of char; // correct alignment
235 
236     levelread: dword;
237     levelwrite: dword;
238     dupes: pointer;
239     newDupes: pointer;
240     imported: dword;
241 
242     group: PChar;
243 
244     ccoff: longint;            // 1 if carbon copy is not allowed from this area
245 
246     uid,
247     gid,
248     fperm: dword;
249 
250     nolink: longint;          // do not reply-link area
251     keepsb: longint;          // keep seen-by's and path
252     scn: longint;             // 1 if scanned
253     nopack: longint;          // do not pack area
254   end;
255 
256   PFileArea = ^TFileArea;
257   TFileArea = packed record
258     areaName: PChar;
259     pathName: PChar;
260     description: PChar;
261     sendorig: longint;         // 1 - Send Original
262     pass: longint;             // 1 - Passthrough File Area
263     noCRC: longint;            // 0 if CRC check should be done on incoming files
264     noreplace: longint;        // 1 - no replace files in this filearea
265     useAka: PAddress;
266     downlinks: ^PAreaLink;
267     downlinkCount: dword;
268     levelread: dword;
269     levelwrite: dword;
270     mandatory: char;
271     hide: char;
272     noPause: char;
273 
274     group: PChar;
275   end;
276 
277   PBbsArea = ^TBbsArea;
278   TBbsArea = packed record
279     areaName: PChar;
280     pathName: PChar;
281     description: PChar;
282   end;
283 
284   TCarbonTypeEnum = (ct_to, ct_from, ct_kludge, ct_subject,
285 						 ct_msgtext, ct_addr);
286 
287   PCarbon = ^TCarbon;
288   TCarbon = packed record
289     _type: TCarbonTypeEnum;
290     _str: PChar;
291     reason: PChar;
292     area: PArea;
293     addr: TAddress;
294     areaname: PChar;
295     export: longint;
296     netMail: longint;
297     move: longint;
298     extspawn: longint;
299   end;
300 
301   PUnpacker = ^TUnpacker;
302   TUnpacker = packed record
303     offset: longint;
304     matchCode: ^byte;
305     mask: ^byte;
306     codeSize: longint;
307     call: PChar;
308   end;
309 
310   PRemap = ^TRemap;
311   TRemap = packed record
312     oldaddr: TAddress;
313     newaddr: TAddress;
314     toname: PChar;
315   end;
316 
317   TNodelistFormatEnum = (fts5000, points24);
318 
319   PNodelist = ^TNodelist;
320   TNodelist = packed record
321     nodelistName: PChar;              // name of unpacked nodelist w/o path
322     diffUpdateStem: PChar;            // with pathname
323     fullUpdateStem: PChar;            // with pathname
324     defaultZone: dword;
325     format: dword;
326   end;
327 
328   PSaveTic = ^TSaveTic;
329   TSaveTic = record
330     fileAreaNameMask: PChar;
331     pathName: PChar;
332   end;
333 
334   PFidoConfig = ^TFidoConfig;
335   TFidoConfig = packed record
336     cfgVersionMajor: dword;
337     cfgVersionMinor: dword;
338     name: PChar;
339     location: PChar;
340     sysop: PChar;
341     addrCount: dword;
342     addr: PAddress;
343     publicCount: dword;
344     publicDir: ^PChar;
345     linkCount: dword;
346     links: PLink;
347     inbound: PChar;
348     outbound: PChar;
349     protInbound: PChar;
350     listInbound: PChar;
351     localInbound: PChar;
352     tempInbound: PChar;
353     logFileDir: PChar;
354     dupeHistoryDir: PChar;
355     nodelistDir: PChar;
356     msgBaseDir: PChar;
357     magic: PChar;
358     areafixhelp: PChar;
359     filefixhelp: PChar;
360     tempOutbound: PChar;
361     ticoutbound: PChar;
362     fileAreaBaseDir: PChar;
363     passFileAreaDir: PChar;
364     busyFileDir: PChar;
365     semaDir: PChar;
366     badFilesDir: PChar;
367     loglevels: PChar;
368     ScreenLogLevels: PChar;
369     dupeArea: TArea;
370     badArea: TArea;
371     netMailAreaCount: dword;
372     netMailAreas: PArea;
373     echoAreaCount: dword;
374     echoAreas: PArea;
375     localAreaCount: dword;
376     localAreas: PArea;
377     fileAreaCount: dword;
378     fileAreas: PFileArea;
379     bbsAreaCount: dword;
380     bbsAreas: PBbsArea;
381     routeCount: dword;
382     route: PRoute;
383     routeFileCount: dword;
384     routeFile: PRoute;
385     routeMailCount: dword;
386     routeMail: PRoute;
387     packCount: dword;
388     pack: PPacker;
389     unpackCount: dword;
390     unpack: PUnpacker;
391     intab: PChar;
392     outtab: PChar;
393     echotosslog: PChar;
394     importlog: PChar;
395     LinkWithImportlog: PChar;
396     lockfile: PChar;
397     LogUID,
398     LogGID,
399     LogPerm: dword;
400     fileAreasLog: PChar;
401     longNameList: PChar;
402     fileNewAreasLog: PChar;
403     fileArcList: PChar;
404     filePassList: PChar;
405     fileDupeList: PChar;
406     msgidfile: PChar;
407     carbonCount: dword;
408     carbons: PCarbon;
409     carbonAndQuit: dword;
410     carbonKeepSb: dword;
411     carbonOut: dword;
412     includeFiles: ^PChar;
413     includeCount: dword;
414     remapCount: dword;
415     remaps: PRemap;
416     areafixFromPkt: dword;
417     areafixKillReports: dword;
418     areafixKillRequests: dword;
419     areafixMsgSize: dword;
420     areafixSplitStr: PChar;
421     areafixOrigin: PChar;
422     PublicGroup: ^PChar;
423     numPublicGroup: dword;
424     ReportTo: PChar;
425     execOnFileCount: dword;
426     execOnFile: PExecOnFile;
427     logEchoToScreen: dword;
428     separateBundles: dword;
429     defarcmailSize: dword;
430     ignoreCapWord: dword;
431     noProcessBundles: dword;
432     disableTID: dword;
433 
434     afterUnpack: PChar;
435     beforePack: PChar;
436     processPkt: PChar;
437     createDirs: dword;
438     longDirNames: dword;
439     splitDirs: dword;
440     addDLC: dword;
441     fileSingleDescLine: dword;
442     fileCheckDest: dword;
443     filefixKillReports: dword;
444     filefixKillRequests: dword;
445     convertLongNames: TNameCaseConvEnum;
446     convertShortNames: TNameCaseConvEnum;
447     fileDescPos: dword;
448     DLCDigits: dword;
449     fileMaxDupeAge: dword;
450     fileFileUMask: dword;
451     fileDirUMask: dword;
452     oritinInAnnounce: dword;
453     MaxTicLineLength: dword;
454     fileLocalPwd: PChar;
455     fileLDescString: PChar;
456     saveTicCount: dword;
457     saveTic: PSaveTic;
458     nodelistCount: dword;
459     nodelists: PNodelist;
460     fidoUserList: PChar;
461 
462     typeDupeBase: TDupeCheckTypeEnum;
463     areasMaxDupeAge: dword;
464 
465     linkDefaults: PLink;
466     describeLinkDefaults: integer;
467     createAreasCase: TNameCaseEnum;
468     areasFileNameCase: TNameCaseEnum;
469     tossingExt: PChar;
470 {$ifdef __NT __}
471     setConsoleTitle: dword;
472 {$endif}
473     addToSeen: PAddress;
474     addToSeenCount: dword;
475 
476     tearline: PChar;
477     origin: PChar;
478   end;
479 
480 function readConfig(_Filename: PChar): PFidoConfig;
481 
482 procedure disposeConfig(_Config: PFidoConfig);
483 
484 function getLink(_Config: TFidoConfig; _Addr: PChar): PLink;
485 
486 function getLinkFromAddr(_Config: TFidoConfig; _Aka: TAddress): PLink;
487 
488 function getAddr(_Config: TFidoConfig; _Addr: PChar): PAddress;
489 
490 function existAddr(_Config: TFidoConfig; _Aka: TAddress): longint;
491 
492 function getArea(_Config: PFidoConfig; _AreaName: PChar): PArea;
493 
494 function getNetMailArea(_Config: PFidoConfig; _AreaName: PChar): PArea;
495 
496   {: This function returns 0 if the link is not linked to the area,
497      else it returns 1. }
498 function isLinkOfArea(_Link: PLink; _Area: PArea): longint;
499 
500   {: This function dumps the config to a file. The file is in fidoconfig format
501      so, it is possible to change the config in memory and write it to disk.
502      All formatting and comments are removed and the include structure of the
503      config cannot be recreated. So be careful. A file called <fileName> which
504      already exists will be overwritten.
505      1 if there were problems writing the config
506      0 else }
507 function dumpConfigToFile(_Config: PFidoConfig; _FileName: PChar): longint;
508 
509 (*
510   { the following functions are for internal use. }
511   { Only use them if you really know what you do. }
512   function readLine(F:pFILE):PChar;
513 
514   function parseLine(line:PChar; config:PFidoConfig):longint;
515 
516   procedure parseConfig(f:pFILE; config:PFidoConfig);
517 *)
518   function getConfigFileName:PChar;
519 (*
520   function trimLine(line: PChar): PChar;
521 *)
522 
523 
524   {: This method can be used to get a program-specifically config-filename,
525      in the same directories which are searched for fidoconfig.
526      @param EnvVar should be set to a string which resembles a
527             environment-variable which should be checked if it includes
528             the fileName.
529      @param ConfigName is the filename of the config  without  any prefixes.
530             e.g. getConfigFileNameForProgram("FIDOCONFIG", "config");
531             is the call which is used for fidoconfig }
532 function getConfigFileNameForProgram(_EnvVar: PChar; _ConfigName: PChar): PChar;
533 
534 function isLinkOfFileArea(_Link: PLink; _Area: PFileArea): longint;
535 
536 function getFileArea(_Config: PFidoConfig; _AreaName: PChar): PFileArea;
537 
538 (*
539   { this function can be used to dump config to stdout or to an already opened file. }
540   procedure dumpConfig(config:PFidoConfig; f:pFILE);
541 *)
542 
543 
544 implementation
545 
546 function striptwhite(_Str: PChar): PChar; external LIB_FIDOCONFIG_NAME name 'striptwhite';
547 
548 function readConfig(_Filename: PChar): PFidoConfig; external LIB_FIDOCONFIG_NAME name 'readConfig';
549 procedure disposeConfig(_Config: PFidoConfig); external LIB_FIDOCONFIG_NAME name 'disposeConfig';
550 
551 function getLink(_Config: TFidoConfig; _Addr: PChar): PLink; external LIB_FIDOCONFIG_NAME name 'getLink';
552 function getLinkFromAddr(_Config: TFidoConfig; _Aka: TAddress): PLink; external LIB_FIDOCONFIG_NAME name 'getLinkFromAddr';
553 function getAddr(_Config: TFidoConfig; _Addr: PChar): PAddress; external LIB_FIDOCONFIG_NAME name 'getAddr';
554 function existAddr(_Config: TFidoConfig; _Aka: TAddress): longint; external LIB_FIDOCONFIG_NAME name 'existAddr';
555 function getArea(_Config: PFidoConfig; _AreaName: PChar): PArea; external LIB_FIDOCONFIG_NAME name 'getArea';
556 function getNetMailArea(_Config: PFidoConfig; _AreaName: PChar): PArea; external LIB_FIDOCONFIG_NAME name 'getNetMailArea';
557 function isLinkOfArea(_Link: PLink; _Area: PArea): longint; external LIB_FIDOCONFIG_NAME name 'isLinkOfArea';
558 function dumpConfigToFile(_Config: PFidoConfig; _FileName: PChar): longint; external LIB_FIDOCONFIG_NAME name 'dumpConfigToFile';
559 (*
560   function readLine(F:pFILE):PChar; external LIB_FIDOCONFIG_NAME;
561   function parseLine(line:PChar; config:PFidoConfig):longint; external LIB_FIDOCONFIG_NAME;
562   procedure parseConfig(f:pFILE; config:PFidoConfig); external LIB_FIDOCONFIG_NAME;
563   function trimLine(line: PChar): PChar; external LIB_FIDOCONFIG_NAME;
564 *)
565 function getConfigFileName: PChar; external LIB_FIDOCONFIG_NAME name 'getConfigFileName';
566 function getConfigFileNameForProgram(_EnvVar: PChar; _ConfigName: PChar): PChar; external LIB_FIDOCONFIG_NAME name 'getConfigFileNameForProgram';
567 function isLinkOfFileArea(_Link: PLink; _Area: PFileArea): longint; external LIB_FIDOCONFIG_NAME name 'isLinkOfFileArea';
568 function getFileArea(_Config: PFidoConfig; _AreaName: PChar): PFileArea; external LIB_FIDOCONFIG_NAME name 'getFileArea';
569 (*
570   procedure dumpConfig(config:PFidoConfig; f:pFILE); external LIB_FIDOCONFIG_NAME;
571 *)
572 
573 end.
574