Make yaz_use_attribute_create a public function
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 19 Mar 2014 13:24:30 +0000 (14:24 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 19 Mar 2014 13:24:30 +0000 (14:24 +0100)
Useful when generating a facet response in a server.

include/yaz/proto.h
src/sru-p.h
src/sru_facet.c
src/srw.c
src/srwutil.c

index 43441a7..a5115e8 100644 (file)
@@ -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);
 
 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 <yaz/prt-ext.h>
 YAZ_END_CDECL
 
 #include <yaz/prt-ext.h>
index 3a3031b..30c6f1b 100644 (file)
@@ -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);
 
 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,
 char *yaz_negotiate_sru_version(char *input_ver);
 
 void yaz_sru_facet_request(ODR, Z_FacetList **facetList,
index 126fb41..6802b15 100644 (file)
@@ -259,32 +259,8 @@ void yaz_sru_facet_response(ODR o, Z_FacetList **facetList, xmlNodePtr n)
                             p_terms = p2;
                     }
                     if (index_name)
                             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;
                     if (p_terms)
                     {
                         xmlNode *p;
index fcb1d54..f4a6453 100644 (file)
--- a/src/srw.c
+++ b/src/srw.c
@@ -19,6 +19,7 @@
 #include <libxml/tree.h>
 #include <assert.h>
 #include <yaz/facet.h>
 #include <libxml/tree.h>
 #include <assert.h>
 #include <yaz/facet.h>
+#include <yaz/proto.h>
 #include "sru-p.h"
 
 char *yaz_negotiate_sru_version(char *input_ver)
 #include "sru-p.h"
 
 char *yaz_negotiate_sru_version(char *input_ver)
index cb00278..83665d4 100644 (file)
@@ -39,29 +39,37 @@ char *yaz_encode_sru_dbpath_odr(ODR out, const char *db)
     return dst;
 }
 
     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));
         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 *));
         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));
         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;
 }
     attributes->attributes = elements;
     return attributes;
 }