📄 pi3file.cpp
字号:
#\n\
# ---\n\
<Object>\n\
Name Main\n\
Class UNIXDaemonClass\n\
\n\
# Actual class to accept new IO requests and dispatch them\n\
ServerObject ThreadPoolDispatcher\n\
PIDFile \"../Logs/pid.log\"\n\
RLimitCpu Maximum\n\
\n\
# User that child processes will run as. Server must run as root to \n\
# be able to change to the specified user. A user id number can be\n\
# specified with #number. Server which start with root privileges should\n\
# change to a user id with lesser privileges for security reasons.\n\
# User nobody\n\
\n\
# Group that child processes will run as. Server must run as root to\n\
# be able to change to a different group. A group id number can be\n\
# specified with #number.\n\
# Group #-1\n\
\n\
# generate a server unique lockfile name and write it into\n\
# Logs/lockfile.txt\n\
LockFileName \"../Logs/lockfile.txt\"\n\
\n\
# Message to write just before the server is ready to start accepting\n\
# connections.\n\
Message \"Pi3Web HTTP Server Started\"\n\
\n\
# Specify the number of processes. \n\
"
#define SECTION_P4_1 "\n\
</Object>\n\
"
if (*L("General", "ReuseThreads" ))
{
os << SECTION_P3_0;
os << L("Internal", "ServerIOObjectLine" ) << endl;
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = M_LookupValueEx( pConfig, "IOObjects",
"IOObject", iTmp );
if ( !pTmp ) { break; };
int i = 0;
/* --- scan to tab (jump over Type) --- */
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
PIString sType = PIString( pTmp, i );
/* --- scan over whitespace to start of Host --- */
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
pTmp = &( pTmp[i] );
i=0;
/* --- scan to tab --- */
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
PIString sHost = PIString( pTmp, i );
/* --- scan over whitespace to start of Port --- */
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
pTmp = &( pTmp[i] );
i=0;
/* --- scan to tab --- */
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
PIString sPort = PIString( pTmp, i );
/* --- scan over whitespace to start of Send Timeout --- */
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
pTmp = &( pTmp[i] );
i=0;
/* --- scan to tab --- */
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
PIString sSend = PIString( pTmp, i );
/* --- scan over whitespace to start of Receive Timeout --- */
for( ; pTmp[i] && isspace(pTmp[i]); i++ );
pTmp = &( pTmp[i] );
i=0;
/* --- scan to tab --- */
for( ; pTmp[i] && pTmp[i]!='\t'; i++ );
PIString sRecv = PIString( pTmp, i );
if ( sType=="TCP" )
{
os << "\tSecondaryIO TCPIO BindHost=\"" << (const char *)sHost << "\"";
os << " BindPort=\"" << (const char *)sPort << "\"";
os << " SendTimeout=\"" << (const char *)sSend << "\"";
os << " RecvTimeout=\"" << (const char *)sRecv << "\"";
}
if ( sType=="SSL" )
{
os << "\tSecondaryIO SSL Type=\"Passive\" Version=\"23\" \\" << endl;
os << "PrivateKeyFile=\"./" << (const char *)sHost << "_"
<< (const char *)sPort << "_" "key.pem\"";
os << " CertificateFile=\"./" << (const char *)sHost << "_"
<< (const char *)sPort << "_" "cert.pem\"";
os << " CACertificatePath=\"./\" \\" << endl;
os << "IOObject=\"TCPIO";
os << " BindHost=\"" << (const char *)sHost << "\"";
os << " BindPort=\"" << (const char *)sPort << "\"";
os << " SendTimeout=\"" << (const char *)sSend << "\"";
os << " RecvTimeout=\"" << (const char *)sRecv << "\"\"";
}
os << endl;
}
}
else
{
os << SECTION_P3;
os << L("Internal", "ServerIOObjectLine" ) << endl;
}
os << SECTION_P3_1;
os << "\tMaxThreads " << L( "General", "Threads" );
os << SECTION_P3_2;
os << "\tExitAfter " << L( "General", "ExitAfter" );
os << SECTION_P3_3;
os << SECTION_P4;
os << "\tNumberOfProcesses " << L( "General", "Processes" );
os << SECTION_P4_1;
#define SECTION_P10 "\n\
# ---\n\
#\n\
# Start\n\
#\n\
# Handle initial phases of requests, typically before we have enough\n\
# information to select different execution paths\n\
#\n\
# ---\n\
<Object>\n\
Name Start\n\
Class FlexibleHandlerClass\n\
Init ReturnCode ReturnCode=COMPLETED\n\
Headers ReadRequestHeaders\n\
"
os << SECTION_P10;
/*
** Write out the HOSTMAP phases for IP virtual hosts
*/
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = M_LookupValueEx( pConfig, "VirtualHosts",
"IP", iTmp );
if ( !pTmp ) { break; };
/*
** Split the virtual host into IP, hostname, docroot, administrator
*/
int i;
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sIPAddress( pTmp, i );
os << "\tHostMap VirtualHostByAddress VirtualHostObject=\""
<< sIPAddress << "\" BindAddress=\"" << sIPAddress << "\"" << endl;
};
/*
** Write out the HOSTMAP phases for Non-IP virtual hosts
*/
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = M_LookupValueEx( pConfig, "VirtualHosts",
"NonIP", iTmp );
if ( !pTmp ) { break; };
/*
** Split the virtual host into [IP], hostname, docroot, [administrator]
*/
int i;
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sHostname( pTmp, i );
os << "\tHostMap VirtualHostByName VirtualHostObject=\"" << sHostname
<< "\" HostName=\"" << sHostname << "\"" << endl;
};
#define SECTION_P10_1 "\n\
HostMap ReturnCode ReturnCode=COMPLETED\n\
# Mapping DirectoryMappings\n\
\n\
#\n\
# Default mappings\n\
#\n\
Mapping MapToErrorDocument \\\n\
IgnoreStatus=\"0 200\" \\\n\
DefaultMessage=\"/errors/unknown.htm\" \\\n\
301=\"/errors/301.htm\" \\\n\
304=\"/errors/304.htm\" \\\n\
400=\"/errors/400.htm\" \\\n\
401=\"/errors/401.htm\" \\\n\
403=\"/errors/403.htm\" \\\n\
404=\"/errors/404.htm\" \\\n\
500=\"/errors/500.htm\" \\\n\
501=\"/errors/501.htm\"\n\
# Mapping UserDirectory UserDirectoryRoot=\"/home/\" \\\n\
# HTMLDirectory=\"/public_html\"\n\
"
#define SECTION_P10_2 "\n\
HostMap ReturnCode ReturnCode=COMPLETED\n\
# Mapping DirectoryMappings\n\
\n\
#\n\
# Default mappings\n\
#\n\
Mapping MapToErrorDocument \\\n\
IgnoreStatus=\"0 200\" \\\n\
DefaultMessage=\"/errors/unknown.htm\" \\\n\
301=\"/errors/301.ssi\" \\\n\
304=\"/errors/304.ssi\" \\\n\
400=\"/errors/400.htm\" \\\n\
401=\"/errors/401.ssi\" \\\n\
403=\"/errors/403.ssi\" \\\n\
404=\"/errors/404.ssi\" \\\n\
500=\"/errors/500.ssi\" \\\n\
501=\"/errors/501.htm\"\n\
# Mapping UserDirectory UserDirectoryRoot=\"/home/\" \\\n\
# HTMLDirectory=\"/public_html\"\n\
"
if ( strstr( L( "General", "ErrorMessages" ), "Verbose" ))
{ os << SECTION_P10_2; }
else
{ os << SECTION_P10_1; }
/*
** Place holders for default document root
*/
int iIsDocumentRoot;
PIString sDocumentRootVirtualPath;
const char *pDocumentRootType;
PIString sDocumentRootRealm;
/*
** Write in mappings
*/
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = M_LookupValueEx( pConfig, "Mappings",
"Mapping", iTmp );
if ( !pTmp ) { break; };
iIsDocumentRoot = 0;
sDocumentRootVirtualPath = PIString::Empty();
pDocumentRootType = 0;
sDocumentRootRealm = PIString::Empty();
/*
** Split the mappings into type, from and to
*/
int i;
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sType( pTmp, i );
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && isspace(pTmp[i]); i++);
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sFrom( pTmp, i );
/*
** See if this is the document root
*/
if ( sFrom=="/" )
{
iIsDocumentRoot = 1;
};
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && isspace(pTmp[i]); i++);
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sTo( pTmp, i );
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && isspace(pTmp[i]); i++);
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sRealm( pTmp, i );
if ( sType=="CGI" )
{ pDocumentRootType = "CGIMapper"; }
else if ( sType=="Documents" )
{ pDocumentRootType = "PathMapper"; }
else if ( sType=="Windows CGI" )
{ pDocumentRootType = "WinCGIMapper"; }
else if ( sType=="Fast CGI" )
{ pDocumentRootType = "FCGIMapper"; }
else if ( sType=="ISAPI" )
{ pDocumentRootType = "ISAPIMapper"; }
else if ( sType=="Redirect" )
{ pDocumentRootType = "RedirectMapper"; }
else
{ assert( 0 ); };
if ( !iIsDocumentRoot )
{
os << "\tMapping " << pDocumentRootType << " ";
pDocumentRootType = 0;
};
/*
** Write in code to generate a realm marker
*/
if ( iIsDocumentRoot )
{
sDocumentRootVirtualPath = sTo;
}
else
{
os << "From=\"" << sFrom << "\" To=\"" << sTo << "\" ";
};
if ( strcmp( sRealm, "(none)" ) )
{
if ( !iIsDocumentRoot )
{
os << "\\" << endl;
os << "\t\tAction=\"&dbreplace(response,string,AuthenticationRealm,";
os << sRealm << ")\"";
}
else
{ sDocumentRootRealm = sRealm; };
};
os << endl;
};
/*
** Write IP hosts
*/
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = M_LookupValueEx( pConfig, "VirtualHosts",
"IP", iTmp );
if ( !pTmp ) { break; };
/*
** Split the virtual host into IP, hostname, docroot, administrator
*/
int i;
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sIPAddress( pTmp, i );
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && isspace(pTmp[i]); i++);
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && isspace(pTmp[i]); i++);
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sDocroot( pTmp, i );
os << "\t# Document root for the IP virtual host '"
<< sIPAddress << "'" << endl;
os << "\tMapping Condition=\"&cmp($l," << sIPAddress << ")\" \\"
<< endl;
os << "\t\tPathMapper From=\"/\" To=\"" << sDocroot << "\"" << endl;
};
/*
** Write NonIP hosts
*/
iTmp = 0;
for(;; iTmp++ )
{
const char *pTmp = M_LookupValueEx( pConfig, "VirtualHosts",
"NonIP", iTmp );
if ( !pTmp ) { break; };
/*
** Split the virtual host into hostname, docroot, administrator
*/
int i;
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sHostname( pTmp, i );
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && isspace(pTmp[i]); i++);
pTmp = &(pTmp[i]);
for( i=0; pTmp[i] && pTmp[i]!='\t'; i++);
PIString sDocroot( pTmp, i );
os << "\t# Document root for the Non-IP virtual host '"
<< sHostname << "'" << endl;
os << "\tMapping Condition=\"&cmpi($v," << sHostname << ")\" \\" <<endl;
os << "\t\tPathMapper From=\"/\" To=\"" << sDocroot << "\"" << endl;
};
/*
** Write document root
*/
os << "#" << endl;
os << "# Default document root" << endl;
os << "#" << endl;
if ( iIsDocumentRoot )
{
os << "\tMapping " << pDocumentRootType << " ";
os << "From=\"/\" To=\"" << sDocumentRootVirtualPath << "\" ";
if ( sDocumentRootRealm!=PIString::Empty() )
{
os << "\\" << endl;
os <<"\t\tAction=\"&dbreplace(response,string,AuthenticationRealm,";
os << sDocumentRootRealm << ")\"";
};
os << endl;
};
#define SECTION_P11 "\
</Object>\n\
\n"
os << SECTION_P11;
#define SECTION_P12 "\n\
# ---\n\
#\n\
# Options\n\
#\n\
# Handle requests with HTTP verb Options\n\
#\n\
# ---\n\
<Object>\n\
Name Options\n\
Class FlexibleHandlerClass\n\
Condition \"&cmpi($m,OPTIONS)\"\n\
Mapping ReturnCode ReturnCode=COMPLETED\n\
CheckPath ReturnCode ReturnCode=COMPLETED\n\
CheckAccess ReturnCode ReturnCode=COMPLETED\n\
</Object>\n\
\n"
os << SECTION_P12;
#define SECTION_P13 "\n\
# ---\n\
#\n\
# Default\n\
#\n\
# Handle requests that other handlers have passed up\n\
#\n\
# ---\n\
<Object>\n\
Name Default\n\
Class FlexibleHandlerClass\n\
CheckPath DirectoryExists\
"
os << SECTION_P13;
/*
** Write in index files
*/
iTmp = 0;
for(;; iTmp++ )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -