Code style changes

This commit is contained in:
Ai Lin Chia
2016-04-29 14:29:06 +02:00
parent 0bbf3a4381
commit dd2fb62d6c

119
Conf.cpp

@ -14,6 +14,7 @@ mode_t getFileCreationFlags() {
s_setUmask = true;
umask ( 0 );
}
return S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH ;
}
@ -22,19 +23,19 @@ mode_t getDirCreationFlags() {
s_setUmask = true;
umask ( 0 );
}
return S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH |
S_IXUSR | S_IXGRP;
return S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IXUSR | S_IXGRP;
}
Conf::Conf ( ) {
m_save = true;
m_doingCommandLine = false;
// set max mem to 16GB at least until we load on disk
m_maxMem = 16000000000;
}
static bool isInWhiteSpaceList ( const char *p , const char *buf ) {
if ( ! p ) return false;
const char *match = strstr ( buf , p );
@ -53,10 +54,6 @@ static bool isInWhiteSpaceList ( const char *p , const char *buf ) {
}
bool Conf::isCollAdmin ( TcpSocket *sock , HttpRequest *hr ) {
// until we have coll tokens use this...
//return isMasterAdmin ( socket , hr );
// master always does
if ( isMasterAdmin ( sock , hr ) ) return true;
@ -67,8 +64,7 @@ bool Conf::isCollAdmin ( TcpSocket *sock , HttpRequest *hr ) {
}
bool Conf::isCollAdminForColl ( TcpSocket *sock, HttpRequest *hr, char *coll ){
bool Conf::isCollAdminForColl ( TcpSocket *sock, HttpRequest *hr, char *coll ) {
CollectionRec *cr = g_collectiondb.getRec ( coll );
if ( ! cr ) return false;
@ -76,14 +72,9 @@ bool Conf::isCollAdminForColl ( TcpSocket *sock, HttpRequest *hr, char *coll ){
return isCollAdmin2 ( sock , hr , cr );
}
bool Conf::isCollAdmin2 ( TcpSocket *sock ,
HttpRequest *hr ,
CollectionRec *cr ) {
bool Conf::isCollAdmin2 ( TcpSocket *sock, HttpRequest *hr, CollectionRec *cr ) {
if ( ! cr ) return false;
//int32_t page = g_pages.getDynamicPageNumber(hr);
// never for main! must be root!
if ( strcmp(cr->m_coll,"main")==0 ) return false;
@ -107,11 +98,6 @@ bool Conf::isCollAdmin2 ( TcpSocket *sock ,
buf = cr->m_collectionPasswords.getBufStart();
if ( isInWhiteSpaceList ( p , buf ) ) return true;
// the very act of just knowing the collname of a guest account
// is good enough to update it
//if ( strncmp ( cr->m_coll , "guest_" , 6 ) == 0 )
// return true;
return false;
}
@ -119,7 +105,6 @@ bool Conf::isCollAdmin2 ( TcpSocket *sock ,
// . is user a root administrator?
// . only need to be from root IP *OR* have password, not both
bool Conf::isMasterAdmin ( TcpSocket *socket , HttpRequest *hr ) {
bool isAdmin = false;
// totally open access?
@ -132,8 +117,6 @@ bool Conf::isMasterAdmin ( TcpSocket *socket , HttpRequest *hr ) {
if ( socket && isMasterIp ( socket->m_ip ) )
isAdmin = true;
//if ( isConnectIp ( socket->m_ip ) ) return true;
if ( hasMasterPwd ( hr ) )
isAdmin = true;
@ -144,14 +127,12 @@ bool Conf::isMasterAdmin ( TcpSocket *socket , HttpRequest *hr ) {
// cancels our admin view
if ( hr && ! hr->getLong("admin",1) )
return false;
return true;
}
bool Conf::hasMasterPwd ( HttpRequest *hr ) {
//if ( m_numMasterPwds == 0 ) return false;
if ( m_masterPwds.length() <= 0 )
return false;
@ -170,15 +151,8 @@ bool Conf::hasMasterPwd ( HttpRequest *hr ) {
// . check this ip in the list of admin ips
bool Conf::isMasterIp ( uint32_t ip ) {
//if ( m_numMasterIps == 0 ) return false;
//if ( m_numConnectIps == 0 ) return false;
if ( m_connectIps.length() <= 0 ) return false;
// for ( int32_t i = 0 ; i < m_numConnectIps ; i++ )
// if ( m_connectIps[i] == (int32_t)ip )
// return true;
char *p = iptoa(ip);
char *buf = m_connectIps.getBufStart();
@ -186,21 +160,7 @@ bool Conf::isMasterIp ( uint32_t ip ) {
}
bool Conf::isConnectIp ( uint32_t ip ) {
return isMasterIp(ip);
// for ( int32_t i = 0 ; i < m_numConnectIps ; i++ ) {
// if ( m_connectIps[i] == (int32_t)ip )
// return true;
// // . 192.0.2.0 ips mean the whole block
// // . the high byte in the int32_t is the Least Signficant Byte
// if ( (m_connectIps[i] >> 24) == 0 &&
// (m_connectIps[i] & 0x00ffffff) ==
// ((int32_t)ip & 0x00ffffff) )
// return true;
// }
// no match
//return false;
}
// . set all member vars to their default values
@ -212,19 +172,17 @@ void Conf::reset ( ) {
bool Conf::init ( char *dir ) { // , int32_t hostId ) {
g_parms.setToDefault ( (char *)this , OBJ_CONF ,NULL);
m_save = true;
char fname[1024];
//if ( dir ) sprintf ( fname , "%slocalgb.conf", dir );
//else sprintf ( fname , "./localgb.conf" );
File f;
//f.set ( fname );
//m_isLocal = true;
//if ( ! f.doesExist() ) {
m_isLocal = false;
if ( dir ) sprintf ( fname , "%sgb.conf", dir );
else sprintf ( fname , "./gb.conf" );
// try regular gb.conf then
f.set ( fname );
//}
// make sure g_mem.maxMem is big enough temporarily
g_conf.m_maxMem = 8000000000; // 8gb temp
@ -240,22 +198,21 @@ bool Conf::init ( char *dir ) { // , int32_t hostId ) {
// set to defaults
g_conf.reset();
// and save it
//log("gb: Saving %s",fname);
m_save = true;
save();
// clear errors
g_errno = 0;
status = true;
}
// update g_mem
//g_mem.m_maxMem = g_conf.m_maxMem;
if ( ! g_mem.init ( ) ) return false;
// always turn this off
g_conf.m_testMem = false;
// and this, in case you forgot to turn it off
if ( g_conf.m_isLive ) g_conf.m_doConsistencyTesting = false;
// and this on
g_conf.m_indexDeletes = true;
@ -266,7 +223,8 @@ bool Conf::init ( char *dir ) { // , int32_t hostId ) {
g_conf.m_useStatsdb = true;
// hard-code disable this -- could be dangerous
g_conf.m_bypassValidation = true;//false;
g_conf.m_bypassValidation = true;
// this could too! (need this)
g_conf.m_allowScale = true;//false;
@ -290,7 +248,6 @@ bool Conf::init ( char *dir ) { // , int32_t hostId ) {
}
void Conf::setRootIps ( ) {
// set m_numDns based on Conf::m_dnsIps[] array
int32_t i; for ( i = 0; i < MAX_DNSIPS ; i++ ) {
m_dnsPorts[i] = 53;
@ -298,7 +255,6 @@ void Conf::setRootIps ( ) {
}
m_numDns = i;
Host *h = g_hostdb.getMyHost();
// fail back to public dns
@ -313,7 +269,6 @@ void Conf::setRootIps ( ) {
m_numDns = 1;
}
// default this to off on startup for now until it works better
m_askRootNameservers = false;
@ -346,46 +301,10 @@ bool Conf::save ( ) {
// will look for the hostname in each collection for a match
// no match defaults to default collection
char *Conf::getDefaultColl ( char *hostname, int32_t hostnameLen ) {
if ( ! m_defaultColl || ! m_defaultColl[0] )
if ( ! m_defaultColl || ! m_defaultColl[0] ) {
return "main";
}
// just use default coll for now to keep things simple
return m_defaultColl;
/*
// return defaultColl for empty hostname
if (!hostname || hostnameLen <= 0)
return m_defaultColl;
// check each coll for the hostname
int32_t numRecs = g_collectiondb.getNumRecs();
collnum_t currCollnum = g_collectiondb.getFirstCollnum();
for ( int32_t i = 0; i < numRecs; i++ ) {
// get the collection name
char *coll = g_collectiondb.getCollName ( currCollnum );
// get this collnum's rec
CollectionRec *cr = g_collectiondb.getRec ( coll );
// loop through 3 possible hostnames
for ( int32_t h = 0; h < 3; h++ ) {
char *cmpHostname;
switch ( h ) {
case 0: cmpHostname = cr->m_collectionHostname; break;
case 1: cmpHostname = cr->m_collectionHostname1; break;
case 2: cmpHostname = cr->m_collectionHostname2; break;
}
// . get collection hostname length, reject if 0 or
// larger than hostnameLen (impossible match)
int32_t cmpLen = gbstrlen(cmpHostname);
if ( cmpLen == 0 || cmpLen > hostnameLen )
continue;
// . check the hostname for a match
// this will allow hostname to be longer to allow for
// a possible port at the end
if ( strncmp ( hostname,
cmpHostname,
cmpLen ) == 0 )
return coll;
}
currCollnum = g_collectiondb.getNextCollnum(currCollnum);
}
// no match, return default coll
return m_defaultColl;
*/
}