Removed unused functions: cli_exec, cli_ptpush, cli_ptpop

This commit is contained in:
Olof Hagsand 2017-10-21 19:15:24 +02:00
parent 4b0c060667
commit 178a09cf3b
4 changed files with 14 additions and 101 deletions

View file

@ -1002,7 +1002,13 @@ from_client_msg(clicon_handle h,
} }
} }
reply: reply:
assert(cbuf_len(cbret)); if (cbuf_len(cbret) == 0)
cprintf(cbret, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>rpc</error-type>"
"<error-severity>error</error-severity>"
"<error-message>Internal error</error-message>"
"</rpc-error></rpc-reply>");
clicon_debug(1, "%s %s", __FUNCTION__, cbuf_get(cbret)); clicon_debug(1, "%s %s", __FUNCTION__, cbuf_get(cbret));
if (send_msg_reply(ce->ce_s, cbuf_get(cbret), cbuf_len(cbret)+1) < 0){ if (send_msg_reply(ce->ce_s, cbuf_get(cbret), cbuf_len(cbret)+1) < 0){
switch (errno){ switch (errno){

View file

@ -67,9 +67,9 @@
#include "cli_handle.h" #include "cli_handle.h"
/* /*! Name of master plugin functions
* Name of plugin functions
* More in clicon_plugin.h * More in clicon_plugin.h
* @note not really used consider documenting or remove
*/ */
#define PLUGIN_PROMPT_HOOK "plugin_prompt_hook" #define PLUGIN_PROMPT_HOOK "plugin_prompt_hook"
#define PLUGIN_PARSE_HOOK "plugin_parse_hook" #define PLUGIN_PARSE_HOOK "plugin_parse_hook"
@ -658,6 +658,10 @@ clicon_parse(clicon_handle h,
fprintf(stderr, "No such parse-tree registered: %s\n", modename); fprintf(stderr, "No such parse-tree registered: %s\n", modename);
goto done; goto done;
} }
if ((pt = cligen_tree_active_get(cli_cligen(h))) == NULL){
fprintf(stderr, "No such parse-tree registered: %s\n", modename);
goto done;
}
if ((cvv = cvec_new(0)) == NULL){ if ((cvv = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new"); clicon_err(OE_UNIX, errno, "cvec_new");
goto done;; goto done;;
@ -903,102 +907,6 @@ cli_prompt(char *fmt)
return prompt; return prompt;
} }
/*
* Run command in CLI engine
*/
int
cli_exec(clicon_handle h, char *cmd, char **mode, int *result)
{
return clicon_parse(h, cmd, mode, result);
}
/*
* push_one
* nifty code that 'pushes' a syntax one ore more levels
* op: eg "set"
* cmd: eg "edit policy-options"
*/
int
cli_ptpush(clicon_handle h, char *mode, char *string, char *op)
{
cg_obj *co, *co_cmd, *cc;
parse_tree *pt;
char **vec = NULL;
int i, j, nvec;
int found;
parse_tree pt_top;
cli_syntaxmode_t *m;
if ((m = syntax_mode_find(cli_syntax(h), mode, 0)) == NULL)
return 0;
pt_top = m->csm_pt;
if ((co_cmd = co_find_one(pt_top, op)) == NULL)
return 0;
pt = &co_cmd->co_pt;
/* vec is the command, eg 'edit policy_option' */
if ((vec = clicon_strsep(string, " ", &nvec)) == NULL)
goto catch;
co = NULL;
found = 0;
for (i=0; i<nvec; i++){
found = 0;
for (j=0; j<pt->pt_len; j++){
co = pt->pt_vec[j];
if (co && co->co_type == CO_COMMAND &&
(strcmp(co->co_command, vec[i])==0)){
pt = &co->co_pt;
found++;
break;
}
}
if (!found)
break;//not found on this level
}
if (found){ // match all levels
if (!co_cmd->co_pushed){
co_cmd->co_pt_push = co_cmd->co_pt;
co_cmd->co_pushed++;
}
co_cmd->co_pt = co->co_pt;
pt = &co_cmd->co_pt;
for (i=0; i<pt->pt_len; i++) /* set correct parent */
if ((cc = pt->pt_vec[i]) != NULL)
co_up_set(cc, co_cmd);
}
catch:
if (vec)
free(vec);
return 0;
}
int
cli_ptpop(clicon_handle h, char *mode, char *op)
{
cg_obj *co_cmd, *cc;
int i;
parse_tree *pt;
parse_tree pt_top;
cli_syntaxmode_t *m;
if ((m = syntax_mode_find(cli_syntax(h), mode, 0)) == NULL)
return 0;
pt_top = m->csm_pt;
if ((co_cmd = co_find_one(pt_top, op)) == NULL) //set
return 0;
if (!co_cmd->co_pushed)
return 0;
co_cmd->co_pushed = 0;
co_cmd->co_pt = co_cmd->co_pt_push;
pt = &co_cmd->co_pt;
for (i=0; i<pt->pt_len; i++) /* set correct parent */
if ((cc = pt->pt_vec[i]) != NULL)
co_up_set(cc, co_cmd);
return 0;
}
/*! Find a cli plugin based on name and resolve a function pointer in it. /*! Find a cli plugin based on name and resolve a function pointer in it.
* Callback from clicon_dbvars_parse() * Callback from clicon_dbvars_parse()
* Find a cli plugin based on name if given and use dlsym to resolve a * Find a cli plugin based on name if given and use dlsym to resolve a

View file

@ -54,7 +54,6 @@ int cli_syntax_load(clicon_handle h);
int cli_handler_err(FILE *fd); int cli_handler_err(FILE *fd);
int cli_set_prompt(clicon_handle h, const char *mode, const char *prompt); int cli_set_prompt(clicon_handle h, const char *mode, const char *prompt);
char *cli_prompt(char *fmt); char *cli_prompt(char *fmt);
int cli_exec(clicon_handle h, char *cmd, char **mode, int *result);
int cli_ptpush(clicon_handle h, char *mode, char *string, char *op); int cli_ptpush(clicon_handle h, char *mode, char *string, char *op);
int cli_ptpop(clicon_handle h, char *mode, char *op); int cli_ptpop(clicon_handle h, char *mode, char *op);

View file

@ -723,7 +723,7 @@ api_operation_post(clicon_handle h,
xbot = xtop; xbot = xtop;
if (api_path2xml(oppath, yspec, xtop, 1, &xbot, &y) < 0) if (api_path2xml(oppath, yspec, xtop, 1, &xbot, &y) < 0)
goto done; goto done;
if (data){ if (data && strlen(data)){
/* Parse input data as json or xml into xml */ /* Parse input data as json or xml into xml */
if (parse_xml){ if (parse_xml){
if (clicon_xml_parse_str(data, &xdata) < 0){ if (clicon_xml_parse_str(data, &xdata) < 0){