yumapro  20.10-10
YumaPro SDK

XPath 1.0 parser implementation used by multiple programs. More...

Collaboration diagram for XPath1 Parser:

Macros

#define SET_SKIP_MODE(pcb)   (pcb)->flags |= XP_FL_SKIP_MODE
 Set the current skip mode active used only by internal xpath1_pred.c XPath requires that AND and OR expressions only be evaluated until the final value is known. More...
 
#define CLEAR_SKIP_MODE(pcb)   (pcb)->flags &= ~XP_FL_SKIP_MODE
 Clear the current skip mode.
 
#define IS_SKIP_MODE(pcb)   ((pcb)->flags & XP_FL_SKIP_MODE)
 Check if skip mode is active.
 

Functions

status_t xpath1_parse_expr (tk_chain_t *tkc, ncx_module_t *mod, xpath_pcb_t *pcb, xpath_source_t source)
 Parse the XPATH 1.0 expression string. More...
 
status_t xpath1_validate_expr (ncx_module_t *mod, obj_template_t *obj, xpath_pcb_t *pcb)
 Validate the previously parsed expression string. More...
 
status_t xpath1_validate_expr_ex (ncx_module_t *mod, obj_template_t *obj, xpath_pcb_t *pcb, boolean missing_is_error, boolean set_backptrs, ncx_xpath_type_t backptr_type)
 Validate the previously parsed expression string. More...
 
xpath_result_txpath1_eval_expr (xpath_pcb_t *pcb, val_value_t *val, val_value_t *docroot, boolean logerrors, boolean configonly, status_t *res)
 Evaluate an XPath expression use if the prefixes are YANG: must/when. More...
 
xpath_result_txpath1_eval_expr2 (xpath_pcb_t *pcb, val_value_t *val, val_value_t *docroot, boolean logerrors, boolean configonly, boolean force_only, status_t *res)
 Evaluate an XPath expression (alt) More...
 
xpath_result_txpath1_eval_expr3 (xpath_pcb_t *pcb, val_value_t *val, val_value_t *docroot, boolean logerrors, boolean configonly, boolean force_only, xml_msg_hdr_t *get2_mhdr, boolean get_when, xpath_get2_node_t *val_get2, status_t *res)
 Evaluate an XPath expression (alt3) More...
 
status_t xpath1_test_data_rule (xpath_pcb_t *pcb, getcb_get2_t *get2cb, boolean *testres)
 Test a NACM data rule expression against a GET2 control block. More...
 
xpath_result_txpath1_eval_xmlexpr (xmlTextReaderPtr reader, xpath_pcb_t *pcb, val_value_t *val, val_value_t *docroot, boolean logerrors, boolean configonly, status_t *res)
 Evaluate an XML document expression. More...
 
void xpath1_prune_nodeset (xpath_pcb_t *pcb, xpath_result_t *result)
 Check the current result nodeset and remove any redundant nodes from a NETCONF POV. More...
 
boolean xpath1_check_node_exists (xpath_pcb_t *pcb, dlq_hdr_t *resultQ, const val_value_t *val)
 Check if any ancestor-ot-self node is already in the specified Q. More...
 
boolean xpath1_check_node_exists_slow (xpath_pcb_t *pcb, dlq_hdr_t *resultQ, const val_value_t *val)
 Check if any ancestor-ot-self node is already in the specified Q Slow version. More...
 
boolean xpath1_check_resnode_exists (xpath_pcb_t *pcb, dlq_hdr_t *resultQ, xpath_resnode_t *resnode)
 Check if any ancestor-ot-self node is already in the specified Q. More...
 
status_t xpath1_stringify_nodeset (xpath_pcb_t *pcb, const xpath_result_t *result, xmlChar **str)
 Convert a value node pointer to a string node. More...
 
status_t xpath1_stringify_node (xpath_pcb_t *pcb, val_value_t *val, xmlChar **str)
 Convert a value node to a string node. More...
 
boolean xpath1_compare_result_to_string (xpath_pcb_t *pcb, xpath_result_t *result, xmlChar *strval, status_t *res)
 Compare an XPath result to the specified string. More...
 
boolean xpath1_compare_result_to_number (xpath_pcb_t *pcb, xpath_result_t *result, ncx_num_t *numval, status_t *res)
 Compare an XPath result to the specified number. More...
 
boolean xpath1_compare_nodeset_results (xpath_pcb_t *pcb, xpath_result_t *result1, xpath_result_t *result2, status_t *res)
 Compare an XPath result to another result. More...
 
boolean xpath1_find_val_in_nodeset (xpath_result_t *result, const xmlChar *valstr)
 Check a nodeset result and find the same value in one of the nodes. More...
 
boolean xpath1_find_val_in_nodeset_ex (xpath_result_t *result, val_value_t *testval)
 Check a nodeset result and find the same value in one of the nodes. More...
 
xpath_result_txpath1_parse_expr_int (xpath_pcb_t *pcb, status_t *res)
 Parse an XPath Expr sequence It has already been tokenized. More...
 
xpath_result_txpath1_parse_relational_expr_int (xpath_pcb_t *pcb, status_t *res)
 Parse an XPath Relational Expr sequence It has already been tokenized. More...
 
boolean xpath1_keep_object (obj_template_t *testobj, boolean textmode, xmlns_id_t nsid, const xmlChar *name)
 Test if an object should be kept in a resnode node-test. More...
 
void xpath1_dump_result (log_debug_t lvl, xpath_pcb_t *pcb, xpath_result_t *result, const char *banner)
 Generate log output displaying the contents of a result. More...
 
void xpath1_dump_resnode (log_debug_t lvl, xpath_resnode_t *resnode, const char *banner)
 Generate log output displaying the contents of an XPath resnode. More...
 
boolean xpath1_cmp_results (xpath_pcb_t *pcb, xpath_result_t *val1, xpath_result_t *val2, xpath_exop_t exop, status_t *res)
 Compare 2 results, using the specified logic operator. More...
 
const xpath_fncb_txpath1_fn_get_functions_ptr (void)
 Get the start of the function array for XPath 1.0 plus the current() function. More...
 
status_t xpath1_pred_parse_predicate (xpath_pcb_t *pcb, xpath_result_t **result)
 Parse an XPath Predicate sequence It has already been tokenized. More...
 
status_t xpath_wr_expr (ses_cb_t *scb, val_value_t *xpathval)
 Write the specified XPath expression to the current session using the default prefixes. More...
 

Detailed Description

XPath 1.0 parser implementation used by multiple programs.

Debug function to write an Xpath expression.

XPath 1.0 predicate parsing support.

XPath 1.0 function library support.

XPath 1.0 parser compare support.

Macro Definition Documentation

#define SET_SKIP_MODE (   pcb)    (pcb)->flags |= XP_FL_SKIP_MODE

Set the current skip mode active used only by internal xpath1_pred.c XPath requires that AND and OR expressions only be evaluated until the final value is known.

Skip mode allows the tokens to be skipped without processing the sub-expression

Function Documentation

boolean xpath1_check_node_exists ( xpath_pcb_t pcb,
dlq_hdr_t *  resultQ,
const val_value_t val 
)

Check if any ancestor-ot-self node is already in the specified Q.

ONLY FOR VALUE NODES IN THE RESULT

This is only done after all the nodes have been processed and the nodeset is complete. For NETCONF purposes, the entire path to root is added for the context node, and the entire context node contexts are always returned

Parameters
pcbparser control block to use
resultQQ of xpath_resnode_t structs to check
DOES NOT HAVE TO BE WITHIN A RESULT NODE Q
valvalue node pointer value to find
Returns
TRUE if found, FALSE otherwise

Here is the call graph for this function:

boolean xpath1_check_node_exists_slow ( xpath_pcb_t pcb,
dlq_hdr_t *  resultQ,
const val_value_t val 
)

Check if any ancestor-ot-self node is already in the specified Q Slow version.

ONLY FOR VALUE NODES IN THE RESULT

This is only done after all the nodes have been processed and the nodeset is complete. For NETCONF purposes, the entire path to root is added for the context node, and the entire context node contexts are always returned

Parameters
pcbparser control block to use
resultQQ of xpath_resnode_t structs to check
DOES NOT HAVE TO BE WITHIN A RESULT NODE Q
valvalue node pointer value to find
Returns
TRUE if found, FALSE otherwise

Here is the call graph for this function:

boolean xpath1_check_resnode_exists ( xpath_pcb_t pcb,
dlq_hdr_t *  resultQ,
xpath_resnode_t resnode 
)

Check if any ancestor-ot-self node is already in the specified Q.

ONLY FOR VALUE NODES IN THE RESULT

This is only done after all the nodes have been processed and the nodeset is complete. For NETCONF purposes, the entire path to root is added for the context node, and the entire context node contexts are always returned

Parameters
pcbparser control block to use
resultQQ of xpath_resnode_t structs to check
DOES NOT HAVE TO BE WITHIN A RESULT NODE Q
resnoderesnode to find
Returns
TRUE if found, FALSE otherwise

Here is the call graph for this function:

boolean xpath1_cmp_results ( xpath_pcb_t pcb,
xpath_result_t val1,
xpath_result_t val2,
xpath_exop_t  exop,
status_t res 
)

Compare 2 results, using the specified logic operator.

Parameters
pcbparser control block to use
val1first result struct to compare
val2second result struct to compare
exopXPath exression operator to use
resaddress of resturn status
Return values
*resreturn status
Returns
relation result (TRUE or FALSE)

Here is the call graph for this function:

Here is the caller graph for this function:

boolean xpath1_compare_nodeset_results ( xpath_pcb_t pcb,
xpath_result_t result1,
xpath_result_t result2,
status_t res 
)

Compare an XPath result to another result.

  • result1 = node-set
  • result2 = node-set
Parameters
pcbparser control block to use
result1result1 struct to compare
result2result2 struct to compare
resaddress of return status
Return values
*resreturn status
Returns
equality relation result (TRUE or FALSE)

Here is the call graph for this function:

boolean xpath1_compare_result_to_number ( xpath_pcb_t pcb,
xpath_result_t result,
ncx_num_t numval,
status_t res 
)

Compare an XPath result to the specified number.

result = number

Parameters
pcbparser control block to use
resultresult struct to compare
numvalnumber struct to compare to result MUST BE TYPE NCX_BT_FLOAT64
resaddress of return status
Return values
*resreturn status
Returns
equality relation result (TRUE or FALSE)

Here is the call graph for this function:

boolean xpath1_compare_result_to_string ( xpath_pcb_t pcb,
xpath_result_t result,
xmlChar *  strval,
status_t res 
)

Compare an XPath result to the specified string.

result = 'string'

Parameters
pcbparser control block to use
resultresult struct to compare
strvalstring value to compare to result
resaddress of return status
Return values
*resreturn status
Returns
equality relation result (TRUE or FALSE)

Here is the call graph for this function:

void xpath1_dump_resnode ( log_debug_t  lvl,
xpath_resnode_t resnode,
const char *  banner 
)

Generate log output displaying the contents of an XPath resnode.

Debugging function

Parameters
lvldebug level for output
resnoderesnode to dump
banneroptional first banner string to use
void xpath1_dump_result ( log_debug_t  lvl,
xpath_pcb_t pcb,
xpath_result_t result,
const char *  banner 
)

Generate log output displaying the contents of a result.

Debugging function

Parameters
lvldebug level for output
pcbparser control block to use
resultresult to dump
banneroptional first banner string to use

Here is the call graph for this function:

Here is the caller graph for this function:

xpath_result_t* xpath1_eval_expr ( xpath_pcb_t pcb,
val_value_t val,
val_value_t docroot,
boolean  logerrors,
boolean  configonly,
status_t res 
)

Evaluate an XPath expression use if the prefixes are YANG: must/when.

Evaluate the expression and get the expression nodeset result

Parameters
pcbXPath parser control block to use
valstart context node for value of current()
docrootptr to cfg->root or top of rpc/rpc-replay/notif tree
logerrorsTRUE if log_error and ncx_print_errormsg should be used to log XPath errors and warnings
FALSE if internal error info should be recorded in the xpath_result_t struct instead
configonlyconfig mode
            XP_SRC_XML:
                  TRUE if this is a <get-config> call
                  and all config=false nodes should be skipped
                  FALSE if <get> call and non-config nodes
                  will not be skipped
            XP_SRC_YANG and XP_SRC_LEAFREF:
                  should be set to false
resaddress of return status
Return values
*resis set to the return status
Returns
malloced result struct with expr result NULL if no result produced (see *res for reason)

Here is the call graph for this function:

Here is the caller graph for this function:

xpath_result_t* xpath1_eval_expr2 ( xpath_pcb_t pcb,
val_value_t val,
val_value_t docroot,
boolean  logerrors,
boolean  configonly,
boolean  force_only,
status_t res 
)

Evaluate an XPath expression (alt)

use if the prefixes are YANG: must/when Evaluate the expression and get the expression nodeset result

Parameters
pcbXPath parser control block to use
valstart context node for value of current()
docrootptr to cfg->root or top of rpc/rpc-replay/notif tree
logerrorsTRUE if log_error and ncx_print_errormsg should be used to log XPath errors and warnings
FALSE if internal error info should be recorded in the xpath_result_t struct instead
configonlyconfig mode
            XP_SRC_XML:
                  TRUE if this is a <get-config> call
                  and all config=false nodes should be skipped
                  FALSE if <get> call and non-config nodes
                  will not be skipped
            XP_SRC_YANG and XP_SRC_LEAFREF:
                  should be set to false
force_onlyTRUE to force configonly == FALSE
resaddress of return status
Return values
*resis set to the return status
Returns
malloced result struct with expr result NULL if no result produced (see *res for reason)

Here is the call graph for this function:

xpath_result_t* xpath1_eval_expr3 ( xpath_pcb_t pcb,
val_value_t val,
val_value_t docroot,
boolean  logerrors,
boolean  configonly,
boolean  force_only,
xml_msg_hdr_t get2_mhdr,
boolean  get_when,
xpath_get2_node_t val_get2,
status_t res 
)

Evaluate an XPath expression (alt3)

use if the prefixes are YANG: must/when Evaluate the expression and get the expression nodeset result

Parameters
pcbXPath parser control block to use
valstart context node for value of current()
docrootptr to cfg->root or top of rpc/rpc-replay/notif tree
logerrorsTRUE if log_error and ncx_print_errormsg should be used to log XPath errors and warnings
FALSE if internal error info should be recorded in the xpath_result_t struct instead
configonlyconfig mode
            XP_SRC_XML:
                  TRUE if this is a <get-config> call
                  and all config=false nodes should be skipped
                  FALSE if <get> call and non-config nodes
                  will not be skipped
            XP_SRC_YANG and XP_SRC_LEAFREF:
                  should be set to false
force_onlyTRUE to force configonly == FALSE
get2_mhdrmessage header to use if GET2 callbacks will be used
get_whenTRUE if this eval is for a when-stmt in a data node so all the value will be retrieved instead of using temp values with a wlaker callback; FALSE == normal
val_get2XPAth GET2 node to use as the context node instead of 'val'
resaddress of return status
Return values
*resis set to the return status
Returns
malloced result struct with expr result

Here is the call graph for this function:

Here is the caller graph for this function:

xpath_result_t* xpath1_eval_xmlexpr ( xmlTextReaderPtr  reader,
xpath_pcb_t pcb,
val_value_t val,
val_value_t docroot,
boolean  logerrors,
boolean  configonly,
status_t res 
)

Evaluate an XML document expression.

use if the prefixes are XML: select Evaluate the expression and get the expression nodeset result Called from inside the XML parser, so the XML reader must be used to get the XML namespace to prefix mappings

Parameters
readerXML reader to use
pcbXPath parser control block to use
valstart context node for value of current()
docrootptr to cfg->root or top of rpc/rpc-replay/notif tree
logerrorsTRUE if log_error and ncx_print_errormsg should be used to log XPath errors and warnings
FALSE if internal error info should be recorded in the xpath_result_t struct instead
configonlyconfig mode
            XP_SRC_XML:
                  TRUE if this is a <get-config> call
                  and all config=false nodes should be skipped
                  FALSE if <get> call and non-config nodes
                  will not be skipped
            XP_SRC_YANG and XP_SRC_LEAFREF:
                  should be set to false
resaddress of return status
Return values
*resis set to the return status
Returns
malloced result struct with expr result NULL if no result produced (see *res for reason)

Here is the call graph for this function:

Here is the caller graph for this function:

boolean xpath1_find_val_in_nodeset ( xpath_result_t result,
const xmlChar *  valstr 
)

Check a nodeset result and find the same value in one of the nodes.

Parameters
resultresult struct to compare
valstrvalue string to find
Returns
TRUE if string found

Here is the call graph for this function:

Here is the caller graph for this function:

boolean xpath1_find_val_in_nodeset_ex ( xpath_result_t result,
val_value_t testval 
)

Check a nodeset result and find the same value in one of the nodes.

Use val_value instead of plain string to make sure that in case of idref node the string value will be evaluated accordingly

Parameters
resultresult struct to compare
testvalvalue to find and compare with
Returns
TRUE if string found

Here is the call graph for this function:

Here is the caller graph for this function:

const xpath_fncb_t* xpath1_fn_get_functions_ptr ( void  )

Get the start of the function array for XPath 1.0 plus the current() function.

Returns
pointer to functions array

Here is the caller graph for this function:

boolean xpath1_keep_object ( obj_template_t testobj,
boolean  textmode,
xmlns_id_t  nsid,
const xmlChar *  name 
)

Test if an object should be kept in a resnode node-test.

Support for the node-test rule in XPath 1.0 Any test present can cause the node to be excluded Default is keep if all test params off

Parameters
testobjobject to test
textmodetrue if testing for text nodes; false to ignore
nsidchild node NSID or 0 for any
namechild name or NULL if any
Returns
TRUE if passes test to keep

Here is the call graph for this function:

status_t xpath1_parse_expr ( tk_chain_t tkc,
ncx_module_t mod,
xpath_pcb_t pcb,
xpath_source_t  source 
)

Parse the XPATH 1.0 expression string.

Main API entry point

parse initial expr with YANG prefixes: must/when the object is left out in case it is in a grouping

This is just a first pass done when the XPath string is consumed. If this is a YANG file source then the prefixes will be checked against the 'mod' import Q

The expression is parsed into XPath tokens and checked for well-formed syntax and function invocations. Any variable

If the source is XP_SRC_INSTANCEID, then YANG instance-identifier syntax is followed, not XPath 1.0 This is only used by instance-identifiers in default-stmt, conf file, CLI, etc.

Error messages are printed by this function!! Do not duplicate error messages upon error return

Parameters
tkcparent token chain
modmodule in progress
pcbinitialized xpath parser control block for the expression; use xpath_new_pcb to initialize before calling this fn The pcb->exprstr MUST BE SET BEFORE THIS CALL
sourceenum indicating source of this expression
Return values
pcb->tkcis filled and then partially validated
pcb->parseresis set
Returns
status

Here is the call graph for this function:

Here is the caller graph for this function:

xpath_result_t* xpath1_parse_expr_int ( xpath_pcb_t pcb,
status_t res 
)

Parse an XPath Expr sequence It has already been tokenized.

Error messages are printed by this function!! Do not duplicate error messages upon error return

[14] Expr ::= OrExpr

Parameters
pcbparser control block in progress
resaddress of result status
Return values
*resExpression result status
Returns
pointer to malloced result struct or NULL if no result processing in effect

Here is the caller graph for this function:

xpath_result_t* xpath1_parse_relational_expr_int ( xpath_pcb_t pcb,
status_t res 
)

Parse an XPath Relational Expr sequence It has already been tokenized.

Parameters
pcbparser control block in progress
resaddress of result status
Return values
*resExpression result status
Returns
pointer to malloced result struct or NULL if no result processing in effect
status_t xpath1_pred_parse_predicate ( xpath_pcb_t pcb,
xpath_result_t **  result 
)

Parse an XPath Predicate sequence It has already been tokenized.

Error messages are printed by this function!! Do not duplicate error messages upon error return

  [8] Predicate ::= '[' PredicateExpr ']'
  [9] PredicateExpr ::= Expr
Parameters
pcbparser control block in progress
resultaddress of result in progress to filter *result may be NULL only if IS_SKIP_MODE is TRUE
Return values
*resultmay be pruned based on filter matches nodes may be updated if descendants are checked and matches are found;
Returns
status

Here is the call graph for this function:

void xpath1_prune_nodeset ( xpath_pcb_t pcb,
xpath_result_t result 
)

Check the current result nodeset and remove any redundant nodes from a NETCONF POV.

Any node that has an ancestor already in the result will be deleted

Parameters
pcbXPath parser control block to use
resultXPath result nodeset to prune
Return values
result->nodeQcontents may be adjusted or removed

Here is the call graph for this function:

Here is the caller graph for this function:

status_t xpath1_stringify_node ( xpath_pcb_t pcb,
val_value_t val,
xmlChar **  str 
)

Convert a value node to a string node.

string(node)

Parameters
pcbparser control block to use
valvalue node to stringify
straddress of return string
Return values
*strmalloced and filled in string (if NO_ERR)
Returns
status, NO_ER or ERR_INTERNAL_MEM, etc.

Here is the call graph for this function:

Here is the caller graph for this function:

status_t xpath1_stringify_nodeset ( xpath_pcb_t pcb,
const xpath_result_t result,
xmlChar **  str 
)

Convert a value node pointer to a string node.

ONLY FOR VALUE NODES IN THE RESULT

string(nodeset)

Parameters
pcbparser control block to use
resultresult to stringify
straddress of return string
Return values
*strmalloced and filled in string (if NO_ERR)
Returns
status, NO_ER or ERR_INTERNAL_MEM, etc.

Here is the call graph for this function:

Here is the caller graph for this function:

status_t xpath1_test_data_rule ( xpath_pcb_t pcb,
getcb_get2_t get2cb,
boolean *  testres 
)

Test a NACM data rule expression against a GET2 control block.

Determine if the specified data node is covered by the rule in the pcb

Parameters
pcbthe XPath parser control block to process
get2cbGET2 control block to use
testresaddress of test result
Return values
*testresTRUE if the expression applies to the get2cb
== FALSE if the expression does not apply
Returns
status

Here is the call graph for this function:

status_t xpath1_validate_expr ( ncx_module_t mod,
obj_template_t obj,
xpath_pcb_t pcb 
)

Validate the previously parsed expression string.

  • QName prefixes are valid
  • function calls are well-formed and exist in the pcb->functions array
  • variable references exist in the pcb->varbindQ

parse expr with YANG prefixes: must/when called from final OBJ xpath check after all cooked objects are in place

Called after all 'uses' and 'augment' expansion so validation against cooked object tree can be done

Error messages are printed by this function!! Do not duplicate error messages upon error return

Parameters
modmodule containing the 'obj' (in progress)
objobject containing the XPath clause
pcbthe XPath parser control block to process
Return values
pcb->objand pcb->objmod are set
pcb->validateresis set
Returns
status

Here is the call graph for this function:

Here is the caller graph for this function:

status_t xpath1_validate_expr_ex ( ncx_module_t mod,
obj_template_t obj,
xpath_pcb_t pcb,
boolean  missing_is_error,
boolean  set_backptrs,
ncx_xpath_type_t  backptr_type 
)

Validate the previously parsed expression string.

  • QName prefixes are valid
  • function calls are well-formed and exist in the pcb->functions array
  • variable references exist in the &pcb->varbindQ

parse expr with YANG prefixes: must/when called from final OBJ xpath check after all cooked objects are in place

Called after all 'uses' and 'augment' expansion so validation against cooked object tree can be done

Error messages are printed by this function!! Do not duplicate error messages upon error return

Parameters
modmodule containing the 'obj' (in progress)
objobject containing the XPath clause
pcbthe XPath parser control block to process
missing_is_errorTRUE if a missing node is an error
== FALSE if a warning
set_backptrsTRUE if this is the special mode to go through the expression and set obj_template_t back ptrs; used only by the server is ncx_use_xpath_backptrs()
== FALSE for normal mode
backptr_typeenum identifying xpath_backptr type ignored unless set_backptrs == TRUE
Return values
pcb->objand pcb->objmod are set
pcb->validateresis set
Returns
status

Here is the call graph for this function:

Here is the caller graph for this function:

status_t xpath_wr_expr ( ses_cb_t scb,
val_value_t xpathval 
)

Write the specified XPath expression to the current session using the default prefixes.

The XPath pcb must be previously parsed and found valid

Parameters
scbsession control block to use
xpathvalthe value containing the XPath expr to write
Returns
status

Here is the call graph for this function: