IP : 3.148.238.144Hostname : premium184.web-hosting.comKernel : Linux premium184.web-hosting.com 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64Disable Function : None :) OS : Linux
PATH:
/
home/
riggvwfp/
../
../
./
home/
../
usr/
include/
asm/
../
drm/
../
json-c/
json_tokener.h/
/
/* * $Id: json_tokener.h,v 1.10 2006/07/25 03:24:50 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark <michael@metaparadigm.com> * * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. * */
/** * @file * @brief Methods to parse an input string into a tree of json_object objects. */ #ifndef _json_tokener_h_ #define _json_tokener_h_
struct json_tokener { char *str; struct printbuf *pb; int max_depth, depth, is_double, st_pos, char_offset; enum json_tokener_error err; unsigned int ucs_char; char quote_char; struct json_tokener_srec *stack; int flags; }; /** * @deprecated Unused in json-c code */ typedef struct json_tokener json_tokener;
/** * Be strict when parsing JSON input. Use caution with * this flag as what is considered valid may become more * restrictive from one release to the next, causing your * code to fail on previously working input. * * This flag is not set by default. * * @see json_tokener_set_flags() */ #define JSON_TOKENER_STRICT 0x01
/** * Given an error previously returned by json_tokener_get_error(), * return a human readable description of the error. * * @return a generic error message is returned if an invalid error value is provided. */ const char *json_tokener_error_desc(enum json_tokener_error jerr);
/** * Retrieve the error caused by the last call to json_tokener_parse_ex(), * or json_tokener_success if there is no error. * * When parsing a JSON string in pieces, if the tokener is in the middle * of parsing this will return json_tokener_continue. * * See also json_tokener_error_desc(). */ JSON_EXPORT enum json_tokener_error json_tokener_get_error(struct json_tokener *tok);
/** * Set flags that control how parsing will be done. */ JSON_EXPORT void json_tokener_set_flags(struct json_tokener *tok, int flags);
/** * Parse a string and return a non-NULL json_object if a valid JSON value * is found. The string does not need to be a JSON object or array; * it can also be a string, number or boolean value. * * A partial JSON string can be parsed. If the parsing is incomplete, * NULL will be returned and json_tokener_get_error() will return * json_tokener_continue. * json_tokener_parse_ex() can then be called with additional bytes in str * to continue the parsing. * * If json_tokener_parse_ex() returns NULL and the error is anything other than * json_tokener_continue, a fatal error has occurred and parsing must be * halted. Then, the tok object must not be reused until json_tokener_reset() is * called. * * When a valid JSON value is parsed, a non-NULL json_object will be * returned. Also, json_tokener_get_error() will return json_tokener_success. * Be sure to check the type with json_object_is_type() or * json_object_get_type() before using the object. * * @b XXX this shouldn't use internal fields: * Trailing characters after the parsed value do not automatically cause an * error. It is up to the caller to decide whether to treat this as an * error or to handle the additional characters, perhaps by parsing another * json value starting from that point. * * Extra characters can be detected by comparing the tok->char_offset against * the length of the last len parameter passed in. * * The tokener does \b not maintain an internal buffer so the caller is * responsible for calling json_tokener_parse_ex with an appropriate str * parameter starting with the extra characters. * * This interface is presently not 64-bit clean due to the int len argument * so the function limits the maximum string size to INT32_MAX (2GB). * If the function is called with len == -1 then strlen is called to check * the string length is less than INT32_MAX (2GB) * * Example: * @code json_object *jobj = NULL; const char *mystring = NULL; int stringlen = 0; enum json_tokener_error jerr; do { mystring = ... // get JSON string, e.g. read from file, etc... stringlen = strlen(mystring); jobj = json_tokener_parse_ex(tok, mystring, stringlen); } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); if (jerr != json_tokener_success) { fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); // Handle errors, as appropriate for your application. } if (tok->char_offset < stringlen) // XXX shouldn't access internal fields { // Handle extra characters after parsed object as desired. // e.g. issue an error, parse another object from that point, etc... } // Success, use jobj here.
@endcode * * @param tok a json_tokener previously allocated with json_tokener_new() * @param str an string with any valid JSON expression, or portion of. This does not need to be null terminated. * @param len the length of str */ JSON_EXPORT struct json_object* json_tokener_parse_ex(struct json_tokener *tok, const char *str, int len);