Restricted yang (sub)module file match to match RFC6020 exactly
This commit is contained in:
parent
148d5d9432
commit
43c39160a5
10 changed files with 86 additions and 55 deletions
|
|
@ -230,31 +230,33 @@ clicon_rpc_generate_error(cxobj *xerr)
|
|||
* @param[in] h CLICON handle
|
||||
* @param[in] db Name of database
|
||||
* @param[in] xpath XPath (or "")
|
||||
* @param[in] errmode 0 if xml errors are returned as clicon_err
|
||||
* 1 if xml errors are in xt and return 0.
|
||||
* @param[out] xt XML tree. must be freed by caller with xml_free
|
||||
* @param[out] xt XML tree. Free with xml_free.
|
||||
* Either <config> or <rpc-error>.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error, fatal or xml
|
||||
* @code
|
||||
* cxobj *xt = NULL;
|
||||
* if (clicon_rpc_get_config(h, "running", "/", 0, &xt) < 0)
|
||||
* if (clicon_rpc_get_config(h, "running", "/", &xt) < 0)
|
||||
* err;
|
||||
* if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
|
||||
* clicon_rpc_generate_error(xerr);
|
||||
* err;
|
||||
* }
|
||||
* if (xt)
|
||||
* xml_free(xt);
|
||||
* @endcode
|
||||
* @see clicon_rpc_generate_error
|
||||
*/
|
||||
int
|
||||
clicon_rpc_get_config(clicon_handle h,
|
||||
char *db,
|
||||
char *xpath,
|
||||
int errmode,
|
||||
cxobj **xt)
|
||||
{
|
||||
int retval = -1;
|
||||
struct clicon_msg *msg = NULL;
|
||||
cbuf *cb = NULL;
|
||||
cxobj *xret = NULL;
|
||||
cxobj *xerr;
|
||||
cxobj *xd;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL)
|
||||
|
|
@ -267,22 +269,12 @@ clicon_rpc_get_config(clicon_handle h,
|
|||
goto done;
|
||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
||||
goto done;
|
||||
if (errmode == 0){ /* Move this to caller */
|
||||
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
|
||||
clicon_rpc_generate_error(xerr);
|
||||
/* Send xml error back: first check error, then ok */
|
||||
if ((xd = xpath_first(xret, "/rpc-reply/rpc-error")) != NULL)
|
||||
xd = xml_parent(xd); /* point to rpc-reply */
|
||||
else if ((xd = xpath_first(xret, "/rpc-reply/data/config")) == NULL)
|
||||
if ((xd = xml_new("config", NULL)) == NULL)
|
||||
goto done;
|
||||
}
|
||||
if ((xd = xpath_first(xret, "//data/config")) == NULL)
|
||||
if ((xd = xml_new("config", NULL)) == NULL)
|
||||
goto done;
|
||||
}
|
||||
else{ /* Send xml error back (this should be default behaviour) */
|
||||
if ((xd = xpath_first(xret, "//rpc-error")) == NULL){
|
||||
if ((xd = xpath_first(xret, "//data/config")) == NULL)
|
||||
if ((xd = xml_new("config", NULL)) == NULL)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (xt){
|
||||
if (xml_rm(xd) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -71,10 +71,6 @@
|
|||
#include "clixon_yang_type.h"
|
||||
#include "clixon_yang_parse.h"
|
||||
|
||||
/* Instead of using dynamic type lookup, use a cache that is evaluated early
|
||||
for static scope type binding */
|
||||
#define YANG_TYPE_CACHE 1
|
||||
|
||||
|
||||
/* Mapping between yang keyword string <--> clicon constants */
|
||||
static const map_str2int ykmap[] = {
|
||||
|
|
@ -1392,7 +1388,7 @@ yang_parse_file(clicon_handle h,
|
|||
* @param[in] module Name of main YANG module.
|
||||
* @param[out] fbuf Buffer containing filename
|
||||
*
|
||||
* @retval 1 Match founbd, Most recent entry returned in fbuf
|
||||
* @retval 1 Match found, Most recent entry returned in fbuf
|
||||
* @retval 0 No matching entry found
|
||||
* @retval -1 Error
|
||||
*/
|
||||
|
|
@ -1406,17 +1402,20 @@ yang_parse_find_match(clicon_handle h,
|
|||
struct dirent *dp = NULL;
|
||||
int ndp;
|
||||
cbuf *regex = NULL;
|
||||
char *regexstr;
|
||||
|
||||
if ((regex = cbuf_new()) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(regex, "^%s.*(.yang)$", module);
|
||||
regexstr = cbuf_get(regex);
|
||||
/* RFC 6020: The name of the file SHOULD be of the form:
|
||||
module-or-submodule-name ['@' revision-date] ( '.yang' / '.yin' )
|
||||
revision-date ::= 4DIGIT "-" 2DIGIT "-" 2DIGIT
|
||||
*/
|
||||
cprintf(regex, "^%s(@[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])?(.yang)$",
|
||||
module);
|
||||
if ((ndp = clicon_file_dirent(yang_dir,
|
||||
&dp,
|
||||
regexstr,
|
||||
cbuf_get(regex),
|
||||
S_IFREG)) < 0)
|
||||
goto done;
|
||||
/* Entries are sorted, last entry should be most recent date */
|
||||
|
|
@ -1587,10 +1586,9 @@ yang_parse(clicon_handle h,
|
|||
/* Add top module name as dbspec-name */
|
||||
clicon_dbspec_name_set(h, ymod->ys_argument);
|
||||
|
||||
#ifdef YANG_TYPE_CACHE
|
||||
/* Resolve all types */
|
||||
yang_apply((yang_node*)ysp, ys_resolve_type, NULL);
|
||||
#endif
|
||||
|
||||
/* Step 2: Macro expansion of all grouping/uses pairs. Expansion needs marking */
|
||||
if (yang_expand((yang_node*)ysp) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -178,7 +178,8 @@ yang_type_cache_get(yang_type_cache *ycache,
|
|||
}
|
||||
|
||||
int
|
||||
yang_type_cache_cp(yang_type_cache **ycnew, yang_type_cache *ycold)
|
||||
yang_type_cache_cp(yang_type_cache **ycnew,
|
||||
yang_type_cache *ycold)
|
||||
{
|
||||
int retval = -1;
|
||||
int options;
|
||||
|
|
@ -211,7 +212,8 @@ yang_type_cache_free(yang_type_cache *ycache)
|
|||
|
||||
/*! Resolve types: populate type caches */
|
||||
int
|
||||
ys_resolve_type(yang_stmt *ys, void *arg)
|
||||
ys_resolve_type(yang_stmt *ys,
|
||||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
int options = 0x0;
|
||||
|
|
@ -333,7 +335,9 @@ cv2yang_type(enum cv_type cv_type)
|
|||
* @param[out] cvtype
|
||||
*/
|
||||
int
|
||||
clicon_type2cv(char *origtype, char *restype, enum cv_type *cvtype)
|
||||
clicon_type2cv(char *origtype,
|
||||
char *restype,
|
||||
enum cv_type *cvtype)
|
||||
{
|
||||
int retval = -1;
|
||||
|
||||
|
|
@ -700,7 +704,7 @@ ys_typedef_up(yang_stmt *ys)
|
|||
This is a sanity check of base identity of identity-ref and for identity
|
||||
statements.
|
||||
|
||||
Return true if node is identityref and is derived from identity_name
|
||||
Return true if node is identityref and is derived from identity_name
|
||||
The derived-from() function returns true if the (first) node (in
|
||||
document order in the argument "nodes") is a node of type identityref,
|
||||
and its value is an identity that is derived from the identity
|
||||
|
|
@ -718,7 +722,8 @@ Return true if node is identityref and is derived from identity_name
|
|||
Så vad är det denna function ska göra? Svar: 1
|
||||
*/
|
||||
yang_stmt *
|
||||
yang_find_identity(yang_stmt *ys, char *identity)
|
||||
yang_find_identity(yang_stmt *ys,
|
||||
char *identity)
|
||||
{
|
||||
char *id;
|
||||
char *prefix = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue