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

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