Ignore:
Timestamp:
1999-02-08T14:28:04+13:00 (25 years ago)
Author:
rjmcnab
Message:

Got the receptionist producing something using the statusaction.

File:
1 edited

Legend:

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

    r150 r155  
    1212/*
    1313   $Log$
     14   Revision 1.3  1999/02/08 01:28:00  rjmcnab
     15
     16   Got the receptionist producing something using the statusaction.
     17
    1418   Revision 1.2  1999/02/05 10:42:43  rjmcnab
    1519
     
    9296
    9397// split up the cgi arguments
    94 void parse_cgi_args (text_t argstr, cgiargsclass &args) {
     98void split_cgi_args (text_t argstr, cgiargsclass &args) {
    9599  args.clear();
    96100 
     
    143147  return outtext;
    144148}
     149
     150
     151
     152
     153static text_t::const_iterator get_next_save_arg (text_t::const_iterator first,
     154                       text_t::const_iterator last,
     155                       text_t &argname) {
     156  first = getdelimitstr (first, last, '-', argname);
     157  return first;
     158}
     159
     160
     161// check_save_conf_str checks the configuration string for
     162// the saved args and makes sure it does not conflict with
     163// the information about the arguments. If an error is encountered
     164// it will return false and the program should not produce any
     165// output.
     166bool check_save_conf_str (const text_t &saveconf,
     167              const cgiargsinfoclass &argsinfo,
     168              ostream &logout) {
     169  outconvertclass text_t2ascii;
     170
     171  text_tset argsset;
     172  text_t::const_iterator saveconfhere = saveconf.begin ();
     173  text_t::const_iterator saveconfend = saveconf.end ();
     174  text_t argname;
     175  const cgiarginfo *info;
     176
     177  // first check to make sure all saved arguments can be saved
     178 
     179  while (saveconfhere != saveconfend) {
     180    saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
     181
     182    if (!argname.empty()) {
     183      // save the argument name for later
     184      argsset.insert (argname);
     185
     186      // check the argument
     187      info =  argsinfo.getarginfo (argname);
     188      if (info == NULL) {
     189    logout << text_t2ascii << "Error: the cgi argument \"" << argname
     190           << "\" is used in the configuration string for the\n"
     191           << "saved arguments but does not exist as a valid argument.\n\n";
     192    return false;
     193      }
     194      if (info->savedarginfo == cgiarginfo::mustnot) {
     195    logout << text_t2ascii << "Error: the cgi argument \"" << argname
     196           << "\" is used in the configuration string for the\n"
     197           << "saved arguments but has been specified as an argument whose\n"
     198           << "state must not be saved.\n\n";
     199    return false;
     200      }
     201    }
     202  }
     203
     204
     205  // next check that all saved arguments that should be saved
     206  // are saved
     207  cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
     208  cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
     209
     210  while (argsinfohere != argsinfoend) {
     211    if (((*argsinfohere).second.savedarginfo == cgiarginfo::must) &&
     212    (argsset.find((*argsinfohere).second.shortname) == argsset.end())) {
     213      logout << text_t2ascii << "Error: the cgi argument \""
     214         << (*argsinfohere).second.shortname << "\" was specified as needing to\n"
     215         << "be save but was not listed in the saved arguments.\n\n";
     216      return false;
     217    }
     218
     219    argsinfohere++;
     220  }
     221 
     222  return true; // made it, no clashes
     223}
     224
     225
     226// create_save_conf_str will create a configuration string
     227// based on the information in argsinfo. This method of configuration
     228// is not recomended as small changes can produce large changes in
     229// the resulting configuration string (for instance a totally different
     230// ordering). Only arguments which "must" be saved are included in
     231// the resulting string.
     232text_t create_save_conf_str (const cgiargsinfoclass &argsinfo,
     233                 ostream &/*logout*/) {
     234  cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
     235  cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
     236  text_t saveconf;
     237  bool first = true;
     238
     239  while (argsinfohere != argsinfoend) {
     240    // save this argument if it must be saved
     241    if ((*argsinfohere).second.savedarginfo == cgiarginfo::must) {
     242      if (!first) saveconf.push_back ('-');
     243      else first = false;
     244      saveconf += (*argsinfohere).second.shortname;
     245    }
     246
     247    argsinfohere++;
     248  }
     249 
     250  return saveconf;
     251}
     252
     253
     254// expand_save_args will expand the saved arguments based
     255// on saveconf placing the results in args if they are not
     256// already defined. If it encounters an error it will return false
     257// and output more information to logout.
     258bool expand_save_args (const cgiargsinfoclass &argsinfo,
     259               const text_t &saveconf,
     260               cgiargsclass &args,
     261               ostream &logout) {
     262  outconvertclass text_t2ascii;
     263
     264  text_t *arg_e = args.getarg("e");
     265  if (arg_e == NULL) return true; // no compressed arguments
     266  if (arg_e->empty()) return true; // no compressed arguments
     267
     268  text_t argname, argvalue;
     269  const cgiarginfo *argnameinfo;
     270 
     271  text_t::const_iterator saveconfhere = saveconf.begin();
     272  text_t::const_iterator saveconfend = saveconf.end();
     273 
     274  text_t::iterator arg_ehere = arg_e->begin();
     275  text_t::iterator arg_eend = arg_e->end();
     276  while (saveconfhere != saveconfend && arg_ehere != arg_eend) {
     277    saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
     278
     279    if (!argname.empty()) {
     280      // found another entry
     281      argnameinfo = argsinfo.getarginfo (argname);
     282
     283      if (argnameinfo == NULL) {
     284    // no information about the argument could be found
     285    // we can't keep going because we don't know whether
     286    // this argument is a single or multiple character value
     287    logout << text_t2ascii << "Error: the cgi argument \"" << argname
     288           << "\" was specified as being a compressed argument\n"
     289           << "but no information about it could be found within the "
     290           << "cgiargsinfoclass.\n";
     291    return false;
     292
     293      } else {
     294    // found the argument information
     295    if (argnameinfo->multiplechar) {
     296      arg_ehere = getdelimitstr (arg_ehere, arg_eend, '-', argvalue);
     297      if (!argvalue.empty()) args.setdefaultarg (argname, argvalue);
     298    } else {
     299      args.setdefaultcarg (argname,*arg_ehere);
     300      arg_ehere++;
     301    }
     302      }
     303    }
     304  }
     305
     306  return true;
     307}
     308
     309
     310// adds the default values for those arguments which have not
     311// been specified
     312void add_default_args (const cgiargsinfoclass &argsinfo,
     313               cgiargsclass &args,
     314               ostream &/*logout*/) {
     315  cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
     316  cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
     317
     318  while (argsinfohere != argsinfoend) {
     319    if ((*argsinfohere).second.defaultstatus != cgiarginfo::none) {
     320      args.setdefaultarg ((*argsinfohere).second.shortname,
     321              (*argsinfohere).second.argdefault);
     322    }
     323    argsinfohere++;
     324  }
     325}
     326
     327
     328// compress_save_args will compress the arguments and return
     329// them in compressed_args. If an error was encountered
     330// compressed_args will be set to to "", an error will be
     331// written to logout, and the function will return false.
     332bool compress_save_args (const cgiargsinfoclass &argsinfo,
     333             const text_t &saveconf,
     334             cgiargsclass &args,
     335             text_t &compressed_args,
     336             ostream &logout) {
     337  outconvertclass text_t2ascii;
     338
     339  compressed_args.clear();
     340
     341  text_t argname, argvalue;
     342  const cgiarginfo *argnameinfo;
     343 
     344  text_t::const_iterator saveconfhere = saveconf.begin();
     345  text_t::const_iterator saveconfend = saveconf.end();
     346 
     347  while (saveconfhere != saveconfend) {
     348    saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
     349
     350    if (!argname.empty()) {
     351      // found another entry
     352      argnameinfo = argsinfo.getarginfo (argname);
     353
     354      if (argnameinfo == NULL) {
     355    // no information about the argument could be found
     356    // we can't keep going because we don't know whether
     357    // this argument is a single or multiple character value
     358    logout << text_t2ascii << "Error: the cgi argument \"" << argname
     359           << "\" was specified as being a compressed argument\n"
     360           << "but no information about it could be found within the "
     361           << "cgiargsinfoclass.\n";
     362    compressed_args.clear();
     363    return false;
     364
     365      } else {
     366    // found the argument information
     367    if (argnameinfo->multiplechar) {
     368      // multiple character argument
     369      compressed_args += args[argname];
     370      if (saveconfhere != saveconfend) compressed_args.push_back ('-');
     371
     372    } else {
     373      // single character argument
     374      if (args[argname].size() == 0) {
     375        logout << text_t2ascii << "Error: the cgi argument \"" << argname
     376           << "\" was specified as being a compressed argument which\n"
     377           << "should have a one character value but it was empty.\n\n";
     378        compressed_args.clear ();
     379        return false;
     380
     381      } else if (args[argname].size() > 1) {
     382        logout << text_t2ascii << "Error: the cgi argument \"" << argname
     383           << "\" was specified as being a compressed argument which\n"
     384           << "should have a one character value but it had multiple characters.\n\n";
     385        compressed_args.clear ();
     386        return false;
     387      }
     388
     389      // everything is ok
     390      compressed_args += args[argname];
     391    }
     392      }
     393    }
     394  }
     395
     396  return true;
     397}
     398
     399
     400// args_tounicode converts any arguments which are not in unicode
     401// to unicode using inconvert
     402void args_tounicode (cgiargsclass &args, inconvertclass &inconvert) {
     403  cgiargsclass::iterator here = args.begin();
     404  cgiargsclass::iterator end = args.end();
     405
     406  while (here != end) {
     407    if ((*here).second.getencoding() > 0) {
     408      (*here).second = inconvert.convert((*here).second);
     409    }
     410   
     411    here++;
     412  }
     413}
Note: See TracChangeset for help on using the changeset viewer.