yumapro  25.10-3
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
320
321
338extern void
340 xml_msg_hdr_t *msg,
341 const xmlChar *modname,
342 const xmlChar *namestr,
343 const xmlChar *valstr,
344 ncx_btype_t btyp,
345 int32 startindent,
346 boolean isfirst);
347
348
378extern status_t
380 xml_msg_hdr_t *msg,
381 xmlns_id_t parent_nsid,
382 val_value_t *val,
383 int32 startindent,
384 val_nodetest_fn_t testfn,
385 boolean isfirst,
386 boolean islast,
387 boolean isfirstchild,
388 boolean isfirstsibling,
389 boolean force_lastsibling,
390 boolean force_lastsib_value,
391 boolean force_array_obj);
392
393
426extern status_t
428 xml_msg_hdr_t *msg,
429 xmlns_id_t parent_nsid,
430 val_value_t *val,
431 int32 startindent,
432 val_nodetest_fn_t testfn,
433 boolean isfirst,
434 boolean islast,
435 boolean isfirstchild,
436 boolean isfirstsibling,
437 boolean force_lastsibling,
438 boolean force_lastsib_value,
439 boolean force_array_obj,
440 xmlns_id_t force_nsid,
441 const xmlChar *force_name);
442
443
459extern status_t
461 xml_msg_hdr_t *msg,
462 xmlns_id_t parent_nsid,
463 val_value_t *val,
464 int32 startindent,
465 val_nodetest_fn_t testfn);
466
467
485extern status_t
487 xml_msg_hdr_t *msg,
488 xmlns_id_t parent_nsid,
489 val_value_t *val,
490 int32 startindent,
491 val_nodetest_fn_t testfn,
492 xmlns_id_t force_nsid,
493 const xmlChar *force_name);
494
495
506extern status_t
507 json_wr_check_open_file (FILE *fp,
508 val_value_t *val,
509 int32 startindent,
510 int32 indent,
511 val_nodetest_fn_t testfn);
512
513
527extern status_t
528 json_wr_check_open_file2 (FILE *fp,
529 val_value_t *val,
530 int32 startindent,
531 int32 indent,
532 val_nodetest_fn_t testfn,
533 boolean modnames);
534
535
536
537
553extern status_t
554 json_wr_check_open_file3 (FILE *fp,
555 val_value_t *val,
556 int32 startindent,
557 int32 indent,
558 val_nodetest_fn_t testfn,
559 boolean modnames,
560 boolean fixspace);
561
562
573extern status_t
574 json_wr_check_file (const xmlChar *filespec,
575 val_value_t *val,
576 int32 startindent,
577 int32 indent,
578 val_nodetest_fn_t testfn);
579
580
581
595extern status_t
596 json_wr_check_file2 (const xmlChar *filespec,
597 val_value_t *val,
598 int32 startindent,
599 int32 indent,
600 val_nodetest_fn_t testfn,
601 boolean modnames);
602
603
619extern status_t
620 json_wr_check_file3 (const xmlChar *filespec,
621 val_value_t *val,
622 int32 startindent,
623 int32 indent,
624 val_nodetest_fn_t testfn,
625 boolean modnames,
626 boolean fixspace);
627
628
638extern status_t
639 json_wr_file (const xmlChar *filespec,
640 val_value_t *val,
641 int32 startindent,
642 int32 indent);
643
656extern status_t
657 json_wr_file2 (const xmlChar *filespec,
658 val_value_t *val,
659 int32 startindent,
660 int32 indent,
661 boolean modnames);
662
663
664
685extern status_t
686 json_wr_file3 (const xmlChar *filespec,
687 val_value_t *val,
688 int32 startindent,
689 int32 indent,
690 boolean modnames,
691 boolean fixspace);
692
693
701extern void
703 int32 startindent);
704
705
721extern void
723 xml_msg_hdr_t *msg,
724 val_value_t *val,
725 obj_template_t *objnode,
726 int32 indent,
727 val_nodetest_fn_t testfn,
728 boolean isfirst,
729 boolean isfirstchild);
730
731
747extern void
749 xml_msg_hdr_t *msg,
750 getcb_get2_t *parent_get2cb,
751 obj_template_t *objnode,
752 int32 indent,
753 val_nodetest_fn_t testfn,
754 boolean isfirst,
755 boolean isfirstchild);
756
757
761#ifdef __cplusplus
762} /* end extern 'C' */
763#endif
764
765#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:3251
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.
Definition: json_wr.c:2944
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:1777
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:2867
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:1909
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:2155
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:1740
status_t json_wr_check_file3(const xmlChar *filespec, val_value_t *val, int32 startindent, int32 indent, val_nodetest_fn_t testfn, boolean modnames, boolean fixspace)
Write the specified value to a FILE in JSON format.
Definition: json_wr.c:3170
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:3433
status_t json_wr_file3(const xmlChar *filespec, val_value_t *val, int32 startindent, int32 indent, boolean modnames, boolean fixspace)
Write the specified value to a FILE in JSON format.
Definition: json_wr.c:3285
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:1529
void json_wr_simval_line2(ses_cb_t *scb, xml_msg_hdr_t *msg, const xmlChar *modname, 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:1947
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:3106
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:1656
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:1477
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:2912
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:2822
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:1845
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:3073
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:3219
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:1592
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:2028
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:3348
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:3314
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:2084
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:1711
status_t json_wr_check_open_file3(FILE *fp, val_value_t *val, int32 startindent, int32 indent, val_nodetest_fn_t testfn, boolean modnames, boolean fixspace)
Write the specified value to an open FILE in JSON format.
Definition: json_wr.c:2980
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:219
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:236
NETCONF Session Common definitions module.
Global error messages for status code enumerations.
GET2 control block.
Definition: getcb.h:360
One YANG data-def-stmt.
Definition: obj.h:1284
Session Control Block.
Definition: ses.h:759
one value to match one type
Definition: val.h:1024
Common Encoding Message Header No longer XML specific!! Used by JSON and CBOR parsing as well!...
Definition: xml_msg.h:476
Value Node Basic Support.
Value Node Utilities.