From 0594c1b39bd724b0f80ef9dc1ceb937f5cf2c199 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 18 May 2005 12:38:40 +0000 Subject: [PATCH] Added functin yaz_del_charneg_record, which removes character set negotiation from otherInfo. --- include/yaz/charneg.h | 47 ++++++++++++++++++++++++++---------------- src/charneg.c | 55 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/include/yaz/charneg.h b/include/yaz/charneg.h index 82c9a11..f8815af 100644 --- a/include/yaz/charneg.h +++ b/include/yaz/charneg.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: charneg.h,v 1.5 2005-01-15 19:47:09 adam Exp $ + * $Id: charneg.h,v 1.6 2005-05-18 12:38:40 adam Exp $ */ /** * \file charneg.h @@ -50,35 +50,46 @@ YAZ_BEGIN_CDECL /* * Get (*) record from request */ -YAZ_EXPORT Z_CharSetandLanguageNegotiation * - yaz_get_charneg_record(Z_OtherInformation *p); +YAZ_EXPORT +Z_CharSetandLanguageNegotiation *yaz_get_charneg_record(Z_OtherInformation *p); + +/* + * Delete (*) record from request + */ +YAZ_EXPORT +int yaz_del_charneg_record(Z_OtherInformation **p); /* * Client's part. */ -YAZ_EXPORT Z_External *yaz_set_proposal_charneg(ODR odr, - const char **charsets, int num_charsets, const char **langs, - int num_langs, int selected); +YAZ_EXPORT +Z_External *yaz_set_proposal_charneg(ODR odr, + const char **charsets, int num_charsets, + const char **langs, + int num_langs, int selected); -YAZ_EXPORT void yaz_get_response_charneg(NMEM mem, - Z_CharSetandLanguageNegotiation *p, char **charset, char **lang, - int *selected); +YAZ_EXPORT +void yaz_get_response_charneg(NMEM mem, + Z_CharSetandLanguageNegotiation *p, + char **charset, char **lang, + int *selected); /* * Server's part */ -YAZ_EXPORT Z_External *yaz_set_response_charneg(ODR odr, - const char *charset, const char *lang, int selected); - - -YAZ_EXPORT void yaz_get_proposal_charneg(NMEM mem, - Z_CharSetandLanguageNegotiation *p, - char ***charsets, int *num_charsets, - char ***langs, int *num_langs, - int *selected); +YAZ_EXPORT +Z_External *yaz_set_response_charneg(ODR odr, + const char *charset, const char *lang, + int selected); +YAZ_EXPORT +void yaz_get_proposal_charneg(NMEM mem, + Z_CharSetandLanguageNegotiation *p, + char ***charsets, int *num_charsets, + char ***langs, int *num_langs, + int *selected); YAZ_END_CDECL #endif diff --git a/src/charneg.c b/src/charneg.c index 1323862..8d6774e 100644 --- a/src/charneg.c +++ b/src/charneg.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: charneg.c,v 1.3 2005-01-15 19:47:11 adam Exp $ + * $Id: charneg.c,v 1.4 2005-05-18 12:38:40 adam Exp $ */ /** @@ -260,22 +260,22 @@ Z_External *yaz_set_response_charneg(ODR o, const char *charset, /* Get negotiation from OtherInformation. Client&Server side */ Z_CharSetandLanguageNegotiation *yaz_get_charneg_record(Z_OtherInformation *p) { - Z_External *pext; int i; - if(!p) + if (!p) return 0; - for (i=0; inum_elements; i++) { - + for (i = 0; i < p->num_elements; i++) { + Z_External *pext; if ((p->list[i]->which == Z_OtherInfo_externallyDefinedInfo) && (pext = p->list[i]->information.externallyDefinedInfo)) { - + oident *ent = oid_getentbyoid(pext->direct_reference); - - if (ent && ent->value == VAL_CHARNEG3 && ent->oclass == CLASS_NEGOT && - pext->which == Z_External_charSetandLanguageNegotiation) { - + + if (ent && ent->value == VAL_CHARNEG3 + && ent->oclass == CLASS_NEGOT + && pext->which == Z_External_charSetandLanguageNegotiation) + { return pext->u.charNeg3; } } @@ -283,6 +283,41 @@ Z_CharSetandLanguageNegotiation *yaz_get_charneg_record(Z_OtherInformation *p) return 0; } +/* Delete negotiation from OtherInformation. Client&Server side */ +int yaz_del_charneg_record(Z_OtherInformation **p) +{ + int i; + + if (!*p) + return 0; + + for (i = 0; i < (*p)->num_elements; i++) { + Z_External *pext; + if (((*p)->list[i]->which == Z_OtherInfo_externallyDefinedInfo) && + (pext = (*p)->list[i]->information.externallyDefinedInfo)) { + + oident *ent = oid_getentbyoid(pext->direct_reference); + + if (ent && ent->value == VAL_CHARNEG3 + && ent->oclass == CLASS_NEGOT + && pext->which == Z_External_charSetandLanguageNegotiation) + { + --((*p)->num_elements); + if ((*p)->num_elements == 0) + *p = 0; + else + { + for(; i < (*p)->num_elements; i++) + (*p)->list[i] = (*p)->list[i+1]; + } + return 1; + } + } + } + return 0; +} + + /* Get charsets, langs, selected from negotiation.. Server side */ void yaz_get_proposal_charneg(NMEM mem, Z_CharSetandLanguageNegotiation *p, char ***charsets, int *num_charsets, -- 1.7.10.4