src/core/ngx_json_parse.h - nginx-1.31.7 nginx/ @ 939334eff

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Maxim Dounin
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_JSON_PARSE_H_INCLUDED_
  6. ‌#define _NGX_JSON_PARSE_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>
  9. #include <ngx_json_unescape.h>


  10. ‌#define NGX_JSON_SKIP                    -7
  11. ‌#define NGX_JSON_DEFAULT_MAX_DEPTH       64


  12. ‌typedef enum {
  13.     NGX_JSON_OBJECT_OPEN = 0,
  14.     NGX_JSON_OBJECT_CLOSE,
  15.     NGX_JSON_ARRAY_OPEN,
  16.     NGX_JSON_ARRAY_CLOSE,
  17.     NGX_JSON_KEY,
  18.     NGX_JSON_VALUE_STRING,
  19.     NGX_JSON_VALUE_NUMBER,
  20.     NGX_JSON_VALUE_BOOL,
  21.     NGX_JSON_VALUE_NULL
  22. ‌} ngx_json_event_e;


  23. ‌typedef enum {
  24.     ngx_json_start = 0,
  25.     ngx_json_done,
  26.     ngx_json_object,
  27.     ngx_json_object_next,
  28.     ngx_json_object_name_separator,
  29.     ngx_json_value,
  30.     ngx_json_object_value_separator,
  31.     ngx_json_array_value_separator,
  32.     ngx_json_array,
  33.     ngx_json_string,
  34.     ngx_json_number_minus,
  35.     ngx_json_number_int,
  36.     ngx_json_number_int_zero,
  37.     ngx_json_number_frac,
  38.     ngx_json_number_frac_digit,
  39.     ngx_json_number_exp,
  40.     ngx_json_number_exp_plusminus,
  41.     ngx_json_number_exp_digit,
  42.     ngx_json_escaped,
  43.     ngx_json_escaped_hex,       /* first \uXXXX: reading the four hex digits */
  44.     ngx_json_surrogate_start,   /* expect '\' beginning the low surrogate */
  45.     ngx_json_surrogate_u,       /* expect 'u' of the low surrogate */
  46.     ngx_json_surrogate_hex,     /* low \uXXXX: reading the four hex digits */
  47.     ngx_json_true_t,
  48.     ngx_json_true_tr,
  49.     ngx_json_true_tru,
  50.     ngx_json_false_f,
  51.     ngx_json_false_fa,
  52.     ngx_json_false_fal,
  53.     ngx_json_false_fals,
  54.     ngx_json_null_n,
  55.     ngx_json_null_nu,
  56.     ngx_json_null_nul
  57. ‌} ngx_json_state_e;


  58. ‌typedef enum {
  59.     ngx_json_ctx_none = 0,
  60.     ngx_json_ctx_object,
  61.     ngx_json_ctx_array
  62. ‌} ngx_json_container_e;


  63. ‌typedef struct ngx_json_ctx_s  ngx_json_ctx_t;


  64. ‌typedef ngx_int_t (*ngx_json_handler_pt)(ngx_json_ctx_t *ctx,
  65.     ngx_json_event_e event, ngx_str_t *token);


  66. ‌struct ngx_json_ctx_s {
  67.     ngx_json_state_e       state;

  68.     ngx_json_container_e  *stack;
  69.     ngx_uint_t             depth;
  70.     ngx_uint_t             max_depth;

  71.     uint32_t               codepoint;
  72.     ngx_uint_t             hex_left;         /* hex digits still expected */

  73.     ngx_uint_t             skip_until_depth;

  74.     ngx_pool_t            *pool;
  75.     ngx_json_handler_pt    handler;
  76.     void                  *data;

  77.     unsigned               in_key; /* unsigned in_key:1 */
  78. };


  79. void ngx_json_ctx_init(ngx_json_ctx_t *ctx, ngx_pool_t *pool);
  80. ngx_int_t ngx_json_parse_ctx(ngx_json_ctx_t *ctx, u_char *data, size_t len);
  81. ngx_int_t ngx_json_parse(ngx_pool_t *pool, ngx_str_t *json,
  82.     ngx_json_handler_pt handler, void *data);


  83. #endif /* _NGX_JSON_PARSE_H_INCLUDED_ */