1 /*****************************************************************************/
2 /*                                                                           */
3 /*                 (C) Copyright 1991-1997  Alberto Pasquale                 */
4 /*                 Portions (C) Copyright 1999 Per Lundberg                  */
5 /*                                                                           */
6 /*                   A L L   R I G H T S   R E S E R V E D                   */
7 /*                                                                           */
8 /*****************************************************************************/
9 /*                                                                           */
10 /*   How to contact the author:  Alberto Pasquale of 2:332/504@fidonet       */
11 /*                               Viale Verdi 106                             */
12 /*                               41100 Modena                                */
13 /*                               Italy                                       */
14 /*                                                                           */
15 /*****************************************************************************/
16 
17 #ifndef BBSGENLB_HPP
18 #define BBSGENLB_HPP
19 
20 #include <stdio.h>
21 #include <time.h>
22 
23 #define TRUE 1
24 #define FALSE 0
25 typedef int BOOL;
26 
27 extern "C" {
28 #include <smapi/msgapi.h>
29 };
30 
31 #include <newarea.h>
32 #include <limits.h>
33 
34 //#pragma pack (1)
35 
36 typedef NETADDR ADR;
37 
38 
39             // Implementation in Fview.Cpp
40 
41 
42 typedef void (*VShow) (char *strfmt, ...);
43 
44 int fview (char *filename, VShow vshow);
45 
46 // filename is an archive full filename
47 // sc is a function that must be called to output
48 //    each and every line of the content
49 // returns 0 on success
50 
51 
52         // Implementation in StrLst.Cpp
53 
54         // for EchoToss.Log or FileChng.Log
55         // Generates a file with a list of strings
56 
57         // Use Add for each string to be listed.
58         // Use Close when completed.
59         // The OutFile will be deleted if Append = FALSE
60         // and no Add done.
61 
62         // Nothing will be output if no default OutName and no OutNameCfg
63         // is found.
64 
65 class StrLst {
66     private:
67         char *OutNameCfg;
68         char *OutName;  // output file name
69         BOOL Append;
70         FILE *Outf;
71     public:
72         StrLst (char *OutNameCfg, BOOL Append = FALSE, char *OutName = NULL);
73             // OutNameCfg is the name of the config statement
74             //   that specifies the name of the output file.
75             // Append: TRUE if the output must be appended.
76             //   When Append == FALSE, a '+' sign as the first
77             //   character of the outfilename will set
78             //   Append = TRUE anyway.
79             // OutName specifies a default for OutName, in the case
80             //   no OutNameCfg is encountered.
81         ~StrLst (void);
82         void SetDefCfg (char *OutName);
83             // Sets default values, in the case cfg statements are not
84             // found. Can be issued any time before Add.
85             // Useless if already set in StrLst constructor.
86         BOOL ParseCfg (const char *clnline);
87             // Parses clnline in search for a cfg statement
88             // clnline must be a line with:
89             //  - comments removed
90             //  - no terminating spaces
91             //  - no terminating newline
92             //  - no tabs
93             // returns TRUE when cfg line recognized
94         int Add (const char *tag);
95             // Adds tag to the output list
96             // returns 0 on success
97         int Close (void);
98             // returns 0 on success
99 };
100 
101 
102             // Implementation in OutWrap.Cpp
103 
104 // To output with left/right justification: e.g. for descriptions
105 
106 // The cfg statement "<WrapCfg> [<indent> [<right>]]" allows to specify
107 // the indentation for 2nd and up lines and the maximum right column.
108 // When the statement is not found, wrap is disabled.
109 // <indent> defaults to 0, <right> to 79.
110 
111 // Newlines '\n' in source are recognized as line separators.
112 
113 typedef int (*OWShow) (const char *line, void *prm);
114 
115 // Is called for each line to output.
116 // line does not contain trailing newline.
117 // prm can be used to pass some parameter.
118 // Must return 0 on success.
119 
120 #define OWcfgFound     0        // for ParseCfg
121 #define OWcfgNotFound  1
122 #define OWcfgError    -1
123 #define OWcfgDupe     -2
124 
125 
126 class OutWrap {
127     private:
128         char *WrapCfg;      // name of the cfg statement for wrap specs
129         BOOL CfgDone;       // Cfg statement already found
130         int wrapcol,        // blank columns at left (-1 = no wrapping)
131             wrapend;        // tot # of columns
132         char *LineBuf;      // buffer for line to be output
133         int fwrap (const char *src, int begin, OWShow ows, void *prm);
134                              // return bytes written from b, EOF on error
135 
136     public:
137         OutWrap (const char *WrapCfg);
138         ~OutWrap ();
139         int ParseCfg (const char *clnline);
140             // Parses clnline in search for a cfg statement
141             // clnline must be a line with:
142             //  - comments removed
143             //  - no terminating spaces
144             //  - no terminating newline
145             //  - no tabs
146             // returns OWcfgFound on statement found
147             //         OWcfgNotFound on statement not found
148             //         OWcfgError on error in statement
149             //         OWcfgDupe on dupe statement
150         int Out (const char *source, OWShow ows, void *prm = NULL);
151             // source is the string to be output, no trailing newline
152             // ows is a pointer to a function of type OWShow.
153             // prm is pointer to optional parameters.
154             // Returns 0 on success.
155 };
156 
157                         // Implementation in SqTagPat.Cpp
158 
159 // Class to convert a Squish TAG to the path and type of area.
160 
161 struct _SqTagSearch {
162     const char *Tag;      // pointer to area TAG in cfg data (input)
163     char **Path;    // pointer to path pointer (must be allocated and assigned)
164     word *Type;     // pointer to area type in cfg data (to be assigned)
165     ADR  *adr;      // pointer to adr in cfg data or NULL
166     char **origin;  // pointer to origin pointer or NULL
167     dword *attr;    // pointer to attributes or NULL
168     _SqTagSearch *next;
169 };
170 
171 
172 typedef void (*CharPVoid) (const char *);  // to be invoked for each Tag
173                                      // that is not found !
174 
175 class SqTag2Path {
176     private:
177         _SqTagSearch *sqhead;
178         _SqTagSearch **sqtail;
179         ADR *primary;
180         int parsesq (char *linebuf, char *echotag, char *path, word *type,
181                          ADR *adr);
182     public:
183         SqTag2Path ();
184         ~SqTag2Path ();
185         void AddTag (const char *Tag, char **Path, word *Type, ADR *adr = NULL,
186                      char **origin = NULL, dword *attr = NULL);
187                 // Tag: input tag
188                 // Path: pointer to char * to be assigned;
189                 //       *Path must be NULL !!!!
190                 // Type: pointer to word to be assigned;
191                 //   specifies Squish/SDM and ECHO.
192                 // Path and Type will be assigned by ParseSquish.
193                 // *adr is filled with the primary address found in
194                 //   SquishCfg (including -p<adr> override)
195                 // *origin is set NULL for netmail areas
196                 // *attr is set to P for netmail areas;
197                 //   The setting of the Local flag is up to the application.
198         int ParseSquishCfg (char *SquishCfg, CharPVoid sqtnf = NULL);
199                 // Squish's "Include" Statement supported
200                 // 0 on SquishCfg successfully accessed.
201                 // -1 on SquishCfg not found
202                 // -2 on Error in SquishCfg (no Address)
203 };
204 
205 
206                         // Implementation in Misc.Cpp
207 
208                             // for flags, bitwise
209 #define MSC_SrcMov          0x01    // advance input char ptr
210 #define MSC_Allow_NoLevel   0x02    // Allow "/<keys>", w no <level>
211 
212 
213 #define MSC_AcsStrSize      39      // space for <level>/<keys>
214 
215 
216 int strto4Dadr (const char *&adrs, ADR *adr);
217 
218 // adrs is a pointer to a 4D address string that must not necessarily
219 //   be terminated just after the address specification;
220 //   spaces and tabs are allowed before the address; space, tab, newline,
221 //   @ are allowed after the address.
222 // adr is a pointer to a 4D address.
223 // Returns 0 on success address parsing
224 // Returns not zero on illegal or not full address (*adr unchanged, adrs not moved).
225 
226 
227 bool eq4Dadr (const ADR *adr1, const ADR *adr2);
228 
229 // returns true if *adr1==*adr2
230 
231 
232 int GetLevKey (const char *&src, word *level, dword *keys = NULL, byte flags = 0);
233 
234 // Gets a <level>[/<keys>] combination.
235 // src points to a string, with possible leading blanks.
236 // level will contain the found numerical level.
237 // keys, if !NULL, will contain the found keys (1..8,A..X),
238 // case is not significant, keys MUST be !NULL if /<keys> is present.
239 // Following space is skipped.
240 // Returns the number of characters parsed, space included and optionally
241 // advances src to first non-space character (MSC_SrcMov flag).
242 // If MSC_Allow_NoLevel, "/<keys>" is legal and level assumed USHRT_MAX.
243 // Returns -1 if no valid entry found (src not moved).
244 
245 void PrintLevKey (char *buffer, word level, dword keys);
246 
247 // Prints "<level>[/<keys>]" in buffer.
248 // Buffer must be MSC_AcsStrSize.
249 
250 
251 BOOL TagMatch (const char *Tag, const char *WildTag);
252 
253 // Compares Tag with the WildTag (which can contain OS/2 wildcards).
254 // Special tags beginning with '<' must get an exact match (no wildcards).
255 
256 
257 char Ibm2Ascii (char c);
258 
259 // Changes codes 0-255 to 0-127
260 
261 
262                 // Implementation in AreaDat.Cpp
263 
264         // class to handle Max 3.00 FAREA.DAT
265 
266 #define FAD_OVR_MAX   100     // max number of command overrides per area
267 #define FAD_HEAP_SIZE 0x4000  // max size of string  heap
268                               // In case of excess, NextArea returns NULL
269 
270                               // For NextArea
271 #define FAD_Normal    0x0000  // Get all entries, BegDiv/EndDiv included
272 #define FAD_AreasOnly 0x0001  // Skip BegDiv/EndDiv entries
273 
274 
275 // WARNING: the returned fahp and filesbbs ptr points to "STATIC" areas !
276 // When a new area is loaded, the previous fahp/filesbbs info is overwritten.
277 
278 
279 class FAREADAT {
280     private:
281         char *fareaname;
282         FILE *f;
283         FAH *fahp;
284         FAH *LoadArea ();
285         word arean;
286         char *filesbbsbuf, *filesbbsptr;
287     public:
288         FAREADAT ();
289         ~FAREADAT ();
290         int OpenFAreaDat (const char *FAreaDat);
291                                            // prepare to operate on FAreaDat
292                                            // return 0 on success
293                                            // -1: can't open, -2: short
294                                            // -3: ID mismatch
295                                            // FAreaDat: .DAT optional
296         FAH *NextArea (int act = FAD_Normal);
297                                     // return PFAH for next area, NULL if none
298         FAH *Area (word num);
299                 // return PFAH for area #num, NULL if none or division
300         FAH *Area (const char *name);
301                 // return PFAH for area tag "name", NULL if none or division
302         word AreaNum ();        // return current areanum
303         char *filesbbs ();      // return full name of filesbbs for current area
304 };
305 
306 
307                 // Implementation in MaxPrm.Cpp
308 
309 #include <prm.h>
310 
311 #define MaxPRM(p,s) (p->prmheap+(p->prm->s))
312 
313 class MAXPRM {
314     private:
315         byte *buffer;
316     public:
317         m_pointers *prm;
318         char *prmheap;
319         MAXPRM ();
320         ~MAXPRM ();
321         int Read (char *prmname);   // returns 0 on success
322                                     // prmname can have or not .PRM ext
323 };
324 
325 
326             // Implementation in MaxAcs.Cpp
327 
328 class MAXACS {
329     private:
330         byte *buffer;           // pointer to allocated array
331         char *heap;             // pointer to string heap
332         word usn;               // number of user classes
333         word ussize;            // size of each class record
334         byte *uscl1;            // pointer to first user class record
335 
336         int GetGenAcs (char *lks, word *level, dword *keys1, dword *keys0 = NULL);
337                                     // Gets level and keys1/keys0 from lks.
338                                     // keys0 are the negated keys.
339                                     // lks is <level>[/<keys>]
340                                     // If keys0 is NULL, error is returned
341                                     // in the case of negated '!' keys.
342                                     // If keys1 is NULL, keys are not checked.
343                                     // Returns 0 on success.
344         BOOL TokAcs (char *TokAcs, word level, dword keys);
345                                     // TokAcs is a single access string
346                                     // (no & | operators).
347                                     // returns TRUE if level/keys grants
348                                     // access to TokAcs
349         BOOL ProdAccess (char *pac, word level, dword keys);
350                                     // pac is a series of access strings
351                                     // separated by the '&' operator.
352                                     // No '|' operator permitted.
353         int GetLevel (char *slevel, word *level);
354                                     // looks for slevel in access.dat
355                                     // and stores the numeric value in level
356                                     // returns 0 on success
357     public:
358         MAXACS ();
359         ~MAXACS ();
360         int Read (char *acsname);   // returns 0 on success
361                                     // acsname can have or not .DAT ext
362         int GetAcs (char *ACS, word *level, dword *keys = NULL);
363                                     // Gets level and keys for a
364                                     // user access string.
365                                     // If keys is NULL, keys are not
366                                     // checked.
367                                     // returns 0 on success
368         char *LevName (word level); // returns pointer to class name
369                                     // or NULL if level is not equal
370                                     // to a defined class level.
371         char *LevStr (word level);  // returns pointer to class name
372                                     // or to static string with numeric
373                                     // level value.
374         BOOL HaveAccess (char *ACS, word level, dword keys);
375                                     // returns TRUE if level and keys
376                                     // give access to an object of ACS.
377                                     // "name=<s>" and "alias=<s>"
378                                     // do not give access.
379                                     // | and & permitted
380 };
381 
382 
383                     // Implementation in ComprCfg.Cpp
384 
385 
386 class AH_Archiver {
387   private:
388     int  identofs;      // offset of identity string; -2 = last char
389     int  identlen;      // length of identity string
390     byte *identstr;     // identity string (can contain 00)
391     char *addcmd;       // command to add files (with %a %f)
392     char *extcmd;       // command to extract files (with %a %f)
393     const class AH_Archiver *prev;  // pointer to previous Archiver definition
394   public:
395     char *name;         // name of archiver
396     char *ext;          // typical extension
397     AH_Archiver (const class AH_Archiver *aptr);  // constructor
398 
399     friend class AH_ComprCfg;
400 };
401 
402                                 // for AH_VShow
403 #define AH_MT_Action    0
404 #define AH_MT_Info      1
405 #define AH_MT_Warning   2
406 #define AH_MT_Error     3
407 
408 typedef void (*AH_VShow) (byte msgtype, char *strfmt, ...);
409 // function type to be used for output
410 
411 
412 class AH_ComprCfg {
413   private:
414     static AH_VShow outf;
415     static void RcShow (int code, ...); // for RunCmd
416 
417     AH_Archiver *lastarc;  // pointer to last Archiver definition
418     void ScanIdent (const char *tok);  // Scans Ident string
419     BOOL ArcGood (const AH_Archiver *a); // is a good for sfx detection ?
420     const AH_Archiver *SfxNext (const AH_Archiver *a); // finds next arc good for sfx
421     const AH_Archiver *ChkSfx (const char *filename);  // Checks if Sfx
422 
423   public:
424     AH_ComprCfg (const char *cfgfile,       // compress.cfg file
425                  AH_VShow outf = NULL);     // output function pointer
426                                             // is stored as static !
427     int UnArc (const char *filename,        // archive name
428                const char *extract);        // extract template
429                                 // returns errorlevel
430                                 // -1 on error
431                                 // -2 unknown archiver
432                                 // -3 file not found
433     int Arc (const AH_Archiver *a,          // archiver to be used
434              const char *filename,          // archive name
435              const char *add);              // template for add
436                                 // returns errorlevel or -1 on error
437     const AH_Archiver *AddDefined (const char *method); // is (compr) method defined in cfg ?
438     const AH_Archiver *ExtDefined (const char *ext); // is extension defined in compress.cfg ?
439 };
440 
441 
442             // Implementation in Fbbs.Cpp
443 
444 // The description is always null terminated and with no terminating '\n'.
445 // The '\n' character is used to separate multiple lines.
446 // It's possible that a '\n' is present at the end of the description if
447 // the description terminates with an empty line.
448 
449 // Comment line if:
450 // - empty
451 // - starting ctrl characters
452 // - starting space
453 // - starting '-' and then a space or tab
454 // - starting high ascii (>127)
455 
456 
457 typedef BOOL (*SkipFile) (const char *file, void *ptr);
458 
459 // Function type for function to be used by GetEntry/GetGenEntry to
460 // establish whether the file entry must be removed or not.
461 
462 
463             // FBBS.fbbsflags
464 
465 #define FBBS_FLAG_NODATESIZE    0x8000  // date and size NOT used
466 #define FBBS_FLAG_NOCONTSPACE   0x4000  // no space after cont. char
467 
468 #define FBBS_FLAG_DATEFORMAT    0x0003  // mask for date format
469 #define FBBS_FLAG_DATE_USA      0x0000
470 #define FBBS_FLAG_DATE_EURO     0x0001
471 #define FBBS_FLAG_DATE_JAPAN    0x0002
472 #define FBBS_FLAG_DATE_SCIENT   0x0003
473 
474 
475 // ATTENTION: when date&size is used,
476 // the functions that read the files.bbs use the first two tokens
477 // after the filename as date and size !!!
478 
479 // When FBBS_FLAG_NODATESIZE -> date = 0, size = ULONG_MAX.
480 
481 
482             // for GetEntry first
483 
484 #define FBBS_GE_FIRST   TRUE
485 #define FBBS_GE_NEXT    FALSE
486 
487             // for GetDesc action (bitwise)
488 
489 #define FBBS_REMOVE     0x01
490 
491             // flag, besides FB.H
492 
493 #define FF_SAFE         0x8000      // no Trojan check to be performed
494                                     // Input for PutGenEntry/SetDesc
495 
496 
497 class FBBS {
498     private:
499         char filesbbs[PATH_MAX];   // full name of file list
500         int filesize,               // size of buffer for returned file
501             descsize,               // size of buffer for returned description
502             linesize;               // size of files.bbs line buffer
503         char cont;                  // continuation char
504         int cpos;                   // column for cont. char, zero based, -1 for disable
505         word fbbsflags;             // flags
506 
507         SkipFile sf;                // Function pointer: if !NULL, Get(Gen)Entry
508                                     // removes entry if sf is TRUE.
509         void *ptr;                  // To be passed to ptr.
510 
511         FILE *t;                    // Stream used by GetGenEntry when sf.
512                                     // NULL when closed.
513         FILE *f;                    // stream for filesbbs, NULL when closed.
514         int fileh;                  // write handle for filesbbs, -1 when closed.
515 
516         char *line;                 // Pointer to line buffer.
517 
518         BOOL repeatln;              // True when line must be got by
519                                     // Fgetln again.
520         char *lastget;              // result of last Fgetln
521         char *Fgetln ();  // Loads line with next line of text (as fgets),
522                           // returns line or NULL if EOF.
523         int descopy (const char *p = NULL,    // points after filename
524                      char *desc = NULL, // where to copy description
525                      word *flag = NULL, // where to store flags
526                      time_t *date = NULL,  // optional date
527                      dword *size = NULL,   // optional size
528                      FILE *t = NULL     // where to copy the lines
529                      );
530                   // copies description (even multi-line) for file
531                   // present in current line.
532                   // returns 0 on success
533         int descAddLine (const char *p,       // pointer to begin of desc line
534                          char *desc,    // pointer to return desc buffer
535                          int desclen);  // current length of desc
536                       // Appends a new line, preceded by '\n'
537                       // Returns the new length of desc
538                       // Does not exceed descsize
539         void RdClose (); // close f.
540         int WrOpen ();  // prepare fileh for append. 0 on success.
541 
542 
543     public:
544         FBBS (const char *path, // path must terminate by '\' (files.bbs assumed)
545                           // or contain the full filelist name.
546               int filesize, // size of buffer for returned file
547               int descsize, // size of buffer for returned description
548                             // (maybe multi-line) or comment (1 line).
549               int linesize = 1024, // size of files.bbs line buffer
550               char cont = ' ', // continuation character
551               int cpos = 31,   // Column where to put the cont char., 0..78,
552                           // if cont == ' ' the range is 1..78
553                           // If cpos == -1, the multi-line description
554                           // handling is disabled.
555                           // While reading, cpos is not used if cont != ' ',
556                           // otherwise the continued description line MUST
557                           // start at pos (possibly with heading space).
558                           // While writing, if cont != ' ' the following is
559                           // written starting at cpos: cont, ' ', desc;
560                           // otherwise desc is written starting at cpos.
561                           // While writing with cpos == -1, only the
562                           // first line of a multi-line description
563                           // is output, following ones are ignored.
564               word fbbsflags = FBBS_FLAG_NODATESIZE, // default flags
565               SkipFile sf = NULL,   // optional function pointer to remove
566                                     // some entries from files.bbs with
567                                     // Get(Gen)Entry.
568               void *ptr = NULL      // To be passed to sf.
569                         );
570         ~FBBS ();
571         int GetDesc (const char *file,    // file to be searched for
572                      char *desc = NULL,  // destination buffer
573                      word *flag = NULL, // optional flags (/t /b)
574                      byte action = 0, //
575                      const char *repl = NULL, // Optional additional file(s)
576                                         // which description must be removed
577                                         // *repl == '\0' is acceptable.
578                                         // If equal to file, it's ignored.
579                                         // In the case of multiple file names,
580                                         // they are separated by space.
581                      time_t *date = NULL,  // optional date
582                      dword *size = NULL    // optional size
583                      );
584                      // the description is returned into desc,
585                      // it's always zero terminated
586                      // it can contain '\n' in case of multiple lines.
587                      // if FBBS_REMOVE, the description for file is
588                      // removed from the files.bbs
589                      // Return: -2 file list not found
590                      //         -1 on error
591                      //         0  All Ok
592                      //         1  file entry not found
593                      //         2  NO repl entry found
594                      //         3  both entries not found
595                      //
596                      // If file not found:
597                      // *flag = 0, *date = 0, *size = ULONG_MAX
598 
599         int SetDesc (const char *file,          // file to be appended to files.bbs
600                      const char *desc,          // description, null terminated
601                      word flag = 0,       // optional flags (/t /b)
602                      const char *befdesc = NULL,// optional header
603                      time_t date = 0,  // optional date for FA_LISTDATE
604                      dword size = 0    // optional size for FA_LISTDATE
605                      );     // the desc is appended, no check for already
606                             // existent entry (you must use GetDesc).
607                             // desc can be multi-line ('\n' as separator).
608                             // The continuation character and position
609                             // specified in the constructor are used.
610                             // The appended line does not exceed linesize.
611                             // If file is empty or NULL, desc is output
612                             // as a comment line.
613                             // Returns 0 on success
614             // Trojan (control) characters are substituted with space
615             // (in the original desc buffer)
616 
617         int PutGenEntry (const char *file,
618                          const char *desc,
619                          word flag = 0,
620                          const char *befdesc = NULL,
621                          time_t date = 0,
622                          dword size = 0);
623                          // as SetDesc, but file is not closed.
624                          // Suitable for multiple appends.
625 
626         int WrClose (); // close fileh. 0 on success.
627                         // Not really necessary, but useful to check
628                         // for write errors after PutGenEntry.
629 
630         int RdOpen ();  // prepare f for reading from begin. 0 on success.
631                         // Usually not necessary, but useful to restart
632                         // f from begin when you want to use Get(Gen)Entry
633                         // with no FBBS_GE_FIRST and f is already open.
634 
635         int GetEntry (char *file,           // file name returned
636                       char *desc,           // description returned
637                       word *flag = NULL,    // optional flags returned
638                       BOOL first = FBBS_GE_NEXT,   // get first/next
639                             // next is valid also after GetDesc with
640                             // repl==NULL and no REMOVE action
641                       time_t *date = NULL,  // optional date for FA_LISTDATE
642                       dword *size = NULL    // optional size for FA_LISTDATE
643                       );        // returns
644                                 //        -1 error
645                                 //         0 while entry is available
646                                 //         1 no more entries
647                                 //         3 on entry removed
648 
649                       // If file not found:
650                       // *flag = 0, *date = 0, *size = ULONG_MAX
651 
652                       // If sf is passed to FBBS, GetEntry must be invoked
653                       // until no more entries are available, otherwise
654                       // the files.bbs remains unchanged.
655                       // If GetEntry restarts from first, the status
656                       // is reset.
657                       // If first = FBBS_GE_NEXT and f is not open,
658                       // then a FBBS_GE_FIRST is assumed.
659 
660         int GetGenEntry (char *file,   // file name returned, empty if comment
661                       char *desc,      // description or comment line returned
662                       word *flag = NULL,    // optional flags returned
663                       BOOL first = FBBS_GE_NEXT,   // get first/next
664                             // next is valid also after GetDesc with
665                             // repl==NULL and no REMOVE action
666                       time_t *date = NULL,  // optional date for FA_LISTDATE
667                       dword *size = NULL    // optional size for FA_LISTDATE
668                       );        // returns
669                                 //        -1 error
670                                 //         0 on file entry
671                                 //         1 no more entries
672                                 //         2 on comment line
673                                 //         3 on entry removed
674                     // same as GetEntry but also returns comment lines:
675                     // 2 as return value, empty file and comment in desc.
676 
677         int Trunc ();   // Truncates f, 0 on success.
678 };
679 
680 
681 word Max2FbbsDateStyle (    // converts date_style to FBBS_FLAG*
682     sword date_style       // as in max.prm
683     );
684 
685 
686                 // Implementation in SqNetScn.Cpp
687 
688 // Class to handle scan of a a netmail area via Squish MSGAPI.
689 // In the case of Squish base, if sav is given, a pointer to the last
690 // scanned message is saved in "area.<sav>" and used to scan new
691 // messages only.
692 // The area is Locked.
693 
694 // It is assumed that the MsgApi are Opened and Closed externally.
695 
696 #define SQNS_Get_SkipRead   0x01        // Skip msgs marked as read
697 
698 
699 class SqNetScan {
700 
701     private:
702         char savfilename[PATH_MAX];    // name of the file for
703                                         // stored data (last msg ptr).
704                                         // Empty when none applicable
705                                         // (SDM or sav not given).
706         word areatype;                  // MSGTYPE_SDM or MSGTYPE_SQUISH
707         word areazone;                  // Primary (default) zone.
708         HAREA harea;                    // Handle of area, NULL when none.
709         UMSGID hwmID;                   // ID of last scanned message.
710         UMSGID highID;                  // ID of last message to be scanned.
711         HMSG hmsg;                      // current msg handle (NULL when none).
712 
713     public:
714 
715         SqNetScan ();               // Constructor.
716 
717         HAREA Open (const char *path, // path of netmail area.
718                                     // Backslash terminated when SDM.
719                   word type,        // MSGTYPE_SDM or MSGTYPE_SQUISH.
720                   word defzone = 0, // Zone to be assumed.
721                   const char *sav = NULL);  // Extension (no .) for the
722                                     // file where the pointer to the last
723                                     // scanned message is stored.
724                                     // Return the area Handle,
725                                     // NULL on error.
726 
727         UMSGID GetNextMsg (XMSG *xmsg,  // Get UMSGID of next available
728                            byte flags = 0); // message.
729                                         // Load the header into xmsg.
730                                         // Optional flags.
731                                         // Return 0 when no more.
732 
733         void LoadMsgBody (char *body,   // Load message body into body,
734                           size_t size); // maximum size bytes, including
735                                         // terminating NULL, which is
736                                         // guaranteed.
737 
738         int MarkMsgRead ();             // Mark current msg as Read and
739                                         // leave it closed (no LoadMsgBody
740                                         // possible).
741                                         // Return 0 on success.
742 
743         int KillMsg ();                 // Kill current msg.
744                                         // Return 0 on success.
745 
746         int Close ();                   // Close the area, save the last
747                                         // pointer if necessary.
748                                         // Return 0 on success,
749                                         // 1 on "sav" save error,
750                                         // -1 on Api close error.
751 
752         ~SqNetScan ();                  // Destructor.
753 };
754 
755 
756 
757 #endif
758