diff --git a/android/native/jni/Android.mk b/android/native/jni/Android.mk index 97b35c2997..a0de136faf 100644 --- a/android/native/jni/Android.mk +++ b/android/native/jni/Android.mk @@ -27,8 +27,7 @@ LOCAL_MODULE := retroarch-activity RARCH_PATH := ../../.. LIBXML_PATH := ../libxml2 -LOCAL_LIBXML_SRC_FILES = $(LIBXML_PATH)/c14n.c \ - $(LIBXML_PATH)/chvalid.c \ +LOCAL_LIBXML_SRC_FILES = $(LIBXML_PATH)/chvalid.c \ $(LIBXML_PATH)/dict.c \ $(LIBXML_PATH)/encoding.c \ $(LIBXML_PATH)/entities.c \ diff --git a/android/native/libxml2/c14n.c b/android/native/libxml2/c14n.c deleted file mode 100644 index 3d150a5163..0000000000 --- a/android/native/libxml2/c14n.c +++ /dev/null @@ -1,2225 +0,0 @@ -/* - * "Canonical XML" implementation - * http://www.w3.org/TR/xml-c14n - * - * "Exclusive XML Canonicalization" implementation - * http://www.w3.org/TR/xml-exc-c14n - * - * See Copyright for the status of this software. - * - * Author: Aleksey Sanin - */ -#define IN_LIBXML -#include "libxml.h" -#ifdef LIBXML_C14N_ENABLED -#ifdef LIBXML_OUTPUT_ENABLED - -#ifdef HAVE_STDLIB_H -#include -#endif -#include - -#include -#include -#include -#include -#include -#include -#include - -/************************************************************************ - * * - * Some declaration better left private ATM * - * * - ************************************************************************/ - -typedef enum { - XMLC14N_BEFORE_DOCUMENT_ELEMENT = 0, - XMLC14N_INSIDE_DOCUMENT_ELEMENT = 1, - XMLC14N_AFTER_DOCUMENT_ELEMENT = 2 -} xmlC14NPosition; - -typedef struct _xmlC14NVisibleNsStack { - int nsCurEnd; /* number of nodes in the set */ - int nsPrevStart; /* the begginning of the stack for previous visible node */ - int nsPrevEnd; /* the end of the stack for previous visible node */ - int nsMax; /* size of the array as allocated */ - xmlNsPtr *nsTab; /* array of ns in no particular order */ - xmlNodePtr *nodeTab; /* array of nodes in no particular order */ -} xmlC14NVisibleNsStack, *xmlC14NVisibleNsStackPtr; - -typedef struct _xmlC14NCtx { - /* input parameters */ - xmlDocPtr doc; - xmlC14NIsVisibleCallback is_visible_callback; - void* user_data; - int with_comments; - xmlOutputBufferPtr buf; - - /* position in the XML document */ - xmlC14NPosition pos; - int parent_is_doc; - xmlC14NVisibleNsStackPtr ns_rendered; - - /* C14N mode */ - xmlC14NMode mode; - - /* exclusive canonicalization */ - xmlChar **inclusive_ns_prefixes; - - /* error number */ - int error; -} xmlC14NCtx, *xmlC14NCtxPtr; - -static xmlC14NVisibleNsStackPtr xmlC14NVisibleNsStackCreate (void); -static void xmlC14NVisibleNsStackDestroy (xmlC14NVisibleNsStackPtr cur); -static void xmlC14NVisibleNsStackAdd (xmlC14NVisibleNsStackPtr cur, - xmlNsPtr ns, - xmlNodePtr node); -static void xmlC14NVisibleNsStackSave (xmlC14NVisibleNsStackPtr cur, - xmlC14NVisibleNsStackPtr state); -static void xmlC14NVisibleNsStackRestore (xmlC14NVisibleNsStackPtr cur, - xmlC14NVisibleNsStackPtr state); -static void xmlC14NVisibleNsStackShift (xmlC14NVisibleNsStackPtr cur); -static int xmlC14NVisibleNsStackFind (xmlC14NVisibleNsStackPtr cur, - xmlNsPtr ns); -static int xmlExcC14NVisibleNsStackFind (xmlC14NVisibleNsStackPtr cur, - xmlNsPtr ns, - xmlC14NCtxPtr ctx); - -static int xmlC14NIsNodeInNodeset (xmlNodeSetPtr nodes, - xmlNodePtr node, - xmlNodePtr parent); - - - -static int xmlC14NProcessNode(xmlC14NCtxPtr ctx, xmlNodePtr cur); -static int xmlC14NProcessNodeList(xmlC14NCtxPtr ctx, xmlNodePtr cur); -typedef enum { - XMLC14N_NORMALIZE_ATTR = 0, - XMLC14N_NORMALIZE_COMMENT = 1, - XMLC14N_NORMALIZE_PI = 2, - XMLC14N_NORMALIZE_TEXT = 3 -} xmlC14NNormalizationMode; - -static xmlChar *xmlC11NNormalizeString(const xmlChar * input, - xmlC14NNormalizationMode mode); - -#define xmlC11NNormalizeAttr( a ) \ - xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_ATTR) -#define xmlC11NNormalizeComment( a ) \ - xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_COMMENT) -#define xmlC11NNormalizePI( a ) \ - xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_PI) -#define xmlC11NNormalizeText( a ) \ - xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_TEXT) - -#define xmlC14NIsVisible( ctx, node, parent ) \ - (((ctx)->is_visible_callback != NULL) ? \ - (ctx)->is_visible_callback((ctx)->user_data, \ - (xmlNodePtr)(node), (xmlNodePtr)(parent)) : 1) - -#define xmlC14NIsExclusive( ctx ) \ - ( (ctx)->mode == XML_C14N_EXCLUSIVE_1_0 ) - -/************************************************************************ - * * - * Some factorized error routines * - * * - ************************************************************************/ - -/** - * xmlC14NErrMemory: - * @extra: extra informations - * - * Handle a redefinition of memory error - */ -static void -xmlC14NErrMemory(const char *extra) -{ - __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_C14N, - XML_ERR_NO_MEMORY, XML_ERR_ERROR, NULL, 0, extra, - NULL, NULL, 0, 0, - "Memory allocation failed : %s\n", extra); -} - -/** - * xmlC14NErrParam: - * @extra: extra informations - * - * Handle a redefinition of param error - */ -static void -xmlC14NErrParam(const char *extra) -{ - __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_C14N, - XML_ERR_INTERNAL_ERROR, XML_ERR_ERROR, NULL, 0, extra, - NULL, NULL, 0, 0, - "Invalid parameter : %s\n", extra); -} - -/** - * xmlC14NErrInternal: - * @extra: extra informations - * - * Handle a redefinition of internal error - */ -static void -xmlC14NErrInternal(const char *extra) -{ - __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_C14N, - XML_ERR_INTERNAL_ERROR, XML_ERR_ERROR, NULL, 0, extra, - NULL, NULL, 0, 0, - "Internal error : %s\n", extra); -} - -/** - * xmlC14NErrInvalidNode: - * @extra: extra informations - * - * Handle a redefinition of invalid node error - */ -static void -xmlC14NErrInvalidNode(const char *node_type, const char *extra) -{ - __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_C14N, - XML_C14N_INVALID_NODE, XML_ERR_ERROR, NULL, 0, extra, - NULL, NULL, 0, 0, - "Node %s is invalid here : %s\n", node_type, extra); -} - -/** - * xmlC14NErrUnknownNode: - * @extra: extra informations - * - * Handle a redefinition of unknown node error - */ -static void -xmlC14NErrUnknownNode(int node_type, const char *extra) -{ - __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_C14N, - XML_C14N_UNKNOW_NODE, XML_ERR_ERROR, NULL, 0, extra, - NULL, NULL, 0, 0, - "Unknown node type %d found : %s\n", node_type, extra); -} - -/** - * xmlC14NErrRelativeNamespace: - * @extra: extra informations - * - * Handle a redefinition of relative namespace error - */ -static void -xmlC14NErrRelativeNamespace(const char *ns_uri) -{ - __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_C14N, - XML_C14N_RELATIVE_NAMESPACE, XML_ERR_ERROR, NULL, 0, NULL, - NULL, NULL, 0, 0, - "Relative namespace UR is invalid here : %s\n", ns_uri); -} - - - -/** - * xmlC14NErr: - * @ctxt: a C14N evaluation context - * @node: the context node - * @error: the erorr code - * @msg: the message - * @extra: extra informations - * - * Handle a redefinition of attribute error - */ -static void -xmlC14NErr(xmlC14NCtxPtr ctxt, xmlNodePtr node, int error, - const char * msg) -{ - if (ctxt != NULL) - ctxt->error = error; - __xmlRaiseError(NULL, NULL, NULL, - ctxt, node, XML_FROM_C14N, error, - XML_ERR_ERROR, NULL, 0, - NULL, NULL, NULL, 0, 0, "%s", msg); -} - -/************************************************************************ - * * - * The implementation internals * - * * - ************************************************************************/ -#define XML_NAMESPACES_DEFAULT 16 - -static int -xmlC14NIsNodeInNodeset(xmlNodeSetPtr nodes, xmlNodePtr node, xmlNodePtr parent) { - if((nodes != NULL) && (node != NULL)) { - if(node->type != XML_NAMESPACE_DECL) { - return(xmlXPathNodeSetContains(nodes, node)); - } else { - xmlNs ns; - - memcpy(&ns, node, sizeof(ns)); - - /* this is a libxml hack! check xpath.c for details */ - if((parent != NULL) && (parent->type == XML_ATTRIBUTE_NODE)) { - ns.next = (xmlNsPtr)parent->parent; - } else { - ns.next = (xmlNsPtr)parent; - } - - /* - * If the input is an XPath node-set, then the node-set must explicitly - * contain every node to be rendered to the canonical form. - */ - return(xmlXPathNodeSetContains(nodes, (xmlNodePtr)&ns)); - } - } - return(1); -} - -static xmlC14NVisibleNsStackPtr -xmlC14NVisibleNsStackCreate(void) { - xmlC14NVisibleNsStackPtr ret; - - ret = (xmlC14NVisibleNsStackPtr) xmlMalloc(sizeof(xmlC14NVisibleNsStack)); - if (ret == NULL) { - xmlC14NErrMemory("creating namespaces stack"); - return(NULL); - } - memset(ret, 0 , (size_t) sizeof(xmlC14NVisibleNsStack)); - return(ret); -} - -static void -xmlC14NVisibleNsStackDestroy(xmlC14NVisibleNsStackPtr cur) { - if(cur == NULL) { - xmlC14NErrParam("destroying namespaces stack"); - return; - } - if(cur->nsTab != NULL) { - memset(cur->nsTab, 0, cur->nsMax * sizeof(xmlNsPtr)); - xmlFree(cur->nsTab); - } - if(cur->nodeTab != NULL) { - memset(cur->nodeTab, 0, cur->nsMax * sizeof(xmlNodePtr)); - xmlFree(cur->nodeTab); - } - memset(cur, 0, sizeof(xmlC14NVisibleNsStack)); - xmlFree(cur); - -} - -static void -xmlC14NVisibleNsStackAdd(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns, xmlNodePtr node) { - if((cur == NULL) || - ((cur->nsTab == NULL) && (cur->nodeTab != NULL)) || - ((cur->nsTab != NULL) && (cur->nodeTab == NULL))) { - xmlC14NErrParam("adding namespace to stack"); - return; - } - - if ((cur->nsTab == NULL) && (cur->nodeTab == NULL)) { - cur->nsTab = (xmlNsPtr*) xmlMalloc(XML_NAMESPACES_DEFAULT * sizeof(xmlNsPtr)); - cur->nodeTab = (xmlNodePtr*) xmlMalloc(XML_NAMESPACES_DEFAULT * sizeof(xmlNodePtr)); - if ((cur->nsTab == NULL) || (cur->nodeTab == NULL)) { - xmlC14NErrMemory("adding node to stack"); - return; - } - memset(cur->nsTab, 0 , XML_NAMESPACES_DEFAULT * sizeof(xmlNsPtr)); - memset(cur->nodeTab, 0 , XML_NAMESPACES_DEFAULT * sizeof(xmlNodePtr)); - cur->nsMax = XML_NAMESPACES_DEFAULT; - } else if(cur->nsMax == cur->nsCurEnd) { - void *tmp; - int tmpSize; - - tmpSize = 2 * cur->nsMax; - tmp = xmlRealloc(cur->nsTab, tmpSize * sizeof(xmlNsPtr)); - if (tmp == NULL) { - xmlC14NErrMemory("adding node to stack"); - return; - } - cur->nsTab = (xmlNsPtr*)tmp; - - tmp = xmlRealloc(cur->nodeTab, tmpSize * sizeof(xmlNodePtr)); - if (tmp == NULL) { - xmlC14NErrMemory("adding node to stack"); - return; - } - cur->nodeTab = (xmlNodePtr*)tmp; - - cur->nsMax = tmpSize; - } - cur->nsTab[cur->nsCurEnd] = ns; - cur->nodeTab[cur->nsCurEnd] = node; - - ++cur->nsCurEnd; -} - -static void -xmlC14NVisibleNsStackSave(xmlC14NVisibleNsStackPtr cur, xmlC14NVisibleNsStackPtr state) { - if((cur == NULL) || (state == NULL)) { - xmlC14NErrParam("saving namespaces stack"); - return; - } - - state->nsCurEnd = cur->nsCurEnd; - state->nsPrevStart = cur->nsPrevStart; - state->nsPrevEnd = cur->nsPrevEnd; -} - -static void -xmlC14NVisibleNsStackRestore(xmlC14NVisibleNsStackPtr cur, xmlC14NVisibleNsStackPtr state) { - if((cur == NULL) || (state == NULL)) { - xmlC14NErrParam("restoring namespaces stack"); - return; - } - cur->nsCurEnd = state->nsCurEnd; - cur->nsPrevStart = state->nsPrevStart; - cur->nsPrevEnd = state->nsPrevEnd; -} - -static void -xmlC14NVisibleNsStackShift(xmlC14NVisibleNsStackPtr cur) { - if(cur == NULL) { - xmlC14NErrParam("shifting namespaces stack"); - return; - } - cur->nsPrevStart = cur->nsPrevEnd; - cur->nsPrevEnd = cur->nsCurEnd; -} - -static int -xmlC14NStrEqual(const xmlChar *str1, const xmlChar *str2) { - if (str1 == str2) return(1); - if (str1 == NULL) return((*str2) == '\0'); - if (str2 == NULL) return((*str1) == '\0'); - do { - if (*str1++ != *str2) return(0); - } while (*str2++); - return(1); -} - -/** - * xmlC14NVisibleNsStackFind: - * @ctx: the C14N context - * @ns: the namespace to check - * - * Checks whether the given namespace was already rendered or not - * - * Returns 1 if we already wrote this namespace or 0 otherwise - */ -static int -xmlC14NVisibleNsStackFind(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns) -{ - int i; - const xmlChar *prefix; - const xmlChar *href; - int has_empty_ns; - - if(cur == NULL) { - xmlC14NErrParam("searching namespaces stack (c14n)"); - return (0); - } - - /* - * if the default namespace xmlns="" is not defined yet then - * we do not want to print it out - */ - prefix = ((ns == NULL) || (ns->prefix == NULL)) ? BAD_CAST "" : ns->prefix; - href = ((ns == NULL) || (ns->href == NULL)) ? BAD_CAST "" : ns->href; - has_empty_ns = (xmlC14NStrEqual(prefix, NULL) && xmlC14NStrEqual(href, NULL)); - - if (cur->nsTab != NULL) { - int start = (has_empty_ns) ? 0 : cur->nsPrevStart; - for (i = cur->nsCurEnd - 1; i >= start; --i) { - xmlNsPtr ns1 = cur->nsTab[i]; - - if(xmlC14NStrEqual(prefix, (ns1 != NULL) ? ns1->prefix : NULL)) { - return(xmlC14NStrEqual(href, (ns1 != NULL) ? ns1->href : NULL)); - } - } - } - return(has_empty_ns); -} - -static int -xmlExcC14NVisibleNsStackFind(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns, xmlC14NCtxPtr ctx) { - int i; - const xmlChar *prefix; - const xmlChar *href; - int has_empty_ns; - - if(cur == NULL) { - xmlC14NErrParam("searching namespaces stack (exc c14n)"); - return (0); - } - - /* - * if the default namespace xmlns="" is not defined yet then - * we do not want to print it out - */ - prefix = ((ns == NULL) || (ns->prefix == NULL)) ? BAD_CAST "" : ns->prefix; - href = ((ns == NULL) || (ns->href == NULL)) ? BAD_CAST "" : ns->href; - has_empty_ns = (xmlC14NStrEqual(prefix, NULL) && xmlC14NStrEqual(href, NULL)); - - if (cur->nsTab != NULL) { - int start = 0; - for (i = cur->nsCurEnd - 1; i >= start; --i) { - xmlNsPtr ns1 = cur->nsTab[i]; - - if(xmlC14NStrEqual(prefix, (ns1 != NULL) ? ns1->prefix : NULL)) { - if(xmlC14NStrEqual(href, (ns1 != NULL) ? ns1->href : NULL)) { - return(xmlC14NIsVisible(ctx, ns1, cur->nodeTab[i])); - } else { - return(0); - } - } - } - } - return(has_empty_ns); -} - - - - -/** - * xmlC14NIsXmlNs: - * @ns: the namespace to check - * - * Checks whether the given namespace is a default "xml:" namespace - * with href="http://www.w3.org/XML/1998/namespace" - * - * Returns 1 if the node is default or 0 otherwise - */ - -/* todo: make it a define? */ -static int -xmlC14NIsXmlNs(xmlNsPtr ns) -{ - return ((ns != NULL) && - (xmlStrEqual(ns->prefix, BAD_CAST "xml")) && - (xmlStrEqual(ns->href, XML_XML_NAMESPACE))); -} - - -/** - * xmlC14NNsCompare: - * @ns1: the pointer to first namespace - * @ns2: the pointer to second namespace - * - * Compares the namespaces by names (prefixes). - * - * Returns -1 if ns1 < ns2, 0 if ns1 == ns2 or 1 if ns1 > ns2. - */ -static int -xmlC14NNsCompare(xmlNsPtr ns1, xmlNsPtr ns2) -{ - if (ns1 == ns2) - return (0); - if (ns1 == NULL) - return (-1); - if (ns2 == NULL) - return (1); - - return (xmlStrcmp(ns1->prefix, ns2->prefix)); -} - - -/** - * xmlC14NPrintNamespaces: - * @ns: the pointer to namespace - * @ctx: the C14N context - * - * Prints the given namespace to the output buffer from C14N context. - * - * Returns 1 on success or 0 on fail. - */ -static int -xmlC14NPrintNamespaces(const xmlNsPtr ns, xmlC14NCtxPtr ctx) -{ - - if ((ns == NULL) || (ctx == NULL)) { - xmlC14NErrParam("writing namespaces"); - return 0; - } - - if (ns->prefix != NULL) { - xmlOutputBufferWriteString(ctx->buf, " xmlns:"); - xmlOutputBufferWriteString(ctx->buf, (const char *) ns->prefix); - xmlOutputBufferWriteString(ctx->buf, "=\""); - } else { - xmlOutputBufferWriteString(ctx->buf, " xmlns=\""); - } - if(ns->href != NULL) { - xmlOutputBufferWriteString(ctx->buf, (const char *) ns->href); - } - xmlOutputBufferWriteString(ctx->buf, "\""); - return (1); -} - -/** - * xmlC14NProcessNamespacesAxis: - * @ctx: the C14N context - * @node: the current node - * - * Prints out canonical namespace axis of the current node to the - * buffer from C14N context as follows - * - * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) - * - * Namespace Axis - * Consider a list L containing only namespace nodes in the - * axis and in the node-set in lexicographic order (ascending). To begin - * processing L, if the first node is not the default namespace node (a node - * with no namespace URI and no local name), then generate a space followed - * by xmlns="" if and only if the following conditions are met: - * - the element E that owns the axis is in the node-set - * - The nearest ancestor element of E in the node-set has a default - * namespace node in the node-set (default namespace nodes always - * have non-empty values in XPath) - * The latter condition eliminates unnecessary occurrences of xmlns="" in - * the canonical form since an element only receives an xmlns="" if its - * default namespace is empty and if it has an immediate parent in the - * canonical form that has a non-empty default namespace. To finish - * processing L, simply process every namespace node in L, except omit - * namespace node with local name xml, which defines the xml prefix, - * if its string value is http://www.w3.org/XML/1998/namespace. - * - * Exclusive XML Canonicalization v 1.0 (http://www.w3.org/TR/xml-exc-c14n) - * Canonical XML applied to a document subset requires the search of the - * ancestor nodes of each orphan element node for attributes in the xml - * namespace, such as xml:lang and xml:space. These are copied into the - * element node except if a declaration of the same attribute is already - * in the attribute axis of the element (whether or not it is included in - * the document subset). This search and copying are omitted from the - * Exclusive XML Canonicalization method. - * - * Returns 0 on success or -1 on fail. - */ -static int -xmlC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) -{ - xmlNodePtr n; - xmlNsPtr ns, tmp; - xmlListPtr list; - int already_rendered; - int has_empty_ns = 0; - - if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { - xmlC14NErrParam("processing namespaces axis (c14n)"); - return (-1); - } - - /* - * Create a sorted list to store element namespaces - */ - list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NNsCompare); - if (list == NULL) { - xmlC14NErrInternal("creating namespaces list (c14n)"); - return (-1); - } - - /* check all namespaces */ - for(n = cur; n != NULL; n = n->parent) { - for(ns = n->nsDef; ns != NULL; ns = ns->next) { - tmp = xmlSearchNs(cur->doc, cur, ns->prefix); - - if((tmp == ns) && !xmlC14NIsXmlNs(ns) && xmlC14NIsVisible(ctx, ns, cur)) { - already_rendered = xmlC14NVisibleNsStackFind(ctx->ns_rendered, ns); - if(visible) { - xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); - } - if(!already_rendered) { - xmlListInsert(list, ns); - } - if(xmlStrlen(ns->prefix) == 0) { - has_empty_ns = 1; - } - } - } - } - - /** - * if the first node is not the default namespace node (a node with no - * namespace URI and no local name), then generate a space followed by - * xmlns="" if and only if the following conditions are met: - * - the element E that owns the axis is in the node-set - * - the nearest ancestor element of E in the node-set has a default - * namespace node in the node-set (default namespace nodes always - * have non-empty values in XPath) - */ - if(visible && !has_empty_ns) { - static xmlNs ns_default; - - memset(&ns_default, 0, sizeof(ns_default)); - if(!xmlC14NVisibleNsStackFind(ctx->ns_rendered, &ns_default)) { - xmlC14NPrintNamespaces(&ns_default, ctx); - } - } - - - /* - * print out all elements from list - */ - xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx); - - /* - * Cleanup - */ - xmlListDelete(list); - return (0); -} - - -/** - * xmlExcC14NProcessNamespacesAxis: - * @ctx: the C14N context - * @node: the current node - * - * Prints out exclusive canonical namespace axis of the current node to the - * buffer from C14N context as follows - * - * Exclusive XML Canonicalization - * http://www.w3.org/TR/xml-exc-c14n - * - * If the element node is in the XPath subset then output the node in - * accordance with Canonical XML except for namespace nodes which are - * rendered as follows: - * - * 1. Render each namespace node iff: - * * it is visibly utilized by the immediate parent element or one of - * its attributes, or is present in InclusiveNamespaces PrefixList, and - * * its prefix and value do not appear in ns_rendered. ns_rendered is - * obtained by popping the state stack in order to obtain a list of - * prefixes and their values which have already been rendered by - * an output ancestor of the namespace node's parent element. - * 2. Append the rendered namespace node to the list ns_rendered of namespace - * nodes rendered by output ancestors. Push ns_rendered on state stack and - * recurse. - * 3. After the recursion returns, pop thestate stack. - * - * - * Returns 0 on success or -1 on fail. - */ -static int -xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) -{ - xmlNsPtr ns; - xmlListPtr list; - xmlAttrPtr attr; - int already_rendered; - int has_empty_ns = 0; - int has_visibly_utilized_empty_ns = 0; - int has_empty_ns_in_inclusive_list = 0; - - if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { - xmlC14NErrParam("processing namespaces axis (exc c14n)"); - return (-1); - } - - if(!xmlC14NIsExclusive(ctx)) { - xmlC14NErrParam("processing namespaces axis (exc c14n)"); - return (-1); - - } - - /* - * Create a sorted list to store element namespaces - */ - list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NNsCompare); - if (list == NULL) { - xmlC14NErrInternal("creating namespaces list (exc c14n)"); - return (-1); - } - - /* - * process inclusive namespaces: - * All namespace nodes appearing on inclusive ns list are - * handled as provided in Canonical XML - */ - if(ctx->inclusive_ns_prefixes != NULL) { - xmlChar *prefix; - int i; - - for (i = 0; ctx->inclusive_ns_prefixes[i] != NULL; ++i) { - prefix = ctx->inclusive_ns_prefixes[i]; - /* - * Special values for namespace with empty prefix - */ - if (xmlStrEqual(prefix, BAD_CAST "#default") - || xmlStrEqual(prefix, BAD_CAST "")) { - prefix = NULL; - has_empty_ns_in_inclusive_list = 1; - } - - ns = xmlSearchNs(cur->doc, cur, prefix); - if((ns != NULL) && !xmlC14NIsXmlNs(ns) && xmlC14NIsVisible(ctx, ns, cur)) { - already_rendered = xmlC14NVisibleNsStackFind(ctx->ns_rendered, ns); - if(visible) { - xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); - } - if(!already_rendered) { - xmlListInsert(list, ns); - } - if(xmlStrlen(ns->prefix) == 0) { - has_empty_ns = 1; - } - } - } - } - - /* add node namespace */ - if(cur->ns != NULL) { - ns = cur->ns; - } else { - ns = xmlSearchNs(cur->doc, cur, NULL); - has_visibly_utilized_empty_ns = 1; - } - if((ns != NULL) && !xmlC14NIsXmlNs(ns)) { - if(visible && xmlC14NIsVisible(ctx, ns, cur)) { - if(!xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, ns, ctx)) { - xmlListInsert(list, ns); - } - } - if(visible) { - xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); - } - if(xmlStrlen(ns->prefix) == 0) { - has_empty_ns = 1; - } - } - - - /* add attributes */ - for(attr = cur->properties; attr != NULL; attr = attr->next) { - /* - * we need to check that attribute is visible and has non - * default namespace (XML Namespaces: "default namespaces - * do not apply directly to attributes") - */ - if((attr->ns != NULL) && !xmlC14NIsXmlNs(attr->ns) && xmlC14NIsVisible(ctx, attr, cur)) { - already_rendered = xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, attr->ns, ctx); - xmlC14NVisibleNsStackAdd(ctx->ns_rendered, attr->ns, cur); - if(!already_rendered && visible) { - xmlListInsert(list, attr->ns); - } - if(xmlStrlen(attr->ns->prefix) == 0) { - has_empty_ns = 1; - } - } else if((attr->ns != NULL) && (xmlStrlen(attr->ns->prefix) == 0) && (xmlStrlen(attr->ns->href) == 0)) { - has_visibly_utilized_empty_ns = 1; - } - } - - /* - * Process xmlns="" - */ - if(visible && has_visibly_utilized_empty_ns && - !has_empty_ns && !has_empty_ns_in_inclusive_list) { - static xmlNs ns_default; - - memset(&ns_default, 0, sizeof(ns_default)); - - already_rendered = xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, &ns_default, ctx); - if(!already_rendered) { - xmlC14NPrintNamespaces(&ns_default, ctx); - } - } else if(visible && !has_empty_ns && has_empty_ns_in_inclusive_list) { - static xmlNs ns_default; - - memset(&ns_default, 0, sizeof(ns_default)); - if(!xmlC14NVisibleNsStackFind(ctx->ns_rendered, &ns_default)) { - xmlC14NPrintNamespaces(&ns_default, ctx); - } - } - - - - /* - * print out all elements from list - */ - xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx); - - /* - * Cleanup - */ - xmlListDelete(list); - return (0); -} - - -/** - * xmlC14NIsXmlAttr: - * @attr: the attr to check - * - * Checks whether the given attribute is a default "xml:" namespace - * with href="http://www.w3.org/XML/1998/namespace" - * - * Returns 1 if the node is default or 0 otherwise - */ - -/* todo: make it a define? */ -static int -xmlC14NIsXmlAttr(xmlAttrPtr attr) -{ - return ((attr->ns != NULL) && - (xmlC14NIsXmlNs(attr->ns) != 0)); -} - - -/** - * xmlC14NAttrsCompare: - * @attr1: the pointer tls o first attr - * @attr2: the pointer to second attr - * - * Prints the given attribute to the output buffer from C14N context. - * - * Returns -1 if attr1 < attr2, 0 if attr1 == attr2 or 1 if attr1 > attr2. - */ -static int -xmlC14NAttrsCompare(xmlAttrPtr attr1, xmlAttrPtr attr2) -{ - int ret = 0; - - /* - * Simple cases - */ - if (attr1 == attr2) - return (0); - if (attr1 == NULL) - return (-1); - if (attr2 == NULL) - return (1); - if (attr1->ns == attr2->ns) { - return (xmlStrcmp(attr1->name, attr2->name)); - } - - /* - * Attributes in the default namespace are first - * because the default namespace is not applied to - * unqualified attributes - */ - if (attr1->ns == NULL) - return (-1); - if (attr2->ns == NULL) - return (1); - if (attr1->ns->prefix == NULL) - return (-1); - if (attr2->ns->prefix == NULL) - return (1); - - ret = xmlStrcmp(attr1->ns->href, attr2->ns->href); - if (ret == 0) { - ret = xmlStrcmp(attr1->name, attr2->name); - } - return (ret); -} - - -/** - * xmlC14NPrintAttrs: - * @attr: the pointer to attr - * @ctx: the C14N context - * - * Prints out canonical attribute urrent node to the - * buffer from C14N context as follows - * - * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) - * - * Returns 1 on success or 0 on fail. - */ -static int -xmlC14NPrintAttrs(const xmlAttrPtr attr, xmlC14NCtxPtr ctx) -{ - xmlChar *value; - xmlChar *buffer; - - if ((attr == NULL) || (ctx == NULL)) { - xmlC14NErrParam("writing attributes"); - return (0); - } - - xmlOutputBufferWriteString(ctx->buf, " "); - if (attr->ns != NULL && xmlStrlen(attr->ns->prefix) > 0) { - xmlOutputBufferWriteString(ctx->buf, - (const char *) attr->ns->prefix); - xmlOutputBufferWriteString(ctx->buf, ":"); - } - xmlOutputBufferWriteString(ctx->buf, (const char *) attr->name); - xmlOutputBufferWriteString(ctx->buf, "=\""); - - value = xmlNodeListGetString(ctx->doc, attr->children, 1); - /* todo: should we log an error if value==NULL ? */ - if (value != NULL) { - buffer = xmlC11NNormalizeAttr(value); - xmlFree(value); - if (buffer != NULL) { - xmlOutputBufferWriteString(ctx->buf, (const char *) buffer); - xmlFree(buffer); - } else { - xmlC14NErrInternal("normalizing attributes axis"); - return (0); - } - } - xmlOutputBufferWriteString(ctx->buf, "\""); - return (1); -} - -/** - * xmlC14NFindHiddenParentAttr: - * - * Finds an attribute in a hidden parent node. - * - * Returns a pointer to the attribute node (if found) or NULL otherwise. - */ -static xmlAttrPtr -xmlC14NFindHiddenParentAttr(xmlC14NCtxPtr ctx, xmlNodePtr cur, const xmlChar * name, const xmlChar * ns) -{ - xmlAttrPtr res; - while((cur != NULL) && (!xmlC14NIsVisible(ctx, cur, cur->parent))) { - res = xmlHasNsProp(cur, name, ns); - if(res != NULL) { - return res; - } - - cur = cur->parent; - } - - return NULL; -} - -/** - * xmlC14NFixupBaseAttr: - * - * Fixes up the xml:base attribute - * - * Returns the newly created attribute or NULL - */ -static xmlAttrPtr -xmlC14NFixupBaseAttr(xmlC14NCtxPtr ctx, xmlAttrPtr xml_base_attr) -{ - xmlChar * res = NULL; - xmlNodePtr cur; - xmlAttrPtr attr; - xmlChar * tmp_str; - xmlChar * tmp_str2; - int tmp_str_len; - - if ((ctx == NULL) || (xml_base_attr == NULL) || (xml_base_attr->parent == NULL)) { - xmlC14NErrParam("processing xml:base attribute"); - return (NULL); - } - - /* start from current value */ - res = xmlNodeListGetString(ctx->doc, xml_base_attr->children, 1); - if(res == NULL) { - xmlC14NErrInternal("processing xml:base attribute - can't get attr value"); - return (NULL); - } - - /* go up the stack until we find a node that we rendered already */ - cur = xml_base_attr->parent->parent; - while((cur != NULL) && (!xmlC14NIsVisible(ctx, cur, cur->parent))) { - attr = xmlHasNsProp(cur, BAD_CAST "base", XML_XML_NAMESPACE); - if(attr != NULL) { - /* get attr value */ - tmp_str = xmlNodeListGetString(ctx->doc, attr->children, 1); - if(tmp_str == NULL) { - xmlFree(res); - - xmlC14NErrInternal("processing xml:base attribute - can't get attr value"); - return (NULL); - } - - /* we need to add '/' if our current base uri ends with '..' or '.' - to ensure that we are forced to go "up" all the time */ - tmp_str_len = xmlStrlen(tmp_str); - if(tmp_str_len > 1 && tmp_str[tmp_str_len - 2] == '.') { - tmp_str2 = xmlStrcat(tmp_str, BAD_CAST "/"); - if(tmp_str2 == NULL) { - xmlFree(tmp_str); - xmlFree(res); - - xmlC14NErrInternal("processing xml:base attribute - can't modify uri"); - return (NULL); - } - - tmp_str = tmp_str2; - } - - /* build uri */ - tmp_str2 = xmlBuildURI(res, tmp_str); - if(tmp_str2 == NULL) { - xmlFree(tmp_str); - xmlFree(res); - - xmlC14NErrInternal("processing xml:base attribute - can't construct uri"); - return (NULL); - } - - /* cleanup and set the new res */ - xmlFree(tmp_str); - xmlFree(res); - res = tmp_str2; - } - - /* next */ - cur = cur->parent; - } - - /* check if result uri is empty or not */ - if((res == NULL) || xmlStrEqual(res, BAD_CAST "")) { - xmlFree(res); - return (NULL); - } - - /* create and return the new attribute node */ - attr = xmlNewNsProp(NULL, xml_base_attr->ns, BAD_CAST "base", res); - if(attr == NULL) { - xmlFree(res); - - xmlC14NErrInternal("processing xml:base attribute - can't construct attribute"); - return (NULL); - } - - /* done */ - xmlFree(res); - return (attr); -} - -/** - * xmlC14NProcessAttrsAxis: - * @ctx: the C14N context - * @cur: the current node - * @parent_visible: the visibility of parent node - * @all_parents_visible: the visibility of all parent nodes - * - * Prints out canonical attribute axis of the current node to the - * buffer from C14N context as follows - * - * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) - * - * Attribute Axis - * In lexicographic order (ascending), process each node that - * is in the element's attribute axis and in the node-set. - * - * The processing of an element node E MUST be modified slightly - * when an XPath node-set is given as input and the element's - * parent is omitted from the node-set. - * - * - * Exclusive XML Canonicalization v 1.0 (http://www.w3.org/TR/xml-exc-c14n) - * - * Canonical XML applied to a document subset requires the search of the - * ancestor nodes of each orphan element node for attributes in the xml - * namespace, such as xml:lang and xml:space. These are copied into the - * element node except if a declaration of the same attribute is already - * in the attribute axis of the element (whether or not it is included in - * the document subset). This search and copying are omitted from the - * Exclusive XML Canonicalization method. - * - * Returns 0 on success or -1 on fail. - */ -static int -xmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int parent_visible) -{ - xmlAttrPtr attr; - xmlListPtr list; - xmlAttrPtr attrs_to_delete = NULL; - - /* special processing for 1.1 spec */ - xmlAttrPtr xml_base_attr = NULL; - xmlAttrPtr xml_lang_attr = NULL; - xmlAttrPtr xml_space_attr = NULL; - - if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { - xmlC14NErrParam("processing attributes axis"); - return (-1); - } - - /* - * Create a sorted list to store element attributes - */ - list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NAttrsCompare); - if (list == NULL) { - xmlC14NErrInternal("creating attributes list"); - return (-1); - } - - switch(ctx->mode) { - case XML_C14N_1_0: - /* The processing of an element node E MUST be modified slightly when an XPath node-set is - * given as input and the element's parent is omitted from the node-set. The method for processing - * the attribute axis of an element E in the node-set is enhanced. All element nodes along E's - * ancestor axis are examined for nearest occurrences of attributes in the xml namespace, such - * as xml:lang and xml:space (whether or not they are in the node-set). From this list of attributes, - * remove any that are in E's attribute axis (whether or not they are in the node-set). Then, - * lexicographically merge this attribute list with the nodes of E's attribute axis that are in - * the node-set. The result of visiting the attribute axis is computed by processing the attribute - * nodes in this merged attribute list. - */ - - /* - * Add all visible attributes from current node. - */ - attr = cur->properties; - while (attr != NULL) { - /* check that attribute is visible */ - if (xmlC14NIsVisible(ctx, attr, cur)) { - xmlListInsert(list, attr); - } - attr = attr->next; - } - - /* - * Handle xml attributes - */ - if (parent_visible && (cur->parent != NULL) && - (!xmlC14NIsVisible(ctx, cur->parent, cur->parent->parent))) - { - xmlNodePtr tmp; - - /* - * If XPath node-set is not specified then the parent is always - * visible! - */ - tmp = cur->parent; - while (tmp != NULL) { - attr = tmp->properties; - while (attr != NULL) { - if (xmlC14NIsXmlAttr(attr) != 0) { - if (xmlListSearch(list, attr) == NULL) { - xmlListInsert(list, attr); - } - } - attr = attr->next; - } - tmp = tmp->parent; - } - } - - /* done */ - break; - case XML_C14N_EXCLUSIVE_1_0: - /* attributes in the XML namespace, such as xml:lang and xml:space - * are not imported into orphan nodes of the document subset - */ - - /* - * Add all visible attributes from current node. - */ - attr = cur->properties; - while (attr != NULL) { - /* check that attribute is visible */ - if (xmlC14NIsVisible(ctx, attr, cur)) { - xmlListInsert(list, attr); - } - attr = attr->next; - } - - /* do nothing special for xml attributes */ - break; - case XML_C14N_1_1: - /* The processing of an element node E MUST be modified slightly when an XPath node-set is - * given as input and some of the element's ancestors are omitted from the node-set. - * - * Simple inheritable attributes are attributes that have a value that requires at most a simple - * redeclaration. This redeclaration is done by supplying a new value in the child axis. The - * redeclaration of a simple inheritable attribute A contained in one of E's ancestors is done - * by supplying a value to an attribute Ae inside E with the same name. Simple inheritable attributes - * are xml:lang and xml:space. - * - * The method for processing the attribute axis of an element E in the node-set is hence enhanced. - * All element nodes along E's ancestor axis are examined for the nearest occurrences of simple - * inheritable attributes in the xml namespace, such as xml:lang and xml:space (whether or not they - * are in the node-set). From this list of attributes, any simple inheritable attributes that are - * already in E's attribute axis (whether or not they are in the node-set) are removed. Then, - * lexicographically merge this attribute list with the nodes of E's attribute axis that are in - * the node-set. The result of visiting the attribute axis is computed by processing the attribute - * nodes in this merged attribute list. - * - * The xml:id attribute is not a simple inheritable attribute and no processing of these attributes is - * performed. - * - * The xml:base attribute is not a simple inheritable attribute and requires special processing beyond - * a simple redeclaration. - * - * Attributes in the XML namespace other than xml:base, xml:id, xml:lang, and xml:space MUST be processed - * as ordinary attributes. - */ - - /* - * Add all visible attributes from current node. - */ - attr = cur->properties; - while (attr != NULL) { - /* special processing for XML attribute kiks in only when we have invisible parents */ - if ((!parent_visible) || (xmlC14NIsXmlAttr(attr) == 0)) { - /* check that attribute is visible */ - if (xmlC14NIsVisible(ctx, attr, cur)) { - xmlListInsert(list, attr); - } - } else { - int matched = 0; - - /* check for simple inheritance attributes */ - if((!matched) && (xml_lang_attr == NULL) && xmlStrEqual(attr->name, BAD_CAST "lang")) { - xml_lang_attr = attr; - matched = 1; - } - if((!matched) && (xml_space_attr == NULL) && xmlStrEqual(attr->name, BAD_CAST "space")) { - xml_space_attr = attr; - matched = 1; - } - - /* check for base attr */ - if((!matched) && (xml_base_attr == NULL) && xmlStrEqual(attr->name, BAD_CAST "base")) { - xml_base_attr = attr; - matched = 1; - } - - /* otherwise, it is a normal attribute, so just check if it is visible */ - if((!matched) && xmlC14NIsVisible(ctx, attr, cur)) { - xmlListInsert(list, attr); - } - } - - /* move to the next one */ - attr = attr->next; - } - - /* special processing for XML attribute kiks in only when we have invisible parents */ - if ((parent_visible)) { - - /* simple inheritance attributes - copy */ - if(xml_lang_attr == NULL) { - xml_lang_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, BAD_CAST "lang", XML_XML_NAMESPACE); - } - if(xml_lang_attr != NULL) { - xmlListInsert(list, xml_lang_attr); - } - if(xml_space_attr == NULL) { - xml_space_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, BAD_CAST "space", XML_XML_NAMESPACE); - } - if(xml_space_attr != NULL) { - xmlListInsert(list, xml_space_attr); - } - - /* base uri attribute - fix up */ - if(xml_base_attr == NULL) { - /* if we don't have base uri attribute, check if we have a "hidden" one above */ - xml_base_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, BAD_CAST "base", XML_XML_NAMESPACE); - } - if(xml_base_attr != NULL) { - xml_base_attr = xmlC14NFixupBaseAttr(ctx, xml_base_attr); - if(xml_base_attr != NULL) { - xmlListInsert(list, xml_base_attr); - - /* note that we MUST delete returned attr node ourselves! */ - xml_base_attr->next = attrs_to_delete; - attrs_to_delete = xml_base_attr; - } - } - } - - /* done */ - break; - } - - /* - * print out all elements from list - */ - xmlListWalk(list, (xmlListWalker) xmlC14NPrintAttrs, (const void *) ctx); - - /* - * Cleanup - */ - xmlFreePropList(attrs_to_delete); - xmlListDelete(list); - return (0); -} - -/** - * xmlC14NCheckForRelativeNamespaces: - * @ctx: the C14N context - * @cur: the current element node - * - * Checks that current element node has no relative namespaces defined - * - * Returns 0 if the node has no relative namespaces or -1 otherwise. - */ -static int -xmlC14NCheckForRelativeNamespaces(xmlC14NCtxPtr ctx, xmlNodePtr cur) -{ - xmlNsPtr ns; - - if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { - xmlC14NErrParam("checking for relative namespaces"); - return (-1); - } - - ns = cur->nsDef; - while (ns != NULL) { - if (xmlStrlen(ns->href) > 0) { - xmlURIPtr uri; - - uri = xmlParseURI((const char *) ns->href); - if (uri == NULL) { - xmlC14NErrInternal("parsing namespace uri"); - return (-1); - } - if (xmlStrlen((const xmlChar *) uri->scheme) == 0) { - xmlC14NErrRelativeNamespace(uri->scheme); - xmlFreeURI(uri); - return (-1); - } - if ((xmlStrcasecmp((const xmlChar *) uri->scheme, BAD_CAST "urn") != 0) - && (xmlStrcasecmp((const xmlChar *) uri->scheme, BAD_CAST "dav") !=0) - && (xmlStrlen((const xmlChar *) uri->server) == 0)) { - xmlC14NErrRelativeNamespace(uri->scheme); - xmlFreeURI(uri); - return (-1); - } - xmlFreeURI(uri); - } - ns = ns->next; - } - return (0); -} - -/** - * xmlC14NProcessElementNode: - * @ctx: the pointer to C14N context object - * @cur: the node to process - * @visible: this node is visible - * @all_parents_visible: whether all the parents of this node are visible - * - * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) - * - * Element Nodes - * If the element is not in the node-set, then the result is obtained - * by processing the namespace axis, then the attribute axis, then - * processing the child nodes of the element that are in the node-set - * (in document order). If the element is in the node-set, then the result - * is an open angle bracket (<), the element QName, the result of - * processing the namespace axis, the result of processing the attribute - * axis, a close angle bracket (>), the result of processing the child - * nodes of the element that are in the node-set (in document order), an - * open angle bracket, a forward slash (/), the element QName, and a close - * angle bracket. - * - * Returns non-negative value on success or negative value on fail - */ -static int -xmlC14NProcessElementNode(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) -{ - int ret; - xmlC14NVisibleNsStack state; - int parent_is_doc = 0; - - if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { - xmlC14NErrParam("processing element node"); - return (-1); - } - - /* - * Check relative relative namespaces: - * implementations of XML canonicalization MUST report an operation - * failure on documents containing relative namespace URIs. - */ - if (xmlC14NCheckForRelativeNamespaces(ctx, cur) < 0) { - xmlC14NErrInternal("checking for relative namespaces"); - return (-1); - } - - - /* - * Save ns_rendered stack position - */ - memset(&state, 0, sizeof(state)); - xmlC14NVisibleNsStackSave(ctx->ns_rendered, &state); - - if (visible) { - if (ctx->parent_is_doc) { - /* save this flag into the stack */ - parent_is_doc = ctx->parent_is_doc; - ctx->parent_is_doc = 0; - ctx->pos = XMLC14N_INSIDE_DOCUMENT_ELEMENT; - } - xmlOutputBufferWriteString(ctx->buf, "<"); - - if ((cur->ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) { - xmlOutputBufferWriteString(ctx->buf, - (const char *) cur->ns->prefix); - xmlOutputBufferWriteString(ctx->buf, ":"); - } - xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name); - } - - if (!xmlC14NIsExclusive(ctx)) { - ret = xmlC14NProcessNamespacesAxis(ctx, cur, visible); - } else { - ret = xmlExcC14NProcessNamespacesAxis(ctx, cur, visible); - } - if (ret < 0) { - xmlC14NErrInternal("processing namespaces axis"); - return (-1); - } - /* todo: shouldn't this go to "visible only"? */ - if(visible) { - xmlC14NVisibleNsStackShift(ctx->ns_rendered); - } - - ret = xmlC14NProcessAttrsAxis(ctx, cur, visible); - if (ret < 0) { - xmlC14NErrInternal("processing attributes axis"); - return (-1); - } - - if (visible) { - xmlOutputBufferWriteString(ctx->buf, ">"); - } - if (cur->children != NULL) { - ret = xmlC14NProcessNodeList(ctx, cur->children); - if (ret < 0) { - xmlC14NErrInternal("processing childrens list"); - return (-1); - } - } - if (visible) { - xmlOutputBufferWriteString(ctx->buf, "ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) { - xmlOutputBufferWriteString(ctx->buf, - (const char *) cur->ns->prefix); - xmlOutputBufferWriteString(ctx->buf, ":"); - } - xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name); - xmlOutputBufferWriteString(ctx->buf, ">"); - if (parent_is_doc) { - /* restore this flag from the stack for next node */ - ctx->parent_is_doc = parent_is_doc; - ctx->pos = XMLC14N_AFTER_DOCUMENT_ELEMENT; - } - } - - /* - * Restore ns_rendered stack position - */ - xmlC14NVisibleNsStackRestore(ctx->ns_rendered, &state); - return (0); -} - -/** - * xmlC14NProcessNode: - * @ctx: the pointer to C14N context object - * @cur: the node to process - * - * Processes the given node - * - * Returns non-negative value on success or negative value on fail - */ -static int -xmlC14NProcessNode(xmlC14NCtxPtr ctx, xmlNodePtr cur) -{ - int ret = 0; - int visible; - - if ((ctx == NULL) || (cur == NULL)) { - xmlC14NErrParam("processing node"); - return (-1); - } - - visible = xmlC14NIsVisible(ctx, cur, cur->parent); - switch (cur->type) { - case XML_ELEMENT_NODE: - ret = xmlC14NProcessElementNode(ctx, cur, visible); - break; - case XML_CDATA_SECTION_NODE: - case XML_TEXT_NODE: - /* - * Text Nodes - * the string value, except all ampersands are replaced - * by &, all open angle brackets (<) are replaced by <, all closing - * angle brackets (>) are replaced by >, and all #xD characters are - * replaced by . - */ - /* cdata sections are processed as text nodes */ - /* todo: verify that cdata sections are included in XPath nodes set */ - if ((visible) && (cur->content != NULL)) { - xmlChar *buffer; - - buffer = xmlC11NNormalizeText(cur->content); - if (buffer != NULL) { - xmlOutputBufferWriteString(ctx->buf, - (const char *) buffer); - xmlFree(buffer); - } else { - xmlC14NErrInternal("normalizing text node"); - return (-1); - } - } - break; - case XML_PI_NODE: - /* - * Processing Instruction (PI) Nodes- - * The opening PI symbol (). If the string value is empty, - * then the leading space is not added. Also, a trailing #xA is - * rendered after the closing PI symbol for PI children of the - * root node with a lesser document order than the document - * element, and a leading #xA is rendered before the opening PI - * symbol of PI children of the root node with a greater document - * order than the document element. - */ - if (visible) { - if (ctx->pos == XMLC14N_AFTER_DOCUMENT_ELEMENT) { - xmlOutputBufferWriteString(ctx->buf, "\x0Abuf, "buf, - (const char *) cur->name); - if ((cur->content != NULL) && (*(cur->content) != '\0')) { - xmlChar *buffer; - - xmlOutputBufferWriteString(ctx->buf, " "); - - /* todo: do we need to normalize pi? */ - buffer = xmlC11NNormalizePI(cur->content); - if (buffer != NULL) { - xmlOutputBufferWriteString(ctx->buf, - (const char *) buffer); - xmlFree(buffer); - } else { - xmlC14NErrInternal("normalizing pi node"); - return (-1); - } - } - - if (ctx->pos == XMLC14N_BEFORE_DOCUMENT_ELEMENT) { - xmlOutputBufferWriteString(ctx->buf, "?>\x0A"); - } else { - xmlOutputBufferWriteString(ctx->buf, "?>"); - } - } - break; - case XML_COMMENT_NODE: - /* - * Comment Nodes - * Nothing if generating canonical XML without comments. For - * canonical XML with comments, generate the opening comment - * symbol (). Also, a trailing #xA is rendered - * after the closing comment symbol for comment children of the - * root node with a lesser document order than the document - * element, and a leading #xA is rendered before the opening - * comment symbol of comment children of the root node with a - * greater document order than the document element. (Comment - * children of the root node represent comments outside of the - * top-level document element and outside of the document type - * declaration). - */ - if (visible && ctx->with_comments) { - if (ctx->pos == XMLC14N_AFTER_DOCUMENT_ELEMENT) { - xmlOutputBufferWriteString(ctx->buf, "\x0A\x0A"); - } else { - xmlOutputBufferWriteString(ctx->buf, "-->"); - } - } - break; - case XML_DOCUMENT_NODE: - case XML_DOCUMENT_FRAG_NODE: /* should be processed as document? */ - if (cur->children != NULL) { - ctx->pos = XMLC14N_BEFORE_DOCUMENT_ELEMENT; - ctx->parent_is_doc = 1; - ret = xmlC14NProcessNodeList(ctx, cur->children); - } - break; - - case XML_ATTRIBUTE_NODE: - xmlC14NErrInvalidNode("XML_ATTRIBUTE_NODE", "processing node"); - return (-1); - case XML_NAMESPACE_DECL: - xmlC14NErrInvalidNode("XML_NAMESPACE_DECL", "processing node"); - return (-1); - case XML_ENTITY_REF_NODE: - xmlC14NErrInvalidNode("XML_ENTITY_REF_NODE", "processing node"); - return (-1); - case XML_ENTITY_NODE: - xmlC14NErrInvalidNode("XML_ENTITY_NODE", "processing node"); - return (-1); - - case XML_DOCUMENT_TYPE_NODE: - case XML_NOTATION_NODE: - case XML_DTD_NODE: - case XML_ELEMENT_DECL: - case XML_ATTRIBUTE_DECL: - case XML_ENTITY_DECL: - /* - * should be ignored according to "W3C Canonical XML" - */ - break; - default: - xmlC14NErrUnknownNode(cur->type, "processing node"); - return (-1); - } - - return (ret); -} - -/** - * xmlC14NProcessNodeList: - * @ctx: the pointer to C14N context object - * @cur: the node to start from - * - * Processes all nodes in the row starting from cur. - * - * Returns non-negative value on success or negative value on fail - */ -static int -xmlC14NProcessNodeList(xmlC14NCtxPtr ctx, xmlNodePtr cur) -{ - int ret; - - if (ctx == NULL) { - xmlC14NErrParam("processing node list"); - return (-1); - } - - for (ret = 0; cur != NULL && ret >= 0; cur = cur->next) { - ret = xmlC14NProcessNode(ctx, cur); - } - return (ret); -} - - -/** - * xmlC14NFreeCtx: - * @ctx: the pointer to C14N context object - * - * Cleanups the C14N context object. - */ - -static void -xmlC14NFreeCtx(xmlC14NCtxPtr ctx) -{ - if (ctx == NULL) { - xmlC14NErrParam("freeing context"); - return; - } - - if (ctx->ns_rendered != NULL) { - xmlC14NVisibleNsStackDestroy(ctx->ns_rendered); - } - xmlFree(ctx); -} - -/** - * xmlC14NNewCtx: - * @doc: the XML document for canonization - * @is_visible_callback:the function to use to determine is node visible - * or not - * @user_data: the first parameter for @is_visible_callback function - * (in most cases, it is nodes set) - * @mode: the c14n mode (see @xmlC14NMode) - * @inclusive_ns_prefixe the list of inclusive namespace prefixes - * ended with a NULL or NULL if there is no - * inclusive namespaces (only for ` - * canonicalization) - * @with_comments: include comments in the result (!=0) or not (==0) - * @buf: the output buffer to store canonical XML; this - * buffer MUST have encoder==NULL because C14N requires - * UTF-8 output - * - * Creates new C14N context object to store C14N parameters. - * - * Returns pointer to newly created object (success) or NULL (fail) - */ -static xmlC14NCtxPtr -xmlC14NNewCtx(xmlDocPtr doc, - xmlC14NIsVisibleCallback is_visible_callback, void* user_data, - xmlC14NMode mode, xmlChar ** inclusive_ns_prefixes, - int with_comments, xmlOutputBufferPtr buf) -{ - xmlC14NCtxPtr ctx = NULL; - - if ((doc == NULL) || (buf == NULL)) { - xmlC14NErrParam("creating new context"); - return (NULL); - } - - /* - * Validate the encoding output buffer encoding - */ - if (buf->encoder != NULL) { - xmlC14NErr(ctx, (xmlNodePtr) doc, XML_C14N_REQUIRES_UTF8, -"xmlC14NNewCtx: output buffer encoder != NULL but C14N requires UTF8 output\n"); - return (NULL); - } - - /* - * Validate the XML document encoding value, if provided. - */ - if (doc->charset != XML_CHAR_ENCODING_UTF8) { - xmlC14NErr(ctx, (xmlNodePtr) doc, XML_C14N_REQUIRES_UTF8, - "xmlC14NNewCtx: source document not in UTF8\n"); - return (NULL); - } - - /* - * Allocate a new xmlC14NCtxPtr and fill the fields. - */ - ctx = (xmlC14NCtxPtr) xmlMalloc(sizeof(xmlC14NCtx)); - if (ctx == NULL) { - xmlC14NErrMemory("creating context"); - return (NULL); - } - memset(ctx, 0, sizeof(xmlC14NCtx)); - - /* - * initialize C14N context - */ - ctx->doc = doc; - ctx->with_comments = with_comments; - ctx->is_visible_callback = is_visible_callback; - ctx->user_data = user_data; - ctx->buf = buf; - ctx->parent_is_doc = 1; - ctx->pos = XMLC14N_BEFORE_DOCUMENT_ELEMENT; - ctx->ns_rendered = xmlC14NVisibleNsStackCreate(); - - if(ctx->ns_rendered == NULL) { - xmlC14NErr(ctx, (xmlNodePtr) doc, XML_C14N_CREATE_STACK, - "xmlC14NNewCtx: xmlC14NVisibleNsStackCreate failed\n"); - xmlC14NFreeCtx(ctx); - return (NULL); - } - - /* - * Set "mode" flag and remember list of incluseve prefixes - * for exclusive c14n - */ - ctx->mode = mode; - if(xmlC14NIsExclusive(ctx)) { - ctx->inclusive_ns_prefixes = inclusive_ns_prefixes; - } - return (ctx); -} - -/** - * xmlC14NExecute: - * @doc: the XML document for canonization - * @is_visible_callback:the function to use to determine is node visible - * or not - * @user_data: the first parameter for @is_visible_callback function - * (in most cases, it is nodes set) - * @mode: the c14n mode (see @xmlC14NMode) - * @inclusive_ns_prefixes: the list of inclusive namespace prefixes - * ended with a NULL or NULL if there is no - * inclusive namespaces (only for exclusive - * canonicalization, ignored otherwise) - * @with_comments: include comments in the result (!=0) or not (==0) - * @buf: the output buffer to store canonical XML; this - * buffer MUST have encoder==NULL because C14N requires - * UTF-8 output - * - * Dumps the canonized image of given XML document into the provided buffer. - * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or - * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) - * - * Returns non-negative value on success or a negative value on fail - */ -int -xmlC14NExecute(xmlDocPtr doc, xmlC14NIsVisibleCallback is_visible_callback, - void* user_data, int mode, xmlChar **inclusive_ns_prefixes, - int with_comments, xmlOutputBufferPtr buf) { - - xmlC14NCtxPtr ctx; - xmlC14NMode c14n_mode = XML_C14N_1_0; - int ret; - - if ((buf == NULL) || (doc == NULL)) { - xmlC14NErrParam("executing c14n"); - return (-1); - } - - /* for backward compatibility, we have to have "mode" as "int" - and here we check that user gives valid value */ - switch(mode) { - case XML_C14N_1_0: - case XML_C14N_EXCLUSIVE_1_0: - case XML_C14N_1_1: - c14n_mode = (xmlC14NMode)mode; - break; - default: - xmlC14NErrParam("invalid mode for executing c14n"); - return (-1); - } - - /* - * Validate the encoding output buffer encoding - */ - if (buf->encoder != NULL) { - xmlC14NErr(NULL, (xmlNodePtr) doc, XML_C14N_REQUIRES_UTF8, -"xmlC14NExecute: output buffer encoder != NULL but C14N requires UTF8 output\n"); - return (-1); - } - - ctx = xmlC14NNewCtx(doc, is_visible_callback, user_data, - c14n_mode, inclusive_ns_prefixes, - with_comments, buf); - if (ctx == NULL) { - xmlC14NErr(NULL, (xmlNodePtr) doc, XML_C14N_CREATE_CTXT, - "xmlC14NExecute: unable to create C14N context\n"); - return (-1); - } - - - - /* - * Root Node - * The root node is the parent of the top-level document element. The - * result of processing each of its child nodes that is in the node-set - * in document order. The root node does not generate a byte order mark, - * XML declaration, nor anything from within the document type - * declaration. - */ - if (doc->children != NULL) { - ret = xmlC14NProcessNodeList(ctx, doc->children); - if (ret < 0) { - xmlC14NErrInternal("processing docs children list"); - xmlC14NFreeCtx(ctx); - return (-1); - } - } - - /* - * Flush buffer to get number of bytes written - */ - ret = xmlOutputBufferFlush(buf); - if (ret < 0) { - xmlC14NErrInternal("flushing output buffer"); - xmlC14NFreeCtx(ctx); - return (-1); - } - - /* - * Cleanup - */ - xmlC14NFreeCtx(ctx); - return (ret); -} - -/** - * xmlC14NDocSaveTo: - * @doc: the XML document for canonization - * @nodes: the nodes set to be included in the canonized image - * or NULL if all document nodes should be included - * @mode: the c14n mode (see @xmlC14NMode) - * @inclusive_ns_prefixes: the list of inclusive namespace prefixes - * ended with a NULL or NULL if there is no - * inclusive namespaces (only for exclusive - * canonicalization, ignored otherwise) - * @with_comments: include comments in the result (!=0) or not (==0) - * @buf: the output buffer to store canonical XML; this - * buffer MUST have encoder==NULL because C14N requires - * UTF-8 output - * - * Dumps the canonized image of given XML document into the provided buffer. - * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or - * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) - * - * Returns non-negative value on success or a negative value on fail - */ -int -xmlC14NDocSaveTo(xmlDocPtr doc, xmlNodeSetPtr nodes, - int mode, xmlChar ** inclusive_ns_prefixes, - int with_comments, xmlOutputBufferPtr buf) { - return(xmlC14NExecute(doc, - (xmlC14NIsVisibleCallback)xmlC14NIsNodeInNodeset, - nodes, - mode, - inclusive_ns_prefixes, - with_comments, - buf)); -} - - -/** - * xmlC14NDocDumpMemory: - * @doc: the XML document for canonization - * @nodes: the nodes set to be included in the canonized image - * or NULL if all document nodes should be included - * @mode: the c14n mode (see @xmlC14NMode) - * @inclusive_ns_prefixes: the list of inclusive namespace prefixes - * ended with a NULL or NULL if there is no - * inclusive namespaces (only for exclusive - * canonicalization, ignored otherwise) - * @with_comments: include comments in the result (!=0) or not (==0) - * @doc_txt_ptr: the memory pointer for allocated canonical XML text; - * the caller of this functions is responsible for calling - * xmlFree() to free allocated memory - * - * Dumps the canonized image of given XML document into memory. - * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or - * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) - * - * Returns the number of bytes written on success or a negative value on fail - */ -int -xmlC14NDocDumpMemory(xmlDocPtr doc, xmlNodeSetPtr nodes, - int mode, xmlChar ** inclusive_ns_prefixes, - int with_comments, xmlChar ** doc_txt_ptr) -{ - int ret; - xmlOutputBufferPtr buf; - - if (doc_txt_ptr == NULL) { - xmlC14NErrParam("dumping doc to memory"); - return (-1); - } - - *doc_txt_ptr = NULL; - - /* - * create memory buffer with UTF8 (default) encoding - */ - buf = xmlAllocOutputBuffer(NULL); - if (buf == NULL) { - xmlC14NErrMemory("creating output buffer"); - return (-1); - } - - /* - * canonize document and write to buffer - */ - ret = xmlC14NDocSaveTo(doc, nodes, mode, inclusive_ns_prefixes, - with_comments, buf); - if (ret < 0) { - xmlC14NErrInternal("saving doc to output buffer"); - (void) xmlOutputBufferClose(buf); - return (-1); - } - - ret = buf->buffer->use; - if (ret > 0) { - *doc_txt_ptr = xmlStrndup(buf->buffer->content, ret); - } - (void) xmlOutputBufferClose(buf); - - if ((*doc_txt_ptr == NULL) && (ret > 0)) { - xmlC14NErrMemory("coping canonicanized document"); - return (-1); - } - return (ret); -} - -/** - * xmlC14NDocSave: - * @doc: the XML document for canonization - * @nodes: the nodes set to be included in the canonized image - * or NULL if all document nodes should be included - * @mode: the c14n mode (see @xmlC14NMode) - * @inclusive_ns_prefixes: the list of inclusive namespace prefixes - * ended with a NULL or NULL if there is no - * inclusive namespaces (only for exclusive - * canonicalization, ignored otherwise) - * @with_comments: include comments in the result (!=0) or not (==0) - * @filename: the filename to store canonical XML image - * @compression: the compression level (zlib requred): - * -1 - libxml default, - * 0 - uncompressed, - * >0 - compression level - * - * Dumps the canonized image of given XML document into the file. - * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or - * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) - * - * Returns the number of bytes written success or a negative value on fail - */ -int -xmlC14NDocSave(xmlDocPtr doc, xmlNodeSetPtr nodes, - int mode, xmlChar ** inclusive_ns_prefixes, - int with_comments, const char *filename, int compression) -{ - xmlOutputBufferPtr buf; - int ret; - - if (filename == NULL) { - xmlC14NErrParam("saving doc"); - return (-1); - } -#ifdef HAVE_ZLIB_H - if (compression < 0) - compression = xmlGetCompressMode(); -#endif - - /* - * save the content to a temp buffer, use default UTF8 encoding. - */ - buf = xmlOutputBufferCreateFilename(filename, NULL, compression); - if (buf == NULL) { - xmlC14NErrInternal("creating temporary filename"); - return (-1); - } - - /* - * canonize document and write to buffer - */ - ret = xmlC14NDocSaveTo(doc, nodes, mode, inclusive_ns_prefixes, - with_comments, buf); - if (ret < 0) { - xmlC14NErrInternal("cannicanize document to buffer"); - (void) xmlOutputBufferClose(buf); - return (-1); - } - - /* - * get the numbers of bytes written - */ - ret = xmlOutputBufferClose(buf); - return (ret); -} - - - -/* - * Macro used to grow the current buffer. - */ -#define growBufferReentrant() { \ - buffer_size *= 2; \ - buffer = (xmlChar *) \ - xmlRealloc(buffer, buffer_size * sizeof(xmlChar)); \ - if (buffer == NULL) { \ - xmlC14NErrMemory("growing buffer"); \ - return(NULL); \ - } \ -} - -/** - * xmlC11NNormalizeString: - * @input: the input string - * @mode: the normalization mode (attribute, comment, PI or text) - * - * Converts a string to a canonical (normalized) format. The code is stolen - * from xmlEncodeEntitiesReentrant(). Added normalization of \x09, \x0a, \x0A - * and the @mode parameter - * - * Returns a normalized string (caller is responsible for calling xmlFree()) - * or NULL if an error occurs - */ -static xmlChar * -xmlC11NNormalizeString(const xmlChar * input, - xmlC14NNormalizationMode mode) -{ - const xmlChar *cur = input; - xmlChar *buffer = NULL; - xmlChar *out = NULL; - int buffer_size = 0; - - if (input == NULL) - return (NULL); - - /* - * allocate an translation buffer. - */ - buffer_size = 1000; - buffer = (xmlChar *) xmlMallocAtomic(buffer_size * sizeof(xmlChar)); - if (buffer == NULL) { - xmlC14NErrMemory("allocating buffer"); - return (NULL); - } - out = buffer; - - while (*cur != '\0') { - if ((out - buffer) > (buffer_size - 10)) { - int indx = out - buffer; - - growBufferReentrant(); - out = &buffer[indx]; - } - - if ((*cur == '<') && ((mode == XMLC14N_NORMALIZE_ATTR) || - (mode == XMLC14N_NORMALIZE_TEXT))) { - *out++ = '&'; - *out++ = 'l'; - *out++ = 't'; - *out++ = ';'; - } else if ((*cur == '>') && (mode == XMLC14N_NORMALIZE_TEXT)) { - *out++ = '&'; - *out++ = 'g'; - *out++ = 't'; - *out++ = ';'; - } else if ((*cur == '&') && ((mode == XMLC14N_NORMALIZE_ATTR) || - (mode == XMLC14N_NORMALIZE_TEXT))) { - *out++ = '&'; - *out++ = 'a'; - *out++ = 'm'; - *out++ = 'p'; - *out++ = ';'; - } else if ((*cur == '"') && (mode == XMLC14N_NORMALIZE_ATTR)) { - *out++ = '&'; - *out++ = 'q'; - *out++ = 'u'; - *out++ = 'o'; - *out++ = 't'; - *out++ = ';'; - } else if ((*cur == '\x09') && (mode == XMLC14N_NORMALIZE_ATTR)) { - *out++ = '&'; - *out++ = '#'; - *out++ = 'x'; - *out++ = '9'; - *out++ = ';'; - } else if ((*cur == '\x0A') && (mode == XMLC14N_NORMALIZE_ATTR)) { - *out++ = '&'; - *out++ = '#'; - *out++ = 'x'; - *out++ = 'A'; - *out++ = ';'; - } else if ((*cur == '\x0D') && ((mode == XMLC14N_NORMALIZE_ATTR) || - (mode == XMLC14N_NORMALIZE_TEXT) || - (mode == XMLC14N_NORMALIZE_COMMENT) || - (mode == XMLC14N_NORMALIZE_PI))) { - *out++ = '&'; - *out++ = '#'; - *out++ = 'x'; - *out++ = 'D'; - *out++ = ';'; - } else { - /* - * Works because on UTF-8, all extended sequences cannot - * result in bytes in the ASCII range. - */ - *out++ = *cur; - } - cur++; - } - *out = 0; - return (buffer); -} -#endif /* LIBXML_OUTPUT_ENABLED */ -#define bottom_c14n -#include "elfgcchack.h" -#endif /* LIBXML_C14N_ENABLED */ diff --git a/android/native/libxml2/elfgcchack.h b/android/native/libxml2/elfgcchack.h index d422398a1b..17fa383ad5 100644 --- a/android/native/libxml2/elfgcchack.h +++ b/android/native/libxml2/elfgcchack.h @@ -276,18 +276,6 @@ extern __typeof (xmlAddSibling) xmlAddSibling__internal_alias __attribute((visib #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlAllocOutputBuffer -extern __typeof (xmlAllocOutputBuffer) xmlAllocOutputBuffer __attribute((alias("xmlAllocOutputBuffer__internal_alias"))); -#else -#ifndef xmlAllocOutputBuffer -extern __typeof (xmlAllocOutputBuffer) xmlAllocOutputBuffer__internal_alias __attribute((visibility("hidden"))); -#define xmlAllocOutputBuffer xmlAllocOutputBuffer__internal_alias -#endif -#endif -#endif - #ifdef bottom_xmlIO #undef xmlAllocParserInputBuffer extern __typeof (xmlAllocParserInputBuffer) xmlAllocParserInputBuffer __attribute((alias("xmlAllocParserInputBuffer__internal_alias"))); @@ -298,18 +286,6 @@ extern __typeof (xmlAllocParserInputBuffer) xmlAllocParserInputBuffer__internal_ #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlAttrSerializeTxtContent -extern __typeof (xmlAttrSerializeTxtContent) xmlAttrSerializeTxtContent __attribute((alias("xmlAttrSerializeTxtContent__internal_alias"))); -#else -#ifndef xmlAttrSerializeTxtContent -extern __typeof (xmlAttrSerializeTxtContent) xmlAttrSerializeTxtContent__internal_alias __attribute((visibility("hidden"))); -#define xmlAttrSerializeTxtContent xmlAttrSerializeTxtContent__internal_alias -#endif -#endif -#endif - #if defined(LIBXML_REGEXP_ENABLED) && defined(LIBXML_AUTOMATA_ENABLED) #ifdef bottom_xmlregexp #undef xmlAutomataCompile @@ -744,54 +720,6 @@ extern __typeof (xmlByteConsumed) xmlByteConsumed__internal_alias __attribute((v #endif #endif -#if defined(LIBXML_C14N_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_c14n -#undef xmlC14NDocDumpMemory -extern __typeof (xmlC14NDocDumpMemory) xmlC14NDocDumpMemory __attribute((alias("xmlC14NDocDumpMemory__internal_alias"))); -#else -#ifndef xmlC14NDocDumpMemory -extern __typeof (xmlC14NDocDumpMemory) xmlC14NDocDumpMemory__internal_alias __attribute((visibility("hidden"))); -#define xmlC14NDocDumpMemory xmlC14NDocDumpMemory__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_C14N_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_c14n -#undef xmlC14NDocSave -extern __typeof (xmlC14NDocSave) xmlC14NDocSave __attribute((alias("xmlC14NDocSave__internal_alias"))); -#else -#ifndef xmlC14NDocSave -extern __typeof (xmlC14NDocSave) xmlC14NDocSave__internal_alias __attribute((visibility("hidden"))); -#define xmlC14NDocSave xmlC14NDocSave__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_C14N_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_c14n -#undef xmlC14NDocSaveTo -extern __typeof (xmlC14NDocSaveTo) xmlC14NDocSaveTo __attribute((alias("xmlC14NDocSaveTo__internal_alias"))); -#else -#ifndef xmlC14NDocSaveTo -extern __typeof (xmlC14NDocSaveTo) xmlC14NDocSaveTo__internal_alias __attribute((visibility("hidden"))); -#define xmlC14NDocSaveTo xmlC14NDocSaveTo__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_C14N_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_c14n -#undef xmlC14NExecute -extern __typeof (xmlC14NExecute) xmlC14NExecute __attribute((alias("xmlC14NExecute__internal_alias"))); -#else -#ifndef xmlC14NExecute -extern __typeof (xmlC14NExecute) xmlC14NExecute__internal_alias __attribute((visibility("hidden"))); -#define xmlC14NExecute xmlC14NExecute__internal_alias -#endif -#endif -#endif - #ifdef bottom_uri #undef xmlCanonicPath extern __typeof (xmlCanonicPath) xmlCanonicPath __attribute((alias("xmlCanonicPath__internal_alias"))); @@ -985,18 +913,6 @@ extern __typeof (xmlCleanupMemory) xmlCleanupMemory__internal_alias __attribute( #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlCleanupOutputCallbacks -extern __typeof (xmlCleanupOutputCallbacks) xmlCleanupOutputCallbacks __attribute((alias("xmlCleanupOutputCallbacks__internal_alias"))); -#else -#ifndef xmlCleanupOutputCallbacks -extern __typeof (xmlCleanupOutputCallbacks) xmlCleanupOutputCallbacks__internal_alias __attribute((visibility("hidden"))); -#define xmlCleanupOutputCallbacks xmlCleanupOutputCallbacks__internal_alias -#endif -#endif -#endif - #ifdef bottom_parser #undef xmlCleanupParser extern __typeof (xmlCleanupParser) xmlCleanupParser __attribute((alias("xmlCleanupParser__internal_alias"))); @@ -1675,78 +1591,6 @@ extern __typeof (xmlDocCopyNodeList) xmlDocCopyNodeList__internal_alias __attrib #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlDocDump -extern __typeof (xmlDocDump) xmlDocDump __attribute((alias("xmlDocDump__internal_alias"))); -#else -#ifndef xmlDocDump -extern __typeof (xmlDocDump) xmlDocDump__internal_alias __attribute((visibility("hidden"))); -#define xmlDocDump xmlDocDump__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlDocDumpFormatMemory -extern __typeof (xmlDocDumpFormatMemory) xmlDocDumpFormatMemory __attribute((alias("xmlDocDumpFormatMemory__internal_alias"))); -#else -#ifndef xmlDocDumpFormatMemory -extern __typeof (xmlDocDumpFormatMemory) xmlDocDumpFormatMemory__internal_alias __attribute((visibility("hidden"))); -#define xmlDocDumpFormatMemory xmlDocDumpFormatMemory__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlDocDumpFormatMemoryEnc -extern __typeof (xmlDocDumpFormatMemoryEnc) xmlDocDumpFormatMemoryEnc __attribute((alias("xmlDocDumpFormatMemoryEnc__internal_alias"))); -#else -#ifndef xmlDocDumpFormatMemoryEnc -extern __typeof (xmlDocDumpFormatMemoryEnc) xmlDocDumpFormatMemoryEnc__internal_alias __attribute((visibility("hidden"))); -#define xmlDocDumpFormatMemoryEnc xmlDocDumpFormatMemoryEnc__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlDocDumpMemory -extern __typeof (xmlDocDumpMemory) xmlDocDumpMemory __attribute((alias("xmlDocDumpMemory__internal_alias"))); -#else -#ifndef xmlDocDumpMemory -extern __typeof (xmlDocDumpMemory) xmlDocDumpMemory__internal_alias __attribute((visibility("hidden"))); -#define xmlDocDumpMemory xmlDocDumpMemory__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlDocDumpMemoryEnc -extern __typeof (xmlDocDumpMemoryEnc) xmlDocDumpMemoryEnc __attribute((alias("xmlDocDumpMemoryEnc__internal_alias"))); -#else -#ifndef xmlDocDumpMemoryEnc -extern __typeof (xmlDocDumpMemoryEnc) xmlDocDumpMemoryEnc__internal_alias __attribute((visibility("hidden"))); -#define xmlDocDumpMemoryEnc xmlDocDumpMemoryEnc__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlDocFormatDump -extern __typeof (xmlDocFormatDump) xmlDocFormatDump __attribute((alias("xmlDocFormatDump__internal_alias"))); -#else -#ifndef xmlDocFormatDump -extern __typeof (xmlDocFormatDump) xmlDocFormatDump__internal_alias __attribute((visibility("hidden"))); -#define xmlDocFormatDump xmlDocFormatDump__internal_alias -#endif -#endif -#endif - #ifdef bottom_tree #undef xmlDocGetRootElement extern __typeof (xmlDocGetRootElement) xmlDocGetRootElement __attribute((alias("xmlDocGetRootElement__internal_alias"))); @@ -1769,114 +1613,6 @@ extern __typeof (xmlDocSetRootElement) xmlDocSetRootElement__internal_alias __at #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_valid -#undef xmlDumpAttributeDecl -extern __typeof (xmlDumpAttributeDecl) xmlDumpAttributeDecl __attribute((alias("xmlDumpAttributeDecl__internal_alias"))); -#else -#ifndef xmlDumpAttributeDecl -extern __typeof (xmlDumpAttributeDecl) xmlDumpAttributeDecl__internal_alias __attribute((visibility("hidden"))); -#define xmlDumpAttributeDecl xmlDumpAttributeDecl__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_valid -#undef xmlDumpAttributeTable -extern __typeof (xmlDumpAttributeTable) xmlDumpAttributeTable __attribute((alias("xmlDumpAttributeTable__internal_alias"))); -#else -#ifndef xmlDumpAttributeTable -extern __typeof (xmlDumpAttributeTable) xmlDumpAttributeTable__internal_alias __attribute((visibility("hidden"))); -#define xmlDumpAttributeTable xmlDumpAttributeTable__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_valid -#undef xmlDumpElementDecl -extern __typeof (xmlDumpElementDecl) xmlDumpElementDecl __attribute((alias("xmlDumpElementDecl__internal_alias"))); -#else -#ifndef xmlDumpElementDecl -extern __typeof (xmlDumpElementDecl) xmlDumpElementDecl__internal_alias __attribute((visibility("hidden"))); -#define xmlDumpElementDecl xmlDumpElementDecl__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_valid -#undef xmlDumpElementTable -extern __typeof (xmlDumpElementTable) xmlDumpElementTable __attribute((alias("xmlDumpElementTable__internal_alias"))); -#else -#ifndef xmlDumpElementTable -extern __typeof (xmlDumpElementTable) xmlDumpElementTable__internal_alias __attribute((visibility("hidden"))); -#define xmlDumpElementTable xmlDumpElementTable__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_entities -#undef xmlDumpEntitiesTable -extern __typeof (xmlDumpEntitiesTable) xmlDumpEntitiesTable __attribute((alias("xmlDumpEntitiesTable__internal_alias"))); -#else -#ifndef xmlDumpEntitiesTable -extern __typeof (xmlDumpEntitiesTable) xmlDumpEntitiesTable__internal_alias __attribute((visibility("hidden"))); -#define xmlDumpEntitiesTable xmlDumpEntitiesTable__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_entities -#undef xmlDumpEntityDecl -extern __typeof (xmlDumpEntityDecl) xmlDumpEntityDecl __attribute((alias("xmlDumpEntityDecl__internal_alias"))); -#else -#ifndef xmlDumpEntityDecl -extern __typeof (xmlDumpEntityDecl) xmlDumpEntityDecl__internal_alias __attribute((visibility("hidden"))); -#define xmlDumpEntityDecl xmlDumpEntityDecl__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_valid -#undef xmlDumpNotationDecl -extern __typeof (xmlDumpNotationDecl) xmlDumpNotationDecl __attribute((alias("xmlDumpNotationDecl__internal_alias"))); -#else -#ifndef xmlDumpNotationDecl -extern __typeof (xmlDumpNotationDecl) xmlDumpNotationDecl__internal_alias __attribute((visibility("hidden"))); -#define xmlDumpNotationDecl xmlDumpNotationDecl__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_valid -#undef xmlDumpNotationTable -extern __typeof (xmlDumpNotationTable) xmlDumpNotationTable __attribute((alias("xmlDumpNotationTable__internal_alias"))); -#else -#ifndef xmlDumpNotationTable -extern __typeof (xmlDumpNotationTable) xmlDumpNotationTable__internal_alias __attribute((visibility("hidden"))); -#define xmlDumpNotationTable xmlDumpNotationTable__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlElemDump -extern __typeof (xmlElemDump) xmlElemDump __attribute((alias("xmlElemDump__internal_alias"))); -#else -#ifndef xmlElemDump -extern __typeof (xmlElemDump) xmlElemDump__internal_alias __attribute((visibility("hidden"))); -#define xmlElemDump xmlElemDump__internal_alias -#endif -#endif -#endif - #ifdef bottom_entities #undef xmlEncodeEntitiesReentrant extern __typeof (xmlEncodeEntitiesReentrant) xmlEncodeEntitiesReentrant __attribute((alias("xmlEncodeEntitiesReentrant__internal_alias"))); @@ -4330,30 +4066,6 @@ extern __typeof (xmlNodeBufGetContent) xmlNodeBufGetContent__internal_alias __at #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlNodeDump -extern __typeof (xmlNodeDump) xmlNodeDump __attribute((alias("xmlNodeDump__internal_alias"))); -#else -#ifndef xmlNodeDump -extern __typeof (xmlNodeDump) xmlNodeDump__internal_alias __attribute((visibility("hidden"))); -#define xmlNodeDump xmlNodeDump__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlNodeDumpOutput -extern __typeof (xmlNodeDumpOutput) xmlNodeDumpOutput __attribute((alias("xmlNodeDumpOutput__internal_alias"))); -#else -#ifndef xmlNodeDumpOutput -extern __typeof (xmlNodeDumpOutput) xmlNodeDumpOutput__internal_alias __attribute((visibility("hidden"))); -#define xmlNodeDumpOutput xmlNodeDumpOutput__internal_alias -#endif -#endif -#endif - #ifdef bottom_tree #undef xmlNodeGetBase extern __typeof (xmlNodeGetBase) xmlNodeGetBase __attribute((alias("xmlNodeGetBase__internal_alias"))); @@ -4516,66 +4228,6 @@ extern __typeof (xmlNormalizeWindowsPath) xmlNormalizeWindowsPath__internal_alia #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferClose -extern __typeof (xmlOutputBufferClose) xmlOutputBufferClose __attribute((alias("xmlOutputBufferClose__internal_alias"))); -#else -#ifndef xmlOutputBufferClose -extern __typeof (xmlOutputBufferClose) xmlOutputBufferClose__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferClose xmlOutputBufferClose__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferCreateBuffer -extern __typeof (xmlOutputBufferCreateBuffer) xmlOutputBufferCreateBuffer __attribute((alias("xmlOutputBufferCreateBuffer__internal_alias"))); -#else -#ifndef xmlOutputBufferCreateBuffer -extern __typeof (xmlOutputBufferCreateBuffer) xmlOutputBufferCreateBuffer__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferCreateBuffer xmlOutputBufferCreateBuffer__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferCreateFd -extern __typeof (xmlOutputBufferCreateFd) xmlOutputBufferCreateFd __attribute((alias("xmlOutputBufferCreateFd__internal_alias"))); -#else -#ifndef xmlOutputBufferCreateFd -extern __typeof (xmlOutputBufferCreateFd) xmlOutputBufferCreateFd__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferCreateFd xmlOutputBufferCreateFd__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferCreateFile -extern __typeof (xmlOutputBufferCreateFile) xmlOutputBufferCreateFile __attribute((alias("xmlOutputBufferCreateFile__internal_alias"))); -#else -#ifndef xmlOutputBufferCreateFile -extern __typeof (xmlOutputBufferCreateFile) xmlOutputBufferCreateFile__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferCreateFile xmlOutputBufferCreateFile__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferCreateFilename -extern __typeof (xmlOutputBufferCreateFilename) xmlOutputBufferCreateFilename __attribute((alias("xmlOutputBufferCreateFilename__internal_alias"))); -#else -#ifndef xmlOutputBufferCreateFilename -extern __typeof (xmlOutputBufferCreateFilename) xmlOutputBufferCreateFilename__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferCreateFilename xmlOutputBufferCreateFilename__internal_alias -#endif -#endif -#endif - #ifdef bottom_xmlIO #undef xmlOutputBufferCreateFilenameDefault extern __typeof (xmlOutputBufferCreateFilenameDefault) xmlOutputBufferCreateFilenameDefault __attribute((alias("xmlOutputBufferCreateFilenameDefault__internal_alias"))); @@ -4586,66 +4238,6 @@ extern __typeof (xmlOutputBufferCreateFilenameDefault) xmlOutputBufferCreateFile #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferCreateIO -extern __typeof (xmlOutputBufferCreateIO) xmlOutputBufferCreateIO __attribute((alias("xmlOutputBufferCreateIO__internal_alias"))); -#else -#ifndef xmlOutputBufferCreateIO -extern __typeof (xmlOutputBufferCreateIO) xmlOutputBufferCreateIO__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferCreateIO xmlOutputBufferCreateIO__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferFlush -extern __typeof (xmlOutputBufferFlush) xmlOutputBufferFlush __attribute((alias("xmlOutputBufferFlush__internal_alias"))); -#else -#ifndef xmlOutputBufferFlush -extern __typeof (xmlOutputBufferFlush) xmlOutputBufferFlush__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferFlush xmlOutputBufferFlush__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferWrite -extern __typeof (xmlOutputBufferWrite) xmlOutputBufferWrite __attribute((alias("xmlOutputBufferWrite__internal_alias"))); -#else -#ifndef xmlOutputBufferWrite -extern __typeof (xmlOutputBufferWrite) xmlOutputBufferWrite__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferWrite xmlOutputBufferWrite__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferWriteEscape -extern __typeof (xmlOutputBufferWriteEscape) xmlOutputBufferWriteEscape __attribute((alias("xmlOutputBufferWriteEscape__internal_alias"))); -#else -#ifndef xmlOutputBufferWriteEscape -extern __typeof (xmlOutputBufferWriteEscape) xmlOutputBufferWriteEscape__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferWriteEscape xmlOutputBufferWriteEscape__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlOutputBufferWriteString -extern __typeof (xmlOutputBufferWriteString) xmlOutputBufferWriteString __attribute((alias("xmlOutputBufferWriteString__internal_alias"))); -#else -#ifndef xmlOutputBufferWriteString -extern __typeof (xmlOutputBufferWriteString) xmlOutputBufferWriteString__internal_alias __attribute((visibility("hidden"))); -#define xmlOutputBufferWriteString xmlOutputBufferWriteString__internal_alias -#endif -#endif -#endif - #ifdef bottom_parser #undef xmlParseAttValue extern __typeof (xmlParseAttValue) xmlParseAttValue __attribute((alias("xmlParseAttValue__internal_alias"))); @@ -5861,18 +5453,6 @@ extern __typeof (xmlRegisterDefaultInputCallbacks) xmlRegisterDefaultInputCallba #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlRegisterDefaultOutputCallbacks -extern __typeof (xmlRegisterDefaultOutputCallbacks) xmlRegisterDefaultOutputCallbacks __attribute((alias("xmlRegisterDefaultOutputCallbacks__internal_alias"))); -#else -#ifndef xmlRegisterDefaultOutputCallbacks -extern __typeof (xmlRegisterDefaultOutputCallbacks) xmlRegisterDefaultOutputCallbacks__internal_alias __attribute((visibility("hidden"))); -#define xmlRegisterDefaultOutputCallbacks xmlRegisterDefaultOutputCallbacks__internal_alias -#endif -#endif -#endif - #ifdef bottom_xmlIO #undef xmlRegisterInputCallbacks extern __typeof (xmlRegisterInputCallbacks) xmlRegisterInputCallbacks __attribute((alias("xmlRegisterInputCallbacks__internal_alias"))); @@ -5893,18 +5473,6 @@ extern __typeof (xmlRegisterNodeDefault) xmlRegisterNodeDefault__internal_alias #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlIO -#undef xmlRegisterOutputCallbacks -extern __typeof (xmlRegisterOutputCallbacks) xmlRegisterOutputCallbacks __attribute((alias("xmlRegisterOutputCallbacks__internal_alias"))); -#else -#ifndef xmlRegisterOutputCallbacks -extern __typeof (xmlRegisterOutputCallbacks) xmlRegisterOutputCallbacks__internal_alias __attribute((visibility("hidden"))); -#define xmlRegisterOutputCallbacks xmlRegisterOutputCallbacks__internal_alias -#endif -#endif -#endif - #ifdef bottom_valid #undef xmlRemoveID extern __typeof (xmlRemoveID) xmlRemoveID __attribute((alias("xmlRemoveID__internal_alias"))); @@ -6279,198 +5847,6 @@ extern __typeof (xmlSAXVersion) xmlSAXVersion__internal_alias __attribute((visib #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveClose -extern __typeof (xmlSaveClose) xmlSaveClose __attribute((alias("xmlSaveClose__internal_alias"))); -#else -#ifndef xmlSaveClose -extern __typeof (xmlSaveClose) xmlSaveClose__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveClose xmlSaveClose__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveDoc -extern __typeof (xmlSaveDoc) xmlSaveDoc __attribute((alias("xmlSaveDoc__internal_alias"))); -#else -#ifndef xmlSaveDoc -extern __typeof (xmlSaveDoc) xmlSaveDoc__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveDoc xmlSaveDoc__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveFile -extern __typeof (xmlSaveFile) xmlSaveFile __attribute((alias("xmlSaveFile__internal_alias"))); -#else -#ifndef xmlSaveFile -extern __typeof (xmlSaveFile) xmlSaveFile__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveFile xmlSaveFile__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveFileEnc -extern __typeof (xmlSaveFileEnc) xmlSaveFileEnc __attribute((alias("xmlSaveFileEnc__internal_alias"))); -#else -#ifndef xmlSaveFileEnc -extern __typeof (xmlSaveFileEnc) xmlSaveFileEnc__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveFileEnc xmlSaveFileEnc__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveFileTo -extern __typeof (xmlSaveFileTo) xmlSaveFileTo __attribute((alias("xmlSaveFileTo__internal_alias"))); -#else -#ifndef xmlSaveFileTo -extern __typeof (xmlSaveFileTo) xmlSaveFileTo__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveFileTo xmlSaveFileTo__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveFlush -extern __typeof (xmlSaveFlush) xmlSaveFlush __attribute((alias("xmlSaveFlush__internal_alias"))); -#else -#ifndef xmlSaveFlush -extern __typeof (xmlSaveFlush) xmlSaveFlush__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveFlush xmlSaveFlush__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveFormatFile -extern __typeof (xmlSaveFormatFile) xmlSaveFormatFile __attribute((alias("xmlSaveFormatFile__internal_alias"))); -#else -#ifndef xmlSaveFormatFile -extern __typeof (xmlSaveFormatFile) xmlSaveFormatFile__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveFormatFile xmlSaveFormatFile__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveFormatFileEnc -extern __typeof (xmlSaveFormatFileEnc) xmlSaveFormatFileEnc __attribute((alias("xmlSaveFormatFileEnc__internal_alias"))); -#else -#ifndef xmlSaveFormatFileEnc -extern __typeof (xmlSaveFormatFileEnc) xmlSaveFormatFileEnc__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveFormatFileEnc xmlSaveFormatFileEnc__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveFormatFileTo -extern __typeof (xmlSaveFormatFileTo) xmlSaveFormatFileTo __attribute((alias("xmlSaveFormatFileTo__internal_alias"))); -#else -#ifndef xmlSaveFormatFileTo -extern __typeof (xmlSaveFormatFileTo) xmlSaveFormatFileTo__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveFormatFileTo xmlSaveFormatFileTo__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveSetAttrEscape -extern __typeof (xmlSaveSetAttrEscape) xmlSaveSetAttrEscape __attribute((alias("xmlSaveSetAttrEscape__internal_alias"))); -#else -#ifndef xmlSaveSetAttrEscape -extern __typeof (xmlSaveSetAttrEscape) xmlSaveSetAttrEscape__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveSetAttrEscape xmlSaveSetAttrEscape__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveSetEscape -extern __typeof (xmlSaveSetEscape) xmlSaveSetEscape __attribute((alias("xmlSaveSetEscape__internal_alias"))); -#else -#ifndef xmlSaveSetEscape -extern __typeof (xmlSaveSetEscape) xmlSaveSetEscape__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveSetEscape xmlSaveSetEscape__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveToBuffer -extern __typeof (xmlSaveToBuffer) xmlSaveToBuffer __attribute((alias("xmlSaveToBuffer__internal_alias"))); -#else -#ifndef xmlSaveToBuffer -extern __typeof (xmlSaveToBuffer) xmlSaveToBuffer__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveToBuffer xmlSaveToBuffer__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveToFd -extern __typeof (xmlSaveToFd) xmlSaveToFd __attribute((alias("xmlSaveToFd__internal_alias"))); -#else -#ifndef xmlSaveToFd -extern __typeof (xmlSaveToFd) xmlSaveToFd__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveToFd xmlSaveToFd__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveToFilename -extern __typeof (xmlSaveToFilename) xmlSaveToFilename __attribute((alias("xmlSaveToFilename__internal_alias"))); -#else -#ifndef xmlSaveToFilename -extern __typeof (xmlSaveToFilename) xmlSaveToFilename__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveToFilename xmlSaveToFilename__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveToIO -extern __typeof (xmlSaveToIO) xmlSaveToIO __attribute((alias("xmlSaveToIO__internal_alias"))); -#else -#ifndef xmlSaveToIO -extern __typeof (xmlSaveToIO) xmlSaveToIO__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveToIO xmlSaveToIO__internal_alias -#endif -#endif -#endif - -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_xmlsave -#undef xmlSaveTree -extern __typeof (xmlSaveTree) xmlSaveTree __attribute((alias("xmlSaveTree__internal_alias"))); -#else -#ifndef xmlSaveTree -extern __typeof (xmlSaveTree) xmlSaveTree__internal_alias __attribute((visibility("hidden"))); -#define xmlSaveTree xmlSaveTree__internal_alias -#endif -#endif -#endif - #ifdef bottom_uri #undef xmlSaveUri extern __typeof (xmlSaveUri) xmlSaveUri __attribute((alias("xmlSaveUri__internal_alias"))); @@ -6666,18 +6042,6 @@ extern __typeof (xmlSplitQName3) xmlSplitQName3__internal_alias __attribute((vis #endif #endif -#if defined(LIBXML_OUTPUT_ENABLED) -#ifdef bottom_valid -#undef xmlSprintfElementContent -extern __typeof (xmlSprintfElementContent) xmlSprintfElementContent __attribute((alias("xmlSprintfElementContent__internal_alias"))); -#else -#ifndef xmlSprintfElementContent -extern __typeof (xmlSprintfElementContent) xmlSprintfElementContent__internal_alias __attribute((visibility("hidden"))); -#define xmlSprintfElementContent xmlSprintfElementContent__internal_alias -#endif -#endif -#endif - #ifdef bottom_parser #undef xmlStopParser extern __typeof (xmlStopParser) xmlStopParser __attribute((alias("xmlStopParser__internal_alias"))); diff --git a/android/native/libxml2/encoding.c b/android/native/libxml2/encoding.c index f3198d5971..35b1dfc8c7 100644 --- a/android/native/libxml2/encoding.c +++ b/android/native/libxml2/encoding.c @@ -145,92 +145,6 @@ asciiToUTF8(unsigned char* out, int *outlen, return(*outlen); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * UTF8Toascii: - * @out: a pointer to an array of bytes to store the result - * @outlen: the length of @out - * @in: a pointer to an array of UTF-8 chars - * @inlen: the length of @in - * - * Take a block of UTF-8 chars in and try to convert it to an ASCII - * block of chars out. - * - * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise - * The value of @inlen after return is the number of octets consumed - * if the return value is positive, else unpredictable. - * The value of @outlen after return is the number of octets consumed. - */ -static int -UTF8Toascii(unsigned char* out, int *outlen, - const unsigned char* in, int *inlen) { - const unsigned char* processed = in; - const unsigned char* outend; - const unsigned char* outstart = out; - const unsigned char* instart = in; - const unsigned char* inend; - unsigned int c, d; - int trailing; - - if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1); - if (in == NULL) { - /* - * initialization nothing to do - */ - *outlen = 0; - *inlen = 0; - return(0); - } - inend = in + (*inlen); - outend = out + (*outlen); - while (in < inend) { - d = *in++; - if (d < 0x80) { c= d; trailing= 0; } - else if (d < 0xC0) { - /* trailing byte in leading position */ - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } - else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } - else if (d < 0xF8) { c= d & 0x07; trailing= 3; } - else { - /* no chance for this in Ascii */ - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } - - if (inend - in < trailing) { - break; - } - - for ( ; trailing; trailing--) { - if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80)) - break; - c <<= 6; - c |= d & 0x3F; - } - - /* assertion: c is a single UTF-4 value */ - if (c < 0x80) { - if (out >= outend) - break; - *out++ = c; - } else { - /* no chance for this in Ascii */ - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } - processed = in; - } - *outlen = out - outstart; - *inlen = processed - instart; - return(*outlen); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * isolat1ToUTF8: * @out: a pointer to an array of bytes to store the result @@ -316,99 +230,6 @@ UTF8ToUTF8(unsigned char* out, int *outlen, return(*outlen); } - -#ifdef LIBXML_OUTPUT_ENABLED -/** - * UTF8Toisolat1: - * @out: a pointer to an array of bytes to store the result - * @outlen: the length of @out - * @in: a pointer to an array of UTF-8 chars - * @inlen: the length of @in - * - * Take a block of UTF-8 chars in and try to convert it to an ISO Latin 1 - * block of chars out. - * - * Returns the number of bytes written if success, -2 if the transcoding fails, - or -1 otherwise - * The value of @inlen after return is the number of octets consumed - * if the return value is positive, else unpredictable. - * The value of @outlen after return is the number of octets consumed. - */ -int -UTF8Toisolat1(unsigned char* out, int *outlen, - const unsigned char* in, int *inlen) { - const unsigned char* processed = in; - const unsigned char* outend; - const unsigned char* outstart = out; - const unsigned char* instart = in; - const unsigned char* inend; - unsigned int c, d; - int trailing; - - if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1); - if (in == NULL) { - /* - * initialization nothing to do - */ - *outlen = 0; - *inlen = 0; - return(0); - } - inend = in + (*inlen); - outend = out + (*outlen); - while (in < inend) { - d = *in++; - if (d < 0x80) { c= d; trailing= 0; } - else if (d < 0xC0) { - /* trailing byte in leading position */ - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } - else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } - else if (d < 0xF8) { c= d & 0x07; trailing= 3; } - else { - /* no chance for this in IsoLat1 */ - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } - - if (inend - in < trailing) { - break; - } - - for ( ; trailing; trailing--) { - if (in >= inend) - break; - if (((d= *in++) & 0xC0) != 0x80) { - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } - c <<= 6; - c |= d & 0x3F; - } - - /* assertion: c is a single UTF-4 value */ - if (c <= 0xFF) { - if (out >= outend) - break; - *out++ = c; - } else { - /* no chance for this in IsoLat1 */ - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } - processed = in; - } - *outlen = out - outstart; - *inlen = processed - instart; - return(*outlen); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * UTF16LEToUTF8: * @out: a pointer to an array of bytes to store the result @@ -497,156 +318,6 @@ UTF16LEToUTF8(unsigned char* out, int *outlen, return(*outlen); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * UTF8ToUTF16LE: - * @outb: a pointer to an array of bytes to store the result - * @outlen: the length of @outb - * @in: a pointer to an array of UTF-8 chars - * @inlen: the length of @in - * - * Take a block of UTF-8 chars in and try to convert it to an UTF-16LE - * block of chars out. - * - * Returns the number of bytes written, or -1 if lack of space, or -2 - * if the transcoding failed. - */ -static int -UTF8ToUTF16LE(unsigned char* outb, int *outlen, - const unsigned char* in, int *inlen) -{ - unsigned short* out = (unsigned short*) outb; - const unsigned char* processed = in; - const unsigned char *const instart = in; - unsigned short* outstart= out; - unsigned short* outend; - const unsigned char* inend; - unsigned int c, d; - int trailing; - unsigned char *tmp; - unsigned short tmp1, tmp2; - - /* UTF16LE encoding has no BOM */ - if ((out == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1); - if (in == NULL) { - *outlen = 0; - *inlen = 0; - return(0); - } - inend= in + *inlen; - outend = out + (*outlen / 2); - while (in < inend) { - d= *in++; - if (d < 0x80) { c= d; trailing= 0; } - else if (d < 0xC0) { - /* trailing byte in leading position */ - *outlen = (out - outstart) * 2; - *inlen = processed - instart; - return(-2); - } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } - else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } - else if (d < 0xF8) { c= d & 0x07; trailing= 3; } - else { - /* no chance for this in UTF-16 */ - *outlen = (out - outstart) * 2; - *inlen = processed - instart; - return(-2); - } - - if (inend - in < trailing) { - break; - } - - for ( ; trailing; trailing--) { - if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80)) - break; - c <<= 6; - c |= d & 0x3F; - } - - /* assertion: c is a single UTF-4 value */ - if (c < 0x10000) { - if (out >= outend) - break; - if (xmlLittleEndian) { - *out++ = c; - } else { - tmp = (unsigned char *) out; - *tmp = c ; - *(tmp + 1) = c >> 8 ; - out++; - } - } - else if (c < 0x110000) { - if (out+1 >= outend) - break; - c -= 0x10000; - if (xmlLittleEndian) { - *out++ = 0xD800 | (c >> 10); - *out++ = 0xDC00 | (c & 0x03FF); - } else { - tmp1 = 0xD800 | (c >> 10); - tmp = (unsigned char *) out; - *tmp = (unsigned char) tmp1; - *(tmp + 1) = tmp1 >> 8; - out++; - - tmp2 = 0xDC00 | (c & 0x03FF); - tmp = (unsigned char *) out; - *tmp = (unsigned char) tmp2; - *(tmp + 1) = tmp2 >> 8; - out++; - } - } - else - break; - processed = in; - } - *outlen = (out - outstart) * 2; - *inlen = processed - instart; - return(*outlen); -} - -/** - * UTF8ToUTF16: - * @outb: a pointer to an array of bytes to store the result - * @outlen: the length of @outb - * @in: a pointer to an array of UTF-8 chars - * @inlen: the length of @in - * - * Take a block of UTF-8 chars in and try to convert it to an UTF-16 - * block of chars out. - * - * Returns the number of bytes written, or -1 if lack of space, or -2 - * if the transcoding failed. - */ -static int -UTF8ToUTF16(unsigned char* outb, int *outlen, - const unsigned char* in, int *inlen) -{ - if (in == NULL) { - /* - * initialization, add the Byte Order Mark for UTF-16LE - */ - if (*outlen >= 2) { - outb[0] = 0xFF; - outb[1] = 0xFE; - *outlen = 2; - *inlen = 0; -#ifdef DEBUG_ENCODING - xmlGenericError(xmlGenericErrorContext, - "Added FFFE Byte Order Mark\n"); -#endif - return(2); - } - *outlen = 0; - *inlen = 0; - return(0); - } - return (UTF8ToUTF16LE(outb, outlen, in, inlen)); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * UTF16BEToUTF8: * @out: a pointer to an array of bytes to store the result @@ -739,114 +410,6 @@ UTF16BEToUTF8(unsigned char* out, int *outlen, return(*outlen); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * UTF8ToUTF16BE: - * @outb: a pointer to an array of bytes to store the result - * @outlen: the length of @outb - * @in: a pointer to an array of UTF-8 chars - * @inlen: the length of @in - * - * Take a block of UTF-8 chars in and try to convert it to an UTF-16BE - * block of chars out. - * - * Returns the number of byte written, or -1 by lack of space, or -2 - * if the transcoding failed. - */ -static int -UTF8ToUTF16BE(unsigned char* outb, int *outlen, - const unsigned char* in, int *inlen) -{ - unsigned short* out = (unsigned short*) outb; - const unsigned char* processed = in; - const unsigned char *const instart = in; - unsigned short* outstart= out; - unsigned short* outend; - const unsigned char* inend; - unsigned int c, d; - int trailing; - unsigned char *tmp; - unsigned short tmp1, tmp2; - - /* UTF-16BE has no BOM */ - if ((outb == NULL) || (outlen == NULL) || (inlen == NULL)) return(-1); - if (in == NULL) { - *outlen = 0; - *inlen = 0; - return(0); - } - inend= in + *inlen; - outend = out + (*outlen / 2); - while (in < inend) { - d= *in++; - if (d < 0x80) { c= d; trailing= 0; } - else if (d < 0xC0) { - /* trailing byte in leading position */ - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; } - else if (d < 0xF0) { c= d & 0x0F; trailing= 2; } - else if (d < 0xF8) { c= d & 0x07; trailing= 3; } - else { - /* no chance for this in UTF-16 */ - *outlen = out - outstart; - *inlen = processed - instart; - return(-2); - } - - if (inend - in < trailing) { - break; - } - - for ( ; trailing; trailing--) { - if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80)) break; - c <<= 6; - c |= d & 0x3F; - } - - /* assertion: c is a single UTF-4 value */ - if (c < 0x10000) { - if (out >= outend) break; - if (xmlLittleEndian) { - tmp = (unsigned char *) out; - *tmp = c >> 8; - *(tmp + 1) = c; - out++; - } else { - *out++ = c; - } - } - else if (c < 0x110000) { - if (out+1 >= outend) break; - c -= 0x10000; - if (xmlLittleEndian) { - tmp1 = 0xD800 | (c >> 10); - tmp = (unsigned char *) out; - *tmp = tmp1 >> 8; - *(tmp + 1) = (unsigned char) tmp1; - out++; - - tmp2 = 0xDC00 | (c & 0x03FF); - tmp = (unsigned char *) out; - *tmp = tmp2 >> 8; - *(tmp + 1) = (unsigned char) tmp2; - out++; - } else { - *out++ = 0xD800 | (c >> 10); - *out++ = 0xDC00 | (c & 0x03FF); - } - } - else - break; - processed = in; - } - *outlen = (out - outstart) * 2; - *inlen = processed - instart; - return(*outlen); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /************************************************************************ * * * Generic encoding handling routines * @@ -1347,16 +910,6 @@ xmlInitCharEncodingHandlers(void) { return; } xmlNewCharEncodingHandler("UTF-8", UTF8ToUTF8, UTF8ToUTF8); -#ifdef LIBXML_OUTPUT_ENABLED - xmlUTF16LEHandler = - xmlNewCharEncodingHandler("UTF-16LE", UTF16LEToUTF8, UTF8ToUTF16LE); - xmlUTF16BEHandler = - xmlNewCharEncodingHandler("UTF-16BE", UTF16BEToUTF8, UTF8ToUTF16BE); - xmlNewCharEncodingHandler("UTF-16", UTF16LEToUTF8, UTF8ToUTF16); - xmlNewCharEncodingHandler("ISO-8859-1", isolat1ToUTF8, UTF8Toisolat1); - xmlNewCharEncodingHandler("ASCII", asciiToUTF8, UTF8Toascii); - xmlNewCharEncodingHandler("US-ASCII", asciiToUTF8, UTF8Toascii); -#else xmlUTF16LEHandler = xmlNewCharEncodingHandler("UTF-16LE", UTF16LEToUTF8, NULL); xmlUTF16BEHandler = @@ -1365,7 +918,6 @@ xmlInitCharEncodingHandlers(void) { xmlNewCharEncodingHandler("ISO-8859-1", isolat1ToUTF8, NULL); xmlNewCharEncodingHandler("ASCII", asciiToUTF8, NULL); xmlNewCharEncodingHandler("US-ASCII", asciiToUTF8, NULL); -#endif /* LIBXML_OUTPUT_ENABLED */ #if !defined(LIBXML_ICONV_ENABLED) #ifdef LIBXML_ISO8859X_ENABLED xmlRegisterCharEncodingHandlersISO8859x (); diff --git a/android/native/libxml2/entities.c b/android/native/libxml2/entities.c index 6aef49f435..a24ea84651 100644 --- a/android/native/libxml2/entities.c +++ b/android/native/libxml2/entities.c @@ -865,158 +865,5 @@ xmlCopyEntitiesTable(xmlEntitiesTablePtr table) { } #endif /* LIBXML_TREE_ENABLED */ -#ifdef LIBXML_OUTPUT_ENABLED - -/** - * xmlDumpEntityContent: - * @buf: An XML buffer. - * @content: The entity content. - * - * This will dump the quoted string value, taking care of the special - * treatment required by % - */ -static void -xmlDumpEntityContent(xmlBufferPtr buf, const xmlChar *content) { - if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; - if (xmlStrchr(content, '%')) { - const xmlChar * base, *cur; - - xmlBufferCCat(buf, "\""); - base = cur = content; - while (*cur != 0) { - if (*cur == '"') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST """, 6); - cur++; - base = cur; - } else if (*cur == '%') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST "%", 6); - cur++; - base = cur; - } else { - cur++; - } - } - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferCCat(buf, "\""); - } else { - xmlBufferWriteQuotedString(buf, content); - } -} - -/** - * xmlDumpEntityDecl: - * @buf: An XML buffer. - * @ent: An entity table - * - * This will dump the content of the entity table as an XML DTD definition - */ -void -xmlDumpEntityDecl(xmlBufferPtr buf, xmlEntityPtr ent) { - if ((buf == NULL) || (ent == NULL)) return; - switch (ent->etype) { - case XML_INTERNAL_GENERAL_ENTITY: - xmlBufferWriteChar(buf, "name); - xmlBufferWriteChar(buf, " "); - if (ent->orig != NULL) - xmlBufferWriteQuotedString(buf, ent->orig); - else - xmlDumpEntityContent(buf, ent->content); - xmlBufferWriteChar(buf, ">\n"); - break; - case XML_EXTERNAL_GENERAL_PARSED_ENTITY: - xmlBufferWriteChar(buf, "name); - if (ent->ExternalID != NULL) { - xmlBufferWriteChar(buf, " PUBLIC "); - xmlBufferWriteQuotedString(buf, ent->ExternalID); - xmlBufferWriteChar(buf, " "); - xmlBufferWriteQuotedString(buf, ent->SystemID); - } else { - xmlBufferWriteChar(buf, " SYSTEM "); - xmlBufferWriteQuotedString(buf, ent->SystemID); - } - xmlBufferWriteChar(buf, ">\n"); - break; - case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: - xmlBufferWriteChar(buf, "name); - if (ent->ExternalID != NULL) { - xmlBufferWriteChar(buf, " PUBLIC "); - xmlBufferWriteQuotedString(buf, ent->ExternalID); - xmlBufferWriteChar(buf, " "); - xmlBufferWriteQuotedString(buf, ent->SystemID); - } else { - xmlBufferWriteChar(buf, " SYSTEM "); - xmlBufferWriteQuotedString(buf, ent->SystemID); - } - if (ent->content != NULL) { /* Should be true ! */ - xmlBufferWriteChar(buf, " NDATA "); - if (ent->orig != NULL) - xmlBufferWriteCHAR(buf, ent->orig); - else - xmlBufferWriteCHAR(buf, ent->content); - } - xmlBufferWriteChar(buf, ">\n"); - break; - case XML_INTERNAL_PARAMETER_ENTITY: - xmlBufferWriteChar(buf, "name); - xmlBufferWriteChar(buf, " "); - if (ent->orig == NULL) - xmlDumpEntityContent(buf, ent->content); - else - xmlBufferWriteQuotedString(buf, ent->orig); - xmlBufferWriteChar(buf, ">\n"); - break; - case XML_EXTERNAL_PARAMETER_ENTITY: - xmlBufferWriteChar(buf, "name); - if (ent->ExternalID != NULL) { - xmlBufferWriteChar(buf, " PUBLIC "); - xmlBufferWriteQuotedString(buf, ent->ExternalID); - xmlBufferWriteChar(buf, " "); - xmlBufferWriteQuotedString(buf, ent->SystemID); - } else { - xmlBufferWriteChar(buf, " SYSTEM "); - xmlBufferWriteQuotedString(buf, ent->SystemID); - } - xmlBufferWriteChar(buf, ">\n"); - break; - default: - xmlEntitiesErr(XML_DTD_UNKNOWN_ENTITY, - "xmlDumpEntitiesDecl: internal: unknown type entity type"); - } -} - -/** - * xmlDumpEntityDeclScan: - * @ent: An entity table - * @buf: An XML buffer. - * - * When using the hash table scan function, arguments need to be reversed - */ -static void -xmlDumpEntityDeclScan(xmlEntityPtr ent, xmlBufferPtr buf) { - xmlDumpEntityDecl(buf, ent); -} - -/** - * xmlDumpEntitiesTable: - * @buf: An XML buffer. - * @table: An entity table - * - * This will dump the content of the entity table as an XML DTD definition - */ -void -xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) { - xmlHashScan(table, (xmlHashScanner)xmlDumpEntityDeclScan, buf); -} -#endif /* LIBXML_OUTPUT_ENABLED */ #define bottom_entities #include "elfgcchack.h" diff --git a/android/native/libxml2/globals.c b/android/native/libxml2/globals.c index 1f70dbc1c2..504fad91f5 100644 --- a/android/native/libxml2/globals.c +++ b/android/native/libxml2/globals.c @@ -550,11 +550,6 @@ xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc fun xmlMutexLock(xmlThrDefMutex); old = xmlOutputBufferCreateFilenameValueThrDef; -#ifdef LIBXML_OUTPUT_ENABLED - if (old == NULL) { - old = __xmlOutputBufferCreateFilename; - } -#endif xmlOutputBufferCreateFilenameValueThrDef = func; xmlMutexUnlock(xmlThrDefMutex); diff --git a/android/native/libxml2/libxml/c14n.h b/android/native/libxml2/libxml/c14n.h index 3011af79eb..6b9c453a44 100644 --- a/android/native/libxml2/libxml/c14n.h +++ b/android/native/libxml2/libxml/c14n.h @@ -17,110 +17,6 @@ #ifndef __XML_C14N_H__ #define __XML_C14N_H__ #ifdef LIBXML_C14N_ENABLED -#ifdef LIBXML_OUTPUT_ENABLED - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#include -#include -#include - -/* - * XML Canonicazation - * http://www.w3.org/TR/xml-c14n - * - * Exclusive XML Canonicazation - * http://www.w3.org/TR/xml-exc-c14n - * - * Canonical form of an XML document could be created if and only if - * a) default attributes (if any) are added to all nodes - * b) all character and parsed entity references are resolved - * In order to achive this in libxml2 the document MUST be loaded with - * following global setings: - * - * xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS; - * xmlSubstituteEntitiesDefault(1); - * - * or corresponding parser context setting: - * xmlParserCtxtPtr ctxt; - * - * ... - * ctxt->loadsubset = XML_DETECT_IDS | XML_COMPLETE_ATTRS; - * ctxt->replaceEntities = 1; - * ... - */ - -/* - * xmlC14NMode: - * - * Predefined values for C14N modes - * - */ -typedef enum { - XML_C14N_1_0 = 0, /* Origianal C14N 1.0 spec */ - XML_C14N_EXCLUSIVE_1_0 = 1, /* Exclusive C14N 1.0 spec */ - XML_C14N_1_1 = 2 /* C14N 1.1 spec */ -} xmlC14NMode; - -XMLPUBFUN int XMLCALL - xmlC14NDocSaveTo (xmlDocPtr doc, - xmlNodeSetPtr nodes, - int mode, /* a xmlC14NMode */ - xmlChar **inclusive_ns_prefixes, - int with_comments, - xmlOutputBufferPtr buf); - -XMLPUBFUN int XMLCALL - xmlC14NDocDumpMemory (xmlDocPtr doc, - xmlNodeSetPtr nodes, - int mode, /* a xmlC14NMode */ - xmlChar **inclusive_ns_prefixes, - int with_comments, - xmlChar **doc_txt_ptr); - -XMLPUBFUN int XMLCALL - xmlC14NDocSave (xmlDocPtr doc, - xmlNodeSetPtr nodes, - int mode, /* a xmlC14NMode */ - xmlChar **inclusive_ns_prefixes, - int with_comments, - const char* filename, - int compression); - - -/** - * This is the core C14N function - */ -/** - * xmlC14NIsVisibleCallback: - * @user_data: user data - * @node: the curent node - * @parent: the parent node - * - * Signature for a C14N callback on visible nodes - * - * Returns 1 if the node should be included - */ -typedef int (*xmlC14NIsVisibleCallback) (void* user_data, - xmlNodePtr node, - xmlNodePtr parent); - -XMLPUBFUN int XMLCALL - xmlC14NExecute (xmlDocPtr doc, - xmlC14NIsVisibleCallback is_visible_callback, - void* user_data, - int mode, /* a xmlC14NMode */ - xmlChar **inclusive_ns_prefixes, - int with_comments, - xmlOutputBufferPtr buf); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* LIBXML_OUTPUT_ENABLED */ #endif /* LIBXML_C14N_ENABLED */ #endif /* __XML_C14N_H__ */ diff --git a/android/native/libxml2/libxml/encoding.h b/android/native/libxml2/libxml/encoding.h index c74b25f3cb..c962a6a376 100644 --- a/android/native/libxml2/libxml/encoding.h +++ b/android/native/libxml2/libxml/encoding.h @@ -207,13 +207,6 @@ XMLPUBFUN int XMLCALL /* * Export a few useful functions */ -#ifdef LIBXML_OUTPUT_ENABLED -XMLPUBFUN int XMLCALL - UTF8Toisolat1 (unsigned char *out, - int *outlen, - const unsigned char *in, - int *inlen); -#endif /* LIBXML_OUTPUT_ENABLED */ XMLPUBFUN int XMLCALL isolat1ToUTF8 (unsigned char *out, int *outlen, diff --git a/android/native/libxml2/libxml/entities.h b/android/native/libxml2/libxml/entities.h index bbe5874258..e59ff7ae7d 100644 --- a/android/native/libxml2/libxml/entities.h +++ b/android/native/libxml2/libxml/entities.h @@ -120,14 +120,6 @@ XMLPUBFUN xmlEntitiesTablePtr XMLCALL #endif /* LIBXML_TREE_ENABLED */ XMLPUBFUN void XMLCALL xmlFreeEntitiesTable (xmlEntitiesTablePtr table); -#ifdef LIBXML_OUTPUT_ENABLED -XMLPUBFUN void XMLCALL - xmlDumpEntitiesTable (xmlBufferPtr buf, - xmlEntitiesTablePtr table); -XMLPUBFUN void XMLCALL - xmlDumpEntityDecl (xmlBufferPtr buf, - xmlEntityPtr ent); -#endif /* LIBXML_OUTPUT_ENABLED */ #ifdef __cplusplus diff --git a/android/native/libxml2/libxml/tree.h b/android/native/libxml2/libxml/tree.h index f60e0285ab..61157aaa6e 100644 --- a/android/native/libxml2/libxml/tree.h +++ b/android/native/libxml2/libxml/tree.h @@ -1067,12 +1067,6 @@ XMLPUBFUN void XMLCALL xmlBufferWriteQuotedString(xmlBufferPtr buf, const xmlChar *string); -#ifdef LIBXML_OUTPUT_ENABLED -XMLPUBFUN void xmlAttrSerializeTxtContent(xmlBufferPtr buf, - xmlDocPtr doc, - xmlAttrPtr attr, - const xmlChar *string); -#endif /* LIBXML_OUTPUT_ENABLED */ #ifdef LIBXML_TREE_ENABLED /* @@ -1083,84 +1077,6 @@ XMLPUBFUN int XMLCALL xmlNodePtr tree); #endif -#ifdef LIBXML_OUTPUT_ENABLED -/* - * Saving. - */ -XMLPUBFUN void XMLCALL - xmlDocDumpFormatMemory (xmlDocPtr cur, - xmlChar **mem, - int *size, - int format); -XMLPUBFUN void XMLCALL - xmlDocDumpMemory (xmlDocPtr cur, - xmlChar **mem, - int *size); -XMLPUBFUN void XMLCALL - xmlDocDumpMemoryEnc (xmlDocPtr out_doc, - xmlChar **doc_txt_ptr, - int * doc_txt_len, - const char *txt_encoding); -XMLPUBFUN void XMLCALL - xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, - xmlChar **doc_txt_ptr, - int * doc_txt_len, - const char *txt_encoding, - int format); -XMLPUBFUN int XMLCALL - xmlDocFormatDump (FILE *f, - xmlDocPtr cur, - int format); -XMLPUBFUN int XMLCALL - xmlDocDump (FILE *f, - xmlDocPtr cur); -XMLPUBFUN void XMLCALL - xmlElemDump (FILE *f, - xmlDocPtr doc, - xmlNodePtr cur); -XMLPUBFUN int XMLCALL - xmlSaveFile (const char *filename, - xmlDocPtr cur); -XMLPUBFUN int XMLCALL - xmlSaveFormatFile (const char *filename, - xmlDocPtr cur, - int format); -XMLPUBFUN int XMLCALL - xmlNodeDump (xmlBufferPtr buf, - xmlDocPtr doc, - xmlNodePtr cur, - int level, - int format); - -XMLPUBFUN int XMLCALL - xmlSaveFileTo (xmlOutputBufferPtr buf, - xmlDocPtr cur, - const char *encoding); -XMLPUBFUN int XMLCALL - xmlSaveFormatFileTo (xmlOutputBufferPtr buf, - xmlDocPtr cur, - const char *encoding, - int format); -XMLPUBFUN void XMLCALL - xmlNodeDumpOutput (xmlOutputBufferPtr buf, - xmlDocPtr doc, - xmlNodePtr cur, - int level, - int format, - const char *encoding); - -XMLPUBFUN int XMLCALL - xmlSaveFormatFileEnc (const char *filename, - xmlDocPtr cur, - const char *encoding, - int format); - -XMLPUBFUN int XMLCALL - xmlSaveFileEnc (const char *filename, - xmlDocPtr cur, - const char *encoding); - -#endif /* LIBXML_OUTPUT_ENABLED */ /* * XHTML */ diff --git a/android/native/libxml2/libxml/valid.h b/android/native/libxml2/libxml/valid.h index a778fa9f91..a25b2a6170 100644 --- a/android/native/libxml2/libxml/valid.h +++ b/android/native/libxml2/libxml/valid.h @@ -162,14 +162,6 @@ XMLPUBFUN xmlNotationTablePtr XMLCALL #endif /* LIBXML_TREE_ENABLED */ XMLPUBFUN void XMLCALL xmlFreeNotationTable (xmlNotationTablePtr table); -#ifdef LIBXML_OUTPUT_ENABLED -XMLPUBFUN void XMLCALL - xmlDumpNotationDecl (xmlBufferPtr buf, - xmlNotationPtr nota); -XMLPUBFUN void XMLCALL - xmlDumpNotationTable (xmlBufferPtr buf, - xmlNotationTablePtr table); -#endif /* LIBXML_OUTPUT_ENABLED */ /* Element Content */ /* the non Doc version are being deprecated */ @@ -196,13 +188,6 @@ XMLPUBFUN void XMLCALL int size, xmlElementContentPtr content, int englob); -#ifdef LIBXML_OUTPUT_ENABLED -/* DEPRECATED */ -XMLPUBFUN void XMLCALL - xmlSprintfElementContent(char *buf, - xmlElementContentPtr content, - int englob); -#endif /* LIBXML_OUTPUT_ENABLED */ /* DEPRECATED */ /* Element */ @@ -218,14 +203,6 @@ XMLPUBFUN xmlElementTablePtr XMLCALL #endif /* LIBXML_TREE_ENABLED */ XMLPUBFUN void XMLCALL xmlFreeElementTable (xmlElementTablePtr table); -#ifdef LIBXML_OUTPUT_ENABLED -XMLPUBFUN void XMLCALL - xmlDumpElementTable (xmlBufferPtr buf, - xmlElementTablePtr table); -XMLPUBFUN void XMLCALL - xmlDumpElementDecl (xmlBufferPtr buf, - xmlElementPtr elem); -#endif /* LIBXML_OUTPUT_ENABLED */ /* Enumeration */ XMLPUBFUN xmlEnumerationPtr XMLCALL @@ -254,14 +231,6 @@ XMLPUBFUN xmlAttributeTablePtr XMLCALL #endif /* LIBXML_TREE_ENABLED */ XMLPUBFUN void XMLCALL xmlFreeAttributeTable (xmlAttributeTablePtr table); -#ifdef LIBXML_OUTPUT_ENABLED -XMLPUBFUN void XMLCALL - xmlDumpAttributeTable (xmlBufferPtr buf, - xmlAttributeTablePtr table); -XMLPUBFUN void XMLCALL - xmlDumpAttributeDecl (xmlBufferPtr buf, - xmlAttributePtr attr); -#endif /* LIBXML_OUTPUT_ENABLED */ /* IDs */ XMLPUBFUN xmlIDPtr XMLCALL diff --git a/android/native/libxml2/libxml/xmlIO.h b/android/native/libxml2/libxml/xmlIO.h index fa6dcf2ca9..3f0efc61dd 100644 --- a/android/native/libxml2/libxml/xmlIO.h +++ b/android/native/libxml2/libxml/xmlIO.h @@ -62,53 +62,6 @@ typedef int (XMLCALL *xmlInputReadCallback) (void * context, char * buffer, int */ typedef int (XMLCALL *xmlInputCloseCallback) (void * context); -#ifdef LIBXML_OUTPUT_ENABLED -/* - * Those are the functions and datatypes for the library output - * I/O structures. - */ - -/** - * xmlOutputMatchCallback: - * @filename: the filename or URI - * - * Callback used in the I/O Output API to detect if the current handler - * can provide output fonctionnalities for this resource. - * - * Returns 1 if yes and 0 if another Output module should be used - */ -typedef int (XMLCALL *xmlOutputMatchCallback) (char const *filename); -/** - * xmlOutputOpenCallback: - * @filename: the filename or URI - * - * Callback used in the I/O Output API to open the resource - * - * Returns an Output context or NULL in case or error - */ -typedef void * (XMLCALL *xmlOutputOpenCallback) (char const *filename); -/** - * xmlOutputWriteCallback: - * @context: an Output context - * @buffer: the buffer of data to write - * @len: the length of the buffer in bytes - * - * Callback used in the I/O Output API to write to the resource - * - * Returns the number of bytes written or -1 in case of error - */ -typedef int (XMLCALL *xmlOutputWriteCallback) (void * context, const char * buffer, - int len); -/** - * xmlOutputCloseCallback: - * @context: an Output context - * - * Callback used in the I/O Output API to close the resource - * - * Returns 0 or -1 in case of error - */ -typedef int (XMLCALL *xmlOutputCloseCallback) (void * context); -#endif /* LIBXML_OUTPUT_ENABLED */ #ifdef __cplusplus } @@ -137,21 +90,6 @@ struct _xmlParserInputBuffer { }; -#ifdef LIBXML_OUTPUT_ENABLED -struct _xmlOutputBuffer { - void* context; - xmlOutputWriteCallback writecallback; - xmlOutputCloseCallback closecallback; - - xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */ - - xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */ - xmlBufferPtr conv; /* if encoder != NULL buffer for output */ - int written; /* total number of byte written */ - int error; -}; -#endif /* LIBXML_OUTPUT_ENABLED */ - /* * Interfaces for input */ @@ -211,70 +149,6 @@ xmlParserInputBufferPtr __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc); -#ifdef LIBXML_OUTPUT_ENABLED -/* - * Interfaces for output - */ -XMLPUBFUN void XMLCALL - xmlCleanupOutputCallbacks (void); -XMLPUBFUN void XMLCALL - xmlRegisterDefaultOutputCallbacks(void); -XMLPUBFUN xmlOutputBufferPtr XMLCALL - xmlAllocOutputBuffer (xmlCharEncodingHandlerPtr encoder); - -XMLPUBFUN xmlOutputBufferPtr XMLCALL - xmlOutputBufferCreateFilename (const char *URI, - xmlCharEncodingHandlerPtr encoder, - int compression); - -XMLPUBFUN xmlOutputBufferPtr XMLCALL - xmlOutputBufferCreateFile (FILE *file, - xmlCharEncodingHandlerPtr encoder); - -XMLPUBFUN xmlOutputBufferPtr XMLCALL - xmlOutputBufferCreateBuffer (xmlBufferPtr buffer, - xmlCharEncodingHandlerPtr encoder); - -XMLPUBFUN xmlOutputBufferPtr XMLCALL - xmlOutputBufferCreateFd (int fd, - xmlCharEncodingHandlerPtr encoder); - -XMLPUBFUN xmlOutputBufferPtr XMLCALL - xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite, - xmlOutputCloseCallback ioclose, - void *ioctx, - xmlCharEncodingHandlerPtr encoder); - -XMLPUBFUN int XMLCALL - xmlOutputBufferWrite (xmlOutputBufferPtr out, - int len, - const char *buf); -XMLPUBFUN int XMLCALL - xmlOutputBufferWriteString (xmlOutputBufferPtr out, - const char *str); -XMLPUBFUN int XMLCALL - xmlOutputBufferWriteEscape (xmlOutputBufferPtr out, - const xmlChar *str, - xmlCharEncodingOutputFunc escaping); - -XMLPUBFUN int XMLCALL - xmlOutputBufferFlush (xmlOutputBufferPtr out); -XMLPUBFUN int XMLCALL - xmlOutputBufferClose (xmlOutputBufferPtr out); - -XMLPUBFUN int XMLCALL - xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc, - xmlOutputOpenCallback openFunc, - xmlOutputWriteCallback writeFunc, - xmlOutputCloseCallback closeFunc); - -xmlOutputBufferPtr - __xmlOutputBufferCreateFilename(const char *URI, - xmlCharEncodingHandlerPtr encoder, - int compression); - -#endif /* LIBXML_OUTPUT_ENABLED */ - XMLPUBFUN xmlParserInputPtr XMLCALL xmlCheckHTTPInput (xmlParserCtxtPtr ctxt, xmlParserInputPtr ret); diff --git a/android/native/libxml2/libxml/xmlsave.h b/android/native/libxml2/libxml/xmlsave.h index fb329b22db..e72cb7bcb8 100644 --- a/android/native/libxml2/libxml/xmlsave.h +++ b/android/native/libxml2/libxml/xmlsave.h @@ -15,74 +15,6 @@ #include #include -#ifdef LIBXML_OUTPUT_ENABLED -#ifdef __cplusplus -extern "C" { -#endif - -/** - * xmlSaveOption: - * - * This is the set of XML save options that can be passed down - * to the xmlSaveToFd() and similar calls. - */ -typedef enum { - XML_SAVE_FORMAT = 1<<0, /* format save output */ - XML_SAVE_NO_DECL = 1<<1, /* drop the xml declaration */ - XML_SAVE_NO_EMPTY = 1<<2, /* no empty tags */ - XML_SAVE_NO_XHTML = 1<<3, /* disable XHTML1 specific rules */ - XML_SAVE_XHTML = 1<<4, /* force XHTML1 specific rules */ - XML_SAVE_AS_XML = 1<<5, /* force XML serialization on HTML doc */ - XML_SAVE_AS_HTML = 1<<6, /* force HTML serialization on XML doc */ - XML_SAVE_WSNONSIG = 1<<7 /* format with non-significant whitespace */ -} xmlSaveOption; - - -typedef struct _xmlSaveCtxt xmlSaveCtxt; -typedef xmlSaveCtxt *xmlSaveCtxtPtr; - -XMLPUBFUN xmlSaveCtxtPtr XMLCALL - xmlSaveToFd (int fd, - const char *encoding, - int options); -XMLPUBFUN xmlSaveCtxtPtr XMLCALL - xmlSaveToFilename (const char *filename, - const char *encoding, - int options); - -XMLPUBFUN xmlSaveCtxtPtr XMLCALL - xmlSaveToBuffer (xmlBufferPtr buffer, - const char *encoding, - int options); - -XMLPUBFUN xmlSaveCtxtPtr XMLCALL - xmlSaveToIO (xmlOutputWriteCallback iowrite, - xmlOutputCloseCallback ioclose, - void *ioctx, - const char *encoding, - int options); - -XMLPUBFUN long XMLCALL - xmlSaveDoc (xmlSaveCtxtPtr ctxt, - xmlDocPtr doc); -XMLPUBFUN long XMLCALL - xmlSaveTree (xmlSaveCtxtPtr ctxt, - xmlNodePtr node); - -XMLPUBFUN int XMLCALL - xmlSaveFlush (xmlSaveCtxtPtr ctxt); -XMLPUBFUN int XMLCALL - xmlSaveClose (xmlSaveCtxtPtr ctxt); -XMLPUBFUN int XMLCALL - xmlSaveSetEscape (xmlSaveCtxtPtr ctxt, - xmlCharEncodingOutputFunc escape); -XMLPUBFUN int XMLCALL - xmlSaveSetAttrEscape (xmlSaveCtxtPtr ctxt, - xmlCharEncodingOutputFunc escape); -#ifdef __cplusplus -} -#endif -#endif /* LIBXML_OUTPUT_ENABLED */ #endif /* __XML_XMLSAVE_H__ */ diff --git a/android/native/libxml2/libxml/xmlversion.h b/android/native/libxml2/libxml/xmlversion.h index b8003a8f5e..37f1e5e2b1 100644 --- a/android/native/libxml2/libxml/xmlversion.h +++ b/android/native/libxml2/libxml/xmlversion.h @@ -94,15 +94,6 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version); #define LIBXML_TREE_ENABLED #endif -/** - * LIBXML_OUTPUT_ENABLED: - * - * Whether the serialization/saving support is configured in - */ -#if 1 -#define LIBXML_OUTPUT_ENABLED -#endif - /** * LIBXML_PUSH_ENABLED: * diff --git a/android/native/libxml2/parser.c b/android/native/libxml2/parser.c index 8aaeade425..b0d47bc272 100644 --- a/android/native/libxml2/parser.c +++ b/android/native/libxml2/parser.c @@ -769,11 +769,7 @@ xmlHasFeature(xmlFeature feature) return(0); #endif case XML_WITH_OUTPUT: -#ifdef LIBXML_OUTPUT_ENABLED - return(1); -#else return(0); -#endif case XML_WITH_PUSH: #ifdef LIBXML_PUSH_ENABLED return(1); @@ -12819,9 +12815,6 @@ xmlInitParser(void) { xmlInitCharEncodingHandlers(); xmlDefaultSAXHandlerInit(); xmlRegisterDefaultInputCallbacks(); -#ifdef LIBXML_OUTPUT_ENABLED - xmlRegisterDefaultOutputCallbacks(); -#endif /* LIBXML_OUTPUT_ENABLED */ xmlParserInitialized = 1; } @@ -12855,9 +12848,6 @@ xmlCleanupParser(void) { xmlCleanupCharEncodingHandlers(); xmlDictCleanup(); xmlCleanupInputCallbacks(); -#ifdef LIBXML_OUTPUT_ENABLED - xmlCleanupOutputCallbacks(); -#endif xmlCleanupGlobals(); xmlResetLastError(); xmlCleanupThreads(); /* must be last if called not from the main thread */ diff --git a/android/native/libxml2/valid.c b/android/native/libxml2/valid.c index 888d4a8d73..9c29ddc3dc 100644 --- a/android/native/libxml2/valid.c +++ b/android/native/libxml2/valid.c @@ -1141,96 +1141,6 @@ xmlFreeElementContent(xmlElementContentPtr cur) { xmlFreeDocElementContent(NULL, cur); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlDumpElementContent: - * @buf: An XML buffer - * @content: An element table - * @glob: 1 if one must print the englobing parenthesis, 0 otherwise - * - * This will dump the content of the element table as an XML DTD definition - */ -static void -xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob) { - if (content == NULL) return; - - if (glob) xmlBufferWriteChar(buf, "("); - switch (content->type) { - case XML_ELEMENT_CONTENT_PCDATA: - xmlBufferWriteChar(buf, "#PCDATA"); - break; - case XML_ELEMENT_CONTENT_ELEMENT: - if (content->prefix != NULL) { - xmlBufferWriteCHAR(buf, content->prefix); - xmlBufferWriteChar(buf, ":"); - } - xmlBufferWriteCHAR(buf, content->name); - break; - case XML_ELEMENT_CONTENT_SEQ: - if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || - (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) - xmlDumpElementContent(buf, content->c1, 1); - else - xmlDumpElementContent(buf, content->c1, 0); - xmlBufferWriteChar(buf, " , "); - if ((content->c2->type == XML_ELEMENT_CONTENT_OR) || - ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) && - (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))) - xmlDumpElementContent(buf, content->c2, 1); - else - xmlDumpElementContent(buf, content->c2, 0); - break; - case XML_ELEMENT_CONTENT_OR: - if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || - (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) - xmlDumpElementContent(buf, content->c1, 1); - else - xmlDumpElementContent(buf, content->c1, 0); - xmlBufferWriteChar(buf, " | "); - if ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) || - ((content->c2->type == XML_ELEMENT_CONTENT_OR) && - (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))) - xmlDumpElementContent(buf, content->c2, 1); - else - xmlDumpElementContent(buf, content->c2, 0); - break; - default: - xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, - "Internal: ELEMENT content corrupted invalid type\n", - NULL); - } - if (glob) - xmlBufferWriteChar(buf, ")"); - switch (content->ocur) { - case XML_ELEMENT_CONTENT_ONCE: - break; - case XML_ELEMENT_CONTENT_OPT: - xmlBufferWriteChar(buf, "?"); - break; - case XML_ELEMENT_CONTENT_MULT: - xmlBufferWriteChar(buf, "*"); - break; - case XML_ELEMENT_CONTENT_PLUS: - xmlBufferWriteChar(buf, "+"); - break; - } -} - -/** - * xmlSprintfElementContent: - * @buf: an output buffer - * @content: An element table - * @englob: 1 if one must print the englobing parenthesis, 0 otherwise - * - * Deprecated, unsafe, use xmlSnprintfElementContent - */ -void -xmlSprintfElementContent(char *buf ATTRIBUTE_UNUSED, - xmlElementContentPtr content ATTRIBUTE_UNUSED, - int englob ATTRIBUTE_UNUSED) { -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlSnprintfElementContent: * @buf: an output buffer @@ -1647,95 +1557,6 @@ xmlCopyElementTable(xmlElementTablePtr table) { } #endif /* LIBXML_TREE_ENABLED */ -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlDumpElementDecl: - * @buf: the XML buffer output - * @elem: An element table - * - * This will dump the content of the element declaration as an XML - * DTD definition - */ -void -xmlDumpElementDecl(xmlBufferPtr buf, xmlElementPtr elem) { - if ((buf == NULL) || (elem == NULL)) - return; - switch (elem->etype) { - case XML_ELEMENT_TYPE_EMPTY: - xmlBufferWriteChar(buf, "prefix != NULL) { - xmlBufferWriteCHAR(buf, elem->prefix); - xmlBufferWriteChar(buf, ":"); - } - xmlBufferWriteCHAR(buf, elem->name); - xmlBufferWriteChar(buf, " EMPTY>\n"); - break; - case XML_ELEMENT_TYPE_ANY: - xmlBufferWriteChar(buf, "prefix != NULL) { - xmlBufferWriteCHAR(buf, elem->prefix); - xmlBufferWriteChar(buf, ":"); - } - xmlBufferWriteCHAR(buf, elem->name); - xmlBufferWriteChar(buf, " ANY>\n"); - break; - case XML_ELEMENT_TYPE_MIXED: - xmlBufferWriteChar(buf, "prefix != NULL) { - xmlBufferWriteCHAR(buf, elem->prefix); - xmlBufferWriteChar(buf, ":"); - } - xmlBufferWriteCHAR(buf, elem->name); - xmlBufferWriteChar(buf, " "); - xmlDumpElementContent(buf, elem->content, 1); - xmlBufferWriteChar(buf, ">\n"); - break; - case XML_ELEMENT_TYPE_ELEMENT: - xmlBufferWriteChar(buf, "prefix != NULL) { - xmlBufferWriteCHAR(buf, elem->prefix); - xmlBufferWriteChar(buf, ":"); - } - xmlBufferWriteCHAR(buf, elem->name); - xmlBufferWriteChar(buf, " "); - xmlDumpElementContent(buf, elem->content, 1); - xmlBufferWriteChar(buf, ">\n"); - break; - default: - xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, - "Internal: ELEMENT struct corrupted invalid type\n", - NULL); - } -} - -/** - * xmlDumpElementDeclScan: - * @elem: An element table - * @buf: the XML buffer output - * - * This routine is used by the hash scan function. It just reverses - * the arguments. - */ -static void -xmlDumpElementDeclScan(xmlElementPtr elem, xmlBufferPtr buf) { - xmlDumpElementDecl(buf, elem); -} - -/** - * xmlDumpElementTable: - * @buf: the XML buffer output - * @table: An element table - * - * This will dump the content of the element table as an XML DTD definition - */ -void -xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table) { - if ((buf == NULL) || (table == NULL)) - return; - xmlHashScan(table, (xmlHashScanner) xmlDumpElementDeclScan, buf); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlCreateEnumeration: * @name: the enumeration name or NULL @@ -1801,29 +1622,6 @@ xmlCopyEnumeration(xmlEnumerationPtr cur) { } #endif /* LIBXML_TREE_ENABLED */ -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlDumpEnumeration: - * @buf: the XML buffer output - * @enum: An enumeration - * - * This will dump the content of the enumeration - */ -static void -xmlDumpEnumeration(xmlBufferPtr buf, xmlEnumerationPtr cur) { - if ((buf == NULL) || (cur == NULL)) - return; - - xmlBufferWriteCHAR(buf, cur->name); - if (cur->next == NULL) - xmlBufferWriteChar(buf, ")"); - else { - xmlBufferWriteChar(buf, " | "); - xmlDumpEnumeration(buf, cur->next); - } -} -#endif /* LIBXML_OUTPUT_ENABLED */ - #ifdef LIBXML_VALID_ENABLED /** * xmlScanIDAttributeDecl: @@ -2191,116 +1989,6 @@ xmlCopyAttributeTable(xmlAttributeTablePtr table) { } #endif /* LIBXML_TREE_ENABLED */ -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlDumpAttributeDecl: - * @buf: the XML buffer output - * @attr: An attribute declaration - * - * This will dump the content of the attribute declaration as an XML - * DTD definition - */ -void -xmlDumpAttributeDecl(xmlBufferPtr buf, xmlAttributePtr attr) { - if ((buf == NULL) || (attr == NULL)) - return; - xmlBufferWriteChar(buf, "elem); - xmlBufferWriteChar(buf, " "); - if (attr->prefix != NULL) { - xmlBufferWriteCHAR(buf, attr->prefix); - xmlBufferWriteChar(buf, ":"); - } - xmlBufferWriteCHAR(buf, attr->name); - switch (attr->atype) { - case XML_ATTRIBUTE_CDATA: - xmlBufferWriteChar(buf, " CDATA"); - break; - case XML_ATTRIBUTE_ID: - xmlBufferWriteChar(buf, " ID"); - break; - case XML_ATTRIBUTE_IDREF: - xmlBufferWriteChar(buf, " IDREF"); - break; - case XML_ATTRIBUTE_IDREFS: - xmlBufferWriteChar(buf, " IDREFS"); - break; - case XML_ATTRIBUTE_ENTITY: - xmlBufferWriteChar(buf, " ENTITY"); - break; - case XML_ATTRIBUTE_ENTITIES: - xmlBufferWriteChar(buf, " ENTITIES"); - break; - case XML_ATTRIBUTE_NMTOKEN: - xmlBufferWriteChar(buf, " NMTOKEN"); - break; - case XML_ATTRIBUTE_NMTOKENS: - xmlBufferWriteChar(buf, " NMTOKENS"); - break; - case XML_ATTRIBUTE_ENUMERATION: - xmlBufferWriteChar(buf, " ("); - xmlDumpEnumeration(buf, attr->tree); - break; - case XML_ATTRIBUTE_NOTATION: - xmlBufferWriteChar(buf, " NOTATION ("); - xmlDumpEnumeration(buf, attr->tree); - break; - default: - xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, - "Internal: ATTRIBUTE struct corrupted invalid type\n", - NULL); - } - switch (attr->def) { - case XML_ATTRIBUTE_NONE: - break; - case XML_ATTRIBUTE_REQUIRED: - xmlBufferWriteChar(buf, " #REQUIRED"); - break; - case XML_ATTRIBUTE_IMPLIED: - xmlBufferWriteChar(buf, " #IMPLIED"); - break; - case XML_ATTRIBUTE_FIXED: - xmlBufferWriteChar(buf, " #FIXED"); - break; - default: - xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, - "Internal: ATTRIBUTE struct corrupted invalid def\n", - NULL); - } - if (attr->defaultValue != NULL) { - xmlBufferWriteChar(buf, " "); - xmlBufferWriteQuotedString(buf, attr->defaultValue); - } - xmlBufferWriteChar(buf, ">\n"); -} - -/** - * xmlDumpAttributeDeclScan: - * @attr: An attribute declaration - * @buf: the XML buffer output - * - * This is used with the hash scan function - just reverses arguments - */ -static void -xmlDumpAttributeDeclScan(xmlAttributePtr attr, xmlBufferPtr buf) { - xmlDumpAttributeDecl(buf, attr); -} - -/** - * xmlDumpAttributeTable: - * @buf: the XML buffer output - * @table: An attribute table - * - * This will dump the content of the attribute table as an XML DTD definition - */ -void -xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) { - if ((buf == NULL) || (table == NULL)) - return; - xmlHashScan(table, (xmlHashScanner) xmlDumpAttributeDeclScan, buf); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /************************************************************************ * * * NOTATIONs * @@ -2462,61 +2150,6 @@ xmlCopyNotationTable(xmlNotationTablePtr table) { } #endif /* LIBXML_TREE_ENABLED */ -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlDumpNotationDecl: - * @buf: the XML buffer output - * @nota: A notation declaration - * - * This will dump the content the notation declaration as an XML DTD definition - */ -void -xmlDumpNotationDecl(xmlBufferPtr buf, xmlNotationPtr nota) { - if ((buf == NULL) || (nota == NULL)) - return; - xmlBufferWriteChar(buf, "name); - if (nota->PublicID != NULL) { - xmlBufferWriteChar(buf, " PUBLIC "); - xmlBufferWriteQuotedString(buf, nota->PublicID); - if (nota->SystemID != NULL) { - xmlBufferWriteChar(buf, " "); - xmlBufferWriteQuotedString(buf, nota->SystemID); - } - } else { - xmlBufferWriteChar(buf, " SYSTEM "); - xmlBufferWriteQuotedString(buf, nota->SystemID); - } - xmlBufferWriteChar(buf, " >\n"); -} - -/** - * xmlDumpNotationDeclScan: - * @nota: A notation declaration - * @buf: the XML buffer output - * - * This is called with the hash scan function, and just reverses args - */ -static void -xmlDumpNotationDeclScan(xmlNotationPtr nota, xmlBufferPtr buf) { - xmlDumpNotationDecl(buf, nota); -} - -/** - * xmlDumpNotationTable: - * @buf: the XML buffer output - * @table: A notation table - * - * This will dump the content of the notation table as an XML DTD definition - */ -void -xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) { - if ((buf == NULL) || (table == NULL)) - return; - xmlHashScan(table, (xmlHashScanner) xmlDumpNotationDeclScan, buf); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /************************************************************************ * * * IDs * diff --git a/android/native/libxml2/xmlIO.c b/android/native/libxml2/xmlIO.c index 4860385253..1cbb2d09ab 100644 --- a/android/native/libxml2/xmlIO.c +++ b/android/native/libxml2/xmlIO.c @@ -118,27 +118,6 @@ static xmlInputCallback xmlInputCallbackTable[MAX_INPUT_CALLBACK]; static int xmlInputCallbackNr = 0; static int xmlInputCallbackInitialized = 0; -#ifdef LIBXML_OUTPUT_ENABLED -/* - * Output I/O callback sets - */ -typedef struct _xmlOutputCallback { - xmlOutputMatchCallback matchcallback; - xmlOutputOpenCallback opencallback; - xmlOutputWriteCallback writecallback; - xmlOutputCloseCallback closecallback; -} xmlOutputCallback; - -#define MAX_OUTPUT_CALLBACK 15 - -static xmlOutputCallback xmlOutputCallbackTable[MAX_OUTPUT_CALLBACK]; -static int xmlOutputCallbackNr = 0; -static int xmlOutputCallbackInitialized = 0; - -xmlOutputBufferPtr -xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder); -#endif /* LIBXML_OUTPUT_ENABLED */ - /************************************************************************ * * * Tree memory error handler * @@ -550,33 +529,6 @@ xmlPopInputCallbacks(void) return(xmlInputCallbackNr); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlCleanupOutputCallbacks: - * - * clears the entire output callback table. this includes the - * compiled-in I/O callbacks. - */ -void -xmlCleanupOutputCallbacks(void) -{ - int i; - - if (!xmlOutputCallbackInitialized) - return; - - for (i = xmlOutputCallbackNr - 1; i >= 0; i--) { - xmlOutputCallbackTable[i].matchcallback = NULL; - xmlOutputCallbackTable[i].opencallback = NULL; - xmlOutputCallbackTable[i].writecallback = NULL; - xmlOutputCallbackTable[i].closecallback = NULL; - } - - xmlOutputCallbackNr = 0; - xmlOutputCallbackInitialized = 0; -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /************************************************************************ * * * Standard I/O for file accesses * @@ -809,29 +761,6 @@ xmlFdRead (void * context, char * buffer, int len) { return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlFdWrite: - * @context: the I/O context - * @buffer: where to get data - * @len: number of bytes to write - * - * Write @len bytes from @buffer to the I/O channel. - * - * Returns the number of bytes written - */ -static int -xmlFdWrite (void * context, const char * buffer, int len) { - int ret = 0; - - if (len > 0) { - ret = write((int) (long) context, &buffer[0], len); - if (ret < 0) xmlIOErr(0, "write()"); - } - return(ret); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlFdClose: * @context: the I/O context @@ -945,55 +874,6 @@ xmlFileOpen (const char *filename) { return retval; } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlFileOpenW: - * @filename: the URI for matching - * - * output to from FILE *, - * if @filename is "-" then the standard output is used - * - * Returns an I/O context or NULL in case of error - */ -static void * -xmlFileOpenW (const char *filename) { - const char *path = NULL; - FILE *fd; - - if (!strcmp(filename, "-")) { - fd = stdout; - return((void *) fd); - } - - if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) -#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) - path = &filename[17]; -#else - path = &filename[16]; -#endif - else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { -#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) - path = &filename[8]; -#else - path = &filename[7]; -#endif - } else - path = filename; - - if (path == NULL) - return(NULL); - -#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) - fd = xmlWrapOpen(path, 1); -#else - fd = fopen(path, "wb"); -#endif /* WIN32 */ - - if (fd == NULL) xmlIOErr(0, path); - return((void *) fd); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlFileRead: * @context: the I/O context @@ -1014,32 +894,6 @@ xmlFileRead (void * context, char * buffer, int len) { return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlFileWrite: - * @context: the I/O context - * @buffer: where to drop data - * @len: number of bytes to write - * - * Write @len bytes from @buffer to the I/O channel. - * - * Returns the number of bytes written - */ -static int -xmlFileWrite (void * context, const char * buffer, int len) { - int items; - - if ((context == NULL) || (buffer == NULL)) - return(-1); - items = fwrite(&buffer[0], len, 1, (FILE *) context); - if ((items == 0) && (ferror((FILE *) context))) { - xmlIOErr(0, "fwrite()"); - return(-1); - } - return(items * len); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlFileClose: * @context: the I/O context @@ -1088,28 +942,6 @@ xmlFileFlush (void * context) { return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlBufferWrite: - * @context: the xmlBuffer - * @buffer: the data to write - * @len: number of bytes to write - * - * Write @len bytes from @buffer to the xml buffer - * - * Returns the number of bytes written - */ -static int -xmlBufferWrite (void * context, const char * buffer, int len) { - int ret; - - ret = xmlBufferAdd((xmlBufferPtr) context, (const xmlChar *) buffer, len); - if (ret != 0) - return(-1); - return(len); -} -#endif - #ifdef HAVE_ZLIB_H /************************************************************************ * * @@ -1199,56 +1031,6 @@ xmlGzfileOpen (const char *filename) { return retval; } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlGzfileOpenW: - * @filename: the URI for matching - * @compression: the compression factor (0 - 9 included) - * - * input from compressed file open - * if @filename is " " then the standard input is used - * - * Returns an I/O context or NULL in case of error - */ -static void * -xmlGzfileOpenW (const char *filename, int compression) { - const char *path = NULL; - char mode[15]; - gzFile fd; - - snprintf(mode, sizeof(mode), "wb%d", compression); - if (!strcmp(filename, "-")) { - fd = gzdopen(dup(1), mode); - return((void *) fd); - } - - if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) -#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) - path = &filename[17]; -#else - path = &filename[16]; -#endif - else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { -#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) - path = &filename[8]; -#else - path = &filename[7]; -#endif - } else - path = filename; - - if (path == NULL) - return(NULL); - -#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) - fd = xmlWrapGzOpen(path, mode); -#else - fd = gzopen(path, mode); -#endif - return((void *) fd); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlGzfileRead: * @context: the I/O context @@ -1268,27 +1050,6 @@ xmlGzfileRead (void * context, char * buffer, int len) { return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlGzfileWrite: - * @context: the I/O context - * @buffer: where to drop data - * @len: number of bytes to write - * - * Write @len bytes from @buffer to the compressed I/O channel. - * - * Returns the number of bytes written - */ -static int -xmlGzfileWrite (void * context, const char * buffer, int len) { - int ret; - - ret = gzwrite((gzFile) context, (char *) &buffer[0], len); - if (ret < 0) xmlIOErr(0, "gzwrite()"); - return(ret); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlGzfileClose: * @context: the I/O context @@ -1450,34 +1211,6 @@ xmlRegisterInputCallbacks(xmlInputMatchCallback matchFunc, return(xmlInputCallbackNr++); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlRegisterOutputCallbacks: - * @matchFunc: the xmlOutputMatchCallback - * @openFunc: the xmlOutputOpenCallback - * @writeFunc: the xmlOutputWriteCallback - * @closeFunc: the xmlOutputCloseCallback - * - * Register a new set of I/O callback for handling output. - * - * Returns the registered handler number or -1 in case of error - */ -int -xmlRegisterOutputCallbacks(xmlOutputMatchCallback matchFunc, - xmlOutputOpenCallback openFunc, xmlOutputWriteCallback writeFunc, - xmlOutputCloseCallback closeFunc) { - if (xmlOutputCallbackNr >= MAX_OUTPUT_CALLBACK) { - return(-1); - } - xmlOutputCallbackTable[xmlOutputCallbackNr].matchcallback = matchFunc; - xmlOutputCallbackTable[xmlOutputCallbackNr].opencallback = openFunc; - xmlOutputCallbackTable[xmlOutputCallbackNr].writecallback = writeFunc; - xmlOutputCallbackTable[xmlOutputCallbackNr].closecallback = closeFunc; - xmlOutputCallbackInitialized = 1; - return(xmlOutputCallbackNr++); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlRegisterDefaultInputCallbacks: * @@ -1506,40 +1239,6 @@ xmlRegisterDefaultInputCallbacks(void) { xmlInputCallbackInitialized = 1; } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlRegisterDefaultOutputCallbacks: - * - * Registers the default compiled-in I/O handlers. - */ -void -xmlRegisterDefaultOutputCallbacks (void) { - if (xmlOutputCallbackInitialized) - return; - -#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) - xmlInitPlatformSpecificIo(); -#endif - - xmlRegisterOutputCallbacks(xmlFileMatch, xmlFileOpenW, - xmlFileWrite, xmlFileClose); - -/********************************* - No way a-priori to distinguish between gzipped files from - uncompressed ones except opening if existing then closing - and saving with same compression ratio ... a pain. - -#ifdef HAVE_ZLIB_H - xmlRegisterOutputCallbacks(xmlGzfileMatch, xmlGzfileOpen, - xmlGzfileWrite, xmlGzfileClose); -#endif - - Nor FTP PUT .... - **********************************/ - xmlOutputCallbackInitialized = 1; -} - -#endif /* LIBXML_OUTPUT_ENABLED */ /** * xmlAllocParserInputBuffer: @@ -1579,114 +1278,6 @@ xmlAllocParserInputBuffer(xmlCharEncoding enc) { return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlAllocOutputBuffer: - * @encoder: the encoding converter or NULL - * - * Create a buffered parser output - * - * Returns the new parser output or NULL - */ -xmlOutputBufferPtr -xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) { - xmlOutputBufferPtr ret; - - ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); - if (ret == NULL) { - xmlIOErrMemory("creating output buffer"); - return(NULL); - } - memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); - ret->buffer = xmlBufferCreate(); - if (ret->buffer == NULL) { - xmlFree(ret); - return(NULL); - } - - /* try to avoid a performance problem with Windows realloc() */ - if (ret->buffer->alloc == XML_BUFFER_ALLOC_EXACT) - ret->buffer->alloc = XML_BUFFER_ALLOC_DOUBLEIT; - - ret->encoder = encoder; - if (encoder != NULL) { - ret->conv = xmlBufferCreateSize(4000); - if (ret->conv == NULL) { - xmlFree(ret); - return(NULL); - } - - /* - * This call is designed to initiate the encoder state - */ - xmlCharEncOutFunc(encoder, ret->conv, NULL); - } else - ret->conv = NULL; - ret->writecallback = NULL; - ret->closecallback = NULL; - ret->context = NULL; - ret->written = 0; - - return(ret); -} - -/** - * xmlAllocOutputBufferInternal: - * @encoder: the encoding converter or NULL - * - * Create a buffered parser output - * - * Returns the new parser output or NULL - */ -xmlOutputBufferPtr -xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder) { - xmlOutputBufferPtr ret; - - ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); - if (ret == NULL) { - xmlIOErrMemory("creating output buffer"); - return(NULL); - } - memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); - ret->buffer = xmlBufferCreate(); - if (ret->buffer == NULL) { - xmlFree(ret); - return(NULL); - } - - - /* - * For conversion buffers we use the special IO handling - * We don't do that from the exported API to avoid confusing - * user's code. - */ - ret->buffer->alloc = XML_BUFFER_ALLOC_IO; - ret->buffer->contentIO = ret->buffer->content; - - ret->encoder = encoder; - if (encoder != NULL) { - ret->conv = xmlBufferCreateSize(4000); - if (ret->conv == NULL) { - xmlFree(ret); - return(NULL); - } - - /* - * This call is designed to initiate the encoder state - */ - xmlCharEncOutFunc(encoder, ret->conv, NULL); - } else - ret->conv = NULL; - ret->writecallback = NULL; - ret->closecallback = NULL; - ret->context = NULL; - ret->written = 0; - - return(ret); -} - -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlFreeParserInputBuffer: * @in: a buffered parser input @@ -1715,48 +1306,6 @@ xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) { xmlFree(in); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlOutputBufferClose: - * @out: a buffered output - * - * flushes and close the output I/O channel - * and free up all the associated resources - * - * Returns the number of byte written or -1 in case of error. - */ -int -xmlOutputBufferClose(xmlOutputBufferPtr out) -{ - int written; - int err_rc = 0; - - if (out == NULL) - return (-1); - if (out->writecallback != NULL) - xmlOutputBufferFlush(out); - if (out->closecallback != NULL) { - err_rc = out->closecallback(out->context); - } - written = out->written; - if (out->conv) { - xmlBufferFree(out->conv); - out->conv = NULL; - } - if (out->encoder != NULL) { - xmlCharEncCloseFunc(out->encoder); - } - if (out->buffer != NULL) { - xmlBufferFree(out->buffer); - out->buffer = NULL; - } - - if (out->error) - err_rc = -1; - xmlFree(out); - return ((err_rc == 0) ? written : err_rc); -} -#endif /* LIBXML_OUTPUT_ENABLED */ xmlParserInputBufferPtr __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { @@ -1844,144 +1393,6 @@ xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { return __xmlParserInputBufferCreateFilename(URI, enc); } -#ifdef LIBXML_OUTPUT_ENABLED -xmlOutputBufferPtr -__xmlOutputBufferCreateFilename(const char *URI, - xmlCharEncodingHandlerPtr encoder, - int compression ATTRIBUTE_UNUSED) { - xmlOutputBufferPtr ret; - xmlURIPtr puri; - int i = 0; - void *context = NULL; - char *unescaped = NULL; -#ifdef HAVE_ZLIB_H - int is_file_uri = 1; -#endif - - if (xmlOutputCallbackInitialized == 0) - xmlRegisterDefaultOutputCallbacks(); - - if (URI == NULL) return(NULL); - - puri = xmlParseURI(URI); - if (puri != NULL) { -#ifdef HAVE_ZLIB_H - if ((puri->scheme != NULL) && - (!xmlStrEqual(BAD_CAST puri->scheme, BAD_CAST "file"))) - is_file_uri = 0; -#endif - /* - * try to limit the damages of the URI unescaping code. - */ - if ((puri->scheme == NULL) || - (xmlStrEqual(BAD_CAST puri->scheme, BAD_CAST "file"))) - unescaped = xmlURIUnescapeString(URI, 0, NULL); - xmlFreeURI(puri); - } - - /* - * Try to find one of the output accept method accepting that scheme - * Go in reverse to give precedence to user defined handlers. - * try with an unescaped version of the URI - */ - if (unescaped != NULL) { -#ifdef HAVE_ZLIB_H - if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) { - context = xmlGzfileOpenW(unescaped, compression); - if (context != NULL) { - ret = xmlAllocOutputBufferInternal(encoder); - if (ret != NULL) { - ret->context = context; - ret->writecallback = xmlGzfileWrite; - ret->closecallback = xmlGzfileClose; - } - xmlFree(unescaped); - return(ret); - } - } -#endif - for (i = xmlOutputCallbackNr - 1;i >= 0;i--) { - if ((xmlOutputCallbackTable[i].matchcallback != NULL) && - (xmlOutputCallbackTable[i].matchcallback(unescaped) != 0)) { - context = xmlOutputCallbackTable[i].opencallback(unescaped); - if (context != NULL) - break; - } - } - xmlFree(unescaped); - } - - /* - * If this failed try with a non-escaped URI this may be a strange - * filename - */ - if (context == NULL) { -#ifdef HAVE_ZLIB_H - if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) { - context = xmlGzfileOpenW(URI, compression); - if (context != NULL) { - ret = xmlAllocOutputBufferInternal(encoder); - if (ret != NULL) { - ret->context = context; - ret->writecallback = xmlGzfileWrite; - ret->closecallback = xmlGzfileClose; - } - return(ret); - } - } -#endif - for (i = xmlOutputCallbackNr - 1;i >= 0;i--) { - if ((xmlOutputCallbackTable[i].matchcallback != NULL) && - (xmlOutputCallbackTable[i].matchcallback(URI) != 0)) { - context = xmlOutputCallbackTable[i].opencallback(URI); - if (context != NULL) - break; - } - } - } - - if (context == NULL) { - return(NULL); - } - - /* - * Allocate the Output buffer front-end. - */ - ret = xmlAllocOutputBufferInternal(encoder); - if (ret != NULL) { - ret->context = context; - ret->writecallback = xmlOutputCallbackTable[i].writecallback; - ret->closecallback = xmlOutputCallbackTable[i].closecallback; - } - return(ret); -} - -/** - * xmlOutputBufferCreateFilename: - * @URI: a C string containing the URI or filename - * @encoder: the encoding converter or NULL - * @compression: the compression ration (0 none, 9 max). - * - * Create a buffered output for the progressive saving of a file - * If filename is "-' then we use stdout as the output. - * Automatic support for ZLIB/Compress compressed document is provided - * by default if found at compile-time. - * TODO: currently if compression is set, the library only support - * writing to a local file. - * - * Returns the new output or NULL - */ -xmlOutputBufferPtr -xmlOutputBufferCreateFilename(const char *URI, - xmlCharEncodingHandlerPtr encoder, - int compression ATTRIBUTE_UNUSED) { - if ((xmlOutputBufferCreateFilenameValue)) { - return xmlOutputBufferCreateFilenameValue(URI, encoder, compression); - } - return __xmlOutputBufferCreateFilename(URI, encoder, compression); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlParserInputBufferCreateFile: * @file: a FILE* @@ -2011,62 +1422,6 @@ xmlParserInputBufferCreateFile(FILE *file, xmlCharEncoding enc) { return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlOutputBufferCreateFile: - * @file: a FILE* - * @encoder: the encoding converter or NULL - * - * Create a buffered output for the progressive saving to a FILE * - * buffered C I/O - * - * Returns the new parser output or NULL - */ -xmlOutputBufferPtr -xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) { - xmlOutputBufferPtr ret; - - if (xmlOutputCallbackInitialized == 0) - xmlRegisterDefaultOutputCallbacks(); - - if (file == NULL) return(NULL); - - ret = xmlAllocOutputBufferInternal(encoder); - if (ret != NULL) { - ret->context = file; - ret->writecallback = xmlFileWrite; - ret->closecallback = xmlFileFlush; - } - - return(ret); -} - -/** - * xmlOutputBufferCreateBuffer: - * @buffer: a xmlBufferPtr - * @encoder: the encoding converter or NULL - * - * Create a buffered output for the progressive saving to a xmlBuffer - * - * Returns the new parser output or NULL - */ -xmlOutputBufferPtr -xmlOutputBufferCreateBuffer(xmlBufferPtr buffer, - xmlCharEncodingHandlerPtr encoder) { - xmlOutputBufferPtr ret; - - if (buffer == NULL) return(NULL); - - ret = xmlOutputBufferCreateIO((xmlOutputWriteCallback) - xmlBufferWrite, - (xmlOutputCloseCallback) - NULL, (void *) buffer, encoder); - - return(ret); -} - -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlParserInputBufferCreateFd: * @fd: a file descriptor number @@ -2172,33 +1527,6 @@ xmlParserInputBufferCreateStatic(const char *mem, int size, return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlOutputBufferCreateFd: - * @fd: a file descriptor number - * @encoder: the encoding converter or NULL - * - * Create a buffered output for the progressive saving - * to a file descriptor - * - * Returns the new parser output or NULL - */ -xmlOutputBufferPtr -xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) { - xmlOutputBufferPtr ret; - - if (fd < 0) return(NULL); - - ret = xmlAllocOutputBufferInternal(encoder); - if (ret != NULL) { - ret->context = (void *) (long) fd; - ret->writecallback = xmlFdWrite; - ret->closecallback = NULL; - } - - return(ret); -} -#endif /* LIBXML_OUTPUT_ENABLED */ /** * xmlParserInputBufferCreateIO: @@ -2229,38 +1557,6 @@ xmlParserInputBufferCreateIO(xmlInputReadCallback ioread, return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlOutputBufferCreateIO: - * @iowrite: an I/O write function - * @ioclose: an I/O close function - * @ioctx: an I/O handler - * @encoder: the charset encoding if known - * - * Create a buffered output for the progressive saving - * to an I/O handler - * - * Returns the new parser output or NULL - */ -xmlOutputBufferPtr -xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite, - xmlOutputCloseCallback ioclose, void *ioctx, - xmlCharEncodingHandlerPtr encoder) { - xmlOutputBufferPtr ret; - - if (iowrite == NULL) return(NULL); - - ret = xmlAllocOutputBufferInternal(encoder); - if (ret != NULL) { - ret->context = (void *) ioctx; - ret->writecallback = iowrite; - ret->closecallback = ioclose; - } - - return(ret); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlParserInputBufferCreateFilenameDefault: * @func: function pointer to the new ParserInputBufferCreateFilenameFunc @@ -2293,11 +1589,6 @@ xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func) { xmlOutputBufferCreateFilenameFunc old = xmlOutputBufferCreateFilenameValue; -#ifdef LIBXML_OUTPUT_ENABLED - if (old == NULL) { - old = __xmlOutputBufferCreateFilename; - } -#endif xmlOutputBufferCreateFilenameValue = func; return(old); } @@ -2495,388 +1786,6 @@ xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len) { return(-1); } -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlOutputBufferWrite: - * @out: a buffered parser output - * @len: the size in bytes of the array. - * @buf: an char array - * - * Write the content of the array in the output I/O buffer - * This routine handle the I18N transcoding from internal UTF-8 - * The buffer is lossless, i.e. will store in case of partial - * or delayed writes. - * - * Returns the number of chars immediately written, or -1 - * in case of error. - */ -int -xmlOutputBufferWrite(xmlOutputBufferPtr out, int len, const char *buf) { - int nbchars = 0; /* number of chars to output to I/O */ - int ret; /* return from function call */ - int written = 0; /* number of char written to I/O so far */ - int chunk; /* number of byte curreent processed from buf */ - - if ((out == NULL) || (out->error)) return(-1); - if (len < 0) return(0); - if (out->error) return(-1); - - do { - chunk = len; - if (chunk > 4 * MINLEN) - chunk = 4 * MINLEN; - - /* - * first handle encoding stuff. - */ - if (out->encoder != NULL) { - /* - * Store the data in the incoming raw buffer - */ - if (out->conv == NULL) { - out->conv = xmlBufferCreate(); - } - ret = xmlBufferAdd(out->buffer, (const xmlChar *) buf, chunk); - if (ret != 0) - return(-1); - - if ((out->buffer->use < MINLEN) && (chunk == len)) - goto done; - - /* - * convert as much as possible to the parser reading buffer. - */ - ret = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); - if ((ret < 0) && (ret != -3)) { - xmlIOErr(XML_IO_ENCODER, NULL); - out->error = XML_IO_ENCODER; - return(-1); - } - nbchars = out->conv->use; - } else { - ret = xmlBufferAdd(out->buffer, (const xmlChar *) buf, chunk); - if (ret != 0) - return(-1); - nbchars = out->buffer->use; - } - buf += chunk; - len -= chunk; - - if ((nbchars < MINLEN) && (len <= 0)) - goto done; - - if (out->writecallback) { - /* - * second write the stuff to the I/O channel - */ - if (out->encoder != NULL) { - ret = out->writecallback(out->context, - (const char *)out->conv->content, nbchars); - if (ret >= 0) - xmlBufferShrink(out->conv, ret); - } else { - ret = out->writecallback(out->context, - (const char *)out->buffer->content, nbchars); - if (ret >= 0) - xmlBufferShrink(out->buffer, ret); - } - if (ret < 0) { - xmlIOErr(XML_IO_WRITE, NULL); - out->error = XML_IO_WRITE; - return(ret); - } - out->written += ret; - } - written += nbchars; - } while (len > 0); - -done: -#ifdef DEBUG_INPUT - xmlGenericError(xmlGenericErrorContext, - "I/O: wrote %d chars\n", written); -#endif - return(written); -} - -/** - * xmlEscapeContent: - * @out: a pointer to an array of bytes to store the result - * @outlen: the length of @out - * @in: a pointer to an array of unescaped UTF-8 bytes - * @inlen: the length of @in - * - * Take a block of UTF-8 chars in and escape them. - * Returns 0 if success, or -1 otherwise - * The value of @inlen after return is the number of octets consumed - * if the return value is positive, else unpredictable. - * The value of @outlen after return is the number of octets consumed. - */ -static int -xmlEscapeContent(unsigned char* out, int *outlen, - const xmlChar* in, int *inlen) { - unsigned char* outstart = out; - const unsigned char* base = in; - unsigned char* outend = out + *outlen; - const unsigned char* inend; - - inend = in + (*inlen); - - while ((in < inend) && (out < outend)) { - if (*in == '<') { - if (outend - out < 4) break; - *out++ = '&'; - *out++ = 'l'; - *out++ = 't'; - *out++ = ';'; - } else if (*in == '>') { - if (outend - out < 4) break; - *out++ = '&'; - *out++ = 'g'; - *out++ = 't'; - *out++ = ';'; - } else if (*in == '&') { - if (outend - out < 5) break; - *out++ = '&'; - *out++ = 'a'; - *out++ = 'm'; - *out++ = 'p'; - *out++ = ';'; - } else if (*in == '\r') { - if (outend - out < 5) break; - *out++ = '&'; - *out++ = '#'; - *out++ = '1'; - *out++ = '3'; - *out++ = ';'; - } else { - *out++ = (unsigned char) *in; - } - ++in; - } - *outlen = out - outstart; - *inlen = in - base; - return(0); -} - -/** - * xmlOutputBufferWriteEscape: - * @out: a buffered parser output - * @str: a zero terminated UTF-8 string - * @escaping: an optional escaping function (or NULL) - * - * Write the content of the string in the output I/O buffer - * This routine escapes the caracters and then handle the I18N - * transcoding from internal UTF-8 - * The buffer is lossless, i.e. will store in case of partial - * or delayed writes. - * - * Returns the number of chars immediately written, or -1 - * in case of error. - */ -int -xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str, - xmlCharEncodingOutputFunc escaping) { - int nbchars = 0; /* number of chars to output to I/O */ - int ret; /* return from function call */ - int written = 0; /* number of char written to I/O so far */ - int oldwritten=0;/* loop guard */ - int chunk; /* number of byte currently processed from str */ - int len; /* number of bytes in str */ - int cons; /* byte from str consumed */ - - if ((out == NULL) || (out->error) || (str == NULL) || - (out->buffer == NULL) || - (out->buffer->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) return(-1); - len = strlen((const char *)str); - if (len < 0) return(0); - if (out->error) return(-1); - if (escaping == NULL) escaping = xmlEscapeContent; - - do { - oldwritten = written; - - /* - * how many bytes to consume and how many bytes to store. - */ - cons = len; - chunk = (out->buffer->size - out->buffer->use) - 1; - - /* - * make sure we have enough room to save first, if this is - * not the case force a flush, but make sure we stay in the loop - */ - if (chunk < 40) { - if (xmlBufferGrow(out->buffer, out->buffer->size + 100) < 0) - return(-1); - oldwritten = -1; - continue; - } - - /* - * first handle encoding stuff. - */ - if (out->encoder != NULL) { - /* - * Store the data in the incoming raw buffer - */ - if (out->conv == NULL) { - out->conv = xmlBufferCreate(); - } - ret = escaping(out->buffer->content + out->buffer->use , - &chunk, str, &cons); - if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ - return(-1); - out->buffer->use += chunk; - out->buffer->content[out->buffer->use] = 0; - - if ((out->buffer->use < MINLEN) && (cons == len)) - goto done; - - /* - * convert as much as possible to the output buffer. - */ - ret = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); - if ((ret < 0) && (ret != -3)) { - xmlIOErr(XML_IO_ENCODER, NULL); - out->error = XML_IO_ENCODER; - return(-1); - } - nbchars = out->conv->use; - } else { - ret = escaping(out->buffer->content + out->buffer->use , - &chunk, str, &cons); - if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ - return(-1); - out->buffer->use += chunk; - out->buffer->content[out->buffer->use] = 0; - nbchars = out->buffer->use; - } - str += cons; - len -= cons; - - if ((nbchars < MINLEN) && (len <= 0)) - goto done; - - if (out->writecallback) { - /* - * second write the stuff to the I/O channel - */ - if (out->encoder != NULL) { - ret = out->writecallback(out->context, - (const char *)out->conv->content, nbchars); - if (ret >= 0) - xmlBufferShrink(out->conv, ret); - } else { - ret = out->writecallback(out->context, - (const char *)out->buffer->content, nbchars); - if (ret >= 0) - xmlBufferShrink(out->buffer, ret); - } - if (ret < 0) { - xmlIOErr(XML_IO_WRITE, NULL); - out->error = XML_IO_WRITE; - return(ret); - } - out->written += ret; - } else if (out->buffer->size - out->buffer->use < MINLEN) { - xmlBufferResize(out->buffer, out->buffer->size + MINLEN); - } - written += nbchars; - } while ((len > 0) && (oldwritten != written)); - -done: -#ifdef DEBUG_INPUT - xmlGenericError(xmlGenericErrorContext, - "I/O: wrote %d chars\n", written); -#endif - return(written); -} - -/** - * xmlOutputBufferWriteString: - * @out: a buffered parser output - * @str: a zero terminated C string - * - * Write the content of the string in the output I/O buffer - * This routine handle the I18N transcoding from internal UTF-8 - * The buffer is lossless, i.e. will store in case of partial - * or delayed writes. - * - * Returns the number of chars immediately written, or -1 - * in case of error. - */ -int -xmlOutputBufferWriteString(xmlOutputBufferPtr out, const char *str) { - int len; - - if ((out == NULL) || (out->error)) return(-1); - if (str == NULL) - return(-1); - len = strlen(str); - - if (len > 0) - return(xmlOutputBufferWrite(out, len, str)); - return(len); -} - -/** - * xmlOutputBufferFlush: - * @out: a buffered output - * - * flushes the output I/O channel - * - * Returns the number of byte written or -1 in case of error. - */ -int -xmlOutputBufferFlush(xmlOutputBufferPtr out) { - int nbchars = 0, ret = 0; - - if ((out == NULL) || (out->error)) return(-1); - /* - * first handle encoding stuff. - */ - if ((out->conv != NULL) && (out->encoder != NULL)) { - /* - * convert as much as possible to the parser reading buffer. - */ - nbchars = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); - if (nbchars < 0) { - xmlIOErr(XML_IO_ENCODER, NULL); - out->error = XML_IO_ENCODER; - return(-1); - } - } - - /* - * second flush the stuff to the I/O channel - */ - if ((out->conv != NULL) && (out->encoder != NULL) && - (out->writecallback != NULL)) { - ret = out->writecallback(out->context, - (const char *)out->conv->content, out->conv->use); - if (ret >= 0) - xmlBufferShrink(out->conv, ret); - } else if (out->writecallback != NULL) { - ret = out->writecallback(out->context, - (const char *)out->buffer->content, out->buffer->use); - if (ret >= 0) - xmlBufferShrink(out->buffer, ret); - } - if (ret < 0) { - xmlIOErr(XML_IO_FLUSH, NULL); - out->error = XML_IO_FLUSH; - return(ret); - } - out->written += ret; - -#ifdef DEBUG_INPUT - xmlGenericError(xmlGenericErrorContext, - "I/O: flushed %d chars\n", ret); -#endif - return(ret); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - /** * xmlParserGetDirectory: * @filename: the path to a file diff --git a/android/native/libxml2/xmllint.c b/android/native/libxml2/xmllint.c index 6516ba6265..5f8abd1003 100644 --- a/android/native/libxml2/xmllint.c +++ b/android/native/libxml2/xmllint.c @@ -82,9 +82,6 @@ #ifdef LIBXML_C14N_ENABLED #include #endif -#ifdef LIBXML_OUTPUT_ENABLED -#include -#endif #ifndef XML_XML_DEFAULT_CATALOG #define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog" @@ -114,12 +111,6 @@ static int noenc = 0; static int noblanks = 0; static int noout = 0; static int nowrap = 0; -#ifdef LIBXML_OUTPUT_ENABLED -static int format = 0; -static const char *output = NULL; -static int compress = 0; -static int oldout = 0; -#endif /* LIBXML_OUTPUT_ENABLED */ #ifdef LIBXML_VALID_ENABLED static int valid = 0; static int postvalid = 0; @@ -1991,168 +1982,6 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { walkDoc(doc); } #endif /* LIBXML_READER_ENABLED */ -#ifdef LIBXML_OUTPUT_ENABLED - if (noout == 0) { - int ret; - - /* - * print it. - */ - if ((timing) && (!repeat)) { - startTimer(); - } -#ifdef LIBXML_C14N_ENABLED - if (canonical) { - xmlChar *result = NULL; - int size; - - size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_0, NULL, 1, &result); - if (size >= 0) { - if (write(1, result, size) == -1) { - fprintf(stderr, "Can't write data\n"); - } - xmlFree(result); - } else { - fprintf(stderr, "Failed to canonicalize\n"); - progresult = XMLLINT_ERR_OUT; - } - } else if (canonical) { - xmlChar *result = NULL; - int size; - - size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_1_1, NULL, 1, &result); - if (size >= 0) { - if (write(1, result, size) == -1) { - fprintf(stderr, "Can't write data\n"); - } - xmlFree(result); - } else { - fprintf(stderr, "Failed to canonicalize\n"); - progresult = XMLLINT_ERR_OUT; - } - } else - if (exc_canonical) { - xmlChar *result = NULL; - int size; - - size = xmlC14NDocDumpMemory(doc, NULL, XML_C14N_EXCLUSIVE_1_0, NULL, 1, &result); - if (size >= 0) { - if (write(1, result, size) == -1) { - fprintf(stderr, "Can't write data\n"); - } - xmlFree(result); - } else { - fprintf(stderr, "Failed to canonicalize\n"); - progresult = XMLLINT_ERR_OUT; - } - } else -#endif -#ifdef HAVE_SYS_MMAN_H - if (memory) { - xmlChar *result; - int len; - - if (encoding != NULL) { - if (format == 1) { - xmlDocDumpFormatMemoryEnc(doc, &result, &len, encoding, 1); - } else { - xmlDocDumpMemoryEnc(doc, &result, &len, encoding); - } - } else { - if (format == 1) - xmlDocDumpFormatMemory(doc, &result, &len, 1); - else - xmlDocDumpMemory(doc, &result, &len); - } - if (result == NULL) { - fprintf(stderr, "Failed to save\n"); - progresult = XMLLINT_ERR_OUT; - } else { - if (write(1, result, len) == -1) { - fprintf(stderr, "Can't write data\n"); - } - xmlFree(result); - } - - } else -#endif /* HAVE_SYS_MMAN_H */ - if (compress) { - xmlSaveFile(output ? output : "-", doc); - } else if (oldout) { - if (encoding != NULL) { - if (format == 1) { - ret = xmlSaveFormatFileEnc(output ? output : "-", doc, - encoding, 1); - } - else { - ret = xmlSaveFileEnc(output ? output : "-", doc, - encoding); - } - if (ret < 0) { - fprintf(stderr, "failed save to %s\n", - output ? output : "-"); - progresult = XMLLINT_ERR_OUT; - } - } else if (format == 1) { - ret = xmlSaveFormatFile(output ? output : "-", doc, 1); - if (ret < 0) { - fprintf(stderr, "failed save to %s\n", - output ? output : "-"); - progresult = XMLLINT_ERR_OUT; - } - } else { - FILE *out; - if (output == NULL) - out = stdout; - else { - out = fopen(output,"wb"); - } - if (out != NULL) { - if (xmlDocDump(out, doc) < 0) - progresult = XMLLINT_ERR_OUT; - - if (output != NULL) - fclose(out); - } else { - fprintf(stderr, "failed to open %s\n", output); - progresult = XMLLINT_ERR_OUT; - } - } - } else { - xmlSaveCtxtPtr ctxt; - int saveOpts = 0; - - if (format == 1) - saveOpts |= XML_SAVE_FORMAT; - else if (format == 2) - saveOpts |= XML_SAVE_WSNONSIG; - -#if defined(LIBXML_VALID_ENABLED) - if (xmlout) - saveOpts |= XML_SAVE_AS_XML; -#endif - - if (output == NULL) - ctxt = xmlSaveToFd(1, encoding, saveOpts); - else - ctxt = xmlSaveToFilename(output, encoding, saveOpts); - - if (ctxt != NULL) { - if (xmlSaveDoc(ctxt, doc) < 0) { - fprintf(stderr, "failed save to %s\n", - output ? output : "-"); - progresult = XMLLINT_ERR_OUT; - } - xmlSaveClose(ctxt); - } else { - progresult = XMLLINT_ERR_OUT; - } - } - if ((timing) && (!repeat)) { - endTimer("Saving"); - } - } -#endif /* LIBXML_OUTPUT_ENABLED */ #ifdef LIBXML_VALID_ENABLED /* @@ -2296,11 +2125,7 @@ static void showVersion(const char *name) { static void usage(const char *name) { printf("Usage : %s [options] XMLfiles ...\n", name); -#ifdef LIBXML_OUTPUT_ENABLED - printf("\tParse the XML files and output the result of the parsing\n"); -#else printf("\tParse the XML files\n"); -#endif /* LIBXML_OUTPUT_ENABLED */ printf("\t--version : display the version of the XML library used\n"); #ifdef LIBXML_READER_ENABLED printf("\t--debug : dump the nodes content when using --stream\n"); @@ -2330,11 +2155,6 @@ static void usage(const char *name) { printf("\t--output file or -o file: save to a given file\n"); printf("\t--repeat : repeat 100 times, for timing or profiling\n"); printf("\t--insert : ad-hoc test for valid insertions\n"); -#ifdef LIBXML_OUTPUT_ENABLED -#ifdef HAVE_ZLIB_H - printf("\t--compress : turn on gzip compression of output\n"); -#endif -#endif /* LIBXML_OUTPUT_ENABLED */ #ifdef LIBXML_PUSH_ENABLED printf("\t--push : use the push mode of the parser\n"); #endif /* LIBXML_PUSH_ENABLED */ @@ -2345,15 +2165,6 @@ static void usage(const char *name) { printf("\t--nowarning : do not emit warnings from parser/validator\n"); printf("\t--noblanks : drop (ignorable?) blanks spaces\n"); printf("\t--nocdata : replace cdata section with text nodes\n"); -#ifdef LIBXML_OUTPUT_ENABLED - printf("\t--format : reformat/reindent the input\n"); - printf("\t--encode encoding : output in the given encoding\n"); - printf("\t--dropdtd : remove the DOCTYPE of the input docs\n"); - printf("\t--pretty STYLE : pretty-print in a particular style\n"); - printf("\t 0 Do not pretty print\n"); - printf("\t 1 Format the XML content, as --format\n"); - printf("\t 2 Add whitespace inside tags, preserving content\n"); -#endif /* LIBXML_OUTPUT_ENABLED */ printf("\t--c14n : save in W3C canonical format v1.0 (with comments)\n"); printf("\t--c14n11 : save in W3C canonical format v1.1 (with comments)\n"); printf("\t--exc-c14n : save in W3C exclusive canonical format (with comments)\n"); @@ -2448,14 +2259,6 @@ main(int argc, char **argv) { } else if ((!strcmp(argv[i], "-noout")) || (!strcmp(argv[i], "--noout"))) noout++; -#ifdef LIBXML_OUTPUT_ENABLED - else if ((!strcmp(argv[i], "-o")) || - (!strcmp(argv[i], "-output")) || - (!strcmp(argv[i], "--output"))) { - i++; - output = argv[i]; - } -#endif /* LIBXML_OUTPUT_ENABLED */ else if ((!strcmp(argv[i], "-htmlout")) || (!strcmp(argv[i], "--htmlout"))) htmlout++; @@ -2528,15 +2331,6 @@ main(int argc, char **argv) { else if ((!strcmp(argv[i], "-testIO")) || (!strcmp(argv[i], "--testIO"))) testIO++; -#ifdef LIBXML_OUTPUT_ENABLED -#ifdef HAVE_ZLIB_H - else if ((!strcmp(argv[i], "-compress")) || - (!strcmp(argv[i], "--compress"))) { - compress++; - xmlSetCompressMode(9); - } -#endif -#endif /* LIBXML_OUTPUT_ENABLED */ else if ((!strcmp(argv[i], "-nowarning")) || (!strcmp(argv[i], "--nowarning"))) { xmlGetWarningsDefaultValue = 0; @@ -2593,17 +2387,11 @@ main(int argc, char **argv) { else if ((!strcmp(argv[i], "-format")) || (!strcmp(argv[i], "--format"))) { noblanks++; -#ifdef LIBXML_OUTPUT_ENABLED - format = 1; -#endif /* LIBXML_OUTPUT_ENABLED */ xmlKeepBlanksDefault(0); } else if ((!strcmp(argv[i], "-pretty")) || (!strcmp(argv[i], "--pretty"))) { i++; -#ifdef LIBXML_OUTPUT_ENABLED - format = atoi(argv[i]); -#endif /* LIBXML_OUTPUT_ENABLED */ if (format == 1) { noblanks++; xmlKeepBlanksDefault(0); diff --git a/android/native/libxml2/xmlsave.c b/android/native/libxml2/xmlsave.c index 7d500a0ed4..bb5db8a0a2 100644 --- a/android/native/libxml2/xmlsave.c +++ b/android/native/libxml2/xmlsave.c @@ -64,1888 +64,5 @@ xmlIsXHTML(const xmlChar *systemID, const xmlChar *publicID) { return(0); } -#ifdef LIBXML_OUTPUT_ENABLED - -#define TODO \ - xmlGenericError(xmlGenericErrorContext, \ - "Unimplemented block at %s:%d\n", \ - __FILE__, __LINE__); - -struct _xmlSaveCtxt { - void *_private; - int type; - int fd; - const xmlChar *filename; - const xmlChar *encoding; - xmlCharEncodingHandlerPtr handler; - xmlOutputBufferPtr buf; - xmlDocPtr doc; - int options; - int level; - int format; - char indent[MAX_INDENT + 1]; /* array for indenting output */ - int indent_nr; - int indent_size; - xmlCharEncodingOutputFunc escape; /* used for element content */ - xmlCharEncodingOutputFunc escapeAttr;/* used for attribute content */ -}; - -/************************************************************************ - * * - * Output error handlers * - * * - ************************************************************************/ -/** - * xmlSaveErrMemory: - * @extra: extra informations - * - * Handle an out of memory condition - */ -static void -xmlSaveErrMemory(const char *extra) -{ - __xmlSimpleError(XML_FROM_OUTPUT, XML_ERR_NO_MEMORY, NULL, NULL, extra); -} - -/** - * xmlSaveErr: - * @code: the error number - * @node: the location of the error. - * @extra: extra informations - * - * Handle an out of memory condition - */ -static void -xmlSaveErr(int code, xmlNodePtr node, const char *extra) -{ - const char *msg = NULL; - - switch(code) { - case XML_SAVE_NOT_UTF8: - msg = "string is not in UTF-8\n"; - break; - case XML_SAVE_CHAR_INVALID: - msg = "invalid character value\n"; - break; - case XML_SAVE_UNKNOWN_ENCODING: - msg = "unknown encoding %s\n"; - break; - case XML_SAVE_NO_DOCTYPE: - msg = "document has no DOCTYPE\n"; - break; - default: - msg = "unexpected error number\n"; - } - __xmlSimpleError(XML_FROM_OUTPUT, code, node, msg, extra); -} - -/************************************************************************ - * * - * Special escaping routines * - * * - ************************************************************************/ -static unsigned char * -xmlSerializeHexCharRef(unsigned char *out, int val) { - unsigned char *ptr; - - *out++ = '&'; - *out++ = '#'; - *out++ = 'x'; - if (val < 0x10) ptr = out; - else if (val < 0x100) ptr = out + 1; - else if (val < 0x1000) ptr = out + 2; - else if (val < 0x10000) ptr = out + 3; - else if (val < 0x100000) ptr = out + 4; - else ptr = out + 5; - out = ptr + 1; - while (val > 0) { - switch (val & 0xF) { - case 0: *ptr-- = '0'; break; - case 1: *ptr-- = '1'; break; - case 2: *ptr-- = '2'; break; - case 3: *ptr-- = '3'; break; - case 4: *ptr-- = '4'; break; - case 5: *ptr-- = '5'; break; - case 6: *ptr-- = '6'; break; - case 7: *ptr-- = '7'; break; - case 8: *ptr-- = '8'; break; - case 9: *ptr-- = '9'; break; - case 0xA: *ptr-- = 'A'; break; - case 0xB: *ptr-- = 'B'; break; - case 0xC: *ptr-- = 'C'; break; - case 0xD: *ptr-- = 'D'; break; - case 0xE: *ptr-- = 'E'; break; - case 0xF: *ptr-- = 'F'; break; - default: *ptr-- = '0'; break; - } - val >>= 4; - } - *out++ = ';'; - *out = 0; - return(out); -} - -/** - * xmlEscapeEntities: - * @out: a pointer to an array of bytes to store the result - * @outlen: the length of @out - * @in: a pointer to an array of unescaped UTF-8 bytes - * @inlen: the length of @in - * - * Take a block of UTF-8 chars in and escape them. Used when there is no - * encoding specified. - * - * Returns 0 if success, or -1 otherwise - * The value of @inlen after return is the number of octets consumed - * if the return value is positive, else unpredictable. - * The value of @outlen after return is the number of octets consumed. - */ -static int -xmlEscapeEntities(unsigned char* out, int *outlen, - const xmlChar* in, int *inlen) { - unsigned char* outstart = out; - const unsigned char* base = in; - unsigned char* outend = out + *outlen; - const unsigned char* inend; - int val; - - inend = in + (*inlen); - - while ((in < inend) && (out < outend)) { - if (*in == '<') { - if (outend - out < 4) break; - *out++ = '&'; - *out++ = 'l'; - *out++ = 't'; - *out++ = ';'; - in++; - continue; - } else if (*in == '>') { - if (outend - out < 4) break; - *out++ = '&'; - *out++ = 'g'; - *out++ = 't'; - *out++ = ';'; - in++; - continue; - } else if (*in == '&') { - if (outend - out < 5) break; - *out++ = '&'; - *out++ = 'a'; - *out++ = 'm'; - *out++ = 'p'; - *out++ = ';'; - in++; - continue; - } else if (((*in >= 0x20) && (*in < 0x80)) || - (*in == '\n') || (*in == '\t')) { - /* - * default case, just copy ! - */ - *out++ = *in++; - continue; - } else if (*in >= 0x80) { - /* - * We assume we have UTF-8 input. - */ - if (outend - out < 11) break; - - if (*in < 0xC0) { - xmlSaveErr(XML_SAVE_NOT_UTF8, NULL, NULL); - in++; - goto error; - } else if (*in < 0xE0) { - if (inend - in < 2) break; - val = (in[0]) & 0x1F; - val <<= 6; - val |= (in[1]) & 0x3F; - in += 2; - } else if (*in < 0xF0) { - if (inend - in < 3) break; - val = (in[0]) & 0x0F; - val <<= 6; - val |= (in[1]) & 0x3F; - val <<= 6; - val |= (in[2]) & 0x3F; - in += 3; - } else if (*in < 0xF8) { - if (inend - in < 4) break; - val = (in[0]) & 0x07; - val <<= 6; - val |= (in[1]) & 0x3F; - val <<= 6; - val |= (in[2]) & 0x3F; - val <<= 6; - val |= (in[3]) & 0x3F; - in += 4; - } else { - xmlSaveErr(XML_SAVE_CHAR_INVALID, NULL, NULL); - in++; - goto error; - } - if (!IS_CHAR(val)) { - xmlSaveErr(XML_SAVE_CHAR_INVALID, NULL, NULL); - in++; - goto error; - } - - /* - * We could do multiple things here. Just save as a char ref - */ - out = xmlSerializeHexCharRef(out, val); - } else if (IS_BYTE_CHAR(*in)) { - if (outend - out < 6) break; - out = xmlSerializeHexCharRef(out, *in++); - } else { - xmlGenericError(xmlGenericErrorContext, - "xmlEscapeEntities : char out of range\n"); - in++; - goto error; - } - } - *outlen = out - outstart; - *inlen = in - base; - return(0); -error: - *outlen = out - outstart; - *inlen = in - base; - return(-1); -} - -/************************************************************************ - * * - * Allocation and deallocation * - * * - ************************************************************************/ -/** - * xmlSaveCtxtInit: - * @ctxt: the saving context - * - * Initialize a saving context - */ -static void -xmlSaveCtxtInit(xmlSaveCtxtPtr ctxt) -{ - int i; - int len; - - if (ctxt == NULL) return; - if ((ctxt->encoding == NULL) && (ctxt->escape == NULL)) - ctxt->escape = xmlEscapeEntities; - len = xmlStrlen((xmlChar *)xmlTreeIndentString); - if ((xmlTreeIndentString == NULL) || (len == 0)) { - memset(&ctxt->indent[0], 0, MAX_INDENT + 1); - } else { - ctxt->indent_size = len; - ctxt->indent_nr = MAX_INDENT / ctxt->indent_size; - for (i = 0;i < ctxt->indent_nr;i++) - memcpy(&ctxt->indent[i * ctxt->indent_size], xmlTreeIndentString, - ctxt->indent_size); - ctxt->indent[ctxt->indent_nr * ctxt->indent_size] = 0; - } - - if (xmlSaveNoEmptyTags) { - ctxt->options |= XML_SAVE_NO_EMPTY; - } -} - -/** - * xmlFreeSaveCtxt: - * - * Free a saving context, destroying the ouptut in any remaining buffer - */ -static void -xmlFreeSaveCtxt(xmlSaveCtxtPtr ctxt) -{ - if (ctxt == NULL) return; - if (ctxt->encoding != NULL) - xmlFree((char *) ctxt->encoding); - if (ctxt->buf != NULL) - xmlOutputBufferClose(ctxt->buf); - xmlFree(ctxt); -} - -/** - * xmlNewSaveCtxt: - * - * Create a new saving context - * - * Returns the new structure or NULL in case of error - */ -static xmlSaveCtxtPtr -xmlNewSaveCtxt(const char *encoding, int options) -{ - xmlSaveCtxtPtr ret; - - ret = (xmlSaveCtxtPtr) xmlMalloc(sizeof(xmlSaveCtxt)); - if (ret == NULL) { - xmlSaveErrMemory("creating saving context"); - return ( NULL ); - } - memset(ret, 0, sizeof(xmlSaveCtxt)); - - if (encoding != NULL) { - ret->handler = xmlFindCharEncodingHandler(encoding); - if (ret->handler == NULL) { - xmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, encoding); - xmlFreeSaveCtxt(ret); - return(NULL); - } - ret->encoding = xmlStrdup((const xmlChar *)encoding); - ret->escape = NULL; - } - xmlSaveCtxtInit(ret); - - /* - * Use the options - */ - - /* Re-check this option as it may already have been set */ - if ((ret->options & XML_SAVE_NO_EMPTY) && ! (options & XML_SAVE_NO_EMPTY)) { - options |= XML_SAVE_NO_EMPTY; - } - - ret->options = options; - if (options & XML_SAVE_FORMAT) - ret->format = 1; - else if (options & XML_SAVE_WSNONSIG) - ret->format = 2; - - return(ret); -} - -/************************************************************************ - * * - * Dumping XML tree content to a simple buffer * - * * - ************************************************************************/ -/** - * xmlAttrSerializeContent: - * @buf: the XML buffer output - * @doc: the document - * @attr: the attribute pointer - * - * Serialize the attribute in the buffer - */ -static void -xmlAttrSerializeContent(xmlOutputBufferPtr buf, xmlAttrPtr attr) -{ - xmlNodePtr children; - - children = attr->children; - while (children != NULL) { - switch (children->type) { - case XML_TEXT_NODE: - xmlAttrSerializeTxtContent(buf->buffer, attr->doc, - attr, children->content); - break; - case XML_ENTITY_REF_NODE: - xmlBufferAdd(buf->buffer, BAD_CAST "&", 1); - xmlBufferAdd(buf->buffer, children->name, - xmlStrlen(children->name)); - xmlBufferAdd(buf->buffer, BAD_CAST ";", 1); - break; - default: - /* should not happen unless we have a badly built tree */ - break; - } - children = children->next; - } -} - -/************************************************************************ - * * - * Dumping XML tree content to an I/O output buffer * - * * - ************************************************************************/ - -static int xmlSaveSwitchEncoding(xmlSaveCtxtPtr ctxt, const char *encoding) { - xmlOutputBufferPtr buf = ctxt->buf; - - if ((encoding != NULL) && (buf->encoder == NULL) && (buf->conv == NULL)) { - buf->encoder = xmlFindCharEncodingHandler((const char *)encoding); - if (buf->encoder == NULL) { - xmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, NULL, - (const char *)encoding); - return(-1); - } - buf->conv = xmlBufferCreate(); - if (buf->conv == NULL) { - xmlCharEncCloseFunc(buf->encoder); - xmlSaveErrMemory("creating encoding buffer"); - return(-1); - } - /* - * initialize the state, e.g. if outputting a BOM - */ - xmlCharEncOutFunc(buf->encoder, buf->conv, NULL); - } - return(0); -} - -static int xmlSaveClearEncoding(xmlSaveCtxtPtr ctxt) { - xmlOutputBufferPtr buf = ctxt->buf; - xmlOutputBufferFlush(buf); - xmlCharEncCloseFunc(buf->encoder); - xmlBufferFree(buf->conv); - buf->encoder = NULL; - buf->conv = NULL; - return(0); -} - -static void xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); -static void xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur); -void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur); -static int xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur); - -/** - * xmlOutputBufferWriteWSNonSig: - * @ctxt: The save context - * @extra: Number of extra indents to apply to ctxt->level - * - * Write out formatting for non-significant whitespace output. - */ -static void -xmlOutputBufferWriteWSNonSig(xmlSaveCtxtPtr ctxt, int extra) -{ - int i; - if ((ctxt == NULL) || (ctxt->buf == NULL)) - return; - xmlOutputBufferWrite(ctxt->buf, 1, "\n"); - for (i = 0; i < (ctxt->level + extra); i += ctxt->indent_nr) { - xmlOutputBufferWrite(ctxt->buf, ctxt->indent_size * - ((ctxt->level + extra - i) > ctxt->indent_nr ? - ctxt->indent_nr : (ctxt->level + extra - i)), - ctxt->indent); - } -} - -/** - * xmlNsDumpOutput: - * @buf: the XML buffer output - * @cur: a namespace - * @ctxt: the output save context. Optional. - * - * Dump a local Namespace definition. - * Should be called in the context of attributes dumps. - * If @ctxt is supplied, @buf should be its buffer. - */ -static void -xmlNsDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur, xmlSaveCtxtPtr ctxt) { - if ((cur == NULL) || (buf == NULL)) return; - if ((cur->type == XML_LOCAL_NAMESPACE) && (cur->href != NULL)) { - if (xmlStrEqual(cur->prefix, BAD_CAST "xml")) - return; - - if (ctxt != NULL && ctxt->format == 2) - xmlOutputBufferWriteWSNonSig(ctxt, 2); - else - xmlOutputBufferWrite(buf, 1, " "); - - /* Within the context of an element attributes */ - if (cur->prefix != NULL) { - xmlOutputBufferWrite(buf, 6, "xmlns:"); - xmlOutputBufferWriteString(buf, (const char *)cur->prefix); - } else - xmlOutputBufferWrite(buf, 5, "xmlns"); - xmlOutputBufferWrite(buf, 1, "="); - xmlBufferWriteQuotedString(buf->buffer, cur->href); - } -} - -/** - * xmlNsDumpOutputCtxt - * @ctxt: the save context - * @cur: a namespace - * - * Dump a local Namespace definition to a save context. - * Should be called in the context of attribute dumps. - */ -static void -xmlNsDumpOutputCtxt(xmlSaveCtxtPtr ctxt, xmlNsPtr cur) { - xmlNsDumpOutput(ctxt->buf, cur, ctxt); -} - -/** - * xmlNsListDumpOutputCtxt - * @ctxt: the save context - * @cur: the first namespace - * - * Dump a list of local namespace definitions to a save context. - * Should be called in the context of attribute dumps. - */ -static void -xmlNsListDumpOutputCtxt(xmlSaveCtxtPtr ctxt, xmlNsPtr cur) { - while (cur != NULL) { - xmlNsDumpOutput(ctxt->buf, cur, ctxt); - cur = cur->next; - } -} - -/** - * xmlNsListDumpOutput: - * @buf: the XML buffer output - * @cur: the first namespace - * - * Dump a list of local Namespace definitions. - * Should be called in the context of attributes dumps. - */ -void -xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur) { - while (cur != NULL) { - xmlNsDumpOutput(buf, cur, NULL); - cur = cur->next; - } -} - -/** - * xmlDtdDumpOutput: - * @buf: the XML buffer output - * @dtd: the pointer to the DTD - * - * Dump the XML document DTD, if any. - */ -static void -xmlDtdDumpOutput(xmlSaveCtxtPtr ctxt, xmlDtdPtr dtd) { - xmlOutputBufferPtr buf; - int format, level; - xmlDocPtr doc; - - if (dtd == NULL) return; - if ((ctxt == NULL) || (ctxt->buf == NULL)) - return; - buf = ctxt->buf; - xmlOutputBufferWrite(buf, 10, "name); - if (dtd->ExternalID != NULL) { - xmlOutputBufferWrite(buf, 8, " PUBLIC "); - xmlBufferWriteQuotedString(buf->buffer, dtd->ExternalID); - xmlOutputBufferWrite(buf, 1, " "); - xmlBufferWriteQuotedString(buf->buffer, dtd->SystemID); - } else if (dtd->SystemID != NULL) { - xmlOutputBufferWrite(buf, 8, " SYSTEM "); - xmlBufferWriteQuotedString(buf->buffer, dtd->SystemID); - } - if ((dtd->entities == NULL) && (dtd->elements == NULL) && - (dtd->attributes == NULL) && (dtd->notations == NULL) && - (dtd->pentities == NULL)) { - xmlOutputBufferWrite(buf, 1, ">"); - return; - } - xmlOutputBufferWrite(buf, 3, " [\n"); - /* - * Dump the notations first they are not in the DTD children list - * Do this only on a standalone DTD or on the internal subset though. - */ - if ((dtd->notations != NULL) && ((dtd->doc == NULL) || - (dtd->doc->intSubset == dtd))) { - xmlDumpNotationTable(buf->buffer, (xmlNotationTablePtr) dtd->notations); - } - format = ctxt->format; - level = ctxt->level; - doc = ctxt->doc; - ctxt->format = 0; - ctxt->level = -1; - ctxt->doc = dtd->doc; - xmlNodeListDumpOutput(ctxt, dtd->children); - ctxt->format = format; - ctxt->level = level; - ctxt->doc = doc; - xmlOutputBufferWrite(buf, 2, "]>"); -} - -/** - * xmlAttrDumpOutput: - * @buf: the XML buffer output - * @cur: the attribute pointer - * - * Dump an XML attribute - */ -static void -xmlAttrDumpOutput(xmlSaveCtxtPtr ctxt, xmlAttrPtr cur) { - xmlOutputBufferPtr buf; - - if (cur == NULL) return; - buf = ctxt->buf; - if (buf == NULL) return; - if (ctxt->format == 2) - xmlOutputBufferWriteWSNonSig(ctxt, 2); - else - xmlOutputBufferWrite(buf, 1, " "); - if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { - xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); - xmlOutputBufferWrite(buf, 1, ":"); - } - xmlOutputBufferWriteString(buf, (const char *)cur->name); - xmlOutputBufferWrite(buf, 2, "=\""); - xmlAttrSerializeContent(buf, cur); - xmlOutputBufferWrite(buf, 1, "\""); -} - -/** - * xmlAttrListDumpOutput: - * @buf: the XML buffer output - * @doc: the document - * @cur: the first attribute pointer - * @encoding: an optional encoding string - * - * Dump a list of XML attributes - */ -static void -xmlAttrListDumpOutput(xmlSaveCtxtPtr ctxt, xmlAttrPtr cur) { - if (cur == NULL) return; - while (cur != NULL) { - xmlAttrDumpOutput(ctxt, cur); - cur = cur->next; - } -} - - - -/** - * xmlNodeListDumpOutput: - * @cur: the first node - * - * Dump an XML node list, recursive behaviour, children are printed too. - */ -static void -xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { - xmlOutputBufferPtr buf; - - if (cur == NULL) return; - buf = ctxt->buf; - while (cur != NULL) { - if ((ctxt->format == 1) && (xmlIndentTreeOutput) && - ((cur->type == XML_ELEMENT_NODE) || - (cur->type == XML_COMMENT_NODE) || - (cur->type == XML_PI_NODE))) - xmlOutputBufferWrite(buf, ctxt->indent_size * - (ctxt->level > ctxt->indent_nr ? - ctxt->indent_nr : ctxt->level), - ctxt->indent); - xmlNodeDumpOutputInternal(ctxt, cur); - if (ctxt->format == 1) { - xmlOutputBufferWrite(buf, 1, "\n"); - } - cur = cur->next; - } -} - -/** - * xmlNodeDumpOutputInternal: - * @cur: the current node - * - * Dump an XML node, recursive behaviour, children are printed too. - */ -static void -xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { - int format; - xmlNodePtr tmp; - xmlChar *start, *end; - xmlOutputBufferPtr buf; - - if (cur == NULL) return; - buf = ctxt->buf; - if (cur->type == XML_XINCLUDE_START) - return; - if (cur->type == XML_XINCLUDE_END) - return; - if ((cur->type == XML_DOCUMENT_NODE) || - (cur->type == XML_HTML_DOCUMENT_NODE)) { - xmlDocContentDumpOutput(ctxt, (xmlDocPtr) cur); - return; - } - if (cur->type == XML_DTD_NODE) { - xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur); - return; - } - if (cur->type == XML_DOCUMENT_FRAG_NODE) { - xmlNodeListDumpOutput(ctxt, cur->children); - return; - } - if (cur->type == XML_ELEMENT_DECL) { - xmlDumpElementDecl(buf->buffer, (xmlElementPtr) cur); - return; - } - if (cur->type == XML_ATTRIBUTE_DECL) { - xmlDumpAttributeDecl(buf->buffer, (xmlAttributePtr) cur); - return; - } - if (cur->type == XML_ENTITY_DECL) { - xmlDumpEntityDecl(buf->buffer, (xmlEntityPtr) cur); - return; - } - if (cur->type == XML_TEXT_NODE) { - if (cur->content != NULL) { - if (cur->name != xmlStringTextNoenc) { - xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); - } else { - /* - * Disable escaping, needed for XSLT - */ - xmlOutputBufferWriteString(buf, (const char *) cur->content); - } - } - - return; - } - if (cur->type == XML_PI_NODE) { - if (cur->content != NULL) { - xmlOutputBufferWrite(buf, 2, "name); - if (cur->content != NULL) { - if (ctxt->format == 2) - xmlOutputBufferWriteWSNonSig(ctxt, 0); - else - xmlOutputBufferWrite(buf, 1, " "); - xmlOutputBufferWriteString(buf, (const char *)cur->content); - } - xmlOutputBufferWrite(buf, 2, "?>"); - } else { - xmlOutputBufferWrite(buf, 2, "name); - if (ctxt->format == 2) - xmlOutputBufferWriteWSNonSig(ctxt, 0); - xmlOutputBufferWrite(buf, 2, "?>"); - } - return; - } - if (cur->type == XML_COMMENT_NODE) { - if (cur->content != NULL) { - xmlOutputBufferWrite(buf, 4, ""); - } - return; - } - if (cur->type == XML_ENTITY_REF_NODE) { - xmlOutputBufferWrite(buf, 1, "&"); - xmlOutputBufferWriteString(buf, (const char *)cur->name); - xmlOutputBufferWrite(buf, 1, ";"); - return; - } - if (cur->type == XML_CDATA_SECTION_NODE) { - if (cur->content == NULL || *cur->content == '\0') { - xmlOutputBufferWrite(buf, 12, ""); - } else { - start = end = cur->content; - while (*end != '\0') { - if ((*end == ']') && (*(end + 1) == ']') && - (*(end + 2) == '>')) { - end = end + 2; - xmlOutputBufferWrite(buf, 9, ""); - start = end; - } - end++; - } - if (start != end) { - xmlOutputBufferWrite(buf, 9, ""); - } - } - return; - } - if (cur->type == XML_ATTRIBUTE_NODE) { - xmlAttrDumpOutput(ctxt, (xmlAttrPtr) cur); - return; - } - if (cur->type == XML_NAMESPACE_DECL) { - xmlNsDumpOutputCtxt(ctxt, (xmlNsPtr) cur); - return; - } - - format = ctxt->format; - if (format == 1) { - tmp = cur->children; - while (tmp != NULL) { - if ((tmp->type == XML_TEXT_NODE) || - (tmp->type == XML_CDATA_SECTION_NODE) || - (tmp->type == XML_ENTITY_REF_NODE)) { - ctxt->format = 0; - break; - } - tmp = tmp->next; - } - } - xmlOutputBufferWrite(buf, 1, "<"); - if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { - xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); - xmlOutputBufferWrite(buf, 1, ":"); - } - - xmlOutputBufferWriteString(buf, (const char *)cur->name); - if (cur->nsDef) - xmlNsListDumpOutputCtxt(ctxt, cur->nsDef); - if (cur->properties != NULL) - xmlAttrListDumpOutput(ctxt, cur->properties); - - if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) && - (cur->children == NULL) && ((ctxt->options & XML_SAVE_NO_EMPTY) == 0)) { - if (ctxt->format == 2) - xmlOutputBufferWriteWSNonSig(ctxt, 0); - xmlOutputBufferWrite(buf, 2, "/>"); - ctxt->format = format; - return; - } - if (ctxt->format == 2) - xmlOutputBufferWriteWSNonSig(ctxt, 1); - xmlOutputBufferWrite(buf, 1, ">"); - if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { - xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape); - } - if (cur->children != NULL) { - if (ctxt->format == 1) xmlOutputBufferWrite(buf, 1, "\n"); - if (ctxt->level >= 0) ctxt->level++; - xmlNodeListDumpOutput(ctxt, cur->children); - if (ctxt->level > 0) ctxt->level--; - if ((xmlIndentTreeOutput) && (ctxt->format == 1)) - xmlOutputBufferWrite(buf, ctxt->indent_size * - (ctxt->level > ctxt->indent_nr ? - ctxt->indent_nr : ctxt->level), - ctxt->indent); - } - xmlOutputBufferWrite(buf, 2, "ns != NULL) && (cur->ns->prefix != NULL)) { - xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); - xmlOutputBufferWrite(buf, 1, ":"); - } - - xmlOutputBufferWriteString(buf, (const char *)cur->name); - if (ctxt->format == 2) - xmlOutputBufferWriteWSNonSig(ctxt, 0); - xmlOutputBufferWrite(buf, 1, ">"); - ctxt->format = format; -} - -/** - * xmlDocContentDumpOutput: - * @cur: the document - * - * Dump an XML document. - */ -static int -xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur) { - const xmlChar *oldenc = cur->encoding; - const xmlChar *oldctxtenc = ctxt->encoding; - const xmlChar *encoding = ctxt->encoding; - xmlCharEncodingOutputFunc oldescape = ctxt->escape; - xmlCharEncodingOutputFunc oldescapeAttr = ctxt->escapeAttr; - xmlOutputBufferPtr buf = ctxt->buf; - xmlCharEncoding enc; - int switched_encoding = 0; - - xmlInitParser(); - - if ((cur->type != XML_HTML_DOCUMENT_NODE) && - (cur->type != XML_DOCUMENT_NODE)) - return(-1); - - if (ctxt->encoding != NULL) { - cur->encoding = BAD_CAST ctxt->encoding; - } else if (cur->encoding != NULL) { - encoding = cur->encoding; - } else if (cur->charset != XML_CHAR_ENCODING_UTF8) { - encoding = (const xmlChar *) - xmlGetCharEncodingName((xmlCharEncoding) cur->charset); - } - - if (((cur->type == XML_HTML_DOCUMENT_NODE) && - ((ctxt->options & XML_SAVE_AS_XML) == 0) && - ((ctxt->options & XML_SAVE_XHTML) == 0)) || - (ctxt->options & XML_SAVE_AS_HTML)) { - return(-1); - } else if ((cur->type == XML_DOCUMENT_NODE) || - (ctxt->options & XML_SAVE_AS_XML) || - (ctxt->options & XML_SAVE_XHTML)) { - enc = xmlParseCharEncoding((const char*) encoding); - if ((encoding != NULL) && (oldctxtenc == NULL) && - (buf->encoder == NULL) && (buf->conv == NULL) && - ((ctxt->options & XML_SAVE_NO_DECL) == 0)) { - if ((enc != XML_CHAR_ENCODING_UTF8) && - (enc != XML_CHAR_ENCODING_NONE) && - (enc != XML_CHAR_ENCODING_ASCII)) { - /* - * we need to switch to this encoding but just for this - * document since we output the XMLDecl the conversion - * must be done to not generate not well formed documents. - */ - if (xmlSaveSwitchEncoding(ctxt, (const char*) encoding) < 0) { - cur->encoding = oldenc; - return(-1); - } - switched_encoding = 1; - } - if (ctxt->escape == xmlEscapeEntities) - ctxt->escape = NULL; - if (ctxt->escapeAttr == xmlEscapeEntities) - ctxt->escapeAttr = NULL; - } - - - /* - * Save the XML declaration - */ - if ((ctxt->options & XML_SAVE_NO_DECL) == 0) { - xmlOutputBufferWrite(buf, 14, "version != NULL) - xmlBufferWriteQuotedString(buf->buffer, cur->version); - else - xmlOutputBufferWrite(buf, 5, "\"1.0\""); - if (encoding != NULL) { - xmlOutputBufferWrite(buf, 10, " encoding="); - xmlBufferWriteQuotedString(buf->buffer, (xmlChar *) encoding); - } - switch (cur->standalone) { - case 0: - xmlOutputBufferWrite(buf, 16, " standalone=\"no\""); - break; - case 1: - xmlOutputBufferWrite(buf, 17, " standalone=\"yes\""); - break; - } - xmlOutputBufferWrite(buf, 3, "?>\n"); - } - - if (cur->children != NULL) { - xmlNodePtr child = cur->children; - - while (child != NULL) { - ctxt->level = 0; - xmlNodeDumpOutputInternal(ctxt, child); - xmlOutputBufferWrite(buf, 1, "\n"); - child = child->next; - } - } - } - - /* - * Restore the state of the saving context at the end of the document - */ - if ((switched_encoding) && (oldctxtenc == NULL)) { - xmlSaveClearEncoding(ctxt); - ctxt->escape = oldescape; - ctxt->escapeAttr = oldescapeAttr; - } - cur->encoding = oldenc; - return(0); -} - -/************************************************************************ - * * - * Public entry points * - * * - ************************************************************************/ - -/** - * xmlSaveToFd: - * @fd: a file descriptor number - * @encoding: the encoding name to use or NULL - * @options: a set of xmlSaveOptions - * - * Create a document saving context serializing to a file descriptor - * with the encoding and the options given. - * - * Returns a new serialization context or NULL in case of error. - */ -xmlSaveCtxtPtr -xmlSaveToFd(int fd, const char *encoding, int options) -{ - xmlSaveCtxtPtr ret; - - ret = xmlNewSaveCtxt(encoding, options); - if (ret == NULL) return(NULL); - ret->buf = xmlOutputBufferCreateFd(fd, ret->handler); - if (ret->buf == NULL) { - xmlFreeSaveCtxt(ret); - return(NULL); - } - return(ret); -} - -/** - * xmlSaveToFilename: - * @filename: a file name or an URL - * @encoding: the encoding name to use or NULL - * @options: a set of xmlSaveOptions - * - * Create a document saving context serializing to a filename or possibly - * to an URL (but this is less reliable) with the encoding and the options - * given. - * - * Returns a new serialization context or NULL in case of error. - */ -xmlSaveCtxtPtr -xmlSaveToFilename(const char *filename, const char *encoding, int options) -{ - xmlSaveCtxtPtr ret; - int compression = 0; /* TODO handle compression option */ - - ret = xmlNewSaveCtxt(encoding, options); - if (ret == NULL) return(NULL); - ret->buf = xmlOutputBufferCreateFilename(filename, ret->handler, - compression); - if (ret->buf == NULL) { - xmlFreeSaveCtxt(ret); - return(NULL); - } - return(ret); -} - -/** - * xmlSaveToBuffer: - * @buffer: a buffer - * @encoding: the encoding name to use or NULL - * @options: a set of xmlSaveOptions - * - * Create a document saving context serializing to a buffer - * with the encoding and the options given - * - * Returns a new serialization context or NULL in case of error. - */ - -xmlSaveCtxtPtr -xmlSaveToBuffer(xmlBufferPtr buffer, const char *encoding, int options) -{ - xmlSaveCtxtPtr ret; - xmlOutputBufferPtr out_buff; - xmlCharEncodingHandlerPtr handler; - - ret = xmlNewSaveCtxt(encoding, options); - if (ret == NULL) return(NULL); - - if (encoding != NULL) { - handler = xmlFindCharEncodingHandler(encoding); - if (handler == NULL) { - xmlFree(ret); - return(NULL); - } - } else - handler = NULL; - out_buff = xmlOutputBufferCreateBuffer(buffer, handler); - if (out_buff == NULL) { - xmlFree(ret); - if (handler) xmlCharEncCloseFunc(handler); - return(NULL); - } - - ret->buf = out_buff; - return(ret); -} - -/** - * xmlSaveToIO: - * @iowrite: an I/O write function - * @ioclose: an I/O close function - * @ioctx: an I/O handler - * @encoding: the encoding name to use or NULL - * @options: a set of xmlSaveOptions - * - * Create a document saving context serializing to a file descriptor - * with the encoding and the options given - * - * Returns a new serialization context or NULL in case of error. - */ -xmlSaveCtxtPtr -xmlSaveToIO(xmlOutputWriteCallback iowrite, - xmlOutputCloseCallback ioclose, - void *ioctx, const char *encoding, int options) -{ - xmlSaveCtxtPtr ret; - - ret = xmlNewSaveCtxt(encoding, options); - if (ret == NULL) return(NULL); - ret->buf = xmlOutputBufferCreateIO(iowrite, ioclose, ioctx, ret->handler); - if (ret->buf == NULL) { - xmlFreeSaveCtxt(ret); - return(NULL); - } - return(ret); -} - -/** - * xmlSaveDoc: - * @ctxt: a document saving context - * @doc: a document - * - * Save a full document to a saving context - * TODO: The function is not fully implemented yet as it does not return the - * byte count but 0 instead - * - * Returns the number of byte written or -1 in case of error - */ -long -xmlSaveDoc(xmlSaveCtxtPtr ctxt, xmlDocPtr doc) -{ - long ret = 0; - - if ((ctxt == NULL) || (doc == NULL)) return(-1); - if (xmlDocContentDumpOutput(ctxt, doc) < 0) - return(-1); - return(ret); -} - -/** - * xmlSaveTree: - * @ctxt: a document saving context - * @node: the top node of the subtree to save - * - * Save a subtree starting at the node parameter to a saving context - * TODO: The function is not fully implemented yet as it does not return the - * byte count but 0 instead - * - * Returns the number of byte written or -1 in case of error - */ -long -xmlSaveTree(xmlSaveCtxtPtr ctxt, xmlNodePtr node) -{ - long ret = 0; - - if ((ctxt == NULL) || (node == NULL)) return(-1); - xmlNodeDumpOutputInternal(ctxt, node); - return(ret); -} - -/** - * xmlSaveFlush: - * @ctxt: a document saving context - * - * Flush a document saving context, i.e. make sure that all bytes have - * been output. - * - * Returns the number of byte written or -1 in case of error. - */ -int -xmlSaveFlush(xmlSaveCtxtPtr ctxt) -{ - if (ctxt == NULL) return(-1); - if (ctxt->buf == NULL) return(-1); - return(xmlOutputBufferFlush(ctxt->buf)); -} - -/** - * xmlSaveClose: - * @ctxt: a document saving context - * - * Close a document saving context, i.e. make sure that all bytes have - * been output and free the associated data. - * - * Returns the number of byte written or -1 in case of error. - */ -int -xmlSaveClose(xmlSaveCtxtPtr ctxt) -{ - int ret; - - if (ctxt == NULL) return(-1); - ret = xmlSaveFlush(ctxt); - xmlFreeSaveCtxt(ctxt); - return(ret); -} - -/** - * xmlSaveSetEscape: - * @ctxt: a document saving context - * @escape: the escaping function - * - * Set a custom escaping function to be used for text in element content - * - * Returns 0 if successful or -1 in case of error. - */ -int -xmlSaveSetEscape(xmlSaveCtxtPtr ctxt, xmlCharEncodingOutputFunc escape) -{ - if (ctxt == NULL) return(-1); - ctxt->escape = escape; - return(0); -} - -/** - * xmlSaveSetAttrEscape: - * @ctxt: a document saving context - * @escape: the escaping function - * - * Set a custom escaping function to be used for text in attribute content - * - * Returns 0 if successful or -1 in case of error. - */ -int -xmlSaveSetAttrEscape(xmlSaveCtxtPtr ctxt, xmlCharEncodingOutputFunc escape) -{ - if (ctxt == NULL) return(-1); - ctxt->escapeAttr = escape; - return(0); -} - -/************************************************************************ - * * - * Public entry points based on buffers * - * * - ************************************************************************/ -/** - * xmlAttrSerializeTxtContent: - * @buf: the XML buffer output - * @doc: the document - * @attr: the attribute node - * @string: the text content - * - * Serialize text attribute values to an xml simple buffer - */ -void -xmlAttrSerializeTxtContent(xmlBufferPtr buf, xmlDocPtr doc, - xmlAttrPtr attr, const xmlChar * string) -{ - xmlChar *base, *cur; - - if (string == NULL) - return; - base = cur = (xmlChar *) string; - while (*cur != 0) { - if (*cur == '\n') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST " ", 5); - cur++; - base = cur; - } else if (*cur == '\r') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST " ", 5); - cur++; - base = cur; - } else if (*cur == '\t') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST " ", 4); - cur++; - base = cur; - } else if (*cur == '"') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST """, 6); - cur++; - base = cur; - } else if (*cur == '<') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST "<", 4); - cur++; - base = cur; - } else if (*cur == '>') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST ">", 4); - cur++; - base = cur; - } else if (*cur == '&') { - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - xmlBufferAdd(buf, BAD_CAST "&", 5); - cur++; - base = cur; - } else if ((*cur >= 0x80) && ((doc == NULL) || - (doc->encoding == NULL))) { - /* - * We assume we have UTF-8 content. - */ - unsigned char tmp[12]; - int val = 0, l = 1; - - if (base != cur) - xmlBufferAdd(buf, base, cur - base); - if (*cur < 0xC0) { - xmlSaveErr(XML_SAVE_NOT_UTF8, (xmlNodePtr) attr, NULL); - if (doc != NULL) - doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); - xmlSerializeHexCharRef(tmp, *cur); - xmlBufferAdd(buf, (xmlChar *) tmp, -1); - cur++; - base = cur; - continue; - } else if (*cur < 0xE0) { - val = (cur[0]) & 0x1F; - val <<= 6; - val |= (cur[1]) & 0x3F; - l = 2; - } else if (*cur < 0xF0) { - val = (cur[0]) & 0x0F; - val <<= 6; - val |= (cur[1]) & 0x3F; - val <<= 6; - val |= (cur[2]) & 0x3F; - l = 3; - } else if (*cur < 0xF8) { - val = (cur[0]) & 0x07; - val <<= 6; - val |= (cur[1]) & 0x3F; - val <<= 6; - val |= (cur[2]) & 0x3F; - val <<= 6; - val |= (cur[3]) & 0x3F; - l = 4; - } - if ((l == 1) || (!IS_CHAR(val))) { - xmlSaveErr(XML_SAVE_CHAR_INVALID, (xmlNodePtr) attr, NULL); - if (doc != NULL) - doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); - - xmlSerializeHexCharRef(tmp, *cur); - xmlBufferAdd(buf, (xmlChar *) tmp, -1); - cur++; - base = cur; - continue; - } - /* - * We could do multiple things here. Just save - * as a char ref - */ - xmlSerializeHexCharRef(tmp, val); - xmlBufferAdd(buf, (xmlChar *) tmp, -1); - cur += l; - base = cur; - } else { - cur++; - } - } - if (base != cur) - xmlBufferAdd(buf, base, cur - base); -} - -/** - * xmlNodeDump: - * @buf: the XML buffer output - * @doc: the document - * @cur: the current node - * @level: the imbrication level for indenting - * @format: is formatting allowed - * - * Dump an XML node, recursive behaviour,children are printed too. - * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 - * or xmlKeepBlanksDefault(0) was called - * - * Returns the number of bytes written to the buffer or -1 in case of error - */ -int -xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, - int format) -{ - unsigned int use; - int ret; - xmlOutputBufferPtr outbuf; - - xmlInitParser(); - - if (cur == NULL) { -#ifdef DEBUG_TREE - xmlGenericError(xmlGenericErrorContext, - "xmlNodeDump : node == NULL\n"); -#endif - return (-1); - } - if (buf == NULL) { -#ifdef DEBUG_TREE - xmlGenericError(xmlGenericErrorContext, - "xmlNodeDump : buf == NULL\n"); -#endif - return (-1); - } - outbuf = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); - if (outbuf == NULL) { - xmlSaveErrMemory("creating buffer"); - return (-1); - } - memset(outbuf, 0, (size_t) sizeof(xmlOutputBuffer)); - outbuf->buffer = buf; - outbuf->encoder = NULL; - outbuf->writecallback = NULL; - outbuf->closecallback = NULL; - outbuf->context = NULL; - outbuf->written = 0; - - use = buf->use; - xmlNodeDumpOutput(outbuf, doc, cur, level, format, NULL); - xmlFree(outbuf); - ret = buf->use - use; - return (ret); -} - -/** - * xmlElemDump: - * @f: the FILE * for the output - * @doc: the document - * @cur: the current node - * - * Dump an XML/HTML node, recursive behaviour, children are printed too. - */ -void -xmlElemDump(FILE * f, xmlDocPtr doc, xmlNodePtr cur) -{ - xmlOutputBufferPtr outbuf; - - xmlInitParser(); - - if (cur == NULL) { -#ifdef DEBUG_TREE - xmlGenericError(xmlGenericErrorContext, - "xmlElemDump : cur == NULL\n"); -#endif - return; - } -#ifdef DEBUG_TREE - if (doc == NULL) { - xmlGenericError(xmlGenericErrorContext, - "xmlElemDump : doc == NULL\n"); - } -#endif - - outbuf = xmlOutputBufferCreateFile(f, NULL); - if (outbuf == NULL) - return; - if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { - xmlSaveErr(XML_ERR_INTERNAL_ERROR, cur, "HTML support not compiled in\n"); - } else - xmlNodeDumpOutput(outbuf, doc, cur, 0, 1, NULL); - xmlOutputBufferClose(outbuf); -} - -/************************************************************************ - * * - * Saving functions front-ends * - * * - ************************************************************************/ - -/** - * xmlNodeDumpOutput: - * @buf: the XML buffer output - * @doc: the document - * @cur: the current node - * @level: the imbrication level for indenting - * @format: is formatting allowed - * @encoding: an optional encoding string - * - * Dump an XML node, recursive behaviour, children are printed too. - * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 - * or xmlKeepBlanksDefault(0) was called - */ -void -xmlNodeDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, - int level, int format, const char *encoding) -{ - xmlSaveCtxt ctxt; - - xmlInitParser(); - - if ((buf == NULL) || (cur == NULL)) return; - - if (encoding == NULL) - encoding = "UTF-8"; - - memset(&ctxt, 0, sizeof(ctxt)); - ctxt.doc = doc; - ctxt.buf = buf; - ctxt.level = level; - ctxt.format = format ? 1 : 0; - ctxt.encoding = (const xmlChar *) encoding; - xmlSaveCtxtInit(&ctxt); - ctxt.options |= XML_SAVE_AS_XML; - - xmlNodeDumpOutputInternal(&ctxt, cur); -} - -/** - * xmlDocDumpFormatMemoryEnc: - * @out_doc: Document to generate XML text from - * @doc_txt_ptr: Memory pointer for allocated XML text - * @doc_txt_len: Length of the generated XML text - * @txt_encoding: Character encoding to use when generating XML text - * @format: should formatting spaces been added - * - * Dump the current DOM tree into memory using the character encoding specified - * by the caller. Note it is up to the caller of this function to free the - * allocated memory with xmlFree(). - * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 - * or xmlKeepBlanksDefault(0) was called - */ - -void -xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr, - int * doc_txt_len, const char * txt_encoding, - int format) { - xmlSaveCtxt ctxt; - int dummy = 0; - xmlOutputBufferPtr out_buff = NULL; - xmlCharEncodingHandlerPtr conv_hdlr = NULL; - - if (doc_txt_len == NULL) { - doc_txt_len = &dummy; /* Continue, caller just won't get length */ - } - - if (doc_txt_ptr == NULL) { - *doc_txt_len = 0; - return; - } - - *doc_txt_ptr = NULL; - *doc_txt_len = 0; - - if (out_doc == NULL) { - /* No document, no output */ - return; - } - - /* - * Validate the encoding value, if provided. - * This logic is copied from xmlSaveFileEnc. - */ - - if (txt_encoding == NULL) - txt_encoding = (const char *) out_doc->encoding; - if (txt_encoding != NULL) { - conv_hdlr = xmlFindCharEncodingHandler(txt_encoding); - if ( conv_hdlr == NULL ) { - xmlSaveErr(XML_SAVE_UNKNOWN_ENCODING, (xmlNodePtr) out_doc, - txt_encoding); - return; - } - } - - if ((out_buff = xmlAllocOutputBuffer(conv_hdlr)) == NULL ) { - xmlSaveErrMemory("creating buffer"); - return; - } - - memset(&ctxt, 0, sizeof(ctxt)); - ctxt.doc = out_doc; - ctxt.buf = out_buff; - ctxt.level = 0; - ctxt.format = format ? 1 : 0; - ctxt.encoding = (const xmlChar *) txt_encoding; - xmlSaveCtxtInit(&ctxt); - ctxt.options |= XML_SAVE_AS_XML; - xmlDocContentDumpOutput(&ctxt, out_doc); - xmlOutputBufferFlush(out_buff); - if (out_buff->conv != NULL) { - *doc_txt_len = out_buff->conv->use; - *doc_txt_ptr = xmlStrndup(out_buff->conv->content, *doc_txt_len); - } else { - *doc_txt_len = out_buff->buffer->use; - *doc_txt_ptr = xmlStrndup(out_buff->buffer->content, *doc_txt_len); - } - (void)xmlOutputBufferClose(out_buff); - - if ((*doc_txt_ptr == NULL) && (*doc_txt_len > 0)) { - *doc_txt_len = 0; - xmlSaveErrMemory("creating output"); - } - - return; -} - -/** - * xmlDocDumpMemory: - * @cur: the document - * @mem: OUT: the memory pointer - * @size: OUT: the memory length - * - * Dump an XML document in memory and return the #xmlChar * and it's size - * in bytes. It's up to the caller to free the memory with xmlFree(). - * The resulting byte array is zero terminated, though the last 0 is not - * included in the returned size. - */ -void -xmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { - xmlDocDumpFormatMemoryEnc(cur, mem, size, NULL, 0); -} - -/** - * xmlDocDumpFormatMemory: - * @cur: the document - * @mem: OUT: the memory pointer - * @size: OUT: the memory length - * @format: should formatting spaces been added - * - * - * Dump an XML document in memory and return the #xmlChar * and it's size. - * It's up to the caller to free the memory with xmlFree(). - * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 - * or xmlKeepBlanksDefault(0) was called - */ -void -xmlDocDumpFormatMemory(xmlDocPtr cur, xmlChar**mem, int *size, int format) { - xmlDocDumpFormatMemoryEnc(cur, mem, size, NULL, format); -} - -/** - * xmlDocDumpMemoryEnc: - * @out_doc: Document to generate XML text from - * @doc_txt_ptr: Memory pointer for allocated XML text - * @doc_txt_len: Length of the generated XML text - * @txt_encoding: Character encoding to use when generating XML text - * - * Dump the current DOM tree into memory using the character encoding specified - * by the caller. Note it is up to the caller of this function to free the - * allocated memory with xmlFree(). - */ - -void -xmlDocDumpMemoryEnc(xmlDocPtr out_doc, xmlChar **doc_txt_ptr, - int * doc_txt_len, const char * txt_encoding) { - xmlDocDumpFormatMemoryEnc(out_doc, doc_txt_ptr, doc_txt_len, - txt_encoding, 0); -} - -/** - * xmlDocFormatDump: - * @f: the FILE* - * @cur: the document - * @format: should formatting spaces been added - * - * Dump an XML document to an open FILE. - * - * returns: the number of bytes written or -1 in case of failure. - * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 - * or xmlKeepBlanksDefault(0) was called - */ -int -xmlDocFormatDump(FILE *f, xmlDocPtr cur, int format) { - xmlSaveCtxt ctxt; - xmlOutputBufferPtr buf; - const char * encoding; - xmlCharEncodingHandlerPtr handler = NULL; - int ret; - - if (cur == NULL) { -#ifdef DEBUG_TREE - xmlGenericError(xmlGenericErrorContext, - "xmlDocDump : document == NULL\n"); -#endif - return(-1); - } - encoding = (const char *) cur->encoding; - - if (encoding != NULL) { - handler = xmlFindCharEncodingHandler(encoding); - if (handler == NULL) { - xmlFree((char *) cur->encoding); - cur->encoding = NULL; - encoding = NULL; - } - } - buf = xmlOutputBufferCreateFile(f, handler); - if (buf == NULL) return(-1); - memset(&ctxt, 0, sizeof(ctxt)); - ctxt.doc = cur; - ctxt.buf = buf; - ctxt.level = 0; - ctxt.format = format ? 1 : 0; - ctxt.encoding = (const xmlChar *) encoding; - xmlSaveCtxtInit(&ctxt); - ctxt.options |= XML_SAVE_AS_XML; - xmlDocContentDumpOutput(&ctxt, cur); - - ret = xmlOutputBufferClose(buf); - return(ret); -} - -/** - * xmlDocDump: - * @f: the FILE* - * @cur: the document - * - * Dump an XML document to an open FILE. - * - * returns: the number of bytes written or -1 in case of failure. - */ -int -xmlDocDump(FILE *f, xmlDocPtr cur) { - return(xmlDocFormatDump (f, cur, 0)); -} - -/** - * xmlSaveFileTo: - * @buf: an output I/O buffer - * @cur: the document - * @encoding: the encoding if any assuming the I/O layer handles the trancoding - * - * Dump an XML document to an I/O buffer. - * Warning ! This call xmlOutputBufferClose() on buf which is not available - * after this call. - * - * returns: the number of bytes written or -1 in case of failure. - */ -int -xmlSaveFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding) { - xmlSaveCtxt ctxt; - int ret; - - if (buf == NULL) return(-1); - if (cur == NULL) { - xmlOutputBufferClose(buf); - return(-1); - } - memset(&ctxt, 0, sizeof(ctxt)); - ctxt.doc = cur; - ctxt.buf = buf; - ctxt.level = 0; - ctxt.format = 0; - ctxt.encoding = (const xmlChar *) encoding; - xmlSaveCtxtInit(&ctxt); - ctxt.options |= XML_SAVE_AS_XML; - xmlDocContentDumpOutput(&ctxt, cur); - ret = xmlOutputBufferClose(buf); - return(ret); -} - -/** - * xmlSaveFormatFileTo: - * @buf: an output I/O buffer - * @cur: the document - * @encoding: the encoding if any assuming the I/O layer handles the trancoding - * @format: should formatting spaces been added - * - * Dump an XML document to an I/O buffer. - * Warning ! This call xmlOutputBufferClose() on buf which is not available - * after this call. - * - * returns: the number of bytes written or -1 in case of failure. - */ -int -xmlSaveFormatFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, - const char *encoding, int format) -{ - xmlSaveCtxt ctxt; - int ret; - - if (buf == NULL) return(-1); - if ((cur == NULL) || - ((cur->type != XML_DOCUMENT_NODE) && - (cur->type != XML_HTML_DOCUMENT_NODE))) { - xmlOutputBufferClose(buf); - return(-1); - } - memset(&ctxt, 0, sizeof(ctxt)); - ctxt.doc = cur; - ctxt.buf = buf; - ctxt.level = 0; - ctxt.format = format ? 1 : 0; - ctxt.encoding = (const xmlChar *) encoding; - xmlSaveCtxtInit(&ctxt); - ctxt.options |= XML_SAVE_AS_XML; - xmlDocContentDumpOutput(&ctxt, cur); - ret = xmlOutputBufferClose(buf); - return (ret); -} - -/** - * xmlSaveFormatFileEnc: - * @filename: the filename or URL to output - * @cur: the document being saved - * @encoding: the name of the encoding to use or NULL. - * @format: should formatting spaces be added. - * - * Dump an XML document to a file or an URL. - * - * Returns the number of bytes written or -1 in case of error. - * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 - * or xmlKeepBlanksDefault(0) was called - */ -int -xmlSaveFormatFileEnc( const char * filename, xmlDocPtr cur, - const char * encoding, int format ) { - xmlSaveCtxt ctxt; - xmlOutputBufferPtr buf; - xmlCharEncodingHandlerPtr handler = NULL; - int ret; - - if (cur == NULL) - return(-1); - - if (encoding == NULL) - encoding = (const char *) cur->encoding; - - if (encoding != NULL) { - - handler = xmlFindCharEncodingHandler(encoding); - if (handler == NULL) - return(-1); - } - -#ifdef HAVE_ZLIB_H - if (cur->compression < 0) cur->compression = xmlGetCompressMode(); -#endif - /* - * save the content to a temp buffer. - */ - buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression); - if (buf == NULL) return(-1); - memset(&ctxt, 0, sizeof(ctxt)); - ctxt.doc = cur; - ctxt.buf = buf; - ctxt.level = 0; - ctxt.format = format ? 1 : 0; - ctxt.encoding = (const xmlChar *) encoding; - xmlSaveCtxtInit(&ctxt); - ctxt.options |= XML_SAVE_AS_XML; - - xmlDocContentDumpOutput(&ctxt, cur); - - ret = xmlOutputBufferClose(buf); - return(ret); -} - - -/** - * xmlSaveFileEnc: - * @filename: the filename (or URL) - * @cur: the document - * @encoding: the name of an encoding (or NULL) - * - * Dump an XML document, converting it to the given encoding - * - * returns: the number of bytes written or -1 in case of failure. - */ -int -xmlSaveFileEnc(const char *filename, xmlDocPtr cur, const char *encoding) { - return ( xmlSaveFormatFileEnc( filename, cur, encoding, 0 ) ); -} - -/** - * xmlSaveFormatFile: - * @filename: the filename (or URL) - * @cur: the document - * @format: should formatting spaces been added - * - * Dump an XML document to a file. Will use compression if - * compiled in and enabled. If @filename is "-" the stdout file is - * used. If @format is set then the document will be indented on output. - * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 - * or xmlKeepBlanksDefault(0) was called - * - * returns: the number of bytes written or -1 in case of failure. - */ -int -xmlSaveFormatFile(const char *filename, xmlDocPtr cur, int format) { - return ( xmlSaveFormatFileEnc( filename, cur, NULL, format ) ); -} - -/** - * xmlSaveFile: - * @filename: the filename (or URL) - * @cur: the document - * - * Dump an XML document to a file. Will use compression if - * compiled in and enabled. If @filename is "-" the stdout file is - * used. - * returns: the number of bytes written or -1 in case of failure. - */ -int -xmlSaveFile(const char *filename, xmlDocPtr cur) { - return(xmlSaveFormatFileEnc(filename, cur, NULL, 0)); -} - -#endif /* LIBXML_OUTPUT_ENABLED */ - #define bottom_xmlsave #include "elfgcchack.h"