php_json.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Omar Kilani <omar@php.net> |
  16. | Jakub Zelenka <bukka@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifndef PHP_JSON_H
  20. #define PHP_JSON_H
  21. #define PHP_JSON_VERSION "1.7.0"
  22. #include "zend_smart_str_public.h"
  23. extern zend_module_entry json_module_entry;
  24. #define phpext_json_ptr &json_module_entry
  25. #if defined(PHP_WIN32) && defined(JSON_EXPORTS)
  26. #define PHP_JSON_API __declspec(dllexport)
  27. #else
  28. #define PHP_JSON_API PHPAPI
  29. #endif
  30. #ifdef ZTS
  31. #include "TSRM.h"
  32. #endif
  33. extern PHP_JSON_API zend_class_entry *php_json_serializable_ce;
  34. /* error codes */
  35. typedef enum {
  36. PHP_JSON_ERROR_NONE = 0,
  37. PHP_JSON_ERROR_DEPTH,
  38. PHP_JSON_ERROR_STATE_MISMATCH,
  39. PHP_JSON_ERROR_CTRL_CHAR,
  40. PHP_JSON_ERROR_SYNTAX,
  41. PHP_JSON_ERROR_UTF8,
  42. PHP_JSON_ERROR_RECURSION,
  43. PHP_JSON_ERROR_INF_OR_NAN,
  44. PHP_JSON_ERROR_UNSUPPORTED_TYPE,
  45. PHP_JSON_ERROR_INVALID_PROPERTY_NAME,
  46. PHP_JSON_ERROR_UTF16
  47. } php_json_error_code;
  48. /* json_decode() options */
  49. #define PHP_JSON_OBJECT_AS_ARRAY (1<<0)
  50. #define PHP_JSON_BIGINT_AS_STRING (1<<1)
  51. /* json_encode() options */
  52. #define PHP_JSON_HEX_TAG (1<<0)
  53. #define PHP_JSON_HEX_AMP (1<<1)
  54. #define PHP_JSON_HEX_APOS (1<<2)
  55. #define PHP_JSON_HEX_QUOT (1<<3)
  56. #define PHP_JSON_FORCE_OBJECT (1<<4)
  57. #define PHP_JSON_NUMERIC_CHECK (1<<5)
  58. #define PHP_JSON_UNESCAPED_SLASHES (1<<6)
  59. #define PHP_JSON_PRETTY_PRINT (1<<7)
  60. #define PHP_JSON_UNESCAPED_UNICODE (1<<8)
  61. #define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9)
  62. #define PHP_JSON_PRESERVE_ZERO_FRACTION (1<<10)
  63. #define PHP_JSON_UNESCAPED_LINE_TERMINATORS (1<<11)
  64. /* json_decode() and json_encode() common options */
  65. #define PHP_JSON_INVALID_UTF8_IGNORE (1<<20)
  66. #define PHP_JSON_INVALID_UTF8_SUBSTITUTE (1<<21)
  67. #define PHP_JSON_THROW_ON_ERROR (1<<22)
  68. /* Internal flags */
  69. #define PHP_JSON_OUTPUT_ARRAY 0
  70. #define PHP_JSON_OUTPUT_OBJECT 1
  71. /* default depth */
  72. #define PHP_JSON_PARSER_DEFAULT_DEPTH 512
  73. ZEND_BEGIN_MODULE_GLOBALS(json)
  74. int encoder_depth;
  75. int encode_max_depth;
  76. php_json_error_code error_code;
  77. ZEND_END_MODULE_GLOBALS(json)
  78. PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json)
  79. #define JSON_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(json, v)
  80. #if defined(ZTS) && defined(COMPILE_DL_JSON)
  81. ZEND_TSRMLS_CACHE_EXTERN()
  82. #endif
  83. PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth);
  84. PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options);
  85. PHP_JSON_API int php_json_decode_ex(zval *return_value, char *str, size_t str_len, zend_long options, zend_long depth);
  86. static inline int php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, zend_long depth)
  87. {
  88. return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
  89. }
  90. #endif /* PHP_JSON_H */
  91. /*
  92. * Local variables:
  93. * tab-width: 4
  94. * c-basic-offset: 4
  95. * End:
  96. * vim600: noet sw=4 ts=4 fdm=marker
  97. * vim<600: noet sw=4 ts=4
  98. */