/usr/include/pjlib-util/json.h is in libpjproject-dev 2.7.2~dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | /* $Id: json.h 4704 2014-01-16 05:30:46Z ming $ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJLIB_UTIL_JSON_H__
#define __PJLIB_UTIL_JSON_H__
/**
* @file json.h
* @brief PJLIB JSON Implementation
*/
#include <pj/types.h>
#include <pj/list.h>
#include <pj/pool.h>
PJ_BEGIN_DECL
/**
* @defgroup PJ_JSON JSON Writer and Loader
* @ingroup PJ_FILE_FMT
* @{
* This API implements JSON file format according to RFC 4627. It can be used
* to parse, write, and manipulate JSON documents.
*/
/**
* Type of JSON value.
*/
typedef enum pj_json_val_type
{
PJ_JSON_VAL_NULL, /**< Null value (null) */
PJ_JSON_VAL_BOOL, /**< Boolean value (true, false) */
PJ_JSON_VAL_NUMBER, /**< Numeric (float or fixed point) */
PJ_JSON_VAL_STRING, /**< Literal string value. */
PJ_JSON_VAL_ARRAY, /**< Array */
PJ_JSON_VAL_OBJ /**< Object. */
} pj_json_val_type;
/* Forward declaration for JSON element */
typedef struct pj_json_elem pj_json_elem;
/**
* JSON list to store child elements.
*/
typedef struct pj_json_list
{
PJ_DECL_LIST_MEMBER(pj_json_elem);
} pj_json_list;
/**
* This represents JSON element. A JSON element is basically a name/value
* pair, where the name is a string and the value can be one of null, boolean
* (true and false constants), number, string, array (containing zero or more
* elements), or object. An object can be viewed as C struct, that is a
* compound element containing other elements, each having name/value pair.
*/
struct pj_json_elem
{
PJ_DECL_LIST_MEMBER(pj_json_elem);
pj_str_t name; /**< ELement name. */
pj_json_val_type type; /**< Element type. */
union
{
pj_bool_t is_true; /**< Boolean value. */
float num; /**< Number value. */
pj_str_t str; /**< String value. */
pj_json_list children; /**< Object and array children */
} value; /**< Element value. */
};
/**
* Structure to be specified to pj_json_parse() to be filled with additional
* info when parsing failed.
*/
typedef struct pj_json_err_info
{
unsigned line; /**< Line location of the error */
unsigned col; /**< Column location of the error */
int err_char; /**< The offending character. */
} pj_json_err_info;
/**
* Type of function callback to write JSON document in pj_json_writef().
*
* @param s The string to be written to the document.
* @param size The length of the string
* @param user_data User data that was specified to pj_json_writef()
*
* @return If the callback returns non-PJ_SUCCESS, it will
* stop the pj_json_writef() function and this error
* will be returned to caller.
*/
typedef pj_status_t (*pj_json_writer)(const char *s,
unsigned size,
void *user_data);
/**
* Initialize null element.
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
*/
PJ_DECL(void) pj_json_elem_null(pj_json_elem *el, pj_str_t *name);
/**
* Initialize boolean element with the specified value.
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
*/
PJ_DECL(void) pj_json_elem_bool(pj_json_elem *el, pj_str_t *name,
pj_bool_t val);
/**
* Initialize number element with the specified value.
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
*/
PJ_DECL(void) pj_json_elem_number(pj_json_elem *el, pj_str_t *name,
float val);
/**
* Initialize string element with the specified value.
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
*/
PJ_DECL(void) pj_json_elem_string(pj_json_elem *el, pj_str_t *name,
pj_str_t *val);
/**
* Initialize element as an empty array
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
*/
PJ_DECL(void) pj_json_elem_array(pj_json_elem *el, pj_str_t *name);
/**
* Initialize element as an empty object
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
*/
PJ_DECL(void) pj_json_elem_obj(pj_json_elem *el, pj_str_t *name);
/**
* Add an element to an object or array.
*
* @param el The object or array element.
* @param child Element to be added to the object or array.
*/
PJ_DECL(void) pj_json_elem_add(pj_json_elem *el, pj_json_elem *child);
/**
* Parse a JSON document in the buffer. The buffer MUST be NULL terminated,
* or if not then it must have enough size to put the NULL character.
*
* @param pool The pool to allocate memory for creating elements.
* @param buffer String buffer containing JSON document.
* @param size Size of the document.
* @param err_info Optional structure to be filled with info when
* parsing failed.
*
* @return The root element from the document.
*/
PJ_DECL(pj_json_elem*) pj_json_parse(pj_pool_t *pool,
char *buffer,
unsigned *size,
pj_json_err_info *err_info);
/**
* Write the specified element to the string buffer.
*
* @param elem The element to be written.
* @param buffer Output buffer.
* @param size On input, it must be set to the size of the buffer.
* Upon successful return, this will be set to
* the length of the written string.
*
* @return PJ_SUCCESS on success or the appropriate error.
*/
PJ_DECL(pj_status_t) pj_json_write(const pj_json_elem *elem,
char *buffer, unsigned *size);
/**
* Incrementally write the element to arbitrary medium using the specified
* callback to write the document chunks.
*
* @param elem The element to be written.
* @param writer Callback function which will be called to write
* text chunks.
* @param user_data Arbitrary user data which will be given back when
* calling the callback.
*
* @return PJ_SUCCESS on success or the appropriate error.
*/
PJ_DECL(pj_status_t) pj_json_writef(const pj_json_elem *elem,
pj_json_writer writer,
void *user_data);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJLIB_UTIL_JSON_H__ */
|