forked from gigablast/open-source-search-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectiondb.h
100 lines (72 loc) · 3.04 KB
/
Collectiondb.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
// Matt Wells, copyright Feb 2001
// maintains a simple array of CollectionRecs
#ifndef _COLLECTIONDB_H_
#define _COLLECTIONDB_H_
// . max # of collections we're serving
// . may have to update if business gets going (or make dynamic)
// . lowered to 16 to save some mem
#define MAX_COLL_RECS 16 // 256
#define MAX_COLLS (MAX_COLL_RECS)
class Collectiondb {
public:
Collectiondb();
// does nothing
void reset() ;
// . this loads all the recs from host #0
// . returns false and sets errno on error
// . each collection as a CollectionRec class for it and
// is loaded up from the appropriate config file
bool init ( bool isDump = false );
// this loads all the recs from host #0
bool load ( bool isDump = false );
// . this will save all conf files back to disk that need it
// . returns false and sets g_errno on error, true on success
bool save ( );
bool m_needsSave;
// returns i so that m_recs[i].m_coll = coll
collnum_t getCollnum ( char *coll , long collLen );
collnum_t getCollnum ( char *coll ); // coll is NULL terminated here
char *getCollName ( collnum_t collnum );
char *getColl ( collnum_t collnum ) {return getCollName(collnum);};
// get coll rec specified in the HTTP request
class CollectionRec *getRec ( class HttpRequest *r );
// . get collectionRec from name
// returns NULL if not available
class CollectionRec *getRec ( char *coll );
class CollectionRec *getRec ( char *coll , long collLen );
class CollectionRec *getRec ( collnum_t collnum);
//class CollectionRec *getDefaultRec ( ) ;
class CollectionRec *getFirstRec ( ) ;
char *getFirstCollName ( ) ;
collnum_t getFirstCollnum ( ) ;
// . how many collections we have in here
// . only counts valid existing collections
long getNumRecs() { return m_numRecsUsed; };
// . does this requester have root admin privledges???
// . uses the root collection record!
bool isAdmin ( class HttpRequest *r , class TcpSocket *s );
collnum_t getNextCollnum ( collnum_t collnum );
long long getLastUpdateTime () { return m_lastUpdateTime; };
// updates m_lastUpdateTime so g_spiderCache know when to reload
void updateTime ();
// private:
// . these are called by handleRequest
// . based on "action" cgi var, 1-->add,2-->delete,3-->update
bool addRec ( char *coll , char *cc , long cclen , bool isNew ,
collnum_t collnum , bool isDump , // = false );
bool saveRec ); // = true
bool deleteRec ( char *coll , bool deleteTurkdb = true );
//bool updateRec ( CollectionRec *newrec );
bool deleteRecs ( class HttpRequest *r ) ;
bool resetColl ( char *coll , bool resetTurkdb = true ) ;
// . keep up to 128 of them, these reference into m_list
// . COllectionRec now includes m_needsSave and m_lastUpdateTime
class CollectionRec *m_recs [ MAX_COLLS ];
//bool m_needsSave [ MAX_COLLS ];
//long long m_lastUpdateTime [ MAX_COLLS ];
long m_numRecs;
long m_numRecsUsed;
long long m_lastUpdateTime;
};
extern class Collectiondb g_collectiondb;
#endif