Check for supported recordCompression during startup
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 6 Jul 2009 14:30:21 +0000 (16:30 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 6 Jul 2009 14:32:06 +0000 (16:32 +0200)
Function zebra_register_open checks that specified recordCompression
is supported.

index/recindex.h
index/records.c
index/zebraapi.c

index 3320929..8e854ce 100644 (file)
@@ -85,16 +85,27 @@ ZEBRA_RES rec_close (Records *p);
 */
 Records rec_open(BFiles bfs, int rw, int compression_method);
 
+/** \brief check whether a compression method is supported
+    \param compression_method (REC_COMPRESS_..)
+    \retval 0 if method is unsupported
+    \retval 1 if method is supported
+*/
+int rec_check_compression_method(int compression_method);
+
 char *rec_strdup(const char *s, size_t *len);
 void rec_prstat(Records p, int verbose);
 
 zint rec_sysno_to_int(zint sysno);
 
-/** \brief compression types */
+
+/** \brief No compression ("none") */
 #define REC_COMPRESS_NONE   0
+/** \brief BZIP2 compression (slow and requires big chunks) */
 #define REC_COMPRESS_BZIP2  1
+/** \brief zlib compression (faster and works off small chunks) */
 #define REC_COMPRESS_ZLIB   2
 
+
 enum { 
     recInfo_fileType, 
     recInfo_filename, 
index d1f99a3..797ffa5 100644 (file)
@@ -280,6 +280,28 @@ static ZEBRA_RES rec_write_tmp_buf(Records p, int size, zint *sysnos)
     return ZEBRA_OK;
 }
 
+int rec_check_compression_method(int compression_method)
+{
+    switch(compression_method)
+    {
+    case REC_COMPRESS_ZLIB:
+#if HAVE_ZLIB_H
+        return 1;
+#else
+        return 0;
+#endif
+    case REC_COMPRESS_BZIP2:
+#if HAVE_BZLIB_H
+        return 1;
+#else
+        return 0;
+#endif
+    case REC_COMPRESS_NONE:
+        return 1;
+    }
+    return 0;
+}
+
 Records rec_open(BFiles bfs, int rw, int compression_method)
 {
     Records p;
index 42800e7..d23f8ca 100644 (file)
@@ -433,6 +433,13 @@ struct zebra_register *zebra_register_open(ZebraService zs, const char *name,
         ret = ZEBRA_FAIL;
     }
 
+    if (!rec_check_compression_method(record_compression))
+    {
+        yaz_log(YLOG_FATAL, "unsupported recordCompression: %s",
+                compression_str);
+        ret = ZEBRA_FAIL;
+    }
+
     {
        const char *index_fname = res_get_def(res, "index", "default.idx");
        if (index_fname && *index_fname && strcmp(index_fname, "none"))