source: trunk/gsdl/src/recpt/z3950proto.cpp@ 1285

Last change on this file since 1285 was 1285, checked in by sjboddie, 24 years ago

Removed CVS logging information from source files

  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/**********************************************************************
2 *
3 * z3950proto.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 "z3950proto.h"
27#include "comtypes.h"
28#include <stdio.h>
29
30/***
31 We will use the "collection" argument as the name of the database
32 to query on the z3950 server.
33***/
34
35
36z3950_server::z3950_server() {
37 count=0;
38 info=NULL;
39 meta["iconcollection"]="/~johnmcp/gsdl/images/zserver.png";
40}
41
42
43
44
45// z3950 Protocol functions
46z3950proto::z3950proto() {
47 zserver_count=0;
48}
49
50void z3950proto::add_server (const z3950_server& zserver) {
51
52 // append the new server
53 zserver_count++;
54 zservers.push_back(zserver);
55}
56
57void z3950proto::configure (const text_t &/*key*/,
58 const text_tarray &/*cfgline*/) {
59
60 // this is called for each line in the gsdlsite.cfg file
61 /* cerr << "z3950proto::configure called:"
62 << "key is " << key.getcstr()
63 << "\n1st line is " << cfgline[0].getcstr() << endl;
64 */
65}
66
67
68bool z3950proto::init (ostream &/*logout*/) {
69 // set up tcp connection to server here?
70 // we might also read in the config file here (instead of librarymain.cpp)
71
72 //
73
74 // logout goes to initout.txt
75 // logout <<"zdebug:init:Number of z3950 servers: "<< zserver_count << "\n";
76 //logout << "\t1st server name: " << zservers[0].getName().getcstr() << "\n";
77 return true;
78
79}
80
81/*text_t z3950proto::get_protocol_name () {
82 return "z3950proto";
83}
84*/
85
86void z3950proto::get_collection_list (text_tarray &collist,
87 comerror_t &/*err*/,
88 ostream &/*logout*/) {
89 // logout here DOESN'T go to initout.txt
90 // logout << "zdebug: get_collection_list called:\n";
91
92 /** *** for now, we are assuming that each SERVER is a GSDL collection,
93 as opposed to each DATABASE on the servers.
94 */
95 z3950_server_array::iterator here = zservers.begin();
96 z3950_server_array::iterator end = zservers.end();
97 while (here != end) {
98 collist.push_back(here->getName());
99 //const ShortColInfo_t *info=here->getInfo();
100 //collist.push_back(info->name);
101 here++;
102 }
103}
104
105void z3950proto::has_collection (const text_t &collection, bool &hascollection,
106 comerror_t &/*err*/, ostream &/*logout*/) {
107 z3950_server_array::iterator here = zservers.begin();
108 z3950_server_array::iterator end = zservers.end();
109 while (here != end) {
110 if(here->getName()==collection) {
111 hascollection=true;
112 return;
113 }
114 here++;
115 }
116 hascollection=false;
117}
118
119void z3950proto::ping (const text_t &/*collection*/, bool &wassuccess,
120 comerror_t &/*err*/, ostream &/*logout*/) {
121 // should we just ping the server, or actually create a connection
122 // to the z39.50 server process on the machine ?
123 wassuccess = true;
124}
125
126void z3950proto::get_collectinfo (const text_t &collection,
127 ColInfoResponse_t &collectinfo,
128 comerror_t &err, ostream &logout) {
129
130 // set err to protocolError if something goes wrong...
131
132 z3950_server_array::iterator here = zservers.begin();
133 z3950_server_array::iterator end = zservers.end();
134 while (here != end) {
135 if(here->getName()==collection) {
136 break;
137 }
138 here++;
139 }
140
141 // is this right? ie does end refer to the last element, or AFTER the
142 // last element?
143 if (here==end) {
144 err=protocolError;
145 logout << "z39.50: couldn't find collection"
146 << collection.getcstr()
147 << endl;
148 return;
149 }
150
151 /* collectinfo.shortInfo.name="sdfg";
152 collectinfo.shortInfo.host="localhost";
153 collectinfo.shortInfo.port=0; */
154 const ShortColInfo_t *colinfo=here->getInfo();
155 collectinfo.shortInfo.name=colinfo->name;
156 collectinfo.shortInfo.host=colinfo->host;
157 collectinfo.shortInfo.port=colinfo->port;
158
159 collectinfo.isPublic=true;
160 // don't use beta field
161 /*collectinfo.isBeta=false;*/
162 collectinfo.buildDate=1;
163 // leave ccsCols empty (no cross-coll. searching - for now)
164 /*collectinfo.ccsCols=(text_tarray);*/ //not like this!!!
165 collectinfo.languages.push_back("en");
166 collectinfo.languages.push_back("fr");
167 collectinfo.numDocs=0;
168 collectinfo.numWords=0;
169 collectinfo.numBytes=0;
170 // copy the text maps over.
171 // collectinfo.collectionmeta; // text_tmap
172 // delete collectinfo.collectionmeta;
173 collectinfo.collectionmeta=*(here->getMeta());
174 /* collectinfo.format; //text_tmap
175 collectinfo.building; //text_tmap
176 */
177
178collectinfo.receptionist="z3950"; /* for now... this is a url,
179 relative to .../cgi-bin */
180}
181
182void z3950proto::get_filterinfo (const text_t &/*collection*/,
183 InfoFiltersResponse_t &/*response*/,
184 comerror_t &/*err*/, ostream &/*logout*/) {
185
186}
187
188void z3950proto::filter (const text_t &collection,
189 FilterRequest_t &request,
190 FilterResponse_t &response,
191 comerror_t &err, ostream &logout) {
192 // assume this function is only called when creating the title page,
193 // and looking for the metadata regarding icons.
194 response.numDocs=0;
195 response.isApprox=Approximate; // Exact | Approximate | MoreThan
196 // leave response.termInfo empty
197 // leave response.docInfo empty
198 /* got the following for first query:
199 request.filterResultOptions=FRmetadata;
200 request.getParents=getParents
201 request.fields=metadata
202 request.docSet (includes OID);
203 */
204 // fill in the metadata for each of the OIDs (if it is requested)
205 if (request.filterResultOptions & FRmetadata) {
206 // request.fields // type text_tset
207 // docInfo is type ResultDocInfo_tarray
208 ColInfoResponse_t *info = new ColInfoResponse_t;
209 get_collectinfo (collection, *info, err, logout);
210 // should check err returned here....
211
212 ResultDocInfo_t *docInfo=new ResultDocInfo_t;
213
214 text_tmap::iterator it=info->collectionmeta.find("collectionname");
215 // cerr now goes to errout.txt in etc directory
216 // "(*it).first" is key, "(*it).second" is value(s).
217 if (it!=info->collectionmeta.end())
218 docInfo->metadata["collectionname"].values.push_back((*it).second);
219 else // needs to exist, but be empty
220 docInfo->metadata["collectionname"].values.push_back("");
221
222 it=info->collectionmeta.find("iconcollection");
223 if (it!=info->collectionmeta.end())
224 docInfo->metadata["iconcollection"].values.push_back((*it).second);
225 else // needs to exist, but be empty
226 docInfo->metadata["iconcollection"].values.push_back("");
227
228 it=info->collectionmeta.find("iconcollectionsmall");
229 if (it!=info->collectionmeta.end())
230 docInfo->metadata["iconcollectionsmall"].values.push_back((*it).second);
231 else // needs to exist, but be empty
232 docInfo->metadata["iconcollectionsmall"].values.push_back("");
233
234
235 response.docInfo.push_back(*docInfo);
236 }
237
238 err=noError;
239}
240
241void z3950proto::get_document (const text_t &/*collection*/,
242 const DocumentRequest_t &/*request*/,
243 DocumentResponse_t &/*response*/,
244 comerror_t &err, ostream &logout) {
245
246 if (0) {
247 err=protocolError;
248 logout << "Some error\n";
249 }
250}
251
252
253#endif
Note: See TracBrowser for help on using the repository browser.