xml-imp.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2022-2025 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. #ifndef XML_IMP_H
  23. #define XML_IMP_H
  24. #include "mupdf/fitz.h"
  25. /* These types are required for basic XML operation. */
  26. struct attribute
  27. {
  28. char *value;
  29. struct attribute *next;
  30. char name[FZ_FLEXIBLE_ARRAY];
  31. };
  32. /**
  33. We use a slightly grotty representation for an XML tree.
  34. The topmost element of the tree is an fz_xml with up == NULL.
  35. This signifies that we are a 'doc', rather than a 'node'.
  36. We only ever get a 'doc' node at the root, and this contains
  37. a reference count for the entire tree, together with the
  38. fz_pool pointer used to allocate nodes.
  39. All other structures are 'nodes'. If down is MAGIC_TEXT then
  40. they are text nodes (with no children or attributes).
  41. Otherwise, they are standard XML nodes with attributes
  42. and children.
  43. */
  44. struct fz_xml
  45. {
  46. fz_xml *up, *down;
  47. union
  48. {
  49. struct /* up != NULL */
  50. {
  51. fz_xml *prev, *next;
  52. #ifdef FZ_XML_SEQ
  53. int seq;
  54. #endif
  55. union
  56. {
  57. char text[1]; /* down == MAGIC_TEXT */
  58. struct /* down != MAGIC_TEXT */
  59. {
  60. struct attribute *atts;
  61. char name[FZ_FLEXIBLE_ARRAY];
  62. } d;
  63. } u;
  64. } node;
  65. struct /* up == NULL */
  66. {
  67. int refs;
  68. fz_pool *pool;
  69. } doc;
  70. } u;
  71. };
  72. #define MAGIC_TEXT ((fz_xml *)1)
  73. #define FZ_TEXT_ITEM(item) (item && item->down == MAGIC_TEXT)
  74. #define FZ_DOCUMENT_ITEM(item) (item && item->up == NULL)
  75. size_t xml_parse_entity(int *c, const char *a);
  76. #endif