System call times(2) used again. More 64-bit fixes.
[idzebra-moved-to-github.git] / index / zserver.h
index 13e8901..8680d43 100644 (file)
@@ -1,10 +1,83 @@
 /*
- * Copyright (C) 1994-1998, Index Data I/S 
+ * Copyright (C) 1994-2000, Index Data 
  * All rights reserved.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zserver.h,v $
- * Revision 1.28  1998-01-29 13:40:11  adam
+ * Revision 1.49  2000-05-18 12:01:36  adam
+ * System call times(2) used again. More 64-bit fixes.
+ *
+ * Revision 1.48  2000/04/05 09:49:35  adam
+ * On Unix, zebra/z'mbol uses automake.
+ *
+ * Revision 1.47  2000/03/20 19:08:36  adam
+ * Added remote record import using Z39.50 extended services and Segment
+ * Requests.
+ *
+ * Revision 1.46  2000/03/15 15:00:31  adam
+ * First work on threaded version.
+ *
+ * Revision 1.45  1999/11/30 13:48:04  adam
+ * Improved installation. Updated for inclusion of YAZ header files.
+ *
+ * Revision 1.44  1999/11/04 15:00:45  adam
+ * Implemented delete result set(s).
+ *
+ * Revision 1.43  1999/07/14 10:59:27  adam
+ * Changed functions isc_getmethod, isams_getmethod.
+ * Improved fatal error handling (such as missing EXPLAIN schema).
+ *
+ * Revision 1.42  1999/05/26 07:49:13  adam
+ * C++ compilation.
+ *
+ * Revision 1.41  1999/05/12 13:08:06  adam
+ * First version of ISAMS.
+ *
+ * Revision 1.40  1998/11/16 16:03:45  adam
+ * Moved loggin utilities to Yaz. Was implemented in file zlogs.c.
+ *
+ * Revision 1.39  1998/10/16 08:14:35  adam
+ * Updated record control system.
+ *
+ * Revision 1.38  1998/09/22 10:03:44  adam
+ * Changed result sets to be persistent in the sense that they can
+ * be re-searched if needed.
+ * Fixed memory leak in rsm_or.
+ *
+ * Revision 1.37  1998/09/02 13:53:22  adam
+ * Extra parameter decode added to search routines to implement
+ * persistent queries.
+ *
+ * Revision 1.36  1998/06/24 12:16:16  adam
+ * Support for relations on text operands. Open range support in
+ * DFA module (i.e. [-j], [g-]).
+ *
+ * Revision 1.35  1998/06/23 15:33:35  adam
+ * Added feature to specify sort criteria in query (type 7 specifies
+ * sort flags).
+ *
+ * Revision 1.34  1998/06/22 11:36:50  adam
+ * Added authentication check facility to zebra.
+ *
+ * Revision 1.33  1998/06/12 12:22:14  adam
+ * Work on Zebra API.
+ *
+ * Revision 1.32  1998/05/27 16:57:47  adam
+ * Zebra returns surrogate diagnostic for single records when
+ * appropriate.
+ *
+ * Revision 1.31  1998/05/20 10:12:23  adam
+ * Implemented automatic EXPLAIN database maintenance.
+ * Modified Zebra to work with ASN.1 compiled version of YAZ.
+ *
+ * Revision 1.30  1998/03/05 08:45:13  adam
+ * New result set model and modular ranking system. Moved towards
+ * descent server API. System information stored as "SGML" records.
+ *
+ * Revision 1.29  1998/02/10 12:03:06  adam
+ * Implemented Sort.
+ *
+ * Revision 1.28  1998/01/29 13:40:11  adam
  * Better logging for scan service.
  *
  * Revision 1.27  1997/10/27 14:33:06  adam
  *
  */
 
-
-#ifndef USE_TIMES
-#ifdef __linux__
-#define USE_TIMES 1
-#else
-#define USE_TIMES 0
-#endif
+#if HAVE_SYS_TIMES_H
+#include <sys/times.h>
 #endif
 
-#if USE_TIMES
-#include <sys/times.h>
+#if HAVE_PTHREADS_H
+#include <pthreads.h>
 #endif
 
-#include <backend.h>
+#include <yaz/backend.h>
 #include <rset.h>
 
+#include <sortidx.h>
+#include <passwddb.h>
 #include "index.h"
+#include "zebraapi.h"
 #include "zinfo.h"
 
+YAZ_BEGIN_CDECL
+
 typedef struct {
     int sysno;
     int score;
-} ZServerSetSysno;
+} *ZebraPosSet;
 
-typedef struct ZServerSet_ {
-    char *name;
-    RSET rset;
-    int size;
-    struct ZServerSet_ *next;
-} ZServerSet;
-   
-typedef struct {
-    int registerState; /* 0 (no commit pages), 1 (use commit pages) */
-    time_t registerChange;
-    ZServerSet *sets;
-    Dict dict;
+typedef struct zebra_set *ZebraSet;
+
+typedef struct zebra_rank_class {
+    struct rank_control *control;
+    int init_flag;
+    void *class_handle;
+    struct zebra_rank_class *next;
+} *ZebraRankClass;
+
+struct zebra_service {
+    char *configName;
+    struct zebra_session *sessions;
+    ISAMS isams;
+#if ZMBOL
     ISAM isam;
     ISAMC isamc;
-    Records records;
-    int errCode;
-    char *errString;
-    ODR odr;
-    ZebTargetInfo *zti;
-    data1_handle dh;
-    data1_attset *registered_sets;
+    ISAMD isamd;
+#endif
+    Dict dict;
+    SortIdx sortIdx;
+    int registerState; /* 0 (no commit pages), 1 (use commit pages) */
+    time_t registerChange;
     BFiles bfs;
+    Records records;
+    ZebraExplainInfo zei;
     Res res;
-
     ZebraLockHandle server_lock_cmt;
     ZebraLockHandle server_lock_org;
     char *server_path_prefix;
-#if USE_TIMES
+    data1_handle dh;
+    ZebraMaps zebra_maps;
+    ZebraRankClass rank_classes;
+    RecTypes recTypes;
+    Passwd_db passwd_db;
+    Zebra_mutex_cond session_lock;
+    int stop_flag;
+    int active;
+};
+
+struct recKeys {
+    int buf_used;
+    int buf_max;
+    char *buf;
+    char prevAttrSet;
+    short prevAttrUse;
+    int prevSeqNo;
+};
+
+struct sortKey {
+    char *string;
+    int length;
+    int attrSet;
+    int attrUse;
+    struct sortKey *next;
+};
+
+struct zebra_session {
+    struct zebra_session *next;
+    struct zebra_service *service;
+
+    struct recKeys keys;
+    struct sortKey *sortKeys;
+
+    char **key_buf;
+    size_t ptr_top;
+    size_t ptr_i;
+    size_t key_buf_used;
+    int key_file_no;
+    char *admin_databaseName;
+
+    int destroyed;
+    ZebraSet sets;
+    int errCode;
+    int hits;
+    char *errString;
+#if HAVE_SYS_TIMES_H
     struct tms tms1;
     struct tms tms2;    
 #endif
-    ZebraMaps zebra_maps;
-} ZServerInfo;
+};
+
+struct rank_control {
+    char *name;
+    void *(*create)(ZebraService zh);
+    void (*destroy)(ZebraService zh, void *class_handle);
+    void *(*begin)(ZebraHandle zh, void *class_handle, RSET rset);
+    void (*end)(ZebraHandle zh, void *set_handle);
+    int (*calc)(void *set_handle, int sysno);
+    void (*add)(void *set_handle, int seqno, int term_index);
+};
+
+RSET rpn_search (ZebraHandle zh, NMEM mem,
+                Z_RPNQuery *rpn, int num_bases, char **basenames, 
+                const char *setname, ZebraSet sset);
+
+
+void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+              oid_value attributeset,
+              int num_bases, char **basenames,
+              int *position, int *num_entries, ZebraScanEntry **list,
+              int *is_partial);
 
-int rpn_search (ZServerInfo *zi, 
-                Z_RPNQuery *rpn, int num_bases, char **basenames, 
-                const char *setname, int *hits);
+RSET rset_trunc (ZebraHandle zh, ISAMS_P *isam_p, int no,
+                const char *term, int length_term, const char *flags);
 
-int rpn_scan (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
-              oid_value attributeset,
-              int num_bases, char **basenames,
-              int *position, int *num_entries, struct scan_entry **list,
-              int *status);
+ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
+ZebraSet resultSetGet (ZebraHandle zh, const char *name);
+ZebraSet resultSetAddRPN (ZebraHandle zh, ODR stream, ODR decode,                                         Z_RPNQuery *rpn, int num_bases, char **basenames,
+                          const char *setname);
+RSET resultSetRef (ZebraHandle zh, Z_ResultSetId *resultSetId);
+void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
+                      int *statuses);
 
-RSET rset_trunc (ZServerInfo *zi, ISAM_P *isam_p, int no);
+ZebraPosSet zebraPosSetCreate (ZebraHandle zh, const char *name,
+                              int num, int *positions);
+void zebraPosSetDestroy (ZebraHandle zh, ZebraPosSet records, int num);
 
-ZServerSet *resultSetAdd (ZServerInfo *zi, const char *name,
-                          int ov, RSET rset);
-ZServerSet *resultSetGet (ZServerInfo *zi, const char *name);
-void resultSetDestroy (ZServerInfo *zi);
+void resultSetSort (ZebraHandle zh, NMEM nmem,
+                   int num_input_setnames, const char **input_setnames,
+                   const char *output_setname,
+                   Z_SortKeySpecList *sort_sequence, int *sort_status);
+void resultSetSortSingle (ZebraHandle zh, NMEM nmem,
+                         ZebraSet sset, RSET rset,
+                         Z_SortKeySpecList *sort_sequence, int *sort_status);
+void resultSetRank (ZebraHandle zh, ZebraSet zebraSet, RSET rset);
 
-ZServerSetSysno *resultSetSysnoGet (ZServerInfo *zi, const char *name,
-                                    int num, int *positions);
-void resultSetSysnoDel (ZServerInfo *zi, ZServerSetSysno *records, int num);
-void zlog_rpn (Z_RPNQuery *rpn);
-void zlog_scan (Z_AttributesPlusTerm *zapt, oid_value ast);
+void zebra_sort (ZebraHandle zh, ODR stream,
+                int num_input_setnames, const char **input_setnames,
+                const char *output_setname, Z_SortKeySpecList *sort_sequence,
+                int *sort_status);
 
-int zebra_server_lock_init (ZServerInfo *zi);
-int zebra_server_lock_destroy (ZServerInfo *zi);
-int zebra_server_lock (ZServerInfo *zi, int lockCommit);
-void zebra_server_unlock (ZServerInfo *zi, int commitPhase);
-int zebra_server_lock_get_state (ZServerInfo *zi, time_t *timep);
+int zebra_server_lock_init (ZebraService zh);
+int zebra_server_lock_destroy (ZebraService zh);
+int zebra_server_lock (ZebraService zh, int lockCommit);
+void zebra_server_unlock (ZebraService zh, int commitPhase);
+int zebra_server_lock_get_state (ZebraService zh, time_t *timep);
 
 typedef struct attent
 {
@@ -192,4 +339,38 @@ typedef struct attent
     data1_local_attribute *local_attributes;
 } attent;
 
-int att_getentbyatt(ZServerInfo *zi, attent *res, oid_value set, int att);
+void zebraRankInstall (ZebraService zh, struct rank_control *ctrl);
+ZebraRankClass zebraRankLookup (ZebraHandle zh, const char *name);
+void zebraRankDestroy (ZebraService zh);
+
+int att_getentbyatt(ZebraHandle zh, attent *res, oid_value set, int att);
+
+extern struct rank_control *rank1_class;
+
+int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream,
+                       oid_value input_format, Z_RecordComposition *comp,
+                       oid_value *output_format, char **rec_bufp,
+                       int *rec_lenp, char **basenamep);
+
+void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
+void zebra_index_merge (ZebraHandle zh);
+
+
+struct zebra_fetch_control {
+    off_t offset_end;
+    off_t record_offset;
+    off_t record_int_pos;
+    const char *record_int_buf;
+    int record_int_len;
+    int fd;
+};
+
+int zebra_record_ext_read (void *fh, char *buf, size_t count);
+off_t zebra_record_ext_seek (void *fh, off_t offset);
+off_t zebra_record_ext_tell (void *fh);
+off_t zebra_record_int_seek (void *fh, off_t offset);
+off_t zebra_record_int_tell (void *fh);
+int zebra_record_int_read (void *fh, char *buf, size_t count);
+void zebra_record_int_end (void *fh, off_t offset);
+
+YAZ_END_CDECL