ReactOS  0.4.15-dev-1647-g91fceab
entities.c
Go to the documentation of this file.
1 /*
2  * entities.c : implementation for the XML entities handling
3  *
4  * See Copyright for the status of this software.
5  *
6  * daniel@veillard.com
7  */
8 
9 /* To avoid EBCDIC trouble when parsing on zOS */
10 #if defined(__MVS__)
11 #pragma convert("ISO8859-1")
12 #endif
13 
14 #define IN_LIBXML
15 #include "libxml.h"
16 
17 #include <string.h>
18 #ifdef HAVE_STDLIB_H
19 #include <stdlib.h>
20 #endif
21 #include <libxml/xmlmemory.h>
22 #include <libxml/hash.h>
23 #include <libxml/entities.h>
24 #include <libxml/parser.h>
25 #include <libxml/parserInternals.h>
26 #include <libxml/xmlerror.h>
27 #include <libxml/globals.h>
28 #include <libxml/dict.h>
29 
30 #include "save.h"
31 
32 /*
33  * The XML predefined entities.
34  */
35 
38  NULL, NULL, NULL, NULL, NULL, NULL,
39  BAD_CAST "<", BAD_CAST "<", 1,
41  NULL, NULL, NULL, NULL, 0, 1
42 };
45  NULL, NULL, NULL, NULL, NULL, NULL,
46  BAD_CAST ">", BAD_CAST ">", 1,
48  NULL, NULL, NULL, NULL, 0, 1
49 };
52  NULL, NULL, NULL, NULL, NULL, NULL,
53  BAD_CAST "&", BAD_CAST "&", 1,
55  NULL, NULL, NULL, NULL, 0, 1
56 };
58  NULL, XML_ENTITY_DECL, BAD_CAST "quot",
59  NULL, NULL, NULL, NULL, NULL, NULL,
60  BAD_CAST "\"", BAD_CAST "\"", 1,
62  NULL, NULL, NULL, NULL, 0, 1
63 };
65  NULL, XML_ENTITY_DECL, BAD_CAST "apos",
66  NULL, NULL, NULL, NULL, NULL, NULL,
67  BAD_CAST "'", BAD_CAST "'", 1,
69  NULL, NULL, NULL, NULL, 0, 1
70 };
71 
78 static void
80 {
81  __xmlSimpleError(XML_FROM_TREE, XML_ERR_NO_MEMORY, NULL, NULL, extra);
82 }
83 
91 static void LIBXML_ATTR_FORMAT(2,0)
92 xmlEntitiesErr(xmlParserErrors code, const char *msg)
93 {
94  __xmlSimpleError(XML_FROM_TREE, code, NULL, msg, NULL);
95 }
96 
97 /*
98  * xmlFreeEntity : clean-up an entity record.
99  */
100 static void
101 xmlFreeEntity(xmlEntityPtr entity)
102 {
103  xmlDictPtr dict = NULL;
104 
105  if (entity == NULL)
106  return;
107 
108  if (entity->doc != NULL)
109  dict = entity->doc->dict;
110 
111 
112  if ((entity->children) && (entity->owner == 1) &&
113  (entity == (xmlEntityPtr) entity->children->parent))
114  xmlFreeNodeList(entity->children);
115  if (dict != NULL) {
116  if ((entity->name != NULL) && (!xmlDictOwns(dict, entity->name)))
117  xmlFree((char *) entity->name);
118  if ((entity->ExternalID != NULL) &&
119  (!xmlDictOwns(dict, entity->ExternalID)))
120  xmlFree((char *) entity->ExternalID);
121  if ((entity->SystemID != NULL) &&
122  (!xmlDictOwns(dict, entity->SystemID)))
123  xmlFree((char *) entity->SystemID);
124  if ((entity->URI != NULL) && (!xmlDictOwns(dict, entity->URI)))
125  xmlFree((char *) entity->URI);
126  if ((entity->content != NULL)
127  && (!xmlDictOwns(dict, entity->content)))
128  xmlFree((char *) entity->content);
129  if ((entity->orig != NULL) && (!xmlDictOwns(dict, entity->orig)))
130  xmlFree((char *) entity->orig);
131  } else {
132  if (entity->name != NULL)
133  xmlFree((char *) entity->name);
134  if (entity->ExternalID != NULL)
135  xmlFree((char *) entity->ExternalID);
136  if (entity->SystemID != NULL)
137  xmlFree((char *) entity->SystemID);
138  if (entity->URI != NULL)
139  xmlFree((char *) entity->URI);
140  if (entity->content != NULL)
141  xmlFree((char *) entity->content);
142  if (entity->orig != NULL)
143  xmlFree((char *) entity->orig);
144  }
145  xmlFree(entity);
146 }
147 
148 /*
149  * xmlCreateEntity:
150  *
151  * internal routine doing the entity node structures allocations
152  */
153 static xmlEntityPtr
154 xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type,
155  const xmlChar *ExternalID, const xmlChar *SystemID,
156  const xmlChar *content) {
158 
159  ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
160  if (ret == NULL) {
161  xmlEntitiesErrMemory("xmlCreateEntity: malloc failed");
162  return(NULL);
163  }
164  memset(ret, 0, sizeof(xmlEntity));
165  ret->type = XML_ENTITY_DECL;
166  ret->checked = 0;
167 
168  /*
169  * fill the structure.
170  */
171  ret->etype = (xmlEntityType) type;
172  if (dict == NULL) {
173  ret->name = xmlStrdup(name);
174  if (ExternalID != NULL)
175  ret->ExternalID = xmlStrdup(ExternalID);
176  if (SystemID != NULL)
177  ret->SystemID = xmlStrdup(SystemID);
178  } else {
179  ret->name = xmlDictLookup(dict, name, -1);
180  if (ExternalID != NULL)
181  ret->ExternalID = xmlDictLookup(dict, ExternalID, -1);
182  if (SystemID != NULL)
183  ret->SystemID = xmlDictLookup(dict, SystemID, -1);
184  }
185  if (content != NULL) {
186  ret->length = xmlStrlen(content);
187  if ((dict != NULL) && (ret->length < 5))
188  ret->content = (xmlChar *)
189  xmlDictLookup(dict, content, ret->length);
190  else
191  ret->content = xmlStrndup(content, ret->length);
192  } else {
193  ret->length = 0;
194  ret->content = NULL;
195  }
196  ret->URI = NULL; /* to be computed by the layer knowing
197  the defining entity */
198  ret->orig = NULL;
199  ret->owner = 0;
200 
201  return(ret);
202 }
203 
204 /*
205  * xmlAddEntity : register a new entity for an entities table.
206  */
207 static xmlEntityPtr
208 xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
209  const xmlChar *ExternalID, const xmlChar *SystemID,
210  const xmlChar *content) {
211  xmlDictPtr dict = NULL;
214 
215  if (name == NULL)
216  return(NULL);
217  if (dtd == NULL)
218  return(NULL);
219  if (dtd->doc != NULL)
220  dict = dtd->doc->dict;
221 
222  switch (type) {
226  if (dtd->entities == NULL)
227  dtd->entities = xmlHashCreateDict(0, dict);
228  table = dtd->entities;
229  break;
232  if (dtd->pentities == NULL)
233  dtd->pentities = xmlHashCreateDict(0, dict);
234  table = dtd->pentities;
235  break;
237  return(NULL);
238  }
239  if (table == NULL)
240  return(NULL);
241  ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content);
242  if (ret == NULL)
243  return(NULL);
244  ret->doc = dtd->doc;
245 
246  if (xmlHashAddEntry(table, name, ret)) {
247  /*
248  * entity was already defined at another level.
249  */
250  xmlFreeEntity(ret);
251  return(NULL);
252  }
253  return(ret);
254 }
255 
266  if (name == NULL) return(NULL);
267  switch (name[0]) {
268  case 'l':
269  if (xmlStrEqual(name, BAD_CAST "lt"))
270  return(&xmlEntityLt);
271  break;
272  case 'g':
273  if (xmlStrEqual(name, BAD_CAST "gt"))
274  return(&xmlEntityGt);
275  break;
276  case 'a':
277  if (xmlStrEqual(name, BAD_CAST "amp"))
278  return(&xmlEntityAmp);
279  if (xmlStrEqual(name, BAD_CAST "apos"))
280  return(&xmlEntityApos);
281  break;
282  case 'q':
283  if (xmlStrEqual(name, BAD_CAST "quot"))
284  return(&xmlEntityQuot);
285  break;
286  default:
287  break;
288  }
289  return(NULL);
290 }
291 
306 xmlAddDtdEntity(xmlDocPtr doc, const xmlChar *name, int type,
307  const xmlChar *ExternalID, const xmlChar *SystemID,
308  const xmlChar *content) {
310  xmlDtdPtr dtd;
311 
312  if (doc == NULL) {
313  xmlEntitiesErr(XML_DTD_NO_DOC,
314  "xmlAddDtdEntity: document is NULL");
315  return(NULL);
316  }
317  if (doc->extSubset == NULL) {
318  xmlEntitiesErr(XML_DTD_NO_DTD,
319  "xmlAddDtdEntity: document without external subset");
320  return(NULL);
321  }
322  dtd = doc->extSubset;
323  ret = xmlAddEntity(dtd, name, type, ExternalID, SystemID, content);
324  if (ret == NULL) return(NULL);
325 
326  /*
327  * Link it to the DTD
328  */
329  ret->parent = dtd;
330  ret->doc = dtd->doc;
331  if (dtd->last == NULL) {
332  dtd->children = dtd->last = (xmlNodePtr) ret;
333  } else {
334  dtd->last->next = (xmlNodePtr) ret;
335  ret->prev = dtd->last;
336  dtd->last = (xmlNodePtr) ret;
337  }
338  return(ret);
339 }
340 
355 xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type,
356  const xmlChar *ExternalID, const xmlChar *SystemID,
357  const xmlChar *content) {
359  xmlDtdPtr dtd;
360 
361  if (doc == NULL) {
362  xmlEntitiesErr(XML_DTD_NO_DOC,
363  "xmlAddDocEntity: document is NULL");
364  return(NULL);
365  }
366  if (doc->intSubset == NULL) {
367  xmlEntitiesErr(XML_DTD_NO_DTD,
368  "xmlAddDocEntity: document without internal subset");
369  return(NULL);
370  }
371  dtd = doc->intSubset;
372  ret = xmlAddEntity(dtd, name, type, ExternalID, SystemID, content);
373  if (ret == NULL) return(NULL);
374 
375  /*
376  * Link it to the DTD
377  */
378  ret->parent = dtd;
379  ret->doc = dtd->doc;
380  if (dtd->last == NULL) {
381  dtd->children = dtd->last = (xmlNodePtr) ret;
382  } else {
383  dtd->last->next = (xmlNodePtr) ret;
384  ret->prev = dtd->last;
385  dtd->last = (xmlNodePtr) ret;
386  }
387  return(ret);
388 }
389 
408 xmlNewEntity(xmlDocPtr doc, const xmlChar *name, int type,
409  const xmlChar *ExternalID, const xmlChar *SystemID,
410  const xmlChar *content) {
412  xmlDictPtr dict;
413 
414  if ((doc != NULL) && (doc->intSubset != NULL)) {
415  return(xmlAddDocEntity(doc, name, type, ExternalID, SystemID, content));
416  }
417  if (doc != NULL)
418  dict = doc->dict;
419  else
420  dict = NULL;
421  ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content);
422  if (ret == NULL)
423  return(NULL);
424  ret->doc = doc;
425  return(ret);
426 }
427 
439 static xmlEntityPtr
440 xmlGetEntityFromTable(xmlEntitiesTablePtr table, const xmlChar *name) {
441  return((xmlEntityPtr) xmlHashLookup(table, name));
442 }
443 
458 
459  if (doc == NULL)
460  return(NULL);
461  if ((doc->intSubset != NULL) && (doc->intSubset->pentities != NULL)) {
462  table = (xmlEntitiesTablePtr) doc->intSubset->pentities;
463  ret = xmlGetEntityFromTable(table, name);
464  if (ret != NULL)
465  return(ret);
466  }
467  if ((doc->extSubset != NULL) && (doc->extSubset->pentities != NULL)) {
468  table = (xmlEntitiesTablePtr) doc->extSubset->pentities;
469  return(xmlGetEntityFromTable(table, name));
470  }
471  return(NULL);
472 }
473 
486 xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) {
488 
489  if (doc == NULL)
490  return(NULL);
491  if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
492  table = (xmlEntitiesTablePtr) doc->extSubset->entities;
493  return(xmlGetEntityFromTable(table, name));
494  }
495  return(NULL);
496 }
497 
510 xmlGetDocEntity(const xmlDoc *doc, const xmlChar *name) {
513 
514  if (doc != NULL) {
515  if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
516  table = (xmlEntitiesTablePtr) doc->intSubset->entities;
517  cur = xmlGetEntityFromTable(table, name);
518  if (cur != NULL)
519  return(cur);
520  }
521  if (doc->standalone != 1) {
522  if ((doc->extSubset != NULL) &&
523  (doc->extSubset->entities != NULL)) {
524  table = (xmlEntitiesTablePtr) doc->extSubset->entities;
525  cur = xmlGetEntityFromTable(table, name);
526  if (cur != NULL)
527  return(cur);
528  }
529  }
530  }
531  return(xmlGetPredefinedEntity(name));
532 }
533 
534 /*
535  * Macro used to grow the current buffer.
536  */
537 #define growBufferReentrant() { \
538  xmlChar *tmp; \
539  size_t new_size = buffer_size * 2; \
540  if (new_size < buffer_size) goto mem_error; \
541  tmp = (xmlChar *) xmlRealloc(buffer, new_size); \
542  if (tmp == NULL) goto mem_error; \
543  buffer = tmp; \
544  buffer_size = new_size; \
545 }
546 
560 static xmlChar *
561 xmlEncodeEntitiesInternal(xmlDocPtr doc, const xmlChar *input, int attr) {
562  const xmlChar *cur = input;
563  xmlChar *buffer = NULL;
564  xmlChar *out = NULL;
565  size_t buffer_size = 0;
566  int html = 0;
567 
568  if (input == NULL) return(NULL);
569  if (doc != NULL)
570  html = (doc->type == XML_HTML_DOCUMENT_NODE);
571 
572  /*
573  * allocate an translation buffer.
574  */
575  buffer_size = 1000;
576  buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
577  if (buffer == NULL) {
578  xmlEntitiesErrMemory("xmlEncodeEntities: malloc failed");
579  return(NULL);
580  }
581  out = buffer;
582 
583  while (*cur != '\0') {
584  size_t indx = out - buffer;
585  if (indx + 100 > buffer_size) {
586 
588  out = &buffer[indx];
589  }
590 
591  /*
592  * By default one have to encode at least '<', '>', '"' and '&' !
593  */
594  if (*cur == '<') {
595  const xmlChar *end;
596 
597  /*
598  * Special handling of server side include in HTML attributes
599  */
600  if (html && attr &&
601  (cur[1] == '!') && (cur[2] == '-') && (cur[3] == '-') &&
602  ((end = xmlStrstr(cur, BAD_CAST "-->")) != NULL)) {
603  while (cur != end) {
604  *out++ = *cur++;
605  indx = out - buffer;
606  if (indx + 100 > buffer_size) {
608  out = &buffer[indx];
609  }
610  }
611  *out++ = *cur++;
612  *out++ = *cur++;
613  *out++ = *cur++;
614  continue;
615  }
616  *out++ = '&';
617  *out++ = 'l';
618  *out++ = 't';
619  *out++ = ';';
620  } else if (*cur == '>') {
621  *out++ = '&';
622  *out++ = 'g';
623  *out++ = 't';
624  *out++ = ';';
625  } else if (*cur == '&') {
626  /*
627  * Special handling of &{...} construct from HTML 4, see
628  * http://www.w3.org/TR/html401/appendix/notes.html#h-B.7.1
629  */
630  if (html && attr && (cur[1] == '{') &&
631  (strchr((const char *) cur, '}'))) {
632  while (*cur != '}') {
633  *out++ = *cur++;
634  indx = out - buffer;
635  if (indx + 100 > buffer_size) {
637  out = &buffer[indx];
638  }
639  }
640  *out++ = *cur++;
641  continue;
642  }
643  *out++ = '&';
644  *out++ = 'a';
645  *out++ = 'm';
646  *out++ = 'p';
647  *out++ = ';';
648  } else if (((*cur >= 0x20) && (*cur < 0x80)) ||
649  (*cur == '\n') || (*cur == '\t') || ((html) && (*cur == '\r'))) {
650  /*
651  * default case, just copy !
652  */
653  *out++ = *cur;
654  } else if (*cur >= 0x80) {
655  if (((doc != NULL) && (doc->encoding != NULL)) || (html)) {
656  /*
657  * Bjørn Reese <br@sseusa.com> provided the patch
658  xmlChar xc;
659  xc = (*cur & 0x3F) << 6;
660  if (cur[1] != 0) {
661  xc += *(++cur) & 0x3F;
662  *out++ = xc;
663  } else
664  */
665  *out++ = *cur;
666  } else {
667  /*
668  * We assume we have UTF-8 input.
669  */
670  char buf[11], *ptr;
671  int val = 0, l = 1;
672 
673  if (*cur < 0xC0) {
674  xmlEntitiesErr(XML_CHECK_NOT_UTF8,
675  "xmlEncodeEntities: input not UTF-8");
676  if (doc != NULL)
677  doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
678  snprintf(buf, sizeof(buf), "&#%d;", *cur);
679  buf[sizeof(buf) - 1] = 0;
680  ptr = buf;
681  while (*ptr != 0) *out++ = *ptr++;
682  cur++;
683  continue;
684  } else if (*cur < 0xE0) {
685  val = (cur[0]) & 0x1F;
686  val <<= 6;
687  val |= (cur[1]) & 0x3F;
688  l = 2;
689  } else if (*cur < 0xF0) {
690  val = (cur[0]) & 0x0F;
691  val <<= 6;
692  val |= (cur[1]) & 0x3F;
693  val <<= 6;
694  val |= (cur[2]) & 0x3F;
695  l = 3;
696  } else if (*cur < 0xF8) {
697  val = (cur[0]) & 0x07;
698  val <<= 6;
699  val |= (cur[1]) & 0x3F;
700  val <<= 6;
701  val |= (cur[2]) & 0x3F;
702  val <<= 6;
703  val |= (cur[3]) & 0x3F;
704  l = 4;
705  }
706  if ((l == 1) || (!IS_CHAR(val))) {
707  xmlEntitiesErr(XML_ERR_INVALID_CHAR,
708  "xmlEncodeEntities: char out of range\n");
709  if (doc != NULL)
710  doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
711  snprintf(buf, sizeof(buf), "&#%d;", *cur);
712  buf[sizeof(buf) - 1] = 0;
713  ptr = buf;
714  while (*ptr != 0) *out++ = *ptr++;
715  cur++;
716  continue;
717  }
718  /*
719  * We could do multiple things here. Just save as a char ref
720  */
721  snprintf(buf, sizeof(buf), "&#x%X;", val);
722  buf[sizeof(buf) - 1] = 0;
723  ptr = buf;
724  while (*ptr != 0) *out++ = *ptr++;
725  cur += l;
726  continue;
727  }
728  } else if (IS_BYTE_CHAR(*cur)) {
729  char buf[11], *ptr;
730 
731  snprintf(buf, sizeof(buf), "&#%d;", *cur);
732  buf[sizeof(buf) - 1] = 0;
733  ptr = buf;
734  while (*ptr != 0) *out++ = *ptr++;
735  }
736  cur++;
737  }
738  *out = 0;
739  return(buffer);
740 
741 mem_error:
742  xmlEntitiesErrMemory("xmlEncodeEntities: realloc failed");
743  xmlFree(buffer);
744  return(NULL);
745 }
746 
758 xmlChar *
760  return xmlEncodeEntitiesInternal(doc, input, 1);
761 }
762 
775 xmlChar *
777  return xmlEncodeEntitiesInternal(doc, input, 0);
778 }
779 
790 xmlChar *
792  const xmlChar *cur = input;
793  xmlChar *buffer = NULL;
794  xmlChar *out = NULL;
795  size_t buffer_size = 0;
796  if (input == NULL) return(NULL);
797 
798  /*
799  * allocate an translation buffer.
800  */
801  buffer_size = 1000;
802  buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
803  if (buffer == NULL) {
804  xmlEntitiesErrMemory("xmlEncodeSpecialChars: malloc failed");
805  return(NULL);
806  }
807  out = buffer;
808 
809  while (*cur != '\0') {
810  size_t indx = out - buffer;
811  if (indx + 10 > buffer_size) {
812 
814  out = &buffer[indx];
815  }
816 
817  /*
818  * By default one have to encode at least '<', '>', '"' and '&' !
819  */
820  if (*cur == '<') {
821  *out++ = '&';
822  *out++ = 'l';
823  *out++ = 't';
824  *out++ = ';';
825  } else if (*cur == '>') {
826  *out++ = '&';
827  *out++ = 'g';
828  *out++ = 't';
829  *out++ = ';';
830  } else if (*cur == '&') {
831  *out++ = '&';
832  *out++ = 'a';
833  *out++ = 'm';
834  *out++ = 'p';
835  *out++ = ';';
836  } else if (*cur == '"') {
837  *out++ = '&';
838  *out++ = 'q';
839  *out++ = 'u';
840  *out++ = 'o';
841  *out++ = 't';
842  *out++ = ';';
843  } else if (*cur == '\r') {
844  *out++ = '&';
845  *out++ = '#';
846  *out++ = '1';
847  *out++ = '3';
848  *out++ = ';';
849  } else {
850  /*
851  * Works because on UTF-8, all extended sequences cannot
852  * result in bytes in the ASCII range.
853  */
854  *out++ = *cur;
855  }
856  cur++;
857  }
858  *out = 0;
859  return(buffer);
860 
861 mem_error:
862  xmlEntitiesErrMemory("xmlEncodeSpecialChars: realloc failed");
863  xmlFree(buffer);
864  return(NULL);
865 }
866 
877  return((xmlEntitiesTablePtr) xmlHashCreate(0));
878 }
879 
887 static void
888 xmlFreeEntityWrapper(void *entity, const xmlChar *name ATTRIBUTE_UNUSED) {
889  if (entity != NULL)
890  xmlFreeEntity((xmlEntityPtr) entity);
891 }
892 
899 void
901  xmlHashFree(table, xmlFreeEntityWrapper);
902 }
903 
904 #ifdef LIBXML_TREE_ENABLED
905 
913 static void *
914 xmlCopyEntity(void *payload, const xmlChar *name ATTRIBUTE_UNUSED) {
915  xmlEntityPtr ent = (xmlEntityPtr) payload;
917 
918  cur = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
919  if (cur == NULL) {
920  xmlEntitiesErrMemory("xmlCopyEntity:: malloc failed");
921  return(NULL);
922  }
923  memset(cur, 0, sizeof(xmlEntity));
924  cur->type = XML_ENTITY_DECL;
925 
926  cur->etype = ent->etype;
927  if (ent->name != NULL)
928  cur->name = xmlStrdup(ent->name);
929  if (ent->ExternalID != NULL)
930  cur->ExternalID = xmlStrdup(ent->ExternalID);
931  if (ent->SystemID != NULL)
932  cur->SystemID = xmlStrdup(ent->SystemID);
933  if (ent->content != NULL)
934  cur->content = xmlStrdup(ent->content);
935  if (ent->orig != NULL)
936  cur->orig = xmlStrdup(ent->orig);
937  if (ent->URI != NULL)
938  cur->URI = xmlStrdup(ent->URI);
939  return(cur);
940 }
941 
951 xmlCopyEntitiesTable(xmlEntitiesTablePtr table) {
952  return(xmlHashCopy(table, xmlCopyEntity));
953 }
954 #endif /* LIBXML_TREE_ENABLED */
955 
956 #ifdef LIBXML_OUTPUT_ENABLED
957 
966 static void
967 xmlDumpEntityContent(xmlBufferPtr buf, const xmlChar *content) {
968  if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return;
969  if (xmlStrchr(content, '%')) {
970  const xmlChar * base, *cur;
971 
972  xmlBufferCCat(buf, "\"");
973  base = cur = content;
974  while (*cur != 0) {
975  if (*cur == '"') {
976  if (base != cur)
978  xmlBufferAdd(buf, BAD_CAST "&quot;", 6);
979  cur++;
980  base = cur;
981  } else if (*cur == '%') {
982  if (base != cur)
984  xmlBufferAdd(buf, BAD_CAST "&#x25;", 6);
985  cur++;
986  base = cur;
987  } else {
988  cur++;
989  }
990  }
991  if (base != cur)
993  xmlBufferCCat(buf, "\"");
994  } else {
996  }
997 }
998 
1006 void
1007 xmlDumpEntityDecl(xmlBufferPtr buf, xmlEntityPtr ent) {
1008  if ((buf == NULL) || (ent == NULL)) return;
1009  switch (ent->etype) {
1011  xmlBufferWriteChar(buf, "<!ENTITY ");
1012  xmlBufferWriteCHAR(buf, ent->name);
1013  xmlBufferWriteChar(buf, " ");
1014  if (ent->orig != NULL)
1016  else
1017  xmlDumpEntityContent(buf, ent->content);
1018  xmlBufferWriteChar(buf, ">\n");
1019  break;
1021  xmlBufferWriteChar(buf, "<!ENTITY ");
1022  xmlBufferWriteCHAR(buf, ent->name);
1023  if (ent->ExternalID != NULL) {
1024  xmlBufferWriteChar(buf, " PUBLIC ");
1026  xmlBufferWriteChar(buf, " ");
1028  } else {
1029  xmlBufferWriteChar(buf, " SYSTEM ");
1031  }
1032  xmlBufferWriteChar(buf, ">\n");
1033  break;
1035  xmlBufferWriteChar(buf, "<!ENTITY ");
1036  xmlBufferWriteCHAR(buf, ent->name);
1037  if (ent->ExternalID != NULL) {
1038  xmlBufferWriteChar(buf, " PUBLIC ");
1040  xmlBufferWriteChar(buf, " ");
1042  } else {
1043  xmlBufferWriteChar(buf, " SYSTEM ");
1045  }
1046  if (ent->content != NULL) { /* Should be true ! */
1047  xmlBufferWriteChar(buf, " NDATA ");
1048  if (ent->orig != NULL)
1049  xmlBufferWriteCHAR(buf, ent->orig);
1050  else
1052  }
1053  xmlBufferWriteChar(buf, ">\n");
1054  break;
1056  xmlBufferWriteChar(buf, "<!ENTITY % ");
1057  xmlBufferWriteCHAR(buf, ent->name);
1058  xmlBufferWriteChar(buf, " ");
1059  if (ent->orig == NULL)
1060  xmlDumpEntityContent(buf, ent->content);
1061  else
1063  xmlBufferWriteChar(buf, ">\n");
1064  break;
1066  xmlBufferWriteChar(buf, "<!ENTITY % ");
1067  xmlBufferWriteCHAR(buf, ent->name);
1068  if (ent->ExternalID != NULL) {
1069  xmlBufferWriteChar(buf, " PUBLIC ");
1071  xmlBufferWriteChar(buf, " ");
1073  } else {
1074  xmlBufferWriteChar(buf, " SYSTEM ");
1076  }
1077  xmlBufferWriteChar(buf, ">\n");
1078  break;
1079  default:
1080  xmlEntitiesErr(XML_DTD_UNKNOWN_ENTITY,
1081  "xmlDumpEntitiesDecl: internal: unknown type entity type");
1082  }
1083 }
1084 
1092 static void
1093 xmlDumpEntityDeclScan(void *ent, void *buf,
1094  const xmlChar *name ATTRIBUTE_UNUSED) {
1095  xmlDumpEntityDecl((xmlBufferPtr) buf, (xmlEntityPtr) ent);
1096 }
1097 
1105 void
1106 xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) {
1107  xmlHashScan(table, xmlDumpEntityDeclScan, buf);
1108 }
1109 #endif /* LIBXML_OUTPUT_ENABLED */
1110 #define bottom_entities
1111 #include "elfgcchack.h"
xmlEntityType etype
Definition: entities.h:52
XMLPUBFUN xmlChar *XMLCALL xmlEncodeSpecialChars(const xmlDoc *doc, const xmlChar *input)
xmlElementType type
Definition: tree.h:553
XMLPUBFUN xmlHashTablePtr XMLCALL xmlHashCopy(xmlHashTablePtr table, xmlHashCopier f)
Definition: hash.c:997
XMLPUBFUN const xmlChar *XMLCALL xmlStrstr(const xmlChar *str, const xmlChar *val)
Definition: xmlstring.c:341
static void xmlEntitiesErrMemory(const char *extra)
Definition: entities.c:79
static xmlEntity xmlEntityAmp
Definition: entities.c:50
static xmlEntity xmlEntityGt
Definition: entities.c:43
XMLPUBFUN void XMLCALL xmlHashScan(xmlHashTablePtr table, xmlHashScanner f, void *data)
Definition: hash.c:864
const xmlChar * SystemID
Definition: entities.h:54
struct _xmlDtd * intSubset
Definition: tree.h:570
XMLPUBFUN xmlEntitiesTablePtr XMLCALL xmlCreateEntitiesTable(void)
struct _xmlDoc * doc
Definition: tree.h:415
XMLPUBFUN xmlChar *XMLCALL xmlStrndup(const xmlChar *cur, int len)
Definition: xmlstring.c:41
XMLPUBFUN void XMLCALL xmlFreeNodeList(xmlNodePtr cur)
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
XMLPUBFUN void XMLCALL xmlBufferWriteCHAR(xmlBufferPtr buf, const xmlChar *string)
#define snprintf
Definition: wintirpc.h:48
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glext.h:5644
GLuint buffer
Definition: glext.h:5915
XMLPUBFUN int XMLCALL xmlHashAddEntry(xmlHashTablePtr table, const xmlChar *name, void *userdata)
Definition: hash.c:394
xmlChar * xmlEncodeAttributeEntities(xmlDocPtr doc, const xmlChar *input)
XMLPUBFUN xmlChar *XMLCALL xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input)
XMLPUBFUN const xmlChar *XMLCALL xmlStrchr(const xmlChar *str, xmlChar val)
Definition: xmlstring.c:321
const xmlChar * URI
Definition: entities.h:57
Definition: tree.h:406
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
XMLPUBFUN int XMLCALL xmlBufferCCat(xmlBufferPtr buf, const char *str)
XMLPUBFUN void XMLCALL xmlBufferWriteQuotedString(xmlBufferPtr buf, const xmlChar *string)
Definition: actctx.c:387
WCHAR * name
Definition: actctx.c:405
XMLPUBFUN void XMLCALL xmlHashFree(xmlHashTablePtr table, xmlHashDeallocator f)
Definition: hash.c:327
XMLPUBFUN xmlEntityPtr XMLCALL xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name)
XMLPUBFUN xmlEntityPtr XMLCALL xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name)
int standalone
Definition: tree.h:564
static xmlEntity xmlEntityApos
Definition: entities.c:64
GLuint base
Definition: 3dtext.c:35
static xmlEntity xmlEntityLt
Definition: entities.c:36
xmlChar * orig
Definition: entities.h:49
#define IS_CHAR(c)
static PVOID ptr
Definition: dispmode.c:27
content
Definition: atl_ax.c:993
static void buffer_size(GLcontext *ctx, GLuint *width, GLuint *height)
Definition: swimpl.c:888
xmlNode * xmlNodePtr
Definition: tree.h:488
#define BAD_CAST
Definition: xmlstring.h:35
Definition: dict.c:116
GLuint GLfloat * val
Definition: glext.h:7180
r l[0]
Definition: byte_order.h:167
XMLPUBFUN xmlEntityPtr XMLCALL xmlNewEntity(xmlDocPtr doc, const xmlChar *name, int type, const xmlChar *ExternalID, const xmlChar *SystemID, const xmlChar *content)
#define LIBXML_ATTR_FORMAT(fmt, args)
Definition: xmlversion.h:477
XMLPUBFUN xmlEntityPtr XMLCALL xmlAddDtdEntity(xmlDocPtr doc, const xmlChar *name, int type, const xmlChar *ExternalID, const xmlChar *SystemID, const xmlChar *content)
Definition: id3.c:95
xmlParserErrors
Definition: xmlerror.h:99
static xmlEntity xmlEntityQuot
Definition: entities.c:57
XMLPUBFUN int XMLCALL xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len)
XMLPUBFUN xmlEntityPtr XMLCALL xmlGetPredefinedEntity(const xmlChar *name)
#define IS_BYTE_CHAR(c)
static FILE * out
Definition: regtests2xml.c:44
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
struct _xmlNode * last
Definition: tree.h:411
XMLPUBFUN const xmlChar *XMLCALL xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len)
Definition: dict.c:865
Definition: cookie.c:201
const xmlChar * name
Definition: entities.h:41
XMLPUBFUN xmlHashTablePtr XMLCALL xmlHashCreate(int size)
Definition: hash.c:181
void * entities
Definition: tree.h:421
GLuint GLuint end
Definition: gl.h:1545
XMLPUBFUN xmlEntityPtr XMLCALL xmlGetDocEntity(const xmlDoc *doc, const xmlChar *name)
const xmlChar * ExternalID
Definition: entities.h:53
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
Definition: inflate.c:139
const xmlChar * encoding
Definition: tree.h:574
xmlEntitiesTable * xmlEntitiesTablePtr
Definition: entities.h:71
FxCollectionEntry * cur
struct _xmlNode * children
Definition: tree.h:410
GLenum GLenum GLenum input
Definition: glext.h:9031
XMLPUBFUN xmlEntityPtr XMLCALL xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type, const xmlChar *ExternalID, const xmlChar *SystemID, const xmlChar *content)
XMLPUBFUN int XMLCALL xmlDictOwns(xmlDictPtr dict, const xmlChar *str)
Definition: dict.c:1218
#define ATTRIBUTE_UNUSED
Definition: win32config.h:132
XMLPUBFUN xmlHashTablePtr XMLCALL xmlHashCreateDict(int size, xmlDictPtr dict)
Definition: hash.c:215
#define NULL
Definition: types.h:112
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
Definition: tree.h:551
xmlChar * content
Definition: entities.h:50
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define msg(x)
Definition: auth_time.c:54
struct _xmlDtd * extSubset
Definition: tree.h:571
Definition: name.c:38
#define const
Definition: zconf.h:230
XMLPUBFUN void *XMLCALL xmlHashLookup(xmlHashTablePtr table, const xmlChar *name)
Definition: hash.c:466
#define growBufferReentrant()
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
#define memset(x, y, z)
Definition: compat.h:39
xmlEntity * xmlEntityPtr
Definition: tree.h:49
void * pentities
Definition: tree.h:424
struct _xmlDict * dict
Definition: tree.h:580
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66
xmlEntityType
Definition: entities.h:24
XMLPUBFUN void XMLCALL xmlBufferWriteChar(xmlBufferPtr buf, const char *string)
XMLPUBFUN void XMLCALL xmlFreeEntitiesTable(xmlEntitiesTablePtr table)