File: ClientDB.h

package info (click to toggle)
postman 2.0-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,036 kB
  • ctags: 3,078
  • sloc: cpp: 31,131; ansic: 1,948; sh: 787; makefile: 285
file content (164 lines) | stat: -rw-r--r-- 5,672 bytes parent folder | download
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
/*
ClientDB.h
*/

#ifndef __CLIENTDB_H
#define __CLIENTDB_H

#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <signal.h>
#include <sys/types.h>
#include <db1/db.h>           

#undef USE_REGEX
#define USE_REGEX

#ifdef USE_REGEX
#include<regex.h>
#endif

#include "Language.h"
#include "Utils.h"
#include "Config.h"
#include "XSocket.h"
#include "XVector.h"

#define NUM_RECS_METADATA 7
#define DB_VERSION     "____VERSION____"
#define DB_NAME        "____NAME____"
#define DB_STRUCTURE   "____STRUCTURE____"
#define DB_PERMISSIONS "____PERMISSIONS____"
#define DB_LASTINT     "____LASTINT____"
#define DB_RECCOUNT    "____RECCOUNT____"
#define DB_MAXSIZE     "____MAXSIZE____"

#define CMAXFLAGS 10
typedef char TFlags [CMAXFLAGS + 1];
#define DB_FLAGRECORD_NAME    "__FLAGS__"
#define DB_FLAGRECORD_DEFAULT "----------"

#define DB_EXTENSION       "db"
#define DB_INDEX_EXTENSION "index"

enum TType { fRESERVED, fTEXT, fVARCHAR, fDATETIME, fURL, fINT, fREAL };
#define CMAXFIELDS 30
#define CMAXFIELDNAME 100
typedef char TFieldName [CMAXFIELDNAME + 1];
class TDBField
  {
  public:
    TFieldName fname, flabel, fdefault, fopt1, fopt2, fopt3, fopt4; 
    TType ftype;
    int fsequence, fmaxlength, fdisplaylength, findexlength;
    bool fcouldbenull;
  };
typedef XVector<TDBField> TMatField;

typedef struct 
  {
  int key;
  TBuffer uniqid, value;
  } TDBNodo, *PDBNodo;    
typedef XVector<TDBNodo> TDBNodoList;

typedef struct 
  {
  TBuffer dbname, dbstruct, dbpermissions, dbversion;
  int dblastint, dbreccount, dbmaxsize;
  TMatField *MatField;
  } TDBInfo;

#define CMAXUNIQID 20
typedef char TUniqId [CMAXUNIQID + 1];

enum TModeDB { fMODE_FULL, fMODE_SEARCH };

class ClientDB
  {
  private:
    DB *db, *dbindex;
    TDBNodoList dbnodolist; 
    TBuffer dbdir, dbfname, dbindexfname, ErrorMsg;
    int DefCreateMode, DefOpenMode; 
    enum DBTYPE DBType;
    enum TModeDB ModeDB;
    StringList SLSearch;
    TDBInfo dbinfo;
    bool obtainDBInfo (void);
    void displayDBStructure (void); 
    bool parseDBStructure (void);    
    bool parseDBPermissions (void);
    bool isRecordReserved (TUniqId uniqid);
    bool generaUniqID (TUniqId uniqid);
    bool isFieldName (TFieldName fieldname);
    bool isMainField (TFieldName fieldname);
    int getTotalNumRecords (void);
    bool incRecordCount (TUniqId uniqid);    
    bool delRecordCount (void);
    int deleteIDsFromIndex (StringList *SLIDItems);
    bool compactIndex (void);
    bool openIndex (void);
    bool closeIndex (void);
    bool putField_Text_ByID (TUniqId uniqid, TFieldName fieldname, char *data, int len);
    bool checkValidRecord (const char *envfile);
  public:
    ClientDB (const char *adbfname, const char *adbdir, bool ReadOnly);
    virtual ~ClientDB ();
    bool DBopen (void);
    bool DBclose (void);
    bool Sync (void);
    void displayDBInfo (XSocket *aXS);
    void displayDBStructure (XSocket *aXS);
    void displayDBPermissions (XSocket *aXS);
    const char *getErrorMsg (void);
    int getNumFields (void);    
    int getNumRecords (void);
    const char *getDBName (void);
    int getDBSize (void);
    int getFoundRecords (void);    
    bool isDBSearched (void);
    char *getUniqIDFromIndexPos (int pos, TUniqId uniqid);
    char *getField_Text_ByID (TUniqId uniqid, TFieldName fieldname, char *data, int *len);
    char *displayField_Text_ByID (TUniqId uniqid, TFieldName fieldname, TType fieldtype, char *data, int *len);
    int copyRecordsByID (StringList *SLUniqIDItems);
    int deleteRecordsByID (StringList *SLUniqIDItems);
    int markRecordsByID (StringList *SLUniqIDItems, int queflag, bool value);    
    int Expunge (void);
    bool pasteItems (StringList *SLPapeleraCopy, StringList *SLPapeleraCut);
    TType getTypeFromString (const char *stringtype);    
    const char *getStringFromType (TType atype);
    const TMatField *ClientDB::getMatField (void);    
    char *getDefaultValueField (TType atype, TBuffer adefault);    
    void getAllFieldNames (StringList *SLFieldNames);
    void getAllFieldLabels (StringList *SLFieldLabels);
    bool generaHTMLFormEditNewRecord (StringList *SLHTML);
    bool generaHTMLFormEditRecordByID (TUniqId uniqid, StringList *SLHTML);
    bool generaHTMLFormDisplayRecordByID (TUniqId uniqid, StringList *SLHTML);
    bool SaveRecordFromCGI (const char *envfile, char *recordid);
    bool generaHTMLIndexPage (const char *SortUrl, StringList *SLHTML);
    bool Sort (TFieldName fieldname);
    bool getFlagsById (TUniqId uniqid, TFlags flags);
    bool putFlagsById (TUniqId uniqid, TFlags flags);
    bool changeFlagById (TUniqId uniqid, int queflag, bool value);
    bool isFlagById (TUniqId uniqid, int queflag);
    bool Search (TFieldName fieldname, const char *whatsearch, StringList *SLRes);
    void deleteSearch (void);
    };

bool Match (const char *pc, const char *whatsearch);
void ProcessPattern (const char *whatsearch, TBuffer pattern);
bool getDBNameNoClass (const char *dbfilename, TBuffer dbname);
int getTotalDatabases (const char *dbdir, StringList *SLFilenames, StringList *SLNames);
bool creaDatabase (const char *user, const char *dbtemplate, const char *dbuserpath, const char *name, TBuffer sterror);
bool renameDatabase (const char *dbuserpath, const char *dbfn, const char *newname, TBuffer sterror);
bool deleteDatabase (const char *dbuserpath, const char *dbfn, TBuffer sterror);
bool dumpDatabase (const char *dbuserpath, const char *dbfn, TBuffer sterror, XSocket *aXS);
int getTotalFields (StringList *SLFields);
bool generaIndexFromDB (const char *dbfname, const char *dbindexfname, TBuffer strerr);

#endif