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:
parent
261469be16
commit
24a4991ec8
199 changed files with 4668 additions and 4158 deletions
|
|
@ -41,7 +41,7 @@
|
|||
*/
|
||||
struct clixon_http1_yacc {
|
||||
const char *hy_name; /* Name of syntax (for error string) */
|
||||
clicon_handle hy_h; /* Clixon handle */
|
||||
clixon_handle hy_h; /* Clixon handle */
|
||||
restconf_conn *hy_rc; /* Connection handle */
|
||||
int hy_linenum; /* Number of \n in parsed buffer */
|
||||
char *hy_parse_string; /* original (copy of) parse string */
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@
|
|||
/* typecast macro */
|
||||
#define _HY ((clixon_http1_yacc *)_hy)
|
||||
|
||||
#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_http1_parsetext, _HY->hy_linenum); YYERROR;}
|
||||
#define _YYERROR(msg) {clixon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_http1_parsetext, _HY->hy_linenum); YYERROR;}
|
||||
|
||||
/* add _yy to error parameters */
|
||||
#define YY_(msgid) msgid
|
||||
|
|
@ -124,7 +124,7 @@ void
|
|||
clixon_http1_parseerror(void *_hy,
|
||||
char *s)
|
||||
{
|
||||
clicon_err(OE_RESTCONF, 0, "%s on line %d: %s at or before: '%s'",
|
||||
clixon_err(OE_RESTCONF, 0, "%s on line %d: %s at or before: '%s'",
|
||||
_HY->hy_name,
|
||||
_HY->hy_linenum,
|
||||
s,
|
||||
|
|
@ -153,7 +153,7 @@ http1_parse_query(clixon_http1_yacc *hy,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s: ?%s ", __FUNCTION__, query);
|
||||
if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){
|
||||
clicon_err(OE_RESTCONF, 0, "stream 0 not found");
|
||||
clixon_err(OE_RESTCONF, 0, "stream 0 not found");
|
||||
goto done;
|
||||
}
|
||||
if (uri_str2cvec(query, '&', '=', 1, &sd->sd_qvec) < 0)
|
||||
|
|
@ -172,11 +172,11 @@ http1_body(clixon_http1_yacc *hy,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s: %s ", __FUNCTION__, body);
|
||||
if ((sd = restconf_stream_find(hy->hy_rc, 0)) == NULL){
|
||||
clicon_err(OE_RESTCONF, 0, "stream 0 not found");
|
||||
clixon_err(OE_RESTCONF, 0, "stream 0 not found");
|
||||
goto done;
|
||||
}
|
||||
if (cbuf_append_buf(sd->sd_indata, body, strlen(body)) < 0){
|
||||
clicon_err(OE_RESTCONF, errno, "cbuf_append_buf");
|
||||
clixon_err(OE_RESTCONF, errno, "cbuf_append_buf");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
/* restconf */
|
||||
|
|
@ -91,7 +91,7 @@ static const map_str2str mime_map[] = {
|
|||
* @retval 0 No, not a data path, or not enabled
|
||||
*/
|
||||
int
|
||||
api_path_is_data(clicon_handle h)
|
||||
api_path_is_data(clixon_handle h)
|
||||
{
|
||||
int retval = 0;
|
||||
char *path = NULL;
|
||||
|
|
@ -124,7 +124,7 @@ api_path_is_data(clicon_handle h)
|
|||
* @see api_return_err
|
||||
*/
|
||||
static int
|
||||
api_http_data_err(clicon_handle h,
|
||||
api_http_data_err(clixon_handle h,
|
||||
void *req,
|
||||
int code)
|
||||
{
|
||||
|
|
@ -133,7 +133,7 @@ api_http_data_err(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (restconf_reply_header(req, "Content-Type", "text/html") < 0)
|
||||
|
|
@ -173,7 +173,7 @@ api_http_data_err(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
http_data_check_file_path(clicon_handle h,
|
||||
http_data_check_file_path(clixon_handle h,
|
||||
void *req,
|
||||
char *prefix,
|
||||
cbuf *cbpath,
|
||||
|
|
@ -188,13 +188,13 @@ http_data_check_file_path(clicon_handle h,
|
|||
FILE *f;
|
||||
|
||||
if (prefix == NULL || cbpath == NULL || fp == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "prefix, cbpath0 or fp is NULL");
|
||||
clixon_err(OE_UNIX, EINVAL, "prefix, cbpath0 or fp is NULL");
|
||||
goto done;
|
||||
}
|
||||
p = cbuf_get(cbpath);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, p);
|
||||
if (strncmp(prefix, p, strlen(prefix)) != 0){
|
||||
clicon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath");
|
||||
clixon_err(OE_UNIX, EINVAL, "prefix is not prefix of cbpath");
|
||||
goto done;
|
||||
}
|
||||
for (i=strlen(prefix); i<strlen(p); i++){
|
||||
|
|
@ -277,7 +277,7 @@ http_data_check_file_path(clicon_handle h,
|
|||
* XXX 1: Buffer copying once too many, see #if 0 below
|
||||
*/
|
||||
static int
|
||||
api_http_data_file(clicon_handle h,
|
||||
api_http_data_file(clixon_handle h,
|
||||
void *req,
|
||||
char *pathname,
|
||||
int head)
|
||||
|
|
@ -298,11 +298,11 @@ api_http_data_file(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if ((cbfile = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((www_data_root = clicon_option_str(h, "CLICON_HTTP_DATA_ROOT")) == NULL){
|
||||
clicon_err(OE_RESTCONF, ENOENT, "CLICON_HTTP_DATA_ROOT missing");
|
||||
clixon_err(OE_RESTCONF, ENOENT, "CLICON_HTTP_DATA_ROOT missing");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -346,18 +346,18 @@ api_http_data_file(clicon_handle h,
|
|||
}
|
||||
fseek(f, 0, SEEK_SET); /* same as rewind(f); */
|
||||
if ((cbdata = cbuf_new_alloc(fsize+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new_alloc");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new_alloc");
|
||||
goto done;
|
||||
}
|
||||
/* Unoptimized, no direct read but requires an extra copy,
|
||||
* the cligen buf API should have some mechanism for this case without the extra copy.
|
||||
*/
|
||||
if ((buf = malloc(fsize)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = fread(buf, fsize, 1, f)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "fread");
|
||||
clixon_err(OE_UNIX, errno, "fread");
|
||||
goto done;
|
||||
}
|
||||
sz = (size_t)ret;
|
||||
|
|
@ -368,7 +368,7 @@ api_http_data_file(clicon_handle h,
|
|||
goto ok;
|
||||
}
|
||||
if (cbuf_append_buf(cbdata, buf, fsize) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_append_str");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_append_str");
|
||||
goto done;
|
||||
}
|
||||
if (restconf_reply_header(req, "Content-Type", "%s", media) < 0)
|
||||
|
|
@ -410,7 +410,7 @@ api_http_data_file(clicon_handle h,
|
|||
* Need to enable clixon-restconf.yang www-data feature
|
||||
*/
|
||||
int
|
||||
api_http_data(clicon_handle h,
|
||||
api_http_data(clixon_handle h,
|
||||
void *req,
|
||||
cvec *qvec)
|
||||
{
|
||||
|
|
@ -459,7 +459,7 @@ api_http_data(clicon_handle h,
|
|||
}
|
||||
/* 4. indata should be NULL (no write operations) */
|
||||
if ((indata = restconf_get_indata(req)) == NULL) {
|
||||
clicon_err(OE_RESTCONF, ENOENT, "Unexpected no input cbuf");
|
||||
clixon_err(OE_RESTCONF, ENOENT, "Unexpected no input cbuf");
|
||||
goto done;
|
||||
}
|
||||
if (cbuf_len(indata)){
|
||||
|
|
@ -474,7 +474,7 @@ api_http_data(clicon_handle h,
|
|||
else if (strcmp(media_str, "*/*") != 0 &&
|
||||
strcmp(media_str, "text/html") != 0){
|
||||
#ifdef NOTYET
|
||||
clicon_log(LOG_NOTICE, "%s: media error %s", __FUNCTION__, media_str);
|
||||
clixon_log(h, LOG_NOTICE, "%s: media error %s", __FUNCTION__, media_str);
|
||||
goto done;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int api_path_is_data(clicon_handle h);
|
||||
int api_http_data(clicon_handle h, void *req, cvec *qvec);
|
||||
int api_path_is_data(clixon_handle h);
|
||||
int api_http_data(clixon_handle h, void *req, cvec *qvec);
|
||||
|
||||
#endif /* _CLIXON_HTTP_DATA_H_ */
|
||||
|
|
|
|||
|
|
@ -69,12 +69,12 @@ const char *restconf_code2reason(int code);
|
|||
const restconf_media restconf_media_str2int(char *media);
|
||||
const char *restconf_media_int2str(restconf_media media);
|
||||
int get_user_cookie(char *cookiestr, char *attribute, char **val);
|
||||
int restconf_terminate(clicon_handle h);
|
||||
int restconf_terminate(clixon_handle h);
|
||||
int restconf_insert_attributes(cxobj *xdata, cvec *qvec);
|
||||
int restconf_main_extension_cb(clicon_handle h, yang_stmt *yext, yang_stmt *ys);
|
||||
int restconf_main_extension_cb(clixon_handle h, yang_stmt *yext, yang_stmt *ys);
|
||||
/* also in restconf_handle.h */
|
||||
char *restconf_param_get(clicon_handle h, const char *param);
|
||||
int restconf_param_set(clicon_handle h, const char *param, char *val);
|
||||
char *restconf_param_get(clixon_handle h, const char *param);
|
||||
int restconf_param_set(clixon_handle h, const char *param, char *val);
|
||||
|
||||
#endif /* _CLIXON_RESTCONF_H_ */
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
/* restconf */
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include <fcgiapp.h> /* Need to be after clixon_xml-h due to attribute format */
|
||||
|
|
@ -108,7 +108,7 @@ restconf_reply_header(void *req0,
|
|||
va_list ap;
|
||||
|
||||
if (req == NULL || name == NULL || vfmt == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "req, name or value is NULL");
|
||||
clixon_err(OE_CFG, EINVAL, "req, name or value is NULL");
|
||||
return -1;
|
||||
}
|
||||
va_start(ap, vfmt);
|
||||
|
|
@ -116,13 +116,13 @@ restconf_reply_header(void *req0,
|
|||
va_end(ap);
|
||||
/* allocate value string exactly fitting */
|
||||
if ((value = malloc(vlen+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute actual value */
|
||||
va_start(ap, vfmt);
|
||||
if (vsnprintf(value, vlen+1, vfmt, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ restconf_reply_body_add(void *req0,
|
|||
va_list ap;
|
||||
|
||||
if (req == NULL || bfmt == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "req or body is NULL");
|
||||
clixon_err(OE_CFG, EINVAL, "req or body is NULL");
|
||||
return -1;
|
||||
}
|
||||
va_start(ap, bfmt);
|
||||
|
|
@ -166,13 +166,13 @@ restconf_reply_body_add(void *req0,
|
|||
va_end(ap);
|
||||
/* allocate body string exactly fitting */
|
||||
if ((body = malloc(blen+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* second round: compute actual body */
|
||||
va_start(ap, bfmt);
|
||||
if (vsnprintf(body, blen+1, bfmt, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include "restconf_lib.h"
|
||||
|
|
@ -88,11 +88,11 @@ restconf_reply_header(void *req0,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, name);
|
||||
if (sd == NULL || name == NULL || vfmt == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "sd, name or value is NULL");
|
||||
clixon_err(OE_CFG, EINVAL, "sd, name or value is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((rc = sd->sd_conn) == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "rc is NULL");
|
||||
clixon_err(OE_CFG, EINVAL, "rc is NULL");
|
||||
goto done;
|
||||
}
|
||||
/* First round: compute vlen and allocate value */
|
||||
|
|
@ -101,19 +101,19 @@ restconf_reply_header(void *req0,
|
|||
va_end(ap);
|
||||
/* allocate value string exactly fitting */
|
||||
if ((value = malloc(vlen+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
/* Second round: compute actual value */
|
||||
va_start(ap, vfmt);
|
||||
if (vsnprintf(value, vlen+1, vfmt, ap) < 0){
|
||||
clicon_err(OE_UNIX, errno, "vsnprintf");
|
||||
clixon_err(OE_UNIX, errno, "vsnprintf");
|
||||
va_end(ap);
|
||||
goto done;
|
||||
}
|
||||
va_end(ap);
|
||||
if (cvec_add_string(sd->sd_outp_hdrs, (char*)name, value) < 0){
|
||||
clicon_err(OE_RESTCONF, errno, "cvec_add_string");
|
||||
clixon_err(OE_RESTCONF, errno, "cvec_add_string");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -144,7 +144,7 @@ restconf_reply_send(void *req0,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s code:%d", __FUNCTION__, code);
|
||||
if (sd == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "sd is NULL");
|
||||
clixon_err(OE_CFG, EINVAL, "sd is NULL");
|
||||
goto done;
|
||||
}
|
||||
sd->sd_code = code;
|
||||
|
|
@ -183,7 +183,7 @@ restconf_get_indata(void *req0)
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if (sd == NULL){
|
||||
clicon_err(OE_CFG, EINVAL, "sd is NULL");
|
||||
clixon_err(OE_CFG, EINVAL, "sd is NULL");
|
||||
goto done;
|
||||
}
|
||||
cb = sd->sd_indata;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include "restconf_lib.h"
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
restconf_method_notallowed(clicon_handle h,
|
||||
restconf_method_notallowed(clixon_handle h,
|
||||
void *req,
|
||||
char *allow,
|
||||
int pretty,
|
||||
|
|
@ -112,7 +112,7 @@ restconf_method_notallowed(clicon_handle h,
|
|||
* return an error response with a "415 Unsupported Media Type" status-line
|
||||
*/
|
||||
int
|
||||
restconf_unsupported_media(clicon_handle h,
|
||||
restconf_unsupported_media(clixon_handle h,
|
||||
void *req,
|
||||
int pretty,
|
||||
restconf_media media)
|
||||
|
|
@ -142,7 +142,7 @@ restconf_unsupported_media(clicon_handle h,
|
|||
* return an error response with a "406 Not Acceptable" status-line.
|
||||
*/
|
||||
int
|
||||
restconf_not_acceptable(clicon_handle h,
|
||||
restconf_not_acceptable(clixon_handle h,
|
||||
void *req,
|
||||
int pretty,
|
||||
restconf_media media)
|
||||
|
|
@ -166,7 +166,7 @@ restconf_not_acceptable(clicon_handle h,
|
|||
* @param[in] req Generic http handle
|
||||
*/
|
||||
int
|
||||
restconf_notimplemented(clicon_handle h,
|
||||
restconf_notimplemented(clixon_handle h,
|
||||
void *req,
|
||||
int pretty,
|
||||
restconf_media media)
|
||||
|
|
@ -201,7 +201,7 @@ restconf_notimplemented(clicon_handle h,
|
|||
* @note there are special cases see code
|
||||
*/
|
||||
int
|
||||
api_return_err(clicon_handle h,
|
||||
api_return_err(clixon_handle h,
|
||||
void *req,
|
||||
cxobj *xerr,
|
||||
int pretty,
|
||||
|
|
@ -220,7 +220,7 @@ api_return_err(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* A well-formed error message when entering here should look like:
|
||||
|
|
@ -230,7 +230,7 @@ api_return_err(clicon_handle h,
|
|||
if (strcmp(xml_name(xerr), "rpc-error") != 0 ||
|
||||
(xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "Internal error, system returned invalid error message: ");
|
||||
|
|
@ -240,11 +240,11 @@ api_return_err(clicon_handle h,
|
|||
cbuf_get(cberr)) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xerr2, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, 0, "Internal error, shouldnt happen");
|
||||
clixon_err(OE_XML, 0, "Internal error, shouldnt happen");
|
||||
goto done;
|
||||
}
|
||||
if ((xtag = xpath_first(xerr, NULL, "error-tag")) == NULL){
|
||||
clicon_err(OE_XML, 0, "Internal error, shouldnt happen");
|
||||
clixon_err(OE_XML, 0, "Internal error, shouldnt happen");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -318,7 +318,7 @@ api_return_err(clicon_handle h,
|
|||
}
|
||||
break;
|
||||
default: /* Just ignore the body so that there is a reply */
|
||||
clicon_err(OE_YANG, EINVAL, "Invalid media type %d", media);
|
||||
clixon_err(OE_YANG, EINVAL, "Invalid media type %d", media);
|
||||
goto done;
|
||||
break;
|
||||
} /* switch media */
|
||||
|
|
@ -353,7 +353,7 @@ api_return_err(clicon_handle h,
|
|||
* @see api_return_err where top level is expected to be <rpc-error>
|
||||
*/
|
||||
int
|
||||
api_return_err0(clicon_handle h,
|
||||
api_return_err0(clixon_handle h,
|
||||
void *req,
|
||||
cxobj *xerr,
|
||||
int pretty,
|
||||
|
|
@ -364,7 +364,7 @@ api_return_err0(clicon_handle h,
|
|||
cxobj *xe;
|
||||
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "Expected xml on the form <rpc-error>..");
|
||||
clixon_err(OE_XML, EINVAL, "Expected xml on the form <rpc-error>..");
|
||||
goto done;
|
||||
}
|
||||
if (api_return_err(h, req, xe, pretty, media, code) < 0)
|
||||
|
|
|
|||
|
|
@ -43,13 +43,13 @@
|
|||
* Prototypes
|
||||
*/
|
||||
|
||||
int restconf_method_notallowed(clicon_handle h, void *req, char *allow, int pretty, restconf_media media);
|
||||
int restconf_unsupported_media(clicon_handle h, void *req, int pretty, restconf_media media);
|
||||
int restconf_not_acceptable(clicon_handle h, void *req, int pretty, restconf_media media);
|
||||
int restconf_notimplemented(clicon_handle h, void *req, int pretty, restconf_media media);
|
||||
int restconf_method_notallowed(clixon_handle h, void *req, char *allow, int pretty, restconf_media media);
|
||||
int restconf_unsupported_media(clixon_handle h, void *req, int pretty, restconf_media media);
|
||||
int restconf_not_acceptable(clixon_handle h, void *req, int pretty, restconf_media media);
|
||||
int restconf_notimplemented(clixon_handle h, void *req, int pretty, restconf_media media);
|
||||
|
||||
int api_return_err(clicon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0);
|
||||
int api_return_err0(clicon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0);
|
||||
int api_return_err(clixon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0);
|
||||
int api_return_err0(clixon_handle h, void *req, cxobj *xerr, int pretty, restconf_media media, int code0);
|
||||
|
||||
|
||||
#endif /* _RESTCONF_ERR_H_ */
|
||||
|
|
|
|||
|
|
@ -58,20 +58,20 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include "restconf_lib.h"
|
||||
#include "restconf_handle.h"
|
||||
|
||||
/* header part is copied from struct clicon_handle in lib/src/clixon_handle.c */
|
||||
/* header part is copied from struct clixon_handle in lib/src/clixon_handle.c */
|
||||
|
||||
#define CLICON_MAGIC 0x99aafabe
|
||||
|
||||
#define handle(h) (assert(clicon_handle_check(h)==0),(struct restconf_handle *)(h))
|
||||
#define handle(h) (assert(clixon_handle_check(h)==0),(struct restconf_handle *)(h))
|
||||
|
||||
/* Clicon_handle for backends.
|
||||
* First part of this is header, same for clicon_handle and cli_handle.
|
||||
/* Clixon_handle for backends.
|
||||
* First part of this is header, same for clixon_handle and cli_handle.
|
||||
* Access functions for common fields are found in clicon lib: clicon_options.[ch]
|
||||
* This file should only contain access functions for the _specific_
|
||||
* entries in the struct below.
|
||||
|
|
@ -80,8 +80,8 @@
|
|||
*
|
||||
* This file should only contain access functions for the _specific_
|
||||
* entries in the struct below.
|
||||
* @note The top part must be equivalent to struct clicon_handle in clixon_handle.c
|
||||
* @see struct clicon_handle, struct cli_handle
|
||||
* @note The top part must be equivalent to struct clixon_handle in clixon_handle.c
|
||||
* @see struct clixon_handle, struct cli_handle
|
||||
*/
|
||||
struct restconf_handle {
|
||||
int rh_magic; /* magic (HDR)*/
|
||||
|
|
@ -100,12 +100,12 @@ struct restconf_handle {
|
|||
|
||||
/*! Creates and returns a clicon config handle for other CLICON API calls
|
||||
*/
|
||||
clicon_handle
|
||||
clixon_handle
|
||||
restconf_handle_init(void)
|
||||
{
|
||||
struct restconf_handle *rh;
|
||||
|
||||
rh = clicon_handle_init0(sizeof(struct restconf_handle));
|
||||
rh = clixon_handle_init0(sizeof(struct restconf_handle));
|
||||
rh->rh_pretty = 1; /* clixon-restconf.yang : pretty is default true*/
|
||||
return rh;
|
||||
}
|
||||
|
|
@ -116,13 +116,13 @@ restconf_handle_init(void)
|
|||
* @see backend_client_rm
|
||||
*/
|
||||
int
|
||||
restconf_handle_exit(clicon_handle h)
|
||||
restconf_handle_exit(clixon_handle h)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
||||
if (rh->rh_fcgi_socket)
|
||||
free(rh->rh_fcgi_socket);
|
||||
clicon_handle_exit(h); /* frees h and options (and streams) */
|
||||
clixon_handle_exit(h); /* frees h and options (and streams) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ restconf_handle_exit(clicon_handle h)
|
|||
* Currently using clixon runtime data but there is risk for colliding names
|
||||
*/
|
||||
char *
|
||||
restconf_param_get(clicon_handle h,
|
||||
restconf_param_get(clixon_handle h,
|
||||
const char *param)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
|
@ -154,7 +154,7 @@ restconf_param_get(clicon_handle h,
|
|||
* Currently using clixon runtime data but there is risk for colliding names
|
||||
*/
|
||||
int
|
||||
restconf_param_set(clicon_handle h,
|
||||
restconf_param_set(clixon_handle h,
|
||||
const char *param,
|
||||
char *val)
|
||||
{
|
||||
|
|
@ -176,7 +176,7 @@ restconf_param_set(clicon_handle h,
|
|||
* Currently using clixon runtime data but there is risk for colliding names
|
||||
*/
|
||||
int
|
||||
restconf_param_del_all(clicon_handle h)
|
||||
restconf_param_del_all(clixon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
|
@ -197,7 +197,7 @@ restconf_param_del_all(clicon_handle h)
|
|||
* @retval auth_type
|
||||
*/
|
||||
clixon_auth_type_t
|
||||
restconf_auth_type_get(clicon_handle h)
|
||||
restconf_auth_type_get(clixon_handle h)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ restconf_auth_type_get(clicon_handle h)
|
|||
* Currently using clixon runtime data but there is risk for colliding names
|
||||
*/
|
||||
int
|
||||
restconf_auth_type_set(clicon_handle h,
|
||||
restconf_auth_type_set(clixon_handle h,
|
||||
clixon_auth_type_t type)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
|
@ -229,7 +229,7 @@ restconf_auth_type_set(clicon_handle h,
|
|||
* @retval pretty
|
||||
*/
|
||||
int
|
||||
restconf_pretty_get(clicon_handle h)
|
||||
restconf_pretty_get(clixon_handle h)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
||||
|
|
@ -244,7 +244,7 @@ restconf_pretty_get(clicon_handle h)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
restconf_pretty_set(clicon_handle h,
|
||||
restconf_pretty_set(clixon_handle h,
|
||||
int pretty)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
|
@ -260,7 +260,7 @@ restconf_pretty_set(clicon_handle h,
|
|||
* @retval 1 No, http-data disabled
|
||||
*/
|
||||
int
|
||||
restconf_http_data_get(clicon_handle h)
|
||||
restconf_http_data_get(clixon_handle h)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ restconf_http_data_get(clicon_handle h)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
restconf_http_data_set(clicon_handle h,
|
||||
restconf_http_data_set(clixon_handle h,
|
||||
int http_data)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
|
@ -289,7 +289,7 @@ restconf_http_data_set(clicon_handle h,
|
|||
* @retval socketpath
|
||||
*/
|
||||
char*
|
||||
restconf_fcgi_socket_get(clicon_handle h)
|
||||
restconf_fcgi_socket_get(clixon_handle h)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
||||
|
|
@ -306,13 +306,13 @@ restconf_fcgi_socket_get(clicon_handle h)
|
|||
* Currently using clixon runtime data but there is risk for colliding names
|
||||
*/
|
||||
int
|
||||
restconf_fcgi_socket_set(clicon_handle h,
|
||||
restconf_fcgi_socket_set(clixon_handle h,
|
||||
char *socketpath)
|
||||
{
|
||||
struct restconf_handle *rh = handle(h);
|
||||
|
||||
if ((rh->rh_fcgi_socket = strdup(socketpath)) == NULL){
|
||||
clicon_err(OE_RESTCONF, errno, "strdup");
|
||||
clixon_err(OE_RESTCONF, errno, "strdup");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -42,18 +42,18 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
clicon_handle restconf_handle_init(void);
|
||||
int restconf_handle_exit(clicon_handle h);
|
||||
char *restconf_param_get(clicon_handle h, const char *param);
|
||||
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);
|
||||
int restconf_http_data_get(clicon_handle h);
|
||||
int restconf_http_data_set(clicon_handle h, int http_data);
|
||||
char *restconf_fcgi_socket_get(clicon_handle h);
|
||||
int restconf_fcgi_socket_set(clicon_handle h, char *socketpath);
|
||||
clixon_handle restconf_handle_init(void);
|
||||
int restconf_handle_exit(clixon_handle h);
|
||||
char *restconf_param_get(clixon_handle h, const char *param);
|
||||
int restconf_param_set(clixon_handle h, const char *param, char *val);
|
||||
int restconf_param_del_all(clixon_handle h);
|
||||
clixon_auth_type_t restconf_auth_type_get(clixon_handle h);
|
||||
int restconf_auth_type_set(clixon_handle h, clixon_auth_type_t type);
|
||||
int restconf_pretty_get(clixon_handle h);
|
||||
int restconf_pretty_set(clixon_handle h, int pretty);
|
||||
int restconf_http_data_get(clixon_handle h);
|
||||
int restconf_http_data_set(clixon_handle h, int http_data);
|
||||
char *restconf_fcgi_socket_get(clixon_handle h);
|
||||
int restconf_fcgi_socket_set(clixon_handle h, char *socketpath);
|
||||
|
||||
#endif /* _RESTCONF_HANDLE_H_ */
|
||||
|
|
|
|||
|
|
@ -78,10 +78,10 @@
|
|||
* @param[in] str Pointer to string containing HTTP/1
|
||||
* @param[in] filename Debug string identifying file or connection
|
||||
* @retval 0 Parse OK
|
||||
* @retval -1 Error with clicon_err called.
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
_http1_parse(clicon_handle h,
|
||||
_http1_parse(clixon_handle h,
|
||||
restconf_conn *rc,
|
||||
char *str,
|
||||
const char *filename)
|
||||
|
|
@ -109,11 +109,11 @@ _http1_parse(clicon_handle h,
|
|||
http1_scan_exit(&hy);
|
||||
if (ret != 0){
|
||||
if (filename)
|
||||
clicon_log(LOG_NOTICE, "HTTP1 error: on line %d in %s", hy.hy_linenum, filename);
|
||||
clixon_log(h, LOG_NOTICE, "HTTP1 error: on line %d in %s", hy.hy_linenum, filename);
|
||||
else
|
||||
clicon_log(LOG_NOTICE, "HTTP1 error: on line %d", hy.hy_linenum);
|
||||
if (clicon_errno == 0)
|
||||
clicon_err(OE_RESTCONF, 0, "HTTP1 parser error with no error code (should not happen)");
|
||||
clixon_log(h, LOG_NOTICE, "HTTP1 error: on line %d", hy.hy_linenum);
|
||||
if (clixon_err_category() == 0)
|
||||
clixon_err(OE_RESTCONF, 0, "HTTP1 parser error with no error code (should not happen)");
|
||||
goto done;
|
||||
}
|
||||
ok:
|
||||
|
|
@ -130,10 +130,10 @@ _http1_parse(clicon_handle h,
|
|||
* @param[in] f A file descriptor containing HTTP/1 (as ASCII characters)
|
||||
* @param[in] filename Debug string identifying file or connection
|
||||
* @retval 0 Parse OK
|
||||
* @retval -1 Error with clicon_err called.
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_http1_parse_file(clicon_handle h,
|
||||
clixon_http1_parse_file(clixon_handle h,
|
||||
restconf_conn *rc,
|
||||
FILE *f,
|
||||
const char *filename)
|
||||
|
|
@ -149,18 +149,18 @@ clixon_http1_parse_file(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, filename);
|
||||
if (f == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "f is NULL");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "f is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((buf = malloc(buflen)) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(buf, 0, buflen);
|
||||
ptr = buf;
|
||||
while (1){
|
||||
if ((ret = fread(&ch, 1, 1, f)) < 0){
|
||||
clicon_err(OE_XML, errno, "read");
|
||||
clixon_err(OE_XML, errno, "read");
|
||||
break;
|
||||
}
|
||||
if (ret != 0){
|
||||
|
|
@ -175,7 +175,7 @@ clixon_http1_parse_file(clicon_handle h,
|
|||
oldbuflen = buflen;
|
||||
buflen *= 2;
|
||||
if ((buf = realloc(buf, buflen)) == NULL){
|
||||
clicon_err(OE_XML, errno, "realloc");
|
||||
clixon_err(OE_XML, errno, "realloc");
|
||||
goto done;
|
||||
}
|
||||
memset(buf+oldbuflen, 0, buflen-oldbuflen);
|
||||
|
|
@ -195,10 +195,10 @@ clixon_http1_parse_file(clicon_handle h,
|
|||
* @param[in] rc Restconf connection
|
||||
* @param[in] str HTTP/1 string
|
||||
* @retval 0 Parse OK
|
||||
* @retval -1 Error with clicon_err called.
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
clixon_http1_parse_string(clicon_handle h,
|
||||
clixon_http1_parse_string(clixon_handle h,
|
||||
restconf_conn *rc,
|
||||
char *str)
|
||||
{
|
||||
|
|
@ -213,12 +213,12 @@ clixon_http1_parse_string(clicon_handle h,
|
|||
* @param[in] buf HTTP/1 buffer
|
||||
* @param[in] n Length of buffer
|
||||
* @retval 0 Parse OK
|
||||
* @retval -1 Error with clicon_err called.
|
||||
* @retval -1 Error
|
||||
* @note Had preferred to do this without copying, OR
|
||||
* input flex with a non-null terminated string
|
||||
*/
|
||||
int
|
||||
clixon_http1_parse_buf(clicon_handle h,
|
||||
clixon_http1_parse_buf(clixon_handle h,
|
||||
restconf_conn *rc,
|
||||
char *buf,
|
||||
size_t n)
|
||||
|
|
@ -227,7 +227,7 @@ clixon_http1_parse_buf(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if ((str = malloc(n+1)) == NULL){
|
||||
clicon_err(OE_RESTCONF, errno, "malloc");
|
||||
clixon_err(OE_RESTCONF, errno, "malloc");
|
||||
return -1;
|
||||
}
|
||||
memcpy(str, buf, n);
|
||||
|
|
@ -250,7 +250,7 @@ clixon_http1_parse_buf(clicon_handle h,
|
|||
* runtime config option
|
||||
*/
|
||||
static int
|
||||
http1_upgrade_http2(clicon_handle h,
|
||||
http1_upgrade_http2(clixon_handle h,
|
||||
restconf_stream_data *sd)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -280,7 +280,7 @@ http1_upgrade_http2(clicon_handle h,
|
|||
sd->sd_upgrade2 = 1;
|
||||
if ((settings = restconf_param_get(h, "HTTP_HTTP2_Settings")) != NULL &&
|
||||
(sd->sd_settings2 = (uint8_t*)strdup(settings)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -332,7 +332,7 @@ restconf_http1_reply(restconf_conn *rc,
|
|||
/* Write a body */
|
||||
if (sd->sd_body){
|
||||
if (cbuf_append_buf(sd->sd_outp_buf, cbuf_get(sd->sd_body), cbuf_len(sd->sd_body)) < 0){
|
||||
clicon_err(OE_RESTCONF, errno, "cbuf_append_buf");
|
||||
clixon_err(OE_RESTCONF, errno, "cbuf_append_buf");
|
||||
goto done;
|
||||
}
|
||||
cbuf_free(sd->sd_body);
|
||||
|
|
@ -351,7 +351,7 @@ restconf_http1_reply(restconf_conn *rc,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
restconf_http1_path_root(clicon_handle h,
|
||||
restconf_http1_path_root(clixon_handle h,
|
||||
restconf_conn *rc)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -368,7 +368,7 @@ restconf_http1_path_root(clicon_handle h,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "------------");
|
||||
pretty = restconf_pretty_get(h);
|
||||
if ((sd = restconf_stream_find(rc, 0)) == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "No stream_data");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "No stream_data");
|
||||
goto done;
|
||||
}
|
||||
/* Sanity check */
|
||||
|
|
@ -484,7 +484,7 @@ restconf_http1_path_root(clicon_handle h,
|
|||
* @see rfc7231 Sec 5.1.1
|
||||
*/
|
||||
int
|
||||
http1_check_expect(clicon_handle h,
|
||||
http1_check_expect(clixon_handle h,
|
||||
restconf_conn *rc,
|
||||
restconf_stream_data *sd)
|
||||
{
|
||||
|
|
@ -518,7 +518,7 @@ http1_check_expect(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
http1_check_content_length(clicon_handle h,
|
||||
http1_check_content_length(clixon_handle h,
|
||||
restconf_stream_data *sd,
|
||||
int *status)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int clixon_http1_parse_file(clicon_handle h, restconf_conn *rc, FILE *f, const char *filename);
|
||||
int clixon_http1_parse_string(clicon_handle h, restconf_conn *rc, char *str);
|
||||
int clixon_http1_parse_buf(clicon_handle h, restconf_conn *rc, char *buf, size_t n);
|
||||
int restconf_http1_path_root(clicon_handle h, restconf_conn *rc);
|
||||
int http1_check_expect(clicon_handle h, restconf_conn *rc, restconf_stream_data *sd);
|
||||
int http1_check_content_length(clicon_handle h, restconf_stream_data *sd, int *status);
|
||||
int clixon_http1_parse_file(clixon_handle h, restconf_conn *rc, FILE *f, const char *filename);
|
||||
int clixon_http1_parse_string(clixon_handle h, restconf_conn *rc, char *str);
|
||||
int clixon_http1_parse_buf(clixon_handle h, restconf_conn *rc, char *buf, size_t n);
|
||||
int restconf_http1_path_root(clixon_handle h, restconf_conn *rc);
|
||||
int http1_check_expect(clixon_handle h, restconf_conn *rc, restconf_stream_data *sd);
|
||||
int http1_check_content_length(clixon_handle h, restconf_stream_data *sd, int *status);
|
||||
|
||||
#endif /* _RESTCONF_HTTP1_H_ */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -87,16 +87,16 @@ const restconf_media restconf_media_str2int(char *media);
|
|||
const char *restconf_media_int2str(restconf_media media);
|
||||
int restconf_str2proto(char *str);
|
||||
const char *restconf_proto2str(int proto);
|
||||
restconf_media restconf_content_type(clicon_handle h);
|
||||
int restconf_convert_hdr(clicon_handle h, char *name, char *val);
|
||||
restconf_media restconf_content_type(clixon_handle h);
|
||||
int restconf_convert_hdr(clixon_handle h, char *name, char *val);
|
||||
int get_user_cookie(char *cookiestr, char *attribute, char **val);
|
||||
int restconf_terminate(clicon_handle h);
|
||||
int restconf_terminate(clixon_handle h);
|
||||
int restconf_insert_attributes(cxobj *xdata, cvec *qvec);
|
||||
int restconf_main_extension_cb(clicon_handle h, yang_stmt *yext, yang_stmt *ys);
|
||||
char *restconf_uripath(clicon_handle h);
|
||||
int restconf_drop_privileges(clicon_handle h);
|
||||
int restconf_authentication_cb(clicon_handle h, void *req, int pretty, restconf_media media_out);
|
||||
int restconf_config_init(clicon_handle h, cxobj *xrestconf);
|
||||
int restconf_main_extension_cb(clixon_handle h, yang_stmt *yext, yang_stmt *ys);
|
||||
char *restconf_uripath(clixon_handle h);
|
||||
int restconf_drop_privileges(clixon_handle h);
|
||||
int restconf_authentication_cb(clixon_handle h, void *req, int pretty, restconf_media media_out);
|
||||
int restconf_config_init(clixon_handle h, cxobj *xrestconf);
|
||||
int restconf_socket_init(const char *netns0, const char *addrstr, const char *addrtype, uint16_t port, int backlog, int flags, int *ss);
|
||||
|
||||
#endif /* _RESTCONF_LIB_H_ */
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include <fcgiapp.h> /* Need to be after clixon_xml.h due to attribute format */
|
||||
|
|
@ -99,7 +99,7 @@
|
|||
* @see https://nginx.org/en/docs/http/ngx_http_core_module.html#var_https
|
||||
*/
|
||||
static int
|
||||
fcgi_params_set(clicon_handle h,
|
||||
fcgi_params_set(clixon_handle h,
|
||||
char **envp)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -131,7 +131,7 @@ fcgi_params_set(clicon_handle h,
|
|||
/*! Try to get config: inline, config-file or query backend
|
||||
*/
|
||||
static int
|
||||
restconf_main_config(clicon_handle h,
|
||||
restconf_main_config(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
const char *inline_config)
|
||||
{
|
||||
|
|
@ -151,7 +151,12 @@ restconf_main_config(clicon_handle h,
|
|||
if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Inline restconf config") < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Inline restconf config", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
/* Replace parent w first child */
|
||||
|
|
@ -172,7 +177,7 @@ restconf_main_config(clicon_handle h,
|
|||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
clicon_err(OE_UNIX, errno, "clicon_session_id_get");
|
||||
clixon_err(OE_UNIX, errno, "clicon_session_id_get");
|
||||
goto done;
|
||||
}
|
||||
clicon_session_id_set(h, id);
|
||||
|
|
@ -181,13 +186,13 @@ restconf_main_config(clicon_handle h,
|
|||
if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL)
|
||||
goto done;
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
clixon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){
|
||||
clixon_netconf_error(h, xerr, "Get backend restconf config", NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get backend restconf config");
|
||||
goto done;
|
||||
}
|
||||
/* Extract restconf configuration */
|
||||
|
|
@ -198,7 +203,7 @@ restconf_main_config(clicon_handle h,
|
|||
(configure_done = restconf_config_init(h, xrestconf)) < 0)
|
||||
goto done;
|
||||
if (!configure_done){ /* Query backend of config. */
|
||||
clicon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled");
|
||||
clixon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -214,7 +219,7 @@ restconf_main_config(clicon_handle h,
|
|||
|
||||
/* XXX Need global variable to for SIGCHLD signal handler
|
||||
*/
|
||||
static clicon_handle _CLICON_HANDLE = NULL;
|
||||
static clixon_handle _CLIXON_HANDLE = NULL;
|
||||
|
||||
/* XXX Need global variable to break FCGI accept loop from signal handler see FCGX_Accept_r(req)
|
||||
*/
|
||||
|
|
@ -229,7 +234,7 @@ restconf_sig_term(int arg)
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (i++ == 0)
|
||||
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
|
||||
clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d",
|
||||
__PROGRAM__, __FUNCTION__, getpid(), arg);
|
||||
else{
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__);
|
||||
|
|
@ -255,7 +260,7 @@ restconf_sig_child(int arg)
|
|||
int pid;
|
||||
|
||||
if ((pid = waitpid(-1, &status, 0)) != -1 && WIFEXITED(status))
|
||||
stream_child_free(_CLICON_HANDLE, pid);
|
||||
stream_child_free(_CLIXON_HANDLE, pid);
|
||||
}
|
||||
|
||||
/*! Usage help routine
|
||||
|
|
@ -264,7 +269,7 @@ restconf_sig_child(int arg)
|
|||
* @param[in] argv0 command line
|
||||
*/
|
||||
static void
|
||||
usage(clicon_handle h,
|
||||
usage(clixon_handle h,
|
||||
char *argv0)
|
||||
{
|
||||
fprintf(stderr, "usage:%s [options]\n"
|
||||
|
|
@ -303,9 +308,9 @@ main(int argc,
|
|||
int c;
|
||||
char *sockpath = NULL;
|
||||
char *path;
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
char *dir;
|
||||
int logdst = CLICON_LOG_SYSLOG;
|
||||
int logdst = CLIXON_LOG_SYSLOG;
|
||||
yang_stmt *yspec = NULL;
|
||||
char *query;
|
||||
cvec *qvec;
|
||||
|
|
@ -324,14 +329,16 @@ main(int argc,
|
|||
enum format_enum config_dump_format = FORMAT_XML;
|
||||
int print_version = 0;
|
||||
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
|
||||
/* Create handle */
|
||||
if ((h = restconf_handle_init()) == NULL)
|
||||
goto done;
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
|
||||
goto done;
|
||||
if (clixon_err_init(h) < 0)
|
||||
goto done;
|
||||
|
||||
_CLICON_HANDLE = h; /* for termination handling */
|
||||
_CLIXON_HANDLE = h; /* for termination handling */
|
||||
|
||||
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
|
||||
switch (c) {
|
||||
|
|
@ -357,11 +364,11 @@ main(int argc,
|
|||
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
|
||||
break;
|
||||
case 'l': /* Log destination: s|e|o */
|
||||
if ((logdst = clicon_log_opt(optarg[0])) < 0)
|
||||
if ((logdst = clixon_log_opt(optarg[0])) < 0)
|
||||
usage(h, argv[0]);
|
||||
if (logdst == CLICON_LOG_FILE &&
|
||||
if (logdst == CLIXON_LOG_FILE &&
|
||||
strlen(optarg)>1 &&
|
||||
clicon_log_file(optarg+1) < 0)
|
||||
clixon_log_file(optarg+1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
} /* switch getopt */
|
||||
|
|
@ -369,20 +376,20 @@ main(int argc,
|
|||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
*/
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
|
||||
clixon_debug_init(dbg, NULL);
|
||||
clicon_log(LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid());
|
||||
clixon_debug_init(h, dbg);
|
||||
clixon_log(h, LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid());
|
||||
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGCHLD, restconf_sig_child, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -460,8 +467,8 @@ main(int argc,
|
|||
cligen_bufthreshold = clicon_option_int(h, "CLICON_CLI_BUF_THRESHOLD");
|
||||
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
|
||||
|
||||
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
|
||||
clicon_log_string_limit_set(sz);
|
||||
if ((sz = clicon_option_int(h, "CLIXON_LOG_STRING_LIMIT")) != 0)
|
||||
clixon_log_string_limit_set(sz);
|
||||
|
||||
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
|
||||
xml_nsctx_namespace_netconf_default(h);
|
||||
|
|
@ -572,16 +579,16 @@ main(int argc,
|
|||
if (restconf_main_config(h, yspec, inline_config) < 0)
|
||||
goto done;
|
||||
if ((sockpath = restconf_fcgi_socket_get(h)) == NULL){
|
||||
clicon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)");
|
||||
clixon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)");
|
||||
goto done;
|
||||
}
|
||||
if (FCGX_Init() != 0){ /* How to cleanup memory after this? */
|
||||
clicon_err(OE_CFG, errno, "FCGX_Init");
|
||||
clixon_err(OE_CFG, errno, "FCGX_Init");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "restconf_main: Opening FCGX socket: %s", sockpath);
|
||||
if ((sock = FCGX_OpenSocket(sockpath, 10)) < 0){
|
||||
clicon_err(OE_CFG, errno, "FCGX_OpenSocket");
|
||||
clixon_err(OE_CFG, errno, "FCGX_OpenSocket");
|
||||
goto done;
|
||||
}
|
||||
_MYSOCK = sock;
|
||||
|
|
@ -590,18 +597,18 @@ main(int argc,
|
|||
gid_t wgid = -1;
|
||||
wwwuser = clicon_option_str(h, "CLICON_RESTCONF_USER");
|
||||
if (group_name2gid(wwwuser, &wgid) < 0){
|
||||
clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser);
|
||||
clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser);
|
||||
goto done;
|
||||
}
|
||||
if (chown(sockpath, -1, wgid) < 0){
|
||||
clicon_err(OE_CFG, errno, "chown");
|
||||
clixon_err(OE_CFG, errno, "chown");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_socket_set(h, sock) < 0)
|
||||
goto done;
|
||||
/* umask settings may interfer: we want group to write: this is 774 */
|
||||
if (chmod(sockpath, S_IRWXU|S_IRWXG|S_IROTH) < 0){
|
||||
clicon_err(OE_UNIX, errno, "chmod");
|
||||
clixon_err(OE_UNIX, errno, "chmod");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -616,14 +623,14 @@ main(int argc,
|
|||
clicon_data_set(h, "session-transport", "cl:restconf");
|
||||
|
||||
if (FCGX_InitRequest(req, sock, 0) != 0){
|
||||
clicon_err(OE_CFG, errno, "FCGX_InitRequest");
|
||||
clixon_err(OE_CFG, errno, "FCGX_InitRequest");
|
||||
goto done;
|
||||
}
|
||||
while (1) {
|
||||
finish = 1; /* If zero, dont finish request, initiate new */
|
||||
|
||||
if (FCGX_Accept_r(req) < 0) {
|
||||
clicon_err(OE_CFG, errno, "FCGX_Accept_r");
|
||||
clixon_err(OE_CFG, errno, "FCGX_Accept_r");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "------------");
|
||||
|
|
@ -692,7 +699,7 @@ main(int argc,
|
|||
else{ /* A handler is forked so we initiate a new request after instead
|
||||
of finishing the old */
|
||||
if (FCGX_InitRequest(req, sock, 0) != 0){
|
||||
clicon_err(OE_CFG, errno, "FCGX_InitRequest");
|
||||
clixon_err(OE_CFG, errno, "FCGX_InitRequest");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
* Data structures:
|
||||
* 1 1
|
||||
* +--------------------+ restconf_handle_get +--------------------+
|
||||
* | rn restconf_native | <--------------------- | h clicon_handle |
|
||||
* | rn restconf_native | <--------------------- | h clixon_handle |
|
||||
* | _handle | +--------------------+
|
||||
* +--------------------+ ^
|
||||
* common SSL config \ |
|
||||
|
|
@ -186,7 +186,7 @@ static int session_id_context = 1;
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
restconf_native_handle_set(clicon_handle h,
|
||||
restconf_native_handle_set(clixon_handle h,
|
||||
restconf_native_handle *rh)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
|
@ -235,7 +235,7 @@ init_openssl(void)
|
|||
/* This isn't strictly necessary... OpenSSL performs RAND_poll
|
||||
* automatically on first use of random number generator. */
|
||||
if (RAND_poll() != 1) {
|
||||
clicon_err(OE_SSL, errno, "Random generator has not been seeded with enough data");
|
||||
clixon_err(OE_SSL, errno, "Random generator has not been seeded with enough data");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -260,7 +260,7 @@ restconf_verify_certs(int preverify_ok,
|
|||
int err;
|
||||
int depth;
|
||||
// SSL *ssl;
|
||||
// clicon_handle h;
|
||||
// clixon_handle h;
|
||||
err_cert = X509_STORE_CTX_get_current_cert(store);
|
||||
err = X509_STORE_CTX_get_error(store);
|
||||
depth = X509_STORE_CTX_get_error_depth(store);
|
||||
|
|
@ -361,7 +361,7 @@ alpn_select_proto_cb(SSL *ssl,
|
|||
/*
|
||||
*/
|
||||
static SSL_CTX *
|
||||
restconf_ssl_context_create(clicon_handle h)
|
||||
restconf_ssl_context_create(clixon_handle h)
|
||||
{
|
||||
const SSL_METHOD *method;
|
||||
SSL_CTX *ctx = NULL;
|
||||
|
|
@ -369,7 +369,7 @@ restconf_ssl_context_create(clicon_handle h)
|
|||
method = TLS_server_method();
|
||||
|
||||
if ((ctx = SSL_CTX_new(method)) == NULL) {
|
||||
clicon_err(OE_SSL, 0, "SSL_CTX_new");
|
||||
clixon_err(OE_SSL, 0, "SSL_CTX_new");
|
||||
goto done;
|
||||
}
|
||||
/* Options
|
||||
|
|
@ -414,7 +414,7 @@ restconf_ssl_context_configure(clixon_handle h,
|
|||
*/
|
||||
if (server_ca_cert_path){
|
||||
if (SSL_CTX_load_verify_locations(ctx, server_ca_cert_path, NULL) != 1){
|
||||
clicon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations(%s)", server_ca_cert_path);
|
||||
clixon_err(OE_SSL, 0, "SSL_CTX_load_verify_locations(%s)", server_ca_cert_path);
|
||||
goto done;
|
||||
}
|
||||
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER /*| SSL_VERIFY_FAIL_IF_NO_PEER_CERT */,
|
||||
|
|
@ -496,15 +496,15 @@ restconf_checkcert_file(cxobj *xrestconf,
|
|||
char *filename;
|
||||
|
||||
if ((x = xpath_first(xrestconf, nsc, "%s", name)) == NULL){
|
||||
clicon_err(OE_FATAL, EFAULT, "cert '%s' not found in config", name);
|
||||
clixon_err(OE_FATAL, EFAULT, "cert '%s' not found in config", name);
|
||||
goto done;
|
||||
}
|
||||
if ((filename = xml_body(x)) == NULL){
|
||||
clicon_err(OE_FATAL, EFAULT, "cert '%s' NULL value in config", name);
|
||||
clixon_err(OE_FATAL, EFAULT, "cert '%s' NULL value in config", name);
|
||||
goto done;
|
||||
}
|
||||
if (stat(filename, &fstat) < 0) {
|
||||
clicon_err(OE_FATAL, errno, "cert '%s'", filename);
|
||||
clixon_err(OE_FATAL, errno, "cert '%s'", filename);
|
||||
goto done;
|
||||
}
|
||||
*var = filename;
|
||||
|
|
@ -516,7 +516,7 @@ restconf_checkcert_file(cxobj *xrestconf,
|
|||
/*! Accept new socket client
|
||||
*
|
||||
* @param[in] fd Socket (unix or ip)
|
||||
* @param[in] arg typecast clicon_handle
|
||||
* @param[in] arg typecast clixon_handle
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see openssl_init_socket where this callback is registered
|
||||
|
|
@ -527,7 +527,7 @@ restconf_accept_client(int fd,
|
|||
{
|
||||
int retval = -1;
|
||||
restconf_socket *rsock;
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
int s;
|
||||
struct sockaddr from = {0,};
|
||||
socklen_t len;
|
||||
|
|
@ -536,13 +536,13 @@ restconf_accept_client(int fd,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, fd);
|
||||
if ((rsock = (restconf_socket *)arg) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "rsock is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "rsock is NULL");
|
||||
goto done;
|
||||
}
|
||||
h = rsock->rs_h;
|
||||
len = sizeof(from);
|
||||
if ((s = accept(rsock->rs_ss, &from, &len)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "accept");
|
||||
clixon_err(OE_UNIX, errno, "accept");
|
||||
goto done;
|
||||
}
|
||||
switch (from.sa_family){
|
||||
|
|
@ -565,7 +565,7 @@ restconf_accept_client(int fd,
|
|||
rsock->rs_from_addr = NULL;
|
||||
}
|
||||
if ((rsock->rs_from_addr = calloc(INET6_ADDRSTRLEN, 1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
if (inet_ntop(from.sa_family, addr, rsock->rs_from_addr, INET6_ADDRSTRLEN) < 0)
|
||||
|
|
@ -590,7 +590,7 @@ restconf_accept_client(int fd,
|
|||
/*!
|
||||
*/
|
||||
static int
|
||||
restconf_native_terminate(clicon_handle h)
|
||||
restconf_native_terminate(clixon_handle h)
|
||||
{
|
||||
restconf_native_handle *rn;
|
||||
restconf_socket *rsock;
|
||||
|
|
@ -643,7 +643,7 @@ restconf_native_terminate(clicon_handle h)
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
restconf_clixon_backend(clicon_handle h,
|
||||
restconf_clixon_backend(clixon_handle h,
|
||||
cxobj **xrestconfp)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -659,11 +659,11 @@ restconf_clixon_backend(clicon_handle h,
|
|||
while (1){
|
||||
if (clicon_hello_req(h, "cl:restconf", NULL, &id) < 0){
|
||||
if (errno == ENOENT){
|
||||
clicon_err(OE_UNIX, errno, "waiting");
|
||||
clixon_err(OE_UNIX, errno, "waiting");
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
clicon_err(OE_UNIX, errno, "clicon_session_id_get");
|
||||
clixon_err(OE_UNIX, errno, "clicon_session_id_get");
|
||||
goto done;
|
||||
}
|
||||
clicon_session_id_set(h, id);
|
||||
|
|
@ -672,14 +672,19 @@ restconf_clixon_backend(clicon_handle h,
|
|||
if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL)
|
||||
goto done;
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
clixon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
}
|
||||
/* XXX xconfig leaked */
|
||||
if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get backend restconf config") < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Get backend restconf config", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
/* Extract restconf configuration */
|
||||
|
|
@ -713,7 +718,7 @@ restconf_clixon_backend(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
openssl_init_socket(clicon_handle h,
|
||||
openssl_init_socket(clixon_handle h,
|
||||
cxobj *xs,
|
||||
cvec *nsc)
|
||||
{
|
||||
|
|
@ -733,7 +738,7 @@ openssl_init_socket(clicon_handle h,
|
|||
* See restconf_native_terminate for freeing
|
||||
*/
|
||||
if ((rsock = malloc(sizeof *rsock)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(rsock, 0, sizeof *rsock);
|
||||
|
|
@ -745,7 +750,7 @@ openssl_init_socket(clicon_handle h,
|
|||
goto done;
|
||||
if (rsock->rs_callhome){
|
||||
if (!rsock->rs_ssl){
|
||||
clicon_err(OE_SSL, EINVAL, "Restconf callhome requires SSL");
|
||||
clixon_err(OE_SSL, EINVAL, "Restconf callhome requires SSL");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -763,15 +768,15 @@ openssl_init_socket(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if ((rn = restconf_native_handle_get(h)) == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "No openssl handle");
|
||||
clixon_err(OE_XML, EFAULT, "No openssl handle");
|
||||
goto done;
|
||||
}
|
||||
if ((rsock->rs_addrstr = strdup(address)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
if ((rsock->rs_addrtype = strdup(addrtype)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
rsock->rs_port = port;
|
||||
|
|
@ -804,7 +809,7 @@ openssl_init_socket(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
restconf_openssl_init(clicon_handle h,
|
||||
restconf_openssl_init(clixon_handle h,
|
||||
int dbg0,
|
||||
cxobj *xrestconf)
|
||||
{
|
||||
|
|
@ -834,7 +839,7 @@ restconf_openssl_init(clicon_handle h,
|
|||
(x = xpath_first(xrestconf, nsc, "debug")) != NULL &&
|
||||
(bstr = xml_body(x)) != NULL){
|
||||
dbg = atoi(bstr);
|
||||
clixon_debug_init(dbg, NULL);
|
||||
clixon_debug_init(h, dbg);
|
||||
/* If debug was enabled here from config and not initially,
|
||||
* print clixn options and loaded yang files
|
||||
*/
|
||||
|
|
@ -852,7 +857,7 @@ restconf_openssl_init(clicon_handle h,
|
|||
}
|
||||
int status = setrlimit(RLIMIT_CORE, &rlp);
|
||||
if (status != 0) {
|
||||
clicon_log(LOG_INFO, "%s: setrlimit() failed, %s", __FUNCTION__, strerror(errno));
|
||||
clixon_log(h, LOG_INFO, "%s: setrlimit() failed, %s", __FUNCTION__, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -880,8 +885,8 @@ restconf_openssl_init(clicon_handle h,
|
|||
for (i=0; i<veclen; i++){
|
||||
if (openssl_init_socket(h, vec[i], nsc) < 0){
|
||||
/* Bind errors are ignored, proceed with next after log */
|
||||
if (clicon_errno == OE_UNIX && clicon_suberrno == EADDRNOTAVAIL)
|
||||
clicon_err_reset();
|
||||
if (clixon_err_category() == OE_UNIX && clixon_err_subnr() == EADDRNOTAVAIL)
|
||||
clixon_err_reset();
|
||||
else
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -910,7 +915,7 @@ restconf_openssl_init(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
restconf_clixon_init(clicon_handle h,
|
||||
restconf_clixon_init(clixon_handle h,
|
||||
char *inline_config,
|
||||
int print_version,
|
||||
cxobj **xrestconfp)
|
||||
|
|
@ -937,7 +942,7 @@ restconf_clixon_init(clicon_handle h,
|
|||
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
|
||||
|
||||
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
|
||||
clicon_log_string_limit_set(sz);
|
||||
clixon_log_string_limit_set(sz);
|
||||
|
||||
/* Add (hardcoded) netconf features in case ietf-netconf loaded here
|
||||
* Otherwise it is loaded in netconf_module_load below
|
||||
|
|
@ -1025,7 +1030,7 @@ restconf_clixon_init(clicon_handle h,
|
|||
if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clixon_netconf_error(h, xerr, "Inline restconf config", NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Inline restconf config");
|
||||
goto done;
|
||||
}
|
||||
/* Replace parent w first child */
|
||||
|
|
@ -1086,7 +1091,7 @@ restconf_sig_term(int arg)
|
|||
{
|
||||
static int i=0;
|
||||
|
||||
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
|
||||
clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d",
|
||||
__PROGRAM__, __FUNCTION__, getpid(), arg);
|
||||
if (i++ > 0) /* Allow one sigterm before proper exit */
|
||||
exit(-1);
|
||||
|
|
@ -1103,7 +1108,7 @@ restconf_sig_term(int arg)
|
|||
* @param[in] h Clixon handle
|
||||
*/
|
||||
static void
|
||||
usage(clicon_handle h,
|
||||
usage(clixon_handle h,
|
||||
char *argv0)
|
||||
{
|
||||
fprintf(stderr, "usage:%s [options]\n"
|
||||
|
|
@ -1138,9 +1143,9 @@ main(int argc,
|
|||
int retval = -1;
|
||||
char *argv0 = argv[0];
|
||||
int c;
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
int dbg = 0;
|
||||
int logdst = CLICON_LOG_SYSLOG;
|
||||
int logdst = CLIXON_LOG_SYSLOG;
|
||||
restconf_native_handle *rn = NULL;
|
||||
int ret;
|
||||
cxobj *xrestconf = NULL;
|
||||
|
|
@ -1149,12 +1154,14 @@ main(int argc,
|
|||
enum format_enum config_dump_format = FORMAT_XML;
|
||||
int print_version = 0;
|
||||
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
|
||||
/* Create handle */
|
||||
if ((h = restconf_handle_init()) == NULL)
|
||||
goto done;
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
|
||||
goto done;
|
||||
if (clixon_err_init(h) < 0)
|
||||
goto done;
|
||||
|
||||
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
|
||||
switch (c) {
|
||||
|
|
@ -1180,11 +1187,11 @@ main(int argc,
|
|||
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
|
||||
break;
|
||||
case 'l': /* Log destination: s|e|o */
|
||||
if ((logdst = clicon_log_opt(optarg[0])) < 0)
|
||||
if ((logdst = clixon_log_opt(optarg[0])) < 0)
|
||||
usage(h, argv0);
|
||||
if (logdst == CLICON_LOG_FILE &&
|
||||
if (logdst == CLIXON_LOG_FILE &&
|
||||
strlen(optarg)>1 &&
|
||||
clicon_log_file(optarg+1) < 0)
|
||||
clixon_log_file(optarg+1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
} /* switch getopt */
|
||||
|
|
@ -1192,7 +1199,7 @@ main(int argc,
|
|||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
*/
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
|
||||
/*
|
||||
* Register error category and error/log callbacks for openssl special error handling
|
||||
|
|
@ -1212,18 +1219,18 @@ main(int argc,
|
|||
) < 0)
|
||||
goto done;
|
||||
#endif
|
||||
clixon_debug_init(dbg, NULL);
|
||||
clicon_log(LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid());
|
||||
clixon_debug_init(h, dbg);
|
||||
clixon_log(h, LOG_NOTICE, "%s native %u Started", __PROGRAM__, getpid());
|
||||
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
yang_init(h);
|
||||
|
|
@ -1317,13 +1324,13 @@ main(int argc,
|
|||
if ((ret = restconf_clixon_init(h, inline_config, print_version, &xrestconf)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){ /* restconf disabled */
|
||||
clicon_log(LOG_INFO, "restconf configuration not found or disabled");
|
||||
clixon_log(h, LOG_INFO, "restconf configuration not found or disabled");
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
/* Create and stroe global openssl handle */
|
||||
if ((rn = malloc(sizeof *rn)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(rn, 0, sizeof *rn);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include "restconf_lib.h"
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
* @see RFC5789 PATCH Method for HTTP Section 3.2
|
||||
*/
|
||||
int
|
||||
api_data_options(clicon_handle h,
|
||||
api_data_options(clixon_handle h,
|
||||
void *req)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -194,7 +194,7 @@ match_list_keys(yang_stmt *y,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
api_data_write(clicon_handle h,
|
||||
api_data_write(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path0,
|
||||
int pi,
|
||||
|
|
@ -239,7 +239,7 @@ api_data_write(clicon_handle h,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data);
|
||||
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;
|
||||
|
|
@ -328,7 +328,7 @@ api_data_write(clicon_handle h,
|
|||
switch (media_in){
|
||||
case YANG_DATA_XML:
|
||||
if ((ret = clixon_xml_parse_string(data, yb, yspec, &xdata0, &xerr)) < 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;
|
||||
|
|
@ -342,7 +342,7 @@ api_data_write(clicon_handle h,
|
|||
break;
|
||||
case YANG_DATA_JSON:
|
||||
if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xdata0, &xerr)) < 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;
|
||||
|
|
@ -620,7 +620,7 @@ api_data_write(clicon_handle h,
|
|||
* --> Best solution and applied here
|
||||
*/
|
||||
int
|
||||
api_data_put(clicon_handle h,
|
||||
api_data_put(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path0,
|
||||
int pi,
|
||||
|
|
@ -658,7 +658,7 @@ api_data_put(clicon_handle h,
|
|||
* create it. (CANT BE DONE WITH NETCONF)
|
||||
*/
|
||||
int
|
||||
api_data_patch(clicon_handle h,
|
||||
api_data_patch(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path0,
|
||||
int pi,
|
||||
|
|
@ -712,7 +712,7 @@ api_data_patch(clicon_handle h,
|
|||
* Netconf: <edit-config> (nc:operation="delete")
|
||||
*/
|
||||
int
|
||||
api_data_delete(clicon_handle h,
|
||||
api_data_delete(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path,
|
||||
int pi,
|
||||
|
|
@ -739,7 +739,7 @@ api_data_delete(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:%s", __FUNCTION__, api_path);
|
||||
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;
|
||||
}
|
||||
for (i=0; i<pi; i++)
|
||||
|
|
|
|||
|
|
@ -41,24 +41,24 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int api_data_options(clicon_handle h, void *req);
|
||||
int api_data_write(clicon_handle h, void *req, char *api_path0,
|
||||
int api_data_options(clixon_handle h, void *req);
|
||||
int api_data_write(clixon_handle h, void *req, char *api_path0,
|
||||
int pi,
|
||||
cvec *qvec, char *data,
|
||||
int pretty, restconf_media media_in, restconf_media media_out,
|
||||
int plain_patch, ietf_ds_t ds);
|
||||
|
||||
int api_data_put(clicon_handle h, void *req, char *api_path,
|
||||
int api_data_put(clixon_handle h, void *req, char *api_path,
|
||||
int pi,
|
||||
cvec *qvec, char *data,
|
||||
int pretty, restconf_media media_out, ietf_ds_t ds);
|
||||
|
||||
int api_data_patch(clicon_handle h, void *req, char *api_path,
|
||||
int api_data_patch(clixon_handle h, void *req, char *api_path,
|
||||
int pi,
|
||||
cvec *qvec, char *data, int pretty,
|
||||
restconf_media media_out, ietf_ds_t ds);
|
||||
|
||||
int api_data_delete(clicon_handle h, void *req, char *api_path, int pi,
|
||||
int api_data_delete(clixon_handle h, void *req, char *api_path, int pi,
|
||||
int pretty, restconf_media media_out, ietf_ds_t ds);
|
||||
|
||||
#endif /* _RESTCONF_METHODS_H_ */
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include "restconf_lib.h"
|
||||
|
|
@ -64,7 +64,7 @@
|
|||
#include "restconf_methods_get.h"
|
||||
|
||||
/* Forward */
|
||||
static int api_data_pagination(clicon_handle h, void *req, char *api_path, int pi, cvec *qvec, int pretty, restconf_media media_out);
|
||||
static int api_data_pagination(clixon_handle h, void *req, char *api_path, int pi, cvec *qvec, int pretty, restconf_media media_out);
|
||||
|
||||
/*! Generic GET (both HEAD and GET)
|
||||
* According to restconf
|
||||
|
|
@ -97,7 +97,7 @@ static int api_data_pagination(clicon_handle h, void *req, char *api_path, int p
|
|||
* @note there is an ad-hoc method to determine json pagination request instead of regular GET
|
||||
*/
|
||||
static int
|
||||
api_data_get2(clicon_handle h,
|
||||
api_data_get2(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path,
|
||||
int pi,
|
||||
|
|
@ -130,7 +130,7 @@ api_data_get2(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
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;
|
||||
}
|
||||
/* strip /... from start */
|
||||
|
|
@ -184,7 +184,7 @@ api_data_get2(clicon_handle h,
|
|||
if (strcmp(attr, "unbounded") != 0){
|
||||
char *reason = NULL;
|
||||
if ((ret = parse_int32(attr, &depth, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_int32");
|
||||
clixon_err(OE_XML, errno, "parse_int32");
|
||||
goto done;
|
||||
}
|
||||
if (ret==0){
|
||||
|
|
@ -206,7 +206,7 @@ api_data_get2(clicon_handle h,
|
|||
ret = clicon_rpc_get(h, xpath, nsc, content, depth, defaults, &xret);
|
||||
|
||||
if (ret < 0){
|
||||
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0)
|
||||
if (netconf_operation_failed_xml(&xerr, "protocol", clixon_err_reason()) < 0)
|
||||
goto done;
|
||||
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
|
||||
goto done;
|
||||
|
|
@ -227,7 +227,7 @@ api_data_get2(clicon_handle h,
|
|||
}
|
||||
/* Normal return, no error */
|
||||
if ((cbx = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (xpath==NULL || strcmp(xpath,"/")==0){ /* Special case: data root */
|
||||
|
|
@ -246,7 +246,7 @@ api_data_get2(clicon_handle h,
|
|||
}
|
||||
else{
|
||||
if (xpath_vec(xret, nsc, "%s", &xvec, &xlen, xpath) < 0){
|
||||
if (netconf_operation_failed_xml(&xerr, "application", clicon_err_reason) < 0)
|
||||
if (netconf_operation_failed_xml(&xerr, "application", clixon_err_reason()) < 0)
|
||||
goto done;
|
||||
if (api_return_err0(h, req, xerr, pretty, media_out, 0) < 0)
|
||||
goto done;
|
||||
|
|
@ -345,7 +345,7 @@ api_data_get2(clicon_handle h,
|
|||
* @see draft-ietf-netconf-restconf-collection-00.txt
|
||||
*/
|
||||
static int
|
||||
api_data_pagination(clicon_handle h,
|
||||
api_data_pagination(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path,
|
||||
int pi,
|
||||
|
|
@ -383,7 +383,7 @@ api_data_pagination(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
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;
|
||||
}
|
||||
/* strip /... from start */
|
||||
|
|
@ -406,7 +406,7 @@ api_data_pagination(clicon_handle h,
|
|||
goto done;
|
||||
if (ret == 0){ /* validation failed */
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
goto done;
|
||||
}
|
||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
||||
|
|
@ -419,7 +419,7 @@ api_data_pagination(clicon_handle h,
|
|||
"Element is not list or leaf-list which is required for GET paginate") < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
goto done;
|
||||
}
|
||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
||||
|
|
@ -436,7 +436,7 @@ api_data_pagination(clicon_handle h,
|
|||
"content", "Unrecognized value of content attribute") < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
goto done;
|
||||
}
|
||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
||||
|
|
@ -446,7 +446,7 @@ api_data_pagination(clicon_handle h,
|
|||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s path:%s", __FUNCTION__, xpath);
|
||||
if (content != CONTENT_CONFIG && content != CONTENT_NONCONFIG && content != CONTENT_ALL){
|
||||
clicon_err(OE_XML, EINVAL, "Invalid content attribute %d", content);
|
||||
clixon_err(OE_XML, EINVAL, "Invalid content attribute %d", content);
|
||||
goto done;
|
||||
}
|
||||
/* Clixon extensions and collection attributes */
|
||||
|
|
@ -456,7 +456,7 @@ api_data_pagination(clicon_handle h,
|
|||
if (strcmp(attr, "unbounded") != 0){
|
||||
char *reason = NULL;
|
||||
if ((ret = parse_int32(attr, &depth, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_int32");
|
||||
clixon_err(OE_XML, errno, "parse_int32");
|
||||
goto done;
|
||||
}
|
||||
if (ret==0){
|
||||
|
|
@ -493,10 +493,10 @@ api_data_pagination(clicon_handle h,
|
|||
if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc, content,
|
||||
depth, NULL, offset, limit, direction, sort, where,
|
||||
&xret) < 0){
|
||||
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_err_reason) < 0)
|
||||
if (netconf_operation_failed_xml(&xerr, "protocol", clixon_err_reason()) < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
clixon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
goto done;
|
||||
}
|
||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
||||
|
|
@ -607,7 +607,7 @@ api_data_pagination(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
api_data_head(clicon_handle h,
|
||||
api_data_head(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path,
|
||||
int pi,
|
||||
|
|
@ -648,7 +648,7 @@ api_data_head(clicon_handle h,
|
|||
* Netconf: <get-config>, <get>
|
||||
*/
|
||||
int
|
||||
api_data_get(clicon_handle h,
|
||||
api_data_get(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path,
|
||||
int pi,
|
||||
|
|
@ -703,7 +703,7 @@ api_data_get(clicon_handle h,
|
|||
* { 'ietf-system:system-restart' : [null] }
|
||||
*/
|
||||
int
|
||||
api_operations_get(clicon_handle h,
|
||||
api_operations_get(clixon_handle h,
|
||||
void *req,
|
||||
char *path,
|
||||
int pi,
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int api_data_head(clicon_handle h, void *req, char *api_path, int pi,
|
||||
int api_data_head(clixon_handle h, void *req, char *api_path, int pi,
|
||||
cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds);
|
||||
int api_data_get(clicon_handle h, void *req, char *api_path, int pi,
|
||||
int api_data_get(clixon_handle h, void *req, char *api_path, int pi,
|
||||
cvec *qvec, int pretty, restconf_media media_out, ietf_ds_t ds);
|
||||
int api_operations_get(clicon_handle h, void *req,
|
||||
int api_operations_get(clixon_handle h, void *req,
|
||||
char *api_path, int pi, cvec *qvec, char *data,
|
||||
int pretty, restconf_media media_out);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int api_data_yang_patch(clicon_handle h, void *req, char *api_path0,
|
||||
int api_data_yang_patch(clixon_handle h, void *req, char *api_path0,
|
||||
int pi,
|
||||
cvec *qvec, char *data,
|
||||
int pretty, restconf_media media_in, restconf_media media_out,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include "restconf_lib.h"
|
||||
|
|
@ -75,7 +75,7 @@
|
|||
* @note ports are ignored
|
||||
*/
|
||||
static int
|
||||
http_location_header(clicon_handle h,
|
||||
http_location_header(clixon_handle h,
|
||||
void *req,
|
||||
cxobj *xobj)
|
||||
{
|
||||
|
|
@ -91,7 +91,7 @@ http_location_header(clicon_handle h,
|
|||
goto done;
|
||||
if (xobj != NULL){
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
clixon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (xml2api_path_1(xobj, cb) < 0)
|
||||
|
|
@ -155,7 +155,7 @@ http_location_header(clicon_handle h,
|
|||
* @see api_data_put
|
||||
*/
|
||||
int
|
||||
api_data_post(clicon_handle h,
|
||||
api_data_post(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path,
|
||||
int pi,
|
||||
|
|
@ -192,7 +192,7 @@ api_data_post(clicon_handle h,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s api_path:\"%s\"", __FUNCTION__, api_path);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s data:\"%s\"", __FUNCTION__, data);
|
||||
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;
|
||||
}
|
||||
for (i=0; i<pi; i++)
|
||||
|
|
@ -241,7 +241,7 @@ api_data_post(clicon_handle h,
|
|||
switch (media_in){
|
||||
case YANG_DATA_XML:
|
||||
if ((ret = clixon_xml_parse_string(data, yb, yspec, &xbot, &xerr)) < 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;
|
||||
|
|
@ -255,7 +255,7 @@ api_data_post(clicon_handle h,
|
|||
break;
|
||||
case YANG_DATA_JSON:
|
||||
if ((ret = clixon_json_parse_string(data, 1, yb, yspec, &xbot, &xerr)) < 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;
|
||||
|
|
@ -335,7 +335,7 @@ api_data_post(clicon_handle h,
|
|||
|
||||
/* Create text buffer for transfer to backend */
|
||||
if ((cbx = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
clixon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* For internal XML protocol: add username attribute for access control
|
||||
|
|
@ -412,7 +412,7 @@ api_data_post(clicon_handle h,
|
|||
* @param[in] media_out Output media
|
||||
* @retval 1 OK
|
||||
* @retval 0 Fail, Error message sent
|
||||
* @retval -1 Fatal error, clicon_err called
|
||||
* @retval -1 Fatal error
|
||||
*
|
||||
* RFC8040 3.6.1
|
||||
* If the "rpc" or "action" statement has an "input" section, then
|
||||
|
|
@ -423,7 +423,7 @@ api_data_post(clicon_handle h,
|
|||
* (Any other input is assumed as error.)
|
||||
*/
|
||||
static int
|
||||
api_operations_post_input(clicon_handle h,
|
||||
api_operations_post_input(clixon_handle h,
|
||||
void *req,
|
||||
char *data,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -443,7 +443,7 @@ api_operations_post_input(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, data);
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
clixon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Parse input data as json or xml into xml */
|
||||
|
|
@ -453,7 +453,7 @@ api_operations_post_input(clicon_handle h,
|
|||
/* XXX: Here data is on the form: <input xmlns="urn:example:clixon"/> and has no proper yang binding
|
||||
* support */
|
||||
if ((ret = clixon_xml_parse_string(data, YB_NONE, yspec, &xdata, &xerr)) < 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;
|
||||
|
|
@ -469,7 +469,7 @@ api_operations_post_input(clicon_handle h,
|
|||
/* XXX: Here data is on the form: {"clixon-example:input":null} and has no proper yang binding
|
||||
* support */
|
||||
if ((ret = clixon_json_parse_string(data, 1, YB_NONE, yspec, &xdata, &xerr)) < 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;
|
||||
|
|
@ -545,11 +545,11 @@ api_operations_post_input(clicon_handle h,
|
|||
* @param[out] xoutputp Restconf JSON/XML output
|
||||
* @retval 1 OK
|
||||
* @retval 0 Fail, Error message sent
|
||||
* @retval -1 Fatal error, clicon_err called
|
||||
* @retval -1 Fatal error
|
||||
* xret should like: <top><rpc-reply><x xmlns="uri">0</x></rpc-reply></top>
|
||||
*/
|
||||
static int
|
||||
api_operations_post_output(clicon_handle h,
|
||||
api_operations_post_output(clixon_handle h,
|
||||
void *req,
|
||||
cxobj *xret,
|
||||
yang_stmt *yspec,
|
||||
|
|
@ -691,7 +691,7 @@ api_operations_post_output(clicon_handle h,
|
|||
* 10. Validate and send reply to originator
|
||||
*/
|
||||
int
|
||||
api_operations_post(clicon_handle h,
|
||||
api_operations_post(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path,
|
||||
int pi,
|
||||
|
|
@ -725,11 +725,11 @@ api_operations_post(clicon_handle h,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s json:\"%s\" path:\"%s\"", __FUNCTION__, data, api_path);
|
||||
/* 1. Initialize */
|
||||
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;
|
||||
}
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, 0, "cbuf_new");
|
||||
clixon_err(OE_UNIX, 0, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
for (i=0; i<pi; i++)
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int api_data_post(clicon_handle h, void *req, char *api_path,
|
||||
int api_data_post(clixon_handle h, void *req, char *api_path,
|
||||
int pi, cvec *qvec, char *data,
|
||||
int pretty,
|
||||
restconf_media media_in,
|
||||
restconf_media media_out, ietf_ds_t ds);
|
||||
|
||||
int api_operations_post(clicon_handle h, void *req, char *api_path,
|
||||
int api_operations_post(clixon_handle h, void *req, char *api_path,
|
||||
int pi, cvec *qvec, char *data,
|
||||
int pretty, restconf_media media_out);
|
||||
|
||||
|
|
|
|||
|
|
@ -92,26 +92,26 @@ restconf_stream_data_new(restconf_conn *rc,
|
|||
restconf_stream_data *sd;
|
||||
|
||||
if ((sd = malloc(sizeof(restconf_stream_data))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(sd, 0, sizeof(restconf_stream_data));
|
||||
sd->sd_stream_id = stream_id;
|
||||
sd->sd_fd = -1;
|
||||
if ((sd->sd_inbuf = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
return NULL;
|
||||
}
|
||||
if ((sd->sd_indata = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
return NULL;
|
||||
}
|
||||
if ((sd->sd_outp_hdrs = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
clixon_err(OE_UNIX, errno, "cvec_new");
|
||||
return NULL;
|
||||
}
|
||||
if ((sd->sd_outp_buf = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
return NULL;
|
||||
}
|
||||
sd->sd_conn = rc;
|
||||
|
|
@ -176,14 +176,14 @@ restconf_stream_free(restconf_stream_data *sd)
|
|||
* @see restconf_conn_free
|
||||
*/
|
||||
restconf_conn *
|
||||
restconf_conn_new(clicon_handle h,
|
||||
restconf_conn_new(clixon_handle h,
|
||||
int s,
|
||||
restconf_socket *rsock)
|
||||
{
|
||||
restconf_conn *rc;
|
||||
|
||||
if ((rc = (restconf_conn*)malloc(sizeof(restconf_conn))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
memset(rc, 0, sizeof(restconf_conn));
|
||||
|
|
@ -210,7 +210,7 @@ restconf_conn_free(restconf_conn *rc)
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (rc == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "rc is NULL");
|
||||
goto done;
|
||||
}
|
||||
#ifdef HAVE_LIBNGHTTP2
|
||||
|
|
@ -257,7 +257,7 @@ ssl_x509_name_oneline(SSL *ssl,
|
|||
X509_NAME *name;
|
||||
|
||||
if (ssl == NULL || oneline == NULL) {
|
||||
clicon_err(OE_RESTCONF, EINVAL, "ssl or cn is NULL");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "ssl or cn is NULL");
|
||||
goto done;
|
||||
}
|
||||
#if OPENSSL_VERSION_NUMBER < 0x30000000L
|
||||
|
|
@ -272,7 +272,7 @@ ssl_x509_name_oneline(SSL *ssl,
|
|||
if ((p = X509_NAME_oneline(name, NULL, 0)) == NULL)
|
||||
goto ok;
|
||||
if ((*oneline = strdup(p)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
ok:
|
||||
|
|
@ -303,7 +303,7 @@ ssl_x509_name_oneline(SSL *ssl,
|
|||
* @see restconf_accept_client where connection can be exited at an earlier stage
|
||||
*/
|
||||
int
|
||||
restconf_connection_sanity(clicon_handle h,
|
||||
restconf_connection_sanity(clixon_handle h,
|
||||
restconf_conn *rc,
|
||||
restconf_stream_data *sd)
|
||||
{
|
||||
|
|
@ -339,12 +339,12 @@ restconf_connection_sanity(clicon_handle h,
|
|||
if (ssl_x509_name_oneline(rc->rc_ssl, &oneline) < 0)
|
||||
goto done;
|
||||
if (oneline)
|
||||
clicon_log(LOG_NOTICE, "Cert error: %s: %s", oneline, X509_verify_cert_error_string(code));
|
||||
clixon_log(h, LOG_NOTICE, "Cert error: %s: %s", oneline, X509_verify_cert_error_string(code));
|
||||
else
|
||||
clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(code));
|
||||
clixon_log(h, LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(code));
|
||||
/* Send return error message */
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "HTTP cert verification failed: %s[%ld]",
|
||||
|
|
@ -385,7 +385,7 @@ restconf_connection_sanity(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
native_buf_write(clicon_handle h,
|
||||
native_buf_write(clixon_handle h,
|
||||
char *buf,
|
||||
size_t buflen,
|
||||
restconf_conn *rc,
|
||||
|
|
@ -398,7 +398,7 @@ native_buf_write(clicon_handle h,
|
|||
SSL *ssl;
|
||||
|
||||
if (rc == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "rc is NULL");
|
||||
goto done;
|
||||
}
|
||||
ssl = rc->rc_ssl;
|
||||
|
|
@ -411,7 +411,7 @@ native_buf_write(clicon_handle h,
|
|||
size_t sz;
|
||||
sz = buflen>256?256:buflen; /* Truncate to 256 */
|
||||
if ((dbgstr = malloc(sz+1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
clixon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memcpy(dbgstr, buf, sz);
|
||||
|
|
@ -435,12 +435,12 @@ native_buf_write(clicon_handle h,
|
|||
continue;
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_RESTCONF, er, "SSL_write %d", er);
|
||||
clixon_err(OE_RESTCONF, er, "SSL_write %d", er);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_SSL, 0, "SSL_write");
|
||||
clixon_err(OE_SSL, 0, "SSL_write");
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -461,7 +461,7 @@ native_buf_write(clicon_handle h,
|
|||
goto closed; /* Close socket and ssl */
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_UNIX, errno, "write %d", errno);
|
||||
clixon_err(OE_UNIX, errno, "write %d", errno);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -490,7 +490,7 @@ native_buf_write(clicon_handle h,
|
|||
* @see restconf_badrequest which can only be called in a request context
|
||||
*/
|
||||
static int
|
||||
native_send_badrequest(clicon_handle h,
|
||||
native_send_badrequest(clixon_handle h,
|
||||
char *media,
|
||||
char *body,
|
||||
restconf_conn *rc)
|
||||
|
|
@ -500,7 +500,7 @@ native_send_badrequest(clicon_handle h,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n");
|
||||
|
|
@ -530,7 +530,7 @@ native_send_badrequest(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
http1_native_clear_input(clicon_handle h,
|
||||
http1_native_clear_input(clixon_handle h,
|
||||
restconf_stream_data *sd)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -586,7 +586,7 @@ read_ssl(restconf_conn *rc,
|
|||
*np = 0; /* should already be zero */
|
||||
break;
|
||||
default:
|
||||
clicon_log(LOG_WARNING, "%s SSL_read(): %s sslerr:%d", __FUNCTION__, strerror(errno), sslerr);
|
||||
clixon_log(rc->rc_h, LOG_WARNING, "%s SSL_read(): %s sslerr:%d", __FUNCTION__, strerror(errno), sslerr);
|
||||
*np = 0;
|
||||
break;
|
||||
} /* switch */
|
||||
|
|
@ -635,7 +635,7 @@ read_regular(restconf_conn *rc,
|
|||
*again = 1;
|
||||
break;
|
||||
default:;
|
||||
clicon_err(OE_XML, errno, "read");
|
||||
clixon_err(OE_XML, errno, "read");
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -665,14 +665,14 @@ restconf_http1_process(restconf_conn *rc,
|
|||
{
|
||||
int retval = -1;
|
||||
restconf_stream_data *sd;
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
int ret;
|
||||
int status;
|
||||
cbuf *cberr = NULL;
|
||||
|
||||
h = rc->rc_h;
|
||||
if ((sd = restconf_stream_find(rc, 0)) == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
|
||||
goto done;
|
||||
}
|
||||
/* Two states for reading:
|
||||
|
|
@ -691,7 +691,7 @@ restconf_http1_process(restconf_conn *rc,
|
|||
goto done;
|
||||
if (status == 1){ /* Next read: keep header state and only append inbody */
|
||||
if (cbuf_append_buf(sd->sd_indata, buf, n) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_append");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_append");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -700,7 +700,7 @@ restconf_http1_process(restconf_conn *rc,
|
|||
* This is different from sd_indata that it is before and includes headers
|
||||
*/
|
||||
if (cbuf_append_buf(sd->sd_inbuf, buf, n) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_append");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_append");
|
||||
goto done;
|
||||
}
|
||||
if (clixon_http1_parse_string(h, rc, cbuf_get(sd->sd_inbuf)) < 0){
|
||||
|
|
@ -720,10 +720,10 @@ restconf_http1_process(restconf_conn *rc,
|
|||
* timeout here.
|
||||
*/
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cberr, "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><error><error-type>protocol</error-type><error-tag>malformed-message</error-tag><error-message>%s</error-message></error></errors>", clicon_err_reason);
|
||||
cprintf(cberr, "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><error><error-type>protocol</error-type><error-tag>malformed-message</error-tag><error-message>%s</error-message></error></errors>", clixon_err_reason());
|
||||
if ((ret = native_send_badrequest(h, "application/yang-data+xml", cbuf_get(cberr), rc)) < 0)
|
||||
goto done;
|
||||
if (http1_native_clear_input(h, sd) < 0)
|
||||
|
|
@ -812,7 +812,7 @@ restconf_http2_upgrade(restconf_conn *rc)
|
|||
restconf_stream_data *sd;
|
||||
|
||||
if ((sd = restconf_stream_find(rc, 0)) == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "restconf stream not found");
|
||||
goto done;
|
||||
}
|
||||
if (sd->sd_upgrade2){
|
||||
|
|
@ -836,7 +836,7 @@ restconf_http2_upgrade(restconf_conn *rc)
|
|||
sd->sd_settings2?strlen((const char*)sd->sd_settings2):0,
|
||||
0, /* XXX: 1 if HEAD */
|
||||
NULL)) < 0){
|
||||
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_upgrade2");
|
||||
clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_upgrade2");
|
||||
goto done;
|
||||
}
|
||||
if (http2_send_server_connection(rc) < 0){
|
||||
|
|
@ -889,7 +889,7 @@ restconf_http2_process(restconf_conn *rc,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (rc->rc_exit){ /* Server-initiated exit for http/2 */
|
||||
if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, 0)) < 0){
|
||||
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
|
||||
clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
|
||||
goto done; // XXX not here in original?
|
||||
}
|
||||
}
|
||||
|
|
@ -924,7 +924,7 @@ restconf_http2_process(restconf_conn *rc,
|
|||
* @retval rn Restconf native handle
|
||||
*/
|
||||
restconf_native_handle *
|
||||
restconf_native_handle_get(clicon_handle h)
|
||||
restconf_native_handle_get(clixon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
size_t len;
|
||||
|
|
@ -963,11 +963,11 @@ restconf_connection(int s,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %d", __FUNCTION__, s);
|
||||
if ((rc = (restconf_conn*)arg) == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "arg is NULL");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "arg is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (s != rc->rc_s){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "s != rc->rc_s");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "s != rc->rc_s");
|
||||
goto done;
|
||||
}
|
||||
gettimeofday(&rc->rc_t, NULL); /* activity timer */
|
||||
|
|
@ -1049,13 +1049,13 @@ restconf_connection_close1(restconf_conn *rc)
|
|||
restconf_socket *rsock;
|
||||
|
||||
if (rc == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "rc is NULL");
|
||||
goto done;
|
||||
}
|
||||
rsock = rc->rc_socket;
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
|
||||
if (close(rc->rc_s) < 0){
|
||||
clicon_err(OE_UNIX, errno, "close");
|
||||
clixon_err(OE_UNIX, errno, "close");
|
||||
goto done;
|
||||
}
|
||||
clixon_event_unreg_fd(rc->rc_s, restconf_connection);
|
||||
|
|
@ -1113,7 +1113,7 @@ restconf_close_ssl_socket(restconf_conn *rc,
|
|||
else{
|
||||
/* To avoid close again in restconf_native_terminate */
|
||||
rc->rc_s = -1;
|
||||
clicon_err(OE_SSL, sslerr, "SSL_shutdown, %s err:%d %d", callfn, sslerr, er);
|
||||
clixon_err(OE_SSL, sslerr, "SSL_shutdown, %s err:%d %d", callfn, sslerr, er);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1141,7 +1141,7 @@ restconf_close_ssl_socket(restconf_conn *rc,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
ssl_alpn_check(clicon_handle h,
|
||||
ssl_alpn_check(clixon_handle h,
|
||||
const unsigned char *alpn,
|
||||
unsigned int alpnlen,
|
||||
restconf_conn *rc,
|
||||
|
|
@ -1162,12 +1162,12 @@ ssl_alpn_check(clicon_handle h,
|
|||
#endif
|
||||
else {
|
||||
if ((cberr = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (alpn != NULL){
|
||||
cprintf(cberr, "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><error><error-type>protocol</error-type><error-tag>malformed-message</error-tag><error-message>ALPN: protocol not recognized: %s</error-message></error></errors>", alpn);
|
||||
clicon_log(LOG_INFO, "%s Warning: %s", __FUNCTION__, cbuf_get(cberr));
|
||||
clixon_log(h, LOG_INFO, "%s Warning: %s", __FUNCTION__, cbuf_get(cberr));
|
||||
if (native_send_badrequest(h,
|
||||
"application/yang-data+xml",
|
||||
cbuf_get(cberr), rc) < 0)
|
||||
|
|
@ -1186,7 +1186,7 @@ ssl_alpn_check(clicon_handle h,
|
|||
if (pstr)
|
||||
p = restconf_str2proto(pstr);
|
||||
if (pstr == NULL || p == -1){
|
||||
clicon_log(LOG_INFO, "%s Warning: ALPN: No protocol selected, or no ALPN?", __FUNCTION__);
|
||||
clixon_log(h, LOG_INFO, "%s Warning: ALPN: No protocol selected, or no ALPN?", __FUNCTION__);
|
||||
if (restconf_close_ssl_socket(rc, __FUNCTION__, 0) < 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
|
|
@ -1223,7 +1223,7 @@ ssl_alpn_check(clicon_handle h,
|
|||
* @see openssl_init_socket where this callback is registered
|
||||
*/
|
||||
int
|
||||
restconf_ssl_accept_client(clicon_handle h,
|
||||
restconf_ssl_accept_client(clixon_handle h,
|
||||
int s,
|
||||
restconf_socket *rsock,
|
||||
restconf_conn **rcp)
|
||||
|
|
@ -1247,7 +1247,7 @@ restconf_ssl_accept_client(clicon_handle h,
|
|||
#endif
|
||||
#endif
|
||||
if ((rn = restconf_native_handle_get(h)) == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "No openssl handle");
|
||||
clixon_err(OE_XML, EFAULT, "No openssl handle");
|
||||
goto done;
|
||||
}
|
||||
/*
|
||||
|
|
@ -1258,7 +1258,7 @@ restconf_ssl_accept_client(clicon_handle h,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s s:%d", __FUNCTION__, rc->rc_s);
|
||||
if (rsock->rs_ssl){
|
||||
if ((rc->rc_ssl = SSL_new(rn->rn_ctx)) == NULL){
|
||||
clicon_err(OE_SSL, 0, "SSL_new");
|
||||
clixon_err(OE_SSL, 0, "SSL_new");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s SSL_new(%p)", __FUNCTION__, rc->rc_ssl);
|
||||
|
|
@ -1279,16 +1279,16 @@ restconf_ssl_accept_client(clicon_handle h,
|
|||
emailAddress = olof@hagsand.se
|
||||
*/
|
||||
if (SSL_set1_host(rc->rc_ssl, "andy") != 1) { /* for peer cert */
|
||||
clicon_err(OE_SSL, 0, "SSL_set1_host");
|
||||
clixon_err(OE_SSL, 0, "SSL_set1_host");
|
||||
goto done;
|
||||
}
|
||||
if (SSL_add1_host(rc->rc_ssl, "olof") != 1) { /* for peer cert */
|
||||
clicon_err(OE_SSL, 0, "SSL_set1_host");
|
||||
clixon_err(OE_SSL, 0, "SSL_set1_host");
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
if (SSL_set_fd(rc->rc_ssl, rc->rc_s) != 1){
|
||||
clicon_err(OE_SSL, 0, "SSL_set_fd");
|
||||
clixon_err(OE_SSL, 0, "SSL_set_fd");
|
||||
goto done;
|
||||
}
|
||||
readmore = 1;
|
||||
|
|
@ -1348,7 +1348,7 @@ restconf_ssl_accept_client(clicon_handle h,
|
|||
case SSL_ERROR_WANT_CLIENT_HELLO_CB: /* 11 */
|
||||
#endif
|
||||
default:
|
||||
clicon_err(OE_SSL, 0, "SSL_accept:%d", e);
|
||||
clixon_err(OE_SSL, 0, "SSL_accept:%d", e);
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1409,7 +1409,7 @@ restconf_ssl_accept_client(clicon_handle h,
|
|||
}
|
||||
#if 0
|
||||
else{
|
||||
clicon_log(LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(ret));
|
||||
clixon_log(h, LOG_NOTICE, "Cert error: %s", X509_verify_cert_error_string(ret));
|
||||
/* Maybe should return already here, but to get proper return message need to
|
||||
* continue to http/1 or http/2 handling
|
||||
* @see restconf_connection_sanity
|
||||
|
|
@ -1436,12 +1436,12 @@ restconf_ssl_accept_client(clicon_handle h,
|
|||
case HTTP_2:{
|
||||
if (http2_session_init(rc) < 0){
|
||||
restconf_close_ssl_socket(rc, __FUNCTION__, 0);
|
||||
clicon_err_reset();
|
||||
clixon_err_reset();
|
||||
goto closed;
|
||||
}
|
||||
if (http2_send_server_connection(rc) < 0){
|
||||
restconf_close_ssl_socket(rc, __FUNCTION__, 0);
|
||||
clicon_err_reset();
|
||||
clixon_err_reset();
|
||||
goto closed;
|
||||
}
|
||||
break;
|
||||
|
|
@ -1475,7 +1475,7 @@ restconf_idle_timer_set(struct timeval t,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "restconf idle timer %s", descr);
|
||||
|
|
@ -1521,11 +1521,11 @@ restconf_idle_cb(int fd,
|
|||
struct timeval to = {0,};
|
||||
|
||||
if ((rc = (restconf_conn *)arg) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "rc is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "rc is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((rsock = rc->rc_socket) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "rsock is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "rsock is NULL");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
|
||||
|
|
@ -1577,12 +1577,12 @@ restconf_idle_timer(restconf_conn *rc)
|
|||
restconf_socket *rsock;
|
||||
|
||||
if (rc == NULL || !rc->rc_callhome){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "rc is NULL or not callhome");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "rc is NULL or not callhome");
|
||||
goto done;
|
||||
}
|
||||
rsock = rc->rc_socket;
|
||||
if (rsock == NULL || !rsock->rs_periodic || rsock->rs_idle_timeout==0){
|
||||
clicon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic");
|
||||
clixon_err(OE_YANG, EINVAL, "rsock is NULL or not periodic");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\" register", __FUNCTION__, rsock->rs_description);
|
||||
|
|
@ -1609,7 +1609,7 @@ restconf_callhome_cb(int fd,
|
|||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
restconf_socket *rsock = NULL;
|
||||
struct sockaddr_in6 sin6 = {0,}; // because its larger than sin and sa
|
||||
struct sockaddr *sa = (struct sockaddr *)&sin6;
|
||||
|
|
@ -1620,7 +1620,7 @@ restconf_callhome_cb(int fd,
|
|||
|
||||
rsock = (restconf_socket *)arg;
|
||||
if (rsock == NULL || !rsock->rs_callhome){
|
||||
clicon_err(OE_YANG, EINVAL, "rsock is NULL");
|
||||
clixon_err(OE_YANG, EINVAL, "rsock is NULL");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
|
||||
|
|
@ -1629,7 +1629,7 @@ restconf_callhome_cb(int fd,
|
|||
if (clixon_inet2sin(rsock->rs_addrtype, rsock->rs_addrstr, rsock->rs_port, sa, &sa_len) < 0)
|
||||
goto done;
|
||||
if ((s = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "socket");
|
||||
clixon_err(OE_UNIX, errno, "socket");
|
||||
goto done;
|
||||
}
|
||||
if (connect(s, sa, sa_len) < 0){
|
||||
|
|
@ -1683,7 +1683,7 @@ restconf_callhome_timer(restconf_socket *rsock,
|
|||
cbuf *cb = NULL;
|
||||
|
||||
if (rsock == NULL || !rsock->rs_callhome){
|
||||
clicon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome");
|
||||
clixon_err(OE_YANG, EINVAL, "rsock is NULL or not callhome");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s \"%s\"", __FUNCTION__, rsock->rs_description);
|
||||
|
|
@ -1709,7 +1709,7 @@ restconf_callhome_timer(restconf_socket *rsock,
|
|||
timeradd(&now, &t1, &t);
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "restconf callhome timer %s", rsock->rs_description);
|
||||
|
|
@ -1745,7 +1745,7 @@ restconf_callhome_timer(restconf_socket *rsock,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
restconf_socket_extract(clicon_handle h,
|
||||
restconf_socket_extract(clixon_handle h,
|
||||
cxobj *xs,
|
||||
cvec *nsc,
|
||||
restconf_socket *rsock,
|
||||
|
|
@ -1765,18 +1765,18 @@ restconf_socket_extract(clicon_handle h,
|
|||
yang_stmt *ysub = NULL;
|
||||
|
||||
if ((x = xpath_first(xs, nsc, "namespace")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "Mandatory namespace not given");
|
||||
clixon_err(OE_XML, EINVAL, "Mandatory namespace not given");
|
||||
goto done;
|
||||
}
|
||||
*namespace = xml_body(x);
|
||||
if ((x = xpath_first(xs, nsc, "description")) != NULL){
|
||||
if ((rsock->rs_description = strdup(xml_body(x))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if ((x = xpath_first(xs, nsc, "address")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "Mandatory address not given");
|
||||
clixon_err(OE_XML, EINVAL, "Mandatory address not given");
|
||||
goto done;
|
||||
}
|
||||
/* address is a union type and needs a special investigation to see which type (ipv4 or ipv6)
|
||||
|
|
@ -1785,25 +1785,25 @@ restconf_socket_extract(clicon_handle h,
|
|||
body = xml_body(x);
|
||||
y = xml_spec(x);
|
||||
if ((cv = cv_dup(yang_cv_get(y))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cv_dup");
|
||||
clixon_err(OE_UNIX, errno, "cv_dup");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = cv_parse1(body, cv, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "cv_parse1");
|
||||
clixon_err(OE_XML, errno, "cv_parse1");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EFAULT, "%s", reason);
|
||||
clixon_err(OE_XML, EFAULT, "%s", reason);
|
||||
goto done;
|
||||
}
|
||||
if ((ret = ys_cv_validate(h, cv, y, &ysub, &reason)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EFAULT, "Validation os address: %s", reason);
|
||||
clixon_err(OE_XML, EFAULT, "Validation os address: %s", reason);
|
||||
goto done;
|
||||
}
|
||||
if (ysub == NULL){
|
||||
clicon_err(OE_XML, EFAULT, "No address union type");
|
||||
clixon_err(OE_XML, EFAULT, "No address union type");
|
||||
goto done;
|
||||
}
|
||||
*address = body;
|
||||
|
|
@ -1818,11 +1818,11 @@ restconf_socket_extract(clicon_handle h,
|
|||
if ((x = xpath_first(xs, nsc, "port")) != NULL &&
|
||||
(str = xml_body(x)) != NULL){
|
||||
if ((ret = parse_uint16(str, port, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_uint16");
|
||||
clixon_err(OE_XML, errno, "parse_uint16");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "Unrecognized value of port: %s", str);
|
||||
clixon_err(OE_XML, EINVAL, "Unrecognized value of port: %s", str);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1834,7 +1834,7 @@ restconf_socket_extract(clicon_handle h,
|
|||
else if (strcmp(str, "true") == 0)
|
||||
rsock->rs_ssl = 1;
|
||||
else {
|
||||
clicon_err(OE_XML, EINVAL, "Unrecognized value of ssl: %s", str);
|
||||
clixon_err(OE_XML, EINVAL, "Unrecognized value of ssl: %s", str);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1848,22 +1848,22 @@ restconf_socket_extract(clicon_handle h,
|
|||
if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/period")) != NULL &&
|
||||
(str = xml_body(x)) != NULL){
|
||||
if ((ret = parse_uint32(str, &rsock->rs_period, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_uint16");
|
||||
clixon_err(OE_XML, errno, "parse_uint16");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "Unrecognized value of period: %s", str);
|
||||
clixon_err(OE_XML, EINVAL, "Unrecognized value of period: %s", str);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if ((x = xpath_first(xs, nsc, "call-home/connection-type/periodic/idle-timeout")) != NULL &&
|
||||
(str = xml_body(x)) != NULL){
|
||||
if ((ret = parse_uint16(str, &rsock->rs_idle_timeout, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_uint16");
|
||||
clixon_err(OE_XML, errno, "parse_uint16");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "Unrecognized value of idle-timeout: %s", str);
|
||||
clixon_err(OE_XML, EINVAL, "Unrecognized value of idle-timeout: %s", str);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1871,11 +1871,11 @@ restconf_socket_extract(clicon_handle h,
|
|||
if ((x = xpath_first(xs, nsc, "call-home/reconnect-strategy/max-attempts")) != NULL &&
|
||||
(str = xml_body(x)) != NULL){
|
||||
if ((ret = parse_uint8(str, &rsock->rs_max_attempts, &reason)) < 0){
|
||||
clicon_err(OE_XML, errno, "parse_uint8");
|
||||
clixon_err(OE_XML, errno, "parse_uint8");
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EINVAL, "Unrecognized value of max-attempts: %s", str);
|
||||
clixon_err(OE_XML, EINVAL, "Unrecognized value of max-attempts: %s", str);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
* Data structures:
|
||||
* 1 1
|
||||
* +--------------------+ restconf_handle_get +--------------------+
|
||||
* | rn restconf_native | <--------------------- | h clicon_handle |
|
||||
* | rn restconf_native | <--------------------- | h clixon_handle |
|
||||
* | _handle | +--------------------+
|
||||
* +--------------------+ ^
|
||||
* common SSL config \ |
|
||||
|
|
@ -109,7 +109,7 @@ typedef struct restconf_conn {
|
|||
int rc_proto_d1; /* parsed version digit 1 */
|
||||
int rc_proto_d2; /* parsed version digit 2 */
|
||||
int rc_s; /* Connection socket */
|
||||
clicon_handle rc_h; /* Clixon handle */
|
||||
clixon_handle rc_h; /* Clixon handle */
|
||||
SSL *rc_ssl; /* Structure for SSL connection */
|
||||
restconf_stream_data *rc_streams; /* List of http/2 session streams */
|
||||
int rc_exit; /* Set to close socket server-side */
|
||||
|
|
@ -132,7 +132,7 @@ typedef struct restconf_conn {
|
|||
*/
|
||||
typedef struct restconf_socket{
|
||||
qelem_t rs_qelem; /* List header */
|
||||
clicon_handle rs_h; /* Clixon handle */
|
||||
clixon_handle rs_h; /* Clixon handle */
|
||||
char *rs_description; /* Description */
|
||||
int rs_callhome; /* 0: listen, 1: callhome */
|
||||
int rs_ss; /* Listen: Server socket, ready for accept
|
||||
|
|
@ -174,19 +174,19 @@ typedef struct {
|
|||
restconf_stream_data *restconf_stream_data_new(restconf_conn *rc, int32_t stream_id);
|
||||
restconf_stream_data *restconf_stream_find(restconf_conn *rc, int32_t id);
|
||||
int restconf_stream_free(restconf_stream_data *sd);
|
||||
restconf_conn *restconf_conn_new(clicon_handle h, int s, restconf_socket *socket);
|
||||
restconf_conn *restconf_conn_new(clixon_handle h, int s, restconf_socket *socket);
|
||||
int ssl_x509_name_oneline(SSL *ssl, char **oneline);
|
||||
|
||||
int restconf_close_ssl_socket(restconf_conn *rc, const char *callfn, int sslerr0);
|
||||
int restconf_connection_sanity(clicon_handle h, restconf_conn *rc, restconf_stream_data *sd);
|
||||
restconf_native_handle *restconf_native_handle_get(clicon_handle h);
|
||||
int restconf_connection_sanity(clixon_handle h, restconf_conn *rc, restconf_stream_data *sd);
|
||||
restconf_native_handle *restconf_native_handle_get(clixon_handle h);
|
||||
int restconf_connection(int s, void *arg);
|
||||
int restconf_ssl_accept_client(clicon_handle h, int s, restconf_socket *rsock, restconf_conn **rcp);
|
||||
int restconf_ssl_accept_client(clixon_handle h, int s, restconf_socket *rsock, restconf_conn **rcp);
|
||||
int restconf_idle_timer_unreg(restconf_conn *rc);
|
||||
int restconf_idle_timer(restconf_conn *rc);
|
||||
int restconf_callhome_timer_unreg(restconf_socket *rsock);
|
||||
int restconf_callhome_timer(restconf_socket *rsock, int status);
|
||||
int restconf_socket_extract(clicon_handle h, cxobj *xs, cvec *nsc, restconf_socket *rsock,
|
||||
int restconf_socket_extract(clixon_handle h, cxobj *xs, cvec *nsc, restconf_socket *rsock,
|
||||
char **namespace, char **address, char **addrtype, uint16_t *port);
|
||||
|
||||
#endif /* _RESTCONF_NATIVE_H_ */
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#ifdef HAVE_LIBNGHTTP2
|
||||
|
|
@ -210,12 +210,12 @@ session_send_callback(nghttp2_session *session,
|
|||
continue;
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_RESTCONF, er, "SSL_write %d", sslerr);
|
||||
clixon_err(OE_RESTCONF, er, "SSL_write %d", sslerr);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_SSL, 0, "SSL_write");
|
||||
clixon_err(OE_SSL, 0, "SSL_write");
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
|
@ -240,7 +240,7 @@ session_send_callback(nghttp2_session *session,
|
|||
}
|
||||
#endif
|
||||
else{
|
||||
clicon_err(OE_UNIX, errno, "write");
|
||||
clixon_err(OE_UNIX, errno, "write");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ static int
|
|||
restconf_nghttp2_path(restconf_stream_data *sd)
|
||||
{
|
||||
int retval = -1;
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
restconf_conn *rc;
|
||||
char *oneline = NULL;
|
||||
cvec *cvv = NULL;
|
||||
|
|
@ -297,7 +297,7 @@ restconf_nghttp2_path(restconf_stream_data *sd)
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "------------");
|
||||
rc = sd->sd_conn;
|
||||
if ((h = rc->rc_h) == NULL){
|
||||
clicon_err(OE_RESTCONF, EINVAL, "arg is NULL");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "arg is NULL");
|
||||
goto done;
|
||||
}
|
||||
if (rc->rc_ssl != NULL){
|
||||
|
|
@ -428,7 +428,7 @@ restconf_submit_response(nghttp2_session *session,
|
|||
data_prd.source.ptr = sd;
|
||||
data_prd.read_callback = restconf_sd_read;
|
||||
if ((hdrs = (nghttp2_nv*)calloc(1+cvec_len(sd->sd_outp_hdrs), sizeof(nghttp2_nv))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "calloc");
|
||||
clixon_err(OE_UNIX, errno, "calloc");
|
||||
goto done;
|
||||
}
|
||||
hdr = &hdrs[i++];
|
||||
|
|
@ -454,7 +454,7 @@ restconf_submit_response(nghttp2_session *session,
|
|||
stream_id,
|
||||
hdrs, i,
|
||||
(data_prd.source.ptr != NULL)?&data_prd:NULL)) < 0){
|
||||
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_response");
|
||||
clixon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_response");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -682,7 +682,7 @@ on_begin_headers_callback(nghttp2_session *session,
|
|||
* Both |name| and |value| are guaranteed to be NULL-terminated.
|
||||
*/
|
||||
static int
|
||||
nghttp2_hdr2clixon(clicon_handle h,
|
||||
nghttp2_hdr2clixon(clixon_handle h,
|
||||
char *name,
|
||||
char *value)
|
||||
{
|
||||
|
|
@ -882,7 +882,7 @@ error_callback2(nghttp2_session *session,
|
|||
{
|
||||
// restconf_conn *rc = (restconf_conn *)user_data;
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
clicon_err(OE_NGHTTP2, lib_error_code, "%s", msg);
|
||||
clixon_err(OE_NGHTTP2, lib_error_code, "%s", msg);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -907,7 +907,7 @@ http2_recv(restconf_conn *rc,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (rc->rc_ngsession == NULL){
|
||||
/* http2_session_init not called */
|
||||
clicon_err(OE_RESTCONF, EINVAL, "No nghttp2 session");
|
||||
clixon_err(OE_RESTCONF, EINVAL, "No nghttp2 session");
|
||||
goto done;
|
||||
}
|
||||
/* may make additional pending frames */
|
||||
|
|
@ -918,13 +918,13 @@ http2_recv(restconf_conn *rc,
|
|||
* when |session| was configured as server and
|
||||
* `nghttp2_option_set_no_recv_client_magic()` is not used with
|
||||
* nonzero value. */
|
||||
clicon_log(LOG_INFO, "%s Received bad client magic byte strin", __FUNCTION__);
|
||||
clixon_log(NULL, LOG_INFO, "%s Received bad client magic byte strin", __FUNCTION__);
|
||||
/* unsure if this does anything, byt does not seem to hurt */
|
||||
if ((ngerr = nghttp2_session_terminate_session(rc->rc_ngsession, ngerr)) < 0)
|
||||
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
|
||||
clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_terminate_session %d", ngerr);
|
||||
goto fail;
|
||||
}
|
||||
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_mem_recv");
|
||||
clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_mem_recv");
|
||||
goto done;
|
||||
}
|
||||
/* sends highest prio frame from outbound queue to remote peer. It does this as
|
||||
|
|
@ -932,9 +932,9 @@ http2_recv(restconf_conn *rc,
|
|||
* :enum:`NGHTTP2_ERR_WOULDBLOCK` or the outbound queue becomes empty.
|
||||
* @see session_send_callback()
|
||||
*/
|
||||
clicon_err_reset();
|
||||
clixon_err_reset();
|
||||
if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){
|
||||
if (clicon_errno)
|
||||
if (clixon_err_category())
|
||||
goto done;
|
||||
else
|
||||
goto fail; /* Not fatal error */
|
||||
|
|
@ -963,11 +963,11 @@ http2_send_server_connection(restconf_conn *rc)
|
|||
NGHTTP2_FLAG_NONE,
|
||||
iv,
|
||||
ARRLEN(iv))) != 0){
|
||||
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_settings");
|
||||
clixon_err(OE_NGHTTP2, ngerr, "nghttp2_submit_settings");
|
||||
goto done;
|
||||
}
|
||||
if ((ngerr = nghttp2_session_send(rc->rc_ngsession)) != 0){
|
||||
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_send");
|
||||
clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_send");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -1017,7 +1017,7 @@ http2_session_init(restconf_conn *rc)
|
|||
|
||||
/* Create session for server use, register callbacks */
|
||||
if ((ngerr = nghttp2_session_server_new3(&session, callbacks, rc, NULL, NULL)) < 0){
|
||||
clicon_err(OE_NGHTTP2, ngerr, "nghttp2_session_server_new");
|
||||
clixon_err(OE_NGHTTP2, ngerr, "nghttp2_session_server_new");
|
||||
goto done;
|
||||
}
|
||||
nghttp2_session_callbacks_del(callbacks);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
/* restconf */
|
||||
|
|
@ -76,7 +76,7 @@
|
|||
* @retval 1 Yes, a restconf path
|
||||
*/
|
||||
int
|
||||
api_path_is_restconf(clicon_handle h)
|
||||
api_path_is_restconf(clixon_handle h)
|
||||
{
|
||||
int retval = 0;
|
||||
char *path = NULL;
|
||||
|
|
@ -108,7 +108,7 @@ api_path_is_restconf(clicon_handle h)
|
|||
* enables deployments to specify where the RESTCONF API is located.
|
||||
*/
|
||||
int
|
||||
api_well_known(clicon_handle h,
|
||||
api_well_known(clixon_handle h,
|
||||
void *req)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -134,7 +134,7 @@ api_well_known(clicon_handle h,
|
|||
goto done;
|
||||
/* Create body */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n");
|
||||
|
|
@ -166,7 +166,7 @@ api_well_known(clicon_handle h,
|
|||
* @see api_root_restconf for accessing /restconf/ *
|
||||
*/
|
||||
static int
|
||||
api_root_restconf_exact(clicon_handle h,
|
||||
api_root_restconf_exact(clixon_handle h,
|
||||
void *req,
|
||||
char *request_method,
|
||||
int pretty,
|
||||
|
|
@ -187,7 +187,7 @@ api_root_restconf_exact(clicon_handle h,
|
|||
goto ok;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
|
||||
|
|
@ -201,7 +201,7 @@ api_root_restconf_exact(clicon_handle h,
|
|||
goto done;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (xml_rootchild(xt, 0, &xt) < 0)
|
||||
|
|
@ -241,7 +241,7 @@ api_root_restconf_exact(clicon_handle h,
|
|||
* @param[in] media_out Restconf output media
|
||||
*/
|
||||
static int
|
||||
api_operational_state(clicon_handle h,
|
||||
api_operational_state(clixon_handle h,
|
||||
void *req,
|
||||
char *request_method,
|
||||
int pretty,
|
||||
|
|
@ -264,7 +264,7 @@ api_operational_state(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
api_yang_library_version(clicon_handle h,
|
||||
api_yang_library_version(clixon_handle h,
|
||||
void *req,
|
||||
int pretty,
|
||||
restconf_media media_out)
|
||||
|
|
@ -289,7 +289,7 @@ api_yang_library_version(clicon_handle h,
|
|||
if (xml_bind_special(xt, yspec, "/rc:restconf/yang-library-version") < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
switch (media_out){
|
||||
|
|
@ -333,7 +333,7 @@ api_yang_library_version(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
api_data(clicon_handle h,
|
||||
api_data(clixon_handle h,
|
||||
void *req,
|
||||
char *api_path,
|
||||
cvec *pcvec,
|
||||
|
|
@ -421,7 +421,7 @@ api_data(clicon_handle h,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
api_operations(clicon_handle h,
|
||||
api_operations(clixon_handle h,
|
||||
void *req,
|
||||
char *request_method,
|
||||
char *path,
|
||||
|
|
@ -462,7 +462,7 @@ api_operations(clicon_handle h,
|
|||
* @see api_root_restconf_exact for accessing /restconf/ exact
|
||||
*/
|
||||
int
|
||||
api_root_restconf(clicon_handle h,
|
||||
api_root_restconf(clixon_handle h,
|
||||
void *req,
|
||||
cvec *qvec)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int api_path_is_restconf(clicon_handle h);
|
||||
int api_well_known(clicon_handle h, void *req);
|
||||
int api_root_restconf(clicon_handle h, void *req, cvec *qvec);
|
||||
int api_path_is_restconf(clixon_handle h);
|
||||
int api_well_known(clixon_handle h, void *req);
|
||||
int api_root_restconf(clixon_handle h, void *req, cvec *qvec);
|
||||
|
||||
#endif /* _RESTCONF_ROOT_H_ */
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int api_path_is_stream(clicon_handle h);
|
||||
int stream_child_free(clicon_handle h, int pid);
|
||||
int stream_child_freeall(clicon_handle h);
|
||||
int api_stream(clicon_handle h, void *req, cvec *qvec, int *finish);
|
||||
int api_path_is_stream(clixon_handle h);
|
||||
int stream_child_free(clixon_handle h, int pid);
|
||||
int stream_child_freeall(clixon_handle h);
|
||||
int api_stream(clixon_handle h, void *req, cvec *qvec, int *finish);
|
||||
|
||||
#endif /* _RESTCONF_STREAM_H_ */
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include <fcgiapp.h> /* Need to be after clixon_xml.h due to attribute format */
|
||||
|
|
@ -124,7 +124,7 @@ static struct stream_child *STREAM_CHILD = NULL;
|
|||
* @retval 0 No, not a stream path
|
||||
*/
|
||||
int
|
||||
api_path_is_stream(clicon_handle h)
|
||||
api_path_is_stream(clixon_handle h)
|
||||
{
|
||||
int retval = 0;
|
||||
char *path = NULL;
|
||||
|
|
@ -156,7 +156,7 @@ api_path_is_stream(clicon_handle h)
|
|||
* @note could hang STREAM_CHILD list on clicon handle instead.
|
||||
*/
|
||||
int
|
||||
stream_child_free(clicon_handle h,
|
||||
stream_child_free(clixon_handle h,
|
||||
int pid)
|
||||
{
|
||||
struct stream_child *sc;
|
||||
|
|
@ -181,7 +181,7 @@ stream_child_free(clicon_handle h,
|
|||
* Typically called on restconf exit
|
||||
*/
|
||||
int
|
||||
stream_child_freeall(clicon_handle h)
|
||||
stream_child_freeall(clixon_handle h)
|
||||
{
|
||||
struct stream_child *sc;
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ restconf_stream_cb(int s,
|
|||
/* handle close from remote end: this will exit the client */
|
||||
if (eof){
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s eof", __FUNCTION__);
|
||||
clicon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
|
||||
clixon_err(OE_PROTO, ESHUTDOWN, "Socket unexpected close");
|
||||
errno = ESHUTDOWN;
|
||||
FCGX_FPrintF(r->out, "SHUTDOWN\r\n");
|
||||
FCGX_FPrintF(r->out, "\r\n");
|
||||
|
|
@ -236,12 +236,12 @@ restconf_stream_cb(int s,
|
|||
if ((ret = clicon_msg_decode(reply, NULL, NULL, &xtop, NULL)) < 0) /* XXX pass yang_spec */
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clicon_err(OE_XML, EFAULT, "Invalid notification");
|
||||
clixon_err(OE_XML, EFAULT, "Invalid notification");
|
||||
goto done;
|
||||
}
|
||||
/* create event */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((xn = xpath_first(xtop, NULL, "notification")) == NULL)
|
||||
|
|
@ -289,7 +289,7 @@ restconf_stream_cb(int s,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
restconf_stream(clicon_handle h,
|
||||
restconf_stream(clixon_handle h,
|
||||
void *req,
|
||||
char *name,
|
||||
cvec *qvec,
|
||||
|
|
@ -309,7 +309,7 @@ restconf_stream(clicon_handle h,
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
*sp = -1;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
clixon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "<rpc xmlns=\"%s\" %s><create-subscription xmlns=\"%s\"><stream>%s</stream>",
|
||||
|
|
@ -416,7 +416,7 @@ stream_timeout(int s,
|
|||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
api_stream(clicon_handle h,
|
||||
api_stream(clixon_handle h,
|
||||
void *req,
|
||||
cvec *qvec,
|
||||
int *finish)
|
||||
|
|
@ -548,7 +548,7 @@ api_stream(clicon_handle h,
|
|||
* killed, call FCGX_Free
|
||||
*/
|
||||
if ((sc = malloc(sizeof(struct stream_child))) == NULL){
|
||||
clicon_err(OE_XML, errno, "malloc");
|
||||
clixon_err(OE_XML, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(sc, 0, sizeof(struct stream_child));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue