From 8f8560e0ab3b370263683d8aea81b839c5927091 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 13 Dec 2006 11:25:17 +0000 Subject: [PATCH] Added header yaz/xmltypes.h which include libxml2' node definitions or provide dummy alternatives if libxml2 is disabled (or does not exist). This allows all Libxml2 related functions to be publicly defined unconditionally. Also provides a more type safe system for applications using these functions. --- include/yaz/Makefile.am | 4 +-- include/yaz/marcdisp.h | 9 ++++--- include/yaz/nmem_xml.h | 6 ++--- include/yaz/record_conv.h | 7 +++--- include/yaz/retrieval.h | 4 +-- include/yaz/xmlquery.h | 7 ++---- include/yaz/xmltypes.h | 59 +++++++++++++++++++++++++++++++++++++++++++++ src/elementset.c | 6 ++--- src/marcdisp.c | 12 ++++----- src/record_conv.c | 6 ++--- src/retrieval.c | 6 ++--- 11 files changed, 87 insertions(+), 39 deletions(-) create mode 100644 include/yaz/xmltypes.h diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index 449f834..7f818ee 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.35 2006-12-13 10:35:44 adam Exp $ +## $Id: Makefile.am,v 1.36 2006-12-13 11:25:17 adam Exp $ pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \ diagbib1.h diagsrw.h diagsru_update.h sortspec.h log.h logrpn.h marcdisp.h \ @@ -7,7 +7,7 @@ pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \ readconf.h record_conv.h retrieval.h statserv.h \ tcpip.h test.h unix.h tpath.h wrbuf.h xmalloc.h \ yaz-ccl.h yaz-iconv.h yaz-util.h yaz-version.h yconfig.h proto.h \ - xmlquery.h libxml2_error.h \ + xmlquery.h libxml2_error.h xmltypes.h \ \ ill.h ill-core.h item-req.h z-accdes1.h z-accform1.h \ z-acckrb1.h z-core.h z-date.h z-diag1.h z-espec1.h z-estask.h z-exp.h \ diff --git a/include/yaz/marcdisp.h b/include/yaz/marcdisp.h index 9c59961..97fad09 100644 --- a/include/yaz/marcdisp.h +++ b/include/yaz/marcdisp.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: marcdisp.h,v 1.20 2006-12-07 11:08:04 adam Exp $ */ +/* $Id: marcdisp.h,v 1.21 2006-12-13 11:25:17 adam Exp $ */ /** * \file marcdisp.h @@ -38,6 +38,8 @@ #include #include +#include + YAZ_BEGIN_CDECL /** \brief a yaz_marc_t handle (private content) */ @@ -147,11 +149,11 @@ YAZ_EXPORT int yaz_marc_read_iso2709(yaz_marc_t mt, /** \brief parses MARCXML/MarcXchange record from xmlNode pointer \param mt handle - \param xmlnode is a pointer to root xmlNode pointer + \param ptr is a pointer to root xml node Returns 0=OK, -1=ERROR */ -YAZ_EXPORT int yaz_marc_read_xml(yaz_marc_t mt, const void *xmlnode); +YAZ_EXPORT int yaz_marc_read_xml(yaz_marc_t mt, const xmlNode *ptr); /** \brief writes record in line format \param mt handle @@ -167,7 +169,6 @@ YAZ_EXPORT int yaz_marc_write_line(yaz_marc_t mt, WRBUF wrbuf); Sets leader[9]='a' . Returns 0=OK, -1=ERROR . */ - YAZ_EXPORT int yaz_marc_write_marcxml(yaz_marc_t mt, WRBUF wrbuf); /** \brief writes record in MarcXchange XML diff --git a/include/yaz/nmem_xml.h b/include/yaz/nmem_xml.h index 4b5bf74..08eb524 100644 --- a/include/yaz/nmem_xml.h +++ b/include/yaz/nmem_xml.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: nmem_xml.h,v 1.1 2006-10-27 12:19:15 adam Exp $ */ +/* $Id: nmem_xml.h,v 1.2 2006-12-13 11:25:17 adam Exp $ */ /** * \file nmem_xml.h @@ -35,8 +35,7 @@ #include -#if YAZ_HAVE_XML2 -#include +#include YAZ_BEGIN_CDECL @@ -46,7 +45,6 @@ YAZ_EXPORT char *nmem_text_node_cdata(const xmlNode *ptr, NMEM nmem); YAZ_END_CDECL #endif -#endif /* * Local variables: * c-basic-offset: 4 diff --git a/include/yaz/record_conv.h b/include/yaz/record_conv.h index 07f9c90..b96046e 100644 --- a/include/yaz/record_conv.h +++ b/include/yaz/record_conv.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: record_conv.h,v 1.6 2006-12-12 10:41:38 marc Exp $ */ +/* $Id: record_conv.h,v 1.7 2006-12-13 11:25:17 adam Exp $ */ /** * \file record_conv.h @@ -37,6 +37,7 @@ #include #include #include +#include YAZ_BEGIN_CDECL @@ -75,11 +76,9 @@ YAZ_EXPORT void yaz_record_conv_destroy(yaz_record_conv_t p); \endverbatim - - */ YAZ_EXPORT -int yaz_record_conv_configure(yaz_record_conv_t p, const void *node); +int yaz_record_conv_configure(yaz_record_conv_t p, const xmlNode *node); /** performs record conversion \param p record conversion handle diff --git a/include/yaz/retrieval.h b/include/yaz/retrieval.h index 22ba84b..e1cb75d 100644 --- a/include/yaz/retrieval.h +++ b/include/yaz/retrieval.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: retrieval.h,v 1.6 2006-10-09 21:02:41 adam Exp $ */ +/* $Id: retrieval.h,v 1.7 2006-12-13 11:25:17 adam Exp $ */ /** * \file retrieval.h @@ -82,7 +82,7 @@ YAZ_EXPORT void yaz_retrieval_destroy(yaz_retrieval_t p); \endverbatim */ YAZ_EXPORT -int yaz_retrieval_configure(yaz_retrieval_t p, const void *node); +int yaz_retrieval_configure(yaz_retrieval_t p, const xmlNode *node); /** performs retrieval request based on schema and format diff --git a/include/yaz/xmlquery.h b/include/yaz/xmlquery.h index 2e22a67..069dab8 100644 --- a/include/yaz/xmlquery.h +++ b/include/yaz/xmlquery.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: xmlquery.h,v 1.7 2006-10-13 11:30:37 adam Exp $ */ +/* $Id: xmlquery.h,v 1.8 2006-12-13 11:25:17 adam Exp $ */ /** \file xmlquery.h \brief Query / XML conversions @@ -33,11 +33,9 @@ #ifndef YAZ_XMLQUERY_H #define YAZ_XMLQUERY_H -#if YAZ_HAVE_XML2 #include #include - -#include +#include YAZ_BEGIN_CDECL @@ -50,7 +48,6 @@ YAZ_EXPORT void yaz_xml2query(const void *xmlnodep, Z_Query **query, ODR odr, YAZ_END_CDECL #endif -#endif /* * Local variables: diff --git a/include/yaz/xmltypes.h b/include/yaz/xmltypes.h new file mode 100644 index 0000000..7f14df7 --- /dev/null +++ b/include/yaz/xmltypes.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1995-2006, Index Data + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Index Data nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* $Id: xmltypes.h,v 1.1 2006-12-13 11:25:17 adam Exp $ */ + +/** + * \file xmltypes.h + * \brief Define fundamental Libxml2 types for functions YAZ provide. + * \details If Libxml2 is not installed, we define dummy types instead. + */ +#ifndef YAZ_XMLTYPES_H +#define YAZ_XMLTYPES_H + +#if YAZ_HAVE_XML2 +#include +#endif + +YAZ_BEGIN_CDECL + +#if YAZ_HAVE_XML2 +#else +typedef void xmlNode; +typedef void *xmlDocPtr; +#endif + +YAZ_END_CDECL + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/elementset.c b/src/elementset.c index 173bc0f..ee75e70 100644 --- a/src/elementset.c +++ b/src/elementset.c @@ -2,11 +2,11 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: elementset.c,v 1.1 2006-11-14 08:48:26 adam Exp $ + * $Id: elementset.c,v 1.2 2006-12-13 11:25:17 adam Exp $ */ /** - * \file tpath.c - * \brief File Path utilities + * \file elementset.c + * \brief Z39.50 element set utilities */ #if HAVE_CONFIG_H diff --git a/src/marcdisp.c b/src/marcdisp.c index 6c8a603..994c5a6 100644 --- a/src/marcdisp.c +++ b/src/marcdisp.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdisp.c,v 1.36 2006-12-07 11:08:05 adam Exp $ + * $Id: marcdisp.c,v 1.37 2006-12-13 11:25:17 adam Exp $ */ /** @@ -956,10 +956,11 @@ static int yaz_marc_read_xml_fields(yaz_marc_t mt, const xmlNode *ptr) } return 0; } +#endif -int yaz_marc_read_xml(yaz_marc_t mt, const void *xmlnode) +int yaz_marc_read_xml(yaz_marc_t mt, const xmlNode *ptr) { - const xmlNode *ptr = xmlnode; +#if YAZ_HAVE_XML2 for(; ptr; ptr = ptr->next) if (ptr->type == XML_ELEMENT_NODE) { @@ -983,13 +984,10 @@ int yaz_marc_read_xml(yaz_marc_t mt, const void *xmlnode) if (yaz_marc_read_xml_leader(mt, &ptr)) return -1; return yaz_marc_read_xml_fields(mt, ptr->next); -} #else -int yaz_marc_read_xml(yaz_marc_t mt, const void *xmlnode) -{ return -1; -} #endif +} int yaz_marc_read_iso2709(yaz_marc_t mt, const char *buf, int bsize) { diff --git a/src/record_conv.c b/src/record_conv.c index bf148e9..086eec5 100644 --- a/src/record_conv.c +++ b/src/record_conv.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: record_conv.c,v 1.12 2006-12-12 10:41:38 marc Exp $ + * $Id: record_conv.c,v 1.13 2006-12-13 11:25:17 adam Exp $ */ /** * \file record_conv.c @@ -339,10 +339,8 @@ static int conv_marc(yaz_record_conv_t p, const xmlNode *ptr) return 0; } -int yaz_record_conv_configure(yaz_record_conv_t p, const void *ptr_v) +int yaz_record_conv_configure(yaz_record_conv_t p, const xmlNode *ptr) { - const xmlNode *ptr = ptr_v; - yaz_record_conv_reset(p); /* parsing element children */ diff --git a/src/retrieval.c b/src/retrieval.c index eecea4c..32afd87 100644 --- a/src/retrieval.c +++ b/src/retrieval.c @@ -2,7 +2,7 @@ * Copyright (C) 2005-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: retrieval.c,v 1.13 2006-12-12 10:41:38 marc Exp $ + * $Id: retrieval.c,v 1.14 2006-12-13 11:25:17 adam Exp $ */ /** * \file retrieval.c @@ -234,10 +234,8 @@ static int conf_retrieval(yaz_retrieval_t p, const xmlNode *ptr) return 0; } -int yaz_retrieval_configure(yaz_retrieval_t p, const void *ptr_v) +int yaz_retrieval_configure(yaz_retrieval_t p, const xmlNode *ptr) { - const xmlNode *ptr = ptr_v; - yaz_retrieval_reset(p); if (ptr && ptr->type == XML_ELEMENT_NODE && -- 1.7.10.4