Changeset 12512
- Timestamp:
- 2006-08-24T11:06:42+12:00 (18 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/cgiargs.cpp
r9620 r12512 32 32 value.clear(); 33 33 source = program_arg; 34 fileupload.clear(); 34 35 } 35 36 … … 50 51 } 51 52 53 54 void fileupload_t::clear() { 55 name.clear(); 56 type.clear(); 57 size = 0; 58 tmp_name.clear(); 59 } 60 61 ostream &operator<<(ostream &outs, const fileupload_t &fu) { 62 utf8outconvertclass text_t2utf8; 63 outs << "*** fileupload\n"; 64 65 outs << text_t2utf8 << "name=" << fu.name << ", type="<< fu.type<<", size="<<fu.size<<", tmp_name="<<fu.tmp_name<<"\n"; 66 return outs; 67 } 52 68 53 69 … … 96 112 } 97 113 114 void cgiargsclass::setargfile (const text_t &key, const fileupload_t &fileupload) { 115 iterator here = args.find (key); 116 if (here != args.end()) { 117 (*here).second.fileupload = fileupload; 118 } 119 } 120 98 121 text_t *cgiargsclass::getarg (const text_t &key) { 99 122 iterator here = args.find (key); … … 108 131 return text->getint(); 109 132 } 133 134 fileupload_t *cgiargsclass::getargfile (const text_t &key) { 135 iterator here = args.find (key); 136 if (here == args.end()) return NULL; 137 return &((*here).second.fileupload); 138 } 139 110 140 111 141 … … 134 164 multiplechar = false; 135 165 multiplevalue = false; 166 fileupload = false; 136 167 defaultstatus = weak; 137 168 argdefault.clear(); … … 145 176 (x.multiplechar == y.multiplechar) && 146 177 (x.multiplevalue == y.multiplevalue) && 178 (x.fileupload == y.fileupload) && 147 179 (x.defaultstatus == y.defaultstatus) && 148 180 (x.argdefault == y.argdefault) && … … 157 189 ((x.multiplevalue < y.multiplevalue) || 158 190 ((x.multiplevalue == y.multiplevalue) && 159 ((x.multiplechar < y.multiplechar) || 160 ((x.multiplechar == y.multiplechar) && 161 ((x.defaultstatus < y.defaultstatus) || 162 ((x.defaultstatus == y.defaultstatus) && 163 ((x.argdefault < y.argdefault) || 164 ((x.argdefault == y.argdefault) && 165 ((x.savedarginfo < y.savedarginfo)))))))))))))); 191 ((x.fileupload == y.fileupload) && 192 ((x.fileupload < y.fileupload) || 193 ((x.multiplechar < y.multiplechar) || 194 ((x.multiplechar == y.multiplechar) && 195 ((x.defaultstatus < y.defaultstatus) || 196 ((x.defaultstatus == y.defaultstatus) && 197 ((x.argdefault < y.argdefault) || 198 ((x.argdefault == y.argdefault) && 199 ((x.savedarginfo < y.savedarginfo)))))))))))))))); 166 200 } 167 201 … … 173 207 // addarginfo will combine the information with the present 174 208 // information. If name clashes were detected then the information 175 // will be written to logout and addarginfo will return false. No209 // will be written to logout (or stderr) and addarginfo will return false. No 176 210 // processing with the arguments should be done if this happens 177 211 // as the results will be meaningless. 178 bool cgiargsinfoclass::addarginfo (ostream *logout, const cgiarginfo &info) { 179 212 bool cgiargsinfoclass::addarginfo (ostream *logout, cgiarginfo &info) { 213 214 // if info.fileupload is set certain other fields are implicitly 215 // overridden 216 if (info.fileupload) { 217 info.multiplechar = false; 218 info.defaultstatus = cgiarginfo::weak; 219 info.argdefault = ""; 220 info.savedarginfo = cgiarginfo::mustnot; 221 } 180 222 cgiarginfo *orginfo = getarginfo (info.shortname); 181 223 if (orginfo == NULL) { … … 185 227 186 228 if (orginfo->longname != info.longname) { 187 if (logout != NULL) {188 outconvertclass text_t2ascii;229 outconvertclass text_t2ascii; 230 if (logout != NULL) { 189 231 (*logout) << text_t2ascii << "Error: cgi argument name clash for argument \"" 190 232 << info.shortname << "\".\nOne long name was\n \"" << orginfo->longname 191 233 << "\"\nand the other was\n \"" << info.longname << "\".\n\n"; 234 } else { 235 cerr << text_t2ascii << "Error: cgi argument name clash for argument \"" 236 << info.shortname << "\".\nOne long name was\n \"" << orginfo->longname 237 << "\"\nand the other was\n \"" << info.longname << "\".\n\n"; 192 238 } 193 239 return false; // found a clash … … 195 241 196 242 if (orginfo->multiplevalue != info.multiplevalue) { 197 if (logout != NULL) {198 outconvertclass text_t2ascii;243 outconvertclass text_t2ascii; 244 if (logout != NULL) { 199 245 (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname 200 246 << "\" was given as being a single value option\n" 201 247 << "and a multiple value option.\n\n"; 248 } else { 249 cerr << text_t2ascii << "Error: cgi argument \"" << info.shortname 250 << "\" was given as being a single value option\n" 251 << "and a multiple value option.\n\n"; 202 252 } 203 253 return false; // found a clash 204 254 } 205 255 256 if (orginfo->fileupload != info.fileupload) { 257 outconvertclass text_t2ascii; 258 if (logout != NULL) { 259 (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname 260 << "\" was given as being a file upload argument\n" 261 << "and a non file upload argument.\n\n"; 262 } else { 263 cerr << text_t2ascii << "Error: cgi argument \"" << info.shortname 264 << "\" was given as being a file upload argument\n" 265 << "and a non file upload argument.\n\n"; 266 } 267 return false; // found a clash 268 } 269 206 270 if (orginfo->multiplechar != info.multiplechar) { 207 if (logout != NULL) {208 outconvertclass text_t2ascii;271 outconvertclass text_t2ascii; 272 if (logout != NULL) { 209 273 (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname 210 274 << "\" was given as being a single character option\n" 211 275 << "and a multiple character option.\n\n"; 212 } 276 } else { 277 cerr << text_t2ascii << "Error: cgi argument \"" << info.shortname 278 << "\" was given as being a single character option\n" 279 << "and a multiple character option.\n\n"; 280 } 213 281 return false; // found a clash 214 282 } 215 283 216 284 if (!info.multiplechar && info.argdefault.size() > 1) { 217 if (logout != NULL) {218 outconvertclass text_t2ascii;285 outconvertclass text_t2ascii; 286 if (logout != NULL) { 219 287 (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname 220 288 << "\" was defined as being a single character option\n" 221 289 << "but a multiple character default was given.\n\n"; 290 } else { 291 cerr << text_t2ascii << "Error: cgi argument \"" << info.shortname 292 << "\" was defined as being a single character option\n" 293 << "but a multiple character default was given.\n\n"; 222 294 } 223 295 return false; // found a problem … … 229 301 (orginfo->savedarginfo==cgiarginfo::must && 230 302 info.savedarginfo==cgiarginfo::mustnot)) { 231 if (logout != NULL) {232 outconvertclass text_t2ascii;303 outconvertclass text_t2ascii; 304 if (logout != NULL) { 233 305 (*logout) << text_t2ascii << "Error: it was specified that cgi argument \"" 234 306 << info.shortname << "\" should be saved in the state\n" 235 307 << "information and that it should not be save in the state information.\n\n"; 308 } else { 309 cerr << text_t2ascii << "Error: it was specified that cgi argument \"" 310 << info.shortname << "\" should be saved in the state\n" 311 << "information and that it should not be save in the state information.\n\n"; 236 312 } 237 313 return false; // found a clash … … 252 328 } 253 329 254 bool cgiargsinfoclass::addarginfo (ostream *logout, const cgiargsinfoclass &info) { 255 const_iterator here = info.begin (); 256 const_iterator end = info.end (); 330 bool cgiargsinfoclass::addarginfo (ostream *logout, cgiargsinfoclass &info) { 331 332 iterator here = info.begin (); 333 iterator end = info.end (); 257 334 258 335 while (here != end) { 259 if (!addarginfo (logout, (*here).second)) return false; 336 if (!addarginfo (NULL, (*here).second)) { 337 cerr << "returning false\n"; 338 return false; 339 } 260 340 ++here; 261 341 } … … 299 379 } 300 380 301 bool cgiargsinfoclass::addarginfo (ostream *logout, con st confcgiarg_tmap& info)381 bool cgiargsinfoclass::addarginfo (ostream *logout, confcgiarg_tmap& info) 302 382 { 303 383 confcgiarg_tmap::const_iterator thisArg = info.begin(); … … 323 403 return &((*here).second); 324 404 } 405 406 // stream operators to print cgiarginfo for debugging purposes 407 ostream &operator<<(ostream &outs, const cgiargsinfoclass &argsinfo) { 408 utf8outconvertclass text_t2utf8; 409 cgiargsinfoclass::const_iterator here = argsinfo.begin (); 410 cgiargsinfoclass::const_iterator end = argsinfo.end (); 411 412 outs << "*** cgiargsinfoclass\n"; 413 414 while (here != end) { 415 outs << text_t2utf8 << (*here).first << ", "; 416 ++here; 417 } 418 outs << "\n"; 419 420 return outs; 421 } -
trunk/gsdl/src/recpt/cgiargs.h
r7594 r12512 53 53 enum response_t {location, content, fullcontent, undecided_location}; 54 54 55 struct fileupload_t { 56 void clear(); 57 fileupload_t() {clear();} 58 59 text_t name; 60 text_t type; 61 int size; 62 text_t tmp_name; 63 }; 64 65 typedef map<text_t, fileupload_t, lttext_t> fileupload_tmap; 55 66 56 67 struct cgiarg_t { … … 63 74 text_t value; 64 75 source_t source; 65 }; 76 fileupload_t fileupload; 77 }; 78 79 ostream &operator<<(ostream &outs, const fileupload_t &fu); 66 80 67 81 bool operator==(const cgiarg_t &x, const cgiarg_t &y); … … 126 140 void setdefaultcarg (const text_t &key, unsigned short c, 127 141 cgiarg_t::source_t source=cgiarg_t::default_arg); 142 void setargfile (const text_t &key, const fileupload_t &fileupload); 128 143 text_t *getarg (const text_t &key); 129 144 int getintarg (const text_t &key); 145 fileupload_t *getargfile (const text_t &key); 130 146 text_t &operator[] (const text_t &key) {return args[key].value;} 131 147 cgiarg_t &lookupcgiarg (const text_t &key) {return args[key];} … … 157 173 // use the same name) 158 174 bool multiplevalue; 175 176 // fileupload should be set if the argument is to be used to upload files 177 bool fileupload; 159 178 160 179 // defaultstatus_t indicates how good the default is when different … … 224 243 // processing with the arguments should be done if this happens 225 244 // as the results will be meaningless. 226 bool addarginfo (ostream *logout, c onst cgiarginfo &info);227 bool addarginfo (ostream *logout, c onst cgiargsinfoclass &info);245 bool addarginfo (ostream *logout, cgiarginfo &info); 246 bool addarginfo (ostream *logout, cgiargsinfoclass &info); 228 247 229 248 // addarginfo will override args info with info loaded from config files 230 249 // if the args do not exists will be created 231 250 bool addarginfo (ostream *logout, const text_t& argshortname, const text_tmap& mapinfo); 232 bool addarginfo (ostream *logout, con st confcgiarg_tmap& info);251 bool addarginfo (ostream *logout, confcgiarg_tmap& info); 233 252 234 253 cgiarginfo *getarginfo (const text_t &key); … … 237 256 }; 238 257 258 ostream &operator<<(ostream &outs, const cgiargsinfoclass &argsinfo); 239 259 240 260 #endif
Note:
See TracChangeset
for help on using the changeset viewer.