Changeset 146


Ignore:
Timestamp:
1999-02-04T23:00:57+13:00 (25 years ago)
Author:
rjmcnab
Message:

Developed the idea of an "action" and having them define the cgi arguments
which they need and how those cgi arguments function.

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

Legend:

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

    r108 r146  
    1212/*
    1313   $Log$
     14   Revision 1.2  1999/02/04 10:00:53  rjmcnab
     15
     16   Developed the idea of an "action" and having them define the cgi arguments
     17   which they need and how those cgi arguments function.
     18
    1419   Revision 1.1  1999/01/08 08:40:52  rjmcnab
    1520
     
    2227 */
    2328
    24 static char *RCSID = "$Id$";
     29
     30#include "action.h"
     31#include <assert.h>
    2532
    2633
    27 #include "action.h"
     34action::action () {
     35}
     36
     37action::~action () {
     38}
     39
     40// returns the "a" argument value that will specify this action
     41// this name should be short but does not have to be one character
     42// long
     43text_t action::get_action_name () {
     44  return "nzdl";
     45}
     46
     47// get_cgihead_info determines the cgi header information for
     48// a set of cgi arguments. If response contains location then
     49// response_data contains the redirect address. If reponse
     50// contains content then reponse_data contains the content-type.
     51// Note that images can now be produced by the receptionist.
     52void action::get_cgihead_info (cgiargsclass &args, response_t &response,
     53                   text_t &response_data, ostream &logout) {
     54  response = location;
     55  response_data = "http://www.nzdl.org";
     56}
     57 
     58// returns false if there was an error which prevented the action
     59// from outputing anything.
     60bool action::do_action (cgiargsclass &args, outconvertclass &outconvert,
     61            ostream &textout, ostream &logout) {
     62  return true;
     63}
     64
     65// configure should be called once for each configuration line
     66void action::configure (const text_tarray &cfgline) {
     67}
    2868
    2969
    3070
     71// theaction becomes the property of this class after addaction
     72// therefore theaction should always be created using new but
     73// not deleted after the call to addaction.
     74void actionmapclass::addaction (action *theaction) {
     75  // can't add a null action
     76  assert (theaction != NULL);
     77  if (theaction == NULL) return;
     78 
     79  // can't add an action with no name
     80  assert (!(theaction->get_action_name()).empty());
     81  if ((theaction->get_action_name()).empty()) return;
    3182
     83  actionptr aptr;
     84  aptr.a = theaction;
     85  actionptrs[theaction->get_action_name()] = aptr;
     86}
     87
     88// getaction will return NULL if the action could not be found
     89action *actionmapclass::getaction (const text_t &key) {
     90  iterator here = actionptrs.find (key);
     91  if (here == actionptrs.end()) return NULL;
     92 
     93  return (*here).second.a;
     94}
  • trunk/gsdl/src/recpt/action.h

    r108 r146  
    1414#define ACTION_H
    1515
     16#include "gsdlconf.h"
     17#include "text_t.h"
     18#include "cgiargs.h"
    1619
     20#if defined(GSDL_USE_OBJECTSPACE)
     21#  include <ospace\std\iostream>
     22#elif defined(GSDL_USE_IOS_H)
     23#  include <iostream.h>
     24#else
     25#  include <iostream>
     26#endif
     27
     28
     29class action {
     30protected:
     31  cgiargsinfoclass argsinfo;
     32
     33public:
     34  action ();
     35  virtual ~action ();
     36
     37  // returns the "a" argument value that will specify this action
     38  // this name should be short but does not have to be one character
     39  // long
     40  virtual text_t get_action_name ();
     41
     42  // response_t is used to inform the calling code what type of
     43  // cgi header it should produce
     44  // eventually this should reside in cgiutils.h
     45  enum response_t {location, content};
     46
     47  // get_cgihead_info determines the cgi header information for
     48  // a set of cgi arguments. If response contains location then
     49  // response_data contains the redirect address. If reponse
     50  // contains content then reponse_data contains the content-type.
     51  // Note that images can now be produced by the receptionist.
     52  virtual void get_cgihead_info (cgiargsclass &args, response_t &response,
     53                 text_t &response_data, ostream &logout);
     54 
     55  // returns false if there was an error which prevented the action
     56  // from outputing anything.
     57  virtual bool do_action (cgiargsclass &args, outconvertclass &outconvert,
     58              ostream &textout, ostream &logout);
     59
     60  // configure should be called once for each configuration line
     61  virtual void configure (const text_tarray &cfgline);
     62
     63  // getargsinfo should be called after all configuration files
     64  // have been read
     65  cgiargsinfoclass getargsinfo () {return argsinfo;};
     66};
     67
     68
     69// actionptr is used to keep track of pointers to actions
     70// sub classes of action might not be the same size so
     71// you probably don't want to treat a sub class as a standard
     72// "action" class when it comes to copying etc -- anyone got
     73// a better way to do this ????
     74class actionptr {
     75public:
     76  action *a;
     77
     78  actionptr () {a=NULL;}
     79  ~actionptr () {if (a!=NULL) delete a; a=NULL;}
     80};
     81
     82typedef map<text_t, actionptr, lttext_t> actionptrmap;
     83
     84// contains a list of actions indexed by their name
     85class actionmapclass {
     86protected:
     87  actionptrmap actionptrs;
     88
     89public:
     90  // type support for actionptrmap
     91  typedef actionptrmap::iterator iterator;
     92  typedef actionptrmap::const_iterator const_iterator;
     93  typedef actionptrmap::reference reference;
     94  typedef actionptrmap::const_reference const_reference;
     95  typedef actionptrmap::size_type size_type;
     96
     97  typedef actionptrmap::difference_type difference_type;
     98  typedef actionptrmap::const_reverse_iterator const_reverse_iterator;
     99  typedef actionptrmap::reverse_iterator reverse_iterator;
     100 
     101  // constructors
     102  actionmapclass ();
     103
     104  // basic container support
     105  iterator begin () {return actionptrs.begin();}
     106  const_iterator begin () const {return actionptrs.begin();}
     107  iterator end () {return actionptrs.end();}
     108  const_iterator end () const {return actionptrs.end();}
     109
     110  void erase(iterator pos) {actionptrs.erase(pos);}
     111  void erase(iterator first, iterator last) {actionptrs.erase(first, last);}
     112  actionmapclass &operator=(const actionmapclass &x) {actionptrs=x.actionptrs;return *this;}
     113
     114  bool empty () const {return actionptrs.empty();}
     115  size_type size() const {return actionptrs.size();}
     116
     117
     118  // added functionality
     119  void clear () {actionptrs.erase(actionptrs.begin(),actionptrs.end());}
     120
     121  // theaction becomes the property of this class after addaction
     122  // therefore theaction should always be created using new but
     123  // not deleted after the call to addaction.
     124  void addaction (action *theaction);
     125
     126  // getaction will return NULL if the action could not be found
     127  action *getaction (const text_t &key);
     128};
    17129
    18130
  • trunk/gsdl/src/recpt/cgiargs.cpp

    r112 r146  
    1212/*
    1313   $Log$
     14   Revision 1.3  1999/02/04 10:00:54  rjmcnab
     15
     16   Developed the idea of an "action" and having them define the cgi arguments
     17   which they need and how those cgi arguments function.
     18
    1419   Revision 1.2  1999/01/12 01:51:06  rjmcnab
    1520
     
    3237 
    3338// constructors
    34 cgiargsclass::cgiargsclass ()
    35 {
     39cgiargsclass::cgiargsclass () {
    3640}
    3741
     
    110114
    111115
     116
     117cgiarginfo::cgiarginfo () {
     118  multiplechar = false;
     119  defaultstatus = weak;
     120}
     121
     122 
     123// constructor
     124cgiargsinfoclass::cgiargsinfoclass () {
     125}
     126
     127// addarginfo will combine the information with the present
     128// information. If name clashes were detected then the information
     129// will be written to logout and addarginfo will return false. No
     130// processing with the arguments should be done if this happens
     131// as the results will be meaningless.
     132bool cgiargsinfoclass::addarginfo (ostream &logout, const cgiarginfo &info) {
     133  outconvertclass text_t2ascii;
     134
     135  cgiarginfo *orginfo = getarginfo (info.shortname);
     136  if (orginfo == NULL) {
     137    argsinfo[info.shortname] = info;
     138    return true; // no clashes
     139  }
     140
     141  if (orginfo->longname != info.longname) {
     142    logout << text_t2ascii << "Error: cgi argument name clash for argument \""
     143       << info.shortname << "\".\nOne long name was\n  \"" << orginfo->longname
     144       << "\"\nand the other was\n  \"" << info.longname << "\".\n\n";
     145    return false; // found a clash
     146  }
     147
     148  if (orginfo->multiplechar != info.multiplechar) {
     149    logout << text_t2ascii << "Error: cgi argument \"" << info.shortname
     150       << "\" was given as being a single character option\n"
     151       << "and a multiple character option.\n\n";
     152    return false; // found a clash
     153  }
     154
     155  if (!info.multiplechar && info.argdefault.size() > 1) {
     156    logout << text_t2ascii << "Error: cgi argument \"" << info.shortname
     157       << "\" was defined as being a single character option\n"
     158       << "but a multiple character default was given.\n\n";
     159  }
     160
     161  if (orginfo->defaultstatus > info.defaultstatus) {
     162    return true;
     163  }
     164
     165  orginfo->defaultstatus = info.defaultstatus;
     166  orginfo->argdefault = info.argdefault;
     167  return true;
     168}
     169
     170bool cgiargsinfoclass::addarginfo (ostream &logout, const cgiargsinfoclass &info) {
     171  const_iterator here = info.begin ();
     172  const_iterator end = info.end ();
     173
     174  while (here != end) {
     175    if (!addarginfo (logout, (*here).second)) return false;
     176    here++;
     177  }
     178 
     179  return true; // made it, no clashes
     180}
     181
     182cgiarginfo *cgiargsinfoclass::getarginfo (const text_t &key) {
     183  iterator here = argsinfo.find (key);
     184  if (here == argsinfo.end()) return NULL;
     185
     186  return &((*here).second);
     187}
     188
  • trunk/gsdl/src/recpt/cgiargs.h

    r114 r146  
    3434
    3535
     36
    3637typedef map<text_t, text_t, lttext_t> textmap;
    3738
    38 
     39// cgiargsclass is used to store a particular set
     40// of cgi arguments.
    3941class cgiargsclass
    4042{
     
    9092};
    9193
    92 
    9394// stream operators to print cgi arguments for debugging purposes
    9495ostream &operator<<(ostream &outs, const cgiargsclass &args);
    9596
    9697
     98
     99// cgiarginfo holds information relating to a cgi argument
     100class cgiarginfo {
     101public:
     102  cgiarginfo ();
     103
     104  // shortname is the name used in cgi arguments
     105  text_t shortname;
     106
     107  // longname is the name used when giving information
     108  // about the argument and to spot name duplication
     109  text_t longname;
     110
     111  // multiplechar should be set to true if the value can be
     112  // more than one character long
     113  bool multiplechar;
     114
     115  // defaultstatus_t indicates how good the default is when different
     116  // defaults are given for one argument. "weak" is a basic guess that doesn't
     117  // hold much weight, "good" is a better guess, "config" was a default
     118  // given in a configuration file, and "imperative" means it must not
     119  // be overriden at any costs (unless there is another "imperative"...)
     120  // Note: I assume that the comparison weak < good < config < imperative
     121  // holds :-/
     122  enum defaultstatus_t {weak, good, config, imperative};
     123
     124  defaultstatus_t defaultstatus;
     125  text_t argdefault;   // a default value
     126};
     127
     128
     129typedef map<text_t, cgiarginfo, lttext_t> argsinfomap;
     130
     131// contains a list of cgi argument information
     132class cgiargsinfoclass {
     133protected:
     134  argsinfomap argsinfo;
     135
     136public:
     137  // type support for arginfomap
     138  typedef argsinfomap::iterator iterator;
     139  typedef argsinfomap::const_iterator const_iterator;
     140  typedef argsinfomap::reference reference;
     141  typedef argsinfomap::const_reference const_reference;
     142  typedef argsinfomap::size_type size_type;
     143  typedef argsinfomap::difference_type difference_type;
     144  typedef argsinfomap::const_reverse_iterator const_reverse_iterator;
     145  typedef argsinfomap::reverse_iterator reverse_iterator;
     146 
     147  // constructors
     148  cgiargsinfoclass ();
     149
     150  // basic container support
     151  iterator begin () {return argsinfo.begin();}
     152  const_iterator begin () const {return argsinfo.begin();}
     153  iterator end () {return argsinfo.end();}
     154  const_iterator end () const {return argsinfo.end();}
     155
     156  void erase(iterator pos) {argsinfo.erase(pos);}
     157  void erase(iterator first, iterator last) {argsinfo.erase(first, last);}
     158  cgiargsinfoclass &operator=(const cgiargsinfoclass &x) {argsinfo=x.argsinfo;return *this;}
     159
     160  bool empty () const {return argsinfo.empty();}
     161  size_type size() const {return argsinfo.size();}
     162
     163
     164  // added functionality
     165  void clear () {argsinfo.erase(argsinfo.begin(),argsinfo.end());}
     166
     167  // addarginfo will combine the information with the present
     168  // information. If name clashes were detected then the information
     169  // will be written to logout and addarginfo will return false. No
     170  // processing with the arguments should be done if this happens
     171  // as the results will be meaningless.
     172  bool addarginfo (ostream &logout, const cgiarginfo &info);
     173  bool addarginfo (ostream &logout, const cgiargsinfoclass &info);
     174
     175  cgiarginfo *getarginfo (const text_t &key);
     176  cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];}
     177};
     178
     179
     180
    97181#endif
  • trunk/gsdl/src/recpt/cgiwrapper.cpp

    r144 r146  
    1212/*
    1313   $Log$
     14   Revision 1.2  1999/02/04 10:00:56  rjmcnab
     15
     16   Developed the idea of an "action" and having them define the cgi arguments
     17   which they need and how those cgi arguments function.
     18
    1419   Revision 1.1  1999/02/04 01:16:17  rjmcnab
    1520
     
    223228  // initialise the library software
    224229  ofstream initout (GSDL_GSDLHOME "/etc/initout.txt");
    225   if (!recpt.init(initout)) {
     230  if (!recpt.digest(initout)) {
    226231    // an error occurred during the initialisation
    227232    initout.close();
  • trunk/gsdl/src/recpt/receptionist.cpp

    r145 r146  
    1212/*
    1313   $Log$
     14   Revision 1.3  1999/02/04 10:00:56  rjmcnab
     15
     16   Developed the idea of an "action" and having them define the cgi arguments
     17   which they need and how those cgi arguments function.
     18
    1419   Revision 1.2  1999/02/04 01:17:27  rjmcnab
    1520
     
    7378// meaningless output), instead an error page should be
    7479// produced by the calling code.
    75 bool receptionist::init (ostream &logout) {
     80bool receptionist::digest (ostream &logout) {
    7681  // redirect the error output to logout
    77   disp.setlogout (&logout);
     82  //  disp.setlogout (&logout);
    7883
    7984  // set default values for the configuration file
    80   cfg_info.defaultaction = "p";
    81   cfg_info.defaultpage = "about";
    82   cfg_info.defaultencoding = "w";
     85  //  cfg_info.defaultaction = "p";
     86  //  cfg_info.defaultpage = "about";
     87  //  cfg_info.defaultencoding = "w";
    8388
    8489  // read in the configuration files etc/collect.cfg and index/build.cfg
    8590  // entries in build.cfg should override those in collect.cfg
    86   filename = filename_cat (collectdir, "etc");
    87   filename = filename_cat (filename, "collect.cfg");
    88   cfg_read(filename);
     91  //  filename = filename_cat (collectdir, "etc");
     92  //  filename = filename_cat (filename, "collect.cfg");
     93  //  cfg_read(filename);
    8994
    9095  // load up the default macro files, the collection directory
    9196  // is searched first for the file and then the main directory
    92   text_t colmacrodir = filename_cat (collectdir, "macros");
    93   text_t gsdlmacrodir = filename_cat (gsdlhome, "macros");
    94   text_tarray::iterator arrhere = cfg_info.macrofiles.begin();
    95   text_tarray::iterator arrend = cfg_info.macrofiles.end();
    96   while (arrhere != arrend) {
    97     filename = filename_cat (colmacrodir, *arrhere);
    98     if (!file_exists (filename)) {
    99       filename = filename_cat (gsdlmacrodir, *arrhere);
    100     }
    101     disp.loaddefaultmacros(filename);
    102     arrhere++;
    103   }
     97  //  text_t colmacrodir = filename_cat (collectdir, "macros");
     98  //  text_t gsdlmacrodir = filename_cat (gsdlhome, "macros");
     99  //  text_tarray::iterator arrhere = cfg_info.macrofiles.begin();
     100  //  text_tarray::iterator arrend = cfg_info.macrofiles.end();
     101  //  while (arrhere != arrend) {
     102  //    filename = filename_cat (colmacrodir, *arrhere);
     103  //    if (!file_exists (filename)) {
     104  //      filename = filename_cat (gsdlmacrodir, *arrhere);
     105  //    }
     106  //    disp.loaddefaultmacros(filename);
     107  //    arrhere++;
     108  //  }
    104109
    105   srand(time(NULL));
     110  //  srand(time(NULL));
    106111
    107   utf8outconvert.set_rzws(1);
    108   gboutconvert.set_rzws(1);
     112  //  utf8outconvert.set_rzws(1);
     113  //  gboutconvert.set_rzws(1);
    109114
    110   return collect_init(collection);
     115  //  return collect_init(collection);
     116  return true;
    111117}
    112118
     
    134140// contains content then reponse_data contains the content-type.
    135141// Note that images can now be produced by the receptionist.
    136 void receptionist::get_cgihead_info (const cgiargsclass &args, response_t &response,
     142void receptionist::get_cgihead_info (cgiargsclass &args, response_t &response,
    137143                     text_t &response_data, ostream &logout) {
    138144}
     
    140146
    141147// produce the page content
    142 void receptionist::produce_content (const cgiargsclass &args, ostream &contentout,
     148void receptionist::produce_content (cgiargsclass &args, ostream &contentout,
    143149                    ostream &logout) {
    144150}
  • trunk/gsdl/src/recpt/receptionist.h

    r145 r146  
    4747  void set_gwcgi (const text_t &thegwcgi);
    4848
    49   // init should be called after setgsdhome has been called.
     49  // digest should be called after setgsdhome has been called.
    5050  // It returns true on success and false on failure. If false is
    5151  // returned getpage should not be called (without producing
    5252  // meaningless output), instead an error page should be
    5353  // produced by the calling code.
    54   bool init (ostream &logout);
     54  bool digest (ostream &logout);
    5555 
    5656  // There are two ways to produce a page. You can either call parse_cgi_args,
     
    7373  // response_t is used to inform the calling code what type of
    7474  // cgi header it should produce
     75  // eventually this should reside in cgiutils.h
    7576  enum response_t {location, content};
    7677
     
    8081  // contains content then reponse_data contains the content-type.
    8182  // Note that images can now be produced by the receptionist.
    82   void get_cgihead_info (const cgiargsclass &args, response_t &response,
     83  void get_cgihead_info (cgiargsclass &args, response_t &response,
    8384             text_t &response_data, ostream &logout);
    8485
    8586  // produce the page content
    86   void produce_content (const cgiargsclass &args, ostream &contentout,
     87  void produce_content (cgiargsclass &args, ostream &contentout,
    8788            ostream &logout);
    8889
Note: See TracChangeset for help on using the changeset viewer.