Record buffer maintained in server_info.
[idzebra-moved-to-github.git] / index / zserver.c
index 61e4bd6..c36ccaf 100644 (file)
@@ -1,10 +1,19 @@
 /*
- * Copyright (C) 1995, Index Data I/S 
+ * Copyright (C) 1994-1995, Index Data I/S 
  * All rights reserved.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zserver.c,v $
- * Revision 1.3  1995-09-05 15:28:40  adam
+ * Revision 1.6  1995-09-08 08:53:22  adam
+ * Record buffer maintained in server_info.
+ *
+ * Revision 1.5  1995/09/06  16:11:18  adam
+ * Option: only one word key per file.
+ *
+ * Revision 1.4  1995/09/06  10:33:04  adam
+ * More work on present. Some log messages removed.
+ *
+ * Revision 1.3  1995/09/05  15:28:40  adam
  * More work on search engine.
  *
  * Revision 1.2  1995/09/04  12:33:43  adam
@@ -44,20 +53,21 @@ bend_initresult *bend_init (bend_initrequest *q)
         r.errstring = "dict_open fail: filedict";
         return &r;
     }
-    if (!(server_info.fileDict = dict_open (FNAME_FILE_DICT, 5, 0)))
+    if (!(server_info.fileDict = dict_open (FNAME_FILE_DICT, 10, 0)))
     {
         r.errcode = 1;
         r.errstring = "dict_open fail: filedict";
         return &r;
     }    
-    if (!(server_info.wordDict = dict_open (FNAME_WORD_DICT, 20, 0)))
+    if (!(server_info.wordDict = dict_open (FNAME_WORD_DICT, 40, 0)))
     {
         dict_close (server_info.fileDict);
         r.errcode = 1;
         r.errstring = "dict_open fail: worddict";
         return &r;
     }    
-    if (!(server_info.wordIsam = is_open (FNAME_WORD_ISAM, key_compare, 0)))
+    if (!(server_info.wordIsam = is_open (FNAME_WORD_ISAM, key_compare, 0,
+                                          sizeof (struct it_key))))
     {
         dict_close (server_info.wordDict);
         dict_close (server_info.fileDict);
@@ -65,6 +75,7 @@ bend_initresult *bend_init (bend_initrequest *q)
         r.errstring = "is_open fail: wordisam";
         return &r;
     }
+    server_info.recordBuf = NULL;
     return &r;
 }
 
@@ -99,6 +110,8 @@ bend_fetchresult *bend_fetch (void *handle, bend_fetchrequest *q, int *num)
     r.last_in_set = 0;
     r.basename = "base";
 
+    xfree (server_info.recordBuf);
+    server_info.recordBuf = NULL;
     positions[0] = q->number;
     records = resultSetRecordGet (&server_info, q->setname, 1, positions);
     if (!records)
@@ -107,8 +120,14 @@ bend_fetchresult *bend_fetch (void *handle, bend_fetchrequest *q, int *num)
         r.errcode = 13;
         return &r;
     }
+    if (!records[0].buf)
+    {
+        r.errcode = 13;
+        logf (LOG_DEBUG, "Out of range. pos=%d", q->number);
+        return &r;
+    }
     r.len = records[0].size;
-    r.record = malloc (r.len+1);
+    server_info.recordBuf = r.record = xmalloc (r.len+1);
     strcpy (r.record, records[0].buf);
     resultSetRecordDel (&server_info, records, 1);
     r.format = VAL_SUTRS;
@@ -148,6 +167,8 @@ void bend_close (void *handle)
     dict_close (server_info.wordDict);
     is_close (server_info.wordIsam);
     close (server_info.sys_idx_fd);
+    xfree (server_info.recordBuf);
+    server_info.recordBuf = NULL;
     return;
 }