You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

  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. };
  25. extern JSON_parser new_JSON_parser(int depth);
  26. extern int parse_JSON_ex(JSON_parser jp, zval *z, unsigned short utf16_json[], int length, int options TSRMLS_DC);
  27. extern int free_JSON_parser(JSON_parser jp);
  28. static inline int parse_JSON(JSON_parser jp, zval *z, unsigned short utf16_json[], int length, int assoc TSRMLS_DC)
  29. {
  30. return parse_JSON_ex(jp, z, utf16_json, length, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0 TSRMLS_CC);
  31. }
  32. #endif