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 |
|
---|
30 | #ifdef GSDL_LOCAL_LIBRARY
|
---|
31 | // for PostMessage()
|
---|
32 | # include <windows.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | configaction::configaction () {
|
---|
36 |
|
---|
37 | recpt = NULL;
|
---|
38 |
|
---|
39 | cgiarginfo arg_ainfo;
|
---|
40 | arg_ainfo.shortname = "a";
|
---|
41 | arg_ainfo.longname = "action";
|
---|
42 | arg_ainfo.multiplechar = true;
|
---|
43 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
44 | arg_ainfo.argdefault = "config";
|
---|
45 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
46 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
47 |
|
---|
48 | /*
|
---|
49 | The cmd argument may be one of the following:
|
---|
50 | -- release-collection - release the collection specified by the "c"
|
---|
51 | argument
|
---|
52 | -- add-collection - add and configure a collection server for the
|
---|
53 | collection specified by the "c" argument
|
---|
54 | -- kill - if running as the local library this will kill the server
|
---|
55 | */
|
---|
56 | arg_ainfo.shortname = "cmd";
|
---|
57 | arg_ainfo.longname = "config command";
|
---|
58 | arg_ainfo.multiplechar = true;
|
---|
59 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
60 | arg_ainfo.argdefault = g_EmptyText;
|
---|
61 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
62 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
63 | }
|
---|
64 |
|
---|
65 | configaction::~configaction () {
|
---|
66 | }
|
---|
67 |
|
---|
68 | void configaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
|
---|
69 | response_t &response, text_t &response_data,
|
---|
70 | ostream &logout) {
|
---|
71 | response = content;
|
---|
72 | response_data = "text/html";
|
---|
73 | }
|
---|
74 |
|
---|
75 | bool configaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
|
---|
76 | browsermapclass *browsers, displayclass &disp,
|
---|
77 | outconvertclass &outconvert, ostream &textout,
|
---|
78 | ostream &logout) {
|
---|
79 |
|
---|
80 | if (recpt == NULL) return false;
|
---|
81 |
|
---|
82 | if ((args["cmd"] == "add-collection") && (!args["c"].empty())) {
|
---|
83 | create_colservr(args["c"], logout);
|
---|
84 | textout << "configured add-collection\n";
|
---|
85 |
|
---|
86 | } else if ((args["cmd"] == "release-collection") && (!args["c"].empty())) {
|
---|
87 | remove_colservr(args["c"], logout);
|
---|
88 | textout << "configured release-collection\n";
|
---|
89 |
|
---|
90 | } else if (args["cmd"] == "kill") {
|
---|
91 | textout << "killed\n";
|
---|
92 | #ifdef GSDL_LOCAL_LIBRARY
|
---|
93 | HWND gw = FindWindow("Greenstone Digital Library Software",
|
---|
94 | "Greenstone Digital Library Software");
|
---|
95 | PostMessage(gw, WM_DESTROY, 0, 0);
|
---|
96 | #endif
|
---|
97 | }
|
---|
98 |
|
---|
99 | return true;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | // create and initialize a new collection server and
|
---|
104 | // add it to the null protocol.
|
---|
105 | void configaction::create_colservr (const text_t &collection, ostream &logout) {
|
---|
106 |
|
---|
107 | // just in case we're adding a collection that already exists
|
---|
108 | recpt->uncache_collection(collection);
|
---|
109 |
|
---|
110 | recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
|
---|
111 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
112 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
113 | while (rprotolist_here != rprotolist_end) {
|
---|
114 | comerror_t err = noError;
|
---|
115 | if ((*rprotolist_here).p != NULL) {
|
---|
116 | if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
|
---|
117 | // create collection server and add it to nullproto
|
---|
118 | (*rprotolist_here).p->add_collection(collection, recpt, gsdlhome, gsdlhome);
|
---|
119 | // re-initialize the null protocol
|
---|
120 | if (!(*rprotolist_here).p->init(err, logout)) {
|
---|
121 | logout << "configaction::create_colservr: nullproto init failed\n";
|
---|
122 | }
|
---|
123 | return;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | ++rprotolist_here;
|
---|
127 | }
|
---|
128 |
|
---|
129 | logout << "configaction::create_colservr: no valid nullproto found\n";
|
---|
130 | }
|
---|
131 |
|
---|
132 | // delete a collection server from the null protocol
|
---|
133 | void configaction::remove_colservr (const text_t &collection, ostream &logout) {
|
---|
134 |
|
---|
135 | recpt->uncache_collection(collection);
|
---|
136 |
|
---|
137 | recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
|
---|
138 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
139 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
140 | while (rprotolist_here != rprotolist_end) {
|
---|
141 | comerror_t err = noError;
|
---|
142 | if ((*rprotolist_here).p != NULL) {
|
---|
143 | if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
|
---|
144 | (*rprotolist_here).p->remove_collection(collection, logout);
|
---|
145 | return;
|
---|
146 | }
|
---|
147 | }
|
---|
148 | ++rprotolist_here;
|
---|
149 | }
|
---|
150 |
|
---|
151 | logout << "configaction::create_colserver: no valid nullproto found\n";
|
---|
152 | }
|
---|