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

@ -56,7 +56,7 @@
/* cligen */
#include <cligen/cligen.h>
/* clicon */
/* clixon */
#include <clixon/clixon.h>
#include "restconf_lib.h"
@ -205,7 +205,7 @@ yang_patch_strip_after_last_slash(char* val)
* @retval -1 Error
*/
static int
yang_patch_do_replace(clicon_handle h,
yang_patch_do_replace(clixon_handle h,
void *req,
int pi,
cvec *qvec,
@ -226,23 +226,23 @@ yang_patch_do_replace(clicon_handle h,
cbuf *json_simple_patch = NULL;
if ((delete_req_uri = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if ((json_simple_patch = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
// Make delete_req_uri something like "/restconf/data/ietf-interfaces:interfaces"
if (cbuf_append_str(delete_req_uri, cbuf_get(simple_patch_request_uri)) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append_str");
clixon_err(OE_UNIX, errno, "cbuf_append_str");
goto done;
}
// Add the target to delete_req_uri,
// so it's something like "/restconf/data/ietf-interfaces:interfaces/interface=eth2"
if (cbuf_append_str(delete_req_uri, target_val) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append_str");
clixon_err(OE_UNIX, errno, "cbuf_append_str");
goto done;
}
@ -259,7 +259,7 @@ yang_patch_do_replace(clicon_handle h,
// Make post_req_uri something like "/restconf/data/ietf-interfaces:interfaces"
if (cbuf_append_str(simple_patch_request_uri, cbuf_get(post_req_uri)) < 0){
clicon_err(OE_UNIX, errno, "cbuf_append_str");
clixon_err(OE_UNIX, errno, "cbuf_append_str");
goto done;
}
// Now insert the new values into the data
@ -307,7 +307,7 @@ yang_patch_do_replace(clicon_handle h,
* @retval -1 Error
*/
static int
yang_patch_do_create(clicon_handle h,
yang_patch_do_create(clixon_handle h,
void *req,
int pi,
cvec *qvec,
@ -326,7 +326,7 @@ yang_patch_do_create(clicon_handle h,
// Send the POST request
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
for (int k = 0; k < value_vec_len; k++) {
@ -368,7 +368,7 @@ yang_patch_do_create(clicon_handle h,
* @retval -1 Error
*/
static int
yang_patch_do_insert(clicon_handle h,
yang_patch_do_insert(clixon_handle h,
void *req,
int pi,
int pretty,
@ -391,11 +391,11 @@ yang_patch_do_insert(clicon_handle h,
cvec *qvec_tmp = NULL;
if ((point_str = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if ((qvec_tmp = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
// Loop through the XML, and get each value
@ -410,7 +410,7 @@ yang_patch_do_insert(clicon_handle h,
// Set the insert attributes
if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_add");
clixon_err(OE_UNIX, errno, "cvec_add");
goto done;
}
cv_name_set(cv, "insert");
@ -420,7 +420,7 @@ yang_patch_do_insert(clicon_handle h,
if (point_val)
cbuf_append_str(point_str, point_val);
if ((cv = cvec_add(qvec_tmp, CGV_STRING)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_add");
clixon_err(OE_UNIX, errno, "cvec_add");
goto done;
}
cv_name_set(cv, "point");
@ -459,7 +459,7 @@ yang_patch_do_insert(clicon_handle h,
* @retval -1 Error
*/
static int
yang_patch_do_merge(clicon_handle h,
yang_patch_do_merge(clixon_handle h,
void *req,
int pi,
cvec *qvec,
@ -479,7 +479,7 @@ yang_patch_do_merge(clicon_handle h,
cbuf *json_simple_patch = NULL;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if (key_xn != NULL)
@ -521,7 +521,7 @@ yang_patch_do_merge(clicon_handle h,
* @retval -1 Error
*/
static int
yang_patch_do_value(clicon_handle h,
yang_patch_do_value(clixon_handle h,
void *req,
int pi,
cvec *qvec,
@ -551,7 +551,7 @@ yang_patch_do_value(clicon_handle h,
key_node_id = xml_name(*values_child_vec);
/* Create cbufs:s */
if ((patch_header = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
cprintf(patch_header, "%s:%s", modname, key_node_id);
@ -601,7 +601,7 @@ yang_patch_do_value(clicon_handle h,
* @retval -1 Error
*/
static int
yang_patch_do_edit(clicon_handle h,
yang_patch_do_edit(clixon_handle h,
void *req,
int pi,
cvec *qvec,
@ -638,26 +638,26 @@ yang_patch_do_edit(clicon_handle h,
clixon_debug_xml(1, xn, "%s %d xn:", __FUNCTION__, __LINE__);
/* Create cbufs:s */
if ((simple_patch_request_uri = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if ((api_path_target = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if ((x = xpath_first(xn, NULL, "target")) == NULL){
clicon_err(OE_YANG, 0, "target mandatory element not found");
clixon_err(OE_YANG, 0, "target mandatory element not found");
goto done;
}
target_val = xml_body(x);
if ((x = xpath_first(xn, NULL, "operation")) == NULL){
clicon_err(OE_YANG, 0, "operation mandatory element not found");
clixon_err(OE_YANG, 0, "operation mandatory element not found");
goto done;
}
operation = yang_patch_op2int(xml_body(x));
/* target and operation are mandatory */
if (target_val == NULL){
clicon_err(OE_YANG, 0, "operation/target: mandatory element not found");
clixon_err(OE_YANG, 0, "operation/target: mandatory element not found");
goto done;
}
if (operation == YANG_PATCH_OP_INSERT){
@ -666,7 +666,7 @@ yang_patch_do_edit(clicon_handle h,
if ((x = xpath_first(xn, NULL, "where")) != NULL)
where_val = xml_body(x);
if (point_val == NULL || where_val == NULL){
clicon_err(OE_YANG, 0, "point/where: expected element not found");
clixon_err(OE_YANG, 0, "point/where: expected element not found");
goto done;
}
}
@ -756,7 +756,7 @@ yang_patch_do_edit(clicon_handle h,
* Currently "move" not supported
*/
int
api_data_yang_patch(clicon_handle h,
api_data_yang_patch(clixon_handle h,
void *req,
char *api_path0,
int pi,
@ -780,7 +780,7 @@ api_data_yang_patch(clicon_handle h,
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
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;
}
api_path=api_path0;
@ -808,7 +808,7 @@ api_data_yang_patch(clicon_handle h,
}
/* Common error handling for json/xml parsing above */
if (ret < 0){
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
if (netconf_malformed_message_xml(&xerr, clixon_err_reason()) < 0)
goto done;
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
goto done;
@ -860,7 +860,7 @@ api_data_yang_patch(clicon_handle h,
#else // CLIXON_YANG_PATCH
int
api_data_yang_patch(clicon_handle h,
api_data_yang_patch(clixon_handle h,
void *req,
char *api_path0,
int pi,
@ -871,7 +871,7 @@ api_data_yang_patch(clicon_handle h,
restconf_media media_out,
ietf_ds_t ds)
{
clicon_err(OE_RESTCONF, 0, "Not implemented");
clixon_err(OE_RESTCONF, 0, "Not implemented");
return -1;
}
#endif // CLIXON_YANG_PATCH