Main Page | Namespace List | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

NEnvironment.cp

Go to the documentation of this file.
00001 00024 00025 #define MW_CGI monsterworks::cgi 00026 00027 #include <NCapture.h> 00028 using MW_CGI::NCapture; 00029 00030 #include <NEnvironment.h> 00031 using MW_CGI::NEnvironment; 00032 using std::string; 00033 using std::pair; 00034 using std::map; 00035 00036 namespace { 00037 00038 MW_CGI::NEnvironment::Variables ourKeyStrings; 00039 00041 void NEnvironmentInitialize(); 00042 00043 }; 00044 00050 const MW_CGI::NEnvironment::Variables& MW_CGI::NEnvironment::GetVariables() 00051 { 00052 NEnvironmentInitialize(); 00053 00054 return ourKeyStrings; 00055 } 00056 00062 std::string MW_CGI::NEnvironment::GetValue( 00063 const std::string& inName) 00064 { 00065 NEnvironmentInitialize(); 00066 00067 return NCapture::GetEnvironmentVariable(inName); 00068 00069 } 00070 00078 std::string MW_CGI::NEnvironment::GetValue( 00079 EKeys inKey) 00080 { 00081 NEnvironmentInitialize(); 00082 00083 Variables::const_iterator theValue = ourKeyStrings.lower_bound(inKey); 00084 if (theValue == ourKeyStrings.end()) 00085 { 00086 assert(false); 00087 } 00088 00089 return GetValue(theValue->second); 00090 } 00091 00096 bool MW_CGI::NEnvironment::IsPostMethod() 00097 { 00098 NEnvironmentInitialize(); 00099 00100 return (NEnvironment::GetValue(NEnvironment::EKey_RequestMethod) == "POST"); 00101 } 00102 00107 bool MW_CGI::NEnvironment::IsGetMethod() 00108 { 00109 NEnvironmentInitialize(); 00110 00111 return (NEnvironment::GetValue(NEnvironment::EKey_RequestMethod) == "GET"); 00112 } 00113 00114 namespace { 00115 00119 void NEnvironmentInitialize() 00120 { 00121 00122 static bool initialized = false; 00123 00124 if (initialized) 00125 { 00126 return; 00127 } 00128 00130 #define KEYS_INSERT(theKey,theString) ourKeyStrings.insert(pair<NEnvironment::EKeys,string>(NEnvironment::EKey_##theKey, theString)); 00131 KEYS_INSERT(RemoteAddress, "REMOTE_ADDR"); 00132 KEYS_INSERT(RemotePort, "REMOTE_PORT"); 00133 KEYS_INSERT(RequestURI, "REQUEST_URI"); 00134 KEYS_INSERT(RequestMethod, "REQUEST_METHOD"); 00135 KEYS_INSERT(ServerSignature, "SERVER_SIGNATURE"); 00136 KEYS_INSERT(ServerAddress, "SERVER_ADDR"); 00137 KEYS_INSERT(ServerProtocol, "SERVER_PROTOCOL"); 00138 KEYS_INSERT(ServerPort, "SERVER_PORT"); 00139 KEYS_INSERT(ServerName, "SERVER_NAME"); 00140 KEYS_INSERT(ServerAdministrator, "SERVER_ADMIN"); 00141 KEYS_INSERT(ServerSoftware, "SERVER_SOFTWARE"); 00142 KEYS_INSERT(HTTPUserAgent, "HTTP_USER_AGENT"); 00143 KEYS_INSERT(HTTPAccept, "HTTP_ACCEPT"); 00144 KEYS_INSERT(HTTPHost, "HTTP_HOST"); 00145 KEYS_INSERT(HTTPAcceptEncoding, "HTTP_ACCEPT_ENCODING"); 00146 KEYS_INSERT(HTTPConnection, "HTTP_CONNECTION"); 00147 KEYS_INSERT(HTTPAcceptLanguage, "HTTP_ACCEPT_LANGUAGE"); 00148 KEYS_INSERT(ScriptURI, "SCRIPT_URI"); 00149 KEYS_INSERT(ScriptName, "SCRIPT_NAME"); 00150 KEYS_INSERT(ScriptURL, "SCRIPT_URL"); 00151 KEYS_INSERT(ScriptFilename, "SCRIPT_FILENAME"); 00152 KEYS_INSERT(QueryString, "QUERY_STRING"); 00153 KEYS_INSERT(PathInformation, "PATH_INFO"); 00154 KEYS_INSERT(PathTranslated, "PATH_TRANSLATED"); 00155 KEYS_INSERT(DocumentRoot, "DOCUMENT_ROOT"); 00156 KEYS_INSERT(ExecutablePath, "PATH"); 00157 KEYS_INSERT(GatewayInterface, "GATEWAY_INTERFACE"); 00158 KEYS_INSERT(RemoteHost, "REMOTE_HOST"); 00159 KEYS_INSERT(AuthenticationType, "AUTH_TYPE"); 00160 KEYS_INSERT(RemoteUser, "REMOTE_USER"); 00161 KEYS_INSERT(RemoteIdentity, "REMOTE_IDENT"); 00162 KEYS_INSERT(ContentType, "CONTENT_TYPE"); 00163 KEYS_INSERT(ContentLength, "CONTENT_LENGTH"); 00164 #undef KEYS_INSERT 00165 00166 initialized = true; 00167 } 00168 00169 };

monsterworks Code by Monsterworks. Made available under the GNU Public License.
Documentation by doxygen.