Misc formatting

This commit is contained in:
Olof hagsand 2025-01-10 16:27:40 +01:00
parent 43d9bc845d
commit 3be786c211
7 changed files with 165 additions and 168 deletions

View file

@ -1,7 +1,7 @@
/* /*
* *
***** BEGIN LICENSE BLOCK ***** ***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate) Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate)
@ -25,14 +25,14 @@
in which case the provisions of the GPL are applicable instead in which case the provisions of the GPL are applicable instead
of those above. If you wish to allow use of your version of this file only of those above. If you wish to allow use of your version of this file only
under the terms of the GPL, and not to allow others to under the terms of the GPL, and not to allow others to
use your version of this file under the terms of Apache License version 2, use your version of this file under the terms of Apache License version 2,
indicate your decision by deleting the provisions above and replace them with indicate your decision by deleting the provisions above and replace them with
the notice and other provisions required by the GPL. If you do not delete the notice and other provisions required by the GPL. If you do not delete
the provisions above, a recipient may use your version of this file under the provisions above, a recipient may use your version of this file under
the terms of any one of the Apache License version 2 or the GPL. the terms of any one of the Apache License version 2 or the GPL.
***** END LICENSE BLOCK ***** ***** END LICENSE BLOCK *****
* *
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -191,8 +191,8 @@ cli_signal_flush(clixon_handle h)
* @param[in] cvv * @param[in] cvv
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* Create and add an XML body as child of XML node xbot. Set its value to the last * Create and add an XML body as child of XML node xbot. Set its value to the last
* CLI variable vector element. * CLI variable vector element.
*/ */
int int
dbxml_body(cxobj *xbot, dbxml_body(cxobj *xbot,
@ -364,8 +364,8 @@ mtpoint_paths(yang_stmt *yspec0,
/*! Modify xml datastore from a callback using xml key format strings /*! Modify xml datastore from a callback using xml key format strings
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables * @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Arguments given at the callback: * @param[in] argv Arguments given at the callback:
* <api_path_fmt> Generated API PATH (this is added implicitly, not actually given in the cvv) * <api_path_fmt> Generated API PATH (this is added implicitly, not actually given in the cvv)
* <api_path_fmt>* Added by merge in treeref_merge_co * <api_path_fmt>* Added by merge in treeref_merge_co
* [<mt-point>] Optional YANG path-arg/xpath from mount-point * [<mt-point>] Optional YANG path-arg/xpath from mount-point
@ -383,8 +383,8 @@ mtpoint_paths(yang_stmt *yspec0,
* argv[0] = "/interfaces/interface/%s/type" * argv[0] = "/interfaces/interface/%s/type"
* op: OP_MERGE * op: OP_MERGE
* @see cli_callback_generate where arg is generated * @see cli_callback_generate where arg is generated
* @note The last value may require namespace binding present in nsctx. Note that the nsctx * @note The last value may require namespace binding present in nsctx. Note that the nsctx
* cannot normally be supplied by the clispec functions, such as cli_set, but need to be * cannot normally be supplied by the clispec functions, such as cli_set, but need to be
* generated by a function such as clixon_instance_id_bind() or other programmatically. * generated by a function such as clixon_instance_id_bind() or other programmatically.
*/ */
int int
@ -439,7 +439,7 @@ cli_dbxml(clixon_handle h,
/* Get and combined api-path01 */ /* Get and combined api-path01 */
if (mtpoint_paths(yspec0, mtpoint, api_path_fmt, &api_path_fmt01) < 0) if (mtpoint_paths(yspec0, mtpoint, api_path_fmt, &api_path_fmt01) < 0)
goto done; goto done;
/* Transform template format string + cvv to actual api-path /* Transform template format string + cvv to actual api-path
* cvvi indicates if all cvv entries were used * cvvi indicates if all cvv entries were used
*/ */
if (api_path_fmt2api_path(api_path_fmt01, cvv, yspec0, &api_path, &cvvi) < 0) if (api_path_fmt2api_path(api_path_fmt01, cvv, yspec0, &api_path, &cvvi) < 0)
@ -447,7 +447,7 @@ cli_dbxml(clixon_handle h,
} }
else { else {
/* Only top-level tree */ /* Only top-level tree */
/* Transform template format string + cvv to actual api-path /* Transform template format string + cvv to actual api-path
* cvvi indicates if all cvv entries were used * cvvi indicates if all cvv entries were used
*/ */
if (api_path_fmt2api_path(api_path_fmt, cvv, yspec0, &api_path, &cvvi) < 0) if (api_path_fmt2api_path(api_path_fmt, cvv, yspec0, &api_path, &cvvi) < 0)
@ -524,7 +524,7 @@ cli_dbxml(clixon_handle h,
/*! Set datastore xml entry /*! Set datastore xml entry
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables * @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
@ -546,7 +546,7 @@ cli_set(clixon_handle h,
/*! Merge datastore xml entry /*! Merge datastore xml entry
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables * @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
@ -568,7 +568,7 @@ cli_merge(clixon_handle h,
/*! Create datastore xml entry /*! Create datastore xml entry
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables * @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
@ -590,7 +590,7 @@ cli_create(clixon_handle h,
/*! Remove datastore xml entry /*! Remove datastore xml entry
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables * @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
@ -613,7 +613,7 @@ cli_remove(clixon_handle h,
/*! Delete datastore xml /*! Delete datastore xml
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Vector of cli string and instantiated variables * @param[in] cvv Vector of cli string and instantiated variables
* @param[in] argv Vector. First element xml key format string, eg "/aaa/%s" * @param[in] argv Vector. First element xml key format string, eg "/aaa/%s"
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
@ -830,7 +830,7 @@ cli_commit(clixon_handle h,
/*! Generic validate callback /*! Generic validate callback
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Vector of command variables * @param[in] cvv Vector of command variables
* @param[in] argv * @param[in] argv
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
*/ */
@ -884,7 +884,7 @@ compare_db_names(clixon_handle h,
goto done; goto done;
goto done; goto done;
} }
/* Note that XML and TEXT uses a (new) structured in-mem algorithm while /* Note that XML and TEXT uses a (new) structured in-mem algorithm while
* JSON and CLI uses (old) UNIX file diff. * JSON and CLI uses (old) UNIX file diff.
*/ */
switch (format){ switch (format){
@ -927,7 +927,7 @@ compare_db_names(clixon_handle h,
/*! Compare two dbs using XML. Write to file and run diff /*! Compare two dbs using XML. Write to file and run diff
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv * @param[in] cvv
* @param[in] argv <db1> <db2> <format> * @param[in] argv <db1> <db2> <format>
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
@ -981,8 +981,8 @@ compare_dbs(clixon_handle h,
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum) * <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* *
* @note that "filename" is local on client filesystem not backend. * @note that "filename" is local on client filesystem not backend.
* @note file is assumed to have a dummy top-tag, eg <clicon></clicon> * @note file is assumed to have a dummy top-tag, eg <clicon></clicon>
* @code * @code
* # cligen spec * # cligen spec
@ -1155,7 +1155,7 @@ load_config_file(clixon_handle h,
* Utility function used by cligen spec file * Utility function used by cligen spec file
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Variable vector (containing <varname>) * @param[in] cvv Variable vector (containing <varname>)
* @param[in] argv A string: "<dbname> <varname> [<format>]" * @param[in] argv A string: "<dbname> <varname> [<format>]"
* <dbname> is running, candidate, or startup * <dbname> is running, candidate, or startup
* <varname> is name of cligen variable in the "cvv" vector containing file name * <varname> is name of cligen variable in the "cvv" vector containing file name
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum) * <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
@ -1270,12 +1270,12 @@ save_config_file(clixon_handle h,
return retval; return retval;
} }
/*! Delete all elements in a database /*! Delete all elements in a database
* *
* Utility function used by cligen spec file * Utility function used by cligen spec file
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Vector of command variables * @param[in] cvv Vector of command variables
* @param[in] argv * @param[in] argv
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
*/ */
@ -1387,7 +1387,7 @@ cli_notification_cb(int s,
} }
/*! Make a notify subscription to backend and un/register callback for return messages. /*! Make a notify subscription to backend and un/register callback for return messages.
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Not used * @param[in] cvv Not used
* @param[in] arg A string with <log stream name> <stream status> [<format>] * @param[in] arg A string with <log stream name> <stream status> [<format>]
@ -1397,7 +1397,7 @@ cli_notification_cb(int s,
* @retval -1 Error * @retval -1 Error
* Example code: Start logging of mystream and show logs as xml * Example code: Start logging of mystream and show logs as xml
* @code * @code
* cmd("comment"), cli_notify("mystream","1","xml"); * cmd("comment"), cli_notify("mystream","1","xml");
* @endcode * @endcode
*/ */
int int
@ -1436,14 +1436,14 @@ cli_notify(clixon_handle h,
} }
/*! Lock database /*! Lock database
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Not used * @param[in] cvv Not used
* @param[in] arg A string with <database> * @param[in] arg A string with <database>
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @code * @code
* lock("comment"), cli_lock("running"); * lock("comment"), cli_lock("running");
* @endcode * @endcode
* XXX: format is a memory leak * XXX: format is a memory leak
*/ */
@ -1468,14 +1468,14 @@ cli_lock(clixon_handle h,
} }
/*! Unlock database /*! Unlock database
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Not used * @param[in] cvv Not used
* @param[in] arg A string with <database> * @param[in] arg A string with <database>
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @code * @code
* lock("comment"), cli_unlock("running"); * lock("comment"), cli_unlock("running");
* @endcode * @endcode
* XXX: format is a memory leak * XXX: format is a memory leak
*/ */
@ -1500,7 +1500,7 @@ cli_unlock(clixon_handle h,
} }
/*! Kill session /*! Kill session
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Not used * @param[in] cvv Not used
* @param[in] arg variabel w session nr * @param[in] arg variabel w session nr
@ -1538,8 +1538,8 @@ cli_kill_session(clixon_handle h,
/*! Copy one configuration object to antother /*! Copy one configuration object to antother
* *
* Works for objects that are items in a yang list with a keyname, eg as: * Works for objects that are items in a yang list with a keyname, eg as:
* list sender{ * list sender{
* key name; * key name;
* leaf name{... * leaf name{...
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
@ -1682,7 +1682,7 @@ cli_copy_config(clixon_handle h,
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Not used * @param[in] cvv Not used
* @param[in] arg A string with <database> * @param[in] arg A string with <database>
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
*/ */
@ -1702,11 +1702,11 @@ cli_help(clixon_handle h,
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] cvv Not used * @param[in] cvv Not used
* @param[in] arg A string with <database> * @param[in] arg A string with <database>
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @code * @code
* restart("comment") , cli_restart_plugin("myplugin", "restart"); * restart("comment") , cli_restart_plugin("myplugin", "restart");
* @endcode * @endcode
*/ */
int int
@ -1733,6 +1733,10 @@ cli_restart_plugin(clixon_handle h,
/* Append cvv1 to cvv0 and return a new cvec /* Append cvv1 to cvv0 and return a new cvec
* *
* @param[in] cvv0 First cvv
* @param[in] cvv1 Second cvv
* @retval cvv New cvv, free with cvec_free
* @retval NULL Error
* @note if cvv0 is non-null, the first element of cvv1 is skipped * @note if cvv0 is non-null, the first element of cvv1 is skipped
*/ */
cvec* cvec*
@ -1807,7 +1811,7 @@ cvec_concat_cb(cvec *cvv,
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @code * @code
* actions-daemon("Actions daemon operations") start, * actions-daemon("Actions daemon operations") start,
* cli_process_control("Action process", "start"); * cli_process_control("Action process", "start");
* @endcode * @endcode
*/ */

View file

@ -136,8 +136,8 @@ clicon_db_elmnt_set(clixon_handle h,
* @retval -1 Error * @retval -1 Error
*/ */
static int static int
xmldb_db2file1(clixon_handle h, xmldb_db2file1(clixon_handle h,
const char *db, const char *db,
int multi, int multi,
char **filename) char **filename)
{ {
@ -206,10 +206,10 @@ xmldb_db2subdir(clixon_handle h,
const char *db, const char *db,
char **subdirp) char **subdirp)
{ {
int retval = -1; int retval = -1;
cbuf *cb = NULL; cbuf *cb = NULL;
char *dir; char *dir;
char *subdir = NULL; char *subdir = NULL;
if ((cb = cbuf_new()) == NULL){ if ((cb = cbuf_new()) == NULL){
clixon_err(OE_XML, errno, "cbuf_new"); clixon_err(OE_XML, errno, "cbuf_new");

View file

@ -212,7 +212,6 @@ xml_copy_bottom_recurse(cxobj *x0t,
if (xml_copy(x0k, x1k) < 0) if (xml_copy(x0k, x1k) < 0)
goto done; goto done;
} }
} }
} }
if (xml_sort(x1p) < 0) if (xml_sort(x1p) < 0)

View file

@ -184,7 +184,7 @@ text2file(cxobj *xn,
else{ else{
*leafl = 0; *leafl = 0;
*leaflname = NULL; *leaflname = NULL;
(*fn)(f, "%*s\n", PRETTYPRINT_INDENT*(level), "]"); (*fn)(f, "%*s]\n", PRETTYPRINT_INDENT*(level), "");
} }
} }
xc = NULL; /* count children (elements and bodies, not attributes) */ xc = NULL; /* count children (elements and bodies, not attributes) */
@ -260,7 +260,7 @@ text2file(cxobj *xn,
/* Stop leaf-list printing (ie []) if no longer leaflist and same name */ /* Stop leaf-list printing (ie []) if no longer leaflist and same name */
if (yn && yang_keyword_get(yn) != Y_LEAF_LIST && *leafl != 0){ if (yn && yang_keyword_get(yn) != Y_LEAF_LIST && *leafl != 0){
*leafl = 0; *leafl = 0;
(*fn)(f, "%*s\n", PRETTYPRINT_INDENT*(level+1), "]"); (*fn)(f, "%*s]\n", PRETTYPRINT_INDENT*(level+1), "");
} }
if (!tleaf(xn)) if (!tleaf(xn))
(*fn)(f, "%*s}\n", PRETTYPRINT_INDENT*level, ""); (*fn)(f, "%*s}\n", PRETTYPRINT_INDENT*level, "");

View file

@ -1970,10 +1970,10 @@ done:
* until nodes marked with XML_FLAG_MARK are reached, where * until nodes marked with XML_FLAG_MARK are reached, where
* (2) the complete subtree of that node is copied. * (2) the complete subtree of that node is copied.
* (3) Special case: key nodes in lists are copied if any node in list is marked * (3) Special case: key nodes in lists are copied if any node in list is marked
* @param[in] x0 * @param[in] x0 XML tree source
* @param[in] x1 * @param[in] x1 XML tree target
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @note you may want to check:!yang_config(ys) * @note you may want to check:!yang_config(ys)
*/ */
int int

View file

@ -1,7 +1,7 @@
/* /*
* *
***** BEGIN LICENSE BLOCK ***** ***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2019 Olof Hagsand Copyright (C) 2009-2019 Olof Hagsand
Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate) Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC(Netgate)
@ -25,7 +25,7 @@
of those above. If you wish to allow use of your version of this file only of those above. If you wish to allow use of your version of this file only
under the terms of the GPL, and not to allow others to under the terms of the GPL, and not to allow others to
use your version of this file under the terms of Apache License version 2, indicate use your version of this file under the terms of Apache License version 2, indicate
your decision by deleting the provisions above and replace them with the your decision by deleting the provisions above and replace them with the
notice and other provisions required by the GPL. If you do not delete notice and other provisions required by the GPL. If you do not delete
the provisions above, a recipient may use your version of this file under the provisions above, a recipient may use your version of this file under
the terms of any one of the Apache License version 2 or the GPL. the terms of any one of the Apache License version 2 or the GPL.
@ -34,17 +34,17 @@
* Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10
* *
* Note on xcur parameter to most xpath functions: * Note on xcur parameter to most XPath functions:
* The W3 standard defines the document root / element as the top-level. * The W3 standard defines the document root / element as the top-level.
* In the clixon xpath API, the document root is defined as the top of the xml tree. * In the clixon XPath API, the document root is defined as the top of the xml tree.
* The xcur argument of xpath_first and others is the "current" xml node (xcur) which can * The xcur argument of XPath_first and others is the "current" xml node (xcur) which can
* be any node in that tree, not necessarily the document root. * be any node in that tree, not necessarily the document root.
* This is convenient if you want to use relative xpaths from any location in the tree (eg ../../foo/bar). * This is convenient if you want to use relative XPaths from any location in the tree (eg ../../foo/bar).
* It may be confusing if you expect xcur to be the root node. * It may be confusing if you expect xcur to be the root node.
* *
* Some notes on namespace extensions in Netconf/Yang * Some notes on namespace extensions in Netconf/Yang
* 1) The xpath is not "namespace-aware" in the sense that if you look for a path, eg * 1) The XPath is not "namespace-aware" in the sense that if you look for a path, eg
* "n:a/n:b", those must match the XML, so they need to match prefixes AND name in the xml * "n:a/n:b", those must match the XML, so they need to match prefixes AND name in the xml
* such as <n:a><n:b>. An xml with <m:a><m:b> (or <a><b>) will NOT match EVEN IF they have the * such as <n:a><n:b>. An xml with <m:a><m:b> (or <a><b>) will NOT match EVEN IF they have the
* same namespace given by xmlns settings. * same namespace given by xmlns settings.
* 2) RFC6241 8.9.1 * 2) RFC6241 8.9.1
@ -57,7 +57,7 @@
* select="/t:top/t:users/t:user[t:name='fred']"/> * select="/t:top/t:users/t:user[t:name='fred']"/>
* </get-config> * </get-config>
* One observation is that the namespace context is static, so it can not be a part * One observation is that the namespace context is static, so it can not be a part
* of the xpath-tree, which is context-dependent. * of the XPath-tree, which is context-dependent.
* Best is to send it as a (read-only) parameter to the xp_eval family of functions * Best is to send it as a (read-only) parameter to the xp_eval family of functions
* as an exlicit namespace context. * as an exlicit namespace context.
* 3) localonly flag refers to https://www.w3.org/TR/REC-xml-names/, where : * 3) localonly flag refers to https://www.w3.org/TR/REC-xml-names/, where :
@ -103,7 +103,7 @@
#include "clixon_xpath_parse.h" #include "clixon_xpath_parse.h"
#include "clixon_xpath_eval.h" #include "clixon_xpath_eval.h"
/* Use apostrophe(') in xpath literals, eg a/[x='foo'], not double-quotes(") /* Use apostrophe(') in XPath literals, eg a/[x='foo'], not double-quotes(")
* If not set, use ": a/[x="foo"] * If not set, use ": a/[x="foo"]
* Advantage with ' is it works well in clispecs, " must be escaped * Advantage with ' is it works well in clispecs, " must be escaped
* @see https://www.w3.org/TR/xpath-10/#NT-Literal * @see https://www.w3.org/TR/xpath-10/#NT-Literal
@ -114,7 +114,7 @@
* Variables * Variables
*/ */
/* Mapping between xpath_tree node name string <--> int /* Mapping between XPath_tree node name string <--> int
* @see xpath_tree_int2str * @see xpath_tree_int2str
*/ */
static const map_str2int xpath_tree_map[] = { static const map_str2int xpath_tree_map[] = {
@ -135,11 +135,11 @@ static const map_str2int xpath_tree_map[] = {
{"primaryexpr", XP_PRI0}, {"primaryexpr", XP_PRI0},
{"primaryexpr nr", XP_PRIME_NR}, {"primaryexpr nr", XP_PRIME_NR},
{"primaryexpr str", XP_PRIME_STR}, {"primaryexpr str", XP_PRIME_STR},
{"primaryexpr fn", XP_PRIME_FN}, {"primaryexpr fn", XP_PRIME_FN},
{NULL, -1} {NULL, -1}
}; };
/* Mapping between axis_type string <--> int /* Mapping between axis_type string <--> int
* @see axis_type_int2str * @see axis_type_int2str
*/ */
static const map_str2int axis_type_map[] = { static const map_str2int axis_type_map[] = {
@ -179,7 +179,7 @@ axis_type_str2int(char *name)
return clicon_str2int(axis_type_map, name); return clicon_str2int(axis_type_map, name);
} }
/*! Map from xpath_tree node name int to string /*! Map from XPath_tree node name int to string
*/ */
char* char*
xpath_tree_int2str(int nodetype) xpath_tree_int2str(int nodetype)
@ -187,7 +187,7 @@ xpath_tree_int2str(int nodetype)
return (char*)clicon_int2str(xpath_tree_map, nodetype); return (char*)clicon_int2str(xpath_tree_map, nodetype);
} }
/*! Print XPath parse tree /*! Print XPath parse tree
* *
* @note uses "" instead of '' in printing literals, rule [29] in https://www.w3.org/TR/xpath-10 * @note uses "" instead of '' in printing literals, rule [29] in https://www.w3.org/TR/xpath-10
*/ */
@ -220,7 +220,7 @@ xpath_tree_print0(cbuf *cb,
return 0; return 0;
} }
/*! Print a xpath_tree to CLIgen buf /*! Print a XPath_tree to CLIgen buf
* *
* @param[out] cb CLIgen buffer * @param[out] cb CLIgen buffer
* @param[in] xs XPath tree * @param[in] xs XPath tree
@ -233,7 +233,7 @@ xpath_tree_print_cb(cbuf *cb,
return 0; return 0;
} }
/*! Print a xpath_tree /*! Print a XPath_tree
* *
* @param[in] f UNIX output stream * @param[in] f UNIX output stream
* @param[in] xs XPath tree * @param[in] xs XPath tree
@ -242,7 +242,7 @@ xpath_tree_print_cb(cbuf *cb,
* @see xpath_tree2str * @see xpath_tree2str
*/ */
int int
xpath_tree_print(FILE *f, xpath_tree_print(FILE *f,
xpath_tree *xs) xpath_tree *xs)
{ {
int retval = -1; int retval = -1;
@ -260,7 +260,7 @@ xpath_tree_print(FILE *f,
return retval; return retval;
} }
/*! Create an xpath string from an xpath tree, ie "unparsing" /*! Create an XPath string from an XPath tree, ie "unparsing"
* *
* @param[in] xs XPath tree * @param[in] xs XPath tree
* @param[out] xpath XPath string as CLIgen buf * @param[out] xpath XPath string as CLIgen buf
@ -299,7 +299,7 @@ xpath_tree2cbuf(xpath_tree *xs,
cprintf(xcb, "%s", xs->xs_s1); cprintf(xcb, "%s", xs->xs_s1);
break; break;
case XP_PRIME_NR: case XP_PRIME_NR:
cprintf(xcb, "%s", xs->xs_strnr?xs->xs_strnr:"0"); cprintf(xcb, "%s", xs->xs_strnr?xs->xs_strnr:"0");
break; break;
case XP_PRIME_STR: case XP_PRIME_STR:
#ifdef XPATH_USE_APOSTROPHE #ifdef XPATH_USE_APOSTROPHE
@ -376,8 +376,8 @@ xpath_tree2cbuf(xpath_tree *xs,
} }
static int static int
xpath_tree_append(xpath_tree *xt, xpath_tree_append(xpath_tree *xt,
xpath_tree ***vec, xpath_tree ***vec,
size_t *len) size_t *len)
{ {
int retval = -1; int retval = -1;
@ -392,7 +392,7 @@ xpath_tree_append(xpath_tree *xt,
return retval; return retval;
} }
/*! Check if two xpath-trees (parsed xpaths) ar equal /*! Check if two xpath-trees (parsed XPaths) ar equal
* *
* @param[in] xt1 XPath parse 1 * @param[in] xt1 XPath parse 1
* @param[in] xt2 XPath parse 2 * @param[in] xt2 XPath parse 2
@ -405,7 +405,7 @@ xpath_tree_append(xpath_tree *xt,
int int
xpath_tree_eq(xpath_tree *xt1, /* pattern */ xpath_tree_eq(xpath_tree *xt1, /* pattern */
xpath_tree *xt2, xpath_tree *xt2,
xpath_tree ***vec, xpath_tree ***vec,
size_t *len) size_t *len)
{ {
int retval = -1; /* Error */ int retval = -1; /* Error */
@ -515,7 +515,7 @@ xpath_tree_traverse(xpath_tree *xt,
return xs; return xs;
} }
/*! Free a xpath_tree /*! Free a XPath_tree
* *
* @param[in] xs XPath tree * @param[in] xs XPath tree
* @see xpath_parse creates a xpath_tree * @see xpath_parse creates a xpath_tree
@ -537,7 +537,7 @@ xpath_tree_free(xpath_tree *xs)
return 0; return 0;
} }
/*! Given xpath, parse it, and return structured xpath tree /*! Given XPath, parse it, and return structured XPath tree
* *
* @param[in] xpath String with XPath 1.0 syntax * @param[in] xpath String with XPath 1.0 syntax
* @param[out] xptree XPath-tree, parsed, structured XPath, free:xpath_tree_free * @param[out] xptree XPath-tree, parsed, structured XPath, free:xpath_tree_free
@ -550,8 +550,8 @@ xpath_tree_free(xpath_tree *xs)
* if (xpt) * if (xpt)
* xpath_tree_free(xpt); * xpath_tree_free(xpt);
* @endcode * @endcode
* @see xpath_tree_free * @see xpath_tree_free
* @see xpath_tree2cbuf for unparsing, ie producing an original xpath string * @see xpath_tree2cbuf for unparsing, ie producing an original XPath string
*/ */
int int
xpath_parse(const char *xpath, xpath_parse(const char *xpath,
@ -559,7 +559,7 @@ xpath_parse(const char *xpath,
{ {
int retval = -1; int retval = -1;
clixon_xpath_yacc xpy = {0,}; clixon_xpath_yacc xpy = {0,};
cbuf *cb = NULL; cbuf *cb = NULL;
clixon_debug(CLIXON_DBG_PARSE, "%s", xpath); clixon_debug(CLIXON_DBG_PARSE, "%s", xpath);
if (xpath == NULL){ if (xpath == NULL){
@ -604,9 +604,9 @@ xpath_parse(const char *xpath,
return retval; return retval;
} }
/*! Given XML tree and xpath, parse xpath, eval it and return xpath context, /*! Given XML tree and XPath, parse XPath, eval it and return XPath context,
* *
* This is a raw form of xpath where you can do type conversion of the return * This is a raw form of XPath where you can do type conversion of the return
* value, etc, not just a nodeset. * value, etc, not just a nodeset.
* @param[in] xcur XML-tree where to search * @param[in] xcur XML-tree where to search
* @param[in] nsc External XML namespace context, or NULL * @param[in] nsc External XML namespace context, or NULL
@ -624,7 +624,7 @@ xpath_parse(const char *xpath,
* @endcode * @endcode
*/ */
int int
xpath_vec_ctx(cxobj *xcur, xpath_vec_ctx(cxobj *xcur,
cvec *nsc, cvec *nsc,
const char *xpath, const char *xpath,
int localonly, int localonly,
@ -633,7 +633,7 @@ xpath_vec_ctx(cxobj *xcur,
int retval = -1; int retval = -1;
xpath_tree *xptree = NULL; xpath_tree *xptree = NULL;
xp_ctx xc = {0,}; xp_ctx xc = {0,};
clixon_debug(CLIXON_DBG_XPATH | CLIXON_DBG_DETAIL, "%s", xpath); clixon_debug(CLIXON_DBG_XPATH | CLIXON_DBG_DETAIL, "%s", xpath);
if (xpath_parse(xpath, &xptree) < 0) if (xpath_parse(xpath, &xptree) < 0)
goto done; goto done;
@ -677,9 +677,9 @@ xpath_vec_ctx(cxobj *xcur,
* @see also xpath_vec. * @see also xpath_vec.
*/ */
cxobj * cxobj *
xpath_first(cxobj *xcur, xpath_first(cxobj *xcur,
cvec *nsc, cvec *nsc,
const char *xpformat, const char *xpformat,
...) ...)
{ {
cxobj *cx = NULL; cxobj *cx = NULL;
@ -687,8 +687,8 @@ xpath_first(cxobj *xcur,
size_t len; size_t len;
char *xpath = NULL; char *xpath = NULL;
xp_ctx *xr = NULL; xp_ctx *xr = NULL;
va_start(ap, xpformat); va_start(ap, xpformat);
len = vsnprintf(NULL, 0, xpformat, ap); len = vsnprintf(NULL, 0, xpformat, ap);
va_end(ap); va_end(ap);
/* allocate a message string exactly fitting the message length */ /* allocate a message string exactly fitting the message length */
@ -697,7 +697,7 @@ xpath_first(cxobj *xcur,
goto done; goto done;
} }
/* second round: compute write message from reason and args */ /* second round: compute write message from reason and args */
va_start(ap, xpformat); va_start(ap, xpformat);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
clixon_err(OE_UNIX, errno, "vsnprintf"); clixon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap); va_end(ap);
@ -737,8 +737,8 @@ xpath_first(cxobj *xcur,
* @see also xpath_first. * @see also xpath_first.
*/ */
cxobj * cxobj *
xpath_first_localonly(cxobj *xcur, xpath_first_localonly(cxobj *xcur,
const char *xpformat, const char *xpformat,
...) ...)
{ {
cxobj *cx = NULL; cxobj *cx = NULL;
@ -746,8 +746,8 @@ xpath_first_localonly(cxobj *xcur,
size_t len; size_t len;
char *xpath = NULL; char *xpath = NULL;
xp_ctx *xr = NULL; xp_ctx *xr = NULL;
va_start(ap, xpformat); va_start(ap, xpformat);
len = vsnprintf(NULL, 0, xpformat, ap); len = vsnprintf(NULL, 0, xpformat, ap);
va_end(ap); va_end(ap);
/* allocate a message string exactly fitting the message length */ /* allocate a message string exactly fitting the message length */
@ -756,7 +756,7 @@ xpath_first_localonly(cxobj *xcur,
goto done; goto done;
} }
/* second round: compute write message from reason and args */ /* second round: compute write message from reason and args */
va_start(ap, xpformat); va_start(ap, xpformat);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
clixon_err(OE_UNIX, errno, "vsnprintf"); clixon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap); va_end(ap);
@ -775,7 +775,7 @@ xpath_first_localonly(cxobj *xcur,
return cx; return cx;
} }
/*! Given XML tree and xpath, returns nodeset as xml node vector /*! Given XML tree and XPath, returns nodeset as xml node vector
* *
* If result is not nodeset, return empty nodeset * If result is not nodeset, return empty nodeset
* @param[in] xcur xml-tree where to search * @param[in] xcur xml-tree where to search
@ -789,7 +789,7 @@ xpath_first_localonly(cxobj *xcur,
* cvec *nsc; // namespace context * cvec *nsc; // namespace context
* cxobj **vec = NULL; * cxobj **vec = NULL;
* size_t veclen; * size_t veclen;
* if (xpath_vec(xcur, nsc, "//symbol/foo", &vec, &veclen) < 0) * if (xpath_vec(xcur, nsc, "//symbol/foo", &vec, &veclen) < 0)
* err; * err;
* for (i=0; i<veclen; i++){ * for (i=0; i<veclen; i++){
* xn = vec[i]; * xn = vec[i];
@ -799,10 +799,10 @@ xpath_first_localonly(cxobj *xcur,
* @endcode * @endcode
*/ */
int int
xpath_vec(cxobj *xcur, xpath_vec(cxobj *xcur,
cvec *nsc, cvec *nsc,
const char *xpformat, const char *xpformat,
cxobj ***vec, cxobj ***vec,
size_t *veclen, size_t *veclen,
...) ...)
{ {
@ -810,18 +810,18 @@ xpath_vec(cxobj *xcur,
va_list ap; va_list ap;
size_t len; size_t len;
char *xpath = NULL; char *xpath = NULL;
xp_ctx *xr = NULL; xp_ctx *xr = NULL;
va_start(ap, veclen); va_start(ap, veclen);
len = vsnprintf(NULL, 0, xpformat, ap); len = vsnprintf(NULL, 0, xpformat, ap);
va_end(ap); va_end(ap);
/* allocate an xpath string exactly fitting the length */ /* allocate an XPath string exactly fitting the length */
if ((xpath = malloc(len+1)) == NULL){ if ((xpath = malloc(len+1)) == NULL){
clixon_err(OE_UNIX, errno, "malloc"); clixon_err(OE_UNIX, errno, "malloc");
goto done; goto done;
} }
/* second round: actually compute xpath string content */ /* second round: actually compute XPath string content */
va_start(ap, veclen); va_start(ap, veclen);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
clixon_err(OE_UNIX, errno, "vsnprintf"); clixon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap); va_end(ap);
@ -860,7 +860,7 @@ xpath_vec(cxobj *xcur,
* cxobj **vec; * cxobj **vec;
* size_t veclen; * size_t veclen;
* cvec *nsc; // namespace context (not NULL) * cvec *nsc; // namespace context (not NULL)
* if (xpath_vec_flag(xcur, nsc, "//symbol/foo", XML_FLAG_ADD, &vec, &veclen) < 0) * if (xpath_vec_flag(xcur, nsc, "//symbol/foo", XML_FLAG_ADD, &vec, &veclen) < 0)
* goto err; * goto err;
* for (i=0; i<veclen; i++){ * for (i=0; i<veclen; i++){
* xn = vec[i]; * xn = vec[i];
@ -872,11 +872,11 @@ xpath_vec(cxobj *xcur,
* @see also xpath_vec This is a specialized version. * @see also xpath_vec This is a specialized version.
*/ */
int int
xpath_vec_flag(cxobj *xcur, xpath_vec_flag(cxobj *xcur,
cvec *nsc, cvec *nsc,
const char *xpformat, const char *xpformat,
uint16_t flags, uint16_t flags,
cxobj ***vec, cxobj ***vec,
size_t *veclen, size_t *veclen,
...) ...)
{ {
@ -888,8 +888,8 @@ xpath_vec_flag(cxobj *xcur,
int i; int i;
cxobj *x; cxobj *x;
int ilen = 0; /* change when cxvec_append uses size_t */ int ilen = 0; /* change when cxvec_append uses size_t */
va_start(ap, veclen); va_start(ap, veclen);
len = vsnprintf(NULL, 0, xpformat, ap); len = vsnprintf(NULL, 0, xpformat, ap);
va_end(ap); va_end(ap);
/* allocate a message string exactly fitting the message length */ /* allocate a message string exactly fitting the message length */
@ -898,7 +898,7 @@ xpath_vec_flag(cxobj *xcur,
goto done; goto done;
} }
/* second round: compute write message from reason and args */ /* second round: compute write message from reason and args */
va_start(ap, veclen); va_start(ap, veclen);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
clixon_err(OE_UNIX, errno, "vsnprintf"); clixon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap); va_end(ap);
@ -913,7 +913,7 @@ xpath_vec_flag(cxobj *xcur,
x = xr->xc_nodeset[i]; x = xr->xc_nodeset[i];
if (flags==0x0 || xml_flag(x, flags)) if (flags==0x0 || xml_flag(x, flags))
if (cxvec_append(x, vec, &ilen) < 0) if (cxvec_append(x, vec, &ilen) < 0)
goto done; goto done;
} }
} }
*veclen = ilen; *veclen = ilen;
@ -926,7 +926,7 @@ xpath_vec_flag(cxobj *xcur,
return retval; return retval;
} }
/*! Given XML tree and xpath, returns boolean /*! Given XML tree and XPath, returns boolean
* *
* Returns true if the nodeset is non-empty * Returns true if the nodeset is non-empty
* @param[in] xcur xml-tree where to search * @param[in] xcur xml-tree where to search
@ -937,9 +937,9 @@ xpath_vec_flag(cxobj *xcur,
* @retval -1 Error * @retval -1 Error
*/ */
int int
xpath_vec_bool(cxobj *xcur, xpath_vec_bool(cxobj *xcur,
cvec *nsc, cvec *nsc,
const char *xpformat, const char *xpformat,
...) ...)
{ {
int retval = -1; int retval = -1;
@ -947,8 +947,8 @@ xpath_vec_bool(cxobj *xcur,
size_t len; size_t len;
char *xpath = NULL; char *xpath = NULL;
xp_ctx *xr = NULL; xp_ctx *xr = NULL;
va_start(ap, xpformat); va_start(ap, xpformat);
len = vsnprintf(NULL, 0, xpformat, ap); len = vsnprintf(NULL, 0, xpformat, ap);
va_end(ap); va_end(ap);
/* allocate a message string exactly fitting the message length */ /* allocate a message string exactly fitting the message length */
@ -957,7 +957,7 @@ xpath_vec_bool(cxobj *xcur,
goto done; goto done;
} }
/* second round: compute write message from reason and args */ /* second round: compute write message from reason and args */
va_start(ap, xpformat); va_start(ap, xpformat);
if (vsnprintf(xpath, len+1, xpformat, ap) < 0){ if (vsnprintf(xpath, len+1, xpformat, ap) < 0){
clixon_err(OE_UNIX, errno, "vsnprintf"); clixon_err(OE_UNIX, errno, "vsnprintf");
va_end(ap); va_end(ap);
@ -1028,10 +1028,10 @@ traverse_canonical_str(xpath_tree *xs,
return retval; return retval;
} }
/*! Translate an xpath/nsc pair to a "canonical" form using yang prefixes /*! Translate an XPath/nsc pair to a "canonical" form using yang prefixes
* *
* Returns new namespace context and rewrites the xpath tree * Returns new namespace context and rewrites the XPath tree
* @param[in] xs Parsed xpath - xpath_tree * @param[in] xs Parsed XPath - xpath_tree
* @param[in] yspec Yang spec containing all modules, associated with namespaces * @param[in] yspec Yang spec containing all modules, associated with namespaces
* @param[in] nsc0 Input namespace context * @param[in] nsc0 Input namespace context
* @param[in] exprstr Interpret strings as <prefix>:<name> (primaryexpr/literal/string) * @param[in] exprstr Interpret strings as <prefix>:<name> (primaryexpr/literal/string)
@ -1040,7 +1040,7 @@ traverse_canonical_str(xpath_tree *xs,
* @retval 1 OK with nsc1 containing the transformed nsc * @retval 1 OK with nsc1 containing the transformed nsc
* @retval 0 XPath failure with reason set to why * @retval 0 XPath failure with reason set to why
* @retval -1 Fatal Error * @retval -1 Fatal Error
* @note Setting str to 1 requires a knowledge of the context of the xpath, ie that strings are * @note Setting str to 1 requires a knowledge of the context of the XPath, ie that strings are
* something like identityref and is safe to translate into canonical form * something like identityref and is safe to translate into canonical form
*/ */
static int static int
@ -1058,7 +1058,7 @@ xpath_traverse_canonical(xpath_tree *xs,
yang_stmt *ymod; yang_stmt *ymod;
cbuf *cb = NULL; cbuf *cb = NULL;
int ret; int ret;
switch (xs->xs_type){ switch (xs->xs_type){
case XP_PRIME_STR: case XP_PRIME_STR:
if (exprstr != 0) if (exprstr != 0)
@ -1087,13 +1087,13 @@ xpath_traverse_canonical(xpath_tree *xs,
clixon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "No yang found for namespace: %s", namespace); cprintf(cb, "No yang found for namespace: %s", namespace);
if (reason) if (reason)
*reason = cb; *reason = cb;
goto fail; goto fail;
#endif #endif
} }
if (ymod == NULL) if (ymod == NULL)
prefix1 = prefix0; prefix1 = prefix0;
else else
if ((prefix1 = yang_find_myprefix(ymod)) == NULL){ if ((prefix1 = yang_find_myprefix(ymod)) == NULL){
@ -1101,7 +1101,7 @@ xpath_traverse_canonical(xpath_tree *xs,
clixon_err(OE_UNIX, errno, "cbuf_new"); clixon_err(OE_UNIX, errno, "cbuf_new");
goto done; goto done;
} }
cprintf(cb, "No prefix found in module: %s", yang_argument_get(ymod)); cprintf(cb, "No prefix found in module: %s", yang_argument_get(ymod));
if (reason) if (reason)
*reason = cb; *reason = cb;
goto fail; goto fail;
@ -1122,7 +1122,7 @@ xpath_traverse_canonical(xpath_tree *xs,
break; break;
default: default:
break; break;
} }
if (xs->xs_c0){ if (xs->xs_c0){
if ((ret = xpath_traverse_canonical(xs->xs_c0, yspec, nsc0, exprstr, nsc1, reason)) < 0) if ((ret = xpath_traverse_canonical(xs->xs_c0, yspec, nsc0, exprstr, nsc1, reason)) < 0)
goto done; goto done;
@ -1134,7 +1134,7 @@ xpath_traverse_canonical(xpath_tree *xs,
goto done; goto done;
if (ret == 0) if (ret == 0)
goto fail; goto fail;
} }
retval = 1; retval = 1;
done: done:
return retval; return retval;
@ -1143,20 +1143,20 @@ xpath_traverse_canonical(xpath_tree *xs,
goto done; goto done;
} }
/*! Translate an xpath/nsc pair to a "canonical" form using yang prefixes /*! Translate an XPath/nsc pair to a "canonical" form using yang prefixes
* *
* @param[in] xpath0 Input xpath * @param[in] xpath0 Input XPath
* @param[in] nsc0 Input namespace context * @param[in] nsc0 Input namespace context
* @param[in] yspec Yang spec containing all modules, associated with namespaces * @param[in] yspec Yang spec containing all modules, associated with namespaces
* @param[in] exprstr Interpret strings as <prefix>:<name> (primaryexpr/literal/string) * @param[in] exprstr Interpret strings as <prefix>:<name> (primaryexpr/literal/string)
* @param[out] xpath1 Output xpath. Free after use * @param[out] xpath1 Output XPath. Free after use
* @param[out] nsc1 Output namespace context. Free after use with xml_nsctx_free * @param[out] nsc1 Output namespace context. Free after use with xml_nsctx_free
* @param[out] cbreason reason if retval = 0 * @param[out] cbreason reason if retval = 0
* @retval 1 OK, xpath1 and nsc1 allocated * @retval 1 OK, xpath1 and nsc1 allocated
* @retval 0 XPath failure with reason set to why * @retval 0 XPath failure with reason set to why
* @retval -1 Fatal Error * @retval -1 Fatal Error
* Example: * Example:
* Module A has prefix a and namespace urn:example:a and symbols x * Module A has prefix a and namespace urn:example:a and symbols x
* Module B with prefix b and namespace urn:example:b and symbols y * Module B with prefix b and namespace urn:example:b and symbols y
* Then incoming: * Then incoming:
* xpath0: /x/c:y * xpath0: /x/c:y
@ -1175,8 +1175,8 @@ xpath_traverse_canonical(xpath_tree *xs,
* if (nsc1) xml_nsctx_free(nsc1); * if (nsc1) xml_nsctx_free(nsc1);
* if (reason) cbuf_free(reason); * if (reason) cbuf_free(reason);
* @endcode * @endcode
* @note Unsolvable issue of mountpoints, eg an xpath of //x:foo where foo is under one or several * @note Unsolvable issue of mountpoints, eg an XPath of //x:foo where foo is under one or several
* mountpoints: a well-defined namespace cannot be determined. Therefore just allow * mountpoints: a well-defined namespace cannot be determined. Therefore just allow
* inconsistencies and hope that it will be covered by other code * inconsistencies and hope that it will be covered by other code
* @see xpath2xml * @see xpath2xml
*/ */
@ -1265,7 +1265,7 @@ xpath2canonical(const char *xpath0,
* @note This function is made for making optimizations in certain circumstances, such as a list * @note This function is made for making optimizations in certain circumstances, such as a list
*/ */
int int
xpath_count(cxobj *xcur, xpath_count(cxobj *xcur,
cvec *nsc, cvec *nsc,
const char *xpath, const char *xpath,
uint32_t *count) uint32_t *count)
@ -1294,12 +1294,12 @@ xpath_count(cxobj *xcur,
return retval; return retval;
} }
/*! Given an XML node, build an xpath recursively to root, internal function /*! Given an XML node, build an XPath recursively to root, internal function
* *
* @param[in] x XML object * @param[in] x XML object
* @param[in] nsc Namespace context * @param[in] nsc Namespace context
* @param[in] spec If set, recursively continue only to root without spec * @param[in] spec If set, recursively continue only to root without spec
* @param[in] apostrophe If set, use apostrophe in xpath literals, eg a/[x='foo'], not double-quotes(") * @param[out] cb XPath string as cbuf. * @param[in] apostrophe If set, use apostrophe in XPath literals, eg a/[x='foo'], not double-quotes(") * @param[out] cb XPath string as cbuf.
* @retval 0 OK * @retval 0 OK
* @retval -1 Error. eg XML malformed * @retval -1 Error. eg XML malformed
*/ */
@ -1322,7 +1322,7 @@ xml2xpath1(cxobj *x,
enum rfc_6020 keyword; enum rfc_6020 keyword;
char *prefix = NULL; char *prefix = NULL;
char *namespace; char *namespace;
if ((xp = xml_parent(x)) == NULL) if ((xp = xml_parent(x)) == NULL)
goto ok; goto ok;
y = xml_spec(x); y = xml_spec(x);
@ -1407,18 +1407,18 @@ xml2xpath1(cxobj *x,
return retval; return retval;
} }
/*! Given an XML node, build an xpath to root /*! Given an XML node, build an XPath to root
* *
* Creates an XPath from an XML node with some limitations, see notes below. * Creates an XPath from an XML node with some limitations, see notes below.
* The prefixes used are from the given namespace context if any, otherwise the native prefixes are used, if any. * The prefixes used are from the given namespace context if any, otherwise the native prefixes are used, if any.
* Note that this means that prefixes may be translated such as if the XML namespace mapping is different than the once used * Note that this means that prefixes may be translated such as if the XML namespace mapping is different than the once used
* in the XML. * in the XML.
* Therefore, if nsc is "canonical", the returned xpath is also "canonical", even though the XML is not. * Therefore, if nsc is "canonical", the returned XPath is also "canonical", even though the XML is not.
* @param[in] x XML object * @param[in] x XML object
* @param[in] nsc Namespace context * @param[in] nsc Namespace context
* @param[in] spec If set, recursively continue only to root without spec (added in 6.1 for yang mount) * @param[in] spec If set, recursively continue only to root without spec (added in 6.1 for yang mount)
* @param[in] apostrophe If set, use apostrophe in xpath literals, eg a/[x='foo'], not double-quotes(") * @param[in] apostrophe If set, use apostrophe in XPath literals, eg a/[x='foo'], not double-quotes(")
* @param[out] xpath Malloced xpath string. Need to free() after use * @param[out] xpath Malloced XPath string. Need to free() after use
* @retval 0 OK * @retval 0 OK
* @retval -1 Error. (eg XML malformed) * @retval -1 Error. (eg XML malformed)
* @code * @code
@ -1430,7 +1430,7 @@ xml2xpath1(cxobj *x,
* free(xpath); * free(xpath);
* @endcode * @endcode
* @note x needs to be bound to YANG, see eg xml_bind_yang() * @note x needs to be bound to YANG, see eg xml_bind_yang()
* @note namespaces of xpath is not well-defined, follows xml, should be canonical? * @note namespaces of XPath is not well-defined, follows xml, should be canonical?
*/ */
int int
xml2xpath(cxobj *x, xml2xpath(cxobj *x,
@ -1465,16 +1465,16 @@ xml2xpath(cxobj *x,
return retval; return retval;
} }
/*! Create xml tree from xpath as xpath-tree /*! Create xml tree from XPath as xpath-tree
* *
* @param[in] xs Parsed xpath - xpath_tree * @param[in] xs Parsed XPath - xpath_tree
* @param[in] nsc Namespace context for xpath * @param[in] nsc Namespace context for XPath
* @param[in] x0 XML tree so far * @param[in] x0 XML tree so far
* @param[out] xbotp Resulting xml tree (end of xpath) (optional) * @param[out] xbotp Resulting xml tree (end of XPath) (optional)
* @param[out] xerr Netconf error message (if retval=0) * @param[out] xerr Netconf error message (if retval=0)
* @retval 1 OK * @retval 1 OK
* @retval 0 Invalid xpath * @retval 0 Invalid XPath
* @retval -1 Fatal error, clixon_err called * @retval -1 Fatal error, clixon_err called
* @see xpath_traverse_canonical * @see xpath_traverse_canonical
*/ */
static int static int
@ -1562,7 +1562,7 @@ xpath2xml_traverse(xpath_tree *xs,
*xbotp = x0; *xbotp = x0;
*ybotp = y0; *ybotp = y0;
} }
} }
retval = 1; retval = 1;
done: done:
clixon_debug(CLIXON_DBG_XPATH | CLIXON_DBG_DETAIL, "retval:%d", retval); clixon_debug(CLIXON_DBG_XPATH | CLIXON_DBG_DETAIL, "retval:%d", retval);
@ -1572,18 +1572,18 @@ xpath2xml_traverse(xpath_tree *xs,
goto done; goto done;
} }
/*! Create xml tree from restricted xpath /*! Create xml tree from restricted XPath
* *
* Create an XML tree from "scratch" using xpath. * Create an XML tree from "scratch" using XPath.
* @param[in] xpath (Absolute) XPath * @param[in] xpath (Absolute) XPath
* @param[in] nsc Namespace context for xpath * @param[in] nsc Namespace context for xpath
* @param[in,out] xtop Incoming XML tree * @param[in,out] xtop Incoming XML tree
* @param[in] yspec Yang spec for xtop * @param[in] yspec Yang spec for xtop
* @param[out] xbotp Resulting xml tree (end of xpath) (optional) * @param[out] xbotp Resulting xml tree (end of XPath) (optional)
* @param[out] ybotp Yang spec matching xpathp * @param[out] ybotp Yang spec matching xpathp
* @param[out] xerr Netconf error message (if retval=0) * @param[out] xerr Netconf error message (if retval=0)
* @retval 1 OK * @retval 1 OK
* @retval 0 Invalid xpath * @retval 0 Invalid XPath
* @retval -1 Fatal error, clixon_err called * @retval -1 Fatal error, clixon_err called
* @see api_path2xml * @see api_path2xml
* @see xml2xpath * @see xml2xpath
@ -1608,12 +1608,12 @@ xpath2xml(char *xpath,
goto done; goto done;
} }
if (*xpath != '/'){ if (*xpath != '/'){
cprintf(cberr, "Invalid absolute xpath: %s (must start with '/')", xpath); cprintf(cberr, "Invalid absolute XPath: %s (must start with '/')", xpath);
if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0) if (xerr && netconf_invalid_value_xml(xerr, "application", cbuf_get(cberr)) < 0)
goto done; goto done;
goto fail; goto fail;
} }
/* Parse input xpath into an xpath-tree */ /* Parse input XPath into an xpath-tree */
if (xpath_parse(xpath, &xpt) < 0) if (xpath_parse(xpath, &xpt) < 0)
goto done; goto done;
if ((retval = xpath2xml_traverse(xpt, nsc, xtop, ytop, xbotp, ybotp, xerr)) < 1) if ((retval = xpath2xml_traverse(xpt, nsc, xtop, ytop, xbotp, ybotp, xerr)) < 1)

View file

@ -84,12 +84,6 @@
#include "clixon_xml_map.h" #include "clixon_xml_map.h"
#include "clixon_yang_parse_lib.h" #include "clixon_yang_parse_lib.h"
/*! Force add ietf-yang-library@2019-01-04 on all mount-points
*
* This is a limitation of of the current implementation
*/
#define YANG_SCHEMA_MOUNT_YANG_LIB_FORCE
/*! Create modstate structure /*! Create modstate structure
* *
* @retval md modstate struct * @retval md modstate struct