source: trunk/gsdl/src/recpt/statusaction.cpp@ 173

Last change on this file since 173 was 172, checked in by rjmcnab, 25 years ago

Merged sources.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1/**********************************************************************
2 *
3 * statusaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: statusaction.cpp 172 1999-02-25 21:59:02Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.6 1999/02/25 21:59:02 rjmcnab
15
16 Merged sources.
17
18 Revision 1.5 1999/02/21 22:33:58 rjmcnab
19
20 Lots of stuff :-)
21
22 Revision 1.4 1999/02/12 02:40:18 sjboddie
23
24 Added page action
25
26 Revision 1.3 1999/02/11 23:07:00 sjboddie
27
28 extended the status action
29
30 Revision 1.2 1999/02/11 01:24:06 rjmcnab
31
32 Fixed a few compiler warnings.
33
34 Revision 1.1 1999/02/11 01:01:27 rjmcnab
35
36 Initial revision.
37
38 */
39
40
41#include "statusaction.h"
42#include <assert.h>
43
44statusaction::statusaction () {
45 disabled = true;
46 recpt = NULL;
47
48 // this action uses cgi variable "a"
49 cgiarginfo arg_ainfo;
50 arg_ainfo.shortname = "a";
51 arg_ainfo.longname = "action";
52 arg_ainfo.multiplechar = true;
53 arg_ainfo.defaultstatus = cgiarginfo::weak;
54 arg_ainfo.argdefault = "status";
55 arg_ainfo.savedarginfo = cgiarginfo::must;
56
57 argsinfo.addarginfo (NULL, arg_ainfo);
58}
59
60statusaction::~statusaction () {
61}
62
63bool statusaction::check_cgiargs (cgiargsclass &/*args*/, ostream &/*logout*/) {
64 // don't want to check anything yet.
65 return true;
66}
67
68void statusaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
69 text_t &response_data, ostream &/*logout*/) {
70 response = content;
71 response_data = "text/html";
72}
73
74bool statusaction::do_action (cgiargsclass &args, recptproto */*collectproto*/,
75 displayclass &/*disp*/, outconvertclass &outconvert,
76 ostream &textout, ostream &/*logout*/) {
77 textout << outconvert << "<html>\n";
78 textout << outconvert << "<head>\n";
79 textout << outconvert << "<title>Status information</title>\n";
80 textout << outconvert << "</head>\n";
81 textout << outconvert << "<body>\n";
82 if (disabled) textout << outconvert << "<h2>Status disabled</h2>\n";
83 else {
84 textout << outconvert << "<h2>Receptionist configuration information</h2>\n";
85
86 if (recpt == NULL) {
87 textout << outconvert << "The status action does not contain information\n";
88 textout << outconvert << "about any receptionists. The method set_receptionist\n";
89 textout << outconvert << "was probably not called from the module which instantiated\n";
90 textout << outconvert << "this action.\n";
91
92 } else {
93 const recptconf &rcinfo = recpt->get_configinfo ();
94
95 textout << outconvert << "<table>\n";
96 textout << outconvert << "<tr valign=top><th>gsdlhome</th><td>\"" << rcinfo.gsdlhome
97 << "\"</td></tr>\n";
98 textout << outconvert << "<tr valign=top><th>collection</th><td>\"" << rcinfo.collection
99 << "\"</td></tr>\n";
100 textout << outconvert << "<tr valign=top><th>collectdir</th><td>\"" << rcinfo.collectdir
101 << "\"</td></tr>\n";
102 textout << outconvert << "<tr valign=top><th>httpimg</th><td>\"" << rcinfo.httpimg
103 << "\"</td></tr>\n";
104 textout << outconvert << "<tr valign=top><th>gwcgi</th><td>\"" << rcinfo.gwcgi
105 << "\"</td></tr>\n";
106
107
108 // macrofiles
109 textout << outconvert << "<tr valign=top><th>macrofiles</th><td>";
110 text_tarray::const_iterator macrohere = rcinfo.macrofiles.begin ();
111 text_tarray::const_iterator macroend = rcinfo.macrofiles.end ();
112 bool macrofirst = true;
113 while (macrohere != macroend) {
114 if (!macrofirst) textout << outconvert << ", ";
115 macrofirst = false;
116 textout << outconvert << "\"" << *macrohere << "\"";
117 macrohere++;
118 }
119 textout << outconvert << "</td></tr>\n";
120
121 // saveconf
122 textout << outconvert << "<tr valign=top><th>saveconf</th><td>\"" << rcinfo.saveconf
123 << "\"</td></tr>\n";
124
125 // arguments
126 cgiargsinfoclass *rcargsinfo = recpt->get_cgiargsinfo_ptr ();
127 if (rcargsinfo != NULL) {
128 textout << outconvert << "<tr valign=top><th>arguments</th><td>";
129
130 cgiargsinfoclass::const_iterator argsinfohere = rcargsinfo->begin ();
131 cgiargsinfoclass::const_iterator argsinfoend = rcargsinfo->end ();
132 bool argsinfofirst = true;
133 while (argsinfohere != argsinfoend) {
134 if (!argsinfofirst) textout << outconvert << ", ";
135 argsinfofirst = false;
136 textout << outconvert << "\"" << (*argsinfohere).second.shortname << "\"";
137 argsinfohere++;
138 }
139
140 textout << outconvert << "</td></tr>\n";
141 }
142
143 // actions
144 actionmapclass *actions = recpt->get_actionmap_ptr();
145 if (actions != NULL) {
146 textout << outconvert << "<tr valign=top><th>actions</th><td>";
147
148 actionptrmap::iterator actionshere = actions->begin ();
149 actionptrmap::iterator actionsend = actions->end ();
150 bool actionsfirst = true;
151 while (actionshere != actionsend) {
152 if (!actionsfirst) textout << outconvert << ", ";
153 actionsfirst = false;
154 assert ((*actionshere).second.a != NULL);
155 if ((*actionshere).second.a != NULL) {
156 textout << outconvert << "\"" << (*actionshere).second.a->get_action_name() << "\"";
157 }
158 actionshere++;
159 }
160
161 textout << outconvert << "</td></tr>\n";
162 }
163
164 // protocols
165 recptprotolistclass *protocols = recpt->get_recptprotolist_ptr ();
166 if (protocols != NULL) {
167 textout << outconvert << "<tr valign=top><th>protocols</th><td>";
168
169 recptprotolistclass::iterator protohere = protocols->begin ();
170 recptprotolistclass::iterator protoend = protocols->end ();
171 bool protofirst = true;
172 while (protohere != protoend) {
173 if (!protofirst) textout << outconvert << ", ";
174 protofirst = false;
175 if ((*protohere).p != NULL) {
176 textout << outconvert << "\"" << (*protohere).p->get_protocol_name() << "\"";
177 }
178 protohere++;
179 }
180
181 textout << outconvert << "</td></tr>\n";
182 }
183
184 // converters
185 convertinfoclass *converters = recpt->get_convertinfo_ptr ();
186 if (converters != NULL) {
187 textout << outconvert << "<tr valign=top><th>converters</th><td>";
188
189 convertinfoclass::iterator converthere = converters->begin ();
190 convertinfoclass::iterator convertend = converters->end ();
191 bool convertfirst = true;
192 while (converthere != convertend) {
193 if (!convertfirst) textout << outconvert << ", ";
194 convertfirst = false;
195 textout << outconvert << "\"" << (*converthere).second.name << "\"";
196 converthere++;
197 }
198
199 textout << outconvert << "</td></tr>\n";
200 }
201
202
203 textout << outconvert
204 << "</table>\n"
205 << "<hr>\n"
206 << "<h2>Argument information</h2>\n"
207 << "<table>";
208
209 // argument information
210 textout << outconvert << "<tr valign=top><th>short name</th><th>long name</th>"
211 << "<th>multiple char?</th>"
212 << "<th>default</th><th>default status</th><th>saved args</th>"
213 << "<th>current value</th></tr>\n";
214
215 cgiargsclass::const_iterator argshere = args.begin();
216 cgiargsclass::const_iterator argsend = args.end();
217 cgiarginfo *ainfo;
218
219 while (argshere != argsend) {
220 const text_t &aname = (*argshere).first;
221 textout << outconvert
222 << "<tr valign=top><td>" << aname << "</td>\n";
223
224 if ((rcargsinfo != NULL) &&
225 ((ainfo=rcargsinfo->getarginfo(aname)) != NULL)) {
226 textout << outconvert << "<td>" << ainfo->longname << "</td>\n";
227 if (ainfo->multiplechar) textout << outconvert << "<td>yes</td>\n";
228 else textout << outconvert << "<td>no</td>\n";
229 textout << outconvert << "<td>" << ainfo->argdefault << "</td>\n";
230 switch (ainfo->defaultstatus) {
231 case cgiarginfo::none: textout << outconvert << "<td>none</td>\n"; break;
232 case cgiarginfo::weak: textout << outconvert << "<td>weak</td>\n"; break;
233 case cgiarginfo::good: textout << outconvert << "<td>good</td>\n"; break;
234 case cgiarginfo::config: textout << outconvert << "<td>config</td>\n"; break;
235 case cgiarginfo::imperative: textout << outconvert << "<td>imperative</td>\n"; break;
236 }
237 switch (ainfo->savedarginfo) {
238 case cgiarginfo::mustnot: textout << outconvert << "<td>mustnot</td>\n"; break;
239 case cgiarginfo::can: textout << outconvert << "<td>can</td>\n"; break;
240 case cgiarginfo::must: textout << outconvert << "<td>must</td>\n"; break;
241 }
242 } else {
243 textout << outconvert << "<td colspan=5></td>\n";
244 }
245
246 textout << outconvert << "<td>\"" << (*argshere).second << "\"</td></tr>\n";
247
248 argshere ++;
249 }
250
251 textout << outconvert
252 << "</table>\n"
253 << "<hr>\n"
254 << "<h2>Action information</h2>\n"
255 << "<table>";
256
257 // action information
258 if (actions != NULL) {
259 textout << outconvert
260 << "<tr><th>action name</th><th>cgi arguments</th></tr>\n";
261
262 actionptrmap::iterator actionshere = actions->begin ();
263 actionptrmap::iterator actionsend = actions->end ();
264 while (actionshere != actionsend) {
265 assert ((*actionshere).second.a != NULL);
266 if ((*actionshere).second.a != NULL) {
267 textout << outconvert
268 << "<tr><td>" << (*actionshere).second.a->get_action_name()
269 << "</td><td>";
270
271 cgiargsinfoclass argsinfo = (*actionshere).second.a->getargsinfo();
272 cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
273 cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
274 bool aifirst = true;
275 while (argsinfohere != argsinfoend) {
276 if (!aifirst) textout << outconvert << ", ";
277 aifirst = false;
278 textout << outconvert << (*argsinfohere).second.shortname;
279 argsinfohere++;
280 }
281
282 textout << outconvert << "</td></tr>\n";
283 }
284 actionshere++;
285 }
286 }
287
288 textout << outconvert << "</table><hr>\n";
289 }
290 }
291
292 ifstream initin (GSDL_GSDLHOME "/etc/initout.txt");
293 if (initin) {
294 textout << outconvert << "<p>The initialisation error log, " GSDL_GSDLHOME "/etc/initout.txt, contains the\n";
295 textout << outconvert << "following information:\n\n";
296 text_t errorpage = "<p><pre>\n";
297
298 char c;
299 initin.get(c);
300 while (!initin.eof ()) {
301 errorpage.push_back(c);
302 initin.get(c);
303 }
304
305 errorpage += "</pre>\n";
306 initin.close();
307 textout << outconvert << errorpage;
308
309 } else {
310 textout << outconvert << "Couldn't read initialisation error log, " GSDL_GSDLHOME "/etc/initout.txt.\n";
311 }
312
313 ifstream errin (GSDL_GSDLHOME "/etc/errout.txt");
314 if (initin) {
315 textout << outconvert << "<p>The error log, " GSDL_GSDLHOME "/etc/errout.txt, contains the\n";
316 textout << outconvert << "following information:\n\n";
317 text_t errorpage = "<p><pre>\n";
318
319 char c;
320 errin.get(c);
321 while (!errin.eof ()) {
322 errorpage.push_back(c);
323 errin.get(c);
324 }
325
326 errorpage += "</pre>\n";
327 errin.close();
328 textout << outconvert << errorpage;
329
330 } else {
331 textout << outconvert << "Couldn't read error log, " GSDL_GSDLHOME "/etc/errout.txt.\n";
332 }
333
334 textout << outconvert << "</body>\n";
335 textout << outconvert << "</html>\n";
336
337 return true;
338}
339
340void statusaction::configure (const text_t &key, const text_tarray &cfgline) {
341 if ((key == "status") && (cfgline.size() == 1) &&
342 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
343 disabled = false;
344 } else {
345 // call the parent class to deal with the things which
346 // are not dealt with here
347 action::configure (key, cfgline);
348 }
349}
Note: See TracBrowser for help on using the repository browser.