| OLD | NEW |
| 1 /* | 1 /* |
| 2 * "Canonical XML" implementation | 2 * "Canonical XML" implementation |
| 3 * http://www.w3.org/TR/xml-c14n | 3 * http://www.w3.org/TR/xml-c14n |
| 4 * | 4 * |
| 5 * "Exclusive XML Canonicalization" implementation | 5 * "Exclusive XML Canonicalization" implementation |
| 6 * http://www.w3.org/TR/xml-exc-c14n | 6 * http://www.w3.org/TR/xml-exc-c14n |
| 7 * | 7 * |
| 8 * See Copyright for the status of this software. | 8 * See Copyright for the status of this software. |
| 9 * | 9 * |
| 10 * Author: Aleksey Sanin <aleksey@aleksey.com> | 10 * Author: Aleksey Sanin <aleksey@aleksey.com> |
| 11 */ | 11 */ |
| 12 #define IN_LIBXML | 12 #define IN_LIBXML |
| 13 #include "libxml.h" | 13 #include "libxml.h" |
| 14 #ifdef LIBXML_C14N_ENABLED | 14 #ifdef LIBXML_C14N_ENABLED |
| 15 #ifdef LIBXML_OUTPUT_ENABLED | 15 #ifdef LIBXML_OUTPUT_ENABLED |
| 16 | 16 |
| 17 #ifdef HAVE_STDLIB_H | 17 #ifdef HAVE_STDLIB_H |
| 18 #include <stdlib.h> | 18 #include <stdlib.h> |
| 19 #endif | 19 #endif |
| 20 #include <string.h> | 20 #include <string.h> |
| 21 | 21 |
| 22 #include <libxml/tree.h> | 22 #include <libxml/tree.h> |
| 23 #include <libxml/parser.h> | 23 #include <libxml/parser.h> |
| 24 #include <libxml/uri.h> | 24 #include <libxml/uri.h> |
| 25 #include <libxml/xmlerror.h> | 25 #include <libxml/xmlerror.h> |
| 26 #include <libxml/globals.h> | 26 #include <libxml/globals.h> |
| 27 #include <libxml/xpathInternals.h> | 27 #include <libxml/xpathInternals.h> |
| 28 #include <libxml/c14n.h> | 28 #include <libxml/c14n.h> |
| 29 | 29 |
| 30 #include "buf.h" |
| 31 |
| 30 /************************************************************************ | 32 /************************************************************************ |
| 31 * * | 33 * * |
| 32 * Some declaration better left private ATM * | 34 * Some declaration better left private ATM * |
| 33 * * | 35 * * |
| 34 ************************************************************************/ | 36 ************************************************************************/ |
| 35 | 37 |
| 36 typedef enum { | 38 typedef enum { |
| 37 XMLC14N_BEFORE_DOCUMENT_ELEMENT = 0, | 39 XMLC14N_BEFORE_DOCUMENT_ELEMENT = 0, |
| 38 XMLC14N_INSIDE_DOCUMENT_ELEMENT = 1, | 40 XMLC14N_INSIDE_DOCUMENT_ELEMENT = 1, |
| 39 XMLC14N_AFTER_DOCUMENT_ELEMENT = 2 | 41 XMLC14N_AFTER_DOCUMENT_ELEMENT = 2 |
| 40 } xmlC14NPosition; | 42 } xmlC14NPosition; |
| 41 | 43 |
| 42 typedef struct _xmlC14NVisibleNsStack { | 44 typedef struct _xmlC14NVisibleNsStack { |
| 43 int nsCurEnd; /* number of nodes in the set */ | 45 int nsCurEnd; /* number of nodes in the set */ |
| 44 int nsPrevStart; /* the begginning of the stack for previous visible
node */ | 46 int nsPrevStart; /* the begginning of the stack for previous visible
node */ |
| 45 int nsPrevEnd; /* the end of the stack for previous visible node */ | 47 int nsPrevEnd; /* the end of the stack for previous visible node */ |
| 46 int nsMax; /* size of the array as allocated */ | 48 int nsMax; /* size of the array as allocated */ |
| 47 xmlNsPtr » *nsTab;» /* array of ns in no particular order */» | 49 xmlNsPtr» *nsTab;» /* array of ns in no particular order */ |
| 48 xmlNodePtr *nodeTab; /* array of nodes in no particular order */ | 50 xmlNodePtr *nodeTab; /* array of nodes in no particular order */ |
| 49 } xmlC14NVisibleNsStack, *xmlC14NVisibleNsStackPtr; | 51 } xmlC14NVisibleNsStack, *xmlC14NVisibleNsStackPtr; |
| 50 | 52 |
| 51 typedef struct _xmlC14NCtx { | 53 typedef struct _xmlC14NCtx { |
| 52 /* input parameters */ | 54 /* input parameters */ |
| 53 xmlDocPtr doc; | 55 xmlDocPtr doc; |
| 54 xmlC14NIsVisibleCallback is_visible_callback; | 56 xmlC14NIsVisibleCallback is_visible_callback; |
| 55 void* user_data; | 57 void* user_data; |
| 56 int with_comments; | 58 int with_comments; |
| 57 xmlOutputBufferPtr buf; | 59 xmlOutputBufferPtr buf; |
| 58 | 60 |
| 59 /* position in the XML document */ | 61 /* position in the XML document */ |
| 60 xmlC14NPosition pos; | 62 xmlC14NPosition pos; |
| 61 int parent_is_doc; | 63 int parent_is_doc; |
| 62 xmlC14NVisibleNsStackPtr ns_rendered; | 64 xmlC14NVisibleNsStackPtr ns_rendered; |
| 63 | 65 |
| 64 /* C14N mode */ | 66 /* C14N mode */ |
| 65 xmlC14NMode mode; | 67 xmlC14NMode mode; |
| 66 | 68 |
| 67 /* exclusive canonicalization */ | 69 /* exclusive canonicalization */ |
| 68 xmlChar **inclusive_ns_prefixes; | 70 xmlChar **inclusive_ns_prefixes; |
| 69 | 71 |
| 70 /* error number */ | 72 /* error number */ |
| 71 int error; | 73 int error; |
| 72 } xmlC14NCtx, *xmlC14NCtxPtr; | 74 } xmlC14NCtx, *xmlC14NCtxPtr; |
| 73 | 75 |
| 74 static xmlC14NVisibleNsStackPtr xmlC14NVisibleNsStackCreate (void); | 76 static xmlC14NVisibleNsStackPtr xmlC14NVisibleNsStackCreate (void); |
| 75 static void xmlC14NVisibleNsStackDestroy (xmlC14NVisibleNsStackPtr cur); | 77 static void xmlC14NVisibleNsStackDestroy (xmlC14NVisibleNsStackPtr cur); |
| 76 static void xmlC14NVisibleNsStackAdd» (xmlC14NVisibleNsStackPtr cu
r, | 78 static void xmlC14NVisibleNsStackAdd» (xmlC14NVisibleNsStackPtr cu
r, |
| 77 xmlNsPtr ns, | 79 xmlNsPtr ns, |
| 78 xmlNodePtr node); | 80 xmlNodePtr node); |
| 79 static void » » » xmlC14NVisibleNsStackSave» (xmlC14NVisibleN
sStackPtr cur, | 81 static void» » » xmlC14NVisibleNsStackSave» (xmlC14NVisibleN
sStackPtr cur, |
| 80 xmlC14NVisibleN
sStackPtr state); | 82 xmlC14NVisibleN
sStackPtr state); |
| 81 static void » » » xmlC14NVisibleNsStackRestore» (xmlC14NVisibleN
sStackPtr cur, | 83 static void» » » xmlC14NVisibleNsStackRestore» (xmlC14NVisibleN
sStackPtr cur, |
| 82 xmlC14NVisibleN
sStackPtr state); | 84 xmlC14NVisibleN
sStackPtr state); |
| 83 static void » » » xmlC14NVisibleNsStackShift» (xmlC14NVisibleN
sStackPtr cur); | 85 static void» » » xmlC14NVisibleNsStackShift» (xmlC14NVisibleN
sStackPtr cur); |
| 84 static int» » » xmlC14NVisibleNsStackFind» (xmlC14NVisibleN
sStackPtr cur, | 86 static int» » » xmlC14NVisibleNsStackFind» (xmlC14NVisibleN
sStackPtr cur, |
| 85 xmlNsPtr ns); | 87 xmlNsPtr ns); |
| 86 static int» » » xmlExcC14NVisibleNsStackFind» (xmlC14NVisibleN
sStackPtr cur, | 88 static int» » » xmlExcC14NVisibleNsStackFind» (xmlC14NVisibleN
sStackPtr cur, |
| 87 xmlNsPtr ns, | 89 xmlNsPtr ns, |
| 88 xmlC14NCtxPtr c
tx); | 90 xmlC14NCtxPtr c
tx); |
| 89 | 91 |
| 90 static int xmlC14NIsNodeInNodeset (xmlNodeSetPtr n
odes, | 92 static int xmlC14NIsNodeInNodeset (xmlNodeSetPtr n
odes, |
| 91 xmlNodePtr node
, | 93 xmlNodePtr node
, |
| 92 xmlNodePtr pare
nt); | 94 xmlNodePtr pare
nt); |
| 93 | 95 |
| 94 | 96 |
| 95 | 97 |
| 96 static int xmlC14NProcessNode(xmlC14NCtxPtr ctx, xmlNodePtr cur); | 98 static int xmlC14NProcessNode(xmlC14NCtxPtr ctx, xmlNodePtr cur); |
| 97 static int xmlC14NProcessNodeList(xmlC14NCtxPtr ctx, xmlNodePtr cur); | 99 static int xmlC14NProcessNodeList(xmlC14NCtxPtr ctx, xmlNodePtr cur); |
| 98 typedef enum { | 100 typedef enum { |
| 99 XMLC14N_NORMALIZE_ATTR = 0, | 101 XMLC14N_NORMALIZE_ATTR = 0, |
| 100 XMLC14N_NORMALIZE_COMMENT = 1, | 102 XMLC14N_NORMALIZE_COMMENT = 1, |
| 101 XMLC14N_NORMALIZE_PI = 2, | 103 XMLC14N_NORMALIZE_PI = 2, |
| 102 XMLC14N_NORMALIZE_TEXT = 3 | 104 XMLC14N_NORMALIZE_TEXT = 3 |
| 103 } xmlC14NNormalizationMode; | 105 } xmlC14NNormalizationMode; |
| 104 | 106 |
| 105 static xmlChar *xmlC11NNormalizeString(const xmlChar * input, | 107 static xmlChar *xmlC11NNormalizeString(const xmlChar * input, |
| 106 xmlC14NNormalizationMode mode); | 108 xmlC14NNormalizationMode mode); |
| 107 | 109 |
| 108 #define » xmlC11NNormalizeAttr( a ) \ | 110 #define»xmlC11NNormalizeAttr( a ) \ |
| 109 xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_ATTR) | 111 xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_ATTR) |
| 110 #define » xmlC11NNormalizeComment( a ) \ | 112 #define»xmlC11NNormalizeComment( a ) \ |
| 111 xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_COMMENT) | 113 xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_COMMENT) |
| 112 #define » xmlC11NNormalizePI( a )»\ | 114 #define»xmlC11NNormalizePI( a )»\ |
| 113 xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_PI) | 115 xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_PI) |
| 114 #define » xmlC11NNormalizeText( a ) \ | 116 #define»xmlC11NNormalizeText( a ) \ |
| 115 xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_TEXT) | 117 xmlC11NNormalizeString((a), XMLC14N_NORMALIZE_TEXT) |
| 116 | 118 |
| 117 #define » xmlC14NIsVisible( ctx, node, parent ) \ | 119 #define»xmlC14NIsVisible( ctx, node, parent ) \ |
| 118 (((ctx)->is_visible_callback != NULL) ? \ | 120 (((ctx)->is_visible_callback != NULL) ? \ |
| 119 (ctx)->is_visible_callback((ctx)->user_data, \ | 121 (ctx)->is_visible_callback((ctx)->user_data, \ |
| 120 (xmlNodePtr)(node), (xmlNodePtr)(parent)) : 1) | 122 (xmlNodePtr)(node), (xmlNodePtr)(parent)) : 1) |
| 121 | 123 |
| 122 #define » xmlC14NIsExclusive( ctx ) \ | 124 #define»xmlC14NIsExclusive( ctx ) \ |
| 123 ( (ctx)->mode == XML_C14N_EXCLUSIVE_1_0 ) | 125 ( (ctx)->mode == XML_C14N_EXCLUSIVE_1_0 ) |
| 124 | 126 |
| 125 /************************************************************************ | 127 /************************************************************************ |
| 126 * * | 128 * * |
| 127 * » » Some factorized error routines» » » » * | 129 *» » Some factorized error routines» » » » * |
| 128 * * | 130 * * |
| 129 ************************************************************************/ | 131 ************************************************************************/ |
| 130 | 132 |
| 131 /** | 133 /** |
| 132 * xmlC14NErrMemory: | 134 * xmlC14NErrMemory: |
| 133 * @extra: extra informations | 135 * @extra: extra informations |
| 134 * | 136 * |
| 135 * Handle a redefinition of memory error | 137 * Handle a redefinition of memory error |
| 136 */ | 138 */ |
| 137 static void | 139 static void |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 NULL, NULL, NULL, 0, 0, "%s", msg); | 244 NULL, NULL, NULL, 0, 0, "%s", msg); |
| 243 } | 245 } |
| 244 | 246 |
| 245 /************************************************************************ | 247 /************************************************************************ |
| 246 * * | 248 * * |
| 247 * The implementation internals * | 249 * The implementation internals * |
| 248 * * | 250 * * |
| 249 ************************************************************************/ | 251 ************************************************************************/ |
| 250 #define XML_NAMESPACES_DEFAULT 16 | 252 #define XML_NAMESPACES_DEFAULT 16 |
| 251 | 253 |
| 252 static int» » » | 254 static int |
| 253 xmlC14NIsNodeInNodeset(xmlNodeSetPtr nodes, xmlNodePtr node, xmlNodePtr parent)
{ | 255 xmlC14NIsNodeInNodeset(xmlNodeSetPtr nodes, xmlNodePtr node, xmlNodePtr parent)
{ |
| 254 if((nodes != NULL) && (node != NULL)) { | 256 if((nodes != NULL) && (node != NULL)) { |
| 255 if(node->type != XML_NAMESPACE_DECL) { | 257 if(node->type != XML_NAMESPACE_DECL) { |
| 256 return(xmlXPathNodeSetContains(nodes, node)); | 258 return(xmlXPathNodeSetContains(nodes, node)); |
| 257 } else { | 259 } else { |
| 258 xmlNs ns; | 260 xmlNs ns; |
| 259 » | 261 |
| 260 » memcpy(&ns, node, sizeof(ns)); | 262 » memcpy(&ns, node, sizeof(ns)); |
| 261 » | 263 |
| 262 /* this is a libxml hack! check xpath.c for details */ | 264 /* this is a libxml hack! check xpath.c for details */ |
| 263 if((parent != NULL) && (parent->type == XML_ATTRIBUTE_NODE)) { | 265 if((parent != NULL) && (parent->type == XML_ATTRIBUTE_NODE)) { |
| 264 ns.next = (xmlNsPtr)parent->parent; | 266 ns.next = (xmlNsPtr)parent->parent; |
| 265 } else { | 267 } else { |
| 266 » » ns.next = (xmlNsPtr)parent; | 268 » » ns.next = (xmlNsPtr)parent; |
| 267 } | 269 } |
| 268 | 270 |
| 269 » /* | 271 » /* |
| 270 » * If the input is an XPath node-set, then the node-set must explici
tly | 272 » * If the input is an XPath node-set, then the node-set must explici
tly |
| 271 * contain every node to be rendered to the canonical form. | 273 * contain every node to be rendered to the canonical form. |
| 272 */ | 274 */ |
| 273 return(xmlXPathNodeSetContains(nodes, (xmlNodePtr)&ns)); | 275 return(xmlXPathNodeSetContains(nodes, (xmlNodePtr)&ns)); |
| 274 } | 276 } |
| 275 } | 277 } |
| 276 return(1); | 278 return(1); |
| 277 } | 279 } |
| 278 | 280 |
| 279 static xmlC14NVisibleNsStackPtr | 281 static xmlC14NVisibleNsStackPtr |
| 280 xmlC14NVisibleNsStackCreate(void) { | 282 xmlC14NVisibleNsStackCreate(void) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 298 if(cur->nsTab != NULL) { | 300 if(cur->nsTab != NULL) { |
| 299 memset(cur->nsTab, 0, cur->nsMax * sizeof(xmlNsPtr)); | 301 memset(cur->nsTab, 0, cur->nsMax * sizeof(xmlNsPtr)); |
| 300 xmlFree(cur->nsTab); | 302 xmlFree(cur->nsTab); |
| 301 } | 303 } |
| 302 if(cur->nodeTab != NULL) { | 304 if(cur->nodeTab != NULL) { |
| 303 memset(cur->nodeTab, 0, cur->nsMax * sizeof(xmlNodePtr)); | 305 memset(cur->nodeTab, 0, cur->nsMax * sizeof(xmlNodePtr)); |
| 304 xmlFree(cur->nodeTab); | 306 xmlFree(cur->nodeTab); |
| 305 } | 307 } |
| 306 memset(cur, 0, sizeof(xmlC14NVisibleNsStack)); | 308 memset(cur, 0, sizeof(xmlC14NVisibleNsStack)); |
| 307 xmlFree(cur); | 309 xmlFree(cur); |
| 308 | 310 |
| 309 } | 311 } |
| 310 | 312 |
| 311 static void | 313 static void |
| 312 xmlC14NVisibleNsStackAdd(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns, xmlNodePtr n
ode) { | 314 xmlC14NVisibleNsStackAdd(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns, xmlNodePtr n
ode) { |
| 313 if((cur == NULL) || | 315 if((cur == NULL) || |
| 314 ((cur->nsTab == NULL) && (cur->nodeTab != NULL)) || | 316 ((cur->nsTab == NULL) && (cur->nodeTab != NULL)) || |
| 315 ((cur->nsTab != NULL) && (cur->nodeTab == NULL))) { | 317 ((cur->nsTab != NULL) && (cur->nodeTab == NULL))) { |
| 316 xmlC14NErrParam("adding namespace to stack"); | 318 xmlC14NErrParam("adding namespace to stack"); |
| 317 return; | 319 return; |
| 318 } | 320 } |
| 319 | 321 |
| 320 if ((cur->nsTab == NULL) && (cur->nodeTab == NULL)) { | 322 if ((cur->nsTab == NULL) && (cur->nodeTab == NULL)) { |
| 321 cur->nsTab = (xmlNsPtr*) xmlMalloc(XML_NAMESPACES_DEFAULT * sizeof(xmlNs
Ptr)); | 323 cur->nsTab = (xmlNsPtr*) xmlMalloc(XML_NAMESPACES_DEFAULT * sizeof(xmlNs
Ptr)); |
| 322 cur->nodeTab = (xmlNodePtr*) xmlMalloc(XML_NAMESPACES_DEFAULT * sizeof(x
mlNodePtr)); | 324 cur->nodeTab = (xmlNodePtr*) xmlMalloc(XML_NAMESPACES_DEFAULT * sizeof(x
mlNodePtr)); |
| 323 if ((cur->nsTab == NULL) || (cur->nodeTab == NULL)) { | 325 if ((cur->nsTab == NULL) || (cur->nodeTab == NULL)) { |
| 324 xmlC14NErrMemory("adding node to stack"); | 326 xmlC14NErrMemory("adding node to stack"); |
| 325 return; | 327 return; |
| 326 } | 328 } |
| 327 memset(cur->nsTab, 0 , XML_NAMESPACES_DEFAULT * sizeof(xmlNsPtr)); | 329 memset(cur->nsTab, 0 , XML_NAMESPACES_DEFAULT * sizeof(xmlNsPtr)); |
| 328 memset(cur->nodeTab, 0 , XML_NAMESPACES_DEFAULT * sizeof(xmlNodePtr)); | 330 memset(cur->nodeTab, 0 , XML_NAMESPACES_DEFAULT * sizeof(xmlNodePtr)); |
| 329 cur->nsMax = XML_NAMESPACES_DEFAULT; | 331 cur->nsMax = XML_NAMESPACES_DEFAULT; |
| 330 } else if(cur->nsMax == cur->nsCurEnd) { | 332 } else if(cur->nsMax == cur->nsCurEnd) { |
| 331 » void *tmp;» | 333 » void *tmp; |
| 332 int tmpSize; | 334 int tmpSize; |
| 333 » | 335 |
| 334 tmpSize = 2 * cur->nsMax; | 336 tmpSize = 2 * cur->nsMax; |
| 335 tmp = xmlRealloc(cur->nsTab, tmpSize * sizeof(xmlNsPtr)); | 337 tmp = xmlRealloc(cur->nsTab, tmpSize * sizeof(xmlNsPtr)); |
| 336 if (tmp == NULL) { | 338 if (tmp == NULL) { |
| 337 xmlC14NErrMemory("adding node to stack"); | 339 xmlC14NErrMemory("adding node to stack"); |
| 338 return; | 340 return; |
| 339 } | 341 } |
| 340 cur->nsTab = (xmlNsPtr*)tmp; | 342 cur->nsTab = (xmlNsPtr*)tmp; |
| 341 | 343 |
| 342 tmp = xmlRealloc(cur->nodeTab, tmpSize * sizeof(xmlNodePtr)); | 344 tmp = xmlRealloc(cur->nodeTab, tmpSize * sizeof(xmlNodePtr)); |
| 343 if (tmp == NULL) { | 345 if (tmp == NULL) { |
| 344 xmlC14NErrMemory("adding node to stack"); | 346 xmlC14NErrMemory("adding node to stack"); |
| 345 return; | 347 return; |
| 346 } | 348 } |
| 347 cur->nodeTab = (xmlNodePtr*)tmp; | 349 cur->nodeTab = (xmlNodePtr*)tmp; |
| 348 | 350 |
| 349 cur->nsMax = tmpSize; | 351 cur->nsMax = tmpSize; |
| 350 } | 352 } |
| 351 cur->nsTab[cur->nsCurEnd] = ns; | 353 cur->nsTab[cur->nsCurEnd] = ns; |
| 352 cur->nodeTab[cur->nsCurEnd] = node; | 354 cur->nodeTab[cur->nsCurEnd] = node; |
| 353 | 355 |
| 354 ++cur->nsCurEnd; | 356 ++cur->nsCurEnd; |
| 355 } | 357 } |
| 356 | 358 |
| 357 static void | 359 static void |
| 358 xmlC14NVisibleNsStackSave(xmlC14NVisibleNsStackPtr cur, xmlC14NVisibleNsStackPtr
state) { | 360 xmlC14NVisibleNsStackSave(xmlC14NVisibleNsStackPtr cur, xmlC14NVisibleNsStackPtr
state) { |
| 359 if((cur == NULL) || (state == NULL)) { | 361 if((cur == NULL) || (state == NULL)) { |
| 360 xmlC14NErrParam("saving namespaces stack"); | 362 xmlC14NErrParam("saving namespaces stack"); |
| 361 return; | 363 return; |
| 362 } | 364 } |
| 363 | 365 |
| 364 state->nsCurEnd = cur->nsCurEnd; | 366 state->nsCurEnd = cur->nsCurEnd; |
| 365 state->nsPrevStart = cur->nsPrevStart; | 367 state->nsPrevStart = cur->nsPrevStart; |
| 366 state->nsPrevEnd = cur->nsPrevEnd; | 368 state->nsPrevEnd = cur->nsPrevEnd; |
| 367 } | 369 } |
| 368 | 370 |
| 369 static void | 371 static void |
| 370 xmlC14NVisibleNsStackRestore(xmlC14NVisibleNsStackPtr cur, xmlC14NVisibleNsStack
Ptr state) { | 372 xmlC14NVisibleNsStackRestore(xmlC14NVisibleNsStackPtr cur, xmlC14NVisibleNsStack
Ptr state) { |
| 371 if((cur == NULL) || (state == NULL)) { | 373 if((cur == NULL) || (state == NULL)) { |
| 372 xmlC14NErrParam("restoring namespaces stack"); | 374 xmlC14NErrParam("restoring namespaces stack"); |
| 373 return; | 375 return; |
| 374 } | 376 } |
| 375 cur->nsCurEnd = state->nsCurEnd; | 377 cur->nsCurEnd = state->nsCurEnd; |
| 376 cur->nsPrevStart = state->nsPrevStart; | 378 cur->nsPrevStart = state->nsPrevStart; |
| 377 cur->nsPrevEnd = state->nsPrevEnd; | 379 cur->nsPrevEnd = state->nsPrevEnd; |
| 378 } | 380 } |
| 379 | 381 |
| 380 static void | 382 static void |
| 381 xmlC14NVisibleNsStackShift(xmlC14NVisibleNsStackPtr cur) { | 383 xmlC14NVisibleNsStackShift(xmlC14NVisibleNsStackPtr cur) { |
| 382 if(cur == NULL) { | 384 if(cur == NULL) { |
| 383 xmlC14NErrParam("shifting namespaces stack"); | 385 xmlC14NErrParam("shifting namespaces stack"); |
| 384 return; | 386 return; |
| 385 } | 387 } |
| 386 cur->nsPrevStart = cur->nsPrevEnd; | 388 cur->nsPrevStart = cur->nsPrevEnd; |
| 387 cur->nsPrevEnd = cur->nsCurEnd; | 389 cur->nsPrevEnd = cur->nsCurEnd; |
| 388 } | 390 } |
| 389 | 391 |
| 390 static int | 392 static int |
| 391 xmlC14NStrEqual(const xmlChar *str1, const xmlChar *str2) { | 393 xmlC14NStrEqual(const xmlChar *str1, const xmlChar *str2) { |
| 392 if (str1 == str2) return(1); | 394 if (str1 == str2) return(1); |
| 393 if (str1 == NULL) return((*str2) == '\0'); | 395 if (str1 == NULL) return((*str2) == '\0'); |
| 394 if (str2 == NULL) return((*str1) == '\0'); | 396 if (str2 == NULL) return((*str1) == '\0'); |
| 395 do { | 397 do { |
| 396 if (*str1++ != *str2) return(0); | 398 if (*str1++ != *str2) return(0); |
| 397 } while (*str2++); | 399 } while (*str2++); |
| 398 return(1); | 400 return(1); |
| 399 } | 401 } |
| 400 | 402 |
| 401 /** | 403 /** |
| 402 * xmlC14NVisibleNsStackFind: | 404 * xmlC14NVisibleNsStackFind: |
| 403 * @ctx:» » the C14N context | 405 * @ctx:» » the C14N context |
| 404 * @ns: the namespace to check | 406 * @ns: the namespace to check |
| 405 * | 407 * |
| 406 * Checks whether the given namespace was already rendered or not | 408 * Checks whether the given namespace was already rendered or not |
| 407 * | 409 * |
| 408 * Returns 1 if we already wrote this namespace or 0 otherwise | 410 * Returns 1 if we already wrote this namespace or 0 otherwise |
| 409 */ | 411 */ |
| 410 static int | 412 static int |
| 411 xmlC14NVisibleNsStackFind(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns) | 413 xmlC14NVisibleNsStackFind(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns) |
| 412 { | 414 { |
| 413 int i; | 415 int i; |
| 414 const xmlChar *prefix; | 416 const xmlChar *prefix; |
| 415 const xmlChar *href; | 417 const xmlChar *href; |
| 416 int has_empty_ns; | 418 int has_empty_ns; |
| 417 | 419 |
| 418 if(cur == NULL) { | 420 if(cur == NULL) { |
| 419 xmlC14NErrParam("searching namespaces stack (c14n)"); | 421 xmlC14NErrParam("searching namespaces stack (c14n)"); |
| 420 return (0); | 422 return (0); |
| 421 } | 423 } |
| 422 | 424 |
| 423 /* | 425 /* |
| 424 * if the default namespace xmlns="" is not defined yet then | 426 * if the default namespace xmlns="" is not defined yet then |
| 425 * we do not want to print it out | 427 * we do not want to print it out |
| 426 */ | 428 */ |
| 427 prefix = ((ns == NULL) || (ns->prefix == NULL)) ? BAD_CAST "" : ns->prefix; | 429 prefix = ((ns == NULL) || (ns->prefix == NULL)) ? BAD_CAST "" : ns->prefix; |
| 428 href = ((ns == NULL) || (ns->href == NULL)) ? BAD_CAST "" : ns->href; | 430 href = ((ns == NULL) || (ns->href == NULL)) ? BAD_CAST "" : ns->href; |
| 429 has_empty_ns = (xmlC14NStrEqual(prefix, NULL) && xmlC14NStrEqual(href, NULL)
); | 431 has_empty_ns = (xmlC14NStrEqual(prefix, NULL) && xmlC14NStrEqual(href, NULL)
); |
| 430 | 432 |
| 431 if (cur->nsTab != NULL) { | 433 if (cur->nsTab != NULL) { |
| 432 int start = (has_empty_ns) ? 0 : cur->nsPrevStart; | 434 int start = (has_empty_ns) ? 0 : cur->nsPrevStart; |
| 433 for (i = cur->nsCurEnd - 1; i >= start; --i) { | 435 for (i = cur->nsCurEnd - 1; i >= start; --i) { |
| 434 xmlNsPtr ns1 = cur->nsTab[i]; | 436 xmlNsPtr ns1 = cur->nsTab[i]; |
| 435 » | 437 |
| 436 if(xmlC14NStrEqual(prefix, (ns1 != NULL) ? ns1->prefix : NULL)) { | 438 if(xmlC14NStrEqual(prefix, (ns1 != NULL) ? ns1->prefix : NULL)) { |
| 437 return(xmlC14NStrEqual(href, (ns1 != NULL) ? ns1->href : NULL)); | 439 return(xmlC14NStrEqual(href, (ns1 != NULL) ? ns1->href : NULL)); |
| 438 } | 440 } |
| 439 } | 441 } |
| 440 } | 442 } |
| 441 return(has_empty_ns); | 443 return(has_empty_ns); |
| 442 } | 444 } |
| 443 | 445 |
| 444 static int» » » | 446 static int |
| 445 xmlExcC14NVisibleNsStackFind(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns, xmlC14NC
txPtr ctx) { | 447 xmlExcC14NVisibleNsStackFind(xmlC14NVisibleNsStackPtr cur, xmlNsPtr ns, xmlC14NC
txPtr ctx) { |
| 446 int i; | 448 int i; |
| 447 const xmlChar *prefix; | 449 const xmlChar *prefix; |
| 448 const xmlChar *href; | 450 const xmlChar *href; |
| 449 int has_empty_ns; | 451 int has_empty_ns; |
| 450 | 452 |
| 451 if(cur == NULL) { | 453 if(cur == NULL) { |
| 452 xmlC14NErrParam("searching namespaces stack (exc c14n)"); | 454 xmlC14NErrParam("searching namespaces stack (exc c14n)"); |
| 453 return (0); | 455 return (0); |
| 454 } | 456 } |
| 455 | 457 |
| 456 /* | 458 /* |
| 457 * if the default namespace xmlns="" is not defined yet then | 459 * if the default namespace xmlns="" is not defined yet then |
| 458 * we do not want to print it out | 460 * we do not want to print it out |
| 459 */ | 461 */ |
| 460 prefix = ((ns == NULL) || (ns->prefix == NULL)) ? BAD_CAST "" : ns->prefix; | 462 prefix = ((ns == NULL) || (ns->prefix == NULL)) ? BAD_CAST "" : ns->prefix; |
| 461 href = ((ns == NULL) || (ns->href == NULL)) ? BAD_CAST "" : ns->href; | 463 href = ((ns == NULL) || (ns->href == NULL)) ? BAD_CAST "" : ns->href; |
| 462 has_empty_ns = (xmlC14NStrEqual(prefix, NULL) && xmlC14NStrEqual(href, NULL)
); | 464 has_empty_ns = (xmlC14NStrEqual(prefix, NULL) && xmlC14NStrEqual(href, NULL)
); |
| 463 | 465 |
| 464 if (cur->nsTab != NULL) { | 466 if (cur->nsTab != NULL) { |
| 465 int start = 0; | 467 int start = 0; |
| 466 for (i = cur->nsCurEnd - 1; i >= start; --i) { | 468 for (i = cur->nsCurEnd - 1; i >= start; --i) { |
| 467 xmlNsPtr ns1 = cur->nsTab[i]; | 469 xmlNsPtr ns1 = cur->nsTab[i]; |
| 468 » | 470 |
| 469 if(xmlC14NStrEqual(prefix, (ns1 != NULL) ? ns1->prefix : NULL)) { | 471 if(xmlC14NStrEqual(prefix, (ns1 != NULL) ? ns1->prefix : NULL)) { |
| 470 if(xmlC14NStrEqual(href, (ns1 != NULL) ? ns1->href : NULL)) { | 472 if(xmlC14NStrEqual(href, (ns1 != NULL) ? ns1->href : NULL)) { |
| 471 » » return(xmlC14NIsVisible(ctx, ns1, cur->nodeTab[i])); | 473 » » return(xmlC14NIsVisible(ctx, ns1, cur->nodeTab[i])); |
| 472 } else { | 474 } else { |
| 473 return(0); | 475 return(0); |
| 474 } | 476 } |
| 475 } | 477 } |
| 476 } | 478 } |
| 477 } | 479 } |
| 478 return(has_empty_ns); | 480 return(has_empty_ns); |
| 479 } | 481 } |
| 480 | 482 |
| 481 | 483 |
| 482 | 484 |
| 483 | 485 |
| 484 /** | 486 /** |
| 485 * xmlC14NIsXmlNs: | 487 * xmlC14NIsXmlNs: |
| 486 * @ns: » » the namespace to check | 488 * @ns:»» the namespace to check |
| 487 * » » | 489 * |
| 488 * Checks whether the given namespace is a default "xml:" namespace | 490 * Checks whether the given namespace is a default "xml:" namespace |
| 489 * with href="http://www.w3.org/XML/1998/namespace" | 491 * with href="http://www.w3.org/XML/1998/namespace" |
| 490 * | 492 * |
| 491 * Returns 1 if the node is default or 0 otherwise | 493 * Returns 1 if the node is default or 0 otherwise |
| 492 */ | 494 */ |
| 493 | 495 |
| 494 /* todo: make it a define? */ | 496 /* todo: make it a define? */ |
| 495 static int | 497 static int |
| 496 xmlC14NIsXmlNs(xmlNsPtr ns) | 498 xmlC14NIsXmlNs(xmlNsPtr ns) |
| 497 { | 499 { |
| 498 return ((ns != NULL) && | 500 return ((ns != NULL) && |
| 499 (xmlStrEqual(ns->prefix, BAD_CAST "xml")) && | 501 (xmlStrEqual(ns->prefix, BAD_CAST "xml")) && |
| 500 (xmlStrEqual(ns->href, XML_XML_NAMESPACE))); | 502 (xmlStrEqual(ns->href, XML_XML_NAMESPACE))); |
| 501 } | 503 } |
| 502 | 504 |
| 503 | 505 |
| 504 /** | 506 /** |
| 505 * xmlC14NNsCompare: | 507 * xmlC14NNsCompare: |
| 506 * @ns1: the pointer to first namespace | 508 * @ns1: the pointer to first namespace |
| 507 * @ns2: » » the pointer to second namespace | 509 * @ns2:» » the pointer to second namespace |
| 508 * | 510 * |
| 509 * Compares the namespaces by names (prefixes). | 511 * Compares the namespaces by names (prefixes). |
| 510 * | 512 * |
| 511 * Returns -1 if ns1 < ns2, 0 if ns1 == ns2 or 1 if ns1 > ns2. | 513 * Returns -1 if ns1 < ns2, 0 if ns1 == ns2 or 1 if ns1 > ns2. |
| 512 */ | 514 */ |
| 513 static int | 515 static int |
| 514 xmlC14NNsCompare(xmlNsPtr ns1, xmlNsPtr ns2) | 516 xmlC14NNsCompare(xmlNsPtr ns1, xmlNsPtr ns2) |
| 515 { | 517 { |
| 516 if (ns1 == ns2) | 518 if (ns1 == ns2) |
| 517 return (0); | 519 return (0); |
| 518 if (ns1 == NULL) | 520 if (ns1 == NULL) |
| 519 return (-1); | 521 return (-1); |
| 520 if (ns2 == NULL) | 522 if (ns2 == NULL) |
| 521 return (1); | 523 return (1); |
| 522 | 524 |
| 523 return (xmlStrcmp(ns1->prefix, ns2->prefix)); | 525 return (xmlStrcmp(ns1->prefix, ns2->prefix)); |
| 524 } | 526 } |
| 525 | 527 |
| 526 | 528 |
| 527 /** | 529 /** |
| 528 * xmlC14NPrintNamespaces: | 530 * xmlC14NPrintNamespaces: |
| 529 * @ns: the pointer to namespace | 531 * @ns: the pointer to namespace |
| 530 * @ctx: » » the C14N context | 532 * @ctx:» » the C14N context |
| 531 * | 533 * |
| 532 * Prints the given namespace to the output buffer from C14N context. | 534 * Prints the given namespace to the output buffer from C14N context. |
| 533 * | 535 * |
| 534 * Returns 1 on success or 0 on fail. | 536 * Returns 1 on success or 0 on fail. |
| 535 */ | 537 */ |
| 536 static int | 538 static int |
| 537 xmlC14NPrintNamespaces(const xmlNsPtr ns, xmlC14NCtxPtr ctx) | 539 xmlC14NPrintNamespaces(const xmlNsPtr ns, xmlC14NCtxPtr ctx) |
| 538 { | 540 { |
| 539 | 541 |
| 540 if ((ns == NULL) || (ctx == NULL)) { | 542 if ((ns == NULL) || (ctx == NULL)) { |
| 541 xmlC14NErrParam("writing namespaces"); | 543 xmlC14NErrParam("writing namespaces"); |
| 542 return 0; | 544 return 0; |
| 543 } | 545 } |
| 544 | 546 |
| 545 if (ns->prefix != NULL) { | 547 if (ns->prefix != NULL) { |
| 546 xmlOutputBufferWriteString(ctx->buf, " xmlns:"); | 548 xmlOutputBufferWriteString(ctx->buf, " xmlns:"); |
| 547 xmlOutputBufferWriteString(ctx->buf, (const char *) ns->prefix); | 549 xmlOutputBufferWriteString(ctx->buf, (const char *) ns->prefix); |
| 548 xmlOutputBufferWriteString(ctx->buf, "=\""); | 550 xmlOutputBufferWriteString(ctx->buf, "="); |
| 549 } else { | 551 } else { |
| 550 xmlOutputBufferWriteString(ctx->buf, " xmlns=\""); | 552 xmlOutputBufferWriteString(ctx->buf, " xmlns="); |
| 551 } | 553 } |
| 552 if(ns->href != NULL) { | 554 if(ns->href != NULL) { |
| 553 » xmlOutputBufferWriteString(ctx->buf, (const char *) ns->href); | 555 » xmlBufWriteQuotedString(ctx->buf->buffer, ns->href); |
| 556 } else { |
| 557 » xmlOutputBufferWriteString(ctx->buf, "\"\""); |
| 554 } | 558 } |
| 555 xmlOutputBufferWriteString(ctx->buf, "\""); | |
| 556 return (1); | 559 return (1); |
| 557 } | 560 } |
| 558 | 561 |
| 559 /** | 562 /** |
| 560 * xmlC14NProcessNamespacesAxis: | 563 * xmlC14NProcessNamespacesAxis: |
| 561 * @ctx: » » the C14N context | 564 * @ctx:» » the C14N context |
| 562 * @node: the current node | 565 * @node: the current node |
| 563 * | 566 * |
| 564 * Prints out canonical namespace axis of the current node to the | 567 * Prints out canonical namespace axis of the current node to the |
| 565 * buffer from C14N context as follows | 568 * buffer from C14N context as follows |
| 566 * | 569 * |
| 567 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) | 570 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) |
| 568 * | 571 * |
| 569 * Namespace Axis | 572 * Namespace Axis |
| 570 * Consider a list L containing only namespace nodes in the | 573 * Consider a list L containing only namespace nodes in the |
| 571 * axis and in the node-set in lexicographic order (ascending). To begin | 574 * axis and in the node-set in lexicographic order (ascending). To begin |
| 572 * processing L, if the first node is not the default namespace node (a node | 575 * processing L, if the first node is not the default namespace node (a node |
| 573 * with no namespace URI and no local name), then generate a space followed | 576 * with no namespace URI and no local name), then generate a space followed |
| 574 * by xmlns="" if and only if the following conditions are met: | 577 * by xmlns="" if and only if the following conditions are met: |
| 575 * - the element E that owns the axis is in the node-set | 578 * - the element E that owns the axis is in the node-set |
| 576 * - The nearest ancestor element of E in the node-set has a default | 579 * - The nearest ancestor element of E in the node-set has a default |
| 577 *» namespace node in the node-set (default namespace nodes always | 580 *» namespace node in the node-set (default namespace nodes always |
| 578 * have non-empty values in XPath) | 581 * have non-empty values in XPath) |
| 579 * The latter condition eliminates unnecessary occurrences of xmlns="" in | 582 * The latter condition eliminates unnecessary occurrences of xmlns="" in |
| 580 * the canonical form since an element only receives an xmlns="" if its | 583 * the canonical form since an element only receives an xmlns="" if its |
| 581 * default namespace is empty and if it has an immediate parent in the | 584 * default namespace is empty and if it has an immediate parent in the |
| 582 * canonical form that has a non-empty default namespace. To finish | 585 * canonical form that has a non-empty default namespace. To finish |
| 583 * processing L, simply process every namespace node in L, except omit | 586 * processing L, simply process every namespace node in L, except omit |
| 584 * namespace node with local name xml, which defines the xml prefix, | 587 * namespace node with local name xml, which defines the xml prefix, |
| 585 * if its string value is http://www.w3.org/XML/1998/namespace. | 588 * if its string value is http://www.w3.org/XML/1998/namespace. |
| 586 * | 589 * |
| 587 * Exclusive XML Canonicalization v 1.0 (http://www.w3.org/TR/xml-exc-c14n) | 590 * Exclusive XML Canonicalization v 1.0 (http://www.w3.org/TR/xml-exc-c14n) |
| 588 * Canonical XML applied to a document subset requires the search of the | 591 * Canonical XML applied to a document subset requires the search of the |
| 589 * ancestor nodes of each orphan element node for attributes in the xml | 592 * ancestor nodes of each orphan element node for attributes in the xml |
| 590 * namespace, such as xml:lang and xml:space. These are copied into the | 593 * namespace, such as xml:lang and xml:space. These are copied into the |
| 591 * element node except if a declaration of the same attribute is already | 594 * element node except if a declaration of the same attribute is already |
| 592 * in the attribute axis of the element (whether or not it is included in | 595 * in the attribute axis of the element (whether or not it is included in |
| 593 * the document subset). This search and copying are omitted from the | 596 * the document subset). This search and copying are omitted from the |
| 594 * Exclusive XML Canonicalization method. | 597 * Exclusive XML Canonicalization method. |
| 595 * | 598 * |
| 596 * Returns 0 on success or -1 on fail. | 599 * Returns 0 on success or -1 on fail. |
| 597 */ | 600 */ |
| 598 static int | 601 static int |
| 599 xmlC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) | 602 xmlC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) |
| 600 { | 603 { |
| 601 xmlNodePtr n; | 604 xmlNodePtr n; |
| 602 xmlNsPtr ns, tmp; | 605 xmlNsPtr ns, tmp; |
| 603 xmlListPtr list; | 606 xmlListPtr list; |
| 604 int already_rendered; | 607 int already_rendered; |
| 605 int has_empty_ns = 0; | 608 int has_empty_ns = 0; |
| 606 | 609 |
| 607 if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { | 610 if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { |
| 608 xmlC14NErrParam("processing namespaces axis (c14n)"); | 611 xmlC14NErrParam("processing namespaces axis (c14n)"); |
| 609 return (-1); | 612 return (-1); |
| 610 } | 613 } |
| 611 | 614 |
| 612 /* | 615 /* |
| 613 * Create a sorted list to store element namespaces | 616 * Create a sorted list to store element namespaces |
| 614 */ | 617 */ |
| 615 list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NNsCompare); | 618 list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NNsCompare); |
| 616 if (list == NULL) { | 619 if (list == NULL) { |
| 617 xmlC14NErrInternal("creating namespaces list (c14n)"); | 620 xmlC14NErrInternal("creating namespaces list (c14n)"); |
| 618 return (-1); | 621 return (-1); |
| 619 } | 622 } |
| 620 | 623 |
| 621 /* check all namespaces */ | 624 /* check all namespaces */ |
| 622 for(n = cur; n != NULL; n = n->parent) { | 625 for(n = cur; n != NULL; n = n->parent) { |
| 623 for(ns = n->nsDef; ns != NULL; ns = ns->next) { | 626 for(ns = n->nsDef; ns != NULL; ns = ns->next) { |
| 624 tmp = xmlSearchNs(cur->doc, cur, ns->prefix); | 627 tmp = xmlSearchNs(cur->doc, cur, ns->prefix); |
| 625 » | 628 |
| 626 if((tmp == ns) && !xmlC14NIsXmlNs(ns) && xmlC14NIsVisible(ctx, ns, c
ur)) { | 629 if((tmp == ns) && !xmlC14NIsXmlNs(ns) && xmlC14NIsVisible(ctx, ns, c
ur)) { |
| 627 already_rendered = xmlC14NVisibleNsStackFind(ctx->ns_rendered, n
s); | 630 already_rendered = xmlC14NVisibleNsStackFind(ctx->ns_rendered, n
s); |
| 628 if(visible) { | 631 if(visible) { |
| 629 » xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); | 632 » xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); |
| 630 } | 633 } |
| 631 if(!already_rendered) { | 634 if(!already_rendered) { |
| 632 » » xmlListInsert(list, ns); | 635 » » xmlListInsert(list, ns); |
| 633 } | 636 } |
| 634 » » if(xmlStrlen(ns->prefix) == 0) { | 637 » » if(xmlStrlen(ns->prefix) == 0) { |
| 635 has_empty_ns = 1; | 638 has_empty_ns = 1; |
| 636 } | 639 } |
| 637 } | 640 } |
| 638 } | 641 } |
| 639 } | 642 } |
| 640 » | 643 |
| 641 /** | 644 /** |
| 642 * if the first node is not the default namespace node (a node with no | 645 * if the first node is not the default namespace node (a node with no |
| 643 * namespace URI and no local name), then generate a space followed by | 646 * namespace URI and no local name), then generate a space followed by |
| 644 * xmlns="" if and only if the following conditions are met: | 647 * xmlns="" if and only if the following conditions are met: |
| 645 * - the element E that owns the axis is in the node-set | 648 * - the element E that owns the axis is in the node-set |
| 646 * - the nearest ancestor element of E in the node-set has a default | 649 * - the nearest ancestor element of E in the node-set has a default |
| 647 * namespace node in the node-set (default namespace nodes always | 650 * namespace node in the node-set (default namespace nodes always |
| 648 * have non-empty values in XPath) | 651 * have non-empty values in XPath) |
| 649 */ | 652 */ |
| 650 if(visible && !has_empty_ns) { | 653 if(visible && !has_empty_ns) { |
| 651 static xmlNs ns_default; | 654 static xmlNs ns_default; |
| 652 | 655 |
| 653 memset(&ns_default, 0, sizeof(ns_default)); | 656 memset(&ns_default, 0, sizeof(ns_default)); |
| 654 if(!xmlC14NVisibleNsStackFind(ctx->ns_rendered, &ns_default)) { | 657 if(!xmlC14NVisibleNsStackFind(ctx->ns_rendered, &ns_default)) { |
| 655 » xmlC14NPrintNamespaces(&ns_default, ctx); | 658 » xmlC14NPrintNamespaces(&ns_default, ctx); |
| 656 } | 659 } |
| 657 } | 660 } |
| 658 » | 661 |
| 659 | 662 |
| 660 /* | 663 /* |
| 661 * print out all elements from list | 664 * print out all elements from list |
| 662 */ | 665 */ |
| 663 xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx
); | 666 xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx
); |
| 664 | 667 |
| 665 /* | 668 /* |
| 666 * Cleanup | 669 * Cleanup |
| 667 */ | 670 */ |
| 668 xmlListDelete(list); | 671 xmlListDelete(list); |
| 669 return (0); | 672 return (0); |
| 670 } | 673 } |
| 671 | 674 |
| 672 | 675 |
| 673 /** | 676 /** |
| 674 * xmlExcC14NProcessNamespacesAxis: | 677 * xmlExcC14NProcessNamespacesAxis: |
| 675 * @ctx: » » the C14N context | 678 * @ctx:» » the C14N context |
| 676 * @node: the current node | 679 * @node: the current node |
| 677 * | 680 * |
| 678 * Prints out exclusive canonical namespace axis of the current node to the | 681 * Prints out exclusive canonical namespace axis of the current node to the |
| 679 * buffer from C14N context as follows | 682 * buffer from C14N context as follows |
| 680 * | 683 * |
| 681 * Exclusive XML Canonicalization | 684 * Exclusive XML Canonicalization |
| 682 * http://www.w3.org/TR/xml-exc-c14n | 685 * http://www.w3.org/TR/xml-exc-c14n |
| 683 * | 686 * |
| 684 * If the element node is in the XPath subset then output the node in | 687 * If the element node is in the XPath subset then output the node in |
| 685 * accordance with Canonical XML except for namespace nodes which are | 688 * accordance with Canonical XML except for namespace nodes which are |
| 686 * rendered as follows: | 689 * rendered as follows: |
| 687 * | 690 * |
| 688 * 1. Render each namespace node iff: | 691 * 1. Render each namespace node iff: |
| 689 * * it is visibly utilized by the immediate parent element or one of | 692 * * it is visibly utilized by the immediate parent element or one of |
| 690 * its attributes, or is present in InclusiveNamespaces PrefixList, and | 693 * its attributes, or is present in InclusiveNamespaces PrefixList, and |
| 691 * * its prefix and value do not appear in ns_rendered. ns_rendered is | 694 * * its prefix and value do not appear in ns_rendered. ns_rendered is |
| 692 * obtained by popping the state stack in order to obtain a list of | 695 * obtained by popping the state stack in order to obtain a list of |
| 693 * prefixes and their values which have already been rendered by | 696 * prefixes and their values which have already been rendered by |
| 694 * an output ancestor of the namespace node's parent element. | 697 * an output ancestor of the namespace node's parent element. |
| 695 * 2. Append the rendered namespace node to the list ns_rendered of namespace | 698 * 2. Append the rendered namespace node to the list ns_rendered of namespace |
| 696 * nodes rendered by output ancestors. Push ns_rendered on state stack and | 699 * nodes rendered by output ancestors. Push ns_rendered on state stack and |
| 697 * recurse. | 700 * recurse. |
| 698 * 3. After the recursion returns, pop thestate stack. | 701 * 3. After the recursion returns, pop thestate stack. |
| 699 * | 702 * |
| 700 * | 703 * |
| 701 * Returns 0 on success or -1 on fail. | 704 * Returns 0 on success or -1 on fail. |
| 702 */ | 705 */ |
| 703 static int | 706 static int |
| 704 xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) | 707 xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) |
| 705 { | 708 { |
| 706 xmlNsPtr ns; | 709 xmlNsPtr ns; |
| 707 xmlListPtr list; | 710 xmlListPtr list; |
| 708 xmlAttrPtr attr; | 711 xmlAttrPtr attr; |
| 709 int already_rendered; | 712 int already_rendered; |
| 710 int has_empty_ns = 0; | 713 int has_empty_ns = 0; |
| 711 int has_visibly_utilized_empty_ns = 0; | 714 int has_visibly_utilized_empty_ns = 0; |
| 712 int has_empty_ns_in_inclusive_list = 0; | 715 int has_empty_ns_in_inclusive_list = 0; |
| 713 | 716 |
| 714 if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { | 717 if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { |
| 715 xmlC14NErrParam("processing namespaces axis (exc c14n)"); | 718 xmlC14NErrParam("processing namespaces axis (exc c14n)"); |
| 716 return (-1); | 719 return (-1); |
| 717 } | 720 } |
| 718 | 721 |
| 719 if(!xmlC14NIsExclusive(ctx)) { | 722 if(!xmlC14NIsExclusive(ctx)) { |
| 720 xmlC14NErrParam("processing namespaces axis (exc c14n)"); | 723 xmlC14NErrParam("processing namespaces axis (exc c14n)"); |
| 721 return (-1); | 724 return (-1); |
| 722 | 725 |
| 723 } | 726 } |
| 724 | 727 |
| 725 /* | 728 /* |
| 726 * Create a sorted list to store element namespaces | 729 * Create a sorted list to store element namespaces |
| 727 */ | 730 */ |
| 728 list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NNsCompare); | 731 list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NNsCompare); |
| 729 if (list == NULL) { | 732 if (list == NULL) { |
| 730 xmlC14NErrInternal("creating namespaces list (exc c14n)"); | 733 xmlC14NErrInternal("creating namespaces list (exc c14n)"); |
| 731 return (-1); | 734 return (-1); |
| 732 } | 735 } |
| 733 | 736 |
| 734 /* | 737 /* |
| 735 * process inclusive namespaces: | 738 * process inclusive namespaces: |
| 736 * All namespace nodes appearing on inclusive ns list are | 739 * All namespace nodes appearing on inclusive ns list are |
| 737 * handled as provided in Canonical XML | 740 * handled as provided in Canonical XML |
| 738 */ | 741 */ |
| 739 if(ctx->inclusive_ns_prefixes != NULL) { | 742 if(ctx->inclusive_ns_prefixes != NULL) { |
| 740 » xmlChar *prefix; | 743 » xmlChar *prefix; |
| 741 int i; | 744 int i; |
| 742 » | 745 |
| 743 for (i = 0; ctx->inclusive_ns_prefixes[i] != NULL; ++i) { | 746 for (i = 0; ctx->inclusive_ns_prefixes[i] != NULL; ++i) { |
| 744 prefix = ctx->inclusive_ns_prefixes[i]; | 747 prefix = ctx->inclusive_ns_prefixes[i]; |
| 745 /* | 748 /* |
| 746 * Special values for namespace with empty prefix | 749 * Special values for namespace with empty prefix |
| 747 */ | 750 */ |
| 748 if (xmlStrEqual(prefix, BAD_CAST "#default") | 751 if (xmlStrEqual(prefix, BAD_CAST "#default") |
| 749 || xmlStrEqual(prefix, BAD_CAST "")) { | 752 || xmlStrEqual(prefix, BAD_CAST "")) { |
| 750 prefix = NULL; | 753 prefix = NULL; |
| 751 has_empty_ns_in_inclusive_list = 1; | 754 has_empty_ns_in_inclusive_list = 1; |
| 752 } | 755 } |
| 753 » | 756 |
| 754 » ns = xmlSearchNs(cur->doc, cur, prefix);» | 757 » ns = xmlSearchNs(cur->doc, cur, prefix); |
| 755 if((ns != NULL) && !xmlC14NIsXmlNs(ns) && xmlC14NIsVisible(ctx, ns,
cur)) { | 758 if((ns != NULL) && !xmlC14NIsXmlNs(ns) && xmlC14NIsVisible(ctx, ns,
cur)) { |
| 756 already_rendered = xmlC14NVisibleNsStackFind(ctx->ns_rendered, n
s); | 759 already_rendered = xmlC14NVisibleNsStackFind(ctx->ns_rendered, n
s); |
| 757 if(visible) { | 760 if(visible) { |
| 758 » » xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); | 761 » » xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); |
| 759 } | 762 } |
| 760 if(!already_rendered) { | 763 if(!already_rendered) { |
| 761 » » xmlListInsert(list, ns); | 764 » » xmlListInsert(list, ns); |
| 762 } | 765 } |
| 763 » » if(xmlStrlen(ns->prefix) == 0) { | 766 » » if(xmlStrlen(ns->prefix) == 0) { |
| 764 has_empty_ns = 1; | 767 has_empty_ns = 1; |
| 765 } | 768 } |
| 766 } | 769 } |
| 767 } | 770 } |
| 768 } | 771 } |
| 769 | 772 |
| 770 /* add node namespace */ | 773 /* add node namespace */ |
| 771 if(cur->ns != NULL) { | 774 if(cur->ns != NULL) { |
| 772 ns = cur->ns; | 775 ns = cur->ns; |
| 773 } else { | 776 } else { |
| 774 ns = xmlSearchNs(cur->doc, cur, NULL); | 777 ns = xmlSearchNs(cur->doc, cur, NULL); |
| 775 has_visibly_utilized_empty_ns = 1; | 778 has_visibly_utilized_empty_ns = 1; |
| 776 } | 779 } |
| 777 if((ns != NULL) && !xmlC14NIsXmlNs(ns)) { | 780 if((ns != NULL) && !xmlC14NIsXmlNs(ns)) { |
| 778 » if(visible && xmlC14NIsVisible(ctx, ns, cur)) { | 781 » if(visible && xmlC14NIsVisible(ctx, ns, cur)) { |
| 779 if(!xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, ns, ctx)) { | 782 if(!xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, ns, ctx)) { |
| 780 xmlListInsert(list, ns); | 783 xmlListInsert(list, ns); |
| 781 } | 784 } |
| 782 } | 785 } |
| 783 if(visible) { | 786 if(visible) { |
| 784 » xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); | 787 » xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); |
| 785 } | 788 } |
| 786 if(xmlStrlen(ns->prefix) == 0) { | 789 if(xmlStrlen(ns->prefix) == 0) { |
| 787 has_empty_ns = 1; | 790 has_empty_ns = 1; |
| 788 } | 791 } |
| 789 } | 792 } |
| 790 | 793 |
| 791 | 794 |
| 792 /* add attributes */ | 795 /* add attributes */ |
| 793 for(attr = cur->properties; attr != NULL; attr = attr->next) { | 796 for(attr = cur->properties; attr != NULL; attr = attr->next) { |
| 794 /* | 797 /* |
| 795 * we need to check that attribute is visible and has non | 798 * we need to check that attribute is visible and has non |
| 796 * default namespace (XML Namespaces: "default namespaces | 799 * default namespace (XML Namespaces: "default namespaces |
| 797 » * do not apply directly to attributes")» | 800 » * do not apply directly to attributes") |
| 798 */ | 801 */ |
| 799 if((attr->ns != NULL) && !xmlC14NIsXmlNs(attr->ns) && xmlC14NIsVisible(c
tx, attr, cur)) { | 802 if((attr->ns != NULL) && !xmlC14NIsXmlNs(attr->ns) && xmlC14NIsVisible(c
tx, attr, cur)) { |
| 800 already_rendered = xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, at
tr->ns, ctx); | 803 already_rendered = xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, at
tr->ns, ctx); |
| 801 » xmlC14NVisibleNsStackAdd(ctx->ns_rendered, attr->ns, cur); | 804 » xmlC14NVisibleNsStackAdd(ctx->ns_rendered, attr->ns, cur); |
| 802 if(!already_rendered && visible) { | 805 if(!already_rendered && visible) { |
| 803 » » xmlListInsert(list, attr->ns); | 806 » » xmlListInsert(list, attr->ns); |
| 804 } | 807 } |
| 805 if(xmlStrlen(attr->ns->prefix) == 0) { | 808 if(xmlStrlen(attr->ns->prefix) == 0) { |
| 806 has_empty_ns = 1; | 809 has_empty_ns = 1; |
| 807 } | 810 } |
| 808 } else if((attr->ns != NULL) && (xmlStrlen(attr->ns->prefix) == 0) && (x
mlStrlen(attr->ns->href) == 0)) { | 811 } else if((attr->ns != NULL) && (xmlStrlen(attr->ns->prefix) == 0) && (x
mlStrlen(attr->ns->href) == 0)) { |
| 809 has_visibly_utilized_empty_ns = 1; | 812 has_visibly_utilized_empty_ns = 1; |
| 810 } | 813 } |
| 811 } | 814 } |
| 812 | 815 |
| 813 /* | 816 /* |
| 814 * Process xmlns="" | 817 * Process xmlns="" |
| 815 */ | 818 */ |
| 816 if(visible && has_visibly_utilized_empty_ns && | 819 if(visible && has_visibly_utilized_empty_ns && |
| 817 !has_empty_ns && !has_empty_ns_in_inclusive_list) { | 820 !has_empty_ns && !has_empty_ns_in_inclusive_list) { |
| 818 static xmlNs ns_default; | 821 static xmlNs ns_default; |
| 819 | 822 |
| 820 memset(&ns_default, 0, sizeof(ns_default)); | 823 memset(&ns_default, 0, sizeof(ns_default)); |
| 821 » | 824 |
| 822 already_rendered = xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, &ns_de
fault, ctx); | 825 already_rendered = xmlExcC14NVisibleNsStackFind(ctx->ns_rendered, &ns_de
fault, ctx); |
| 823 if(!already_rendered) { | 826 if(!already_rendered) { |
| 824 » xmlC14NPrintNamespaces(&ns_default, ctx); | 827 » xmlC14NPrintNamespaces(&ns_default, ctx); |
| 825 } | 828 } |
| 826 } else if(visible && !has_empty_ns && has_empty_ns_in_inclusive_list) { | 829 } else if(visible && !has_empty_ns && has_empty_ns_in_inclusive_list) { |
| 827 static xmlNs ns_default; | 830 static xmlNs ns_default; |
| 828 | 831 |
| 829 memset(&ns_default, 0, sizeof(ns_default)); | 832 memset(&ns_default, 0, sizeof(ns_default)); |
| 830 if(!xmlC14NVisibleNsStackFind(ctx->ns_rendered, &ns_default)) { | 833 if(!xmlC14NVisibleNsStackFind(ctx->ns_rendered, &ns_default)) { |
| 831 » xmlC14NPrintNamespaces(&ns_default, ctx); | 834 » xmlC14NPrintNamespaces(&ns_default, ctx); |
| 832 } | 835 } |
| 833 } | 836 } |
| 834 | 837 |
| 835 | |
| 836 | 838 |
| 837 /* | 839 |
| 838 * print out all elements from list | 840 /* |
| 841 * print out all elements from list |
| 839 */ | 842 */ |
| 840 xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx
); | 843 xmlListWalk(list, (xmlListWalker) xmlC14NPrintNamespaces, (const void *) ctx
); |
| 841 | 844 |
| 842 /* | 845 /* |
| 843 * Cleanup | 846 * Cleanup |
| 844 */ | 847 */ |
| 845 xmlListDelete(list); | 848 xmlListDelete(list); |
| 846 return (0); | 849 return (0); |
| 847 } | 850 } |
| 848 | 851 |
| 849 | 852 |
| 850 /** | 853 /** |
| 851 * xmlC14NIsXmlAttr: | 854 * xmlC14NIsXmlAttr: |
| 852 * @attr: » » the attr to check | 855 * @attr:» » the attr to check |
| 853 * » » | 856 * |
| 854 * Checks whether the given attribute is a default "xml:" namespace | 857 * Checks whether the given attribute is a default "xml:" namespace |
| 855 * with href="http://www.w3.org/XML/1998/namespace" | 858 * with href="http://www.w3.org/XML/1998/namespace" |
| 856 * | 859 * |
| 857 * Returns 1 if the node is default or 0 otherwise | 860 * Returns 1 if the node is default or 0 otherwise |
| 858 */ | 861 */ |
| 859 | 862 |
| 860 /* todo: make it a define? */ | 863 /* todo: make it a define? */ |
| 861 static int | 864 static int |
| 862 xmlC14NIsXmlAttr(xmlAttrPtr attr) | 865 xmlC14NIsXmlAttr(xmlAttrPtr attr) |
| 863 { | 866 { |
| 864 return ((attr->ns != NULL) && | 867 return ((attr->ns != NULL) && |
| 865 (xmlC14NIsXmlNs(attr->ns) != 0)); | 868 (xmlC14NIsXmlNs(attr->ns) != 0)); |
| 866 } | 869 } |
| 867 | 870 |
| 868 | 871 |
| 869 /** | 872 /** |
| 870 * xmlC14NAttrsCompare: | 873 * xmlC14NAttrsCompare: |
| 871 * @attr1: the pointer tls o first attr | 874 * @attr1: the pointer tls o first attr |
| 872 * @attr2: » » the pointer to second attr | 875 * @attr2:» » the pointer to second attr |
| 873 * | 876 * |
| 874 * Prints the given attribute to the output buffer from C14N context. | 877 * Prints the given attribute to the output buffer from C14N context. |
| 875 * | 878 * |
| 876 * Returns -1 if attr1 < attr2, 0 if attr1 == attr2 or 1 if attr1 > attr2. | 879 * Returns -1 if attr1 < attr2, 0 if attr1 == attr2 or 1 if attr1 > attr2. |
| 877 */ | 880 */ |
| 878 static int | 881 static int |
| 879 xmlC14NAttrsCompare(xmlAttrPtr attr1, xmlAttrPtr attr2) | 882 xmlC14NAttrsCompare(xmlAttrPtr attr1, xmlAttrPtr attr2) |
| 880 { | 883 { |
| 881 int ret = 0; | 884 int ret = 0; |
| 882 | 885 |
| 883 /* | 886 /* |
| 884 * Simple cases | 887 * Simple cases |
| 885 */ | 888 */ |
| 886 if (attr1 == attr2) | 889 if (attr1 == attr2) |
| 887 return (0); | 890 return (0); |
| 888 if (attr1 == NULL) | 891 if (attr1 == NULL) |
| 889 return (-1); | 892 return (-1); |
| 890 if (attr2 == NULL) | 893 if (attr2 == NULL) |
| 891 return (1); | 894 return (1); |
| 892 if (attr1->ns == attr2->ns) { | 895 if (attr1->ns == attr2->ns) { |
| 893 return (xmlStrcmp(attr1->name, attr2->name)); | 896 return (xmlStrcmp(attr1->name, attr2->name)); |
| 894 } | 897 } |
| 895 | 898 |
| 896 /* | 899 /* |
| 897 * Attributes in the default namespace are first | 900 * Attributes in the default namespace are first |
| 898 * because the default namespace is not applied to | 901 * because the default namespace is not applied to |
| 899 * unqualified attributes | 902 * unqualified attributes |
| 900 */ | 903 */ |
| 901 if (attr1->ns == NULL) | 904 if (attr1->ns == NULL) |
| 902 return (-1); | 905 return (-1); |
| 903 if (attr2->ns == NULL) | 906 if (attr2->ns == NULL) |
| 904 return (1); | 907 return (1); |
| 905 if (attr1->ns->prefix == NULL) | 908 if (attr1->ns->prefix == NULL) |
| 906 return (-1); | 909 return (-1); |
| 907 if (attr2->ns->prefix == NULL) | 910 if (attr2->ns->prefix == NULL) |
| 908 return (1); | 911 return (1); |
| 909 | 912 |
| 910 ret = xmlStrcmp(attr1->ns->href, attr2->ns->href); | 913 ret = xmlStrcmp(attr1->ns->href, attr2->ns->href); |
| 911 if (ret == 0) { | 914 if (ret == 0) { |
| 912 ret = xmlStrcmp(attr1->name, attr2->name); | 915 ret = xmlStrcmp(attr1->name, attr2->name); |
| 913 } | 916 } |
| 914 return (ret); | 917 return (ret); |
| 915 } | 918 } |
| 916 | 919 |
| 917 | 920 |
| 918 /** | 921 /** |
| 919 * xmlC14NPrintAttrs: | 922 * xmlC14NPrintAttrs: |
| 920 * @attr: the pointer to attr | 923 * @attr: the pointer to attr |
| 921 * @ctx: » » the C14N context | 924 * @ctx:» » the C14N context |
| 922 * | 925 * |
| 923 * Prints out canonical attribute urrent node to the | 926 * Prints out canonical attribute urrent node to the |
| 924 * buffer from C14N context as follows | 927 * buffer from C14N context as follows |
| 925 * | 928 * |
| 926 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) | 929 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) |
| 927 * | 930 * |
| 928 * Returns 1 on success or 0 on fail. | 931 * Returns 1 on success or 0 on fail. |
| 929 */ | 932 */ |
| 930 static int | 933 static int |
| 931 xmlC14NPrintAttrs(const xmlAttrPtr attr, xmlC14NCtxPtr ctx) | 934 xmlC14NPrintAttrs(const xmlAttrPtr attr, xmlC14NCtxPtr ctx) |
| 932 { | 935 { |
| 933 xmlChar *value; | 936 xmlChar *value; |
| 934 xmlChar *buffer; | 937 xmlChar *buffer; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 961 } | 964 } |
| 962 } | 965 } |
| 963 xmlOutputBufferWriteString(ctx->buf, "\""); | 966 xmlOutputBufferWriteString(ctx->buf, "\""); |
| 964 return (1); | 967 return (1); |
| 965 } | 968 } |
| 966 | 969 |
| 967 /** | 970 /** |
| 968 * xmlC14NFindHiddenParentAttr: | 971 * xmlC14NFindHiddenParentAttr: |
| 969 * | 972 * |
| 970 * Finds an attribute in a hidden parent node. | 973 * Finds an attribute in a hidden parent node. |
| 971 * | 974 * |
| 972 * Returns a pointer to the attribute node (if found) or NULL otherwise. | 975 * Returns a pointer to the attribute node (if found) or NULL otherwise. |
| 973 */ | 976 */ |
| 974 static xmlAttrPtr | 977 static xmlAttrPtr |
| 975 xmlC14NFindHiddenParentAttr(xmlC14NCtxPtr ctx, xmlNodePtr cur, const xmlChar * n
ame, const xmlChar * ns) | 978 xmlC14NFindHiddenParentAttr(xmlC14NCtxPtr ctx, xmlNodePtr cur, const xmlChar * n
ame, const xmlChar * ns) |
| 976 { | 979 { |
| 977 xmlAttrPtr res; | 980 xmlAttrPtr res; |
| 978 while((cur != NULL) && (!xmlC14NIsVisible(ctx, cur, cur->parent))) { | 981 while((cur != NULL) && (!xmlC14NIsVisible(ctx, cur, cur->parent))) { |
| 979 res = xmlHasNsProp(cur, name, ns); | 982 res = xmlHasNsProp(cur, name, ns); |
| 980 if(res != NULL) { | 983 if(res != NULL) { |
| 981 return res; | 984 return res; |
| 982 } | 985 } |
| 983 | 986 |
| 984 cur = cur->parent; | 987 cur = cur->parent; |
| 985 } | 988 } |
| 986 | 989 |
| 987 return NULL; | 990 return NULL; |
| 988 } | 991 } |
| 989 | 992 |
| 990 /** | 993 /** |
| 991 * xmlC14NFixupBaseAttr: | 994 * xmlC14NFixupBaseAttr: |
| 992 * | 995 * |
| 993 * Fixes up the xml:base attribute | 996 * Fixes up the xml:base attribute |
| 994 * | 997 * |
| 995 * Returns the newly created attribute or NULL | 998 * Returns the newly created attribute or NULL |
| 996 */ | 999 */ |
| 997 static xmlAttrPtr | 1000 static xmlAttrPtr |
| 998 xmlC14NFixupBaseAttr(xmlC14NCtxPtr ctx, xmlAttrPtr xml_base_attr) | 1001 xmlC14NFixupBaseAttr(xmlC14NCtxPtr ctx, xmlAttrPtr xml_base_attr) |
| 999 { | 1002 { |
| 1000 xmlChar * res = NULL; | 1003 xmlChar * res = NULL; |
| 1001 xmlNodePtr cur; | 1004 xmlNodePtr cur; |
| 1002 xmlAttrPtr attr; | 1005 xmlAttrPtr attr; |
| 1003 xmlChar * tmp_str; | 1006 xmlChar * tmp_str; |
| 1004 xmlChar * tmp_str2; | 1007 xmlChar * tmp_str2; |
| 1005 int tmp_str_len; | 1008 int tmp_str_len; |
| 1006 | 1009 |
| 1007 if ((ctx == NULL) || (xml_base_attr == NULL) || (xml_base_attr->parent == NU
LL)) { | 1010 if ((ctx == NULL) || (xml_base_attr == NULL) || (xml_base_attr->parent == NU
LL)) { |
| 1008 xmlC14NErrParam("processing xml:base attribute"); | 1011 xmlC14NErrParam("processing xml:base attribute"); |
| 1009 return (NULL); | 1012 return (NULL); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1021 while((cur != NULL) && (!xmlC14NIsVisible(ctx, cur, cur->parent))) { | 1024 while((cur != NULL) && (!xmlC14NIsVisible(ctx, cur, cur->parent))) { |
| 1022 attr = xmlHasNsProp(cur, BAD_CAST "base", XML_XML_NAMESPACE); | 1025 attr = xmlHasNsProp(cur, BAD_CAST "base", XML_XML_NAMESPACE); |
| 1023 if(attr != NULL) { | 1026 if(attr != NULL) { |
| 1024 /* get attr value */ | 1027 /* get attr value */ |
| 1025 tmp_str = xmlNodeListGetString(ctx->doc, attr->children, 1); | 1028 tmp_str = xmlNodeListGetString(ctx->doc, attr->children, 1); |
| 1026 if(tmp_str == NULL) { | 1029 if(tmp_str == NULL) { |
| 1027 xmlFree(res); | 1030 xmlFree(res); |
| 1028 | 1031 |
| 1029 xmlC14NErrInternal("processing xml:base attribute - can't get at
tr value"); | 1032 xmlC14NErrInternal("processing xml:base attribute - can't get at
tr value"); |
| 1030 return (NULL); | 1033 return (NULL); |
| 1031 } | 1034 } |
| 1032 | 1035 |
| 1033 /* we need to add '/' if our current base uri ends with '..' or '.' | 1036 /* we need to add '/' if our current base uri ends with '..' or '.' |
| 1034 to ensure that we are forced to go "up" all the time */ | 1037 to ensure that we are forced to go "up" all the time */ |
| 1035 tmp_str_len = xmlStrlen(tmp_str); | 1038 tmp_str_len = xmlStrlen(tmp_str); |
| 1036 if(tmp_str_len > 1 && tmp_str[tmp_str_len - 2] == '.') { | 1039 if(tmp_str_len > 1 && tmp_str[tmp_str_len - 2] == '.') { |
| 1037 tmp_str2 = xmlStrcat(tmp_str, BAD_CAST "/"); | 1040 tmp_str2 = xmlStrcat(tmp_str, BAD_CAST "/"); |
| 1038 if(tmp_str2 == NULL) { | 1041 if(tmp_str2 == NULL) { |
| 1039 xmlFree(tmp_str); | 1042 xmlFree(tmp_str); |
| 1040 xmlFree(res); | 1043 xmlFree(res); |
| 1041 | 1044 |
| 1042 xmlC14NErrInternal("processing xml:base attribute - can't mo
dify uri"); | 1045 xmlC14NErrInternal("processing xml:base attribute - can't mo
dify uri"); |
| 1043 return (NULL); | 1046 return (NULL); |
| 1044 } | 1047 } |
| 1045 | 1048 |
| 1046 tmp_str = tmp_str2; | 1049 tmp_str = tmp_str2; |
| 1047 } | 1050 } |
| 1048 | 1051 |
| 1049 /* build uri */ | 1052 /* build uri */ |
| 1050 tmp_str2 = xmlBuildURI(res, tmp_str); | 1053 tmp_str2 = xmlBuildURI(res, tmp_str); |
| 1051 if(tmp_str2 == NULL) { | 1054 if(tmp_str2 == NULL) { |
| 1052 xmlFree(tmp_str); | 1055 xmlFree(tmp_str); |
| 1053 xmlFree(res); | 1056 xmlFree(res); |
| 1054 | 1057 |
| 1055 xmlC14NErrInternal("processing xml:base attribute - can't constr
uct uri"); | 1058 xmlC14NErrInternal("processing xml:base attribute - can't constr
uct uri"); |
| 1056 return (NULL); | 1059 return (NULL); |
| 1057 } | 1060 } |
| 1058 | 1061 |
| 1059 /* cleanup and set the new res */ | 1062 /* cleanup and set the new res */ |
| 1060 xmlFree(tmp_str); | 1063 xmlFree(tmp_str); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1073 } | 1076 } |
| 1074 | 1077 |
| 1075 /* create and return the new attribute node */ | 1078 /* create and return the new attribute node */ |
| 1076 attr = xmlNewNsProp(NULL, xml_base_attr->ns, BAD_CAST "base", res); | 1079 attr = xmlNewNsProp(NULL, xml_base_attr->ns, BAD_CAST "base", res); |
| 1077 if(attr == NULL) { | 1080 if(attr == NULL) { |
| 1078 xmlFree(res); | 1081 xmlFree(res); |
| 1079 | 1082 |
| 1080 xmlC14NErrInternal("processing xml:base attribute - can't construct attr
ibute"); | 1083 xmlC14NErrInternal("processing xml:base attribute - can't construct attr
ibute"); |
| 1081 return (NULL); | 1084 return (NULL); |
| 1082 } | 1085 } |
| 1083 | 1086 |
| 1084 /* done */ | 1087 /* done */ |
| 1085 xmlFree(res); | 1088 xmlFree(res); |
| 1086 return (attr); | 1089 return (attr); |
| 1087 } | 1090 } |
| 1088 | 1091 |
| 1089 /** | 1092 /** |
| 1090 * xmlC14NProcessAttrsAxis: | 1093 * xmlC14NProcessAttrsAxis: |
| 1091 * @ctx: » » the C14N context | 1094 * @ctx:» » the C14N context |
| 1092 * @cur: the current node | 1095 * @cur: the current node |
| 1093 * @parent_visible: the visibility of parent node | 1096 * @parent_visible: the visibility of parent node |
| 1094 * @all_parents_visible: the visibility of all parent nodes | 1097 * @all_parents_visible: the visibility of all parent nodes |
| 1095 * | 1098 * |
| 1096 * Prints out canonical attribute axis of the current node to the | 1099 * Prints out canonical attribute axis of the current node to the |
| 1097 * buffer from C14N context as follows | 1100 * buffer from C14N context as follows |
| 1098 * | 1101 * |
| 1099 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) | 1102 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) |
| 1100 * | 1103 * |
| 1101 * Attribute Axis | 1104 * Attribute Axis |
| 1102 * In lexicographic order (ascending), process each node that | 1105 * In lexicographic order (ascending), process each node that |
| 1103 * is in the element's attribute axis and in the node-set. | 1106 * is in the element's attribute axis and in the node-set. |
| 1104 * | 1107 * |
| 1105 * The processing of an element node E MUST be modified slightly | 1108 * The processing of an element node E MUST be modified slightly |
| 1106 * when an XPath node-set is given as input and the element's | 1109 * when an XPath node-set is given as input and the element's |
| 1107 * parent is omitted from the node-set. | 1110 * parent is omitted from the node-set. |
| 1108 * | 1111 * |
| 1109 * | 1112 * |
| 1110 * Exclusive XML Canonicalization v 1.0 (http://www.w3.org/TR/xml-exc-c14n) | 1113 * Exclusive XML Canonicalization v 1.0 (http://www.w3.org/TR/xml-exc-c14n) |
| 1111 * | 1114 * |
| 1112 * Canonical XML applied to a document subset requires the search of the | 1115 * Canonical XML applied to a document subset requires the search of the |
| 1113 * ancestor nodes of each orphan element node for attributes in the xml | 1116 * ancestor nodes of each orphan element node for attributes in the xml |
| 1114 * namespace, such as xml:lang and xml:space. These are copied into the | 1117 * namespace, such as xml:lang and xml:space. These are copied into the |
| 1115 * element node except if a declaration of the same attribute is already | 1118 * element node except if a declaration of the same attribute is already |
| 1116 * in the attribute axis of the element (whether or not it is included in | 1119 * in the attribute axis of the element (whether or not it is included in |
| 1117 * the document subset). This search and copying are omitted from the | 1120 * the document subset). This search and copying are omitted from the |
| 1118 * Exclusive XML Canonicalization method. | 1121 * Exclusive XML Canonicalization method. |
| 1119 * | 1122 * |
| 1120 * Returns 0 on success or -1 on fail. | 1123 * Returns 0 on success or -1 on fail. |
| 1121 */ | 1124 */ |
| 1122 static int | 1125 static int |
| 1123 xmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int parent_visible) | 1126 xmlC14NProcessAttrsAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int parent_visible) |
| 1124 { | 1127 { |
| 1125 xmlAttrPtr attr; | 1128 xmlAttrPtr attr; |
| 1126 xmlListPtr list; | 1129 xmlListPtr list; |
| 1127 xmlAttrPtr attrs_to_delete = NULL; | 1130 xmlAttrPtr attrs_to_delete = NULL; |
| 1128 | 1131 |
| 1129 /* special processing for 1.1 spec */ | 1132 /* special processing for 1.1 spec */ |
| 1130 xmlAttrPtr xml_base_attr = NULL; | 1133 xmlAttrPtr xml_base_attr = NULL; |
| 1131 xmlAttrPtr xml_lang_attr = NULL; | 1134 xmlAttrPtr xml_lang_attr = NULL; |
| 1132 xmlAttrPtr xml_space_attr = NULL; | 1135 xmlAttrPtr xml_space_attr = NULL; |
| 1133 | 1136 |
| 1134 if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { | 1137 if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { |
| 1135 xmlC14NErrParam("processing attributes axis"); | 1138 xmlC14NErrParam("processing attributes axis"); |
| 1136 return (-1); | 1139 return (-1); |
| 1137 } | 1140 } |
| 1138 | 1141 |
| 1139 /* | 1142 /* |
| 1140 * Create a sorted list to store element attributes | 1143 * Create a sorted list to store element attributes |
| 1141 */ | 1144 */ |
| 1142 list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NAttrsCompare); | 1145 list = xmlListCreate(NULL, (xmlListDataCompare) xmlC14NAttrsCompare); |
| 1143 if (list == NULL) { | 1146 if (list == NULL) { |
| 1144 xmlC14NErrInternal("creating attributes list"); | 1147 xmlC14NErrInternal("creating attributes list"); |
| 1145 return (-1); | 1148 return (-1); |
| 1146 } | 1149 } |
| 1147 | 1150 |
| 1148 switch(ctx->mode) { | 1151 switch(ctx->mode) { |
| 1149 case XML_C14N_1_0: | 1152 case XML_C14N_1_0: |
| 1150 /* The processing of an element node E MUST be modified slightly when an
XPath node-set is | 1153 /* The processing of an element node E MUST be modified slightly when an
XPath node-set is |
| 1151 * given as input and the element's parent is omitted from the node-set.
The method for processing | 1154 * given as input and the element's parent is omitted from the node-set.
The method for processing |
| 1152 * the attribute axis of an element E in the node-set is enhanced. All e
lement nodes along E's | 1155 * the attribute axis of an element E in the node-set is enhanced. All e
lement nodes along E's |
| 1153 * ancestor axis are examined for nearest occurrences of attributes in t
he xml namespace, such | 1156 * ancestor axis are examined for nearest occurrences of attributes in t
he xml namespace, such |
| 1154 * as xml:lang and xml:space (whether or not they are in the node-set).
From this list of attributes, | 1157 * as xml:lang and xml:space (whether or not they are in the node-set).
From this list of attributes, |
| 1155 * remove any that are in E's attribute axis (whether or not they are in
the node-set). Then, | 1158 * remove any that are in E's attribute axis (whether or not they are in
the node-set). Then, |
| 1156 * lexicographically merge this attribute list with the nodes of E's att
ribute axis that are in | 1159 * lexicographically merge this attribute list with the nodes of E's att
ribute axis that are in |
| 1157 * the node-set. The result of visiting the attribute axis is computed b
y processing the attribute | 1160 * the node-set. The result of visiting the attribute axis is computed b
y processing the attribute |
| 1158 * nodes in this merged attribute list. | 1161 * nodes in this merged attribute list. |
| 1159 */ | 1162 */ |
| 1160 | 1163 |
| 1161 /* | 1164 /* |
| 1162 * Add all visible attributes from current node. | 1165 * Add all visible attributes from current node. |
| 1163 */ | 1166 */ |
| 1164 attr = cur->properties; | 1167 attr = cur->properties; |
| 1165 while (attr != NULL) { | 1168 while (attr != NULL) { |
| 1166 /* check that attribute is visible */ | 1169 /* check that attribute is visible */ |
| 1167 if (xmlC14NIsVisible(ctx, attr, cur)) { | 1170 if (xmlC14NIsVisible(ctx, attr, cur)) { |
| 1168 xmlListInsert(list, attr); | 1171 xmlListInsert(list, attr); |
| 1169 } | 1172 } |
| 1170 attr = attr->next; | 1173 attr = attr->next; |
| 1171 } | 1174 } |
| 1172 | 1175 |
| 1173 /* | 1176 /* |
| 1174 * Handle xml attributes | 1177 * Handle xml attributes |
| 1175 */ | 1178 */ |
| 1176 if (parent_visible && (cur->parent != NULL) && | 1179 if (parent_visible && (cur->parent != NULL) && |
| 1177 (!xmlC14NIsVisible(ctx, cur->parent, cur->parent->parent))) | 1180 (!xmlC14NIsVisible(ctx, cur->parent, cur->parent->parent))) |
| 1178 { | 1181 { |
| 1179 xmlNodePtr tmp; | 1182 xmlNodePtr tmp; |
| 1180 | 1183 |
| 1181 /* | 1184 /* |
| 1182 * If XPath node-set is not specified then the parent is always | 1185 * If XPath node-set is not specified then the parent is always |
| 1183 * visible! | 1186 * visible! |
| 1184 */ | 1187 */ |
| 1185 tmp = cur->parent; | 1188 tmp = cur->parent; |
| 1186 while (tmp != NULL) { | 1189 while (tmp != NULL) { |
| 1187 attr = tmp->properties; | 1190 attr = tmp->properties; |
| 1188 while (attr != NULL) { | 1191 while (attr != NULL) { |
| 1189 if (xmlC14NIsXmlAttr(attr) != 0) { | 1192 if (xmlC14NIsXmlAttr(attr) != 0) { |
| 1190 if (xmlListSearch(list, attr) == NULL) { | 1193 if (xmlListSearch(list, attr) == NULL) { |
| 1191 xmlListInsert(list, attr); | 1194 xmlListInsert(list, attr); |
| 1192 } | 1195 } |
| 1193 } | 1196 } |
| 1194 attr = attr->next; | 1197 attr = attr->next; |
| 1195 } | 1198 } |
| 1196 tmp = tmp->parent; | 1199 tmp = tmp->parent; |
| 1197 } | 1200 } |
| 1198 } | 1201 } |
| 1199 | 1202 |
| 1200 /* done */ | 1203 /* done */ |
| 1201 break; | 1204 break; |
| 1202 case XML_C14N_EXCLUSIVE_1_0: | 1205 case XML_C14N_EXCLUSIVE_1_0: |
| 1203 /* attributes in the XML namespace, such as xml:lang and xml:space | 1206 /* attributes in the XML namespace, such as xml:lang and xml:space |
| 1204 * are not imported into orphan nodes of the document subset | 1207 * are not imported into orphan nodes of the document subset |
| 1205 */ | 1208 */ |
| 1206 | 1209 |
| 1207 /* | 1210 /* |
| 1208 * Add all visible attributes from current node. | 1211 * Add all visible attributes from current node. |
| 1209 */ | 1212 */ |
| 1210 attr = cur->properties; | 1213 attr = cur->properties; |
| 1211 while (attr != NULL) { | 1214 while (attr != NULL) { |
| 1212 /* check that attribute is visible */ | 1215 /* check that attribute is visible */ |
| 1213 if (xmlC14NIsVisible(ctx, attr, cur)) { | 1216 if (xmlC14NIsVisible(ctx, attr, cur)) { |
| 1214 xmlListInsert(list, attr); | 1217 xmlListInsert(list, attr); |
| 1215 } | 1218 } |
| 1216 attr = attr->next; | 1219 attr = attr->next; |
| 1217 } | 1220 } |
| 1218 | 1221 |
| 1219 /* do nothing special for xml attributes */ | 1222 /* do nothing special for xml attributes */ |
| 1220 break; | 1223 break; |
| 1221 case XML_C14N_1_1: | 1224 case XML_C14N_1_1: |
| 1222 /* The processing of an element node E MUST be modified slightly when an
XPath node-set is | 1225 /* The processing of an element node E MUST be modified slightly when an
XPath node-set is |
| 1223 * given as input and some of the element's ancestors are omitted from t
he node-set. | 1226 * given as input and some of the element's ancestors are omitted from t
he node-set. |
| 1224 * | 1227 * |
| 1225 * Simple inheritable attributes are attributes that have a value that r
equires at most a simple | 1228 * Simple inheritable attributes are attributes that have a value that r
equires at most a simple |
| 1226 * redeclaration. This redeclaration is done by supplying a new value in
the child axis. The | 1229 * redeclaration. This redeclaration is done by supplying a new value in
the child axis. The |
| 1227 * redeclaration of a simple inheritable attribute A contained in one of
E's ancestors is done | 1230 * redeclaration of a simple inheritable attribute A contained in one of
E's ancestors is done |
| 1228 * by supplying a value to an attribute Ae inside E with the same name.
Simple inheritable attributes | 1231 * by supplying a value to an attribute Ae inside E with the same name.
Simple inheritable attributes |
| 1229 * are xml:lang and xml:space. | 1232 * are xml:lang and xml:space. |
| 1230 * | 1233 * |
| 1231 * The method for processing the attribute axis of an element E in the n
ode-set is hence enhanced. | 1234 * The method for processing the attribute axis of an element E in the n
ode-set is hence enhanced. |
| 1232 * All element nodes along E's ancestor axis are examined for the neares
t occurrences of simple | 1235 * All element nodes along E's ancestor axis are examined for the neares
t occurrences of simple |
| 1233 * inheritable attributes in the xml namespace, such as xml:lang and xml
:space (whether or not they | 1236 * inheritable attributes in the xml namespace, such as xml:lang and xml
:space (whether or not they |
| 1234 * are in the node-set). From this list of attributes, any simple inheri
table attributes that are | 1237 * are in the node-set). From this list of attributes, any simple inheri
table attributes that are |
| 1235 * already in E's attribute axis (whether or not they are in the node-se
t) are removed. Then, | 1238 * already in E's attribute axis (whether or not they are in the node-se
t) are removed. Then, |
| 1236 * lexicographically merge this attribute list with the nodes of E's att
ribute axis that are in | 1239 * lexicographically merge this attribute list with the nodes of E's att
ribute axis that are in |
| 1237 * the node-set. The result of visiting the attribute axis is computed b
y processing the attribute | 1240 * the node-set. The result of visiting the attribute axis is computed b
y processing the attribute |
| 1238 * nodes in this merged attribute list. | 1241 * nodes in this merged attribute list. |
| 1239 * | 1242 * |
| 1240 * The xml:id attribute is not a simple inheritable attribute and no pro
cessing of these attributes is | 1243 * The xml:id attribute is not a simple inheritable attribute and no pro
cessing of these attributes is |
| 1241 * performed. | 1244 * performed. |
| 1242 * | 1245 * |
| 1243 * The xml:base attribute is not a simple inheritable attribute and requ
ires special processing beyond | 1246 * The xml:base attribute is not a simple inheritable attribute and requ
ires special processing beyond |
| 1244 * a simple redeclaration. | 1247 * a simple redeclaration. |
| 1245 * | 1248 * |
| 1246 * Attributes in the XML namespace other than xml:base, xml:id, xml:lang
, and xml:space MUST be processed | 1249 * Attributes in the XML namespace other than xml:base, xml:id, xml:lang
, and xml:space MUST be processed |
| 1247 * as ordinary attributes. | 1250 * as ordinary attributes. |
| 1248 */ | 1251 */ |
| 1249 | 1252 |
| 1250 /* | 1253 /* |
| 1251 * Add all visible attributes from current node. | 1254 * Add all visible attributes from current node. |
| 1252 */ | 1255 */ |
| 1253 attr = cur->properties; | 1256 attr = cur->properties; |
| 1254 while (attr != NULL) { | 1257 while (attr != NULL) { |
| 1255 /* special processing for XML attribute kiks in only when we have in
visible parents */ | 1258 /* special processing for XML attribute kiks in only when we have in
visible parents */ |
| 1256 if ((!parent_visible) || (xmlC14NIsXmlAttr(attr) == 0)) { | 1259 if ((!parent_visible) || (xmlC14NIsXmlAttr(attr) == 0)) { |
| 1257 /* check that attribute is visible */ | 1260 /* check that attribute is visible */ |
| 1258 if (xmlC14NIsVisible(ctx, attr, cur)) { | 1261 if (xmlC14NIsVisible(ctx, attr, cur)) { |
| 1259 xmlListInsert(list, attr); | 1262 xmlListInsert(list, attr); |
| 1260 } | 1263 } |
| 1261 } else { | 1264 } else { |
| 1262 int matched = 0; | 1265 int matched = 0; |
| 1263 | 1266 |
| 1264 /* check for simple inheritance attributes */ | 1267 /* check for simple inheritance attributes */ |
| 1265 if((!matched) && (xml_lang_attr == NULL) && xmlStrEqual(attr->na
me, BAD_CAST "lang")) { | 1268 if((!matched) && (xml_lang_attr == NULL) && xmlStrEqual(attr->na
me, BAD_CAST "lang")) { |
| 1266 xml_lang_attr = attr; | 1269 xml_lang_attr = attr; |
| 1267 matched = 1; | 1270 matched = 1; |
| 1268 } | 1271 } |
| 1269 if((!matched) && (xml_space_attr == NULL) && xmlStrEqual(attr->n
ame, BAD_CAST "space")) { | 1272 if((!matched) && (xml_space_attr == NULL) && xmlStrEqual(attr->n
ame, BAD_CAST "space")) { |
| 1270 xml_space_attr = attr; | 1273 xml_space_attr = attr; |
| 1271 matched = 1; | 1274 matched = 1; |
| 1272 } | 1275 } |
| 1273 | 1276 |
| 1274 /* check for base attr */ | 1277 /* check for base attr */ |
| 1275 if((!matched) && (xml_base_attr == NULL) && xmlStrEqual(attr->na
me, BAD_CAST "base")) { | 1278 if((!matched) && (xml_base_attr == NULL) && xmlStrEqual(attr->na
me, BAD_CAST "base")) { |
| 1276 xml_base_attr = attr; | 1279 xml_base_attr = attr; |
| 1277 matched = 1; | 1280 matched = 1; |
| 1278 } | 1281 } |
| 1279 | 1282 |
| 1280 /* otherwise, it is a normal attribute, so just check if it is v
isible */ | 1283 /* otherwise, it is a normal attribute, so just check if it is v
isible */ |
| 1281 if((!matched) && xmlC14NIsVisible(ctx, attr, cur)) { | 1284 if((!matched) && xmlC14NIsVisible(ctx, attr, cur)) { |
| 1282 xmlListInsert(list, attr); | 1285 xmlListInsert(list, attr); |
| 1283 } | 1286 } |
| 1284 } | 1287 } |
| 1285 | 1288 |
| 1286 /* move to the next one */ | 1289 /* move to the next one */ |
| 1287 attr = attr->next; | 1290 attr = attr->next; |
| 1288 } | 1291 } |
| 1289 | 1292 |
| 1290 /* special processing for XML attribute kiks in only when we have invisi
ble parents */ | 1293 /* special processing for XML attribute kiks in only when we have invisi
ble parents */ |
| 1291 if ((parent_visible)) { | 1294 if ((parent_visible)) { |
| 1292 | 1295 |
| 1293 /* simple inheritance attributes - copy */ | 1296 /* simple inheritance attributes - copy */ |
| 1294 if(xml_lang_attr == NULL) { | 1297 if(xml_lang_attr == NULL) { |
| 1295 xml_lang_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, BA
D_CAST "lang", XML_XML_NAMESPACE); | 1298 xml_lang_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, BA
D_CAST "lang", XML_XML_NAMESPACE); |
| 1296 } | 1299 } |
| 1297 if(xml_lang_attr != NULL) { | 1300 if(xml_lang_attr != NULL) { |
| 1298 xmlListInsert(list, xml_lang_attr); | 1301 xmlListInsert(list, xml_lang_attr); |
| 1299 } | 1302 } |
| 1300 if(xml_space_attr == NULL) { | 1303 if(xml_space_attr == NULL) { |
| 1301 xml_space_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, B
AD_CAST "space", XML_XML_NAMESPACE); | 1304 xml_space_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, B
AD_CAST "space", XML_XML_NAMESPACE); |
| 1302 } | 1305 } |
| 1303 if(xml_space_attr != NULL) { | 1306 if(xml_space_attr != NULL) { |
| 1304 xmlListInsert(list, xml_space_attr); | 1307 xmlListInsert(list, xml_space_attr); |
| 1305 } | 1308 } |
| 1306 | 1309 |
| 1307 /* base uri attribute - fix up */ | 1310 /* base uri attribute - fix up */ |
| 1308 if(xml_base_attr == NULL) { | 1311 if(xml_base_attr == NULL) { |
| 1309 /* if we don't have base uri attribute, check if we have a "hidd
en" one above */ | 1312 /* if we don't have base uri attribute, check if we have a "hidd
en" one above */ |
| 1310 xml_base_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, BA
D_CAST "base", XML_XML_NAMESPACE); | 1313 xml_base_attr = xmlC14NFindHiddenParentAttr(ctx, cur->parent, BA
D_CAST "base", XML_XML_NAMESPACE); |
| 1311 } | 1314 } |
| 1312 if(xml_base_attr != NULL) { | 1315 if(xml_base_attr != NULL) { |
| 1313 xml_base_attr = xmlC14NFixupBaseAttr(ctx, xml_base_attr); | 1316 xml_base_attr = xmlC14NFixupBaseAttr(ctx, xml_base_attr); |
| 1314 if(xml_base_attr != NULL) { | 1317 if(xml_base_attr != NULL) { |
| 1315 xmlListInsert(list, xml_base_attr); | 1318 xmlListInsert(list, xml_base_attr); |
| 1316 | 1319 |
| 1317 /* note that we MUST delete returned attr node ourselves! */ | 1320 /* note that we MUST delete returned attr node ourselves! */ |
| 1318 xml_base_attr->next = attrs_to_delete; | 1321 xml_base_attr->next = attrs_to_delete; |
| 1319 attrs_to_delete = xml_base_attr; | 1322 attrs_to_delete = xml_base_attr; |
| 1320 } | 1323 } |
| 1321 } | 1324 } |
| 1322 } | 1325 } |
| 1323 | 1326 |
| 1324 /* done */ | 1327 /* done */ |
| 1325 break; | 1328 break; |
| 1326 } | 1329 } |
| 1327 | 1330 |
| 1328 /* | 1331 /* |
| 1329 * print out all elements from list | 1332 * print out all elements from list |
| 1330 */ | 1333 */ |
| 1331 xmlListWalk(list, (xmlListWalker) xmlC14NPrintAttrs, (const void *) ctx); | 1334 xmlListWalk(list, (xmlListWalker) xmlC14NPrintAttrs, (const void *) ctx); |
| 1332 | 1335 |
| 1333 /* | 1336 /* |
| 1334 * Cleanup | 1337 * Cleanup |
| 1335 */ | 1338 */ |
| 1336 xmlFreePropList(attrs_to_delete); | 1339 xmlFreePropList(attrs_to_delete); |
| 1337 xmlListDelete(list); | 1340 xmlListDelete(list); |
| 1338 return (0); | 1341 return (0); |
| 1339 } | 1342 } |
| 1340 | 1343 |
| 1341 /** | 1344 /** |
| 1342 * xmlC14NCheckForRelativeNamespaces: | 1345 * xmlC14NCheckForRelativeNamespaces: |
| 1343 * @ctx: the C14N context | 1346 * @ctx: the C14N context |
| 1344 * @cur: the current element node | 1347 * @cur: the current element node |
| 1345 * | 1348 * |
| 1346 * Checks that current element node has no relative namespaces defined | 1349 * Checks that current element node has no relative namespaces defined |
| 1347 * | 1350 * |
| 1348 * Returns 0 if the node has no relative namespaces or -1 otherwise. | 1351 * Returns 0 if the node has no relative namespaces or -1 otherwise. |
| 1349 */ | 1352 */ |
| 1350 static int | 1353 static int |
| 1351 xmlC14NCheckForRelativeNamespaces(xmlC14NCtxPtr ctx, xmlNodePtr cur) | 1354 xmlC14NCheckForRelativeNamespaces(xmlC14NCtxPtr ctx, xmlNodePtr cur) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1381 } | 1384 } |
| 1382 xmlFreeURI(uri); | 1385 xmlFreeURI(uri); |
| 1383 } | 1386 } |
| 1384 ns = ns->next; | 1387 ns = ns->next; |
| 1385 } | 1388 } |
| 1386 return (0); | 1389 return (0); |
| 1387 } | 1390 } |
| 1388 | 1391 |
| 1389 /** | 1392 /** |
| 1390 * xmlC14NProcessElementNode: | 1393 * xmlC14NProcessElementNode: |
| 1391 * @ctx: » » the pointer to C14N context object | 1394 * @ctx:» » the pointer to C14N context object |
| 1392 * @cur: the node to process | 1395 * @cur: the node to process |
| 1393 * @visible: this node is visible | 1396 * @visible: this node is visible |
| 1394 * @all_parents_visible: whether all the parents of this node are visible | 1397 * @all_parents_visible: whether all the parents of this node are visible |
| 1395 * » » | 1398 * |
| 1396 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) | 1399 * Canonical XML v 1.0 (http://www.w3.org/TR/xml-c14n) |
| 1397 * | 1400 * |
| 1398 * Element Nodes | 1401 * Element Nodes |
| 1399 * If the element is not in the node-set, then the result is obtained | 1402 * If the element is not in the node-set, then the result is obtained |
| 1400 * by processing the namespace axis, then the attribute axis, then | 1403 * by processing the namespace axis, then the attribute axis, then |
| 1401 * processing the child nodes of the element that are in the node-set | 1404 * processing the child nodes of the element that are in the node-set |
| 1402 * (in document order). If the element is in the node-set, then the result | 1405 * (in document order). If the element is in the node-set, then the result |
| 1403 * is an open angle bracket (<), the element QName, the result of | 1406 * is an open angle bracket (<), the element QName, the result of |
| 1404 * processing the namespace axis, the result of processing the attribute | 1407 * processing the namespace axis, the result of processing the attribute |
| 1405 * axis, a close angle bracket (>), the result of processing the child | 1408 * axis, a close angle bracket (>), the result of processing the child |
| 1406 * nodes of the element that are in the node-set (in document order), an | 1409 * nodes of the element that are in the node-set (in document order), an |
| 1407 * open angle bracket, a forward slash (/), the element QName, and a close | 1410 * open angle bracket, a forward slash (/), the element QName, and a close |
| 1408 * angle bracket. | 1411 * angle bracket. |
| 1409 * | 1412 * |
| 1410 * Returns non-negative value on success or negative value on fail | 1413 * Returns non-negative value on success or negative value on fail |
| 1411 */ | 1414 */ |
| 1412 static int | 1415 static int |
| 1413 xmlC14NProcessElementNode(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) | 1416 xmlC14NProcessElementNode(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) |
| 1414 { | 1417 { |
| 1415 int ret; | 1418 int ret; |
| 1416 xmlC14NVisibleNsStack state; | 1419 xmlC14NVisibleNsStack state; |
| 1417 int parent_is_doc = 0; | 1420 int parent_is_doc = 0; |
| 1418 | 1421 |
| 1419 if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { | 1422 if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { |
| 1420 xmlC14NErrParam("processing element node"); | 1423 xmlC14NErrParam("processing element node"); |
| 1421 return (-1); | 1424 return (-1); |
| 1422 } | 1425 } |
| 1423 | 1426 |
| 1424 /* | 1427 /* |
| 1425 * Check relative relative namespaces: | 1428 * Check relative relative namespaces: |
| 1426 * implementations of XML canonicalization MUST report an operation | 1429 * implementations of XML canonicalization MUST report an operation |
| 1427 * failure on documents containing relative namespace URIs. | 1430 * failure on documents containing relative namespace URIs. |
| 1428 */ | 1431 */ |
| 1429 if (xmlC14NCheckForRelativeNamespaces(ctx, cur) < 0) { | 1432 if (xmlC14NCheckForRelativeNamespaces(ctx, cur) < 0) { |
| 1430 xmlC14NErrInternal("checking for relative namespaces"); | 1433 xmlC14NErrInternal("checking for relative namespaces"); |
| 1431 return (-1); | 1434 return (-1); |
| 1432 } | 1435 } |
| 1433 | 1436 |
| 1434 | 1437 |
| 1435 /* | 1438 /* |
| 1436 * Save ns_rendered stack position | 1439 * Save ns_rendered stack position |
| 1437 */ | 1440 */ |
| 1438 memset(&state, 0, sizeof(state)); | 1441 memset(&state, 0, sizeof(state)); |
| 1439 xmlC14NVisibleNsStackSave(ctx->ns_rendered, &state); | 1442 xmlC14NVisibleNsStackSave(ctx->ns_rendered, &state); |
| 1440 | 1443 |
| 1441 if (visible) {» | 1444 if (visible) { |
| 1442 if (ctx->parent_is_doc) { | 1445 if (ctx->parent_is_doc) { |
| 1443 /* save this flag into the stack */ | 1446 /* save this flag into the stack */ |
| 1444 parent_is_doc = ctx->parent_is_doc; | 1447 parent_is_doc = ctx->parent_is_doc; |
| 1445 ctx->parent_is_doc = 0; | 1448 ctx->parent_is_doc = 0; |
| 1446 ctx->pos = XMLC14N_INSIDE_DOCUMENT_ELEMENT; | 1449 ctx->pos = XMLC14N_INSIDE_DOCUMENT_ELEMENT; |
| 1447 } | 1450 } |
| 1448 xmlOutputBufferWriteString(ctx->buf, "<"); | 1451 xmlOutputBufferWriteString(ctx->buf, "<"); |
| 1449 | 1452 |
| 1450 if ((cur->ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) { | 1453 if ((cur->ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) { |
| 1451 xmlOutputBufferWriteString(ctx->buf, | 1454 xmlOutputBufferWriteString(ctx->buf, |
| 1452 (const char *) cur->ns->prefix); | 1455 (const char *) cur->ns->prefix); |
| 1453 xmlOutputBufferWriteString(ctx->buf, ":"); | 1456 xmlOutputBufferWriteString(ctx->buf, ":"); |
| 1454 } | 1457 } |
| 1455 xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name); | 1458 xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name); |
| 1456 } | 1459 } |
| 1457 | 1460 |
| 1458 if (!xmlC14NIsExclusive(ctx)) { | 1461 if (!xmlC14NIsExclusive(ctx)) { |
| 1459 ret = xmlC14NProcessNamespacesAxis(ctx, cur, visible); | 1462 ret = xmlC14NProcessNamespacesAxis(ctx, cur, visible); |
| 1460 } else { | 1463 } else { |
| 1461 ret = xmlExcC14NProcessNamespacesAxis(ctx, cur, visible); | 1464 ret = xmlExcC14NProcessNamespacesAxis(ctx, cur, visible); |
| 1462 } | 1465 } |
| 1463 if (ret < 0) { | 1466 if (ret < 0) { |
| 1464 xmlC14NErrInternal("processing namespaces axis"); | 1467 xmlC14NErrInternal("processing namespaces axis"); |
| 1465 return (-1); | 1468 return (-1); |
| 1466 } | 1469 } |
| 1467 /* todo: shouldn't this go to "visible only"? */ | 1470 /* todo: shouldn't this go to "visible only"? */ |
| 1468 if(visible) { | 1471 if(visible) { |
| 1469 xmlC14NVisibleNsStackShift(ctx->ns_rendered); | 1472 xmlC14NVisibleNsStackShift(ctx->ns_rendered); |
| 1470 } | 1473 } |
| 1471 | 1474 |
| 1472 ret = xmlC14NProcessAttrsAxis(ctx, cur, visible); | 1475 ret = xmlC14NProcessAttrsAxis(ctx, cur, visible); |
| 1473 if (ret < 0) { | 1476 if (ret < 0) { |
| 1474 xmlC14NErrInternal("processing attributes axis"); | 1477 xmlC14NErrInternal("processing attributes axis"); |
| 1475 » return (-1); | 1478 » return (-1); |
| 1476 } | 1479 } |
| 1477 | 1480 |
| 1478 if (visible) { | 1481 if (visible) { |
| 1479 xmlOutputBufferWriteString(ctx->buf, ">"); | 1482 xmlOutputBufferWriteString(ctx->buf, ">"); |
| 1480 } | 1483 } |
| 1481 if (cur->children != NULL) { | 1484 if (cur->children != NULL) { |
| 1482 ret = xmlC14NProcessNodeList(ctx, cur->children); | 1485 ret = xmlC14NProcessNodeList(ctx, cur->children); |
| 1483 if (ret < 0) { | 1486 if (ret < 0) { |
| 1484 xmlC14NErrInternal("processing childrens list"); | 1487 xmlC14NErrInternal("processing childrens list"); |
| 1485 return (-1); | 1488 return (-1); |
| 1486 } | 1489 } |
| 1487 } | 1490 } |
| 1488 if (visible) { | 1491 if (visible) { |
| 1489 xmlOutputBufferWriteString(ctx->buf, "</"); | 1492 xmlOutputBufferWriteString(ctx->buf, "</"); |
| 1490 if ((cur->ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) { | 1493 if ((cur->ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) { |
| 1491 xmlOutputBufferWriteString(ctx->buf, | 1494 xmlOutputBufferWriteString(ctx->buf, |
| 1492 (const char *) cur->ns->prefix); | 1495 (const char *) cur->ns->prefix); |
| 1493 xmlOutputBufferWriteString(ctx->buf, ":"); | 1496 xmlOutputBufferWriteString(ctx->buf, ":"); |
| 1494 } | 1497 } |
| 1495 xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name); | 1498 xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name); |
| 1496 xmlOutputBufferWriteString(ctx->buf, ">"); | 1499 xmlOutputBufferWriteString(ctx->buf, ">"); |
| 1497 if (parent_is_doc) { | 1500 if (parent_is_doc) { |
| 1498 /* restore this flag from the stack for next node */ | 1501 /* restore this flag from the stack for next node */ |
| 1499 ctx->parent_is_doc = parent_is_doc; | 1502 ctx->parent_is_doc = parent_is_doc; |
| 1500 ctx->pos = XMLC14N_AFTER_DOCUMENT_ELEMENT; | 1503 ctx->pos = XMLC14N_AFTER_DOCUMENT_ELEMENT; |
| 1501 } | 1504 } |
| 1502 } | 1505 } |
| 1503 | 1506 |
| 1504 /* | 1507 /* |
| 1505 * Restore ns_rendered stack position | 1508 * Restore ns_rendered stack position |
| 1506 */ | 1509 */ |
| 1507 xmlC14NVisibleNsStackRestore(ctx->ns_rendered, &state); | 1510 xmlC14NVisibleNsStackRestore(ctx->ns_rendered, &state); |
| 1508 return (0); | 1511 return (0); |
| 1509 } | 1512 } |
| 1510 | 1513 |
| 1511 /** | 1514 /** |
| 1512 * xmlC14NProcessNode: | 1515 * xmlC14NProcessNode: |
| 1513 * @ctx: » » the pointer to C14N context object | 1516 * @ctx:» » the pointer to C14N context object |
| 1514 * @cur: the node to process | 1517 * @cur: the node to process |
| 1515 * » » | 1518 * |
| 1516 * Processes the given node | 1519 * Processes the given node |
| 1517 * | 1520 * |
| 1518 * Returns non-negative value on success or negative value on fail | 1521 * Returns non-negative value on success or negative value on fail |
| 1519 */ | 1522 */ |
| 1520 static int | 1523 static int |
| 1521 xmlC14NProcessNode(xmlC14NCtxPtr ctx, xmlNodePtr cur) | 1524 xmlC14NProcessNode(xmlC14NCtxPtr ctx, xmlNodePtr cur) |
| 1522 { | 1525 { |
| 1523 int ret = 0; | 1526 int ret = 0; |
| 1524 int visible; | 1527 int visible; |
| 1525 | 1528 |
| 1526 if ((ctx == NULL) || (cur == NULL)) { | 1529 if ((ctx == NULL) || (cur == NULL)) { |
| 1527 xmlC14NErrParam("processing node"); | 1530 xmlC14NErrParam("processing node"); |
| 1528 return (-1); | 1531 return (-1); |
| 1529 } | 1532 } |
| 1530 | 1533 |
| 1531 visible = xmlC14NIsVisible(ctx, cur, cur->parent); | 1534 visible = xmlC14NIsVisible(ctx, cur, cur->parent); |
| 1532 switch (cur->type) { | 1535 switch (cur->type) { |
| 1533 case XML_ELEMENT_NODE: | 1536 case XML_ELEMENT_NODE: |
| 1534 ret = xmlC14NProcessElementNode(ctx, cur, visible); | 1537 ret = xmlC14NProcessElementNode(ctx, cur, visible); |
| 1535 break; | 1538 break; |
| 1536 case XML_CDATA_SECTION_NODE: | 1539 case XML_CDATA_SECTION_NODE: |
| 1537 case XML_TEXT_NODE: | 1540 case XML_TEXT_NODE: |
| 1538 /* | 1541 /* |
| 1539 * Text Nodes | 1542 * Text Nodes |
| 1540 * the string value, except all ampersands are replaced | 1543 * the string value, except all ampersands are replaced |
| 1541 * by &, all open angle brackets (<) are replaced by <, all c
losing | 1544 * by &, all open angle brackets (<) are replaced by <, all c
losing |
| 1542 * angle brackets (>) are replaced by >, and all #xD characters a
re | 1545 * angle brackets (>) are replaced by >, and all #xD characters a
re |
| 1543 * replaced by 
. | 1546 * replaced by 
. |
| 1544 */ | 1547 */ |
| 1545 /* cdata sections are processed as text nodes */ | 1548 /* cdata sections are processed as text nodes */ |
| 1546 /* todo: verify that cdata sections are included in XPath nodes set
*/ | 1549 /* todo: verify that cdata sections are included in XPath nodes set
*/ |
| 1547 if ((visible) && (cur->content != NULL)) { | 1550 if ((visible) && (cur->content != NULL)) { |
| 1548 xmlChar *buffer; | 1551 xmlChar *buffer; |
| 1549 | 1552 |
| 1550 buffer = xmlC11NNormalizeText(cur->content); | 1553 buffer = xmlC11NNormalizeText(cur->content); |
| 1551 if (buffer != NULL) { | 1554 if (buffer != NULL) { |
| 1552 xmlOutputBufferWriteString(ctx->buf, | 1555 xmlOutputBufferWriteString(ctx->buf, |
| 1553 (const char *) buffer); | 1556 (const char *) buffer); |
| 1554 xmlFree(buffer); | 1557 xmlFree(buffer); |
| 1555 } else { | 1558 } else { |
| 1556 xmlC14NErrInternal("normalizing text node"); | 1559 xmlC14NErrInternal("normalizing text node"); |
| 1557 return (-1); | 1560 return (-1); |
| 1558 } | 1561 } |
| 1559 } | 1562 } |
| 1560 break; | 1563 break; |
| 1561 case XML_PI_NODE: | 1564 case XML_PI_NODE: |
| 1562 /* | 1565 /* |
| 1563 * Processing Instruction (PI) Nodes- | 1566 * Processing Instruction (PI) Nodes- |
| 1564 * The opening PI symbol (<?), the PI target name of the node, | 1567 * The opening PI symbol (<?), the PI target name of the node, |
| 1565 * a leading space and the string value if it is not empty, and | 1568 * a leading space and the string value if it is not empty, and |
| 1566 * the closing PI symbol (?>). If the string value is empty, | 1569 * the closing PI symbol (?>). If the string value is empty, |
| 1567 * then the leading space is not added. Also, a trailing #xA is | 1570 * then the leading space is not added. Also, a trailing #xA is |
| 1568 * rendered after the closing PI symbol for PI children of the | 1571 * rendered after the closing PI symbol for PI children of the |
| 1569 * root node with a lesser document order than the document | 1572 * root node with a lesser document order than the document |
| 1570 * element, and a leading #xA is rendered before the opening PI | 1573 * element, and a leading #xA is rendered before the opening PI |
| 1571 * symbol of PI children of the root node with a greater document | 1574 * symbol of PI children of the root node with a greater document |
| 1572 * order than the document element. | 1575 * order than the document element. |
| 1573 */ | 1576 */ |
| 1574 if (visible) { | 1577 if (visible) { |
| 1575 if (ctx->pos == XMLC14N_AFTER_DOCUMENT_ELEMENT) { | 1578 if (ctx->pos == XMLC14N_AFTER_DOCUMENT_ELEMENT) { |
| 1576 xmlOutputBufferWriteString(ctx->buf, "\x0A<?"); | 1579 xmlOutputBufferWriteString(ctx->buf, "\x0A<?"); |
| 1577 } else { | 1580 } else { |
| 1578 xmlOutputBufferWriteString(ctx->buf, "<?"); | 1581 xmlOutputBufferWriteString(ctx->buf, "<?"); |
| 1579 } | 1582 } |
| 1580 | 1583 |
| 1581 xmlOutputBufferWriteString(ctx->buf, | 1584 xmlOutputBufferWriteString(ctx->buf, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1600 if (ctx->pos == XMLC14N_BEFORE_DOCUMENT_ELEMENT) { | 1603 if (ctx->pos == XMLC14N_BEFORE_DOCUMENT_ELEMENT) { |
| 1601 xmlOutputBufferWriteString(ctx->buf, "?>\x0A"); | 1604 xmlOutputBufferWriteString(ctx->buf, "?>\x0A"); |
| 1602 } else { | 1605 } else { |
| 1603 xmlOutputBufferWriteString(ctx->buf, "?>"); | 1606 xmlOutputBufferWriteString(ctx->buf, "?>"); |
| 1604 } | 1607 } |
| 1605 } | 1608 } |
| 1606 break; | 1609 break; |
| 1607 case XML_COMMENT_NODE: | 1610 case XML_COMMENT_NODE: |
| 1608 /* | 1611 /* |
| 1609 * Comment Nodes | 1612 * Comment Nodes |
| 1610 * Nothing if generating canonical XML without comments. For | 1613 * Nothing if generating canonical XML without comments. For |
| 1611 * canonical XML with comments, generate the opening comment | 1614 * canonical XML with comments, generate the opening comment |
| 1612 * symbol (<!--), the string value of the node, and the | 1615 * symbol (<!--), the string value of the node, and the |
| 1613 * closing comment symbol (-->). Also, a trailing #xA is rendered | 1616 * closing comment symbol (-->). Also, a trailing #xA is rendered |
| 1614 * after the closing comment symbol for comment children of the | 1617 * after the closing comment symbol for comment children of the |
| 1615 * root node with a lesser document order than the document | 1618 * root node with a lesser document order than the document |
| 1616 * element, and a leading #xA is rendered before the opening | 1619 * element, and a leading #xA is rendered before the opening |
| 1617 * comment symbol of comment children of the root node with a | 1620 * comment symbol of comment children of the root node with a |
| 1618 * greater document order than the document element. (Comment | 1621 * greater document order than the document element. (Comment |
| 1619 * children of the root node represent comments outside of the | 1622 * children of the root node represent comments outside of the |
| 1620 * top-level document element and outside of the document type | 1623 * top-level document element and outside of the document type |
| 1621 * declaration). | 1624 * declaration). |
| 1622 */ | 1625 */ |
| 1623 if (visible && ctx->with_comments) { | 1626 if (visible && ctx->with_comments) { |
| 1624 if (ctx->pos == XMLC14N_AFTER_DOCUMENT_ELEMENT) { | 1627 if (ctx->pos == XMLC14N_AFTER_DOCUMENT_ELEMENT) { |
| 1625 xmlOutputBufferWriteString(ctx->buf, "\x0A<!--"); | 1628 xmlOutputBufferWriteString(ctx->buf, "\x0A<!--"); |
| 1626 } else { | 1629 } else { |
| 1627 xmlOutputBufferWriteString(ctx->buf, "<!--"); | 1630 xmlOutputBufferWriteString(ctx->buf, "<!--"); |
| 1628 } | 1631 } |
| 1629 | 1632 |
| 1630 if (cur->content != NULL) { | 1633 if (cur->content != NULL) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1680 case XML_DOCUMENT_TYPE_NODE: | 1683 case XML_DOCUMENT_TYPE_NODE: |
| 1681 case XML_NOTATION_NODE: | 1684 case XML_NOTATION_NODE: |
| 1682 case XML_DTD_NODE: | 1685 case XML_DTD_NODE: |
| 1683 case XML_ELEMENT_DECL: | 1686 case XML_ELEMENT_DECL: |
| 1684 case XML_ATTRIBUTE_DECL: | 1687 case XML_ATTRIBUTE_DECL: |
| 1685 case XML_ENTITY_DECL: | 1688 case XML_ENTITY_DECL: |
| 1686 #ifdef LIBXML_XINCLUDE_ENABLED | 1689 #ifdef LIBXML_XINCLUDE_ENABLED |
| 1687 case XML_XINCLUDE_START: | 1690 case XML_XINCLUDE_START: |
| 1688 case XML_XINCLUDE_END: | 1691 case XML_XINCLUDE_END: |
| 1689 #endif | 1692 #endif |
| 1690 /* | 1693 /* |
| 1691 * should be ignored according to "W3C Canonical XML" | 1694 * should be ignored according to "W3C Canonical XML" |
| 1692 */ | 1695 */ |
| 1693 break; | 1696 break; |
| 1694 default: | 1697 default: |
| 1695 xmlC14NErrUnknownNode(cur->type, "processing node"); | 1698 xmlC14NErrUnknownNode(cur->type, "processing node"); |
| 1696 return (-1); | 1699 return (-1); |
| 1697 } | 1700 } |
| 1698 | 1701 |
| 1699 return (ret); | 1702 return (ret); |
| 1700 } | 1703 } |
| 1701 | 1704 |
| 1702 /** | 1705 /** |
| 1703 * xmlC14NProcessNodeList: | 1706 * xmlC14NProcessNodeList: |
| 1704 * @ctx: » » the pointer to C14N context object | 1707 * @ctx:» » the pointer to C14N context object |
| 1705 * @cur: the node to start from | 1708 * @cur: the node to start from |
| 1706 * » » | 1709 * |
| 1707 * Processes all nodes in the row starting from cur. | 1710 * Processes all nodes in the row starting from cur. |
| 1708 * | 1711 * |
| 1709 * Returns non-negative value on success or negative value on fail | 1712 * Returns non-negative value on success or negative value on fail |
| 1710 */ | 1713 */ |
| 1711 static int | 1714 static int |
| 1712 xmlC14NProcessNodeList(xmlC14NCtxPtr ctx, xmlNodePtr cur) | 1715 xmlC14NProcessNodeList(xmlC14NCtxPtr ctx, xmlNodePtr cur) |
| 1713 { | 1716 { |
| 1714 int ret; | 1717 int ret; |
| 1715 | 1718 |
| 1716 if (ctx == NULL) { | 1719 if (ctx == NULL) { |
| 1717 xmlC14NErrParam("processing node list"); | 1720 xmlC14NErrParam("processing node list"); |
| 1718 return (-1); | 1721 return (-1); |
| 1719 } | 1722 } |
| 1720 | 1723 |
| 1721 for (ret = 0; cur != NULL && ret >= 0; cur = cur->next) { | 1724 for (ret = 0; cur != NULL && ret >= 0; cur = cur->next) { |
| 1722 ret = xmlC14NProcessNode(ctx, cur); | 1725 ret = xmlC14NProcessNode(ctx, cur); |
| 1723 } | 1726 } |
| 1724 return (ret); | 1727 return (ret); |
| 1725 } | 1728 } |
| 1726 | 1729 |
| 1727 | 1730 |
| 1728 /** | 1731 /** |
| 1729 * xmlC14NFreeCtx: | 1732 * xmlC14NFreeCtx: |
| 1730 * @ctx: the pointer to C14N context object | 1733 * @ctx: the pointer to C14N context object |
| 1731 * » » | 1734 * |
| 1732 * Cleanups the C14N context object. | 1735 * Cleanups the C14N context object. |
| 1733 */ | 1736 */ |
| 1734 | 1737 |
| 1735 static void | 1738 static void |
| 1736 xmlC14NFreeCtx(xmlC14NCtxPtr ctx) | 1739 xmlC14NFreeCtx(xmlC14NCtxPtr ctx) |
| 1737 { | 1740 { |
| 1738 if (ctx == NULL) { | 1741 if (ctx == NULL) { |
| 1739 xmlC14NErrParam("freeing context"); | 1742 xmlC14NErrParam("freeing context"); |
| 1740 return; | 1743 return; |
| 1741 } | 1744 } |
| 1742 | 1745 |
| 1743 if (ctx->ns_rendered != NULL) { | 1746 if (ctx->ns_rendered != NULL) { |
| 1744 xmlC14NVisibleNsStackDestroy(ctx->ns_rendered); | 1747 xmlC14NVisibleNsStackDestroy(ctx->ns_rendered); |
| 1745 } | 1748 } |
| 1746 xmlFree(ctx); | 1749 xmlFree(ctx); |
| 1747 } | 1750 } |
| 1748 | 1751 |
| 1749 /** | 1752 /** |
| 1750 * xmlC14NNewCtx: | 1753 * xmlC14NNewCtx: |
| 1751 * @doc: » » the XML document for canonization | 1754 * @doc:» » the XML document for canonization |
| 1752 * @is_visible_callback:the function to use to determine is node visible | 1755 * @is_visible_callback:the function to use to determine is node visible |
| 1753 * or not | 1756 * or not |
| 1754 * @user_data: »» the first parameter for @is_visible_callback function | 1757 * @user_data:» » the first parameter for @is_visible_callback function |
| 1755 * (in most cases, it is nodes set) | 1758 * (in most cases, it is nodes set) |
| 1756 * @mode: the c14n mode (see @xmlC14NMode) | 1759 * @mode: the c14n mode (see @xmlC14NMode) |
| 1757 * @inclusive_ns_prefixe the list of inclusive namespace prefixes | 1760 * @inclusive_ns_prefixe the list of inclusive namespace prefixes |
| 1758 * ended with a NULL or NULL if there is no | 1761 * ended with a NULL or NULL if there is no |
| 1759 *» » » inclusive namespaces (only for ` | 1762 *» » » inclusive namespaces (only for ` |
| 1760 * canonicalization) | 1763 * canonicalization) |
| 1761 * @with_comments: » include comments in the result (!=0) or not (==0) | 1764 * @with_comments:» include comments in the result (!=0) or not (==0) |
| 1762 * @buf: » » the output buffer to store canonical XML; this | 1765 * @buf:» » the output buffer to store canonical XML; this |
| 1763 * buffer MUST have encoder==NULL because C14N requires | 1766 * buffer MUST have encoder==NULL because C14N requires |
| 1764 * UTF-8 output | 1767 * UTF-8 output |
| 1765 * » » | 1768 * |
| 1766 * Creates new C14N context object to store C14N parameters. | 1769 * Creates new C14N context object to store C14N parameters. |
| 1767 * | 1770 * |
| 1768 * Returns pointer to newly created object (success) or NULL (fail) | 1771 * Returns pointer to newly created object (success) or NULL (fail) |
| 1769 */ | 1772 */ |
| 1770 static xmlC14NCtxPtr | 1773 static xmlC14NCtxPtr |
| 1771 xmlC14NNewCtx(xmlDocPtr doc, | 1774 xmlC14NNewCtx(xmlDocPtr doc, |
| 1772 xmlC14NIsVisibleCallback is_visible_callback, void* user_data, | 1775 xmlC14NIsVisibleCallback is_visible_callback, void* user_data, |
| 1773 xmlC14NMode mode, xmlChar ** inclusive_ns_prefixes, | 1776 xmlC14NMode mode, xmlChar ** inclusive_ns_prefixes, |
| 1774 int with_comments, xmlOutputBufferPtr buf) | 1777 int with_comments, xmlOutputBufferPtr buf) |
| 1775 { | 1778 { |
| 1776 xmlC14NCtxPtr ctx = NULL; | 1779 xmlC14NCtxPtr ctx = NULL; |
| 1777 | 1780 |
| 1778 if ((doc == NULL) || (buf == NULL)) { | 1781 if ((doc == NULL) || (buf == NULL)) { |
| 1779 xmlC14NErrParam("creating new context"); | 1782 xmlC14NErrParam("creating new context"); |
| 1780 return (NULL); | 1783 return (NULL); |
| 1781 } | 1784 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1833 */ | 1836 */ |
| 1834 ctx->mode = mode; | 1837 ctx->mode = mode; |
| 1835 if(xmlC14NIsExclusive(ctx)) { | 1838 if(xmlC14NIsExclusive(ctx)) { |
| 1836 ctx->inclusive_ns_prefixes = inclusive_ns_prefixes; | 1839 ctx->inclusive_ns_prefixes = inclusive_ns_prefixes; |
| 1837 } | 1840 } |
| 1838 return (ctx); | 1841 return (ctx); |
| 1839 } | 1842 } |
| 1840 | 1843 |
| 1841 /** | 1844 /** |
| 1842 * xmlC14NExecute: | 1845 * xmlC14NExecute: |
| 1843 * @doc: » » the XML document for canonization | 1846 * @doc:» » the XML document for canonization |
| 1844 * @is_visible_callback:the function to use to determine is node visible | 1847 * @is_visible_callback:the function to use to determine is node visible |
| 1845 * or not | 1848 * or not |
| 1846 * @user_data: »» the first parameter for @is_visible_callback function | 1849 * @user_data:» » the first parameter for @is_visible_callback function |
| 1847 * (in most cases, it is nodes set) | 1850 * (in most cases, it is nodes set) |
| 1848 * @mode: the c14n mode (see @xmlC14NMode) | 1851 * @mode: the c14n mode (see @xmlC14NMode) |
| 1849 * @inclusive_ns_prefixes: the list of inclusive namespace prefixes | 1852 * @inclusive_ns_prefixes: the list of inclusive namespace prefixes |
| 1850 * ended with a NULL or NULL if there is no | 1853 * ended with a NULL or NULL if there is no |
| 1851 *» » » inclusive namespaces (only for exclusive | 1854 *» » » inclusive namespaces (only for exclusive |
| 1852 * canonicalization, ignored otherwise) | 1855 * canonicalization, ignored otherwise) |
| 1853 * @with_comments: » include comments in the result (!=0) or not (==0) | 1856 * @with_comments:» include comments in the result (!=0) or not (==0) |
| 1854 * @buf: » » the output buffer to store canonical XML; this | 1857 * @buf:» » the output buffer to store canonical XML; this |
| 1855 * buffer MUST have encoder==NULL because C14N requires | 1858 * buffer MUST have encoder==NULL because C14N requires |
| 1856 * UTF-8 output | 1859 * UTF-8 output |
| 1857 * » » | 1860 * |
| 1858 * Dumps the canonized image of given XML document into the provided buffer. | 1861 * Dumps the canonized image of given XML document into the provided buffer. |
| 1859 * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or | 1862 * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or |
| 1860 * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) | 1863 * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) |
| 1861 * | 1864 * |
| 1862 * Returns non-negative value on success or a negative value on fail | 1865 * Returns non-negative value on success or a negative value on fail |
| 1863 */ | 1866 */ |
| 1864 int » » | 1867 int |
| 1865 xmlC14NExecute(xmlDocPtr doc, xmlC14NIsVisibleCallback is_visible_callback, | 1868 xmlC14NExecute(xmlDocPtr doc, xmlC14NIsVisibleCallback is_visible_callback, |
| 1866 void* user_data, int mode, xmlChar **inclusive_ns_prefixes, | 1869 void* user_data, int mode, xmlChar **inclusive_ns_prefixes, |
| 1867 int with_comments, xmlOutputBufferPtr buf) { | 1870 int with_comments, xmlOutputBufferPtr buf) { |
| 1868 | 1871 |
| 1869 xmlC14NCtxPtr ctx; | 1872 xmlC14NCtxPtr ctx; |
| 1870 xmlC14NMode c14n_mode = XML_C14N_1_0; | 1873 xmlC14NMode c14n_mode = XML_C14N_1_0; |
| 1871 int ret; | 1874 int ret; |
| 1872 | 1875 |
| 1873 if ((buf == NULL) || (doc == NULL)) { | 1876 if ((buf == NULL) || (doc == NULL)) { |
| 1874 xmlC14NErrParam("executing c14n"); | 1877 xmlC14NErrParam("executing c14n"); |
| 1875 return (-1); | 1878 return (-1); |
| 1876 } | 1879 } |
| 1877 | 1880 |
| 1878 /* for backward compatibility, we have to have "mode" as "int" | 1881 /* for backward compatibility, we have to have "mode" as "int" |
| 1879 and here we check that user gives valid value */ | 1882 and here we check that user gives valid value */ |
| 1880 switch(mode) { | 1883 switch(mode) { |
| 1881 case XML_C14N_1_0: | 1884 case XML_C14N_1_0: |
| 1882 case XML_C14N_EXCLUSIVE_1_0: | 1885 case XML_C14N_EXCLUSIVE_1_0: |
| 1883 case XML_C14N_1_1: | 1886 case XML_C14N_1_1: |
| 1884 c14n_mode = (xmlC14NMode)mode; | 1887 c14n_mode = (xmlC14NMode)mode; |
| 1885 break; | 1888 break; |
| 1886 default: | 1889 default: |
| 1887 xmlC14NErrParam("invalid mode for executing c14n"); | 1890 xmlC14NErrParam("invalid mode for executing c14n"); |
| 1888 return (-1); | 1891 return (-1); |
| 1889 } | 1892 } |
| 1890 | 1893 |
| 1891 /* | 1894 /* |
| 1892 * Validate the encoding output buffer encoding | 1895 * Validate the encoding output buffer encoding |
| 1893 */ | 1896 */ |
| 1894 if (buf->encoder != NULL) { | 1897 if (buf->encoder != NULL) { |
| 1895 xmlC14NErr(NULL, (xmlNodePtr) doc, XML_C14N_REQUIRES_UTF8, | 1898 xmlC14NErr(NULL, (xmlNodePtr) doc, XML_C14N_REQUIRES_UTF8, |
| 1896 "xmlC14NExecute: output buffer encoder != NULL but C14N requires UTF8 output\n")
; | 1899 "xmlC14NExecute: output buffer encoder != NULL but C14N requires UTF8 output\n")
; |
| 1897 return (-1); | 1900 return (-1); |
| 1898 } | 1901 } |
| 1899 | 1902 |
| 1900 ctx = xmlC14NNewCtx(doc, is_visible_callback, user_data, | 1903 ctx = xmlC14NNewCtx(doc, is_visible_callback, user_data, |
| 1901 c14n_mode, inclusive_ns_prefixes, | 1904 c14n_mode, inclusive_ns_prefixes, |
| 1902 with_comments, buf); | 1905 with_comments, buf); |
| 1903 if (ctx == NULL) { | 1906 if (ctx == NULL) { |
| 1904 xmlC14NErr(NULL, (xmlNodePtr) doc, XML_C14N_CREATE_CTXT, | 1907 xmlC14NErr(NULL, (xmlNodePtr) doc, XML_C14N_CREATE_CTXT, |
| 1905 "xmlC14NExecute: unable to create C14N context\n"); | 1908 "xmlC14NExecute: unable to create C14N context\n"); |
| 1906 return (-1); | 1909 return (-1); |
| 1907 } | 1910 } |
| 1908 | 1911 |
| 1909 | 1912 |
| 1910 | 1913 |
| 1911 /* | 1914 /* |
| 1912 * Root Node | 1915 * Root Node |
| 1913 * The root node is the parent of the top-level document element. The | 1916 * The root node is the parent of the top-level document element. The |
| 1914 * result of processing each of its child nodes that is in the node-set | 1917 * result of processing each of its child nodes that is in the node-set |
| 1915 * in document order. The root node does not generate a byte order mark, | 1918 * in document order. The root node does not generate a byte order mark, |
| 1916 * XML declaration, nor anything from within the document type | 1919 * XML declaration, nor anything from within the document type |
| 1917 * declaration. | 1920 * declaration. |
| 1918 */ | 1921 */ |
| 1919 if (doc->children != NULL) { | 1922 if (doc->children != NULL) { |
| 1920 ret = xmlC14NProcessNodeList(ctx, doc->children); | 1923 ret = xmlC14NProcessNodeList(ctx, doc->children); |
| 1921 if (ret < 0) { | 1924 if (ret < 0) { |
| 1922 xmlC14NErrInternal("processing docs children list"); | 1925 xmlC14NErrInternal("processing docs children list"); |
| 1923 xmlC14NFreeCtx(ctx); | 1926 xmlC14NFreeCtx(ctx); |
| 1924 return (-1); | 1927 return (-1); |
| 1925 } | 1928 } |
| 1926 } | 1929 } |
| 1927 | 1930 |
| 1928 /* | 1931 /* |
| 1929 * Flush buffer to get number of bytes written | 1932 * Flush buffer to get number of bytes written |
| 1930 */ | 1933 */ |
| 1931 ret = xmlOutputBufferFlush(buf); | 1934 ret = xmlOutputBufferFlush(buf); |
| 1932 if (ret < 0) { | 1935 if (ret < 0) { |
| 1933 xmlC14NErrInternal("flushing output buffer"); | 1936 xmlC14NErrInternal("flushing output buffer"); |
| 1934 xmlC14NFreeCtx(ctx); | 1937 xmlC14NFreeCtx(ctx); |
| 1935 return (-1); | 1938 return (-1); |
| 1936 } | 1939 } |
| 1937 | 1940 |
| 1938 /* | 1941 /* |
| 1939 * Cleanup | 1942 * Cleanup |
| 1940 */ | 1943 */ |
| 1941 xmlC14NFreeCtx(ctx); | 1944 xmlC14NFreeCtx(ctx); |
| 1942 return (ret); | 1945 return (ret); |
| 1943 } | 1946 } |
| 1944 | 1947 |
| 1945 /** | 1948 /** |
| 1946 * xmlC14NDocSaveTo: | 1949 * xmlC14NDocSaveTo: |
| 1947 * @doc: » » the XML document for canonization | 1950 * @doc:» » the XML document for canonization |
| 1948 * @nodes: » » the nodes set to be included in the canonized image | 1951 * @nodes:» » the nodes set to be included in the canonized image |
| 1949 * » » or NULL if all document nodes should be included | 1952 *» » or NULL if all document nodes should be included |
| 1950 * @mode: the c14n mode (see @xmlC14NMode) | 1953 * @mode: the c14n mode (see @xmlC14NMode) |
| 1951 * @inclusive_ns_prefixes: the list of inclusive namespace prefixes | 1954 * @inclusive_ns_prefixes: the list of inclusive namespace prefixes |
| 1952 * ended with a NULL or NULL if there is no | 1955 * ended with a NULL or NULL if there is no |
| 1953 *» » » inclusive namespaces (only for exclusive | 1956 *» » » inclusive namespaces (only for exclusive |
| 1954 * canonicalization, ignored otherwise) | 1957 * canonicalization, ignored otherwise) |
| 1955 * @with_comments: » include comments in the result (!=0) or not (==0) | 1958 * @with_comments:» include comments in the result (!=0) or not (==0) |
| 1956 * @buf: » » the output buffer to store canonical XML; this | 1959 * @buf:» » the output buffer to store canonical XML; this |
| 1957 * buffer MUST have encoder==NULL because C14N requires | 1960 * buffer MUST have encoder==NULL because C14N requires |
| 1958 * UTF-8 output | 1961 * UTF-8 output |
| 1959 * » » | 1962 * |
| 1960 * Dumps the canonized image of given XML document into the provided buffer. | 1963 * Dumps the canonized image of given XML document into the provided buffer. |
| 1961 * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or | 1964 * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or |
| 1962 * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) | 1965 * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) |
| 1963 * | 1966 * |
| 1964 * Returns non-negative value on success or a negative value on fail | 1967 * Returns non-negative value on success or a negative value on fail |
| 1965 */ | 1968 */ |
| 1966 int | 1969 int |
| 1967 xmlC14NDocSaveTo(xmlDocPtr doc, xmlNodeSetPtr nodes, | 1970 xmlC14NDocSaveTo(xmlDocPtr doc, xmlNodeSetPtr nodes, |
| 1968 int mode, xmlChar ** inclusive_ns_prefixes, | 1971 int mode, xmlChar ** inclusive_ns_prefixes, |
| 1969 int with_comments, xmlOutputBufferPtr buf) { | 1972 int with_comments, xmlOutputBufferPtr buf) { |
| 1970 return(xmlC14NExecute(doc, | 1973 return(xmlC14NExecute(doc, |
| 1971 (xmlC14NIsVisibleCallback)xmlC14NIsNodeInNodeset, | 1974 (xmlC14NIsVisibleCallback)xmlC14NIsNodeInNodeset, |
| 1972 nodes, | 1975 nodes, |
| 1973 mode, | 1976 mode, |
| 1974 inclusive_ns_prefixes, | 1977 inclusive_ns_prefixes, |
| 1975 with_comments, | 1978 with_comments, |
| 1976 buf)); | 1979 buf)); |
| 1977 } | 1980 } |
| 1978 | 1981 |
| 1979 | 1982 |
| 1980 /** | 1983 /** |
| 1981 * xmlC14NDocDumpMemory: | 1984 * xmlC14NDocDumpMemory: |
| 1982 * @doc: » » the XML document for canonization | 1985 * @doc:» » the XML document for canonization |
| 1983 * @nodes: » » the nodes set to be included in the canonized image | 1986 * @nodes:» » the nodes set to be included in the canonized image |
| 1984 * » » or NULL if all document nodes should be included | 1987 *» » or NULL if all document nodes should be included |
| 1985 * @mode: the c14n mode (see @xmlC14NMode) | 1988 * @mode: the c14n mode (see @xmlC14NMode) |
| 1986 * @inclusive_ns_prefixes: the list of inclusive namespace prefixes | 1989 * @inclusive_ns_prefixes: the list of inclusive namespace prefixes |
| 1987 * ended with a NULL or NULL if there is no | 1990 * ended with a NULL or NULL if there is no |
| 1988 *» » » inclusive namespaces (only for exclusive | 1991 *» » » inclusive namespaces (only for exclusive |
| 1989 * canonicalization, ignored otherwise) | 1992 * canonicalization, ignored otherwise) |
| 1990 * @with_comments: » include comments in the result (!=0) or not (==0) | 1993 * @with_comments:» include comments in the result (!=0) or not (==0) |
| 1991 * @doc_txt_ptr: » the memory pointer for allocated canonical XML text; | 1994 * @doc_txt_ptr:» the memory pointer for allocated canonical XML text; |
| 1992 * the caller of this functions is responsible for calling | 1995 * the caller of this functions is responsible for calling |
| 1993 *» » » xmlFree() to free allocated memory | 1996 *» » » xmlFree() to free allocated memory |
| 1994 * » » | 1997 * |
| 1995 * Dumps the canonized image of given XML document into memory. | 1998 * Dumps the canonized image of given XML document into memory. |
| 1996 * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or | 1999 * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or |
| 1997 * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) | 2000 * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) |
| 1998 * | 2001 * |
| 1999 * Returns the number of bytes written on success or a negative value on fail | 2002 * Returns the number of bytes written on success or a negative value on fail |
| 2000 */ | 2003 */ |
| 2001 int | 2004 int |
| 2002 xmlC14NDocDumpMemory(xmlDocPtr doc, xmlNodeSetPtr nodes, | 2005 xmlC14NDocDumpMemory(xmlDocPtr doc, xmlNodeSetPtr nodes, |
| 2003 int mode, xmlChar ** inclusive_ns_prefixes, | 2006 int mode, xmlChar ** inclusive_ns_prefixes, |
| 2004 int with_comments, xmlChar ** doc_txt_ptr) | 2007 int with_comments, xmlChar ** doc_txt_ptr) |
| 2005 { | 2008 { |
| 2006 int ret; | 2009 int ret; |
| 2007 xmlOutputBufferPtr buf; | 2010 xmlOutputBufferPtr buf; |
| 2008 | 2011 |
| 2009 if (doc_txt_ptr == NULL) { | 2012 if (doc_txt_ptr == NULL) { |
| 2010 xmlC14NErrParam("dumping doc to memory"); | 2013 xmlC14NErrParam("dumping doc to memory"); |
| 2011 return (-1); | 2014 return (-1); |
| 2012 } | 2015 } |
| 2013 | 2016 |
| 2014 *doc_txt_ptr = NULL; | 2017 *doc_txt_ptr = NULL; |
| 2015 | 2018 |
| 2016 /* | 2019 /* |
| 2017 * create memory buffer with UTF8 (default) encoding | 2020 * create memory buffer with UTF8 (default) encoding |
| 2018 */ | 2021 */ |
| 2019 buf = xmlAllocOutputBuffer(NULL); | 2022 buf = xmlAllocOutputBuffer(NULL); |
| 2020 if (buf == NULL) { | 2023 if (buf == NULL) { |
| 2021 xmlC14NErrMemory("creating output buffer"); | 2024 xmlC14NErrMemory("creating output buffer"); |
| 2022 return (-1); | 2025 return (-1); |
| 2023 } | 2026 } |
| 2024 | 2027 |
| 2025 /* | 2028 /* |
| 2026 * canonize document and write to buffer | 2029 * canonize document and write to buffer |
| 2027 */ | 2030 */ |
| 2028 ret = xmlC14NDocSaveTo(doc, nodes, mode, inclusive_ns_prefixes, | 2031 ret = xmlC14NDocSaveTo(doc, nodes, mode, inclusive_ns_prefixes, |
| 2029 with_comments, buf); | 2032 with_comments, buf); |
| 2030 if (ret < 0) { | 2033 if (ret < 0) { |
| 2031 xmlC14NErrInternal("saving doc to output buffer"); | 2034 xmlC14NErrInternal("saving doc to output buffer"); |
| 2032 (void) xmlOutputBufferClose(buf); | 2035 (void) xmlOutputBufferClose(buf); |
| 2033 return (-1); | 2036 return (-1); |
| 2034 } | 2037 } |
| 2035 | 2038 |
| 2036 ret = buf->buffer->use; | 2039 ret = xmlBufUse(buf->buffer); |
| 2037 if (ret > 0) { | 2040 if (ret > 0) { |
| 2038 *doc_txt_ptr = xmlStrndup(buf->buffer->content, ret); | 2041 *doc_txt_ptr = xmlStrndup(xmlBufContent(buf->buffer), ret); |
| 2039 } | 2042 } |
| 2040 (void) xmlOutputBufferClose(buf); | 2043 (void) xmlOutputBufferClose(buf); |
| 2041 | 2044 |
| 2042 if ((*doc_txt_ptr == NULL) && (ret > 0)) { | 2045 if ((*doc_txt_ptr == NULL) && (ret > 0)) { |
| 2043 xmlC14NErrMemory("coping canonicanized document"); | 2046 xmlC14NErrMemory("coping canonicanized document"); |
| 2044 return (-1); | 2047 return (-1); |
| 2045 } | 2048 } |
| 2046 return (ret); | 2049 return (ret); |
| 2047 } | 2050 } |
| 2048 | 2051 |
| 2049 /** | 2052 /** |
| 2050 * xmlC14NDocSave: | 2053 * xmlC14NDocSave: |
| 2051 * @doc: » » the XML document for canonization | 2054 * @doc:» » the XML document for canonization |
| 2052 * @nodes: » » the nodes set to be included in the canonized image | 2055 * @nodes:» » the nodes set to be included in the canonized image |
| 2053 * » » or NULL if all document nodes should be included | 2056 *» » or NULL if all document nodes should be included |
| 2054 * @mode: the c14n mode (see @xmlC14NMode) | 2057 * @mode: the c14n mode (see @xmlC14NMode) |
| 2055 * @inclusive_ns_prefixes: the list of inclusive namespace prefixes | 2058 * @inclusive_ns_prefixes: the list of inclusive namespace prefixes |
| 2056 * ended with a NULL or NULL if there is no | 2059 * ended with a NULL or NULL if there is no |
| 2057 *» » » inclusive namespaces (only for exclusive | 2060 *» » » inclusive namespaces (only for exclusive |
| 2058 * canonicalization, ignored otherwise) | 2061 * canonicalization, ignored otherwise) |
| 2059 * @with_comments: » include comments in the result (!=0) or not (==0) | 2062 * @with_comments:» include comments in the result (!=0) or not (==0) |
| 2060 * @filename: » » the filename to store canonical XML image | 2063 * @filename:» » the filename to store canonical XML image |
| 2061 * @compression:» the compression level (zlib requred): | 2064 * @compression:» the compression level (zlib requred): |
| 2062 * -1 - libxml default, | 2065 * -1 - libxml default, |
| 2063 *» » » » 0 - uncompressed, | 2066 *» » » » 0 - uncompressed, |
| 2064 * >0 - compression level | 2067 * >0 - compression level |
| 2065 * » » | 2068 * |
| 2066 * Dumps the canonized image of given XML document into the file. | 2069 * Dumps the canonized image of given XML document into the file. |
| 2067 * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or | 2070 * For details see "Canonical XML" (http://www.w3.org/TR/xml-c14n) or |
| 2068 * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) | 2071 * "Exclusive XML Canonicalization" (http://www.w3.org/TR/xml-exc-c14n) |
| 2069 * | 2072 * |
| 2070 * Returns the number of bytes written success or a negative value on fail | 2073 * Returns the number of bytes written success or a negative value on fail |
| 2071 */ | 2074 */ |
| 2072 int | 2075 int |
| 2073 xmlC14NDocSave(xmlDocPtr doc, xmlNodeSetPtr nodes, | 2076 xmlC14NDocSave(xmlDocPtr doc, xmlNodeSetPtr nodes, |
| 2074 int mode, xmlChar ** inclusive_ns_prefixes, | 2077 int mode, xmlChar ** inclusive_ns_prefixes, |
| 2075 int with_comments, const char *filename, int compression) | 2078 int with_comments, const char *filename, int compression) |
| 2076 { | 2079 { |
| 2077 xmlOutputBufferPtr buf; | 2080 xmlOutputBufferPtr buf; |
| 2078 int ret; | 2081 int ret; |
| 2079 | 2082 |
| 2080 if (filename == NULL) { | 2083 if (filename == NULL) { |
| 2081 xmlC14NErrParam("saving doc"); | 2084 xmlC14NErrParam("saving doc"); |
| 2082 return (-1); | 2085 return (-1); |
| 2083 } | 2086 } |
| 2084 #ifdef HAVE_ZLIB_H | 2087 #ifdef HAVE_ZLIB_H |
| 2085 if (compression < 0) | 2088 if (compression < 0) |
| 2086 compression = xmlGetCompressMode(); | 2089 compression = xmlGetCompressMode(); |
| 2087 #endif | 2090 #endif |
| 2088 | 2091 |
| 2089 /* | 2092 /* |
| 2090 * save the content to a temp buffer, use default UTF8 encoding. | 2093 * save the content to a temp buffer, use default UTF8 encoding. |
| 2091 */ | 2094 */ |
| 2092 buf = xmlOutputBufferCreateFilename(filename, NULL, compression); | 2095 buf = xmlOutputBufferCreateFilename(filename, NULL, compression); |
| 2093 if (buf == NULL) { | 2096 if (buf == NULL) { |
| 2094 xmlC14NErrInternal("creating temporary filename"); | 2097 xmlC14NErrInternal("creating temporary filename"); |
| 2095 return (-1); | 2098 return (-1); |
| 2096 } | 2099 } |
| 2097 | 2100 |
| 2098 /* | 2101 /* |
| 2099 * canonize document and write to buffer | 2102 * canonize document and write to buffer |
| 2100 */ | 2103 */ |
| 2101 ret = xmlC14NDocSaveTo(doc, nodes, mode, inclusive_ns_prefixes, | 2104 ret = xmlC14NDocSaveTo(doc, nodes, mode, inclusive_ns_prefixes, |
| 2102 with_comments, buf); | 2105 with_comments, buf); |
| 2103 if (ret < 0) { | 2106 if (ret < 0) { |
| 2104 xmlC14NErrInternal("cannicanize document to buffer"); | 2107 xmlC14NErrInternal("cannicanize document to buffer"); |
| 2105 (void) xmlOutputBufferClose(buf); | 2108 (void) xmlOutputBufferClose(buf); |
| 2106 return (-1); | 2109 return (-1); |
| 2107 } | 2110 } |
| 2108 | 2111 |
| 2109 /* | 2112 /* |
| 2110 * get the numbers of bytes written | 2113 * get the numbers of bytes written |
| 2111 */ | 2114 */ |
| 2112 ret = xmlOutputBufferClose(buf); | 2115 ret = xmlOutputBufferClose(buf); |
| 2113 return (ret); | 2116 return (ret); |
| 2114 } | 2117 } |
| 2115 | 2118 |
| 2116 | 2119 |
| 2117 | 2120 |
| 2118 /* | 2121 /* |
| 2119 * Macro used to grow the current buffer. | 2122 * Macro used to grow the current buffer. |
| 2120 */ | 2123 */ |
| 2121 #define growBufferReentrant() { \ | 2124 #define growBufferReentrant() { \ |
| 2122 buffer_size *= 2; \ | 2125 buffer_size *= 2; \ |
| 2123 buffer = (xmlChar *) \ | 2126 buffer = (xmlChar *) \ |
| 2124 » » xmlRealloc(buffer, buffer_size * sizeof(xmlChar));» \ | 2127 » » xmlRealloc(buffer, buffer_size * sizeof(xmlChar));» \ |
| 2125 if (buffer == NULL) { \ | 2128 if (buffer == NULL) { \ |
| 2126 xmlC14NErrMemory("growing buffer"); \ | 2129 xmlC14NErrMemory("growing buffer"); \ |
| 2127 return(NULL); \ | 2130 return(NULL); \ |
| 2128 } \ | 2131 } \ |
| 2129 } | 2132 } |
| 2130 | 2133 |
| 2131 /** | 2134 /** |
| 2132 * xmlC11NNormalizeString: | 2135 * xmlC11NNormalizeString: |
| 2133 * @input: the input string | 2136 * @input: the input string |
| 2134 * @mode: the normalization mode (attribute, comment, PI or text) | 2137 * @mode: the normalization mode (attribute, comment, PI or text) |
| 2135 * | 2138 * |
| 2136 * Converts a string to a canonical (normalized) format. The code is stolen | 2139 * Converts a string to a canonical (normalized) format. The code is stolen |
| 2137 * from xmlEncodeEntitiesReentrant(). Added normalization of \x09, \x0a, \x0A | 2140 * from xmlEncodeEntitiesReentrant(). Added normalization of \x09, \x0a, \x0A |
| 2138 * and the @mode parameter | 2141 * and the @mode parameter |
| 2139 * | 2142 * |
| 2140 * Returns a normalized string (caller is responsible for calling xmlFree()) | 2143 * Returns a normalized string (caller is responsible for calling xmlFree()) |
| 2141 * or NULL if an error occurs | 2144 * or NULL if an error occurs |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2226 } | 2229 } |
| 2227 cur++; | 2230 cur++; |
| 2228 } | 2231 } |
| 2229 *out = 0; | 2232 *out = 0; |
| 2230 return (buffer); | 2233 return (buffer); |
| 2231 } | 2234 } |
| 2232 #endif /* LIBXML_OUTPUT_ENABLED */ | 2235 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 2233 #define bottom_c14n | 2236 #define bottom_c14n |
| 2234 #include "elfgcchack.h" | 2237 #include "elfgcchack.h" |
| 2235 #endif /* LIBXML_C14N_ENABLED */ | 2238 #endif /* LIBXML_C14N_ENABLED */ |
| OLD | NEW |