source: trunk/gsdl/src/recpt/cgiutils.cpp@ 12555

Last change on this file since 12555 was 12555, checked in by kjdon, 18 years ago

reverted split_cgi_args back to 1.25 version, pre davids depositor work. The depositor seems to work still, and the newer version was stuffing up other things. So hopefully it wasn't essential

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 23.5 KB
Line 
1/**********************************************************************
2 *
3 * cgiutils.cpp -- general cgi utilities
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#include "cgiutils.h"
27#include "md5.h"
28#include "fileutil.h"
29#include "gsdlunicode.h"
30#include "fileutil.h"
31#include "unitool.h" // in mg, for output_utf8_char
32
33#if defined(GSDL_USE_OBJECTSPACE)
34# include <ospace\std\iostream>
35# include <ospace\std\fstream>
36#elif defined(GSDL_USE_IOS_H)
37# include <iostream.h>
38# include <fstream.h>
39#else
40# include <iostream>
41# include <fstream>
42#endif
43
44
45static unsigned short hexdigit (unsigned short c) {
46 if (c >= '0' && c <= '9') return (c-'0');
47 if (c >= 'a' && c <= 'f') return (c-'a'+10);
48 if (c >= 'A' && c <= 'F') return (c-'A'+10);
49 return c;
50}
51
52
53static void c2hex (unsigned short c, text_t &t) {
54 t.clear();
55
56 if (c >= 256) {
57 t = "20"; // ' '
58 return;
59 }
60
61 unsigned short o1, o2;
62
63 o1 = (c/16) % 16;
64 o2 = c % 16;
65 if (o1 >= 10) o1 += 'a' - 10;
66 else o1 += '0';
67 if (o2 >= 10) o2 += 'a' - 10;
68 else o2 += '0';
69
70 t.push_back(o1);
71 t.push_back(o2);
72}
73
74static text_t::iterator getline (text_t::iterator first,
75 text_t::iterator last,
76 bool include_crlf) {
77 while (first != last) {
78 if (((first+1) != last) && (*first == 13) && (*(first+1) == 10)) {
79 // found <CRLF>
80 if (include_crlf) first += 2;
81 break;
82 }
83 first++;
84 }
85 return first;
86}
87
88static void process_post_section (text_t &argname, text_t &argdata, text_t &filename, text_t &filedata,
89 text_t &filetype, bool &isfile, text_t &argstr,
90 fileupload_tmap &fileuploads, const text_t &gsdlhome) {
91
92 if (!argname.empty()) {
93
94 if (!isfile) {
95 // argdata includes a trailing <CRLF> that we must remove
96 if ((argdata.size() > 1) && (*(argdata.end()-2) == 13) && (*(argdata.end()-1) == 10)) {
97 argdata.erase(argdata.end()-2, argdata.end());
98 }
99 if (!argstr.empty()) argstr += "&";
100 argstr += argname + "=" + argdata;
101
102 } else if (!filename.empty()) {
103 // filedata includes a trailing <CRLF> that we must remove
104 if ((filedata.size() > 1) && (*(filedata.end()-2) == 13) && (*(filedata.end()-1) == 10)) {
105 filedata.erase(filedata.end()-2, filedata.end());
106 }
107
108 // create tmp_name for storing the file on disk
109 text_t tmp_name = md5data(filedata);
110 tmp_name = filename_cat(gsdlhome, "tmp", tmp_name);
111 char *tmp_name_c = tmp_name.getcstr();
112
113 // write the file data to disk
114 outconvertclass out;
115 ofstream filestream(tmp_name_c, ios::out | ios::binary);
116 filestream << out << filedata;
117 filestream.close();
118 delete tmp_name_c;
119
120 // populate the fields of a fileupload_t and put it in the
121 // fileuploads map
122 fileupload_t fu;
123 // note that filename currently may or may not include the path since
124 // some browsers (e.g. IE) include the path while others
125 // (e.g. mozilla) do not. we should probably remove the path from
126 // this field here to get a consistent value across all browsers.
127 text_t::iterator slash = findlastchar(filename.begin(), filename.end(), '\\');
128 if (slash != filename.end()) {
129 filename = substr(slash+1, filename.end());
130 }
131 fu.name = filename;
132 fu.type = filetype;
133 // size has yet to be implemented
134 fu.size = 0;
135 fu.tmp_name = tmp_name;
136 fileuploads[argname] = fu;
137 }
138 }
139 isfile = false;
140 argname.clear();
141 argdata.clear();
142 filename.clear();
143 filedata.clear();
144 filetype.clear();
145}
146
147// parse data obtained through a CGI POST request
148text_t parse_post_data (text_t &content_type, text_t &raw_post_data,
149 fileupload_tmap &fileuploads, const text_t &gsdlhome) {
150
151 text_t argstr;
152
153 text_t::iterator content_type_begin = content_type.begin();
154 text_t::iterator content_type_end = content_type.end();
155 if (findword(content_type_begin, content_type_end, "multipart/form-data") == content_type_end) {
156 // a simple post request
157 return raw_post_data;
158
159 } else {
160 // multipart/form data - may contain one or more uploaded files
161
162 /*
163 content_type should look something like the following
164 multipart/form-data; boundary=---------------------------7d411e1a50330
165
166 while raw_post_data will be as follows
167 -----------------------------7d43e73450330CRLF
168 Content-Disposition: form-data; name="e"<CRLF>
169 <CRLF>
170 d-0testss--1-0-00---4----0--0-110--1en-Zz-1---10-about-0--00031-001utfZz-8-0<CRLF>
171 -----------------------------7d43e73450330<CRLF>
172 Content-Disposition: form-data; name="afile"; filename="C:\somedoc.doc"<CRLF>
173 Content-Type: application/msword<CRLF>
174 <CRLF>
175 <Content of file><CRLF>
176
177 */
178
179 // first get the boundary from content-type
180 text_t::iterator boundary_begin = findword(content_type_begin, content_type_end, "boundary=");
181 if (boundary_begin+9 < content_type_end) boundary_begin += 9;
182 else {
183 // error
184 return "";
185 }
186 text_t boundary = substr(boundary_begin, getline(boundary_begin, content_type_end, false));
187 int boundary_len = boundary.size();
188
189 text_t argname, argdata, filename, filedata, filetype;
190 bool isfile = false;
191 text_t::iterator data_here = raw_post_data.begin();
192 text_t::iterator data_end = raw_post_data.end();
193 while (data_here != data_end) {
194
195 // get the next available line (including the trailing <CRLF>
196 text_t line = substr(data_here, getline(data_here, data_end, true));
197 data_here += line.size();
198 text_t::iterator line_begin = line.begin();
199 text_t::iterator line_end = line.end();
200 if (findword(line_begin, line_end, boundary) != line_end) {
201 // we've found a boundary
202 process_post_section(argname, argdata, filename, filedata, filetype,
203 isfile, argstr, fileuploads, gsdlhome);
204
205 } else if (findword(line_begin, line_end, "Content-Disposition: form-data") != line_end) {
206 // we've found the the beginning of a new section
207 argname.clear();
208 argdata.clear();
209
210 // get the name of this piece of form data
211 text_t::iterator it = findword(line_begin, line_end, "name=\"");
212 if (it == line_end) break; // error - this shouldn't happen
213 it = findchar(it, line_end, '"');
214 if ((it != line_end) && (it+1 != line_end)) {
215 argname = substr(it+1, findchar(it+1, line_end, '"'));
216 }
217
218 // if this piece of form data contains filename="" it's a file
219 // upload and needs to be treated special
220 it = (findword(line_begin, line_end, "filename=\""));
221 if (it != line_end) {
222 // we've found a file upload
223 isfile = true;
224 it = findchar(it, line_end, '"');
225 if ((it != line_end) && (it+1 != line_end)) {
226 filename = substr(it+1, findchar(it+1, line_end, '"'));
227 }
228
229 // the next line is the content-type of this section
230 line = substr(data_here, getline(data_here, data_end, true));
231 data_here += line.size();
232 line_begin = line.begin();
233 line_end = line.end();
234 it = (findword(line_begin, line_end, "Content-Type: "));
235 if (it != line_end) {
236 filetype = substr(it+14, getline(it, line_end, false));
237 }
238 }
239
240 // eat up the next line as it's just a <CRLF> on it's own
241 data_here += 2;
242
243 } else {
244 if (isfile) filedata += line;
245 else argdata += line;
246 }
247 }
248
249 // process last section
250 process_post_section(argname, argdata, filename, filedata, filetype,
251 isfile, argstr, fileuploads, gsdlhome);
252
253 return argstr;
254 }
255}
256
257// convert %xx and + to their appropriate equivalents
258// IE 6.0 and later use "%u" followed by 4 hex digits... MS IIS extension!
259void decode_cgi_arg (text_t &argstr) {
260 text_t::iterator in = argstr.begin();
261 text_t::iterator out = in;
262 text_t::iterator end = argstr.end();
263
264 while (in != end) {
265 if (*in == '+') *out = ' ';
266
267 else if (*in == '%') {
268 unsigned short c = '%';
269 ++in;
270 if (in != end) { // this is an encoding...
271 if (*in == 'u') { // convert %uHHHH to unicode then current encoding
272 // this assumes a short int is at least 16 bits...
273 ++in;
274 if (in != end)
275 c=hexdigit(*in++) << 12;
276 if (in != end)
277 c+=hexdigit(*in++) << 8;
278 if (in != end)
279 c+=hexdigit(*in++) << 4;
280 if (in != end)
281 c+=hexdigit(*in);
282 /* BAD!! The following assumes the interface is using utf-8. But
283 at this point we don't know what encoding we are using, unless
284 we can parse it out of the string we are currently decoding... */
285 text_t uni=" ";
286 uni[0]=c;
287 text_t utf8=to_utf8(uni);
288 int last_byte=utf8.size()-1;
289 for (int i=0;i<last_byte;++i)
290 *out++ = utf8[i];
291 c=utf8[last_byte];
292 } else { // convert %HH to hex value
293 c = hexdigit (*in);
294 ++in;
295 if (in != end && c < 16) { // sanity check on the previous character
296 c = c*16 + hexdigit (*in);
297 }
298 }
299 }
300 *out = c;
301 } else *out = *in;
302
303 if (in != end) ++in;
304 ++out;
305 }
306
307 // remove the excess characters
308 argstr.erase (out, end);
309}
310
311
312// split up the cgi arguments
313void split_cgi_args (const cgiargsinfoclass &argsinfo, text_t argstr,
314 cgiargsclass &args) {
315 args.clear();
316
317 text_t::const_iterator here = argstr.begin();
318 text_t::const_iterator end = argstr.end();
319 text_t key, value;
320
321 // extract out the key=value pairs
322 while (here != end) {
323 // get the next key and value pair
324 here = getdelimitstr (here, end, '=', key);
325 here = getdelimitstr (here, end, '&', value);
326
327 // convert %xx and + to their appropriate equivalents
328 decode_cgi_arg (value);
329
330 value.setencoding(1); // other encoding
331 // store this key=value pair
332 if (!key.empty()) {
333
334 // if arg occurs multiple times (as is the case with multiple
335 // checkboxes using the same name) we'll create a comma separated
336 // list of all the values (this uses a hack that encodes naturally
337 // occurring commas as %2C - values will therefore need to be decoded
338 // again before use) - it should use an array instead
339 const cgiarginfo *info = argsinfo.getarginfo (key);
340 if (info != NULL && info->multiplevalue) {
341 text_t newvalue = args[key];
342 if (args.lookupcgiarg(key).source == cgiarg_t::cgi_arg) newvalue += ",";
343 newvalue += encode_commas(value);
344 args.setarg (key, newvalue, cgiarg_t::cgi_arg);
345
346 } else {
347 args.setarg (key, value, cgiarg_t::cgi_arg);
348 }
349 }
350 }
351}
352
353text_t encode_commas (const text_t &intext) {
354
355 text_t outtext;
356
357 text_t::const_iterator here = intext.begin ();
358 text_t::const_iterator end = intext.end ();
359
360 while (here != end) {
361 if (*here == ',') outtext += "%2C";
362 else outtext.push_back (*here);
363 ++here;
364 }
365 return outtext;
366}
367
368text_t decode_commas (const text_t &intext) {
369
370 text_t outtext;
371
372 text_t::const_iterator here = intext.begin ();
373 text_t::const_iterator end = intext.end ();
374
375 while (here != end) {
376 if ((here+2<end) && *here == '%' && *(here+1) == '2' &&
377 (*(here+2) == 'C' || *(here+2) == 'c')) {
378 here += 2;
379 outtext.push_back(',');
380
381 }else outtext.push_back (*here);
382 ++here;
383 }
384 return outtext;
385}
386
387text_t minus_safe (const text_t &intext) {
388
389 text_t outtext;
390
391 text_t::const_iterator here = intext.begin ();
392 text_t::const_iterator end = intext.end ();
393
394 while (here != end) {
395 if (*here == '-') outtext += "Zz-";
396 else outtext.push_back (*here);
397 ++here;
398 }
399 outtext = cgi_safe (outtext);
400 return outtext;
401}
402
403text_t cgi_safe (const text_t &intext) {
404 text_t outtext;
405
406 text_t::const_iterator here = intext.begin ();
407 text_t::const_iterator end = intext.end ();
408 unsigned short c;
409 text_t ttmp;
410
411 while (here != end) {
412 c = *here;
413 if (((c >= 'a') && (c <= 'z')) ||
414 ((c >= 'A') && (c <= 'Z')) ||
415 ((c >= '0') && (c <= '9')) ||
416 (c == '+') || (c == '%') || (c == '-')) {
417 // alphanumeric character
418 outtext.push_back(c);
419 } else if (c == ' ') {
420 // space
421 outtext.push_back('+');
422 } else if (c > 255) { // unicode character
423 unsigned char buf[3]; // up to 3 bytes
424 buf[0]='\0';buf[1]='\0';buf[2]='\0';
425 output_utf8_char(c,buf, buf+2);
426 outtext.push_back('%');
427 c2hex(buf[0], ttmp);
428 outtext += ttmp;
429 outtext.push_back('%');
430 c2hex(buf[1], ttmp);
431 outtext += ttmp;
432 if (buf[2]) {
433 outtext.push_back('%');
434 c2hex(buf[2], ttmp);
435 outtext += ttmp;
436 }
437 } else {
438 // everything else
439 outtext.push_back('%');
440 c2hex(c, ttmp);
441 outtext += ttmp;
442 }
443
444 ++here;
445 }
446
447 return outtext;
448}
449
450
451
452
453static text_t::const_iterator get_next_save_arg (text_t::const_iterator first,
454 text_t::const_iterator last,
455 text_t &argname) {
456 first = getdelimitstr (first, last, '-', argname);
457 return first;
458}
459
460
461// check_save_conf_str checks the configuration string for
462// the saved args and makes sure it does not conflict with
463// the information about the arguments. If an error is encountered
464// it will return false and the program should not produce any
465// output.
466bool check_save_conf_str (const text_t &saveconf,
467 const cgiargsinfoclass &argsinfo,
468 ostream &logout) {
469 outconvertclass text_t2ascii;
470
471 text_tset argsset;
472 text_t::const_iterator saveconfhere = saveconf.begin ();
473 text_t::const_iterator saveconfend = saveconf.end ();
474 text_t argname;
475 const cgiarginfo *info;
476
477 // first check to make sure all saved arguments can be saved
478
479 while (saveconfhere != saveconfend) {
480 saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
481
482 if (!argname.empty()) {
483 // save the argument name for later
484 argsset.insert (argname);
485
486 // check the argument
487 info = argsinfo.getarginfo (argname);
488 if (info == NULL) {
489 logout << text_t2ascii << "Error: the cgi argument \"" << argname
490 << "\" is used in the configuration string for the\n"
491 << "saved arguments but does not exist as a valid argument.\n\n";
492 return false;
493 }
494 if (info->savedarginfo == cgiarginfo::mustnot) {
495 logout << text_t2ascii << "Error: the cgi argument \"" << argname
496 << "\" is used in the configuration string for the\n"
497 << "saved arguments but has been specified as an argument whose\n"
498 << "state must not be saved.\n\n";
499 return false;
500 }
501 }
502 }
503
504
505 // next check that all saved arguments that should be saved
506 // are saved
507 cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
508 cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
509
510 while (argsinfohere != argsinfoend) {
511 if (((*argsinfohere).second.savedarginfo == cgiarginfo::must) &&
512 (argsset.find((*argsinfohere).second.shortname) == argsset.end())) {
513 logout << text_t2ascii << "Error: the cgi argument \""
514 << (*argsinfohere).second.shortname << "\" was specified as needing to\n"
515 << "be save but was not listed in the saved arguments.\n\n";
516 return false;
517 }
518
519 ++argsinfohere;
520 }
521
522 return true; // made it, no clashes
523}
524
525
526// create_save_conf_str will create a configuration string
527// based on the information in argsinfo. This method of configuration
528// is not recomended as small changes can produce large changes in
529// the resulting configuration string (for instance a totally different
530// ordering). Only arguments which "must" be saved are included in
531// the resulting string.
532text_t create_save_conf_str (const cgiargsinfoclass &argsinfo,
533 ostream &/*logout*/) {
534 cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
535 cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
536 text_t saveconf;
537 bool first = true;
538
539 while (argsinfohere != argsinfoend) {
540 // save this argument if it must be saved
541 if ((*argsinfohere).second.savedarginfo == cgiarginfo::must) {
542 if (!first) saveconf.push_back ('-');
543 else first = false;
544 saveconf += (*argsinfohere).second.shortname;
545 }
546
547 ++argsinfohere;
548 }
549
550 return saveconf;
551}
552
553
554// expand_save_args will expand the saved arguments based
555// on saveconf placing the results in args if they are not
556// already defined. If it encounters an error it will return false
557// and output more information to logout.
558bool expand_save_args (const cgiargsinfoclass &argsinfo,
559 const text_t &saveconf,
560 cgiargsclass &args,
561 ostream &logout) {
562 outconvertclass text_t2ascii;
563
564 text_t *arg_e = args.getarg("e");
565 if (arg_e == NULL) return true; // no compressed arguments
566 if (arg_e->empty()) return true; // no compressed arguments
567
568 text_t argname, argvalue;
569 const cgiarginfo *argnameinfo;
570
571 text_t::const_iterator saveconfhere = saveconf.begin();
572 text_t::const_iterator saveconfend = saveconf.end();
573
574 text_t::iterator arg_ebegin = arg_e->begin();
575 text_t::iterator arg_eend = arg_e->end();
576 text_t::iterator arg_ehere = arg_ebegin;
577 while (saveconfhere != saveconfend && arg_ehere != arg_eend) {
578 saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
579
580 if (!argname.empty()) {
581 // found another entry
582 argnameinfo = argsinfo.getarginfo (argname);
583
584 if (argnameinfo == NULL) {
585 // no information about the argument could be found
586 // we can't keep going because we don't know whether
587 // this argument is a single or multiple character value
588 logout << text_t2ascii << "Error: the cgi argument \"" << argname
589 << "\" was specified as being a compressed argument\n"
590 << "but no information about it could be found within the "
591 << "cgiargsinfoclass.\n";
592 return false;
593
594 } else {
595
596 // found the argument information
597 if (argnameinfo->multiplechar) {
598 text_t::const_iterator sav = arg_ehere;
599 arg_ehere = getdelimitstr (arg_ehere, arg_eend, '-', argvalue);
600 if (distance(arg_ebegin, arg_ehere) > 2) {
601 // replace any '-' chars escaped with 'Zz'
602 bool first = true;
603 while ((*(arg_ehere-3) == 'Z') && (*(arg_ehere-2) == 'z')) {
604 if (first) argvalue.clear();
605 arg_ehere = (findchar (arg_ehere, arg_eend, '-')) + 1;
606 while (sav != (arg_ehere-1)) {
607 if (!((*sav == 'Z') && (*(sav+1) == 'z') && (*(sav+2) == '-')) &&
608 !((*(sav-1) == 'Z') && (*sav == 'z') && (*(sav+1) == '-'))) argvalue.push_back (*sav);
609 ++sav;
610 }
611 first = false;
612 }
613 }
614 argvalue.setencoding(1); // other encoding
615 if (!argvalue.empty()) args.setdefaultarg (argname, argvalue, cgiarg_t::compressed_arg);
616 } else {
617 args.setdefaultcarg (argname,*arg_ehere, cgiarg_t::compressed_arg);
618 ++arg_ehere;
619 }
620 }
621 }
622 }
623
624 return true;
625}
626
627
628// adds the default values for those arguments which have not
629// been specified
630void add_default_args (const cgiargsinfoclass &argsinfo,
631 cgiargsclass &args,
632 ostream &/*logout*/) {
633 cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
634 cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
635
636 while (argsinfohere != argsinfoend) {
637 if ((*argsinfohere).second.defaultstatus != cgiarginfo::none) {
638 args.setdefaultarg ((*argsinfohere).second.shortname,
639 (*argsinfohere).second.argdefault, cgiarg_t::default_arg);
640 }
641 ++argsinfohere;
642 }
643}
644
645void add_fileupload_args (const cgiargsinfoclass &argsinfo,
646 cgiargsclass &args,
647 fileupload_tmap &fileuploads,
648 ostream &logout) {
649
650 const cgiarginfo *info = argsinfo.getarginfo("a");
651 fileupload_tmap::const_iterator this_file = fileuploads.begin();
652 fileupload_tmap::const_iterator end_file = fileuploads.end();
653 while (this_file != end_file) {
654 const cgiarginfo *info = argsinfo.getarginfo((*this_file).first);
655 if (info != NULL) {
656 if ((*info).fileupload && (file_exists((*this_file).second.tmp_name))) {
657 args.setargfile((*this_file).first, (*this_file).second);
658 }
659 }
660 this_file++;
661 }
662}
663
664// compress_save_args will compress the arguments and return
665// them in compressed_args. If an error was encountered
666// compressed_args will be set to to "", an error will be
667// written to logout, and the function will return false.
668bool compress_save_args (const cgiargsinfoclass &argsinfo,
669 const text_t &saveconf,
670 cgiargsclass &args,
671 text_t &compressed_args,
672 outconvertclass &outconvert,
673 ostream &logout) {
674 outconvertclass text_t2ascii;
675
676 compressed_args.clear();
677
678 text_t argname, argvalue;
679 const cgiarginfo *argnameinfo;
680
681 text_t::const_iterator saveconfhere = saveconf.begin();
682 text_t::const_iterator saveconfend = saveconf.end();
683
684 while (saveconfhere != saveconfend) {
685 saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
686
687 if (!argname.empty()) {
688 // found another entry
689 argnameinfo = argsinfo.getarginfo (argname);
690
691 if (argnameinfo == NULL) {
692 // no information about the argument could be found
693 // we can't keep going because we don't know whether
694 // this argument is a single or multiple character value
695 logout << text_t2ascii << "Error: the cgi argument \"" << argname
696 << "\" was specified as being a compressed argument\n"
697 << "but no information about it could be found within the "
698 << "cgiargsinfoclass.\n";
699 compressed_args.clear();
700 return false;
701
702 } else {
703 // found the argument information
704 if (argnameinfo->multiplechar) {
705 // multiple character argument -- sort out any '-' chars
706 if (args["w"]=="utf-16be") // browsers don't like \0 in urls...
707 compressed_args += minus_safe (args[argname]);
708 else
709 compressed_args += minus_safe (outconvert.convert(args[argname]));
710
711 if (saveconfhere != saveconfend) compressed_args.push_back ('-');
712
713 } else {
714 // single character argument
715 if (args[argname].size() == 0) {
716 logout << text_t2ascii << "Error: the cgi argument \"" << argname
717 << "\" was specified as being a compressed argument which\n"
718 << "should have a one character value but it was empty.\n\n";
719 compressed_args.clear ();
720 return false;
721
722 } else if (args[argname].size() > 1) {
723 logout << text_t2ascii << "Error: the cgi argument \"" << argname
724 << "\" was specified as being a compressed argument which\n"
725 << "should have a one character value but it had multiple characters.\n\n";
726 compressed_args.clear ();
727 return false;
728 }
729
730 // everything is ok
731 compressed_args += args[argname];
732 }
733 }
734 }
735 }
736
737 return true;
738}
739
740
741// args_tounicode converts any arguments which are not in unicode
742// to unicode using inconvert
743void args_tounicode (cgiargsclass &args, inconvertclass &inconvert) {
744 cgiargsclass::iterator here = args.begin();
745 cgiargsclass::iterator end = args.end();
746
747 while (here != end) {
748 if ((*here).second.value.getencoding() > 0) {
749 (*here).second.value = inconvert.convert((*here).second.value);
750 }
751
752 ++here;
753 }
754}
755
756// fcgienv will be loaded with environment name-value pairs
757// if using fastcgi (had to do this as getenv doesn't work
758// with our implementation of fastcgi). if fcgienv is empty
759// we'll simply use getenv
760text_t gsdl_getenv (const text_t &name, text_tmap &fcgienv) {
761 if (fcgienv.empty()) {
762 char *n = name.getcstr();
763 char *v = getenv(n);
764 delete []n;
765 if (v != NULL) return v;
766 return g_EmptyText;
767
768 } else return fcgienv[name];
769}
Note: See TracBrowser for help on using the repository browser.