Removed argc/argv parameters from ca_start plugin API function. You may need to change signatures of your startup in your plugins
This commit is contained in:
parent
cdbce7645e
commit
60cb87f998
12 changed files with 72 additions and 96 deletions
22
CHANGELOG.md
22
CHANGELOG.md
|
|
@ -35,6 +35,28 @@
|
||||||
|
|
||||||
|
|
||||||
### API changes on existing features (you may need to change your code)
|
### API changes on existing features (you may need to change your code)
|
||||||
|
* Removed argc/argv parameters from ca_start plugin API function:
|
||||||
|
* You may need to change signatures of your startup in your plugins, eg from:
|
||||||
|
```
|
||||||
|
int xxx_start(clicon_handle h, int argc, char **argv)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static clixon_plugin_api xxx_api = {
|
||||||
|
...
|
||||||
|
.ca_start = xxx_start,
|
||||||
|
```
|
||||||
|
to:
|
||||||
|
```
|
||||||
|
int xxx_start(clicon_handle h)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static clixon_plugin_api xxx_api = {
|
||||||
|
...
|
||||||
|
.ca_start = xxx_start,
|
||||||
|
```
|
||||||
|
* If you use argv/argc use `clicon_argv_get()` in the init function instead.
|
||||||
* Changed hash API for better error handling
|
* Changed hash API for better error handling
|
||||||
* hash_dump, hash_keys, clicon_option_dump have new signatures
|
* hash_dump, hash_keys, clicon_option_dump have new signatures
|
||||||
* Renamed `xml_insert` to `xml_wrap_all`.
|
* Renamed `xml_insert` to `xml_wrap_all`.
|
||||||
|
|
|
||||||
|
|
@ -163,23 +163,6 @@ backend_server_socket(clicon_handle h)
|
||||||
return ss;
|
return ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Call plugin_start with -- user options */
|
|
||||||
static int
|
|
||||||
plugin_start_useroptions(clicon_handle h,
|
|
||||||
char *argv0,
|
|
||||||
int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
tmp = *(argv-1);
|
|
||||||
*(argv-1) = argv0;
|
|
||||||
if (clixon_plugin_start(h, argc+1, argv-1) < 0)
|
|
||||||
return -1;
|
|
||||||
*(argv-1) = tmp;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Load external NACM file
|
/*! Load external NACM file
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
|
|
@ -726,7 +709,7 @@ main(int argc,
|
||||||
clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret));
|
clicon_log(LOG_NOTICE, "%s: %u %s", __PROGRAM__, getpid(), cbuf_get(cbret));
|
||||||
|
|
||||||
/* Call backend plugin_start with user -- options */
|
/* Call backend plugin_start with user -- options */
|
||||||
if (plugin_start_useroptions(h, argv0, argc, argv) <0)
|
if (clixon_plugin_start(h) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (once)
|
if (once)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
|
|
@ -540,12 +540,9 @@ main(int argc, char **argv)
|
||||||
cligen_match_cgvar_same(1);
|
cligen_match_cgvar_same(1);
|
||||||
|
|
||||||
/* Call start function in all plugins before we go interactive
|
/* Call start function in all plugins before we go interactive
|
||||||
Pass all args after the standard options to plugin_start
|
|
||||||
*/
|
*/
|
||||||
tmp = *(argv-1);
|
if (clixon_plugin_start(h) < 0)
|
||||||
*(argv-1) = argv0;
|
goto done;
|
||||||
clixon_plugin_start(h, argc+1, argv-1);
|
|
||||||
*(argv-1) = tmp;
|
|
||||||
|
|
||||||
cligen_line_scrolling_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_LINESCROLLING"));
|
cligen_line_scrolling_set(cli_cligen(h), clicon_option_int(h,"CLICON_CLI_LINESCROLLING"));
|
||||||
/*! Start CLI history and load from file */
|
/*! Start CLI history and load from file */
|
||||||
|
|
|
||||||
|
|
@ -350,7 +350,6 @@ main(int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
char *tmp;
|
|
||||||
char *argv0 = argv[0];
|
char *argv0 = argv[0];
|
||||||
int quiet = 0;
|
int quiet = 0;
|
||||||
clicon_handle h;
|
clicon_handle h;
|
||||||
|
|
@ -511,10 +510,8 @@ main(int argc,
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Call start function is all plugins before we go interactive */
|
/* Call start function is all plugins before we go interactive */
|
||||||
tmp = *(argv-1);
|
if (clixon_plugin_start(h) < 0)
|
||||||
*(argv-1) = argv0;
|
goto done;
|
||||||
clixon_plugin_start(h, argc+1, argv-1);
|
|
||||||
*(argv-1) = tmp;
|
|
||||||
|
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
send_hello(h, 1);
|
send_hello(h, 1);
|
||||||
|
|
|
||||||
|
|
@ -520,7 +520,6 @@ main(int argc,
|
||||||
char *path;
|
char *path;
|
||||||
clicon_handle h;
|
clicon_handle h;
|
||||||
char *dir;
|
char *dir;
|
||||||
char *tmp;
|
|
||||||
int logdst = CLICON_LOG_SYSLOG;
|
int logdst = CLICON_LOG_SYSLOG;
|
||||||
yang_spec *yspec = NULL;
|
yang_spec *yspec = NULL;
|
||||||
yang_spec *yspecfg = NULL; /* For config XXX clixon bug */
|
yang_spec *yspecfg = NULL; /* For config XXX clixon bug */
|
||||||
|
|
@ -677,12 +676,9 @@ main(int argc,
|
||||||
yang_spec_parse_module(h, "clixon-rfc5277", NULL, yspec)< 0)
|
yang_spec_parse_module(h, "clixon-rfc5277", NULL, yspec)< 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* Call start function in all plugins before we go interactive
|
/* Call start function in all plugins before we go interactive
|
||||||
Pass all args after the standard options to plugin_start
|
|
||||||
*/
|
*/
|
||||||
tmp = *(argv-1);
|
if (clixon_plugin_start(h) < 0)
|
||||||
*(argv-1) = argv0;
|
goto done;
|
||||||
clixon_plugin_start(h, argc+1, argv-1);
|
|
||||||
*(argv-1) = tmp;
|
|
||||||
|
|
||||||
if ((sockpath = clicon_option_str(h, "CLICON_RESTCONF_PATH")) == NULL){
|
if ((sockpath = clicon_option_str(h, "CLICON_RESTCONF_PATH")) == NULL){
|
||||||
clicon_err(OE_CFG, errno, "No CLICON_RESTCONF_PATH in clixon configure file");
|
clicon_err(OE_CFG, errno, "No CLICON_RESTCONF_PATH in clixon configure file");
|
||||||
|
|
|
||||||
|
|
@ -496,21 +496,12 @@ example_reset(clicon_handle h,
|
||||||
|
|
||||||
/*! Plugin start.
|
/*! Plugin start.
|
||||||
* @param[in] h Clicon handle
|
* @param[in] h Clicon handle
|
||||||
* @param[in] argc Argument vector length (args after -- to backend_main)
|
|
||||||
* @param[in] argv Argument vector
|
|
||||||
*
|
*
|
||||||
* plugin_start is called once everything has been initialized, right before
|
* plugin_start is called once everything has been initialized, right before
|
||||||
* the main event loop is entered.
|
* the main event loop is entered.
|
||||||
* From the cli/backend, command line options can be passed to the
|
|
||||||
* plugins by using "-- <args>" where <args> is any choice of
|
|
||||||
* options specific to the application. These options are passed to the
|
|
||||||
* plugin_start function via the argc and argv arguments which
|
|
||||||
* can be processed with the standard getopt(3).
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
example_start(clicon_handle h,
|
example_start(clicon_handle h)
|
||||||
int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -555,6 +546,7 @@ clixon_plugin_init(clicon_handle h)
|
||||||
|
|
||||||
clicon_debug(1, "%s backend", __FUNCTION__);
|
clicon_debug(1, "%s backend", __FUNCTION__);
|
||||||
|
|
||||||
|
/* Get user command-line options (after --) */
|
||||||
if (clicon_argv_get(h, &argc, &argv) < 0)
|
if (clicon_argv_get(h, &argc, &argv) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
|
|
|
||||||
|
|
@ -89,9 +89,7 @@ nacm_statedata(clicon_handle h,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
plugin_start(clicon_handle h,
|
plugin_start(clicon_handle h)
|
||||||
int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
* the main event loop is entered.
|
* the main event loop is entered.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
plugin_start(clicon_handle h, int argc, char **argv)
|
plugin_start(clicon_handle h)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ static const char Base64[] =
|
||||||
static const char Pad64 = '=';
|
static const char Pad64 = '=';
|
||||||
|
|
||||||
/* Use http basic auth. Set by starting restonf with:
|
/* Use http basic auth. Set by starting restonf with:
|
||||||
clixon_restconf ... -- -a
|
* clixon_restconf ... -- -a
|
||||||
*/
|
*/
|
||||||
static int basic_auth = 0;
|
static int basic_auth = 0;
|
||||||
|
|
||||||
|
|
@ -298,29 +298,11 @@ restconf_client_rpc(clicon_handle h,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Start example restonf plugin. Set authentication method
|
/*! Start example restonf plugin. Set authentication method
|
||||||
* Arguments are argc/argv after --
|
|
||||||
* Currently defined: -a enable http basic authentication
|
|
||||||
* @note There are three hardwired users andy, wilma and guest from RFC8341 A.1
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
example_restconf_start(clicon_handle h,
|
example_restconf_start(clicon_handle h)
|
||||||
int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
{
|
||||||
int c;
|
clicon_debug(1, "%s", __FUNCTION__);
|
||||||
|
|
||||||
clicon_debug(1, "%s argc:%d", __FUNCTION__, argc);
|
|
||||||
optind = 1;
|
|
||||||
opterr = 0;
|
|
||||||
while ((c = getopt(argc, argv, "a")) != -1){
|
|
||||||
switch (c) {
|
|
||||||
case 'a':
|
|
||||||
basic_auth = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,11 +320,31 @@ static clixon_plugin_api api = {
|
||||||
* @param[in] h Clixon handle
|
* @param[in] h Clixon handle
|
||||||
* @retval NULL Error with clicon_err set
|
* @retval NULL Error with clicon_err set
|
||||||
* @retval api Pointer to API struct
|
* @retval api Pointer to API struct
|
||||||
|
* Arguments are argc/argv after --
|
||||||
|
* Currently defined: -a enable http basic authentication
|
||||||
|
* @note There are three hardwired users andy, wilma and guest from RFC8341 A.1
|
||||||
*/
|
*/
|
||||||
clixon_plugin_api *
|
clixon_plugin_api *
|
||||||
clixon_plugin_init(clicon_handle h)
|
clixon_plugin_init(clicon_handle h)
|
||||||
{
|
{
|
||||||
|
int argc; /* command-line options (after --) */
|
||||||
|
char **argv = NULL;
|
||||||
|
char c;
|
||||||
|
|
||||||
clicon_debug(1, "%s restconf", __FUNCTION__);
|
clicon_debug(1, "%s restconf", __FUNCTION__);
|
||||||
|
/* Get user command-line options (after --) */
|
||||||
|
if (clicon_argv_get(h, &argc, &argv) < 0)
|
||||||
|
return NULL;
|
||||||
|
opterr = 0;
|
||||||
|
optind = 1;
|
||||||
|
while ((c = getopt(argc, argv, "a")) != -1)
|
||||||
|
switch (c) {
|
||||||
|
case 'a':
|
||||||
|
basic_auth = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* Register local netconf rpc client (note not backend rpc client) */
|
/* Register local netconf rpc client (note not backend rpc client) */
|
||||||
if (rpc_callback_register(h, restconf_client_rpc, NULL, "urn:example:clixon", "client-rpc") < 0)
|
if (rpc_callback_register(h, restconf_client_rpc, NULL, "urn:example:clixon", "client-rpc") < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -98,12 +98,9 @@ typedef int (*clicon_upgrade_cb)(
|
||||||
* Backend see config_plugin.c
|
* Backend see config_plugin.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Called when backend started with cmd-line arguments from daemon call.
|
/* Called when application started (eg after daemon call).
|
||||||
* Call plugin start functions with argc/argv multiple arguments.
|
|
||||||
* Typically the argc/argv are the ones appearing after "--", eg
|
|
||||||
* clicon_cli -f /etc/clicon.xml -- -a myopt
|
|
||||||
*/
|
*/
|
||||||
typedef int (plgstart_t)(clicon_handle, int, char **); /* Plugin start */
|
typedef int (plgstart_t)(clicon_handle); /* Plugin start */
|
||||||
|
|
||||||
/* Called just before plugin unloaded.
|
/* Called just before plugin unloaded.
|
||||||
*/
|
*/
|
||||||
|
|
@ -141,7 +138,7 @@ typedef char *(cli_prompthook_t)(clicon_handle, char *mode);
|
||||||
* Note that for STARTUP_ERR and _INVALID, running runs in failsafe mode
|
* Note that for STARTUP_ERR and _INVALID, running runs in failsafe mode
|
||||||
* and startup contains the erroneous or invalid database.
|
* and startup contains the erroneous or invalid database.
|
||||||
* The user should repair the startup and
|
* The user should repair the startup and
|
||||||
* (1) restart he backend
|
* (1) restart the backend
|
||||||
* (2) copy startup to candidate and commit.
|
* (2) copy startup to candidate and commit.
|
||||||
*/
|
*/
|
||||||
enum startup_status{
|
enum startup_status{
|
||||||
|
|
@ -237,7 +234,7 @@ clixon_plugin *clixon_plugin_find(clicon_handle h, char *name);
|
||||||
|
|
||||||
int clixon_plugins_load(clicon_handle h, char *function, char *dir, char *regexp);
|
int clixon_plugins_load(clicon_handle h, char *function, char *dir, char *regexp);
|
||||||
|
|
||||||
int clixon_plugin_start(clicon_handle h, int argc, char **argv);
|
int clixon_plugin_start(clicon_handle h);
|
||||||
|
|
||||||
int clixon_plugin_exit(clicon_handle h);
|
int clixon_plugin_exit(clicon_handle h);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1076,7 +1076,7 @@ clicon_argv_get(clicon_handle h,
|
||||||
if (argv){
|
if (argv){
|
||||||
if ((p = hash_value(cdat, "argv", NULL)) == NULL)
|
if ((p = hash_value(cdat, "argv", NULL)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
*argv = *(char***)p;
|
*argv = (char**)p;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1099,15 +1099,18 @@ clicon_argv_set(clicon_handle h,
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
clicon_hash_t *cdat = clicon_data(h);
|
clicon_hash_t *cdat = clicon_data(h);
|
||||||
char **argvv = NULL;
|
char **argvv = NULL;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
/* add space for null-termination and argv[0] program name */
|
/* add space for null-termination and argv[0] program name */
|
||||||
if ((argvv = calloc(argc+2, sizeof(char*))) == NULL){
|
len = argc+2;
|
||||||
|
if ((argvv = calloc(len, sizeof(char*))) == NULL){
|
||||||
clicon_err(OE_UNIX, errno, "calloc");
|
clicon_err(OE_UNIX, errno, "calloc");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
memcpy(argvv+1, argv, argc*sizeof(char*));
|
memcpy(argvv+1, argv, argc*sizeof(char*));
|
||||||
argvv[0] = prgm;
|
argvv[0] = prgm;
|
||||||
if (hash_add(cdat, "argv", &argvv, sizeof(argvv))==NULL)
|
/* Note the value is the argv vector (which is copied) */
|
||||||
|
if (hash_add(cdat, "argv", argvv, len*sizeof(char*))==NULL)
|
||||||
goto done;
|
goto done;
|
||||||
argc += 1;
|
argc += 1;
|
||||||
if (hash_add(cdat, "argc", &argc, sizeof(argc))==NULL)
|
if (hash_add(cdat, "argc", &argc, sizeof(argc))==NULL)
|
||||||
|
|
|
||||||
|
|
@ -295,21 +295,11 @@ done:
|
||||||
|
|
||||||
/*! Call plugin_start in all plugins
|
/*! Call plugin_start in all plugins
|
||||||
* @param[in] h Clicon handle
|
* @param[in] h Clicon handle
|
||||||
* @param[in] argc
|
* Call plugin start functions (if defined)
|
||||||
* @param[in] argv
|
* @note Start functions used to have argc/argv. Use clicon_argv_get() instead
|
||||||
* Call plugin start functions (if defined) with argc/argv multiple
|
|
||||||
* arguments.
|
|
||||||
* Typically the argc/argv are the ones appearing after "--", eg
|
|
||||||
* clicon_cli -f /etc/clicon.xml -- -a myopt
|
|
||||||
* In the example above argc=3 and
|
|
||||||
* argv[0]: clicon_cli
|
|
||||||
* argv[1]: -a
|
|
||||||
* argv[2]: myopt
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
clixon_plugin_start(clicon_handle h,
|
clixon_plugin_start(clicon_handle h)
|
||||||
int argc,
|
|
||||||
char **argv)
|
|
||||||
{
|
{
|
||||||
clixon_plugin *cp;
|
clixon_plugin *cp;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -319,8 +309,7 @@ clixon_plugin_start(clicon_handle h,
|
||||||
cp = &_clixon_plugins[i];
|
cp = &_clixon_plugins[i];
|
||||||
if ((startfn = cp->cp_api.ca_start) == NULL)
|
if ((startfn = cp->cp_api.ca_start) == NULL)
|
||||||
continue;
|
continue;
|
||||||
// optind = 0;
|
if (startfn(h) < 0) {
|
||||||
if (startfn(h, argc, argv) < 0) {
|
|
||||||
clicon_debug(1, "plugin_start() failed");
|
clicon_debug(1, "plugin_start() failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue