Changeset 12512


Ignore:
Timestamp:
2006-08-24T11:06:42+12:00 (18 years ago)
Author:
kjdon
Message:

Added Stefan's fileupload code to replace use of cgicc by depositor. Changed the signature of some methods; added fileupload_t; cgiargsclass now has fileupload_t variable; cgiargsinfoclass now has 'bool fileupload' variable; added some more debug print methods; in addarginfo, if logout is null I write the error message to stderr

Location:
trunk/gsdl/src/recpt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/cgiargs.cpp

    r9620 r12512  
    3232  value.clear();
    3333  source = program_arg;
     34  fileupload.clear();
    3435}
    3536
     
    5051}
    5152
     53
     54void fileupload_t::clear() {
     55  name.clear();
     56  type.clear();
     57  size = 0;
     58  tmp_name.clear();
     59}
     60
     61ostream &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}
    5268
    5369
     
    96112}
    97113
     114void 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
    98121text_t *cgiargsclass::getarg (const text_t &key) {
    99122  iterator here = args.find (key);
     
    108131  return text->getint();
    109132}
     133
     134fileupload_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
    110140
    111141
     
    134164  multiplechar = false;
    135165  multiplevalue = false;
     166  fileupload = false;
    136167  defaultstatus = weak;
    137168  argdefault.clear();
     
    145176      (x.multiplechar == y.multiplechar) &&
    146177      (x.multiplevalue == y.multiplevalue) &&
     178      (x.fileupload == y.fileupload) &&
    147179      (x.defaultstatus == y.defaultstatus) &&
    148180      (x.argdefault == y.argdefault) &&
     
    157189         ((x.multiplevalue < y.multiplevalue) ||
    158190          ((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))))))))))))))));
    166200}
    167201
     
    173207// addarginfo will combine the information with the present
    174208// information. If name clashes were detected then the information
    175 // will be written to logout and addarginfo will return false. No
     209// will be written to logout (or stderr) and addarginfo will return false. No
    176210// processing with the arguments should be done if this happens
    177211// as the results will be meaningless.
    178 bool cgiargsinfoclass::addarginfo (ostream *logout, const cgiarginfo &info) {
    179 
     212bool 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  }
    180222  cgiarginfo *orginfo = getarginfo (info.shortname);
    181223  if (orginfo == NULL) {
     
    185227
    186228  if (orginfo->longname != info.longname) {
    187     if (logout != NULL) {
    188       outconvertclass text_t2ascii;
     229    outconvertclass text_t2ascii;
     230    if (logout != NULL) {
    189231      (*logout) << text_t2ascii << "Error: cgi argument name clash for argument \""
    190232        << info.shortname << "\".\nOne long name was\n  \"" << orginfo->longname
    191233        << "\"\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";
    192238    }
    193239    return false; // found a clash
     
    195241
    196242  if (orginfo->multiplevalue != info.multiplevalue) {
    197     if (logout != NULL) {
    198       outconvertclass text_t2ascii;
     243    outconvertclass text_t2ascii;
     244    if (logout != NULL) {
    199245      (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname
    200246        << "\" was given as being a single value option\n"
    201247        << "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";
    202252    }
    203253    return false; // found a clash
    204254  }
    205255
     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
    206270  if (orginfo->multiplechar != info.multiplechar) {
    207     if (logout != NULL) {
    208       outconvertclass text_t2ascii;
     271    outconvertclass text_t2ascii;
     272    if (logout != NULL) {
    209273      (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname
    210274        << "\" was given as being a single character option\n"
    211275        << "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    }
    213281    return false; // found a clash
    214282  }
    215283 
    216284  if (!info.multiplechar && info.argdefault.size() > 1) {
    217     if (logout != NULL) {
    218       outconvertclass text_t2ascii;
     285    outconvertclass text_t2ascii;
     286    if (logout != NULL) {
    219287      (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname
    220288        << "\" was defined as being a single character option\n"
    221289        << "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";
    222294    }
    223295    return false;  // found a problem
     
    229301      (orginfo->savedarginfo==cgiarginfo::must &&
    230302       info.savedarginfo==cgiarginfo::mustnot)) {
    231     if (logout != NULL) {
    232       outconvertclass text_t2ascii;
     303    outconvertclass text_t2ascii;
     304    if (logout != NULL) {
    233305      (*logout) << text_t2ascii << "Error: it was specified that cgi argument \""
    234306        << info.shortname << "\" should be saved in the state\n"
    235307        << "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";
    236312    }
    237313    return false; // found a clash
     
    252328}
    253329
    254 bool cgiargsinfoclass::addarginfo (ostream *logout, const cgiargsinfoclass &info) {
    255   const_iterator here = info.begin ();
    256   const_iterator end = info.end ();
     330bool cgiargsinfoclass::addarginfo (ostream *logout, cgiargsinfoclass &info) {
     331 
     332  iterator here = info.begin ();
     333  iterator end = info.end ();
    257334
    258335  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    }
    260340    ++here;
    261341  }
     
    299379}
    300380
    301 bool cgiargsinfoclass::addarginfo (ostream *logout, const confcgiarg_tmap& info)
     381bool cgiargsinfoclass::addarginfo (ostream *logout, confcgiarg_tmap& info)
    302382{
    303383  confcgiarg_tmap::const_iterator thisArg = info.begin();
     
    323403  return &((*here).second);
    324404}
     405
     406// stream operators to print cgiarginfo for debugging purposes
     407ostream &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  
    5353enum response_t {location, content, fullcontent, undecided_location};
    5454
     55struct 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
     65typedef map<text_t, fileupload_t, lttext_t> fileupload_tmap;
    5566
    5667struct cgiarg_t {
     
    6374  text_t value;
    6475  source_t source;
    65 };
     76  fileupload_t fileupload;
     77};
     78
     79ostream &operator<<(ostream &outs, const fileupload_t &fu);
    6680
    6781bool operator==(const cgiarg_t &x, const cgiarg_t &y);
     
    126140  void setdefaultcarg (const text_t &key, unsigned short c,
    127141               cgiarg_t::source_t source=cgiarg_t::default_arg);
     142  void setargfile (const text_t &key, const fileupload_t &fileupload);
    128143  text_t *getarg (const text_t &key);
    129144  int getintarg (const text_t &key);
     145  fileupload_t *getargfile (const text_t &key);
    130146  text_t &operator[] (const text_t &key) {return args[key].value;}
    131147  cgiarg_t &lookupcgiarg (const text_t &key) {return args[key];}
     
    157173  // use the same name)
    158174  bool multiplevalue;
     175
     176  // fileupload should be set if the argument is to be used to upload files
     177  bool fileupload;
    159178
    160179  // defaultstatus_t indicates how good the default is when different
     
    224243  // processing with the arguments should be done if this happens
    225244  // as the results will be meaningless.
    226   bool addarginfo (ostream *logout, const cgiarginfo &info);
    227   bool addarginfo (ostream *logout, const cgiargsinfoclass &info);
     245  bool addarginfo (ostream *logout, cgiarginfo &info);
     246  bool addarginfo (ostream *logout, cgiargsinfoclass &info);
    228247
    229248  // addarginfo will override args info with info loaded from config files
    230249  // if the args do not exists will be created
    231250  bool addarginfo (ostream *logout, const text_t& argshortname, const text_tmap& mapinfo);
    232   bool addarginfo (ostream *logout, const confcgiarg_tmap& info);
     251  bool addarginfo (ostream *logout, confcgiarg_tmap& info);
    233252
    234253  cgiarginfo *getarginfo (const text_t &key);
     
    237256};
    238257
     258ostream &operator<<(ostream &outs, const cgiargsinfoclass &argsinfo);
    239259
    240260#endif
Note: See TracChangeset for help on using the changeset viewer.