Zebra config renamed.
[idzebra-moved-to-github.git] / index / zserver.c
index 553e6fb..2bfe9c8 100644 (file)
@@ -4,7 +4,36 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zserver.c,v $
- * Revision 1.20  1995-10-27 14:00:12  adam
+ * Revision 1.28  1995-11-28 09:09:48  adam
+ * Zebra config renamed.
+ * Use setting 'recordId' to identify record now.
+ * Bug fix in recindex.c: rec_release_blocks was invokeded even
+ * though the blocks were already released.
+ * File traversal properly deletes records when needed.
+ *
+ * Revision 1.27  1995/11/27  13:58:54  adam
+ * New option -t. storeStore data implemented in server.
+ *
+ * Revision 1.26  1995/11/25  10:24:07  adam
+ * More record fields - they are enumerated now.
+ * New options: flagStoreData flagStoreKey.
+ *
+ * Revision 1.25  1995/11/21  15:29:13  adam
+ * Config file 'base' read by default by both indexer and server.
+ *
+ * Revision 1.24  1995/11/20  16:59:47  adam
+ * New update method: the 'old' keys are saved for each records.
+ *
+ * Revision 1.23  1995/11/16  17:00:56  adam
+ * Better logging of rpn query.
+ *
+ * Revision 1.22  1995/11/16  15:34:55  adam
+ * Uses new record management system in both indexer and server.
+ *
+ * Revision 1.21  1995/11/01  16:25:52  quinn
+ * *** empty log message ***
+ *
+ * Revision 1.20  1995/10/27  14:00:12  adam
  * Implemented detection of database availability.
  *
  * Revision 1.19  1995/10/17  18:02:11  adam
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <common.h>
+#include <data1.h>
 #include <recctrl.h>
 #include <dmalloc.h>
 #include "zserver.h"
@@ -90,25 +121,27 @@ bend_initresult *bend_init (bend_initrequest *q)
     r.handle = name;
 
     logf (LOG_DEBUG, "bend_init");
-    server_info.sets = NULL;
-    if (!(server_info.sys_idx_fd = open (FNAME_SYS_IDX, O_RDONLY)))
+
+    if (!common_resource)
     {
-        logf (LOG_WARN|LOG_ERRNO, "sys_idx open fail");
-        r.errcode = 1;
-        r.errstring = "sys_idx open fail";
-        return &r;
+        struct statserv_options_block *sob;
+
+        sob = statserv_getcontrol ();
+        logf (LOG_LOG, "Reading resources from %s", sob->configname);
+        if (!(common_resource = res_open (sob->configname)))
+        {
+            logf (LOG_FATAL, "Cannot open resource `%s'", sob->configname);
+            exit (1);
+        }
     }
-    if (!(server_info.fileDict = dict_open (FNAME_FILE_DICT, 10, 0)))
-    {
-        logf (LOG_WARN, "dict_open fail: fname dict");
-        r.errcode = 1;
-        r.errstring = "dict_open fail: fname dict";
-        return &r;
-    }    
+
+    data1_tabpath = res_get(common_resource, "profilePath");
+    server_info.sets = NULL;
+
+    server_info.records = rec_open (0);
     if (!(server_info.wordDict = dict_open (FNAME_WORD_DICT, 40, 0)))
     {
         logf (LOG_WARN, "dict_open fail: word dict");
-        dict_close (server_info.fileDict);
         r.errcode = 1;
         r.errstring = "dict_open fail: word dict";
         return &r;
@@ -118,7 +151,6 @@ bend_initresult *bend_init (bend_initrequest *q)
     {
         logf (LOG_WARN, "is_open fail: word isam");
         dict_close (server_info.wordDict);
-        dict_close (server_info.fileDict);
         r.errcode = 1;
         r.errstring = "is_open fail: word isam";
         return &r;
@@ -135,9 +167,12 @@ bend_searchresult *bend_search (void *handle, bend_searchrequest *q, int *fd)
     r.errstring = 0;
     r.hits = 0;
 
+
     odr_reset (server_info.odr);
     server_info.errCode = 0;
     server_info.errString = NULL;
+
+    logf (LOG_LOG, "ResultSet '%s'", q->setname);
     switch (q->query->which)
     {
     case Z_Query_type_1:
@@ -152,34 +187,40 @@ bend_searchresult *bend_search (void *handle, bend_searchrequest *q, int *fd)
     return &r;
 }
 
-static int record_read (int fd, char *buf, size_t count)
+static int record_ext_read (int fd, char *buf, size_t count)
 {
     return read (fd, buf, count);
 }
 
+static int record_int_pos;
+static char *record_int_buf;
+static int record_int_len;
+
+static int record_int_read (int fd, char *buf, size_t count)
+{
+    int l = record_int_len - record_int_pos;
+    if (l <= 0)
+        return 0;
+    l = (l < count) ? l : count;
+    memcpy (buf, record_int_buf + record_int_pos, l);
+    record_int_pos += l;
+    return l;
+}
+
 static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
                           oid_value input_format, Z_RecordComposition *comp,
                          oid_value *output_format, char **rec_bufp,
                          int *rec_lenp)
 {
-    char record_info[SYS_IDX_ENTRY_LEN];
+    Record rec;
     char *fname, *file_type;
     RecType rt;
     struct recRetrieveCtrl retrieveCtrl;
 
-    if (lseek (zi->sys_idx_fd, sysno * SYS_IDX_ENTRY_LEN,
-               SEEK_SET) == -1)
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "Retrieve: lseek of sys_idx");
-        exit (1);
-    }
-    if (read (zi->sys_idx_fd, record_info, SYS_IDX_ENTRY_LEN) == -1)
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "Retrieve: read of sys_idx");
-        exit (1);
-    }
-    file_type = record_info;
-    fname = record_info + strlen(record_info) + 1;
+    rec = rec_get (zi->records, sysno);
+    file_type = rec->info[recInfo_fileType];
+    fname = rec->info[recInfo_filename];
+
     if (!(rt = recType_byName (file_type)))
     {
         logf (LOG_FATAL|LOG_ERRNO, "Retrieve: Cannot handle type %s", 
@@ -187,19 +228,31 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
         exit (1);
     }
     logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score);
-    if ((retrieveCtrl.fd = open (fname, O_RDONLY)) == -1)
+    if (rec->size[recInfo_storeData] > 0)
+    {
+        retrieveCtrl.readf = record_int_read;
+        record_int_len = rec->size[recInfo_storeData];
+        record_int_buf = rec->info[recInfo_storeData];
+        record_int_pos = 0;
+        logf (LOG_DEBUG, "Internal retrieve. %d bytes", record_int_len);
+    }
+    else 
     {
-        char *msg = "Record doesn't exist";
-        logf (LOG_WARN|LOG_ERRNO, "Retrieve: Open record file %s", fname);
-        *output_format = VAL_SUTRS;
-        *rec_bufp = msg;
-        *rec_lenp = strlen (msg);
-        return 0;     /* or 14: System error in presenting records */
+        if ((retrieveCtrl.fd = open (fname, O_RDONLY)) == -1)
+        {
+            char *msg = "Record doesn't exist";
+            logf (LOG_WARN|LOG_ERRNO, "Retrieve: Open record file %s", fname);
+            *output_format = VAL_SUTRS;
+            *rec_bufp = msg;
+            *rec_lenp = strlen (msg);
+            rec_rm (&rec);
+            return 0;     /* or 14: System error in presenting records */
+        }
+        retrieveCtrl.readf = record_ext_read;
     }
     retrieveCtrl.localno = sysno;
     retrieveCtrl.score = score;
     retrieveCtrl.odr = stream;
-    retrieveCtrl.readf = record_read;
     retrieveCtrl.input_format = retrieveCtrl.output_format = input_format;
     retrieveCtrl.comp = comp;
     retrieveCtrl.diagnostic = 0;
@@ -208,6 +261,8 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
     *rec_bufp = retrieveCtrl.rec_buf;
     *rec_lenp = retrieveCtrl.rec_len;
     close (retrieveCtrl.fd);
+    rec_rm (&rec);
+
     return retrieveCtrl.diagnostic;
 }
 
@@ -272,21 +327,19 @@ bend_scanresult *bend_scan (void *handle, bend_scanrequest *q, int *num)
 
 void bend_close (void *handle)
 {
-    dict_close (server_info.fileDict);
     dict_close (server_info.wordDict);
     is_close (server_info.wordIsam);
-    close (server_info.sys_idx_fd);
+    rec_close (&server_info.records);
     return;
 }
 
 int main (int argc, char **argv)
 {
-    char *base_name = "base";
+    struct statserv_options_block *sob;
+
+    sob = statserv_getcontrol ();
+    strcpy (sob->configname, FNAME_CONFIG);
+    statserv_setcontrol (sob);
 
-    if (!(common_resource = res_open (base_name)))
-    {
-        logf (LOG_FATAL, "Cannot open resource `%s'", base_name);
-        exit (1);
-    }
     return statserv_main (argc, argv);
 }