Changeset 1168 for branches/z3950-branch/gsdl/src/recpt/z3950proto.cpp
- Timestamp:
- 2000-05-11T13:56:34+12:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/z3950-branch/gsdl/src/recpt/z3950proto.cpp
r1164 r1168 6 6 #include "comtypes.h" 7 7 #include <stdio.h> 8 9 // config file parsing stuff 10 #include "z3950cfg.h" // for reading in config files - 11 // defines "struct z3950cfg *zserver_list" as the head of the list. 12 extern FILE *yyin; 13 // for some reason, adding the following line screws up the linking... 14 //extern int zconfigparse(); 8 15 9 16 /*** … … 17 24 info=NULL; 18 25 meta["iconcollection"]="/~johnmcp/gsdl/images/zserver.png"; 26 // meta["collectionextra"]="Extra collection information"; 27 // meta["collectionname"]="overwritten"; 28 } 29 void z3950_server::setMeta(const text_t &key, const text_t &value) { 30 meta[key]=value; 31 } 32 void z3950_server::setName(const text_t &newname) { 33 title=newname; 34 meta["collectionname"]=newname; 35 // cout << "Have set server name\n"; 19 36 } 20 37 … … 34 51 } 35 52 36 void z3950proto::configure (const text_t &/*key*/, 37 const text_tarray &/*cfgline*/) { 53 void z3950proto::read_config_file(const text_t &filename) { 54 struct z3950cfg *here; 55 z3950_server *zserver; 56 ShortColInfo_t *tempinfo; 57 58 cerr << "attempting to read config file: " << filename.getcstr() << "\n"; 59 // zconfigparse() is defined in zparse.tab.c, 60 // which is the bison output of zparse.y 61 62 yyin=fopen(filename.getcstr(),"r"); 63 if (yyin==NULL) { 64 cerr << "Could not open "<<filename.getcstr()<<" for reading.\n"; 65 } 66 zconfigparse(); 67 // we now have the config files in the ptr zserver_list 68 if (zserver_list==NULL) 69 return; // no valid servers found in the config file - note that 70 // the parser will have already spat out any errors. 71 72 // now create z3950servers for each structure in server_list 73 here=zserver_list; 74 while (here!=NULL) { 75 zserver=new z3950_server; 76 tempinfo=new ShortColInfo_t; 77 78 tempinfo->host.setcstr(here->hostname); 79 tempinfo->port=here->port; 80 tempinfo->name.setcstr(here->dbname); 81 zserver->setInfo(tempinfo); 82 zserver->setName(here->shortname); 83 // now collection metadata. 84 zserver->setMeta("collectionname",here->longname); 85 if (here->icon!=NULL) 86 zserver->setMeta("iconcollection",here->icon); 87 if (here->smallicon!=NULL) 88 zserver->setMeta("iconcollectionsmall",here->smallicon); 89 if (0) { 90 cerr << "creating metadata:\n\tcolname is " << here->longname 91 << "\n\ticoncollection is " << here->icon 92 << "\n and\ticoncollectionsmall is " << here->smallicon 93 << "\n"; 94 } 95 96 // and about list .... later. 97 98 add_server(*zserver); 99 here=here->next; 100 } 101 102 // finally, delete all unneeded allocated memory in server_list 103 104 } 105 106 void z3950proto::configure (const text_t &key, 107 const text_tarray &cfgline) { 38 108 39 109 // 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 */ 110 111 if (0) 112 cerr << "z3950proto::configure called:" 113 << "key is " << key.getcstr() 114 << "\n1st line is " << cfgline[0].getcstr() << endl; 115 44 116 } 45 117 … … 155 227 */ 156 228 157 collectinfo.receptionist="z3950"; /* for now... this is a url, 158 relative to .../cgi-bin */ 229 ////collectinfo.receptionist="z3950"; 230 /* for now... this is a url, relative to .../cgi-bin. 231 NOTE: if this is empty, it defaults to _gwcgi_?a=p&p=about&c=<colname> 232 */ 159 233 } 160 234 … … 169 243 FilterResponse_t &response, 170 244 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. 245 246 // this function is called when: 247 // * creating the title page,(looking for iconcoll* & collectname metadata) 248 // * creating the about page (looking for "Title" metadata) 249 // For the title page, we should not create a connection to the target 250 // (target means the actual z39.50 server, origin means us), but 251 // for the about page and query pages, we need to get information from the 252 // origin. (eg for the about page, we will print out some info such as ID, 253 // name and version. 254 255 // cerr now goes to errout.txt in etc directory 256 173 257 response.numDocs=0; 174 258 response.isApprox=Approximate; // Exact | Approximate | MoreThan … … 181 265 request.docSet (includes OID); 182 266 */ 183 // fill in the metadata for each of the OIDs (if it is requested) 267 268 // response.termInfo.push_back(""); ??????? (should be empty if not req.) 269 270 184 271 if (request.filterResultOptions & FRmetadata) { 185 // request.fields // type text_tset 186 // docInfo is type ResultDocInfo_tarray 272 187 273 ColInfoResponse_t *info = new ColInfoResponse_t; 188 274 get_collectinfo (collection, *info, err, logout); 189 275 // should check err returned here.... 190 276 277 ////////// cerr << "Filter.\n"; 278 191 279 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 280 281 /* In the absence of any other information, (eg commented code), 282 assuming that if the request.fields is empty, then we should return 283 all metadata, otherwise return only the requested fields */ 284 285 if (!request.fields.empty()) { 286 // loop on all the metadata fields in request.fields (type text_tset) 287 text_tset::iterator fields_here=request.fields.begin(); 288 text_tset::iterator fields_end=request.fields.end(); 289 text_tmap::iterator it; 290 while (fields_here!=fields_end) { 291 it=info->collectionmeta.find(*fields_here); 292 ////////// cerr << "filter: getting " << (*fields_here).getcstr(); 293 if (it!=info->collectionmeta.end()) 294 docInfo->metadata[*fields_here].values.push_back((*it).second); 295 else { 296 docInfo->metadata[*fields_here].values.push_back(""); 297 /////// cerr << " (not found)"; 298 } 299 ////////cerr << "\n"; 300 fields_here++; 301 } // end of while loop 302 } // end of if (!request.fields.empty()) 303 else { 304 // return all metadata for about page or query 305 text_tmap::iterator colmeta_here=info->collectionmeta.begin(); 306 text_tmap::iterator colmeta_end=info->collectionmeta.end(); 307 while (colmeta_here!=colmeta_end) { 308 docInfo->metadata[(*colmeta_here).first]. 309 values.push_back((*colmeta_here).second); 310 /////cerr << "\t" << (*colmeta_here).first.getcstr() << "\n"; 311 colmeta_here++; 312 } 313 // get data from target. 314 z3950_server_array::iterator zserver = zservers.begin(); 315 z3950_server_array::iterator zend = zservers.end(); 316 while (zserver != zend) { 317 if(zserver->getName()==collection) { 318 break; 319 } 320 zserver++; 321 } 322 // now have collection in zserver. 323 // check if "collectionextra" metadata is set. If it isn't, we should 324 // create connection to target to get it. 325 if (info->collectionmeta.find("collectionextra")==colmeta_end) { 326 // it doesn't exist. 327 zserver->setMeta("collectionextra","This is some extra info."); 328 docInfo->metadata["collectionextra"].values.push_back("This is extra"); 329 } 330 331 } // end of else 213 332 214 333 response.docInfo.push_back(*docInfo); 215 } 216 334 } //end of if (... & FRmetadata) ... 217 335 err=noError; 218 336 }
Note:
See TracChangeset
for help on using the changeset viewer.