00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <iostream>
00041 #include <string.h>
00042 #include <stdlib.h>
00043
00044
00045
00046
00047 using namespace std;
00048
00049
00051 class CGI_Interface2 {
00052 public:
00054 CGI_Interface2( char*, int);
00056 char * GetString(char * key);
00058 int GetInt(char * key);
00060 float GetFloat(char * key);
00062 int NumberOfKeys();
00064 char * GetNextKey();
00066 void BeginKey();
00067
00069 char *InputBuffer;
00071 int InputBufferLen;
00073 char * keys[MAXKEYS];
00075 char * values[MAXKEYS];
00077 int NumKeys;
00079 int KeyIndex;
00080 };
00081
00082
00083
00084 CGI_Interface2::CGI_Interface2(char* inputStr, int inputLen) {
00085
00086 char * p; int len;
00087
00088 InputBuffer = (char*)malloc( inputLen + 100 );
00089 memcpy( InputBuffer, inputStr, inputLen );
00090
00091
00092 p = getenv("QUERY_STRING");
00093
00094 len = inputLen;
00095 InputBufferLen = len;
00096
00097
00098 if (p && *p && len + 4 < MAXINPUTLEN) {
00099 if (len > 1) strcat(InputBuffer,"&");
00100 strncat(InputBuffer, p, MAXINPUTLEN-len-1);
00101 }
00102
00103
00104
00105 NumKeys = KeyIndex = 0; p = InputBuffer;
00106 while (NumKeys < MAXKEYS) {
00107 keys[NumKeys] = p;
00108 p = strchr (p, '=');
00109 if (p==0) break;
00110 *p = 0;
00111 values[NumKeys++] = ++p;
00112 p = strchr (p, '&');
00113 if (p==0) break;
00114 *p = 0; p++;
00115 }
00116
00117
00118 for (int i=0; i<NumKeys; i++) {
00119
00120 p = values[i];
00121 while (1) {
00122 p = strchr(p,'+');
00123 if (p==0) break;
00124 *p = ' ';
00125 }
00126
00127 p = values[i];
00128 while (1) {
00129 p = strchr(p,'%');
00130 if (p==0) break;
00131 int hi = p[1] | 0x20;
00132 int lo = p[2] | 0x20;
00133 if (hi > '9') hi -= 87; else hi -= 48;
00134 if (lo > '9') lo -= 87; else lo -= 48;
00135 *p = (char)(hi * 16 + lo);
00136 strcpy (p+1, p+3); p++;
00137 }
00138 }
00139
00140
00141 }
00142
00143
00144
00145 char * CGI_Interface2::GetString(char * key) {
00146 for (int i=0; i<NumKeys; i++) {
00147 if (strcmp(keys[i],key)==0) {
00148 return values[i];
00149 }
00150 }
00151 return "";
00152 }
00153
00154
00155 int CGI_Interface2::GetInt(char * key) {
00156 for (int i=0; i<NumKeys; i++) {
00157 if (strcmp(keys[i],key)==0) {
00158 return atoi(values[i]);
00159 }
00160 }
00161 return 0;
00162 }
00163
00164
00165 float CGI_Interface2::GetFloat(char * key) {
00166 for (int i=0; i<NumKeys; i++) {
00167 if (strcmp(keys[i],key)==0) {
00168 return float(atof(values[i]));
00169 }
00170 }
00171 return 0.;
00172 }
00173
00174
00175 int CGI_Interface2::NumberOfKeys() {
00176 return NumKeys;
00177 }
00178
00179
00180 char * CGI_Interface2::GetNextKey() {
00181 if (KeyIndex >= NumKeys) return 0;
00182 return keys[KeyIndex++];
00183 }
00184
00185
00186 void CGI_Interface2::BeginKey() {
00187 KeyIndex = 0;
00188 }
00189
00190
00191 #ifndef NOTMAIN
00192
00193 #endif
00194
00195