⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				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 = AD_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 = AD_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 = AD_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 = AD_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 = AD_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++ )
		{
		const char *pTmp = AD_lookupValueEx( pConfig, "HTTP", 
					"IndexFile", iTmp );
		if ( !pTmp ) { break; };

		os << " IndexFile=\"" << pTmp << "\"";
		}

#define SECTION_P14 "\n\
	CheckPath Condition=\"&cmp(&dblookup(response,string,ObjectMap),Redirect)\" \
StatusCode StatusCode=\"302\"\n\
	CheckPath RefuseFileByMask AllowFileMask=\"EF\" RefuseStatus=404\n\
	CheckPath RefuseFileByMask AllowFileMask=\"F\" RefuseStatus=403\n\
	CheckPath ReturnCode ReturnCode=COMPLETED\n\
	CheckAuth Authenticate\n\
	CheckAccess AccessByFile RequirePermissions=\"R\"\n\
\n\
	CheckType ConditionalGet \n\
	CheckType CheckForDirectory SetType=\"internal/x-directory\"\n\
\n\
	#\n\
	# Otherwise: Set the media type based on the file extension\n\
	#\n\
	CheckType MIMETypeByExtension \n\
\n\
	#\n\
	# Set StatusCode 501 for not allowed HTTP verbs\n\
	#\n\
	CheckType Condition=\"&not(&regexp(*$m*,\
"
	os << SECTION_P14;

	/*
	** Advanced HTTP (1.1) settings
	*/
	__iOptions = atoi(L("HTTP", "Methods"));
	if ( __iOptions & 1 ) { os << "GET"; };
	if ( __iOptions & 2 ) { os << "HEAD"; };
	if ( __iOptions & 4 ) { os << "POST"; };
	if ( __iOptions & 8 ) { os << "PUT"; };
	if ( __iOptions & 16 ) { os << "DELETE"; };
	if ( __iOptions & 32 ) { os << "OPTIONS"; };
	if ( __iOptions & 64 ) { os << "TRACE"; };

	os << "))\" StatusCode StatusCode=\"501\"\n";

#define SECTION_P15 "\n\
	#\n\
	# Return 'COMPLETED' so an internal error will not be raised\n\
	#\n\
	CheckType ReturnCode ReturnCode=COMPLETED\n\
\n\
	#\n\
	# Most requests refer to a file, so put that first \n\
	#\n\
	# Handle GET and HEAD requests by sending a file if NEITHER\n\
	#	- the value of ObjectMap in the response DB is set\n\
	#	NOR\n\
	#	- the media type of the resource does match 'internal/*'\n\
	#\n\
	Handle Condition=\"&not(&or(&dblookup(response,string,ObjectMap),\\\n\
&regexp('internal/*',$c)))\" SendFile"
	os << SECTION_P15;

	if (L("HTTP", "Ranges" )[0])
		{
		os << " Ranges=\"" << L("HTTP", "Ranges" ) << "\"";
		}
	if (L("HTTP", "ChunkLimit" )[0])
		{
		os << " ChunkLimit=\"" << L("HTTP", "ChunkLimit" ) << "\"";
		}
	os << endl;

	/*
	** Directory Index
	*/
	os << "\tHandle Condition=\"&cmp($c,internal/x-directory)\" ";
	// allow customized directory index
	if ( atoi(L( "DirIndex", "Layout" )) == 6 )
		{ os << "CustomIndex" << endl; }
	else
		{ os << "DirIndex" << endl; }

	/*
	** Remaining response types
	*/
#define SECTION_P15_1 "\
	Handle Condition=\"&cmp($c,internal/x-server-parsed-html)\" SendSSI \\\n\
		Exec=Yes ExecFileFixup=\"\\n\
/* exec file=\"\" maps to Standard CGI (Scripts) */\\\n\
&dbreplace(response,string,ObjectMap,Scripts)\\n\
&dbreplace(response,rfc822,Content-Type,internal/x-cgi)\"\n\
	Handle Condition=\"&cmp($c,internal/x-imagemap)\" ImageMap\n\
	Handle Condition=\"&cmp($c,internal/x-server-parsed-php)\" PHP4\n\
	Handle SendFile"

	os << SECTION_P

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -