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

Last change on this file since 1177 was 1164, checked in by johnmcp, 24 years ago

added files to create the z3950proto class, which is based on
the recptproto class (but without lots of the functionality...) - johnmcp

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