FS-11074: [Core, Build-System] Add PostgreSQL to the Freeswitch Core on Windows.
This commit is contained in:
parent
d22e16ece9
commit
49d19bffcd
|
@ -844,3 +844,5 @@ tiff-4.0.2/configure
|
||||||
unimrcp/configure
|
unimrcp/configure
|
||||||
zlib-*/
|
zlib-*/
|
||||||
zlib-*
|
zlib-*
|
||||||
|
libpq-*/
|
||||||
|
libpq-*
|
||||||
|
|
|
@ -39,7 +39,12 @@
|
||||||
|
|
||||||
#ifdef SWITCH_HAVE_PGSQL
|
#ifdef SWITCH_HAVE_PGSQL
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
#else
|
||||||
|
#include <winsock2.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct switch_pgsql_handle {
|
struct switch_pgsql_handle {
|
||||||
|
@ -253,6 +258,7 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_send_query(switch_pgsql_handl
|
||||||
if (!PQsendQuery(handle->con, sql)) {
|
if (!PQsendQuery(handle->con, sql)) {
|
||||||
err_str = switch_pgsql_handle_get_error(handle);
|
err_str = switch_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_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);
|
switch_pgsql_finish_results(handle);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -292,7 +298,11 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
|
||||||
switch_time_t ctime;
|
switch_time_t ctime;
|
||||||
unsigned int usec = msec * 1000;
|
unsigned int usec = msec * 1000;
|
||||||
char *err_str;
|
char *err_str;
|
||||||
struct pollfd fds[2] = { {0} };
|
#ifndef _WIN32
|
||||||
|
struct pollfd fds[2] = { { 0 } };
|
||||||
|
#else
|
||||||
|
fd_set rs, es;
|
||||||
|
#endif
|
||||||
int poll_res = 0;
|
int poll_res = 0;
|
||||||
|
|
||||||
if(!handle) {
|
if(!handle) {
|
||||||
|
@ -309,6 +319,8 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
|
||||||
start = switch_micro_time_now();
|
start = switch_micro_time_now();
|
||||||
while((ctime = switch_micro_time_now()) - start <= usec) {
|
while((ctime = switch_micro_time_now()) - start <= usec) {
|
||||||
int wait_time = (usec - (ctime - start)) / 1000;
|
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].fd = handle->sock;
|
||||||
fds[0].events |= POLLIN;
|
fds[0].events |= POLLIN;
|
||||||
fds[0].events |= POLLERR;
|
fds[0].events |= POLLERR;
|
||||||
|
@ -318,8 +330,17 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
|
||||||
fds[0].events |= POLLRDNORM;
|
fds[0].events |= POLLRDNORM;
|
||||||
fds[0].events |= POLLRDBAND;
|
fds[0].events |= POLLRDBAND;
|
||||||
|
|
||||||
/* Wait for the PostgreSQL socket to be ready for data reads. */
|
poll_res = poll(&fds[0], 1, wait_time);
|
||||||
if ((poll_res = poll(&fds[0], 1, wait_time)) > 0 ) {
|
#else
|
||||||
|
struct timeval wait = { 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 ) {
|
||||||
|
#ifndef _WIN32
|
||||||
if (fds[0].revents & POLLHUP || fds[0].revents & POLLNVAL) {
|
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);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "PGSQL socket closed or invalid while waiting for result for query (%s)\n", handle->sql);
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -327,6 +348,9 @@ SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_next_result_timed(switch_pgsq
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Poll error trying to read PGSQL socket for query (%s)\n", handle->sql);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Poll error trying to read PGSQL socket for query (%s)\n", handle->sql);
|
||||||
goto error;
|
goto error;
|
||||||
} else if (fds[0].revents & POLLIN || fds[0].revents & POLLPRI || fds[0].revents & POLLRDNORM || fds[0].revents & POLLRDBAND) {
|
} else if (fds[0].revents & POLLIN || fds[0].revents & POLLPRI || fds[0].revents & POLLRDNORM || fds[0].revents & POLLRDBAND) {
|
||||||
|
#else
|
||||||
|
if (FD_ISSET(handle->sock, &rs)) {
|
||||||
|
#endif
|
||||||
/* Then try to consume any input waiting. */
|
/* Then try to consume any input waiting. */
|
||||||
if (PQconsumeInput(handle->con)) {
|
if (PQconsumeInput(handle->con)) {
|
||||||
if (PQstatus(handle->con) == CONNECTION_BAD) {
|
if (PQstatus(handle->con) == CONNECTION_BAD) {
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v140</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<Import Project="$(SolutionDir)\w32\libpq.props" />
|
||||||
<Import Project="$(SolutionDir)\w32\openssl.props" />
|
<Import Project="$(SolutionDir)\w32\openssl.props" />
|
||||||
<Import Project="$(SolutionDir)\w32\curl.props" />
|
<Import Project="$(SolutionDir)\w32\curl.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ImportGroup Label="PropertySheets">
|
||||||
|
<Import Project="basedir.props" Condition=" '$(BaseDirImported)' == ''"/>
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros">
|
||||||
|
<libpqVersion>10.3</libpqVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<libpqVersionImported>true</libpqVersionImported>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup />
|
||||||
|
<ItemDefinitionGroup />
|
||||||
|
<ItemGroup>
|
||||||
|
<BuildMacro Include="libpqVersion">
|
||||||
|
<Value>$(libpqVersion)</Value>
|
||||||
|
</BuildMacro>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ImportGroup Label="PropertySheets">
|
||||||
|
<Import Project="libpq-version.props" Condition=" '$(libpqVersionImported)' == '' "/>
|
||||||
|
<Import Project="downloadpackage.task" Condition=" '$(downloadpackagetask_Imported)' == '' " />
|
||||||
|
</ImportGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Label="UserMacros">
|
||||||
|
<libpqlibDir>$(BaseDir)libs\libpq-$(libpqVersion)</libpqlibDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Download Target.
|
||||||
|
Name must be unique.
|
||||||
|
By design, targets are executed only once per project.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
package: URI
|
||||||
|
|
||||||
|
expectfileordirectory: Skips the download and extraction if exists
|
||||||
|
|
||||||
|
outputfolder: Folder to store a downloaded file.
|
||||||
|
By default "$(BaseDir)libs", if empty
|
||||||
|
|
||||||
|
outputfilename: If not empty, overrides filename from URI.
|
||||||
|
.exe files don't get extracted
|
||||||
|
|
||||||
|
extractto: Folder to extract an archive to
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Target Name="libpqBinariesDownloadTarget" BeforeTargets="CustomBuild" DependsOnTargets="7za">
|
||||||
|
<DownloadPackageTask
|
||||||
|
package="http://files.freeswitch.org/windows/packages/libpq/$(libpqVersion)/libpq-$(libpqVersion)-binaries-$(Platform.ToLower())-$(Configuration.ToLower()).zip"
|
||||||
|
expectfileordirectory="$(libpqlibDir)\binaries\$(Platform)\$(Configuration)\libpq.dll"
|
||||||
|
outputfolder=""
|
||||||
|
outputfilename=""
|
||||||
|
extractto="$(BaseDir)libs\"
|
||||||
|
/>
|
||||||
|
</Target>
|
||||||
|
<Target Name="libpqHeadersDownloadTarget" BeforeTargets="CustomBuild" DependsOnTargets="7za">
|
||||||
|
<DownloadPackageTask
|
||||||
|
package="http://files.freeswitch.org/windows/packages/libpq/$(libpqVersion)/libpq-$(libpqVersion)-headers.zip"
|
||||||
|
expectfileordirectory="$(libpqlibDir)\include\libpq-fe.h"
|
||||||
|
outputfolder=""
|
||||||
|
outputfilename=""
|
||||||
|
extractto="$(BaseDir)libs\"
|
||||||
|
/>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="libpqcopyTarget" AfterTargets="Build" DependsOnTargets="Build">
|
||||||
|
<ItemGroup>
|
||||||
|
<libpqFiles Include="$(libpqlibDir)\binaries\$(Platform)\$(Configuration)\*.dll"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<Copy Condition="!exists('$(BaseDir)\$(Platform)\$(Configuration)\libpq.dll')"
|
||||||
|
SourceFiles="@(libpqFiles)"
|
||||||
|
DestinationFiles="@(libpqFiles->'$(BaseDir)\$(Platform)\$(Configuration)\%(Filename)%(Extension)')"
|
||||||
|
/>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemDefinitionGroup>
|
||||||
|
<ClCompile>
|
||||||
|
<AdditionalIncludeDirectories>$(libpqlibDir)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<PreprocessorDefinitions>SWITCH_HAVE_PGSQL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalLibraryDirectories>$(libpqlibDir)\binaries\$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>libpq.lib;Secur32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
</Project>
|
Loading…
Reference in New Issue