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