* The following backward compatible options to configure have been obsoleted. If you havent already migrated this code you must do this now.

* Backend startup modes prior to 3.3.3. As enabled with `configure --with-startup-compat`. Configure option CLICON_USE_STARTUP_CONFIG is also obsoleted.
  * Configuration files (non-XML) prior to 3.3.3. As enabled with `configure --with-config-compat`. The template clicon.conf.cpp files are also removed.
  * Clixon XML C-lib prior to 3.4.0. As enabled with `configure --with-xml-compat`
This commit is contained in:
Olof hagsand 2018-01-01 14:48:57 +01:00
parent 75848a8e30
commit 3758c8dab4
11 changed files with 11 additions and 529 deletions

View file

@ -4,6 +4,12 @@
### Major changes: ### Major changes:
### Minor changes: ### Minor changes:
* The following backward compatible options to configure have been obsoleted. If you havent already migrated this code you must do this now.
* Backend startup modes prior to 3.3.3. As enabled with `configure --with-startup-compat`. Configure option CLICON_USE_STARTUP_CONFIG is also obsoleted.
* Configuration files (non-XML) prior to 3.3.3. As enabled with `configure --with-config-compat`. The template clicon.conf.cpp files are also removed.
* Clixon XML C-lib prior to 3.4.0. As enabled with `configure --with-xml-compat`
### Corrected Bugs ### Corrected Bugs
### Known issues ### Known issues

View file

@ -56,7 +56,7 @@ SUBDIRS = lib apps include etc datastore yang
.PHONY: doc all clean depend $(SUBDIRS) install loc TAGS .config.status docker .PHONY: doc all clean depend $(SUBDIRS) install loc TAGS .config.status docker
all: $(SUBDIRS) clixon.conf.cpp clixon.mk all: $(SUBDIRS) clixon.mk
$(SUBDIRS): $(SUBDIRS):
(cd $@ && $(MAKE) $(MFLAGS) all) (cd $@ && $(MAKE) $(MFLAGS) all)
@ -65,16 +65,11 @@ depend:
for i in $(SUBDIRS) doc example docker; \ for i in $(SUBDIRS) doc example docker; \
do (cd $$i && $(MAKE) $(MFLAGS) depend); done do (cd $$i && $(MAKE) $(MFLAGS) depend); done
# template clixon.conf file
clixon.conf.cpp: clixon.conf.cpp.cpp
$(CPP) -P -x assembler-with-cpp -Dprefix=$(prefix) -Dlocalstatedir=$(localstatedir) -Dsysconfdir=$(sysconfdir) -Ddatadir=$(datadir) -Dlibdir=$(libdir) $< > $@
clixon.mk: clixon.mk.cpp clixon.mk: clixon.mk.cpp
$(CPP) -P -traditional-cpp -x assembler-with-cpp -Dprefix=$(prefix) -Dlocalstatedir=$(localstatedir) -Dsysconfdir=$(sysconfdir) -Ddatadir=$(datadir) -Dlibdir=$(libdir) $< > $@ $(CPP) -P -traditional-cpp -x assembler-with-cpp -Dprefix=$(prefix) -Dlocalstatedir=$(localstatedir) -Dsysconfdir=$(sysconfdir) -Ddatadir=$(datadir) -Dlibdir=$(libdir) $< > $@
install: clixon.conf.cpp clixon.mk install: clixon.mk
install -d -m 755 $(DESTDIR)$(datadir)/clixon install -d -m 755 $(DESTDIR)$(datadir)/clixon
install -m 755 clixon.conf.cpp $(DESTDIR)$(datadir)/clixon
install -m 755 clixon.mk $(DESTDIR)$(datadir)/clixon install -m 755 clixon.mk $(DESTDIR)$(datadir)/clixon
for i in $(SUBDIRS) doc; \ for i in $(SUBDIRS) doc; \
do (cd $$i; $(MAKE) $(MFLAGS) $@)||exit 1; done; \ do (cd $$i; $(MAKE) $(MFLAGS) $@)||exit 1; done; \
@ -88,7 +83,6 @@ install-include:
uninstall: uninstall:
for i in $(SUBDIRS) doc example docker; \ for i in $(SUBDIRS) doc example docker; \
do (cd $$i && $(MAKE) $(MFLAGS) $@)||exit 1; done; do (cd $$i && $(MAKE) $(MFLAGS) $@)||exit 1; done;
rm -f $(DESTDIR)$(datadir)/clixon/clixon.conf.cpp
rm -f $(DESTDIR)$(datadir)/clixon/clixon.mk rm -f $(DESTDIR)$(datadir)/clixon/clixon.mk
doc: doc:
@ -106,8 +100,7 @@ clean:
distclean: distclean:
rm -f Makefile TAGS config.status config.log *~ .depend rm -f Makefile TAGS config.status config.log *~ .depend
rm -rf autom4te.cache rm -rf autom4te.cache clixon.mk build-root/rpmbuild
rm -rf clixon.conf.cpp clixon.mk build-root/rpmbuild
rm -f build-root/*.tar.xz build-root/*.rpm extras/rpm/Makefile rm -f build-root/*.tar.xz build-root/*.rpm extras/rpm/Makefile
for i in $(SUBDIRS) doc example docker; \ for i in $(SUBDIRS) doc example docker; \
do (cd $$i && $(MAKE) $(MFLAGS) $@); done do (cd $$i && $(MAKE) $(MFLAGS) $@); done

View file

@ -73,11 +73,7 @@
#include "backend_handle.h" #include "backend_handle.h"
/* Command line options to be passed to getopt(3) */ /* Command line options to be passed to getopt(3) */
#ifdef BACKEND_STARTUP_COMPAT
#define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:IRCrg:y:x:" /* substitute s: for IRCc:r */
#else
#define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:g:y:x:" /* substitute s: for IRCc:r */ #define BACKEND_OPTS "hD:f:d:b:Fzu:P:1s:c:g:y:x:" /* substitute s: for IRCc:r */
#endif
/*! Terminate. Cannot use h after this */ /*! Terminate. Cannot use h after this */
static int static int
@ -142,12 +138,6 @@ usage(char *argv0, clicon_handle h)
" -P <file>\tPid filename (default: %s)\n" " -P <file>\tPid filename (default: %s)\n"
" -s <mode>\tSpecify backend startup mode: none|startup|running|init (replaces -IRCr\n" " -s <mode>\tSpecify backend startup mode: none|startup|running|init (replaces -IRCr\n"
" -c <file>\tLoad extra xml configuration, but don't commit.\n" " -c <file>\tLoad extra xml configuration, but don't commit.\n"
#ifdef BACKEND_STARTUP_COMPAT
" -I\t\tInitialize running state database\n"
" -R\t\tCall plugin_reset() in plugins to reset system state in running db (use with -I)\n"
" -C\t\tCall plugin_reset() in plugins to reset system state in candidate db (use with -I)\n"
" -r\t\tReload running database\n"
#endif /* BACKEND_STARTUP_COMPAT */
" -g <group>\tClient membership required to this group (default: %s)\n" " -g <group>\tClient membership required to this group (default: %s)\n"
" -y <file>\tOverride yang spec file (dont include .yang suffix)\n" " -y <file>\tOverride yang spec file (dont include .yang suffix)\n"
" -x <plugin>\tXMLDB plugin\n", " -x <plugin>\tXMLDB plugin\n",
@ -270,161 +260,6 @@ plugin_start_useroptions(clicon_handle h,
return 0; return 0;
} }
#ifdef BACKEND_STARTUP_COMPAT
/*! Initialize running-config from file application configuration
*
* @param[in] h clicon handle
* @param[in] extraxml_file clicon application configuration file
* @param[in] running_db Name of running db
* @retval 0 OK
* @retval -1 Error. clicon_err set
*/
static int
rundb_main(clicon_handle h,
char *extraxml_file)
{
int retval = -1;
int fd = -1;
cxobj *xt = NULL;
cxobj *xn;
if (xmldb_create(h, "tmp") < 0)
goto done;
if (xmldb_copy(h, "running", "tmp") < 0)
goto done;
if ((fd = open(extraxml_file, O_RDONLY)) < 0){
clicon_err(OE_UNIX, errno, "open(%s)", extraxml_file);
goto done;
}
if (xml_parse_file(fd, &xt, "</clicon>") < 0)
goto done;
if ((xn = xml_child_i(xt, 0)) != NULL)
if (xmldb_put(h, "tmp", OP_MERGE, xn) < 0)
goto done;
if (candidate_commit(h, "tmp") < 0)
goto done;
if (xmldb_delete(h, "tmp") < 0)
goto done;
retval = 0;
done:
if (xt)
xml_free(xt);
if (fd != -1)
close(fd);
return retval;
}
static int
candb_reset(clicon_handle h)
{
int retval = -1;
if (xmldb_copy(h, "running", "tmp") < 0)
goto done;
/* Request plugins to reset system state, eg initiate running from system
* -R
*/
if (plugin_reset_state(h, "tmp") < 0)
goto done;
if (candidate_commit(h, "tmp") < 0)
goto done;
retval = 0;
done:
return retval;
}
/*! Legacy (old-style) startup mode where flags -IRCcr was used
*/
static int
fragmented_startup_mode(clicon_handle h,
char *argv0,
int argc,
char *argv[],
int reload_running,
int init_rundb,
int reset_state_candidate,
int reset_state_running,
char *extraxml_file)
{
int retval = -1;
/* First check for startup config */
if (clicon_option_int(h, "CLICON_USE_STARTUP_CONFIG") > 0){
if (xmldb_exists(h, "startup") == 1){
/* copy startup config -> running */
if (xmldb_copy(h, "startup", "running") < 0)
goto done;
}
else
if (db_reset(h, "running") < 0)
goto done;
if (xmldb_create(h, "candidate") < 0)
goto done;
if (xmldb_copy(h, "running", "candidate") < 0)
goto done;
}
/* If running exists and reload_running set, make a copy to candidate */
if (reload_running){
if (xmldb_exists(h, "running") != 1){
clicon_log(LOG_NOTICE, "%s: -r (reload running) option given but no running_db found, proceeding without", __PROGRAM__);
reload_running = 0; /* void it, so we dont commit candidate below */
}
else
if (xmldb_copy(h, "running", "candidate") < 0)
goto done;
}
/* Init running db
* -I or if it isnt there
*/
if (init_rundb || xmldb_exists(h, "running") != 1){
if (db_reset(h, "running") < 0)
goto done;
}
/* If candidate does not exist, create it from running */
if (xmldb_exists(h, "candidate") != 1){
if (xmldb_create(h, "candidate") < 0)
goto done;
if (xmldb_copy(h, "running", "candidate") < 0)
goto done;
}
/* Load plugins and call plugin_init() */
if (plugin_initiate(h) != 0)
goto done;
if (reset_state_candidate){
if (candb_reset(h) < 0)
goto done;
}
else
if (reset_state_running){
if (plugin_reset_state(h, "running") < 0)
goto done;
}
if (plugin_start_useroptions(h, argv0, argc, argv) <0)
goto done;
if (reload_running){
/* This could be a failed validation, and we should not fail for that */
(void)candidate_commit(h, "candidate");
}
/* Have we specified a config file to load? eg
* -c [<file>]
*/
if (extraxml_file)
if (rundb_main(h, extraxml_file) < 0)
goto done;
/* Initiate the shared candidate. */
if (xmldb_copy(h, "running", "candidate") < 0)
goto done;
retval = 0;
done:
return retval;
}
#endif /* BACKEND_STARTUP_COMPAT */
/*! Merge xml in filename into database /*! Merge xml in filename into database
*/ */
static int static int
@ -648,12 +483,6 @@ main(int argc, char **argv)
int foreground; int foreground;
int once; int once;
enum startup_mode_t startup_mode; enum startup_mode_t startup_mode;
#ifdef BACKEND_STARTUP_COMPAT
int init_rundb = 0;
int reset_state_running = 0;
int reset_state_candidate = 0;
int reload_running = 0;
#endif
char *extraxml_file; char *extraxml_file;
char *config_group; char *config_group;
char *argv0 = argv[0]; char *argv0 = argv[0];
@ -769,20 +598,6 @@ main(int argc, char **argv)
case 'c': /* Load application config */ case 'c': /* Load application config */
extraxml_file = optarg; extraxml_file = optarg;
break; break;
#ifdef BACKEND_STARTUP_COMPAT
case 'I': /* Initiate running db */
init_rundb++;
break;
case 'R': /* Reset state directly into running */
reset_state_running++;
break;
case 'C': /* Reset state into candidate and then commit it */
reset_state_candidate++;
break;
case 'r': /* Reload running */
reload_running++;
break;
#endif /* BACKEND_STARTUP_COMPAT */
case 'g': /* config socket group */ case 'g': /* config socket group */
clicon_option_str_set(h, "CLICON_SOCK_GROUP", optarg); clicon_option_str_set(h, "CLICON_SOCK_GROUP", optarg);
break; break;
@ -890,19 +705,9 @@ main(int argc, char **argv)
goto done; goto done;
/* If startup mode is not defined, eg via OPTION or -s, assume old method */ /* If startup mode is not defined, eg via OPTION or -s, assume old method */
startup_mode = clicon_startup_mode(h); startup_mode = clicon_startup_mode(h);
if (startup_mode == -1){ /* Old style, fragmented mode, phase out */ if (startup_mode == -1){
#ifdef BACKEND_STARTUP_COMPAT
if (fragmented_startup_mode(h,
argv0, argc, argv,
reload_running, init_rundb,
reset_state_candidate, reset_state_running,
extraxml_file
) < 0)
goto done;
#else
clicon_log(LOG_ERR, "Startup mode undefined. Specify option CLICON_STARTUP_MODE or specify -s option to clicon_backend.\n"); clicon_log(LOG_ERR, "Startup mode undefined. Specify option CLICON_STARTUP_MODE or specify -s option to clicon_backend.\n");
goto done; goto done;
#endif
} }
else { else {
/* Init running db if it is not there /* Init running db if it is not there

View file

@ -42,19 +42,5 @@ clixon_DBSPECDIR=prefix/share/$(APPNAME)
clixon_SYSCONFDIR=sysconfdir clixon_SYSCONFDIR=sysconfdir
clixon_LOCALSTATEDIR=localstatedir/$(APPNAME) clixon_LOCALSTATEDIR=localstatedir/$(APPNAME)
clixon_LIBDIR=libdir/$(APPNAME) clixon_LIBDIR=libdir/$(APPNAME)
clixon_DATADIR=datadir/clixon clixon_DATADIR=datadir/clixon # for system yang files
# Rules for the clixon application configuration file.
# The clixon applications should be started with this fileas its -f argument.
# Typically installed in sysconfdir
# Example: APPNAME=myapp --> clixon_cli -f /usr/local/etc/myapp.conf
# The two variants are if there is a .conf.local file or not
.PHONY: $(APPNAME).conf
ifneq (,$(wildcard ${APPNAME}.conf.local))
${APPNAME}.conf: ${clixon_DATADIR}/clixon.conf.cpp ${APPNAME}.conf.local
$(CPP) -P -x assembler-with-cpp -DAPPNAME=$(APPNAME) $< > $@
cat ${APPNAME}.conf.local >> $@
else
${APPNAME}.conf: ${clixon_DATADIR}/clixon.conf.cpp
$(CPP) -P -x assembler-with-cpp -DAPPNAME=$(APPNAME) $< > $@
endif

71
configure vendored
View file

@ -632,9 +632,6 @@ CPP
OBJEXT OBJEXT
EXEEXT EXEEXT
ac_ct_CC ac_ct_CC
with_xml_compat
with_config_compat
with_startup_compat
with_keyvalue with_keyvalue
with_restconf with_restconf
RANLIB RANLIB
@ -712,9 +709,6 @@ with_cligen
with_restconf with_restconf
with_keyvalue with_keyvalue
with_qdbm with_qdbm
with_startup_compat
with_config_compat
with_xml_compat
' '
ac_precious_vars='build_alias ac_precious_vars='build_alias
host_alias host_alias
@ -1353,9 +1347,6 @@ Optional Packages:
--without-restconf disable support for restconf --without-restconf disable support for restconf
--with-keyvalue enable support for key-value xmldb datastore --with-keyvalue enable support for key-value xmldb datastore
--with-qdbm=dir Use QDBM here, if keyvalue --with-qdbm=dir Use QDBM here, if keyvalue
--with-startup-compat Backward compatibility of backend startup commands
--with-config-compat Backward compatibility of configuration file
--with-xml-compat Backward compatibility of XML API
Some influential environment variables: Some influential environment variables:
CC C compiler command CC C compiler command
@ -2357,13 +2348,6 @@ test -n "$target_alias" &&
# If yes, compile apps/restconf # If yes, compile apps/restconf
# If yes, compile datastore/keyvalue # If yes, compile datastore/keyvalue
# If yes, backward compatible with 3.3.2 backend startup
# If yes, backward compatible with 3.3.2 .conf configuration
# If yes, backward compatible with 3.3.3 XML api new and parse functions
# #
ac_ext=c ac_ext=c
ac_cpp='$CPP $CPPFLAGS' ac_cpp='$CPP $CPPFLAGS'
@ -4061,61 +4045,6 @@ fi
fi fi
# This is for backward compatibility of backend startup commands in 3.3.3
# Will be removed in 3.4.0
# Check whether --with-startup_compat was given.
if test "${with_startup_compat+set}" = set; then :
withval=$with_startup_compat;
else
with_startup_compat=no
fi
if test "x${with_startup_compat}" == xyes; then
cat >>confdefs.h <<_ACEOF
#define BACKEND_STARTUP_COMPAT $with_startup_compat
_ACEOF
fi
# This is for backward compatibility of .conf configuration file in 3.3.3
# Will be removed in 3.4.0
# Check whether --with-config_compat was given.
if test "${with_config_compat+set}" = set; then :
withval=$with_config_compat;
else
with_config_compat=no
fi
if test "x${with_config_compat}" == xyes; then
cat >>confdefs.h <<_ACEOF
#define CONFIG_COMPAT $with_config_compat
_ACEOF
fi
# Clixon 3.4.0 changes XML creation and parse API
# Set this for backward compat and migration.
# Will be removed in 3.5.0
# Check whether --with-xml_compat was given.
if test "${with_xml_compat+set}" = set; then :
withval=$with_xml_compat;
else
with_xml_compat=no
fi
if test "x${with_xml_compat}" == xyes; then
cat >>confdefs.h <<_ACEOF
#define XML_COMPAT $with_xml_compat
_ACEOF
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for crypt in -lcrypt" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for crypt in -lcrypt" >&5
$as_echo_n "checking for crypt in -lcrypt... " >&6; } $as_echo_n "checking for crypt in -lcrypt... " >&6; }
if ${ac_cv_lib_crypt_crypt+:} false; then : if ${ac_cv_lib_crypt_crypt+:} false; then :

View file

@ -86,13 +86,6 @@ AC_SUBST(AR)
AC_SUBST(RANLIB) AC_SUBST(RANLIB)
AC_SUBST(with_restconf) # If yes, compile apps/restconf AC_SUBST(with_restconf) # If yes, compile apps/restconf
AC_SUBST(with_keyvalue) # If yes, compile datastore/keyvalue AC_SUBST(with_keyvalue) # If yes, compile datastore/keyvalue
# If yes, backward compatible with 3.3.2 backend startup
AC_SUBST(with_startup_compat)
# If yes, backward compatible with 3.3.2 .conf configuration
AC_SUBST(with_config_compat)
# If yes, backward compatible with 3.3.3 XML api new and parse functions
AC_SUBST(with_xml_compat)
# #
AC_PROG_CC() AC_PROG_CC()
AC_PROG_CPP AC_PROG_CPP
@ -168,37 +161,6 @@ if test "x${with_keyvalue}" == xyes; then
AC_CONFIG_FILES(datastore/keyvalue/Makefile) AC_CONFIG_FILES(datastore/keyvalue/Makefile)
fi fi
# This is for backward compatibility of backend startup commands in 3.3.3
# Will be removed in 3.4.0
AC_ARG_WITH([startup_compat],
[AS_HELP_STRING([--with-startup-compat],[Backward compatibility of backend startup commands])],
[],
[with_startup_compat=no])
if test "x${with_startup_compat}" == xyes; then
AC_DEFINE_UNQUOTED(BACKEND_STARTUP_COMPAT, $with_startup_compat, [Backward compatible backend startup command-line options])
fi
# This is for backward compatibility of .conf configuration file in 3.3.3
# Will be removed in 3.4.0
AC_ARG_WITH([config_compat],
[AS_HELP_STRING([--with-config-compat],[Backward compatibility of configuration file])],
[],
[with_config_compat=no])
if test "x${with_config_compat}" == xyes; then
AC_DEFINE_UNQUOTED(CONFIG_COMPAT, $with_config_compat, [Backward compatible of .conf configuration files])
fi
# Clixon 3.4.0 changes XML creation and parse API
# Set this for backward compat and migration.
# Will be removed in 3.5.0
AC_ARG_WITH([xml_compat],
[AS_HELP_STRING([--with-xml-compat],[Backward compatibility of XML API])],
[],
[with_xml_compat=no])
if test "x${with_xml_compat}" == xyes; then
AC_DEFINE_UNQUOTED(XML_COMPAT, $with_xml_compat, [Backward compatible of XML API])
fi
AC_CHECK_LIB(crypt, crypt) AC_CHECK_LIB(crypt, crypt)
AC_CHECK_HEADERS(crypt.h) AC_CHECK_HEADERS(crypt.h)

View file

@ -1,8 +1,5 @@
/* include/clixon_config.h.in. Generated from configure.ac by autoheader. */ /* include/clixon_config.h.in. Generated from configure.ac by autoheader. */
/* Backward compatible backend startup command-line options */
#undef BACKEND_STARTUP_COMPAT
/* Clixon data dir for system yang files etc */ /* Clixon data dir for system yang files etc */
#undef CLIXON_DATADIR #undef CLIXON_DATADIR
@ -18,9 +15,6 @@
/* Clixon version string */ /* Clixon version string */
#undef CLIXON_VERSION_STRING #undef CLIXON_VERSION_STRING
/* Backward compatible of .conf configuration files */
#undef CONFIG_COMPAT
/* Define to 1 if you have the `alphasort' function. */ /* Define to 1 if you have the `alphasort' function. */
#undef HAVE_ALPHASORT #undef HAVE_ALPHASORT
@ -138,9 +132,6 @@
/* Define to 1 if you have the ANSI C header files. */ /* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS #undef STDC_HEADERS
/* Backward compatible of XML API */
#undef XML_COMPAT
/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
`char[]'. */ `char[]'. */
#undef YYTEXT_POINTER #undef YYTEXT_POINTER

View file

@ -56,8 +56,6 @@
#undef CLIXON_VERSION_MINOR #undef CLIXON_VERSION_MINOR
#undef CLIXON_VERSION_PATCH #undef CLIXON_VERSION_PATCH
#undef XML_COMPAT
/* /*
* Use this constant to disable some prototypes that should not be visible outside the lib. * Use this constant to disable some prototypes that should not be visible outside the lib.
* This is an alternative to use separate internal include files. * This is an alternative to use separate internal include files.

View file

@ -161,16 +161,4 @@ int xml_body_uint32(cxobj *xb, uint32_t *val);
int xml_operation(char *opstr, enum operation_type *op); int xml_operation(char *opstr, enum operation_type *op);
char *xml_operation2str(enum operation_type op); char *xml_operation2str(enum operation_type op);
#ifdef XML_COMPAT /* See CHANGELOG */
/* MANUAL CHANGE: xml_new(name, parent) --> xml_new(name, parent, NULL) */
#define xml_new_spec(name, parent) xml_new(name, parent, NULL)
#define clicon_xml_parse(xt, fmt, ...) xml_parse_va(xt, NULL, fmt, __VA_ARGS__)
#define clicon_xml_parse_file(fd, xt, etag) xml_parse_file(fd, etag, NULL, xt)
#define clicon_xml_parse_string(strp, xt) xml_parse_string(*strp, NULL, xt)
#define clicon_xml_parse_str(str, xt) xml_parse_string(str, NULL, xt)
#define xml_parse(str, xt) xml_parse_string(str, NULL, &xt)
#endif
#endif /* _CLIXON_XML_H */ #endif /* _CLIXON_XML_H */

View file

@ -183,168 +183,6 @@ clicon_option_readfile_xml(clicon_hash_t *copt,
return retval; return retval;
} }
#ifdef CONFIG_COMPAT
/*! Read filename and set values to global options registry
* For legacy configuration file, ie not xml
* @see clicon_option_readfile_xml
*/
static int
clicon_option_readfile(clicon_hash_t *copt,
const char *filename)
{
struct stat st;
char opt[1024];
char val[1024];
char line[1024];
char *cp;
FILE *f = NULL;
int retval = -1;
if (filename == NULL || !strlen(filename)){
clicon_err(OE_UNIX, 0, "Not specified");
goto done;
}
if (stat(filename, &st) < 0){
clicon_err(OE_UNIX, errno, "%s", filename);
goto done;
}
if (!S_ISREG(st.st_mode)){
clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
goto done;
}
if ((f = fopen(filename, "r")) == NULL) {
clicon_err(OE_UNIX, errno, "configure file: %s", filename);
return -1;
}
clicon_debug(2, "Reading config file %s", __FUNCTION__, filename);
while (fgets(line, sizeof(line), f)) {
if ((cp = strchr(line, '\n')) != NULL) /* strip last \n */
*cp = '\0';
/* Trim out comments, strip whitespace, and remove CR */
if ((cp = strchr(line, '#')) != NULL)
memcpy(cp, "\n", 2);
if (sscanf(line, "%s %s", opt, val) < 2)
continue;
if ((hash_add(copt,
opt,
val,
strlen(val)+1)) == NULL)
goto done;
}
retval = 0;
done:
if (f)
fclose(f);
return retval;
}
/*! Set default values of some options that may not appear in config-file
*/
static int
clicon_option_default(clicon_hash_t *copt)
{
char *val;
int retval = 0;
if (!hash_lookup(copt, "CLICON_YANG_MODULE_MAIN")){
if (hash_add(copt, "CLICON_YANG_MODULE_MAIN", "clicon", strlen("clicon")+1) < 0)
goto done;
}
if (!hash_lookup(copt, "CLICON_SOCK_GROUP")){
val = CLICON_SOCK_GROUP;
if (hash_add(copt, "CLICON_SOCK_GROUP", val, strlen(val)+1) < 0)
goto done;
}
if (!hash_lookup(copt, "CLICON_CLI_MODE")){
if (hash_add(copt, "CLICON_CLI_MODE", "base", strlen("base")+1) < 0)
goto done;
}
if (!hash_lookup(copt, "CLICON_MASTER_PLUGIN")){
val = CLICON_MASTER_PLUGIN;
if (hash_add(copt, "CLICON_MASTER_PLUGIN", val, strlen(val)+1) < 0)
goto done;
}
if (!hash_lookup(copt, "CLICON_CLI_GENMODEL")){
if (hash_add(copt, "CLICON_CLI_GENMODEL", "1", strlen("1")+1) < 0)
goto done;
}
if (!hash_lookup(copt, "CLICON_CLI_GENMODEL_TYPE")){
if (hash_add(copt, "CLICON_CLI_GENMODEL_TYPE", "VARS", strlen("VARS")+1) < 0)
goto done;
}
if (!hash_lookup(copt, "CLICON_AUTOCOMMIT")){
if (hash_add(copt, "CLICON_AUTOCOMMIT", "0", strlen("0")+1) < 0)
goto done;
}
/* Legacy is 1 but default should really be 0. New apps should use 0 */
if (!hash_lookup(copt, "CLICON_CLI_VARONLY")){
if (hash_add(copt, "CLICON_CLI_VARONLY", "1", strlen("1")+1) < 0)
goto done;
}
if (!hash_lookup(copt, "CLICON_CLI_GENMODEL_COMPLETION")){
if (hash_add(copt, "CLICON_CLI_GENMODEL_COMPLETION", "1", strlen("1")+1) < 0)
goto done;
}
/* Default is to use line-scrolling */
if (!hash_lookup(copt, "CLICON_CLI_LINESCROLLING")){
if (hash_add(copt, "CLICON_CLI_LINESCROLLING", "1", strlen("1")+1) < 0)
goto done;
}
retval = 0;
done:
return retval;
}
/*! Check that options are set
*/
static int
clicon_option_sanity(clicon_hash_t *copt)
{
int retval = -1;
if (!hash_lookup(copt, "CLICON_CLI_DIR")){
clicon_err(OE_UNIX, 0, "CLICON_CLI_DIR not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_CLISPEC_DIR")){
clicon_err(OE_UNIX, 0, "CLICON_CLISPEC_DIR not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_BACKEND_DIR")){
clicon_err(OE_UNIX, 0, "CLICON_BACKEND_DIR not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_NETCONF_DIR")){
clicon_err(OE_UNIX, 0, "CLICON_NETCONF_DIR not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_RESTCONF_DIR")){
clicon_err(OE_UNIX, 0, "CLICON_RESTCONF_DIR not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_YANG_DIR")){
clicon_err(OE_UNIX, 0, "CLICON_YANG_DIR not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_XMLDB_DIR")){
clicon_err(OE_UNIX, 0, "CLICON_XMLDB_DIR not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_SOCK")){
clicon_err(OE_UNIX, 0, "CLICON_SOCK not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_BACKEND_PIDFILE")){
clicon_err(OE_UNIX, 0, "CLICON_BACKEND_PIDFILE not defined in config file");
goto done;
}
retval = 0;
done:
return retval;
}
#endif /* CONFIG_COMPAT */
/*! Initialize option values /*! Initialize option values
* *
* Set default options, Read config-file, Check that all values are set. * Set default options, Read config-file, Check that all values are set.
@ -389,19 +227,8 @@ clicon_options_main(clicon_handle h)
xml_child_sort = 0; xml_child_sort = 0;
} }
else { else {
#ifdef CONFIG_COMPAT
/* Set default options */
if (clicon_option_default(copt) < 0) /* init registry from file */
goto done;
/* Read configfile */
if (clicon_option_readfile(copt, configfile) < 0)
goto done;
if (clicon_option_sanity(copt) < 0)
goto done;
#else /* CONFIG_COMPAT */
clicon_err(OE_CFG, 0, "%s: suffix %s not recognized (Run ./configure --with-config-compat?)", configfile, suffix); clicon_err(OE_CFG, 0, "%s: suffix %s not recognized (Run ./configure --with-config-compat?)", configfile, suffix);
goto done; goto done;
#endif /* CONFIG_COMPAT */
} }
retval = 0; retval = 0;
done: done:

View file

@ -26,9 +26,6 @@ fi
if [ ! -f $DIR/usr/local/share/clixon/clixon.mk ]; then if [ ! -f $DIR/usr/local/share/clixon/clixon.mk ]; then
err $DIR/usr/local/share/clixon/clixon.mk err $DIR/usr/local/share/clixon/clixon.mk
fi fi
if [ ! -f $DIR/usr/local/share/clixon/clixon.conf.cpp ]; then
err $DIR/usr/local/share/clixon/clixon.conf.cpp
fi
if [ ! -f $DIR/usr/local/share/clixon/clixon-config* ]; then if [ ! -f $DIR/usr/local/share/clixon/clixon-config* ]; then
err $DIR/usr/local/share/clixon/clixon-config* err $DIR/usr/local/share/clixon/clixon-config*
fi fi