php_json.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 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. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifndef PHP_JSON_H
  20. #define PHP_JSON_H
  21. #define PHP_JSON_VERSION "1.2.1"
  22. #include "ext/standard/php_smart_str.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. ZEND_BEGIN_MODULE_GLOBALS(json)
  34. int encoder_depth;
  35. int error_code;
  36. int encode_max_depth;
  37. ZEND_END_MODULE_GLOBALS(json)
  38. #ifdef ZTS
  39. # define JSON_G(v) TSRMG(json_globals_id, zend_json_globals *, v)
  40. #else
  41. # define JSON_G(v) (json_globals.v)
  42. #endif
  43. PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_DC);
  44. PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, int str_len, int options, long depth TSRMLS_DC);
  45. extern PHP_JSON_API zend_class_entry *php_json_serializable_ce;
  46. /* json_encode() options */
  47. #define PHP_JSON_HEX_TAG (1<<0)
  48. #define PHP_JSON_HEX_AMP (1<<1)
  49. #define PHP_JSON_HEX_APOS (1<<2)
  50. #define PHP_JSON_HEX_QUOT (1<<3)
  51. #define PHP_JSON_FORCE_OBJECT (1<<4)
  52. #define PHP_JSON_NUMERIC_CHECK (1<<5)
  53. #define PHP_JSON_UNESCAPED_SLASHES (1<<6)
  54. #define PHP_JSON_PRETTY_PRINT (1<<7)
  55. #define PHP_JSON_UNESCAPED_UNICODE (1<<8)
  56. #define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9)
  57. #define PHP_JSON_PRESERVE_ZERO_FRACTION (1<<10)
  58. /* Internal flags */
  59. #define PHP_JSON_OUTPUT_ARRAY 0
  60. #define PHP_JSON_OUTPUT_OBJECT 1
  61. /* json_decode() options */
  62. #define PHP_JSON_OBJECT_AS_ARRAY (1<<0)
  63. #define PHP_JSON_BIGINT_AS_STRING (1<<1)
  64. static inline void php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, long depth TSRMLS_DC)
  65. {
  66. php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth TSRMLS_CC);
  67. }
  68. #endif /* PHP_JSON_H */
  69. /*
  70. * Local variables:
  71. * tab-width: 4
  72. * c-basic-offset: 4
  73. * End:
  74. * vim600: noet sw=4 ts=4 fdm=marker
  75. * vim<600: noet sw=4 ts=4
  76. */