2018-04-20 14:55:00 +00:00
|
|
|
/* wsjson.h
|
2018-11-19 14:52:30 +00:00
|
|
|
* JSON parsing functions.
|
2016-09-28 10:01:33 +00:00
|
|
|
*
|
|
|
|
* Copyright 2016, Dario Lombardo
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2016-09-28 10:01:33 +00:00
|
|
|
*/
|
|
|
|
|
2018-04-20 14:55:00 +00:00
|
|
|
#ifndef __WSJSON_H__
|
|
|
|
#define __WSJSON_H__
|
2016-09-28 10:01:33 +00:00
|
|
|
|
|
|
|
#include "ws_symbol_export.h"
|
|
|
|
#include <glib.h>
|
|
|
|
|
2016-10-15 18:48:17 +00:00
|
|
|
#include "jsmn.h"
|
|
|
|
|
2016-09-28 10:01:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a buffer is json an returns true if it is.
|
|
|
|
*/
|
2018-11-19 14:52:30 +00:00
|
|
|
WS_DLL_PUBLIC gboolean json_validate(const guint8 *buf, const size_t len);
|
2016-09-28 10:01:33 +00:00
|
|
|
|
2018-11-19 14:52:30 +00:00
|
|
|
WS_DLL_PUBLIC int json_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens);
|
2016-10-15 18:48:17 +00:00
|
|
|
|
2019-06-16 10:40:14 +00:00
|
|
|
/**
|
|
|
|
* Get the pointer to an object belonging to parent object and named as the name variable.
|
|
|
|
* Returns NULL if not found.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC jsmntok_t *json_get_object(const char *buf, jsmntok_t *parent, const gchar* name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the unescaped value of a string object belonging to parent object and named as the name variable.
|
|
|
|
* Returns NULL if not found. Caution: it modifies input buffer.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC char *json_get_string(char *buf, jsmntok_t *parent, const gchar* name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of a number object belonging to parent object and named as the name variable.
|
|
|
|
* Returns FALSE if not found. Caution: it modifies input buffer.
|
|
|
|
* Scientific notation not supported yet.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC gboolean json_get_double(char *buf, jsmntok_t *parent, const gchar* name, gdouble *val);
|
|
|
|
|
2017-09-02 19:47:14 +00:00
|
|
|
/**
|
2018-11-19 14:52:30 +00:00
|
|
|
* Decode the contents of a JSON string value by overwriting the input data.
|
|
|
|
* Returns TRUE on success and FALSE if invalid characters were encountered.
|
2017-09-02 19:47:14 +00:00
|
|
|
*/
|
2018-11-19 14:52:30 +00:00
|
|
|
WS_DLL_PUBLIC gboolean json_decode_string_inplace(char *text);
|
2017-09-02 19:47:14 +00:00
|
|
|
|
2016-09-28 10:01:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
2018-11-19 14:21:02 +00:00
|
|
|
* indent-tabs-mode: nil
|
2016-09-28 10:01:33 +00:00
|
|
|
* End:
|
|
|
|
*
|
2018-11-19 14:21:02 +00:00
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
2016-10-01 17:08:51 +00:00
|
|
|
*/
|