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()
This commit is contained in:
Olof hagsand 2021-12-28 11:44:19 +01:00
parent 32930f4f6b
commit 3117332ddd
16 changed files with 81 additions and 66 deletions

View file

@ -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){

View file

@ -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;
}

View file

@ -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_ */

View file

@ -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:

View file

@ -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;

View file

@ -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),

View file

@ -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

View file

@ -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/<name> */