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

📄 config.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 5 页
字号:
\n\
# Include  standard IO and server stuff\n\
include ../Conf/IO.cnf\n\
include ../Conf/Server.cnf\n\
include ../Conf/Pi3API.cnf\n\
include ../Conf/HTTP.cnf\n\
include ../Conf/Fcgi.cnf\n\
include ../Conf/Plugins.cnf\n\
include ../Conf/ISAPI.cnf\n\
include ../Conf/PHP4.cnf\n\
include ../Conf/SSL.cnf\n\
include ../Conf/SiteRoot.cnf\n\
\n\
# ---\n\
#\n\
# IO Object for main listening socket.\n\
#\n\
# ---\n\
<Object>\n\
    Name ServerIOObject\n\
    Class TCPIPIOClass\n\
    Type Passive\n\
\n\
# A hostname must be specified for the Pi3Web HTTP server. The hostname\n\
# will be used by the server lookup the IP address that this server will\n\
# listen on. A value of INADDR_ANY let the server listen on any IP address.\n\
\n"
	/*
	** Write network preferences
	*/
	os << SECTION_P1;
	os << "\
	BindHost " << L("General", "Host") << "\n\
\n\
# A TCP port must be specified for this HTTP server. The TCP port\n\
# is the port that the HTTP will listen for requests on. This is\n\
# typically 80 for HTTP servers. \n\
#\n\
# Note that UNIX operating systems normally require that the server\n\
# initially run as user 'root' to bind on ports between 0 and 1024\n\
	BindPort " << L("General", "Port") << "\n\
\n\
# Timeout accepting connections. -1 specifies no timeout.\n\
	AcceptTimeout -1\n\
\n\
# Specify timeout for sending data. -1 specifies no timeout. \n\
	RecvTimeout " << L("General", "RecvTimeout" ) << "\n\
\n\
# Specify timeout for receiving data. -1 specifies no timeout. \n\
	SendTimeout " << L("General", "SendTimeout" ) << "\n" << endl;

#define SECTION_P1_2 "\
	PeerIPVariable STRING:RemoteAddr\n\
	PeerHostNameVariable STRING:RemoteHost\n\
	LocalAddressVariable STRING:LocalAddr\n\
	ServerPortVariable RFC822:ServerPort\n\
\n\
# Flags\n\
#\n\
#   OwnDB - Object adds its own DB, rather than use the parents\n\
#               this is necessary to avoid collision of values placed in\n\
#               the DB between different connection. \n\
#\n\
#   SetPeerAddress - IP address of remote peer with be put\n\
#               into the specified variable.\n\
#\n\
#   DNSReverseLookup - Use reverse DNS to get the hostname of the \n\
#               peer and place it in the specified variable.\n\
#\n\
#   SetLocalAddress - Put local address in the specified variable.\n\
"

	os << SECTION_P1_2;
	os << "\tFlags OwnDB|";
	if ( *AD_lookupValue( pConfig, "General", "DNSReverseLookup" ) )
		{ os << "DNSReverseLookup|"; };
	os << "SetPeerAddress|SetLocalAddress" << endl;
	os << "</Object>" << endl << endl;

/*
** Write out information on the ssl object
*/
#define SECTION_P1_30 "\
# ---\n\
#\n\
# SSL IO filter object\n\
#\n\
# ---\n\
<Object>\n\
    Name SSLIOObject\n\
    Class SSLClass\n\
\n\
# Type, passive (server) or active (client)\n\
	Type Passive\n\
\n\
# SSL version,\n\
#	\"2\"=SSLv2 only\n\
#	\"3\"=SSLv3 only\n\
#	\"23\"=SSLv2 or SSLv3\n\
#	\"10\"=TLS1.0\n\
"
	os << SECTION_P1_30;
	os << "\tVersion ";
	int __iOptions = atoi(L("SSL", "Options"));
	if ( __iOptions & 1 ) { os << "2"; };
	if ( __iOptions & 2 ) { os << "3"; };
	if ( __iOptions & 4 ) { os << "10"; };
	os << endl << endl;

#define SECTION_P1_31 "\
# Client certificate verification,\n\
#	0=No verification performed\n\
#	1=Certificate is verified, but not mandatory\n\
#	2=Certificate must be present\n\
"
	os << SECTION_P1_31;
	os << "\tVerify "<< L("SSL", "Validation") << endl;
	os << endl;
	os << "# Verify depth to verify client certificates before giving up." << endl;
	os << "\tVerifyDepth " << L("SSL", "Depth") << endl;
	os << endl;
	os << "# insert the CA certificate file path and name here" << endl;
	os << "\tCACertificatePath \"" << L("SSL", "CaCertPath") << "\"" << endl;
	if ( L("SSL", "CaCertFile") )
		{ os << "\tCACertificateFile \"" << L("SSL", "CaCertFile") << "\"" << endl; };
	os << endl;

#define SECTION_P1_32 "\
# lower level IO object that SSL layer uses for transport\n\
#	IOObject SnoopIO IOObject=\"ServerIOObject\" OutFile=\"./encrypt.dbg\" Flag=\"Verbose\"\n\
	IOObject ServerIOObject\n\
\n"
	os << SECTION_P1_32;
	os << "# insert the name of your key file here" << endl;
	os << "\tPrivateKeyFile \"" << L("SSL", "PKeyFile") << "\"" << endl;
	os << endl;
	os << "# insert the name of your certificate file here" << endl;
	os << "\tCertificateFile \"" << L("SSL", "CertFile") << "\"" << endl;
	os << endl;

#define SECTION_P1_33 "\
# DebugFile output, filename or 'STDERR' or 'STDOUT'\n\
#	DebugFile \"STDERR\"\n\
"
	os << SECTION_P1_33;
	if ( __iOptions & 8 )
		{ os << "\tDebugFile \"../Logs/SSL.txt\"" << endl; }
	else
		{ os << "#\tDebugFile \"../Logs/SSL.txt\"" << endl; }
	os << endl;

	os << "# Flag, miscellanious options, \"Bugs\", \"Hack\", etc." << endl;
	if ( __iOptions & 16 ) { os << "\tFlag \"Bugs\"" << endl; };
	if ( __iOptions & 32 ) { os << "\tFlag \"Hack\"" << endl; };
	os << endl;

#define SECTION_P1_34 "\
# List of acceptable ciphers, disable to allow all valid cipher suites.\n\
#	CipherList \"ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH\"\n\
#	CipherList \"NULL-MD5\"\n\
"
	os << SECTION_P1_34;
	os << "\tCipherList \"" << L("SSL", "Ciphers") << "\"" << endl;

#define SECTION_P1_35 "\
</Object>\n\
\n"
	os << SECTION_P1_35;

/*
** Write out information on the main virtual host
*/
#define SECTION_P2 "\
# ---\n\
# Main virtual host object.\n\
# ---\n\
<Object>\n\
	Name MainVirtualHostInformation\n\
	Class VirtualHostClass\n"

	os << SECTION_P2;
	/*
	** Main virtual host settings
	*/
	os << "\tAdministrator " << L( "General", "Admin" ) << endl;
	os << "\tHostName " << L( "General", "Host" ) << endl;
	const char *pPort = L( "General", "Port" );
	if ( atoi( pPort )!=80 )
		{ os << "\tServerPort " << L( "General", "Port" ) << endl; };
    os << "</Object>" << endl;

    /*
    ** Now do ip virtual host objects
    */
	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++);
		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 );

		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 sAdministrator( pTmp, i );

        /*
        ** Write out the details
        */
        os << "# --- The IP virtual host '" << sIPAddress << "' ---" << endl;
        os << "<Object>" << endl;
        os << "\tName " << sIPAddress << endl;
        os << "\tClass VirtualHostClass" << endl;
        os << "\tAdministrator " << sAdministrator << endl;
        os << "\tHostName " << sHostname << endl;
		if ( atoi( pPort )!=80 )
			{ os << "\tServerPort " << L( "General", "Port" ) << endl; };
        os << "</Object>" << endl;
        };

    /*
    ** Now do non-ip virtual host objects
    */
	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 );

		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 sAdministrator( pTmp, i );

        /*
        ** Write out the details
        */
        os << "# --- The Non-IP virtual host '" << sHostname << "' ---" << endl;
        os << "<Object>" << endl;
        os << "\tName " << sHostname << endl;
        os << "\tClass VirtualHostClass" << endl;
        os << "\tAdministrator " << sAdministrator << endl;
        os << "\tHostName " << sHostname << endl;
		if ( atoi( pPort )!=80 )
			{ os << "\tServerPort " << L( "General", "Port" ) << endl; };
        os << "</Object>" << endl;
        };

#define SECTION_P3 "\
\n\
# ---\n\
#\n\
#    Thread dispatch object\n\
#\n\
#   This is an instance of MultiThreadedIOServerClass with appropriate\n\
#   parameters\n\
#\n\
# ---\n\
<Object>\n\
	Name ThreadPoolDispatcher\n\
	Class MultiThreadedIOServerClass\n\
\n\
# The IOObject is the object that will be used for the listening socket\n\
# it can be a real IOObject (such as TCP/IP), as test IO object which \n\
# feeds stub data into the server or a filter IO object which encrpts\n\
# or logs data passed through it.\n\
#\n\
#    Example test IO object:\n\
# 	IOObject TestIOObject\n\
#\n\
#    Log IO to file:\n\
#	IOObject SnoopIO IOObject=\"ServerIOObject\" OutFile=\"./snoop.dbg\" Flag=\"Verbose\"\n\
#\n\
"
#define SECTION_P3_0 "\
\n\
# ---\n\
#\n\
#    Thread dispatch object\n\
#\n\
#   This is an instance of MultiThreadedMultiIOServerClass with appropriate\n\
#   parameters\n\
#\n\
# ---\n\
<Object>\n\
	Name ThreadPoolDispatcher\n\
	Class MTMIOServerClass\n\
\n\
# The IOObject is the object that will be used for the listening socket\n\
# it can be a real IOObject (such as TCP/IP), as test IO object which \n\
# feeds stub data into the server or a filter IO object which encrpts\n\
# or logs data passed through it.\n\
#\n\
#    Example test IO object:\n\
# 	IOObject TestIOObject\n\
#\n\
#    Log IO to file:\n\
#	IOObject SnoopIO IOObject=\"ServerIOObject\" OutFile=\"./snoop.dbg\" Flag=\"Verbose\"\n\
#\n\
"
#define SECTION_P3_1 "\
\n\
# Dispatch accepted IO connection to the HTTPLogicObject\n\
	LogicObject HTTPLogicObject\n\
\n\
# Number of threads to use \n\
"
#define SECTION_P3_2 "\n\
\n\
# Number of requests to exit after\n\
"
#define SECTION_P3_3 "\n\
</Object>\n\
\n"

#define SECTION_P4 "\n\
# ---\n\
#\n\
# Main Pi3 object. \n\
#\n\
# This is an instance of the UNIXDaemonClass to fork the server into\n\
# one monitor process and 'NumberOfProcesses' child processes. \n\
#\n\
# The monitor process automatically starts a new child processes whenever\n\
# a child process exits.\n\
#\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 = AD_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;

⌨️ 快捷键说明

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