source: trunk/gsdl/src/recpt/configaction.cpp@ 4290

Last change on this file since 4290 was 4290, checked in by sjboddie, 21 years ago

Added a "configaction" to allow new collection servers to be added to and
removed from a persistent version of greenstone (i.e. the local library)
while it's still running. Without this you need to restart the server in
order for it to notice any new collections that may have appeared.
Use "?a=config&cmd=add-collection&c=colname" to create and configure a
collection server for the "colname" collection.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/**********************************************************************
2 *
3 * configaction.cpp --
4 * Copyright (C) 2003 DL Consulting Ltd
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
27#include "configaction.h"
28#include "recptconfig.h"
29
30configaction::configaction () {
31
32 recpt = NULL;
33
34 cgiarginfo arg_ainfo;
35 arg_ainfo.shortname = "a";
36 arg_ainfo.longname = "action";
37 arg_ainfo.multiplechar = true;
38 arg_ainfo.defaultstatus = cgiarginfo::weak;
39 arg_ainfo.argdefault = "config";
40 arg_ainfo.savedarginfo = cgiarginfo::must;
41 argsinfo.addarginfo (NULL, arg_ainfo);
42
43 /*
44 The cmd argument may be one of the following:
45 -- release-collection - release the collection specified by the "c"
46 argument
47 -- add-collection - add and configure a collection server for the
48 collection specified by the "c" argument
49 */
50 arg_ainfo.shortname = "cmd";
51 arg_ainfo.longname = "config command";
52 arg_ainfo.multiplechar = true;
53 arg_ainfo.defaultstatus = cgiarginfo::weak;
54 arg_ainfo.argdefault = "configure-all";
55 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
56 argsinfo.addarginfo (NULL, arg_ainfo);
57}
58
59configaction::~configaction () {
60}
61
62void configaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
63 response_t &response, text_t &response_data,
64 ostream &logout) {
65 response = content;
66 response_data = "text/html";
67}
68
69bool configaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
70 browsermapclass *browsers, displayclass &disp,
71 outconvertclass &outconvert, ostream &textout,
72 ostream &logout) {
73
74 if (recpt == NULL) return false;
75
76 if ((args["cmd"] == "add-collection") && (!args["c"].empty())) {
77 create_colservr(args["c"], logout);
78 textout << "configured add-collection\n";
79
80 } else if ((args["cmd"] == "release-collection") && (!args["c"].empty())) {
81 remove_colservr(args["c"], logout);
82 textout << "configured release-collection\n";
83
84 }
85
86 return true;
87}
88
89
90// create and initialize a new collection server and
91// add it to the null protocol.
92void configaction::create_colservr (const text_t &collection, ostream &logout) {
93
94 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
95 recptprotolistclass::iterator rprotolist_here = protos->begin();
96 recptprotolistclass::iterator rprotolist_end = protos->end();
97 while (rprotolist_here != rprotolist_end) {
98 comerror_t err = noError;
99 if ((*rprotolist_here).p != NULL) {
100 if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
101 // create collection server and add it to nullproto
102 (*rprotolist_here).p->add_collection(collection, recpt, gsdlhome, gsdlhome);
103 // re-initialize the null protocol
104 if (!(*rprotolist_here).p->init(err, logout)) {
105 logout << "configaction::create_colservr: nullproto init failed\n";
106 }
107 return;
108 }
109 }
110 rprotolist_here ++;
111 }
112
113 logout << "configaction::create_colservr: no valid nullproto found\n";
114}
115
116// delete a collection server from the null protocol
117void configaction::remove_colservr (const text_t &collection, ostream &logout) {
118
119 recpt->uncache_collection(collection);
120
121 recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
122 recptprotolistclass::iterator rprotolist_here = protos->begin();
123 recptprotolistclass::iterator rprotolist_end = protos->end();
124 while (rprotolist_here != rprotolist_end) {
125 comerror_t err = noError;
126 if ((*rprotolist_here).p != NULL) {
127 if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
128 (*rprotolist_here).p->remove_collection(collection, logout);
129 return;
130 }
131 }
132 rprotolist_here ++;
133 }
134
135 logout << "configaction::create_colserver: no valid nullproto found\n";
136}
Note: See TracBrowser for help on using the repository browser.