fixes for compilation
This commit is contained in:
parent
ba835346a5
commit
2485bec483
7 changed files with 17 additions and 237 deletions
|
|
@ -1546,12 +1546,17 @@ from_client_get_pageable_list(clicon_handle h,
|
||||||
/* Split into CT or CF */
|
/* Split into CT or CF */
|
||||||
if (yang_config_ancestor(y) == 1){ /* CT */
|
if (yang_config_ancestor(y) == 1){ /* CT */
|
||||||
if (content == CONTENT_CONFIG || content == CONTENT_ALL){
|
if (content == CONTENT_CONFIG || content == CONTENT_ALL){
|
||||||
if (xmldb_get0(h, datastore, YB_MODULE, nsc, cbuf_get(cb), 1, &xret, NULL) < 0) {
|
if ((ret = xmldb_get0(h, datastore, YB_MODULE, nsc, cbuf_get(cb), 1, &xret, NULL, &xerr)) < 0) {
|
||||||
if (netconf_operation_failed(cbret, "application", "read registry")< 0)
|
if (netconf_operation_failed(cbret, "application", "read registry")< 0)
|
||||||
goto done;
|
goto done;
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ret == 0){
|
||||||
|
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
|
||||||
|
goto done;
|
||||||
|
goto ok;
|
||||||
|
}
|
||||||
/* There may be CF data in a CT collection */
|
/* There may be CF data in a CT collection */
|
||||||
if (content == CONTENT_ALL){
|
if (content == CONTENT_ALL){
|
||||||
if ((ret = client_statedata(h, cbuf_get(cb), nsc, content, &xret)) < 0)
|
if ((ret = client_statedata(h, cbuf_get(cb), nsc, content, &xret)) < 0)
|
||||||
|
|
|
||||||
|
|
@ -218,6 +218,7 @@ api_data_get2(clicon_handle h,
|
||||||
if ((cbx = cbuf_new()) == NULL){
|
if ((cbx = cbuf_new()) == NULL){
|
||||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
goto done;
|
goto done;
|
||||||
|
}
|
||||||
if (xpath==NULL || strcmp(xpath,"/")==0){ /* Special case: data root */
|
if (xpath==NULL || strcmp(xpath,"/")==0){ /* Special case: data root */
|
||||||
switch (media_out){
|
switch (media_out){
|
||||||
case YANG_DATA_XML:
|
case YANG_DATA_XML:
|
||||||
|
|
@ -229,9 +230,6 @@ api_data_get2(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (restconf_unsupported_media(req) < 0)
|
|
||||||
goto done;
|
|
||||||
goto ok;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -442,227 +440,6 @@ api_data_collection(clicon_handle h,
|
||||||
sort = cvec_find_str(qvec, "sort");
|
sort = cvec_find_str(qvec, "sort");
|
||||||
where = cvec_find_str(qvec, "where");
|
where = cvec_find_str(qvec, "where");
|
||||||
|
|
||||||
if (clicon_rpc_get_collection(h, api_path, y, nsc, content,
|
|
||||||
depth, count, skip, direction, sort, where,
|
|
||||||
&xret) < 0){
|
|
||||||
if (netconf_operation_failed_xml(&xerr, "protocol", clicon_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)");
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
|
||||||
goto done;
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We get return via netconf which is complete tree from root
|
|
||||||
* We need to cut that tree to only the object.
|
|
||||||
*/
|
|
||||||
#if 0 /* DEBUG */
|
|
||||||
if (clicon_debug_get())
|
|
||||||
clicon_log_xml(LOG_DEBUG, xret, "%s xret:", __FUNCTION__);
|
|
||||||
#endif
|
|
||||||
/* Check if error return */
|
|
||||||
if ((xe = xpath_first(xret, NULL, "//rpc-error")) != NULL){
|
|
||||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
|
||||||
goto done;
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
/* Normal return, no error */
|
|
||||||
if ((cbx = cbuf_new()) == NULL)
|
|
||||||
goto done;
|
|
||||||
switch (media_out){
|
|
||||||
case YANG_COLLECTION_XML:
|
|
||||||
if (clicon_xml2cbuf(cbx, xret, 0, pretty, -1) < 0) /* Dont print top object? */
|
|
||||||
goto done;
|
|
||||||
break;
|
|
||||||
case YANG_COLLECTION_JSON:
|
|
||||||
if (xml2json_cbuf(cbx, xret, pretty) < 0)
|
|
||||||
goto done;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (restconf_unsupported_media(req) < 0)
|
|
||||||
goto done;
|
|
||||||
goto ok;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
/* Check if not exists */
|
|
||||||
if (xlen == 0){
|
|
||||||
/* 4.3: If a retrieval request for a data resource represents an
|
|
||||||
instance that does not exist, then an error response containing
|
|
||||||
a "404 Not Found" status-line MUST be returned by the server.
|
|
||||||
The error-tag value "invalid-value" is used in this case. */
|
|
||||||
if (netconf_invalid_value_xml(&xerr, "application", "Instance does not exist") < 0)
|
|
||||||
goto done;
|
|
||||||
/* override invalid-value default 400 with 404 */
|
|
||||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) != NULL){
|
|
||||||
if (api_return_err(h, req, xe, pretty, media_out, 404) < 0)
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
clicon_debug(1, "%s cbuf:%s", __FUNCTION__, cbuf_get(cbx));
|
|
||||||
if (restconf_reply_header(req, "Content-Type", "%s", restconf_media_int2str(media_out)) < 0)
|
|
||||||
goto done;
|
|
||||||
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
|
|
||||||
goto done;
|
|
||||||
if (restconf_reply_send(req, 200, cbx) < 0)
|
|
||||||
goto done;
|
|
||||||
ok:
|
|
||||||
retval = 0;
|
|
||||||
done:
|
|
||||||
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
|
|
||||||
if (cbrpc)
|
|
||||||
cbuf_free(cbrpc);
|
|
||||||
if (xpath)
|
|
||||||
free(xpath);
|
|
||||||
if (nsc)
|
|
||||||
xml_nsctx_free(nsc);
|
|
||||||
if (xtop)
|
|
||||||
xml_free(xtop);
|
|
||||||
if (cbx)
|
|
||||||
cbuf_free(cbx);
|
|
||||||
if (xret)
|
|
||||||
xml_free(xret);
|
|
||||||
if (xerr)
|
|
||||||
xml_free(xerr);
|
|
||||||
if (xvec)
|
|
||||||
free(xvec);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! GET Collection
|
|
||||||
* According to restconf collection draft. Lists, work in progress
|
|
||||||
* @param[in] h Clixon handle
|
|
||||||
* @param[in] req Generic Www handle
|
|
||||||
* @param[in] api_path According to restconf (Sec 3.5.3.1 in rfc8040)
|
|
||||||
* @param[in] pcvec Vector of path ie DOCUMENT_URI element
|
|
||||||
* @param[in] pi Offset, where path starts
|
|
||||||
* @param[in] qvec Vector of query string (QUERY_STRING)
|
|
||||||
* @param[in] pretty Set to 1 for pretty-printed xml/json output
|
|
||||||
* @param[in] media_out Output media
|
|
||||||
* @param[in] head If 1 is HEAD, otherwise GET
|
|
||||||
* @code
|
|
||||||
* curl -X GET http://localhost/restconf/data/interfaces
|
|
||||||
* @endcode
|
|
||||||
* A collection resource contains a set of data resources. It is used
|
|
||||||
* to represent a all instances or a subset of all instances in a YANG
|
|
||||||
* list or leaf-list.
|
|
||||||
* @see draft-ietf-netconf-restconf-collection-00.txt
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
api_data_collection(clicon_handle h,
|
|
||||||
void *req,
|
|
||||||
char *api_path,
|
|
||||||
cvec *pcvec, /* XXX remove? */
|
|
||||||
int pi,
|
|
||||||
cvec *qvec,
|
|
||||||
int pretty,
|
|
||||||
restconf_media media_out)
|
|
||||||
{
|
|
||||||
int retval = -1;
|
|
||||||
char *xpath = NULL;
|
|
||||||
cbuf *cbx = NULL;
|
|
||||||
yang_stmt *yspec;
|
|
||||||
cxobj *xret = NULL;
|
|
||||||
cxobj *xerr = NULL; /* malloced */
|
|
||||||
cxobj *xe = NULL; /* not malloced */
|
|
||||||
cxobj **xvec = NULL;
|
|
||||||
int i;
|
|
||||||
int ret;
|
|
||||||
cvec *nsc = NULL;
|
|
||||||
char *attr; /* attribute value string */
|
|
||||||
netconf_content content = CONTENT_ALL;
|
|
||||||
cxobj *xtop = NULL;
|
|
||||||
cxobj *xbot = NULL;
|
|
||||||
yang_stmt *y = NULL;
|
|
||||||
cbuf *cbrpc = NULL;
|
|
||||||
char *depth;
|
|
||||||
char *count;
|
|
||||||
char *skip;
|
|
||||||
char *direction;
|
|
||||||
char *sort;
|
|
||||||
char *where;
|
|
||||||
|
|
||||||
clicon_debug(1, "%s", __FUNCTION__);
|
|
||||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
|
||||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
/* strip /... from start */
|
|
||||||
for (i=0; i<pi; i++)
|
|
||||||
api_path = index(api_path+1, '/');
|
|
||||||
if (api_path){
|
|
||||||
if ((xtop = xml_new("top", NULL, CX_ELMNT)) == NULL)
|
|
||||||
goto done;
|
|
||||||
/* Translate api-path to xml, but to validate the api-path, note: strict=1
|
|
||||||
* xtop and xbot unnecessary for this function but needed by function
|
|
||||||
* Set strict=0 to accept list uri:s with =keys syntax
|
|
||||||
*/
|
|
||||||
if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y, &xerr)) < 0)
|
|
||||||
goto done;
|
|
||||||
/* Translate api-path to xpath: xpath (cbpath) and namespace context (nsc)
|
|
||||||
* XXX: xpath not used in collection?
|
|
||||||
*/
|
|
||||||
if (ret != 0 &&
|
|
||||||
(ret = api_path2xpath(api_path, yspec, &xpath, &nsc, &xerr)) < 0)
|
|
||||||
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)");
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
|
||||||
goto done;
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
if (yang_keyword_get(y) != Y_LIST && yang_keyword_get(y) != Y_LEAF_LIST){
|
|
||||||
if (netconf_bad_element_xml(&xerr, "application",
|
|
||||||
yang_argument_get(y),
|
|
||||||
"Element is not list or leaf-list which is required for GET collection") < 0)
|
|
||||||
goto done;
|
|
||||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
|
||||||
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
|
||||||
goto done;
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for content attribute */
|
|
||||||
if ((attr = cvec_find_str(qvec, "content")) != NULL){
|
|
||||||
clicon_debug(1, "%s content=%s", __FUNCTION__, attr);
|
|
||||||
if ((int)(content = netconf_content_str2int(attr)) == -1){
|
|
||||||
if (netconf_bad_attribute_xml(&xerr, "application",
|
|
||||||
"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)");
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if (api_return_err(h, req, xe, pretty, media_out, 0) < 0)
|
|
||||||
goto done;
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
clicon_debug(1, "%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);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
/* Clixon extensions and collection attributes */
|
|
||||||
depth = cvec_find_str(qvec, "depth");
|
|
||||||
count = cvec_find_str(qvec, "count");
|
|
||||||
skip = cvec_find_str(qvec, "skip");
|
|
||||||
direction = cvec_find_str(qvec, "direction");
|
|
||||||
sort = cvec_find_str(qvec, "sort");
|
|
||||||
where = cvec_find_str(qvec, "where");
|
|
||||||
|
|
||||||
if (clicon_rpc_get_pageable_list(h, "running", xpath, y, nsc, content,
|
if (clicon_rpc_get_pageable_list(h, "running", xpath, y, nsc, content,
|
||||||
depth, count, skip, direction, sort, where,
|
depth, count, skip, direction, sort, where,
|
||||||
&xret) < 0){
|
&xret) < 0){
|
||||||
|
|
@ -703,9 +480,6 @@ api_data_collection(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (restconf_unsupported_media(req) < 0)
|
|
||||||
goto done;
|
|
||||||
goto ok;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
|
@ -730,7 +504,7 @@ api_data_collection(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
|
if (restconf_reply_header(req, "Cache-Control", "no-cache") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (restconf_reply_send(req, 200, cbx) < 0)
|
if (restconf_reply_send(req, 200, cbx, 0 /* XXX head */) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -835,8 +609,6 @@ api_data_get(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (restconf_unsupported_media(req) < 0)
|
|
||||||
goto done;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
|
||||||
|
|
@ -432,7 +432,6 @@ api_root_restconf(clicon_handle h,
|
||||||
cbuf *cb = NULL;
|
cbuf *cb = NULL;
|
||||||
char *media_str = NULL;
|
char *media_str = NULL;
|
||||||
restconf_media media_out = YANG_DATA_JSON;
|
restconf_media media_out = YANG_DATA_JSON;
|
||||||
restconf_media media_in;
|
|
||||||
char *indata = NULL;
|
char *indata = NULL;
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
|
||||||
|
|
@ -1516,6 +1516,7 @@ netconf_module_load(clicon_handle h)
|
||||||
/* Load restconf yang. Note this is also a part of clixon-config */
|
/* Load restconf yang. Note this is also a part of clixon-config */
|
||||||
if (yang_spec_parse_module(h, "clixon-restconf", NULL, yspec)< 0)
|
if (yang_spec_parse_module(h, "clixon-restconf", NULL, yspec)< 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
#if 1
|
||||||
/* XXX: Both the following settings are because clicon-handle is not part of all API
|
/* XXX: Both the following settings are because clicon-handle is not part of all API
|
||||||
* functions
|
* functions
|
||||||
* Treat unknown XML as anydata */
|
* Treat unknown XML as anydata */
|
||||||
|
|
@ -1525,10 +1526,7 @@ netconf_module_load(clicon_handle h)
|
||||||
if (clicon_option_bool(h, "CLICON_NETCONF_MESSAGE_ID_OPTIONAL") == 1)
|
if (clicon_option_bool(h, "CLICON_NETCONF_MESSAGE_ID_OPTIONAL") == 1)
|
||||||
xml_bind_netconf_message_id_optional(1);
|
xml_bind_netconf_message_id_optional(1);
|
||||||
#endif
|
#endif
|
||||||
/* Load restconf collection */
|
/* Load netconf list pagination */
|
||||||
if (yang_spec_parse_module(h, "ietf-netconf-list-pagination", NULL, yspec)< 0)
|
|
||||||
goto done;
|
|
||||||
/* Load restconf collection */
|
|
||||||
if (yang_spec_parse_module(h, "ietf-netconf-list-pagination", NULL, yspec)< 0)
|
if (yang_spec_parse_module(h, "ietf-netconf-list-pagination", NULL, yspec)< 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
|
||||||
|
|
@ -966,7 +966,7 @@ clicon_rpc_get_pageable_list(clicon_handle h,
|
||||||
cprintf(cb, "</get-pageable-list></rpc>");
|
cprintf(cb, "</get-pageable-list></rpc>");
|
||||||
if ((msg = clicon_msg_encode(session_id, "%s", cbuf_get(cb))) == NULL)
|
if ((msg = clicon_msg_encode(session_id, "%s", cbuf_get(cb))) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
|
if (clicon_rpc_msg(h, msg, &xret) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* Send xml error back: first check error, then ok */
|
/* Send xml error back: first check error, then ok */
|
||||||
if ((xr = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
|
if ((xr = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
|
||||||
|
|
|
||||||
|
|
@ -1838,9 +1838,11 @@ ys_populate_leaf(clicon_handle h,
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cg_var *cv = NULL;
|
cg_var *cv = NULL;
|
||||||
|
yang_stmt *yparent;
|
||||||
yang_stmt *ydef;
|
yang_stmt *ydef;
|
||||||
enum cv_type cvtype = CGV_ERR;
|
enum cv_type cvtype = CGV_ERR;
|
||||||
int cvret;
|
int cvret;
|
||||||
|
int ret;
|
||||||
char *reason = NULL;
|
char *reason = NULL;
|
||||||
yang_stmt *yrestype; /* resolved type */
|
yang_stmt *yrestype; /* resolved type */
|
||||||
char *restype; /* resolved type */
|
char *restype; /* resolved type */
|
||||||
|
|
@ -1849,6 +1851,7 @@ ys_populate_leaf(clicon_handle h,
|
||||||
int options = 0x0;
|
int options = 0x0;
|
||||||
yang_stmt *ytypedef; /* where type is define */
|
yang_stmt *ytypedef; /* where type is define */
|
||||||
|
|
||||||
|
yparent = ys->ys_parent; /* Find parent: list/container */
|
||||||
/* 1. Find type specification and set cv type accordingly */
|
/* 1. Find type specification and set cv type accordingly */
|
||||||
if (yang_type_get(ys, &origtype, &yrestype, &options, NULL, NULL, NULL, &fraction_digits) < 0)
|
if (yang_type_get(ys, &origtype, &yrestype, &options, NULL, NULL, NULL, &fraction_digits) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,12 @@ YANGSPECS += ietf-yang-patch@2017-02-22.yang
|
||||||
YANGSPECS += ietf-origin@2018-02-14.yang
|
YANGSPECS += ietf-origin@2018-02-14.yang
|
||||||
YANGSPECS += ietf-yang-metadata@2016-08-05.yang
|
YANGSPECS += ietf-yang-metadata@2016-08-05.yang
|
||||||
YANGSPECS += ietf-netconf-with-defaults@2011-06-01.yang
|
YANGSPECS += ietf-netconf-with-defaults@2011-06-01.yang
|
||||||
|
<<<<<<< HEAD
|
||||||
# in draft-wwlh-netconf-list-pagination:
|
# in draft-wwlh-netconf-list-pagination:
|
||||||
YANGSPECS += ietf-netconf-list-pagination@2020-10-30.yang
|
YANGSPECS += ietf-netconf-list-pagination@2020-10-30.yang
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> fixes for compilation
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue