[Code formatting: Change indentation style to space](https://github.com/clicon/clixon/issues/379)
* Applies to all c/h/y/l/sh files and .editorconfig
This commit is contained in:
parent
a9d1ab006c
commit
d84c529ff1
376 changed files with 38147 additions and 38133 deletions
|
|
@ -87,13 +87,13 @@ co2apipath(cg_obj *co)
|
|||
cg_var *cv;
|
||||
|
||||
if (co == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if ((cb = co->co_callbacks) == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if ((cvv = cb->cc_cvec) == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if ((cv = cvec_i(cvv, 0)) == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
return cv_string_get(cv);
|
||||
}
|
||||
|
||||
|
|
@ -102,25 +102,25 @@ co2apipath(cg_obj *co)
|
|||
*/
|
||||
static cvec*
|
||||
cvec_append(cvec *cvv0,
|
||||
cvec *cvv1)
|
||||
cvec *cvv1)
|
||||
{
|
||||
cvec *cvv2 = NULL;
|
||||
cg_var *cv;
|
||||
|
||||
if (cvv0 == NULL){
|
||||
if ((cvv2 = cvec_dup(cvv1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
return NULL;
|
||||
}
|
||||
if ((cvv2 = cvec_dup(cvv1)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if ((cvv2 = cvec_dup(cvv0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
return NULL;
|
||||
}
|
||||
cv = NULL; /* Append cvv1 to cvv2 */
|
||||
while ((cv = cvec_each1(cvv1, cv)) != NULL)
|
||||
cvec_append_var(cvv2, cv);
|
||||
if ((cvv2 = cvec_dup(cvv0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
return NULL;
|
||||
}
|
||||
cv = NULL; /* Append cvv1 to cvv2 */
|
||||
while ((cv = cvec_each1(cvv1, cv)) != NULL)
|
||||
cvec_append_var(cvv2, cv);
|
||||
}
|
||||
return cvv2;
|
||||
}
|
||||
|
|
@ -137,8 +137,8 @@ cvec_append(cvec *cvv0,
|
|||
*/
|
||||
int
|
||||
cli_auto_edit(clicon_handle h,
|
||||
cvec *cvv1,
|
||||
cvec *argv)
|
||||
cvec *cvv1,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
char *api_path_fmt; /* xml key format */
|
||||
|
|
@ -151,61 +151,61 @@ cli_auto_edit(clicon_handle h,
|
|||
cvec *cvv2 = NULL; /* cvv2 = cvv0 + cvv1 */
|
||||
|
||||
if (cvec_len(argv) != 2){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>, <treename>)", __FUNCTION__);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(api_path_fmt>, <treename>)", __FUNCTION__);
|
||||
goto done;
|
||||
}
|
||||
cv = cvec_i(argv, 1);
|
||||
treename = cv_string_get(cv);
|
||||
/* Find current cligen tree */
|
||||
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
}
|
||||
/* Find the matching cligen object
|
||||
* Note, is complicated: either an instantiated tree (co_treeref_orig)
|
||||
* or actual tree (co_ref)
|
||||
*/
|
||||
if ((co = cligen_co_match(cli_cligen(h))) != NULL){
|
||||
if ((coorig = co->co_treeref_orig) != NULL ||
|
||||
(coorig = co->co_ref) != NULL)
|
||||
cligen_ph_workpoint_set(ph, coorig);
|
||||
else {
|
||||
clicon_err(OE_YANG, EINVAL, "No workpoint found");
|
||||
goto done;
|
||||
}
|
||||
if ((coorig = co->co_treeref_orig) != NULL ||
|
||||
(coorig = co->co_ref) != NULL)
|
||||
cligen_ph_workpoint_set(ph, coorig);
|
||||
else {
|
||||
clicon_err(OE_YANG, EINVAL, "No workpoint found");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else{
|
||||
clicon_err(OE_YANG, EINVAL, "No workpoint found");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, EINVAL, "No workpoint found");
|
||||
goto done;
|
||||
}
|
||||
if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
/* API_path format */
|
||||
if ((api_path_fmt = co2apipath(coorig)) == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "No apipath found");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, EINVAL, "No apipath found");
|
||||
goto done;
|
||||
}
|
||||
/* get api-path and xpath */
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv2, &api_path, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Store this as edit-mode */
|
||||
if (clicon_data_set(h, "cli-edit-mode", api_path) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (clicon_data_cvec_set(h, "cli-edit-cvv", cvv2) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (co->co_filter){
|
||||
cvec *cvv3;
|
||||
if ((cvv3 = cvec_dup(co->co_filter)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_data_cvec_set(h, "cli-edit-filter", cvv3) < 0)
|
||||
goto done;
|
||||
cvec *cvv3;
|
||||
if ((cvv3 = cvec_dup(co->co_filter)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_data_cvec_set(h, "cli-edit-filter", cvv3) < 0)
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (api_path)
|
||||
free(api_path);
|
||||
free(api_path);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -218,8 +218,8 @@ cli_auto_edit(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
cli_auto_up(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cg_var *cv;
|
||||
|
|
@ -238,41 +238,41 @@ cli_auto_up(clicon_handle h,
|
|||
cvec *cvv_filter = NULL;
|
||||
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<treename>)", __FUNCTION__);
|
||||
goto done;
|
||||
}
|
||||
cv = cvec_i(argv, 0);
|
||||
treename = cv_string_get(cv);
|
||||
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
}
|
||||
if ((co0 = cligen_ph_workpoint_get(ph)) == NULL)
|
||||
goto ok;
|
||||
goto ok;
|
||||
cvv_filter = clicon_data_cvec_get(h, "cli-edit-filter");
|
||||
/* Find parent that has a callback, XXX has edit */
|
||||
for (co1 = co_up(co0); co1; co1 = co_up(co1)){
|
||||
cg_obj *cot = NULL;
|
||||
if (co_terminal(co1, &cot)){
|
||||
if (cot == NULL)
|
||||
break; /* found top */
|
||||
if (cvv_filter){
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(cot->co_cvec, cv)) != NULL){
|
||||
if (co_isfilter(cvv_filter, cv_name_get(cv)))
|
||||
break;
|
||||
}
|
||||
if (cv == NULL)
|
||||
break; /* no filter match */
|
||||
}
|
||||
}
|
||||
cg_obj *cot = NULL;
|
||||
if (co_terminal(co1, &cot)){
|
||||
if (cot == NULL)
|
||||
break; /* found top */
|
||||
if (cvv_filter){
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(cot->co_cvec, cv)) != NULL){
|
||||
if (co_isfilter(cvv_filter, cv_name_get(cv)))
|
||||
break;
|
||||
}
|
||||
if (cv == NULL)
|
||||
break; /* no filter match */
|
||||
}
|
||||
}
|
||||
}
|
||||
cligen_ph_workpoint_set(ph, co1);
|
||||
if (co1 == NULL){
|
||||
clicon_data_set(h, "cli-edit-mode", "");
|
||||
clicon_data_cvec_del(h, "cli-edit-cvv");
|
||||
clicon_data_cvec_del(h, "cli-edit-filter");
|
||||
goto ok;
|
||||
clicon_data_set(h, "cli-edit-mode", "");
|
||||
clicon_data_cvec_del(h, "cli-edit-cvv");
|
||||
clicon_data_cvec_del(h, "cli-edit-filter");
|
||||
goto ok;
|
||||
}
|
||||
/* get before and after api-path-fmt (as generated from yang) */
|
||||
api_path_fmt0 = co2apipath(co0);
|
||||
|
|
@ -283,16 +283,16 @@ cli_auto_up(clicon_handle h,
|
|||
j=0; /* count diffs */
|
||||
len = strlen(api_path_fmt0);
|
||||
for (i=strlen(api_path_fmt1); i<len; i++)
|
||||
if (api_path_fmt0[i] == '%')
|
||||
j++;
|
||||
if (api_path_fmt0[i] == '%')
|
||||
j++;
|
||||
cvv1 = cvec_new(0);
|
||||
for (i=0; i<cvec_len(cvv0)-j; i++){
|
||||
cv = cvec_i(cvv0, i);
|
||||
cvec_append_var(cvv1, cv);
|
||||
cv = cvec_i(cvv0, i);
|
||||
cvec_append_var(cvv1, cv);
|
||||
}
|
||||
/* get api-path and xpath */
|
||||
if (api_path_fmt2api_path(api_path_fmt1, cvv1, &api_path, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Store this as edit-mode */
|
||||
clicon_data_set(h, "cli-edit-mode", api_path);
|
||||
clicon_data_cvec_set(h, "cli-edit-cvv", cvv1);
|
||||
|
|
@ -300,7 +300,7 @@ cli_auto_up(clicon_handle h,
|
|||
retval = 0;
|
||||
done:
|
||||
if (api_path)
|
||||
free(api_path);
|
||||
free(api_path);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -313,8 +313,8 @@ cli_auto_up(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
cli_auto_top(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cg_var *cv;
|
||||
|
|
@ -324,8 +324,8 @@ cli_auto_top(clicon_handle h,
|
|||
cv = cvec_i(argv, 0);
|
||||
treename = cv_string_get(cv);
|
||||
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
}
|
||||
cligen_ph_workpoint_set(ph, NULL);
|
||||
/* Store this as edit-mode */
|
||||
|
|
@ -346,19 +346,19 @@ cli_auto_top(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
cli_auto_set(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cvec *cvv2 = NULL;
|
||||
|
||||
cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv);
|
||||
if (cli_dbxml(h, cvv2, argv, OP_REPLACE, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
if (cvv2)
|
||||
cvec_free(cvv2);
|
||||
cvec_free(cvv2);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -369,19 +369,19 @@ cli_auto_set(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
cli_auto_merge(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cvec *cvv2 = NULL;
|
||||
|
||||
cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv);
|
||||
if (cli_dbxml(h, cvv2, argv, OP_MERGE, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
if (cvv2)
|
||||
cvec_free(cvv2);
|
||||
cvec_free(cvv2);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -392,19 +392,19 @@ cli_auto_merge(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
cli_auto_create(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cvec *cvv2 = NULL;
|
||||
|
||||
cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv);
|
||||
if (cli_dbxml(h, cvv2, argv, OP_CREATE, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
if (cvv2)
|
||||
cvec_free(cvv2);
|
||||
cvec_free(cvv2);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -415,19 +415,19 @@ cli_auto_create(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
cli_auto_del(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
cvec *cvv2 = NULL;
|
||||
|
||||
cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv);
|
||||
if (cli_dbxml(h, cvv2, argv, OP_REMOVE, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
if (cvv2)
|
||||
cvec_free(cvv2);
|
||||
cvec_free(cvv2);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -446,16 +446,16 @@ struct findpt_arg{
|
|||
*/
|
||||
static int
|
||||
cli_auto_findpt(cg_obj *co,
|
||||
void *arg)
|
||||
void *arg)
|
||||
{
|
||||
struct findpt_arg *fa = (struct findpt_arg *)arg;
|
||||
cvec *cvv;
|
||||
|
||||
if (co->co_callbacks && (cvv = co->co_callbacks->cc_cvec))
|
||||
if (strcmp(fa->fa_str, cv_string_get(cvec_i(cvv, 0))) == 0){
|
||||
fa->fa_co = co;
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(fa->fa_str, cv_string_get(cvec_i(cvv, 0))) == 0){
|
||||
fa->fa_co = co;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -477,8 +477,8 @@ cli_auto_findpt(cg_obj *co,
|
|||
*/
|
||||
int
|
||||
cli_auto_sub_enter(clicon_handle h,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = -1;
|
||||
char *api_path_fmt; /* Contains wildcards as %.. */
|
||||
|
|
@ -492,8 +492,8 @@ cli_auto_sub_enter(clicon_handle h,
|
|||
struct findpt_arg fa = {0,};
|
||||
|
||||
if (cvec_len(argv) < 2){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<tree> <api_path_fmt> (,vars)*)", __FUNCTION__);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Usage: %s(<tree> <api_path_fmt> (,vars)*)", __FUNCTION__);
|
||||
goto done;
|
||||
}
|
||||
/* First argv argument: treename */
|
||||
cv = cvec_i(argv, 0);
|
||||
|
|
@ -511,48 +511,48 @@ cli_auto_sub_enter(clicon_handle h,
|
|||
*/
|
||||
/* Create a cvv with variables to add to api-path */
|
||||
if ((cvv1 = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
/* Append static variables (skip first treename) */
|
||||
for (i=1; i<cvec_len(argv); i++){
|
||||
if (cvec_append_var(cvv1, cvec_i(argv, i)) < 0)
|
||||
goto done;
|
||||
if (cvec_append_var(cvv1, cvec_i(argv, i)) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Append dynamic variables from the command line (skip first contains whole command line) */
|
||||
for (i=1; i<cvec_len(cvv); i++){
|
||||
if (cvec_append_var(cvv1, cvec_i(cvv, i)) < 0)
|
||||
goto done;
|
||||
if (cvec_append_var(cvv1, cvec_i(cvv, i)) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv1, &api_path, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Assign the variables */
|
||||
if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Store this as edit-mode */
|
||||
if (clicon_data_set(h, "cli-edit-mode", api_path) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (clicon_data_cvec_set(h, "cli-edit-cvv", cvv2) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Find current cligen tree */
|
||||
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
|
||||
clicon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
}
|
||||
/* Find the point in the generated clispec tree where workpoint should be set */
|
||||
fa.fa_str = api_path_fmt;
|
||||
if (pt_apply(cligen_ph_parsetree_get(ph), cli_auto_findpt, INT32_MAX, &fa) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (fa.fa_co == NULL){
|
||||
clicon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path);
|
||||
goto done;
|
||||
}
|
||||
cligen_ph_workpoint_set(ph, fa.fa_co);
|
||||
retval = 0;
|
||||
done:
|
||||
if (api_path)
|
||||
free(api_path);
|
||||
free(api_path);
|
||||
if (cvv1)
|
||||
cvec_free(cvv1);
|
||||
cvec_free(cvv1);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,8 +111,8 @@ autocli_listkw_int2str(int listkw)
|
|||
*/
|
||||
int
|
||||
autocli_module(clicon_handle h,
|
||||
char *modname,
|
||||
int *enablep)
|
||||
char *modname,
|
||||
int *enablep)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xrule;
|
||||
|
|
@ -124,50 +124,50 @@ autocli_module(clicon_handle h,
|
|||
char *body;
|
||||
|
||||
if (enablep == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
}
|
||||
enable = 0;
|
||||
if ((xautocli = clicon_conf_autocli(h)) == NULL)
|
||||
goto ok;
|
||||
goto ok;
|
||||
/* Default rule */
|
||||
if ((str = xml_find_body(xautocli, "module-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No module-default rule");
|
||||
goto done;
|
||||
clicon_err(OE_XML, EINVAL, "No module-default rule");
|
||||
goto done;
|
||||
}
|
||||
enable = strcmp(str, "true") == 0;
|
||||
if (!enable){
|
||||
xrule = NULL;
|
||||
while ((xrule = xml_child_each(xautocli, xrule, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(xrule), "rule") != 0)
|
||||
continue;
|
||||
if ((str = xml_find_body(xrule, "operation")) == NULL)
|
||||
continue;
|
||||
/* Peek in element of rule to skip non-compress operations */
|
||||
if (autocli_str2op(str) != AUTOCLI_OP_ENABLE)
|
||||
continue;
|
||||
/* At this point this rule is a compress rule
|
||||
* enable rules logic is:
|
||||
* - If match, break, done
|
||||
*/
|
||||
xmod = NULL;
|
||||
while ((xmod = xml_child_each(xrule, xmod, CX_ELMNT)) != NULL) {
|
||||
if ((element = xml_name(xmod)) == NULL)
|
||||
continue;
|
||||
if (strcmp(element, "module-name") == 0){
|
||||
if (modname == NULL)
|
||||
break; /* match */
|
||||
if ((body = xml_body(xmod)) == NULL)
|
||||
continue; /* invalid rule? */
|
||||
if (fnmatch(body, modname, 0) == 0)
|
||||
break; /* match */
|
||||
}
|
||||
}
|
||||
if (xmod != NULL){ /* break: found match */
|
||||
enable = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
xrule = NULL;
|
||||
while ((xrule = xml_child_each(xautocli, xrule, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(xrule), "rule") != 0)
|
||||
continue;
|
||||
if ((str = xml_find_body(xrule, "operation")) == NULL)
|
||||
continue;
|
||||
/* Peek in element of rule to skip non-compress operations */
|
||||
if (autocli_str2op(str) != AUTOCLI_OP_ENABLE)
|
||||
continue;
|
||||
/* At this point this rule is a compress rule
|
||||
* enable rules logic is:
|
||||
* - If match, break, done
|
||||
*/
|
||||
xmod = NULL;
|
||||
while ((xmod = xml_child_each(xrule, xmod, CX_ELMNT)) != NULL) {
|
||||
if ((element = xml_name(xmod)) == NULL)
|
||||
continue;
|
||||
if (strcmp(element, "module-name") == 0){
|
||||
if (modname == NULL)
|
||||
break; /* match */
|
||||
if ((body = xml_body(xmod)) == NULL)
|
||||
continue; /* invalid rule? */
|
||||
if (fnmatch(body, modname, 0) == 0)
|
||||
break; /* match */
|
||||
}
|
||||
}
|
||||
if (xmod != NULL){ /* break: found match */
|
||||
enable = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ok:
|
||||
*enablep = enable;
|
||||
|
|
@ -180,9 +180,9 @@ autocli_module(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
autocli_compress_extension(yang_stmt *ys,
|
||||
yang_stmt *ymod,
|
||||
char *body,
|
||||
int *match)
|
||||
yang_stmt *ymod,
|
||||
char *body,
|
||||
int *match)
|
||||
{
|
||||
int retval = -1;
|
||||
char *prefix = NULL;
|
||||
|
|
@ -190,29 +190,29 @@ autocli_compress_extension(yang_stmt *ys,
|
|||
char *ns = NULL;
|
||||
int exist = 0;
|
||||
int ret;
|
||||
|
||||
|
||||
if (nodeid_split(body, &prefix, &id) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (prefix != NULL){
|
||||
if ((ret = yang_find_namespace_by_prefix(ys, prefix, &ns)) < 0)
|
||||
goto done;
|
||||
if (ret == 1){
|
||||
/* First try local node, then try module */
|
||||
if (yang_extension_value(ys, id, ns, &exist, NULL) < 0)
|
||||
goto done;
|
||||
if (exist == 0)
|
||||
if (yang_extension_value(ymod, id, ns, &exist, NULL) < 0)
|
||||
goto done;
|
||||
if (exist == 0)
|
||||
*match = 0;
|
||||
}
|
||||
if ((ret = yang_find_namespace_by_prefix(ys, prefix, &ns)) < 0)
|
||||
goto done;
|
||||
if (ret == 1){
|
||||
/* First try local node, then try module */
|
||||
if (yang_extension_value(ys, id, ns, &exist, NULL) < 0)
|
||||
goto done;
|
||||
if (exist == 0)
|
||||
if (yang_extension_value(ymod, id, ns, &exist, NULL) < 0)
|
||||
goto done;
|
||||
if (exist == 0)
|
||||
*match = 0;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (prefix)
|
||||
free(prefix);
|
||||
free(prefix);
|
||||
if (id)
|
||||
free(id);
|
||||
free(id);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -245,8 +245,8 @@ The surrounding container entities are removed from list nodes.
|
|||
*/
|
||||
int
|
||||
autocli_compress(clicon_handle h,
|
||||
yang_stmt *ys,
|
||||
int *compress)
|
||||
yang_stmt *ys,
|
||||
int *compress)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xautocli = NULL;
|
||||
|
|
@ -263,12 +263,12 @@ autocli_compress(clicon_handle h,
|
|||
char *body;
|
||||
|
||||
if (compress == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((xautocli = clicon_conf_autocli(h)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
}
|
||||
ymod = ys_module(ys);
|
||||
modname = yang_argument_get(ymod);
|
||||
|
|
@ -277,63 +277,63 @@ autocli_compress(clicon_handle h,
|
|||
nodeid = yang_argument_get(ys);
|
||||
xrule = NULL;
|
||||
while ((xrule = xml_child_each(xautocli, xrule, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(xrule), "rule") != 0)
|
||||
continue;
|
||||
if ((str = xml_find_body(xrule, "operation")) == NULL)
|
||||
continue;
|
||||
/* Peek in element of rule to skip non-compress operations */
|
||||
if (autocli_str2op(str) != AUTOCLI_OP_COMPRESS)
|
||||
continue;
|
||||
/* At this point this rule is a compress rule
|
||||
* compress rule logic is "OR", the logic is:
|
||||
* - If match, break, done
|
||||
* - If not match, continue to next rule
|
||||
*/
|
||||
match = 1;
|
||||
xmod = NULL;
|
||||
while ((xmod = xml_child_each(xrule, xmod, CX_ELMNT)) != NULL) {
|
||||
if ((element = xml_name(xmod)) == NULL)
|
||||
continue;
|
||||
if (strcmp(element, "name") == 0 ||
|
||||
strcmp(element, "operation") == 0)
|
||||
continue;
|
||||
if ((body = xml_body(xmod)) == NULL)
|
||||
continue;
|
||||
if (strcmp(element, "yang-keyword") == 0){
|
||||
if (strcmp(body, keywstr) != 0){
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element, "schema-nodeid") == 0){
|
||||
if (strcmp(body, nodeid) != 0){
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element, "module-name") == 0){
|
||||
if (fnmatch(body, modname, 0) != 0){
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element, "extension") == 0){
|
||||
if (autocli_compress_extension(ys, ymod, body, &match) < 0)
|
||||
goto done;
|
||||
if (match == 0)
|
||||
break;
|
||||
}
|
||||
else if (strcmp(element, "yang-keyword-child") == 0){
|
||||
enum rfc_6020 subkeyw;
|
||||
subkeyw = yang_str2key(body);
|
||||
if (yang_single_child_type(ys, subkeyw) == 0){
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match) /* At least one compress rule matches */
|
||||
break;
|
||||
if (strcmp(xml_name(xrule), "rule") != 0)
|
||||
continue;
|
||||
if ((str = xml_find_body(xrule, "operation")) == NULL)
|
||||
continue;
|
||||
/* Peek in element of rule to skip non-compress operations */
|
||||
if (autocli_str2op(str) != AUTOCLI_OP_COMPRESS)
|
||||
continue;
|
||||
/* At this point this rule is a compress rule
|
||||
* compress rule logic is "OR", the logic is:
|
||||
* - If match, break, done
|
||||
* - If not match, continue to next rule
|
||||
*/
|
||||
match = 1;
|
||||
xmod = NULL;
|
||||
while ((xmod = xml_child_each(xrule, xmod, CX_ELMNT)) != NULL) {
|
||||
if ((element = xml_name(xmod)) == NULL)
|
||||
continue;
|
||||
if (strcmp(element, "name") == 0 ||
|
||||
strcmp(element, "operation") == 0)
|
||||
continue;
|
||||
if ((body = xml_body(xmod)) == NULL)
|
||||
continue;
|
||||
if (strcmp(element, "yang-keyword") == 0){
|
||||
if (strcmp(body, keywstr) != 0){
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element, "schema-nodeid") == 0){
|
||||
if (strcmp(body, nodeid) != 0){
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element, "module-name") == 0){
|
||||
if (fnmatch(body, modname, 0) != 0){
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element, "extension") == 0){
|
||||
if (autocli_compress_extension(ys, ymod, body, &match) < 0)
|
||||
goto done;
|
||||
if (match == 0)
|
||||
break;
|
||||
}
|
||||
else if (strcmp(element, "yang-keyword-child") == 0){
|
||||
enum rfc_6020 subkeyw;
|
||||
subkeyw = yang_str2key(body);
|
||||
if (yang_single_child_type(ys, subkeyw) == 0){
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (match) /* At least one compress rule matches */
|
||||
break;
|
||||
}
|
||||
*compress = match;
|
||||
retval = 0;
|
||||
|
|
@ -351,7 +351,7 @@ autocli_compress(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
autocli_completion(clicon_handle h,
|
||||
int *completion)
|
||||
int *completion)
|
||||
{
|
||||
int retval = -1;
|
||||
char *str;
|
||||
|
|
@ -361,26 +361,26 @@ autocli_completion(clicon_handle h,
|
|||
cxobj *xautocli;
|
||||
|
||||
if (completion == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((xautocli = clicon_conf_autocli(h)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
}
|
||||
if ((str = xml_find_body(xautocli, "completion-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No completion-default rule");
|
||||
goto done;
|
||||
clicon_err(OE_XML, EINVAL, "No completion-default rule");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = parse_bool(str, &val, &reason)) < 0){
|
||||
clicon_err(OE_CFG, errno, "parse_bool");
|
||||
clicon_err(OE_CFG, errno, "parse_bool");
|
||||
goto done;
|
||||
}
|
||||
*completion = val;
|
||||
retval = 0;
|
||||
done:
|
||||
if (reason)
|
||||
free(reason);
|
||||
free(reason);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -394,23 +394,23 @@ autocli_completion(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
autocli_list_keyword(clicon_handle h,
|
||||
autocli_listkw_t *listkw)
|
||||
autocli_listkw_t *listkw)
|
||||
{
|
||||
int retval = -1;
|
||||
char *str;
|
||||
cxobj *xautocli = NULL;
|
||||
|
||||
if (listkw == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((xautocli = clicon_conf_autocli(h)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
}
|
||||
if ((str = xml_find_body(xautocli, "list-keyword-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No list-keyword-default rule");
|
||||
goto done;
|
||||
clicon_err(OE_XML, EINVAL, "No list-keyword-default rule");
|
||||
goto done;
|
||||
}
|
||||
*listkw = autocli_listkw_str2int(str);
|
||||
retval = 0;
|
||||
|
|
@ -427,7 +427,7 @@ autocli_list_keyword(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
autocli_treeref_state(clicon_handle h,
|
||||
int *treeref_state)
|
||||
int *treeref_state)
|
||||
{
|
||||
int retval = -1;
|
||||
char *str;
|
||||
|
|
@ -437,26 +437,26 @@ autocli_treeref_state(clicon_handle h,
|
|||
cxobj *xautocli;
|
||||
|
||||
if (treeref_state == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((xautocli = clicon_conf_autocli(h)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
}
|
||||
if ((str = xml_find_body(xautocli, "treeref-state-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No treeref-state-default rule");
|
||||
goto done;
|
||||
clicon_err(OE_XML, EINVAL, "No treeref-state-default rule");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = parse_bool(str, &val, &reason)) < 0){
|
||||
clicon_err(OE_CFG, errno, "parse_bool");
|
||||
clicon_err(OE_CFG, errno, "parse_bool");
|
||||
goto done;
|
||||
}
|
||||
*treeref_state = val;
|
||||
retval = 0;
|
||||
done:
|
||||
if (reason)
|
||||
free(reason);
|
||||
free(reason);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -471,8 +471,8 @@ autocli_treeref_state(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
autocli_edit_mode(clicon_handle h,
|
||||
char *keyw,
|
||||
int *flag)
|
||||
char *keyw,
|
||||
int *flag)
|
||||
{
|
||||
int retval = -1;
|
||||
char *str;
|
||||
|
|
@ -483,30 +483,30 @@ autocli_edit_mode(clicon_handle h,
|
|||
int i;
|
||||
|
||||
if (flag == NULL){
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, EINVAL, "Argument is NULL");
|
||||
goto done;
|
||||
}
|
||||
*flag = 0;
|
||||
if ((xautocli = clicon_conf_autocli(h)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, 0, "No clixon-autocli");
|
||||
goto done;
|
||||
}
|
||||
if ((str = xml_find_body(xautocli, "edit-mode-default")) == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "No edit-mode-default rule");
|
||||
goto done;
|
||||
clicon_err(OE_XML, EINVAL, "No edit-mode-default rule");
|
||||
goto done;
|
||||
}
|
||||
if ((vec = clicon_strsep(str, " ", &nvec)) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
for (i=0; i<nvec; i++){
|
||||
v = vec[i];
|
||||
if (strcmp(v, keyw) == 0){
|
||||
*flag = 1;
|
||||
break;
|
||||
}
|
||||
v = vec[i];
|
||||
if (strcmp(v, keyw) == 0){
|
||||
*flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (vec)
|
||||
free(vec);
|
||||
free(vec);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -87,7 +87,7 @@ struct cli_handle {
|
|||
/* ------ end of common handle ------ */
|
||||
|
||||
cligen_handle cl_cligen; /* cligen handle */
|
||||
cli_syntax_t *cl_stx; /* CLI syntax structure */
|
||||
cli_syntax_t *cl_stx; /* CLI syntax structure */
|
||||
};
|
||||
|
||||
/*! Return a clicon handle for other CLICON API calls
|
||||
|
|
@ -100,11 +100,11 @@ cli_handle_init(void)
|
|||
clicon_handle h = NULL;
|
||||
|
||||
if ((cl = (struct cli_handle *)clicon_handle_init0(sizeof(struct cli_handle))) == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
if ((clih = cligen_init()) == NULL){
|
||||
clicon_handle_exit((clicon_handle)cl);
|
||||
goto done;
|
||||
clicon_handle_exit((clicon_handle)cl);
|
||||
goto done;
|
||||
}
|
||||
cligen_userhandle_set(clih, cl);
|
||||
cligen_eval_wrap_fn_set(clih, plugin_context_check, cl);
|
||||
|
|
@ -124,7 +124,7 @@ cli_handle_exit(clicon_handle h)
|
|||
struct cli_handle *cl = handle(h);
|
||||
|
||||
if (cl->cl_stx)
|
||||
free(cl->cl_stx);
|
||||
free(cl->cl_stx);
|
||||
clicon_handle_exit(h); /* frees h and options */
|
||||
|
||||
cligen_exit(ch);
|
||||
|
|
@ -147,12 +147,12 @@ cli_syntax(clicon_handle h)
|
|||
/*! Set current syntax-group */
|
||||
int
|
||||
cli_syntax_set(clicon_handle h,
|
||||
cli_syntax_t *stx)
|
||||
cli_syntax_t *stx)
|
||||
{
|
||||
struct cli_handle *cl = handle(h);
|
||||
|
||||
if (cl->cl_stx)
|
||||
free(cl->cl_stx);
|
||||
free(cl->cl_stx);
|
||||
cl->cl_stx = stx;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -167,10 +167,10 @@ cli_cligen(clicon_handle h)
|
|||
|
||||
int
|
||||
cli_parse_file(clicon_handle h,
|
||||
FILE *f,
|
||||
char *name, /* just for errs */
|
||||
parse_tree *pt,
|
||||
cvec *globals)
|
||||
FILE *f,
|
||||
char *name, /* just for errs */
|
||||
parse_tree *pt,
|
||||
cvec *globals)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ cli_parse_file(clicon_handle h,
|
|||
|
||||
int
|
||||
cli_susp_hook(clicon_handle h,
|
||||
cligen_susp_cb_t *fn)
|
||||
cligen_susp_cb_t *fn)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ cli_susp_hook(clicon_handle h,
|
|||
}
|
||||
int
|
||||
cli_interrupt_hook(clicon_handle h,
|
||||
cligen_interrupt_cb_t *fn)
|
||||
cligen_interrupt_cb_t *fn)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ cli_interrupt_hook(clicon_handle h,
|
|||
|
||||
int
|
||||
cli_prompt_set(clicon_handle h,
|
||||
char *prompt)
|
||||
char *prompt)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
return cligen_prompt_set(ch, prompt);
|
||||
|
|
@ -206,7 +206,7 @@ cli_prompt_set(clicon_handle h,
|
|||
|
||||
int
|
||||
cli_logsyntax_set(clicon_handle h,
|
||||
int status)
|
||||
int status)
|
||||
{
|
||||
cligen_handle ch = cligen(h);
|
||||
return cligen_logsyntax_set(ch, status);
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@
|
|||
* Internal prototypes. For exported functions see clixon_cli_api.h
|
||||
*/
|
||||
int cli_parse_file(clicon_handle h,
|
||||
FILE *f,
|
||||
char *name, /* just for errs */
|
||||
parse_tree *pt,
|
||||
cvec *globals);
|
||||
FILE *f,
|
||||
char *name, /* just for errs */
|
||||
parse_tree *pt,
|
||||
cvec *globals);
|
||||
|
||||
int cli_susp_hook(clicon_handle h, cligen_susp_cb_t *fn);
|
||||
|
||||
|
|
|
|||
|
|
@ -90,33 +90,33 @@ cli_history_load(clicon_handle h)
|
|||
|
||||
/* Get history size from clixon option, if not use cligen default. */
|
||||
if (clicon_option_exists(h, "CLICON_CLI_HIST_SIZE"))
|
||||
lines = clicon_option_int(h,"CLICON_CLI_HIST_SIZE");
|
||||
lines = clicon_option_int(h,"CLICON_CLI_HIST_SIZE");
|
||||
else
|
||||
lines = CLIGEN_HISTSIZE_DEFAULT;
|
||||
lines = CLIGEN_HISTSIZE_DEFAULT;
|
||||
/* Re-init history with clixon lines (1st time was w cligen defaults) */
|
||||
if (cligen_hist_init(cli_cligen(h), lines) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if ((filename = clicon_option_str(h,"CLICON_CLI_HIST_FILE")) == NULL)
|
||||
goto ok; /* ignore */
|
||||
goto ok; /* ignore */
|
||||
if (wordexp(filename, &result, 0) < 0){
|
||||
clicon_err(OE_UNIX, errno, "wordexp");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "wordexp");
|
||||
goto done;
|
||||
}
|
||||
if ((f = fopen(result.we_wordv[0], "r")) == NULL){
|
||||
clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s",
|
||||
result.we_wordv[0], strerror(errno));
|
||||
goto ok;
|
||||
clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for reading: %s: %s",
|
||||
result.we_wordv[0], strerror(errno));
|
||||
goto ok;
|
||||
}
|
||||
if (cligen_hist_file_load(cli_cligen(h), f) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cligen_hist_file_load");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "cligen_hist_file_load");
|
||||
goto done;
|
||||
}
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
wordfree(&result);
|
||||
if (f)
|
||||
fclose(f);
|
||||
fclose(f);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -133,26 +133,26 @@ cli_history_save(clicon_handle h)
|
|||
wordexp_t result = {0,}; /* for tilde expansion */
|
||||
|
||||
if ((filename = clicon_option_str(h, "CLICON_CLI_HIST_FILE")) == NULL)
|
||||
goto ok; /* ignore */
|
||||
goto ok; /* ignore */
|
||||
if (wordexp(filename, &result, 0) < 0){
|
||||
clicon_err(OE_UNIX, errno, "wordexp");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "wordexp");
|
||||
goto done;
|
||||
}
|
||||
if ((f = fopen(result.we_wordv[0], "w+")) == NULL){
|
||||
clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s",
|
||||
result.we_wordv[0], strerror(errno));
|
||||
goto ok;
|
||||
clicon_log(LOG_DEBUG, "Warning: Could not open CLI history file for writing: %s: %s",
|
||||
result.we_wordv[0], strerror(errno));
|
||||
goto ok;
|
||||
}
|
||||
if (cligen_hist_file_save(cli_cligen(h), f) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cligen_hist_file_save");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "cligen_hist_file_save");
|
||||
goto done;
|
||||
}
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
wordfree(&result);
|
||||
if (f)
|
||||
fclose(f);
|
||||
fclose(f);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -170,13 +170,13 @@ cli_terminate(clicon_handle h)
|
|||
|
||||
clicon_rpc_close_session(h);
|
||||
if ((yspec = clicon_dbspec_yang(h)) != NULL)
|
||||
ys_free(yspec);
|
||||
ys_free(yspec);
|
||||
if ((yspec = clicon_config_yang(h)) != NULL)
|
||||
ys_free(yspec);
|
||||
ys_free(yspec);
|
||||
if ((nsctx = clicon_nsctx_global_get(h)) != NULL)
|
||||
cvec_free(nsctx);
|
||||
cvec_free(nsctx);
|
||||
if ((x = clicon_conf_xml(h)) != NULL)
|
||||
xml_free(x);
|
||||
xml_free(x);
|
||||
clicon_data_cvec_del(h, "cli-edit-cvv");;
|
||||
clicon_data_cvec_del(h, "cli-edit-filter");;
|
||||
xpath_optimize_exit();
|
||||
|
|
@ -198,7 +198,7 @@ static void
|
|||
cli_sig_term(int arg)
|
||||
{
|
||||
clicon_log(LOG_NOTICE, "%s: %u Terminated (killed by sig %d)",
|
||||
__PROGRAM__, getpid(), arg);
|
||||
__PROGRAM__, getpid(), arg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -211,12 +211,12 @@ cli_signal_init (clicon_handle h)
|
|||
|
||||
cli_signal_block(h);
|
||||
if (set_signal(SIGTERM, cli_sig_term, NULL) < 0){
|
||||
clicon_err(OE_UNIX, errno, "Setting SIGTERM signal");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "Setting SIGTERM signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
|
||||
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -239,17 +239,17 @@ cli_interactive(clicon_handle h)
|
|||
|
||||
/* Loop through all commands */
|
||||
while(!cligen_exiting(cli_cligen(h))) {
|
||||
new_mode = cli_syntax_mode(h);
|
||||
cmd = NULL;
|
||||
if (clicon_cliread(h, &cmd) < 0)
|
||||
goto done;
|
||||
if (cmd == NULL) { /* EOF */
|
||||
cligen_exiting_set(cli_cligen(h), 1);
|
||||
continue;
|
||||
}
|
||||
if (clicon_parse(h, cmd, &new_mode, &result, NULL) < 0)
|
||||
goto done;
|
||||
/* Why not check result? */
|
||||
new_mode = cli_syntax_mode(h);
|
||||
cmd = NULL;
|
||||
if (clicon_cliread(h, &cmd) < 0)
|
||||
goto done;
|
||||
if (cmd == NULL) { /* EOF */
|
||||
cligen_exiting_set(cli_cligen(h), 1);
|
||||
continue;
|
||||
}
|
||||
if (clicon_parse(h, cmd, &new_mode, &result, NULL) < 0)
|
||||
goto done;
|
||||
/* Why not check result? */
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -270,89 +270,89 @@ autocli_trees_default(clicon_handle h)
|
|||
|
||||
/* Create backward compatible tree: @datamodel */
|
||||
if ((ph = cligen_ph_add(cli_cligen(h), "datamodel")) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
if ((pt = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
if (cligen_parse_str(cli_cligen(h),
|
||||
"@basemodel, @remove:act-prekey, @remove:act-list, @remove:act-leafconst, @remove:ac-state;",
|
||||
"datamodel", pt, NULL) < 0)
|
||||
goto done;
|
||||
"@basemodel, @remove:act-prekey, @remove:act-list, @remove:act-leafconst, @remove:ac-state;",
|
||||
"datamodel", pt, NULL) < 0)
|
||||
goto done;
|
||||
if (cligen_ph_parsetree_set(ph, pt) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
|
||||
/* Create backward compatible tree: @datamodelshow */
|
||||
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelshow")) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
if ((pt = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
if (cligen_parse_str(cli_cligen(h),
|
||||
"@basemodel, @remove:act-leafvar, @remove:ac-state;",
|
||||
"datamodelshow", pt, NULL) < 0)
|
||||
goto done;
|
||||
"@basemodel, @remove:act-leafvar, @remove:ac-state;",
|
||||
"datamodelshow", pt, NULL) < 0)
|
||||
goto done;
|
||||
if (cligen_ph_parsetree_set(ph, pt) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Create backward compatible tree: @datamodelstate */
|
||||
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelstate")) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
if ((pt = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
if (cligen_parse_str(cli_cligen(h),
|
||||
"@basemodel, @remove:act-leafvar;",
|
||||
"datamodelstate", pt, NULL) < 0)
|
||||
goto done;
|
||||
"@basemodel, @remove:act-leafvar;",
|
||||
"datamodelstate", pt, NULL) < 0)
|
||||
goto done;
|
||||
if (cligen_ph_parsetree_set(ph, pt) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Create new tree: @datamodelmode */
|
||||
if ((ph = cligen_ph_add(cli_cligen(h), "datamodelmode")) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
if ((pt = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "@basemodel, @remove:act-prekey, @remove:act-leafconst, @remove:ac-state");
|
||||
/* Check if container and list are allowed edit modes */
|
||||
mode = 0;
|
||||
if (autocli_edit_mode(h, "container", &mode) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (mode == 0)
|
||||
cprintf(cb, ", @remove:act-container");
|
||||
cprintf(cb, ", @remove:act-container");
|
||||
mode = 0;
|
||||
if (autocli_edit_mode(h, "listall", &mode) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (mode == 0)
|
||||
cprintf(cb, ", @remove:act-list");
|
||||
cprintf(cb, ", @remove:act-list");
|
||||
mode = 0;
|
||||
if (autocli_edit_mode(h, "list", &mode) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (mode == 0)
|
||||
cprintf(cb, ", @remove:act-lastkey");
|
||||
cprintf(cb, ", @remove:act-lastkey");
|
||||
mode = 0;
|
||||
if (autocli_edit_mode(h, "leaf", &mode) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (mode == 0)
|
||||
cprintf(cb, ", @remove:ac-leaf");
|
||||
cprintf(cb, ", @remove:ac-leaf");
|
||||
cprintf(cb, ";");
|
||||
if (cligen_parse_str(cli_cligen(h), cbuf_get(cb), "datamodelmode", pt, NULL) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (cligen_ph_parsetree_set(ph, pt) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -369,7 +369,7 @@ autocli_trees_default(clicon_handle h)
|
|||
*/
|
||||
static int
|
||||
autocli_start(clicon_handle h,
|
||||
int printgen)
|
||||
int printgen)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yspec;
|
||||
|
|
@ -384,21 +384,21 @@ autocli_start(clicon_handle h,
|
|||
* is disable
|
||||
*/
|
||||
if (autocli_module(h, NULL, &enable) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (!enable){
|
||||
clicon_debug(1, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__);
|
||||
goto ok;
|
||||
clicon_debug(1, "%s Autocli not enabled (clixon-autocli)", __FUNCTION__);
|
||||
goto ok;
|
||||
}
|
||||
/* Init yang2cli */
|
||||
if (yang2cli_init(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
/* The actual generating call from yang to clispec for the complete yang spec */
|
||||
if (yang2cli_yspec(h, yspec, AUTOCLI_TREENAME, printgen) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* XXX Create pre-5.5 tree-refs for backward compatibility */
|
||||
if (autocli_trees_default(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -412,30 +412,30 @@ usage(clicon_handle h,
|
|||
char *plgdir = clicon_cli_dir(h);
|
||||
|
||||
fprintf(stderr, "usage:%s [options] [commands]\n"
|
||||
"where commands is a CLI command or options passed to the main plugin\n"
|
||||
"where options are\n"
|
||||
"where commands is a CLI command or options passed to the main plugin\n"
|
||||
"where options are\n"
|
||||
"\t-h \t\tHelp\n"
|
||||
"\t-D <level> \tDebug level\n"
|
||||
"\t-f <file> \tConfig-file (mandatory)\n"
|
||||
"\t-E <dir> \tExtra configuration file directory\n"
|
||||
"\t-F <file> \tRead commands from file (default stdin)\n"
|
||||
"\t-1\t\tDo not enter interactive mode\n"
|
||||
"\t-a UNIX|IPv4|IPv6\tInternal backend socket family\n"
|
||||
"\t-u <path|addr>\tInternal socket domain path or IP addr (see -a)\n"
|
||||
"\t-d <dir>\tSpecify plugin directory (default: %s)\n"
|
||||
"\t-D <level> \tDebug level\n"
|
||||
"\t-f <file> \tConfig-file (mandatory)\n"
|
||||
"\t-E <dir> \tExtra configuration file directory\n"
|
||||
"\t-F <file> \tRead commands from file (default stdin)\n"
|
||||
"\t-1\t\tDo not enter interactive mode\n"
|
||||
"\t-a UNIX|IPv4|IPv6\tInternal backend socket family\n"
|
||||
"\t-u <path|addr>\tInternal socket domain path or IP addr (see -a)\n"
|
||||
"\t-d <dir>\tSpecify plugin directory (default: %s)\n"
|
||||
"\t-m <mode>\tSpecify plugin syntax mode\n"
|
||||
"\t-q \t\tQuiet mode, dont print greetings or prompt, terminate on ctrl-C\n"
|
||||
"\t-p <dir>\tYang directory path (see CLICON_YANG_DIR)\n"
|
||||
"\t-G \t\tPrint auto-cli CLI syntax generated from YANG\n"
|
||||
"\t-L \t\tDebug print dynamic CLI syntax including completions and expansions\n"
|
||||
"\t-l <s|e|o|n|f<file>> \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (stderr is default)\n"
|
||||
"\t-y <file>\tOverride yang spec file (dont include .yang suffix)\n"
|
||||
"\t-c <file>\tSpecify cli spec file.\n"
|
||||
"\t-U <user>\tOver-ride unix user with a pseudo user for NACM.\n"
|
||||
"\t-o \"<option>=<value>\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
|
||||
argv0,
|
||||
plgdir ? plgdir : "none"
|
||||
);
|
||||
"\t-q \t\tQuiet mode, dont print greetings or prompt, terminate on ctrl-C\n"
|
||||
"\t-p <dir>\tYang directory path (see CLICON_YANG_DIR)\n"
|
||||
"\t-G \t\tPrint auto-cli CLI syntax generated from YANG\n"
|
||||
"\t-L \t\tDebug print dynamic CLI syntax including completions and expansions\n"
|
||||
"\t-l <s|e|o|n|f<file>> \tLog on (s)yslog, std(e)rr, std(o)ut, (n)one or (f)ile (stderr is default)\n"
|
||||
"\t-y <file>\tOverride yang spec file (dont include .yang suffix)\n"
|
||||
"\t-c <file>\tSpecify cli spec file.\n"
|
||||
"\t-U <user>\tOver-ride unix user with a pseudo user for NACM.\n"
|
||||
"\t-o \"<option>=<value>\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
|
||||
argv0,
|
||||
plgdir ? plgdir : "none"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -448,8 +448,8 @@ main(int argc,
|
|||
int retval = -1;
|
||||
int c;
|
||||
int once;
|
||||
char *tmp;
|
||||
char *argv0 = argv[0];
|
||||
char *tmp;
|
||||
char *argv0 = argv[0];
|
||||
clicon_handle h;
|
||||
int printgen = 0;
|
||||
int logclisyntax = 0;
|
||||
|
|
@ -474,17 +474,17 @@ main(int argc,
|
|||
|
||||
/* Initiate CLICON handle. CLIgen is also initialized */
|
||||
if ((h = cli_handle_init()) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Set username to clicon handle. Use in all communication to backend
|
||||
* Note, can be overridden by -U
|
||||
*/
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_username_set(h, pw->pw_name) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
cligen_comment_set(cli_cligen(h), '#'); /* Default to handle #! clicon_cli scripts */
|
||||
cligen_lexicalorder_set(cli_cligen(h), 1);
|
||||
|
|
@ -495,38 +495,38 @@ main(int argc,
|
|||
optind = 1;
|
||||
opterr = 0;
|
||||
while ((c = getopt(argc, argv, CLI_OPTS)) != -1)
|
||||
switch (c) {
|
||||
case 'h':
|
||||
/* Defer the call to usage() to later. Reason is that for helpful
|
||||
text messages, default dirs, etc, are not set until later.
|
||||
But this means that we need to check if 'help' is set before
|
||||
exiting, and then call usage() before exit.
|
||||
*/
|
||||
help = 1;
|
||||
break;
|
||||
case 'D' : /* debug */
|
||||
if (sscanf(optarg, "%d", &dbg) != 1)
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'f': /* config file */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
|
||||
break;
|
||||
case 'E': /* extra config directory */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
|
||||
break;
|
||||
case 'l': /* Log destination: s|e|o|f */
|
||||
if ((logdst = clicon_log_opt(optarg[0])) < 0)
|
||||
usage(h, argv[0]);
|
||||
if (logdst == CLICON_LOG_FILE &&
|
||||
strlen(optarg)>1 &&
|
||||
clicon_log_file(optarg+1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
switch (c) {
|
||||
case 'h':
|
||||
/* Defer the call to usage() to later. Reason is that for helpful
|
||||
text messages, default dirs, etc, are not set until later.
|
||||
But this means that we need to check if 'help' is set before
|
||||
exiting, and then call usage() before exit.
|
||||
*/
|
||||
help = 1;
|
||||
break;
|
||||
case 'D' : /* debug */
|
||||
if (sscanf(optarg, "%d", &dbg) != 1)
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'f': /* config file */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
|
||||
break;
|
||||
case 'E': /* extra config directory */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
|
||||
break;
|
||||
case 'l': /* Log destination: s|e|o|f */
|
||||
if ((logdst = clicon_log_opt(optarg[0])) < 0)
|
||||
usage(h, argv[0]);
|
||||
if (logdst == CLICON_LOG_FILE &&
|
||||
strlen(optarg)>1 &&
|
||||
clicon_log_file(optarg+1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
*/
|
||||
|
|
@ -537,94 +537,94 @@ main(int argc,
|
|||
/* Find, read and parse configfile */
|
||||
if (clicon_options_main(h) < 0){
|
||||
if (help)
|
||||
usage(h, argv[0]);
|
||||
goto done;
|
||||
usage(h, argv[0]);
|
||||
goto done;
|
||||
}
|
||||
/* Now rest of options */
|
||||
opterr = 0;
|
||||
optind = 1;
|
||||
while ((c = getopt(argc, argv, CLI_OPTS)) != -1){
|
||||
switch (c) {
|
||||
case 'D' : /* debug */
|
||||
case 'f': /* config file */
|
||||
case 'E': /* extra config dir */
|
||||
case 'l': /* Log destination */
|
||||
break; /* see above */
|
||||
case 'F': /* read commands from file */
|
||||
if (freopen(optarg, "r", stdin) == NULL){
|
||||
fprintf(stderr, "freopen: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case '1' : /* Quit after reading database once - dont wait for events */
|
||||
once = 1;
|
||||
break;
|
||||
case 'a': /* internal backend socket address family */
|
||||
if (clicon_option_add(h, "CLICON_SOCK_FAMILY", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'u': /* internal backend socket unix domain path or ip host */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
if (clicon_option_add(h, "CLICON_SOCK", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'd': /* Plugin directory: overrides configfile */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
if (clicon_option_add(h, "CLICON_CLI_DIR", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'm': /* CLI syntax mode */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
if (clicon_option_add(h, "CLICON_CLI_MODE", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'q' : /* Quiet mode */
|
||||
clicon_quiet_mode_set(h, 1);
|
||||
break;
|
||||
case 'p' : /* yang dir path */
|
||||
if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'G' : /* Print generated CLI syntax */
|
||||
printgen++;
|
||||
break;
|
||||
case 'L' : /* Debug print dynamic CLI syntax */
|
||||
logclisyntax++;
|
||||
break;
|
||||
case 'y' : /* Load yang absolute filename */
|
||||
if (clicon_option_add(h, "CLICON_YANG_MAIN_FILE", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'c' : /* Overwrite clispec with absolute filename */
|
||||
if (clicon_option_add(h, "CLICON_CLISPEC_FILE", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'U': /* Clixon 'pseudo' user */
|
||||
if (clicon_username_set(h, optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'o':{ /* Configuration option */
|
||||
char *val;
|
||||
if ((val = index(optarg, '=')) == NULL)
|
||||
usage(h, argv0);
|
||||
*val++ = '\0';
|
||||
if (clicon_option_add(h, optarg, val) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
}
|
||||
switch (c) {
|
||||
case 'D' : /* debug */
|
||||
case 'f': /* config file */
|
||||
case 'E': /* extra config dir */
|
||||
case 'l': /* Log destination */
|
||||
break; /* see above */
|
||||
case 'F': /* read commands from file */
|
||||
if (freopen(optarg, "r", stdin) == NULL){
|
||||
fprintf(stderr, "freopen: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case '1' : /* Quit after reading database once - dont wait for events */
|
||||
once = 1;
|
||||
break;
|
||||
case 'a': /* internal backend socket address family */
|
||||
if (clicon_option_add(h, "CLICON_SOCK_FAMILY", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'u': /* internal backend socket unix domain path or ip host */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
if (clicon_option_add(h, "CLICON_SOCK", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'd': /* Plugin directory: overrides configfile */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
if (clicon_option_add(h, "CLICON_CLI_DIR", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'm': /* CLI syntax mode */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
if (clicon_option_add(h, "CLICON_CLI_MODE", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'q' : /* Quiet mode */
|
||||
clicon_quiet_mode_set(h, 1);
|
||||
break;
|
||||
case 'p' : /* yang dir path */
|
||||
if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'G' : /* Print generated CLI syntax */
|
||||
printgen++;
|
||||
break;
|
||||
case 'L' : /* Debug print dynamic CLI syntax */
|
||||
logclisyntax++;
|
||||
break;
|
||||
case 'y' : /* Load yang absolute filename */
|
||||
if (clicon_option_add(h, "CLICON_YANG_MAIN_FILE", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'c' : /* Overwrite clispec with absolute filename */
|
||||
if (clicon_option_add(h, "CLICON_CLISPEC_FILE", optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'U': /* Clixon 'pseudo' user */
|
||||
if (clicon_username_set(h, optarg) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 'o':{ /* Configuration option */
|
||||
char *val;
|
||||
if ((val = index(optarg, '=')) == NULL)
|
||||
usage(h, argv0);
|
||||
*val++ = '\0';
|
||||
if (clicon_option_add(h, optarg, val) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
#ifdef __AFL_HAVE_MANUAL_CONTROL
|
||||
__AFL_INIT();
|
||||
__AFL_INIT();
|
||||
#endif
|
||||
|
||||
/* Access the remaining argv/argc options (after --) w clicon-argv_get() */
|
||||
|
|
@ -632,7 +632,7 @@ main(int argc,
|
|||
|
||||
/* Defer: Wait to the last minute to print help message */
|
||||
if (help)
|
||||
usage(h, argv[0]);
|
||||
usage(h, argv[0]);
|
||||
|
||||
/* Init cligen buffers */
|
||||
cligen_buflen = clicon_option_int(h, "CLICON_CLI_BUF_START");
|
||||
|
|
@ -641,17 +641,17 @@ main(int argc,
|
|||
|
||||
/* Init row numbers for raw terminals */
|
||||
if (clicon_option_exists(h, "CLICON_CLI_LINES_DEFAULT")){
|
||||
nr = clicon_option_int(h, "CLICON_CLI_LINES_DEFAULT");
|
||||
cligen_terminal_rows_set(cli_cligen(h), nr);
|
||||
nr = clicon_option_int(h, "CLICON_CLI_LINES_DEFAULT");
|
||||
cligen_terminal_rows_set(cli_cligen(h), nr);
|
||||
}
|
||||
|
||||
if (clicon_yang_regexp(h) == REGEXP_LIBXML2){
|
||||
#ifdef HAVE_LIBXML2
|
||||
/* Enable XSD libxml2 regex engine */
|
||||
cligen_regex_xsd_set(cli_cligen(h), 1);
|
||||
/* Enable XSD libxml2 regex engine */
|
||||
cligen_regex_xsd_set(cli_cligen(h), 1);
|
||||
#else
|
||||
clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
|
||||
goto done;
|
||||
clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXML2 not set (Either change CLICON_YANG_REGEXP to posix, or run: configure --with-libxml2))");
|
||||
goto done;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -662,11 +662,11 @@ main(int argc,
|
|||
cligen_helpstring_lines_set(cli_cligen(h), nr);
|
||||
|
||||
if ((nr = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
|
||||
clicon_log_string_limit_set(nr);
|
||||
clicon_log_string_limit_set(nr);
|
||||
|
||||
/* Setup signal handlers */
|
||||
if (cli_signal_init(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Backward compatible mode, do not include keys in cgv-arrays in callbacks.
|
||||
Should be 0 but default is 1 since all legacy apps use 1
|
||||
|
|
@ -676,16 +676,16 @@ main(int argc,
|
|||
|
||||
/* Initialize plugin module by creating a handle holding plugin and callback lists */
|
||||
if (clixon_plugin_module_init(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
#ifndef CLIXON_STATIC_PLUGINS
|
||||
{
|
||||
char *dir;
|
||||
/* Load cli .so plugins before yangs are loaded (eg extension callbacks) and
|
||||
* before CLI is loaded by cli_syntax_load below */
|
||||
if ((dir = clicon_cli_dir(h)) != NULL &&
|
||||
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
|
||||
goto done;
|
||||
char *dir;
|
||||
/* Load cli .so plugins before yangs are loaded (eg extension callbacks) and
|
||||
* before CLI is loaded by cli_syntax_load below */
|
||||
if ((dir = clicon_cli_dir(h)) != NULL &&
|
||||
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -693,90 +693,90 @@ main(int argc,
|
|||
* Otherwise it is loaded in netconf_module_load below
|
||||
*/
|
||||
if (netconf_module_features(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* In case ietf-yang-metadata is loaded by application, handle annotation extension */
|
||||
if (yang_metadata_init(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
|
||||
xml_nsctx_namespace_netconf_default(h);
|
||||
/* Create top-level and store as option */
|
||||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
|
||||
/* Load Yang modules
|
||||
* 1. Load a yang module as a specific absolute filename */
|
||||
if ((str = clicon_yang_main_file(h)) != NULL){
|
||||
if (yang_spec_parse_file(h, str, yspec) < 0)
|
||||
goto done;
|
||||
if (yang_spec_parse_file(h, str, yspec) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* 2. Load a (single) main module */
|
||||
if ((str = clicon_yang_module_main(h)) != NULL){
|
||||
if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
|
||||
yspec) < 0)
|
||||
goto done;
|
||||
if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
|
||||
yspec) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* 3. Load all modules in a directory */
|
||||
if ((str = clicon_yang_main_dir(h)) != NULL){
|
||||
if (yang_spec_load_dir(h, str, yspec) < 0)
|
||||
goto done;
|
||||
if (yang_spec_load_dir(h, str, yspec) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Load clixon lib yang module */
|
||||
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Load yang module library, RFC7895 */
|
||||
if (yang_modules_init(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Add netconf yang spec, used as internal protocol */
|
||||
if (netconf_module_load(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Here all modules are loaded
|
||||
* Compute and set canonical namespace context
|
||||
*/
|
||||
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Create autocli from YANG */
|
||||
if (autocli_start(h, printgen) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Initialize cli syntax.
|
||||
* Plugins have already been loaded by clixon_plugins_load above */
|
||||
if (cli_syntax_load(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Set syntax mode if specified from command-line or config-file. */
|
||||
if (clicon_option_exists(h, "CLICON_CLI_MODE"))
|
||||
if ((tmp = clicon_cli_mode(h)) != NULL)
|
||||
if (cli_set_syntax_mode(h, tmp) == 0) {
|
||||
fprintf(stderr, "FATAL: Failed to set syntax mode '%s'\n", tmp);
|
||||
goto done;
|
||||
}
|
||||
if ((tmp = clicon_cli_mode(h)) != NULL)
|
||||
if (cli_set_syntax_mode(h, tmp) == 0) {
|
||||
fprintf(stderr, "FATAL: Failed to set syntax mode '%s'\n", tmp);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!cli_syntax_mode(h)){
|
||||
fprintf(stderr, "FATAL: No cli mode set (use -m or CLICON_CLI_MODE)\n");
|
||||
goto done;
|
||||
fprintf(stderr, "FATAL: No cli mode set (use -m or CLICON_CLI_MODE)\n");
|
||||
goto done;
|
||||
}
|
||||
if (cligen_ph_find(cli_cligen(h), cli_syntax_mode(h)) == NULL)
|
||||
clicon_log(LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m <mode> on command line", cli_syntax_mode(h));
|
||||
clicon_log(LOG_WARNING, "No such cli mode: %s (Specify cli mode with CLICON_CLI_MODE in config file or -m <mode> on command line", cli_syntax_mode(h));
|
||||
/* CLIgen tab mode, ie how <tab>s behave */
|
||||
if ((tabmode = clicon_cli_tab_mode(h)) < 0){
|
||||
fprintf(stderr, "FATAL: CLICON_CLI_TAB_MODE not set\n");
|
||||
goto done;
|
||||
fprintf(stderr, "FATAL: CLICON_CLI_TAB_MODE not set\n");
|
||||
goto done;
|
||||
}
|
||||
cligen_tabmode_set(cli_cligen(h), tabmode);
|
||||
|
||||
if (logclisyntax)
|
||||
cli_logsyntax_set(h, logclisyntax);
|
||||
cli_logsyntax_set(h, logclisyntax);
|
||||
|
||||
if (dbg)
|
||||
clicon_option_dump(h, dbg);
|
||||
clicon_option_dump(h, dbg);
|
||||
|
||||
/* Join rest of argv to a single command */
|
||||
restarg = clicon_strjoin(argc, argv, " ");
|
||||
|
|
@ -793,42 +793,42 @@ main(int argc,
|
|||
/* Call start function in all plugins before we go interactive
|
||||
*/
|
||||
if (clixon_plugin_start_all(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
cligen_line_scrolling_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_LINESCROLLING"));
|
||||
/*! Start CLI history and load from file */
|
||||
if (cli_history_load(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Experimental utf8 mode */
|
||||
cligen_utf8_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_UTF8"));
|
||||
/* Launch interfactive event loop, unless -1 */
|
||||
if (restarg != NULL && strlen(restarg)){
|
||||
char *mode = cli_syntax_mode(h);
|
||||
cligen_result result; /* match result */
|
||||
int evalresult = 0; /* if result == 1, calback result */
|
||||
char *mode = cli_syntax_mode(h);
|
||||
cligen_result result; /* match result */
|
||||
int evalresult = 0; /* if result == 1, calback result */
|
||||
|
||||
if (clicon_parse(h, restarg, &mode, &result, &evalresult) < 0)
|
||||
goto done;
|
||||
if (result != 1) /* Not unique match */
|
||||
goto done;
|
||||
if (evalresult < 0)
|
||||
goto done;
|
||||
if (clicon_parse(h, restarg, &mode, &result, &evalresult) < 0)
|
||||
goto done;
|
||||
if (result != 1) /* Not unique match */
|
||||
goto done;
|
||||
if (evalresult < 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
/* Go into event-loop unless -1 command-line */
|
||||
if (!once){
|
||||
retval = cli_interactive(h);
|
||||
retval = cli_interactive(h);
|
||||
}
|
||||
else
|
||||
retval = 0;
|
||||
retval = 0;
|
||||
done:
|
||||
if (restarg)
|
||||
free(restarg);
|
||||
free(restarg);
|
||||
// Gets in your face if we log on stderr
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
|
||||
clicon_log(LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());
|
||||
if (h)
|
||||
cli_terminate(h);
|
||||
cli_terminate(h);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@
|
|||
/*
|
||||
* Constants
|
||||
*/
|
||||
#define CLI_DEFAULT_PROMPT "cli> "
|
||||
#define CLI_DEFAULT_PROMPT "cli> "
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
@ -84,22 +84,22 @@
|
|||
*/
|
||||
static cli_syntaxmode_t *
|
||||
syntax_mode_find(cli_syntax_t *stx,
|
||||
const char *mode,
|
||||
int create)
|
||||
const char *mode,
|
||||
int create)
|
||||
{
|
||||
cli_syntaxmode_t *csm;
|
||||
|
||||
csm = stx->stx_modes;
|
||||
if (csm) {
|
||||
do {
|
||||
if (strcmp(csm->csm_name, mode) == 0)
|
||||
return csm;
|
||||
csm = NEXTQ(cli_syntaxmode_t *, csm);
|
||||
} while (csm && csm != stx->stx_modes);
|
||||
do {
|
||||
if (strcmp(csm->csm_name, mode) == 0)
|
||||
return csm;
|
||||
csm = NEXTQ(cli_syntaxmode_t *, csm);
|
||||
} while (csm && csm != stx->stx_modes);
|
||||
}
|
||||
|
||||
if (create == 0)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
if ((csm = malloc(sizeof(cli_syntaxmode_t))) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
|
|
@ -107,16 +107,16 @@ syntax_mode_find(cli_syntax_t *stx,
|
|||
}
|
||||
memset(csm, 0, sizeof(*csm));
|
||||
if ((csm->csm_name = strdup(mode)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
return NULL;
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
return NULL;
|
||||
}
|
||||
if ((csm->csm_prompt = strdup(CLI_DEFAULT_PROMPT)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
return NULL;
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
return NULL;
|
||||
}
|
||||
if ((csm->csm_pt = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
return NULL;
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
return NULL;
|
||||
}
|
||||
INSQ(csm, stx->stx_modes);
|
||||
stx->stx_nmodes++;
|
||||
|
|
@ -130,15 +130,15 @@ syntax_mode_find(cli_syntax_t *stx,
|
|||
*/
|
||||
static int
|
||||
gen_parse_tree(clicon_handle h,
|
||||
cli_syntaxmode_t *m)
|
||||
cli_syntaxmode_t *m)
|
||||
{
|
||||
int retval = -1;
|
||||
pt_head *ph;
|
||||
|
||||
if ((ph = cligen_ph_add(cli_cligen(h), m->csm_name)) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
if (cligen_ph_parsetree_set(ph, m->csm_pt) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
@ -149,17 +149,17 @@ gen_parse_tree(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
syntax_append(clicon_handle h,
|
||||
cli_syntax_t *stx,
|
||||
const char *name,
|
||||
parse_tree *pt)
|
||||
cli_syntax_t *stx,
|
||||
const char *name,
|
||||
parse_tree *pt)
|
||||
{
|
||||
cli_syntaxmode_t *csm;
|
||||
|
||||
if ((csm = syntax_mode_find(stx, name, 1)) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
if (cligen_parsetree_merge(csm->csm_pt, NULL, pt) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
return -1;
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -174,19 +174,19 @@ cli_syntax_unload(clicon_handle h)
|
|||
cli_syntaxmode_t *csm;
|
||||
|
||||
if (stx == NULL)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
while (stx->stx_nmodes > 0) {
|
||||
csm = stx->stx_modes;
|
||||
DELQ(csm, stx->stx_modes, cli_syntaxmode_t *);
|
||||
if (csm){
|
||||
if (csm->csm_name)
|
||||
free(csm->csm_name);
|
||||
if (csm->csm_prompt)
|
||||
free(csm->csm_prompt);
|
||||
free(csm);
|
||||
}
|
||||
stx->stx_nmodes--;
|
||||
csm = stx->stx_modes;
|
||||
DELQ(csm, stx->stx_modes, cli_syntaxmode_t *);
|
||||
if (csm){
|
||||
if (csm->csm_name)
|
||||
free(csm->csm_name);
|
||||
if (csm->csm_prompt)
|
||||
free(csm->csm_prompt);
|
||||
free(csm);
|
||||
}
|
||||
stx->stx_nmodes--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -208,37 +208,37 @@ cli_syntax_unload(clicon_handle h)
|
|||
*/
|
||||
void *
|
||||
clixon_str2fn(char *name,
|
||||
void *handle,
|
||||
char **error)
|
||||
void *handle,
|
||||
char **error)
|
||||
{
|
||||
void *fn = NULL;
|
||||
|
||||
|
||||
/* Reset error */
|
||||
*error = NULL;
|
||||
/* Special check for auto-cli. If the virtual callback is used, it should be overwritten later
|
||||
* by a callback given in the clispec, eg: set @datamodel, cli_set();
|
||||
*/
|
||||
if (strcmp(name, GENERATE_CALLBACK) == 0)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
/* First check given plugin if any */
|
||||
if (handle) {
|
||||
dlerror(); /* Clear any existing error */
|
||||
fn = dlsym(handle, name);
|
||||
if ((*error = (char*)dlerror()) == NULL)
|
||||
return fn; /* If no error we found the address of the callback */
|
||||
dlerror(); /* Clear any existing error */
|
||||
fn = dlsym(handle, name);
|
||||
if ((*error = (char*)dlerror()) == NULL)
|
||||
return fn; /* If no error we found the address of the callback */
|
||||
}
|
||||
|
||||
/* Now check global namespace which includes any shared object loaded
|
||||
* into the global namespace. I.e. all lib*.so as well as the
|
||||
* master plugin if it exists
|
||||
*/
|
||||
dlerror(); /* Clear any existing error */
|
||||
dlerror(); /* Clear any existing error */
|
||||
/* RTLD_DEFAULT instead of NULL for linux + FreeBSD:
|
||||
* Use default search algorithm. Thanks jdl@netgate.com */
|
||||
fn = dlsym(RTLD_DEFAULT, name);
|
||||
if ((*error = (char*)dlerror()) == NULL)
|
||||
return fn; /* If no error we found the address of the callback */
|
||||
return fn; /* If no error we found the address of the callback */
|
||||
|
||||
/* Return value not really relevant here as the error string is set to
|
||||
* signal an error. However, just checking the function pointer for NULL
|
||||
|
|
@ -254,16 +254,16 @@ clixon_str2fn(char *name,
|
|||
* Make a lookup of plugins already loaded and resolve callbacks from cligen trees to
|
||||
* dl symbols in the plugin.
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] filename Name of file where syntax is specified (in syntax-group dir)
|
||||
* @param[in] dir Name of dir, or NULL
|
||||
* @param[in] filename Name of file where syntax is specified (in syntax-group dir)
|
||||
* @param[in] dir Name of dir, or NULL
|
||||
* @param[out] ptall Universal CLIgen parse tree: apply to all modes
|
||||
* @see clixon_plugins_load Where .so plugin code has been loaded prior to this
|
||||
*/
|
||||
static int
|
||||
cli_load_syntax_file(clicon_handle h,
|
||||
const char *filename,
|
||||
const char *dir,
|
||||
parse_tree *ptall)
|
||||
const char *filename,
|
||||
const char *dir,
|
||||
parse_tree *ptall)
|
||||
{
|
||||
void *handle = NULL; /* Handle to plugin .so module */
|
||||
char *mode = NULL; /* Name of syntax mode to append new syntax */
|
||||
|
|
@ -281,28 +281,28 @@ cli_load_syntax_file(clicon_handle h,
|
|||
#endif
|
||||
|
||||
if ((pt = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
if (dir)
|
||||
snprintf(filepath, MAXPATHLEN-1, "%s/%s", dir, filename);
|
||||
snprintf(filepath, MAXPATHLEN-1, "%s/%s", dir, filename);
|
||||
else
|
||||
snprintf(filepath, MAXPATHLEN-1, "%s", filename);
|
||||
snprintf(filepath, MAXPATHLEN-1, "%s", filename);
|
||||
if ((cvv = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "cvec_new");
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
/* Build parse tree from syntax spec. */
|
||||
if ((f = fopen(filepath, "r")) == NULL){
|
||||
clicon_err(OE_PLUGIN, errno, "fopen %s", filepath);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, errno, "fopen %s", filepath);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Assuming this plugin is first in queue */
|
||||
if (cli_parse_file(h, f, filepath, pt, cvv) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
|
||||
fclose(f);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
|
||||
fclose(f);
|
||||
goto done;
|
||||
}
|
||||
fclose(f);
|
||||
/* Get CLICON specific global variables:
|
||||
|
|
@ -320,70 +320,70 @@ cli_load_syntax_file(clicon_handle h,
|
|||
|
||||
#ifndef CLIXON_STATIC_PLUGINS
|
||||
if (plgnam != NULL) { /* Find plugin for callback resolving */
|
||||
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
|
||||
handle = clixon_plugin_handle_get(cp);
|
||||
if (handle == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
|
||||
plgnam, filename, plgnam,
|
||||
clicon_cli_dir(h));
|
||||
goto done;
|
||||
}
|
||||
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
|
||||
handle = clixon_plugin_handle_get(cp);
|
||||
if (handle == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
|
||||
plgnam, filename, plgnam,
|
||||
clicon_cli_dir(h));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Resolve callback names to function pointers. */
|
||||
if (cligen_callbackv_str2fn(pt, (cgv_str2fn_t*)clixon_str2fn, handle) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
|
||||
filename, plgnam, plgnam);
|
||||
goto done;
|
||||
clicon_err(OE_PLUGIN, 0, "Mismatch between CLIgen file '%s' and CLI plugin file '%s'. Some possible errors:\n\t1. A function given in the CLIgen file does not exist in the plugin (ie link error)\n\t2. The CLIgen spec does not point to the correct plugin .so file (CLICON_PLUGIN=\"%s\" is wrong)",
|
||||
filename, plgnam, plgnam);
|
||||
goto done;
|
||||
}
|
||||
if (cligen_expandv_str2fn(pt, (expandv_str2fn_t*)clixon_str2fn, handle) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Variable translation functions */
|
||||
if (cligen_translate_str2fn(pt, (translate_str2fn_t*)clixon_str2fn, handle) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Make sure we have a syntax mode specified */
|
||||
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
|
||||
mode = clicon_cli_mode(h);
|
||||
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
|
||||
clicon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
|
||||
goto done;
|
||||
}
|
||||
mode = clicon_cli_mode(h);
|
||||
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
|
||||
clicon_err(OE_PLUGIN, 0, "No syntax mode specified in %s", filepath);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
/* Find all modes in CLICON_MODE string: where to append the pt syntax tree */
|
||||
if ((vec = clicon_strsep(mode, ":", &nvec)) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
if (nvec == 1 && strcmp(vec[0], "*") == 0){
|
||||
/* Special case: Add this to all modes. Add to special "universal" syntax
|
||||
* and add to all syntaxes after all files have been loaded. At this point
|
||||
* all modes may not be known (not yet loaded)
|
||||
*/
|
||||
if (cligen_parsetree_merge(ptall, NULL, pt) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
goto done;
|
||||
}
|
||||
/* Special case: Add this to all modes. Add to special "universal" syntax
|
||||
* and add to all syntaxes after all files have been loaded. At this point
|
||||
* all modes may not be known (not yet loaded)
|
||||
*/
|
||||
if (cligen_parsetree_merge(ptall, NULL, pt) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < nvec; i++) {
|
||||
if (syntax_append(h,
|
||||
cli_syntax(h),
|
||||
vec[i],
|
||||
pt) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (prompt)
|
||||
cli_set_prompt(h, vec[i], prompt);
|
||||
}
|
||||
for (i = 0; i < nvec; i++) {
|
||||
if (syntax_append(h,
|
||||
cli_syntax(h),
|
||||
vec[i],
|
||||
pt) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (prompt)
|
||||
cli_set_prompt(h, vec[i], prompt);
|
||||
}
|
||||
}
|
||||
|
||||
cligen_parsetree_free(pt, 1);
|
||||
retval = 0;
|
||||
done:
|
||||
if (cvv)
|
||||
cvec_free(cvv);
|
||||
cvec_free(cvv);
|
||||
if (vec)
|
||||
free(vec);
|
||||
free(vec);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -412,10 +412,10 @@ cli_syntax_load(clicon_handle h)
|
|||
|
||||
/* Syntax already loaded. XXX should we re-load?? */
|
||||
if ((stx = cli_syntax(h)) != NULL)
|
||||
return 0;
|
||||
return 0;
|
||||
if ((ptall = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Format plugin directory path */
|
||||
|
|
@ -424,36 +424,36 @@ cli_syntax_load(clicon_handle h)
|
|||
|
||||
/* Allocate plugin group object */
|
||||
if ((stx = malloc(sizeof(*stx))) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
memset(stx, 0, sizeof(*stx)); /* Zero out all */
|
||||
memset(stx, 0, sizeof(*stx)); /* Zero out all */
|
||||
|
||||
cli_syntax_set(h, stx);
|
||||
|
||||
/* Load single specific clispec file */
|
||||
if (clispec_file){
|
||||
if (cli_load_syntax_file(h, clispec_file, NULL, ptall) < 0)
|
||||
goto done;
|
||||
if (cli_load_syntax_file(h, clispec_file, NULL, ptall) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Load all clispec .cli files in directory */
|
||||
if (clispec_dir){
|
||||
/* Get directory list of files */
|
||||
if ((ndp = clicon_file_dirent(clispec_dir, &dp, "(.cli)$", S_IFREG)) < 0)
|
||||
goto done;
|
||||
/* Load the syntax parse trees into cli_syntax stx structure */
|
||||
for (i = 0; i < ndp; i++) {
|
||||
clicon_debug(1, "DEBUG: Loading syntax '%.*s'",
|
||||
(int)strlen(dp[i].d_name)-4, dp[i].d_name);
|
||||
if (cli_load_syntax_file(h, dp[i].d_name, clispec_dir, ptall) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Get directory list of files */
|
||||
if ((ndp = clicon_file_dirent(clispec_dir, &dp, "(.cli)$", S_IFREG)) < 0)
|
||||
goto done;
|
||||
/* Load the syntax parse trees into cli_syntax stx structure */
|
||||
for (i = 0; i < ndp; i++) {
|
||||
clicon_debug(1, "DEBUG: Loading syntax '%.*s'",
|
||||
(int)strlen(dp[i].d_name)-4, dp[i].d_name);
|
||||
if (cli_load_syntax_file(h, dp[i].d_name, clispec_dir, ptall) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
/* Were any syntax modes successfully loaded? If not, leave */
|
||||
if (stx->stx_nmodes <= 0) {
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Go thorugh all modes and :
|
||||
* 1) Add the universal syntax
|
||||
|
|
@ -461,36 +461,36 @@ cli_syntax_load(clicon_handle h)
|
|||
*/
|
||||
m = stx->stx_modes;
|
||||
do {
|
||||
if (cligen_parsetree_merge(m->csm_pt, NULL, ptall) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
goto done;
|
||||
}
|
||||
if (gen_parse_tree(h, m) != 0)
|
||||
goto done;
|
||||
m = NEXTQ(cli_syntaxmode_t *, m);
|
||||
if (cligen_parsetree_merge(m->csm_pt, NULL, ptall) < 0){
|
||||
clicon_err(OE_PLUGIN, errno, "cligen_parsetree_merge");
|
||||
goto done;
|
||||
}
|
||||
if (gen_parse_tree(h, m) != 0)
|
||||
goto done;
|
||||
m = NEXTQ(cli_syntaxmode_t *, m);
|
||||
} while (m && m != stx->stx_modes);
|
||||
|
||||
/* Set susp and interrupt callbacks into CLIgen */
|
||||
cp = NULL;
|
||||
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||
if (fns==NULL && (fns = clixon_plugin_api_get(cp)->ca_suspend) != NULL)
|
||||
if (cli_susp_hook(h, fns) < 0)
|
||||
goto done;
|
||||
if (fni==NULL && (fni = clixon_plugin_api_get(cp)->ca_interrupt) != NULL)
|
||||
if (cli_interrupt_hook(h, fni) < 0)
|
||||
goto done;
|
||||
if (fns==NULL && (fns = clixon_plugin_api_get(cp)->ca_suspend) != NULL)
|
||||
if (cli_susp_hook(h, fns) < 0)
|
||||
goto done;
|
||||
if (fni==NULL && (fni = clixon_plugin_api_get(cp)->ca_interrupt) != NULL)
|
||||
if (cli_interrupt_hook(h, fni) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* All good. We can now proudly return a new group */
|
||||
retval = 0;
|
||||
done:
|
||||
if (retval != 0) {
|
||||
cli_syntax_unload(h);
|
||||
cli_syntax_set(h, NULL);
|
||||
cli_syntax_unload(h);
|
||||
cli_syntax_set(h, NULL);
|
||||
}
|
||||
cligen_parsetree_free(ptall, 1);
|
||||
if (dp)
|
||||
free(dp);
|
||||
free(dp);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -517,14 +517,14 @@ int
|
|||
cli_handler_err(FILE *f)
|
||||
{
|
||||
if (clicon_errno &&
|
||||
(clicon_get_logflags() & CLICON_LOG_STDERR) == 0){
|
||||
fprintf(f, "%s: %s", clicon_strerror(clicon_errno), clicon_err_reason);
|
||||
if (clicon_suberrno)
|
||||
fprintf(f, ": %s", strerror(clicon_suberrno));
|
||||
fprintf(f, "\n");
|
||||
(clicon_get_logflags() & CLICON_LOG_STDERR) == 0){
|
||||
fprintf(f, "%s: %s", clicon_strerror(clicon_errno), clicon_err_reason);
|
||||
if (clicon_suberrno)
|
||||
fprintf(f, ": %s", strerror(clicon_suberrno));
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
else
|
||||
fprintf(f, "CLI command error\n");
|
||||
fprintf(f, "CLI command error\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -537,7 +537,7 @@ cli_handler_err(FILE *f)
|
|||
* the new mode string.
|
||||
*
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] cmd Command string
|
||||
* @param[in] cmd Command string
|
||||
* @param[in,out] modenamep Pointer to the mode string pointer
|
||||
* @param[out] result CLIgen match result, < 0: errors, >=0 number of matches
|
||||
* @param[out] evalres Evaluation result if result=1
|
||||
|
|
@ -546,10 +546,10 @@ cli_handler_err(FILE *f)
|
|||
*/
|
||||
int
|
||||
clicon_parse(clicon_handle h,
|
||||
char *cmd,
|
||||
char **modenamep,
|
||||
cligen_result *result,
|
||||
int *evalres)
|
||||
char *cmd,
|
||||
char **modenamep,
|
||||
cligen_result *result,
|
||||
int *evalres)
|
||||
{
|
||||
int retval = -1;
|
||||
char *modename;
|
||||
|
|
@ -566,79 +566,79 @@ clicon_parse(clicon_handle h,
|
|||
|
||||
ch = cli_cligen(h);
|
||||
if (clicon_get_logflags()&CLICON_LOG_STDOUT)
|
||||
f = stdout;
|
||||
f = stdout;
|
||||
else
|
||||
f = stderr;
|
||||
f = stderr;
|
||||
stx = cli_syntax(h);
|
||||
if ((modename = *modenamep) == NULL) {
|
||||
csm = stx->stx_active_mode;
|
||||
modename = csm->csm_name;
|
||||
csm = stx->stx_active_mode;
|
||||
modename = csm->csm_name;
|
||||
}
|
||||
else {
|
||||
if ((csm = syntax_mode_find(stx, modename, 0)) == NULL) {
|
||||
fprintf(f, "Can't find syntax mode '%s'\n", modename);
|
||||
goto done;
|
||||
}
|
||||
if ((csm = syntax_mode_find(stx, modename, 0)) == NULL) {
|
||||
fprintf(f, "Can't find syntax mode '%s'\n", modename);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (csm != NULL){
|
||||
if (cligen_ph_active_set_byname(ch, modename) < 0){
|
||||
fprintf(stderr, "No such parse-tree registered: %s\n", modename);
|
||||
goto done;
|
||||
}
|
||||
if ((pt = cligen_pt_active_get(ch)) == NULL){
|
||||
fprintf(stderr, "No such parse-tree registered: %s\n", modename);
|
||||
goto done;
|
||||
}
|
||||
if (cliread_parse(ch, cmd, pt, &match_obj, &cvv, &callbacks, result, &reason) < 0)
|
||||
goto done;
|
||||
/* Debug command and result code */
|
||||
clicon_debug(1, "%s result:%d command: \"%s\"", __FUNCTION__, *result, cmd);
|
||||
switch (*result) {
|
||||
case CG_EOF: /* eof */
|
||||
case CG_ERROR:
|
||||
fprintf(f, "CLI parse error: %s\n", cmd);
|
||||
break;
|
||||
case CG_NOMATCH: /* no match */
|
||||
fprintf(f, "CLI syntax error: \"%s\": %s\n", cmd, reason);
|
||||
break;
|
||||
case CG_MATCH:
|
||||
if (strcmp(modename, *modenamep)){ /* Command in different mode */
|
||||
*modenamep = modename;
|
||||
cli_set_syntax_mode(h, modename);
|
||||
}
|
||||
cli_output_reset();
|
||||
if (!cligen_exiting(ch)) {
|
||||
clicon_err_reset();
|
||||
if ((ret = cligen_eval(ch, match_obj, cvv, callbacks)) < 0) {
|
||||
cli_handler_err(stdout);
|
||||
if (clicon_suberrno == ESHUTDOWN)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else
|
||||
ret = 0;
|
||||
if (evalres)
|
||||
*evalres = ret;
|
||||
break;
|
||||
default:
|
||||
fprintf(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd);
|
||||
break;
|
||||
} /* switch result */
|
||||
if (cvv){
|
||||
cvec_free(cvv);
|
||||
cvv = NULL;
|
||||
}
|
||||
if (cligen_ph_active_set_byname(ch, modename) < 0){
|
||||
fprintf(stderr, "No such parse-tree registered: %s\n", modename);
|
||||
goto done;
|
||||
}
|
||||
if ((pt = cligen_pt_active_get(ch)) == NULL){
|
||||
fprintf(stderr, "No such parse-tree registered: %s\n", modename);
|
||||
goto done;
|
||||
}
|
||||
if (cliread_parse(ch, cmd, pt, &match_obj, &cvv, &callbacks, result, &reason) < 0)
|
||||
goto done;
|
||||
/* Debug command and result code */
|
||||
clicon_debug(1, "%s result:%d command: \"%s\"", __FUNCTION__, *result, cmd);
|
||||
switch (*result) {
|
||||
case CG_EOF: /* eof */
|
||||
case CG_ERROR:
|
||||
fprintf(f, "CLI parse error: %s\n", cmd);
|
||||
break;
|
||||
case CG_NOMATCH: /* no match */
|
||||
fprintf(f, "CLI syntax error: \"%s\": %s\n", cmd, reason);
|
||||
break;
|
||||
case CG_MATCH:
|
||||
if (strcmp(modename, *modenamep)){ /* Command in different mode */
|
||||
*modenamep = modename;
|
||||
cli_set_syntax_mode(h, modename);
|
||||
}
|
||||
cli_output_reset();
|
||||
if (!cligen_exiting(ch)) {
|
||||
clicon_err_reset();
|
||||
if ((ret = cligen_eval(ch, match_obj, cvv, callbacks)) < 0) {
|
||||
cli_handler_err(stdout);
|
||||
if (clicon_suberrno == ESHUTDOWN)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else
|
||||
ret = 0;
|
||||
if (evalres)
|
||||
*evalres = ret;
|
||||
break;
|
||||
default:
|
||||
fprintf(f, "CLI syntax error: \"%s\" is ambiguous\n", cmd);
|
||||
break;
|
||||
} /* switch result */
|
||||
if (cvv){
|
||||
cvec_free(cvv);
|
||||
cvv = NULL;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (callbacks)
|
||||
co_callbacks_free(&callbacks);
|
||||
co_callbacks_free(&callbacks);
|
||||
if (reason)
|
||||
free(reason);
|
||||
free(reason);
|
||||
if (cvv)
|
||||
cvec_free(cvv);
|
||||
cvec_free(cvv);
|
||||
if (match_obj)
|
||||
co_free(match_obj, 0);
|
||||
co_free(match_obj, 0);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -650,7 +650,7 @@ done:
|
|||
*/
|
||||
static char *
|
||||
cli_prompt_get(clicon_handle h,
|
||||
char *fmt)
|
||||
char *fmt)
|
||||
{
|
||||
char *s = fmt;
|
||||
char hname[1024];
|
||||
|
|
@ -662,79 +662,79 @@ cli_prompt_get(clicon_handle h,
|
|||
char *str0;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
/* Start with empty string */
|
||||
while(*s) {
|
||||
if (*s == '%' && *++s) {
|
||||
switch(*s) {
|
||||
case 'H': /* Hostname */
|
||||
if (gethostname(hname, sizeof(hname)) != 0)
|
||||
strncpy(hname, "unknown", sizeof(hname)-1);
|
||||
cprintf(cb, "%s", hname);
|
||||
break;
|
||||
case 'U': /* Username */
|
||||
tmp = getenv("USER");
|
||||
cprintf(cb, "%s", tmp?tmp:"nobody");
|
||||
break;
|
||||
case 'T': /* TTY */
|
||||
if(ttyname_r(fileno(stdin), tty, sizeof(tty)-1) < 0)
|
||||
strcpy(tty, "notty");
|
||||
cprintf(cb, "%s", tty);
|
||||
break;
|
||||
case 'W': /* Last element of working path */
|
||||
if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
|
||||
strlen(path)){
|
||||
int i;
|
||||
if (*s == '%' && *++s) {
|
||||
switch(*s) {
|
||||
case 'H': /* Hostname */
|
||||
if (gethostname(hname, sizeof(hname)) != 0)
|
||||
strncpy(hname, "unknown", sizeof(hname)-1);
|
||||
cprintf(cb, "%s", hname);
|
||||
break;
|
||||
case 'U': /* Username */
|
||||
tmp = getenv("USER");
|
||||
cprintf(cb, "%s", tmp?tmp:"nobody");
|
||||
break;
|
||||
case 'T': /* TTY */
|
||||
if(ttyname_r(fileno(stdin), tty, sizeof(tty)-1) < 0)
|
||||
strcpy(tty, "notty");
|
||||
cprintf(cb, "%s", tty);
|
||||
break;
|
||||
case 'W': /* Last element of working path */
|
||||
if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
|
||||
strlen(path)){
|
||||
int i;
|
||||
|
||||
for (i=strlen(path)-1; i>=0; i--)
|
||||
if (path[i] == '/' || path[i] == ':')
|
||||
/* see yang2api_path_fmt_1() why occasional trailing / */
|
||||
if (i < strlen(path)-1)
|
||||
break;
|
||||
if (i >= 0)
|
||||
cprintf(cb, "%s", &path[i+1]);
|
||||
else
|
||||
cprintf(cb, "%s", path);
|
||||
}
|
||||
else
|
||||
cprintf(cb, "/");
|
||||
break;
|
||||
case 'w': /* Full Working edit path */
|
||||
if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
|
||||
strlen(path))
|
||||
cprintf(cb, "%s", path);
|
||||
else
|
||||
cprintf(cb, "/");
|
||||
break;
|
||||
default:
|
||||
cprintf(cb, "%%");
|
||||
cprintf(cb, "%c", *s);
|
||||
}
|
||||
}
|
||||
else if (*s == '\\' && *++s) {
|
||||
switch(*s) {
|
||||
case 'n':
|
||||
cprintf(cb, "\n");
|
||||
break;
|
||||
default:
|
||||
cprintf(cb, "\\");
|
||||
cprintf(cb, "%c", *s);
|
||||
}
|
||||
}
|
||||
else
|
||||
cprintf(cb, "%c", *s);
|
||||
s++;
|
||||
for (i=strlen(path)-1; i>=0; i--)
|
||||
if (path[i] == '/' || path[i] == ':')
|
||||
/* see yang2api_path_fmt_1() why occasional trailing / */
|
||||
if (i < strlen(path)-1)
|
||||
break;
|
||||
if (i >= 0)
|
||||
cprintf(cb, "%s", &path[i+1]);
|
||||
else
|
||||
cprintf(cb, "%s", path);
|
||||
}
|
||||
else
|
||||
cprintf(cb, "/");
|
||||
break;
|
||||
case 'w': /* Full Working edit path */
|
||||
if (clicon_data_get(h, "cli-edit-mode", &path) == 0 &&
|
||||
strlen(path))
|
||||
cprintf(cb, "%s", path);
|
||||
else
|
||||
cprintf(cb, "/");
|
||||
break;
|
||||
default:
|
||||
cprintf(cb, "%%");
|
||||
cprintf(cb, "%c", *s);
|
||||
}
|
||||
}
|
||||
else if (*s == '\\' && *++s) {
|
||||
switch(*s) {
|
||||
case 'n':
|
||||
cprintf(cb, "\n");
|
||||
break;
|
||||
default:
|
||||
cprintf(cb, "\\");
|
||||
cprintf(cb, "%c", *s);
|
||||
}
|
||||
}
|
||||
else
|
||||
cprintf(cb, "%c", *s);
|
||||
s++;
|
||||
}
|
||||
str0 = cbuf_len(cb) ? cbuf_get(cb) : CLI_DEFAULT_PROMPT;
|
||||
if ((promptstr = strdup(str0)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
cbuf_free(cb);
|
||||
return promptstr;
|
||||
}
|
||||
|
||||
|
|
@ -746,7 +746,7 @@ cli_prompt_get(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
clicon_cliread(clicon_handle h,
|
||||
char **stringp)
|
||||
char **stringp)
|
||||
{
|
||||
int retval = -1;
|
||||
char *pfmt = NULL;
|
||||
|
|
@ -761,29 +761,29 @@ clicon_cliread(clicon_handle h,
|
|||
/* Get prompt from plugin callback? */
|
||||
cp = NULL;
|
||||
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||
if ((fn = clixon_plugin_api_get(cp)->ca_prompt) == NULL)
|
||||
continue;
|
||||
pfmt = fn(h, mode->csm_name);
|
||||
break;
|
||||
if ((fn = clixon_plugin_api_get(cp)->ca_prompt) == NULL)
|
||||
continue;
|
||||
pfmt = fn(h, mode->csm_name);
|
||||
break;
|
||||
}
|
||||
if (clicon_quiet_mode(h))
|
||||
cli_prompt_set(h, "");
|
||||
cli_prompt_set(h, "");
|
||||
else{
|
||||
if ((promptstr = cli_prompt_get(h, pfmt ? pfmt : mode->csm_prompt)) == NULL)
|
||||
goto done;
|
||||
cli_prompt_set(h, promptstr);
|
||||
free(promptstr);
|
||||
if ((promptstr = cli_prompt_get(h, pfmt ? pfmt : mode->csm_prompt)) == NULL)
|
||||
goto done;
|
||||
cli_prompt_set(h, promptstr);
|
||||
free(promptstr);
|
||||
}
|
||||
cligen_ph_active_set_byname(cli_cligen(h), mode->csm_name);
|
||||
|
||||
if (cliread(cli_cligen(h), stringp) < 0){
|
||||
clicon_err(OE_FATAL, errno, "CLIgen");
|
||||
goto done;
|
||||
clicon_err(OE_FATAL, errno, "CLIgen");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (pfmt)
|
||||
free(pfmt);
|
||||
free(pfmt);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -798,12 +798,12 @@ clicon_cliread(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
cli_set_syntax_mode(clicon_handle h,
|
||||
const char *name)
|
||||
const char *name)
|
||||
{
|
||||
cli_syntaxmode_t *mode;
|
||||
|
||||
if ((mode = syntax_mode_find(cli_syntax(h), name, 1)) == NULL)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
cli_syntax(h)->stx_active_mode = mode;
|
||||
return 1;
|
||||
|
|
@ -818,7 +818,7 @@ cli_syntax_mode(clicon_handle h)
|
|||
cli_syntaxmode_t *csm;
|
||||
|
||||
if ((csm = cli_syntax(h)->stx_active_mode) == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
return csm->csm_name;
|
||||
}
|
||||
|
||||
|
|
@ -831,21 +831,21 @@ cli_syntax_mode(clicon_handle h)
|
|||
*/
|
||||
int
|
||||
cli_set_prompt(clicon_handle h,
|
||||
const char *name,
|
||||
const char *prompt)
|
||||
const char *name,
|
||||
const char *prompt)
|
||||
{
|
||||
cli_syntaxmode_t *csm;
|
||||
|
||||
if ((csm = syntax_mode_find(cli_syntax(h), name, 1)) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
if (csm->csm_prompt != NULL){
|
||||
free(csm->csm_prompt);
|
||||
csm->csm_prompt = NULL;
|
||||
free(csm->csm_prompt);
|
||||
csm->csm_prompt = NULL;
|
||||
}
|
||||
if ((csm->csm_prompt = strdup(prompt)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
return -1;
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
1092
apps/cli/cli_show.c
1092
apps/cli/cli_show.c
File diff suppressed because it is too large
Load diff
|
|
@ -77,8 +77,8 @@ cligen_handle cli_cligen(clicon_handle h);
|
|||
|
||||
/* cli_common.c */
|
||||
int cli_notification_register(clicon_handle h, char *stream, enum format_enum format,
|
||||
char *filter, int status,
|
||||
int (*fn)(int, void*), void *arg);
|
||||
char *filter, int status,
|
||||
int (*fn)(int, void*), void *arg);
|
||||
|
||||
/* cli_common.c: CLIgen new vector callbacks */
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ int cli_help(clicon_handle h, cvec *vars, cvec *argv);
|
|||
|
||||
/* In cli_show.c */
|
||||
int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv,
|
||||
cvec *commands, cvec *helptexts);
|
||||
cvec *commands, cvec *helptexts);
|
||||
int clixon_cli2file(clicon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop);
|
||||
|
||||
/* cli_show.c: CLIgen new vector arg callbacks */
|
||||
|
|
@ -161,7 +161,7 @@ int cli_auto_show(clicon_handle h, cvec *cvv, cvec *argv);
|
|||
int cli_show_auto_mode(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
int cli_auto_set(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
int cli_auto_merge(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
int cli_auto_create(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
int cli_auto_create(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
int cli_auto_del(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
int cli_auto_sub_enter(clicon_handle h, cvec *cvv, cvec *argv);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue