source: main/trunk/greenstone2/runtime-src/src/recpt/wizardaction.cpp@ 21324

Last change on this file since 21324 was 21324, checked in by ak19, 14 years ago

Changes to makefiles, configure files, and source code to work with the new configure flags that allow indexers to be individually compiled up by setting each indexer to be enabled or disabled (enable-mg, enable-mgpp, enable-lucene)

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