Created xmldb plugin api

This commit is contained in:
Olof hagsand 2017-04-09 22:53:48 +02:00
parent 4169bd8d30
commit f6b3e95100
39 changed files with 492 additions and 504 deletions

View file

@ -95,8 +95,6 @@ config_terminate(clicon_handle h)
event_exit();
clicon_log_register_callback(NULL, NULL);
clicon_debug(1, "%s done", __FUNCTION__);
if (debug)
chunk_check(stderr, NULL);
return 0;
}
@ -207,7 +205,6 @@ done:
xml_free(xt);
if (fd != -1)
close(fd);
unchunk_group(__FUNCTION__);
return retval;
}

View file

@ -178,15 +178,13 @@ plugin_unload(clicon_handle h,
* @param[in] h Clicon handle
* @param[in] file The plugin (.so) to load
* @param[in] dlflags Arguments to dlopen(3)
* @param[in] label Chunk label
* @retval plugin Plugin struct
* @retval NULL Error
*/
static struct plugin *
plugin_load (clicon_handle h,
char *file,
int dlflags,
const char *label)
int dlflags)
{
char *error;
void *handle;
@ -215,7 +213,7 @@ plugin_load (clicon_handle h,
return NULL;
}
if ((new = chunk(sizeof(*new), label)) == NULL) {
if ((new = malloc(sizeof(*new))) == NULL) {
clicon_err(OE_UNIX, errno, "dhunk: %s", strerror(errno));
dlclose(handle);
return NULL;
@ -319,8 +317,8 @@ plugin_append(struct plugin *p)
{
struct plugin *new;
if ((new = rechunk(plugins, (nplugins+1) * sizeof (*p), NULL)) == NULL) {
clicon_err(OE_UNIX, errno, "chunk");
if ((new = realloc(plugins, (nplugins+1) * sizeof (*p))) == NULL) {
clicon_err(OE_UNIX, errno, "realloc");
return -1;
}
@ -348,11 +346,11 @@ config_plugin_load_dir(clicon_handle h,
int np = 0;
int ndp;
struct stat st;
char *filename;
struct dirent *dp;
char filename[MAXPATHLEN];
struct dirent *dp = NULL;
struct plugin *new;
struct plugin *p = NULL;
char *master;
char master[MAXPATHLEN];
char *master_plugin;
/* Format master plugin path */
@ -360,50 +358,39 @@ config_plugin_load_dir(clicon_handle h,
clicon_err(OE_PLUGIN, 0, "clicon_master_plugin option not set");
goto quit;
}
master = chunk_sprintf(__FUNCTION__, "%s.so", master_plugin);
if (master == NULL) {
clicon_err(OE_PLUGIN, errno, "chunk_sprintf master plugin");
goto quit;
}
snprintf(master, MAXPATHLEN-1, "%s.so", master_plugin);
/* Allocate plugin group object */
/* Get plugin objects names from plugin directory */
if((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG, __FUNCTION__))<0)
if((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG))<0)
goto quit;
/* reset num plugins */
np = 0;
/* Master plugin must be loaded first if it exists. */
filename = chunk_sprintf(__FUNCTION__, "%s/%s", dir, master);
if (filename == NULL) {
clicon_err(OE_UNIX, errno, "chunk");
goto quit;
}
snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, master);
if (stat(filename, &st) == 0) {
clicon_debug(1, "Loading master plugin '%.*s' ...",
(int)strlen(filename), filename);
new = plugin_load(h, filename, RTLD_NOW|RTLD_GLOBAL, __FUNCTION__);
new = plugin_load(h, filename, RTLD_NOW|RTLD_GLOBAL);
if (new == NULL)
goto quit;
if (plugin_append(new) < 0)
goto quit;
}
/* Now load the rest */
/* Now load the rest. Note plugins is the global variable */
for (i = 0; i < ndp; i++) {
if (strcmp(dp[i].d_name, master) == 0)
continue; /* Skip master now */
filename = chunk_sprintf(__FUNCTION__, "%s/%s", dir, dp[i].d_name);
snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name);
clicon_debug(1, "Loading plugin '%.*s' ...", (int)strlen(filename), filename);
if (filename == NULL) {
clicon_err(OE_UNIX, errno, "chunk");
goto quit;
}
new = plugin_load (h, filename, RTLD_NOW, __FUNCTION__);
new = plugin_load(h, filename, RTLD_NOW);
if (new == NULL)
goto quit;
/* Append to 'plugins' */
if (plugin_append(new) < 0)
goto quit;
}
@ -413,13 +400,19 @@ config_plugin_load_dir(clicon_handle h,
quit:
if (retval != 0) {
if (p) {
while (--np >= 0)
plugin_unload (h, &p[np]);
unchunk(p);
/* XXX p is always NULL */
if (plugins) {
while (--np >= 0){
if ((p = &plugins[np]) == NULL)
continue;
plugin_unload(h, p);
free(p);
}
free(plugins);
}
}
unchunk_group(__FUNCTION__);
if (dp)
free(dp);
return retval;
}
@ -464,8 +457,10 @@ plugin_finish(clicon_handle h)
p = &plugins[i];
plugin_unload(h, p);
}
if (plugins)
unchunk(plugins);
if (plugins){
free(plugins);
plugins = NULL;
}
nplugins = 0;
return 0;
}

View file

@ -94,17 +94,19 @@ cli_notification_register(clicon_handle h,
void *arg)
{
int retval = -1;
char *logname;
char *logname = NULL;
void *p;
int s;
clicon_hash_t *cdat = clicon_data(h);
size_t len;
int s_exist = -1;
if ((logname = chunk_sprintf(__FUNCTION__, "log_socket_%s", stream)) == NULL){
clicon_err(OE_PLUGIN, errno, "%s: chunk_sprintf", __FUNCTION__);
len = strlen("log_socket_") + strlen(stream) + 1;
if ((logname = malloc(len)) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
}
}
snprintf(logname, len, "log_socket_%s", stream);
if ((p = hash_value(cdat, logname, &len)) != NULL)
s_exist = *(int*)p;
@ -132,7 +134,8 @@ cli_notification_register(clicon_handle h,
}
retval = 0;
done:
unchunk_group(__FUNCTION__);
if (logname)
free(logname);
return retval;
}

View file

@ -112,21 +112,23 @@ cli_handle_init(void)
return h;
}
/*
* cli_handle_exit
* frees clicon handle
/*! Free clicon handle
*/
int
cli_handle_exit(clicon_handle h)
{
cligen_handle ch = cligen(h);
struct cli_handle *cl = handle(h);
if (cl->cl_stx)
free(cl->cl_stx);
clicon_handle_exit(h); /* frees h and options */
cligen_exit(ch);
return 0;
}
/*----------------------------------------------------------
* cli-specific handle access functions
*----------------------------------------------------------*/

View file

@ -174,7 +174,8 @@ main(int argc, char **argv)
int printgen = 0;
int logclisyntax = 0;
int help = 0;
char *treename;
char *treename = NULL;
int len;
int logdst = CLICON_LOG_STDERR;
char *restarg = NULL; /* what remains after options */
@ -343,8 +344,14 @@ main(int argc, char **argv)
if (yang2cli(h, yspec, &pt, clicon_cli_genmodel_type(h)) < 0)
goto done;
treename = chunk_sprintf(__FUNCTION__, "datamodel:%s", clicon_dbspec_name(h));
len = strlen("datamodel:") + strlen(clicon_dbspec_name(h)) + 1;
if ((treename = malloc(len)) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
}
snprintf(treename, len, "datamodel:%s", clicon_dbspec_name(h));
cli_tree_add(h, treename, pt);
if (printgen)
cligen_print(stdout, pt, 1);
}
@ -400,9 +407,10 @@ main(int argc, char **argv)
if (!once)
cli_interactive(h);
done:
if (treename)
free(treename);
if (restarg)
free(restarg);
unchunk_group(__FUNCTION__);
// 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\n", __PROGRAM__, getpid());

View file

@ -81,8 +81,7 @@
*
*/
/*
* Find syntax mode named 'mode'. Create if specified
/*! Find syntax mode named 'mode'. Create if specified
*/
static cli_syntaxmode_t *
syntax_mode_find(cli_syntax_t *stx, const char *mode, int create)
@ -101,8 +100,8 @@ syntax_mode_find(cli_syntax_t *stx, const char *mode, int create)
if (create == 0)
return NULL;
if ((m = chunk(sizeof(cli_syntaxmode_t), stx->stx_cnklbl)) == NULL) {
perror("chunk");
if ((m = malloc(sizeof(cli_syntaxmode_t))) == NULL) {
perror("malloc");
return NULL;
}
memset (m, 0, sizeof (*m));
@ -195,7 +194,7 @@ static int
syntax_unload(clicon_handle h)
{
struct cli_plugin *p;
cli_syntax_t *stx = cli_syntax(h);
cli_syntax_t *stx = cli_syntax(h);
if (stx == NULL)
return 0;
@ -205,14 +204,16 @@ syntax_unload(clicon_handle h)
plugin_unload(h, p->cp_handle);
clicon_debug(1, "DEBUG: Plugin '%s' unloaded.", p->cp_name);
DELQ(stx->stx_plugins, stx->stx_plugins, struct cli_plugin *);
if (stx->stx_plugins)
free(stx->stx_plugins);
stx->stx_nplugins--;
}
while (stx->stx_nmodes > 0) {
DELQ(stx->stx_modes, stx->stx_modes, cli_syntaxmode_t *);
if (stx->stx_modes)
free(stx->stx_modes);
stx->stx_nmodes--;
}
unchunk_group(stx->stx_cnklbl);
return 0;
}
@ -265,12 +266,14 @@ clixon_str2fn(char *name,
return NULL;
}
/*
* Load a dynamic plugin object and call it's init-function
/*! Load a dynamic plugin object and call it's init-function
* Note 'file' may be destructively modified
* @retval plugin-handle should be freed after use
*/
static plghndl_t
cli_plugin_load (clicon_handle h, char *file, int dlflags, const char *cnklbl)
cli_plugin_load(clicon_handle h,
char *file,
int dlflags)
{
char *error;
char *name;
@ -292,8 +295,8 @@ cli_plugin_load (clicon_handle h, char *file, int dlflags, const char *cnklbl)
}
}
if ((cp = chunk(sizeof (struct cli_plugin), cnklbl)) == NULL) {
perror("chunk");
if ((cp = malloc(sizeof (struct cli_plugin))) == NULL) {
perror("malloc");
goto quit;
}
memset (cp, 0, sizeof(*cp));
@ -323,7 +326,7 @@ cli_load_syntax(clicon_handle h, const char *filename, const char *clispec_dir)
parse_tree pt = {0,};
int retval = -1;
FILE *f;
char *filepath;
char filepath[MAXPATHLEN];
cvec *vr = NULL;
char *prompt = NULL;
char **vec = NULL;
@ -331,12 +334,7 @@ cli_load_syntax(clicon_handle h, const char *filename, const char *clispec_dir)
char *plgnam;
struct cli_plugin *p;
if ((filepath = chunk_sprintf(__FUNCTION__, "%s/%s",
clispec_dir,
filename)) == NULL){
clicon_err(OE_PLUGIN, errno, "chunk");
goto done;
}
snprintf(filepath, MAXPATHLEN-1, "%s/%s", clispec_dir, filename);
if ((vr = cvec_new(0)) == NULL){
clicon_err(OE_PLUGIN, errno, "cvec_new");
goto done;
@ -403,7 +401,6 @@ done:
cvec_free(vr);
if (vec)
free(vec);
unchunk_group(__FUNCTION__);
return retval;
}
@ -415,10 +412,10 @@ cli_plugin_load_dir(clicon_handle h, char *dir, cli_syntax_t *stx)
{
int i;
int ndp;
struct dirent *dp;
char *file;
struct dirent *dp = NULL;
char *master_plugin;
char *master;
char master[MAXPATHLEN];
char filename[MAXPATHLEN];
struct cli_plugin *cp;
struct stat st;
int retval = -1;
@ -429,24 +426,18 @@ cli_plugin_load_dir(clicon_handle h, char *dir, cli_syntax_t *stx)
clicon_err(OE_PLUGIN, 0, "clicon_master_plugin option not set");
goto quit;
}
if ((master = chunk_sprintf(__FUNCTION__, "%s.so", master_plugin)) == NULL){
clicon_err(OE_PLUGIN, errno, "chunk_sprintf master plugin");
goto quit;
}
snprintf(master, MAXPATHLEN-1, "%s.so", master_plugin);
/* Get plugin objects names from plugin directory */
ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG, __FUNCTION__);
ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG);
if (ndp < 0)
goto quit;
/* Load master plugin first */
file = chunk_sprintf(__FUNCTION__, "%s/%s", dir, master);
if (file == NULL) {
clicon_err(OE_UNIX, errno, "chunk_sprintf dir");
goto quit;
}
if (stat(file, &st) == 0) {
snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, master);
if (stat(filename, &st) == 0) {
clicon_debug(1, "DEBUG: Loading master plugin '%s'", master);
cp = cli_plugin_load(h, file, RTLD_NOW|RTLD_GLOBAL, stx->stx_cnklbl);
cp = cli_plugin_load(h, filename, RTLD_NOW|RTLD_GLOBAL);
if (cp == NULL)
goto quit;
/* Look up certain call-backs in master plugin */
@ -459,33 +450,25 @@ cli_plugin_load_dir(clicon_handle h, char *dir, cli_syntax_t *stx)
INSQ(cp, stx->stx_plugins);
stx->stx_nplugins++;
}
unchunk (file);
/* Load the rest */
for (i = 0; i < ndp; i++) {
if (strcmp (dp[i].d_name, master) == 0)
continue; /* Skip master now */
file = chunk_sprintf(__FUNCTION__, "%s/%s", dir, dp[i].d_name);
if (file == NULL) {
clicon_err(OE_UNIX, errno, "chunk_sprintf dir");
goto quit;
}
snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name);
clicon_debug(1, "DEBUG: Loading plugin '%s'", dp[i].d_name);
if ((cp = cli_plugin_load (h, file, RTLD_NOW, stx->stx_cnklbl)) == NULL)
if ((cp = cli_plugin_load (h, filename, RTLD_NOW)) == NULL)
goto quit;
INSQ(cp, stx->stx_plugins);
stx->stx_nplugins++;
unchunk (file);
}
if (dp)
unchunk(dp);
retval = 0;
quit:
unchunk_group(__FUNCTION__);
if (dp)
free(dp);
return retval;
}
@ -501,8 +484,7 @@ cli_syntax_load (clicon_handle h)
char *clispec_dir = NULL;
int ndp;
int i;
char *cnklbl = "__CLICON_CLI_SYNTAX_CNK_LABEL__";
struct dirent *dp;
struct dirent *dp = NULL;
cli_syntax_t *stx;
cli_syntaxmode_t *m;
@ -521,13 +503,11 @@ cli_syntax_load (clicon_handle h)
}
/* Allocate plugin group object */
if ((stx = chunk(sizeof(*stx), cnklbl)) == NULL) {
clicon_err(OE_UNIX, errno, "chunk");
if ((stx = malloc(sizeof(*stx))) == NULL) {
clicon_err(OE_UNIX, errno, "malloc");
goto quit;
}
memset (stx, 0, sizeof (*stx)); /* Zero out all */
/* populate name and chunk label */
strncpy (stx->stx_cnklbl, cnklbl, sizeof(stx->stx_cnklbl)-1);
cli_syntax_set(h, stx);
@ -541,7 +521,7 @@ cli_syntax_load (clicon_handle h)
goto quit;
/* load syntaxfiles */
if ((ndp = clicon_file_dirent(clispec_dir, &dp, "(.cli)$", S_IFREG, __FUNCTION__)) < 0)
if ((ndp = clicon_file_dirent(clispec_dir, &dp, "(.cli)$", S_IFREG)) < 0)
goto quit;
/* Load the rest */
for (i = 0; i < ndp; i++) {
@ -550,9 +530,6 @@ cli_syntax_load (clicon_handle h)
if (cli_load_syntax(h, dp[i].d_name, clispec_dir) < 0)
goto quit;
}
if (dp)
unchunk(dp);
/* Did we successfully load any syntax modes? */
if (stx->stx_nmodes <= 0) {
@ -577,10 +554,10 @@ cli_syntax_load (clicon_handle h)
quit:
if (retval != 0) {
syntax_unload(h);
unchunk_group(cnklbl);
cli_syntax_set(h, NULL);
}
unchunk_group(__FUNCTION__);
if (dp)
free(dp);
return retval;
}
@ -663,39 +640,36 @@ clicon_eval(clicon_handle h, char *cmd, cg_obj *match_obj, cvec *vr)
}
/*
* clicon_parse
* Given a command string, parse and evaluate the string according to
/*! Given a command string, parse and evaluate.
* Parse and evaluate the string according to
* the syntax parse tree of the syntax mode specified by *mode.
* If there is no match in the tree for the command, the parse hook
* will be called to see if another mode should be evaluated. If a
* match is found in another mode, the mode variable is updated to point at
* the new mode string.
*
* INPUT:
* cmd The command string
* match_obj Pointer to CLIgen match object
* mode A pointer to the mode string pointer
* OUTPUT:
* kr Keyword vector
* vr Variable vector
* RETURNS:
* -2 : on eof (shouldnt happen)
* -1 : In parse error
* >=0 : Number of matches
* @param[in] h Clicon handle
* @param[in] cmd The command string
* @param[in,out] mode A pointer to the mode string pointer
* @param[out] result -2 On eof (shouldnt happen)
* -1 On parse error
* >=0 Number of matches
*/
int
clicon_parse(clicon_handle h, char *cmd, char **mode, int *result)
clicon_parse(clicon_handle h,
char *cmd,
char **mode,
int *result)
{
char *m, *msav;
int res = -1;
int r;
cli_syntax_t *stx;
char *m, *msav;
int res = -1;
int r;
cli_syntax_t *stx = NULL;
cli_syntaxmode_t *smode;
char *treename;
parse_tree *pt; /* Orig */
cg_obj *match_obj;
cvec *vr = NULL;
cvec *cvv = NULL;
stx = cli_syntax(h);
m = *mode;
@ -719,11 +693,11 @@ clicon_parse(clicon_handle h, char *cmd, char **mode, int *result)
fprintf(stderr, "No such parse-tree registered: %s\n", treename);
goto done;;
}
if ((vr = cvec_new(0)) == NULL){
fprintf(stderr, "%s: cvec_new: %s\n", __FUNCTION__, strerror(errno));
if ((cvv = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
goto done;;
}
res = cliread_parse(cli_cligen(h), cmd, pt, &match_obj, vr);
res = cliread_parse(cli_cligen(h), cmd, pt, &match_obj, cvv);
if (res != CG_MATCH)
pt_expand_cleanup_1(pt);
if (msav){
@ -755,7 +729,7 @@ clicon_parse(clicon_handle h, char *cmd, char **mode, int *result)
*mode = m;
cli_set_syntax_mode(h, m);
}
if ((r = clicon_eval(h, cmd, match_obj, vr)) < 0)
if ((r = clicon_eval(h, cmd, match_obj, cvv)) < 0)
cli_handler_err(stdout);
pt_expand_cleanup_1(pt);
if (result)
@ -769,8 +743,8 @@ clicon_parse(clicon_handle h, char *cmd, char **mode, int *result)
}
}
done:
if (vr)
cvec_free(vr);
if (cvv)
cvec_free(cvv);
return res;
}
@ -891,9 +865,7 @@ cli_set_prompt(clicon_handle h, const char *name, const char *prompt)
return 0;
}
/*
* Format prompt
* XXX: HOST_NAME_MAX from sysconf()
/*! Format prompt
*/
static int
prompt_fmt (char *prompt, size_t plen, char *fmt, ...)
@ -902,65 +874,56 @@ prompt_fmt (char *prompt, size_t plen, char *fmt, ...)
char *s = fmt;
char hname[1024];
char tty[32];
char *new;
char *tmp;
int ret = -1;
cbuf *cb = NULL;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
/* Start with empty string */
if((new = chunk_sprintf(__FUNCTION__, "%s", ""))==NULL)
goto done;
cprintf(cb, "");
while(*s) {
if (*s == '%' && *++s) {
switch(*s) {
case 'H': /* Hostname */
if (gethostname (hname, sizeof (hname)) != 0)
strncpy(hname, "unknown", sizeof(hname)-1);
if((new = chunk_strncat(new, hname, 0, __FUNCTION__))==NULL)
goto done;
cprintf(cb, "%s", hname);
break;
case 'U': /* Username */
tmp = getenv("USER");
if((new = chunk_strncat(new, (tmp ? tmp : "nobody"), 0, __FUNCTION__))==NULL)
goto done;
cprintf(cb, "%s", tmp?tmp:"nobody");
break;
case 'T': /* TTY */
if(ttyname_r(fileno(stdin), tty, sizeof(tty)-1) < 0)
strcpy(tty, "notty");
if((new = chunk_strncat(new, tty, strlen(tty), __FUNCTION__))==NULL)
goto done;
cprintf(cb, "%s", tty);
break;
default:
if((new = chunk_strncat(new, "%", 1, __FUNCTION__))==NULL ||
(new = chunk_strncat(new, s, 1, __FUNCTION__)))
goto done;
cprintf(cb, "%%");
cprintf(cb, "%c", *s);
}
}
else {
if ((new = chunk_strncat(new, s, 1, __FUNCTION__))==NULL)
goto done;
}
else
cprintf(cb, "%c", *s);
s++;
}
done:
if (new)
fmt = new;
if (cb)
fmt = cbuf_get(cb);
va_start(ap, fmt);
ret = vsnprintf(prompt, plen, fmt, ap);
va_end(ap);
unchunk_group(__FUNCTION__);
if (cb)
cbuf_free(cb);
return ret;
}
/*
* Return a formatted prompt string
/*! Return a formatted prompt string
*/
char *
cli_prompt(char *fmt)
@ -1069,11 +1032,10 @@ cli_ptpop(clicon_handle h, char *mode, char *op)
}
/*
* clicon_valcb
/*! Find a cli plugin based on name and resolve a function pointer in it.
* Callback from clicon_dbvars_parse()
* Find a cli plugin based on name if given and
* use dlsym to resolve a function pointer in it.
* Find a cli plugin based on name if given and use dlsym to resolve a
* function pointer in it.
* Call the resolved function to get the cgv populated
*/
int

View file

@ -74,7 +74,6 @@ struct cli_plugin {
/* Plugin group object */
typedef struct {
char stx_cnklbl[128]; /* Plugin group name */
int stx_nplugins; /* Number of plugins */
struct cli_plugin *stx_plugins; /* List of plugins */
int stx_nmodes; /* Number of syntax modes */

View file

@ -213,15 +213,15 @@ expand_dir(char *dir,
mode_t flags,
int detail)
{
DIR *dirp;
DIR *dirp;
struct dirent *dp;
struct stat st;
char *str;
char *cmd;
int len;
int retval = -1;
struct stat st;
char *str;
char *cmd;
int len;
int retval = -1;
struct passwd *pw;
char filename[MAXPATHLEN];
char filename[MAXPATHLEN];
if ((dirp = opendir(dir)) == 0){
fprintf(stderr, "expand_dir: opendir(%s) %s\n",

View file

@ -105,7 +105,7 @@ plugin_unload(clicon_handle h, void *handle)
* Note 'file' may be destructively modified
*/
static plghndl_t
plugin_load (clicon_handle h, char *file, int dlflags, const char *cnklbl)
plugin_load (clicon_handle h, char *file, int dlflags)
{
char *error;
void *handle = NULL;
@ -141,9 +141,9 @@ netconf_plugin_load(clicon_handle h)
int retval = -1;
char *dir;
int ndp;
struct dirent *dp;
struct dirent *dp = NULL;
int i;
char *filename;
char filename[MAXPATHLEN];
plghndl_t *handle;
if ((dir = clicon_netconf_dir(h)) == NULL){
@ -152,30 +152,26 @@ netconf_plugin_load(clicon_handle h)
}
/* Get plugin objects names from plugin directory */
if((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG, __FUNCTION__))<0)
if((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG))<0)
goto quit;
/* Load all plugins */
for (i = 0; i < ndp; i++) {
filename = chunk_sprintf(__FUNCTION__, "%s/%s", dir, dp[i].d_name);
snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name);
clicon_debug(1, "DEBUG: Loading plugin '%.*s' ...",
(int)strlen(filename), filename);
if (filename == NULL) {
clicon_err(OE_UNIX, errno, "chunk");
if ((handle = plugin_load(h, filename, RTLD_NOW)) == NULL)
goto quit;
}
if ((handle = plugin_load (h, filename, RTLD_NOW, __FUNCTION__)) == NULL)
goto quit;
if ((plugins = rechunk(plugins, (nplugins+1) * sizeof (*plugins), NULL)) == NULL) {
clicon_err(OE_UNIX, errno, "chunk");
if ((plugins = realloc(plugins, (nplugins+1) * sizeof (*plugins))) == NULL) {
clicon_err(OE_UNIX, errno, "realloc");
goto quit;
}
plugins[nplugins++] = handle;
unchunk (filename);
}
retval = 0;
quit:
unchunk_group(__FUNCTION__);
if (dp)
free(dp);
return retval;
}
@ -194,8 +190,10 @@ netconf_plugin_unload(clicon_handle h)
}
for (i = 0; i < nplugins; i++)
plugin_unload(h, plugins[i]);
if (plugins)
unchunk(plugins);
if (plugins){
free(plugins);
plugins = NULL;
}
nplugins = 0;
return 0;
}

View file

@ -33,7 +33,6 @@
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -46,6 +45,7 @@
#include <fcgi_stdio.h>
#include <signal.h>
#include <dlfcn.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <curl/curl.h>
@ -175,7 +175,7 @@ str2cvec(char *string,
s++;
cv_name_set(cv, s);
cv_string_set(cv, valu);
free(valu);
curl_free(valu);
}
else{
if (strlen(s)){
@ -278,8 +278,7 @@ static credentials_t *p_credentials = NULL; /* Credentials callback */
static plghndl_t
plugin_load (clicon_handle h,
char *file,
int dlflags,
const char *cnklbl)
int dlflags)
{
char *error;
void *handle = NULL;
@ -319,40 +318,36 @@ restconf_plugin_load(clicon_handle h)
int retval = -1;
char *dir;
int ndp;
struct dirent *dp;
struct dirent *dp = NULL;
int i;
char *filename;
plghndl_t *handle;
char filename[MAXPATHLEN];
if ((dir = clicon_restconf_dir(h)) == NULL){
clicon_err(OE_PLUGIN, 0, "clicon_restconf_dir not defined");
goto quit;
}
/* Get plugin objects names from plugin directory */
if((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG, __FUNCTION__))<0)
if((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG))<0)
goto quit;
/* Load all plugins */
for (i = 0; i < ndp; i++) {
filename = chunk_sprintf(__FUNCTION__, "%s/%s", dir, dp[i].d_name);
snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dp[i].d_name);
clicon_debug(1, "DEBUG: Loading plugin '%.*s' ...",
(int)strlen(filename), filename);
if (filename == NULL) {
clicon_err(OE_UNIX, errno, "chunk");
if ((handle = plugin_load(h, filename, RTLD_NOW)) == NULL)
goto quit;
}
if ((handle = plugin_load (h, filename, RTLD_NOW, __FUNCTION__)) == NULL)
goto quit;
if ((plugins = rechunk(plugins, (nplugins+1) * sizeof (*plugins), NULL)) == NULL) {
clicon_err(OE_UNIX, errno, "chunk");
if ((plugins = realloc(plugins, (nplugins+1) * sizeof (*plugins))) == NULL) {
clicon_err(OE_UNIX, errno, "realloc");
goto quit;
}
plugins[nplugins++] = handle;
unchunk (filename);
}
retval = 0;
quit:
unchunk_group(__FUNCTION__);
if (dp)
free(dp);
return retval;
}
@ -387,8 +382,10 @@ restconf_plugin_unload(clicon_handle h)
for (i = 0; i < nplugins; i++)
plugin_unload(h, plugins[i]);
if (plugins)
unchunk(plugins);
if (plugins){
free(plugins);
plugins = NULL;
}
nplugins = 0;
return 0;
}

View file

@ -58,7 +58,6 @@
#include <signal.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <curl/curl.h>
#include <libgen.h>
/* cligen */

View file

@ -109,7 +109,6 @@ Mapping netconf error-tag -> status code
#include <signal.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <curl/curl.h>
/* cligen */
#include <cligen/cligen.h>