source: trunk/gsdl/src/recpt/wizardaction.cpp@ 12082

Last change on this file since 12082 was 12082, checked in by sjboddie, 18 years ago

Minor changes to get thing compiling under windows. I'm using an old
version of cgiwrapper.cpp and librarymain.cpp to compile as cgicc still
needs to be sorted out under windows. There are still some portability
issues with depositoraction that need to be sorted out too, so I haven't
included it in win32.mak yet.

  • Property svn:keywords set to Author Date Id Revision
File size: 24.6 KB
Line 
1/**********************************************************************
2 *
3 * wizardaction.cpp --
4 * Copyright (C) 2000 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#include "gsdl_modules_cfg.h"
27
28// note that the wizardaction relies on having direct access to a
29// collections configuration file. this breaks the separation between
30// receptionist and collection server and so is not suitable (at least
31// in its current form) for use when collection servers are separate
32// from the receptionist (e.g. when using the CORBA protocol).
33
34// following line required to get fstream.filedesc() on darwin (Mac OS X)
35#define _STREAM_COMPAT 1
36// required for utsname on solaris???
37#define _XOPEN_SOURCE 1
38#define _XOPEN_SOURCE_EXTENDED 1
39
40#include "wizardaction.h"
41#include "OIDtools.h"
42#include "fileutil.h"
43#include "cfgread.h"
44#include "gsdltools.h"
45#include "gsdltimes.h"
46#include "nullproto.h"
47#include "argdb.h"
48#include "cgiutils.h"
49#include <stdio.h>
50#include <fcntl.h>
51
52#if !defined (__WIN32__)
53#include <sys/utsname.h>
54#include <unistd.h>
55#endif
56
57wizardaction::wizardaction () {
58
59 recpt = NULL;
60 disabled = true;
61 gsdlosc = NULL;
62 gsdlhomec = NULL;
63 pathc = NULL;
64
65 macro_prefix = "";
66}
67
68wizardaction::~wizardaction () {
69 if (gsdlosc != NULL) delete []gsdlosc;
70 if (gsdlhomec != NULL) delete []gsdlhomec;
71 if (pathc != NULL) delete []pathc;
72}
73
74void wizardaction::configure (const text_t &key, const text_tarray &cfgline) {
75
76 const text_t& action_name = get_action_name();
77
78 if ((key == action_name) && (cfgline.size() == 1) &&
79 (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
80 disabled = false;
81 } else {
82 // call the parent class to deal with the things which
83 // are not dealt with here
84 action::configure (key, cfgline);
85 }
86}
87
88
89bool wizardaction::init (ostream & /*logout*/) {
90
91 // set up GSDLOS, GSDLHOME and PATH environment variables
92 text_t gsdlos, path;
93 unsigned int path_separator = ':';
94#if defined (__WIN32__)
95 gsdlos = "windows";
96 path_separator = ';';
97
98 path = filename_cat (gsdlhome, "bin", "windows", "perl", "bin;");
99
100#else
101 struct utsname *buf = new struct utsname();
102 int i = uname (buf);
103 if (i == -1) gsdlos = "linux"; // uname failed
104 else gsdlos.setcstr (buf->sysname);
105 delete buf;
106 lc (gsdlos);
107#endif
108
109 pathc = getenv ("PATH");
110 path += filename_cat (gsdlhome, "bin", gsdlos);
111 path.push_back (path_separator);
112 path += filename_cat (gsdlhome, "bin", "script");
113 if (pathc != NULL) {
114 path.push_back (path_separator);
115 path += pathc;
116 }
117 path = "PATH=" + path;
118
119 gsdlos = "GSDLOS=" + gsdlos;
120 text_t setgsdlhome = "GSDLHOME=" + gsdlhome;
121
122 // these will be cleaned up in the destructor
123 gsdlosc = gsdlos.getcstr();
124 gsdlhomec = setgsdlhome.getcstr();
125 pathc = path.getcstr();
126
127 putenv (gsdlosc);
128 putenv (gsdlhomec);
129 putenv (pathc);
130
131 return true;
132}
133
134
135void wizardaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
136 response_t &response,text_t &response_data,
137 ostream &/*logout*/) {
138 response = content;
139 response_data = "text/html";
140}
141
142
143bool wizardaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
144 recptprotolistclass * /*protos*/, ostream &logout) {
145
146 text_t current_page = args["p"];
147
148 if (current_page != "intro" &&
149 current_page != "bildframe1" && current_page != "new" && current_page != "select") {
150 // update arguments that were saved to the harddrive
151 text_tmap saved_args;
152
153 // update the argdb database with any arguments that were set
154 // by previous page as denoted by prefix (eg. di1 or bc1)
155
156 cgiargsclass::const_iterator args_here = args.begin();
157 cgiargsclass::const_iterator args_end = args.end();
158
159 while (args_here != args_end) {
160 text_t args_name = (*args_here).first;
161
162 int prefix_len = macro_prefix.size();
163
164 text_t args_prefix = substr(args_name.begin(),args_name.begin()+prefix_len);
165
166 if (args_prefix == macro_prefix) {
167 saved_args[args_name] = args[args_name];
168 }
169 ++args_here;
170 }
171
172 text_t argfile = filename_cat(gsdlhome, "tmp", args[macro_prefix+"tmp"], "argdb.db");
173 argdb *args_on_disk = new argdb(argfile);
174 if (!args_on_disk->update_args(saved_args)) {
175 // error
176 logout << "wizardaction: argdb::update_args failed (" << argfile << ")\n";
177 }
178
179 // update args from argdb
180 saved_args.erase(saved_args.begin(), saved_args.end());
181 if (!args_on_disk->get_args(saved_args)) {
182 // error
183 logout << "wizardaction: argdb::get_args failed (" << argfile << ")\n";
184 }
185 delete args_on_disk;
186
187 text_tmap::iterator sa_here = saved_args.begin();
188 text_tmap::iterator sa_end = saved_args.end();
189 while (sa_here != sa_end) {
190 if (!(*sa_here).second.empty()) {
191 args[(*sa_here).first] = (*sa_here).second;
192 }
193 ++sa_here;
194 } bool first = true;
195
196 }
197
198 return true;
199}
200
201// tests if collection is write protected (currently just checks if
202// collect.cfg file is writable
203bool wizardaction::collection_protected (const text_t &collection) {
204 text_t cfgfile = filename_cat(gsdlhome, "collect", collection, "etc", "collect.cfg");
205 if (file_writable(cfgfile)) return false;
206 return true;
207}
208
209// set the _statusline_ macro
210void wizardaction::set_statusline (displayclass &disp, cgiargsclass &args, ostream & /*logout*/) {
211
212 // the build command creates .bld.download, .bld.import, and .bld.build files (in that
213 // order) and deletes them (also in that order) when each stage is complete. the .bld
214 // file is the concatenation of all these files.
215 text_t bld_file = filename_cat (gsdlhome, "tmp", args[macro_prefix+"tmp"], args[macro_prefix+"dirname"] + ".bld");
216 text_t statusline;
217
218 if (file_exists (bld_file + ".download")) {
219 statusline = "_collector:textdownloadingfiles_<br>\n";
220 statusline += dm_safe(file_tail(bld_file + ".download", 1, 0));
221 } else if (file_exists (bld_file + ".import")) {
222 statusline = "_collector:textimportingcollection_<br>\n";
223 statusline += dm_safe(file_tail(bld_file + ".import", 1, 0));
224 } else if (file_exists (bld_file + ".build")) {
225 statusline = "_collector:textbuildingcollection_<br>\n";
226 statusline += dm_safe(file_tail(bld_file + ".build", 1, 0));
227 } else {
228 statusline += "_collector:textcreatingcollection_<br>\n";
229 statusline += dm_safe(file_tail(bld_file, 1, 0));
230 }
231
232 disp.setmacro ("statusline", "collector", statusline);
233 disp.setmacro ("statusline", "depositor", statusline);
234}
235
236
237// if sw = 0 replace all carriage returns in intext with the string "\n"
238// else replace all occurances of "\n" with a carriage return
239text_t wizardaction::carriage_replace (const text_t &intext, int sw) {
240
241 text_t outtext;
242 text_t::const_iterator here = intext.begin();
243 text_t::const_iterator end = intext.end();
244 while (here != end) {
245 if (sw == 0) {
246 if (*here == '\n') {
247 if ((here+1) != end && *(here+1) == '\r') ++here;
248 outtext += "\\n";
249 } else if (*here == '\r') {
250 if ((here+1) != end && *(here+1) == '\n') ++here;
251 outtext += "\\n";
252 } else {
253 outtext.push_back (*here);
254 }
255 } else if (*here == '\\' && (here+1) != end && *(here+1) == 'n') {
256 outtext.push_back ('\n');
257 ++here;
258 } else {
259 outtext.push_back (*here);
260 }
261 ++here;
262 }
263 return outtext;
264}
265
266
267// create a short directory name from fullname
268text_t wizardaction::get_directory_name (const text_t &fullname) {
269
270 text_t shortname;
271 if (fullname.empty()) {
272 shortname = "coll";
273
274 } else {
275
276 // first make all lowercase and remove any dodgy characters
277 // (i.e. anything not [a-z]
278 text_t::const_iterator here = fullname.begin();
279 text_t::const_iterator end = fullname.end();
280 while (here != end) {
281 if ((*here >= 'A' && *here <= 'Z') || (*here >= 'a' && *here <= 'z') ||
282 (*here == ' ')) {
283 if (*here >= 'A' && *here <= 'Z') shortname.push_back (*here+32);
284 else if (*here == ' ') {
285 while ((*(here+1)) == ' ') ++here;
286 shortname.push_back (*here);
287 } else shortname.push_back (*here);
288 }
289 ++here;
290 }
291
292 text_tarray words;
293 splitchar (shortname.begin(), shortname.end(), ' ', words);
294 int num_words = words.size();
295
296 if (num_words == 0) {
297 shortname = "coll";
298
299 } else {
300
301 shortname.clear();
302 int use_words = (num_words <= 6) ? num_words : 6;
303 unsigned int substr_len = 6 / use_words;
304
305 for (int i = 0; i < use_words; ++i) {
306 if (words[i].size() < substr_len) shortname += words[i];
307 else shortname += substr (words[i].begin(), words[i].begin()+substr_len);
308 }
309 }
310 }
311
312 // check to see if shortname is unique
313 text_t fulldirname = filename_cat (gsdlhome, "collect", shortname);
314 if (directory_exists (fulldirname)) {
315 int version = 0;
316 text_t newname;
317 do {
318 ++version;
319 newname = shortname;
320 newname.push_back ('v');
321 newname.appendint (version);
322 fulldirname = filename_cat (gsdlhome, "collect", newname);
323 } while (directory_exists (fulldirname));
324
325 shortname = newname;
326 }
327
328 return shortname;
329}
330
331// assigns a temporary directory name for this collector session
332// and creates temporary directory
333// returns false if it couldn't create the directory
334bool wizardaction::assign_tmpname (cgiargsclass &args, ostream &logout) {
335
336 int i = 0;
337 text_t tmpname = "tbuild";
338 while (directory_exists (filename_cat (gsdlhome, "tmp", tmpname + text_t(i)))) {
339 ++i;
340 }
341 tmpname.appendint (i);
342
343 text_t fulltmpdir = filename_cat (gsdlhome, "tmp", tmpname);
344 if (!mk_dir (fulltmpdir)) {
345 outconvertclass text_t2ascii;
346 logout << text_t2ascii << "wizardaction::assign_tmpname unable to create directory ("
347 << fulltmpdir << ")\n";
348 return false;
349 }
350
351 args[macro_prefix + "tmp"] = tmpname;
352 return true;
353}
354
355// set the _fullnamemenu_ macro (and _warnindex_ and _selectedindex_ if
356// we're on the "srce" page)
357void wizardaction::set_fullnamemenu (displayclass &disp, cgiargsclass &args,
358 recptprotolistclass *protos, ostream &logout) {
359
360 if (recpt == NULL) {
361 logout << "ERROR (collectoraction::set_fullnamemenu): This action does not contain\n"
362 << " information about any receptionists. The method set_receptionist was\n"
363 << " probably not called from the module which instantiated this action.\n";
364 return;
365 }
366
367 text_t &current_page = args["p"];
368 text_t currentname = args[macro_prefix+"dirname"];
369 if (current_page == "srce") currentname = args[macro_prefix + "clonecol"];
370
371 text_tarray dirnames;
372 text_tarray fullnames;
373 vector<bool> write_protected;
374 text_tarray build_type;
375
376 bool is_selected = false;
377 int selected_index = 0;
378 int index = 0;
379
380 recptprotolistclass::iterator rprotolist_here = protos->begin();
381 recptprotolistclass::iterator rprotolist_end = protos->end();
382 while (rprotolist_here != rprotolist_end) {
383 if ((*rprotolist_here).p != NULL) {
384
385 // don't include z39.50 collections
386 comerror_t err = noError;
387 if ((*rprotolist_here).p->get_protocol_name (err) == "z3950proto") {
388 ++rprotolist_here;
389 continue;
390 }
391
392 text_tarray collist;
393 (*rprotolist_here).p->get_collection_list (collist, err, logout);
394 if (err == noError) {
395 text_tarray::iterator collist_here = collist.begin();
396 text_tarray::iterator collist_end = collist.end();
397 while (collist_here != collist_end) {
398 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
399 if (cinfo != NULL) {
400 text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
401 if (collectionname.empty()) {
402 collectionname = *collist_here;
403 }
404 dirnames.push_back(*collist_here);
405 fullnames.push_back(collectionname);
406 // check to see if the collection is writable
407 if (collection_protected (*collist_here)) write_protected.push_back(true);
408 else write_protected.push_back(false);
409
410 // remember build type for collection (mg, mgpp, lucene, ...)
411 // used to determine cgi arg 'ct' later on and minus option to 'build'
412 build_type.push_back(cinfo->buildType);
413
414 if (*collist_here == currentname) {
415 is_selected = true;
416 selected_index = index;
417 }
418 ++index;
419 }
420 ++collist_here;
421 }
422 }
423 }
424 ++rprotolist_here;
425 }
426
427 bool first = true;
428
429 text_t warnindex;
430 text_t fullnamemenu = "<select name=\""+macro_prefix+"dirname\" onChange=\"menuchange();\">\n";
431 text_t buildtype_jsarray = "var buildtype = new Array(";
432
433 fullnamemenu += "<option value=\"\">select collection ...</option>\n";
434 buildtype_jsarray += "\"\" ";
435
436 for (int i = 0; i < index; ++i) {
437 // don't want write protected collections in list on "change existing
438 // collection" page
439 if (write_protected[i] && current_page == "existing") continue;
440 fullnamemenu += "<option value=\"" + dirnames[i] + "\"";
441 if (is_selected && i == selected_index) {
442 fullnamemenu += " selected";
443 ++selected_index;
444 is_selected = false;
445 }
446 fullnamemenu.push_back ('>');
447 fullnamemenu += fullnames[i];
448 fullnamemenu.push_back ('\n');
449
450 buildtype_jsarray += ", \"" + build_type[i] + "\"";
451
452 first = false;
453 }
454 fullnamemenu += "</select>\n";
455
456 buildtype_jsarray += ");";
457
458 text_t action_name = get_action_name();
459 disp.setmacro ("fullnamemenu", action_name, fullnamemenu);
460 disp.setmacro ("buildtypearray", action_name, buildtype_jsarray);
461}
462
463// checks to see if any of the plugins in pluginset occur in
464// collections configuration file
465bool wizardaction::uses_weird_plugin (const text_t &collection) {
466
467 text_tset pluginset;
468 pluginset.insert ("HBPlug");
469
470 text_t cfgfile_content;
471 text_t cfgfile_name = filename_cat (gsdlhome, "collect", collection, "etc", "collect.cfg");
472 text_t pluginstr, pluginname;
473
474 if (read_file (cfgfile_name, cfgfile_content)) {
475 text_t::const_iterator here = cfgfile_content.begin();
476 text_t::const_iterator end = cfgfile_content.end();
477 while (here != end) {
478 here = findchar (here, end, 'p');
479 if (here == end) break;
480 if ((here+6 < end) && (substr (here, here+6) == "plugin")) {
481 getdelimitstr (here+6, end, '\n', pluginstr);
482 text_t::const_iterator hp = pluginstr.begin();
483 text_t::const_iterator ep = pluginstr.end();
484 bool found = false;
485 // remove any leading whitespace, trailing options etc.
486 while (hp != ep) {
487 if (*hp == '\t' || *hp == ' ' || *hp == '\n') {
488 if (found) break;
489 } else {
490 pluginname.push_back (*hp);
491 found = true;
492 }
493 ++hp;
494 }
495 text_tset::const_iterator it = pluginset.find (pluginname);
496 if (it != pluginset.end()) return true; // found matching plugin
497 pluginname.clear();
498 }
499 ++here;
500 }
501 }
502 return false;
503}
504
505void wizardaction::gsdl_build (cgiargsclass &args, ostream &logout) {
506
507 outconvertclass text_t2ascii;
508
509 //check to see if the tbuild directory exists
510 text_t tmpdir = filename_cat (gsdlhome, "tmp", args[macro_prefix+"tmp"]);
511 if (!directory_exists (tmpdir)) {
512 message = "tmpfail";
513 return;
514 }
515
516 //check to see if collection name specified
517 text_t &collection = args[macro_prefix+"dirname"];
518 if (collection.empty()) {
519 message = "nocollection";
520 return;
521 }
522
523 // check for a .build file - if it exists then we've already built
524 // the collection (or are in the process of building it)
525 text_t buildfile = filename_cat (tmpdir, ".build");
526 if (file_exists (buildfile)) {
527 return;
528 } else {
529 // create the .build file (this file is just a place holder to let any future
530 // pages know that we've already been here)
531 char *buildfilec = buildfile.getcstr();
532 ofstream bfile_out (buildfilec);
533 delete []buildfilec;
534 if (bfile_out) {
535 bfile_out << "collection building\n";
536 bfile_out.close();
537 } else {
538 message = "tmpfail";
539 return;
540 }
541 }
542
543 //FLAG!
544 const recptconf &rcinfo = recpt->get_configinfo ();
545
546 // create the event header file if LogEvents, EmailEvents or
547 // EmailUserEvents options are turned on.
548 bool logevents =
549 (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents ||
550 rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents ||
551 rcinfo.EmailUserEvents);
552 text_t ehead_file = filename_cat (tmpdir, "ehead.txt");
553 if (logevents) {
554 if (!create_event_header_file (ehead_file, args, logout)) {
555 logevents = false;
556 }
557 }
558
559 text_t collectdir = get_collectdir (args);
560
561 // set up build options
562 //text_t options = "-make_writable -remove_import -out \"";
563 text_t options = "-make_writable -out \"";
564 options += filename_cat (tmpdir, collection + ".bld");
565 options += "\" -collectdir \"" + collectdir + "\" -statsfile \"";
566 options += filename_cat(collectdir, collection, "etc", "import.log") + "\"";
567
568 if (args[macro_prefix+"esrce"] == 1) {
569 // we're adding data to an existing collection
570 options += " -save_archives -append -manifest";
571 }
572
573 text_tarray inputvalues, inputtypes;
574 splitchar (args[macro_prefix+"input"].begin(), args[macro_prefix+"input"].end(), ',', inputvalues);
575 splitchar (args[macro_prefix+"inputtype"].begin(), args[macro_prefix+"inputtype"].end(), ',', inputtypes);
576 int numvalues = inputvalues.size();
577 int numtypes = inputtypes.size();
578 for (int i = 0; i < numvalues; ++i) {
579 if (!inputvalues[i].empty()) {
580 text_t type = "file://"; // default
581 if (i < numtypes) type = inputtypes[i];
582 options += " -download \"" +
583 remove_trailing_slashes(type + format_url(decode_commas(inputvalues[i]))) + "\"";
584 }
585 }
586
587 if (logevents) {
588 if (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents)
589 options += " -log_events";
590 if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents) {
591 options += " -mail_server " + rcinfo.MailServer;
592 options += " -email_events " + rcinfo.maintainer;
593 if (rcinfo.EmailUserEvents) options += "," + args[macro_prefix+"contactemail"];
594 } else if (rcinfo.EmailUserEvents) {
595 options += " -mail_server " + rcinfo.MailServer;
596 options += " -email_events " + args[macro_prefix+"contactemail"];
597 }
598 options += " -event_header " + ehead_file;
599 }
600
601 text_t indextype = args[macro_prefix+"buildtype"];
602 if(indextype == "") {
603 indextype = "mg";
604 }
605 options += " -indextype \"" + indextype + "\"";
606
607 text_t optionfile = filename_cat (tmpdir, "build.opt");
608 char *optionfilec = optionfile.getcstr();
609 ofstream ofile_out (optionfilec);
610 delete []optionfilec;
611 if (!ofile_out) {
612 message = "tmpfail";
613 return;
614 }
615 ofile_out << text_t2ascii << options << "\n";
616 ofile_out.close();
617
618 // if we're altering an existing collection we need to kill off
619 // the existing collection server - we do this for the local library
620 // (and any other persistent version of the library) as the existing
621 // gdbm file can't be deleted while the collection server holds it open
622 if ((args[macro_prefix+"econf"] == 1) || (args[macro_prefix+"esrce"] == 1)) {
623 remove_colservr (collection, logout);
624 }
625
626 // set up the build command - build.bat has some issues with quoting
627 // on win2k when gsdlhome contains spaces so we'll avoid using
628 // "perl -S" here in favor of calling the "build" perl script explicitly
629 text_t build_cmd = "perl \"" + filename_cat (gsdlhome, "bin", "script", "build");
630 build_cmd += "\" -optionfile \"" + optionfile + "\" " + collection;
631
632 // run build command in background (i.e. asynchronously)
633 gsdl_system (build_cmd, false, logout);
634
635}
636
637void wizardaction::gsdl_cancel_build (cgiargsclass &args, ostream &logout) {
638 // I really wanted to do what this perl script does fromS within the library
639 // c++ code. I ran into some problems though (like how do you write a portable
640 // "rm -r" in c++?). One day I'll spend some time sorting it out ... maybe.
641 text_t cancel_cmd = "perl -S cancel_build.pl -collectdir \"";
642 cancel_cmd += filename_cat (gsdlhome, "tmp", args[macro_prefix+"tmp"]) + "\" ";
643 cancel_cmd += args[macro_prefix+"dirname"];
644 // To be on the safe side we'll make this a synchronous call
645 // so that all tidying up is done before the user has a chance
646 // to do anything else (like start rebuilding their collection).
647 // This means that for a big collection where there's lots of
648 // stuff to delete etc. it might take a while before the "build
649 // cancelled" page appears.
650 gsdl_system (cancel_cmd, true, logout);
651}
652
653text_t wizardaction::get_collectdir (cgiargsclass &args)
654{
655 if ((args[macro_prefix+"econf"] == 1) || (args[macro_prefix+"esrce"] == 1)) {
656 // we're adding to a collection in place
657 return filename_cat(gsdlhome, "collect");
658 }
659 else {
660 return filename_cat (gsdlhome, "tmp", args[macro_prefix+"tmp"]);
661 }
662}
663
664// create and initialize a new collection server and
665// add it to the null protocol.
666void wizardaction::create_colserver (const text_t &collection, ostream &logout) {
667
668 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
669 recptprotolistclass::iterator rprotolist_here = protos->begin();
670 recptprotolistclass::iterator rprotolist_end = protos->end();
671 while (rprotolist_here != rprotolist_end) {
672 comerror_t err = noError;
673 if ((*rprotolist_here).p != NULL) {
674 if ((*rprotolist_here).p->get_protocol_name (err) == "nullproto") {
675 // create collection server and add it to nullproto
676 (*rprotolist_here).p->add_collection (collection, recpt, gsdlhome, gsdlhome);
677 // make sure gsdlhome is configured
678 text_tarray tmp;
679 tmp.push_back (gsdlhome);
680 (*rprotolist_here).p->configure ("gsdlhome", tmp, err);
681 // re-initialize the null protocol
682 if (!(*rprotolist_here).p->init (err, logout)) {
683 logout << "wizardaction::create_colserver: nullproto init failed\n";
684 }
685 return;
686 }
687 }
688 ++rprotolist_here;
689 }
690
691 logout << "wizardaction::create_colserver: no valid nullproto found\n";
692}
693
694// delete a collection server from the null protocol
695void wizardaction::remove_colservr (const text_t &collection, ostream &logout) {
696
697 recpt->uncache_collection (collection);
698
699 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
700 recptprotolistclass::iterator rprotolist_here = protos->begin();
701 recptprotolistclass::iterator rprotolist_end = protos->end();
702 while (rprotolist_here != rprotolist_end) {
703 comerror_t err = noError;
704 if ((*rprotolist_here).p != NULL) {
705 if ((*rprotolist_here).p->get_protocol_name (err) == "nullproto") {
706 (*rprotolist_here).p->remove_collection (collection, logout);
707 return;
708 }
709 }
710 ++rprotolist_here;
711 }
712
713 logout << "wizardaction::create_colserver: no valid nullproto found\n";
714}
715
716bool wizardaction::create_event_header_file (const text_t &filename, cgiargsclass &args,
717 ostream &logout) {
718
719 outconvertclass text_t2ascii;
720 char *filenamec = filename.getcstr();
721 ofstream eheadfile (filenamec);
722 delete []filenamec;
723
724 if (eheadfile) {
725 eheadfile << text_t2ascii << get_event_header (args);
726 eheadfile.close();
727 return true;
728 }
729
730 logout << text_t2ascii << "wizardaction::create_event_header ERROR: Couldn't create "
731 << "Event Header file " << filename << ". Event logging disabled\n";
732 return false;
733}
734
735text_t wizardaction::get_event_header (cgiargsclass &args) {
736 text_t header = "Greenstone Username: " + args["un"] + "\n";
737 header += "Collection: " + args[macro_prefix+"dirname"] + "\n";
738 header += "Collection Creator: " + args[macro_prefix+"contactemail"] + "\n";
739 header += "GSDLHOME: " + gsdlhome + "\n";
740 header += "Build Location: " + get_collectdir(args) + "\n";
741
742 return header;
743}
744
745
746// format_url simply strips "http://", "ftp://", or "file://" off the
747// beginning of url if they're there
748text_t wizardaction::format_url (const text_t &url) {
749 text_t::const_iterator begin = url.begin();
750 text_t::const_iterator end = url.end();
751
752 if (url.size() >= 7) {
753 text_t prefix = substr(begin, begin+7);
754 if (prefix == "http://" || prefix == "file://") {
755 return substr(begin+7, end);
756 }
757 }
758 if (url.size() >= 6) {
759 if (substr(begin, begin+6) == "ftp://") {
760 return substr(begin+6, end);
761 }
762 }
763 return url;
764}
765
766text_t wizardaction::remove_trailing_slashes (text_t str) {
767
768 while (*(str.end()-1) == '\\') {
769 str.pop_back();
770 }
771 return str;
772}
773
Note: See TracBrowser for help on using the repository browser.