yajl_parser.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef __YAJL_PARSER_H__
  17. #define __YAJL_PARSER_H__
  18. #include "api/yajl_parse.h"
  19. #include "yajl_bytestack.h"
  20. #include "yajl_buf.h"
  21. #include "yajl_lex.h"
  22. typedef enum {
  23. yajl_state_start = 0,
  24. yajl_state_parse_complete,
  25. yajl_state_parse_error,
  26. yajl_state_lexical_error,
  27. yajl_state_map_start,
  28. yajl_state_map_sep,
  29. yajl_state_map_need_val,
  30. yajl_state_map_got_val,
  31. yajl_state_map_need_key,
  32. yajl_state_array_start,
  33. yajl_state_array_got_val,
  34. yajl_state_array_need_val,
  35. yajl_state_got_value,
  36. } yajl_state;
  37. struct yajl_handle_t {
  38. const yajl_callbacks * callbacks;
  39. void * ctx;
  40. yajl_lexer lexer;
  41. const char * parseError;
  42. /* the number of bytes consumed from the last client buffer,
  43. * in the case of an error this will be an error offset, in the
  44. * case of an error this can be used as the error offset */
  45. size_t bytesConsumed;
  46. /* temporary storage for decoded strings */
  47. yajl_buf decodeBuf;
  48. /* a stack of states. access with yajl_state_XXX routines */
  49. yajl_bytestack stateStack;
  50. /* memory allocation routines */
  51. yajl_alloc_funcs alloc;
  52. /* bitfield */
  53. unsigned int flags;
  54. /* memory limit */
  55. unsigned long memoryLimit;
  56. };
  57. yajl_status
  58. yajl_do_parse(yajl_handle handle, const unsigned char * jsonText,
  59. size_t jsonTextLen);
  60. yajl_status
  61. yajl_do_finish(yajl_handle handle);
  62. unsigned char *
  63. yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
  64. size_t jsonTextLen, int verbose);
  65. /* A little built in integer parsing routine with the same semantics as strtol
  66. * that's unaffected by LOCALE. */
  67. #ifdef __cplusplus
  68. extern "C"
  69. #endif
  70. long long
  71. yajl_parse_integer(const unsigned char *number, unsigned int length);
  72. #ifdef __cplusplus
  73. extern "C"
  74. #endif
  75. unsigned long long
  76. yajl_parse_unsigned_integer(const unsigned char *number, unsigned int length);
  77. #endif