json.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * JavaScript Object Notation (JSON) parser (RFC7159)
  3. * Copyright (c) 2017, Qualcomm Atheros, Inc.
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef JSON_H
  9. #define JSON_H
  10. struct json_token {
  11. enum json_type {
  12. JSON_VALUE,
  13. JSON_OBJECT,
  14. JSON_ARRAY,
  15. JSON_STRING,
  16. JSON_NUMBER,
  17. JSON_BOOLEAN,
  18. JSON_NULL,
  19. } type;
  20. enum json_parsing_state {
  21. JSON_EMPTY,
  22. JSON_STARTED,
  23. JSON_WAITING_VALUE,
  24. JSON_COMPLETED,
  25. } state;
  26. char *name;
  27. char *string;
  28. int number;
  29. struct json_token *parent, *child, *sibling;
  30. };
  31. void json_escape_string(char *txt, size_t maxlen, const char *data, size_t len);
  32. struct json_token * json_parse(const char *data, size_t data_len);
  33. void json_free(struct json_token *json);
  34. struct json_token * json_get_member(struct json_token *json, const char *name);
  35. struct wpabuf * json_get_member_base64url(struct json_token *json,
  36. const char *name);
  37. void json_print_tree(struct json_token *root, char *buf, size_t buflen);
  38. #endif /* JSON_H */