Changeset 1168 for branches/z3950-branch


Ignore:
Timestamp:
2000-05-11T13:56:34+12:00 (24 years ago)
Author:
johnmcp
Message:

added proper config file parsing for z39.50 servers, and minor changes
to pageaction (minor bug when display collections from >1 proto) and
cgiwrapper (announces which collections are z39.50 servers).

Location:
branches/z3950-branch/gsdl/src/recpt
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/z3950-branch/gsdl/src/recpt/Makefile.in

    r1004 r1168  
    7777RECEPTHEADERS =
    7878
    79 LIBRARYHEADERS = nullproto.h
     79LIBRARYHEADERS = nullproto.h z3950proto.h
    8080
    8181HEADERS = $(COMMONHEADERS) $(RECPTHEADERS) $(LIBRARYHEADERS)
     
    9595RECPTSOURCES = recptmain.cpp
    9696
    97 LIBRARYSOURCES = nullproto.cpp librarymain.cpp
     97LIBRARYSOURCES = nullproto.cpp z3950proto.cpp librarymain.cpp
    9898
    9999SOURCES = $(COMMONSOURCES) $(RECPTSOURCES) $(LIBRARYSOURCES)
     
    109109        hlistbrowserclass.o datelistbrowserclass.o invbrowserclass.o \
    110110        pagedbrowserclass.o htmlbrowserclass.o delhistoryaction.o \
    111         historydb.o
     111        historydb.o parse.yy.o
    112112
    113113RECPTOBJECTS = recptmain.o
    114114
    115 LIBRARYOBJECTS = nullproto.o librarymain.o
     115LIBRARYOBJECTS = nullproto.o z3950proto.o librarymain.o zparse.tab.o
    116116
    117117OBJECTS = $(COMMONOBJECTS) $(RECPTOBJECTS) $(LIBRARYOBJECTS)
     
    133133                  ../colservr/phrasequeryfilter.o
    134134
    135 
     135# bison and flex temp files
     136zparse.tab.c: zparse.y
     137    bison -d zparse.y
     138parse.yy.c: parse.fl
     139    flex -oparse.yy.c parse.fl
     140PARSE_TMPFILES= zparse.tab.o zparse.tab.c zparse.tab.h parse.yy.o parse.yy.c
    136141EXEC = recpt library
    137142
     
    139144
    140145distclean:
    141     rm -f $(OBJECTS) $(EXEC) Makefile
     146    rm -f $(OBJECTS) $(EXEC) $(PARSE_TMPFILES) Makefile
    142147
    143148clean:
    144     rm -f $(OBJECTS) $(EXEC)
     149    rm -f $(OBJECTS) $(EXEC) $(PARSE_TMPFILES)
    145150
    146151install:
  • branches/z3950-branch/gsdl/src/recpt/cgiwrapper.cpp

    r1097 r1168  
    2828/*
    2929   $Log$
     30   Revision 1.25.2.1  2000/05/11 01:56:27  johnmcp
     31
     32   added proper config file parsing for z39.50 servers, and minor changes
     33   to pageaction (minor bug when display collections from >1 proto) and
     34   cgiwrapper (announces which collections are z39.50 servers).
     35
    3036   Revision 1.25  2000/04/14 04:45:19  sjboddie
    3137   Modified the English of the debug output slightly
     
    483489  recptprotolistclass::iterator rprotolist_here = protos->begin();
    484490  recptprotolistclass::iterator rprotolist_end = protos->end();
     491
     492  bool is_z3950 = false;
    485493  while (rprotolist_here != rprotolist_end) {
    486     if ((*rprotolist_here).p != NULL) {
    487 
    488       text_tarray collist;
    489       comerror_t err;
    490       (*rprotolist_here).p->get_collection_list (collist, err, cerr);
    491       if (err == noError) {
    492     text_tarray::iterator collist_here = collist.begin();
    493     text_tarray::iterator collist_end = collist.end();
    494 
    495     while (collist_here != collist_end) {
     494    if ((*rprotolist_here).p == NULL) continue;
     495    else if (is_z3950==false &&
     496         (*rprotolist_here).p->get_protocol_name() == "z3950proto") {
     497      cout << "\nZ39.50 Servers:   (always public)\n"
     498       << "---------------\n";
     499      is_z3950=true;
     500    }
     501
     502    text_tarray collist;
     503    comerror_t err;
     504    (*rprotolist_here).p->get_collection_list (collist, err, cerr);
     505    if (err == noError) {
     506      text_tarray::iterator collist_here = collist.begin();
     507      text_tarray::iterator collist_end = collist.end();
     508     
     509      while (collist_here != collist_end) {
     510   
     511    cout << text_t2ascii << *collist_here;
     512   
     513    int spaces = (22 - (*collist_here).size());
     514    if (spaces < 2) spaces = 2;
     515    text_t outspaces;
     516    for (int i = 0; i < spaces; i++) outspaces.push_back (' ');
     517    cout << text_t2ascii << outspaces;
     518   
     519    ColInfoResponse_t cinfo;
     520    (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, cerr);
     521    if (err == noError && is_z3950 == false) {
     522      if (cinfo.isPublic) cout << "public ";
     523      else cout << "private";
    496524     
    497       cout << text_t2ascii << *collist_here;
    498 
    499       int spaces = (22 - (*collist_here).size());
    500       if (spaces < 2) spaces = 2;
    501       text_t outspaces;
    502       for (int i = 0; i < spaces; i++) outspaces.push_back (' ');
    503       cout << text_t2ascii << outspaces;
    504 
    505       ColInfoResponse_t cinfo;
    506       (*rprotolist_here).p->get_collectinfo (*collist_here, cinfo, err, cerr);
    507       if (err == noError) {
    508         if (cinfo.isPublic) cout << "public ";
    509         else cout << "private";
    510 
    511         if (cinfo.buildDate > 0) cout << "   running    ";
    512         else cout << "   not running";
    513       }
    514 
    515       cout << "\n";
    516 
    517       collist_here ++;
     525      if (cinfo.buildDate > 0) cout << "   running    ";
     526      else cout << "   not running";
    518527    }
     528   
     529    cout << "\n";
     530   
     531    collist_here ++;
    519532      }
    520533    }
     534    is_z3950=false;
    521535    rprotolist_here ++;
    522   }
     536  } // end of while loop
    523537 
    524538  cout << "------------------------------------------------------------\n";
  • branches/z3950-branch/gsdl/src/recpt/librarymain.cpp

    r1089 r1168  
    2828/*
    2929   $Log$
     30   Revision 1.25.2.1  2000/05/11 01:56:29  johnmcp
     31
     32   added proper config file parsing for z39.50 servers, and minor changes
     33   to pageaction (minor bug when display collections from >1 proto) and
     34   cgiwrapper (announces which collections are z39.50 servers).
     35
    3036   Revision 1.25  2000/04/14 02:52:05  sjboddie
    3137   tidied up error messaging and set up some debugging info to be output
     
    118124#include "cgiwrapper.h"
    119125#include "nullproto.h"
     126// z39.50 stuff - johnmcp
     127#include "z3950proto.h"
    120128#include "collectserver.h"
    121129#include "filter.h"
     
    153161  receptionist recpt;
    154162  nullproto nproto;
     163  z3950proto zproto;
    155164  text_tarray collections;
     165
    156166
    157167  // get gsdlhome
     
    207217    colinfo.push_back (gsdlhome);
    208218    recpt.configure ("collectinfo", colinfo);
    209  
     219   
    210220    nproto.add_collectserver (cserver);
    211221    thiscol ++;
     
    215225  recpt.add_protocol (&nproto);
    216226 
     227
     228
     229  // z39.50 stuff - johnmcp
     230
     231  // add the z39.50 server information. Read in the file
     232  // etc/recpt/z3950.cfg for list of servers and their databases.
     233  text_t z3950cfg = filename_cat (gsdlhome, "etc");
     234  z3950cfg = filename_cat (z3950cfg, "recpt");
     235  z3950cfg = filename_cat (z3950cfg, "z3950.cfg");
     236  if (file_exists(z3950cfg)) {
     237    zproto.read_config_file(z3950cfg);
     238    // only add this protocol if we have any servers configured.
     239    if (zproto.getServerCount()>0)
     240      recpt.add_protocol (&zproto);
     241  }
     242
     243
    217244  // add other converters
    218245  utf8inconvertclass utf8inconvert;
  • branches/z3950-branch/gsdl/src/recpt/pageaction.cpp

    r1033 r1168  
    2828/*
    2929   $Log$
     30   Revision 1.29.6.1  2000/05/11 01:56:30  johnmcp
     31
     32   added proper config file parsing for z39.50 servers, and minor changes
     33   to pageaction (minor bug when display collections from >1 proto) and
     34   cgiwrapper (announces which collections are z39.50 servers).
     35
    3036   Revision 1.29  2000/03/19 21:16:46  nzdl
    3137   added german language interface
     
    266272      collist_here ++;
    267273    }
    268     homeextra += "</tr></table></center>\n";
    269     disp.setmacro ("homeextra", "home", homeextra);
    270       }
    271     }
     274    // disp.setmacro ("homeextra", "home", homeextra);
     275      }
     276    }
     277    homeextra += "</td></tr>\n<tr>\n";
    272278    rprotolist_here ++;
    273279  }
     280  homeextra += "</tr></table></center>\n";
     281  disp.setmacro ("homeextra", "home", homeextra);
    274282}
    275283
  • branches/z3950-branch/gsdl/src/recpt/z3950proto.cpp

    r1164 r1168  
    66#include "comtypes.h"
    77#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.
     12extern FILE *yyin;
     13// for some reason, adding the following line screws up the linking...
     14//extern int zconfigparse();
    815
    916/***
     
    1724  info=NULL;
    1825  meta["iconcollection"]="/~johnmcp/gsdl/images/zserver.png";
     26  // meta["collectionextra"]="Extra collection information";
     27  // meta["collectionname"]="overwritten";
     28}
     29void z3950_server::setMeta(const text_t &key, const text_t &value) {
     30  meta[key]=value;
     31}
     32void z3950_server::setName(const text_t &newname) {
     33  title=newname;
     34  meta["collectionname"]=newname;
     35  // cout << "Have set server name\n";
    1936}
    2037
     
    3451}
    3552
    36 void z3950proto::configure (const text_t &/*key*/,
    37                 const text_tarray &/*cfgline*/) {
     53void 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
     106void z3950proto::configure (const text_t &key,
     107                const text_tarray &cfgline) {
    38108
    39109  // 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 
    44116}
    45117
     
    155227  */
    156228
    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  */
    159233}
    160234
     
    169243             FilterResponse_t &response,
    170244             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
    173257  response.numDocs=0;
    174258  response.isApprox=Approximate; // Exact | Approximate | MoreThan
     
    181265     request.docSet (includes OID);
    182266  */
    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
    184271  if (request.filterResultOptions & FRmetadata) {
    185     // request.fields // type text_tset
    186     // docInfo is type ResultDocInfo_tarray
     272
    187273    ColInfoResponse_t *info = new ColInfoResponse_t;
    188274    get_collectinfo (collection, *info, err, logout);
    189275    // should check err returned here....
    190276
     277    ////////// cerr << "Filter.\n";
     278
    191279    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
    213332
    214333    response.docInfo.push_back(*docInfo);
    215   }
    216 
     334  } //end of  if (... & FRmetadata) ...
    217335  err=noError;
    218336}
  • branches/z3950-branch/gsdl/src/recpt/z3950proto.h

    r1164 r1168  
    55#include "recptproto.h"
    66
    7 // each server can have one or more databases
    8 /*
    9   class z3950_DB {
    10   protected:
    11   text_t name; // Descriptive name
    12   text_t database; // name for server
    13  
    14   public:
    15   z3950_DB();     // constructor
    16   ~z3950_DB();    // deconstructor
    17   const text_t getName() {return name;}                // this gets name
    18   void setName(text_t newName) {name=newName;} // this sets name
    19   // need to get next (for linked list)
    20   };
    21  
    22 
    23   typedef  vector<z3950_DB>  z3950_DB_array;
    24 */
    25 
    26 /*class z3950_DB_Array {
    27   protected:
    28   int count;
    29   // some arraytype...
    30   public:
    31   z3950_DB first();
    32   z3950_DB last();
    33   void     add(z3950_DB *db);
    34   void     remove(z3950_DB *db);
    35   };
    36 */
    37 
    38 
     7// each "server" (ie collection) consists of a {z39.50 server + database} pair.
    398class z3950_server {
    409 protected:
     
    4918 public:
    5019  z3950_server();
    51   // z3950_DB_array getDBs();
    5220  const text_t getName() {return title;}
    53   void setName(const text_t &newname) {title=newname;}
    54   //  void setHostname(const text_t &newname) {hostname=newname;}
     21  void setMeta(const text_t &key, const text_t &value);
     22  void setName(const text_t &newname);
    5523  void setInfo(ShortColInfo_t *newinfo) {info=newinfo;}
    5624  const ShortColInfo_t *getInfo() {return info;}
     
    7139  virtual ~z3950proto() {}
    7240
     41  int getServerCount() { return zserver_count;}
    7342  /*
    7443  void add_collectserver (collectserver *thecserver)
    7544        {cservers.addcollectserver(thecserver);}
    7645  */
     46 
     47  void add_server(const z3950_server& zserver);
    7748
    78   void add_server(const z3950_server& zserver);
     49  void read_config_file(const text_t &filename);
    7950
    8051  void configure (const text_t &key, const text_tarray &cfgline);
Note: See TracChangeset for help on using the changeset viewer.