Home --> Documentations --> PJLIB-UTIL Reference

json.h
Go to the documentation of this file.
1 /* $Id: json.h 4704 2014-01-16 05:30:46Z ming $ */
2 /*
3  * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 #ifndef __PJLIB_UTIL_JSON_H__
20 #define __PJLIB_UTIL_JSON_H__
21 
22 
28 #include <pj/types.h>
29 #include <pj/list.h>
30 #include <pj/pool.h>
31 
33 
45 typedef enum pj_json_val_type
46 {
54 
55 /* Forward declaration for JSON element */
56 typedef struct pj_json_elem pj_json_elem;
57 
61 typedef struct pj_json_list
62 {
63  PJ_DECL_LIST_MEMBER(pj_json_elem);
64 } pj_json_list;
65 
74 {
75  PJ_DECL_LIST_MEMBER(pj_json_elem);
78  union
79  {
81  float num;
84  } value;
85 };
86 
91 typedef struct pj_json_err_info
92 {
93  unsigned line;
94  unsigned col;
95  int err_char;
97 
109 typedef pj_status_t (*pj_json_writer)(const char *s,
110  unsigned size,
111  void *user_data);
112 
119 PJ_DECL(void) pj_json_elem_null(pj_json_elem *el, pj_str_t *name);
120 
128 PJ_DECL(void) pj_json_elem_bool(pj_json_elem *el, pj_str_t *name,
129  pj_bool_t val);
130 
138 PJ_DECL(void) pj_json_elem_number(pj_json_elem *el, pj_str_t *name,
139  float val);
140 
148 PJ_DECL(void) pj_json_elem_string(pj_json_elem *el, pj_str_t *name,
149  pj_str_t *val);
150 
157 PJ_DECL(void) pj_json_elem_array(pj_json_elem *el, pj_str_t *name);
158 
165 PJ_DECL(void) pj_json_elem_obj(pj_json_elem *el, pj_str_t *name);
166 
173 PJ_DECL(void) pj_json_elem_add(pj_json_elem *el, pj_json_elem *child);
174 
187 PJ_DECL(pj_json_elem*) pj_json_parse(pj_pool_t *pool,
188  char *buffer,
189  unsigned *size,
190  pj_json_err_info *err_info);
191 
203 PJ_DECL(pj_status_t) pj_json_write(const pj_json_elem *elem,
204  char *buffer, unsigned *size);
205 
218 PJ_DECL(pj_status_t) pj_json_writef(const pj_json_elem *elem,
219  pj_json_writer writer,
220  void *user_data);
221 
226 PJ_END_DECL
227 
228 #endif /* __PJLIB_UTIL_JSON_H__ */
pj_json_elem * pj_json_parse(pj_pool_t *pool, char *buffer, unsigned *size, pj_json_err_info *err_info)
void pj_json_elem_obj(pj_json_elem *el, pj_str_t *name)
int pj_bool_t
void * user_data
void pj_json_elem_number(pj_json_elem *el, pj_str_t *name, float val)
Definition: json.h:47
Definition: json.h:51
pj_status_t(* pj_json_writer)(const char *s, unsigned size, void *user_data)
Definition: json.h:109
pj_status_t pj_json_writef(const pj_json_elem *elem, pj_json_writer writer, void *user_data)
Definition: json.h:91
Definition: json.h:48
pj_str_t str
Definition: json.h:82
int pj_status_t
Definition: json.h:61
pj_str_t name
Definition: json.h:76
unsigned col
Definition: json.h:94
pj_status_t pj_json_write(const pj_json_elem *elem, char *buffer, unsigned *size)
int err_char
Definition: json.h:95
float num
Definition: json.h:81
Definition: json.h:49
void pj_json_elem_string(pj_json_elem *el, pj_str_t *name, pj_str_t *val)
void pj_json_elem_array(pj_json_elem *el, pj_str_t *name)
Definition: json.h:50
#define PJ_BEGIN_DECL
pj_json_list children
Definition: json.h:83
void pj_json_elem_add(pj_json_elem *el, pj_json_elem *child)
unsigned line
Definition: json.h:93
pj_json_val_type type
Definition: json.h:77
Definition: json.h:52
union pj_json_elem::@1 value
pj_json_val_type
Definition: json.h:45
pj_bool_t is_true
Definition: json.h:80
Definition: json.h:73
void pj_json_elem_bool(pj_json_elem *el, pj_str_t *name, pj_bool_t val)
void pj_json_elem_null(pj_json_elem *el, pj_str_t *name)

 


PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.