xmltok_ns.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const ENCODING *
  2. NS(xmlrpc_XmlGetUtf8InternalEncoding)(void) {
  3. return &ns(internal_utf8_encoding).enc;
  4. }
  5. const ENCODING *
  6. NS(xmlrpc_XmlGetUtf16InternalEncoding)(void) {
  7. #if XML_BYTE_ORDER == 12
  8. return &ns(internal_little2_encoding).enc;
  9. #elif XML_BYTE_ORDER == 21
  10. return &ns(internal_big2_encoding).enc;
  11. #else
  12. const short n = 1;
  13. return *(const char *)&n ?
  14. &ns(internal_little2_encoding).enc :
  15. &ns(internal_big2_encoding).enc;
  16. #endif
  17. }
  18. static
  19. const ENCODING *NS(encodings)[] = {
  20. &ns(latin1_encoding).enc,
  21. &ns(ascii_encoding).enc,
  22. &ns(utf8_encoding).enc,
  23. &ns(big2_encoding).enc,
  24. &ns(big2_encoding).enc,
  25. &ns(little2_encoding).enc,
  26. &ns(utf8_encoding).enc /* NO_ENC */
  27. };
  28. static
  29. int NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end,
  30. const char **nextTokPtr)
  31. {
  32. return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE, ptr, end, nextTokPtr);
  33. }
  34. static
  35. int NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end,
  36. const char **nextTokPtr)
  37. {
  38. return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE, ptr, end, nextTokPtr);
  39. }
  40. int
  41. NS(xmlrpc_XmlInitEncoding)(INIT_ENCODING * const p,
  42. const ENCODING ** const encPtr,
  43. const char * const name) {
  44. int i = getEncodingIndex(name);
  45. if (i == UNKNOWN_ENC)
  46. return 0;
  47. SET_INIT_ENC_INDEX(p, i);
  48. p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
  49. p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
  50. p->initEnc.updatePosition = initUpdatePosition;
  51. p->encPtr = encPtr;
  52. *encPtr = &(p->initEnc);
  53. return 1;
  54. }
  55. static
  56. const ENCODING *NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end)
  57. {
  58. #define ENCODING_MAX 128
  59. char buf[ENCODING_MAX];
  60. char *p = buf;
  61. int i;
  62. XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1);
  63. if (ptr != end)
  64. return 0;
  65. *p = 0;
  66. if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2)
  67. return enc;
  68. i = getEncodingIndex(buf);
  69. if (i == UNKNOWN_ENC)
  70. return 0;
  71. return NS(encodings)[i];
  72. }
  73. int
  74. NS(xmlrpc_XmlParseXmlDecl)(int const isGeneralTextEntity,
  75. const ENCODING * const enc,
  76. const char * const ptr,
  77. const char * const end,
  78. const char ** const badPtr,
  79. const char ** const versionPtr,
  80. const char ** const encodingName,
  81. const ENCODING ** const encoding,
  82. int * const standalone) {
  83. return doParseXmlDecl(NS(findEncoding),
  84. isGeneralTextEntity,
  85. enc,
  86. ptr,
  87. end,
  88. badPtr,
  89. versionPtr,
  90. encodingName,
  91. encoding,
  92. standalone);
  93. }