Ignore:
Timestamp:
2000-08-03T14:49:41+12:00 (24 years ago)
Author:
johnmcp
Message:

Relatively stable z39.50 implementation now, merged with the mgpp source.
(Still needs a decent interface and query language though...)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/z3950-branch/gsdl/src/recpt/receptionist.cpp

    r1148 r1342  
    2222 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    2323 *
    24  * $Id$
    25  *
    2624 *********************************************************************/
    27 
    28 /*
    29    $Log$
    30    Revision 1.49  2000/05/04 05:18:46  sjboddie
    31    attempting to get end-user collection building to work under windows
    32 
    33    Revision 1.48  2000/04/14 02:52:06  sjboddie
    34    tidied up error messaging and set up some debugging info to be output
    35    when running library from command line
    36 
    37    Revision 1.47  2000/02/17 22:26:17  sjboddie
    38    set macros for displaying macrons in utf8
    39 
    40    Revision 1.46  2000/02/17 02:34:09  sjboddie
    41    made compressedoptions macro dm_safe - added SCRIPT_NAME to log string
    42 
    43    Revision 1.45  2000/02/03 01:48:52  sjboddie
    44    fixed potential bug in ccscols stuff
    45 
    46    Revision 1.44  2000/01/24 22:53:09  sjboddie
    47    a few small changes to get fastcgi working properly here at Waikato -
    48    hopefully changes will work everywhere ...
    49 
    50    Revision 1.43  1999/12/06 01:14:16  sjboddie
    51    added arabic encoding
    52 
    53    Revision 1.42  1999/12/05 21:21:04  sjboddie
    54    added support for multiple gsdlhomes and gdbmhomes
    55 
    56    Revision 1.41  1999/11/25 21:44:16  sjboddie
    57    fixed bug in logout
    58 
    59    Revision 1.40  1999/11/08 20:26:37  sjboddie
    60    added multiplevalue option to cgiarginfo
    61 
    62    Revision 1.39  1999/11/03 22:49:10  sjboddie
    63    A location url may now contain macros
    64 
    65    Revision 1.38  1999/11/01 21:49:34  sjboddie
    66    changes to arguments of many functions
    67 
    68    Revision 1.37  1999/10/20 03:55:03  sjboddie
    69    yet another problem with calling browserclass
    70    processOID functions correctly
    71 
    72    Revision 1.36  1999/10/19 03:23:44  davidb
    73    Collection building support through web pages
    74    and internal and external link handling for collection documents
    75 
    76    Revision 1.35  1999/10/18 20:07:05  sjboddie
    77    tidied up a few things - moved processing of "hp" argument
    78    to htmlbrowserclass
    79 
    80    Revision 1.34  1999/10/14 23:00:52  sjboddie
    81    finished changes to browsing support
    82 
    83    Revision 1.33  1999/10/10 08:14:10  sjboddie
    84    - metadata now returns mp rather than array
    85    - redesigned browsing support (although it's not finished so
    86    won't currently work ;-)
    87 
    88    Revision 1.32  1999/09/21 11:28:45  sjboddie
    89    tidied up file locking
    90 
    91    Revision 1.31  1999/09/16 21:38:17  sjboddie
    92    added some file locking stuff for logging. Windows still needs to
    93    be done.
    94 
    95    Revision 1.30  1999/09/07 04:56:58  sjboddie
    96    added GPL notice
    97 
    98    Revision 1.29  1999/09/03 10:02:30  rjmcnab
    99    Made the page parameters configurable. Now the page parameters must
    100    correspond to cgi arguments in name and value (ie language=zh should now
    101    be l=zh) which makes things more consistent anyway. Removed a couple of
    102    specialised NZDL page parameters.
    103 
    104    Moved the combining of the cgi arguments so that the receptionist does
    105    all the configuration now.
    106 
    107    Made the macro precedence configurable.
    108 
    109    Made cgi arguments totally configurable. Now any piece of information about
    110    a cgi argument can be configured meaning that cgi arguments can be declared
    111    from the configuration file.
    112 
    113    Removed the argdefault configuration argument. This should now be done
    114    using cgiarg.
    115 
    116    Revision 1.28  1999/09/03 04:39:46  rjmcnab
    117    Made cookies and logs optional (they are turned off by default). To
    118    turn them on put
    119 
    120    usecookies true
    121    logcgiargs true
    122 
    123    in your configuration file.
    124 
    125    Revision 1.27  1999/09/02 00:27:21  rjmcnab
    126    A few small things.
    127 
    128    Revision 1.26  1999/08/25 04:43:06  sjboddie
    129    made FilterRequest_t::docSet an array rather than a set
    130 
    131    Revision 1.25  1999/08/20 00:59:01  sjboddie
    132    -fixed up location redirection
    133    -added some usage logging, also now set a GSDL_UID cookie. Logging
    134    does NOT presently lock the log file while it's in use. That has yet
    135    to be done.
    136 
    137    Revision 1.24  1999/08/13 04:16:42  sjboddie
    138    added some collection-level metadata stuff
    139 
    140    Revision 1.23  1999/08/11 23:28:59  sjboddie
    141    added support for html classifier (i.e. the hp argumant now must be
    142    translated too).
    143 
    144    Revision 1.22  1999/08/10 22:45:21  sjboddie
    145    format option ShowTopPages is now called DocumentTopPages
    146 
    147    Revision 1.21  1999/08/09 04:25:17  sjboddie
    148    moved OID translation stuff from documentaction::define_external_macros
    149    to receptionist
    150 
    151    Revision 1.20  1999/07/30 02:13:09  sjboddie
    152    -added collectinfo argument to some functions
    153    -made some function prototypes virtual
    154 
    155    Revision 1.19  1999/07/15 06:02:05  rjmcnab
    156    Moved the setting of argsinfo into the constructor. Added the configuration
    157    command argdefault (as used by the actions). Added code to output the
    158    correct charset based on the page encoding so that the user does not need
    159    to specify the encoding used for a particular page.
    160 
    161    Revision 1.18  1999/07/11 01:05:20  rjmcnab
    162    Stored origin of cgiarg with argument.
    163 
    164    Revision 1.17  1999/07/10 22:18:26  rjmcnab
    165    Added calls to define_external_cgiargs.
    166 
    167    Revision 1.16  1999/06/27 21:49:03  sjboddie
    168    fixed a couple of version conflicts - tidied up some small things
    169 
    170    Revision 1.15  1999/06/26 01:14:32  rjmcnab
    171    Made a couple of changes to handle different encodings.
    172 
    173    Revision 1.14  1999/06/09 00:08:36  sjboddie
    174    query string macro (_cgiargq_) is now made html safe before being set
    175 
    176    Revision 1.13  1999/06/08 04:29:31  sjboddie
    177    added argsinfo to the call to check_cgiargs to make it easy to set
    178    args to their default if they're found to be screwed up
    179 
    180    Revision 1.12  1999/04/30 01:59:42  sjboddie
    181    lots of stuff - getting documentaction working (documentaction replaces
    182    old browseaction)
    183 
    184    Revision 1.11  1999/03/25 03:06:43  sjboddie
    185 
    186    altered receptionist slightly so it now passes *collectproto to
    187    define_internal_macros and define_external_macros - need it
    188    for browseaction
    189 
    190    Revision 1.10  1999/03/05 03:53:54  sjboddie
    191 
    192    fixed some bugs
    193 
    194    Revision 1.9  1999/02/28 20:00:16  rjmcnab
    195 
    196 
    197    Fixed a few things.
    198 
    199    Revision 1.8  1999/02/25 21:58:59  rjmcnab
    200 
    201    Merged sources.
    202 
    203    Revision 1.7  1999/02/21 22:33:55  rjmcnab
    204 
    205    Lots of stuff :-)
    206 
    207    Revision 1.6  1999/02/11 01:24:05  rjmcnab
    208 
    209    Fixed a few compiler warnings.
    210 
    211    Revision 1.5  1999/02/08 01:28:02  rjmcnab
    212 
    213    Got the receptionist producing something using the statusaction.
    214 
    215    Revision 1.4  1999/02/05 10:42:46  rjmcnab
    216 
    217    Continued working on receptionist
    218 
    219    Revision 1.3  1999/02/04 10:00:56  rjmcnab
    220 
    221    Developed the idea of an "action" and having them define the cgi arguments
    222    which they need and how those cgi arguments function.
    223 
    224    Revision 1.2  1999/02/04 01:17:27  rjmcnab
    225 
    226    Got it outputing something.
    227 
    228 
    229  */
    230 
    23125
    23226#include "receptionist.h"
     
    23933#include <time.h>
    24034#include <stdio.h>
     35#if defined (GSDL_USE_IOS_H)
    24136#include <fstream.h>
     37#else
     38#include <fstream>
     39#endif
    24240
    24341#if defined (__WIN32_)
     
    25250  collectdir.clear();
    25351  httpprefix.clear();
    254   httpimg.clear();
     52  httpimg = "/images";
    25553  gwcgi.clear();
    25654  macrofiles.erase(macrofiles.begin(), macrofiles.end());
     
    27270}
    27371
    274 
     72void collectioninfo_t::clear () {
     73  gsdl_gsdlhome.clear();
     74  gsdl_gdbmhome.clear();
     75
     76  info_loaded = false;
     77  info.clear();
     78}
    27579
    27680receptionist::receptionist () {
     
    789593  utf8outconvertclass text_t2utf8;
    790594  char *lfile = filename.getcstr();
     595
    791596  ofstream log (lfile, ios::app);
    792597 
     
    912717bool receptionist::produce_content (cgiargsclass &args, ostream &contentout,
    913718                    ostream &logout) {
    914  
     719
    915720  // decide on the output conversion class
    916721  text_t &arg_w = args["w"];
     
    1019824  colinfo_tmap::iterator colend = configinfo.collectinfo.end();
    1020825  while (colhere != colend) {
    1021     gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
    1022     maindirs.insert (gsdlmacrodir);
     826    if (!((*colhere).second.gsdl_gsdlhome).empty()) {
     827      gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
     828      maindirs.insert (gsdlmacrodir);
     829    }
    1023830    colhere ++;
    1024831  }
     
    1103910
    1104911    text_t &arg_c = args["c"];
    1105     ColInfoResponse_t cinfo;
    1106     comerror_t err;
    1107912    recptproto *collectproto = protocols.getrecptproto (arg_c, logout);
    1108     collectproto->get_collectinfo (arg_c, cinfo, err, logout);
    1109 
    1110     if (!cinfo.ccsCols.empty()) {
    1111       args["ccs"] = 1;
    1112       if (args["cc"].empty()) {
    1113     text_tarray::const_iterator col_here = cinfo.ccsCols.begin();
    1114     text_tarray::const_iterator col_end = cinfo.ccsCols.end();
    1115     bool first = true;
    1116     while (col_here != col_end) {
    1117       // make sure it's a valid collection
    1118       if (protocols.getrecptproto (*col_here, logout) != NULL) {
    1119         if (!first) args["cc"].push_back (',');
    1120         args["cc"] += *col_here;
    1121         first = false;
     913    if (collectproto == NULL) {
     914      // oops, this collection isn't valid
     915      outconvertclass text_t2ascii;
     916      logout << text_t2ascii << "ERROR: Invalid collection: " << arg_c << "\n";
     917      args["c"].clear();
     918
     919    } else {
     920
     921      ColInfoResponse_t *cinfo = get_collectinfo_ptr (collectproto, arg_c, logout);
     922
     923      if (cinfo != NULL) {
     924    if (!cinfo->ccsCols.empty()) {
     925      args["ccs"] = 1;
     926      if (args["cc"].empty()) {
     927        text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
     928        text_tarray::const_iterator col_end = cinfo->ccsCols.end();
     929        bool first = true;
     930        while (col_here != col_end) {
     931          // make sure it's a valid collection
     932          if (protocols.getrecptproto (*col_here, logout) != NULL) {
     933        if (!first) args["cc"].push_back (',');
     934        args["cc"] += *col_here;
     935        first = false;
     936          }
     937          col_here ++;
     938        }
    1122939      }
    1123       col_here ++;
    1124940    }
     941      } else {
     942    logout << "ERROR (receptionist::check_mainargs): get_collectinfo_ptr returned NULL\n";
    1125943      }
    1126944    }
     
    12451063  decode_cgi_arg (compressedoptions);
    12461064  disp.setmacro ("decodedcompressedoptions", "Global", dm_safe(compressedoptions));
     1065
     1066#if defined (__WIN32__)
     1067  disp.setmacro ("win32", "Global", "1");
     1068#endif
    12471069
    12481070  // set macron macros if encoding is utf8
     
    13071129  }
    13081130}
     1131
     1132// gets collection info from cache if found or
     1133// calls collection server (and updates cache)
     1134// returns NULL if there's an error
     1135ColInfoResponse_t *receptionist::get_collectinfo_ptr (recptproto *collectproto,
     1136                              const text_t &collection,
     1137                              ostream &logout) {
     1138 
     1139  // check the cache
     1140  colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
     1141  if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
     1142    // found it
     1143    return &((*it).second.info);
     1144  }
     1145
     1146  // not cached, get info from collection server
     1147  if (collectproto == NULL) {
     1148    logout << "ERROR: receptionist::get_collectinfo_ptr passed null collectproto\n";
     1149    return NULL;
     1150  }
     1151   
     1152  comerror_t err;
     1153  if (it == configinfo.collectinfo.end()) {
     1154    collectioninfo_t cinfo;
     1155    collectproto->get_collectinfo (collection, cinfo.info, err, logout);
     1156    if (err != noError) {
     1157      outconvertclass text_t2ascii;
     1158      logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
     1159         << get_comerror_string (err) << "\"while getting collectinfo\n";
     1160      return NULL;
     1161    }
     1162    cinfo.info_loaded = true;
     1163    configinfo.collectinfo[collection] = cinfo;
     1164    return &(configinfo.collectinfo[collection].info);
     1165  } else {
     1166    collectproto->get_collectinfo (collection, (*it).second.info, err, logout);
     1167    if (err != noError) {
     1168      outconvertclass text_t2ascii;
     1169      logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
     1170         << get_comerror_string (err) << "\"while getting collectinfo\n";
     1171      return NULL;
     1172    }
     1173    (*it).second.info_loaded = true;
     1174    return &((*it).second.info);
     1175  }
     1176}
Note: See TracChangeset for help on using the changeset viewer.