Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: third_party/libxml/src/entities.c

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no iconv Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libxml/src/encoding.c ('k') | third_party/libxml/src/error.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * entities.c : implementation for the XML entities handling 2 * entities.c : implementation for the XML entities handling
3 * 3 *
4 * See Copyright for the status of this software. 4 * See Copyright for the status of this software.
5 * 5 *
6 * daniel@veillard.com 6 * daniel@veillard.com
7 */ 7 */
8 8
9 #define IN_LIBXML 9 #define IN_LIBXML
10 #include "libxml.h" 10 #include "libxml.h"
11 11
12 #include <string.h> 12 #include <string.h>
13 #ifdef HAVE_STDLIB_H 13 #ifdef HAVE_STDLIB_H
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #endif 15 #endif
16 #include <libxml/xmlmemory.h> 16 #include <libxml/xmlmemory.h>
17 #include <libxml/hash.h> 17 #include <libxml/hash.h>
18 #include <libxml/entities.h> 18 #include <libxml/entities.h>
19 #include <libxml/parser.h> 19 #include <libxml/parser.h>
20 #include <libxml/parserInternals.h> 20 #include <libxml/parserInternals.h>
21 #include <libxml/xmlerror.h> 21 #include <libxml/xmlerror.h>
22 #include <libxml/globals.h> 22 #include <libxml/globals.h>
23 #include <libxml/dict.h> 23 #include <libxml/dict.h>
24 24
25 #include "save.h"
26
25 /* 27 /*
26 * The XML predefined entities. 28 * The XML predefined entities.
27 */ 29 */
28 30
29 static xmlEntity xmlEntityLt = { 31 static xmlEntity xmlEntityLt = {
30 NULL, XML_ENTITY_DECL, BAD_CAST "lt", 32 NULL, XML_ENTITY_DECL, BAD_CAST "lt",
31 NULL, NULL, NULL, NULL, NULL, NULL, 33 NULL, NULL, NULL, NULL, NULL, NULL,
32 BAD_CAST "<", BAD_CAST "<", 1, 34 BAD_CAST "<", BAD_CAST "<", 1,
33 XML_INTERNAL_PREDEFINED_ENTITY, 35 XML_INTERNAL_PREDEFINED_ENTITY,
34 NULL, NULL, NULL, NULL, 0, 1 36 NULL, NULL, NULL, NULL, 0, 1
35 }; 37 };
36 static xmlEntity xmlEntityGt = { 38 static xmlEntity xmlEntityGt = {
37 NULL, XML_ENTITY_DECL, BAD_CAST "gt", 39 NULL, XML_ENTITY_DECL, BAD_CAST "gt",
38 NULL, NULL, NULL, NULL, NULL, NULL, 40 NULL, NULL, NULL, NULL, NULL, NULL,
39 BAD_CAST ">", BAD_CAST ">", 1, 41 BAD_CAST ">", BAD_CAST ">", 1,
40 XML_INTERNAL_PREDEFINED_ENTITY, 42 XML_INTERNAL_PREDEFINED_ENTITY,
41 NULL, NULL, NULL, NULL, 0, 1 43 NULL, NULL, NULL, NULL, 0, 1
42 }; 44 };
43 static xmlEntity xmlEntityAmp = { 45 static xmlEntity xmlEntityAmp = {
44 NULL, XML_ENTITY_DECL, BAD_CAST "amp", 46 NULL, XML_ENTITY_DECL, BAD_CAST "amp",
45 NULL, NULL, NULL, NULL, NULL, NULL, 47 NULL, NULL, NULL, NULL, NULL, NULL,
46 BAD_CAST "&", BAD_CAST "&", 1, 48 BAD_CAST "&", BAD_CAST "&", 1,
47 XML_INTERNAL_PREDEFINED_ENTITY, 49 XML_INTERNAL_PREDEFINED_ENTITY,
48 NULL, NULL, NULL, NULL, 0, 1 50 NULL, NULL, NULL, NULL, 0, 1
49 }; 51 };
50 static xmlEntity xmlEntityQuot = { 52 static xmlEntity xmlEntityQuot = {
51 NULL, XML_ENTITY_DECL, BAD_CAST "quot", 53 NULL, XML_ENTITY_DECL, BAD_CAST "quot",
52 NULL, NULL, NULL, NULL, NULL, NULL, 54 NULL, NULL, NULL, NULL, NULL, NULL,
53 BAD_CAST "\"", BAD_CAST "\"", 1, 55 BAD_CAST "\"", BAD_CAST "\"", 1,
54 XML_INTERNAL_PREDEFINED_ENTITY, 56 XML_INTERNAL_PREDEFINED_ENTITY,
55 NULL, NULL, NULL, NULL, 0, 1 57 NULL, NULL, NULL, NULL, 0, 1
56 }; 58 };
57 static xmlEntity xmlEntityApos = { 59 static xmlEntity xmlEntityApos = {
58 NULL, XML_ENTITY_DECL, BAD_CAST "apos", 60 NULL, XML_ENTITY_DECL, BAD_CAST "apos",
59 NULL, NULL, NULL, NULL, NULL, NULL, 61 NULL, NULL, NULL, NULL, NULL, NULL,
60 BAD_CAST "'", BAD_CAST "'", 1, 62 BAD_CAST "'", BAD_CAST "'", 1,
61 XML_INTERNAL_PREDEFINED_ENTITY, 63 XML_INTERNAL_PREDEFINED_ENTITY,
62 NULL, NULL, NULL, NULL, 0, 1 64 NULL, NULL, NULL, NULL, 0, 1
63 }; 65 };
64 66
65 /** 67 /**
66 * xmlEntitiesErrMemory: 68 * xmlEntitiesErrMemory:
67 * @extra: extra informations 69 * @extra: extra informations
68 * 70 *
69 * Handle an out of memory condition 71 * Handle an out of memory condition
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 421 }
420 422
421 /** 423 /**
422 * xmlGetEntityFromTable: 424 * xmlGetEntityFromTable:
423 * @table: an entity table 425 * @table: an entity table
424 * @name: the entity name 426 * @name: the entity name
425 * @parameter: look for parameter entities 427 * @parameter: look for parameter entities
426 * 428 *
427 * Do an entity lookup in the table. 429 * Do an entity lookup in the table.
428 * returns the corresponding parameter entity, if found. 430 * returns the corresponding parameter entity, if found.
429 * 431 *
430 * Returns A pointer to the entity structure or NULL if not found. 432 * Returns A pointer to the entity structure or NULL if not found.
431 */ 433 */
432 static xmlEntityPtr 434 static xmlEntityPtr
433 xmlGetEntityFromTable(xmlEntitiesTablePtr table, const xmlChar *name) { 435 xmlGetEntityFromTable(xmlEntitiesTablePtr table, const xmlChar *name) {
434 return((xmlEntityPtr) xmlHashLookup(table, name)); 436 return((xmlEntityPtr) xmlHashLookup(table, name));
435 } 437 }
436 438
437 /** 439 /**
438 * xmlGetParameterEntity: 440 * xmlGetParameterEntity:
439 * @doc: the document referencing the entity 441 * @doc: the document referencing the entity
440 * @name: the entity name 442 * @name: the entity name
441 * 443 *
442 * Do an entity lookup in the internal and external subsets and 444 * Do an entity lookup in the internal and external subsets and
443 * returns the corresponding parameter entity, if found. 445 * returns the corresponding parameter entity, if found.
444 * 446 *
445 * Returns A pointer to the entity structure or NULL if not found. 447 * Returns A pointer to the entity structure or NULL if not found.
446 */ 448 */
447 xmlEntityPtr 449 xmlEntityPtr
448 xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name) { 450 xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name) {
449 xmlEntitiesTablePtr table; 451 xmlEntitiesTablePtr table;
450 xmlEntityPtr ret; 452 xmlEntityPtr ret;
451 453
452 if (doc == NULL) 454 if (doc == NULL)
453 return(NULL); 455 return(NULL);
454 if ((doc->intSubset != NULL) && (doc->intSubset->pentities != NULL)) { 456 if ((doc->intSubset != NULL) && (doc->intSubset->pentities != NULL)) {
(...skipping 10 matching lines...) Expand all
465 } 467 }
466 468
467 /** 469 /**
468 * xmlGetDtdEntity: 470 * xmlGetDtdEntity:
469 * @doc: the document referencing the entity 471 * @doc: the document referencing the entity
470 * @name: the entity name 472 * @name: the entity name
471 * 473 *
472 * Do an entity lookup in the DTD entity hash table and 474 * Do an entity lookup in the DTD entity hash table and
473 * returns the corresponding entity, if found. 475 * returns the corresponding entity, if found.
474 * Note: the first argument is the document node, not the DTD node. 476 * Note: the first argument is the document node, not the DTD node.
475 * 477 *
476 * Returns A pointer to the entity structure or NULL if not found. 478 * Returns A pointer to the entity structure or NULL if not found.
477 */ 479 */
478 xmlEntityPtr 480 xmlEntityPtr
479 xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) { 481 xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) {
480 xmlEntitiesTablePtr table; 482 xmlEntitiesTablePtr table;
481 483
482 if (doc == NULL) 484 if (doc == NULL)
483 return(NULL); 485 return(NULL);
484 if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) { 486 if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) {
485 table = (xmlEntitiesTablePtr) doc->extSubset->entities; 487 table = (xmlEntitiesTablePtr) doc->extSubset->entities;
486 return(xmlGetEntityFromTable(table, name)); 488 return(xmlGetEntityFromTable(table, name));
487 } 489 }
488 return(NULL); 490 return(NULL);
489 } 491 }
490 492
491 /** 493 /**
492 * xmlGetDocEntity: 494 * xmlGetDocEntity:
493 * @doc: the document referencing the entity 495 * @doc: the document referencing the entity
494 * @name: the entity name 496 * @name: the entity name
495 * 497 *
496 * Do an entity lookup in the document entity hash table and 498 * Do an entity lookup in the document entity hash table and
497 * returns the corresponding entity, otherwise a lookup is done 499 * returns the corresponding entity, otherwise a lookup is done
498 * in the predefined entities too. 500 * in the predefined entities too.
499 * 501 *
500 * Returns A pointer to the entity structure or NULL if not found. 502 * Returns A pointer to the entity structure or NULL if not found.
501 */ 503 */
502 xmlEntityPtr 504 xmlEntityPtr
503 xmlGetDocEntity(xmlDocPtr doc, const xmlChar *name) { 505 xmlGetDocEntity(const xmlDoc *doc, const xmlChar *name) {
504 xmlEntityPtr cur; 506 xmlEntityPtr cur;
505 xmlEntitiesTablePtr table; 507 xmlEntitiesTablePtr table;
506 508
507 if (doc != NULL) { 509 if (doc != NULL) {
508 if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) { 510 if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) {
509 table = (xmlEntitiesTablePtr) doc->intSubset->entities; 511 table = (xmlEntitiesTablePtr) doc->intSubset->entities;
510 cur = xmlGetEntityFromTable(table, name); 512 cur = xmlGetEntityFromTable(table, name);
511 if (cur != NULL) 513 if (cur != NULL)
512 return(cur); 514 return(cur);
513 } 515 }
514 if (doc->standalone != 1) { 516 if (doc->standalone != 1) {
515 if ((doc->extSubset != NULL) && 517 if ((doc->extSubset != NULL) &&
516 (doc->extSubset->entities != NULL)) { 518 (doc->extSubset->entities != NULL)) {
517 table = (xmlEntitiesTablePtr) doc->extSubset->entities; 519 table = (xmlEntitiesTablePtr) doc->extSubset->entities;
518 cur = xmlGetEntityFromTable(table, name); 520 cur = xmlGetEntityFromTable(table, name);
519 if (cur != NULL) 521 if (cur != NULL)
520 return(cur); 522 return(cur);
521 } 523 }
522 } 524 }
523 } 525 }
524 return(xmlGetPredefinedEntity(name)); 526 return(xmlGetPredefinedEntity(name));
525 } 527 }
526 528
527 /* 529 /*
528 * Macro used to grow the current buffer. 530 * Macro used to grow the current buffer.
529 */ 531 */
530 #define growBufferReentrant() { \ 532 #define growBufferReentrant() { \
531 buffer_size *= 2;» » » » » » » \ 533 xmlChar *tmp; \
532 buffer = (xmlChar *)» » » » » » \ 534 size_t new_size = buffer_size * 2; \
533 » » xmlRealloc(buffer, buffer_size * sizeof(xmlChar));» \ 535 if (new_size < buffer_size) goto mem_error; \
534 if (buffer == NULL) {» » » » » » \ 536 tmp = (xmlChar *) xmlRealloc(buffer, new_size);» \
535 xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: realloc failed");\ 537 if (tmp == NULL) goto mem_error; \
536 » return(NULL);» » » » » » » \ 538 buffer = tmp;» » » » » » » \
537 }» » » » » » » » » \ 539 buffer_size = new_size;» » » » » » \
538 } 540 }
539 541
540
541 /** 542 /**
542 * xmlEncodeEntitiesReentrant: 543 * xmlEncodeEntitiesInternal:
543 * @doc: the document containing the string 544 * @doc: the document containing the string
544 * @input: A string to convert to XML. 545 * @input: A string to convert to XML.
546 * @attr: are we handling an atrbute value
545 * 547 *
546 * Do a global encoding of a string, replacing the predefined entities 548 * Do a global encoding of a string, replacing the predefined entities
547 * and non ASCII values with their entities and CharRef counterparts. 549 * and non ASCII values with their entities and CharRef counterparts.
548 * Contrary to xmlEncodeEntities, this routine is reentrant, and result 550 * Contrary to xmlEncodeEntities, this routine is reentrant, and result
549 * must be deallocated. 551 * must be deallocated.
550 * 552 *
551 * Returns A newly allocated string with the substitution done. 553 * Returns A newly allocated string with the substitution done.
552 */ 554 */
553 xmlChar * 555 static xmlChar *
554 xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { 556 xmlEncodeEntitiesInternal(xmlDocPtr doc, const xmlChar *input, int attr) {
555 const xmlChar *cur = input; 557 const xmlChar *cur = input;
556 xmlChar *buffer = NULL; 558 xmlChar *buffer = NULL;
557 xmlChar *out = NULL; 559 xmlChar *out = NULL;
558 int buffer_size = 0; 560 size_t buffer_size = 0;
559 int html = 0; 561 int html = 0;
560 562
561 if (input == NULL) return(NULL); 563 if (input == NULL) return(NULL);
562 if (doc != NULL) 564 if (doc != NULL)
563 html = (doc->type == XML_HTML_DOCUMENT_NODE); 565 html = (doc->type == XML_HTML_DOCUMENT_NODE);
564 566
565 /* 567 /*
566 * allocate an translation buffer. 568 * allocate an translation buffer.
567 */ 569 */
568 buffer_size = 1000; 570 buffer_size = 1000;
569 buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); 571 buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
570 if (buffer == NULL) { 572 if (buffer == NULL) {
571 xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: malloc failed"); 573 xmlEntitiesErrMemory("xmlEncodeEntities: malloc failed");
572 return(NULL); 574 return(NULL);
573 } 575 }
574 out = buffer; 576 out = buffer;
575 577
576 while (*cur != '\0') { 578 while (*cur != '\0') {
577 if (out - buffer > buffer_size - 100) { 579 size_t indx = out - buffer;
578 » int indx = out - buffer; 580 if (indx + 100 > buffer_size) {
579 581
580 growBufferReentrant(); 582 growBufferReentrant();
581 out = &buffer[indx]; 583 out = &buffer[indx];
582 } 584 }
583 585
584 /* 586 /*
585 * By default one have to encode at least '<', '>', '"' and '&' ! 587 * By default one have to encode at least '<', '>', '"' and '&' !
586 */ 588 */
587 if (*cur == '<') { 589 if (*cur == '<') {
590 const xmlChar *end;
591
592 /*
593 * Special handling of server side include in HTML attributes
594 */
595 if (html && attr &&
596 (cur[1] == '!') && (cur[2] == '-') && (cur[3] == '-') &&
597 ((end = xmlStrstr(cur, BAD_CAST "-->")) != NULL)) {
598 while (cur != end) {
599 *out++ = *cur++;
600 indx = out - buffer;
601 if (indx + 100 > buffer_size) {
602 growBufferReentrant();
603 out = &buffer[indx];
604 }
605 }
606 *out++ = *cur++;
607 *out++ = *cur++;
608 *out++ = *cur++;
609 continue;
610 }
588 *out++ = '&'; 611 *out++ = '&';
589 *out++ = 'l'; 612 *out++ = 'l';
590 *out++ = 't'; 613 *out++ = 't';
591 *out++ = ';'; 614 *out++ = ';';
592 } else if (*cur == '>') { 615 } else if (*cur == '>') {
593 *out++ = '&'; 616 *out++ = '&';
594 *out++ = 'g'; 617 *out++ = 'g';
595 *out++ = 't'; 618 *out++ = 't';
596 *out++ = ';'; 619 *out++ = ';';
597 } else if (*cur == '&') { 620 } else if (*cur == '&') {
621 /*
622 * Special handling of &{...} construct from HTML 4, see
623 * http://www.w3.org/TR/html401/appendix/notes.html#h-B.7.1
624 */
625 if (html && attr && (cur[1] == '{') &&
626 (strchr((const char *) cur, '}'))) {
627 while (*cur != '}') {
628 *out++ = *cur++;
629 indx = out - buffer;
630 if (indx + 100 > buffer_size) {
631 growBufferReentrant();
632 out = &buffer[indx];
633 }
634 }
635 *out++ = *cur++;
636 continue;
637 }
598 *out++ = '&'; 638 *out++ = '&';
599 *out++ = 'a'; 639 *out++ = 'a';
600 *out++ = 'm'; 640 *out++ = 'm';
601 *out++ = 'p'; 641 *out++ = 'p';
602 *out++ = ';'; 642 *out++ = ';';
603 } else if (((*cur >= 0x20) && (*cur < 0x80)) || 643 } else if (((*cur >= 0x20) && (*cur < 0x80)) ||
604 (*cur == '\n') || (*cur == '\t') || ((html) && (*cur == '\r'))) { 644 (*cur == '\n') || (*cur == '\t') || ((html) && (*cur == '\r'))) {
605 /* 645 /*
606 * default case, just copy ! 646 * default case, just copy !
607 */ 647 */
(...skipping 12 matching lines...) Expand all
620 *out++ = *cur; 660 *out++ = *cur;
621 } else { 661 } else {
622 /* 662 /*
623 * We assume we have UTF-8 input. 663 * We assume we have UTF-8 input.
624 */ 664 */
625 char buf[11], *ptr; 665 char buf[11], *ptr;
626 int val = 0, l = 1; 666 int val = 0, l = 1;
627 667
628 if (*cur < 0xC0) { 668 if (*cur < 0xC0) {
629 xmlEntitiesErr(XML_CHECK_NOT_UTF8, 669 xmlEntitiesErr(XML_CHECK_NOT_UTF8,
630 » » » "xmlEncodeEntitiesReentrant : input not UTF-8"); 670 » » » "xmlEncodeEntities: input not UTF-8");
631 if (doc != NULL) 671 if (doc != NULL)
632 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); 672 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
633 snprintf(buf, sizeof(buf), "&#%d;", *cur); 673 snprintf(buf, sizeof(buf), "&#%d;", *cur);
634 buf[sizeof(buf) - 1] = 0; 674 buf[sizeof(buf) - 1] = 0;
635 ptr = buf; 675 ptr = buf;
636 while (*ptr != 0) *out++ = *ptr++; 676 while (*ptr != 0) *out++ = *ptr++;
637 cur++; 677 cur++;
638 continue; 678 continue;
639 } else if (*cur < 0xE0) { 679 } else if (*cur < 0xE0) {
640 val = (cur[0]) & 0x1F; 680 val = (cur[0]) & 0x1F;
(...skipping 12 matching lines...) Expand all
653 val <<= 6; 693 val <<= 6;
654 val |= (cur[1]) & 0x3F; 694 val |= (cur[1]) & 0x3F;
655 val <<= 6; 695 val <<= 6;
656 val |= (cur[2]) & 0x3F; 696 val |= (cur[2]) & 0x3F;
657 val <<= 6; 697 val <<= 6;
658 val |= (cur[3]) & 0x3F; 698 val |= (cur[3]) & 0x3F;
659 l = 4; 699 l = 4;
660 } 700 }
661 if ((l == 1) || (!IS_CHAR(val))) { 701 if ((l == 1) || (!IS_CHAR(val))) {
662 xmlEntitiesErr(XML_ERR_INVALID_CHAR, 702 xmlEntitiesErr(XML_ERR_INVALID_CHAR,
663 » » » "xmlEncodeEntitiesReentrant : char out of range\n"); 703 » » » "xmlEncodeEntities: char out of range\n");
664 if (doc != NULL) 704 if (doc != NULL)
665 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); 705 doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
666 snprintf(buf, sizeof(buf), "&#%d;", *cur); 706 snprintf(buf, sizeof(buf), "&#%d;", *cur);
667 buf[sizeof(buf) - 1] = 0; 707 buf[sizeof(buf) - 1] = 0;
668 ptr = buf; 708 ptr = buf;
669 while (*ptr != 0) *out++ = *ptr++; 709 while (*ptr != 0) *out++ = *ptr++;
670 cur++; 710 cur++;
671 continue; 711 continue;
672 } 712 }
673 /* 713 /*
(...skipping 11 matching lines...) Expand all
685 725
686 snprintf(buf, sizeof(buf), "&#%d;", *cur); 726 snprintf(buf, sizeof(buf), "&#%d;", *cur);
687 buf[sizeof(buf) - 1] = 0; 727 buf[sizeof(buf) - 1] = 0;
688 ptr = buf; 728 ptr = buf;
689 while (*ptr != 0) *out++ = *ptr++; 729 while (*ptr != 0) *out++ = *ptr++;
690 } 730 }
691 cur++; 731 cur++;
692 } 732 }
693 *out = 0; 733 *out = 0;
694 return(buffer); 734 return(buffer);
735
736 mem_error:
737 xmlEntitiesErrMemory("xmlEncodeEntities: realloc failed");
738 xmlFree(buffer);
739 return(NULL);
695 } 740 }
696 741
697 /** 742 /**
743 * xmlEncodeAttributeEntities:
744 * @doc: the document containing the string
745 * @input: A string to convert to XML.
746 *
747 * Do a global encoding of a string, replacing the predefined entities
748 * and non ASCII values with their entities and CharRef counterparts for
749 * attribute values.
750 *
751 * Returns A newly allocated string with the substitution done.
752 */
753 xmlChar *
754 xmlEncodeAttributeEntities(xmlDocPtr doc, const xmlChar *input) {
755 return xmlEncodeEntitiesInternal(doc, input, 1);
756 }
757
758 /**
759 * xmlEncodeEntitiesReentrant:
760 * @doc: the document containing the string
761 * @input: A string to convert to XML.
762 *
763 * Do a global encoding of a string, replacing the predefined entities
764 * and non ASCII values with their entities and CharRef counterparts.
765 * Contrary to xmlEncodeEntities, this routine is reentrant, and result
766 * must be deallocated.
767 *
768 * Returns A newly allocated string with the substitution done.
769 */
770 xmlChar *
771 xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
772 return xmlEncodeEntitiesInternal(doc, input, 0);
773 }
774
775 /**
698 * xmlEncodeSpecialChars: 776 * xmlEncodeSpecialChars:
699 * @doc: the document containing the string 777 * @doc: the document containing the string
700 * @input: A string to convert to XML. 778 * @input: A string to convert to XML.
701 * 779 *
702 * Do a global encoding of a string, replacing the predefined entities 780 * Do a global encoding of a string, replacing the predefined entities
703 * this routine is reentrant, and result must be deallocated. 781 * this routine is reentrant, and result must be deallocated.
704 * 782 *
705 * Returns A newly allocated string with the substitution done. 783 * Returns A newly allocated string with the substitution done.
706 */ 784 */
707 xmlChar * 785 xmlChar *
708 xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) { 786 xmlEncodeSpecialChars(const xmlDoc *doc ATTRIBUTE_UNUSED, const xmlChar *input) {
709 const xmlChar *cur = input; 787 const xmlChar *cur = input;
710 xmlChar *buffer = NULL; 788 xmlChar *buffer = NULL;
711 xmlChar *out = NULL; 789 xmlChar *out = NULL;
712 int buffer_size = 0; 790 size_t buffer_size = 0;
713 if (input == NULL) return(NULL); 791 if (input == NULL) return(NULL);
714 792
715 /* 793 /*
716 * allocate an translation buffer. 794 * allocate an translation buffer.
717 */ 795 */
718 buffer_size = 1000; 796 buffer_size = 1000;
719 buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); 797 buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
720 if (buffer == NULL) { 798 if (buffer == NULL) {
721 xmlEntitiesErrMemory("xmlEncodeSpecialChars: malloc failed"); 799 xmlEntitiesErrMemory("xmlEncodeSpecialChars: malloc failed");
722 return(NULL); 800 return(NULL);
723 } 801 }
724 out = buffer; 802 out = buffer;
725 803
726 while (*cur != '\0') { 804 while (*cur != '\0') {
727 if (out - buffer > buffer_size - 10) { 805 size_t indx = out - buffer;
728 » int indx = out - buffer; 806 if (indx + 10 > buffer_size) {
729 807
730 growBufferReentrant(); 808 growBufferReentrant();
731 out = &buffer[indx]; 809 out = &buffer[indx];
732 } 810 }
733 811
734 /* 812 /*
735 * By default one have to encode at least '<', '>', '"' and '&' ! 813 * By default one have to encode at least '<', '>', '"' and '&' !
736 */ 814 */
737 if (*cur == '<') { 815 if (*cur == '<') {
738 *out++ = '&'; 816 *out++ = '&';
(...skipping 28 matching lines...) Expand all
767 /* 845 /*
768 * Works because on UTF-8, all extended sequences cannot 846 * Works because on UTF-8, all extended sequences cannot
769 * result in bytes in the ASCII range. 847 * result in bytes in the ASCII range.
770 */ 848 */
771 *out++ = *cur; 849 *out++ = *cur;
772 } 850 }
773 cur++; 851 cur++;
774 } 852 }
775 *out = 0; 853 *out = 0;
776 return(buffer); 854 return(buffer);
855
856 mem_error:
857 xmlEntitiesErrMemory("xmlEncodeSpecialChars: realloc failed");
858 xmlFree(buffer);
859 return(NULL);
777 } 860 }
778 861
779 /** 862 /**
780 * xmlCreateEntitiesTable: 863 * xmlCreateEntitiesTable:
781 * 864 *
782 * create and initialize an empty entities hash table. 865 * create and initialize an empty entities hash table.
783 * This really doesn't make sense and should be deprecated 866 * This really doesn't make sense and should be deprecated
784 * 867 *
785 * Returns the xmlEntitiesTablePtr just created or NULL in case of error. 868 * Returns the xmlEntitiesTablePtr just created or NULL in case of error.
786 */ 869 */
(...skipping 26 matching lines...) Expand all
813 xmlFreeEntitiesTable(xmlEntitiesTablePtr table) { 896 xmlFreeEntitiesTable(xmlEntitiesTablePtr table) {
814 xmlHashFree(table, (xmlHashDeallocator) xmlFreeEntityWrapper); 897 xmlHashFree(table, (xmlHashDeallocator) xmlFreeEntityWrapper);
815 } 898 }
816 899
817 #ifdef LIBXML_TREE_ENABLED 900 #ifdef LIBXML_TREE_ENABLED
818 /** 901 /**
819 * xmlCopyEntity: 902 * xmlCopyEntity:
820 * @ent: An entity 903 * @ent: An entity
821 * 904 *
822 * Build a copy of an entity 905 * Build a copy of an entity
823 * 906 *
824 * Returns the new xmlEntitiesPtr or NULL in case of error. 907 * Returns the new xmlEntitiesPtr or NULL in case of error.
825 */ 908 */
826 static xmlEntityPtr 909 static xmlEntityPtr
827 xmlCopyEntity(xmlEntityPtr ent) { 910 xmlCopyEntity(xmlEntityPtr ent) {
828 xmlEntityPtr cur; 911 xmlEntityPtr cur;
829 912
830 cur = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); 913 cur = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity));
831 if (cur == NULL) { 914 if (cur == NULL) {
832 xmlEntitiesErrMemory("xmlCopyEntity:: malloc failed"); 915 xmlEntitiesErrMemory("xmlCopyEntity:: malloc failed");
833 return(NULL); 916 return(NULL);
(...skipping 15 matching lines...) Expand all
849 if (ent->URI != NULL) 932 if (ent->URI != NULL)
850 cur->URI = xmlStrdup(ent->URI); 933 cur->URI = xmlStrdup(ent->URI);
851 return(cur); 934 return(cur);
852 } 935 }
853 936
854 /** 937 /**
855 * xmlCopyEntitiesTable: 938 * xmlCopyEntitiesTable:
856 * @table: An entity table 939 * @table: An entity table
857 * 940 *
858 * Build a copy of an entity table. 941 * Build a copy of an entity table.
859 * 942 *
860 * Returns the new xmlEntitiesTablePtr or NULL in case of error. 943 * Returns the new xmlEntitiesTablePtr or NULL in case of error.
861 */ 944 */
862 xmlEntitiesTablePtr 945 xmlEntitiesTablePtr
863 xmlCopyEntitiesTable(xmlEntitiesTablePtr table) { 946 xmlCopyEntitiesTable(xmlEntitiesTablePtr table) {
864 return(xmlHashCopy(table, (xmlHashCopier) xmlCopyEntity)); 947 return(xmlHashCopy(table, (xmlHashCopier) xmlCopyEntity));
865 } 948 }
866 #endif /* LIBXML_TREE_ENABLED */ 949 #endif /* LIBXML_TREE_ENABLED */
867 950
868 #ifdef LIBXML_OUTPUT_ENABLED 951 #ifdef LIBXML_OUTPUT_ENABLED
869 952
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 * xmlDumpEntityDeclScan: 1081 * xmlDumpEntityDeclScan:
999 * @ent: An entity table 1082 * @ent: An entity table
1000 * @buf: An XML buffer. 1083 * @buf: An XML buffer.
1001 * 1084 *
1002 * When using the hash table scan function, arguments need to be reversed 1085 * When using the hash table scan function, arguments need to be reversed
1003 */ 1086 */
1004 static void 1087 static void
1005 xmlDumpEntityDeclScan(xmlEntityPtr ent, xmlBufferPtr buf) { 1088 xmlDumpEntityDeclScan(xmlEntityPtr ent, xmlBufferPtr buf) {
1006 xmlDumpEntityDecl(buf, ent); 1089 xmlDumpEntityDecl(buf, ent);
1007 } 1090 }
1008 1091
1009 /** 1092 /**
1010 * xmlDumpEntitiesTable: 1093 * xmlDumpEntitiesTable:
1011 * @buf: An XML buffer. 1094 * @buf: An XML buffer.
1012 * @table: An entity table 1095 * @table: An entity table
1013 * 1096 *
1014 * This will dump the content of the entity table as an XML DTD definition 1097 * This will dump the content of the entity table as an XML DTD definition
1015 */ 1098 */
1016 void 1099 void
1017 xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) { 1100 xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) {
1018 xmlHashScan(table, (xmlHashScanner)xmlDumpEntityDeclScan, buf); 1101 xmlHashScan(table, (xmlHashScanner)xmlDumpEntityDeclScan, buf);
1019 } 1102 }
1020 #endif /* LIBXML_OUTPUT_ENABLED */ 1103 #endif /* LIBXML_OUTPUT_ENABLED */
1021 #define bottom_entities 1104 #define bottom_entities
1022 #include "elfgcchack.h" 1105 #include "elfgcchack.h"
OLDNEW
« no previous file with comments | « third_party/libxml/src/encoding.c ('k') | third_party/libxml/src/error.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698