📄 config.cpp
字号:
/*
** SSL defaults
*/
AD_DEFAULT( "SSL", "Debug", "" );
// SSL2 SSL3 TLS1 Debg Bugs Hack
// 1 2 4 8 16 32
AD_DEFAULT( "SSL", "Options", "3" );
AD_DEFAULT( "SSL", "PKeyFile", "./key.pem" );
AD_DEFAULT( "SSL", "CertFile", "./cert.pem" );
AD_DEFAULT( "SSL", "Validation", "0" );
AD_DEFAULT( "SSL", "Depth", "1" );
AD_DEFAULT( "SSL", "CaCertPath", "./" );
// AD_DEFAULT( "SSL", "CaCertFile", "" );
AD_DEFAULT( "SSL", "Ciphers", "DEFAULT" );
/*
** MIME Types
*/
if ( !AD_lookupValue( pConfig, "MIMETypes", "Mapping" ) )
{
for( int i=0; __pMIMETypes[i]; i++ )
{
AD_addValue( pConfig, "MIMETypes", "Mapping", __pMIMETypes[i] );
};
}
/*
** Mappings
*/
if ( !AD_lookupValue( pConfig, "Mappings", "Mapping" ) )
{
for( int i=0; __pMappings[i]; i++ )
{
AD_addValue( pConfig, "Mappings", "Mapping", __pMappings[i] );
};
}
/*
** Logfiles
*/
if ( !AD_lookupValue( pConfig, "Logfiles", "Logging" ) )
{
for( int i=0; __pLogfiles[i]; i++ )
{
AD_addValue( pConfig, "Logfiles", "Logging", __pLogfiles[i] );
};
}
/*
** Mapping Types
*/
if ( !AD_lookupValue( pConfig, "Internal", "MappingTypes" ) )
{
for( int i=0; __pMappingTypes[i]; i++ )
{
AD_addValue( pConfig, "Internal", "MappingTypes",
__pMappingTypes[i] );
};
}
/*
** IOObject Types
*/
if ( !AD_lookupValue( pConfig, "Internal", "IOTypes" ) )
{
for( int i=0; __pIOTypes[i]; i++ )
{
AD_addValue( pConfig, "Internal", "IOTypes",
__pIOTypes[i] );
};
}
/*
** Logging types
*/
if ( !AD_lookupValue( pConfig, "Internal", "LoggingTypes" ) )
{
for( int i=0; __pLoggingTypes[i]; i++ )
{
AD_addValue( pConfig, "Internal", "LoggingTypes",
__pLoggingTypes[i] );
};
}
/*
** Always have an admin realm - to act as a starting point.
*/
int iTmp = 0;
const char *pRealm = NULL;
for (;;iTmp++)
{
pRealm = AD_lookupValueEx( pConfig, "Realms", "Basic", iTmp );
if ( pRealm && !stricmp( pRealm, "Administration" )) break;
pRealm = AD_lookupValueEx( pConfig, "Realms", "Digest", iTmp );
if ( pRealm && !stricmp( pRealm, "Administration" )) break;
pRealm = AD_lookupValueEx( pConfig, "Realms", "Ntlm", iTmp );
if ( pRealm && !stricmp( pRealm, "Administration" )) break;
if (!pRealm) { break; };
}
if ( !pRealm || stricmp( pRealm, "Administration" ))
{
AD_DEFAULT( "Realms", "Basic", "Administration" );
}
/*
** Reset the operating system, e.g. if system upgraded.
*/
OSVERSIONINFO VerInfo;
VerInfo.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
if ( GetVersionEx(&VerInfo)&&VerInfo.dwPlatformId==VER_PLATFORM_WIN32_NT )
{
// set if not present
AD_DEFAULT( "General", "OS", "NT" );
// set if different
if ( strcmp( AD_lookupValue( pConfig, "General", "OS" ), "NT" ))
{ AD_replaceValue( pConfig, "General", "OS", "NT" ); }
}
else if ( GetVersionEx(&VerInfo)&&VerInfo.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS )
{
// set if not present
AD_DEFAULT( "General", "OS", "W95" );
// set if different
if ( strcmp( AD_lookupValue( pConfig, "General", "OS" ), "W95" ))
{ AD_replaceValue( pConfig, "General", "OS", "W95" ); }
}
/*
** Do not enter any virtual host information.
*/
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PTConfig AD_loadConfig( const char *pFileName )
{
enum { BUF_SIZE=2047 };
char szBuf[BUF_SIZE+1];
pRetained = PI_NEW( PIString );
assert( pFileName );
fstream ifs( pFileName, ios::in | ios::nocreate );
if ( !ifs || ifs.eof() )
{ return 0; };
AD_hourglassOn();
Section *pCurrentSection = 0;
DblList *plSections = PI_NEW( DblList );
enum { NORMAL, SECTION, RETAINED } eState = NORMAL;
for(; !ifs.eof();)
{
*szBuf = '\0';
ifs.getline( szBuf, BUF_SIZE );
szBuf[BUF_SIZE] = '\0';
if ( eState!=RETAINED && ( *szBuf=='\0' || *szBuf!='#' ) )
{ continue; };
switch( eState )
{
case NORMAL:
if ( !strncmp( &(szBuf[1]), SECTION_START,
sizeof( SECTION_START )-1 ) )
{
if ( pCurrentSection )
plSections->Append( (DblList::type)pCurrentSection );
pCurrentSection = PI_NEW( Section( &(szBuf[sizeof(SECTION_START)]) ) );
eState = SECTION;
}
else if ( !strncmp( &(szBuf[1]), NOTMODIFIED_START,
sizeof( NOTMODIFIED_START )-1 ) )
{ eState = RETAINED; };
break;
case SECTION:
if ( !strncmp( &(szBuf[1]), SECTION_END,
sizeof( SECTION_END )-1 ) )
{ eState = NORMAL; }
else
{ pCurrentSection->NewValue( &(szBuf[1]) ); };
break;
case RETAINED:
if ( !strncmp( &(szBuf[1]), NOTMODIFIED_END,
sizeof( NOTMODIFIED_END )-1 ) )
{ eState = NORMAL; }
else
{
assert( pRetained );
pRetained->Concatenate( szBuf );
pRetained->Concatenate( '\n' );
};
break;
default:
assert( 0 );
};
};
if ( pCurrentSection )
plSections->Append( (DblList::type)pCurrentSection );
/*
** Setup defaults
*/
Internal_setupDefaults( plSections );
AD_hourglassOff();
return plSections;
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
PTConfig AD_createDefaultConfig()
{
AD_hourglassOn();
DblList *plSections = PI_NEW( DblList );
/*
** Setup defaults
*/
Internal_setupDefaults( plSections );
AD_hourglassOff();
return plSections;
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static const char *Internal_lookupValue( PTConfig pConfig, const char *pSection,
const char *pVariable, int iIndex )
{
assert( pSection && pVariable );
for( DblListIterator i( *((DblList *)pConfig) ); !i.BadIndex(); i++ )
{
Section *pTheSection = (Section *)i.Current();
if ( strcmp( pTheSection->sSectionName, pSection ) ) continue;
for( DblListIterator j( pTheSection->lPairs ); !j.BadIndex(); j++ )
{
ValuePair *pPair = (ValuePair *)j.Current();
if ( pPair->sVariable==pVariable && !(iIndex--) )
{ return pPair->sValue; };
};
};
return 0;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
const char *AD_lookupValue( PTConfig pConfig, const char *pSection,
const char *pVariable )
{
return Internal_lookupValue( pConfig, pSection, pVariable, 0 );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
const char *AD_lookupValueEx( PTConfig pConfig, const char *pSection,
const char *pVariable, int iIndex )
{
return Internal_lookupValue( pConfig, pSection, pVariable, iIndex );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static int Internal_changeValue( PTConfig pConfig, const char *pSection,
const char *pVariable, const char *pNewValue, int iReplace )
{
assert( pSection && pVariable && pNewValue );
for( DblListIterator i( *((DblList *)pConfig) ); !i.BadIndex(); i++ )
{
Section *pTheSection = (Section *)i.Current();
if ( strcmp( pTheSection->sSectionName, pSection ) ) continue;
if ( iReplace )
{
/*
** Search for an existing value and replace it if found
*/
for( DblListIterator j( pTheSection->lPairs ); !j.BadIndex(); j++ )
{
ValuePair *pPair = (ValuePair *)j.Current();
if ( pPair->sVariable==pVariable )
{
pPair->sValue = pNewValue;
return 1;
};
};
};
/*
** variable not found in section, or new value
*/
pTheSection->lPairs.Append( (DblList::type)PI_NEW( ValuePair(
pVariable, pNewValue ) ) );
return 1;
};
/*
** section not found
*/
Section *pNewSection = PI_NEW( Section( pSection ) );
pNewSection->lPairs.Append( (DblList::type)PI_NEW( ValuePair(
pVariable, pNewValue ) ) );
((DblList *)pConfig)->Append( (DblList::type)pNewSection );
return 1; /* success */
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int AD_addValue( PTConfig pConfig, const char *pSection,
const char *pVariable, const char *pNewValue )
{
return Internal_changeValue( pConfig, pSection, pVariable, pNewValue, 0 );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int AD_replaceValue( PTConfig pConfig, const char *pSection,
const char *pVariable, const char *pNewValue )
{
return Internal_changeValue( pConfig, pSection, pVariable, pNewValue, 1 );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int AD_deleteValue( PTConfig pConfig, const char *pSection,
const char *pVariable )
{
assert( pSection && pVariable );
for( DblListIterator i( *((DblList *)pConfig) ); !i.BadIndex(); i++ )
{
Section *pTheSection = (Section *)i.Current();
if ( strcmp( pTheSection->sSectionName, pSection ) ) continue;
for(;;)
{
/*
** Loop forever to restart each time a match is deleted
*/
int iNotFound = 1;
for( DblListIterator j( pTheSection->lPairs ); !j.BadIndex(); j++ )
{
ValuePair *pPair = (ValuePair *)j.Current();
if ( pPair->sVariable==pVariable )
{
pTheSection->lPairs.Detach( j );
PI_DELETE( pPair );
iNotFound = 0; /* start again */
break;
};
};
if ( iNotFound ) { break; };
};
};
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
void Internal_writeDefaultParagraphs( ostream &os )
{
#define SECTION_P16 "\n\
# ---\n\
#\n\
# Scripts, WinScripts, FastCGIScripts\n\
#\n\
# Handler sequences for resources which have mapped to these\n\
# respective types\n\
#\n\
# ---\n\
<Object>\n\
Name Scripts\n\
Class FlexibleHandlerClass\n\
Condition \"&cmp(&dblookup(response,string,ObjectMap),Scripts)\"\n\
CheckPath RefuseFileByMask AllowFileMask=\"EFD\" RefuseStatus=404\n\
CheckPath RefuseFileByMask AllowFileMask=\"F\" RefuseStatus=403\n\
CheckPath ReturnCode ReturnCode=COMPLETED\n\
CheckAccess AccessByFile RequirePermissions=\"X\"\n\
CheckType ReturnCode ReturnCode=COMPLETED\n\
Handle StandardCGI\n\
</Object>\n\
\n\
<Object>\n\
Name WinScripts\n\
Class FlexibleHandlerClass\n\
Condition \"&cmp(&dblookup(response,string,ObjectMap),WinScripts)\"\n\
CheckPath RefuseFileByMask AllowFileMask=\"EFD\" RefuseStatus=404\n\
CheckPath RefuseFileByMask AllowFileMask=\"F\" RefuseStatus=403\n\
CheckPath ReturnCode ReturnCode=COMPLETED\n\
CheckAccess AccessByFile RequirePermissions=\"X\"\n\
CheckType ReturnCode ReturnCode=COMPLETED\n\
Handle WindowsCGI\n\
</Object>\n\
"
os << SECTION_P16;
#define SECTION_P17 "\n\
<Object>\n\
Name FastCGIScripts\n\
Class FlexibleHandlerClass\n\
Condition \"&cmp(&dblookup(response,string,ObjectMap),FastCGIScripts)\"\n\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -