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

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

Reorganised the statusaction, added more functions to comtypes.

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