From 5350317640042c3507172d28d14279595eb7a49f Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 19 Mar 2014 14:24:30 +0100 Subject: [PATCH] Make yaz_use_attribute_create a public function Useful when generating a facet response in a server. --- include/yaz/proto.h | 8 ++++++++ src/sru-p.h | 2 -- src/sru_facet.c | 28 ++-------------------------- src/srw.c | 1 + src/srwutil.c | 46 +++++++++++++++++++++++++++------------------- 5 files changed, 38 insertions(+), 47 deletions(-) diff --git a/include/yaz/proto.h b/include/yaz/proto.h index 43441a7..a5115e8 100644 --- a/include/yaz/proto.h +++ b/include/yaz/proto.h @@ -193,6 +193,14 @@ void yaz_set_esn(Z_RecordComposition **comp_p, const char *esn, NMEM nmem); YAZ_EXPORT Z_DefaultDiagFormat *yaz_decode_init_diag(int no, Z_InitResponse *initrs); +/** \brief creates AttributeList with type=1(use) and string value + \param o ODR for encoding + \param name use-value + \returns attribute list with only one use-attribute +*/ +YAZ_EXPORT +Z_AttributeList *yaz_use_attribute_create(ODR o, const char *name); + YAZ_END_CDECL #include diff --git a/src/sru-p.h b/src/sru-p.h index 3a3031b..30c6f1b 100644 --- a/src/sru-p.h +++ b/src/sru-p.h @@ -35,8 +35,6 @@ void yaz_add_name_value_str(ODR o, char **name, char **value, int *i, void yaz_add_name_value_int(ODR o, char **name, char **value, int *i, char *a_name, Odr_int *val); -Z_AttributeList *yaz_use_attribute_create(ODR o, const char *name); - char *yaz_negotiate_sru_version(char *input_ver); void yaz_sru_facet_request(ODR, Z_FacetList **facetList, diff --git a/src/sru_facet.c b/src/sru_facet.c index 126fb41..6802b15 100644 --- a/src/sru_facet.c +++ b/src/sru_facet.c @@ -259,32 +259,8 @@ void yaz_sru_facet_response(ODR o, Z_FacetList **facetList, xmlNodePtr n) p_terms = p2; } if (index_name) - { - Z_AttributeList *al = - (Z_AttributeList*) odr_malloc(o, sizeof(*al)); - Z_ComplexAttribute *ca = - (Z_ComplexAttribute *) odr_malloc(o, sizeof(*ca)); - Z_AttributeElement *ae = - (Z_AttributeElement *) odr_malloc(o, sizeof(*ae)); - al->num_attributes = 1; - al->attributes = (Z_AttributeElement **) - odr_malloc(o, sizeof(*al->attributes)); - al->attributes[0] = ae; - ae->attributeSet = 0; - ae->attributeType = odr_intdup(o, 1); - ae->which = Z_AttributeValue_complex; - ae->value.complex = ca; - ca->num_semanticAction = 0; - ca->semanticAction = 0; - ca->num_list = 1; - ca->list = (Z_StringOrNumeric **) - odr_malloc(o, sizeof(*ca->list)); - ca->list[0] = (Z_StringOrNumeric *) - odr_malloc(o, sizeof(**ca->list)); - ca->list[0]->which = Z_StringOrNumeric_string; - ca->list[0]->u.string = index_name; - ff->attributes = al; - } + ff->attributes = yaz_use_attribute_create(o, + index_name); if (p_terms) { xmlNode *p; diff --git a/src/srw.c b/src/srw.c index fcb1d54..f4a6453 100644 --- a/src/srw.c +++ b/src/srw.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "sru-p.h" char *yaz_negotiate_sru_version(char *input_ver) diff --git a/src/srwutil.c b/src/srwutil.c index cb00278..83665d4 100644 --- a/src/srwutil.c +++ b/src/srwutil.c @@ -39,29 +39,37 @@ char *yaz_encode_sru_dbpath_odr(ODR out, const char *db) return dst; } -Z_AttributeList *yaz_use_attribute_create(ODR o, const char *name) +Z_AttributeElement *yaz_string_element_create(ODR o, int type, + const char *value) { - Z_AttributeList *attributes= (Z_AttributeList *) - odr_malloc(o, sizeof(*attributes)); - Z_AttributeElement ** elements; - attributes->num_attributes = 1; - elements = (Z_AttributeElement**) - odr_malloc(o, attributes->num_attributes * sizeof(*elements)); - elements[0] = (Z_AttributeElement*) odr_malloc(o,sizeof(**elements)); - elements[0]->attributeType = odr_intdup(o, 1); - elements[0]->attributeSet = odr_nullval(); - elements[0]->which = Z_AttributeValue_complex; - elements[0]->value.complex = (Z_ComplexAttribute *) + Z_AttributeElement *element = (Z_AttributeElement*) + odr_malloc(o, sizeof(*element)); + element->attributeType = odr_intdup(o, type); + element->attributeSet = odr_nullval(); + element->which = Z_AttributeValue_complex; + element->value.complex = (Z_ComplexAttribute *) odr_malloc(o, sizeof(Z_ComplexAttribute)); - elements[0]->value.complex->num_list = 1; - elements[0]->value.complex->list = (Z_StringOrNumeric **) + element->value.complex->num_list = 1; + element->value.complex->list = (Z_StringOrNumeric **) odr_malloc(o, 1 * sizeof(Z_StringOrNumeric *)); - elements[0]->value.complex->list[0] = (Z_StringOrNumeric *) + element->value.complex->list[0] = (Z_StringOrNumeric *) odr_malloc(o, sizeof(Z_StringOrNumeric)); - elements[0]->value.complex->list[0]->which = Z_StringOrNumeric_string; - elements[0]->value.complex->list[0]->u.string = odr_strdup(o, name); - elements[0]->value.complex->semanticAction = 0; - elements[0]->value.complex->num_semanticAction = 0; + element->value.complex->list[0]->which = Z_StringOrNumeric_string; + element->value.complex->list[0]->u.string = odr_strdup(o, value); + element->value.complex->semanticAction = 0; + element->value.complex->num_semanticAction = 0; + return element; +} + +Z_AttributeList *yaz_use_attribute_create(ODR o, const char *name) +{ + Z_AttributeList *attributes = (Z_AttributeList *) + odr_malloc(o, sizeof(*attributes)); + Z_AttributeElement **elements = (Z_AttributeElement**) + odr_malloc(o, attributes->num_attributes * sizeof(*elements)); + + elements[0] = yaz_string_element_create(o, 1, name); + attributes->num_attributes = 1; attributes->attributes = elements; return attributes; } -- 1.7.10.4