X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzebraapi.c;h=dc0913fd30c32bb9b0731b947f6199c4a2da2c1c;hb=c63292356fbdef7b575efbf027ba8574482b0320;hp=29ad2f4dc8513735e7cb9e2a07e7226c5938e694;hpb=ba1ca9cd76ff8e56daff04ee0e6c8fa21c7b04b6;p=idzebra-moved-to-github.git diff --git a/index/zebraapi.c b/index/zebraapi.c index 29ad2f4..dc0913f 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,9 +1,26 @@ -/* - * Copyright (C) 1995-2002, Index Data - * All rights reserved. - * - * $Id: zebraapi.c,v 1.62 2002-07-15 11:50:45 adam Exp $ - */ +/* $Id: zebraapi.c,v 1.67 2002-08-18 10:20:35 adam Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 + Index Data Aps + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Zebra; see the file LICENSE.zebra. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. +*/ + + #include #include @@ -53,12 +70,13 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg); ZebraHandle zebra_open (ZebraService zs) { ZebraHandle zh; + const char *default_encoding; if (!zs) return 0; zh = (ZebraHandle) xmalloc (sizeof(*zh)); - yaz_log (LOG_LOG, "zebra_open zs=%p returns %p", zs, zh); + yaz_log (LOG_DEBUG, "zebra_open zs=%p returns %p", zs, zh); zh->service = zs; zh->reg = 0; /* no register attached yet */ @@ -82,6 +100,21 @@ ZebraHandle zebra_open (ZebraService zs) zh->shadow_enable = 1; + default_encoding = res_get_def(zs->global_res, "encoding", "ISO-8859-1"); + zh->record_encoding = xstrdup (default_encoding); +#if HAVE_ICONV_H + zh->iconv_to_utf8 = + iconv_open ("UTF-8", default_encoding); + if (zh->iconv_to_utf8 == (iconv_t)(-1)) + yaz_log (LOG_WARN, "iconv: %s to UTF-8 unsupported", + default_encoding); + zh->iconv_from_utf8 = + iconv_open (default_encoding, "UTF-8"); + if (zh->iconv_to_utf8 == (iconv_t)(-1)) + yaz_log (LOG_WARN, "iconv: UTF-8 to %s unsupported", + default_encoding); +#endif + zebra_mutex_cond_lock (&zs->session_lock); zh->next = zs->sessions; @@ -104,7 +137,7 @@ ZebraService zebra_start (const char *configName) { ZebraService zh = xmalloc (sizeof(*zh)); - yaz_log (LOG_LOG, "Read resources `%s'", configName); + yaz_log (LOG_DEBUG, "Read resources `%s'", configName); zh->global_res = res; zh->configName = xstrdup(configName); @@ -149,10 +182,10 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, assert (res); - yaz_log (LOG_LOG, "zebra_register_open rw = %d useshadow=%d p=%p", + yaz_log (LOG_DEBUG, "zebra_register_open rw = %d useshadow=%d p=%p", rw, useshadow, reg); - reg->dh = data1_create (); + reg->dh = data1_createx (DATA1_FLAG_XML); if (!reg->dh) return 0; reg->bfs = bfs_create (res_get (res, "register"), reg_path); @@ -297,7 +330,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name, return 0; } reg->active = 2; - yaz_log (LOG_LOG, "zebra_register_open ok p=%p", reg); + yaz_log (LOG_DEBUG, "zebra_register_open ok p=%p", reg); return reg; } @@ -318,7 +351,7 @@ void zebra_admin_start (ZebraHandle zh) static void zebra_register_close (ZebraService zs, struct zebra_register *reg) { - yaz_log(LOG_LOG, "zebra_register_close p=%p", reg); + yaz_log(LOG_DEBUG, "zebra_register_close p=%p", reg); reg->stop_flag = 0; zebra_chdir (zs); if (reg->records) @@ -350,7 +383,7 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg) xfree (reg->key_buf); xfree (reg->name); xfree (reg); - yaz_log (LOG_LOG, "zebra_register_close 2"); + yaz_log(LOG_DEBUG, "zebra_register_close 2"); } void zebra_stop(ZebraService zs) @@ -387,7 +420,7 @@ void zebra_close (ZebraHandle zh) return; zs = zh->service; - yaz_log (LOG_LOG, "zebra_close zh=%p", zh); + yaz_log (LOG_DEBUG, "zebra_close zh=%p", zh); if (!zh) return ; resultSetDestroy (zh, -1, 0, 0); @@ -397,6 +430,14 @@ void zebra_close (ZebraHandle zh) zebra_register_close (zh->service, zh->reg); zebra_close_res (zh); + xfree (zh->record_encoding); +#if HAVE_ICONV_H + if (zh->iconv_to_utf8 != (iconv_t) (-1)) + iconv_close (zh->iconv_to_utf8); + if (zh->iconv_from_utf8 != (iconv_t) (-1)) + iconv_close (zh->iconv_from_utf8); +#endif + xfree (zh->admin_databaseName); zebra_mutex_cond_lock (&zs->session_lock); zebra_lock_destroy (zh->lock_normal); @@ -653,6 +694,11 @@ int zebra_select_databases (ZebraHandle zh, int num_bases, zh->errCode = 109; return -1; } + if (!zh->lock_normal || !zh->lock_shadow) + { + zh->errCode = 2; + return -1; + } return 0; } @@ -967,6 +1013,12 @@ int zebra_begin_read (ZebraHandle zh) zh->errCode = 109; return -1; } + if (!zh->lock_normal || !zh->lock_shadow) + { + (zh->trans_no)--; + zh->errCode = 2; + return -1; + } zebra_get_state (zh, &val, &seqno); if (val == 'd') val = 'o'; @@ -1304,3 +1356,9 @@ void zebra_shadow_enable (ZebraHandle zh, int value) zh->shadow_enable = value; } +int zebra_record_encoding (ZebraHandle zh, const char *encoding) +{ + xfree (zh->record_encoding); + zh->record_encoding = xstrdup (encoding); + return 0; +}