From: Adam Dickmeiss Date: Mon, 6 Jul 2009 14:30:21 +0000 (+0200) Subject: Check for supported recordCompression during startup X-Git-Tag: v2.0.39~1 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=5a5e8d852ce98a805b02679a971cdf4216d94177;p=idzebra-moved-to-github.git Check for supported recordCompression during startup Function zebra_register_open checks that specified recordCompression is supported. --- diff --git a/index/recindex.h b/index/recindex.h index 3320929..8e854ce 100644 --- a/index/recindex.h +++ b/index/recindex.h @@ -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, diff --git a/index/records.c b/index/records.c index d1f99a3..797ffa5 100644 --- a/index/records.c +++ b/index/records.c @@ -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; diff --git a/index/zebraapi.c b/index/zebraapi.c index 42800e7..d23f8ca 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -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"))