sysrepo  3.0.0
YANG-based system repository for all-around configuration management.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
XPath Processing Utilities

Set of helpers working on a subset of xpath expressions used of node identification Functions modify inputs arguments by placing termination zero at appropriate places to save up string duplication. The state of processing is stored in sr_xpath_ctx_t opaque for user. It allows to continue in processing where the processing stopped or recover processed input. More...

Data Structures

struct  sr_xpath_ctx_s
 State of xpath parsing. User must not modify nor rely on the content of the structure. More...
 

Typedefs

typedef struct sr_xpath_ctx_s sr_xpath_ctx_t
 State of xpath parsing. User must not modify nor rely on the content of the structure. More...
 

Functions

char * sr_xpath_key_value (char *xpath, const char *node_name, const char *key_name, sr_xpath_ctx_t *state)
 Looks up the value of the key in a node specified by name. More...
 
char * sr_xpath_key_value_idx (char *xpath, size_t node_index, size_t key_index, sr_xpath_ctx_t *state)
 Looks up the value of the key in a node specified by index. First node has index zero. More...
 
char * sr_xpath_last_node (char *xpath, sr_xpath_ctx_t *state)
 Returns pointer to the last node. More...
 
char * sr_xpath_next_key_name (char *xpath, sr_xpath_ctx_t *state)
 Returns the name of the next key at the current level in processed xpath. More...
 
char * sr_xpath_next_key_value (char *xpath, sr_xpath_ctx_t *state)
 Returns the value of the next key at the current level in processed xpath. More...
 
char * sr_xpath_next_node (char *xpath, sr_xpath_ctx_t *state)
 The function returns a pointer to the following node. If xpath is not NULL returns the first node name, otherwise returns the subsequent node according to the state. More...
 
char * sr_xpath_next_node_with_ns (char *xpath, sr_xpath_ctx_t *state)
 Same as sr_xpath_next_node with the difference that namespace is included in result if present in xpath. More...
 
char * sr_xpath_node (char *xpath, const char *node_name, sr_xpath_ctx_t *state)
 Returns a pointer to the node specified by name. It searches from the beginning of the xpath, returns first match. Can be used to jump at the desired node xpath and subsequent analysis of key values. More...
 
char * sr_xpath_node_idx (char *xpath, size_t index, sr_xpath_ctx_t *state)
 Returns node specified by index starting at the begin of expression. First node has index 0. More...
 
char * sr_xpath_node_idx_rel (char *xpath, size_t index, sr_xpath_ctx_t *state)
 Return node specified by index. Following node has index zero. More...
 
char * sr_xpath_node_key_value (char *xpath, const char *key, sr_xpath_ctx_t *state)
 Looks up the value for the key at the current level in xpath. More...
 
char * sr_xpath_node_key_value_idx (char *xpath, size_t index, sr_xpath_ctx_t *state)
 Looks up the value for the key at the current level in xpath specified by index. First key has index zero. More...
 
char * sr_xpath_node_name (const char *xpath)
 Returns pointer to the string after the last slash in xpath (node name). More...
 
int sr_xpath_node_name_eq (const char *xpath, const char *node_str)
 Compares string after the last slash in xpath (node name) with provided string. More...
 
char * sr_xpath_node_rel (char *xpath, const char *node_name, sr_xpath_ctx_t *state)
 Similar to sr_xpath_node. The difference is that search start at current node according to the state. More...
 
void sr_xpath_recover (sr_xpath_ctx_t *state)
 Recovers the xpath string to the original state (puts back the character that was replaced by termination zero). More...
 

Detailed Description

Set of helpers working on a subset of xpath expressions used of node identification Functions modify inputs arguments by placing termination zero at appropriate places to save up string duplication. The state of processing is stored in sr_xpath_ctx_t opaque for user. It allows to continue in processing where the processing stopped or recover processed input.

Similarly to strtok function in all subsequent calls that is supposed to work with the same input xpath must be NULL.

Note
All of these functions are quite inefficient! If that matters, it is best not to use them.

Data Structure Documentation

struct sr_xpath_ctx_s

State of xpath parsing. User must not modify nor rely on the content of the structure.

Definition at line 45 of file xpath.h.

Data Fields
char * begining

Pointer to the begining of the processed string

char * current_node

Pointer to the currently processed node, used as a context for key search

char replaced_char

Character that was overwritten by the last termination 0

char * replaced_position

Pointer to the posistion where the last terminating 0 by was written

Typedef Documentation

State of xpath parsing. User must not modify nor rely on the content of the structure.

Function Documentation

char* sr_xpath_key_value ( char *  xpath,
const char *  node_name,
const char *  key_name,
sr_xpath_ctx_t state 
)

Looks up the value of the key in a node specified by name.

Parameters
[in]xpath
[in]node_name
[in]key_name
[in]state
Returns
Pointer to the key value, NULL if not found
char* sr_xpath_key_value_idx ( char *  xpath,
size_t  node_index,
size_t  key_index,
sr_xpath_ctx_t state 
)

Looks up the value of the key in a node specified by index. First node has index zero.

Parameters
[in]xpath
[in]node_index
[in]key_index
[in]state
Returns
Pointer to the key value, NULL if not found or index out of bound
char* sr_xpath_last_node ( char *  xpath,
sr_xpath_ctx_t state 
)

Returns pointer to the last node.

Parameters
[in]xpath
[in]state
Returns
Pointer to the last node
char* sr_xpath_next_key_name ( char *  xpath,
sr_xpath_ctx_t state 
)

Returns the name of the next key at the current level in processed xpath.

Parameters
[in]xpath
[in]state
Returns
Pointer to the key name, NULL if there are no more keys at the current level
char* sr_xpath_next_key_value ( char *  xpath,
sr_xpath_ctx_t state 
)

Returns the value of the next key at the current level in processed xpath.

Parameters
[in]xpath
[in]state
Returns
Pointer to the key value, NULL if there are no more keys at the current level
char* sr_xpath_next_node ( char *  xpath,
sr_xpath_ctx_t state 
)

The function returns a pointer to the following node. If xpath is not NULL returns the first node name, otherwise returns the subsequent node according to the state.

The state is modified upon function successful return from function, so the subsequent calls can continue in processing or xpath can be recovered by calling sr_xpath_recover.

Note
It writes terminating zero at the and of the node name.
Skips the namespace if it is present to get node name qualified by namespace use sr_xpath_next_node_with_ns
Parameters
[in]xpath- xpath to be processed, can be NULL
[in]state
Returns
Pointer to the node name, NULL if there are no more node names
char* sr_xpath_next_node_with_ns ( char *  xpath,
sr_xpath_ctx_t state 
)

Same as sr_xpath_next_node with the difference that namespace is included in result if present in xpath.

Parameters
[in]xpath- xpath to be processed, can be NULL if the user wants to continue in processing of previous input
[in]state
Returns
Pointer to the node name including namespace, NULL if there are no more node names
char* sr_xpath_node ( char *  xpath,
const char *  node_name,
sr_xpath_ctx_t state 
)

Returns a pointer to the node specified by name. It searches from the beginning of the xpath, returns first match. Can be used to jump at the desired node xpath and subsequent analysis of key values.

Parameters
[in]xpath
[in]node_name
[in]state
Returns
Pointer to the node, NULL if the node with the specified name is not found
char* sr_xpath_node_idx ( char *  xpath,
size_t  index,
sr_xpath_ctx_t state 
)

Returns node specified by index starting at the begin of expression. First node has index 0.

Parameters
[in]xpath
[in]index
[in]state
Returns
Pointer to the specified node, NULL if the index is out of bounds
char* sr_xpath_node_idx_rel ( char *  xpath,
size_t  index,
sr_xpath_ctx_t state 
)

Return node specified by index. Following node has index zero.

Parameters
[in]xpath
[in]index
[in]state
Returns
Pointer to the specified node, NULL if the index is out of bounds
char* sr_xpath_node_key_value ( char *  xpath,
const char *  key,
sr_xpath_ctx_t state 
)

Looks up the value for the key at the current level in xpath.

Parameters
[in]xpath
[in]key- key name to be looked up
[in]state
Returns
Key value, NULL if the key with the specified name is not found
char* sr_xpath_node_key_value_idx ( char *  xpath,
size_t  index,
sr_xpath_ctx_t state 
)

Looks up the value for the key at the current level in xpath specified by index. First key has index zero.

Parameters
[in]xpath
[in]index
[in]state
Returns
Key value, NULL if the index is out of bound
char* sr_xpath_node_name ( const char *  xpath)

Returns pointer to the string after the last slash in xpath (node name).

Note
The returned string can also contain namespace and/or key values if they were specified for the last node in xpath.
Parameters
[in]xpath
Returns
Result, NULL in case of the slash was not found
int sr_xpath_node_name_eq ( const char *  xpath,
const char *  node_str 
)

Compares string after the last slash in xpath (node name) with provided string.

Note
The returned string can also contain namespace and/or key values if they were specified for the last node in xpath.
Parameters
[in]xpath
[in]node_strString to test for equality.
Returns
true in case that the Node names are equal, false otherwise
char* sr_xpath_node_rel ( char *  xpath,
const char *  node_name,
sr_xpath_ctx_t state 
)

Similar to sr_xpath_node. The difference is that search start at current node according to the state.

Parameters
[in]xpath
[in]node_name
[in]state
Returns
Pointer to the node, NULL if the node with the specified name is not found
void sr_xpath_recover ( sr_xpath_ctx_t state)

Recovers the xpath string to the original state (puts back the character that was replaced by termination zero).

Parameters
[in]state