- Restructure plugin module using a "module struct" rather than global variables.

This include plugin module init and exit functions
  New type: clixon_plugin_t exposed via public API while struct clixon_plugin is private
- Makefile changes for static linkage using "LINKAGE=static"
- Moved nacm external init to later stage in backend_main
This commit is contained in:
Olof hagsand 2021-04-19 09:39:07 +02:00
parent 7ebb538ebf
commit b88722fa25
29 changed files with 557 additions and 345 deletions

View file

@ -46,7 +46,9 @@ endif
SH_SUFFIX = @SH_SUFFIX@
INSTALLFLAGS = @INSTALLFLAGS@
LDFLAGS = @LDFLAGS@
ifeq ($(LINKAGE),static)
LDFLAGS += -rdynamic -L.
endif
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
@ -63,7 +65,7 @@ CLIXON_MINOR = @CLIXON_VERSION_MINOR@
# Use this clixon lib for linking
ifeq ($(LINKAGE),static)
CLIXON_LIB = libclixon$(SH_SUFFIX)
CLIXON_LIB = libclixon.a
else
CLIXON_LIB = libclixon$(SH_SUFFIX).$(CLIXON_MAJOR).$(CLIXON_MINOR)
endif
@ -113,6 +115,7 @@ $(top_srcdir)/lib/src/$(CLIXON_LIB):
clean:
rm -f *.core $(APPL) $(APPOBJ) $(LIBOBJ) $(MYLIB) $(MYLIBSO) $(MYLIBLINK) test test.c
rm -f *.gcda *.gcno *.gcov # coverage
distclean: clean
rm -f Makefile *~ .depend
@ -130,8 +133,8 @@ install-lib: $(MYLIB)
install -m 0644 $(INSTALLFLAGS) $(MYLIB) $(DESTDIR)$(libdir)
install -d -m 0755 $(DESTDIR)$(libdir)/clixon/plugins/backend
ifeq ($(LINKAGE),dynamic)
ln -sf $(MYLIB) $(DESTDIR)$(libdir)/$(MYLIBSO) # -l:libclixon_config.so.2
ln -sf $(MYLIBSO) $(DESTDIR)$(libdir)/$(MYLIBLINK) # -l:libclixon_config.so
ln -sf $(MYLIB) $(DESTDIR)$(libdir)/$(MYLIBSO) # -l:libclixon_backend.so.2
ln -sf $(MYLIBSO) $(DESTDIR)$(libdir)/$(MYLIBLINK) # -l:libclixon_backend.so
endif
uninstall:
@ -147,7 +150,7 @@ install-include: clixon_backend.h clixon_backend_handle.h clixon_backend_transac
.SUFFIXES: .c .o
.c.o:
$(CC) $(INCLUDES) -D__PROGRAM__=\"$(APPL)\" $(CPPFLAGS) $(CFLAGS) -c $<
$(CC) $(INCLUDES) $(CPPFLAGS) -D__PROGRAM__=\"$(APPL)\" $(CFLAGS) -c $<
# Just link test programs
test.c :
@ -157,7 +160,11 @@ test: test.c $(LIBOBJ) $(MYLIB)
$(CC) $(INCLUDES) $(LDFLAGS) $< $(LIBOBJ) -L. $(MYLIB) $(LIBS) -o $@
$(APPL) : $(APPOBJ) $(MYLIB) $(LIBDEPS)
ifeq ($(LINKAGE),dynamic)
$(CC) $(LDFLAGS) $(APPOBJ) -L. $(MYLIB) $(LIBS) -o $@
else
$(CC) $(LDFLAGS) $(APPOBJ) -L. $(LIBOBJ) $(LIBS) -o $@
endif
$(MYLIBDYNAMIC): $(LIBOBJ) $(LIBDEPS)
ifeq ($(HOST_VENDOR),apple)

View file

@ -1547,7 +1547,7 @@ from_client_restart_plugin(clicon_handle h,
cxobj **vec = NULL;
size_t veclen;
int i;
clixon_plugin *cp;
clixon_plugin_t *cp;
int ret;
if (xpath_vec(xe, NULL, "plugin", &vec, &veclen) < 0)

View file

@ -878,7 +878,7 @@ from_client_validate(clicon_handle h,
*/
int
from_client_restart_one(clicon_handle h,
clixon_plugin *cp,
clixon_plugin_t *cp,
cbuf *cbret)
{
int retval = -1;
@ -895,7 +895,7 @@ from_client_restart_one(clicon_handle h,
if (xmldb_db_reset(h, db) < 0)
goto done;
/* Application may define extra xml in its reset function*/
if ((resetfn = cp->cp_api.ca_reset) != NULL){
if ((resetfn = clixon_plugin_api_get(cp)->ca_reset) != NULL){
if ((retval = resetfn(h, db)) < 0) {
clicon_debug(1, "plugin_start() failed");
goto done;

View file

@ -50,6 +50,6 @@ int from_client_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void
int from_client_discard_changes(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_cancel_commit(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_validate(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg, void *regarg);
int from_client_restart_one(clicon_handle h, clixon_plugin *cp, cbuf *cbret);
int from_client_restart_one(clicon_handle h, clixon_plugin_t *cp, cbuf *cbret);
#endif /* _BACKEND_COMMIT_H_ */

View file

@ -125,11 +125,8 @@ backend_terminate(clicon_handle h)
if ((x = clicon_conf_xml(h)) != NULL)
xml_free(x);
stream_publish_exit();
clixon_plugin_exit_all(h);
/* Delete all backend plugin RPC callbacks */
rpc_callback_delete_all(h);
/* Delete all backend plugin upgrade callbacks */
upgrade_callback_delete_all(h);
/* Delete all plugins, RPC callbacks, and upgrade callbacks */
clixon_plugin_module_exit(h);
/* Delete all process-control entries */
clixon_process_delete_all(h);
@ -517,7 +514,6 @@ main(int argc,
/* Initiate CLICON handle */
if ((h = backend_handle_init()) == NULL)
return -1;
foreground = 0;
once = 0;
zap = 0;
@ -582,12 +578,10 @@ main(int argc,
clicon_option_str_set(h, "CLICON_WWWUSER", WWWUSER);
clicon_option_str_set(h, "CLICON_WWWDIR", WWWDIR);
/* External NACM file? */
nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE");
if (nacm_mode && strcmp(nacm_mode, "external") == 0)
if (nacm_load_external(h) < 0)
goto done;
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Now run through the operational args */
opterr = 1;
optind = 1;
@ -780,6 +774,14 @@ main(int argc,
if (netconf_module_features(h) < 0)
goto done;
/* External NACM file?
* Note, loads yang -> extensions -> plugins
*/
nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE");
if (nacm_mode && strcmp(nacm_mode, "external") == 0)
if (nacm_load_external(h) < 0)
goto done;
/* Create top-level yang spec and store as option */
if ((yspec = yspec_new()) == NULL)
goto done;

View file

@ -74,18 +74,18 @@
* @retval -1 Error
*/
int
clixon_plugin_reset_one(clixon_plugin *cp,
clixon_plugin_reset_one(clixon_plugin_t *cp,
clicon_handle h,
char *db)
{
int retval = -1;
plgreset_t *fn; /* callback */
if ((fn = cp->cp_api.ca_reset) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_reset) != NULL){
if (fn(h, db) < 0) {
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Reset callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -106,7 +106,7 @@ clixon_plugin_reset_all(clicon_handle h,
char *db)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
@ -125,18 +125,18 @@ clixon_plugin_reset_all(clicon_handle h,
* @retval -1 Error
*/
static int
clixon_plugin_pre_daemon_one(clixon_plugin *cp,
clixon_plugin_pre_daemon_one(clixon_plugin_t *cp,
clicon_handle h)
{
int retval = -1;
plgdaemon_t *fn; /* Daemonize plugin callback function */
if ((fn = cp->cp_api.ca_pre_daemon) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_pre_daemon) != NULL){
if (fn(h) < 0) {
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Pre-daemon callback in plugin:\
%s returned -1 but did not make a clicon_err call",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -158,7 +158,7 @@ int
clixon_plugin_pre_daemon_all(clicon_handle h)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
@ -177,17 +177,17 @@ clixon_plugin_pre_daemon_all(clicon_handle h)
* @retval -1 Error
*/
static int
clixon_plugin_daemon_one(clixon_plugin *cp,
clixon_plugin_daemon_one(clixon_plugin_t *cp,
clicon_handle h)
{
int retval = -1;
plgdaemon_t *fn; /* Daemonize plugin callback function */
if ((fn = cp->cp_api.ca_daemon) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_daemon) != NULL){
if (fn(h) < 0) {
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: Daemon callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -211,7 +211,7 @@ int
clixon_plugin_daemon_all(clicon_handle h)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
/* Loop through all plugins, call callbacks in each */
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
@ -244,7 +244,7 @@ clixon_plugin_daemon_all(clicon_handle h)
* @retval 1 OK if callback found (and called) xret is set
*/
static int
clixon_plugin_statedata_one(clixon_plugin *cp,
clixon_plugin_statedata_one(clixon_plugin_t *cp,
clicon_handle h,
cvec *nsc,
char *xpath,
@ -254,13 +254,13 @@ clixon_plugin_statedata_one(clixon_plugin *cp,
plgstatedata_t *fn; /* Plugin statedata fn */
cxobj *x = NULL;
if ((fn = cp->cp_api.ca_statedata) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_statedata) != NULL){
if ((x = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done;
if (fn(h, nsc, xpath, x) < 0){
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto fail; /* Dont quit here on user callbacks */
}
@ -298,7 +298,7 @@ clixon_plugin_statedata_all(clicon_handle h,
int retval = -1;
int ret;
cxobj *x = NULL;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
cbuf *cberr = NULL;
cxobj *xerr = NULL;
@ -313,7 +313,7 @@ clixon_plugin_statedata_all(clicon_handle h,
}
/* error reason should be in clicon_err_reason */
cprintf(cberr, "Internal error, state callback in plugin %s returned invalid XML: %s",
cp->cp_name, clicon_err_reason);
clixon_plugin_name_get(cp), clicon_err_reason);
if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0)
goto done;
xml_free(*xret);
@ -338,7 +338,7 @@ clixon_plugin_statedata_all(clicon_handle h,
if (ret == 0){
if (clixon_netconf_internal_error(xerr,
". Internal error, state callback returned invalid XML from plugin: ",
cp->cp_name) < 0)
clixon_plugin_name_get(cp)) < 0)
goto done;
xml_free(*xret);
*xret = xerr;
@ -432,18 +432,18 @@ transaction_free(transaction_data_t *td)
* @retval -1 Error
*/
int
plugin_transaction_begin_one(clixon_plugin *cp,
plugin_transaction_begin_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
if ((fn = cp->cp_api.ca_trans_begin) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_trans_begin) != NULL){
if (fn(h, (transaction_data)td) < 0){
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -465,7 +465,7 @@ plugin_transaction_begin_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_begin_one(cp, h, td) < 0)
@ -484,18 +484,18 @@ plugin_transaction_begin_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_validate_one(clixon_plugin *cp,
plugin_transaction_validate_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
if ((fn = cp->cp_api.ca_trans_validate) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_trans_validate) != NULL){
if (fn(h, (transaction_data)td) < 0){
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -515,7 +515,7 @@ plugin_transaction_validate_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_validate_one(cp, h, td) < 0)
@ -535,18 +535,18 @@ plugin_transaction_validate_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_complete_one(clixon_plugin *cp,
plugin_transaction_complete_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
if ((fn = cp->cp_api.ca_trans_complete) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_trans_complete) != NULL){
if (fn(h, (transaction_data)td) < 0){
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -568,7 +568,7 @@ plugin_transaction_complete_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_complete_one(cp, h, td) < 0)
@ -594,15 +594,15 @@ plugin_transaction_revert_all(clicon_handle h,
int nr)
{
int retval = 0;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
trans_cb_t *fn;
while ((cp = clixon_plugin_each_revert(h, cp, nr)) != NULL) {
if ((fn = cp->cp_api.ca_trans_revert) == NULL)
if ((fn = clixon_plugin_api_get(cp)->ca_trans_revert) == NULL)
continue;
if ((retval = fn(h, (transaction_data)td)) < 0){
clicon_log(LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
break;
}
}
@ -618,18 +618,18 @@ plugin_transaction_revert_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_commit_one(clixon_plugin *cp,
plugin_transaction_commit_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
if ((fn = cp->cp_api.ca_trans_commit) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit) != NULL){
if (fn(h, (transaction_data)td) < 0){
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -652,7 +652,7 @@ plugin_transaction_commit_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
int i=0;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
@ -677,18 +677,18 @@ plugin_transaction_commit_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_commit_done_one(clixon_plugin *cp,
plugin_transaction_commit_done_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
if ((fn = cp->cp_api.ca_trans_commit_done) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit_done) != NULL){
if (fn(h, (transaction_data)td) < 0){
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -709,7 +709,7 @@ plugin_transaction_commit_done_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_commit_done_one(cp, h, td) < 0)
@ -728,18 +728,18 @@ plugin_transaction_commit_done_all(clicon_handle h,
* @retval -1 Error
*/
int
plugin_transaction_end_one(clixon_plugin *cp,
plugin_transaction_end_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
if ((fn = cp->cp_api.ca_trans_end) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_trans_end) != NULL){
if (fn(h, (transaction_data)td) < 0){
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -759,7 +759,7 @@ plugin_transaction_end_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_end_one(cp, h, td) < 0)
@ -771,18 +771,18 @@ plugin_transaction_end_all(clicon_handle h,
}
int
plugin_transaction_abort_one(clixon_plugin *cp,
plugin_transaction_abort_one(clixon_plugin_t *cp,
clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
trans_cb_t *fn;
if ((fn = cp->cp_api.ca_trans_abort) != NULL){
if ((fn = clixon_plugin_api_get(cp)->ca_trans_abort) != NULL){
if (fn(h, (transaction_data)td) < 0){
if (!clicon_errno) /* sanity: log if clicon_err() is not called ! */
clicon_log(LOG_NOTICE, "%s: Plugin '%s' callback does not make clicon_err call on error",
__FUNCTION__, cp->cp_name);
__FUNCTION__, clixon_plugin_name_get(cp));
goto done;
}
}
@ -802,7 +802,7 @@ plugin_transaction_abort_all(clicon_handle h,
transaction_data_t *td)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (plugin_transaction_abort_one(cp, h, td) < 0)

View file

@ -69,7 +69,7 @@ typedef struct {
/*
* Prototypes
*/
int clixon_plugin_reset_one(clixon_plugin *cp, clicon_handle h, char *db);
int clixon_plugin_reset_one(clixon_plugin_t *cp, clicon_handle h, char *db);
int clixon_plugin_reset_all(clicon_handle h, char *db);
int clixon_plugin_pre_daemon_all(clicon_handle h);
@ -80,25 +80,25 @@ int clixon_plugin_statedata_all(clicon_handle h, yang_stmt *yspec, cvec *nsc, ch
transaction_data_t * transaction_new(void);
int transaction_free(transaction_data_t *);
int plugin_transaction_begin_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_begin_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_begin_all(clicon_handle h, transaction_data_t *td);
int plugin_transaction_validate_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_validate_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_validate_all(clicon_handle h, transaction_data_t *td);
int plugin_transaction_complete_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_complete_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_complete_all(clicon_handle h, transaction_data_t *td);
int plugin_transaction_commit_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_commit_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_commit_all(clicon_handle h, transaction_data_t *td);
int plugin_transaction_commit_done_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_commit_done_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_commit_done_all(clicon_handle h, transaction_data_t *td);
int plugin_transaction_end_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_end_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_end_all(clicon_handle h, transaction_data_t *td);
int plugin_transaction_abort_one(clixon_plugin *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_abort_one(clixon_plugin_t *cp, clicon_handle h, transaction_data_t *td);
int plugin_transaction_abort_all(clicon_handle h, transaction_data_t *td);
#endif /* _BACKEND_PLUGIN_H_ */

View file

@ -300,13 +300,13 @@ backend_plugin_restconf_register(clicon_handle h,
yang_stmt *yspec)
{
int retval = -1;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
if (clixon_pseudo_plugin(h, "restconf pseudo plugin", &cp) < 0)
goto done;
cp->cp_api.ca_trans_validate = restconf_pseudo_process_validate;
cp->cp_api.ca_trans_commit = restconf_pseudo_process_commit;
clixon_plugin_api_get(cp)->ca_trans_validate = restconf_pseudo_process_validate;
clixon_plugin_api_get(cp)->ca_trans_commit = restconf_pseudo_process_commit;
/* Register generic process-control of restconf daemon, ie start/stop restconf */
if (restconf_pseudo_process_control(h) < 0)

View file

@ -214,7 +214,7 @@ transaction_print(FILE *f,
xn = td->td_avec[i];
xml_print(f, xn);
}
fprintf(stderr, "Changed\n=========\n");
fprintf(f, "Changed\n=========\n");
for (i=0; i<td->td_clen; i++){
xn = td->td_scvec[i];
xml_print(f, xn);

View file

@ -41,7 +41,7 @@ CFLAGS = @CFLAGS@
LINKAGE = @LINKAGE@
CPPFLAGS = @CPPFLAGS@
ifeq ($(LINKAGE),dynamic)
CPPFLAGS += -fPIC
CPPFLAGS += -fPIC
endif
SH_SUFFIX = @SH_SUFFIX@
INSTALLFLAGS = @INSTALLFLAGS@
@ -66,10 +66,10 @@ CLIXON_MAJOR = @CLIXON_VERSION_MAJOR@
CLIXON_MINOR = @CLIXON_VERSION_MINOR@
# Use this clixon lib for linking
ifeq ($(LINKAGE),dynamic)
CLIXON_LIB = libclixon$(SH_SUFFIX).$(CLIXON_MAJOR).$(CLIXON_MINOR)
else
ifeq ($(LINKAGE),static)
CLIXON_LIB = libclixon.a
else
CLIXON_LIB = libclixon$(SH_SUFFIX).$(CLIXON_MAJOR).$(CLIXON_MINOR)
endif
# For dependency. A little strange that we rely on it being built in the src dir
@ -78,7 +78,6 @@ LIBDEPS = $(top_srcdir)/lib/src/$(CLIXON_LIB)
LIBS = -L$(top_srcdir)/lib/src $(top_srcdir)/lib/src/$(CLIXON_LIB) @LIBS@
INCLUDES = -I. -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@
# Name of application
@ -118,6 +117,7 @@ $(top_srcdir)/lib/src/$(CLIXON_LIB):
clean:
rm -f $(LIBOBJ) $(APPOBJ) *.core $(APPL) $(MYLIB) $(MYLIBSO) $(MYLIBLINK) test test.c
rm -f *.gcda *.gcno *.gcov # coverage
distclean: clean
rm -f Makefile *~ .depend

View file

@ -178,7 +178,11 @@ cli_terminate(clicon_handle h)
xml_free(x);
clicon_data_cvec_del(h, "cli-edit-cvv");;
xpath_optimize_exit();
cli_plugin_finish(h);
/* Delete all plugins, and RPC callbacks */
clixon_plugin_module_exit(h);
/* Delete CLI syntax et al */
cli_plugin_finish(h);
cli_history_save(h);
cli_handle_exit(h);
clixon_err_exit();
@ -615,6 +619,10 @@ main(int argc,
*/
cv_exclude_keys(clicon_cli_varonly(h));
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Load cli plugins before yangs are loaded (eg extension callbacks) */
if ((dir = clicon_cli_dir(h)) != NULL &&
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
@ -625,7 +633,6 @@ main(int argc,
*/
if (netconf_module_features(h) < 0)
goto done;
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
xml_nsctx_namespace_netconf_default(h);

View file

@ -271,7 +271,7 @@ cli_load_syntax_file(clicon_handle h,
char **vec = NULL;
int i, nvec;
char *plgnam;
clixon_plugin *cp;
clixon_plugin_t *cp;
if ((pt = pt_new()) == NULL){
clicon_err(OE_UNIX, errno, "pt_new");
@ -313,7 +313,7 @@ cli_load_syntax_file(clicon_handle h,
if (plgnam != NULL) { /* Find plugin for callback resolving */
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
handle = cp->cp_handle;
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,
@ -393,7 +393,7 @@ cli_syntax_load(clicon_handle h)
cli_syntaxmode_t *m;
cligen_susp_cb_t *fns = NULL;
cligen_interrupt_cb_t *fni = NULL;
clixon_plugin *cp;
clixon_plugin_t *cp;
parse_tree *ptall = NULL; /* Universal CLIgen parse tree all modes */
/* Syntax already loaded. XXX should we re-load?? */
@ -457,10 +457,10 @@ cli_syntax_load(clicon_handle h)
/* Set susp and interrupt callbacks into CLIgen */
cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if (fns==NULL && (fns = cp->cp_api.ca_suspend) != 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 = cp->cp_api.ca_interrupt) != NULL)
if (fni==NULL && (fni = clixon_plugin_api_get(cp)->ca_interrupt) != NULL)
if (cli_interrupt_hook(h, fni) < 0)
goto done;
}
@ -469,7 +469,6 @@ cli_syntax_load(clicon_handle h)
retval = 0;
done:
if (retval != 0) {
clixon_plugin_exit_all(h);
cli_syntax_unload(h);
cli_syntax_set(h, NULL);
}
@ -485,8 +484,6 @@ done:
int
cli_plugin_finish(clicon_handle h)
{
/* Remove all CLI plugins */
clixon_plugin_exit_all(h);
/* Remove all cligen syntax modes */
cli_syntax_unload(h);
cli_syntax_set(h, NULL);
@ -744,7 +741,7 @@ clicon_cliread(clicon_handle h,
cli_syntaxmode_t *mode;
cli_syntax_t *stx;
cli_prompthook_t *fn;
clixon_plugin *cp;
clixon_plugin_t *cp;
char *promptstr;
stx = cli_syntax(h);
@ -752,7 +749,7 @@ clicon_cliread(clicon_handle h,
/* Get prompt from plugin callback? */
cp = NULL;
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if ((fn = cp->cp_api.ca_prompt) == NULL)
if ((fn = clixon_plugin_api_get(cp)->ca_prompt) == NULL)
continue;
pfmt = fn(h, mode->csm_name);
break;

View file

@ -111,6 +111,7 @@ $(top_srcdir)/lib/src/$(CLIXON_LIB):
clean:
rm -f $(APPL) $(APPOBJ) $(LIBOBJ) *.core $(MYLIB) $(MYLIBSO) $(MYLIBLINK)
rm -f *.gcda *.gcno *.gcov # coverage
distclean: clean
rm -f Makefile *~ .depend

View file

@ -584,8 +584,9 @@ netconf_terminate(clicon_handle h)
cvec *nsctx;
cxobj *x;
clixon_plugin_exit_all(h);
rpc_callback_delete_all(h);
/* Delete all plugins, and RPC callbacks */
clixon_plugin_module_exit(h);
clicon_rpc_close_session(h);
if ((yspec = clicon_dbspec_yang(h)) != NULL)
ys_free(yspec);
@ -796,6 +797,10 @@ main(int argc,
if (netconf_module_features(h) < 0)
goto done;
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Create top-level yang spec and store as option */
if ((yspec = yspec_new()) == NULL)
goto done;

View file

@ -78,10 +78,9 @@ LIBDEPS = $(top_srcdir)/lib/src/$(CLIXON_LIB)
LIBS = -L$(top_srcdir)/lib/src $(top_srcdir)/lib/src/$(CLIXON_LIB) @LIBS@
CPPFLAGS = @CPPFLAGS@
ifeq ($(LINKAGE),dynamic)
CPPFLAGS = @CPPFLAGS@ -fPIC
else
CPPFLAGS = @CPPFLAGS@
CPPFLAGS += -fPIC
endif
INCLUDES = -I. -I$(top_srcdir)/lib/src -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@
@ -139,6 +138,7 @@ $(top_srcdir)/lib/src/$(CLIXON_LIB):
clean:
rm -f $(LIBOBJ) *.core $(APPL) $(APPOBJ) *.o $(MYLIB) $(MYLIBSO) $(MYLIBLINK) # extra .o to clean residue if with_restconf changes
rm -f *.gcda *.gcno *.gcov # coverage
distclean: clean
rm -f Makefile *~ .depend
@ -201,4 +201,3 @@ depend:
$(CC) $(DEPENDFLAGS) @DEFS@ $(INCLUDES) $(CFLAGS) -MM $(APPFCGI) $(APPSRC) > .depend
#include .depend

View file

@ -247,8 +247,9 @@ restconf_terminate(clicon_handle h)
clicon_debug(1, "%s", __FUNCTION__);
if ((fs = clicon_socket_get(h)) != -1)
close(fs);
clixon_plugin_exit_all(h);
rpc_callback_delete_all(h);
/* Delete all plugins, and RPC callbacks */
clixon_plugin_module_exit(h);
clicon_rpc_close_session(h);
if ((yspec = clicon_dbspec_yang(h)) != NULL)
ys_free(yspec);

View file

@ -211,7 +211,7 @@ main(int argc,
char *stream_path;
int finish = 0;
char *str;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
uint32_t id = 0;
cvec *nsctx_global = NULL; /* Global namespace context */
size_t cligen_buflen;
@ -362,6 +362,10 @@ main(int argc,
/* Treat unknown XML as anydata */
if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1)
xml_bind_yang_unknown_anydata(1);
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Load restconf plugins before yangs are loaded (eg extension callbacks) */
if ((dir = clicon_restconf_dir(h)) != NULL)
@ -372,7 +376,7 @@ main(int argc,
*/
if (clixon_pseudo_plugin(h, "pseudo restconf", &cp) < 0)
goto done;
cp->cp_api.ca_extension = restconf_main_extension_cb;
clixon_plugin_api_get(cp)->ca_extension = restconf_main_extension_cb;
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
@ -427,6 +431,9 @@ main(int argc,
if (dbg)
clicon_option_dump(h, dbg);
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Call start function in all plugins before we go interactive */
if (clixon_plugin_start_all(h) < 0)
goto done;

View file

@ -1544,7 +1544,7 @@ restconf_clixon_init(clicon_handle h,
size_t cligen_buflen;
size_t cligen_bufthreshold;
yang_stmt *yspec = NULL;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
char *str;
cvec *nsctx_global = NULL; /* Global namespace context */
cxobj *xrestconf;
@ -1581,7 +1581,7 @@ restconf_clixon_init(clicon_handle h,
*/
if (clixon_pseudo_plugin(h, "pseudo restconf", &cp) < 0)
goto done;
cp->cp_api.ca_extension = restconf_main_extension_cb;
clixon_plugin_api_get(cp)->ca_extension = restconf_main_extension_cb;
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
@ -1614,7 +1614,6 @@ restconf_clixon_init(clicon_handle h,
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)
goto done;
/* Add system modules */
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040") &&
yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec)< 0)
@ -1847,6 +1846,9 @@ main(int argc,
if (dbg)
clicon_option_dump(h, dbg);
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Call start function in all plugins before we go interactive */
if (clixon_plugin_start_all(h) < 0)
goto done;