Work.
[idzebra-moved-to-github.git] / index / zserver.c
index a208a37..2bfe9c8 100644 (file)
@@ -4,7 +4,21 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zserver.c,v $
- * Revision 1.25  1995-11-21 15:29:13  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
@@ -121,7 +135,7 @@ bend_initresult *bend_init (bend_initrequest *q)
         }
     }
 
-    data1_tabpath = res_get(common_resource, "data1_tabpath");
+    data1_tabpath = res_get(common_resource, "profilePath");
     server_info.sets = NULL;
 
     server_info.records = rec_open (0);
@@ -173,11 +187,26 @@ 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,
@@ -189,8 +218,8 @@ static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
     struct recRetrieveCtrl retrieveCtrl;
 
     rec = rec_get (zi->records, sysno);
-    file_type = rec->info[0];
-    fname = rec->info[1];
+    file_type = rec->info[recInfo_fileType];
+    fname = rec->info[recInfo_filename];
 
     if (!(rt = recType_byName (file_type)))
     {
@@ -199,20 +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);
-        rec_rm (&rec);
-        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;
@@ -298,7 +338,7 @@ int main (int argc, char **argv)
     struct statserv_options_block *sob;
 
     sob = statserv_getcontrol ();
-    strcpy (sob->configname, "base");
+    strcpy (sob->configname, FNAME_CONFIG);
     statserv_setcontrol (sob);
 
     return statserv_main (argc, argv);