yumapro  20.10-14
YumaPro SDK

Contains JSON parsing and output utilities. More...

Collaboration diagram for JSON:

Data Structures

struct  json_walker_cookie_t
 JSON walker function for GET2 support. More...
 

Enumerations

enum  json_wr_tag_t
 type parser used in 3 separate modes
 

Functions

status_t json_parse_top_identifier (ses_cb_t *scb, xml_msg_hdr_t *msg, obj_template_t *obj, const xmlChar **modname, const xmlChar **name, xmlChar **tempbuff)
 Parse a top-level JSON object;. More...
 
status_t json_parse_text (ses_cb_t *scb, xml_msg_hdr_t *msg, obj_template_t *obj, dlq_hdr_t *returnQ)
 Parse token chain representing JSON Text. More...
 
status_t json_parse_buffer (xmlChar *buff, obj_template_t *obj, dlq_hdr_t *returnQ)
 Parse buffer of JSON into val_value_t structs. More...
 
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 More...
 
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) More...
 
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 More...
 
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 More...
 
void json_wr_end_object (ses_cb_t *scb, xml_msg_hdr_t *msg, int32 startindent)
 generate end of a JSON object More...
 
void json_wr_start_array (ses_cb_t *scb, xml_msg_hdr_t *msg, int32 startindent)
 generate start of a JSON array More...
 
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 More...
 
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 More...
 
void json_wr_end_array (ses_cb_t *scb, xml_msg_hdr_t *msg, int32 startindent)
 generate end of a JSON array More...
 
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 More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
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. More...
 
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. More...
 
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. More...
 
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, not a real value node More...
 
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) More...
 
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) More...
 

Detailed Description

Contains JSON parsing and output utilities.

JSON output functions.

Used by the client and server for RESTCONF protocol messages. Also used by yangcli-pro display-mode=json.

Generates plain or YANG JSON format.

Function Documentation

◆ json_parse_buffer()

status_t json_parse_buffer ( xmlChar *  buff,
obj_template_t obj,
dlq_hdr_t *  returnQ 
)

Parse buffer of JSON into val_value_t structs.

Defaults are not added to any objects Missing objects are not checked

A seperate parsing phase is used to fully validate the input contained in the returned val_value_t structs.

This parsing phase checks that simple types are complete and child members of complex types are valid (but maybe missing or incomplete child nodes).

Parameters
buffzero-terminated buffer to parse
objobj_template_t for the object to parse
returnQaddress of Q to store parsed value results
Return values
returnQhas 1 or more malloced val_value_t representing the parsed value(s); If top-level arry found then there may be more than 1 entry in the returnQ
Returns
return status

◆ json_parse_text()

status_t json_parse_text ( ses_cb_t scb,
xml_msg_hdr_t msg,
obj_template_t obj,
dlq_hdr_t *  returnQ 
)

Parse token chain representing JSON Text.

This function assumes that the msg->tkc token control block has been setup correctly in advance

     tkc = tk_new_chain();
     tk_setup_chain_json_buffs(tkc, ...);  (example!)
     tk_tokenize_input(tkc);

Makes sure that only allowed value strings or child nodes (and their values) are entered.

Defaults are not added to any objects Missing objects are not checked

A separate parsing phase is used to fully validate the input contained in the returned val_value_t structs.

This parsing phase checks that simple types are complete and child members of complex types are valid (but maybe missing or incomplete child nodes).

Parameters
scbsession control block
msgxml_msg header from the incoming RPC message
objobj_template_t for the object to parse
returnQaddress of Q to store parsed value results
Return values
returnQhas 1 or more malloced val_value_t representing the parsed value(s)
msg->errQmay be appended with new errors
Returns
return status

◆ json_parse_top_identifier()

status_t json_parse_top_identifier ( ses_cb_t scb,
xml_msg_hdr_t msg,
obj_template_t obj,
const xmlChar **  modname,
const xmlChar **  name,
xmlChar **  tempbuff 
)

Parse a top-level JSON object;.

will be used only for the DATASTORE launchpoint in order to set request_target and obj

Parameters
scbsession control block Input is read from scb->reader.
msgincoming RPC message Errors are appended to msg->errQ
objobject template to use for parsing
modnamereturn module name pointer, may be NULL
namereturn pointer to name of the node
tempbuffbuffer to write, must be freed by caller
Return values
*namename of the node
*modnamemodname of the identifier
*tempbuffMALLOCED buffer to hold copy of current token This must be freed with m__free
Returns
return status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_check_child_obj()

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)

Write an entire <get2> val_value_t out from the obj_template_t callback Using an optional testfn to filter output

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
valparent of the object to write
objnodechild object node to write
indentstart indent amount if indent enabled
testfncallback function to use, NULL if not used
isfirstfirst node printed
isfirstchildisfirstchild of whatever container
Here is the call graph for this function:

◆ json_wr_check_child_obj_ex()

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)

Write an entire <get2> val_value_t out from the obj_template_t callback Using an optional testfn to filter output.

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
parent_get2cbparent get2 control block of the object to write
objnodechild object node to write
indentstart indent amount if indent enabled
testfncallback function to use, NULL if not used
isfirstfirst node printed
isfirstchildisfirstchild of whatever container
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_check_file()

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.

Parameters
filespecexact path of filename to open
valvalue for output
startindentstarting indent point
indentindent amount (0..9 spaces)
testfncallback test function to use
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_check_open_file()

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.

Parameters
fpopen FILE control block
valvalue for output
startindentstarting indent point
indentindent amount (0..9 spaces)
testfncallback test function to use
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_end_array()

void json_wr_end_array ( ses_cb_t scb,
xml_msg_hdr_t msg,
int32  startindent 
)

generate end of a JSON array

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
startindentstart indent amount if indent enabled
Here is the call graph for this function:

◆ json_wr_end_object()

void json_wr_end_object ( ses_cb_t scb,
xml_msg_hdr_t msg,
int32  startindent 
)

generate end of a JSON object

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
startindentstart indent amount if indent enabled
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_file()

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.

Parameters
filespecexact path of filename to open
valvalue for output
startindentstarting indent point
indentindent amount (0..9 spaces)
Returns
status
Here is the call graph for this function:

◆ json_wr_full_check_val()

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)

Write an entire val_value_t out as XML, including the top level Using an optional testfn to filter output

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
parent_nsidparent namespace ID; used if val->parent NULL
valvalue to write
startindentstart indent amount if indent enabled
testfncallback function to use, NULL if not used
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_full_check_val_force()

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)

Write an entire val_value_t out as JSON, including the top level Using an optional testfn to filter output Force top-node nsid/name if set

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
parent_nsidparent namespace ID; used if val->parent NULL
valvalue to write
startindentstart indent amount if indent enabled
testfncallback function to use, NULL if not used
force_nsidtop-level NSID to use instead of val (if set)
force_nametop-level name to use instead of val (if set)
Returns
status
Here is the call graph for this function:

◆ json_wr_max_check_val()

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)

Write an entire val_value_t out as XML, including the top level Using an optional testfn to filter output Maximum parameters exposed

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
parent_nsidparent namespace ID; used if val->parent NULL
valvalue to write
startindentstart indent amount if indent enabled
testfncallback function to use, NULL if not used
isfirstTRUE if this is the first (top) val printed
islastTRUE if this is the last (top) val printed
isfirstchildTRUE if this is the first child of a parent node
FALSE if this is the 2nd - Nth value of an array
isfirstsiblingTRUE if this is the first value of an array
FALSE if this is the 2nd - Nth value of an array
force_lastsiblingTRUE to force this as the last sibling; TRUE or FALSE to check the sibling of 'val'
force_lastsib_valueTRUE to force this as the last sibling
FALSE to force this as not the last sibling; ignore if force_lastsibling is FALSE
force_array_objTRUE to treat select leafs and containers as leaf-lists and lists which normally have only 1 instance in their actual context, but select removes the context
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_max_check_val_force()

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)

Write an entire val_value_t out as JSON, including the top level Using an optional testfn to filter output Maximum parameters exposed Force top-node nsid/name if set

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
parent_nsidparent namespace ID; used if val->parent NULL
valvalue to write
startindentstart indent amount if indent enabled
testfncallback function to use, NULL if not used
isfirstTRUE if this is the first (top) val printed
islastTRUE if this is the last (top) val printed
isfirstchildTRUE if this is the first child of a parent node
FALSE if this is the 2nd - Nth value of an array
isfirstsiblingTRUE if this is the first value of an array
FALSE if this is the 2nd - Nth value of an array
force_lastsiblingTRUE to force this as the last sibling; TRUE or FALSE to check the sibling of 'val'
force_lastsib_valueTRUE to force this as the last sibling
FALSE to force this as not the last sibling; ignore if force_lastsibling is FALSE
force_array_objTRUE to treat select leafs and containers as leaf-lists and lists which normally have only 1 instance in their actual context, but select removes the context
force_nsidtop-level NSID to use instead of val (if set)
force_nametop-level name to use instead of val (if set)
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_output_null()

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, not a real value node

Parameters
scbsession control block
startindentstart indent amount if indent enabled
Here is the call graph for this function:

◆ json_wr_simval_line()

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

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
nsidactive namespace ID
namestrcomplete name string
  • has module name already if needed
  • NULL to skip (inside an array)
valstrvalue string to write (NULL for empty types)
btypbasetype of the value before translated to string
startindentstart indent amount if indent enabled
isfirst== TRUE if this is the first line; FALSE if not
Here is the call graph for this function:

◆ json_wr_start_array()

void json_wr_start_array ( ses_cb_t scb,
xml_msg_hdr_t msg,
int32  startindent 
)

generate start of a JSON array

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
startindentstart indent amount if indent enabled
Here is the call graph for this function:

◆ json_wr_start_array_obj()

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

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
modnamemodule name of JSON object (NULL to omit)
namename of JSON object
objobject to use
startindentstart indent amount if indent enabled
startbraceTRUE to print start brace
startbracketTRUE to print start bracket
Here is the call graph for this function:

◆ json_wr_start_array_val()

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

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
valvalue node to output
startindentstart indent amount if indent enabled
startbraceTRUE to print start brace
startbracketTRUE to print start bracket
Here is the call graph for this function:

◆ json_wr_start_object()

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

Parameters
scbsession control block to use for writing
msgxml_msg_hdr_t in progress
modnamemodule name of JSON object (NULL to omit)
namename of JSON object
startindentstart indent amount if indent enabled
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_wr_start_object_ex()

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)

Parameters
scbsession control block to use for writing
msgxml_msg_hdr_t in progress
modnamemodule name of JSON object (NULL to omit)
namename of JSON object
startindentstart indent amount if indent enabled
startbraceTRUE to print start brace
endbraceTRUE to print start brace
Here is the call graph for this function:

◆ json_wr_start_object_obj()

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

Parameters
scbsession control block to use for writing
msgxml_msg_hdr_t in progress
modnamemodule name of JSON object (NULL to omit)
namename of JSON object
objobject template to use for JSON start
startindentstart indent amount if indent enabled
Here is the call graph for this function:

◆ json_wr_start_object_val()

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

Generate start JSON for a val_value_t struct

Parameters
scbsession control block
msgxml_msg_hdr_t in progress
valvalue node to output
startindentstart indent amount if indent enabled
Here is the call graph for this function: