1 /*****************************************************************************/
2 /*                                                                           */
3 /*                 (C) Copyright 1995-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 _FBlib_HPP_
18 #define _FBlib_HPP_
19 
20 #include <stdlib.h>
21 #include <smapi/msgapi.h>
22 #include <apgenlib.hpp>
23 
24 //#pragma pack (1)
25 
26 #define FBBSLSIZE 1024      // size of files.bbs line buffer
27 
28 class namelist;
29 class FBD;
30 class ANumLst;
31 struct AreaData;
32 struct FIDX;
33 struct _area;
34 
35 typedef void (*DupeF) (FIDX *p, BOOL included);
36 typedef void (*ShowF) (char *AreaName, char *AreaPath, int Code);
37 
38                             // FileBase function, flags parameter
39 
40 #define _UniqueDmpLine_     0x0001  // Change '\n' to ' ' in .DMP
41 
42 
43                             // for ShowF, BuildArea, OpenArea
44 #define _Error_            -3
45 #define _BbsPathNotFound_  -2       // for files.*
46 #define _FilePathNotFound_ -1       // for area files
47 #define _OK_                0
48 #define _BegProc_           1    // Processing begun (normally)
49 #define _ReadOnly_          2
50 #define _WriteProtected_    3
51 #define _NoFilesBbs_        4
52 
53                 // for Build action
54 
55 #define _FBUpdate_       0x0001     // update main index, otherwise rebuild
56 #define _FBNoLocBase_    0x0002     // don't write local dat/dmp/idx
57 #define _FBMarkedOnly_   0x0004     // Build marked areas only, even with Rebuild
58 #define _FBAutoDate_     0x0008     // Date and Size must be read from dir (by default)
59 #define _FBNewAsMarked_  0x0010     // Consider areas with FILESBBS newer
60                                     // than FILESIDX as marked. RO/CDROM skipped.
61 #define _FBSkipSlow_     0x0020     // Skip areas of type Slow (CD etc.) and
62                                     // build all others !
63 
64                 // for flag in AreaAddEntry
65 
66 
67 #define FF_FILE     0x01 /* Entry is a filename */
68 #define FF_NOTIME   0x10 /* Don't deduct file from user's time limit */
69 #define FF_NOBYTES  0x20 /* Don't deduce file from user's DL bytes limit */
70 
71 
72 struct FAH;
73 
74 
75 class FileBase {
76     private:
77         namelist *AreaNameList;
78         namelist *AreaPathList;
79         FBD *fbd;
80         AreaData *ad;
81 
82         char cont;          // continuation character
83         int cpos;           // spaces before cont char
84         word flags;         // special flags
85 
86         BOOL AreaNameMatch (const char *areaname);
87         BOOL AreaPathMatch (const char *areapath);
88         int DmpWrite (const char *text, dword *ofs);
89             // Writes text to files.dmp, stores offset into ofs.
90             // returns 0 on success
91         int BuildArea (word areanum, const char *filepath, const char *filesbbs,
92                        const char *acs, word fattr, sword date_style,
93                        BOOL NoLocBase = FALSE);
94             // Builds files.dat .dmp .idx, stores data for maxfiles.idx
95             // NoLocBase can be passed along to AreaOpen
96             // returns _OK_, _BbsPathNotFound_, _FilePathNotFound_,
97             //         _ReadOnly_, _WriteProtected_, _Error_
98         BOOL IsBuild (const FAH *fahp, word action);
99             // return TRUE if area must be built.
100 
101     public:
102         FileBase (char cont = ' ',  // cont. character
103                   int cpos = 31,    // cont. column, -1 to disable
104                   word flags = 0    // Special flags.
105                   );
106         ~FileBase (void);
107         int AreaOpen (word areanum, const char *filesbbs,
108                       BOOL NoLocBase = FALSE);
109                     // areanum: number of area in area.dat
110                     // filesbbs: "<path>\<name>" (can have an extension)
111                     // NoLocBase: Do Not Build local DAT/DMP/IDX
112                     // Opens files.dat and files.dmp and prepares for addentry
113                     // returns _OK_, _BbsPathNotFound_, _ReadOnly_,
114                     //         _WriteProtected_, _Error_
115         int AreaAddEntry (const char *filename, word flag,
116                           const _stamp *cre_date, const _stamp *mod_date,
117                           dword size, const char *desc, const char *acs,
118                           const char *path = NULL);
119                     // Appends files.dat and files.dmp
120                     // Stores file data for later index build
121                     // cre_date is the date of creation (upload)
122                     // mod_date is the date of last write (dir)
123                     // path optionally indicates an override path
124                     // Returns 0 on success
125         int AreaClose (void);
126                     // Closes files.dat and files.dmp
127                     // Builds the current area index from stored data
128                     // Returns 0 on success
129         void AddName (const char *areaname, const char *AreaDat = NULL);
130                      // area tag to be rebuilt
131                     // AreaDat != NULL -> add the upload path of areaname
132         void AddPath (const char *areapath);  // area path to be rebuilt
133         int Build (const char *AreaDat, word action, const char *FullIdx,
134                    const char *NoDupeIdx = NULL, ShowF sf = NULL,
135                    DupeF df = NULL);
136           // NoDupeIdx is the full pathname for the file-request, no dupes,
137           // Index file. In case of dupes, it contains the file in the
138           // lowest area number.
139           // df is a function called for each Dupe found while building NoDupeIdx
140           // sf is a function called for each area processed
141           // AreaDat && update  -> Build marked areas, update main index
142           // AreaDat && !update -> Build all areas, rebuild main index
143           // AreaDat,!update,MarkedOnly -> Build marked areas, rebuild index
144           // Stored data is always used in addition to the built areas.
145           // !AreaDat -> use stored data only, rebuild/update main index
146           // returns 0 on success
147 };
148 
149 
150 
151 
152 #endif
153