c14n.c revision 38ae7e4efe803ea78b6499cd05a394db32623e41
/*
* "Canonical XML" implementation
*
* "Exclusive XML Canonicalization" implementation
*
* See Copyright for the status of this software.
*
* Author: Aleksey Sanin <aleksey@aleksey.com>
*/
#define IN_LIBXML
#include "libxml.h"
#ifdef LIBXML_C14N_ENABLED
#ifdef LIBXML_OUTPUT_ENABLED
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#include <libxml/xmlerror.h>
#include <libxml/xpathInternals.h>
/************************************************************************
* *
* Some declaration better left private ATM *
* *
************************************************************************/
typedef enum {
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 */
typedef struct _xmlC14NCtx {
/* input parameters */
void* user_data;
int with_comments;
/* position in the XML document */
int parent_is_doc;
/* exclusive canonicalization */
int exclusive;
/* error number */
int error;
} xmlC14NCtx, *xmlC14NCtxPtr;
static xmlC14NVisibleNsStackPtr xmlC14NVisibleNsStackCreate (void);
typedef enum {
XMLC14N_NORMALIZE_PI = 2,
#define xmlC11NNormalizeAttr( a ) \
#define xmlC11NNormalizeComment( a ) \
#define xmlC11NNormalizePI( a ) \
#define xmlC11NNormalizeText( a ) \
/************************************************************************
* *
* Some factorized error routines *
* *
************************************************************************/
/**
* xmlC14NErrMemory:
* @extra: extra informations
*
* Handle a redefinition of memory error
*/
static void
xmlC14NErrMemory(const char *extra)
{
"Memory allocation failed : %s\n", extra);
}
/**
* xmlC14NErrParam:
* @extra: extra informations
*
* Handle a redefinition of param error
*/
static void
xmlC14NErrParam(const char *extra)
{
"Invalid parameter : %s\n", extra);
}
/**
* xmlC14NErrInternal:
* @extra: extra informations
*
* Handle a redefinition of internal error
*/
static void
xmlC14NErrInternal(const char *extra)
{
"Internal error : %s\n", extra);
}
/**
* xmlC14NErrInvalidNode:
* @extra: extra informations
*
* Handle a redefinition of invalid node error
*/
static void
{
}
/**
* xmlC14NErrUnknownNode:
* @extra: extra informations
*
* Handle a redefinition of unknown node error
*/
static void
{
}
/**
* xmlC14NErrRelativeNamespace:
* @extra: extra informations
*
* Handle a redefinition of relative namespace error
*/
static void
xmlC14NErrRelativeNamespace(const char *ns_uri)
{
"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
const char * msg)
{
XML_ERR_ERROR, NULL, 0,
}
/************************************************************************
* *
* The implementation internals *
* *
************************************************************************/
#define XML_NAMESPACES_DEFAULT 16
static int
} else {
/* this is a libxml hack! check xpath.c for details */
} else {
}
/*
* 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(1);
}
static xmlC14NVisibleNsStackPtr
xmlC14NVisibleNsStackCreate(void) {
xmlC14NErrMemory("creating namespaces stack");
return(NULL);
}
return(ret);
}
static void
xmlC14NErrParam("destroying namespaces stack");
return;
}
}
}
}
static void
xmlC14NErrParam("adding namespace to stack");
return;
}
xmlC14NErrMemory("adding node to stack");
return;
}
void *tmp;
int tmpSize;
xmlC14NErrMemory("adding node to stack");
return;
}
xmlC14NErrMemory("adding node to stack");
return;
}
}
}
static void
xmlC14NErrParam("saving namespaces stack");
return;
}
}
static void
xmlC14NErrParam("restoring namespaces stack");
return;
}
}
static void
xmlC14NErrParam("shifting namespaces stack");
return;
}
}
static int
do {
} 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
{
int i;
int has_empty_ns;
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
*/
}
}
}
return(has_empty_ns);
}
static int
int i;
int has_empty_ns;
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
*/
int start = 0;
} 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
{
}
/**
* 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
{
return (0);
return (-1);
return (1);
}
/**
* 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
{
xmlC14NErrParam("writing namespaces");
return 0;
}
} else {
}
}
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
{
xmlNodePtr n;
int already_rendered;
int has_empty_ns = 0;
xmlC14NErrParam("processing namespaces axis (c14n)");
return (-1);
}
/*
* Create a sorted list to store element namespaces
*/
xmlC14NErrInternal("creating namespaces list (c14n)");
return (-1);
}
/* check all namespaces */
if(visible) {
}
if(!already_rendered) {
}
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;
}
}
/*
* print out all elements from list
*/
/*
* Cleanup
*/
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
*
* 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
{
int already_rendered;
int has_empty_ns = 0;
int has_visibly_utilized_empty_ns = 0;
int has_empty_ns_in_inclusive_list = 0;
xmlC14NErrParam("processing namespaces axis (exc c14n)");
return (-1);
}
xmlC14NErrParam("processing namespaces axis (exc c14n)");
return (-1);
}
/*
* Create a sorted list to store element namespaces
*/
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
*/
int i;
/*
* Special values for namespace with empty prefix
*/
}
if(visible) {
}
if(!already_rendered) {
}
has_empty_ns = 1;
}
}
}
}
/* add node namespace */
} else {
}
}
}
if(visible) {
}
has_empty_ns = 1;
}
}
/* add attributes */
/*
* we need to check that attribute is visible and has non
* default namespace (XML Namespaces: "default namespaces
* do not apply directly to attributes")
*/
if(!already_rendered && visible) {
}
has_empty_ns = 1;
}
} else if((attr->ns != NULL) && (xmlStrlen(attr->ns->prefix) == 0) && (xmlStrlen(attr->ns->href) == 0)) {
}
}
/*
* Process xmlns=""
*/
if(visible && has_visibly_utilized_empty_ns &&
static xmlNs ns_default;
if(!already_rendered) {
}
static xmlNs ns_default;
}
}
/*
* print out all elements from list
*/
/*
* Cleanup
*/
return (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
{
int ret = 0;
/*
* Simple cases
*/
return (0);
return (-1);
return (1);
}
/*
* Attributes in the default namespace are first
* because the default namespace is not applied to
* unqualified attributes
*/
return (-1);
return (1);
return (-1);
return (1);
if (ret == 0) {
}
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
{
xmlC14NErrParam("writing attributes");
return (0);
}
}
/* todo: should we log an error if value==NULL ? */
} else {
xmlC14NErrInternal("normalizing attributes axis");
return (0);
}
}
return (1);
}
/**
* xmlC14NProcessAttrsAxis:
* @ctx: the C14N context
* @cur: the current node
* @parent_visible: the visibility of parent node
*
* 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
{
xmlC14NErrParam("processing attributes axis");
return (-1);
}
/*
* Create a sorted list to store element attributes
*/
xmlC14NErrInternal("creating attributes list");
return (-1);
}
/*
* Add all visible attributes from current node.
*/
/* check that attribute is visible */
}
}
/*
* include attributes in "xml" namespace defined in ancestors
* (only for non-exclusive XML Canonicalization)
*/
/*
* If XPath node-set is not specified then the parent is always
* visible!
*/
}
}
}
}
}
/*
* print out all elements from list
*/
/*
* Cleanup
*/
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
{
xmlC14NErrParam("checking for relative namespaces");
return (-1);
}
xmlC14NErrInternal("parsing namespace uri");
return (-1);
}
return (-1);
}
return (-1);
}
}
}
return (0);
}
/**
* xmlC14NProcessElementNode:
* @ctx: the pointer to C14N context object
* @cur: the node to process
*
* 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
{
int ret;
int parent_is_doc = 0;
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.
*/
xmlC14NErrInternal("checking for relative namespaces");
return (-1);
}
/*
* Save ns_rendered stack position
*/
if (visible) {
if (ctx->parent_is_doc) {
/* save this flag into the stack */
ctx->parent_is_doc = 0;
}
}
}
} else {
}
if (ret < 0) {
xmlC14NErrInternal("processing namespaces axis");
return (-1);
}
/* todo: shouldn't this go to "visible only"? */
if(visible) {
}
if (ret < 0) {
xmlC14NErrInternal("processing attributes axis");
return (-1);
}
if (visible) {
}
if (ret < 0) {
xmlC14NErrInternal("processing childrens list");
return (-1);
}
}
if (visible) {
}
if (parent_is_doc) {
/* restore this flag from the stack for next node */
}
}
/*
* Restore ns_rendered stack position
*/
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
{
int ret = 0;
int visible;
xmlC14NErrParam("processing node");
return (-1);
}
case XML_ELEMENT_NODE:
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 */
(const char *) buffer);
} else {
xmlC14NErrInternal("normalizing text node");
return (-1);
}
}
break;
case XML_PI_NODE:
/*
* Processing Instruction (PI) Nodes-
* The opening PI symbol (<?), the PI target name of the node,
* a leading space and the string value if it is not empty, and
* the closing 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) {
} else {
}
/* todo: do we need to normalize pi? */
(const char *) buffer);
} else {
xmlC14NErrInternal("normalizing pi node");
return (-1);
}
}
} else {
}
}
break;
case XML_COMMENT_NODE:
/*
* Comment Nodes
* Nothing if generating canonical XML without comments. For
* canonical XML with comments, generate the opening comment
* symbol (<!--), the string value of the node, and the
* closing 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).
*/
} else {
}
/* todo: do we need to normalize comment? */
(const char *) buffer);
} else {
xmlC14NErrInternal("normalizing comment node");
return (-1);
}
}
} else {
}
}
break;
case XML_DOCUMENT_NODE:
case XML_DOCUMENT_FRAG_NODE: /* should be processed as document? */
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE: /* should be processed as document? */
#endif
#ifdef LIBXML_HTML_ENABLED
case XML_HTML_DOCUMENT_NODE: /* should be processed as document? */
#endif
}
break;
case XML_ATTRIBUTE_NODE:
return (-1);
case XML_NAMESPACE_DECL:
return (-1);
case XML_ENTITY_REF_NODE:
return (-1);
case XML_ENTITY_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:
#ifdef LIBXML_XINCLUDE_ENABLED
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
#endif
/*
* should be ignored according to "W3C Canonical XML"
*/
break;
default:
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
{
int ret;
xmlC14NErrParam("processing node list");
return (-1);
}
}
return (ret);
}
/**
* xmlC14NFreeCtx:
* @ctx: the pointer to C14N context object
*
* Cleanups the C14N context object.
*/
static void
{
xmlC14NErrParam("freeing context");
return;
}
}
}
/**
* 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)
* @inclusive_ns_prefixe the list of inclusive namespace prefixes
* ended with a NULL or NULL if there is no
* inclusive namespaces (only for exclusive
* 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
{
xmlC14NErrParam("creating new context");
return (NULL);
}
/*
* Validate the encoding output buffer encoding
*/
"xmlC14NNewCtx: output buffer encoder != NULL but C14N requires UTF8 output\n");
return (NULL);
}
/*
* Validate the XML document encoding value, if provided.
*/
"xmlC14NNewCtx: source document not in UTF8\n");
return (NULL);
}
/*
* Allocate a new xmlC14NCtxPtr and fill the fields.
*/
xmlC14NErrMemory("creating context");
return (NULL);
}
/*
* initialize C14N context
*/
"xmlC14NNewCtx: xmlC14NVisibleNsStackCreate failed\n");
return (NULL);
}
/*
* Set "exclusive" flag, create a nodes set for namespaces
* stack and remember list of incluseve prefixes
*/
if (exclusive) {
}
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)
* @exclusive: the exclusive flag (0 - non-exclusive canonicalization;
* otherwise - exclusive canonicalization)
* @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
int ret;
xmlC14NErrParam("executing c14n");
return (-1);
}
/*
* Validate the encoding output buffer encoding
*/
"xmlC14NExecute: output buffer encoder != NULL but C14N requires UTF8 output\n");
return (-1);
}
with_comments, buf);
"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 (ret < 0) {
xmlC14NErrInternal("processing docs children list");
return (-1);
}
}
/*
* Flush buffer to get number of bytes written
*/
if (ret < 0) {
xmlC14NErrInternal("flushing output buffer");
return (-1);
}
/*
* Cleanup
*/
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
* @exclusive: the exclusive flag (0 - non-exclusive canonicalization;
* otherwise - exclusive canonicalization)
* @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
return(xmlC14NExecute(doc,
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
* @exclusive: the exclusive flag (0 - non-exclusive canonicalization;
* otherwise - exclusive canonicalization)
* @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
{
int ret;
if (doc_txt_ptr == NULL) {
xmlC14NErrParam("dumping doc to memory");
return (-1);
}
*doc_txt_ptr = NULL;
/*
* create memory buffer with UTF8 (default) encoding
*/
xmlC14NErrMemory("creating output buffer");
return (-1);
}
/*
* canonize document and write to buffer
*/
with_comments, buf);
if (ret < 0) {
xmlC14NErrInternal("saving doc to output buffer");
(void) xmlOutputBufferClose(buf);
return (-1);
}
if (ret > 0) {
}
(void) xmlOutputBufferClose(buf);
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
* @exclusive: the exclusive flag (0 - non-exclusive canonicalization;
* otherwise - exclusive canonicalization)
* @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
{
int ret;
xmlC14NErrParam("saving doc");
return (-1);
}
#ifdef HAVE_ZLIB_H
if (compression < 0)
#endif
/*
* save the content to a temp buffer, use default UTF8 encoding.
*/
xmlC14NErrInternal("creating temporary filename");
return (-1);
}
/*
* canonize document and write to buffer
*/
with_comments, buf);
if (ret < 0) {
xmlC14NErrInternal("cannicanize document to buffer");
(void) xmlOutputBufferClose(buf);
return (-1);
}
/*
* get the numbers of bytes written
*/
return (ret);
}
/*
* Macro used to grow the current buffer.
*/
#define growBufferReentrant() { \
buffer_size *= 2; \
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 *
{
int buffer_size = 0;
return (NULL);
/*
* allocate an translation buffer.
*/
buffer_size = 1000;
xmlC14NErrMemory("allocating buffer");
return (NULL);
}
while (*cur != '\0') {
}
(mode == XMLC14N_NORMALIZE_TEXT))) {
*out++ = '&';
*out++ = 'l';
*out++ = 't';
*out++ = ';';
*out++ = '&';
*out++ = 'g';
*out++ = 't';
*out++ = ';';
(mode == XMLC14N_NORMALIZE_TEXT))) {
*out++ = '&';
*out++ = 'a';
*out++ = 'm';
*out++ = 'p';
*out++ = ';';
*out++ = '&';
*out++ = 'q';
*out++ = 'u';
*out++ = 'o';
*out++ = 't';
*out++ = ';';
*out++ = '&';
*out++ = '#';
*out++ = 'x';
*out++ = '9';
*out++ = ';';
*out++ = '&';
*out++ = '#';
*out++ = 'x';
*out++ = 'A';
*out++ = ';';
(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.
*/
}
cur++;
}
*out++ = 0;
return (buffer);
}
#endif /* LIBXML_OUTPUT_ENABLED */
#define bottom_c14n
#include "elfgcchack.h"
#endif /* LIBXML_C14N_ENABLED */