[108] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * receptionist.h -- a web interface for the gsdl
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * PUT COPYRIGHT NOTICE HERE
|
---|
| 7 | *
|
---|
| 8 | * $Id: receptionist.h 189 1999-03-05 03:53:56Z sjboddie $
|
---|
| 9 | *
|
---|
| 10 | *********************************************************************/
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | #ifndef RECEPTIONIST_H
|
---|
| 14 | #define RECEPTIONIST_H
|
---|
| 15 |
|
---|
[145] | 16 | #include "gsdlconf.h"
|
---|
[108] | 17 | #include "text_t.h"
|
---|
| 18 | #include "cgiargs.h"
|
---|
[155] | 19 | #include "display.h"
|
---|
| 20 | #include "action.h"
|
---|
[165] | 21 | #include "recptproto.h"
|
---|
| 22 | #include "converter.h"
|
---|
[108] | 23 |
|
---|
| 24 | #ifndef MACROPRECEDENCE
|
---|
| 25 | #define MACROPRECEDENCE "style,collection,queryversion,version,language"
|
---|
| 26 | #endif
|
---|
| 27 |
|
---|
| 28 |
|
---|
[165] | 29 | struct recptconf {
|
---|
| 30 | text_t gsdlhome;
|
---|
| 31 | text_t collection; // will equal "" in 'general' mode
|
---|
| 32 | text_t collectdir; // will equal gsdlhome in 'general' mode
|
---|
| 33 | text_t httpimg;
|
---|
| 34 | text_t gwcgi;
|
---|
| 35 | text_tarray macrofiles;
|
---|
| 36 | text_t saveconf;
|
---|
| 37 | };
|
---|
| 38 |
|
---|
| 39 |
|
---|
[108] | 40 | class receptionist {
|
---|
[165] | 41 | protected:
|
---|
| 42 | recptconf configinfo;
|
---|
| 43 |
|
---|
| 44 | cgiargsinfoclass argsinfo;
|
---|
| 45 | actionmapclass actions;
|
---|
| 46 | recptprotolistclass protocols;
|
---|
| 47 | displayclass disp;
|
---|
| 48 | convertinfoclass converters;
|
---|
[173] | 49 | // prepare_page sets up page parameters, sets display macros
|
---|
| 50 | // and opens the page ready for output
|
---|
| 51 | void prepare_page (action *a, cgiargsclass &args, recptproto *collectproto,
|
---|
[189] | 52 | ostream &logout);
|
---|
| 53 | void define_general_macros (cgiargsclass &args, ostream &logout);
|
---|
[165] | 54 |
|
---|
[108] | 55 | public:
|
---|
[145] | 56 | receptionist () {}
|
---|
[108] | 57 | virtual ~receptionist() {}
|
---|
| 58 |
|
---|
[165] | 59 | // add_action makes another action available to the receptionist
|
---|
| 60 | // the action remains the property of the calling code and that
|
---|
| 61 | // code should destroy the action after the recptionist has been
|
---|
| 62 | // destroyed.
|
---|
| 63 | void add_action (action *theaction) {actions.addaction(theaction);}
|
---|
| 64 | actionmapclass *get_actionmap_ptr () {return &actions;}
|
---|
[108] | 65 |
|
---|
[165] | 66 | // add_protocol makes another protocol available to the receptionist
|
---|
| 67 | // without any protocols, no collections will be available. The
|
---|
| 68 | // protocols remain the property of the calling code.
|
---|
| 69 | void add_protocol (recptproto *theprotocol) {protocols.addrecptproto(theprotocol);}
|
---|
| 70 | recptprotolistclass *get_recptprotolist_ptr () {return &protocols;}
|
---|
| 71 |
|
---|
| 72 | // add_converter makes another converter available to the receptionist.
|
---|
| 73 | // Converters are needed to display pages using different encodings.
|
---|
| 74 | // The converters remain the property of the calling code.
|
---|
| 75 | void add_converter (const text_t &name, inconvertclass *inconverter,
|
---|
| 76 | rzwsoutconvertclass *outconverter)
|
---|
| 77 | {converters.add_converter(name, inconverter, outconverter);}
|
---|
| 78 | convertinfoclass *get_convertinfo_ptr () {return &converters;}
|
---|
[108] | 79 |
|
---|
[145] | 80 |
|
---|
[165] | 81 | // configure should be called for each line in the
|
---|
| 82 | // configuration files to configure the receptionist and everything
|
---|
| 83 | // it contains. The configuration should take place after everything
|
---|
| 84 | // has been added but before the initialisation.
|
---|
| 85 | void configure (const text_t &key, const text_tarray &cfgline);
|
---|
| 86 | void configure (const text_t &key, const text_t &value);
|
---|
| 87 | const recptconf &get_configinfo () {return configinfo;}
|
---|
| 88 | cgiargsinfoclass *get_cgiargsinfo_ptr () {return &argsinfo;}
|
---|
| 89 |
|
---|
[108] | 90 |
|
---|
[165] | 91 | // init should be called after all the actions, protocols, and
|
---|
| 92 | // converters have been added to the receptionist and after everything
|
---|
| 93 | // has been configured but before any pages are created.
|
---|
[108] | 94 | // It returns true on success and false on failure. If false is
|
---|
| 95 | // returned getpage should not be called (without producing
|
---|
| 96 | // meaningless output), instead an error page should be
|
---|
| 97 | // produced by the calling code.
|
---|
[150] | 98 | bool init (ostream &logout);
|
---|
[108] | 99 |
|
---|
| 100 | // There are two ways to produce a page. You can either call parse_cgi_args,
|
---|
[155] | 101 | // get_cgihead_info, and produce_content or you can just call parse_cgi_args and
|
---|
| 102 | // produce_cgi_page (which will be satisfactory in most cases). You might want to call
|
---|
[108] | 103 | // parse_cgi_args, get_cgihead_info, and produce_content when you want to
|
---|
[155] | 104 | // interface directly with a web server for which the standard header is inappropriate.
|
---|
[108] | 105 |
|
---|
| 106 | // parse_cgi_args parses cgi arguments into an argument class.
|
---|
[155] | 107 | // This function should be called for each page request. It returns false
|
---|
| 108 | // if there was a major problem with the cgi arguments.
|
---|
| 109 | bool parse_cgi_args (const text_t &argstr, cgiargsclass &args, ostream &logout);
|
---|
[108] | 110 |
|
---|
[155] | 111 | // produce_cgi_page will call get_cgihead_info and
|
---|
| 112 | // produce_content in the appropriate way to output a cgi header and
|
---|
| 113 | // the page content (if needed). If a page could not be created it
|
---|
| 114 | // will return false
|
---|
| 115 | bool produce_cgi_page (cgiargsclass &args, ostream &contentout,
|
---|
| 116 | ostream &logout);
|
---|
[108] | 117 |
|
---|
| 118 | // get_cgihead_info determines the cgi header information for
|
---|
| 119 | // a set of cgi arguments. If response contains location then
|
---|
| 120 | // response_data contains the redirect address. If reponse
|
---|
| 121 | // contains content then reponse_data contains the content-type.
|
---|
| 122 | // Note that images can now be produced by the receptionist.
|
---|
[146] | 123 | void get_cgihead_info (cgiargsclass &args, response_t &response,
|
---|
[108] | 124 | text_t &response_data, ostream &logout);
|
---|
| 125 |
|
---|
| 126 | // produce the page content
|
---|
[155] | 127 | bool produce_content (cgiargsclass &args, ostream &contentout,
|
---|
[108] | 128 | ostream &logout);
|
---|
| 129 |
|
---|
| 130 | // returns the compressed argument ("e") corresponding to the argument
|
---|
| 131 | // list. This can be used to save preferences between sessions.
|
---|
[145] | 132 | text_t get_compressed_arg (const cgiargsclass &args);
|
---|
[108] | 133 |
|
---|
| 134 | protected:
|
---|
[155] | 135 | // will read in all the macro files. If one is not found an
|
---|
| 136 | // error message will be written to logout and the method will
|
---|
| 137 | // return false.
|
---|
| 138 | bool read_macrofiles (ostream &logout);
|
---|
[108] | 139 |
|
---|
[155] | 140 | // Will define the main general arguments used by the receptionist.
|
---|
| 141 | // If an error occurs a message will be written to logout and the
|
---|
| 142 | // method will return false.
|
---|
| 143 | virtual bool define_mainargs (ostream &logout);
|
---|
| 144 |
|
---|
| 145 | // check_mainargs will check all the main arguments. If a major
|
---|
| 146 | // error is found it will return false and no cgi page should
|
---|
| 147 | // be created using the arguments.
|
---|
| 148 | virtual bool check_mainargs (cgiargsclass &args, ostream &logout);
|
---|
[108] | 149 | };
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | #endif
|
---|