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