JSON_parser.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* JSON_parser.h */
  2. #ifndef JSON_PARSER_H
  3. #define JSON_PARSER_H
  4. #include "php.h"
  5. #include "ext/standard/php_smart_str.h"
  6. #include "php_json.h"
  7. #define JSON_PARSER_DEFAULT_DEPTH 512
  8. typedef struct JSON_parser_struct {
  9. int state;
  10. int depth;
  11. int top;
  12. int error_code;
  13. int* stack;
  14. zval **the_zstack;
  15. zval *the_static_zstack[JSON_PARSER_DEFAULT_DEPTH];
  16. } * JSON_parser;
  17. enum error_codes {
  18. PHP_JSON_ERROR_NONE = 0,
  19. PHP_JSON_ERROR_DEPTH,
  20. PHP_JSON_ERROR_STATE_MISMATCH,
  21. PHP_JSON_ERROR_CTRL_CHAR,
  22. PHP_JSON_ERROR_SYNTAX,
  23. PHP_JSON_ERROR_UTF8,
  24. PHP_JSON_ERROR_RECURSION,
  25. PHP_JSON_ERROR_INF_OR_NAN,
  26. PHP_JSON_ERROR_UNSUPPORTED_TYPE
  27. };
  28. extern JSON_parser new_JSON_parser(int depth);
  29. extern int parse_JSON_ex(JSON_parser jp, zval *z, unsigned short utf16_json[], int length, int options TSRMLS_DC);
  30. extern int free_JSON_parser(JSON_parser jp);
  31. static inline int parse_JSON(JSON_parser jp, zval *z, unsigned short utf16_json[], int length, int assoc TSRMLS_DC)
  32. {
  33. return parse_JSON_ex(jp, z, utf16_json, length, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0 TSRMLS_CC);
  34. }
  35. #endif