1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * nullproto.cpp --
|
---|
4 | * Copyright (C) 1999 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 "nullproto.h"
|
---|
27 | #include <assert.h>
|
---|
28 |
|
---|
29 | #include "filter.h"
|
---|
30 | #include "browsefilter.h"
|
---|
31 |
|
---|
32 | #include "fileutil.h"
|
---|
33 | // for read_file
|
---|
34 |
|
---|
35 | nullproto::nullproto() {
|
---|
36 | cset = NULL;
|
---|
37 | }
|
---|
38 |
|
---|
39 | nullproto::~nullproto() {
|
---|
40 | }
|
---|
41 |
|
---|
42 | // add collection to collectset (this should not be called until after the
|
---|
43 | // collectset has been added to the protocol with set_collectset()
|
---|
44 | void nullproto::add_collection (const text_t &collection, void *recpt,
|
---|
45 | const text_t &gsdlhome, const text_t& collecthome,
|
---|
46 | const text_t &dbhome)
|
---|
47 | {
|
---|
48 |
|
---|
49 | if (cset != NULL) {
|
---|
50 | this->cset->add_collection (collection, gsdlhome, collecthome);
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | // remove_collection deletes the collection server of collection.
|
---|
56 | // This only needs to be called if a collectionserver is to be
|
---|
57 | // removed while the library is running. The destructor function
|
---|
58 | // cleans up all collectservers when the program exits.
|
---|
59 | void nullproto::remove_collection (const text_t &collection, ostream &logout) {
|
---|
60 | cset->remove_collection(collection, logout);
|
---|
61 | }
|
---|
62 |
|
---|
63 | // this configure will configure each of the collection servers
|
---|
64 | void nullproto::configure (const text_t &key, const text_tarray &cfgline,
|
---|
65 | comerror_t &err) {
|
---|
66 | // the naming of the collection should not be done here,
|
---|
67 | // it should be done just after the collection server has been
|
---|
68 | // created
|
---|
69 |
|
---|
70 | // the protocol should not configure the collection set; it should be
|
---|
71 | // done direct to the collection server set
|
---|
72 | if (key == "gsdlhome" || key == "gdbmhome"
|
---|
73 | || key == "collecthome" || key == "collectdir") {
|
---|
74 | cset->configure(key, cfgline);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | // this init will configure and init each of the collection servers
|
---|
79 | bool nullproto::init (comerror_t &err, ostream &logout) {
|
---|
80 | return cset->init(logout);
|
---|
81 | }
|
---|
82 |
|
---|
83 | text_t nullproto::get_site_name (comerror_t &err) {
|
---|
84 | return "localhost";
|
---|
85 | }
|
---|
86 |
|
---|
87 | text_t nullproto::get_protocol_name (comerror_t &err) {
|
---|
88 | return "nullproto";
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | void nullproto::get_collection_list (text_tarray &collist, comerror_t &err,
|
---|
93 | ostream &/*logout*/) {
|
---|
94 | cset->getCollectionList(collist);
|
---|
95 | err = noError; // no error is guaranteed - collection server shouldn't
|
---|
96 | // about receptionist error states, logout is irrelevant
|
---|
97 | }
|
---|
98 |
|
---|
99 | void nullproto::has_collection (const text_t &collection, bool &hascollection,
|
---|
100 | comerror_t &err, ostream &/*logout*/) {
|
---|
101 | hascollection = (cset->getCollectServer(collection) != NULL);
|
---|
102 | err = noError;
|
---|
103 | }
|
---|
104 |
|
---|
105 | void nullproto::ping (const text_t &collection, bool &wassuccess,
|
---|
106 | comerror_t &err, ostream &logout) {
|
---|
107 | collectserver *cserver = cset->getCollectServer(collection);
|
---|
108 | if (cserver != NULL) cserver->ping(wassuccess, err, logout);
|
---|
109 | else err = protocolError;
|
---|
110 | }
|
---|
111 |
|
---|
112 | void nullproto::get_collectinfo (const text_t &collection,
|
---|
113 | ColInfoResponse_t &collectinfo,
|
---|
114 | comerror_t &err, ostream &logout) {
|
---|
115 | collectserver *cserver = cset->getCollectServer (collection);
|
---|
116 | if (cserver != NULL) cserver->get_collectinfo (collectinfo, err, logout);
|
---|
117 | else err = protocolError;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | void nullproto::get_filterinfo (const text_t &collection,
|
---|
122 | InfoFiltersResponse_t &response,
|
---|
123 | comerror_t &err, ostream &logout) {
|
---|
124 | collectserver *cserver = cset->getCollectServer (collection);
|
---|
125 | if (cserver != NULL) cserver->get_filterinfo (response, err, logout);
|
---|
126 | else err = protocolError;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void nullproto::get_filteroptions (const text_t &collection,
|
---|
130 | const InfoFilterOptionsRequest_t &request,
|
---|
131 | InfoFilterOptionsResponse_t &response,
|
---|
132 | comerror_t &err, ostream &logout) {
|
---|
133 | collectserver *cserver = cset->getCollectServer (collection);
|
---|
134 | if (cserver != NULL) cserver->get_filteroptions (request, response, err, logout);
|
---|
135 | else err = protocolError;
|
---|
136 | }
|
---|
137 |
|
---|
138 | // returns the contents of a collection's rss-items.rdf file (generated by BasePlugout)
|
---|
139 | void nullproto::get_rss_items (const text_t &collection,
|
---|
140 | const text_t &gsdlhome,
|
---|
141 | text_t &rss_items,
|
---|
142 | comerror_t &err,
|
---|
143 | ostream &logout) {
|
---|
144 |
|
---|
145 | text_t rss_filename = filename_cat(gsdlhome,"collect",collection,"index","rss-items.rdf");
|
---|
146 | // read contents of file rss_filename into the string rss_items
|
---|
147 | if (read_file(rss_filename,rss_items)) {
|
---|
148 | err = noError;
|
---|
149 | } else {
|
---|
150 | err = protocolError;
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | void nullproto::filter (const text_t &collection,
|
---|
155 | FilterRequest_t &request,
|
---|
156 | FilterResponse_t &response,
|
---|
157 | comerror_t &err, ostream &logout) {
|
---|
158 | collectserver *cserver = cset->getCollectServer (collection);
|
---|
159 | if (cserver != NULL) cserver->filter (request, response, err, logout);
|
---|
160 | else err = protocolError;
|
---|
161 | }
|
---|
162 |
|
---|
163 | void nullproto::get_document (const text_t &collection,
|
---|
164 | const DocumentRequest_t &request,
|
---|
165 | DocumentResponse_t &response,
|
---|
166 | comerror_t &err, ostream &logout) {
|
---|
167 | collectserver *cserver = cset->getCollectServer (collection);
|
---|
168 | if (cserver != NULL) cserver->get_document (request, response, err, logout);
|
---|
169 | else err = protocolError;
|
---|
170 | }
|
---|
171 |
|
---|
172 | void nullproto::is_searchable (const text_t &collection, bool &issearchable,
|
---|
173 | comerror_t &err, ostream &logout) {
|
---|
174 | issearchable = false;
|
---|
175 | collectserver *cserver = cset->getCollectServer (collection);
|
---|
176 | if (cserver != NULL) cserver->is_searchable (issearchable, err, logout);
|
---|
177 | else err = protocolError;
|
---|
178 | }
|
---|