Files
privacore-open-source-searc…/Parms.h

306 lines
9.2 KiB
C
Raw Normal View History

2013-08-02 13:12:24 -07:00
// Matt Wells, copyright Feb 2002
// Ideally, CollectionRec.h and SearchInput.h should be automatically generated
// from Parms.cpp. But Parms need to be marked if they contribute to
2013-08-02 13:12:24 -07:00
// SearchInput::makeKey() for caching the SERPS.
2016-03-08 22:14:30 +01:00
#ifndef GB_PARMS_H
#define GB_PARMS_H
2013-08-02 13:12:24 -07:00
class CollectionRec;
class UdpSlot;
2014-11-10 14:45:11 -08:00
void handleRequest3e ( UdpSlot *slot , int32_t niceness ) ;
void handleRequest3f ( UdpSlot *slot , int32_t niceness ) ;
2013-08-02 13:12:24 -07:00
enum {
OBJ_CONF = 1 ,
OBJ_COLL ,
2014-02-09 22:25:08 -07:00
OBJ_SI , // SearchInput class
OBJ_GBREQUEST , // for GigablastRequest class of parms
2015-05-03 17:51:47 -07:00
OBJ_IR , // InjectionRequest class from PageInject.h
2014-02-09 22:25:08 -07:00
OBJ_NONE
};
2013-08-02 13:12:24 -07:00
enum {
TYPE_BOOL = 1 ,
TYPE_BOOL2 ,
TYPE_CHECKBOX ,
TYPE_CHAR ,
TYPE_CHAR2 , //needed to display char as a number (maxNumHops)
TYPE_CMD ,
TYPE_FLOAT ,
TYPE_IP ,
TYPE_LONG ,
TYPE_LONG_LONG , // 10
2013-08-02 13:12:24 -07:00
TYPE_NONE ,
TYPE_PRIORITY ,
TYPE_PRIORITY2 ,
TYPE_PRIORITY_BOXES ,
TYPE_RETRIES ,
TYPE_STRING ,
TYPE_STRINGBOX ,
TYPE_STRINGNONEMPTY ,
TYPE_TIME ,
TYPE_DATE2 , // 20
2013-08-02 13:12:24 -07:00
TYPE_DATE ,
TYPE_RULESET ,
TYPE_FILTER ,
TYPE_COMMENT ,
2016-03-08 23:21:39 +01:00
TYPE_CONSTANT ,
2013-08-02 13:12:24 -07:00
TYPE_MONOD2 ,
TYPE_MONOM2 ,
TYPE_LONG_CONST ,
TYPE_SITERULE , // 29
2014-02-09 22:25:08 -07:00
TYPE_SAFEBUF ,
2014-04-09 19:51:36 -07:00
TYPE_UFP ,
2014-05-06 10:47:57 -07:00
TYPE_FILEUPLOADBUTTON,
2014-06-11 17:24:33 -07:00
TYPE_DOUBLE,
TYPE_CHARPTR
};
2013-08-02 13:12:24 -07:00
// bit flags for Parm::m_flags
#define PF_COOKIE 0x00000001 // store in cookie?
#define PF_REDBOX 0x00000002 // redbox constraint on search results
//#define PF_UNUSED 0x00000004
#define PF_WIDGET_PARM 0x00000008
#define PF_API 0x00000010
#define PF_REBUILDURLFILTERS 0x00000020
#define PF_NOSYNC 0x00000040
#define PF_DIFFBOT 0x00000080
#define PF_HIDDEN 0x00000100
#define PF_NOSAVE 0x00000200
#define PF_DUP 0x00000400
#define PF_TEXTAREA 0x00000800
#define PF_COLLDEFAULT 0x00001000
#define PF_NOAPI 0x00002000
#define PF_REQUIRED 0x00004000
#define PF_REBUILDPROXYTABLE 0x00008000
#define PF_NOHTML 0x00010000
#define PF_CLONE 0x00020000
#define PF_PRIVATE 0x00040000 // for password to not show in api
#define PF_SMALLTEXTAREA 0x00080000
#define PF_REBUILDACTIVELIST 0x00100000
#define PF_REBUILDRANKINGSETTINGS 0x00200000 // ranking setting. Reinitialize any derived values
2013-08-02 13:12:24 -07:00
class Parm {
public:
const char *m_title; // displayed above m_desc on admin gui page
const char *m_desc; // description of variable displayed on admin gui page
const char *m_cgi; // cgi name, contains %i if an array
2016-03-02 13:50:11 +01:00
2016-04-17 23:25:19 +02:00
const char *m_xml; // default to rendition of m_title if NULL
2014-11-10 14:45:11 -08:00
int32_t m_off; // this variable's offset into the CollectionRec class
int32_t m_arrayCountOffset; // Arrays element count offset into the CollectionRec class
2014-04-09 19:51:36 -07:00
char m_colspan;
2013-08-02 13:12:24 -07:00
char m_type; // TYPE_BOOL, TYPE_LONG, ...
2014-11-10 14:45:11 -08:00
int32_t m_page; // PAGE_MASTER, PAGE_SPIDER, ... see Pages.h
2013-08-02 13:12:24 -07:00
char m_obj; // OBJ_CONF or OBJ_COLL
// the maximum number of elements supported in the array.
// this is 1 if NOT an array (i.e. array of only one parm).
// in such cases a "count" is NOT stored before the parm in
// CollectionRec.h or Conf.h.
2016-05-19 18:37:26 +02:00
bool isArray() { return (m_max>1); }
2014-11-10 14:45:11 -08:00
int32_t m_max; // max elements in the array
// if array is fixed size, how many elements in it?
// this is 0 if not a FIXED size array.
int32_t m_fixed;
2014-11-10 14:45:11 -08:00
int32_t m_size; // max string size
const char *m_def; // default value of this variable if not in either conf
2014-11-10 14:45:11 -08:00
int32_t m_defOff; // if default value points to a collectionrec parm!
2013-08-02 13:12:24 -07:00
char m_cast; // true if we should broadcast to all hosts (default)
2016-03-09 15:08:11 +01:00
const char *m_units;
2013-08-02 13:12:24 -07:00
char m_addin; // add "insert above" link to gui when displaying array
char m_rowid; // id of row controls are in, if any
char m_rdonly;// if in read-only mode, blank out this control?
char m_hdrs; // print headers for row or print title/desc for single?
2014-11-10 14:45:11 -08:00
int32_t m_flags;
int32_t m_parmNum; // slot # in the m_parms[] array that we are
bool (*m_func)(char *parmRec);
// some functions can block, like when deleting a coll because
// the tree might be saving, so they take a "we" ptr
bool (*m_func2)(char *parmRec,class WaitEntry *we);
2014-11-10 14:45:11 -08:00
int32_t m_plen; // offset of length for TYPE_STRINGS (m_htmlHeadLen...)
bool m_group; // start of a new group of controls?
2013-08-02 13:12:24 -07:00
char m_save; // save to xml file? almost always true
2014-11-10 14:45:11 -08:00
int32_t m_min;
2013-08-02 13:12:24 -07:00
// these are used for search parms in PageResults.cpp
2014-11-10 14:45:11 -08:00
int32_t m_sminc ;// offset of min in CollectionRec (-1 for none)
int32_t m_smaxc ;// offset of max in CollectionRec (-1 for none)
int32_t m_smin; // absolute min
int32_t m_smax; // absolute max
2013-08-02 13:12:24 -07:00
char m_sprpg; // propagate the cgi variable to other pages via GET?
char m_sprpp; // propagate the cgi variable to other pages via POST?
bool m_sync; // this parm should be synced
2014-11-10 14:45:11 -08:00
int32_t m_hash; // hash of "title"
int32_t m_cgiHash; // hash of m_cgi
2013-08-02 13:12:24 -07:00
2014-11-10 14:45:11 -08:00
int32_t getNumInArray ( collnum_t collnum ) ;
2013-12-26 11:20:19 -08:00
2014-11-10 14:45:11 -08:00
bool printVal ( class SafeBuf *sb , collnum_t collnum , int32_t occNum ) ;
2013-08-02 13:12:24 -07:00
};
#define MAX_PARMS 940
2013-08-02 13:12:24 -07:00
#define MAX_XML_CONF (200*1024)
#include "Xml.h"
#include "SafeBuf.h"
class Parms {
public:
Parms();
void init();
2014-02-10 21:45:03 -07:00
bool sendPageGeneric ( class TcpSocket *s, class HttpRequest *r );
2013-08-02 13:12:24 -07:00
2014-02-10 21:45:03 -07:00
bool printParmTable ( SafeBuf *sb , TcpSocket *s , HttpRequest *r );
2013-08-02 13:12:24 -07:00
bool printParms (SafeBuf* sb, TcpSocket *s , HttpRequest *r );
bool printParms2 (SafeBuf* sb,
2014-11-10 14:45:11 -08:00
int32_t page,
2014-02-10 21:45:03 -07:00
CollectionRec *cr,
int32_t nc ,
2014-11-10 14:45:11 -08:00
int32_t pd ,
2014-02-09 22:25:08 -07:00
bool isCrawlbot ,
char format, //bool isJSON,
TcpSocket *sock,
bool isMasterAdmin,
2014-09-29 18:28:36 -07:00
bool isCollAdmin
2014-02-09 22:25:08 -07:00
);
2013-08-02 13:12:24 -07:00
bool printParm ( SafeBuf* sb,
2016-05-22 21:38:00 +02:00
const char *username,
Parm *m ,
2014-11-10 14:45:11 -08:00
int32_t mm , // m = &m_parms[mm]
int32_t j ,
int32_t jend ,
2013-08-02 13:12:24 -07:00
char *THIS ,
2016-05-22 21:38:00 +02:00
const char *coll ,
const char *pwd ,
const char *bg ,
2014-11-10 14:45:11 -08:00
int32_t nc ,
int32_t pd ,
bool lastRow ,
bool isCrawlbot ,//= false,
char format , //= FORMAT_HTML,
bool isMasterAdmin ,
2014-09-30 16:22:18 -07:00
bool isCollAdmin ,
class TcpSocket *sock );
2013-08-02 13:12:24 -07:00
2014-11-10 14:45:11 -08:00
class Parm *getParmFromParmHash ( int32_t parmHash );
2013-08-02 13:12:24 -07:00
2014-11-10 14:45:11 -08:00
bool setFromRequest ( HttpRequest *r , //int32_t user,
2013-08-02 13:12:24 -07:00
TcpSocket* s,
class CollectionRec *newcr ,
char *THIS ,
2014-11-10 14:45:11 -08:00
int32_t objType );
2014-11-10 14:45:11 -08:00
bool insertParm ( int32_t i , int32_t an , char *THIS ) ;
bool removeParm ( int32_t i , int32_t an , char *THIS ) ;
2013-08-02 13:12:24 -07:00
void setParm ( char *THIS, Parm *m, int32_t mm, int32_t j, const char *def,
2013-08-02 13:12:24 -07:00
bool isHtmlEncoded , bool fromRequest ) ;
void setToDefault ( char *THIS , char objType ,
2014-06-18 05:04:45 -07:00
CollectionRec *argcr );//= NULL ) ;
2013-08-02 13:12:24 -07:00
bool setFromFile ( void *THIS ,
char *filename ,
char *filenameDef ,
char objType ) ;
2013-08-02 13:12:24 -07:00
2014-10-01 19:55:24 -07:00
bool setXmlFromFile(Xml *xml, char *filename, class SafeBuf *sb );
2013-08-02 13:12:24 -07:00
bool saveToXml ( char *THIS , char *f , char objType ) ;
2013-08-02 13:12:24 -07:00
bool getParmHtmlEncoded ( SafeBuf *sb , Parm *m , char *s );
2013-08-02 13:12:24 -07:00
2014-06-11 17:24:33 -07:00
bool setGigablastRequest ( class TcpSocket *s ,
class HttpRequest *hr ,
class GigablastRequest *gr );
2013-09-17 12:21:09 -07:00
// . make it so a collectionrec can be copied in Collectiondb.cpp
// . so the rec can be copied and the old one deleted without
// freeing the safebufs now used by the new one.
void detachSafeBufs ( class CollectionRec *cr ) ;
2013-08-02 13:12:24 -07:00
void overlapTest ( char step ) ;
//
// new functions
//
bool addNewParmToList1 ( SafeBuf *parmList ,
collnum_t collnum ,
2016-05-22 21:38:00 +02:00
const char *parmValString ,
2014-11-10 14:45:11 -08:00
int32_t occNum ,
2016-05-22 21:38:00 +02:00
const char *parmName ) ;
bool addNewParmToList2 ( SafeBuf *parmList ,
collnum_t collnum ,
2016-05-22 21:38:00 +02:00
const char *parmValString ,
2014-11-10 14:45:11 -08:00
int32_t occNum ,
Parm *m ) ;
2016-02-17 14:05:19 +01:00
bool addCurrentParmToList2 ( SafeBuf *parmList ,
collnum_t collnum ,
2014-11-10 14:45:11 -08:00
int32_t occNum ,
Parm *m ) ;
bool convertHttpRequestToParmList (HttpRequest *hr,SafeBuf *parmList,
2014-11-10 14:45:11 -08:00
int32_t page , TcpSocket *sock );
Parm *getParmFast2 ( int32_t cgiHash32 ) ;
2016-05-22 21:38:00 +02:00
Parm *getParmFast1 ( const char *cgi , int32_t *occNum ) ;
bool broadcastParmList ( SafeBuf *parmList ,
void *state ,
void (* callback)(void *) ,
bool sendToGrunts = true ,
2013-12-26 11:20:19 -08:00
bool sendToProxies = false ,
// send to this single hostid? -1 means all
2014-11-10 14:45:11 -08:00
int32_t hostId = -1 ,
int32_t hostId2 = -1 ); // hostid range?
bool doParmSendingLoop ( ) ;
bool syncParmsWithHost0 ( ) ;
bool makeSyncHashList ( SafeBuf *hashList ) ;
bool addAllParmsToList ( SafeBuf *parmList, collnum_t collnum ) ;
bool updateParm ( char *rec , class WaitEntry *we ) ;
2014-07-09 07:13:24 -07:00
bool cloneCollRec ( char *srcCR , char *dstCR ) ;
//
// end new functions
//
bool m_inSyncWithHost0;
bool m_triedToSync;
2013-08-02 13:12:24 -07:00
bool m_isDefaultLoaded;
2013-08-02 13:12:24 -07:00
Parm m_parms [ MAX_PARMS ];
2014-11-10 14:45:11 -08:00
int32_t m_numParms;
2013-08-02 13:12:24 -07:00
// just those Parms that have a m_sparm of 1
Parm *m_searchParms [ MAX_PARMS ];
2014-11-10 14:45:11 -08:00
int32_t m_numSearchParms;
2013-08-02 13:12:24 -07:00
// for parsing default.conf file for collection recs for OBJ_COLL
Xml m_xml2;
};
extern Parms g_parms;
2016-03-08 22:14:30 +01:00
#endif // GB_PARMS_H