50#include "MagickCore/studio.h"
51#include "MagickCore/blob.h"
52#include "MagickCore/blob-private.h"
53#include "MagickCore/exception.h"
54#include "MagickCore/exception-private.h"
55#include "MagickCore/image-private.h"
56#include "MagickCore/log.h"
57#include "MagickCore/memory_.h"
58#include "MagickCore/memory-private.h"
59#include "MagickCore/semaphore.h"
60#include "MagickCore/string_.h"
61#include "MagickCore/string-private.h"
62#include "MagickCore/token-private.h"
63#include "MagickCore/xml-tree.h"
64#include "MagickCore/xml-tree-private.h"
65#include "MagickCore/utility.h"
66#include "MagickCore/utility-private.h"
71#define NumberPredefinedEntities 10
72#define XMLWhitespace "\t\r\n "
119 ***processing_instructions,
137 *sentinel[] = { (
char *) NULL };
179 child->offset=offset;
180 child->parent=xml_info;
183 xml_info->child=child;
186 head=xml_info->child;
187 if (head->offset > offset)
190 xml_info->child=child;
196 (node->ordered->offset <= offset))
198 child->ordered=node->ordered;
203 while ((node != (
XMLTreeInfo *) NULL) && (strcmp(node->tag,child->tag) != 0))
208 if ((node != (
XMLTreeInfo *) NULL) && (node->offset <= offset))
211 (node->next->offset <= offset))
213 child->next=node->next;
219 previous->sibling=node->sibling;
223 while ((node != (
XMLTreeInfo *) NULL) && (node->offset <= offset))
230 previous->sibling=child;
236 const char *tag,
const size_t offset)
243 child=(
XMLTreeInfo *) AcquireMagickMemory(
sizeof(*child));
246 (void) memset(child,0,
sizeof(*child));
247 child->tag=ConstantString(tag);
248 child->attributes=sentinel;
249 child->content=ConstantString(
"");
250 child->debug=IsEventLogging();
251 child->signature=MagickCoreSignature;
252 return(InsertTagIntoXMLTree(xml_info,child,offset));
284static char *CanonicalXMLContent(
const char *content,
285 const MagickBooleanType pedantic)
300 utf8=ConvertLatin1ToUTF8((
const unsigned char *) content);
301 if (utf8 == (
unsigned char *) NULL)
302 return((
char *) NULL);
303 for (p=utf8; *p !=
'\0'; p++)
304 if ((*p < 0x20) && (*p != 0x09) && (*p != 0x0a) && (*p != 0x0d))
311 base64=Base64Encode(utf8,strlen((
char *) utf8),&length);
312 utf8=(
unsigned char *) RelinquishMagickMemory(utf8);
313 if (base64 == (
char *) NULL)
314 return((
char *) NULL);
315 canonical_content=AcquireString(
"<base64>");
316 (void) ConcatenateString(&canonical_content,base64);
317 base64=DestroyString(base64);
318 (void) ConcatenateString(&canonical_content,
"</base64>");
319 return(canonical_content);
321 canonical_content=SubstituteXMLEntities((
const char *) utf8,pedantic);
322 utf8=(
unsigned char *) RelinquishMagickMemory(utf8);
323 return(canonical_content);
327 const char *path,
const size_t offset)
331 subnode[MagickPathExtent],
332 tag[MagickPathExtent];
346 assert((xml_info->signature == MagickCoreSignature) ||
347 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
348 if (IsEventLogging() != MagickFalse)
349 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
351 components=GetPathComponents(path,&number_components);
352 if (components == (
char **) NULL)
354 for (i=0; i < (ssize_t) number_components; i++)
356 GetPathComponent(components[i],SubimagePath,subnode);
357 GetPathComponent(components[i],CanonicalPath,tag);
358 child=GetXMLTreeChild(node,tag);
360 child=AddChildToXMLTree(node,tag,offset);
364 for (j=(ssize_t) StringToLong(subnode)-1; j > 0; j--)
372 components[i]=DestroyString(components[i]);
374 for ( ; i < (ssize_t) number_components; i++)
375 components[i]=DestroyString(components[i]);
376 components=(
char **) RelinquishMagickMemory(components);
406static char **DestroyXMLTreeAttributes(
char **attributes)
414 if ((attributes == (
char **) NULL) || (attributes == sentinel))
415 return((
char **) NULL);
416 for (i=0; attributes[i] != (
char *) NULL; i+=2)
421 if (attributes[i] != (
char *) NULL)
422 attributes[i]=DestroyString(attributes[i]);
423 if (attributes[i+1] != (
char *) NULL)
424 attributes[i+1]=DestroyString(attributes[i+1]);
426 attributes=(
char **) RelinquishMagickMemory(attributes);
427 return((
char **) NULL);
430static void DestroyXMLTreeChild(
XMLTreeInfo *xml_info,
437 child=xml_info->child;
443 (void) DestroyXMLTree_(node,depth+1);
447static void DestroyXMLTreeOrdered(
XMLTreeInfo *xml_info,
454 ordered=xml_info->ordered;
458 ordered=node->ordered;
460 (void) DestroyXMLTree_(node,depth+1);
464static void DestroyXMLTreeRoot(
XMLTreeInfo *xml_info)
477 assert((xml_info->signature == MagickCoreSignature) ||
478 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
479 if (IsEventLogging() != MagickFalse)
480 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
487 for (i=NumberPredefinedEntities; root->entities[i] != (
char *) NULL; i+=2)
488 root->entities[i+1]=DestroyString(root->entities[i+1]);
489 root->entities=(
char **) RelinquishMagickMemory(root->entities);
490 for (i=0; root->attributes[i] != (
char **) NULL; i++)
492 attributes=root->attributes[i];
493 if (attributes[0] != (
char *) NULL)
494 attributes[0]=DestroyString(attributes[0]);
495 for (j=1; attributes[j] != (
char *) NULL; j+=3)
497 if (attributes[j] != (
char *) NULL)
498 attributes[j]=DestroyString(attributes[j]);
499 if (attributes[j+1] != (
char *) NULL)
500 attributes[j+1]=DestroyString(attributes[j+1]);
501 if (attributes[j+2] != (
char *) NULL)
502 attributes[j+2]=DestroyString(attributes[j+2]);
504 attributes=(
char **) RelinquishMagickMemory(attributes);
506 if (root->attributes[0] != (
char **) NULL)
507 root->attributes=(
char ***) RelinquishMagickMemory(root->attributes);
508 if (root->processing_instructions[0] != (
char **) NULL)
510 for (i=0; root->processing_instructions[i] != (
char **) NULL; i++)
512 for (j=0; root->processing_instructions[i][j] != (
char *) NULL; j++)
513 root->processing_instructions[i][j]=DestroyString(
514 root->processing_instructions[i][j]);
515 root->processing_instructions[i][j+1]=DestroyString(
516 root->processing_instructions[i][j+1]);
517 root->processing_instructions[i]=(
char **) RelinquishMagickMemory(
518 root->processing_instructions[i]);
520 root->processing_instructions=(
char ***) RelinquishMagickMemory(
521 root->processing_instructions);
529 assert((xml_info->signature == MagickCoreSignature) ||
530 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
531 if (IsEventLogging() != MagickFalse)
532 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
533 if (depth > MagickMaxRecursionDepth)
535 DestroyXMLTreeChild(xml_info,depth+1);
536 DestroyXMLTreeOrdered(xml_info,depth+1);
537 DestroyXMLTreeRoot(xml_info);
538 xml_info->attributes=DestroyXMLTreeAttributes(xml_info->attributes);
539 xml_info->content=DestroyString(xml_info->content);
540 xml_info->tag=DestroyString(xml_info->tag);
541 xml_info=(
XMLTreeInfo *) RelinquishMagickMemory(xml_info);
547 return(DestroyXMLTree_(xml_info,0));
574MagickPrivate
char *FileToXML(
const char *filename,
const size_t extent)
595 assert(filename != (
const char *) NULL);
598 if (LocaleCompare(filename,
"-") != 0)
599 file=open_utf8(filename,O_RDONLY | O_BINARY,0);
601 return((
char *) NULL);
602 offset=(MagickOffsetType) lseek(file,0,SEEK_END);
604 if ((file == fileno(stdin)) || (offset < 0) ||
605 (offset != (MagickOffsetType) ((ssize_t) offset)))
616 offset=(MagickOffsetType) lseek(file,0,SEEK_SET);
617 quantum=(size_t) MagickMaxBufferExtent;
618 if ((fstat(file,&file_stats) == 0) && (file_stats.st_size > 0))
619 quantum=(
size_t) MagickMin(file_stats.st_size,MagickMaxBufferExtent);
620 xml=(
char *) AcquireQuantumMemory(quantum,
sizeof(*xml));
621 for (i=0; xml != (
char *) NULL; i+=(size_t) count)
623 count=read(file,xml+i,quantum);
630 if (~((
size_t) i) < (quantum+1))
632 xml=(
char *) RelinquishMagickMemory(xml);
635 xml=(
char *) ResizeQuantumMemory(xml,i+quantum+1,
sizeof(*xml));
636 if ((i+(
size_t) count) >= extent)
639 if (LocaleCompare(filename,
"-") != 0)
640 file=close_utf8(file);
641 if (xml == (
char *) NULL)
642 return((
char *) NULL);
645 xml=(
char *) RelinquishMagickMemory(xml);
646 return((
char *) NULL);
648 length=MagickMin(i+(
size_t) count,extent);
652 length=(size_t) MagickMin(offset,(MagickOffsetType) extent);
654 if (~length >= (MagickPathExtent-1))
655 xml=(
char *) AcquireQuantumMemory(length+MagickPathExtent,
sizeof(*xml));
656 if (xml == (
char *) NULL)
658 file=close_utf8(file);
659 return((
char *) NULL);
661 map=MapBlob(file,ReadMode,0,length);
662 if (map != (
char *) NULL)
664 (void) memcpy(xml,map,length);
665 (void) UnmapBlob(map,length);
669 (void) lseek(file,0,SEEK_SET);
670 for (i=0; i < length; i+=(size_t) count)
672 count=read(file,xml+i,(
size_t) MagickMin(length-i,(
size_t)
673 MagickMaxBufferExtent));
683 file=close_utf8(file)-1;
684 xml=(
char *) RelinquishMagickMemory(xml);
685 return((
char *) NULL);
689 if (LocaleCompare(filename,
"-") != 0)
690 file=close_utf8(file);
692 xml=(
char *) RelinquishMagickMemory(xml);
721 assert((xml_info->signature == MagickCoreSignature) ||
722 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
723 if (IsEventLogging() != MagickFalse)
724 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
725 return(xml_info->next);
753MagickExport
const char *GetXMLTreeAttribute(
XMLTreeInfo *xml_info,
764 assert((xml_info->signature == MagickCoreSignature) ||
765 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
766 if (IsEventLogging() != MagickFalse)
767 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
768 if (xml_info->attributes == (
char **) NULL)
769 return((
const char *) NULL);
771 while ((xml_info->attributes[i] != (
char *) NULL) &&
772 (strcmp(xml_info->attributes[i],tag) != 0))
774 if (xml_info->attributes[i] != (
char *) NULL)
775 return(xml_info->attributes[i+1]);
780 while ((root->attributes[i] != (
char **) NULL) &&
781 (strcmp(root->attributes[i][0],xml_info->tag) != 0))
783 if (root->attributes[i] == (
char **) NULL)
784 return((
const char *) NULL);
786 while ((root->attributes[i][j] != (
char *) NULL) &&
787 (strcmp(root->attributes[i][j],tag) != 0))
789 if (root->attributes[i][j] == (
char *) NULL)
790 return((
const char *) NULL);
791 return(root->attributes[i][j+1]);
823 assert((xml_info->signature == MagickCoreSignature) ||
824 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
825 if (IsEventLogging() != MagickFalse)
826 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
827 child=xml_info->child;
828 if (tag != (
const char *) NULL)
829 while ((child != (
XMLTreeInfo *) NULL) && (strcmp(child->tag,tag) != 0))
830 child=child->sibling;
857MagickExport
const char *GetXMLTreeContent(
XMLTreeInfo *xml_info)
860 assert((xml_info->signature == MagickCoreSignature) ||
861 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
862 if (IsEventLogging() != MagickFalse)
863 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
864 return(xml_info->content);
892 assert((xml_info->signature == MagickCoreSignature) ||
893 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
894 if (IsEventLogging() != MagickFalse)
895 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
896 return(xml_info->sibling);
921MagickExport
const char *GetXMLTreeTag(
XMLTreeInfo *xml_info)
924 assert((xml_info->signature == MagickCoreSignature) ||
925 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
926 if (IsEventLogging() != MagickFalse)
927 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
928 return(xml_info->tag);
957static char *ConvertUTF16ToUTF8(
const char *content,
size_t *length)
975 utf8=(
char *) AcquireQuantumMemory(*length+1,
sizeof(*utf8));
976 if (utf8 == (
char *) NULL)
977 return((
char *) NULL);
978 encoding=(*content ==
'\xFE') ? 1 : (*content ==
'\xFF') ? 0 : -1;
984 (void) memcpy(utf8,content,*length*
sizeof(*utf8));
990 for (i=2; i < (ssize_t) (*length-1); i+=2)
992 c=(encoding != 0) ? ((content[i] & 0xff) << 8) | (content[i+1] & 0xff) :
993 ((content[i+1] & 0xff) << 8) | (content[i] & 0xff);
994 if ((c >= 0xd800) && (c <= 0xdfff) && ((i+=2) < (ssize_t) (*length-1)))
996 byte=(encoding != 0) ? ((content[i] & 0xff) << 8) |
997 (content[i+1] & 0xff) : ((content[i+1] & 0xff) << 8) |
999 c=(((c & 0x3ff) << 10) | (
byte & 0x3ff))+0x10000;
1001 if ((
size_t) (j+MagickPathExtent) > extent)
1003 extent=(size_t) j+MagickPathExtent;
1004 utf8=(
char *) ResizeQuantumMemory(utf8,extent,
sizeof(*utf8));
1005 if (utf8 == (
char *) NULL)
1018 for (bits=0;
byte != 0;
byte/=2)
1021 utf8[j++]=(0xFF << (7-bits)) | (c >> (6*bits));
1025 utf8[j]=(char) (0x80 | ((c >> (6*bits)) & 0x3f));
1030 utf8=(
char *) ResizeQuantumMemory(utf8,(*length+1),
sizeof(*utf8));
1031 if (utf8 != (
char *) NULL)
1036static char *ParseEntities(
char *xml,
char **entities,
int state)
1060 for ( ; *xml !=
'\0'; xml++)
1061 while (*xml ==
'\r')
1065 (void) memmove(xml,xml+1,strlen(xml));
1069 while ((*xml !=
'\0') && (*xml !=
'&') && ((*xml !=
'%') ||
1070 (state !=
'%')) && (isspace((
int) ((
unsigned char) *xml)) == 0))
1082 if ((state !=
'c') && (strncmp(xml,
"&#",2) == 0))
1088 c=(int) strtol(xml+2,&entity,10);
1090 c=(int) strtol(xml+3,&entity,16);
1091 if ((c == 0) || (*entity !=
';'))
1107 for (i=0;
byte != 0;
byte/=2)
1110 *xml=(char) ((0xFF << (7-i)) | (c >> (6*i)));
1115 *xml=(char) (0x80 | ((c >> (6*i)) & 0x3F));
1119 (void) memmove(xml,strchr(xml,
';')+1,strlen(strchr(xml,
';')));
1122 if (((*xml ==
'&') && ((state ==
'&') || (state ==
' ') ||
1123 (state ==
'*'))) || ((state ==
'%') && (*xml ==
'%')))
1129 while ((entities[i] != (
char *) NULL) &&
1130 (strncmp(xml+1,entities[i],strlen(entities[i])) != 0))
1132 if (entities[i++] == (
char *) NULL)
1135 if (entities[i] != (
char *) NULL)
1140 length=strlen(entities[i]);
1141 entity=strchr(xml,
';');
1142 if ((entity != (
char *) NULL) &&
1143 ((length-1L) >= (
size_t) (entity-xml)))
1145 offset=(ssize_t) (xml-p);
1146 extent=((size_t) offset+length+strlen(entity));
1149 p=(
char *) ResizeQuantumMemory(p,extent+1,
sizeof(*p));
1150 if (p == (
char *) NULL)
1151 ThrowFatalException(ResourceLimitFatalError,
1152 "MemoryAllocationFailed");
1160 extent_xml=(
char *) AcquireQuantumMemory(extent+1,
1161 sizeof(*extent_xml));
1162 if (extent_xml != (
char *) NULL)
1164 memset(extent_xml,0,extent*
sizeof(*extent_xml));
1165 (void) CopyMagickString(extent_xml,p,extent*
1166 sizeof(*extent_xml));
1170 if (p == (
char *) NULL)
1171 ThrowFatalException(ResourceLimitFatalError,
1172 "MemoryAllocationFailed");
1174 entity=strchr(xml,
';');
1176 if (entity != (
char *) NULL)
1177 (void) memmove(xml+length,entity+1,strlen(entity));
1178 (void) memcpy(xml,entities[i],length);
1182 if (((state ==
' ') || (state ==
'*')) &&
1183 (isspace((
int) ((
unsigned char) *xml)) != 0))
1193 for (xml=p; *xml !=
'\0'; xml++)
1198 i=(ssize_t) strspn(xml,accept);
1200 (void) memmove(xml,xml+i,strlen(xml+i)+1);
1201 while ((*xml !=
'\0') && (*xml !=
' '))
1207 if ((xml >= p) && (*xml ==
' '))
1210 return(p == q ? ConstantString(p) : p);
1213static void ParseCharacterContent(
XMLTreeRoot *root,
char *xml,
1214 const size_t length,
const char state)
1219 xml_info=root->node;
1220 if ((xml_info == (
XMLTreeInfo *) NULL) || (xml_info->tag == (
char *) NULL) ||
1224 xml=ParseEntities(xml,root->entities,state);
1225 if ((xml_info->content != (
char *) NULL) && (*xml_info->content !=
'\0'))
1227 (void) ConcatenateString(&xml_info->content,xml);
1228 xml=DestroyString(xml);
1232 if (xml_info->content != (
char *) NULL)
1233 xml_info->content=DestroyString(xml_info->content);
1234 xml_info->content=xml;
1242 (root->node->tag == (
char *) NULL) || (strcmp(tag,root->node->tag) != 0))
1244 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1245 "ParseError",
"unexpected closing tag </%s>",tag);
1246 return(&root->root);
1248 root->node=root->node->parent;
1252static MagickBooleanType ValidateEntities(
char *tag,
char *xml,
1253 const int delimiter,
const size_t depth,
char **entities)
1261 if (depth > MagickMaxRecursionDepth)
1262 return(MagickFalse);
1265 while ((*xml !=
'\0') && (*xml != delimiter))
1269 if (strncmp(xml+1,tag,strlen(tag)) == 0)
1270 return(MagickFalse);
1272 while ((entities[i] != (
char *) NULL) &&
1273 (strncmp(entities[i],xml+1,strlen(entities[i])) == 0))
1275 if ((entities[i] != (
char *) NULL) &&
1276 (ValidateEntities(tag,entities[i+1],delimiter,depth+1,entities) == MagickFalse))
1277 return(MagickFalse);
1281static void ParseProcessingInstructions(
XMLTreeRoot *root,
char *xml,
1293 xml+=strcspn(xml,XMLWhitespace);
1297 xml+=strspn(xml+1,XMLWhitespace)+1;
1299 if (strcmp(target,
"xml") == 0)
1301 xml=strstr(xml,
"standalone");
1302 if ((xml != (
char *) NULL) &&
1303 (strncmp(xml+strspn(xml+10,XMLWhitespace
"='\"")+10,
"yes",3) == 0))
1304 root->standalone=MagickTrue;
1307 if (root->processing_instructions[0] == (
char **) NULL)
1309 root->processing_instructions=(
char ***) AcquireCriticalMemory(
sizeof(
1310 *root->processing_instructions));
1311 *root->processing_instructions=(
char **) NULL;
1314 while ((root->processing_instructions[i] != (
char **) NULL) &&
1315 (strcmp(target,root->processing_instructions[i][0]) != 0))
1317 if (root->processing_instructions[i] == (
char **) NULL)
1319 root->processing_instructions=(
char ***) ResizeQuantumMemory(
1320 root->processing_instructions,(
size_t) (i+2),
1321 sizeof(*root->processing_instructions));
1322 if (root->processing_instructions == (
char ***) NULL)
1323 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1324 root->processing_instructions[i]=(
char **) AcquireQuantumMemory(3,
1325 sizeof(**root->processing_instructions));
1326 if (root->processing_instructions[i] == (
char **) NULL)
1327 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1328 root->processing_instructions[i+1]=(
char **) NULL;
1329 root->processing_instructions[i][0]=ConstantString(target);
1330 root->processing_instructions[i][1]=(
char *)
1331 root->processing_instructions[i+1];
1332 root->processing_instructions[i+1]=(
char **) NULL;
1333 root->processing_instructions[i][2]=ConstantString(
"");
1336 while (root->processing_instructions[i][j] != (
char *) NULL)
1338 root->processing_instructions[i]=(
char **) ResizeQuantumMemory(
1339 root->processing_instructions[i],(
size_t) (j+3),
1340 sizeof(**root->processing_instructions));
1341 if (root->processing_instructions[i] == (
char **) NULL)
1342 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1343 root->processing_instructions[i][j+2]=(
char *) ResizeQuantumMemory(
1344 root->processing_instructions[i][j+1],(
size_t) (j+1),
1345 sizeof(***root->processing_instructions));
1346 if (root->processing_instructions[i][j+2] == (
char *) NULL)
1347 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1348 (void) CopyMagickString(root->processing_instructions[i][j+2]+j-1,
1349 root->root.tag != (
char *) NULL ?
">" :
"<",2);
1350 root->processing_instructions[i][j]=ConstantString(xml);
1351 root->processing_instructions[i][j+1]=(
char *) NULL;
1354static MagickBooleanType ParseInternalDoctype(
XMLTreeRoot *root,
char *xml,
1361 **predefined_entities,
1371 predefined_entities=(
char **) AcquireMagickMemory(
sizeof(sentinel));
1372 if (predefined_entities == (
char **) NULL)
1373 ThrowFatalException(ResourceLimitError,
"MemoryAllocationFailed");
1374 (void) memcpy(predefined_entities,sentinel,
sizeof(sentinel));
1375 for (xml[length]=
'\0'; xml != (
char *) NULL; )
1377 while ((*xml !=
'\0') && (*xml !=
'<') && (*xml !=
'%'))
1381 if ((strlen(xml) > 9) && (strncmp(xml,
"<!ENTITY",8) == 0))
1386 if (strspn(xml+8,XMLWhitespace) == 0)
1388 xml+=strspn(xml+8,XMLWhitespace)+8;
1390 n=xml+strspn(xml,XMLWhitespace
"%");
1391 if ((isalpha((
int) ((
unsigned char) *n)) == 0) && (*n !=
'_'))
1393 xml=n+strcspn(n,XMLWhitespace);
1397 v=xml+strspn(xml+1,XMLWhitespace)+1;
1400 if ((q !=
'"') && (q !=
'\''))
1405 xml=strchr(xml,
'>');
1408 entities=(*c ==
'%') ? predefined_entities : root->entities;
1409 for (i=0; entities[i] != (
char *) NULL; i++) ;
1410 entities=(
char **) ResizeQuantumMemory(entities,(
size_t) (i+3),
1412 if (entities == (
char **) NULL)
1413 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1415 predefined_entities=entities;
1417 root->entities=entities;
1421 if (xml != (
char *) NULL)
1426 entities[i+1]=ParseEntities(v,predefined_entities,
'%');
1427 entities[i+2]=(
char *) NULL;
1428 if ((ValidateEntities(n,entities[i+1],
'%',0,entities) != MagickFalse) &&
1429 (ValidateEntities(n,entities[i+1],
'&',0,entities) != MagickFalse))
1433 if (entities[i+1] != v)
1434 entities[i+1]=DestroyString(entities[i+1]);
1435 (void) ThrowMagickException(exception,GetMagickModule(),
1436 OptionWarning,
"ParseError",
"circular entity declaration %s",n);
1437 predefined_entities=(
char **) RelinquishMagickMemory(
1438 predefined_entities);
1439 return(MagickFalse);
1443 if (strncmp(xml,
"<!ATTLIST",9) == 0)
1448 t=xml+strspn(xml+9,XMLWhitespace)+9;
1451 (void) ThrowMagickException(exception,GetMagickModule(),
1452 OptionWarning,
"ParseError",
"unclosed <!ATTLIST");
1453 predefined_entities=(
char **) RelinquishMagickMemory(
1454 predefined_entities);
1455 return(MagickFalse);
1457 xml=t+strcspn(t,XMLWhitespace
">");
1462 while ((root->attributes[i] != (
char **) NULL) &&
1463 (n != (
char *) NULL) &&
1464 (strcmp(n,root->attributes[i][0]) != 0))
1466 while ((*(n=xml+strspn(xml+1,XMLWhitespace)+1) !=
'\0') &&
1469 xml=n+strcspn(n,XMLWhitespace);
1474 (void) ThrowMagickException(exception,GetMagickModule(),
1475 OptionWarning,
"ParseError",
"malformed <!ATTLIST");
1476 predefined_entities=(
char **) RelinquishMagickMemory(
1477 predefined_entities);
1478 return(MagickFalse);
1480 xml+=strspn(xml+1,XMLWhitespace)+1;
1481 c=(
char *) (strncmp(xml,
"CDATA",5) != 0 ?
"*" :
" ");
1482 if (strncmp(xml,
"NOTATION",8) == 0)
1483 xml+=strspn(xml+8,XMLWhitespace)+8;
1484 xml=(*xml ==
'(') ? strchr(xml,
')') : xml+
1485 strcspn(xml,XMLWhitespace);
1486 if (xml == (
char *) NULL)
1488 (void) ThrowMagickException(exception,GetMagickModule(),
1489 OptionWarning,
"ParseError",
"malformed <!ATTLIST");
1490 predefined_entities=(
char **) RelinquishMagickMemory(
1491 predefined_entities);
1492 return(MagickFalse);
1494 xml+=strspn(xml,XMLWhitespace
")");
1495 if (strncmp(xml,
"#FIXED",6) == 0)
1496 xml+=strspn(xml+6,XMLWhitespace)+6;
1499 xml+=strcspn(xml,XMLWhitespace
">")-1;
1505 if (((*xml ==
'"') || (*xml ==
'\'')) &&
1506 ((xml=strchr(v=xml+1,*xml)) != (
char *) NULL))
1510 (void) ThrowMagickException(exception,GetMagickModule(),
1511 OptionWarning,
"ParseError",
"malformed <!ATTLIST");
1512 predefined_entities=(
char **) RelinquishMagickMemory(
1513 predefined_entities);
1514 return(MagickFalse);
1516 if (root->attributes[i] == (
char **) NULL)
1522 root->attributes=(
char ***) AcquireQuantumMemory(2,
1523 sizeof(*root->attributes));
1525 root->attributes=(
char ***) ResizeQuantumMemory(
1526 root->attributes,(
size_t) (i+2),
1527 sizeof(*root->attributes));
1528 if (root->attributes == (
char ***) NULL)
1529 ThrowFatalException(ResourceLimitFatalError,
1530 "MemoryAllocationFailed");
1531 root->attributes[i]=(
char **) AcquireQuantumMemory(2,
1532 sizeof(**root->attributes));
1533 if (root->attributes[i] == (
char **) NULL)
1534 ThrowFatalException(ResourceLimitFatalError,
1535 "MemoryAllocationFailed");
1536 root->attributes[i][0]=ConstantString(t);
1537 root->attributes[i][1]=(
char *) NULL;
1538 root->attributes[i+1]=(
char **) NULL;
1540 for (j=1; root->attributes[i][j] != (
char *) NULL; j+=3) ;
1541 root->attributes[i]=(
char **) ResizeQuantumMemory(
1542 root->attributes[i],(
size_t) (j+4),
sizeof(**root->attributes));
1543 if (root->attributes[i] == (
char **) NULL)
1544 ThrowFatalException(ResourceLimitFatalError,
1545 "MemoryAllocationFailed");
1546 root->attributes[i][j+3]=(
char *) NULL;
1547 root->attributes[i][j+2]=ConstantString(c);
1548 root->attributes[i][j+1]=(
char *) NULL;
1549 if (v != (
char *) NULL)
1550 root->attributes[i][j+1]=ParseEntities(v,root->entities,*c);
1551 root->attributes[i][j]=ConstantString(n);
1555 if (strncmp(xml,
"<!--", 4) == 0)
1556 xml=strstr(xml+4,
"-->");
1558 if (strncmp(xml,
"<?", 2) == 0)
1562 if (xml != (
char *) NULL)
1564 ParseProcessingInstructions(root,c,(
size_t) (xml-c));
1570 xml=strchr(xml,
'>');
1572 if ((*(xml++) ==
'%') && (root->standalone == MagickFalse))
1575 predefined_entities=(
char **) RelinquishMagickMemory(predefined_entities);
1579static void ParseOpenTag(
XMLTreeRoot *root,
char *tag,
char **attributes)
1584 xml_info=root->node;
1585 if (xml_info->tag == (
char *) NULL)
1586 xml_info->tag=ConstantString(tag);
1588 xml_info=AddChildToXMLTree(xml_info,tag,strlen(xml_info->content));
1590 xml_info->attributes=attributes;
1591 root->node=xml_info;
1602static inline MagickBooleanType IsSkipTag(
const char *tag)
1608 while (ignore_tags[i] != (
const char *) NULL)
1610 if (LocaleCompare(tag,ignore_tags[i]) == 0)
1614 return(MagickFalse);
1648 if ((xml == (
const char *) NULL) || (strlen(xml) == 0))
1650 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1651 "ParseError",
"root tag missing");
1654 root=(
XMLTreeRoot *) NewXMLTreeTag((
char *) NULL);
1656 utf8=ConvertUTF16ToUTF8(xml,&length);
1657 if (utf8 == (
char *) NULL)
1659 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1660 "ParseError",
"UTF16 to UTF8 failed");
1663 terminal=utf8[MagickMax(length-1,0)];
1664 utf8[MagickMax(length-1,0)]=
'\0';
1666 while ((*p !=
'\0') && (*p !=
'<'))
1670 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1671 "ParseError",
"root tag missing");
1672 utf8=DestroyString(utf8);
1675 attribute=(
char **) NULL;
1680 attributes=(
char **) sentinel;
1683 if ((isalpha((
int) ((
unsigned char) *p)) != 0) || (*p ==
'_') ||
1684 (*p ==
':') || (c <
'\0'))
1691 (void) ThrowMagickException(exception,GetMagickModule(),
1692 OptionWarning,
"ParseError",
"root tag missing");
1693 utf8=DestroyString(utf8);
1694 return(&root->root);
1696 p+=(ptrdiff_t) strcspn(p,XMLWhitespace
"/>");
1697 while (isspace((
int) ((
unsigned char) *p)) != 0)
1699 if (((isalpha((
int) ((
unsigned char) *p)) != 0) || (*p ==
'_')) &&
1700 (ignore_depth == 0))
1702 if ((*p !=
'\0') && (*p !=
'/') && (*p !=
'>'))
1708 while ((root->attributes[i] != (
char **) NULL) &&
1709 (strcmp(root->attributes[i][0],tag) != 0))
1711 attribute=root->attributes[i];
1713 for (l=0; (*p !=
'\0') && (*p !=
'/') && (*p !=
'>'); l+=2)
1719 attributes=(
char **) AcquireQuantumMemory(4,
1720 sizeof(*attributes));
1722 attributes=(
char **) ResizeQuantumMemory(attributes,(
size_t)
1723 (l+4),
sizeof(*attributes));
1724 if (attributes == (
char **) NULL)
1726 (void) ThrowMagickException(exception,GetMagickModule(),
1727 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"");
1728 utf8=DestroyString(utf8);
1729 return(&root->root);
1731 attributes[l+2]=(
char *) NULL;
1732 attributes[l+1]=(
char *) NULL;
1734 p+=(ptrdiff_t) strcspn(p,XMLWhitespace
"=/>");
1735 if ((*p !=
'=') && (isspace((
int) ((
unsigned char) *p)) == 0))
1736 attributes[l]=ConstantString(
"");
1740 p+=(ptrdiff_t) strspn(p,XMLWhitespace
"=");
1742 if ((c ==
'"') || (c ==
'\''))
1749 while ((*p !=
'\0') && (*p != c))
1755 attributes[l]=ConstantString(
"");
1756 attributes[l+1]=ConstantString(
"");
1757 (void) DestroyXMLTreeAttributes(attributes);
1758 (void) ThrowMagickException(exception,
1759 GetMagickModule(),OptionWarning,
"ParseError",
1761 utf8=DestroyString(utf8);
1762 return(&root->root);
1765 while ((attribute != (
char **) NULL) &&
1766 (attribute[j] != (
char *) NULL) &&
1767 (strcmp(attribute[j],attributes[l]) != 0))
1769 attributes[l+1]=ParseEntities(attributes[l+1],
1770 root->entities,(attribute != (
char **) NULL) &&
1771 (attribute[j] != (
char *) NULL) ? *attribute[j+2] :
1774 attributes[l]=ConstantString(attributes[l]);
1776 while (isspace((
int) ((
unsigned char) *p)) != 0)
1782 while ((*p !=
'\0') && (*p !=
'/') && (*p !=
'>'))
1791 if (((*p !=
'\0') && (*p !=
'>')) ||
1792 ((*p ==
'\0') && (terminal !=
'>')))
1795 (void) DestroyXMLTreeAttributes(attributes);
1796 (void) ThrowMagickException(exception,GetMagickModule(),
1797 OptionWarning,
"ParseError",
"missing >");
1798 utf8=DestroyString(utf8);
1799 return(&root->root);
1801 if ((ignore_depth != 0) || (IsSkipTag(tag) != MagickFalse))
1802 (void) DestroyXMLTreeAttributes(attributes);
1805 ParseOpenTag(root,tag,attributes);
1806 (void) ParseCloseTag(root,tag,exception);
1812 if ((*p ==
'>') || ((*p ==
'\0') && (terminal ==
'>')))
1815 if ((ignore_depth == 0) && (IsSkipTag(tag) == MagickFalse))
1816 ParseOpenTag(root,tag,attributes);
1820 (void) DestroyXMLTreeAttributes(attributes);
1827 (void) DestroyXMLTreeAttributes(attributes);
1828 (void) ThrowMagickException(exception,GetMagickModule(),
1829 OptionWarning,
"ParseError",
"missing >");
1830 utf8=DestroyString(utf8);
1831 return(&root->root);
1842 p+=(ptrdiff_t) strcspn(tag,XMLWhitespace
">")+1;
1844 if ((c ==
'\0') && (terminal !=
'>'))
1846 (void) ThrowMagickException(exception,GetMagickModule(),
1847 OptionWarning,
"ParseError",
"missing >");
1848 utf8=DestroyString(utf8);
1849 return(&root->root);
1852 if ((ignore_depth == 0) &&
1853 (ParseCloseTag(root,tag,exception) != (
XMLTreeInfo *) NULL))
1855 utf8=DestroyString(utf8);
1856 return(&root->root);
1858 if (ignore_depth > 0)
1861 if (isspace((
int) ((
unsigned char) *p)) != 0)
1862 p+=(ptrdiff_t) strspn(p,XMLWhitespace);
1865 if (strncmp(p,
"!--",3) == 0)
1871 if ((p == (
char *) NULL) || ((*(p+=2) !=
'>') && (*p !=
'\0')) ||
1872 ((*p ==
'\0') && (terminal !=
'>')))
1874 (void) ThrowMagickException(exception,GetMagickModule(),
1875 OptionWarning,
"ParseError",
"unclosed <!--");
1876 utf8=DestroyString(utf8);
1877 return(&root->root);
1881 if (strncmp(p,
"![CDATA[",8) == 0)
1887 if (p != (
char *) NULL)
1890 if (ignore_depth == 0)
1891 ParseCharacterContent(root,tag+8,(
size_t) (p-tag-10),
'c');
1895 (void) ThrowMagickException(exception,GetMagickModule(),
1896 OptionWarning,
"ParseError",
"unclosed <![CDATA[");
1897 utf8=DestroyString(utf8);
1898 return(&root->root);
1902 if (strncmp(p,
"!DOCTYPE",8) == 0)
1907 for (l=0; (*p !=
'\0') && (((l == 0) && (*p !=
'>')) ||
1908 ((l != 0) && ((*p !=
']') ||
1909 (*(p+strspn(p+1,XMLWhitespace)+1) !=
'>'))));
1910 l=(ssize_t) ((*p ==
'[') ? 1 : l))
1911 p+=(ptrdiff_t) strcspn(p+1,
"[]>")+1;
1912 if ((*p ==
'\0') && (terminal !=
'>'))
1914 (void) ThrowMagickException(exception,GetMagickModule(),
1915 OptionWarning,
"ParseError",
"unclosed <!DOCTYPE");
1916 utf8=DestroyString(utf8);
1917 return(&root->root);
1920 tag=strchr(tag,
'[')+1;
1923 status=ParseInternalDoctype(root,tag,(
size_t) (p-tag),
1925 if (status == MagickFalse)
1927 utf8=DestroyString(utf8);
1928 return(&root->root);
1942 if (p == (
char *) NULL)
1945 }
while ((*p !=
'\0') && (*p !=
'>'));
1946 if ((p == (
char *) NULL) || ((*p ==
'\0') &&
1949 (void) ThrowMagickException(exception,GetMagickModule(),
1950 OptionWarning,
"ParseError",
"unclosed <?");
1951 utf8=DestroyString(utf8);
1952 return(&root->root);
1954 ParseProcessingInstructions(root,tag+1,(
size_t) (p-tag-2));
1958 (void) ThrowMagickException(exception,GetMagickModule(),
1959 OptionWarning,
"ParseError",
"unexpected <");
1960 utf8=DestroyString(utf8);
1961 return(&root->root);
1963 if ((p == (
char *) NULL) || (*p ==
'\0'))
1967 if ((*p !=
'\0') && (*p !=
'<'))
1972 while ((*p !=
'\0') && (*p !=
'<'))
1976 if (ignore_depth == 0)
1977 ParseCharacterContent(root,tag,(
size_t) (p-tag),
'&');
1983 utf8=DestroyString(utf8);
1985 return(&root->root);
1986 if (root->node->tag == (
char *) NULL)
1988 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1989 "ParseError",
"root tag missing");
1990 return(&root->root);
1992 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1993 "ParseError",
"unclosed tag: '%s'",root->node->tag);
1994 return(&root->root);
2019MagickExport
XMLTreeInfo *NewXMLTreeTag(
const char *tag)
2022 *predefined_entities[NumberPredefinedEntities+1] =
2024 "lt;",
"<",
"gt;",
">",
"quot;",
""",
2025 "apos;",
"'",
"amp;",
"&", (
char *) NULL
2031 root=(
XMLTreeRoot *) AcquireMagickMemory(
sizeof(*root));
2034 (void) memset(root,0,
sizeof(*root));
2035 root->root.tag=(
char *) NULL;
2036 if (tag != (
char *) NULL)
2037 root->root.tag=ConstantString(tag);
2038 root->node=(&root->root);
2039 root->root.content=ConstantString(
"");
2040 root->entities=(
char **) AcquireMagickMemory(
sizeof(predefined_entities));
2041 if (root->entities == (
char **) NULL)
2043 (void) memcpy(root->entities,predefined_entities,
sizeof(predefined_entities));
2044 root->root.attributes=sentinel;
2045 root->attributes=(
char ***) root->root.attributes;
2046 root->processing_instructions=(
char ***) root->root.attributes;
2047 root->debug=IsEventLogging();
2048 root->signature=MagickCoreSignature;
2049 return(&root->root);
2079 const char *content)
2082 assert((xml_info->signature == MagickCoreSignature) ||
2083 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
2084 if (IsEventLogging() != MagickFalse)
2085 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2086 if (xml_info->content != (
char *) NULL)
2087 xml_info->content=DestroyString(xml_info->content);
2088 xml_info->content=(
char *) ConstantString(content);
2115static char *EncodePredefinedEntities(
const char *source,ssize_t offset,
2116 char **destination,
size_t *length,
size_t *extent,MagickBooleanType pedantic)
2122 canonical_content=CanonicalXMLContent(source,pedantic);
2128 content=AcquireString(source);
2129 content[offset]=
'\0';
2130 canonical_content=CanonicalXMLContent(content,pedantic);
2131 content=DestroyString(content);
2133 if (canonical_content == (
char *) NULL)
2134 return(*destination);
2135 if ((*length+strlen(canonical_content)+MagickPathExtent) > *extent)
2137 *extent=(*length)+strlen(canonical_content)+MagickPathExtent;
2138 *destination=(
char *) ResizeQuantumMemory(*destination,*extent,
2139 sizeof(**destination));
2140 if (*destination == (
char *) NULL)
2141 return(*destination);
2143 *length+=(size_t) FormatLocaleString(*destination+(*length),*extent,
"%s",
2145 canonical_content=DestroyString(canonical_content);
2146 return(*destination);
2149static char *XMLTreeTagToXML(
XMLTreeInfo *xml_info,
char **source,
size_t *length,
2150 size_t *extent,
size_t start,
char ***attributes)
2165 content=(
char *)
"";
2167 content=xml_info->parent->content;
2169 *source=EncodePredefinedEntities(content+start,(ssize_t) (xml_info->offset-
2170 start),source,length,extent,MagickFalse);
2171 if ((*length+strlen(xml_info->tag)+MagickPathExtent) > *extent)
2173 *extent=(*length)+strlen(xml_info->tag)+MagickPathExtent;
2174 *source=(
char *) ResizeQuantumMemory(*source,*extent,
sizeof(**source));
2175 if (*source == (
char *) NULL)
2178 *length+=(size_t) FormatLocaleString(*source+(*length),*extent,
2179 "<%s",xml_info->tag);
2180 for (i=0; xml_info->attributes[i]; i+=2)
2182 attribute=GetXMLTreeAttribute(xml_info,xml_info->attributes[i]);
2183 if (attribute != xml_info->attributes[i+1])
2185 if ((*length+strlen(xml_info->attributes[i])+MagickPathExtent) > *extent)
2187 *extent=(*length)+strlen(xml_info->attributes[i])+MagickPathExtent;
2188 *source=(
char *) ResizeQuantumMemory(*source,*extent,
sizeof(**source));
2189 if (*source == (
char *) NULL)
2190 return((
char *) NULL);
2192 *length+=(size_t) FormatLocaleString(*source+(*length),*extent,
" %s=\"",
2193 xml_info->attributes[i]);
2194 (void) EncodePredefinedEntities(xml_info->attributes[i+1],-1,source,length,
2196 *length+=(size_t) FormatLocaleString(*source+(*length),*extent,
"\"");
2199 while ((attributes[i] != (
char **) NULL) &&
2200 (strcmp(attributes[i][0],xml_info->tag) != 0))
2203 while ((attributes[i] != (
char **) NULL) &&
2204 (attributes[i][j] != (
char *) NULL))
2206 if ((attributes[i][j+1] == (
char *) NULL) ||
2207 (GetXMLTreeAttribute(xml_info,attributes[i][j]) != attributes[i][j+1]))
2212 if ((*length+strlen(attributes[i][j])+MagickPathExtent) > *extent)
2214 *extent=(*length)+strlen(attributes[i][j])+MagickPathExtent;
2215 *source=(
char *) ResizeQuantumMemory(*source,*extent,
sizeof(**source));
2216 if (*source == (
char *) NULL)
2217 return((
char *) NULL);
2219 *length+=(size_t) FormatLocaleString(*source+(*length),*extent,
" %s=\"",
2221 (void) EncodePredefinedEntities(attributes[i][j+1],-1,source,length,extent,
2223 *length+=(size_t) FormatLocaleString(*source+(*length),*extent,
"\"");
2226 *length+=(size_t) FormatLocaleString(*source+(*length),*extent,
2227 *xml_info->content ?
">" :
"/>");
2229 *source=XMLTreeTagToXML(xml_info->child,source,length,extent,0,attributes);
2231 *source=EncodePredefinedEntities(xml_info->content,-1,source,length,extent,
2233 if ((*length+strlen(xml_info->tag)+MagickPathExtent) > *extent)
2235 *extent=(*length)+strlen(xml_info->tag)+MagickPathExtent;
2236 *source=(
char *) ResizeQuantumMemory(*source,*extent,
sizeof(**source));
2237 if (*source == (
char *) NULL)
2238 return((
char *) NULL);
2240 if (*xml_info->content !=
'\0')
2241 *length+=(size_t) FormatLocaleString(*source+(*length),*extent,
"</%s>",
2243 while ((offset < xml_info->offset) && (content[offset] !=
'\0'))
2246 content=XMLTreeTagToXML(xml_info->ordered,source,length,extent,offset,
2249 content=EncodePredefinedEntities(content+offset,-1,source,length,extent,
2254MagickExport
char *XMLTreeInfoToXML(
XMLTreeInfo *xml_info)
2278 assert((xml_info->signature == MagickCoreSignature) ||
2279 (((
XMLTreeRoot *) xml_info)->signature == MagickCoreSignature));
2280 if (IsEventLogging() != MagickFalse)
2281 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2282 if (xml_info->tag == (
char *) NULL)
2283 return((
char *) NULL);
2284 xml=AcquireString((
char *) NULL);
2286 extent=MagickPathExtent;
2290 parent=xml_info->parent;
2292 for (i=0; root->processing_instructions[i] != (
char **) NULL; i++)
2297 for (k=2; root->processing_instructions[i][k-1]; k++) ;
2298 p=root->processing_instructions[i][1];
2299 for (j=1; p != (
char *) NULL; j++)
2301 if (root->processing_instructions[i][k][j-1] ==
'>')
2303 p=root->processing_instructions[i][j];
2306 q=root->processing_instructions[i][0];
2307 if ((length+strlen(p)+strlen(q)+MagickPathExtent) > extent)
2309 extent=length+strlen(p)+strlen(q)+MagickPathExtent;
2310 xml=(
char *) ResizeQuantumMemory(xml,extent,
sizeof(*xml));
2311 if (xml == (
char *) NULL)
2314 length+=(size_t) FormatLocaleString(xml+length,extent,
"<?%s%s%s?>\n",q,
2315 *p !=
'\0' ?
" " :
"",p);
2316 p=root->processing_instructions[i][j];
2319 ordered=xml_info->ordered;
2322 xml=XMLTreeTagToXML(xml_info,&xml,&length,&extent,0,root->attributes);
2323 xml_info->parent=parent;
2324 xml_info->ordered=ordered;
2326 for (i=0; root->processing_instructions[i] != (
char **) NULL; i++)
2331 for (k=2; root->processing_instructions[i][k-1]; k++) ;
2332 p=root->processing_instructions[i][1];
2333 for (j=1; p != (
char *) NULL; j++)
2335 if (root->processing_instructions[i][k][j-1] ==
'<')
2337 p=root->processing_instructions[i][j];
2340 q=root->processing_instructions[i][0];
2341 if ((length+strlen(p)+strlen(q)+MagickPathExtent) > extent)
2343 extent=length+strlen(p)+strlen(q)+MagickPathExtent;
2344 xml=(
char *) ResizeQuantumMemory(xml,extent,
sizeof(*xml));
2345 if (xml == (
char *) NULL)
2348 length+=(size_t) FormatLocaleString(xml+length,extent,
"\n<?%s%s%s?>",q,
2349 *p !=
'\0' ?
" " :
"",p);
2350 p=root->processing_instructions[i][j];
2353 return((
char *) ResizeQuantumMemory(xml,length+1,
sizeof(*xml)));