yumapro  24.10-2
YumaPro SDK
Loading...
Searching...
No Matches
json_wr.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3 * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
4 *
5 * Unless required by applicable law or agreed to in writing,
6 * software distributed under the License is distributed on an
7 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the
9 * specific language governing permissions and limitations
10 * under the License.
11 */
12#ifndef _H_json_wr
13#define _H_json_wr
14
15/* FILE: json_wr.h
16*********************************************************************
17* *
18* P U R P O S E *
19* *
20*********************************************************************/
21
27/*********************************************************************
28* *
29* C H A N G E H I S T O R Y *
30* *
31*********************************************************************
32
33date init comment
34----------------------------------------------------------------------
3501-sep-11 abb Begun;
36
37*/
38
39#include <stdio.h>
40#include <xmlstring.h>
41
42#ifndef _H_ses
43#include "ses.h"
44#endif
45
46#ifndef _H_status
47#include "status.h"
48#endif
49
50#ifndef _H_val
51#include "val.h"
52#endif
53
54#ifndef _H_val_util
55#include "val_util.h"
56#endif
57
58#ifndef _H_getcb
59#include "getcb.h"
60#endif
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/********************************************************************
67* *
68* C O N S T A N T S *
69* *
70*********************************************************************/
71#define JSON_WR_YANG_NULL (const xmlChar *)"[null]"
72
73/********************************************************************
74* *
75* T Y P E S *
76* *
77*********************************************************************/
78
79
88typedef enum json_wr_tag_t_ {
89 JSON_WR_TAG_NONE,
90 JSON_WR_TAG_FIRST,
91 JSON_WR_TAG_MIDDLE,
92 JSON_WR_TAG_LAST
94
96typedef struct json_walker_cookie_t_ {
99
102
104 int32 indent;
105
108
111
113 boolean maxmode;
114
116 boolean isfirst;
117
120
121 /* YPW-1199: malformed JSON output for leaf-lists and list */
127 boolean list_failed;
128
130
131
132/********************************************************************
133* *
134* F U N C T I O N S *
135* *
136*********************************************************************/
137
138
148extern void
150 xml_msg_hdr_t *msg,
151 const xmlChar *modname,
152 const xmlChar *name,
153 int32 startindent);
154
155
167extern void
169 xml_msg_hdr_t *msg,
170 const xmlChar *modname,
171 const xmlChar *name,
172 int32 startindent,
173 boolean startbrace,
174 boolean endbrace);
175
176
187extern void
189 xml_msg_hdr_t *msg,
190 val_value_t *val,
191 int32 startindent);
192
193
205extern void
207 xml_msg_hdr_t *msg,
208 const xmlChar *modname,
209 const xmlChar *name,
210 obj_template_t *obj,
211 int32 startindent);
212
213
221extern void
223 xml_msg_hdr_t *msg,
224 int32 startindent);
225
226
234extern void
236 xml_msg_hdr_t *msg,
237 int32 startindent);
238
239
252extern void
254 xml_msg_hdr_t *msg,
255 const xmlChar *modname,
256 const xmlChar *name,
257 obj_template_t *obj,
258 int32 startindent,
259 boolean startbrace,
260 boolean startbracket);
261
262
273extern void
275 xml_msg_hdr_t *msg,
276 val_value_t *val,
277 int32 startindent,
278 boolean startbrace,
279 boolean startbracket);
280
281
289extern void
291 xml_msg_hdr_t *msg,
292 int32 startindent);
293
294
309extern void
311 xml_msg_hdr_t *msg,
312 xmlns_id_t nsid,
313 const xmlChar *namestr,
314 const xmlChar *valstr,
315 ncx_btype_t btyp,
316 int32 startindent,
317 boolean isfirst);
318
319
349extern status_t
351 xml_msg_hdr_t *msg,
352 xmlns_id_t parent_nsid,
353 val_value_t *val,
354 int32 startindent,
355 val_nodetest_fn_t testfn,
356 boolean isfirst,
357 boolean islast,
358 boolean isfirstchild,
359 boolean isfirstsibling,
360 boolean force_lastsibling,
361 boolean force_lastsib_value,
362 boolean force_array_obj);
363
364
397extern status_t
399 xml_msg_hdr_t *msg,
400 xmlns_id_t parent_nsid,
401 val_value_t *val,
402 int32 startindent,
403 val_nodetest_fn_t testfn,
404 boolean isfirst,
405 boolean islast,
406 boolean isfirstchild,
407 boolean isfirstsibling,
408 boolean force_lastsibling,
409 boolean force_lastsib_value,
410 boolean force_array_obj,
411 xmlns_id_t force_nsid,
412 const xmlChar *force_name);
413
414
430extern status_t
432 xml_msg_hdr_t *msg,
433 xmlns_id_t parent_nsid,
434 val_value_t *val,
435 int32 startindent,
436 val_nodetest_fn_t testfn);
437
438
456extern status_t
458 xml_msg_hdr_t *msg,
459 xmlns_id_t parent_nsid,
460 val_value_t *val,
461 int32 startindent,
462 val_nodetest_fn_t testfn,
463 xmlns_id_t force_nsid,
464 const xmlChar *force_name);
465
466
477extern status_t
478 json_wr_check_open_file (FILE *fp,
479 val_value_t *val,
480 int32 startindent,
481 int32 indent,
482 val_nodetest_fn_t testfn);
483
484
497extern status_t
498 json_wr_check_open_file2 (FILE *fp,
499 val_value_t *val,
500 int32 startindent,
501 int32 indent,
502 val_nodetest_fn_t testfn,
503 boolean modnames);
504
505
506
507
508
519extern status_t
520 json_wr_check_file (const xmlChar *filespec,
521 val_value_t *val,
522 int32 startindent,
523 int32 indent,
524 val_nodetest_fn_t testfn);
525
526
527
539extern status_t
540 json_wr_check_file2 (const xmlChar *filespec,
541 val_value_t *val,
542 int32 startindent,
543 int32 indent,
544 val_nodetest_fn_t testfn,
545 boolean modnames);
546
547
557extern status_t
558 json_wr_file (const xmlChar *filespec,
559 val_value_t *val,
560 int32 startindent,
561 int32 indent);
562
573extern status_t
574 json_wr_file2 (const xmlChar *filespec,
575 val_value_t *val,
576 int32 startindent,
577 int32 indent,
578 boolean modnames);
579
580
588extern void
590 int32 startindent);
591
592
608extern void
610 xml_msg_hdr_t *msg,
611 val_value_t *val,
612 obj_template_t *objnode,
613 int32 indent,
614 val_nodetest_fn_t testfn,
615 boolean isfirst,
616 boolean isfirstchild);
617
618
634extern void
636 xml_msg_hdr_t *msg,
637 getcb_get2_t *parent_get2cb,
638 obj_template_t *objnode,
639 int32 indent,
640 val_nodetest_fn_t testfn,
641 boolean isfirst,
642 boolean isfirstchild);
643
644
648#ifdef __cplusplus
649} /* end extern 'C' */
650#endif
651
652#endif /* _H_json_wr */
GET1 and GET2 Callback Support.
status_t json_wr_file2(const xmlChar *filespec, val_value_t *val, int32 startindent, int32 indent, boolean modnames)
Write the specified value to a FILE in JSON format.
Definition: json_wr.c:3004
status_t json_wr_check_open_file2(FILE *fp, val_value_t *val, int32 startindent, int32 indent, val_nodetest_fn_t testfn, boolean modnames)
Write the specified value to an open FILE in JSON format Allow JSON or JSON-IETF format.
Definition: json_wr.c:2805
void json_wr_start_array_obj(ses_cb_t *scb, xml_msg_hdr_t *msg, const xmlChar *modname, const xmlChar *name, obj_template_t *obj, int32 startindent, boolean startbrace, boolean startbracket)
generate start of a JSON array; use OBJ to check the modname
Definition: json_wr.c:1731
status_t json_wr_full_check_val_force(ses_cb_t *scb, xml_msg_hdr_t *msg, xmlns_id_t parent_nsid, val_value_t *val, int32 startindent, val_nodetest_fn_t testfn, xmlns_id_t force_nsid, const xmlChar *force_name)
generate entire val_value_t *w/filter)
Definition: json_wr.c:2729
void json_wr_end_array(ses_cb_t *scb, xml_msg_hdr_t *msg, int32 startindent)
generate end of a JSON array
Definition: json_wr.c:1863
status_t json_wr_max_check_val_force(ses_cb_t *scb, xml_msg_hdr_t *msg, xmlns_id_t parent_nsid, val_value_t *val, int32 startindent, val_nodetest_fn_t testfn, boolean isfirst, boolean islast, boolean isfirstchild, boolean isfirstsibling, boolean force_lastsibling, boolean force_lastsib_value, boolean force_array_obj, xmlns_id_t force_nsid, const xmlChar *force_name)
generate entire val_value_t *w/filter)
Definition: json_wr.c:2063
void json_wr_start_array(ses_cb_t *scb, xml_msg_hdr_t *msg, int32 startindent)
generate start of a JSON array
Definition: json_wr.c:1694
void json_wr_check_child_obj_ex(ses_cb_t *scb, xml_msg_hdr_t *msg, getcb_get2_t *parent_get2cb, obj_template_t *objnode, int32 indent, val_nodetest_fn_t testfn, boolean isfirst, boolean isfirstchild)
generate entire val_value_t *w/filter) (extended version)
Definition: json_wr.c:3150
json_wr_tag_t
type parser used in 3 separate modes
Definition: json_wr.h:88
void json_wr_start_object_ex(ses_cb_t *scb, xml_msg_hdr_t *msg, const xmlChar *modname, const xmlChar *name, int32 startindent, boolean startbrace, boolean endbrace)
generate start of a JSON object (extended version)
Definition: json_wr.c:1495
status_t json_wr_check_file2(const xmlChar *filespec, val_value_t *val, int32 startindent, int32 indent, val_nodetest_fn_t testfn, boolean modnames)
Write the specified value to a FILE in JSON format.
Definition: json_wr.c:2926
void json_wr_start_object_obj(ses_cb_t *scb, xml_msg_hdr_t *msg, const xmlChar *modname, const xmlChar *name, obj_template_t *obj, int32 startindent)
generate start of a JSON object based on val value tree; use OBJ to check the modname
Definition: json_wr.c:1617
void json_wr_start_object(ses_cb_t *scb, xml_msg_hdr_t *msg, const xmlChar *modname, const xmlChar *name, int32 startindent)
generate start of a JSON object
Definition: json_wr.c:1443
status_t json_wr_check_open_file(FILE *fp, val_value_t *val, int32 startindent, int32 indent, val_nodetest_fn_t testfn)
Write the specified value to an open FILE in JSON format.
Definition: json_wr.c:2774
status_t json_wr_full_check_val(ses_cb_t *scb, xml_msg_hdr_t *msg, xmlns_id_t parent_nsid, val_value_t *val, int32 startindent, val_nodetest_fn_t testfn)
generate entire val_value_t *w/filter)
Definition: json_wr.c:2684
void json_wr_start_array_val(ses_cb_t *scb, xml_msg_hdr_t *msg, val_value_t *val, int32 startindent, boolean startbrace, boolean startbracket)
generate start of a JSON array; use value node
Definition: json_wr.c:1799
status_t json_wr_check_file(const xmlChar *filespec, val_value_t *val, int32 startindent, int32 indent, val_nodetest_fn_t testfn)
Write the specified value to a FILE in JSON format.
Definition: json_wr.c:2894
status_t json_wr_file(const xmlChar *filespec, val_value_t *val, int32 startindent, int32 indent)
Write the specified value to a FILE in JSON format.
Definition: json_wr.c:2973
void json_wr_start_object_val(ses_cb_t *scb, xml_msg_hdr_t *msg, val_value_t *val, int32 startindent)
generate start of a JSON object based on val value tree
Definition: json_wr.c:1558
void json_wr_simval_line(ses_cb_t *scb, xml_msg_hdr_t *msg, xmlns_id_t nsid, const xmlChar *namestr, const xmlChar *valstr, ncx_btype_t btyp, int32 startindent, boolean isfirst)
generate 1 line for a simple value within a container or array
Definition: json_wr.c:1898
void json_wr_check_child_obj(ses_cb_t *scb, xml_msg_hdr_t *msg, val_value_t *val, obj_template_t *objnode, int32 indent, val_nodetest_fn_t testfn, boolean isfirst, boolean isfirstchild)
generate entire val_value_t *w/filter)
Definition: json_wr.c:3065
void json_wr_output_null(ses_cb_t *scb, int32 startindent)
generate a null value; needed for printing empty <data> element which is done as a wrapper,...
Definition: json_wr.c:3031
status_t json_wr_max_check_val(ses_cb_t *scb, xml_msg_hdr_t *msg, xmlns_id_t parent_nsid, val_value_t *val, int32 startindent, val_nodetest_fn_t testfn, boolean isfirst, boolean islast, boolean isfirstchild, boolean isfirstsibling, boolean force_lastsibling, boolean force_lastsib_value, boolean force_array_obj)
generate entire val_value_t *w/filter)
Definition: json_wr.c:1992
void json_wr_end_object(ses_cb_t *scb, xml_msg_hdr_t *msg, int32 startindent)
generate end of a JSON object
Definition: json_wr.c:1665
boolean(* val_nodetest_fn_t)(xml_msg_hdr_t *mhdr, ncx_withdefaults_t withdef, boolean realtest, val_value_t *node)
user function callback template to test output of a specified node.
Definition: val_util.h:132
status_t
global error return code
Definition: status_enum.h:210
uint16 xmlns_id_t
integer handle for registered namespaces
Definition: xmlns.h:89
ncx_btype_t
enumeration of the built-in NCX types These types cannot be overridden and cannot be imported
Definition: ncxtypes.h:213
NETCONF Session Common definitions module.
Global error messages for status code enumerations.
GET2 control block.
Definition: getcb.h:357
One YANG data-def-stmt.
Definition: obj.h:1229
Session Control Block.
Definition: ses.h:573
one value to match one type
Definition: val.h:912
Common Encoding Message Header No longer XML specific!! Used by JSON and CBOR parsing as well!...
Definition: xml_msg.h:404
Value Node Basic Support.
Value Node Utilities.