From b23a551976e442c5cbb0ee4aa46768904dd57ccf Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 4 Aug 2010 11:20:22 +0200 Subject: [PATCH] Move otherinfo facet stuff to facet.c Reshape functions a little.. No need to pass the facet OID when it is already given that this is facets etc.. --- client/client.c | 5 ++--- include/yaz/facet.h | 9 ++++++--- include/yaz/otherinfo.h | 11 ----------- src/facet.c | 47 ++++++++++++++++++++++++++++++++++++++--------- src/otherinfo.c | 39 +-------------------------------------- src/zoom-c.c | 2 +- ztest/ztest.c | 4 +--- 7 files changed, 49 insertions(+), 68 deletions(-) diff --git a/client/client.c b/client/client.c index c6c1ab3..36e328d 100644 --- a/client/client.c +++ b/client/client.c @@ -248,9 +248,8 @@ void add_otherInfos(Z_APDU *a) int i; yaz_oi_APDU(a, &oi); - if (facet_list) { - yaz_oi_set_facetlist_oid(oi, out, yaz_oid_userinfo_facet_1, 1, facet_list); - } + if (facet_list) + yaz_oi_set_facetlist(oi, out, facet_list); for (i = 0; i < maxOtherInfosSupported; ++i) { if (oid_oidlen(extraOtherInfos[i].oid) > 0) diff --git a/include/yaz/facet.h b/include/yaz/facet.h index 8a22208..d51b2ef 100644 --- a/include/yaz/facet.h +++ b/include/yaz/facet.h @@ -69,9 +69,6 @@ void yaz_facet_attr_get_z_attributes(const Z_AttributeList *attributes, struct yaz_facet_attr *av); YAZ_EXPORT -Z_FacetList *extract_facet_request(ODR odr, Z_OtherInformation *search_input); - -YAZ_EXPORT Z_Term *term_create(ODR odr, const char *cstr); YAZ_EXPORT @@ -91,6 +88,12 @@ Z_FacetList* facet_list_create(ODR odr, int num_facets); YAZ_EXPORT void facet_list_field_set(ODR odr, Z_FacetList *list, Z_FacetField *field, int index); +YAZ_EXPORT +void yaz_oi_set_facetlist( + Z_OtherInformation **otherInformation, ODR odr, Z_FacetList *facet_list); + +YAZ_EXPORT +Z_FacetList *yaz_oi_get_facetlist(Z_OtherInformation **otherInformation); YAZ_END_CDECL diff --git a/include/yaz/otherinfo.h b/include/yaz/otherinfo.h index 3c936ee..1660f37 100644 --- a/include/yaz/otherinfo.h +++ b/include/yaz/otherinfo.h @@ -45,17 +45,6 @@ Z_OtherInformationUnit *yaz_oi_update ( const Odr_oid *oid, int categoryValue, int delete_flag); YAZ_EXPORT -void yaz_oi_set_facetlist_oid ( - Z_OtherInformation **otherInformation, ODR odr, - const Odr_oid *oid, int categoryValue, - Z_FacetList *facet_list); - -YAZ_EXPORT -Z_FacetList *yaz_oi_get_facetlist_oid ( - Z_OtherInformation **otherInformation, ODR odr, - const Odr_oid *oid, int categoryValue, int delete_flag); - -YAZ_EXPORT void yaz_oi_set_string_oid ( Z_OtherInformation **otherInformation, ODR odr, const Odr_oid *oid, int categoryValue, diff --git a/src/facet.c b/src/facet.c index 13d1566..dd27b6f 100644 --- a/src/facet.c +++ b/src/facet.c @@ -19,6 +19,44 @@ #include #include +void yaz_oi_set_facetlist( + Z_OtherInformation **otherInformation, ODR odr, + Z_FacetList *facet_list) +{ + int categoryValue = 1; + Z_External *z_external = 0; + Z_OtherInformationUnit *oi = + yaz_oi_update(otherInformation, odr, yaz_oid_userinfo_facet_1, + categoryValue, 0); + if (!oi) + return; + oi->which = Z_OtherInfo_externallyDefinedInfo; + z_external = odr_malloc(odr, sizeof(*z_external)); + z_external->which = Z_External_userFacets; + z_external->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_facet_1); + z_external->indirect_reference = 0; + z_external->descriptor = 0; + z_external->u.facetList = facet_list; + oi->information.externallyDefinedInfo = z_external; +} + +Z_FacetList *yaz_oi_get_facetlist(Z_OtherInformation **otherInformation) +{ + int categoryValue = 1; + Z_External *z_external = 0; + Z_OtherInformationUnit *oi = + yaz_oi_update(otherInformation, 0, yaz_oid_userinfo_facet_1, + categoryValue, 0); + if (!oi) + return 0; + z_external = oi->information.externallyDefinedInfo; + + if (z_external && z_external->which == Z_External_userFacets) { + return z_external->u.facetList; + } + return 0; +} + /* Little helper to extract a string attribute */ /* Gets the first string, there is usually only one */ /* in case of errors, returns null */ @@ -167,15 +205,6 @@ void yaz_facet_attr_get_z_attributes(const Z_AttributeList *attributes, return; } /* facetattrs */ - -Z_FacetList *extract_facet_request(ODR odr, Z_OtherInformation *search_input) -{ - Z_FacetList *facet_list = - yaz_oi_get_facetlist_oid(&search_input, odr, - yaz_oid_userinfo_facet_1, 1, 0); - return facet_list; -} - Z_Term *term_create(ODR odr, const char *cstr) { Z_Term *term = odr_malloc(odr, sizeof(*term)); diff --git a/src/otherinfo.c b/src/otherinfo.c index b022460..80cb19d 100644 --- a/src/otherinfo.c +++ b/src/otherinfo.c @@ -69,7 +69,7 @@ void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip) } } -Z_OtherInformationUnit *yaz_oi_update ( +Z_OtherInformationUnit *yaz_oi_update( Z_OtherInformation **otherInformationP, ODR odr, const Odr_oid *oid, int categoryValue, int delete_flag) { @@ -178,43 +178,6 @@ char *yaz_oi_get_string_oid ( return 0; } -void yaz_oi_set_facetlist_oid ( - Z_OtherInformation **otherInformation, ODR odr, - const Odr_oid *oid, int categoryValue, - Z_FacetList *facet_list) -{ - Z_External *z_external = 0; - Z_OtherInformationUnit *oi = - yaz_oi_update(otherInformation, odr, oid, categoryValue, 0); - if (!oi) - return; - oi->which = Z_OtherInfo_externallyDefinedInfo; - z_external = odr_malloc(odr, sizeof(*z_external)); - z_external->which = Z_External_userFacets; - z_external->direct_reference = odr_oiddup(odr, oid); - z_external->indirect_reference = 0; - z_external->descriptor = 0; - z_external->u.facetList = facet_list; - oi->information.externallyDefinedInfo = z_external; -} - -Z_FacetList *yaz_oi_get_facetlist_oid ( - Z_OtherInformation **otherInformation, ODR odr, - const Odr_oid *oid, int categoryValue, int delete_flag) -{ - Z_External *z_external = 0; - Z_OtherInformationUnit *oi = - yaz_oi_update(otherInformation, 0, oid, categoryValue, delete_flag); - if (!oi) - return 0; - z_external = oi->information.externallyDefinedInfo; - - if (z_external && z_external->which == Z_External_userFacets) { - return z_external->u.facetList; - } - return 0; -} - /* * Local variables: diff --git a/src/zoom-c.c b/src/zoom-c.c index 4ed5d8d..d42e394 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -1760,7 +1760,7 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c) Z_OtherInformation **oi; yaz_oi_APDU(apdu, &oi); if (facet_list) { - yaz_oi_set_facetlist_oid(oi, c->odr_out, yaz_oid_userinfo_facet_1, 1, facet_list); + yaz_oi_set_facetlist(oi, c->odr_out, facet_list); } } } diff --git a/ztest/ztest.c b/ztest/ztest.c index 69a8786..6397831 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -396,9 +396,7 @@ int ztest_search(void *handle, bend_search_rr *rr) if (1) { - /* TODO Not general. Only handles one (Facet) OtherInformation. Overwrite */ - Z_FacetList *facet_list = extract_facet_request(rr->stream, rr->search_input); - + Z_FacetList *facet_list = yaz_oi_get_facetlist(&rr->search_input); if (facet_list) { yaz_log(YLOG_LOG, "%d Facets in search request.", facet_list->num); rr->search_info = build_facet_response(rr->stream, facet_list); -- 1.7.10.4