Restructured error,debug anf log API

Renamed functions clicon->clixon, replaced global variables w access functions
Unified clicon_netconf_error with clixon_err()
This commit is contained in:
Olof hagsand 2023-11-13 10:12:52 +01:00
parent 261469be16
commit 24a4991ec8
199 changed files with 4668 additions and 4158 deletions

View file

@ -61,7 +61,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
#include "restconf_api.h"
@ -265,7 +265,7 @@ restconf_proto2str(int proto)
*
*/
restconf_media
restconf_content_type(clicon_handle h)
restconf_content_type(clixon_handle h)
{
char *str = NULL;
restconf_media m;
@ -282,7 +282,7 @@ restconf_content_type(clicon_handle h)
* Example: Host -> HTTP_HOST
*/
int
restconf_convert_hdr(clicon_handle h,
restconf_convert_hdr(clixon_handle h,
char *name,
char *val)
{
@ -293,7 +293,7 @@ restconf_convert_hdr(clicon_handle h,
size_t len;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
/* convert key name */
@ -353,7 +353,7 @@ get_user_cookie(char *cookiestr,
* @param[in] h Clixon handle
*/
int
restconf_terminate(clicon_handle h)
restconf_terminate(clixon_handle h)
{
yang_stmt *yspec;
cvec *nsctx;
@ -379,7 +379,7 @@ restconf_terminate(clicon_handle h)
restconf_handle_exit(h);
clixon_err_exit();
clixon_debug(CLIXON_DBG_DEFAULT, "%s pid:%u done", __FUNCTION__, getpid());
clicon_log_exit(); /* Must be after last clixon_debug */
clixon_log_exit(); /* Must be after last clixon_debug */
return 0;
}
@ -432,7 +432,7 @@ restconf_insert_attributes(cxobj *xdata,
}
if ((pstr = cvec_find_str(qvec, "point")) != NULL){
if (y == NULL){
clicon_err(OE_YANG, 0, "Cannot yang resolve %s", xml_name(xdata));
clixon_err(OE_YANG, 0, "Cannot yang resolve %s", xml_name(xdata));
goto done;
}
if (yang_keyword_get(y) == Y_LIST)
@ -443,7 +443,7 @@ restconf_insert_attributes(cxobj *xdata,
if ((ret = api_path2xpath(pstr, ys_spec(y), &xpath, &nsc, NULL)) < 0)
goto done;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if (yang_keyword_get(y) == Y_LIST){
@ -456,12 +456,12 @@ restconf_insert_attributes(cxobj *xdata,
else{ /* LEAF_LIST */
/* translate /../x[.='x'] --> x */
if ((p = rindex(xpath,'\'')) == NULL){
clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
clixon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
goto done;
}
*p = '\0';
if ((p = rindex(xpath,'\'')) == NULL){
clicon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
clixon_err(OE_YANG, 0, "Translated api->xpath %s->%s not on leaf-list canonical form: ../[.='x']", pstr, xpath);
goto done;
}
p++;
@ -508,7 +508,7 @@ restconf_insert_attributes(cxobj *xdata,
* @see ietf-restconf.yang
*/
int
restconf_main_extension_cb(clicon_handle h,
restconf_main_extension_cb(clixon_handle h,
yang_stmt *yext,
yang_stmt *ys)
{
@ -547,18 +547,18 @@ restconf_main_extension_cb(clicon_handle h,
* @retval path malloced, need free
*/
char *
restconf_uripath(clicon_handle h)
restconf_uripath(clixon_handle h)
{
char *path = NULL;
char *path2 = NULL;
char *q;
if ((path = restconf_param_get(h, "REQUEST_URI")) == NULL){
clicon_err(OE_RESTCONF, 0, "No REQUEST_URI");
clixon_err(OE_RESTCONF, 0, "No REQUEST_URI");
return NULL;
}
if ((path2 = strdup(path)) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
clixon_err(OE_UNIX, errno, "strdup");
return NULL;
}
if ((q = index(path2, '?')) != NULL)
@ -574,7 +574,7 @@ restconf_uripath(clicon_handle h)
* Group set to CLICON_SOCK_GROUP to communicate with backend
*/
int
restconf_drop_privileges(clicon_handle h)
restconf_drop_privileges(clixon_handle h)
{
int retval = -1;
uid_t newuid = -1;
@ -587,11 +587,11 @@ restconf_drop_privileges(clicon_handle h)
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
/* Sanity check: backend group exists */
if ((group = clicon_sock_group(h)) == NULL){
clicon_err(OE_FATAL, 0, "clicon_sock_group option not set");
clixon_err(OE_FATAL, 0, "clicon_sock_group option not set");
return -1;
}
if (group_name2gid(group, &gid) < 0){
clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group." /* \n required here due to multi-line log */
clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group." /* \n required here due to multi-line log */
"The config daemon requires a valid group to create a server UNIX socket\n"
"Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n"
"or create the group and add the user to it. Check documentation for how to do this on your platform",
@ -608,18 +608,18 @@ restconf_drop_privileges(clicon_handle h)
/* Get (wanted) new www user id */
if (name2uid(user, &newuid) < 0){
clicon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", user);
clixon_err(OE_DAEMON, errno, "'%s' is not a valid user .\n", user);
goto done;
}
/* get current userid, if already at this level OK */
if ((uid = getuid()) == newuid)
goto ok;
if (uid != 0){
clicon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid);
clixon_err(OE_DAEMON, EPERM, "Privileges can only be dropped from root user (uid is %u)\n", uid);
goto done;
}
if (setgid(gid) == -1) {
clicon_err(OE_DAEMON, errno, "setgid %d", gid);
clixon_err(OE_DAEMON, errno, "setgid %d", gid);
goto done;
}
switch (priv_mode){
@ -628,7 +628,7 @@ restconf_drop_privileges(clicon_handle h)
goto done;
/* Verify you cannot regain root privileges */
if (setuid(0) != -1){
clicon_err(OE_DAEMON, EPERM, "Could regain root privilieges");
clixon_err(OE_DAEMON, EPERM, "Could regain root privilieges");
goto done;
}
break;
@ -658,7 +658,7 @@ restconf_drop_privileges(clicon_handle h)
* @retval -1 Error
*/
int
restconf_authentication_cb(clicon_handle h,
restconf_authentication_cb(clixon_handle h,
void *req,
int pretty,
restconf_media media_out)
@ -746,7 +746,7 @@ restconf_authentication_cb(clicon_handle h,
* @retval -1 Error
*/
int
restconf_config_init(clicon_handle h,
restconf_config_init(clixon_handle h,
cxobj *xrestconf)
{
int retval = -1;
@ -759,7 +759,7 @@ restconf_config_init(clicon_handle h,
yang_stmt *y;
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
}
/* Apply default values (removed in clear function) */
@ -776,7 +776,7 @@ restconf_config_init(clicon_handle h,
if ((x = xpath_first(xrestconf, nsc, "auth-type")) != NULL &&
(bstr = xml_body(x)) != NULL){
if ((auth_type = clixon_auth_type_str2int(bstr)) < 0){
clicon_err(OE_CFG, EFAULT, "Invalid restconf auth-type: %s", bstr);
clixon_err(OE_CFG, EFAULT, "Invalid restconf auth-type: %s", bstr);
goto done;
}
restconf_auth_type_set(h, auth_type);