From 2758a30bb7e0deccc1c3bcd09ad847989ecb10d0 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 11 Apr 2017 20:15:43 +0200 Subject: [PATCH] Configure (autoconf) changes: Removed libcurl dependency, Disable restconf and disable restconf options. Added empty text datastore --- CHANGELOG => CHANGELOG.txt | 7 +- apps/Makefile.in | 9 +- apps/backend/backend_main.c | 4 +- configure | 153 ++++---- configure.ac | 43 ++- datastore/Makefile.in | 7 +- datastore/keyvalue/Makefile.in | 5 +- datastore/keyvalue/clixon_chunk.c | 7 +- datastore/keyvalue/clixon_keyvalue.c | 4 +- datastore/keyvalue/clixon_qdb.c | 5 +- datastore/text/Makefile.in | 97 ++++++ datastore/text/clixon_xmldb_text.c | 501 +++++++++++++++++++++++++++ datastore/text/clixon_xmldb_text.h | 56 +++ lib/clixon/clixon.h | 91 ----- lib/clixon/clixon.h.in | 5 +- 15 files changed, 812 insertions(+), 182 deletions(-) rename CHANGELOG => CHANGELOG.txt (95%) create mode 100644 datastore/text/Makefile.in create mode 100644 datastore/text/clixon_xmldb_text.c create mode 100644 datastore/text/clixon_xmldb_text.h delete mode 100644 lib/clixon/clixon.h diff --git a/CHANGELOG b/CHANGELOG.txt similarity index 95% rename from CHANGELOG rename to CHANGELOG.txt index e61c2400..6b28a139 100644 --- a/CHANGELOG +++ b/CHANGELOG.txt @@ -29,7 +29,12 @@ # # ***** END LICENSE BLOCK ***** -- Removed curl dependency +- Added datastore 'text' + +- Configure (autoconf) changes + Removed libcurl dependency + Disable restconf (and fastcgi) with configure --disable-restconf + Disable keyvalue datastore (and qdbm) with configure --disable-keyvalue - Created xmldb plugin api Moved qdbm, chunk and xmldb to datastore keyvalue directories diff --git a/apps/Makefile.in b/apps/Makefile.in index a685dcaa..7f7ca9c0 100644 --- a/apps/Makefile.in +++ b/apps/Makefile.in @@ -37,10 +37,17 @@ CC = @CC@ CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ +with_restconf = @with_restconf@ SHELL = /bin/sh -SUBDIRS = cli backend dbctrl netconf restconf +SUBDIRS = backend +SUBDIRS += cli +SUBDIRS += dbctrl +SUBDIRS += netconf +ifeq ($(with_restconf),yes) +SUBDIRS += restconf +endif .PHONY: all clean depend install $(SUBDIRS) diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index 1b832fe9..f417e2ec 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -141,8 +141,8 @@ usage(char *argv0, clicon_handle h) " -p \t\tPrint database yang specification\n" " -t \t\tPrint alternate spec translation (eg if YANG print KEY, if KEY print YANG)\n" " -g \tClient membership required to this group (default: %s)\n" - "\t-y \tOverride yang spec file (dont include .yang suffix)\n" - "\t-x \tXMLDB plugin\n", + " -y \tOverride yang spec file (dont include .yang suffix)\n" + " -x \tXMLDB plugin\n", argv0, plgdir ? plgdir : "none", confsock ? confsock : "none", diff --git a/configure b/configure index 6140aa7d..f0d9de95 100755 --- a/configure +++ b/configure @@ -632,6 +632,8 @@ CPP OBJEXT EXEEXT ac_ct_CC +with_keyvalue +with_restconf RANLIB AR EXE_SUFFIX @@ -702,6 +704,8 @@ ac_subst_files='' ac_user_opts=' enable_option_checking with_cligen +with_restconf +with_keyvalue with_qdbm ' ac_precious_vars='build_alias @@ -1327,6 +1331,8 @@ Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-cligen=dir Use CLIGEN here + --without-restconf disable support for restconf + --without-keyvalue disable support for key-value xmldb datastore --with-qdbm=dir Use QDBM here Some influential environment variables: @@ -2320,6 +2326,8 @@ test -n "$target_alias" && + # If yes, compile apps/restconf + # If yes, compile datastore/keyvalue # ac_ext=c @@ -3534,7 +3542,6 @@ if test "${with_cligen}"; then fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : @@ -3859,21 +3866,92 @@ else fi -# This is for qdbm +# This is for restconf (and fastcgi) + +# Check whether --with-restconf was given. +if test "${with_restconf+set}" = set; then : + withval=$with_restconf; +else + with_restconf=yes +fi + +if test "x${with_restconf}" == xyes; then + # Lives in libfcgi-dev + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for FCGX_Init in -lfcgi" >&5 +$as_echo_n "checking for FCGX_Init in -lfcgi... " >&6; } +if ${ac_cv_lib_fcgi_FCGX_Init+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lfcgi $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char FCGX_Init (); +int +main () +{ +return FCGX_Init (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_fcgi_FCGX_Init=yes +else + ac_cv_lib_fcgi_FCGX_Init=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_fcgi_FCGX_Init" >&5 +$as_echo "$ac_cv_lib_fcgi_FCGX_Init" >&6; } +if test "x$ac_cv_lib_fcgi_FCGX_Init" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBFCGI 1 +_ACEOF + + LIBS="-lfcgi $LIBS" + +else + as_fn_error $? "libfcgi-dev missing" "$LINENO" 5 +fi + +fi + +# This is for keyvalue datastore (and qdbm) + +# Check whether --with-keyvalue was given. +if test "${with_keyvalue+set}" = set; then : + withval=$with_keyvalue; +else + with_keyvalue=yes +fi + + +if test "x${with_keyvalue}" == xyes; then + echo "yes keyvalue" + # This is for qdbm # Check whether --with-qdbm was given. if test "${with_qdbm+set}" = set; then : withval=$with_qdbm; fi -if test "${with_qdbm}"; then - echo "Using QDBM here: ${with_qdbm}" - CPPFLAGS="-I${with_qdbm}/include ${CPPFLAGS}" - LDFLAGS="-L${with_qdbm}/lib ${LDFLAGS}" -fi - -# Problem: depot.h may be in qdbm/depot.h. -for ac_header in depot.h + if test "${with_qdbm}"; then + echo "Using QDBM here: ${with_qdbm}" + CPPFLAGS="-I${with_qdbm}/include ${CPPFLAGS}" + LDFLAGS="-L${with_qdbm}/lib ${LDFLAGS}" + fi + # Problem: depot.h may be in qdbm/depot.h. + for ac_header in depot.h do : ac_fn_c_check_header_mongrel "$LINENO" "depot.h" "ac_cv_header_depot_h" "$ac_includes_default" if test "x$ac_cv_header_depot_h" = xyes; then : @@ -3900,7 +3978,7 @@ fi done -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dpopen in -lqdbm" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dpopen in -lqdbm" >&5 $as_echo_n "checking for dpopen in -lqdbm... " >&6; } if ${ac_cv_lib_qdbm_dpopen+:} false; then : $as_echo_n "(cached) " >&6 @@ -3947,6 +4025,7 @@ else as_fn_error $? "libqdbm-dev required" "$LINENO" 5 fi +fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for crypt in -lcrypt" >&5 $as_echo_n "checking for crypt in -lcrypt... " >&6; } @@ -4185,58 +4264,9 @@ fi done -# Lives in libfcgi-dev -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for FCGX_Init in -lfcgi" >&5 -$as_echo_n "checking for FCGX_Init in -lfcgi... " >&6; } -if ${ac_cv_lib_fcgi_FCGX_Init+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lfcgi $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char FCGX_Init (); -int -main () -{ -return FCGX_Init (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_fcgi_FCGX_Init=yes -else - ac_cv_lib_fcgi_FCGX_Init=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_fcgi_FCGX_Init" >&5 -$as_echo "$ac_cv_lib_fcgi_FCGX_Init" >&6; } -if test "x$ac_cv_lib_fcgi_FCGX_Init" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBFCGI 1 -_ACEOF - - LIBS="-lfcgi $LIBS" - -else - as_fn_error $? "libfcgi-dev missing" "$LINENO" 5 -fi - - -ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile apps/dbctrl/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile example/docker/Makefile docker/Makefile docker/cli/Makefile docker/cli/Dockerfile docker/backend/Makefile docker/backend/Dockerfile docker/netconf/Makefile docker/netconf/Dockerfile datastore/Makefile datastore/keyvalue/Makefile doc/Makefile" +ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile apps/dbctrl/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile example/docker/Makefile docker/Makefile docker/cli/Makefile docker/cli/Dockerfile docker/backend/Makefile docker/backend/Dockerfile docker/netconf/Makefile docker/netconf/Dockerfile datastore/Makefile datastore/keyvalue/Makefile datastore/text/Makefile doc/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -4953,6 +4983,7 @@ do "docker/netconf/Dockerfile") CONFIG_FILES="$CONFIG_FILES docker/netconf/Dockerfile" ;; "datastore/Makefile") CONFIG_FILES="$CONFIG_FILES datastore/Makefile" ;; "datastore/keyvalue/Makefile") CONFIG_FILES="$CONFIG_FILES datastore/keyvalue/Makefile" ;; + "datastore/text/Makefile") CONFIG_FILES="$CONFIG_FILES datastore/text/Makefile" ;; "doc/Makefile") CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; diff --git a/configure.ac b/configure.ac index c97cf5a3..9b12e28d 100644 --- a/configure.ac +++ b/configure.ac @@ -77,6 +77,8 @@ AC_SUBST(SH_SUFFIX) AC_SUBST(EXE_SUFFIX) AC_SUBST(AR) AC_SUBST(RANLIB) +AC_SUBST(with_restconf) # If yes, compile apps/restconf +AC_SUBST(with_keyvalue) # If yes, compile datastore/keyvalue # AC_PROG_CC() @@ -119,22 +121,39 @@ if test "${with_cligen}"; then LDFLAGS="-L${with_cligen}/lib ${LDFLAGS}" fi - AC_CHECK_HEADERS(cligen/cligen.h,, AC_MSG_ERROR(cligen missing. Try: git clone https://github.com/olofhagsand/cligen.git)) AC_CHECK_LIB(:libcligen.so.${CLIGEN_VERSION}, cligen_init,, AC_MSG_ERROR([CLIgen${CLIGEN_VERSION} missing. Try: git clone https://github.com/olofhagsand/cligen.git])) -# This is for qdbm -AC_ARG_WITH(qdbm, [ --with-qdbm=dir Use QDBM here ] ) -if test "${with_qdbm}"; then - echo "Using QDBM here: ${with_qdbm}" - CPPFLAGS="-I${with_qdbm}/include ${CPPFLAGS}" - LDFLAGS="-L${with_qdbm}/lib ${LDFLAGS}" +# This is for restconf (and fastcgi) +AC_ARG_WITH([restconf], + [AS_HELP_STRING([--without-restconf],[disable support for restconf])], + [], + [with_restconf=yes]) +if test "x${with_restconf}" == xyes; then + # Lives in libfcgi-dev + AC_CHECK_LIB(fcgi, FCGX_Init,, AC_MSG_ERROR([libfcgi-dev missing])) fi -# Problem: depot.h may be in qdbm/depot.h. -AC_CHECK_HEADERS(depot.h,,[AC_CHECK_HEADERS(qdbm/depot.h,,AC_MSG_ERROR(libqdbm-dev required))]) -AC_CHECK_LIB(qdbm, dpopen,, AC_MSG_ERROR(libqdbm-dev required)) +# This is for keyvalue datastore (and qdbm) +AC_ARG_WITH([keyvalue], + [AS_HELP_STRING([--without-keyvalue],[disable support for key-value xmldb datastore])], + [], + [with_keyvalue=yes]) + +if test "x${with_keyvalue}" == xyes; then + echo "yes keyvalue" + # This is for qdbm + AC_ARG_WITH(qdbm, [ --with-qdbm=dir Use QDBM here, if keyvalue ] ) + if test "${with_qdbm}"; then + echo "Using QDBM here: ${with_qdbm}" + CPPFLAGS="-I${with_qdbm}/include ${CPPFLAGS}" + LDFLAGS="-L${with_qdbm}/lib ${LDFLAGS}" + fi + # Problem: depot.h may be in qdbm/depot.h. + AC_CHECK_HEADERS(depot.h,,[AC_CHECK_HEADERS(qdbm/depot.h,,AC_MSG_ERROR(libqdbm-dev required))]) + AC_CHECK_LIB(qdbm, dpopen,, AC_MSG_ERROR(libqdbm-dev required)) +fi AC_CHECK_LIB(crypt, crypt) AC_CHECK_HEADERS(crypt.h) @@ -153,9 +172,6 @@ AC_CHECK_LIB(dl, dlopen) AC_CHECK_FUNCS(inet_aton sigaction sigvec strlcpy strsep strndup alphasort versionsort strverscmp) -# Lives in libfcgi-dev -AC_CHECK_LIB(fcgi, FCGX_Init,, AC_MSG_ERROR([libfcgi-dev missing])) - AH_BOTTOM([#include ]) AC_OUTPUT(Makefile @@ -182,6 +198,7 @@ AC_OUTPUT(Makefile docker/netconf/Dockerfile datastore/Makefile datastore/keyvalue/Makefile + datastore/text/Makefile doc/Makefile ) diff --git a/datastore/Makefile.in b/datastore/Makefile.in index 7ad7112f..76e7a461 100644 --- a/datastore/Makefile.in +++ b/datastore/Makefile.in @@ -37,10 +37,15 @@ CC = @CC@ CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ +with_restconf = @with_restconf@ +with_keyvalue = @with_keyvalue@ SHELL = /bin/sh -SUBDIRS = keyvalue +SUBDIRS = text +ifeq ($(with_keyvalue),yes) +SUBDIRS += keyvalue +endif .PHONY: all clean depend install $(SUBDIRS) diff --git a/datastore/keyvalue/Makefile.in b/datastore/keyvalue/Makefile.in index 0737450e..7db2ef56 100644 --- a/datastore/keyvalue/Makefile.in +++ b/datastore/keyvalue/Makefile.in @@ -51,7 +51,7 @@ LIBS = @LIBS@ DATASTORE = keyvalue CPPFLAGS = @CPPFLAGS@ -INCLUDES = -I. @INCLUDES@ -I$(top_srcdir)/lib/clixon -I$(top_srcdir)/include -I$(top_srcdir) +INCLUDES = -I. -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@ PLUGIN = $(DATASTORE).so @@ -63,9 +63,6 @@ all: $(PLUGIN) -include $(DESTDIR)$(datarootdir)/clixon/clixon.mk -#grideye_sysinfo.so.1: grideye_sysinfo.c -# $(CC) $(CFLAGS) -shared -o $@ -lc $^ -lm - $(PLUGIN): $(SRC) $(CC) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) -shared -o $@ -lc $^ $(LIBS) diff --git a/datastore/keyvalue/clixon_chunk.c b/datastore/keyvalue/clixon_chunk.c index 4d4782a0..bade74fa 100644 --- a/datastore/keyvalue/clixon_chunk.c +++ b/datastore/keyvalue/clixon_chunk.c @@ -36,6 +36,7 @@ ensure errno is set and return -1/NULL */ #include #include +#include #include #include #include @@ -45,7 +46,11 @@ #include /* clicon */ -#include "clixon_queue.h" +#include + +/* clicon */ +#include + #include "clixon_chunk.h" /* diff --git a/datastore/keyvalue/clixon_keyvalue.c b/datastore/keyvalue/clixon_keyvalue.c index fcbab626..68e67a51 100644 --- a/datastore/keyvalue/clixon_keyvalue.c +++ b/datastore/keyvalue/clixon_keyvalue.c @@ -1552,7 +1552,7 @@ kv_init(clicon_handle h, /*! plugin init function */ int -keyvalue_plugin_exit(void) +kv_plugin_exit(void) { return 0; } @@ -1577,7 +1577,7 @@ static const struct xmldb_api api = { 1, XMLDB_API_MAGIC, clixon_xmldb_plugin_init, - keyvalue_plugin_exit, + kv_plugin_exit, kv_get, kv_put, kv_dump, diff --git a/datastore/keyvalue/clixon_qdb.c b/datastore/keyvalue/clixon_qdb.c index 9b716951..1af75ab0 100644 --- a/datastore/keyvalue/clixon_qdb.c +++ b/datastore/keyvalue/clixon_qdb.c @@ -78,9 +78,8 @@ #include /* clicon */ -#include "clixon_log.h" -#include "clixon_err.h" -#include "clixon_queue.h" +#include + #include "clixon_chunk.h" #include "clixon_qdb.h" diff --git a/datastore/text/Makefile.in b/datastore/text/Makefile.in new file mode 100644 index 00000000..7b7cf6e9 --- /dev/null +++ b/datastore/text/Makefile.in @@ -0,0 +1,97 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# +# Copyright (C) 2009-2017 Olof Hagsand and Benny Holmgren +# +# This file is part of CLIXON +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Alternatively, the contents of this file may be used under the terms of +# the GNU General Public License Version 3 or later (the "GPL"), +# in which case the provisions of the GPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of the GPL, and not to allow others to +# use your version of this file under the terms of Apache License version 2, +# indicate your decision by deleting the provisions above and replace them with +# the notice and other provisions required by the GPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the Apache License version 2 or the GPL. +# +# ***** END LICENSE BLOCK ***** +# +prefix = @prefix@ +datarootdir = @datarootdir@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +libdir = @libdir@ +dbdir = @prefix@/db +mandir = @mandir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +sysconfdir = @sysconfdir@ + +VPATH = @srcdir@ +CC = @CC@ +CFLAGS = @CFLAGS@ -rdynamic -fPIC +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +DATASTORE = text +CPPFLAGS = @CPPFLAGS@ + +INCLUDES = -I. -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@ + +PLUGIN = $(DATASTORE).so + +SRC = clixon_xmldb_text.c + +OBJS = $(SRC:.c=.o) + +all: $(PLUGIN) + +-include $(DESTDIR)$(datarootdir)/clixon/clixon.mk + +$(PLUGIN): $(SRC) + $(CC) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) -shared -o $@ -lc $^ $(LIBS) + +clean: + rm -f $(PLUGIN) $(OBJS) *.core + +distclean: clean + rm -f Makefile *~ .depend + +.SUFFIXES: +.SUFFIXES: .c .o + +.c.o: $(SRC) + $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $< + +install: $(PLUGIN) + install -d $(DESTDIR)$(clixon_LIBDIR)/xmldb + install $(PLUGIN) $(DESTDIR)$(clixon_LIBDIR)/xmldb; + +install-include: + +uninstall: + rm -rf $(DESTDIR)$(clixon_LIBDIR)/xmldb/$(PLUGIN); + +TAGS: + find . -name '*.[chyl]' -print | etags - + +depend: + $(CC) $(DEPENDFLAGS) @DEFS@ $(INCLUDES) $(CFLAGS) -MM $(SRC) > .depend + +#include .depend + diff --git a/datastore/text/clixon_xmldb_text.c b/datastore/text/clixon_xmldb_text.c new file mode 100644 index 00000000..2b4926eb --- /dev/null +++ b/datastore/text/clixon_xmldb_text.c @@ -0,0 +1,501 @@ +/* + * + ***** BEGIN LICENSE BLOCK ***** + + Copyright (C) 2009-2017 Olof Hagsand and Benny Holmgren + + This file is part of CLIXON. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Alternatively, the contents of this file may be used under the terms of + the GNU General Public License Version 3 or later (the "GPL"), + in which case the provisions of the GPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of the GPL, and not to allow others to + use your version of this file under the terms of Apache License version 2, + indicate your decision by deleting the provisions above and replace them with + the notice and other provisions required by the GPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the Apache License version 2 or the GPL. + + ***** END LICENSE BLOCK ***** + */ + +#ifdef HAVE_CONFIG_H +#include "clixon_config.h" /* generated by config & autoconf */ +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* cligen */ +#include + +/* clicon */ +#include + +#include "clixon_xmldb_text.h" + +/*! Database locking for candidate and running non-persistent + * Store an integer for running and candidate containing + * the session-id of the client holding the lock. + */ +static int _running_locked = 0; +static int _candidate_locked = 0; +static int _startup_locked = 0; + +/*! Translate from symbolic database name to actual filename in file-system + * @param[in] h Clicon handle + * @param[in] db Symbolic database name, eg "candidate", "running" + * @param[out] filename Filename. Unallocate after use with free() + * @retval 0 OK + * @retval -1 Error + * @note Could need a way to extend which databases exists, eg to register new. + * The currently allowed databases are: + * candidate, tmp, running, result + * The filename reside in CLICON_XMLDB_DIR option + */ +static int +db2file(clicon_handle h, + char *db, + char **filename) +{ + int retval = -1; + cbuf *cb; + char *dir; + + if ((cb = cbuf_new()) == NULL){ + clicon_err(OE_XML, errno, "cbuf_new"); + goto done; + } + if ((dir = clicon_xmldb_dir(h)) == NULL){ + clicon_err(OE_XML, errno, "CLICON_XMLDB_DIR not set"); + goto done; + } + if (strcmp(db, "running") != 0 && + strcmp(db, "candidate") != 0 && + strcmp(db, "startup") != 0 && + strcmp(db, "tmp") != 0){ + clicon_err(OE_XML, 0, "Unexpected database: %s", db); + goto done; + } + cprintf(cb, "%s/%s_db", dir, db); + if ((*filename = strdup4(cbuf_get(cb))) == NULL){ + clicon_err(OE_UNIX, errno, "strdup"); + goto done; + } + retval = 0; + done: + if (cb) + cbuf_free(cb); + return retval; +} + +/*! Get content of database using xpath. return a set of matching sub-trees + * The function returns a minimal tree that includes all sub-trees that match + * xpath. + * @param[in] dbname Name of database to search in (filename including dir path + * @param[in] xpath String with XPATH syntax. or NULL for all + * @param[in] yspec Yang specification + * @param[out] xtop Single XML tree which xvec points to. Free with xml_free() + * @param[out] xvec Vector of xml trees. Free after use. + * @param[out] xlen Length of vector. + * @retval 0 OK + * @retval -1 Error + * @code + * cxobj *xt; + * cxobj **xvec; + * size_t xlen; + * yang_spec *yspec = clicon_dbspec_yang(h); + * if (xmldb_get("running", "/interfaces/interface[name="eth"]", + * &xt, &xvec, &xlen) < 0) + * err; + * for (i=0; i17", &xt) < 0) + * err; + * if (xmldb_put(h, "running", OP_MERGE, NULL, xt) < 0) + * err; + * @endcode + * @see xmldb_put_xkey for single key + */ +int +text_put(clicon_handle h, + char *db, + enum operation_type op, + char *api_path, + cxobj *xt) +{ + int retval = -1; + retval = 0; + // done: + return retval; +} + +/*! Raw dump of database, just keys and values, no xml interpretation + * @param[in] f File + * @param[in] dbfile File-name of database. This is a local file + * @param[in] rxkey Key regexp, eg "^.*$" + * @note This function can only be called locally. + */ +int +text_dump(FILE *f, + char *dbfilename, + char *rxkey) +{ + int retval = -1; + + retval = 0; + // done: + return retval; +} + +/*! Copy database from db1 to db2 + * @param[in] h Clicon handle + * @param[in] from Source database copy + * @param[in] to Destination database + * @retval -1 Error + * @retval 0 OK + */ +int +text_copy(clicon_handle h, + char *from, + char *to) +{ + int retval = -1; + retval = 0; + // done: + return retval; +} + +/*! Lock database + * @param[in] h Clicon handle + * @param[in] db Database + * @param[in] pid Process id + * @retval -1 Error + * @retval 0 OK + */ +int +text_lock(clicon_handle h, + char *db, + int pid) +{ + if (strcmp("running", db) == 0) + _running_locked = pid; + else if (strcmp("candidate", db) == 0) + _candidate_locked = pid; + else if (strcmp("startup", db) == 0) + _startup_locked = pid; + clicon_debug(1, "%s: locked by %u", db, pid); + return 0; +} + +/*! Unlock database + * @param[in] h Clicon handle + * @param[in] db Database + * @param[in] pid Process id + * @retval -1 Error + * @retval 0 OK + * Assume all sanity checks have been made + */ +int +text_unlock(clicon_handle h, + char *db, + int pid) +{ + if (strcmp("running", db) == 0) + _running_locked = 0; + else if (strcmp("candidate", db) == 0) + _candidate_locked = 0; + else if (strcmp("startup", db) == 0) + _startup_locked = 0; + return 0; +} + +/*! Unlock all databases locked by pid (eg process dies) + * @param[in] h Clicon handle + * @param[in] pid Process / Session id + * @retval -1 Error + * @retval 0 Ok + */ +int +text_unlock_all(clicon_handle h, + int pid) +{ + if (_running_locked == pid) + _running_locked = 0; + if (_candidate_locked == pid) + _candidate_locked = 0; + if (_startup_locked == pid) + _startup_locked = 0; + return 0; +} + +/*! Check if database is locked + * @param[in] h Clicon handle + * @param[in] db Database + * @retval -1 Error + * @retval 0 Not locked + * @retval >0 Id of locker + */ +int +text_islocked(clicon_handle h, + char *db) +{ + if (strcmp("running", db) == 0) + return (_running_locked); + else if (strcmp("candidate", db) == 0) + return(_candidate_locked); + else if (strcmp("startup", db) == 0) + return(_startup_locked); + return 0; +} + +/*! Check if db exists + * @param[in] h Clicon handle + * @param[in] db Database + * @retval -1 Error + * @retval 0 No it does not exist + * @retval 1 Yes it exists + */ +int +text_exists(clicon_handle h, + char *db) +{ + int retval = -1; + char *filename = NULL; + struct stat sb; + + if (db2file(h, db, &filename) < 0) + goto done; + if (lstat(filename, &sb) < 0) + retval = 0; + else + retval = 1; + done: + if (filename) + free(filename); + return retval; +} + +/*! Delete database. Remove file + * @param[in] h Clicon handle + * @param[in] db Database + * @retval -1 Error + * @retval 0 OK + */ +int +text_delete(clicon_handle h, + char *db) +{ + int retval = -1; + + retval = 0; + // done: + return retval; +} + +/*! Initialize database + * @param[in] h Clicon handle + * @param[in] db Database + * @retval 0 OK + * @retval -1 Error + */ +int +text_init(clicon_handle h, + char *db) +{ + int retval = -1; + + retval = 0; + // done: + return retval; +} + +/*! plugin init function */ +int +text_plugin_exit(void) +{ + return 0; +} + +static const struct xmldb_api api; + +/*! plugin init function */ +void * +clixon_xmldb_plugin_init(int version) +{ + if (version != XMLDB_API_VERSION){ + clicon_err(OE_DB, 0, "Invalid version %d expected %d", + version, XMLDB_API_VERSION); + goto done; + } + return (void*)&api; + done: + return NULL; +} + +static const struct xmldb_api api = { + 1, + XMLDB_API_MAGIC, + clixon_xmldb_plugin_init, + text_plugin_exit, + text_get, + text_put, + text_dump, + text_copy, + text_lock, + text_unlock, + text_unlock_all, + text_islocked, + text_exists, + text_delete, + text_init, +}; + + +#if 0 /* Test program */ +/* + * Turn this on to get an xpath test program + * Usage: clicon_xpath [] + * read xml from input + * Example compile: + gcc -g -o xmldb -I. -I../clixon ./clixon_xmldb.c -lclixon -lcligen +*/ + +static int +usage(char *argv0) +{ + fprintf(stderr, "usage:\n%s\tget []\t\txml on stdin\n", argv0); + fprintf(stderr, "\tput set|merge|delete\txml to stdout\n"); + exit(0); +} + +int +main(int argc, char **argv) +{ + cxobj *xt; + cxobj *xn; + char *xpath; + enum operation_type op; + char *cmd; + char *db; + char *yangdir; + char *yangmod; + yang_spec *yspec = NULL; + clicon_handle h; + + if ((h = clicon_handle_init()) == NULL) + goto done; + clicon_log_init("xmldb", LOG_DEBUG, CLICON_LOG_STDERR); + if (argc < 4){ + usage(argv[0]); + goto done; + } + cmd = argv[1]; + db = argv[2]; + yangdir = argv[3]; + yangmod = argv[4]; + db_init(db); + if ((yspec = yspec_new()) == NULL) + goto done + if (yang_parse(h, yangdir, yangmod, NULL, yspec) < 0) + goto done; + if (strcmp(cmd, "get")==0){ + if (argc < 5) + usage(argv[0]); + xpath = argc>5?argv[5]:NULL; + if (xmldb_get(h, db, xpath, &xt, NULL, NULL) < 0) + goto done; + clicon_xml2file(stdout, xt, 0, 1); + } + else + if (strcmp(cmd, "put")==0){ + if (argc != 6) + usage(argv[0]); + if (clicon_xml_parse_file(0, &xt, "") < 0) + goto done; + if (xml_rootchild(xt, 0, &xn) < 0) + goto done; + if (strcmp(argv[5], "set") == 0) + op = OP_REPLACE; + else + if (strcmp(argv[4], "merge") == 0) + op = OP_MERGE; + else if (strcmp(argv[5], "delete") == 0) + op = OP_REMOVE; + else + usage(argv[0]); + if (xmldb_put(h, db, op, NULL, xn) < 0) + goto done; + } + else + usage(argv[0]); + printf("\n"); + done: + return 0; +} + +#endif /* Test program */ diff --git a/datastore/text/clixon_xmldb_text.h b/datastore/text/clixon_xmldb_text.h new file mode 100644 index 00000000..b2ca183d --- /dev/null +++ b/datastore/text/clixon_xmldb_text.h @@ -0,0 +1,56 @@ +/* + * + ***** BEGIN LICENSE BLOCK ***** + + Copyright (C) 2009-2017 Olof Hagsand and Benny Holmgren + + This file is part of CLIXON. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Alternatively, the contents of this file may be used under the terms of + the GNU General Public License Version 3 or later (the "GPL"), + in which case the provisions of the GPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of the GPL, and not to allow others to + use your version of this file under the terms of Apache License version 2, + indicate your decision by deleting the provisions above and replace them with + the notice and other provisions required by the GPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the Apache License version 2 or the GPL. + + ***** END LICENSE BLOCK ***** + + Key-value store + */ +#ifndef _CLIXON_XMLDB_TEXT_H +#define _CLIXON_XMLDB_TEXT_H + +/* + * Prototypes + */ +int text_get(clicon_handle h, char *db, char *xpath, + cxobj **xtop, cxobj ***xvec, size_t *xlen); +int text_put(clicon_handle h, char *db, enum operation_type op, + char *api_path, cxobj *xt); +int text_dump(FILE *f, char *dbfilename, char *rxkey); +int text_copy(clicon_handle h, char *from, char *to); +int text_lock(clicon_handle h, char *db, int pid); +int text_unlock(clicon_handle h, char *db, int pid); +int text_unlock_all(clicon_handle h, int pid); +int text_islocked(clicon_handle h, char *db); +int text_exists(clicon_handle h, char *db); +int text_delete(clicon_handle h, char *db); +int text_init(clicon_handle h, char *db); + +#endif /* _CLIXON_XMLDB_TEXT_H */ diff --git a/lib/clixon/clixon.h b/lib/clixon/clixon.h deleted file mode 100644 index 4ccdcab5..00000000 --- a/lib/clixon/clixon.h +++ /dev/null @@ -1,91 +0,0 @@ -/* lib/clixon/clixon.h. Generated from clixon.h.in by configure. */ -/* - * - ***** BEGIN LICENSE BLOCK ***** - - Copyright (C) 2009-2017 Olof Hagsand and Benny Holmgren - - This file is part of CLIXON. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - Alternatively, the contents of this file may be used under the terms of - the GNU General Public License Version 3 or later (the "GPL"), - in which case the provisions of the GPL are applicable instead - of those above. If you wish to allow use of your version of this file only - under the terms of the GPL, and not to allow others to - use your version of this file under the terms of Apache License version 2, - indicate your decision by deleting the provisions above and replace them with - the notice and other provisions required by the GPL. If you do not delete - the provisions above, a recipient may use your version of this file under - the terms of any one of the Apache License version 2 or the GPL. - - ***** END LICENSE BLOCK ***** - - * Meta-include file that includes all sub-files in control-lib - * Note: this include files is for external purposes. Do not include this - * file in clicon lib-routines. - */ - -/* This include file requires the following include file dependencies */ -#include -#include -#include -#include -#include -#include - -/* - * CLIXON version macros - */ - -#define CLIXON_VERSION_STRING "3.2.0" -#define CLIXON_VERSION_MAJOR 3 -#define CLIXON_VERSION_MINOR 2 -#define CLIXON_VERSION_PATCH 0 - -/* - * 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. - */ -#define LIBCLIXON_API 1 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Global variables generated by Makefile - */ -extern const char CLIXON_BUILDSTR[]; -extern const char CLIXON_VERSION[]; diff --git a/lib/clixon/clixon.h.in b/lib/clixon/clixon.h.in index 5d39d819..907aba4f 100644 --- a/lib/clixon/clixon.h.in +++ b/lib/clixon/clixon.h.in @@ -31,6 +31,9 @@ ***** END LICENSE BLOCK ***** + * NOTE: clixon.h is a GENERATED FILE and should not be edited. + * clixon.h.in is the original + * * Meta-include file that includes all sub-files in control-lib * Note: this include files is for external purposes. Do not include this * file in clicon lib-routines. @@ -67,13 +70,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include