Skip to content

Commit

Permalink
Detect version of libpq library.
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrSikora committed Dec 22, 2010
1 parent bc76a6b commit 9bb175f
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 21 deletions.
13 changes: 0 additions & 13 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,4 @@ Features that sooner or later will be added to `ngx_postgres`:

* Cancel long-running queries using `PQcancel()`.

* Detect client library version using `PQlibVersion()` (PostgreSQL 9.1+)
or exports (for older releases):

8.0.0 -> PQcancel 122
8.1.0 -> PQregisterThreadLock 125
8.1.4 -> PQescapeByteaConn 127
8.2.0 -> PQsendDescribePortal 136
8.3.0 -> PQconnectionNeedsPassword 140
8.4.0 -> PQinitOpenSSL 153
8.5.x -> PQinitOpenSSL 153
9.0.0 -> PQconnectStartParams 157
9.1.x -> PQlibVersion 160

* Detect server version using `PQserverVersion()`.
118 changes: 110 additions & 8 deletions config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ngx_feature_name=
ngx_feature_run=no
ngx_feature_incs="#include <libpq-fe.h>"
ngx_feature_test="PQconndefaults();"
ngx_feature_test="(void) PQconndefaults();"

if [ -n "$LIBPQ_INC" -o -n "$LIBPQ_LIB" ]; then
# specified by LIBPQ_INC and LIBPQ_LIB
Expand Down Expand Up @@ -76,19 +76,121 @@ else
fi
fi

if [ $ngx_found = yes ]; then
CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
if [ $ngx_found = no ]; then
cat << END
$0: error: ngx_postgres addon was unable to find the libpq library.
END
exit 1
fi

ngx_version=`grep nginx_version src/core/nginx.h | sed -e 's/^.* \(.*\)$/\1/'`

if [ -z "$ngx_version" ]; then
cat << END
$0: error: ngx_postgres addon was unable to detect version of nginx.
END
exit 1
fi

# work-around for versions of nginx older than nginx-0.9.0
if [ $ngx_version -ge 9000 ]; then
ngx_feature_name="NGX_POSTGRES_LIBRARY_VERSION"
ngx_feature_run=value
else
cat << END
$0: error: the ngx_postgres addon requires the libpq library.
ngx_feature_name="NGX_POSTGRES_LIBRARY_VERSION_DETECTED"
ngx_feature_run=no
fi

lib_version=90100
ngx_feature="libpq library version 9.1"
ngx_feature_test="printf(\"%d\", PQlibVersion())"
. auto/feature

if [ $ngx_found = no ]; then
lib_version=90000
ngx_feature="libpq library version 9.0"
ngx_feature_test="(void) PQconnectStartParams(NULL, NULL, 0);
printf(\"$lib_version\")"
. auto/feature
fi

if [ $ngx_found = no ]; then
lib_version=80400
ngx_feature="libpq library version 8.4"
ngx_feature_test="PQinitOpenSSL(0, 0);
printf(\"$lib_version\")"
. auto/feature
fi

if [ $ngx_found = no ]; then
lib_version=80300
ngx_feature="libpq library version 8.3"
ngx_feature_test="(void) PQconnectionNeedsPassword(NULL);
printf(\"$lib_version\")"
. auto/feature
fi

if [ $ngx_found = no ]; then
lib_version=80200
ngx_feature="libpq library version 8.2"
ngx_feature_test="(void) PQsendDescribePortal(NULL, NULL);
printf(\"$lib_version\")"
. auto/feature
fi

if [ $ngx_found = no ]; then
lib_version=80104
ngx_feature="libpq library version 8.1.4"
ngx_feature_test="(void) PQescapeByteaConn(NULL, NULL, 0, 0);
(void) PQregisterThreadLock(NULL);
printf(\"$lib_version\")"
. auto/feature
fi

if [ $ngx_found = no ]; then
lib_version=80100
ngx_feature="libpq library version 8.1.0"
ngx_feature_test="(void) PQregisterThreadLock(NULL);
printf(\"$lib_version\")"
. auto/feature
fi

if [ $ngx_found = no ]; then
lib_version=80008
ngx_feature="libpq library version 8.0.8"
ngx_feature_test="(void) PQescapeByteaConn(NULL, NULL, 0, 0);
(void) PQcancel(NULL, NULL, 0);
printf(\"$lib_version\")"
. auto/feature
fi

if [ $ngx_found = no ]; then
lib_version=80000
ngx_feature="libpq library version 8.0.0"
ngx_feature_test="(void) PQcancel(NULL, NULL, 0);
printf(\"$lib_version\")"
. auto/feature
fi

if [ $ngx_found = no ]; then
cat << END
$0: error: ngx_postgres addon was unable to detect version of the libpq library.
END
exit 1
exit 1
fi

ngx_addon_name=ngx_postgres_module
# work-around for versions of nginx older than nginx-0.9.0
if [ $ngx_version -lt 9000 ]; then
have=NGX_POSTGRES_LIBRARY_VERSION value=$lib_version . auto/define
fi

ngx_addon_name=ngx_postgres

HTTP_MODULES="$HTTP_MODULES ngx_postgres_module"

CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"

NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_postgres_escape.c $ngx_addon_dir/src/ngx_postgres_handler.c $ngx_addon_dir/src/ngx_postgres_keepalive.c $ngx_addon_dir/src/ngx_postgres_module.c $ngx_addon_dir/src/ngx_postgres_output.c $ngx_addon_dir/src/ngx_postgres_processor.c $ngx_addon_dir/src/ngx_postgres_rewrite.c $ngx_addon_dir/src/ngx_postgres_upstream.c $ngx_addon_dir/src/ngx_postgres_util.c $ngx_addon_dir/src/ngx_postgres_variable.c"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_postgres_escape.h $ngx_addon_dir/src/ngx_postgres_handler.h $ngx_addon_dir/src/ngx_postgres_keepalive.h $ngx_addon_dir/src/ngx_postgres_module.h $ngx_addon_dir/src/ngx_postgres_output.h $ngx_addon_dir/src/ngx_postgres_processor.h $ngx_addon_dir/src/ngx_postgres_rewrite.h $ngx_addon_dir/src/ngx_postgres_upstream.h $ngx_addon_dir/src/ngx_postgres_util.h $ngx_addon_dir/src/ngx_postgres_variable.h $ngx_addon_dir/src/ngx_postgres_ddebug.h $ngx_addon_dir/src/resty_dbd_stream.h"

Expand Down

0 comments on commit 9bb175f

Please sign in to comment.