Permalink
Browse files

ngx_postgres-0.1

  • Loading branch information...
0 parents commit 283ff7e1acf39f5298e0325e067ce64680137cac @PiotrSikora PiotrSikora committed May 5, 2010
Showing with 16,205 additions and 0 deletions.
  1. +2 −0 CHANGES
  2. +25 −0 LICENSE
  3. +52 −0 README
  4. +71 −0 config
  5. +76 −0 src/ngx_postgres_ddebug.h
  6. +347 −0 src/ngx_postgres_handler.c
  7. +49 −0 src/ngx_postgres_handler.h
  8. +260 −0 src/ngx_postgres_keepalive.c
  9. +63 −0 src/ngx_postgres_keepalive.h
  10. +600 −0 src/ngx_postgres_module.c
  11. +50 −0 src/ngx_postgres_module.h
  12. +448 −0 src/ngx_postgres_output.c
  13. +51 −0 src/ngx_postgres_output.h
  14. +352 −0 src/ngx_postgres_processor.c
  15. +50 −0 src/ngx_postgres_processor.h
  16. +481 −0 src/ngx_postgres_upstream.c
  17. +131 −0 src/ngx_postgres_upstream.h
  18. +316 −0 src/ngx_postgres_util.c
  19. +78 −0 src/ngx_postgres_util.h
  20. +59 −0 src/resty_dbd_stream.h
  21. +2 −0 test/CHANGES
  22. +25 −0 test/LICENSE
  23. +52 −0 test/README
  24. +71 −0 test/config
  25. +805 −0 test/inc/Module/AutoInstall.pm
  26. +430 −0 test/inc/Module/Install.pm
  27. +61 −0 test/inc/Module/Install/AutoInstall.pm
  28. +78 −0 test/inc/Module/Install/Base.pm
  29. +81 −0 test/inc/Module/Install/Can.pm
  30. +93 −0 test/inc/Module/Install/Fetch.pm
  31. +34 −0 test/inc/Module/Install/Include.pm
  32. +268 −0 test/inc/Module/Install/Makefile.pm
  33. +624 −0 test/inc/Module/Install/Metadata.pm
  34. +29 −0 test/inc/Module/Install/TestBase.pm
  35. +64 −0 test/inc/Module/Install/Win32.pm
  36. +60 −0 test/inc/Module/Install/WriteAll.pm
  37. +539 −0 test/inc/Spiffy.pm
  38. +684 −0 test/inc/Test/Base.pm
  39. +344 −0 test/inc/Test/Base/Filter.pm
  40. +1,589 −0 test/inc/Test/Builder.pm
  41. +73 −0 test/inc/Test/Builder/Module.pm
  42. +746 −0 test/inc/Test/More.pm
  43. +77 −0 test/lib/Test/Nginx.pm
  44. +470 −0 test/lib/Test/Nginx/LWP.pm
  45. +755 −0 test/lib/Test/Nginx/Socket.pm
  46. +485 −0 test/lib/Test/Nginx/Util.pm
  47. +76 −0 test/src/ngx_postgres_ddebug.h
  48. +347 −0 test/src/ngx_postgres_handler.c
  49. +49 −0 test/src/ngx_postgres_handler.h
  50. +260 −0 test/src/ngx_postgres_keepalive.c
  51. +63 −0 test/src/ngx_postgres_keepalive.h
  52. +600 −0 test/src/ngx_postgres_module.c
  53. +50 −0 test/src/ngx_postgres_module.h
  54. +448 −0 test/src/ngx_postgres_output.c
  55. +51 −0 test/src/ngx_postgres_output.h
  56. +352 −0 test/src/ngx_postgres_processor.c
  57. +50 −0 test/src/ngx_postgres_processor.h
  58. +481 −0 test/src/ngx_postgres_upstream.c
  59. +131 −0 test/src/ngx_postgres_upstream.h
  60. +316 −0 test/src/ngx_postgres_util.c
  61. +78 −0 test/src/ngx_postgres_util.h
  62. +59 −0 test/src/resty_dbd_stream.h
  63. +93 −0 test/t/errors.t
  64. +246 −0 test/t/sanity.t
  65. +48 −0 test/t/servroot/conf/nginx.conf
  66. +1 −0 test/t/servroot/html/index.html
  67. +2 −0 test/t/servroot/logs/access.log
  68. +303 −0 test/t/servroot/logs/error.log
  69. +1 −0 test/t/servroot/logs/nginx.pid
@@ -0,0 +1,2 @@
+2010-05-05 VERSION 0.1
+ * Initial release
25 LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) 2010, FRiCKLE Piotr Sikora <info@frickle.com>
+Copyright (c) 2009-2010, Xiaozhe Wang <chaoslawful@gmail.com>
+Copyright (c) 2009-2010, Yichun Zhang <agentzh@gmail.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 README
@@ -0,0 +1,52 @@
+ABOUT:
+------
+ngx_postgres is an upstream module that allows nginx
+to communicate directly with PostgreSQL database.
+
+Response is generated in RDS format, so it's compatible with:
+rds_json, ngx_drizzle and ngx_oracle modules.
+
+
+CONFIGURATION DIRECTIVES:
+-------------------------
+
+ postgres_server ip[:port] dbname=dbname user=user password=pass (context: upstream)
+ -----------------------------------------------------------------------------------
+ default: none
+
+ postgres_keepalive off | max=count [mode=single|multi] [overflow=ignore|reject] (context: upstream)
+ ---------------------------------------------------------------------------------------------------
+ default: max=10 mode=single overflow=ignore
+
+ postgres_pass upstream (context: http, server, location)
+ --------------------------------------------------------
+ default: none
+
+ postgres_query query (context: http, server, location)
+ ------------------------------------------------------
+ default: none
+
+ postgres_connect_timeout timeout (context: http, server, location)
+ ------------------------------------------------------------------
+ default: 10s
+
+ postgres_result_timeout timeout (context: http, server, location)
+ -----------------------------------------------------------------
+ default: 30s
+
+
+EXAMPLE CONFIGURATION:
+----------------------
+http {
+ upstream database {
+ postgres_server 127.0.0.1 dbname=test
+ user=monty password=some_pass;
+ }
+
+ server {
+ location / {
+ postgres_pass database;
+ postgres_query "select * from cats";
+ }
+ }
+}
71 config
@@ -0,0 +1,71 @@
+ngx_feature="libpq library"
+ngx_feature_name=
+ngx_feature_run=no
+ngx_feature_incs="#include <libpq-fe.h>"
+ngx_feature_path=
+ngx_feature_libs="-lpq"
+ngx_feature_test="PQconndefaults();"
+. auto/feature
+
+if [ $ngx_found = no ]; then
+ # FreeBSD
+ ngx_feature="libpq library in /usr/local/"
+ ngx_feature_path="/usr/local/include"
+ if [ $NGX_RPATH = YES ]; then
+ ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lpq"
+ else
+ ngx_feature_libs="-L/usr/local/lib -lpq"
+ fi
+ . auto/feature
+fi
+
+if [ $ngx_found = no ]; then
+ # OpenBSD
+ ngx_feature="libpq library in /usr/local/../postgresql/"
+ ngx_feature_path="/usr/local/include/postgresql"
+ if [ $NGX_RPATH = YES ]; then
+ ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lpq"
+ else
+ ngx_feature_libs="-L/usr/local/lib -lpq"
+ fi
+ . auto/feature
+fi
+
+if [ $ngx_found = no ]; then
+ # NetBSD
+ ngx_feature="libpq library in /usr/pkg/"
+ ngx_feature_path="/usr/pkg/include/"
+ if [ $NGX_RPATH = YES ]; then
+ ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lpq"
+ else
+ ngx_feature_libs="-L/usr/pkg/lib -lpq"
+ fi
+ . auto/feature
+fi
+
+if [ $ngx_found = no ]; then
+ # MacPorts
+ ngx_feature="libpq library in /opt/local/"
+ ngx_feature_path="/opt/local/include"
+ if [ $NGX_RPATH = YES ]; then
+ ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lpq"
+ else
+ ngx_feature_libs="-L/opt/local/lib -lpq"
+ fi
+ . auto/feature
+fi
+
+if [ $ngx_found = yes ]; then
+ CORE_INCS="$CORE_INCS $ngx_feature_path"
+ CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
+else
+ cat << END
+ $0: error: the ngx_postgres addon requires the libpq library.
+END
+ exit 1
+fi
+
+ngx_addon_name=ngx_postgres_module
+HTTP_MODULES="$HTTP_MODULES ngx_postgres_module"
+NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_postgres_module.c $ngx_addon_dir/src/ngx_postgres_handler.c $ngx_addon_dir/src/ngx_postgres_processor.c $ngx_addon_dir/src/ngx_postgres_upstream.c $ngx_addon_dir/src/ngx_postgres_util.c $ngx_addon_dir/src/ngx_postgres_output.c $ngx_addon_dir/src/ngx_postgres_keepalive.c"
+NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_postgres_ddebug.h $ngx_addon_dir/src/ngx_postgres_module.h $ngx_addon_dir/src/ngx_postgres_handler.h $ngx_addon_dir/src/ngx_postgres_processor.h $ngx_addon_dir/src/ngx_postgres_upstream.h $ngx_addon_dir/src/ngx_postgres_util.h $ngx_addon_dir/src/ngx_postgres_output.h $ngx_addon_dir/src/resty_dbd_stream.h $ngx_addon_dir/src/ngx_postgres_keepalive.h"
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2010, FRiCKLE Piotr Sikora <info@frickle.com>
+ * Copyright (c) 2009-2010, Xiaozhe Wang <chaoslawful@gmail.com>
+ * Copyright (c) 2009-2010, Yichun Zhang <agentzh@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NGX_POSTGRES_DDEBUG_H_
+#define _NGX_POSTGRES_DDEBUG_H_
+
+#include <ngx_core.h>
+
+#if defined(DDEBUG) && (DDEBUG)
+
+# if (NGX_HAVE_VARIADIC_MACROS)
+
+# define dd(...) fprintf(stderr, "postgres *** %s: ", __func__); \
+ fprintf(stderr, __VA_ARGS__); \
+ fprintf(stderr, " *** %s line %d.\n", __FILE__, __LINE__)
+
+# else
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <stdarg.h>
+
+static void
+dd(const char * fmt, ...)
+{
+ /* TODO */
+}
+
+# endif
+
+#else
+
+# if (NGX_HAVE_VARIADIC_MACROS)
+
+# define dd(...)
+
+# else
+
+#include <stdarg.h>
+
+static void
+dd(const char * fmt, ...)
+{
+}
+
+# endif
+
+#endif
+
+#endif /* _NGX_POSTGRES_DDEBUG_H_ */
Oops, something went wrong.

0 comments on commit 283ff7e

Please sign in to comment.