]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11880: [Core,mod_pgsql] Remove native PostgreSQL support from the core, add mod_pg...
authorAndrey Volk <andywolk@gmail.com>
Fri, 7 Jun 2019 17:32:00 +0000 (21:32 +0400)
committerAndrey Volk <andywolk@gmail.com>
Wed, 17 Jul 2019 20:20:50 +0000 (00:20 +0400)
32 files changed:
Freeswitch.2017.sln
Makefile.am
build/modules.conf.in
build/modules.conf.most
conf/rayo/autoload_configs/pre_load_modules.conf.xml [new file with mode: 0644]
conf/rayo/autoload_configs/switch.conf.xml
conf/testing/autoload_configs/pre_load_modules.conf.xml [new file with mode: 0644]
conf/testing/autoload_configs/switch.conf.xml
conf/vanilla/autoload_configs/pre_load_modules.conf.xml [new file with mode: 0644]
conf/vanilla/autoload_configs/switch.conf.xml
configure.ac
debian/bootstrap.sh
debian/control-modules
debian/rules
freeswitch.spec
src/include/switch.h
src/include/switch_core.h
src/include/switch_module_interfaces.h
src/include/switch_pgsql.h [deleted file]
src/include/switch_types.h
src/mod/applications/mod_directory/mod_directory.c
src/mod/applications/mod_fifo/mod_fifo.c
src/mod/databases/mod_pgsql/Makefile.am [new file with mode: 0644]
src/mod/databases/mod_pgsql/mod_pgsql.2017.vcxproj [new file with mode: 0644]
src/mod/databases/mod_pgsql/mod_pgsql.c [moved from src/switch_pgsql.c with 55% similarity]
src/mod/event_handlers/mod_cdr_pg_csv/Makefile.am
src/mod/languages/mod_managed/freeswitch_wrap.cxx
src/mod/languages/mod_managed/managed/examples/winFailToBan/winFailToBan.csproj
src/mod/languages/mod_managed/managed/swig.cs
src/switch_core_sqldb.c
w32/Library/FreeSwitchCore.2017.vcxproj
w32/Setup/Setup.2017.wixproj

index d6b9e278750f3031e467937452c5888810a041d0..d649654ac52016324f82701671052c5aaa6f0ddb 100644 (file)
@@ -580,6 +580,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ffmpeg", "libs\win32\ffmpeg
 EndProject\r
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Setup.CA.DownloadOpenH264", "w32\Setup\CustomActions\Setup.CA.DownloadOpenH264\Setup.CA.DownloadOpenH264.csproj", "{EBFDCFCA-8095-4ECC-98BE-B494BCB4E042}"\r
 EndProject\r
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Databases", "Databases", "{31C2761D-20E0-4BF8-98B9-E32F0D8DD6E1}"\r
+EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_pgsql", "src\mod\databases\mod_pgsql\mod_pgsql.2017.vcxproj", "{1BA65811-5453-46F6-8190-9ECEEFEB7DF2}"\r
+EndProject\r
 Global\r
        GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
                All|Win32 = All|Win32\r
@@ -2659,6 +2663,18 @@ Global
                {EBFDCFCA-8095-4ECC-98BE-B494BCB4E042}.Release|Win32.Build.0 = Release|x86\r
                {EBFDCFCA-8095-4ECC-98BE-B494BCB4E042}.Release|x64.ActiveCfg = Release|x86\r
                {EBFDCFCA-8095-4ECC-98BE-B494BCB4E042}.Release|x64.Build.0 = Release|x86\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.All|Win32.ActiveCfg = Release|Win32\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.All|Win32.Build.0 = Release|Win32\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.All|x64.ActiveCfg = Release|x64\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.All|x64.Build.0 = Release|x64\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.Debug|Win32.Build.0 = Debug|Win32\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.Debug|x64.ActiveCfg = Debug|x64\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.Debug|x64.Build.0 = Debug|x64\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.Release|Win32.ActiveCfg = Release|Win32\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.Release|Win32.Build.0 = Release|Win32\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.Release|x64.ActiveCfg = Release|x64\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2}.Release|x64.Build.0 = Release|x64\r
        EndGlobalSection\r
        GlobalSection(SolutionProperties) = preSolution\r
                HideSolutionNode = FALSE\r
@@ -2869,6 +2885,7 @@ Global
                {EBD0B6B4-C5CA-46B0-BBC7-DBA71DF05D31} = {4F227C26-768F-46A3-8684-1D08A46FB374}\r
                {B19AE6FC-BFFF-428D-B483-3BBEAECCC618} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}\r
                {BC1FD72E-1CD5-4525-A7F5-17C5740BFDED} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B}\r
+               {1BA65811-5453-46F6-8190-9ECEEFEB7DF2} = {31C2761D-20E0-4BF8-98B9-E32F0D8DD6E1}\r
        EndGlobalSection\r
        GlobalSection(ExtensibilityGlobals) = postSolution\r
                SolutionGuid = {09840DE7-9208-45AA-9667-1A71EE93BD1E}\r
index fb81a6f175728eefb1032058265300ad97823123..510448655e683ef911c1791d4a9ad8e41767ef6b 100644 (file)
@@ -326,7 +326,6 @@ library_include_HEADERS = \
        libs/libteletone/src/libteletone.h \
        src/include/switch_limit.h \
        src/include/switch_odbc.h \
-       src/include/switch_pgsql.h \
        src/include/switch_hashtable.h \
        src/include/switch_image.h
 
@@ -390,7 +389,6 @@ libfreeswitch_la_SOURCES = \
        src/switch_config.c \
        src/switch_time.c \
        src/switch_odbc.c \
-       src/switch_pgsql.c \
        src/switch_limit.c \
        src/g711.c \
        src/switch_pcm.c \
index 98f4b7d7fca74a597241596ada783d95d0d2e75a..6b26354d8f10dc603864241df5c6c7b47f235d08 100644 (file)
@@ -79,6 +79,7 @@ codecs/mod_opus
 #codecs/mod_silk
 #codecs/mod_siren
 #codecs/mod_theora
+databases/mod_pgsql
 dialplans/mod_dialplan_asterisk
 #dialplans/mod_dialplan_directory
 dialplans/mod_dialplan_xml
index a4946004d2e4546a2322070825aace21a71f4512..c142b1a3d7bdf98b84d40726c608206718506f42 100644 (file)
@@ -76,6 +76,7 @@ codecs/mod_sangoma_codec
 codecs/mod_silk
 codecs/mod_siren
 codecs/mod_theora
+databases/mod_pgsql
 dialplans/mod_dialplan_asterisk
 dialplans/mod_dialplan_directory
 dialplans/mod_dialplan_xml
diff --git a/conf/rayo/autoload_configs/pre_load_modules.conf.xml b/conf/rayo/autoload_configs/pre_load_modules.conf.xml
new file mode 100644 (file)
index 0000000..659bf7b
--- /dev/null
@@ -0,0 +1,6 @@
+<configuration name="pre_load_modules.conf" description="Modules">\r
+  <modules>\r
+    <!-- Databases -->\r
+    <load module="mod_pgsql"/>\r
+  </modules>\r
+</configuration>\r
index e618069ab217cdd5a5fb2e2f3845d5d37a4d3eef..7b26088a55d62e619904c2ada23c7ae585bd9192 100644 (file)
 
     <param name="rtp-enable-zrtp" value="true"/>
 
+    <!--
+        Native PostgreSQL support was removed from the FreeSWITCH Core!
+        =================================
+        NOTICE: You MUST enable mod_pgsql        
+        =================================
+        According to https://www.postgresql.org/docs/9.6/libpq-connect.html#LIBPQ-CONNSTRING
+        There are two accepted formats for connection strings supported by the libpq library: 
+        * For plain keyword = value strings use pgsql://
+          pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE' application_name='freeswitch'
+        * For RFC 3986 URIs use postgresql:// or postgres://
+          postgresql://
+          postgresql://localhost
+          postgresql://localhost:5433
+          postgresql://localhost/mydb
+          postgresql://user@localhost
+          postgresql://user:secret@localhost
+          postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
+          postgresql:///mydb?host=localhost&port=5433
+    -->
     <!-- <param name="core-db-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE' application_name='freeswitch'" /> -->
+    <!-- <param name="core-db-dsn" value="postgresql://freeswitch:@127.0.0.1/freeswitch?options=-c%20client_min_messages%3DNOTICE&application_name=freeswitch" /> -->
     <!-- <param name="core-db-dsn" value="dsn:username:password" /> -->
     <!-- 
         Allow to specify the sqlite db at a different location (In this example, move it to ramdrive for
diff --git a/conf/testing/autoload_configs/pre_load_modules.conf.xml b/conf/testing/autoload_configs/pre_load_modules.conf.xml
new file mode 100644 (file)
index 0000000..659bf7b
--- /dev/null
@@ -0,0 +1,6 @@
+<configuration name="pre_load_modules.conf" description="Modules">\r
+  <modules>\r
+    <!-- Databases -->\r
+    <load module="mod_pgsql"/>\r
+  </modules>\r
+</configuration>\r
index 8e66e7159f5baa8d6fea63cee148078017a7c190..36158810df84e5ee6ee2db322f9ba0b49b496da4 100644 (file)
 
     <param name="rtp-enable-zrtp" value="true"/>
 
+    <!--
+        Native PostgreSQL support was removed from the FreeSWITCH Core!
+        =================================
+        NOTICE: You MUST enable mod_pgsql        
+        =================================
+        According to https://www.postgresql.org/docs/9.6/libpq-connect.html#LIBPQ-CONNSTRING
+        There are two accepted formats for connection strings supported by the libpq library: 
+        * For plain keyword = value strings use pgsql://
+          pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE'
+        * For RFC 3986 URIs use postgresql:// or postgres://
+          postgresql://
+          postgresql://localhost
+          postgresql://localhost:5433
+          postgresql://localhost/mydb
+          postgresql://user@localhost
+          postgresql://user:secret@localhost
+          postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
+          postgresql:///mydb?host=localhost&port=5433
+    -->
     <!-- <param name="core-db-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE'" /> -->
+    <!-- <param name="core-db-dsn" value="postgresql://freeswitch:@127.0.0.1/freeswitch?options=-c%20client_min_messages%3DNOTICE" /> -->
     <!-- <param name="core-db-dsn" value="dsn:username:password" /> -->
     <!-- 
         Allow to specify the sqlite db at a different location (In this example, move it to ramdrive for
diff --git a/conf/vanilla/autoload_configs/pre_load_modules.conf.xml b/conf/vanilla/autoload_configs/pre_load_modules.conf.xml
new file mode 100644 (file)
index 0000000..659bf7b
--- /dev/null
@@ -0,0 +1,6 @@
+<configuration name="pre_load_modules.conf" description="Modules">\r
+  <modules>\r
+    <!-- Databases -->\r
+    <load module="mod_pgsql"/>\r
+  </modules>\r
+</configuration>\r
index ababe548ac447f99245079c7fc929b31a0d86699..679862cc68ee66102426979c18740dbacb7f4617 100644 (file)
     -->
     <!-- <param name="rtp-retain-crypto-keys" value="true"/> -->
 
+    <!--
+        Native PostgreSQL support was removed from the FreeSWITCH Core!
+        =================================
+        NOTICE: You MUST enable mod_pgsql        
+        =================================
+        According to https://www.postgresql.org/docs/9.6/libpq-connect.html#LIBPQ-CONNSTRING
+        There are two accepted formats for connection strings supported by the libpq library: 
+        * For plain keyword = value strings use pgsql://
+          pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE'
+        * For RFC 3986 URIs use postgresql:// or postgres://
+          postgresql://
+          postgresql://localhost
+          postgresql://localhost:5433
+          postgresql://localhost/mydb
+          postgresql://user@localhost
+          postgresql://user:secret@localhost
+          postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
+          postgresql:///mydb?host=localhost&port=5433
+    -->
     <!-- <param name="core-db-dsn" value="pgsql://hostaddr=127.0.0.1 dbname=freeswitch user=freeswitch password='' options='-c client_min_messages=NOTICE'" /> -->
+    <!-- <param name="core-db-dsn" value="postgresql://freeswitch:@127.0.0.1/freeswitch?options=-c%20client_min_messages%3DNOTICE" /> -->
     <!-- <param name="core-db-dsn" value="dsn:username:password" /> -->
     <!-- 
         Allow to specify the sqlite db at a different location (In this example, move it to ramdrive for
index e53937567752092abd86441aea7c4a7e64c04435..70b559c4f029a53447f6f0d2378ae2afc79667a8 100644 (file)
@@ -643,60 +643,67 @@ CHECK_LIBUUID
 SWITCH_AM_LDFLAGS="$LIBUUID_LIBS $SWITCH_AM_LDFLAGS"
 SWITCH_AM_CFLAGS="$LIBUUID_CFLAGS $SWITCH_AM_CFLAGS"
 
-AC_ARG_ENABLE(core-pgsql-support,     
-       [AS_HELP_STRING([--enable-core-pgsql-support], [Compile with PGSQL Support])],,[enable_core_pgsql_support="no"])
 AC_ARG_ENABLE(core-pgsql-pkgconfig,
        [AS_HELP_STRING([--disable-core-pgsql-pkgconfig], [Use pg_config to get PGQSL build options])],[enable_core_pgsql_pkgconfig="$enableval"],[enable_core_pgsql_pkgconfig="yes"])
 
-if test x"$enable_core_pgsql_support" = x"yes" ; then
-  AC_PATH_PROG([PG_CONFIG], [pg_config], [no])
-  AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no])
-    if test "$PKG_CONFIG" = "no" \
-       || test x"$enable_core_pgsql_pkgconfig" = x"no" \
-       || ! pkg-config libpq; then
+path_remove () {
+  echo "$1" | tr ':' '\n' | grep -Fxv "$2" | tr '\n' ':' | sed 's/:$//'
+}
+path_push_unique () {
+  x="$(eval echo \$$1)"
+  x="$(path_remove "$x" "$2")"
+  if test -z "$x"; then
+    eval export $1="$2"
+  else
+    eval export $1="$2:$x"
+  fi
+}
+
+AC_PATH_PROG([PG_CONFIG], [pg_config], [no])
+AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no])
+
+case $host in
+     *-darwin*)
+       path_push_unique PKG_CONFIG_PATH /usr/local/opt/libpq/lib/pkgconfig
+     ;;
+esac
+
+if test "$PKG_CONFIG" = "no" \
+       || test x"$enable_core_pgsql_pkgconfig" = x"no" \
+       || ! pkg-config libpq; then
        if test "$PG_CONFIG" != "no"; then
-            AC_MSG_CHECKING([for PostgreSQL libraries via pg_config])
-            POSTGRESQL_CFLAGS="-I`$PG_CONFIG --includedir`"
-            POSTGRESQL_LIBDIR="-L`$PG_CONFIG --libdir`"
-            POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir` -lpq"
-            POSTGRESQL_VERSION=`$PG_CONFIG --version | awk '{ print $NF }'`
-            POSTGRESQL_MAJOR_VERSION=`$PG_CONFIG --version | awk '{ print $NF }' | awk -F. '{ print $1 }'`
-            POSTGRESQL_MINOR_VERSION=`$PG_CONFIG --version | awk '{ print $NF }' | awk -F. '{ print $2 }'`
-            POSTGRESQL_PATCH_VERSION=`$PG_CONFIG --version | awk '{ print $NF }' | awk -F. '{ print $3 }'`
-        else
-            AC_MSG_ERROR([no usable pkg-config or pg_config; please install libpq devel package or equivalent])
-        fi
-    else
-      AC_MSG_CHECKING([for PostgreSQL libraries via pkg_config])
-      POSTGRESQL_CFLAGS="`$PKG_CONFIG --cflags libpq`"
-      POSTGRESQL_LIBDIR="`$PKG_CONFIG libpq --libs-only-L`"
-      POSTGRESQL_LDFLAGS="`$PKG_CONFIG --libs libpq`"
-      POSTGRESQL_VERSION="`$PKG_CONFIG --modversion libpq`"
-      POSTGRESQL_MAJOR_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f1 | sed 's/^\([[0-9]]*\)[[^0-9]].*/\1/'`"
-      POSTGRESQL_MINOR_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f2 | sed 's/^\([[0-9]]*\)[[^0-9]].*/\1/'`"
-      POSTGRESQL_PATCH_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f3 | sed 's/^\([[0-9]]*\)[[^0-9]].*/\1/'`"
-      test -n "$POSTGRESQL_PATCH_VERSION" || POSTGRESQL_PATCH_VERSION=0
-    fi
-    save_LIBS="$LIBS"
-    LIBS="$POSTGRESQL_LIBDIR $LIBS"
-    AC_MSG_RESULT([$POSTGRESQL_LIBDIR])
-
-    AC_DEFINE([SWITCH_HAVE_PGSQL], [1], [Define to 1 if PostgreSQL libraries are available])
-    AM_CONDITIONAL([HAVE_PGSQL],[true])
-    AC_DEFINE_UNQUOTED([POSTGRESQL_VERSION], "${POSTGRESQL_VERSION}", [Specifies the version of PostgreSQL we are linking against])
-    AC_DEFINE_UNQUOTED([POSTGRESQL_MAJOR_VERSION], ${POSTGRESQL_MAJOR_VERSION}, [Specifies the version of PostgreSQL we are linking against])
-    AC_DEFINE_UNQUOTED([POSTGRESQL_MINOR_VERSION], ${POSTGRESQL_MINOR_VERSION}, [Specifies the version of PostgreSQL we are linking against])
-    AC_DEFINE_UNQUOTED([POSTGRESQL_PATCH_VERSION], ${POSTGRESQL_PATCH_VERSION}, [Specifies the version of PostgreSQL we are linking against])
-
-    AC_CHECK_LIB([pq], [PQgetvalue],, AC_MSG_ERROR([no usable libpq; please install PostgreSQL devel package or equivalent]))
-    AC_MSG_RESULT([yes])
-    SWITCH_AM_CXXFLAGS="$POSTGRESQL_CFLAGS $SWITCH_AM_CXXFLAGS"
-    SWITCH_AM_LDFLAGS="$POSTGRESQL_LDFLAGS $SWITCH_AM_LDFLAGS"
-
-    LIBS="$save_LIBS"
+               AC_MSG_CHECKING([for PostgreSQL libraries via pg_config])
+               POSTGRESQL_CFLAGS="-I`$PG_CONFIG --includedir`"
+               POSTGRESQL_LIBDIR="-L`$PG_CONFIG --libdir`"
+               POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir` -lpq"
+               POSTGRESQL_VERSION=`$PG_CONFIG --version | awk '{ print $NF }'`
+               POSTGRESQL_MAJOR_VERSION=`$PG_CONFIG --version | awk '{ print $NF }' | awk -F. '{ print $1 }'`
+               POSTGRESQL_MINOR_VERSION=`$PG_CONFIG --version | awk '{ print $NF }' | awk -F. '{ print $2 }'`
+               POSTGRESQL_PATCH_VERSION=`$PG_CONFIG --version | awk '{ print $NF }' | awk -F. '{ print $3 }'`
+       fi
 else
-  AM_CONDITIONAL([HAVE_PGSQL],[false])
+
+       AC_MSG_CHECKING([for PostgreSQL libraries via pkg_config])
+       POSTGRESQL_CFLAGS="`$PKG_CONFIG --cflags libpq`"
+       POSTGRESQL_LIBDIR="`$PKG_CONFIG libpq --libs-only-L`"
+       POSTGRESQL_LDFLAGS="`$PKG_CONFIG --libs libpq`"
+       POSTGRESQL_VERSION="`$PKG_CONFIG --modversion libpq`"
+       POSTGRESQL_MAJOR_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f1 | sed 's/^\([[0-9]]*\)[[^0-9]].*/\1/'`"
+       POSTGRESQL_MINOR_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f2 | sed 's/^\([[0-9]]*\)[[^0-9]].*/\1/'`"
+       POSTGRESQL_PATCH_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f3 | sed 's/^\([[0-9]]*\)[[^0-9]].*/\1/'`"
+       test -n "$POSTGRESQL_PATCH_VERSION" || POSTGRESQL_PATCH_VERSION=0
 fi
+AC_MSG_RESULT([$POSTGRESQL_LIBDIR])
+AC_DEFINE_UNQUOTED([POSTGRESQL_VERSION], "${POSTGRESQL_VERSION}", [Specifies the version of PostgreSQL we are linking against])
+AC_DEFINE_UNQUOTED([POSTGRESQL_MAJOR_VERSION], ${POSTGRESQL_MAJOR_VERSION}, [Specifies the version of PostgreSQL we are linking against])
+AC_DEFINE_UNQUOTED([POSTGRESQL_MINOR_VERSION], ${POSTGRESQL_MINOR_VERSION}, [Specifies the version of PostgreSQL we are linking against])
+AC_DEFINE_UNQUOTED([POSTGRESQL_PATCH_VERSION], ${POSTGRESQL_PATCH_VERSION}, [Specifies the version of PostgreSQL we are linking against])
+have_libpq=no
+AC_CHECK_LIB([pq], [PQgetvalue], [have_libpq="yes"])
+AM_CONDITIONAL([HAVE_PGSQL],[test "${have_libpq}" = "yes"])
+AC_SUBST([POSTGRESQL_CFLAGS], [$POSTGRESQL_CFLAGS])
+AC_SUBST([POSTGRESQL_LDFLAGS], [$POSTGRESQL_LDFLAGS])
+AC_SUBST([POSTGRESQL_LIBDIR], [$POSTGRESQL_LIBDIR])
 
 AC_ARG_ENABLE(deprecated-core-db-events,
        [AS_HELP_STRING([--enable-deprecated-core-db-events], [Keep deprecated core db events])],,[enable_deprecated_core_db_events="no"])
@@ -709,19 +716,6 @@ ESL_LDFLAGS=
 PLATFORM_CORE_LDFLAGS=
 PLATFORM_CORE_LIBS=
 
-path_remove () {
-  echo "$1" | tr ':' '\n' | grep -Fxv "$2" | tr '\n' ':' | sed 's/:$//'
-}
-path_push_unique () {
-  x="$(eval echo \$$1)"
-  x="$(path_remove "$x" "$2")"
-  if test -z "$x"; then
-    eval export $1="$2"
-  else
-    eval export $1="$2:$x"
-  fi
-}
-
 # tweak platform specific flags
 case "$host" in
     *darwin*)
@@ -1930,6 +1924,7 @@ AC_CONFIG_FILES([Makefile
                src/mod/codecs/mod_siren/Makefile
                src/mod/codecs/mod_skel_codec/Makefile
                src/mod/codecs/mod_theora/Makefile
+               src/mod/databases/mod_pgsql/Makefile
                src/mod/dialplans/mod_dialplan_asterisk/Makefile
                src/mod/dialplans/mod_dialplan_directory/Makefile
                src/mod/dialplans/mod_dialplan_xml/Makefile
index 50cdaf32b5df97f62ea87ff254a98163868c3f0a..6dfaa2e019331a91db910cfe635f0f8b1bdf9c15 100755 (executable)
@@ -418,6 +418,7 @@ Depends: \${misc:Depends}, freeswitch (= \${binary:Version}),
  freeswitch-mod-dptools (= \${binary:Version}),
  freeswitch-mod-fifo (= \${binary:Version}),
  freeswitch-mod-hash (= \${binary:Version}),
+ freeswitch-mod-pgsql (= \${binary:Version}),
  freeswitch-mod-spandsp (= \${binary:Version}),
  freeswitch-mod-voicemail (= \${binary:Version}),
  freeswitch-mod-dialplan-xml (= \${binary:Version}),
@@ -468,6 +469,7 @@ Depends: \${misc:Depends}, freeswitch (= \${binary:Version}),
  freeswitch-mod-expr (= \${binary:Version}),
  freeswitch-mod-fifo (= \${binary:Version}),
  freeswitch-mod-hash (= \${binary:Version}),
+ freeswitch-mod-pgsql (= \${binary:Version}),
  freeswitch-mod-voicemail (= \${binary:Version}),
  freeswitch-mod-esf (= \${binary:Version}),
  freeswitch-mod-fsv (= \${binary:Version}),
@@ -534,6 +536,7 @@ Recommends:
  freeswitch-mod-lcr (= \${binary:Version}),
  freeswitch-mod-nibblebill (= \${binary:Version}),
  freeswitch-mod-oreka (= \${binary:Version}),
+ freeswitch-mod-pgsql (= \${binary:Version}),
  freeswitch-mod-redis (= \${binary:Version}),
  freeswitch-mod-rss (= \${binary:Version}),
  freeswitch-mod-sms (= \${binary:Version}),
@@ -620,6 +623,7 @@ Depends: \${misc:Depends}, freeswitch (= \${binary:Version}),
  freeswitch-mod-memcache (= \${binary:Version}),
  freeswitch-mod-nibblebill (= \${binary:Version}),
  freeswitch-mod-oreka (= \${binary:Version}),
+ freeswitch-mod-pgsql (= \${binary:Version}),
  freeswitch-mod-png (= \${binary:Version}),
  freeswitch-mod-redis (= \${binary:Version}),
  freeswitch-mod-rss (= \${binary:Version}),
@@ -859,6 +863,7 @@ Depends: \${misc:Depends}, freeswitch (= \${binary:Version}),
  freeswitch-mod-memcache-dbg (= \${binary:Version}),
  freeswitch-mod-nibblebill-dbg (= \${binary:Version}),
  freeswitch-mod-oreka-dbg (= \${binary:Version}),
+ freeswitch-mod-pgsql-dbg (= \${binary:Version}),
  freeswitch-mod-png-dbg (= \${binary:Version}),
  freeswitch-mod-redis-dbg (= \${binary:Version}),
  freeswitch-mod-rss-dbg (= \${binary:Version}),
index 2d8bbc27cea7f95c158be4131fa6f6d9ea64cfe4..27b2322ceac3ed097b4eb3f63d5625d4c61f7b9e 100644 (file)
@@ -391,6 +391,13 @@ Module: codecs/mod_yuv
 Description: Adds mod_yuv
  Adds mod_yuv.
 
+## mod/databases
+
+Module: databases/mod_pgsql
+Description: Adds mod_pgsql
+ Adds mod_pgsql.
+Build-Depends: libpq-dev 
+
 ## mod/dialplans
 
 Module: dialplans/mod_dialplan_asterisk
index bb0e56f2c0d2786b238daf27ab035a3aa2271733..3cdf7b4ff3a7aa7f795dc6b4446e43bfa8d235a2 100755 (executable)
@@ -74,8 +74,7 @@ override_dh_auto_clean:
                --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
                --prefix=/usr --localstatedir=/var --sysconfdir=/etc \
                --with-gnu-ld --with-python --with-erlang --with-openssl \
-               --enable-core-odbc-support --enable-zrtp \
-               --enable-core-pgsql-support
+               --enable-core-odbc-support --enable-zrtp
        touch $@
 
 override_dh_auto_configure: .stamp-configure
index 4a96e41dc9353e30cbfdb945982d8e98001be6ee..e371f472d0f06937fb4bc6b9d7cbb2402742ad26 100644 (file)
@@ -3,7 +3,7 @@
 # spec file for package freeswitch
 #
 # includes module(s): freeswitch-devel freeswitch-codec-passthru-amr freeswitch-codec-passthru-amrwb freeswitch-codec-passthru-g729 
-#                     freeswitch-codec-passthru-g7231 freeswitch-lua freeswitch-perl freeswitch-python freeswitch-v8 freeswitch-signalwire
+#                     freeswitch-codec-passthru-g7231 freeswitch-lua freeswitch-pgsql freeswitch-perl freeswitch-python freeswitch-v8 freeswitch-signalwire
 #                     freeswitch-lan-de freeswitch-lang-en freeswitch-lang-fr freeswitch-lang-hu freeswitch-lang-ru freeswitch-freetdm
 #                    and others
 #
@@ -838,6 +838,20 @@ Requires:       %{name} = %{version}-%{release}
 %description codec-theora
 Theora Video Codec support for FreeSWITCH open source telephony platform.
 
+######################################################################################################################
+#                              FreeSWITCH Database Modules
+######################################################################################################################
+
+%package database-pgsql
+Summary:       PostgreSQL native support for FreeSWITCH
+Group:         System/Libraries
+Requires:      %{name} = %{version}-%{release}
+Requires:      postgresql-libs
+BuildRequires: postgresql-devel
+
+%description database-pgsql
+PostgreSQL native support for FreeSWITCH.
+
 ######################################################################################################################
 #                              FreeSWITCH Directory Modules
 ######################################################################################################################
@@ -1419,6 +1433,7 @@ Requires: freeswitch-codec-passthru-g729
 Requires:      freeswitch-codec-h26x
 Requires:      freeswitch-codec-ilbc
 Requires:      freeswitch-codec-siren
+Requires:      freeswitch-database-pgsql
 Requires:      freeswitch-format-local-stream
 Requires:      freeswitch-format-native-file
 Requires:      freeswitch-format-portaudio-stream
@@ -1514,6 +1529,13 @@ CODECS_MODULES="codecs/mod_amr codecs/mod_amrwb codecs/mod_bv codecs/mod_codec2
 CODECS_MODULES+="codecs/mod_sangoma_codec"
 %endif
 
+######################################################################################################################
+#
+#                                      Database Modules
+#
+######################################################################################################################
+DATABASES_MODULES="databases/mod_pgsql"
+
 ######################################################################################################################
 #
 #                                      Dialplan Modules
@@ -1616,7 +1638,7 @@ XML_INT_MODULES="xml_int/mod_xml_cdr xml_int/mod_xml_curl xml_int/mod_xml_rpc"
 #                              Create one environment variable out of all the module defs
 #
 ######################################################################################################################
-MYMODULES="$APPLICATIONS_MODULES $CODECS_MODULES $DIALPLANS_MODULES $DIRECTORIES_MODULES \
+MYMODULES="$APPLICATIONS_MODULES $CODECS_MODULES $DATABASES_MODULES $DIALPLANS_MODULES $DIRECTORIES_MODULES \
 $ENDPOINTS_MODULES $ASR_TTS_MODULES $EVENT_HANDLERS_MODULES $FORMATS_MODULES $LANGUAGES_MODULES $LOGGERS_MODULES \
 $SAY_MODULES $TIMERS_MODULES $XML_INT_MODULES"
 
@@ -1669,7 +1691,6 @@ autoreconf --force --install
 --with-dbdir=%{DBDIR} \
 --with-htdocsdir=%{HTDOCSDIR} \
 --with-soundsdir=%{SOUNDSDIR} \
---enable-core-pgsql-support \
 --enable-core-odbc-support \
 --enable-core-libedit-support \
 --with-grammardir=%{GRAMMARDIR} \
@@ -1987,6 +2008,7 @@ fi
 %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/pocketsphinx.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/portaudio.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/post_load_modules.conf.xml
+%config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/pre_load_modules.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/presence_map.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/redis.conf.xml
 %config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/rss.conf.xml
@@ -2262,6 +2284,15 @@ fi
 %files codec-theora
 %{MODINSTDIR}/mod_theora.so*
 
+######################################################################################################################
+#
+#                                              FreeSWITCH Database Modules
+#
+######################################################################################################################
+
+%files database-pgsql
+%{MODINSTDIR}/mod_pgsql.so*
+
 ######################################################################################################################
 #
 #                                              FreeSWITCH Directory Modules
index 3498aecc19b7dc207b5a16e7a2f2436379fb691f..9fdbf12aa66b3f7c101f9c9fb24b0f7b90616021 100644 (file)
 #include "switch_config.h"
 #include "switch_nat.h"
 #include "switch_odbc.h"
-#include "switch_pgsql.h"
 #include "switch_json.h"
 #include "switch_limit.h"
 #include "switch_core_media.h"
index f8c65593547cd99b103d9bfff053d4845f61e508..fa101a0ffa1b8c64aa71fa1118cb6e1a8b3628e5 100644 (file)
@@ -2479,14 +2479,12 @@ typedef enum {
 typedef enum {
        SCDB_TYPE_CORE_DB,
        SCDB_TYPE_ODBC,
-       SCDB_TYPE_PGSQL,
        SCDB_TYPE_DATABASE_INTERFACE
 } switch_cache_db_handle_type_t;
 
 typedef union {
        switch_core_db_t *core_db_dbh;
        switch_odbc_handle_t *odbc_dbh;
-       switch_pgsql_handle_t *pgsql_dbh;
        switch_database_interface_handle_t *database_interface_dbh;
 } switch_cache_db_native_handle_t;
 
@@ -2501,11 +2499,8 @@ typedef struct {
 } switch_cache_db_odbc_options_t;
 
 typedef struct {
-       char *dsn;
-} switch_cache_db_pgsql_options_t;
-
-typedef struct {
-       char *dsn;
+       const char *original_dsn;
+       char *connection_string;
        char prefix[16];
        switch_database_interface_t *database_interface;
        switch_bool_t make_module_no_unloadable;
@@ -2514,7 +2509,6 @@ typedef struct {
 typedef union {
        switch_cache_db_core_db_options_t core_db_options;
        switch_cache_db_odbc_options_t odbc_options;
-       switch_cache_db_pgsql_options_t pgsql_options;
        switch_cache_db_database_interface_options_t database_interface_options;
 } switch_cache_db_connection_options_t;
 
@@ -2531,11 +2525,6 @@ static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_
                        type_str = "DATABASE_INTERFACE";
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       type_str = "PGSQL";
-               }
-               break;
        case SCDB_TYPE_ODBC:
                {
                        type_str = "ODBC";
@@ -2674,6 +2663,11 @@ SWITCH_DECLARE(void) switch_cache_db_database_interface_flush_handles(switch_dat
 */
 SWITCH_DECLARE(switch_status_t) switch_core_check_core_db_dsn(void);
 
+/*!
+\brief Returns error if no suitable database interface found for a dsn.
+*/
+SWITCH_DECLARE(switch_status_t) switch_database_available(char* dsn);
+
 SWITCH_DECLARE(void) switch_core_set_signal_handlers(void);
 SWITCH_DECLARE(uint32_t) switch_core_debug_level(void);
 SWITCH_DECLARE(int32_t) switch_core_sps(void);
index 4407a6872906ebe17647a548510f096aec32db65..d49f7f3eb6ef2f8382f277aeb6b548f05828cbfc 100644 (file)
@@ -621,7 +621,7 @@ struct switch_database_interface {
        const char *interface_name;
        /*! flags indicating database specifics, see switch_database_flag_t */
        uint32_t flags;
-       switch_status_t(*handle_new)(char *dsn, switch_database_interface_handle_t **dih);
+       switch_status_t(*handle_new)(switch_cache_db_database_interface_options_t database_interface_options, switch_database_interface_handle_t **dih);
        switch_status_t(*handle_destroy)(switch_database_interface_handle_t **dih); 
        switch_status_t(*flush)(switch_database_interface_handle_t *dih);
        switch_status_t(*exec_detailed)(const char *file, const char *func, int line, 
diff --git a/src/include/switch_pgsql.h b/src/include/switch_pgsql.h
deleted file mode 100644 (file)
index 6ded45b..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
- *
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- *
- * The Initial Developer of the Original Code is
- * Anthony Minessale II <anthm@freeswitch.org>
- * Portions created by the Initial Developer are Copyright (C)
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Anthony Minessale II <anthm@freeswitch.org>
- * Eliot Gable <egable@gmail.com>
- *
- * switch_pgsql.h -- PGSQL Driver
- *
- */
-
-#ifndef SWITCH_PGSQL_H
-#define SWITCH_PGSQL_H
-
-#include <switch.h>
-
-#define DEFAULT_PGSQL_RETRIES 120
-
-SWITCH_BEGIN_EXTERN_C
-
-struct switch_pgsql_handle;
-struct switch_pgsql_result;
-
-
-typedef enum {
-       SWITCH_PGSQL_STATE_INIT,
-       SWITCH_PGSQL_STATE_DOWN,
-       SWITCH_PGSQL_STATE_CONNECTED,
-       SWITCH_PGSQL_STATE_ERROR
-} switch_pgsql_state_t;
-
-typedef enum {
-       SWITCH_PGSQL_SUCCESS = 0,
-       SWITCH_PGSQL_FAIL = -1
-} switch_pgsql_status_t;
-
-/*!
-  \brief Create a new handle for the PGSQL connection.
-  \param dsn The DSN of the database to connect to. See documentation for PQconnectdb() at
-             http://www.postgresql.org/docs/9.0/static/libpq-connect.html. The DSN *MUST* be
-                        prefixed with 'pgsql;' to use the switch_cache_db* functionality. However, the DSN
-                        passed to this function directly *MUST NOT* be prefixed with 'pgsql;'.
-  \return Returns a pointer to a newly allocated switch_pgsql_handle_t type or NULL on failure.
- */
-SWITCH_DECLARE(switch_pgsql_handle_t *) switch_pgsql_handle_new(const char *dsn);
-
-/*!
-  \brief Sets the number of retries if the PGSQL connection fails.
-  \param handle A fully allocated switch_pgsql_handle_t returned from a call to switch_pgsql_handle_new().
-  \param num_retries How many times to retry connecting to the database if this connection fails.
- */
-SWITCH_DECLARE(void) switch_pgsql_set_num_retries(switch_pgsql_handle_t *handle, int num_retries);
-
-/*!
-  \brief Disconnects a PGSQL connection from the database.
-  \param handle The PGSQL database handle to disconnect.
-  \return Returns SWITCH_PGSQL_SUCCESS or SWITCH_PGSQL_FAIL.
- */
-SWITCH_DECLARE(switch_pgsql_status_t ) switch_pgsql_handle_disconnect(switch_pgsql_handle_t *handle);
-#if 0
-                                                                          ) /* Emacs formatting issue */
-#endif
-/*!
-  \brief Connect to the database specified by the DSN passed to the switch_pgsql_handle_new() call which
-         initialized this handle.
-  \param The database handle to connect to the database.
-  \return Returns SWITCH_PGSQL_SUCCESS or SWITCH_PGSQL_FAIL.
- */
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_connect(switch_pgsql_handle_t *handle);
-
-/*!
- */
-SWITCH_DECLARE(void) switch_pgsql_handle_destroy(switch_pgsql_handle_t **handlep);
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_send_query(switch_pgsql_handle_t *handle, const char* sql);
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_cancel_real(const char *file, const char *func, int line, switch_pgsql_handle_t *handle);
-#define switch_pgsql_cancel(handle) switch_pgsql_cancel_real(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle)
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsql_handle_t *handle, switch_pgsql_result_t **result_out, int seconds);
-#define switch_pgsql_next_result(h, r) switch_pgsql_next_result_timed(h, r, 10000)
-
-SWITCH_DECLARE(void) switch_pgsql_free_result(switch_pgsql_result_t **result);
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_finish_results_real(const char* file, const char *func, int line, switch_pgsql_handle_t *handle);
-#define switch_pgsql_finish_results(handle) switch_pgsql_finish_results_real(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle)
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_base_detailed(const char *file, const char *func, int line,
-                                                                                                                                                        switch_pgsql_handle_t *handle, const char *sql, char **err);
-#define switch_pgsql_handle_exec_base(handle, sql, err) switch_pgsql_handle_exec_base_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle, sql, err)
-
-SWITCH_DECLARE(switch_pgsql_state_t) switch_pgsql_handle_get_state(switch_pgsql_handle_t *handle);
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_detailed(const char *file, const char *func, int line,
-                                                                                                                          switch_pgsql_handle_t *handle, const char *sql, char **err);
-#define switch_pgsql_handle_exec(handle, sql, err) switch_pgsql_handle_exec_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle, sql, err)
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_string_detailed(const char *file, const char *func, int line,
-                                                                                                                                                          switch_pgsql_handle_t *handle, const char *sql, char *resbuf, size_t len, char **err);
-#define switch_pgsql_handle_exec_string(handle, sql, resbuf, len, err) switch_pgsql_handle_exec_string_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle, sql, resbuf, len, err)
-
-SWITCH_DECLARE(switch_bool_t) switch_pgsql_available(void);
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_SQLSetAutoCommitAttr(switch_pgsql_handle_t *handle, switch_bool_t on);
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_SQLEndTran(switch_pgsql_handle_t *handle, switch_bool_t commit);
-
-/*!
-  \brief Execute the sql query and issue a callback for each row returned
-  \param file the file from which this function is called
-  \param func the function from which this function is called
-  \param line the line from which this function is called
-  \param handle the PGSQL handle
-  \param sql the sql string to execute
-  \param callback the callback function to execute
-  \param pdata the state data passed on each callback invocation
-  \return SWITCH_STATUS_SUCCESS if the operation was successful
-  \note none
-*/
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed(const char *file, const char *func, int line, switch_pgsql_handle_t *handle,
-                                                                                                                                                          const char *sql, switch_core_db_callback_func_t callback, void *pdata,
-                                                                                                                                                          char **err);
-/*!
-  \brief Execute the sql query and issue a callback for each row returned
-  \param handle the PGSQL handle
-  \param sql the sql string to execute
-  \param callback the callback function to execute
-  \param pdata the state data passed on each callback invocation
-  \return SWITCH_STATUS_SUCCESS if the operation was successful
-  \note none
-*/
-#define switch_pgsql_handle_callback_exec(handle,  sql,  callback, pdata, err) \
-               switch_pgsql_handle_callback_exec_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, \
-                                                                                                 handle, sql, callback, pdata, err)
-
-
-SWITCH_DECLARE(char *) switch_pgsql_handle_get_error(switch_pgsql_handle_t *handle);
-
-SWITCH_DECLARE(int) switch_pgsql_handle_affected_rows(switch_pgsql_handle_t *handle);
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_flush(switch_pgsql_handle_t *handle);
-
-
-SWITCH_END_EXTERN_C
-#endif
-/* For Emacs:
- * Local Variables:
- * mode:c
- * indent-tabs-mode:t
- * tab-width:4
- * c-basic-offset:4
- * End:
- * For VIM:
- * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
- */
index 72e1633b6b1634a3a5f648d3c189e42a6183d202..e0cc9f3698ce07e55e6f200a0538f7ad2f2f0a45 100644 (file)
@@ -2315,8 +2315,6 @@ typedef struct switch_buffer switch_buffer_t;
 typedef union  switch_codec_settings switch_codec_settings_t;
 typedef struct switch_codec_fmtp switch_codec_fmtp_t;
 typedef struct switch_odbc_handle switch_odbc_handle_t;
-typedef struct switch_pgsql_handle switch_pgsql_handle_t;
-typedef struct switch_pgsql_result switch_pgsql_result_t;
 typedef struct switch_database_interface_handle switch_database_interface_handle_t;
 
 typedef struct switch_io_routines switch_io_routines_t;
index 29e46b8568b7e5ff8ced696e26fc90f745d65afd..1e19adb6f7013cfdabf7db62a6b4a938d0686365 100644 (file)
@@ -468,7 +468,7 @@ static switch_status_t load_config(switch_bool_t reload)
                        char *val = (char *) switch_xml_attr_soft(param, "value");
 
                        if (!strcasecmp(var, "odbc-dsn") && !zstr(val)) {
-                               if (switch_odbc_available() || switch_pgsql_available()) {
+                               if (switch_database_available(val)) {
                                        switch_set_string(globals.odbc_dsn, val);
                                } else {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
index 28429c7244939b160bb4c4efe7a39d5dd28b8542..8749eb84863fe149d968afd80c030fca0680f46c 100644 (file)
@@ -4392,7 +4392,7 @@ static switch_status_t read_config_file(switch_xml_t *xml, switch_xml_t *cfg) {
                        if (!strcasecmp(var, "outbound-strategy") && !zstr(val)) {
                                globals.default_strategy = parse_strategy(val);
                        } else if (!strcasecmp(var, "odbc-dsn") && !zstr(val)) {
-                               if (switch_odbc_available() || switch_pgsql_available()) {
+                               if (switch_database_available(val)) {
                                        switch_set_string(globals.odbc_dsn, val);
                                } else {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
diff --git a/src/mod/databases/mod_pgsql/Makefile.am b/src/mod/databases/mod_pgsql/Makefile.am
new file mode 100644 (file)
index 0000000..23b922b
--- /dev/null
@@ -0,0 +1,18 @@
+include $(top_srcdir)/build/modmake.rulesam
+MODNAME=mod_pgsql
+
+if HAVE_PGSQL
+
+
+mod_LTLIBRARIES = mod_pgsql.la
+mod_pgsql_la_SOURCES  = mod_pgsql.c
+mod_pgsql_la_CFLAGS   = $(AM_CFLAGS) $(POSTGRESQL_CFLAGS)
+mod_pgsql_la_LIBADD   = $(switch_builddir)/libfreeswitch.la
+mod_pgsql_la_LDFLAGS  = -avoid-version -module -no-undefined -shared $(POSTGRESQL_LDFLAGS)
+
+else
+install: error
+all: error
+error:
+       $(error You must install libpq-dev to build mod_pgsql)
+endif
diff --git a/src/mod/databases/mod_pgsql/mod_pgsql.2017.vcxproj b/src/mod/databases/mod_pgsql/mod_pgsql.2017.vcxproj
new file mode 100644 (file)
index 0000000..8548be8
--- /dev/null
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectName>mod_pgsql</ProjectName>
+    <RootNamespace>mod_pgsql</RootNamespace>
+    <Keyword>Win32Proj</Keyword>
+    <ProjectGuid>{1BA65811-5453-46F6-8190-9ECEEFEB7DF2}</ProjectGuid>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v141</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v141</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v141</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>v141</PlatformToolset>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <Import Project="..\..\..\..\w32\libpq.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\..\..\..\w32\module_release.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\..\..\..\w32\module_debug.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\..\..\..\w32\module_release.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\..\..\..\w32\module_debug.props" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup>
+    <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+    </ClCompile>
+    <Link>
+      <AdditionalLibraryDirectories>;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <RandomizedBaseAddress>false</RandomizedBaseAddress>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <DataExecutionPrevention>
+      </DataExecutionPrevention>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <Midl>
+      <TargetEnvironment>X64</TargetEnvironment>
+    </Midl>
+    <ClCompile>
+      <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+    </ClCompile>
+    <Link>
+      <AdditionalLibraryDirectories>;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <RandomizedBaseAddress>false</RandomizedBaseAddress>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <DataExecutionPrevention>
+      </DataExecutionPrevention>
+      <TargetMachine>MachineX64</TargetMachine>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+    </ClCompile>
+    <Link>
+      <AdditionalLibraryDirectories>;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <RandomizedBaseAddress>false</RandomizedBaseAddress>
+      <DataExecutionPrevention>
+      </DataExecutionPrevention>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <Midl>
+      <TargetEnvironment>X64</TargetEnvironment>
+    </Midl>
+    <ClCompile>
+      <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MOD_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+    </ClCompile>
+    <Link>
+      <AdditionalLibraryDirectories>;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <RandomizedBaseAddress>false</RandomizedBaseAddress>
+      <DataExecutionPrevention>
+      </DataExecutionPrevention>
+      <TargetMachine>MachineX64</TargetMachine>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="mod_pgsql.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\..\w32\Library\FreeSwitchCore.2017.vcxproj">
+      <Project>{202d7a4e-760d-4d0e-afa1-d7459ced30ff}</Project>
+      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
similarity index 55%
rename from src/switch_pgsql.c
rename to src/mod/databases/mod_pgsql/mod_pgsql.c
index b3fa2d06e47f4e91fbb06feb5a82be7d5c7ae9c9..53e790148a2e62c4e62f4edf66bf9fb64a7de636 100644 (file)
@@ -1,51 +1,63 @@
 /*
- * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
- *
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- *
- * The Initial Developer of the Original Code is
- * Anthony Minessale II <anthm@freeswitch.org>
- * Portions created by the Initial Developer are Copyright (C)
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Anthony Minessale II <anthm@freeswitch.org>
- * Eliot Gable <egable@gmail.com>
- * Seven Du <dujinfang@gmail.com>
- *
- * switch_pgsql.c -- PGSQL Driver
- *
- */
+* mod_pgsql for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005-2019, Anthony Minessale II <anthm@freeswitch.org>
+*
+* Version: MPL 1.1
+*
+* The contents of this file are subject to the Mozilla Public License Version
+* 1.1 (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.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS" basis,
+* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+* for the specific language governing rights and limitations under the
+* License.
+*
+* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+*
+* The Initial Developer of the Original Code is
+* Anthony Minessale II <anthm@freeswitch.org>
+* Portions created by the Initial Developer are Copyright (C)
+* the Initial Developer. All Rights Reserved.
+*
+* Contributor(s):
+* Anthony Minessale II <anthm@freeswitch.org>
+* Eliot Gable <egable@gmail.com>
+* Seven Du <dujinfang@gmail.com>
+* Andrey Volk <andywolk@gmail.com>
+*
+* mod_pgsql.c -- PostgreSQL FreeSWITCH module
+*
+*/
 
-#include <switch.h>
+#define SWITCH_PGSQL_H
 
-#ifndef WIN32
-#include <switch_private.h>
-#endif
+#include <switch.h>
 
-#ifdef SWITCH_HAVE_PGSQL
 #include <libpq-fe.h>
 
 #ifndef _WIN32
 #include <poll.h>
 #else
-#include <winsock2.h>
+#include <WinSock2.h>
 #endif
 
+switch_loadable_module_interface_t *MODULE_INTERFACE;
+static char *supported_prefixes[4] = { 0 };
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_pgsql_load);
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_pgsql_shutdown);
+SWITCH_MODULE_DEFINITION(mod_pgsql, mod_pgsql_load, mod_pgsql_shutdown, NULL);
+
+#define DEFAULT_PGSQL_RETRIES 120
+
+typedef enum {
+       SWITCH_PGSQL_STATE_INIT,
+       SWITCH_PGSQL_STATE_DOWN,
+       SWITCH_PGSQL_STATE_CONNECTED,
+       SWITCH_PGSQL_STATE_ERROR
+} switch_pgsql_state_t;
 
 struct switch_pgsql_handle {
        char *dsn;
@@ -66,51 +78,41 @@ struct switch_pgsql_result {
        int rows;
        int cols;
 };
-#endif
 
-SWITCH_DECLARE(switch_pgsql_handle_t *) switch_pgsql_handle_new(const char *dsn)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       switch_pgsql_handle_t *new_handle;
+typedef struct switch_pgsql_handle switch_pgsql_handle_t;
+typedef struct switch_pgsql_result switch_pgsql_result_t;
 
-       if (!(new_handle = malloc(sizeof(*new_handle)))) {
-               goto err;
-       }
+switch_status_t pgsql_handle_connect(switch_pgsql_handle_t *handle);
+switch_status_t pgsql_handle_destroy(switch_database_interface_handle_t **dih);
+switch_status_t pgsql_cancel_real(const char *file, const char *func, int line, switch_pgsql_handle_t *handle);
+switch_status_t pgsql_next_result_timed(switch_pgsql_handle_t *handle, switch_pgsql_result_t **result_out, int msec);
 
-       memset(new_handle, 0, sizeof(*new_handle));
+#define pgsql_handle_exec_base(handle, sql, err) pgsql_handle_exec_base_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle, sql, err)
+#define pgsql_next_result(h, r) pgsql_next_result_timed(h, r, 10000)
+#define pgsql_finish_results(handle) pgsql_finish_results_real(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle)
+#define pgsql_cancel(handle) pgsql_cancel_real(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle)
 
-       if (!(new_handle->dsn = strdup(dsn))) {
-               goto err;
-       }
+char * pgsql_handle_get_error(switch_pgsql_handle_t *handle)
+{
+       char * err_str;
 
-       new_handle->sock = 0;
-       new_handle->state = SWITCH_PGSQL_STATE_INIT;
-       new_handle->con = NULL;
-       new_handle->affected_rows = 0;
-       new_handle->num_retries = DEFAULT_PGSQL_RETRIES;
-       new_handle->auto_commit = SWITCH_TRUE;
-       new_handle->in_txn = SWITCH_FALSE;
+       if (!handle) {
+               return NULL;
+       }
 
-       return new_handle;
+       switch_strdup(err_str, PQerrorMessage(handle->con));
 
-  err:
-       if (new_handle) {
-               switch_safe_free(new_handle->dsn);
-               switch_safe_free(new_handle);
-       }
-#endif
-       return NULL;
+       return err_str;
 }
 
-
-#ifdef SWITCH_HAVE_PGSQL
 static int db_is_up(switch_pgsql_handle_t *handle)
 {
        int ret = 0;
        switch_event_t *event;
        char *err_str = NULL;
        int max_tries = DEFAULT_PGSQL_RETRIES;
-       int code = 0, recon = 0;
+       int code = 0;
+       int recon = 0;
 
        if (handle) {
                max_tries = handle->num_retries;
@@ -118,7 +120,7 @@ static int db_is_up(switch_pgsql_handle_t *handle)
                        max_tries = DEFAULT_PGSQL_RETRIES;
        }
 
-  top:
+top:
 
        if (!handle) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Handle\n");
@@ -144,36 +146,18 @@ static int db_is_up(switch_pgsql_handle_t *handle)
                handle->sock = PQsocket(handle->con);
        }
 
-/*     if (!PQsendQuery(handle->con, "SELECT 1")) {
-               code = __LINE__;
-               goto error;
-       }
-
-       if(switch_pgsql_next_result(handle, &result) == SWITCH_PGSQL_FAIL) {
-               code = __LINE__;
-               goto error;
-       }
-
-       if (!result || result->status != PGRES_COMMAND_OK) {
-               code = __LINE__;
-               goto error;
-       }
-
-       switch_pgsql_free_result(&result);
-       switch_pgsql_finish_results(handle);
-*/
        ret = 1;
        goto done;
 
-  error:
-       err_str = switch_pgsql_handle_get_error(handle);
+error:
+       err_str = pgsql_handle_get_error(handle);
 
        if (PQstatus(handle->con) == CONNECTION_BAD) {
                handle->state = SWITCH_PGSQL_STATE_ERROR;
                PQreset(handle->con);
                if (PQstatus(handle->con) == CONNECTION_OK) {
                        handle->state = SWITCH_PGSQL_STATE_CONNECTED;
-                       recon = SWITCH_PGSQL_SUCCESS;
+                       recon = SWITCH_STATUS_SUCCESS;
                        handle->sock = PQsocket(handle->con);
                }
        }
@@ -182,11 +166,11 @@ static int db_is_up(switch_pgsql_handle_t *handle)
 
        if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Failure-Message", "The sql server is not responding for DSN %s [%s][%d]",
-                                                               switch_str_nil(handle->dsn), switch_str_nil(err_str), code);
+                       switch_str_nil(handle->dsn), switch_str_nil(err_str), code);
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The sql server is not responding for DSN %s [%s][%d]\n",
-                                                 switch_str_nil(handle->dsn), switch_str_nil(err_str), code);
+                       switch_str_nil(handle->dsn), switch_str_nil(err_str), code);
 
-               if (recon == SWITCH_PGSQL_SUCCESS) {
+               if (recon == SWITCH_STATUS_SUCCESS) {
                        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection has been re-established");
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "The connection has been re-established\n");
                } else {
@@ -209,30 +193,130 @@ static int db_is_up(switch_pgsql_handle_t *handle)
        switch_yield(1000000);
        goto top;
 
-  done:
+done:
 
        switch_safe_free(err_str);
 
        return ret;
 }
-#endif
 
+void pgsql_free_result(switch_pgsql_result_t **result)
+{
+       if (!*result) {
+               return;
+       }
+
+       if ((*result)->result) {
+               PQclear((*result)->result);
+       }
+       free(*result);
+       *result = NULL;
+}
 
-SWITCH_DECLARE(void) switch_pgsql_set_num_retries(switch_pgsql_handle_t *handle, int num_retries)
+switch_status_t pgsql_finish_results_real(const char* file, const char* func, int line, switch_pgsql_handle_t *handle)
 {
-#ifdef SWITCH_HAVE_PGSQL
-       if (handle) {
-               handle->num_retries = num_retries;
+       switch_pgsql_result_t *res = NULL;
+       switch_status_t final_status = SWITCH_STATUS_SUCCESS;
+       int done = 0;
+
+       do {
+               pgsql_next_result(handle, &res);
+               if (res && res->err && !switch_stristr("already exists", res->err) && !switch_stristr("duplicate key name", res->err)) {
+                       switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Error executing query:\n%s\n", res->err);
+                       final_status = SWITCH_STATUS_FALSE;
+               }
+
+               if (!res) {
+                       done = 1;
+               } else if (res->result) {
+                       char *affected_rows = PQcmdTuples(res->result);
+
+                       if (!zstr(affected_rows)) {
+                               handle->affected_rows = atoi(affected_rows);
+                       }
+               }
+
+               pgsql_free_result(&res);
+       } while (!done);
+
+       return final_status;
+}
+
+switch_status_t pgsql_handle_affected_rows(switch_database_interface_handle_t *dih, int *affected_rows)
+{
+       switch_pgsql_handle_t *handle = NULL;
+
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
        }
-#endif
+
+       handle = dih->handle;
+
+       if (!handle)
+               return SWITCH_STATUS_FALSE;
+
+       *affected_rows = handle->affected_rows;
+
+       return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_disconnect(switch_pgsql_handle_t *handle)
+switch_status_t pgsql_handle_new(switch_cache_db_database_interface_options_t database_interface_options, switch_database_interface_handle_t **dih)
 {
-#ifdef SWITCH_HAVE_PGSQL
+       switch_pgsql_handle_t *new_handle = NULL;       
+       
+       if (!(*dih = malloc(sizeof(**dih)))) {
+               goto err;
+       }
+
+       if (!(new_handle = malloc(sizeof(*new_handle)))) {
+               goto err;
+       }
 
+       memset(new_handle, 0, sizeof(*new_handle));
+
+       if (!strcasecmp(database_interface_options.prefix, "postgresql") || !strcasecmp(database_interface_options.prefix, "postgres")) {
+               new_handle->dsn = strdup(database_interface_options.original_dsn);
+       } else if (!strcasecmp(database_interface_options.prefix, "pgsql")) {
+               new_handle->dsn = strdup(database_interface_options.connection_string);
+       }
+
+       if (!new_handle->dsn) {
+               goto err;
+       }
+
+       new_handle->sock = 0;
+       new_handle->state = SWITCH_PGSQL_STATE_INIT;
+       new_handle->con = NULL;
+       new_handle->affected_rows = 0;
+       new_handle->num_retries = DEFAULT_PGSQL_RETRIES;
+       new_handle->auto_commit = SWITCH_TRUE;
+       new_handle->in_txn = SWITCH_FALSE;
+
+       (*dih)->handle = new_handle;
+
+       if (pgsql_handle_connect(new_handle) != SWITCH_STATUS_SUCCESS) {
+               if (pgsql_handle_destroy(dih) != SWITCH_STATUS_SUCCESS) {
+                       goto err;
+               }
+       }
+
+       return SWITCH_STATUS_SUCCESS;
+
+err:
+       switch_safe_free(*dih);
+
+       if (new_handle) {
+               switch_safe_free(new_handle->dsn);
+               switch_safe_free(new_handle);
+       }               
+
+       return SWITCH_STATUS_FALSE;
+}
+
+switch_status_t pgsql_handle_disconnect(switch_pgsql_handle_t *handle)
+{
        if (!handle) {
-               return SWITCH_PGSQL_FAIL;
+               return SWITCH_STATUS_FALSE;
        }
 
        if (handle->state == SWITCH_PGSQL_STATE_CONNECTED) {
@@ -242,104 +326,330 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_disconnect(switch_pgsq
        switch_safe_free(handle->sql);
        handle->state = SWITCH_PGSQL_STATE_DOWN;
 
-       return SWITCH_PGSQL_SUCCESS;
-#else
-       return SWITCH_PGSQL_FAIL;
-#endif
+       return SWITCH_STATUS_SUCCESS;
+}
+
+switch_status_t pgsql_handle_connect(switch_pgsql_handle_t *handle)
+{      
+       if (!handle) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       if (handle->state == SWITCH_PGSQL_STATE_CONNECTED) {
+               pgsql_handle_disconnect(handle);
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Re-connecting %s\n", handle->dsn);
+       }
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Connecting %s\n", handle->dsn);
+       PQinitSSL(0);
+       
+       handle->con = PQconnectdb(handle->dsn);
+       if (PQstatus(handle->con) != CONNECTION_OK) {
+               char *err_str;
+
+               if ((err_str = pgsql_handle_get_error(handle))) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err_str);
+                       switch_safe_free(err_str);
+               } else {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to connect to the database [%s]\n", handle->dsn);
+                       pgsql_handle_disconnect(handle);
+               }
+
+               return SWITCH_STATUS_FALSE;
+       }
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Connected to [%s]\n", handle->dsn);
+       handle->state = SWITCH_PGSQL_STATE_CONNECTED;
+       handle->sock = PQsocket(handle->con);
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+switch_status_t pgsql_handle_destroy(switch_database_interface_handle_t **dih)
+{
+       switch_pgsql_handle_t *handle = NULL;
+
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       handle = (*dih)->handle;
+
+       if (handle) {
+               pgsql_handle_disconnect(handle);
+
+               switch_safe_free(handle->dsn);
+               free(handle);
+       }
+
+       switch_safe_free(*dih);
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+switch_status_t pgsql_flush(switch_pgsql_handle_t *handle)
+{
+       PGresult *tmp = NULL;
+       int x = 0;
+
+       if (!handle) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       /* Make sure the query is fully cleared */
+       while ((tmp = PQgetResult(handle->con)) != NULL) {
+               PQclear(tmp);
+               x++;
+       }
+
+       if (x) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Flushing %d results\n", x);
+       }
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+switch_status_t database_flush(switch_database_interface_handle_t *dih)
+{
+       switch_pgsql_handle_t *handle;
+
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       handle = dih->handle;
+
+       return pgsql_flush(handle);
 }
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_send_query(switch_pgsql_handle_t *handle, const char* sql)
+switch_status_t pgsql_send_query(switch_pgsql_handle_t *handle, const char* sql)
 {
-#ifdef SWITCH_HAVE_PGSQL
        char *err_str;
 
        switch_safe_free(handle->sql);
        handle->sql = strdup(sql);
        if (!PQsendQuery(handle->con, sql)) {
-               err_str = switch_pgsql_handle_get_error(handle);
+               err_str = pgsql_handle_get_error(handle);
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to send query (%s) to database: %s\n", sql, err_str);
                switch_safe_free(err_str);
-               switch_pgsql_finish_results(handle);
+               pgsql_finish_results(handle);
                goto error;
        }
 
-       return SWITCH_PGSQL_SUCCESS;
- error:
-#endif
-       return SWITCH_PGSQL_FAIL;
+       return SWITCH_STATUS_SUCCESS;
+error:
+       return SWITCH_STATUS_FALSE;
 }
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_cancel_real(const char *file, const char *func, int line, switch_pgsql_handle_t *handle)
+switch_status_t pgsql_handle_exec_base_detailed(const char *file, const char *func, int line,
+       switch_pgsql_handle_t *handle, const char *sql, char **err)
 {
-       switch_pgsql_status_t ret = SWITCH_PGSQL_SUCCESS;
-#ifdef SWITCH_HAVE_PGSQL
-       char err_buf[256];
-       PGcancel *cancel = NULL;
+       char *err_str = NULL;
+       char *er = NULL;
 
-       memset(err_buf, 0, 256);
-       cancel = PQgetCancel(handle->con);
-       if(!PQcancel(cancel, err_buf, 256)) {
-               switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CRIT, "Failed to cancel long-running query (%s): %s\n", handle->sql, err_buf);
-               ret = SWITCH_PGSQL_FAIL;
-       }
-       PQfreeCancel(cancel);
-       switch_pgsql_flush(handle);
+       pgsql_flush(handle);
+       handle->affected_rows = 0;
 
-#endif
-       return ret;
-}
+       if (!db_is_up(handle)) {
+               er = strdup("Database is not up!");
+               goto error;
+       }
 
+       if (handle->auto_commit == SWITCH_FALSE && handle->in_txn == SWITCH_FALSE) {
+               if (pgsql_send_query(handle, "BEGIN") != SWITCH_STATUS_SUCCESS) {
+                       er = strdup("Error sending BEGIN!");
+                       if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
+                               db_is_up(handle); /* If finish_results failed, maybe the db went dead */
+                       }
+                       goto error;
+               }
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsql_handle_t *handle, switch_pgsql_result_t **result_out, int msec)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       switch_pgsql_result_t *res;
-       switch_time_t start;
-       switch_time_t ctime;
-       unsigned int usec = msec * 1000;
-       char *err_str;
-#ifndef _WIN32
-       struct pollfd fds[2] = { { 0 } };
-#else
-       fd_set rs, es;
-#endif
-       int poll_res = 0;
+               if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
+                       db_is_up(handle);
+                       er = strdup("Error sending BEGIN!");
+                       goto error;
+               }
+               handle->in_txn = SWITCH_TRUE;
+       }
 
-       if(!handle) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "**BUG** Null handle passed to switch_pgsql_next_result.\n");
-               return SWITCH_PGSQL_FAIL;
+       if (pgsql_send_query(handle, sql) != SWITCH_STATUS_SUCCESS) {
+               er = strdup("Error sending query!");
+               if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
+                       db_is_up(handle);
+               }
+               goto error;
        }
 
-       /* Try to consume input that might be waiting right away */
-       if (PQconsumeInput(handle->con)) {
-               /* And check to see if we have a full result ready for reading */
-               if (PQisBusy(handle->con)) {
+       return SWITCH_STATUS_SUCCESS;
 
-                       /* Wait for a result to become available, up to msec milliseconds */
-                       start = switch_micro_time_now();
-                       while((ctime = switch_micro_time_now()) - start <= usec) {
-                               int wait_time = (usec - (ctime - start)) / 1000;
-                               /* Wait for the PostgreSQL socket to be ready for data reads. */
-#ifndef _WIN32
-                               fds[0].fd = handle->sock;
-                               fds[0].events |= POLLIN;
-                               fds[0].events |= POLLERR;
-                               fds[0].events |= POLLNVAL;
-                               fds[0].events |= POLLHUP;
-                               fds[0].events |= POLLPRI;
-                               fds[0].events |= POLLRDNORM;
-                               fds[0].events |= POLLRDBAND;
+error:
+       err_str = pgsql_handle_get_error(handle);
 
-                               poll_res = poll(&fds[0], 1, wait_time);
+       if (zstr(err_str)) {
+               if (zstr(er)) {
+                       err_str = strdup((char *)"SQL ERROR!");
+               } else {
+                       err_str = er;
+               }
+       } else {
+               if (!zstr(er)) {
+                       free(er);
+               }
+       }
+
+       if (err_str) {
+               if (!switch_stristr("already exists", err_str) && !switch_stristr("duplicate key name", err_str)) {
+                       switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+               }
+
+               if (err) {
+                       *err = err_str;
+               } else {
+                       free(err_str);
+               }
+       }
+
+       return SWITCH_STATUS_FALSE;
+}
+
+
+switch_status_t pgsql_handle_exec_detailed(const char *file, const char *func, int line,
+       switch_pgsql_handle_t *handle, const char *sql, char **err)
+{
+       if (pgsql_handle_exec_base_detailed(file, func, line, handle, sql, err) == SWITCH_STATUS_FALSE) {
+               goto error;
+       }
+
+       return pgsql_finish_results(handle);
+error:
+       return SWITCH_STATUS_FALSE;
+}
+
+switch_status_t database_handle_exec_detailed(const char *file, const char *func, int line, 
+       switch_database_interface_handle_t *dih, const char *sql, char **err)
+{
+       switch_pgsql_handle_t *handle;
+
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       handle = dih->handle;
+
+       return pgsql_handle_exec_detailed(file, func, line, handle, sql, err);
+}
+
+switch_status_t database_handle_exec_string(switch_database_interface_handle_t *dih, const char *sql, char *resbuf, size_t len, char **err)
+{
+       switch_pgsql_handle_t *handle;
+       switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
+       char *val = NULL;
+       switch_pgsql_result_t *result = NULL;
+
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       handle = dih->handle;
+
+       if (!handle)
+               return SWITCH_STATUS_FALSE;
+
+       handle->affected_rows = 0;
+
+       if (pgsql_handle_exec_base(handle, sql, err) == SWITCH_STATUS_FALSE) {
+               goto error;
+       }
+
+       if (pgsql_next_result(handle, &result) == SWITCH_STATUS_FALSE) {
+               goto error;
+       }
+
+       if (result) {
+               switch (result->status) {
+#if POSTGRESQL_MAJOR_VERSION >= 9 && POSTGRESQL_MINOR_VERSION >= 2
+               case PGRES_SINGLE_TUPLE:
+                       /* Added in PostgreSQL 9.2 */
+#endif
+               case PGRES_COMMAND_OK:
+               case PGRES_TUPLES_OK:
+                       break;
+               default:
+                       sstatus = SWITCH_STATUS_FALSE;
+                       goto done;
+               }
+       }
+
+       if (handle->affected_rows <= 0) {
+               goto done;
+       }
+
+       val = PQgetvalue(result->result, 0, 0);
+       strncpy(resbuf, val, len);
+
+done:
+
+       pgsql_free_result(&result);
+       if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
+               sstatus = SWITCH_STATUS_FALSE;
+       }
+
+       return sstatus;
+
+error:
+
+       return SWITCH_STATUS_FALSE;
+}
+
+switch_status_t pgsql_next_result_timed(switch_pgsql_handle_t *handle, switch_pgsql_result_t **result_out, int msec)
+{
+       switch_pgsql_result_t *res;
+       switch_time_t start;
+       switch_time_t ctime;
+       unsigned int usec = msec * 1000;
+       char *err_str;
+#ifndef _WIN32
+       struct pollfd fds[2] = { { 0 } };
+#else
+       fd_set rs, es;
+#endif
+       int poll_res = 0;
+
+       if (!handle) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "**BUG** Null handle passed to pgsql_next_result.\n");
+               return SWITCH_STATUS_FALSE;
+       }
+
+       /* Try to consume input that might be waiting right away */
+       if (PQconsumeInput(handle->con)) {
+               /* And check to see if we have a full result ready for reading */
+               if (PQisBusy(handle->con)) {
+
+                       /* Wait for a result to become available, up to msec milliseconds */
+                       start = switch_micro_time_now();
+                       while ((ctime = switch_micro_time_now()) - start <= usec) {
+                               switch_time_t wait_time = (usec - (ctime - start)) / 1000;
+                               /* Wait for the PostgreSQL socket to be ready for data reads. */
+#ifndef _WIN32
+                               fds[0].fd = handle->sock;
+                               fds[0].events |= POLLIN;
+                               fds[0].events |= POLLERR;
+                               fds[0].events |= POLLNVAL;
+                               fds[0].events |= POLLHUP;
+                               fds[0].events |= POLLPRI;
+                               fds[0].events |= POLLRDNORM;
+                               fds[0].events |= POLLRDBAND;
+
+                               poll_res = poll(&fds[0], 1, wait_time);
 #else
-                               struct timeval wait = { wait_time * 1000, 0};   
+                               struct timeval wait = { (long)wait_time * 1000, 0 };
                                FD_ZERO(&rs);
                                FD_SET(handle->sock, &rs);
                                FD_ZERO(&es);
                                FD_SET(handle->sock, &es);
                                poll_res = select(0, &rs, 0, &es, &wait);
 #endif
-                               if (poll_res > 0 ) {
+                               if (poll_res > 0) {
 #ifndef _WIN32
                                        if (fds[0].revents & POLLHUP || fds[0].revents & POLLNVAL) {
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "PGSQL socket closed or invalid while waiting for result for query (%s)\n", handle->sql);
@@ -366,10 +676,10 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
                                                        }
                                                } else {
                                                        /* If we had an error trying to consume input, report it and cancel the query. */
-                                                       err_str = switch_pgsql_handle_get_error(handle);
+                                                       err_str = pgsql_handle_get_error(handle);
                                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "An error occurred trying to consume input for query (%s): %s\n", handle->sql, err_str);
                                                        switch_safe_free(err_str);
-                                                       switch_pgsql_cancel(handle);
+                                                       pgsql_cancel(handle);
                                                        goto error;
                                                }
                                        }
@@ -382,49 +692,47 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
                        /* If we broke the loop above because of a timeout, report that and cancel the query. */
                        if (ctime - start > usec) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Query (%s) took too long to complete or database not responding.\n", handle->sql);
-                               switch_pgsql_cancel(handle);
+                               pgsql_cancel(handle);
                                goto error;
                        }
-
                }
        } else {
                /* If we had an error trying to consume input, report it and cancel the query. */
-               err_str = switch_pgsql_handle_get_error(handle);
+               err_str = pgsql_handle_get_error(handle);
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "An error occurred trying to consume input for query (%s): %s\n", handle->sql, err_str);
                switch_safe_free(err_str);
-               /* switch_pgsql_cancel(handle); */
+               /* pgsql_cancel(handle); */
                goto error;
        }
 
-
        /* At this point, we know we can read a full result without blocking. */
-       if(!(res = malloc(sizeof(switch_pgsql_result_t)))) {
+       if (!(res = malloc(sizeof(switch_pgsql_result_t)))) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Malloc failed!\n");
                goto error;
        }
-       memset(res, 0, sizeof(switch_pgsql_result_t));
 
+       memset(res, 0, sizeof(switch_pgsql_result_t));
 
        res->result = PQgetResult(handle->con);
        if (res->result) {
                *result_out = res;
                res->status = PQresultStatus(res->result);
-               switch(res->status) {
-#if (POSTGRESQL_MAJOR_VERSION == 9 && POSTGRESQL_MINOR_VERSION >= 2) || POSTGRESQL_MAJOR_VERSION > 9
+               switch (res->status) {
+//#if (POSTGRESQL_MAJOR_VERSION == 9 && POSTGRESQL_MINOR_VERSION >= 2) || POSTGRESQL_MAJOR_VERSION > 9
                case PGRES_SINGLE_TUPLE:
                        /* Added in PostgreSQL 9.2 */
-#endif
+//#endif
                case PGRES_TUPLES_OK:
-                       {
-                               res->rows = PQntuples(res->result);
-                               handle->affected_rows = res->rows;
-                               res->cols = PQnfields(res->result);
-                       }
-                       break;
-#if (POSTGRESQL_MAJOR_VERSION == 9 && POSTGRESQL_MINOR_VERSION >= 1) || POSTGRESQL_MAJOR_VERSION > 9
+               {
+                       res->rows = PQntuples(res->result);
+                       handle->affected_rows = res->rows;
+                       res->cols = PQnfields(res->result);
+               }
+               break;
+//#if (POSTGRESQL_MAJOR_VERSION == 9 && POSTGRESQL_MINOR_VERSION >= 1) || POSTGRESQL_MAJOR_VERSION > 9
                case PGRES_COPY_BOTH:
                        /* Added in PostgreSQL 9.1 */
-#endif
+//#endif
                case PGRES_COPY_OUT:
                case PGRES_COPY_IN:
                case PGRES_COMMAND_OK:
@@ -447,271 +755,169 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
                *result_out = NULL;
        }
 
-       return SWITCH_PGSQL_SUCCESS;
- error:
+       return SWITCH_STATUS_SUCCESS;
+error:
 
        /* Make sure the failed connection does not have any transactions marked as in progress */
-       switch_pgsql_flush(handle);
+       pgsql_flush(handle);
 
        /* Try to reconnect to the DB if we were dropped */
        db_is_up(handle);
 
-#endif
-       return SWITCH_PGSQL_FAIL;
+       return SWITCH_STATUS_FALSE;
 }
 
-SWITCH_DECLARE(void) switch_pgsql_free_result(switch_pgsql_result_t **result)
+switch_status_t pgsql_cancel_real(const char *file, const char *func, int line, switch_pgsql_handle_t *handle)
 {
-#ifdef SWITCH_HAVE_PGSQL
+       switch_status_t ret = SWITCH_STATUS_SUCCESS;
+       char err_buf[256];
+       PGcancel *cancel = NULL;
 
-       if (!*result) {
-               return;
-       }
+       memset(err_buf, 0, 256);
+       cancel = PQgetCancel(handle->con);
 
-       if ((*result)->result) {
-               PQclear((*result)->result);
+       if (!PQcancel(cancel, err_buf, 256)) {
+               switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CRIT, "Failed to cancel long-running query (%s): %s\n", handle->sql, err_buf);
+               ret = SWITCH_STATUS_FALSE;
        }
-       free(*result);
-       *result = NULL;
-#else
-       return;
-#endif
-}
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_finish_results_real(const char* file, const char* func, int line, switch_pgsql_handle_t *handle)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       switch_pgsql_result_t *res = NULL;
-       switch_pgsql_status_t final_status = SWITCH_PGSQL_SUCCESS;
-       int done = 0;
-       do {
-               switch_pgsql_next_result(handle, &res);
-               if (res && res->err && !switch_stristr("already exists", res->err) && !switch_stristr("duplicate key name", res->err)) {
-                       switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Error executing query:\n%s\n", res->err);
-                       final_status = SWITCH_PGSQL_FAIL;
-               }
-
-               if (!res) {
-                       done = 1;
-               } else if (res->result) {
-                       char *affected_rows = PQcmdTuples(res->result);
 
-                       if (!zstr(affected_rows)) {
-                               handle->affected_rows = atoi(affected_rows);
-                       }
-               }
+       PQfreeCancel(cancel);
+       pgsql_flush(handle);
 
-               switch_pgsql_free_result(&res);
-       } while (!done);
-       return final_status;
-#else
-       return SWITCH_PGSQL_FAIL;
-#endif
+       return ret;
 }
 
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_connect(switch_pgsql_handle_t *handle)
+switch_status_t pgsql_SQLSetAutoCommitAttr(switch_database_interface_handle_t *dih, switch_bool_t on)
 {
-#ifdef SWITCH_HAVE_PGSQL
-       if (handle->state == SWITCH_PGSQL_STATE_CONNECTED) {
-               switch_pgsql_handle_disconnect(handle);
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Re-connecting %s\n", handle->dsn);
-       }
+       switch_pgsql_handle_t *handle;
 
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Connecting %s\n", handle->dsn);
-       PQinitSSL(0);
-       handle->con = PQconnectdb(handle->dsn);
-       if (PQstatus(handle->con) != CONNECTION_OK) {
-               char *err_str;
-               if ((err_str = switch_pgsql_handle_get_error(handle))) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err_str);
-                       switch_safe_free(err_str);
-               } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to connect to the database [%s]\n", handle->dsn);
-                       switch_pgsql_handle_disconnect(handle);
-               }
-               return SWITCH_PGSQL_FAIL;
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
        }
 
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Connected to [%s]\n", handle->dsn);
-       handle->state = SWITCH_PGSQL_STATE_CONNECTED;
-       handle->sock = PQsocket(handle->con);
-       return SWITCH_PGSQL_SUCCESS;
-#else
-       return SWITCH_PGSQL_FAIL;
-#endif
-}
-
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_string_detailed(const char *file, const char *func, int line,
-                                                                                                                                                          switch_pgsql_handle_t *handle, const char *sql, char *resbuf, size_t len, char **err)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       switch_pgsql_status_t sstatus = SWITCH_PGSQL_SUCCESS;
-       char *val = NULL;
-       switch_pgsql_result_t *result = NULL;
+       handle = dih->handle;
 
-       handle->affected_rows = 0;
+       if (!handle)
+               return SWITCH_STATUS_FALSE;
 
-       if (switch_pgsql_handle_exec_base_detailed(file, func, line, handle, sql, err) == SWITCH_PGSQL_FAIL) {
-               goto error;
+       if (on) {
+               handle->auto_commit = SWITCH_TRUE;
+       } else {
+               handle->auto_commit = SWITCH_FALSE;
        }
 
-       if(switch_pgsql_next_result(handle, &result) == SWITCH_PGSQL_FAIL) {
-               goto error;
-       }
+       return SWITCH_STATUS_SUCCESS;
+}
 
-       if (result) {
-               switch (result->status) {
-#if POSTGRESQL_MAJOR_VERSION >= 9 && POSTGRESQL_MINOR_VERSION >= 2
-               case PGRES_SINGLE_TUPLE:
-                       /* Added in PostgreSQL 9.2 */
-#endif
-               case PGRES_COMMAND_OK:
-               case PGRES_TUPLES_OK:
-                       break;
-               default:
-                       sstatus = SWITCH_PGSQL_FAIL;
-                       goto done;
-               }
-       }
+switch_status_t pgsql_SQLEndTran(switch_pgsql_handle_t *handle, switch_bool_t commit)
+{
+       char * err_str = NULL;
 
-       if (handle->affected_rows <= 0) {
-               goto done;
+       if (!handle) {
+               return SWITCH_STATUS_FALSE;
        }
 
-       val = PQgetvalue(result->result, 0, 0);
-       strncpy(resbuf, val, len);
-
-       done:
-
-       switch_pgsql_free_result(&result);
-       if (switch_pgsql_finish_results(handle) != SWITCH_PGSQL_SUCCESS) {
-               sstatus = SWITCH_PGSQL_FAIL;
+       if (commit) {
+               if (!PQsendQuery(handle->con, "COMMIT")) {
+                       err_str = pgsql_handle_get_error(handle);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not commit transaction: %s\n", err_str);
+                       switch_safe_free(err_str);
+                       return SWITCH_STATUS_FALSE;
+               }
+       } else {
+               if (!PQsendQuery(handle->con, "ROLLBACK")) {
+                       err_str = pgsql_handle_get_error(handle);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not rollback transaction: %s\n", err_str);
+                       switch_safe_free(err_str);
+                       return SWITCH_STATUS_FALSE;
+               }
        }
+       handle->in_txn = SWITCH_FALSE;
 
-       return sstatus;
- error:
-       return SWITCH_PGSQL_FAIL;
-#else
-       return SWITCH_PGSQL_FAIL;
-#endif
+       return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_base_detailed(const char *file, const char *func, int line,
-                                                                                                                                                        switch_pgsql_handle_t *handle, const char *sql, char **err)
+switch_status_t database_commit(switch_database_interface_handle_t *dih)
 {
-#ifdef SWITCH_HAVE_PGSQL
-       char *err_str = NULL, *er = NULL;
-
-
+       switch_status_t result;
 
-       switch_pgsql_flush(handle);
-       handle->affected_rows = 0;
+       switch_pgsql_handle_t *handle;
 
-       if (!db_is_up(handle)) {
-               er = strdup("Database is not up!");
-               goto error;
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
        }
 
-       if (handle->auto_commit == SWITCH_FALSE && handle->in_txn == SWITCH_FALSE) {
-               if (switch_pgsql_send_query(handle, "BEGIN") != SWITCH_PGSQL_SUCCESS) {
-                       er = strdup("Error sending BEGIN!");
-                       if (switch_pgsql_finish_results(handle) != SWITCH_PGSQL_SUCCESS) {
-                               db_is_up(handle); /* If finish_results failed, maybe the db went dead */
-                       }
-                       goto error;
-               }
+       handle = dih->handle;
 
-               if (switch_pgsql_finish_results(handle) != SWITCH_PGSQL_SUCCESS) {
-                       db_is_up(handle);
-                       er = strdup("Error sending BEGIN!");
-                       goto error;
-               }
-               handle->in_txn = SWITCH_TRUE;
-       }
+       if (!handle)
+               return SWITCH_STATUS_FALSE;
 
-       if (switch_pgsql_send_query(handle, sql) != SWITCH_PGSQL_SUCCESS) {
-               er = strdup("Error sending query!");
-               if (switch_pgsql_finish_results(handle) != SWITCH_PGSQL_SUCCESS) {
-                       db_is_up(handle);
-               }
-               goto error;
-       }
+       result = pgsql_SQLEndTran(handle, SWITCH_TRUE);
+       result = result && pgsql_SQLSetAutoCommitAttr(dih, SWITCH_TRUE);
+       result = result && pgsql_finish_results(handle);
 
-       return SWITCH_PGSQL_SUCCESS;
+       return result;
+}
 
-  error:
-       err_str = switch_pgsql_handle_get_error(handle);
+switch_status_t database_rollback(switch_database_interface_handle_t *dih)
+{
+       switch_pgsql_handle_t *handle;
 
-       if (zstr(err_str)) {
-               if (zstr(er)) {
-                       err_str = strdup((char *)"SQL ERROR!");
-               } else {
-                       err_str = er;
-               }
-       } else {
-               if (!zstr(er)) {
-                       free(er);
-               }
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
        }
 
-       if (err_str) {
-               if (!switch_stristr("already exists", err_str) && !switch_stristr("duplicate key name", err_str)) {
-                       switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
-               }
-               if (err) {
-                       *err = err_str;
-               } else {
-                       free(err_str);
-               }
-       }
-#endif
-       return SWITCH_PGSQL_FAIL;
-}
+       handle = dih->handle;
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_detailed(const char *file, const char *func, int line,
-                                                                                                                                               switch_pgsql_handle_t *handle, const char *sql, char **err)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       if (switch_pgsql_handle_exec_base_detailed(file, func, line, handle, sql, err) == SWITCH_PGSQL_FAIL) {
-               goto error;
-       }
+       if (!handle)
+               return SWITCH_STATUS_FALSE;
 
-       return switch_pgsql_finish_results(handle);
-  error:
-#endif
-       return SWITCH_PGSQL_FAIL;
+       pgsql_SQLEndTran(handle, SWITCH_FALSE);
+       // Is that enought?
+
+       return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed(const char *file, const char *func, int line,
-                                                                                                                                                          switch_pgsql_handle_t *handle,
-                                                                                                                                                          const char *sql, switch_core_db_callback_func_t callback, void *pdata,
-                                                                                                                                                          char **err)
+switch_status_t pgsql_handle_callback_exec_detailed(const char *file, const char *func, int line,
+       switch_database_interface_handle_t *dih, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
 {
-#ifdef SWITCH_HAVE_PGSQL
        char *err_str = NULL;
        int row = 0, col = 0, err_cnt = 0;
        switch_pgsql_result_t *result = NULL;
 
+       switch_pgsql_handle_t *handle;
+
+       if (!dih) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       handle = dih->handle;
+
+       if (!handle) {
+               return SWITCH_STATUS_FALSE;
+       }
+
        handle->affected_rows = 0;
 
        switch_assert(callback != NULL);
 
-       if (switch_pgsql_handle_exec_base(handle, sql, err) == SWITCH_PGSQL_FAIL) {
+       if (pgsql_handle_exec_base(handle, sql, err) == SWITCH_STATUS_FALSE) {
                goto error;
        }
 
-       if (switch_pgsql_next_result(handle, &result) == SWITCH_PGSQL_FAIL) {
+       if (pgsql_next_result(handle, &result) == SWITCH_STATUS_FALSE) {
                err_cnt++;
-               err_str = switch_pgsql_handle_get_error(handle);
+               err_str = pgsql_handle_get_error(handle);
+
                if (result && !zstr(result->err)) {
                        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(result->err));
                }
+
                if (!zstr(err_str)) {
                        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
                }
+
                switch_safe_free(err_str);
-               err_str = NULL;
        }
 
        while (result != NULL) {
@@ -727,17 +933,17 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed
 
                        for (col = 0; col < result->cols; ++col) {
                                char * tmp;
-                               int len;
+                               size_t len;
 
                                tmp = PQfname(result->result, col);
                                if (tmp) {
                                        len = strlen(tmp);
-                                       names[col] = malloc(len+1);
+                                       names[col] = malloc(len + 1);
                                        names[col][len] = '\0';
                                        strncpy(names[col], tmp, len);
 
                                        len = PQgetlength(result->result, row, col);
-                                       vals[col] = malloc(len+1);
+                                       vals[col] = malloc(len + 1);
                                        vals[col][len] = '\0';
                                        tmp = PQgetvalue(result->result, row, col);
                                        strncpy(vals[col], tmp, len);
@@ -750,7 +956,7 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed
 
                        /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing callback for row %d...\n", row);*/
                        if (callback(pdata, result->cols, vals, names)) {
-                               switch_pgsql_finish_results(handle); /* Makes sure next call to switch_pgsql_next_result will return NULL */
+                               pgsql_finish_results(handle); /* Makes sure next call to switch_pgsql_next_result will return NULL */
                                row = result->rows;                  /* Makes us exit the for loop */
                        }
 
@@ -758,161 +964,74 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed
                                free(names[col]);
                                free(vals[col]);
                        }
+
                        free(names);
                        free(vals);
                }
-               switch_pgsql_free_result(&result);
-               if (switch_pgsql_next_result(handle, &result) == SWITCH_PGSQL_FAIL) {
+
+               pgsql_free_result(&result);
+
+               if (pgsql_next_result(handle, &result) == SWITCH_STATUS_FALSE) {
                        err_cnt++;
-                       err_str = switch_pgsql_handle_get_error(handle);
+                       err_str = pgsql_handle_get_error(handle);
+
                        if (result && !zstr(result->err)) {
                                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(result->err));
                        }
+
                        if (!zstr(err_str)) {
                                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
                        }
                        switch_safe_free(err_str);
-                       err_str = NULL;
                }
        }
+
        if (err_cnt) {
                goto error;
        }
 
-       return SWITCH_PGSQL_SUCCESS;
- error:
-#endif
-       return SWITCH_PGSQL_FAIL;
-}
-
-SWITCH_DECLARE(void) switch_pgsql_handle_destroy(switch_pgsql_handle_t **handlep)
-{
-#ifdef SWITCH_HAVE_PGSQL
-
-       switch_pgsql_handle_t *handle = NULL;
-
-       if (!handlep) {
-               return;
-       }
-       handle = *handlep;
-
-       if (handle) {
-               switch_pgsql_handle_disconnect(handle);
-
-               switch_safe_free(handle->dsn);
-               free(handle);
-       }
-       *handlep = NULL;
-#else
-       return;
-#endif
-}
-
-SWITCH_DECLARE(switch_pgsql_state_t) switch_pgsql_handle_get_state(switch_pgsql_handle_t *handle)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       return handle ? handle->state : SWITCH_PGSQL_STATE_INIT;
-#else
-       return SWITCH_PGSQL_STATE_ERROR;
-#endif
-}
-
-SWITCH_DECLARE(char *) switch_pgsql_handle_get_error(switch_pgsql_handle_t *handle)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       char * err_str;
-       if (!handle) {
-               return NULL;
-       };
-       switch_strdup(err_str, PQerrorMessage(handle->con));
-       return err_str;
-#else
-       return NULL;
-#endif
-}
-
-SWITCH_DECLARE(int) switch_pgsql_handle_affected_rows(switch_pgsql_handle_t *handle)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       return handle->affected_rows;
-#else
-       return 0;
-#endif
-}
-
-SWITCH_DECLARE(switch_bool_t) switch_pgsql_available(void)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       return SWITCH_TRUE;
-#else
-       return SWITCH_FALSE;
-#endif
-}
+       return SWITCH_STATUS_SUCCESS;
+error:
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_SQLSetAutoCommitAttr(switch_pgsql_handle_t *handle, switch_bool_t on)
-{
-#ifdef SWITCH_HAVE_PGSQL
-       if (on) {
-               handle->auto_commit = SWITCH_TRUE;
-       } else {
-               handle->auto_commit = SWITCH_FALSE;
-       }
-       return SWITCH_PGSQL_SUCCESS;
-#else
-       return (switch_pgsql_status_t) SWITCH_FALSE;
-#endif
+       return SWITCH_STATUS_FALSE;
 }
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_flush(switch_pgsql_handle_t *handle)
+SWITCH_MODULE_LOAD_FUNCTION(mod_pgsql_load)
 {
-#ifdef SWITCH_HAVE_PGSQL
-
-       PGresult *tmp = NULL;
-       int x = 0;
-
-       /* Make sure the query is fully cleared */
-       while ((tmp = PQgetResult(handle->con)) != NULL) {
-               PQclear(tmp);
-               x++;
-       }
-
-       if (x) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Flushing %d results\n", x);
-       }
-
-       return SWITCH_PGSQL_SUCCESS;
-#else
-       return (switch_pgsql_status_t) SWITCH_FALSE;
-#endif
+       switch_database_interface_t *database_interface;
+
+       supported_prefixes[0] = (char *)"pgsql";
+       supported_prefixes[1] = (char *)"postgres";
+       supported_prefixes[2] = (char *)"postgresql";
+
+       /* connect my internal structure to the blank pointer passed to me */
+       *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+       MODULE_INTERFACE = *module_interface;
+
+       database_interface = (switch_database_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_DATABASE_INTERFACE);
+       database_interface->flags = 0;
+       database_interface->interface_name = modname;
+       database_interface->prefixes = supported_prefixes;
+       database_interface->handle_new = pgsql_handle_new;
+       database_interface->handle_destroy = pgsql_handle_destroy;
+       database_interface->flush = database_flush;
+       database_interface->exec_detailed = database_handle_exec_detailed;
+       database_interface->exec_string = database_handle_exec_string;
+       database_interface->affected_rows = pgsql_handle_affected_rows;
+       database_interface->sql_set_auto_commit_attr = pgsql_SQLSetAutoCommitAttr;
+       database_interface->commit = database_commit;
+       database_interface->rollback = database_rollback;
+       database_interface->callback_exec_detailed = pgsql_handle_callback_exec_detailed;
+       
+       /* indicate that the module should continue to be loaded */
+       return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_SQLEndTran(switch_pgsql_handle_t *handle, switch_bool_t commit)
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_pgsql_shutdown)
 {
-#ifdef SWITCH_HAVE_PGSQL
-       char * err_str = NULL;
-       if (commit) {
-               if(!PQsendQuery(handle->con, "COMMIT")) {
-                       err_str = switch_pgsql_handle_get_error(handle);
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not commit transaction: %s\n", err_str);
-                       switch_safe_free(err_str);
-                       return SWITCH_PGSQL_FAIL;
-               }
-       } else {
-               if(!PQsendQuery(handle->con, "ROLLBACK")) {
-                       err_str = switch_pgsql_handle_get_error(handle);
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not rollback transaction: %s\n", err_str);
-                       switch_safe_free(err_str);
-                       return SWITCH_PGSQL_FAIL;
-               }
-       }
-       handle->in_txn = SWITCH_FALSE;
-       return SWITCH_PGSQL_SUCCESS;
-#else
-       return (switch_pgsql_status_t) SWITCH_FALSE;
-#endif
+       return SWITCH_STATUS_UNLOAD;
 }
 
-
 /* For Emacs:
  * Local Variables:
  * mode:c
index 7c37b896309a0cf2b1742f1d86489f08d363c7b8..93f5793971a96196f43d2ec2f4085a993e9b1b1a 100644 (file)
@@ -5,9 +5,9 @@ if HAVE_PGSQL
 
 mod_LTLIBRARIES = mod_cdr_pg_csv.la
 mod_cdr_pg_csv_la_SOURCES  = mod_cdr_pg_csv.c
-mod_cdr_pg_csv_la_CFLAGS   = $(AM_CFLAGS) $(SWITCH_AM_CXXFLAGS)
+mod_cdr_pg_csv_la_CFLAGS   = $(AM_CFLAGS) $(SWITCH_AM_CXXFLAGS) $(POSTGRESQL_CFLAGS)
 mod_cdr_pg_csv_la_LIBADD   = $(switch_builddir)/libfreeswitch.la
-mod_cdr_pg_csv_la_LDFLAGS  = -avoid-version -module -no-undefined -shared -lpq $(SWITCH_AM_LDFLAGS)
+mod_cdr_pg_csv_la_LDFLAGS  = -avoid-version -module -no-undefined -shared -lpq $(SWITCH_AM_LDFLAGS) $(POSTGRESQL_LDFLAGS)
 
 else
 install: error
index f7d5e0a44c17f06420094f14e0941488326ec6b7..8377080f6f4b015b4b47353a54bdd7829dad7fa5 100644 (file)
@@ -16978,28 +16978,6 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_native_ha
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_native_handle_t_pgsql_dbh_set___(void * jarg1, void * jarg2) {
-  switch_cache_db_native_handle_t *arg1 = (switch_cache_db_native_handle_t *) 0 ;
-  switch_pgsql_handle_t *arg2 = (switch_pgsql_handle_t *) 0 ;
-  
-  arg1 = (switch_cache_db_native_handle_t *)jarg1; 
-  arg2 = (switch_pgsql_handle_t *)jarg2; 
-  if (arg1) (arg1)->pgsql_dbh = arg2;
-}
-
-
-SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_native_handle_t_pgsql_dbh_get___(void * jarg1) {
-  void * jresult ;
-  switch_cache_db_native_handle_t *arg1 = (switch_cache_db_native_handle_t *) 0 ;
-  switch_pgsql_handle_t *result = 0 ;
-  
-  arg1 = (switch_cache_db_native_handle_t *)jarg1; 
-  result = (switch_pgsql_handle_t *) ((arg1)->pgsql_dbh);
-  jresult = (void *)result; 
-  return jresult;
-}
-
-
 SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_native_handle_t_database_interface_dbh_set___(void * jarg1, void * jarg2) {
   switch_cache_db_native_handle_t *arg1 = (switch_cache_db_native_handle_t *) 0 ;
   switch_database_interface_handle_t *arg2 = (switch_database_interface_handle_t *) 0 ;
@@ -17196,79 +17174,60 @@ SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_delete_switch_cache_db_odbc
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_pgsql_options_t_dsn_set___(void * jarg1, char * jarg2) {
-  switch_cache_db_pgsql_options_t *arg1 = (switch_cache_db_pgsql_options_t *) 0 ;
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_original_dsn_set___(void * jarg1, char * jarg2) {
+  switch_cache_db_database_interface_options_t *arg1 = (switch_cache_db_database_interface_options_t *) 0 ;
   char *arg2 = (char *) 0 ;
   
-  arg1 = (switch_cache_db_pgsql_options_t *)jarg1; 
+  arg1 = (switch_cache_db_database_interface_options_t *)jarg1; 
   arg2 = (char *)jarg2; 
   {
-    delete [] arg1->dsn;
     if (arg2) {
-      arg1->dsn = (char *) (new char[strlen((const char *)arg2)+1]);
-      strcpy((char *)arg1->dsn, (const char *)arg2);
+      arg1->original_dsn = (char const *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->original_dsn, (const char *)arg2);
     } else {
-      arg1->dsn = 0;
+      arg1->original_dsn = 0;
     }
   }
 }
 
 
-SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_pgsql_options_t_dsn_get___(void * jarg1) {
+SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_original_dsn_get___(void * jarg1) {
   char * jresult ;
-  switch_cache_db_pgsql_options_t *arg1 = (switch_cache_db_pgsql_options_t *) 0 ;
+  switch_cache_db_database_interface_options_t *arg1 = (switch_cache_db_database_interface_options_t *) 0 ;
   char *result = 0 ;
   
-  arg1 = (switch_cache_db_pgsql_options_t *)jarg1; 
-  result = (char *) ((arg1)->dsn);
+  arg1 = (switch_cache_db_database_interface_options_t *)jarg1; 
+  result = (char *) ((arg1)->original_dsn);
   jresult = SWIG_csharp_string_callback((const char *)result); 
   return jresult;
 }
 
 
-SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_switch_cache_db_pgsql_options_t___() {
-  void * jresult ;
-  switch_cache_db_pgsql_options_t *result = 0 ;
-  
-  result = (switch_cache_db_pgsql_options_t *)new switch_cache_db_pgsql_options_t();
-  jresult = (void *)result; 
-  return jresult;
-}
-
-
-SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_delete_switch_cache_db_pgsql_options_t___(void * jarg1) {
-  switch_cache_db_pgsql_options_t *arg1 = (switch_cache_db_pgsql_options_t *) 0 ;
-  
-  arg1 = (switch_cache_db_pgsql_options_t *)jarg1; 
-  delete arg1;
-}
-
-
-SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_dsn_set___(void * jarg1, char * jarg2) {
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_connection_string_set___(void * jarg1, char * jarg2) {
   switch_cache_db_database_interface_options_t *arg1 = (switch_cache_db_database_interface_options_t *) 0 ;
   char *arg2 = (char *) 0 ;
   
   arg1 = (switch_cache_db_database_interface_options_t *)jarg1; 
   arg2 = (char *)jarg2; 
   {
-    delete [] arg1->dsn;
+    delete [] arg1->connection_string;
     if (arg2) {
-      arg1->dsn = (char *) (new char[strlen((const char *)arg2)+1]);
-      strcpy((char *)arg1->dsn, (const char *)arg2);
+      arg1->connection_string = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->connection_string, (const char *)arg2);
     } else {
-      arg1->dsn = 0;
+      arg1->connection_string = 0;
     }
   }
 }
 
 
-SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_dsn_get___(void * jarg1) {
+SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_connection_string_get___(void * jarg1) {
   char * jresult ;
   switch_cache_db_database_interface_options_t *arg1 = (switch_cache_db_database_interface_options_t *) 0 ;
   char *result = 0 ;
   
   arg1 = (switch_cache_db_database_interface_options_t *)jarg1; 
-  result = (char *) ((arg1)->dsn);
+  result = (char *) ((arg1)->connection_string);
   jresult = SWIG_csharp_string_callback((const char *)result); 
   return jresult;
 }
@@ -17409,28 +17368,6 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_connectio
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_connection_options_t_pgsql_options_set___(void * jarg1, void * jarg2) {
-  switch_cache_db_connection_options_t *arg1 = (switch_cache_db_connection_options_t *) 0 ;
-  switch_cache_db_pgsql_options_t *arg2 = (switch_cache_db_pgsql_options_t *) 0 ;
-  
-  arg1 = (switch_cache_db_connection_options_t *)jarg1; 
-  arg2 = (switch_cache_db_pgsql_options_t *)jarg2; 
-  if (arg1) (arg1)->pgsql_options = *arg2;
-}
-
-
-SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_connection_options_t_pgsql_options_get___(void * jarg1) {
-  void * jresult ;
-  switch_cache_db_connection_options_t *arg1 = (switch_cache_db_connection_options_t *) 0 ;
-  switch_cache_db_pgsql_options_t *result = 0 ;
-  
-  arg1 = (switch_cache_db_connection_options_t *)jarg1; 
-  result = (switch_cache_db_pgsql_options_t *)& ((arg1)->pgsql_options);
-  jresult = (void *)result; 
-  return jresult;
-}
-
-
 SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_cache_db_connection_options_t_database_interface_options_set___(void * jarg1, void * jarg2) {
   switch_cache_db_connection_options_t *arg1 = (switch_cache_db_connection_options_t *) 0 ;
   switch_cache_db_database_interface_options_t *arg2 = (switch_cache_db_database_interface_options_t *) 0 ;
@@ -17817,6 +17754,18 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_core_check_core_db_ds
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_database_available___(char * jarg1) {
+  int jresult ;
+  char *arg1 = (char *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (char *)jarg1; 
+  result = (switch_status_t)switch_database_available(arg1);
+  jresult = (int)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_core_set_signal_handlers___() {
   switch_core_set_signal_handlers();
 }
@@ -31979,10 +31928,10 @@ SWIGEXPORT unsigned long SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_database_in
 
 SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_database_interface_handle_new_set___(void * jarg1, void * jarg2) {
   switch_database_interface *arg1 = (switch_database_interface *) 0 ;
-  switch_status_t (*arg2)(char *,switch_database_interface_handle_t **) = (switch_status_t (*)(char *,switch_database_interface_handle_t **)) 0 ;
+  switch_status_t (*arg2)(switch_cache_db_database_interface_options_t,switch_database_interface_handle_t **) = (switch_status_t (*)(switch_cache_db_database_interface_options_t,switch_database_interface_handle_t **)) 0 ;
   
   arg1 = (switch_database_interface *)jarg1; 
-  arg2 = (switch_status_t (*)(char *,switch_database_interface_handle_t **))jarg2; 
+  arg2 = (switch_status_t (*)(switch_cache_db_database_interface_options_t,switch_database_interface_handle_t **))jarg2; 
   if (arg1) (arg1)->handle_new = arg2;
 }
 
@@ -31990,10 +31939,10 @@ SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_database_interface_h
 SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_database_interface_handle_new_get___(void * jarg1) {
   void * jresult ;
   switch_database_interface *arg1 = (switch_database_interface *) 0 ;
-  switch_status_t (*result)(char *,switch_database_interface_handle_t **) = 0 ;
+  switch_status_t (*result)(switch_cache_db_database_interface_options_t,switch_database_interface_handle_t **) = 0 ;
   
   arg1 = (switch_database_interface *)jarg1; 
-  result = (switch_status_t (*)(char *,switch_database_interface_handle_t **)) ((arg1)->handle_new);
+  result = (switch_status_t (*)(switch_cache_db_database_interface_options_t,switch_database_interface_handle_t **)) ((arg1)->handle_new);
   jresult = (void *)result; 
   return jresult;
 }
@@ -39404,31 +39353,53 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_event_channel_broadca
 }
 
 
-SWIGEXPORT unsigned long SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_event_channel_unbind___(char * jarg1, void * jarg2) {
+SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_event_channel_deliver___(char * jarg1, void * jarg2, char * jarg3, unsigned long jarg4) {
+  int jresult ;
+  char *arg1 = (char *) 0 ;
+  cJSON **arg2 = (cJSON **) 0 ;
+  char *arg3 = (char *) 0 ;
+  switch_event_channel_id_t arg4 ;
+  switch_status_t result;
+  
+  arg1 = (char *)jarg1; 
+  arg2 = (cJSON **)jarg2; 
+  arg3 = (char *)jarg3; 
+  arg4 = (switch_event_channel_id_t)jarg4; 
+  result = (switch_status_t)switch_event_channel_deliver((char const *)arg1,arg2,(char const *)arg3,arg4);
+  jresult = (int)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT unsigned long SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_event_channel_unbind___(char * jarg1, void * jarg2, void * jarg3) {
   unsigned long jresult ;
   char *arg1 = (char *) 0 ;
   switch_event_channel_func_t arg2 = (switch_event_channel_func_t) 0 ;
+  void *arg3 = (void *) 0 ;
   uint32_t result;
   
   arg1 = (char *)jarg1; 
   arg2 = (switch_event_channel_func_t)jarg2; 
-  result = (uint32_t)switch_event_channel_unbind((char const *)arg1,arg2);
+  arg3 = (void *)jarg3; 
+  result = (uint32_t)switch_event_channel_unbind((char const *)arg1,arg2,arg3);
   jresult = (unsigned long)result; 
   return jresult;
 }
 
 
-SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_event_channel_bind___(char * jarg1, void * jarg2, void * jarg3) {
+SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_event_channel_bind___(char * jarg1, void * jarg2, void * jarg3, void * jarg4) {
   int jresult ;
   char *arg1 = (char *) 0 ;
   switch_event_channel_func_t arg2 = (switch_event_channel_func_t) 0 ;
   switch_event_channel_id_t *arg3 = (switch_event_channel_id_t *) 0 ;
+  void *arg4 = (void *) 0 ;
   switch_status_t result;
   
   arg1 = (char *)jarg1; 
   arg2 = (switch_event_channel_func_t)jarg2; 
   arg3 = (switch_event_channel_id_t *)jarg3; 
-  result = (switch_status_t)switch_event_channel_bind((char const *)arg1,arg2,arg3);
+  arg4 = (void *)jarg4; 
+  result = (switch_status_t)switch_event_channel_bind((char const *)arg1,arg2,arg3,arg4);
   jresult = (int)result; 
   return jresult;
 }
@@ -43260,6 +43231,34 @@ SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_dial_handle_create___
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_dial_handle_create_json_obj___(void * jarg1, void * jarg2) {
+  int jresult ;
+  switch_dial_handle_t **arg1 = (switch_dial_handle_t **) 0 ;
+  cJSON *arg2 = (cJSON *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_dial_handle_t **)jarg1; 
+  arg2 = (cJSON *)jarg2; 
+  result = (switch_status_t)switch_dial_handle_create_json_obj(arg1,arg2);
+  jresult = (int)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_dial_handle_create_json___(void * jarg1, char * jarg2) {
+  int jresult ;
+  switch_dial_handle_t **arg1 = (switch_dial_handle_t **) 0 ;
+  char *arg2 = (char *) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_dial_handle_t **)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (switch_status_t)switch_dial_handle_create_json(arg1,(char const *)arg2);
+  jresult = (int)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_dial_handle_destroy___(void * jarg1) {
   switch_dial_handle_t **arg1 = (switch_dial_handle_t **) 0 ;
   
@@ -43268,6 +43267,34 @@ SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_dial_handle_destroy_
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_dial_handle_serialize_json_obj___(void * jarg1, void * jarg2) {
+  int jresult ;
+  switch_dial_handle_t *arg1 = (switch_dial_handle_t *) 0 ;
+  cJSON **arg2 = (cJSON **) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_dial_handle_t *)jarg1; 
+  arg2 = (cJSON **)jarg2; 
+  result = (switch_status_t)switch_dial_handle_serialize_json_obj(arg1,arg2);
+  jresult = (int)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_dial_handle_serialize_json___(void * jarg1, void * jarg2) {
+  int jresult ;
+  switch_dial_handle_t *arg1 = (switch_dial_handle_t *) 0 ;
+  char **arg2 = (char **) 0 ;
+  switch_status_t result;
+  
+  arg1 = (switch_dial_handle_t *)jarg1; 
+  arg2 = (char **)jarg2; 
+  result = (switch_status_t)switch_dial_handle_serialize_json(arg1,arg2);
+  jresult = (int)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_dial_handle_add_leg_list___(void * jarg1, void * jarg2) {
   switch_dial_handle_t *arg1 = (switch_dial_handle_t *) 0 ;
   switch_dial_leg_list_t **arg2 = (switch_dial_leg_list_t **) 0 ;
@@ -45864,6 +45891,433 @@ SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_delete_switch_log_node_t___
 }
 
 
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_item_t_name_set___(void * jarg1, char * jarg2) {
+  switch_log_json_format_item_t *arg1 = (switch_log_json_format_item_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_log_json_format_item_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg2) {
+      arg1->name = (char const *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->name, (const char *)arg2);
+    } else {
+      arg1->name = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_item_t_name_get___(void * jarg1) {
+  char * jresult ;
+  switch_log_json_format_item_t *arg1 = (switch_log_json_format_item_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_log_json_format_item_t *)jarg1; 
+  result = (char *) ((arg1)->name);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_item_t_value_set___(void * jarg1, char * jarg2) {
+  switch_log_json_format_item_t *arg1 = (switch_log_json_format_item_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_log_json_format_item_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg2) {
+      arg1->value = (char const *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->value, (const char *)arg2);
+    } else {
+      arg1->value = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_item_t_value_get___(void * jarg1) {
+  char * jresult ;
+  switch_log_json_format_item_t *arg1 = (switch_log_json_format_item_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_log_json_format_item_t *)jarg1; 
+  result = (char *) ((arg1)->value);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_switch_log_json_format_item_t___() {
+  void * jresult ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  result = (switch_log_json_format_item_t *)new switch_log_json_format_item_t();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_delete_switch_log_json_format_item_t___(void * jarg1) {
+  switch_log_json_format_item_t *arg1 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_item_t *)jarg1; 
+  delete arg1;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_version_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->version = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_version_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->version);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_host_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->host = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_host_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->host);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_timestamp_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->timestamp = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_timestamp_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->timestamp);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_level_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->level = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_level_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->level);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_ident_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->ident = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_ident_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->ident);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_pid_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->pid = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_pid_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->pid);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_uuid_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->uuid = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_uuid_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->uuid);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_file_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->file = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_file_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->file);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_line_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->line = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_line_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->line);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_function_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->function = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_function_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->function);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_full_message_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->full_message = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_full_message_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->full_message);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_short_message_set___(void * jarg1, void * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *arg2 = (switch_log_json_format_item_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (switch_log_json_format_item_t *)jarg2; 
+  if (arg1) (arg1)->short_message = *arg2;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_short_message_get___(void * jarg1) {
+  void * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  switch_log_json_format_item_t *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (switch_log_json_format_item_t *)& ((arg1)->short_message);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_custom_field_prefix_set___(void * jarg1, char * jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  {
+    if (arg2) {
+      arg1->custom_field_prefix = (char const *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->custom_field_prefix, (const char *)arg2);
+    } else {
+      arg1->custom_field_prefix = 0;
+    }
+  }
+}
+
+
+SWIGEXPORT char * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_custom_field_prefix_get___(void * jarg1) {
+  char * jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  char *result = 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (char *) ((arg1)->custom_field_prefix);
+  jresult = SWIG_csharp_string_callback((const char *)result); 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_timestamp_divisor_set___(void * jarg1, double jarg2) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  double arg2 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  arg2 = (double)jarg2; 
+  if (arg1) (arg1)->timestamp_divisor = arg2;
+}
+
+
+SWIGEXPORT double SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_json_format_t_timestamp_divisor_get___(void * jarg1) {
+  double jresult ;
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  double result;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  result = (double) ((arg1)->timestamp_divisor);
+  jresult = result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_new_switch_log_json_format_t___() {
+  void * jresult ;
+  switch_log_json_format_t *result = 0 ;
+  
+  result = (switch_log_json_format_t *)new switch_log_json_format_t();
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
+SWIGEXPORT void SWIGSTDCALL CSharp_FreeSWITCHfNative_delete_switch_log_json_format_t___(void * jarg1) {
+  switch_log_json_format_t *arg1 = (switch_log_json_format_t *) 0 ;
+  
+  arg1 = (switch_log_json_format_t *)jarg1; 
+  delete arg1;
+}
+
+
+SWIGEXPORT void * SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_node_to_json___(void * jarg1, int jarg2, void * jarg3, void * jarg4) {
+  void * jresult ;
+  switch_log_node_t *arg1 = (switch_log_node_t *) 0 ;
+  int arg2 ;
+  switch_log_json_format_t *arg3 = (switch_log_json_format_t *) 0 ;
+  switch_event_t *arg4 = (switch_event_t *) 0 ;
+  cJSON *result = 0 ;
+  
+  arg1 = (switch_log_node_t *)jarg1; 
+  arg2 = (int)jarg2; 
+  arg3 = (switch_log_json_format_t *)jarg3; 
+  arg4 = (switch_event_t *)jarg4; 
+  result = (cJSON *)switch_log_node_to_json((switch_log_node_t const *)arg1,arg2,arg3,arg4);
+  jresult = (void *)result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_FreeSWITCHfNative_switch_log_init___(void * jarg1, int jarg2) {
   int jresult ;
   switch_memory_pool_t *arg1 = (switch_memory_pool_t *) 0 ;
index 4efad57215bb260cf5558f3467f4a45e0a30e2e9..520762b029d7bde72ebc9bd83e45a57ddcade61c 100644 (file)
@@ -51,7 +51,7 @@
   <ItemGroup>\r
     <ProjectReference Include="..\..\FreeSWITCH.Managed.2017.csproj">\r
       <Project>{834e2b2f-5483-4b80-8fe3-fe48ff76e5c0}</Project>\r
-      <Name>FreeSWITCH.Managed.2015</Name>\r
+      <Name>FreeSWITCH.Managed.2017</Name>\r
     </ProjectReference>\r
   </ItemGroup>\r
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
index e2ae184d5ca51ad3320b2ad1c2a8f35032f6feb2..12cc81a347581fce10829f2c36f33fa88e18c559 100644 (file)
@@ -1083,35 +1083,6 @@ public class SWIGTYPE_p_f_p_char_enum_switch_management_action_t_p_char_switch_s
 
 namespace FreeSWITCH.Native {
 
-public class SWIGTYPE_p_f_p_char_p_p_switch_database_interface_handle__switch_status_t {
-  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
-
-  internal SWIGTYPE_p_f_p_char_p_p_switch_database_interface_handle__switch_status_t(global::System.IntPtr cPtr, bool futureUse) {
-    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-  }
-
-  protected SWIGTYPE_p_f_p_char_p_p_switch_database_interface_handle__switch_status_t() {
-    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-  }
-
-  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_f_p_char_p_p_switch_database_interface_handle__switch_status_t obj) {
-    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
-  }
-}
-
-}
-//------------------------------------------------------------------------------
-// <auto-generated />
-//
-// This file was automatically generated by SWIG (http://www.swig.org).
-// Version 3.0.10
-//
-// Do not make changes to this file unless you know what you are doing--modify
-// the SWIG interface file instead.
-//------------------------------------------------------------------------------
-
-namespace FreeSWITCH.Native {
-
 public class SWIGTYPE_p_f_p_p_switch_database_interface_handle__switch_status_t {
   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
@@ -1199,18 +1170,18 @@ public class SWIGTYPE_p_f_p_q_const__cJSON_p_switch_core_session_p_p_cJSON__swit
 
 namespace FreeSWITCH.Native {
 
-public class SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long__void {
+public class SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long_p_void__void {
   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
-  internal SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long__void(global::System.IntPtr cPtr, bool futureUse) {
+  internal SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long_p_void__void(global::System.IntPtr cPtr, bool futureUse) {
     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
   }
 
-  protected SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long__void() {
+  protected SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long_p_void__void() {
     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
   }
 
-  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long__void obj) {
+  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long_p_void__void obj) {
     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
   }
 }
@@ -4041,6 +4012,35 @@ public class SWIGTYPE_p_f_p_void_p_switch_event__int {
 
 namespace FreeSWITCH.Native {
 
+public class SWIGTYPE_p_f_switch_cache_db_database_interface_options_t_p_p_switch_database_interface_handle__switch_status_t {
+  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+
+  internal SWIGTYPE_p_f_switch_cache_db_database_interface_options_t_p_p_switch_database_interface_handle__switch_status_t(global::System.IntPtr cPtr, bool futureUse) {
+    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+  }
+
+  protected SWIGTYPE_p_f_switch_cache_db_database_interface_options_t_p_p_switch_database_interface_handle__switch_status_t() {
+    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+  }
+
+  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_f_switch_cache_db_database_interface_options_t_p_p_switch_database_interface_handle__switch_status_t obj) {
+    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+  }
+}
+
+}
+//------------------------------------------------------------------------------
+// <auto-generated />
+//
+// This file was automatically generated by SWIG (http://www.swig.org).
+// Version 3.0.10
+//
+// Do not make changes to this file unless you know what you are doing--modify
+// the SWIG interface file instead.
+//------------------------------------------------------------------------------
+
+namespace FreeSWITCH.Native {
+
 public class SWIGTYPE_p_f_uint8_t_p_p_q_const__char_p_void__p_switch_xml {
   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
@@ -6767,35 +6767,6 @@ public class SWIGTYPE_p_switch_odbc_handle {
 
 namespace FreeSWITCH.Native {
 
-public class SWIGTYPE_p_switch_pgsql_handle {
-  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
-
-  internal SWIGTYPE_p_switch_pgsql_handle(global::System.IntPtr cPtr, bool futureUse) {
-    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-  }
-
-  protected SWIGTYPE_p_switch_pgsql_handle() {
-    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-  }
-
-  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_switch_pgsql_handle obj) {
-    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
-  }
-}
-
-}
-//------------------------------------------------------------------------------
-// <auto-generated />
-//
-// This file was automatically generated by SWIG (http://www.swig.org).
-// Version 3.0.10
-//
-// Do not make changes to this file unless you know what you are doing--modify
-// the SWIG interface file instead.
-//------------------------------------------------------------------------------
-
-namespace FreeSWITCH.Native {
-
 public class SWIGTYPE_p_switch_pollfd_t {
   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
@@ -9961,6 +9932,11 @@ else
     return ret;
   }
 
+  public static switch_status_t switch_database_available(string dsn) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_database_available(dsn);
+    return ret;
+  }
+
   public static void switch_core_set_signal_handlers() {
     freeswitchPINVOKE.switch_core_set_signal_handlers();
   }
@@ -12536,13 +12512,18 @@ else
     return ret;
   }
 
-  public static uint switch_event_channel_unbind(string event_channel, SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long__void func) {
-    uint ret = freeswitchPINVOKE.switch_event_channel_unbind(event_channel, SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long__void.getCPtr(func));
+  public static switch_status_t switch_event_channel_deliver(string event_channel, SWIGTYPE_p_p_cJSON json, string key, uint id) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_channel_deliver(event_channel, SWIGTYPE_p_p_cJSON.getCPtr(json), key, id);
     return ret;
   }
 
-  public static switch_status_t switch_event_channel_bind(string event_channel, SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long__void func, SWIGTYPE_p_unsigned_long id) {
-    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_channel_bind(event_channel, SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long__void.getCPtr(func), SWIGTYPE_p_unsigned_long.getCPtr(id));
+  public static uint switch_event_channel_unbind(string event_channel, SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long_p_void__void func, SWIGTYPE_p_void user_data) {
+    uint ret = freeswitchPINVOKE.switch_event_channel_unbind(event_channel, SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long_p_void__void.getCPtr(func), SWIGTYPE_p_void.getCPtr(user_data));
+    return ret;
+  }
+
+  public static switch_status_t switch_event_channel_bind(string event_channel, SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long_p_void__void func, SWIGTYPE_p_unsigned_long id, SWIGTYPE_p_void user_data) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_event_channel_bind(event_channel, SWIGTYPE_p_f_p_q_const__char_p_cJSON_p_q_const__char_unsigned_long_p_void__void.getCPtr(func), SWIGTYPE_p_unsigned_long.getCPtr(id), SWIGTYPE_p_void.getCPtr(user_data));
     return ret;
   }
 
@@ -13526,10 +13507,30 @@ else
     return ret;
   }
 
+  public static switch_status_t switch_dial_handle_create_json_obj(SWIGTYPE_p_p_switch_dial_handle_s handle, SWIGTYPE_p_cJSON json) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_dial_handle_create_json_obj(SWIGTYPE_p_p_switch_dial_handle_s.getCPtr(handle), SWIGTYPE_p_cJSON.getCPtr(json));
+    return ret;
+  }
+
+  public static switch_status_t switch_dial_handle_create_json(SWIGTYPE_p_p_switch_dial_handle_s handle, string handle_string) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_dial_handle_create_json(SWIGTYPE_p_p_switch_dial_handle_s.getCPtr(handle), handle_string);
+    return ret;
+  }
+
   public static void switch_dial_handle_destroy(SWIGTYPE_p_p_switch_dial_handle_s handle) {
     freeswitchPINVOKE.switch_dial_handle_destroy(SWIGTYPE_p_p_switch_dial_handle_s.getCPtr(handle));
   }
 
+  public static switch_status_t switch_dial_handle_serialize_json_obj(SWIGTYPE_p_switch_dial_handle_s handle, SWIGTYPE_p_p_cJSON json) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_dial_handle_serialize_json_obj(SWIGTYPE_p_switch_dial_handle_s.getCPtr(handle), SWIGTYPE_p_p_cJSON.getCPtr(json));
+    return ret;
+  }
+
+  public static switch_status_t switch_dial_handle_serialize_json(SWIGTYPE_p_switch_dial_handle_s handle, ref string str) {
+    switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_dial_handle_serialize_json(SWIGTYPE_p_switch_dial_handle_s.getCPtr(handle), ref str);
+    return ret;
+  }
+
   public static void switch_dial_handle_add_leg_list(SWIGTYPE_p_switch_dial_handle_s handle, SWIGTYPE_p_p_switch_dial_leg_list_s leg_listP) {
     freeswitchPINVOKE.switch_dial_handle_add_leg_list(SWIGTYPE_p_switch_dial_handle_s.getCPtr(handle), SWIGTYPE_p_p_switch_dial_leg_list_s.getCPtr(leg_listP));
   }
@@ -14021,6 +14022,12 @@ else
     freeswitchPINVOKE.switch_rtp_video_loss(SWIGTYPE_p_switch_rtp.getCPtr(rtp_session));
   }
 
+  public static SWIGTYPE_p_cJSON switch_log_node_to_json(switch_log_node_t node, int log_level, switch_log_json_format_t json_format, switch_event chan_vars) {
+    global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_node_to_json(switch_log_node_t.getCPtr(node), log_level, switch_log_json_format_t.getCPtr(json_format), switch_event.getCPtr(chan_vars));
+    SWIGTYPE_p_cJSON ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_cJSON(cPtr, false);
+    return ret;
+  }
+
   public static switch_status_t switch_log_init(SWIGTYPE_p_apr_pool_t pool, switch_bool_t colorize) {
     switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_log_init(SWIGTYPE_p_apr_pool_t.getCPtr(pool), (int)colorize);
     return ret;
@@ -19290,12 +19297,6 @@ class freeswitchPINVOKE {
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_native_handle_t_odbc_dbh_get___")]
   public static extern global::System.IntPtr switch_cache_db_native_handle_t_odbc_dbh_get(global::System.Runtime.InteropServices.HandleRef jarg1);
 
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_native_handle_t_pgsql_dbh_set___")]
-  public static extern void switch_cache_db_native_handle_t_pgsql_dbh_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
-
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_native_handle_t_pgsql_dbh_get___")]
-  public static extern global::System.IntPtr switch_cache_db_native_handle_t_pgsql_dbh_get(global::System.Runtime.InteropServices.HandleRef jarg1);
-
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_native_handle_t_database_interface_dbh_set___")]
   public static extern void switch_cache_db_native_handle_t_database_interface_dbh_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
@@ -19344,23 +19345,17 @@ class freeswitchPINVOKE {
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_delete_switch_cache_db_odbc_options_t___")]
   public static extern void delete_switch_cache_db_odbc_options_t(global::System.Runtime.InteropServices.HandleRef jarg1);
 
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_pgsql_options_t_dsn_set___")]
-  public static extern void switch_cache_db_pgsql_options_t_dsn_set(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
-
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_pgsql_options_t_dsn_get___")]
-  public static extern string switch_cache_db_pgsql_options_t_dsn_get(global::System.Runtime.InteropServices.HandleRef jarg1);
-
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_switch_cache_db_pgsql_options_t___")]
-  public static extern global::System.IntPtr new_switch_cache_db_pgsql_options_t();
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_original_dsn_set___")]
+  public static extern void switch_cache_db_database_interface_options_t_original_dsn_set(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
 
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_delete_switch_cache_db_pgsql_options_t___")]
-  public static extern void delete_switch_cache_db_pgsql_options_t(global::System.Runtime.InteropServices.HandleRef jarg1);
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_original_dsn_get___")]
+  public static extern string switch_cache_db_database_interface_options_t_original_dsn_get(global::System.Runtime.InteropServices.HandleRef jarg1);
 
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_dsn_set___")]
-  public static extern void switch_cache_db_database_interface_options_t_dsn_set(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_connection_string_set___")]
+  public static extern void switch_cache_db_database_interface_options_t_connection_string_set(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
 
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_dsn_get___")]
-  public static extern string switch_cache_db_database_interface_options_t_dsn_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_connection_string_get___")]
+  public static extern string switch_cache_db_database_interface_options_t_connection_string_get(global::System.Runtime.InteropServices.HandleRef jarg1);
 
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_database_interface_options_t_prefix_set___")]
   public static extern void switch_cache_db_database_interface_options_t_prefix_set(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
@@ -19398,12 +19393,6 @@ class freeswitchPINVOKE {
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_connection_options_t_odbc_options_get___")]
   public static extern global::System.IntPtr switch_cache_db_connection_options_t_odbc_options_get(global::System.Runtime.InteropServices.HandleRef jarg1);
 
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_connection_options_t_pgsql_options_set___")]
-  public static extern void switch_cache_db_connection_options_t_pgsql_options_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
-
-  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_connection_options_t_pgsql_options_get___")]
-  public static extern global::System.IntPtr switch_cache_db_connection_options_t_pgsql_options_get(global::System.Runtime.InteropServices.HandleRef jarg1);
-
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_cache_db_connection_options_t_database_interface_options_set___")]
   public static extern void switch_cache_db_connection_options_t_database_interface_options_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
@@ -19482,6 +19471,9 @@ class freeswitchPINVOKE {
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_core_check_core_db_dsn___")]
   public static extern int switch_core_check_core_db_dsn();
 
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_database_available___")]
+  public static extern int switch_database_available(string jarg1);
+
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_core_set_signal_handlers___")]
   public static extern void switch_core_set_signal_handlers();
 
@@ -24747,11 +24739,14 @@ class freeswitchPINVOKE {
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_event_channel_broadcast___")]
   public static extern int switch_event_channel_broadcast(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, string jarg3, uint jarg4);
 
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_event_channel_deliver___")]
+  public static extern int switch_event_channel_deliver(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, string jarg3, uint jarg4);
+
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_event_channel_unbind___")]
-  public static extern uint switch_event_channel_unbind(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+  public static extern uint switch_event_channel_unbind(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, global::System.Runtime.InteropServices.HandleRef jarg3);
 
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_event_channel_bind___")]
-  public static extern int switch_event_channel_bind(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, global::System.Runtime.InteropServices.HandleRef jarg3);
+  public static extern int switch_event_channel_bind(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, global::System.Runtime.InteropServices.HandleRef jarg3, global::System.Runtime.InteropServices.HandleRef jarg4);
 
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_NO_EVENT_CHANNEL_ID_get___")]
   public static extern int NO_EVENT_CHANNEL_ID_get();
@@ -25527,9 +25522,21 @@ class freeswitchPINVOKE {
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_dial_handle_create___")]
   public static extern int switch_dial_handle_create(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_dial_handle_create_json_obj___")]
+  public static extern int switch_dial_handle_create_json_obj(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_dial_handle_create_json___")]
+  public static extern int switch_dial_handle_create_json(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
+
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_dial_handle_destroy___")]
   public static extern void switch_dial_handle_destroy(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_dial_handle_serialize_json_obj___")]
+  public static extern int switch_dial_handle_serialize_json_obj(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_dial_handle_serialize_json___")]
+  public static extern int switch_dial_handle_serialize_json(global::System.Runtime.InteropServices.HandleRef jarg1, ref string jarg2);
+
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_dial_handle_add_leg_list___")]
   public static extern void switch_dial_handle_add_leg_list(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
@@ -26130,6 +26137,117 @@ class freeswitchPINVOKE {
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_delete_switch_log_node_t___")]
   public static extern void delete_switch_log_node_t(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_item_t_name_set___")]
+  public static extern void switch_log_json_format_item_t_name_set(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_item_t_name_get___")]
+  public static extern string switch_log_json_format_item_t_name_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_item_t_value_set___")]
+  public static extern void switch_log_json_format_item_t_value_set(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_item_t_value_get___")]
+  public static extern string switch_log_json_format_item_t_value_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_switch_log_json_format_item_t___")]
+  public static extern global::System.IntPtr new_switch_log_json_format_item_t();
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_delete_switch_log_json_format_item_t___")]
+  public static extern void delete_switch_log_json_format_item_t(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_version_set___")]
+  public static extern void switch_log_json_format_t_version_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_version_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_version_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_host_set___")]
+  public static extern void switch_log_json_format_t_host_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_host_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_host_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_timestamp_set___")]
+  public static extern void switch_log_json_format_t_timestamp_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_timestamp_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_timestamp_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_level_set___")]
+  public static extern void switch_log_json_format_t_level_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_level_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_level_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_ident_set___")]
+  public static extern void switch_log_json_format_t_ident_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_ident_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_ident_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_pid_set___")]
+  public static extern void switch_log_json_format_t_pid_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_pid_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_pid_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_uuid_set___")]
+  public static extern void switch_log_json_format_t_uuid_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_uuid_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_uuid_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_file_set___")]
+  public static extern void switch_log_json_format_t_file_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_file_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_file_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_line_set___")]
+  public static extern void switch_log_json_format_t_line_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_line_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_line_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_function_set___")]
+  public static extern void switch_log_json_format_t_function_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_function_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_function_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_full_message_set___")]
+  public static extern void switch_log_json_format_t_full_message_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_full_message_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_full_message_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_short_message_set___")]
+  public static extern void switch_log_json_format_t_short_message_set(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_short_message_get___")]
+  public static extern global::System.IntPtr switch_log_json_format_t_short_message_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_custom_field_prefix_set___")]
+  public static extern void switch_log_json_format_t_custom_field_prefix_set(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_custom_field_prefix_get___")]
+  public static extern string switch_log_json_format_t_custom_field_prefix_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_timestamp_divisor_set___")]
+  public static extern void switch_log_json_format_t_timestamp_divisor_set(global::System.Runtime.InteropServices.HandleRef jarg1, double jarg2);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_json_format_t_timestamp_divisor_get___")]
+  public static extern double switch_log_json_format_t_timestamp_divisor_get(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_new_switch_log_json_format_t___")]
+  public static extern global::System.IntPtr new_switch_log_json_format_t();
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_delete_switch_log_json_format_t___")]
+  public static extern void delete_switch_log_json_format_t(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+  [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_node_to_json___")]
+  public static extern global::System.IntPtr switch_log_node_to_json(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2, global::System.Runtime.InteropServices.HandleRef jarg3, global::System.Runtime.InteropServices.HandleRef jarg4);
+
   [global::System.Runtime.InteropServices.DllImport("mod_managed", EntryPoint="CSharp_FreeSWITCHfNative_switch_log_init___")]
   public static extern int switch_log_init(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2);
 
@@ -29938,17 +30056,6 @@ public class switch_cache_db_connection_options_t : global::System.IDisposable {
     } 
   }
 
-  public switch_cache_db_pgsql_options_t pgsql_options {
-    set {
-      freeswitchPINVOKE.switch_cache_db_connection_options_t_pgsql_options_set(swigCPtr, switch_cache_db_pgsql_options_t.getCPtr(value));
-    } 
-    get {
-      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_cache_db_connection_options_t_pgsql_options_get(swigCPtr);
-      switch_cache_db_pgsql_options_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_cache_db_pgsql_options_t(cPtr, false);
-      return ret;
-    } 
-  }
-
   public switch_cache_db_database_interface_options_t database_interface_options {
     set {
       freeswitchPINVOKE.switch_cache_db_connection_options_t_database_interface_options_set(swigCPtr, switch_cache_db_database_interface_options_t.getCPtr(value));
@@ -30066,12 +30173,22 @@ public class switch_cache_db_database_interface_options_t : global::System.IDisp
     }
   }
 
-  public string dsn {
+  public string original_dsn {
+    set {
+      freeswitchPINVOKE.switch_cache_db_database_interface_options_t_original_dsn_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_cache_db_database_interface_options_t_original_dsn_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public string connection_string {
     set {
-      freeswitchPINVOKE.switch_cache_db_database_interface_options_t_dsn_set(swigCPtr, value);
+      freeswitchPINVOKE.switch_cache_db_database_interface_options_t_connection_string_set(swigCPtr, value);
     } 
     get {
-      string ret = freeswitchPINVOKE.switch_cache_db_database_interface_options_t_dsn_get(swigCPtr);
+      string ret = freeswitchPINVOKE.switch_cache_db_database_interface_options_t_connection_string_get(swigCPtr);
       return ret;
     } 
   }
@@ -30128,7 +30245,6 @@ namespace FreeSWITCH.Native {
 public enum switch_cache_db_handle_type_t {
   SCDB_TYPE_CORE_DB,
   SCDB_TYPE_ODBC,
-  SCDB_TYPE_PGSQL,
   SCDB_TYPE_DATABASE_INTERFACE
 }
 
@@ -30197,17 +30313,6 @@ public class switch_cache_db_native_handle_t : global::System.IDisposable {
     } 
   }
 
-  public SWIGTYPE_p_switch_pgsql_handle pgsql_dbh {
-    set {
-      freeswitchPINVOKE.switch_cache_db_native_handle_t_pgsql_dbh_set(swigCPtr, SWIGTYPE_p_switch_pgsql_handle.getCPtr(value));
-    } 
-    get {
-      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_cache_db_native_handle_t_pgsql_dbh_get(swigCPtr);
-      SWIGTYPE_p_switch_pgsql_handle ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_switch_pgsql_handle(cPtr, false);
-      return ret;
-    } 
-  }
-
   public switch_database_interface_handle database_interface_dbh {
     set {
       freeswitchPINVOKE.switch_cache_db_native_handle_t_database_interface_dbh_set(swigCPtr, switch_database_interface_handle.getCPtr(value));
@@ -30315,64 +30420,6 @@ public class switch_cache_db_odbc_options_t : global::System.IDisposable {
 
 namespace FreeSWITCH.Native {
 
-public class switch_cache_db_pgsql_options_t : global::System.IDisposable {
-  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
-  protected bool swigCMemOwn;
-
-  internal switch_cache_db_pgsql_options_t(global::System.IntPtr cPtr, bool cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
-  }
-
-  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(switch_cache_db_pgsql_options_t obj) {
-    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
-  }
-
-  ~switch_cache_db_pgsql_options_t() {
-    Dispose();
-  }
-
-  public virtual void Dispose() {
-    lock(this) {
-      if (swigCPtr.Handle != global::System.IntPtr.Zero) {
-        if (swigCMemOwn) {
-          swigCMemOwn = false;
-          freeswitchPINVOKE.delete_switch_cache_db_pgsql_options_t(swigCPtr);
-        }
-        swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-      }
-      global::System.GC.SuppressFinalize(this);
-    }
-  }
-
-  public string dsn {
-    set {
-      freeswitchPINVOKE.switch_cache_db_pgsql_options_t_dsn_set(swigCPtr, value);
-    } 
-    get {
-      string ret = freeswitchPINVOKE.switch_cache_db_pgsql_options_t_dsn_get(swigCPtr);
-      return ret;
-    } 
-  }
-
-  public switch_cache_db_pgsql_options_t() : this(freeswitchPINVOKE.new_switch_cache_db_pgsql_options_t(), true) {
-  }
-
-}
-
-}
-//------------------------------------------------------------------------------
-// <auto-generated />
-//
-// This file was automatically generated by SWIG (http://www.swig.org).
-// Version 3.0.10
-//
-// Do not make changes to this file unless you know what you are doing--modify
-// the SWIG interface file instead.
-//------------------------------------------------------------------------------
-
-namespace FreeSWITCH.Native {
-
 public enum switch_call_cause_t {
   SWITCH_CAUSE_NONE = 0,
   SWITCH_CAUSE_UNALLOCATED_NUMBER = 1,
@@ -34036,13 +34083,13 @@ public class switch_database_interface : global::System.IDisposable {
     } 
   }
 
-  public SWIGTYPE_p_f_p_char_p_p_switch_database_interface_handle__switch_status_t handle_new {
+  public SWIGTYPE_p_f_switch_cache_db_database_interface_options_t_p_p_switch_database_interface_handle__switch_status_t handle_new {
     set {
-      freeswitchPINVOKE.switch_database_interface_handle_new_set(swigCPtr, SWIGTYPE_p_f_p_char_p_p_switch_database_interface_handle__switch_status_t.getCPtr(value));
+      freeswitchPINVOKE.switch_database_interface_handle_new_set(swigCPtr, SWIGTYPE_p_f_switch_cache_db_database_interface_options_t_p_p_switch_database_interface_handle__switch_status_t.getCPtr(value));
     } 
     get {
       global::System.IntPtr cPtr = freeswitchPINVOKE.switch_database_interface_handle_new_get(swigCPtr);
-      SWIGTYPE_p_f_p_char_p_p_switch_database_interface_handle__switch_status_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_p_char_p_p_switch_database_interface_handle__switch_status_t(cPtr, false);
+      SWIGTYPE_p_f_switch_cache_db_database_interface_options_t_p_p_switch_database_interface_handle__switch_status_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_switch_cache_db_database_interface_options_t_p_p_switch_database_interface_handle__switch_status_t(cPtr, false);
       return ret;
     } 
   }
@@ -35832,7 +35879,9 @@ namespace FreeSWITCH.Native {
   ED_DTMF = (1 << 2),
   ED_COPY_DISPLAY = (1 << 3),
   ED_BRIDGE_READ = (1 << 4),
-  ED_BRIDGE_WRITE = (1 << 5)
+  ED_BRIDGE_WRITE = (1 << 5),
+  ED_TAP_READ = (1 << 6),
+  ED_TAP_WRITE = (1 << 7)
 }
 
 }
@@ -40816,6 +40865,274 @@ public enum switch_loadable_module_type_t {
 
 namespace FreeSWITCH.Native {
 
+public class switch_log_json_format_item_t : global::System.IDisposable {
+  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal switch_log_json_format_item_t(global::System.IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+  }
+
+  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(switch_log_json_format_item_t obj) {
+    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  ~switch_log_json_format_item_t() {
+    Dispose();
+  }
+
+  public virtual void Dispose() {
+    lock(this) {
+      if (swigCPtr.Handle != global::System.IntPtr.Zero) {
+        if (swigCMemOwn) {
+          swigCMemOwn = false;
+          freeswitchPINVOKE.delete_switch_log_json_format_item_t(swigCPtr);
+        }
+        swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+      }
+      global::System.GC.SuppressFinalize(this);
+    }
+  }
+
+  public string name {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_item_t_name_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_log_json_format_item_t_name_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public string value {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_item_t_value_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_log_json_format_item_t_value_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t() : this(freeswitchPINVOKE.new_switch_log_json_format_item_t(), true) {
+  }
+
+}
+
+}
+//------------------------------------------------------------------------------
+// <auto-generated />
+//
+// This file was automatically generated by SWIG (http://www.swig.org).
+// Version 3.0.10
+//
+// Do not make changes to this file unless you know what you are doing--modify
+// the SWIG interface file instead.
+//------------------------------------------------------------------------------
+
+namespace FreeSWITCH.Native {
+
+public class switch_log_json_format_t : global::System.IDisposable {
+  private global::System.Runtime.InteropServices.HandleRef swigCPtr;
+  protected bool swigCMemOwn;
+
+  internal switch_log_json_format_t(global::System.IntPtr cPtr, bool cMemoryOwn) {
+    swigCMemOwn = cMemoryOwn;
+    swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+  }
+
+  internal static global::System.Runtime.InteropServices.HandleRef getCPtr(switch_log_json_format_t obj) {
+    return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+  }
+
+  ~switch_log_json_format_t() {
+    Dispose();
+  }
+
+  public virtual void Dispose() {
+    lock(this) {
+      if (swigCPtr.Handle != global::System.IntPtr.Zero) {
+        if (swigCMemOwn) {
+          swigCMemOwn = false;
+          freeswitchPINVOKE.delete_switch_log_json_format_t(swigCPtr);
+        }
+        swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+      }
+      global::System.GC.SuppressFinalize(this);
+    }
+  }
+
+  public switch_log_json_format_item_t version {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_version_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_version_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t host {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_host_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_host_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t timestamp {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_timestamp_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_timestamp_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t level {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_level_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_level_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t ident {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_ident_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_ident_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t pid {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_pid_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_pid_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t uuid {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_uuid_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_uuid_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t file {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_file_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_file_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t line {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_line_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_line_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t function {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_function_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_function_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t full_message {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_full_message_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_full_message_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_item_t short_message {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_short_message_set(swigCPtr, switch_log_json_format_item_t.getCPtr(value));
+    } 
+    get {
+      global::System.IntPtr cPtr = freeswitchPINVOKE.switch_log_json_format_t_short_message_get(swigCPtr);
+      switch_log_json_format_item_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new switch_log_json_format_item_t(cPtr, false);
+      return ret;
+    } 
+  }
+
+  public string custom_field_prefix {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_custom_field_prefix_set(swigCPtr, value);
+    } 
+    get {
+      string ret = freeswitchPINVOKE.switch_log_json_format_t_custom_field_prefix_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public double timestamp_divisor {
+    set {
+      freeswitchPINVOKE.switch_log_json_format_t_timestamp_divisor_set(swigCPtr, value);
+    } 
+    get {
+      double ret = freeswitchPINVOKE.switch_log_json_format_t_timestamp_divisor_get(swigCPtr);
+      return ret;
+    } 
+  }
+
+  public switch_log_json_format_t() : this(freeswitchPINVOKE.new_switch_log_json_format_t(), true) {
+  }
+
+}
+
+}
+//------------------------------------------------------------------------------
+// <auto-generated />
+//
+// This file was automatically generated by SWIG (http://www.swig.org).
+// Version 3.0.10
+//
+// Do not make changes to this file unless you know what you are doing--modify
+// the SWIG interface file instead.
+//------------------------------------------------------------------------------
+
+namespace FreeSWITCH.Native {
+
 public enum switch_log_level_t {
   SWITCH_LOG_DEBUG10 = 110,
   SWITCH_LOG_DEBUG9 = 109,
index 8b30c2adceb5ead944fdb0b48fe4d0e34417c7a7..71127a15c00197274efbba9df5df6897857e9e66 100644 (file)
@@ -188,7 +188,7 @@ static switch_cache_db_handle_t *get_handle(const char *db_str, const char *user
 
        if (!r) {
                for (dbh_ptr = sql_manager.handle_pool; dbh_ptr; dbh_ptr = dbh_ptr->next) {
-                       if (dbh_ptr->hash == hash && ((dbh_ptr->type != SCDB_TYPE_PGSQL && dbh_ptr->type != SCDB_TYPE_DATABASE_INTERFACE) || !dbh_ptr->use_count) && !switch_test_flag(dbh_ptr, CDF_PRUNE) &&
+                       if (dbh_ptr->hash == hash && (dbh_ptr->type != SCDB_TYPE_DATABASE_INTERFACE || !dbh_ptr->use_count) && !switch_test_flag(dbh_ptr, CDF_PRUNE) &&
                                switch_mutex_trylock(dbh_ptr->mutex) == SWITCH_STATUS_SUCCESS) {
                                r = dbh_ptr;
                                break;
@@ -273,11 +273,6 @@ static void sql_close(time_t prune)
                                        database_interface->handle_destroy(&dbh->native_handle.database_interface_dbh);
                                }
                                break;
-                       case SCDB_TYPE_PGSQL:
-                               {
-                                       switch_pgsql_handle_destroy(&dbh->native_handle.pgsql_dbh);
-                               }
-                               break;
                        case SCDB_TYPE_ODBC:
                                {
                                        switch_odbc_handle_destroy(&dbh->native_handle.odbc_dbh);
@@ -344,11 +339,6 @@ SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t
                                database_interface->flush((*dbh)->native_handle.database_interface_dbh);
                        }
                break;
-               case SCDB_TYPE_PGSQL:
-                       {
-                               switch_pgsql_flush((*dbh)->native_handle.pgsql_dbh);
-                       }
-                       break;
                default:
                        break;
                }
@@ -380,19 +370,20 @@ SWITCH_DECLARE(void) switch_cache_db_dismiss_db_handle(switch_cache_db_handle_t
 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
 #endif
 
-SWITCH_DECLARE(switch_status_t) switch_core_check_core_db_dsn(void)
+SWITCH_DECLARE(switch_status_t) switch_database_available(char* dsn)
 {
        switch_status_t status = SWITCH_STATUS_FALSE;
        switch_database_interface_t *database_interface;
 
-       if (!runtime.odbc_dsn) {
+       if (!dsn) {
                status = SWITCH_STATUS_SUCCESS;
-       } else {
+       }
+       else {
                char *colon_slashes = NULL;
-               if (NULL != (colon_slashes = strstr(runtime.odbc_dsn, "://")))
+               if (NULL != (colon_slashes = strstr(dsn, "://")))
                {
                        char prefix[16] = "";
-                       strncpy(prefix, runtime.odbc_dsn, MIN(colon_slashes - runtime.odbc_dsn, 15));
+                       strncpy(prefix, dsn, MIN(colon_slashes - dsn, 15));
 
                        if (!strncasecmp(prefix, "odbc", 4)) {
                                if (switch_odbc_available()) status = SWITCH_STATUS_SUCCESS;
@@ -400,15 +391,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_check_core_db_dsn(void)
                        else if (!strncasecmp(prefix, "sqlite", 6)) {
                                status = SWITCH_STATUS_SUCCESS;
                        }
-                       else if (!strncasecmp(prefix, "pgsql", 5)) {
-                               if (switch_pgsql_available()) status = SWITCH_STATUS_SUCCESS;
-                       }
                        else if ((database_interface = switch_loadable_module_get_database_interface(prefix, NULL))) {
                                status = SWITCH_STATUS_SUCCESS;
                                UNPROTECT_INTERFACE(database_interface);
                        }
                }
-               else if (strchr(runtime.odbc_dsn + 2, ':')) {
+               else if (strchr(dsn + 2, ':')) {
                        status = SWITCH_STATUS_SUCCESS;
                }
        }
@@ -416,6 +404,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_check_core_db_dsn(void)
        return status;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_core_check_core_db_dsn(void)
+{
+       return switch_database_available(runtime.odbc_dsn);
+}
+
 SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle_dsn(switch_cache_db_handle_t **dbh, const char *dsn,
        const char *file, const char *func, int line)
 {
@@ -443,19 +436,16 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle_dsn_ex(switch_cac
                        type = SCDB_TYPE_DATABASE_INTERFACE;
                        connection_options.database_interface_options.make_module_no_unloadable = make_module_no_unloadable;
                        connection_options.database_interface_options.database_interface = database_interface;
-                       connection_options.database_interface_options.dsn = colon_slashes + 3;
+                       connection_options.database_interface_options.original_dsn = dsn;
+                       connection_options.database_interface_options.connection_string = colon_slashes + 3;
                        strcpy(connection_options.database_interface_options.prefix, prefix);
                        UNPROTECT_INTERFACE(database_interface);
                }
        }
 
-       if (!connection_options.database_interface_options.dsn)
-       {               
-               if (!strncasecmp(dsn, "pgsql://", 8)) {
-                       type = SCDB_TYPE_PGSQL;
-                       connection_options.pgsql_options.dsn = (char *)(dsn + 8);
-               }
-               else if (!strncasecmp(dsn, "sqlite://", 9)) {
+       if (!connection_options.database_interface_options.connection_string)
+       {
+               if (!strncasecmp(dsn, "sqlite://", 9)) {
                        type = SCDB_TYPE_CORE_DB;
                        connection_options.core_db_options.db_path = (char *)(dsn + 9);
                }
@@ -532,20 +522,12 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h
        switch (type) {
        case SCDB_TYPE_DATABASE_INTERFACE:
                {
-                       db_name = connection_options->database_interface_options.dsn;
+                       db_name = connection_options->database_interface_options.connection_string;
                        odbc_user = NULL;
                        odbc_pass = NULL;
                        db_type = "database_interface";
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       db_name = connection_options->pgsql_options.dsn;
-                       odbc_user = NULL;
-                       odbc_pass = NULL;
-                       db_type = "pgsql";
-               }
-               break;
        case SCDB_TYPE_ODBC:
                {
                        db_name = connection_options->odbc_options.dsn;
@@ -587,7 +569,6 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h
        } else {
                switch_core_db_t *db = NULL;
                switch_odbc_handle_t *odbc_dbh = NULL;
-               switch_pgsql_handle_t *pgsql_dbh = NULL;
                switch_database_interface_handle_t *database_interface_dbh = NULL;              
 
                switch (type) {
@@ -595,8 +576,8 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h
                        {
                                switch_database_interface_t *database_interface = connection_options->database_interface_options.database_interface;
 
-                               if (SWITCH_STATUS_SUCCESS != database_interface->handle_new(connection_options->database_interface_options.dsn, &database_interface_dbh)) {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! Can't create new handle! Can't connect to DSN %s\n", connection_options->database_interface_options.dsn);
+                               if (SWITCH_STATUS_SUCCESS != database_interface->handle_new(connection_options->database_interface_options, &database_interface_dbh)) {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! Can't create new handle! Can't connect to DSN %s\n", connection_options->database_interface_options.original_dsn);
                                        goto end;
                                }
 
@@ -612,20 +593,6 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h
                                }
                        }
                        break;
-               case SCDB_TYPE_PGSQL:
-                       {
-                               if (!switch_pgsql_available()) {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! PGSQL NOT AVAILABLE! Can't connect to DSN %s\n", connection_options->pgsql_options.dsn);
-                                       goto end;
-                               }
-
-                               if ((pgsql_dbh = switch_pgsql_handle_new(connection_options->pgsql_options.dsn))) {
-                                       if (switch_pgsql_handle_connect(pgsql_dbh) != SWITCH_PGSQL_SUCCESS) {
-                                               switch_pgsql_handle_destroy(&pgsql_dbh);
-                                       }
-                               }
-                       }
-                       break;
                case SCDB_TYPE_ODBC:
                        {
                                if (!switch_odbc_available()) {
@@ -651,7 +618,7 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h
                        goto end;
                }
 
-               if (!db && !odbc_dbh && !pgsql_dbh && !database_interface_dbh) {
+               if (!db && !odbc_dbh && !database_interface_dbh) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure to connect to %s %s!\n", switch_cache_db_type_name(type), db_name);
                        goto end;
                }
@@ -667,8 +634,6 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h
                        new_dbh->native_handle.core_db_dbh = db;
                } else if (odbc_dbh) {
                        new_dbh->native_handle.odbc_dbh = odbc_dbh;
-               } else {
-                       new_dbh->native_handle.pgsql_dbh = pgsql_dbh;
                }
 
                add_handle(new_dbh, db_str, db_callsite_str, thread_str);
@@ -708,12 +673,6 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t
                        status = database_interface_handle_exec(database_interface, dbh->native_handle.database_interface_dbh, sql, &errmsg);
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       type = "PGSQL";
-                       status = switch_pgsql_handle_exec(dbh->native_handle.pgsql_dbh, sql, &errmsg);
-               }
-               break;
        case SCDB_TYPE_ODBC:
                {
                        type = "ODBC";
@@ -861,11 +820,6 @@ SWITCH_DECLARE(int) switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh)
                        database_interface->affected_rows(dbh->native_handle.database_interface_dbh, &affected_rows);
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       return switch_pgsql_handle_affected_rows(dbh->native_handle.pgsql_dbh);
-               }
-               break;
        }
        return 0;
 }
@@ -889,11 +843,6 @@ SWITCH_DECLARE(int) switch_cache_db_load_extension(switch_cache_db_handle_t *dbh
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "load extension not supported by type DATABASE_INTERFACE!\n");
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "load extension not supported by type PGSQL!\n");
-               }
-               break;
        }
        return 0;
 }
@@ -957,11 +906,6 @@ SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t
                        status = database_interface->exec_string(dbh->native_handle.database_interface_dbh, sql, str, len, err);
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       status = switch_pgsql_handle_exec_string(dbh->native_handle.pgsql_dbh, sql, str, len, err);
-               }
-               break;
        }
 
  end:
@@ -1073,17 +1017,6 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans_full(sw
                                }                                       
                        }
                        break;
-               case SCDB_TYPE_PGSQL:
-                       {
-                               switch_pgsql_status_t result;
-
-                               if ((result = switch_pgsql_SQLSetAutoCommitAttr(dbh->native_handle.pgsql_dbh, 0)) != SWITCH_PGSQL_SUCCESS) {
-                                       char tmp[100];
-                                       switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
-                                       errmsg = strdup(tmp);
-                               }
-                       }
-                       break;
                }
 
                if (errmsg) {
@@ -1119,13 +1052,6 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans_full(sw
                                                }
                                        }
                                        break;
-                               case SCDB_TYPE_PGSQL:
-                                       {
-                                               switch_pgsql_SQLEndTran(dbh->native_handle.pgsql_dbh, 1);
-                                               switch_pgsql_SQLSetAutoCommitAttr(dbh->native_handle.pgsql_dbh, 1);
-                                               switch_pgsql_finish_results(dbh->native_handle.pgsql_dbh);
-                                       }
-                                       break;
                                }
 
                                goto again;
@@ -1205,13 +1131,6 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans_full(sw
                        }
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       switch_pgsql_SQLEndTran(dbh->native_handle.pgsql_dbh, 1);
-                       switch_pgsql_SQLSetAutoCommitAttr(dbh->native_handle.pgsql_dbh, 1);
-                       switch_pgsql_finish_results(dbh->native_handle.pgsql_dbh);
-               }
-               break;
        }
 
        if (!zstr(post_trans_execute)) {
@@ -1277,11 +1196,6 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_event_callback(switc
                        }
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       status = switch_pgsql_handle_callback_exec(dbh->native_handle.pgsql_dbh, sql, helper_callback, &h, err);
-               }
-               break;
        case SCDB_TYPE_ODBC:
                {
                        status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, helper_callback, &h, err);
@@ -1347,14 +1261,6 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_event_callback_err(s
                        }
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       status = switch_pgsql_handle_callback_exec(dbh->native_handle.pgsql_dbh, sql, helper_callback, &h, err);
-                       if (err && *err) {
-                               (*err_callback)(pdata, (const char*)*err);
-                       }
-               }
-               break;
        case SCDB_TYPE_ODBC:
                {
                        status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, helper_callback, &h, err);
@@ -1418,11 +1324,6 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cach
                        }
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       status = switch_pgsql_handle_callback_exec(dbh->native_handle.pgsql_dbh, sql, callback, pdata, err);
-               }
-               break;
        case SCDB_TYPE_ODBC:
                {
                        status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err);
@@ -1483,14 +1384,6 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback_err(switch_
                        }
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       status = switch_pgsql_handle_callback_exec(dbh->native_handle.pgsql_dbh, sql, callback, pdata, err);
-                       if (err && *err) {
-                               (*err_callback)(pdata, (const char*)*err);
-                       }
-               }
-               break;
        case SCDB_TYPE_ODBC:
                {
                        status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err);
@@ -1615,16 +1508,6 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive_ex(switch_cache_db_h
                        }
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       if (switch_pgsql_handle_exec(dbh->native_handle.pgsql_dbh, test_sql, NULL) != SWITCH_PGSQL_SUCCESS) {
-                               if (drop_sql) {
-                                       switch_pgsql_handle_exec(dbh->native_handle.pgsql_dbh, drop_sql, NULL);
-                               }
-                               r = switch_pgsql_handle_exec(dbh->native_handle.pgsql_dbh, reactive_sql, NULL) == SWITCH_PGSQL_SUCCESS;
-                       }
-               }
-               break;
        case SCDB_TYPE_ODBC:
                {
                        if (switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) {
@@ -2249,17 +2132,6 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm)
                        }
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       switch_pgsql_status_t result;
-
-                       if ((result = switch_pgsql_SQLSetAutoCommitAttr(qm->event_db->native_handle.pgsql_dbh, 0)) != SWITCH_PGSQL_SUCCESS) {
-                               char tmp[100];
-                               switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
-                               errmsg = strdup(tmp);
-                       }
-               }
-               break;
        }
 
        if (errmsg) {
@@ -2336,13 +2208,6 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm)
                        }
                }
                break;
-       case SCDB_TYPE_PGSQL:
-               {
-                       switch_pgsql_SQLEndTran(qm->event_db->native_handle.pgsql_dbh, 1);
-                       switch_pgsql_SQLSetAutoCommitAttr(qm->event_db->native_handle.pgsql_dbh, 1);
-                       switch_pgsql_finish_results(qm->event_db->native_handle.pgsql_dbh);
-               }
-               break;
        }
 
 
@@ -2394,8 +2259,6 @@ static void *SWITCH_THREAD_FUNC switch_user_sql_thread(switch_thread_t *thread,
        switch (qm->event_db->type) {
        case SCDB_TYPE_DATABASE_INTERFACE:
                break;
-       case SCDB_TYPE_PGSQL:
-               break;
        case SCDB_TYPE_ODBC:
                break;
        case SCDB_TYPE_CORE_DB:
@@ -3755,7 +3618,6 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
 
        switch (sql_manager.dbh->type) {
        case SCDB_TYPE_DATABASE_INTERFACE:
-       case SCDB_TYPE_PGSQL:
        case SCDB_TYPE_ODBC:
                if (switch_test_flag((&runtime), SCF_CLEAR_SQL)) {
                        char sql[512] = "";
@@ -3806,7 +3668,6 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
 
        switch (sql_manager.dbh->type) {
        case SCDB_TYPE_DATABASE_INTERFACE:
-       case SCDB_TYPE_PGSQL:
        case SCDB_TYPE_ODBC:
                {
                        char *err;
@@ -3859,17 +3720,6 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
                                        }
                                }
                                break;
-                       case SCDB_TYPE_PGSQL:
-                               {
-                                       switch_pgsql_status_t result;
-
-                                       if ((result = switch_pgsql_SQLSetAutoCommitAttr(sql_manager.dbh->native_handle.pgsql_dbh, 0)) != SWITCH_PGSQL_SUCCESS) {
-                                               char tmp[100];
-                                               switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to Set AutoCommit Off", result);
-                                               err = strdup(tmp);
-                                       }
-                               }
-                               break;
                        }
 
                        switch_cache_db_execute_sql(sql_manager.dbh, "delete from channels where hostname=''", &err);
@@ -3904,17 +3754,6 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
                                                }
                                        }
                                        break;
-                               case SCDB_TYPE_PGSQL:
-                                       {
-                                               if (switch_pgsql_SQLEndTran(sql_manager.dbh->native_handle.pgsql_dbh, 1) != SWITCH_PGSQL_SUCCESS ||
-                                                       switch_pgsql_SQLSetAutoCommitAttr(sql_manager.dbh->native_handle.pgsql_dbh, 1) != SWITCH_PGSQL_SUCCESS ||
-                                                       switch_pgsql_finish_results(sql_manager.dbh->native_handle.pgsql_dbh) != SWITCH_PGSQL_SUCCESS) {
-                                                       char tmp[100];
-                                                       switch_snprintfv(tmp, sizeof(tmp), "%q-%i", "Unable to commit transaction.", result);
-                                                       err = strdup(tmp);
-                                               }
-                                       }
-                                       break;
                                }
                        }
 
index 1abc20df39e9f7ed3f64b9c1720b404cdbf3dc4b..f6199de568b3c1ce75fe751ea0a75a09b234e285 100644 (file)
@@ -48,7 +48,6 @@
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <Import Project="$(SolutionDir)\w32\switch_version.props" Condition=" '$(switch_versionPropsImported)' == '' " />
-  <Import Project="$(SolutionDir)\w32\libpq.props" Condition=" '$(libpqPropsImported)' == '' " />
   <Import Project="$(SolutionDir)\w32\openssl.props" Condition=" '$(OpensslPropsImported)' == '' " />
   <Import Project="$(SolutionDir)\w32\curl.props" Condition=" '$(CurlPropsImported)' == '' " />
   <Import Project="$(SolutionDir)\w32\pcre.props" Condition=" '$(pcrePropsImported)' == '' " />
@@ -399,7 +398,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
       <DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4389;4127;%(DisableSpecificWarnings)</DisableSpecificWarnings>
     </ClCompile>
     <ClCompile Include="..\..\src\switch_odbc.c" />
-    <ClCompile Include="..\..\src\switch_pgsql.c" />
     <ClCompile Include="..\..\src\switch_pcm.c" />
     <ClCompile Include="..\..\src\switch_speex.c" />
     <ClCompile Include="..\..\src\switch_profile.c" />
@@ -737,7 +735,6 @@ if not exist "$(OutDir)fonts" xcopy "$(SolutionDir)fonts\*.*" "$(OutDir)fonts\"
     <ClInclude Include="..\..\src\include\switch_module_interfaces.h" />
     <ClInclude Include="..\..\src\include\switch_mprintf.h" />
     <ClInclude Include="..\..\src\include\switch_odbc.h" />
-    <ClInclude Include="..\..\src\include\switch_pgsql.h" />
     <ClInclude Include="..\..\src\include\switch_platform.h" />
     <ClInclude Include="..\..\src\include\switch_regex.h" />
     <ClInclude Include="..\..\src\include\switch_resample.h" />
index e740dc05212e6904f0af1b8d231049367cd07f7b..170a47cd8ca615b5842b9834087dd7206ab1f314 100644 (file)
       <RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>\r
       <RefTargetDir>INSTALLFOLDER</RefTargetDir>\r
     </ProjectReference>\r
+    <ProjectReference Include="..\..\src\mod\databases\mod_pgsql\mod_pgsql.2017.vcxproj">\r
+      <Name>mod_pgsql</Name>\r
+      <Project>{1ba65811-5453-46f6-8190-9eceefeb7df2}</Project>\r
+      <Private>True</Private>\r
+      <DoNotHarvest>True</DoNotHarvest>\r
+      <RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>\r
+      <RefTargetDir>INSTALLFOLDER</RefTargetDir>\r
+    </ProjectReference>\r
     <ProjectReference Include="..\..\src\mod\dialplans\mod_dialplan_asterisk\mod_dialplan_asterisk.2017.vcxproj">\r
       <Name>mod_dialplan_asterisk</Name>\r
       <Project>{e7bc026c-7cc5-45a3-bc7c-3b88eef01f24}</Project>\r