mod_netconf: change includes and flags according to libnetconf API
diff --git a/src/Makefile.in b/src/Makefile.in
index e899de3..b3c983d 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -23,8 +23,7 @@
 
 APXS=/usr/sbin/apxs
 
-CFLAGS=-I/usr/include/json
-CPPFLAGS=@CPPFLAGS@
+CFLAGS=@CFLAGS@
 LIBS=@LIBS@
 
 SRCS=mod_netconf.c \
@@ -38,7 +37,7 @@
 all: module client
 
 module: mod_netconf.c
-	$(APXS) $(LIBS) $(ARCSID) $(CPPFLAGS) -c mod_netconf.c notification-server.c
+	$(APXS) $(LIBS) $(ARCSID) $(CFLAGS) -c mod_netconf.c notification-server.c
 
 client: test-client.c
 	gcc $(RCSID) -std=gnu99 -Wall -g -ljson -I/usr/include/json test-client.c -o test-client
diff --git a/src/configure b/src/configure
index d64ca9b..9df5666 100755
--- a/src/configure
+++ b/src/configure
@@ -651,6 +651,10 @@
 LDFLAGS
 CFLAGS
 CC
+LIBNETCONF_WITH
+LIBNETCONF_LIBS
+LIBNETCONF_CFLAGS
+PKG_CONFIG
 RELEASE
 RPMBUILD
 INSTALL_DATA
@@ -696,11 +700,15 @@
 ac_subst_files=''
 ac_user_opts='
 enable_option_checking
+with_libnetconf
 with_notifications
 '
       ac_precious_vars='build_alias
 host_alias
 target_alias
+PKG_CONFIG
+LIBNETCONF_CFLAGS
+LIBNETCONF_LIBS
 CC
 CFLAGS
 LDFLAGS
@@ -1327,9 +1335,16 @@
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
-  --with-notifications    Enable notifications
+  --with-libnetconf=PATH  Set the path to libnetconf (usually local GIT
+                          repository)
+  --without-notifications Disable notifications
 
 Some influential environment variables:
+  PKG_CONFIG  path to pkg-config utility
+  LIBNETCONF_CFLAGS
+              C compiler flags for LIBNETCONF, overriding pkg-config
+  LIBNETCONF_LIBS
+              linker flags for LIBNETCONF, overriding pkg-config
   CC          C compiler command
   CFLAGS      C compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -1970,6 +1985,251 @@
 BUILDREQS="$BUILDREQS json-c-devel httpd-devel"
 
 # Checks for libraries.
+# libnetconf
+
+
+if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
+	if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args.
+set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_PKG_CONFIG+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  case $PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+  { $as_echo "$as_me:$LINENO: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_path_PKG_CONFIG"; then
+  ac_pt_PKG_CONFIG=$PKG_CONFIG
+  # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_ac_pt_PKG_CONFIG+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  case $ac_pt_PKG_CONFIG in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+    ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG
+if test -n "$ac_pt_PKG_CONFIG"; then
+  { $as_echo "$as_me:$LINENO: result: $ac_pt_PKG_CONFIG" >&5
+$as_echo "$ac_pt_PKG_CONFIG" >&6; }
+else
+  { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_pt_PKG_CONFIG" = x; then
+    PKG_CONFIG=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    PKG_CONFIG=$ac_pt_PKG_CONFIG
+  fi
+else
+  PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
+fi
+
+fi
+if test -n "$PKG_CONFIG"; then
+	_pkg_min_version=0.9.0
+	{ $as_echo "$as_me:$LINENO: checking pkg-config is at least version $_pkg_min_version" >&5
+$as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; }
+	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+		{ $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+	else
+		{ $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+		PKG_CONFIG=""
+	fi
+
+fi
+
+# Check whether --with-libnetconf was given.
+if test "${with_libnetconf+set}" = set; then
+  withval=$with_libnetconf; # local copy of libnetconf GIT repo with headers and binaries
+	LIBNETCONF_CFLAGS="-I`cd $withval;pwd`"
+	LIBNETCONF_LIBS="-L`cd $withval;pwd` -lnetconf"
+    LIBNETCONF_WITH=" --with-libnetconf=$withval"
+else
+  # get info from pkg-config about installed package
+
+pkg_failed=no
+{ $as_echo "$as_me:$LINENO: checking for LIBNETCONF" >&5
+$as_echo_n "checking for LIBNETCONF... " >&6; }
+
+if test -n "$LIBNETCONF_CFLAGS"; then
+    pkg_cv_LIBNETCONF_CFLAGS="$LIBNETCONF_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { ($as_echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"libnetconf\"") >&5
+  ($PKG_CONFIG --exists --print-errors "libnetconf") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  pkg_cv_LIBNETCONF_CFLAGS=`$PKG_CONFIG --cflags "libnetconf" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$LIBNETCONF_LIBS"; then
+    pkg_cv_LIBNETCONF_LIBS="$LIBNETCONF_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { ($as_echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"libnetconf\"") >&5
+  ($PKG_CONFIG --exists --print-errors "libnetconf") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  pkg_cv_LIBNETCONF_LIBS=`$PKG_CONFIG --libs "libnetconf" 2>/dev/null`
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        LIBNETCONF_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libnetconf" 2>&1`
+        else
+	        LIBNETCONF_PKG_ERRORS=`$PKG_CONFIG --print-errors "libnetconf" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$LIBNETCONF_PKG_ERRORS" >&5
+
+	{ { $as_echo "$as_me:$LINENO: error: Package requirements (libnetconf) were not met:
+
+$LIBNETCONF_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables LIBNETCONF_CFLAGS
+and LIBNETCONF_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+" >&5
+$as_echo "$as_me: error: Package requirements (libnetconf) were not met:
+
+$LIBNETCONF_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables LIBNETCONF_CFLAGS
+and LIBNETCONF_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+" >&2;}
+   { (exit 1); exit 1; }; }
+elif test $pkg_failed = untried; then
+	{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables LIBNETCONF_CFLAGS
+and LIBNETCONF_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables LIBNETCONF_CFLAGS
+and LIBNETCONF_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+else
+	LIBNETCONF_CFLAGS=$pkg_cv_LIBNETCONF_CFLAGS
+	LIBNETCONF_LIBS=$pkg_cv_LIBNETCONF_LIBS
+        { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+	:
+fi
+    BUILDREQS="$BUILDREQS ,libnetconf-devel"
+
+fi
+
+CFLAGS="$CFLAGS $LIBNETCONF_CFLAGS"
+LIBS="$LIBS $LIBNETCONF_LIBS"
+
+
+
+REQS="$REQS , libnetconf"
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -2904,12 +3164,14 @@
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
-{ $as_echo "$as_me:$LINENO: checking for library containing ncds_apply_rpc" >&5
-$as_echo_n "checking for library containing ncds_apply_rpc... " >&6; }
-if test "${ac_cv_search_ncds_apply_rpc+set}" = set; then
+
+{ $as_echo "$as_me:$LINENO: checking for ncds_new in -lnetconf" >&5
+$as_echo_n "checking for ncds_new in -lnetconf... " >&6; }
+if test "${ac_cv_lib_netconf_ncds_new+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  ac_func_search_save_LIBS=$LIBS
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lnetconf  $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -2923,23 +3185,16 @@
 #ifdef __cplusplus
 extern "C"
 #endif
-char ncds_apply_rpc ();
+char ncds_new ();
 int
 main ()
 {
-return ncds_apply_rpc ();
+return ncds_new ();
   ;
   return 0;
 }
 _ACEOF
-for ac_lib in '' netconf; do
-  if test -z "$ac_lib"; then
-    ac_res="none required"
-  else
-    ac_res=-l$ac_lib
-    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
-  fi
-  rm -f conftest.$ac_objext conftest$ac_exeext
+rm -f conftest.$ac_objext conftest$ac_exeext
 if { (ac_try="$ac_link"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
@@ -2960,44 +3215,34 @@
 	 test "$cross_compiling" = yes ||
 	 $as_test_x conftest$ac_exeext
        }; then
-  ac_cv_search_ncds_apply_rpc=$ac_res
+  ac_cv_lib_netconf_ncds_new=yes
 else
   $as_echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-
+	ac_cv_lib_netconf_ncds_new=no
 fi
 
 rm -rf conftest.dSYM
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
-      conftest$ac_exeext
-  if test "${ac_cv_search_ncds_apply_rpc+set}" = set; then
-  break
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
 fi
-done
-if test "${ac_cv_search_ncds_apply_rpc+set}" = set; then
-  :
-else
-  ac_cv_search_ncds_apply_rpc=no
-fi
-rm conftest.$ac_ext
-LIBS=$ac_func_search_save_LIBS
-fi
-{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_ncds_apply_rpc" >&5
-$as_echo "$ac_cv_search_ncds_apply_rpc" >&6; }
-ac_res=$ac_cv_search_ncds_apply_rpc
-if test "$ac_res" != no; then
-  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_netconf_ncds_new" >&5
+$as_echo "$ac_cv_lib_netconf_ncds_new" >&6; }
+if test "x$ac_cv_lib_netconf_ncds_new" = x""yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBNETCONF 1
+_ACEOF
+
+  LIBS="-lnetconf $LIBS"
 
 else
-  { { $as_echo "$as_me:$LINENO: error: libnetconf not found!" >&5
-$as_echo "$as_me: error: libnetconf not found!" >&2;}
+  { { $as_echo "$as_me:$LINENO: error: libnetconf not found." >&5
+$as_echo "$as_me: error: libnetconf not found." >&2;}
    { (exit 1); exit 1; }; }
 fi
 
-REQS="$REQS libnetconf >= 0.4.0 libwebsockets"
-BUILDREQS="$BUILDREQS libnetconf-devel libwebsockets-devel"
-CPPFLAGS=""
 
 # Checks for header files.
 ac_ext=c
@@ -3773,16 +4018,24 @@
 
 # Check whether --with-notifications was given.
 if test "${with_notifications+set}" = set; then
-  withval=$with_notifications;
-		CPPFLAGS=" -DWITH_NOTIFICATIONS "
+  withval=$with_notifications; if test "x$with_notifications" == "xno"; then
+  CFLAGS="$CFLAGS"
+else
+   CFLAGS="$CFLAGS -DWITH_NOTIFICATIONS "
 		LIBS="-lwebsockets $LIBS"
 
+fi
+
 else
-  CPPFLAGS="$CPPFLAGS"
+
+		CFLAGS="$CFLAGS -DWITH_NOTIFICATIONS "
+		LIBS="-lwebsockets $LIBS"
+
 
 fi
 
 
+CFLAGS="$CFLAGS -I/usr/include/json"
 
 
 
diff --git a/src/configure.in b/src/configure.in
index 26715ae..6b91bf3 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -28,10 +28,24 @@
 BUILDREQS="$BUILDREQS json-c-devel httpd-devel"
 
 # Checks for libraries.
-AC_SEARCH_LIBS([ncds_apply_rpc],[netconf], ,AC_MSG_ERROR([libnetconf not found!]))
-REQS="$REQS libnetconf >= 0.4.0 libwebsockets"
-BUILDREQS="$BUILDREQS libnetconf-devel libwebsockets-devel"
-CPPFLAGS=""
+# libnetconf
+AC_ARG_WITH([libnetconf],
+	AC_HELP_STRING([--with-libnetconf=PATH],[Set the path to libnetconf (usually local GIT repository)]),
+	[# local copy of libnetconf GIT repo with headers and binaries
+	LIBNETCONF_CFLAGS="-I`cd $withval;pwd`"
+	LIBNETCONF_LIBS="-L`cd $withval;pwd` -lnetconf"
+    LIBNETCONF_WITH=" --with-libnetconf=$withval"],
+	[# get info from pkg-config about installed package
+	PKG_CHECK_MODULES(LIBNETCONF, libnetconf)
+    BUILDREQS="$BUILDREQS ,libnetconf-devel"]
+)
+CFLAGS="$CFLAGS $LIBNETCONF_CFLAGS"
+LIBS="$LIBS $LIBNETCONF_LIBS"
+AC_SUBST([LIBNETCONF_LIBS])
+AC_SUBST([LIBNETCONF_CFLAGS])
+AC_SUBST([LIBNETCONF_WITH])
+REQS="$REQS , libnetconf"
+AC_CHECK_LIB([netconf], [ncds_new],[],AC_MSG_ERROR([libnetconf not found.]))
 
 # Checks for header files.
 AC_CHECK_HEADER([libnetconf.h], ,AC_MSG_ERROR([libnetconf.h not found!]))
@@ -47,17 +61,21 @@
 
 
 AC_ARG_WITH([notifications],
-	[AC_HELP_STRING([--with-notifications], [Enable notifications])],
-	[
-		CPPFLAGS=" -DWITH_NOTIFICATIONS "
+	[AC_HELP_STRING([--without-notifications], [Disable notifications])],
+	AS_IF([test "x$with_notifications" == "xno"],[CFLAGS="$CFLAGS"],
+	[ CFLAGS="$CFLAGS -DWITH_NOTIFICATIONS "
 		LIBS="-lwebsockets $LIBS"
-	],
-	[CPPFLAGS="$CPPFLAGS"]
+	]),
+	[
+		CFLAGS="$CFLAGS -DWITH_NOTIFICATIONS "
+		LIBS="-lwebsockets $LIBS"
+	]
 )
 
+CFLAGS="$CFLAGS -I/usr/include/json"
 AC_SUBST(REQS)
 AC_SUBST(BUILDREQS)
-AC_SUBST(CPPFLAGS)
+AC_SUBST(CFLAGS)
 AC_SUBST(RCSID)
 AC_SUBST(ARCSID)
 AC_SUBST(LIBS)
diff --git a/src/mod_netconf.c b/src/mod_netconf.c
index 63adc23..f3a8631 100644
--- a/src/mod_netconf.c
+++ b/src/mod_netconf.c
@@ -67,6 +67,7 @@
 #include <json/json.h>
 
 #include <libnetconf.h>
+#include <libnetconf_ssh.h>
 
 #ifdef WITH_NOTIFICATIONS
 #include "notification_module.h"
@@ -227,7 +228,7 @@
 	ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "prepare to connect %s@%s:%s", user, host, port);
 	nc_verbosity(NC_VERB_DEBUG);
 	session = nc_session_connect(host, (unsigned short) atoi (port), user, cpblts);
-	ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "nc_session_connect done (%x)", (int) session);
+	ap_log_error(APLOG_MARK, APLOG_ERR, 0, server, "nc_session_connect done (%p)", session);
 
 	/* if connected successful, add session to the list */
 	if (session != NULL) {