/********************************************************************** * * action.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * PUT COPYRIGHT NOTICE HERE * * $Id: action.cpp 158 1999-02-11 01:24:06Z rjmcnab $ * *********************************************************************/ /* $Log$ Revision 1.5 1999/02/11 01:24:04 rjmcnab Fixed a few compiler warnings. Revision 1.4 1999/02/08 01:27:59 rjmcnab Got the receptionist producing something using the statusaction. Revision 1.3 1999/02/05 10:42:41 rjmcnab Continued working on receptionist Revision 1.2 1999/02/04 10:00:53 rjmcnab Developed the idea of an "action" and having them define the cgi arguments which they need and how those cgi arguments function. Revision 1.1 1999/01/08 08:40:52 rjmcnab Moved from lib directory. Revision 1.1 1999/01/08 03:57:44 rjmcnab Initial revision */ #include "action.h" #include // define all the macros which are related to pages generated // by this action void action::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/, ostream &/*logout*/) { } action::action () { } action::~action () { } // returns the "a" argument value that will specify this action // this name should be short but does not have to be one character // long text_t action::get_action_name () { return "nzdl"; } // check_cgiargs should be called before get_cgihead_info, // define_external_macros, and do_action. If an error is found // a message will be written to logout, if the error is severe // then the function will return false and no page content // should be produced based on the arguments. bool action::check_cgiargs (cgiargsclass &/*args*/, ostream &/*logout*/) { return true; } // get_cgihead_info determines the cgi header information for // a set of cgi arguments. If response contains location then // response_data contains the redirect address. If reponse // contains content then reponse_data contains the content-type. // Note that images can now be produced by the receptionist. void action::get_cgihead_info (cgiargsclass &/*args*/, response_t &response, text_t &response_data, ostream &/*logout*/) { response = location; response_data = "http://www.nzdl.org"; } // define all the macros which might be used by other actions // to produce pages. These macros should be well documented. void action::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/, ostream &/*logout*/) { } // returns false if there was an error which prevented the action // from outputing anything. bool action::do_action (cgiargsclass &/*args*/, outconvertclass &/*outconvert*/, ostream &/*textout*/, ostream &/*logout*/) { return true; } // configure should be called once for each configuration line // the default version configures the default for any arguments // which this action uses void action::configure (const text_t &key, const text_tarray &cfgline) { cgiarginfo *info = NULL; if ((key == "argdefault") && (cfgline.size() == 2) && ((info = argsinfo.getarginfo(cfgline[0])) != NULL)) { if (info->defaultstatus <= cgiarginfo::config) { info->defaultstatus = cgiarginfo::config; info->argdefault = cfgline[1]; } } } actionmapclass::actionmapclass () { } // theaction becomes the property of this class after addaction // therefore theaction should always be created using new but // not deleted after the call to addaction. void actionmapclass::addaction (action *theaction) { // can't add a null action assert (theaction != NULL); if (theaction == NULL) return; // can't add an action with no name assert (!(theaction->get_action_name()).empty()); if ((theaction->get_action_name()).empty()) return; actionptr aptr; aptr.a = theaction; actionptrs[theaction->get_action_name()] = aptr; aptr.a = NULL; // control has passed on } // getaction will return NULL if the action could not be found action *actionmapclass::getaction (const text_t &key) { iterator here = actionptrs.find (key); if (here == actionptrs.end()) return NULL; return (*here).second.a; }