Changes due to CLIgen removal of expand-prepend code
This commit is contained in:
parent
05c082b202
commit
7577245077
3 changed files with 60 additions and 36 deletions
|
|
@ -377,7 +377,7 @@ cli_dbxml(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
cbuf *api_path_fmt_cb = NULL; /* xml key format */
|
||||
char *api_path_fmt; /* xml key format */
|
||||
char *api_path_fmt;
|
||||
char *api_path_fmt01 = NULL;
|
||||
char *api_path = NULL;
|
||||
cbuf *cb = NULL;
|
||||
|
|
@ -392,7 +392,6 @@ cli_dbxml(clicon_handle h,
|
|||
char *mtpoint = NULL;
|
||||
yang_stmt *yspec0 = NULL;
|
||||
int argc = 0;
|
||||
int i;
|
||||
|
||||
/* Top-level yspec */
|
||||
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
|
||||
|
|
@ -403,22 +402,11 @@ cli_dbxml(clicon_handle h,
|
|||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Iterate through all api_path_fmt:s, assume they start with / */
|
||||
for (argc=0; argc<cvec_len(argv); argc++){
|
||||
cv = cvec_i(argv, argc);
|
||||
str = cv_string_get(cv);
|
||||
if (str[0] != '/')
|
||||
break;
|
||||
}
|
||||
if (argc == 0){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "No <api_path_fmt> in argv");
|
||||
/* Concatenate all argv strings to a sinle string */
|
||||
if (cvec_concat_cb(argv, api_path_fmt_cb) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Append a api_path_fmt from sub-parts */
|
||||
for (i=argc-1; i>=0; i--){
|
||||
cprintf(api_path_fmt_cb, "%s", cv_string_get(cvec_i(argv, i)));
|
||||
}
|
||||
api_path_fmt = cbuf_get(api_path_fmt_cb);
|
||||
argc = cvec_len(argv);
|
||||
if (cvec_len(argv) > argc){
|
||||
cv = cvec_i(argv, argc++);
|
||||
str = cv_string_get(cv);
|
||||
|
|
@ -1654,6 +1642,45 @@ cvec_append(cvec *cvv0,
|
|||
return cvv2;
|
||||
}
|
||||
|
||||
/*! Concatenate all strings in a cvec into a single string
|
||||
*
|
||||
* @param[in] cvv Input vector
|
||||
* @param[out] appstr Concatenated string as existing cbuf
|
||||
*/
|
||||
int
|
||||
cvec_concat_cb(cvec *cvv,
|
||||
cbuf *cb)
|
||||
{
|
||||
int retval = -1;
|
||||
int argc;
|
||||
cg_var *cv;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
if (cb == NULL){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "cb is NULL");
|
||||
goto done;
|
||||
}
|
||||
/* Iterate through all api_path_fmt:s, assume they start with / */
|
||||
for (argc=0; argc<cvec_len(cvv); argc++){
|
||||
cv = cvec_i(cvv, argc);
|
||||
str = cv_string_get(cv);
|
||||
if (str[0] != '/')
|
||||
break;
|
||||
}
|
||||
if (argc == 0){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "No <api_path_fmt> in cvv");
|
||||
goto done;
|
||||
}
|
||||
/* Append a api_path_fmt from sub-parts */
|
||||
for (i=argc-1; i>=0; i--){
|
||||
cprintf(cb, "%s", cv_string_get(cvec_i(cvv, i)));
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Process control as defined by clixon-lib API
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ void cli_signal_block(clicon_handle h);
|
|||
void cli_signal_unblock(clicon_handle h);
|
||||
int mtpoint_paths(yang_stmt *yspec0, char *mtpoint, char *api_path_fmt1, char **api_path_fmt01);
|
||||
cvec *cvec_append(cvec *cvv0, cvec *cvv1);
|
||||
int cvec_concat_cb(cvec *cvv, cbuf *cb);
|
||||
|
||||
/* If you do not find a function here it may be in clixon_cli_api.h which is
|
||||
the external API */
|
||||
|
|
|
|||
|
|
@ -194,7 +194,8 @@ expand_dbvar(void *h,
|
|||
cvec *helptexts)
|
||||
{
|
||||
int retval = -1;
|
||||
char *api_path_fmt = NULL;
|
||||
cbuf *api_path_fmt_cb = NULL;
|
||||
char *api_path_fmt;
|
||||
char *api_path = NULL;
|
||||
char *api_path_fmt01 = NULL;
|
||||
char *dbstr;
|
||||
|
|
@ -226,7 +227,7 @@ expand_dbvar(void *h,
|
|||
cvec *nsc0 = NULL;
|
||||
char *str;
|
||||
int grouping_treeref;
|
||||
cbuf *cbprepend;
|
||||
cvec *callback_cvv;
|
||||
|
||||
if (argv == NULL || (cvec_len(argv) != 2 && cvec_len(argv) != 3)){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "requires arguments: <db> <apipathfmt> [<mountpt>]");
|
||||
|
|
@ -253,23 +254,18 @@ expand_dbvar(void *h,
|
|||
}
|
||||
if (autocli_grouping_treeref(h, &grouping_treeref) < 0)
|
||||
goto done;
|
||||
if ((api_path_fmt_cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if (grouping_treeref &&
|
||||
(cbprepend = cligen_expand_prepend_get(cli_cligen(h))) != NULL){
|
||||
cbuf *cb;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%s%s", cbuf_get(cbprepend), cv_string_get(cv));
|
||||
if ((api_path_fmt = strdup(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else if ((api_path_fmt = strdup(cv_string_get(cv))) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
(callback_cvv = cligen_callback_arguments_get(cli_cligen(h))) != NULL){
|
||||
/* Concatenate callback arguments to a singel prepend string */
|
||||
if (cvec_concat_cb(callback_cvv, api_path_fmt_cb) < 0)
|
||||
goto done;
|
||||
}
|
||||
cprintf(api_path_fmt_cb, "%s", cv_string_get(cv));
|
||||
api_path_fmt = cbuf_get(api_path_fmt_cb);
|
||||
if (cvec_len(argv) > 2){
|
||||
cv = cvec_i(argv, 2);
|
||||
str = cv_string_get(cv);
|
||||
|
|
@ -414,8 +410,8 @@ expand_dbvar(void *h,
|
|||
done:
|
||||
if (nsc0)
|
||||
cvec_free(nsc0);
|
||||
if (api_path_fmt)
|
||||
free(api_path_fmt);
|
||||
if (api_path_fmt_cb)
|
||||
cbuf_free(api_path_fmt_cb);
|
||||
if (api_path_fmt01)
|
||||
free(api_path_fmt01);
|
||||
if (cbxpath)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue