From 3117332ddd670db221083eb2818e01196aca61ed Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 28 Dec 2021 11:44:19 +0100 Subject: [PATCH] Changes in clixon-config.yang: * Removed obsolete options: * `CLICON_YANG_LIST_CHECK` * `CLICON_RESTCONF_PATH` (moved to restconf/fcgi-path) * Fixed: Configure option `CLICON_RESTCONF_PRETTY` was marked as obsolete but was still used. * `CLICON_RESTCONF_PRETTY` is now obsolete for sure * Instead restconf/pretty is used with API function restconf_pretty_get() --- CHANGELOG.md | 8 ++++- apps/restconf/restconf_evhtp.c | 2 +- apps/restconf/restconf_handle.c | 37 ++++++++++++++++++++++- apps/restconf/restconf_handle.h | 2 ++ apps/restconf/restconf_lib.c | 11 +++---- apps/restconf/restconf_main_fcgi.c | 5 --- apps/restconf/restconf_nghttp2.c | 2 +- apps/restconf/restconf_root.c | 7 ++--- apps/restconf/restconf_stream_fcgi.c | 3 +- configure | 4 +-- configure.ac | 2 +- lib/src/clixon_data.c | 13 ++++++++ lib/src/clixon_yang.c | 2 +- lib/src/clixon_yang_parse_lib.c | 20 ++++-------- test/test_pagination_draft.sh | 1 - yang/clixon/clixon-config@2021-12-05.yang | 28 +++-------------- 16 files changed, 81 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f3b9d75..4d1c52a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,7 +59,13 @@ Users may have to change how they access the system * New `clixon-config@2021-12-05.yang` revision * Imported (as a sub-spec): clixon-clispec.yang - + * Removed obsolete options: + * `CLICON_YANG_LIST_CHECK` + * `CLICON_RESTCONF_PATH` (moved to restconf/fcgi-path) + * Fixed: Configure option `CLICON_RESTCONF_PRETTY` was marked as obsolete but was still used. + * `CLICON_RESTCONF_PRETTY` is now obsolete for sure + * Instead restconf/pretty is used with API function restconf_pretty_get() + ### Minor features * Tests: use `YANG_STANDARD_DIR` from `./configure --with-yang-standard-dir=DIR` instead of `YANGMODELS` from site.sh diff --git a/apps/restconf/restconf_evhtp.c b/apps/restconf/restconf_evhtp.c index 4905b45d..37cab196 100644 --- a/apps/restconf/restconf_evhtp.c +++ b/apps/restconf/restconf_evhtp.c @@ -255,7 +255,7 @@ convert_evhtp_params2clixon(clicon_handle h, if (restconf_param_set(h, "REQUEST_URI", path->full) < 0) goto done; clicon_debug(1, "%s proto:%d", __FUNCTION__, req->proto); - pretty = clicon_option_bool(h, "CLICON_RESTCONF_PRETTY"); + pretty = restconf_pretty_get(h); /* XXX: Any two http numbers seem accepted by evhtp, like 1.99, 99.3 as http/1.1*/ if (req->proto != EVHTP_PROTO_10 && req->proto != EVHTP_PROTO_11){ diff --git a/apps/restconf/restconf_handle.c b/apps/restconf/restconf_handle.c index 2573e237..8bf57f1f 100644 --- a/apps/restconf/restconf_handle.c +++ b/apps/restconf/restconf_handle.c @@ -93,6 +93,7 @@ struct restconf_handle { /* ------ end of common handle ------ */ clicon_hash_t *rh_params; /* restconf parameters, including http headers */ clixon_auth_type_t rh_auth_type; /* authentication type */ + int rh_pretty; /* pretty-print for http replies */ }; /*! Creates and returns a clicon config handle for other CLICON API calls @@ -100,7 +101,11 @@ struct restconf_handle { clicon_handle restconf_handle_init(void) { - return clicon_handle_init0(sizeof(struct restconf_handle)); + struct restconf_handle *rh; + + rh = clicon_handle_init0(sizeof(struct restconf_handle)); + rh->rh_pretty = 1; /* clixon-restconf.yang : pretty is default true*/ + return rh; } /*! Deallocates a backend handle, including all client structs @@ -205,3 +210,33 @@ restconf_auth_type_set(clicon_handle h, rh->rh_auth_type = type; return 0; } + +/*! Get restconf pretty-print (for replies) + * @param[in] h Clicon handle + * @retval pretty + */ +int +restconf_pretty_get(clicon_handle h) +{ + struct restconf_handle *rh = handle(h); + + return rh->rh_pretty; +} + +/*! Set restconf pretty-print + * @param[in] h Clicon handle + * @param[in] name Data name + * @param[in] val Data value as null-terminated string + * @retval 0 OK + * @retval -1 Error + * Currently using clixon runtime data but there is risk for colliding names + */ +int +restconf_pretty_set(clicon_handle h, + int pretty) +{ + struct restconf_handle *rh = handle(h); + + rh->rh_pretty = pretty; + return 0; +} diff --git a/apps/restconf/restconf_handle.h b/apps/restconf/restconf_handle.h index 9d5304ea..b19b7aca 100644 --- a/apps/restconf/restconf_handle.h +++ b/apps/restconf/restconf_handle.h @@ -49,5 +49,7 @@ int restconf_param_set(clicon_handle h, const char *param, char *val); int restconf_param_del_all(clicon_handle h); clixon_auth_type_t restconf_auth_type_get(clicon_handle h); int restconf_auth_type_set(clicon_handle h, clixon_auth_type_t type); +int restconf_pretty_get(clicon_handle h); +int restconf_pretty_set(clicon_handle h, int pretty); #endif /* _RESTCONF_HANDLE_H_ */ diff --git a/apps/restconf/restconf_lib.c b/apps/restconf/restconf_lib.c index 1bbc05dc..ec245721 100644 --- a/apps/restconf/restconf_lib.c +++ b/apps/restconf/restconf_lib.c @@ -773,13 +773,10 @@ restconf_config_init(clicon_handle h, } if ((x = xpath_first(xrestconf, nsc, "pretty")) != NULL && (bstr = xml_body(x)) != NULL){ - /* XXX redirection to (obsolete) option, fix by replacing its accesses */ - clicon_option_str_set(h, "CLICON_RESTCONF_PRETTY", bstr); - } - if ((x = xpath_first(xrestconf, nsc, "fcgi-socket")) != NULL && - (bstr = xml_body(x)) != NULL){ - /* XXX redirection to (obsolete) option, fix by replacing its accesses */ - clicon_option_str_set(h, "CLICON_RESTCONF_PATH", bstr); + if (strcmp(bstr, "true") == 0) + restconf_pretty_set(h, 1); + else if (strcmp(bstr, "false") == 0) + restconf_pretty_set(h, 0); } retval = 1; done: diff --git a/apps/restconf/restconf_main_fcgi.c b/apps/restconf/restconf_main_fcgi.c index 91e16b26..7bd08d0f 100644 --- a/apps/restconf/restconf_main_fcgi.c +++ b/apps/restconf/restconf_main_fcgi.c @@ -523,11 +523,6 @@ main(int argc, clicon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled"); goto done; } - /* XXX see restconf_config_init access directly */ - if ((sockpath = clicon_option_str(h, "CLICON_RESTCONF_PATH")) == NULL){ - clicon_err(OE_CFG, errno, "No CLICON_RESTCONF_PATH in clixon configure file"); - goto done; - } if (FCGX_Init() != 0){ /* How to cleanup memory after this? */ clicon_err(OE_CFG, errno, "FCGX_Init"); goto done; diff --git a/apps/restconf/restconf_nghttp2.c b/apps/restconf/restconf_nghttp2.c index 2b5768c9..299a488f 100644 --- a/apps/restconf/restconf_nghttp2.c +++ b/apps/restconf/restconf_nghttp2.c @@ -384,7 +384,7 @@ restconf_sd_read(nghttp2_session *session, #endif assert(cbuf_len(cb) > sd->sd_body_offset); remain = cbuf_len(cb) - sd->sd_body_offset; - clicon_debug(1, "%s length:%zu totlen:%d, offset:%zu remain:%zu", + clicon_debug(1, "%s length:%zu totlen:%zu, offset:%zu remain:%zu", __FUNCTION__, length, cbuf_len(cb), diff --git a/apps/restconf/restconf_root.c b/apps/restconf/restconf_root.c index 2bf7d1a1..a45fe5f6 100644 --- a/apps/restconf/restconf_root.c +++ b/apps/restconf/restconf_root.c @@ -84,7 +84,6 @@ api_well_known(clicon_handle h, int retval = -1; char *request_method; cbuf *cb = NULL; - int pretty; int head; clicon_debug(1, "%s", __FUNCTION__); @@ -95,8 +94,7 @@ api_well_known(clicon_handle h, request_method = restconf_param_get(h, "REQUEST_METHOD"); head = strcmp(request_method, "HEAD") == 0; if (!head && strcmp(request_method, "GET") != 0){ - pretty = clicon_option_bool(h, "CLICON_RESTCONF_PRETTY"); - if (restconf_method_notallowed(h, req, "GET,HEAD", pretty, YANG_DATA_JSON) < 0) + if (restconf_method_notallowed(h, req, "GET,HEAD", restconf_pretty_get(h), YANG_DATA_JSON) < 0) goto done; goto ok; } @@ -445,8 +443,7 @@ api_root_restconf(clicon_handle h, request_method = restconf_param_get(h, "REQUEST_METHOD"); if ((path = restconf_uripath(h)) == NULL) goto done; - /* XXX see restconf_config_init access directly */ - pretty = clicon_option_bool(h, "CLICON_RESTCONF_PRETTY"); + pretty = restconf_pretty_get(h); /* Get media for output (proactive negotiation) RFC7231 by using * Accept:. This is for methods that have output, such as GET, * operation POST, etc diff --git a/apps/restconf/restconf_stream_fcgi.c b/apps/restconf/restconf_stream_fcgi.c index ddac456a..e5175ab8 100644 --- a/apps/restconf/restconf_stream_fcgi.c +++ b/apps/restconf/restconf_stream_fcgi.c @@ -399,8 +399,7 @@ api_stream(clicon_handle h, clicon_debug(1, "%s", __FUNCTION__); if ((path = restconf_uripath(h)) == NULL) goto done; - /* XXX see restconf_config_init access directly */ - pretty = clicon_option_bool(h, "CLICON_RESTCONF_PRETTY"); + pretty = restconf_pretty_get(h); if ((pvec = clicon_strsep(path, "/", &pn)) == NULL) goto done; /* Sanity check of path. Should be /stream/ */ diff --git a/configure b/configure index 753420a9..0338238f 100755 --- a/configure +++ b/configure @@ -5666,8 +5666,8 @@ else fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Standard YANG files should be in ${YANG_STANDARD_DIR}" >&5 -$as_echo "Standard YANG files should be in ${YANG_STANDARD_DIR}" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Standard YANG files expected to be in ${YANG_STANDARD_DIR}" >&5 +$as_echo "Standard YANG files expected to be in ${YANG_STANDARD_DIR}" >&6; } # Default location for config file diff --git a/configure.ac b/configure.ac index 83fc588e..da69b2f8 100644 --- a/configure.ac +++ b/configure.ac @@ -344,7 +344,7 @@ AC_ARG_WITH(yang-standard-dir, [YANG_STANDARD_DIR="$withval"], [YANG_STANDARD_DIR="${prefix}/share/yang/standard"] ) -AC_MSG_RESULT(Standard YANG files should be in ${YANG_STANDARD_DIR}) +AC_MSG_RESULT(Standard YANG files expected to be in ${YANG_STANDARD_DIR}) # Default location for config file AC_DEFINE_UNQUOTED(CLIXON_DEFAULT_CONFIG,"${CLIXON_DEFAULT_CONFIG}",[Location for apps to find default config file]) diff --git a/lib/src/clixon_data.c b/lib/src/clixon_data.c index f7d383a9..32f170a0 100644 --- a/lib/src/clixon_data.c +++ b/lib/src/clixon_data.c @@ -428,6 +428,13 @@ clicon_nacm_cache_set(clicon_handle h, /*! Get YANG specification for Clixon system options and features * Must use hash functions directly since they are not strings. * Example: features are typically accessed directly in the config tree. + * @code + * cxobj *x = NULL; + * while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) { + * if (strcmp(xml_name(x), "CLICON_YANG_DIR") != 0) + * break; + * } + * @endcode */ cxobj * clicon_conf_xml(clicon_handle h) @@ -454,6 +461,9 @@ clicon_conf_xml_set(clicon_handle h, * That is, get the XML of clixon-config/restconf container of clixon-config.yang * @param[in] h Clicon handle * @retval x XML tree containing restconf xml node from clixon-restconf.yang + * @code + * cxobj *xrestconf = clicon_conf_restconf(h); + * @endcode * @note The clixon-restconf.yang instance can also be a part of the running datastore if * CLICON_BACKEND_RESTCONF_PROCESS is true */ @@ -472,6 +482,9 @@ clicon_conf_restconf(clicon_handle h) * That is, get the XML of clixon-config/clispec container of clixon-config.yang * @param[in] h Clicon handle * @retval x XML tree containing clispec xml node from clixon-clispec.yang + * @code + * cxobj *xclispec = clicon_conf_clispec(h); + * @endcode */ cxobj * clicon_conf_clispec(clicon_handle h) diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 05a48a92..c4475776 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -1201,7 +1201,7 @@ yang_find_schemanode(yang_stmt *yn, return ysmatch; } -/*! Given a yang statement, find the prefix associated to this module +/*! Given a yang statement, or module itself, find the prefix associated to this module * * @param[in] ys Yang statement in module tree (or module itself) * @retval NULL No prefix found. This is an error diff --git a/lib/src/clixon_yang_parse_lib.c b/lib/src/clixon_yang_parse_lib.c index 457d588c..68bb45c5 100644 --- a/lib/src/clixon_yang_parse_lib.c +++ b/lib/src/clixon_yang_parse_lib.c @@ -1260,8 +1260,7 @@ ys_schemanode_check(yang_stmt *ys, * Verify the following rule: * RFC 7950 7.8.2: The "key" statement, which MUST be present if the list represents * configuration and MAY be present otherwise - * Unless CLICON_YANG_LIST_CHECK is false (obsolete) - * OR it is the "errors" rule of the ietf-restconf spec which seems to be a special case. + * Unless it is the "errors" rule of the ietf-restconf spec which seems to be a special case. */ static int ys_list_check(clicon_handle h, @@ -1289,18 +1288,11 @@ ys_list_check(clicon_handle h, /* Except nokey exceptions such as rrc 8040 yang-data */ if (!yang_flag_get(yroot, YANG_FLAG_NOKEY)){ /* Note obsolete */ - if (clicon_option_bool(h, "CLICON_YANG_LIST_CHECK")){ - clicon_log(LOG_ERR, "Error: LIST \"%s\" in module \"%s\" lacks key statement which MUST be present (See RFC 7950 Sec 7.8.2)", - yang_argument_get(ys), - yang_argument_get(ymod) - ); - goto done; - } - else - clicon_log(LOG_WARNING, "Warning: LIST \"%s\" in module \"%s\" lacks key statement which MUST be present (See RFC 7950 Sec 7.8.2)", - yang_argument_get(ys), - yang_argument_get(ymod) - ); + clicon_log(LOG_ERR, "Error: LIST \"%s\" in module \"%s\" lacks key statement which MUST be present (See RFC 7950 Sec 7.8.2)", + yang_argument_get(ys), + yang_argument_get(ymod) + ); + goto done; } } /* Traverse subs */ diff --git a/test/test_pagination_draft.sh b/test/test_pagination_draft.sh index cd42e46b..0f1a5ebf 100755 --- a/test/test_pagination_draft.sh +++ b/test/test_pagination_draft.sh @@ -29,7 +29,6 @@ cat < $cfg /usr/local/share/clixon $IETFRFC $dir - false /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/$APPNAME/backend $dir/restconf.pidfile diff --git a/yang/clixon/clixon-config@2021-12-05.yang b/yang/clixon/clixon-config@2021-12-05.yang index cfaaa74e..3a8d6489 100644 --- a/yang/clixon/clixon-config@2021-12-05.yang +++ b/yang/clixon/clixon-config@2021-12-05.yang @@ -49,8 +49,11 @@ module clixon-config { revision 2021-12-05 { description "Added option: - Imported + Imported sub-spec: clixon-clispec.yang + Removed obsolete options: + CLICON_YANG_LIST_CHECK + CLICON_RESTCONF_PATH Released in Clixon 5.5"; } revision 2021-11-11 { @@ -456,19 +459,6 @@ module clixon-config { There is a 'good-enough' posix translation mode and a complete libxml2 mode"; } - leaf CLICON_YANG_LIST_CHECK { - type boolean; - default true; - description - "If false, skip Yang list check sanity checks from RFC 7950, Sec 7.8.2: - The 'key' statement, which MUST be present if the list represents configuration. - Some yang specs seem not to fulfil this. However, if you reset this, there may - be follow-up errors due to code that assumes a configuration list has keys - Marked as obsolete since the observation above seemed to be related to the - yang-data extension in RFC8040 allows non-key lists. This has been implemented - by a YANG_FLAG_NOKEY yang flag mechanism"; - status obsolete; - } leaf CLICON_YANG_UNKNOWN_ANYDATA{ type boolean; default false; @@ -531,16 +521,6 @@ module clixon-config { early in the bootstrapping phase, before clixon-restconf.yang config may be loaded."; } - leaf CLICON_RESTCONF_PATH { - type string; - default "/www-data/fastcgi_restconf.sock"; - description - "FastCGI unix socket. Should be specified in webserver - Eg in nginx: fastcgi_pass unix:/www-data/clicon_restconf.sock - Only if with-restconf=fcgi, NOT native - Note: Obsolete, use fcgi-socket in clixon-restconf.yang instead"; - status obsolete; - } leaf CLICON_RESTCONF_INSTALLDIR { type string; description