From: Adam Dickmeiss Date: Mon, 21 May 2007 11:54:59 +0000 (+0000) Subject: Zebra returns character encoding as part of init response even if X-Git-Tag: ZEBRA.2.0.16~38 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=8174591e6c5c002acca0db83c4c46e1d0265a9e2;p=idzebra-moved-to-github.git Zebra returns character encoding as part of init response even if client does not suggest one. --- diff --git a/include/idzebra/api.h b/include/idzebra/api.h index 4bb7d3f..f38e657 100644 --- a/include/idzebra/api.h +++ b/include/idzebra/api.h @@ -1,4 +1,4 @@ -/* $Id: api.h,v 1.50 2007-05-09 07:42:46 adam Exp $ +/* $Id: api.h,v 1.51 2007-05-21 11:54:59 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -161,6 +161,14 @@ char *zebra_errAdd(ZebraHandle zh); YAZ_EXPORT void zebra_result(ZebraHandle zh, int *code, char **addinfo); + +/** \brief Returns character set encoding for session + \param zh zebra session handle. + \returns encoding name (e.g. "iso-8859-1") +*/ +YAZ_EXPORT +const char *zebra_get_encoding(ZebraHandle zh); + /** \brief Set limit before Zebra does approx hit count \param zh session handle \param approx_limit the limit diff --git a/index/zebraapi.c b/index/zebraapi.c index d17444e..10a4954 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.255 2007-05-08 12:50:04 adam Exp $ +/* $Id: zebraapi.c,v 1.256 2007-05-21 11:54:59 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -99,6 +99,12 @@ static struct zebra_register *zebra_register_open(ZebraService zs, const char *reg_path); static void zebra_register_close(ZebraService zs, struct zebra_register *reg); +const char *zebra_get_encoding(ZebraHandle zh) +{ + assert(zh && zh->session_res); + return res_get_def(zh->session_res, "encoding", "ISO-8859-1"); +} + ZebraHandle zebra_open(ZebraService zs, Res res) { ZebraHandle zh; @@ -147,7 +153,7 @@ ZebraHandle zebra_open(ZebraService zs, Res res) zh->break_handler_func = 0; zh->break_handler_data = 0; - default_encoding = res_get_def(zh->session_res, "encoding", "ISO-8859-1"); + default_encoding = zebra_get_encoding(zh); zh->iconv_to_utf8 = yaz_iconv_open ("UTF-8", default_encoding); diff --git a/index/zebrasrv.c b/index/zebrasrv.c index c57fbc4..25f2d27 100644 --- a/index/zebrasrv.c +++ b/index/zebrasrv.c @@ -1,4 +1,4 @@ -/* $Id: zebrasrv.c,v 1.15 2007-04-17 20:27:14 adam Exp $ +/* $Id: zebrasrv.c,v 1.16 2007-05-21 11:54:59 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -85,6 +85,8 @@ bend_initresult *bend_init (bend_initrequest *q) return r; } r->handle = zh; + + q->query_charset = odr_strdup(q->stream, zebra_get_encoding(zh)); if (q->auth) { if (q->auth->which == Z_IdAuthentication_open) @@ -113,7 +115,7 @@ bend_initresult *bend_init (bend_initrequest *q) r->errstring = user; return r; } - if (q->charneg_request) /* characater set and langauge negotiation? */ + if (q->charneg_request) /* characater set and language negotiation? */ { char **charsets = 0; int num_charsets; @@ -123,11 +125,9 @@ bend_initresult *bend_init (bend_initrequest *q) int i; NMEM nmem = nmem_create(); - yaz_log (YLOG_LOG, "character set and language negotiation"); - - yaz_get_proposal_charneg (nmem, q->charneg_request, - &charsets, &num_charsets, - &langs, &num_langs, &selected); + yaz_get_proposal_charneg(nmem, q->charneg_request, + &charsets, &num_charsets, + &langs, &num_langs, &selected); for (i = 0; i < num_charsets; i++) { @@ -152,21 +152,21 @@ bend_initresult *bend_init (bend_initrequest *q) } else { right_name = charsets[i]; } - if (odr_set_charset (q->decode, "UTF-8", right_name) == 0) + if (odr_set_charset(q->decode, "UTF-8", right_name) == 0) { - yaz_log (YLOG_LOG, "charset %d %s (proper name %s): OK", i, - charsets[i], right_name); - odr_set_charset (q->stream, right_name, "UTF-8"); + yaz_log(YLOG_LOG, "charset %d %s (proper name %s): OK", i, + charsets[i], right_name); + odr_set_charset(q->stream, right_name, "UTF-8"); if (selected) zebra_record_encoding(zh, right_name); zebra_octet_term_encoding(zh, right_name); q->charneg_response = - yaz_set_response_charneg (q->stream, charsets[i], - 0, selected); + yaz_set_response_charneg(q->stream, charsets[i], + 0, selected); break; } else { - yaz_log (YLOG_LOG, "charset %d %s (proper name %s): unsupported", i, - charsets[i], right_name); + yaz_log(YLOG_LOG, "charset %d %s (proper name %s): unsupported", i, + charsets[i], right_name); } } nmem_destroy(nmem);