From a3307ded25bac115deec4564a1ab975380c06328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Thu, 13 Oct 2011 11:42:14 +0800 Subject: [PATCH 01/72] fixed the download page links in docs. --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 401a0ce..741a875 100644 --- a/README +++ b/README @@ -157,7 +157,7 @@ Installation Download the latest version of the release tarball of this module from rds-json-nginx-module file list - (). + (). Compatibility The following versions of Nginx should work with this module: From 6e4ae1f50f4f1b11194759f9b52f121b2059581e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Fri, 4 Nov 2011 18:30:32 +0800 Subject: [PATCH 02/72] confirmed that we work with nginx 1.0.9. --- README | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README b/README index 741a875..c735dc2 100644 --- a/README +++ b/README @@ -140,20 +140,20 @@ Directives Installation Grab the nginx source code from nginx.net (), for - example, the version 1.0.5 (see nginx compatibility), and then build + example, the version 1.0.9 (see nginx compatibility), and then build the source with this module: - $ wget 'http://sysoev.ru/nginx/nginx-1.0.5.tar.gz' - $ tar -xzvf nginx-1.0.5.tar.gz - $ cd nginx-1.0.5/ + wget 'http://sysoev.ru/nginx/nginx-1.0.9.tar.gz' + tar -xzvf nginx-1.0.9.tar.gz + cd nginx-1.0.9/ # Here we assume you would install you nginx under /opt/nginx/. - $ ./configure --prefix=/opt/nginx \ + ./configure --prefix=/opt/nginx \ --add-module=/path/to/drizzle-nginx-module --add-module=/path/to/rds-json-nginx-module - $ make -j2 - $ make install + make -j2 + make install Download the latest version of the release tarball of this module from rds-json-nginx-module file list @@ -164,7 +164,7 @@ Compatibility * 1.1.x (last tested: 1.1.5) - * 1.0.x (last tested: 1.0.8) + * 1.0.x (last tested: 1.0.9) * 0.9.x (last tested: 0.9.4) From 3a576ce1ca2ab297a14fe8bbd6923d9e2b537095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Fri, 2 Dec 2011 17:38:08 +0800 Subject: [PATCH 03/72] added a new (passing) test case for ngx_postgres (github issue #2). --- t/pg.t | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/t/pg.t b/t/pg.t index 4606bdd..002151b 100644 --- a/t/pg.t +++ b/t/pg.t @@ -5,7 +5,7 @@ use Test::Nginx::Socket; repeat_each(2); -plan tests => repeat_each() * 2 * blocks(); +plan tests => repeat_each() * (2 * blocks() + 1); $ENV{TEST_NGINX_POSTGRESQL_PORT} ||= 5432; @@ -100,3 +100,28 @@ GET /test [{"id":1,"flag":true},{"id":2,"flag":false}] --- skip_nginx: 2: < 0.7.46 + + +=== TEST 3: sanity (github issue #2) +--- http_config + upstream backend { + postgres_server 127.0.0.1:$TEST_NGINX_POSTGRESQL_PORT + dbname=ngx_test user=ngx_test password=ngx_test; + } +--- config + location /pg { + rds_json on; + rds_json_root url; + + postgres_pass backend; + postgres_query GET "select * from cats order by id"; + postgres_output rds; + } +--- request +GET /pg +--- response_headers +Content-Type: application/json +--- response_body chop +{"url":[{"id":2,"name":null},{"id":3,"name":"bob"}]} +--- skip_nginx: 2: < 0.7.46 + From 773662e50205fced2a56320a5f6519ab4f895c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Fri, 2 Dec 2011 18:33:46 +0800 Subject: [PATCH 04/72] now we honor environments TEST_NGINX_MYSQL_HOST and TEST_NGINX_POSTGRESQL_HOST. --- t/000_init.t | 73 ++++++++++++++++++++++++++++++++++++++- t/compact/buf.t | 2 +- t/compact/openresty.t | 3 +- t/compact/sanity-stream.t | 3 +- t/compact/sanity.t | 5 +-- t/escape.t | 3 +- t/form.t | 3 +- t/openresty.t | 3 +- t/pg.t | 7 ++-- t/property.t | 3 +- t/sanity-stream.t | 3 +- t/sanity.t | 5 +-- util/build.sh | 2 +- 13 files changed, 98 insertions(+), 17 deletions(-) diff --git a/t/000_init.t b/t/000_init.t index 43150f1..e4a5d0f 100644 --- a/t/000_init.t +++ b/t/000_init.t @@ -7,15 +7,27 @@ repeat_each(1); plan tests => repeat_each() * blocks(); +$ENV{TEST_NGINX_POSTGRESQL_PORT} ||= 5432; +$ENV{TEST_NGINX_POSTGRESQL_HOST} ||= '127.0.0.1'; + +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream database { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ +our $http_config2 = <<'_EOC_'; + upstream database { + postgres_server $TEST_NGINX_POSTGRESQL_HOST:$TEST_NGINX_POSTGRESQL_PORT + dbname=ngx_test user=ngx_test password=ngx_test; + } +_EOC_ + + worker_connections(128); no_shuffle(); run_tests(); @@ -128,3 +140,62 @@ GET /init --- error_code: 200 --- timeout: 10 + + +=== TEST 8: cats - drop table +--- http_config eval: $::http_config2 +--- config + location = /init { + postgres_pass database; + postgres_query "DROP TABLE cats"; + error_page 500 = /ignore; + } + + location /ignore { echo "ignore"; } +--- request +GET /init +--- error_code: 200 +--- timeout: 10 + + + +=== TEST 9: cats - create table +--- http_config eval: $::http_config2 +--- config + location = /init { + postgres_pass database; + postgres_query "CREATE TABLE cats (id integer, name text)"; + } +--- request +GET /init +--- error_code: 200 +--- timeout: 10 + + + +=== TEST 10: cats - insert value +--- http_config eval: $::http_config2 +--- config + location = /init { + postgres_pass database; + postgres_query "INSERT INTO cats (id) VALUES (2)"; + } +--- request +GET /init +--- error_code: 200 +--- timeout: 10 + + + +=== TEST 11: cats - insert value +--- http_config eval: $::http_config2 +--- config + location = /init { + postgres_pass database; + postgres_query "INSERT INTO cats (id, name) VALUES (3, 'bob')"; + } +--- request +GET /init +--- error_code: 200 +--- timeout: 10 + diff --git a/t/compact/buf.t b/t/compact/buf.t index 2782b8d..429ce31 100644 --- a/t/compact/buf.t +++ b/t/compact/buf.t @@ -1,4 +1,4 @@ -# vi:filetype=perl +# vi:filetype= use lib 'lib'; use Test::Nginx::Socket; diff --git a/t/compact/openresty.t b/t/compact/openresty.t index 0d50e85..64ab9ba 100644 --- a/t/compact/openresty.t +++ b/t/compact/openresty.t @@ -13,11 +13,12 @@ log_level('warn'); plan tests => repeat_each() * 3 * blocks(); +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ diff --git a/t/compact/sanity-stream.t b/t/compact/sanity-stream.t index bddd3a9..06114bb 100644 --- a/t/compact/sanity-stream.t +++ b/t/compact/sanity-stream.t @@ -10,11 +10,12 @@ repeat_each(1); plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 3; +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ diff --git a/t/compact/sanity.t b/t/compact/sanity.t index f8143c1..04df8c6 100644 --- a/t/compact/sanity.t +++ b/t/compact/sanity.t @@ -1,4 +1,4 @@ -# vi:filetype=perl +# vi:filetype= use lib 'lib'; use Test::Nginx::Socket; @@ -10,11 +10,12 @@ repeat_each(1); plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 3; +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ diff --git a/t/escape.t b/t/escape.t index 72d3df4..44c6c57 100644 --- a/t/escape.t +++ b/t/escape.t @@ -7,11 +7,12 @@ repeat_each(2); plan tests => repeat_each() * 2 * blocks(); +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ diff --git a/t/form.t b/t/form.t index 99d446b..7fac2b0 100644 --- a/t/form.t +++ b/t/form.t @@ -7,11 +7,12 @@ repeat_each(2); plan tests => repeat_each() * 2 * blocks(); +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ diff --git a/t/openresty.t b/t/openresty.t index f1a22d3..389eb43 100644 --- a/t/openresty.t +++ b/t/openresty.t @@ -13,11 +13,12 @@ log_level('warn'); plan tests => repeat_each() * 3 * blocks(); +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ diff --git a/t/pg.t b/t/pg.t index 002151b..d7be1fd 100644 --- a/t/pg.t +++ b/t/pg.t @@ -7,6 +7,7 @@ repeat_each(2); plan tests => repeat_each() * (2 * blocks() + 1); +$ENV{TEST_NGINX_POSTGRESQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_POSTGRESQL_PORT} ||= 5432; no_long_string(); @@ -18,7 +19,7 @@ __DATA__ === TEST 1: bool blob field (keepalive off) --- http_config upstream backend { - postgres_server 127.0.0.1:$TEST_NGINX_POSTGRESQL_PORT + postgres_server $TEST_NGINX_POSTGRESQL_HOST:$TEST_NGINX_POSTGRESQL_PORT dbname=ngx_test user=ngx_test password=ngx_test; postgres_keepalive off; } @@ -62,7 +63,7 @@ GET /test === TEST 2: bool blob field (keepalive on) --- http_config upstream backend { - postgres_server 127.0.0.1:$TEST_NGINX_POSTGRESQL_PORT + postgres_server $TEST_NGINX_POSTGRESQL_HOST:$TEST_NGINX_POSTGRESQL_PORT dbname=ngx_test user=ngx_test password=ngx_test; } --- config @@ -105,7 +106,7 @@ GET /test === TEST 3: sanity (github issue #2) --- http_config upstream backend { - postgres_server 127.0.0.1:$TEST_NGINX_POSTGRESQL_PORT + postgres_server $TEST_NGINX_POSTGRESQL_HOST:$TEST_NGINX_POSTGRESQL_PORT dbname=ngx_test user=ngx_test password=ngx_test; } --- config diff --git a/t/property.t b/t/property.t index 403e555..843d218 100644 --- a/t/property.t +++ b/t/property.t @@ -7,11 +7,12 @@ repeat_each(2); plan tests => repeat_each() * 2 * blocks(); +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ diff --git a/t/sanity-stream.t b/t/sanity-stream.t index 12c00ce..433695e 100644 --- a/t/sanity-stream.t +++ b/t/sanity-stream.t @@ -10,11 +10,12 @@ repeat_each(1); plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 3; +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ diff --git a/t/sanity.t b/t/sanity.t index 8279b11..ae9bb58 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -10,11 +10,12 @@ repeat_each(1); plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 3; +$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; our $http_config = <<'_EOC_'; upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test; } _EOC_ @@ -328,7 +329,7 @@ GET /test === TEST 13: strings need to be escaped (forcing utf8) --- http_config upstream backend { - drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql + drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test charset=utf8; } diff --git a/util/build.sh b/util/build.sh index db59847..4b6d5fb 100755 --- a/util/build.sh +++ b/util/build.sh @@ -36,7 +36,7 @@ cd nginx-$version/ || exit 1 if [[ "$BUILD_CLEAN" -eq 1 || ! -f Makefile || "$root/config" -nt Makefile || "$root/util/build.sh" -nt Makefile ]]; then ./configure --prefix=$target \ --with-cc-opt="-O1" \ - --with-ld-opt="-Wl,-rpath,/opt/drizzle/lib" \ + --with-ld-opt="-Wl,-rpath,/opt/drizzle/lib:/opt/pg9/lib" \ --without-mail_pop3_module \ --without-mail_imap_module \ --without-mail_smtp_module \ From 2574878dc713b05b2e14b624c7af0a3c74a4ec05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Fri, 2 Dec 2011 18:35:48 +0800 Subject: [PATCH 05/72] updated valgrind.suppress a bit. --- valgrind.suppress | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/valgrind.suppress b/valgrind.suppress index a74d487..7ce38df 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -1,3 +1,18 @@ +{ + + Memcheck:Param + epoll_ctl(event) + fun:epoll_ctl +} +{ + + Memcheck:Leak + fun:malloc + fun:ngx_alloc + fun:ngx_event_process_init + fun:ngx_single_process_cycle + fun:(below main) +} { nginx-core-process-init Memcheck:Leak From 23c47f226f9c992eee0248151d99fae05111c8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Mon, 5 Dec 2011 17:08:53 +0800 Subject: [PATCH 06/72] added more debug level error log outputs to ease debugging (as discussed in github issue #2) --- src/ngx_http_rds_json_filter_module.c | 28 ++++++++++++++++++++++----- src/ngx_http_rds_json_handler.c | 2 ++ src/ngx_http_rds_json_output.c | 2 ++ src/ngx_http_rds_json_processor.c | 2 ++ src/ngx_http_rds_json_util.c | 2 ++ t/sanity.t | 22 +++++++++++++++++++-- 6 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 7bcee34..28ce1b4 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -4,7 +4,9 @@ */ +#ifndef DDEBUG #define DDEBUG 0 +#endif #include "ddebug.h" #include "ngx_http_rds_json_filter_module.h" @@ -171,7 +173,8 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) { ngx_http_set_ctx(r, NULL, ngx_http_rds_json_filter_module); - dd("status is not OK: %d, skipping", (int) r->headers_out.status); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json: skipped due to bad status: %ui", r->headers_out.status); return ngx_http_rds_json_next_header_filter(r); } @@ -180,11 +183,18 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) conf = ngx_http_get_module_loc_conf(r, ngx_http_rds_json_filter_module); - if ( ! conf->enabled) { + if (!conf->enabled) { + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json: skipped because not enabled in the current location"); + return ngx_http_rds_json_next_header_filter(r); } if (ngx_http_rds_json_test_content_type(r) != NGX_OK) { + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json: skipped due to unmatched Content-Type response " + "header \"%V\"", &r->headers_out.content_type); + return ngx_http_rds_json_next_header_filter(r); } @@ -226,6 +236,9 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) r->filter_need_in_memory = 1; + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json header filter postponed header sending"); + /* we do postpone the header sending to the body filter */ return NGX_OK; } @@ -247,6 +260,9 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) return ngx_http_rds_json_next_body_filter(r, in); } + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json body filter postponed header sending"); + switch (ctx->state) { case state_expect_header: rc = ngx_http_rds_json_process_header(r, in, ctx); @@ -270,9 +286,10 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) case state_done: - /* mark the remaining bufs as consumed */ + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json body filter discarding unexpected trailing buffers"); - dd("discarding bufs"); + /* mark the remaining bufs as consumed */ ngx_http_rds_json_discard_bufs(r->pool, in); @@ -302,7 +319,8 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) r->headers_out.status = rc; - dd("sending ERROR headers"); + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json body filter sending error page headers"); ngx_http_rds_json_next_header_filter(r); ngx_http_send_special(r, NGX_HTTP_LAST); diff --git a/src/ngx_http_rds_json_handler.c b/src/ngx_http_rds_json_handler.c index 01bdbc5..080f027 100644 --- a/src/ngx_http_rds_json_handler.c +++ b/src/ngx_http_rds_json_handler.c @@ -1,4 +1,6 @@ +#ifndef DDEBUG #define DDEBUG 0 +#endif #include "ddebug.h" #include "ngx_http_rds_json_handler.h" diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index 6e299be..cb30eed 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -4,7 +4,9 @@ */ +#ifndef DDEBUG #define DDEBUG 0 +#endif #include "ddebug.h" #include "ngx_http_rds_json_filter_module.h" diff --git a/src/ngx_http_rds_json_processor.c b/src/ngx_http_rds_json_processor.c index f83b883..37161f9 100644 --- a/src/ngx_http_rds_json_processor.c +++ b/src/ngx_http_rds_json_processor.c @@ -3,7 +3,9 @@ */ +#ifndef DDEBUG #define DDEBUG 0 +#endif #include "ddebug.h" #include "ngx_http_rds_json_processor.h" diff --git a/src/ngx_http_rds_json_util.c b/src/ngx_http_rds_json_util.c index 707f0fd..60148fd 100644 --- a/src/ngx_http_rds_json_util.c +++ b/src/ngx_http_rds_json_util.c @@ -1,4 +1,6 @@ +#ifndef DDEBUG #define DDEBUG 0 +#endif #include "ddebug.h" #include "resty_dbd_stream.h" diff --git a/t/sanity.t b/t/sanity.t index ae9bb58..50492c6 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -6,9 +6,9 @@ use Test::Nginx::Socket; #repeat_each(10); no_shuffle(); -repeat_each(1); +repeat_each(2); -plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 3; +plan tests => repeat_each() * (2 * blocks() + 7); $ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; $ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; @@ -439,3 +439,21 @@ GET /mysql {"errcode":0,"errstr":"Rows matched: 1 Changed: 0 Warnings: 0"} --- SKIP + + +=== TEST 17: bad MIME type +--- http_config eval: $::http_config +--- config + location /mysql { + default_type "text/css"; + echo hello; + rds_json on; + } +--- request +GET /mysql +--- response_headers +Content-Type: text/css +--- response_body +hello +--- timeout: 15 + From 84b5222db68b06d9fd5d3219235af5636b8e2ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Mon, 5 Dec 2011 17:12:51 +0800 Subject: [PATCH 07/72] use the ngx-build script from the nginx-devel-utils project to build everything in our developer build script. --- util/build.sh | 49 ++++--------------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/util/build.sh b/util/build.sh index 4b6d5fb..ff093db 100755 --- a/util/build.sh +++ b/util/build.sh @@ -3,38 +3,12 @@ # this file is mostly meant to be used by the author himself. root=`pwd` -version=$1 home=~ +version=$1 +force=$2 #opts=$2 -target=$root/work/nginx - -if [ ! -d ./buildroot ]; then - mkdir ./buildroot || exit 1 -fi - -cd buildroot || exit 1 - -if [ ! -s "nginx-$version.tar.gz" ]; then - if [ -f ~/work/nginx-$version.tar.gz ]; then - cp ~/work/nginx-$version.tar.gz ./ || exit 1 - else - wget "http://sysoev.ru/nginx/nginx-$version.tar.gz" -O nginx-$version.tar.gz || exit 1 - cp nginx-$version.tar.gz ~/work/ || exit 1 - fi - tar -xzvf nginx-$version.tar.gz || exit 1 - cp $root/../no-pool-nginx/nginx-$version-no_pool.patch ./ || exit 1 - patch -p0 < nginx-$version-no_pool.patch || exit 1 -fi - -#tar -xzvf nginx-$version.tar.gz || exit 1 -#cp $root/../no-pool-nginx/nginx-$version-no_pool.patch ./ || exit 1 -#patch -p0 < nginx-$version-no_pool.patch || exit 1 - -cd nginx-$version/ || exit 1 - -if [[ "$BUILD_CLEAN" -eq 1 || ! -f Makefile || "$root/config" -nt Makefile || "$root/util/build.sh" -nt Makefile ]]; then - ./configure --prefix=$target \ +ngx-build $force $version \ --with-cc-opt="-O1" \ --with-ld-opt="-Wl,-rpath,/opt/drizzle/lib:/opt/pg9/lib" \ --without-mail_pop3_module \ @@ -57,26 +31,11 @@ if [[ "$BUILD_CLEAN" -eq 1 || ! -f Makefile || "$root/config" -nt Makefile || "$ --add-module=$root/../drizzle-nginx-module \ --add-module=$root/../form-input-nginx-module \ --add-module=$root/../postgres-nginx-module \ - --with-debug \ - || exit 1 + --with-debug #--add-module=$root/../lua-nginx-module \ #--add-module=$home/work/ngx_http_auth_request-0.1 #\ #--with-rtsig_module #--with-cc-opt="-g3 -O0" #--add-module=$root/../echo-nginx-module \ #--without-http_ssi_module # we cannot disable ssi because echo_location_async depends on it (i dunno why?!) - if [ $? -ne 0 ]; then - echo "Failed to configure" - exit 1 - fi -fi - -if [ -f $target/sbin/nginx ]; then - rm -f $target/sbin/nginx -fi -if [ -f $target/logs/nginx.pid ]; then - kill `cat $target/logs/nginx.pid` -fi -make -j3 -make install From 71efdc89abb37ebce7b2229c74609be54fe1e101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Mon, 5 Dec 2011 20:35:02 +0800 Subject: [PATCH 08/72] added more valgrind suppression rules for archlinux gcc 4.6. --- valgrind.suppress | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/valgrind.suppress b/valgrind.suppress index 7ce38df..446d49f 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -1,3 +1,17 @@ +{ + + Memcheck:Leak + fun:malloc + fun:ngx_alloc + fun:ngx_palloc_large +} +{ + + Memcheck:Leak + fun:malloc + fun:ngx_alloc + obj:* +} { Memcheck:Param From 253db2b9d34b68c00970319b3b97f5da268d9e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Mon, 5 Dec 2011 20:44:22 +0800 Subject: [PATCH 09/72] splitted source lines exceeding 80 columns. --- src/ngx_http_rds_json_filter_module.c | 6 ++++-- src/ngx_http_rds_json_output.c | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 28ce1b4..f785d4b 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -174,7 +174,8 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) ngx_http_set_ctx(r, NULL, ngx_http_rds_json_filter_module); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json: skipped due to bad status: %ui", r->headers_out.status); + "rds json: skipped due to bad status: %ui", + r->headers_out.status); return ngx_http_rds_json_next_header_filter(r); } @@ -185,7 +186,8 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) if (!conf->enabled) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json: skipped because not enabled in the current location"); + "rds json: skipped because not enabled in the current " + "location"); return ngx_http_rds_json_next_header_filter(r); } diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index cb30eed..47e6914 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -103,8 +103,8 @@ ngx_http_rds_json_output_bufs(ngx_http_request_t *r, } #if defined(nginx_version) && nginx_version >= 1001004 - ngx_chain_update_chains(r->pool, &ctx->free_bufs, &ctx->busy_bufs, &ctx->out, - ctx->tag); + ngx_chain_update_chains(r->pool, &ctx->free_bufs, &ctx->busy_bufs, + &ctx->out, ctx->tag); #else ngx_chain_update_chains(&ctx->free_bufs, &ctx->busy_bufs, &ctx->out, ctx->tag); From 3397cd4feda277b6b6c3260a5a07f1d1edb02013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Tue, 6 Dec 2011 12:29:11 +0800 Subject: [PATCH 10/72] various test suite improvements and added more debugging outputs (dd macros). --- src/ngx_http_rds_json_filter_module.c | 6 ++++++ t/buf.t | 2 +- t/compact/buf.t | 2 +- t/compact/sanity-stream.t | 2 +- t/compact/sanity.t | 2 +- t/sanity-stream.t | 2 +- t/sanity.t | 3 ++- valgrind.suppress | 7 +++++++ 8 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index f785d4b..816032f 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -345,6 +345,8 @@ ngx_http_rds_json_filter_init(ngx_conf_t *cf) dd("setting next filter"); if (ngx_http_rds_json_filter_used) { + dd("register filters"); + ngx_http_rds_json_next_header_filter = ngx_http_top_header_filter; ngx_http_top_header_filter = ngx_http_rds_json_header_filter; @@ -676,6 +678,8 @@ ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, static char * ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { + dd("set filter used to 1"); + ngx_http_rds_json_filter_used = 1; return ngx_conf_set_flag_slot(cf, cmd, conf); @@ -684,6 +688,8 @@ ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) static ngx_int_t ngx_http_rds_json_pre_config(ngx_conf_t *cf) { + dd("set filter used to 0"); + ngx_http_rds_json_filter_used = 0; return NGX_OK; diff --git a/t/buf.t b/t/buf.t index 9e2ed9e..5118803 100644 --- a/t/buf.t +++ b/t/buf.t @@ -3,7 +3,7 @@ use lib 'lib'; use Test::Nginx::Socket; -repeat_each(1); +repeat_each(2); plan tests => repeat_each() * 2 * blocks(); diff --git a/t/compact/buf.t b/t/compact/buf.t index 429ce31..f467942 100644 --- a/t/compact/buf.t +++ b/t/compact/buf.t @@ -3,7 +3,7 @@ use lib 'lib'; use Test::Nginx::Socket; -repeat_each(1); +repeat_each(2); plan tests => repeat_each() * 2 * blocks(); diff --git a/t/compact/sanity-stream.t b/t/compact/sanity-stream.t index 06114bb..66cf7fd 100644 --- a/t/compact/sanity-stream.t +++ b/t/compact/sanity-stream.t @@ -6,7 +6,7 @@ use Test::Nginx::Socket; #repeat_each(10); no_shuffle(); -repeat_each(1); +repeat_each(2); plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 3; diff --git a/t/compact/sanity.t b/t/compact/sanity.t index 04df8c6..91b57ef 100644 --- a/t/compact/sanity.t +++ b/t/compact/sanity.t @@ -6,7 +6,7 @@ use Test::Nginx::Socket; #repeat_each(10); no_shuffle(); -repeat_each(1); +repeat_each(2); plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 3; diff --git a/t/sanity-stream.t b/t/sanity-stream.t index 433695e..116b987 100644 --- a/t/sanity-stream.t +++ b/t/sanity-stream.t @@ -6,7 +6,7 @@ use Test::Nginx::Socket; #repeat_each(10); no_shuffle(); -repeat_each(1); +repeat_each(2); plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 3; diff --git a/t/sanity.t b/t/sanity.t index 50492c6..2c7ea61 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -21,6 +21,7 @@ our $http_config = <<'_EOC_'; _EOC_ #no_long_string(); +#master_on(); run_tests(); @@ -34,7 +35,7 @@ __DATA__ location /mysql { drizzle_pass backend; #drizzle_dbname $dbname; - drizzle_query 'select * from cats'; + drizzle_query 'select * from cats order by id'; rds_json on; } --- request diff --git a/valgrind.suppress b/valgrind.suppress index 446d49f..8a2e0e8 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -1,3 +1,10 @@ +{ + + Memcheck:Param + socketcall.sendmsg(msg.msg_iov[i]) + fun:__sendmsg_nocancel + fun:ngx_write_channel +} { Memcheck:Leak From c5215c7e54da1f2ca5c00c7eb51661a53b142e75 Mon Sep 17 00:00:00 2001 From: liseen Date: Thu, 29 Mar 2012 20:16:35 +0800 Subject: [PATCH 11/72] added errcode key and errmsg key --- src/ngx_http_rds_json_filter_module.c | 133 ++++++++++++++++++++++++++ src/ngx_http_rds_json_filter_module.h | 3 + src/ngx_http_rds_json_handler.c | 19 +++- t/ret.t | 103 ++++++++++++++++++++ 4 files changed, 253 insertions(+), 5 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 816032f..1305615 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -20,6 +20,9 @@ #define ngx_http_rds_json_content_type "application/json" +#define ngx_http_rds_json_errcode_default_key "\"errcode\"" +#define ngx_http_rds_json_errstr_default_key "\"errstr\"" + static unsigned ngx_http_rds_json_filter_used = 0; @@ -47,6 +50,10 @@ static char * ngx_http_rds_json_success_property(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char * ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static char * ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); +static char * ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); static char * ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_int_t ngx_http_rds_json_pre_config(ngx_conf_t *cf); @@ -89,6 +96,24 @@ static ngx_command_t ngx_http_rds_json_commands[] = { 0, NULL }, + { ngx_string("rds_json_errcode_key"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF + |NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF + |NGX_CONF_TAKE1, + ngx_http_rds_json_errcode_key, + NGX_HTTP_LOC_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("rds_json_errstr_key"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF + |NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF + |NGX_CONF_TAKE1, + ngx_http_rds_json_errstr_key, + NGX_HTTP_LOC_CONF_OFFSET, + 0, + NULL }, + { ngx_string("rds_json_format"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF |NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF @@ -416,6 +441,12 @@ ngx_http_rds_json_merge_conf(ngx_conf_t *cf, void *parent, void *child) ngx_str_set(&conf->root, "\"data\""); } + ngx_conf_merge_str_value(conf->errcode_key, prev->errcode_key, + "\"errcode\""); + + ngx_conf_merge_str_value(conf->errstr_key, prev->errstr_key, + "\"errstr\""); + ngx_conf_merge_str_value(conf->content_type, prev->content_type, ngx_http_rds_json_content_type); @@ -675,6 +706,108 @@ ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, } +static char * +ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) +{ + ngx_http_rds_json_conf_t *jlcf = conf; + ngx_str_t *value; + uintptr_t escape; + u_char *p; + + value = cf->args->elts; + + if (jlcf->root.len) { + return "is duplicate"; + } + + if (value[1].len == 0) { + return "takes an empty value"; + } + + escape = ngx_http_rds_json_escape_json_str(NULL, value[1].data, + value[1].len); + + jlcf->errcode_key.len = value[1].len + escape + sizeof("\"\"") - 1; + + p = ngx_palloc(cf->pool, jlcf->errcode_key.len); + if (p == NULL) { + return NGX_CONF_ERROR; + } + + jlcf->errcode_key.data = p; + + *p++ = '"'; + + if (escape == 0) { + p = ngx_copy(p, value[1].data, value[1].len); + + } else { + p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data, + value[1].len); + } + + *p++ = '"'; + + if (p - jlcf->errcode_key.data != (ssize_t) jlcf->errcode_key.len) { + return "sees buffer error"; + } + + return NGX_CONF_OK; +} + + +static char * +ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) +{ + ngx_http_rds_json_conf_t *jlcf = conf; + ngx_str_t *value; + uintptr_t escape; + u_char *p; + + value = cf->args->elts; + + if (jlcf->errstr_key.len) { + return "is duplicate"; + } + + if (value[1].len == 0) { + return "takes an empty value"; + } + + escape = ngx_http_rds_json_escape_json_str(NULL, value[1].data, + value[1].len); + + jlcf->errstr_key.len = value[1].len + escape + sizeof("\"\"") - 1; + + p = ngx_palloc(cf->pool, jlcf->errstr_key.len); + if (p == NULL) { + return NGX_CONF_ERROR; + } + + jlcf->errstr_key.data = p; + + *p++ = '"'; + + if (escape == 0) { + p = ngx_copy(p, value[1].data, value[1].len); + + } else { + p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data, + value[1].len); + } + + *p++ = '"'; + + if (p - jlcf->errstr_key.data != (ssize_t) jlcf->errstr_key.len) { + return "sees buffer error"; + } + + return NGX_CONF_OK; +} + + static char * ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { diff --git a/src/ngx_http_rds_json_filter_module.h b/src/ngx_http_rds_json_filter_module.h index 275c6fd..87e992a 100644 --- a/src/ngx_http_rds_json_filter_module.h +++ b/src/ngx_http_rds_json_filter_module.h @@ -48,6 +48,9 @@ typedef struct { * key */ ngx_array_t *user_props; /* rds_json_user_property */ + ngx_str_t errcode_key; + ngx_str_t errstr_key; + size_t buf_size; /* for rds_json_ret */ diff --git a/src/ngx_http_rds_json_handler.c b/src/ngx_http_rds_json_handler.c index 080f027..722e880 100644 --- a/src/ngx_http_rds_json_handler.c +++ b/src/ngx_http_rds_json_handler.c @@ -35,7 +35,9 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) /* calculate the buffer size */ - len = sizeof("{\"errcode\":") - 1 + len = sizeof("{") - 1 + + conf->errcode_key.len + + sizeof(":") - 1 + conf->errcode.len + sizeof("}") - 1 ; @@ -44,9 +46,11 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) escape = ngx_http_rds_json_escape_json_str(NULL, errstr.data, errstr.len); - len += sizeof("\"errstr\":\"") - 1 + len += sizeof(",") - 1 + + conf->errstr_key.len + + sizeof(":\"") - 1 + errstr.len + escape - + sizeof("\",") - 1 + + sizeof("\"") - 1 ; } @@ -112,11 +116,16 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) *b->last++ = '{'; - b->last = ngx_copy_literal(b->last, "\"errcode\":"); + b->last = ngx_copy(b->last, conf->errcode_key.data, conf->errcode_key.len); + *b->last++ = ':'; b->last = ngx_copy(b->last, conf->errcode.data, conf->errcode.len); if (errstr.len) { - b->last = ngx_copy_literal(b->last, ",\"errstr\":\""); + *b->last++ = ','; + b->last = ngx_copy(b->last, + conf->errstr_key.data, conf->errstr_key.len); + *b->last++ = ':'; + *b->last++ = '"'; if (escape == 0) { b->last = ngx_copy(b->last, errstr.data, errstr.len); diff --git a/t/ret.t b/t/ret.t index 5cf154a..5105e50 100644 --- a/t/ret.t +++ b/t/ret.t @@ -4,6 +4,7 @@ use lib 'lib'; use Test::Nginx::Socket; repeat_each(3); +#repeat_each(1); plan tests => repeat_each() * 3 * blocks(); @@ -71,3 +72,105 @@ Content-Type: application/json --- response_body chop {"errcode":400,"errstr":"Invalid \"limit\" argument."} + + +=== TEST 5: location internal rewrite +--- config + location @err403 { + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } + + location /foo { + error_page 403 = @err403; + return 403; + } +--- request + GET /foo +--- response_headers +Content-Type: application/json +--- response_body chop +{"errcode":403,"errstr":"Forbidden","ret":false} + + + +=== TEST 6: rds_json_errcode_key +--- config + location /foo { + rds_json_errcode_key "ecode"; + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_headers +Content-Type: application/json +--- response_body chop +{"ecode":403,"errstr":"Forbidden","ret":false} + + +=== TEST 7: rds_json_errcode_key +--- config + rds_json_errcode_key "ecoderoot"; + + location /foo { + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_headers +Content-Type: application/json +--- response_body chop +{"ecoderoot":403,"errstr":"Forbidden","ret":false} + + +=== TEST 8: rds_json_errcode_key +--- config + rds_json_errcode_key "ecoderoot"; + + location /foo { + rds_json_errcode_key "ecode"; + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_headers +Content-Type: application/json +--- response_body chop +{"ecode":403,"errstr":"Forbidden","ret":false} + + + +=== TEST 9: rds_json_errstr_key +--- config + rds_json_errstr_key "msg"; + + location /foo { + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_headers +Content-Type: application/json +--- response_body chop +{"errcode":403,"msg":"Forbidden","ret":false} + + +=== TEST 10: rds_json_errstr_key +--- config + rds_json_errstr_key "msg"; + + location /foo { + rds_json_errstr_key "msg2"; + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_headers +Content-Type: application/json +--- response_body chop +{"errcode":403,"msg2":"Forbidden","ret":false} From 4defa055b2d5dd50ae8a0f30d8ca127aa69fbc7a Mon Sep 17 00:00:00 2001 From: liseen Date: Thu, 29 Mar 2012 20:23:25 +0800 Subject: [PATCH 12/72] updated README --- README | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README b/README index c735dc2..e5efcc8 100644 --- a/README +++ b/README @@ -119,6 +119,18 @@ Directives Both of the and arguments will be automatically quoted according to JSON strings' notation. + rds_json_errcode_key + syntax: rds_json_errcode_key + default: errcode + + Specify the errcode key name used in the JSON output + + rds_json_errstr_key + syntax: rds_json_errstr_key + default: errstr + + Specify the errstr key name used in the JSON output + rds_json_ret syntax: rds_json_ret default: no From 509fbf1ea01e5abccc7096d85984f4a5b06c1ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Sat, 7 Apr 2012 13:29:59 +0800 Subject: [PATCH 13/72] bugfix: microsoft C compilers complained about missing declarations of the type int8_t. now we explicitly include stdint.h. thanks runner-mei for reporting this issue in github issue #3. --- src/ngx_http_rds.h | 1 + src/ngx_http_rds_json_filter_module.h | 1 + src/ngx_http_rds_json_processor.c | 2 +- src/ngx_http_rds_json_util.h | 3 +++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ngx_http_rds.h b/src/ngx_http_rds.h index 2e3d878..838f838 100644 --- a/src/ngx_http_rds.h +++ b/src/ngx_http_rds.h @@ -11,6 +11,7 @@ #include #include #include +#include typedef struct { diff --git a/src/ngx_http_rds_json_filter_module.h b/src/ngx_http_rds_json_filter_module.h index 275c6fd..f0b3712 100644 --- a/src/ngx_http_rds_json_filter_module.h +++ b/src/ngx_http_rds_json_filter_module.h @@ -11,6 +11,7 @@ #include #include #include +#include #ifndef NGX_HTTP_RESET_CONTENT diff --git a/src/ngx_http_rds_json_processor.c b/src/ngx_http_rds_json_processor.c index 37161f9..4c43eb7 100644 --- a/src/ngx_http_rds_json_processor.c +++ b/src/ngx_http_rds_json_processor.c @@ -8,8 +8,8 @@ #endif #include "ddebug.h" -#include "ngx_http_rds_json_processor.h" #include "ngx_http_rds_json_util.h" +#include "ngx_http_rds_json_processor.h" #include "ngx_http_rds_json_output.h" #include "ngx_http_rds.h" #include "ngx_http_rds_utils.h" diff --git a/src/ngx_http_rds_json_util.h b/src/ngx_http_rds_json_util.h index 8002dba..6530c8c 100644 --- a/src/ngx_http_rds_json_util.h +++ b/src/ngx_http_rds_json_util.h @@ -3,6 +3,9 @@ #include #include +#include +#include + #ifndef NGX_UINT64_LEN #define NGX_UINT64_LEN (sizeof("18446744073709551615") - 1) From 0f0241007874ced66d26908d3bd667c9eee54c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Tue, 22 May 2012 17:09:03 +0800 Subject: [PATCH 14/72] fixed README a bit. --- README | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README b/README index e5efcc8..ece327e 100644 --- a/README +++ b/README @@ -121,15 +121,15 @@ Directives rds_json_errcode_key syntax: rds_json_errcode_key - default: errcode + default: rds_json_errcode_key errcode - Specify the errcode key name used in the JSON output + Specify the errcode key name used in the JSON output. rds_json_errstr_key syntax: rds_json_errstr_key - default: errstr + default: rds_json_errstr_key errstr - Specify the errstr key name used in the JSON output + Specify the errstr key name used in the JSON output. rds_json_ret syntax: rds_json_ret From 25a5efc53d7f2bbad14e870345f10f2fa98ec528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Tue, 22 May 2012 17:45:31 +0800 Subject: [PATCH 15/72] fixed coding style issues at various places; bugfix: rds_json_errcode_key could not be used after rds_json_root; added a failing test for using rds_json_errcode_key and/or rds_json_errstr_key with real RDS streams from ngx_drizzle. --- src/ngx_http_rds_json_filter_module.c | 22 ++-- src/ngx_http_rds_json_handler.c | 8 +- t/property.t | 149 ++++++++++++++++++++++++++ t/ret.t | 102 ------------------ 4 files changed, 161 insertions(+), 120 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 1305615..9d5a399 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -427,11 +427,9 @@ ngx_http_rds_json_merge_conf(ngx_conf_t *cf, void *parent, void *child) ngx_conf_merge_uint_value(conf->format, prev->format, json_format_normal); - ngx_conf_merge_str_value(conf->root, prev->root, - ""); + ngx_conf_merge_str_value(conf->root, prev->root, ""); - ngx_conf_merge_str_value(conf->success, prev->success, - ""); + ngx_conf_merge_str_value(conf->success, prev->success, ""); if (conf->user_props == NULL) { conf->user_props = prev->user_props; @@ -442,16 +440,16 @@ ngx_http_rds_json_merge_conf(ngx_conf_t *cf, void *parent, void *child) } ngx_conf_merge_str_value(conf->errcode_key, prev->errcode_key, - "\"errcode\""); + "\"errcode\""); ngx_conf_merge_str_value(conf->errstr_key, prev->errstr_key, - "\"errstr\""); + "\"errstr\""); ngx_conf_merge_str_value(conf->content_type, prev->content_type, - ngx_http_rds_json_content_type); + ngx_http_rds_json_content_type); ngx_conf_merge_size_value(conf->buf_size, prev->buf_size, - (size_t) ngx_pagesize); + (size_t) ngx_pagesize); return NGX_CONF_OK; } @@ -717,7 +715,7 @@ ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, value = cf->args->elts; - if (jlcf->root.len) { + if (jlcf->errcode_key.len) { return "is duplicate"; } @@ -744,7 +742,7 @@ ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, } else { p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data, - value[1].len); + value[1].len); } *p++ = '"'; @@ -777,7 +775,7 @@ ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, } escape = ngx_http_rds_json_escape_json_str(NULL, value[1].data, - value[1].len); + value[1].len); jlcf->errstr_key.len = value[1].len + escape + sizeof("\"\"") - 1; @@ -795,7 +793,7 @@ ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, } else { p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data, - value[1].len); + value[1].len); } *p++ = '"'; diff --git a/src/ngx_http_rds_json_handler.c b/src/ngx_http_rds_json_handler.c index 722e880..d6c1203 100644 --- a/src/ngx_http_rds_json_handler.c +++ b/src/ngx_http_rds_json_handler.c @@ -35,22 +35,18 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) /* calculate the buffer size */ - len = sizeof("{") - 1 + len = sizeof("{:}") - 1 + conf->errcode_key.len - + sizeof(":") - 1 + conf->errcode.len - + sizeof("}") - 1 ; if (errstr.len) { escape = ngx_http_rds_json_escape_json_str(NULL, errstr.data, errstr.len); - len += sizeof(",") - 1 + len += sizeof(",:\"\"") - 1 + conf->errstr_key.len - + sizeof(":\"") - 1 + errstr.len + escape - + sizeof("\"") - 1 ; } diff --git a/t/property.t b/t/property.t index 843d218..af5b2be 100644 --- a/t/property.t +++ b/t/property.t @@ -387,3 +387,152 @@ GET /ret --- response_body chomp {"errcode":400,"errstr":"Non zero ret","city":"beijing","\"hi\"":"\"hello\n\""} + + +=== TEST 21: location internal rewrite +--- config + location @err403 { + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } + + location /foo { + error_page 403 = @err403; + return 403; + } +--- request + GET /foo +--- response_body chop +{"errcode":403,"errstr":"Forbidden","ret":false} + + + +=== TEST 22: rds_json_errcode_key +--- config + location /foo { + rds_json_errcode_key "ecode"; + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_body chop +{"ecode":403,"errstr":"Forbidden","ret":false} + + + +=== TEST 23: rds_json_errcode_key +--- config + rds_json_errcode_key "ecoderoot"; + + location /foo { + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_body chop +{"ecoderoot":403,"errstr":"Forbidden","ret":false} + + + +=== TEST 24: rds_json_errcode_key +--- config + rds_json_errcode_key "ecoderoot"; + + location /foo { + rds_json_errcode_key "ecode"; + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_body chop +{"ecode":403,"errstr":"Forbidden","ret":false} + + + +=== TEST 25: rds_json_errstr_key +--- config + rds_json_errstr_key "msg"; + + location /foo { + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_body chop +{"errcode":403,"msg":"Forbidden","ret":false} + + + +=== TEST 26: rds_json_errstr_key +--- config + rds_json_errstr_key "msg"; + + location /foo { + rds_json_errstr_key "msg2"; + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_body chop +{"errcode":403,"msg2":"Forbidden","ret":false} + + + +=== TEST 27: rds_json_errstr_key & rds_json_root +--- config + rds_json_errstr_key "msg2"; + rds_json_root rows; + + location /foo { + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_body chop +{"errcode":403,"msg2":"Forbidden","ret":false} + + + +=== TEST 28: rds_json_errcode_key & rds_json_root +--- config + rds_json_root rows; + rds_json_errcode_key "code"; + + location /foo { + rds_json_success_property ret; + rds_json_ret 403 "Forbidden"; + } +--- request + GET /foo +--- response_body chop +{"code":403,"errstr":"Forbidden","ret":false} + + + +=== TEST 29: update - custom errstr_key +--- http_config eval: $::http_config +--- config + location /mysql { + drizzle_pass backend; + #drizzle_dbname $dbname; + drizzle_query "update cats set name='bob' where name='bob'"; + rds_json on; + rds_json_errcode_key "\"code\""; + rds_json_errstr_key "\"str\""; + + set $name 'Jimmy"'; + set $age 32; + rds_json_user_property name $name; + rds_json_user_property age $age; + } +--- request +GET /mysql +--- response_body chop +{"name":"Jimmy\"","age":"32","\"code\"":0,"\"str\"":"Rows matched: 1 Changed: 0 Warnings: 0"} + diff --git a/t/ret.t b/t/ret.t index 5105e50..0d77b28 100644 --- a/t/ret.t +++ b/t/ret.t @@ -72,105 +72,3 @@ Content-Type: application/json --- response_body chop {"errcode":400,"errstr":"Invalid \"limit\" argument."} - - -=== TEST 5: location internal rewrite ---- config - location @err403 { - rds_json_success_property ret; - rds_json_ret 403 "Forbidden"; - } - - location /foo { - error_page 403 = @err403; - return 403; - } ---- request - GET /foo ---- response_headers -Content-Type: application/json ---- response_body chop -{"errcode":403,"errstr":"Forbidden","ret":false} - - - -=== TEST 6: rds_json_errcode_key ---- config - location /foo { - rds_json_errcode_key "ecode"; - rds_json_success_property ret; - rds_json_ret 403 "Forbidden"; - } ---- request - GET /foo ---- response_headers -Content-Type: application/json ---- response_body chop -{"ecode":403,"errstr":"Forbidden","ret":false} - - -=== TEST 7: rds_json_errcode_key ---- config - rds_json_errcode_key "ecoderoot"; - - location /foo { - rds_json_success_property ret; - rds_json_ret 403 "Forbidden"; - } ---- request - GET /foo ---- response_headers -Content-Type: application/json ---- response_body chop -{"ecoderoot":403,"errstr":"Forbidden","ret":false} - - -=== TEST 8: rds_json_errcode_key ---- config - rds_json_errcode_key "ecoderoot"; - - location /foo { - rds_json_errcode_key "ecode"; - rds_json_success_property ret; - rds_json_ret 403 "Forbidden"; - } ---- request - GET /foo ---- response_headers -Content-Type: application/json ---- response_body chop -{"ecode":403,"errstr":"Forbidden","ret":false} - - - -=== TEST 9: rds_json_errstr_key ---- config - rds_json_errstr_key "msg"; - - location /foo { - rds_json_success_property ret; - rds_json_ret 403 "Forbidden"; - } ---- request - GET /foo ---- response_headers -Content-Type: application/json ---- response_body chop -{"errcode":403,"msg":"Forbidden","ret":false} - - -=== TEST 10: rds_json_errstr_key ---- config - rds_json_errstr_key "msg"; - - location /foo { - rds_json_errstr_key "msg2"; - rds_json_success_property ret; - rds_json_ret 403 "Forbidden"; - } ---- request - GET /foo ---- response_headers -Content-Type: application/json ---- response_body chop -{"errcode":403,"msg2":"Forbidden","ret":false} From 8f303ee35d1f55707bfb436d9cc1924b45edad5e Mon Sep 17 00:00:00 2001 From: liseen Date: Tue, 22 May 2012 20:20:32 +0800 Subject: [PATCH 16/72] added errstr_key process for rds_json_output --- src/ngx_http_rds_json_handler.c | 12 +++-- src/ngx_http_rds_json_output.c | 84 +++++++++++++++++++-------------- t/property.t | 25 +++++++++- 3 files changed, 81 insertions(+), 40 deletions(-) diff --git a/src/ngx_http_rds_json_handler.c b/src/ngx_http_rds_json_handler.c index d6c1203..230f8c0 100644 --- a/src/ngx_http_rds_json_handler.c +++ b/src/ngx_http_rds_json_handler.c @@ -35,18 +35,24 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) /* calculate the buffer size */ - len = sizeof("{:}") - 1 + len = sizeof("{") - 1 + conf->errcode_key.len + + sizeof(":") - 1 + conf->errcode.len + + sizeof("}") - 1 ; if (errstr.len) { escape = ngx_http_rds_json_escape_json_str(NULL, errstr.data, errstr.len); - len += sizeof(",:\"\"") - 1 + len += sizeof(",") - 1 + conf->errstr_key.len - + errstr.len + escape + + sizeof(":") - 1 + + sizeof("\"") - 1 + + errstr.len + + escape + + sizeof("\"") - 1 ; } diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index 47e6914..d5e6392 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -137,10 +137,29 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, /* calculate the buffer size */ - size = sizeof("{\"errcode\":") - 1 - + ngx_get_num_size(header->std_errcode) - + sizeof("}") - 1 - ; + size = sizeof("{") - 1 + + conf->errcode_key.len + + sizeof(":") - 1 +- + ngx_get_num_size(header->std_errcode) + + sizeof("}") - 1 + ; + + if (header->errstr.len) { + escape = ngx_http_rds_json_escape_json_str(NULL, header->errstr.data, + header->errstr.len); + + size += sizeof(",") - 1 + + conf->errstr_key.len + + sizeof(":") - 1 + + sizeof("\"") - 1 + + header->errstr.len + + escape + + sizeof("\"") - 1 + ; + + } else { + escape = (uintptr_t) 0; + } if (conf->success.len) { size += conf->success.len + sizeof(":,") - 1; @@ -180,18 +199,6 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, } } - if (header->errstr.len) { - escape = ngx_http_rds_json_escape_json_str(NULL, header->errstr.data, - header->errstr.len); - - size += sizeof(",\"errstr\":\"") - 1 - + header->errstr.len + escape - + sizeof("\"") - 1 - ; - } else { - escape = (uintptr_t) 0; - } - if (header->insert_id) { size += sizeof(",\"insert_id\":") - 1 + ngx_get_num_size(header->insert_id) @@ -216,6 +223,31 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, /* fill up the buffer */ *last++ = '{'; + last = ngx_copy(last, conf->errcode_key.data, conf->errcode_key.len); + *last++ = ':'; + + last = ngx_snprintf(last, NGX_UINT16_LEN, "%uD", + (uint32_t) header->std_errcode); + + if (header->errstr.len) { + *last++ = ','; + last = ngx_copy(last, + conf->errstr_key.data, conf->errstr_key.len); + *last++ = ':'; + *last++ = '"'; + + if (escape == 0) { + last = ngx_copy(last, header->errstr.data, + header->errstr.len); + + } else { + last = (u_char *) ngx_http_rds_json_escape_json_str(last, + header->errstr.data, header->errstr.len); + } + + *last++ = '"'; + } + if (conf->success.len) { last = ngx_copy(last, conf->success.data, conf->success.len); @@ -247,26 +279,6 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, } } - last = ngx_copy_literal(last, "\"errcode\":"); - - last = ngx_snprintf(last, NGX_UINT16_LEN, "%uD", - (uint32_t) header->std_errcode); - - if (header->errstr.len) { - last = ngx_copy_literal(last, ",\"errstr\":\""); - - if (escape == 0) { - last = ngx_copy(last, header->errstr.data, - header->errstr.len); - - } else { - last = (u_char *) ngx_http_rds_json_escape_json_str(last, - header->errstr.data, header->errstr.len); - } - - *last++ = '"'; - } - if (header->insert_id) { last = ngx_copy_literal(last, ",\"insert_id\":"); last = ngx_snprintf(last, NGX_UINT64_LEN, "%uL", diff --git a/t/property.t b/t/property.t index af5b2be..3215e80 100644 --- a/t/property.t +++ b/t/property.t @@ -215,7 +215,7 @@ GET /mysql GET /mysql --- response_body chop {"success":true,"errcode":0,"errstr":"Rows matched: 1 Changed: 0 Warnings: 0"} - +--- ONLY === TEST 12: update (user property) @@ -536,3 +536,26 @@ GET /mysql --- response_body chop {"name":"Jimmy\"","age":"32","\"code\"":0,"\"str\"":"Rows matched: 1 Changed: 0 Warnings: 0"} + +=== TEST 30: select - custom errstr_key +--- http_config eval: $::http_config +--- config + location /mysql { + drizzle_pass backend; + drizzle_query "select 'aaa' as a, 'bbb' as b"; + rds_json on; + rds_json_errcode_key "\"code\""; + rds_json_errstr_key "\"str\""; + + rds_json_root data; + + set $name 'Jimmy"'; + set $age 32; + rds_json_user_property name $name; + rds_json_user_property age $age; + } +--- request +GET /mysql +--- response_body chop +{"name":"Jimmy\"","age":"32", "data": [ ] } + From d660cbf98cc671ecd2d9f07b40226aa8e9ddc63b Mon Sep 17 00:00:00 2001 From: liseen Date: Tue, 22 May 2012 21:05:47 +0800 Subject: [PATCH 17/72] fixed key index bug in rds_json's result --- src/ngx_http_rds_json_output.c | 87 +++++++++++++++++----------------- t/property.t | 6 +-- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index d5e6392..10fd040 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -140,27 +140,10 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, size = sizeof("{") - 1 + conf->errcode_key.len + sizeof(":") - 1 -- + ngx_get_num_size(header->std_errcode) + + ngx_get_num_size(header->std_errcode) + sizeof("}") - 1 ; - if (header->errstr.len) { - escape = ngx_http_rds_json_escape_json_str(NULL, header->errstr.data, - header->errstr.len); - - size += sizeof(",") - 1 - + conf->errstr_key.len - + sizeof(":") - 1 - + sizeof("\"") - 1 - + header->errstr.len - + escape - + sizeof("\"") - 1 - ; - - } else { - escape = (uintptr_t) 0; - } - if (conf->success.len) { size += conf->success.len + sizeof(":,") - 1; if (header->std_errcode == 0) { @@ -199,6 +182,24 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, } } + + if (header->errstr.len) { + escape = ngx_http_rds_json_escape_json_str(NULL, header->errstr.data, + header->errstr.len); + + size += sizeof(",") - 1 + + conf->errstr_key.len + + sizeof(":") - 1 + + sizeof("\"") - 1 + + header->errstr.len + + escape + + sizeof("\"") - 1 + ; + + } else { + escape = (uintptr_t) 0; + } + if (header->insert_id) { size += sizeof(",\"insert_id\":") - 1 + ngx_get_num_size(header->insert_id) @@ -223,31 +224,6 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, /* fill up the buffer */ *last++ = '{'; - last = ngx_copy(last, conf->errcode_key.data, conf->errcode_key.len); - *last++ = ':'; - - last = ngx_snprintf(last, NGX_UINT16_LEN, "%uD", - (uint32_t) header->std_errcode); - - if (header->errstr.len) { - *last++ = ','; - last = ngx_copy(last, - conf->errstr_key.data, conf->errstr_key.len); - *last++ = ':'; - *last++ = '"'; - - if (escape == 0) { - last = ngx_copy(last, header->errstr.data, - header->errstr.len); - - } else { - last = (u_char *) ngx_http_rds_json_escape_json_str(last, - header->errstr.data, header->errstr.len); - } - - *last++ = '"'; - } - if (conf->success.len) { last = ngx_copy(last, conf->success.data, conf->success.len); @@ -279,6 +255,31 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, } } + last = ngx_copy(last, conf->errcode_key.data, conf->errcode_key.len); + *last++ = ':'; + + last = ngx_snprintf(last, NGX_UINT16_LEN, "%uD", + (uint32_t) header->std_errcode); + + if (header->errstr.len) { + *last++ = ','; + last = ngx_copy(last, + conf->errstr_key.data, conf->errstr_key.len); + *last++ = ':'; + *last++ = '"'; + + if (escape == 0) { + last = ngx_copy(last, header->errstr.data, + header->errstr.len); + + } else { + last = (u_char *) ngx_http_rds_json_escape_json_str(last, + header->errstr.data, header->errstr.len); + } + + *last++ = '"'; + } + if (header->insert_id) { last = ngx_copy_literal(last, ",\"insert_id\":"); last = ngx_snprintf(last, NGX_UINT64_LEN, "%uL", diff --git a/t/property.t b/t/property.t index 3215e80..05f9fb0 100644 --- a/t/property.t +++ b/t/property.t @@ -215,7 +215,7 @@ GET /mysql GET /mysql --- response_body chop {"success":true,"errcode":0,"errstr":"Rows matched: 1 Changed: 0 Warnings: 0"} ---- ONLY + === TEST 12: update (user property) @@ -537,6 +537,7 @@ GET /mysql {"name":"Jimmy\"","age":"32","\"code\"":0,"\"str\"":"Rows matched: 1 Changed: 0 Warnings: 0"} + === TEST 30: select - custom errstr_key --- http_config eval: $::http_config --- config @@ -557,5 +558,4 @@ GET /mysql --- request GET /mysql --- response_body chop -{"name":"Jimmy\"","age":"32", "data": [ ] } - +{"name":"Jimmy\"","age":"32","data":[{"a":"aaa","b":"bbb"}]} From 483340faffc0d15897933a2c160a02100aef673d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Fri, 1 Jun 2012 15:41:28 +0800 Subject: [PATCH 18/72] now we prevent using (static) globals in the config-time code to prevent potential problems when HUP reload fails. --- src/ngx_http_rds_json_filter_module.c | 91 +++++++++++++++++---------- src/ngx_http_rds_json_filter_module.h | 9 ++- src/ngx_http_rds_json_handler.c | 2 +- src/ngx_http_rds_json_output.c | 10 +-- src/ngx_http_rds_json_output.h | 2 +- src/ngx_http_rds_json_processor.c | 4 +- t/unused.t | 68 ++++++++++++++++++++ 7 files changed, 142 insertions(+), 44 deletions(-) create mode 100644 t/unused.t diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 9d5a399..c746607 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -24,8 +24,6 @@ #define ngx_http_rds_json_errstr_default_key "\"errstr\"" -static unsigned ngx_http_rds_json_filter_used = 0; - static ngx_conf_enum_t ngx_http_rds_json_formats[] = { { ngx_string("normal"), json_format_normal }, { ngx_string("compact"), json_format_compact }, @@ -38,10 +36,11 @@ ngx_http_output_header_filter_pt ngx_http_rds_json_next_header_filter; ngx_http_output_body_filter_pt ngx_http_rds_json_next_body_filter; +static void * ngx_http_rds_json_create_main_conf(ngx_conf_t *cf); static char *ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static void *ngx_http_rds_json_create_conf(ngx_conf_t *cf); -static char *ngx_http_rds_json_merge_conf(ngx_conf_t *cf, void *parent, +static void *ngx_http_rds_json_create_loc_conf(ngx_conf_t *cf); +static char *ngx_http_rds_json_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); static ngx_int_t ngx_http_rds_json_filter_init(ngx_conf_t *cf); static char * ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, @@ -55,7 +54,6 @@ static char * ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, static char * ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char * ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static ngx_int_t ngx_http_rds_json_pre_config(ngx_conf_t *cf); static ngx_command_t ngx_http_rds_json_commands[] = { @@ -66,7 +64,7 @@ static ngx_command_t ngx_http_rds_json_commands[] = { |NGX_CONF_FLAG, ngx_http_rds_json, NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_rds_json_conf_t, enabled), + offsetof(ngx_http_rds_json_loc_conf_t, enabled), NULL }, { ngx_string("rds_json_root"), @@ -120,7 +118,7 @@ static ngx_command_t ngx_http_rds_json_commands[] = { |NGX_CONF_TAKE1, ngx_conf_set_enum_slot, NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_rds_json_conf_t, format), + offsetof(ngx_http_rds_json_loc_conf_t, format), &ngx_http_rds_json_formats }, { ngx_string("rds_json_content_type"), @@ -129,7 +127,7 @@ static ngx_command_t ngx_http_rds_json_commands[] = { |NGX_CONF_TAKE1, ngx_conf_set_str_slot, NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_rds_json_conf_t, content_type), + offsetof(ngx_http_rds_json_loc_conf_t, content_type), NULL }, { ngx_string("rds_json_ret"), @@ -144,7 +142,7 @@ static ngx_command_t ngx_http_rds_json_commands[] = { |NGX_CONF_TAKE1, ngx_conf_set_size_slot, NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_rds_json_conf_t, buf_size), + offsetof(ngx_http_rds_json_loc_conf_t, buf_size), NULL }, ngx_null_command @@ -152,17 +150,17 @@ static ngx_command_t ngx_http_rds_json_commands[] = { static ngx_http_module_t ngx_http_rds_json_filter_module_ctx = { - ngx_http_rds_json_pre_config, /* preconfiguration */ + NULL, /* preconfiguration */ ngx_http_rds_json_filter_init, /* postconfiguration */ - NULL, /* create main configuration */ + ngx_http_rds_json_create_main_conf, /* create main configuration */ NULL, /* init main configuration */ NULL, /* create server configuration */ NULL, /* merge server configuration */ - ngx_http_rds_json_create_conf, /* create location configuration */ - ngx_http_rds_json_merge_conf /* merge location configuration */ + ngx_http_rds_json_create_loc_conf, /* create location configuration */ + ngx_http_rds_json_merge_loc_conf /* merge location configuration */ }; @@ -185,12 +183,16 @@ ngx_module_t ngx_http_rds_json_filter_module = { static ngx_int_t ngx_http_rds_json_header_filter(ngx_http_request_t *r) { - ngx_http_rds_json_ctx_t *ctx; - ngx_http_rds_json_conf_t *conf; + ngx_http_rds_json_ctx_t *ctx; + ngx_http_rds_json_loc_conf_t *conf; + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json header filter, \"%V\"", &r->uri); /* XXX maybe we can generate stub JSON strings like * {"errcode":403,"error":"Permission denied"} * for HTTP error pages? */ + if ((r->headers_out.status < NGX_HTTP_OK) || (r->headers_out.status >= NGX_HTTP_SPECIAL_RESPONSE) || (r->headers_out.status == NGX_HTTP_NO_CONTENT) @@ -277,6 +279,9 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_http_rds_json_ctx_t *ctx; ngx_int_t rc; + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json body filter, \"%V\"", &r->uri); + if (in == NULL || r->header_only) { return ngx_http_rds_json_next_body_filter(r, in); } @@ -367,9 +372,14 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) static ngx_int_t ngx_http_rds_json_filter_init(ngx_conf_t *cf) { - dd("setting next filter"); + ngx_http_rds_json_main_conf_t *rmcf; - if (ngx_http_rds_json_filter_used) { + rmcf = ngx_http_conf_get_module_main_conf(cf, + ngx_http_rds_json_filter_module); + + dd("setting next filter: %d", (int) rmcf->requires_filters); + + if (rmcf->requires_filters) { dd("register filters"); ngx_http_rds_json_next_header_filter = ngx_http_top_header_filter; @@ -384,11 +394,11 @@ ngx_http_rds_json_filter_init(ngx_conf_t *cf) static void * -ngx_http_rds_json_create_conf(ngx_conf_t *cf) +ngx_http_rds_json_create_loc_conf(ngx_conf_t *cf) { - ngx_http_rds_json_conf_t *conf; + ngx_http_rds_json_loc_conf_t *conf; - conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rds_json_conf_t)); + conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rds_json_loc_conf_t)); if (conf == NULL) { return NULL; } @@ -418,10 +428,10 @@ ngx_http_rds_json_create_conf(ngx_conf_t *cf) static char * -ngx_http_rds_json_merge_conf(ngx_conf_t *cf, void *parent, void *child) +ngx_http_rds_json_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { - ngx_http_rds_json_conf_t *prev = parent; - ngx_http_rds_json_conf_t *conf = child; + ngx_http_rds_json_loc_conf_t *prev = parent; + ngx_http_rds_json_loc_conf_t *conf = child; ngx_conf_merge_value(conf->enabled, prev->enabled, 0); @@ -459,7 +469,7 @@ static char * ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_http_rds_json_conf_t *jlcf = conf; + ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_http_core_loc_conf_t *clcf; ngx_str_t *value; ngx_http_compile_complex_value_t ccv; @@ -528,7 +538,7 @@ static char * ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_http_rds_json_conf_t *jlcf = conf; + ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_str_t *value; uintptr_t escape; u_char *p; @@ -579,7 +589,7 @@ static char * ngx_http_rds_json_success_property(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_http_rds_json_conf_t *jlcf = conf; + ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_str_t *value; uintptr_t escape; u_char *p; @@ -630,7 +640,7 @@ static char * ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_http_rds_json_conf_t *jlcf = conf; + ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_str_t *value; ngx_http_rds_json_property_t *prop; uintptr_t escape; @@ -708,7 +718,7 @@ static char * ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_http_rds_json_conf_t *jlcf = conf; + ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_str_t *value; uintptr_t escape; u_char *p; @@ -759,7 +769,7 @@ static char * ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { - ngx_http_rds_json_conf_t *jlcf = conf; + ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_str_t *value; uintptr_t escape; u_char *p; @@ -809,20 +819,33 @@ ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, static char * ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { + ngx_http_rds_json_main_conf_t *rmcf; + + rmcf = ngx_http_conf_get_module_main_conf(cf, + ngx_http_rds_json_filter_module); + dd("set filter used to 1"); - ngx_http_rds_json_filter_used = 1; + rmcf->requires_filters = 1; return ngx_conf_set_flag_slot(cf, cmd, conf); } -static ngx_int_t ngx_http_rds_json_pre_config(ngx_conf_t *cf) +static void * +ngx_http_rds_json_create_main_conf(ngx_conf_t *cf) { - dd("set filter used to 0"); + ngx_http_rds_json_main_conf_t *rmcf; - ngx_http_rds_json_filter_used = 0; + rmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rds_json_main_conf_t)); + if (rmcf == NULL) { + return NULL; + } - return NGX_OK; + /* set by ngx_pcalloc: + * rmcf->requires_filters = 0; + */ + + return rmcf; } diff --git a/src/ngx_http_rds_json_filter_module.h b/src/ngx_http_rds_json_filter_module.h index ac4b859..18019b6 100644 --- a/src/ngx_http_rds_json_filter_module.h +++ b/src/ngx_http_rds_json_filter_module.h @@ -40,6 +40,12 @@ typedef struct { } ngx_http_rds_json_property_t; +typedef struct { + unsigned requires_filters; /* :1 */ + +} ngx_http_rds_json_main_conf_t; + + typedef struct { ngx_flag_t enabled; ngx_uint_t format; @@ -57,7 +63,8 @@ typedef struct { /* for rds_json_ret */ ngx_str_t errcode; ngx_http_complex_value_t *errstr; -} ngx_http_rds_json_conf_t; + +} ngx_http_rds_json_loc_conf_t; typedef enum { diff --git a/src/ngx_http_rds_json_handler.c b/src/ngx_http_rds_json_handler.c index 230f8c0..756e007 100644 --- a/src/ngx_http_rds_json_handler.c +++ b/src/ngx_http_rds_json_handler.c @@ -13,7 +13,6 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) ngx_chain_t *cl; ngx_buf_t *b; size_t len; - ngx_http_rds_json_conf_t *conf; ngx_str_t errstr; ngx_int_t rc; uintptr_t escape = 0; @@ -21,6 +20,7 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) uintptr_t *escapes = NULL; ngx_uint_t i; ngx_http_rds_json_property_t *prop = NULL; + ngx_http_rds_json_loc_conf_t *conf; dd("entered ret handler"); diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index 10fd040..88ee7df 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -131,7 +131,7 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, uintptr_t *escapes = NULL; ngx_http_rds_json_property_t *prop = NULL; - ngx_http_rds_json_conf_t *conf; + ngx_http_rds_json_loc_conf_t *conf; conf = ngx_http_get_module_loc_conf(r, ngx_http_rds_json_filter_module); @@ -314,7 +314,7 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_output_props(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_json_conf_t *conf) + ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_json_loc_conf_t *conf) { size_t size; u_char *pos, *last; @@ -480,7 +480,7 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, uintptr_t val_escape = 0; u_char *p; ngx_uint_t i; - ngx_http_rds_json_conf_t *conf; + ngx_http_rds_json_loc_conf_t *conf; ngx_uint_t format; conf = ngx_http_get_module_loc_conf(r, ngx_http_rds_json_filter_module); @@ -777,7 +777,7 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, uintptr_t escape = 0; u_char *p; ngx_uint_t i; - ngx_http_rds_json_conf_t *conf; + ngx_http_rds_json_loc_conf_t *conf; conf = ngx_http_get_module_loc_conf(r, ngx_http_rds_json_filter_module); @@ -942,7 +942,7 @@ static ngx_int_t ngx_http_rds_json_get_buf(ngx_http_request_t *r, ngx_http_rds_json_ctx_t *ctx) { - ngx_http_rds_json_conf_t *conf; + ngx_http_rds_json_loc_conf_t *conf; dd("MEM enter"); diff --git a/src/ngx_http_rds_json_output.h b/src/ngx_http_rds_json_output.h index d8d42e2..b56a29a 100644 --- a/src/ngx_http_rds_json_output.h +++ b/src/ngx_http_rds_json_output.h @@ -30,7 +30,7 @@ ngx_int_t ngx_http_rds_json_output_field(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len); ngx_int_t ngx_http_rds_json_output_props(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_json_conf_t *conf); + ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_json_loc_conf_t *conf); #endif /* NGX_HTTP_RDS_JSON_OUTPUT_H */ diff --git a/src/ngx_http_rds_json_processor.c b/src/ngx_http_rds_json_processor.c index 4c43eb7..0400afb 100644 --- a/src/ngx_http_rds_json_processor.c +++ b/src/ngx_http_rds_json_processor.c @@ -141,7 +141,7 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, { ngx_buf_t *b; ngx_int_t rc; - ngx_http_rds_json_conf_t *conf; + ngx_http_rds_json_loc_conf_t *conf; if (in == NULL) { return NGX_OK; @@ -244,7 +244,7 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_buf_t *b; ngx_int_t rc; - ngx_http_rds_json_conf_t *conf; + ngx_http_rds_json_loc_conf_t *conf; if (in == NULL) { return NGX_OK; diff --git a/t/unused.t b/t/unused.t new file mode 100644 index 0000000..871efd1 --- /dev/null +++ b/t/unused.t @@ -0,0 +1,68 @@ +# vi:filetype= + +use lib 'lib'; +use Test::Nginx::Socket; + +repeat_each(2); +#repeat_each(1); + +plan tests => repeat_each() * (5 * blocks()); + +log_level('debug'); + +no_long_string(); + +run_tests(); + +__DATA__ + +=== TEST 1: not using this module's directives at all +--- config + location /foo { + echo Hello; + } +--- request + GET /foo +--- response_headers +Content-Type: text/plain +--- response_body +Hello +--- no_error_log +rds json header filter, "/foo" +rds json body filter, "/foo" + + + +=== TEST 2: using rds_json_ret, but not rds_json +--- config + location /foo { + rds_json_ret 400 "Bad request"; + } +--- request + GET /foo +--- response_headers +Content-Type: application/json +--- response_body chop +{"errcode":400,"errstr":"Bad request"} +--- no_error_log +rds json header filter, "/foo" +rds json body filter, "/foo" + + + +=== TEST 3: using rds_json +--- config + location /foo { + echo Hello; + rds_json on; + } +--- request + GET /foo +--- response_headers +Content-Type: text/plain +--- response_body +Hello +--- error_log +rds json header filter, "/foo" +rds json body filter, "/foo" + From 00a013c3029feb3bc31cace25dd9d9a0c8605ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Fri, 1 Jun 2012 21:23:32 +0800 Subject: [PATCH 19/72] updated valgrind.suppress for the "hup reload" + valgrind/memcheck testing mode. --- valgrind.suppress | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/valgrind.suppress b/valgrind.suppress index 8a2e0e8..d94f166 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -272,19 +272,6 @@ fun:ngx_init_cycle fun:main } -{ - - Memcheck:Addr8 - fun:ngx_http_upstream_drizzle_send_query - fun:ngx_http_drizzle_process_events - fun:ngx_http_drizzle_wev_handler - fun:ngx_http_upstream_dbd_handler - fun:ngx_epoll_process_events - fun:ngx_process_events_and_timers - fun:ngx_single_process_cycle - fun:main -} - { Memcheck:Leak From 74c21b38b2737adc1b185c7e8173b2a14131aa77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Sat, 2 Jun 2012 10:35:03 +0800 Subject: [PATCH 20/72] updated valgrind.suppress further for linux i386. --- valgrind.suppress | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/valgrind.suppress b/valgrind.suppress index d94f166..d9ad1fd 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -1,3 +1,13 @@ +{ + +Memcheck:Param +socketcall.sendmsg(msg.msg_iov[i]) +fun:sendmsg +fun:ngx_write_channel +fun:ngx_signal_worker_processes +fun:ngx_master_process_cycle +fun:main +} { Memcheck:Param From 804371f2ee31289fdac3946146d4ee83e923d022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Thu, 21 Jun 2012 20:31:12 +0800 Subject: [PATCH 21/72] marked postgres test cases in 000-init.t. --- t/000_init.t | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/000_init.t b/t/000_init.t index e4a5d0f..e57b498 100644 --- a/t/000_init.t +++ b/t/000_init.t @@ -142,7 +142,7 @@ GET /init -=== TEST 8: cats - drop table +=== TEST 8: cats - drop table - pg --- http_config eval: $::http_config2 --- config location = /init { @@ -159,7 +159,7 @@ GET /init -=== TEST 9: cats - create table +=== TEST 9: cats - create table - pg --- http_config eval: $::http_config2 --- config location = /init { @@ -173,7 +173,7 @@ GET /init -=== TEST 10: cats - insert value +=== TEST 10: cats - insert value - pg --- http_config eval: $::http_config2 --- config location = /init { @@ -187,7 +187,7 @@ GET /init -=== TEST 11: cats - insert value +=== TEST 11: cats - insert value - pg --- http_config eval: $::http_config2 --- config location = /init { From fc02dd5f12d65dc7219b5d714078ffee7f67d446 Mon Sep 17 00:00:00 2001 From: "agentzh (Yichun Zhang)" Date: Mon, 17 Sep 2012 12:10:28 -0700 Subject: [PATCH 22/72] removed the sendmsg/ngx_channel valgrind suppression rules. --- .gitignore | 2 +- valgrind.suppress | 27 --------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index abb8e85..e01906f 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,6 @@ restart misc/ t/servroot/ all -build1[01] +build1[0-3] buildroot/ *.html diff --git a/valgrind.suppress b/valgrind.suppress index d9ad1fd..e8bff1b 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -1,20 +1,3 @@ -{ - -Memcheck:Param -socketcall.sendmsg(msg.msg_iov[i]) -fun:sendmsg -fun:ngx_write_channel -fun:ngx_signal_worker_processes -fun:ngx_master_process_cycle -fun:main -} -{ - - Memcheck:Param - socketcall.sendmsg(msg.msg_iov[i]) - fun:__sendmsg_nocancel - fun:ngx_write_channel -} { Memcheck:Leak @@ -124,16 +107,6 @@ fun:main fun:ngx_create_pool fun:main } -{ - sendmsg_uninit - Memcheck:Param - socketcall.sendmsg(msg.msg_iov[i]) - fun:__sendmsg_nocancel - fun:ngx_write_channel - fun:ngx_signal_worker_processes - fun:ngx_master_process_cycle - fun:main -} { spawn_process_alloc Memcheck:Leak From 66c31d7f9a9dc1c36c3453c83b6bfb57c9d2e6d9 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 19 Oct 2013 14:12:41 -0700 Subject: [PATCH 23/72] bugfix: in case of multiple http {} blocks in nginx.conf, our output filters might be disabled even when this module is configured properly. --- src/ngx_http_rds_json_filter_module.c | 16 ++++++++++++++-- t/unused.t | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index c746607..ca75a92 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -24,6 +24,9 @@ #define ngx_http_rds_json_errstr_default_key "\"errstr\"" +static volatile ngx_cycle_t *ngx_http_rds_json_prev_cycle = NULL; + + static ngx_conf_enum_t ngx_http_rds_json_formats[] = { { ngx_string("normal"), json_format_normal }, { ngx_string("compact"), json_format_compact }, @@ -372,14 +375,23 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) static ngx_int_t ngx_http_rds_json_filter_init(ngx_conf_t *cf) { - ngx_http_rds_json_main_conf_t *rmcf; + int multi_http_blocks; + ngx_http_rds_json_main_conf_t *rmcf; rmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_rds_json_filter_module); + if (ngx_http_rds_json_prev_cycle != ngx_cycle) { + ngx_http_rds_json_prev_cycle = ngx_cycle; + multi_http_blocks = 0; + + } else { + multi_http_blocks = 1; + } + dd("setting next filter: %d", (int) rmcf->requires_filters); - if (rmcf->requires_filters) { + if (multi_http_blocks || rmcf->requires_filters) { dd("register filters"); ngx_http_rds_json_next_header_filter = ngx_http_top_header_filter; diff --git a/t/unused.t b/t/unused.t index 871efd1..a5d2d07 100644 --- a/t/unused.t +++ b/t/unused.t @@ -66,3 +66,26 @@ Hello rds json header filter, "/foo" rds json body filter, "/foo" + + +=== TEST 4: multiple http {} blocks +--- config + location /foo { + echo Hello; + rds_json on; + } + +--- post_main_config + http { + } + +--- request + GET /foo +--- response_headers +Content-Type: text/plain +--- response_body +Hello +--- error_log +rds json header filter, "/foo" +rds json body filter, "/foo" + From fafb44bc3d1d97cfe45ef9b099b5c6c42df00677 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 19 Oct 2013 14:14:04 -0700 Subject: [PATCH 24/72] updated .gitignore to reflect recent changes. --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e01906f..8d4b393 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,9 @@ restart misc/ t/servroot/ all -build1[0-3] +build1[0-9] buildroot/ *.html +*.plist +Makefile +*.patch From bfd2c23071afece1c0ff5ef527e5a49fb4c37392 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 19 Oct 2013 14:15:05 -0700 Subject: [PATCH 25/72] avoided use of nginx master processes in the test suite. --- t/compact/openresty.t | 2 +- t/openresty.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t/compact/openresty.t b/t/compact/openresty.t index 64ab9ba..da8d2c1 100644 --- a/t/compact/openresty.t +++ b/t/compact/openresty.t @@ -8,7 +8,7 @@ repeat_each(2); worker_connections(128); workers(1); -master_on; +#master_on; log_level('warn'); plan tests => repeat_each() * 3 * blocks(); diff --git a/t/openresty.t b/t/openresty.t index 389eb43..b843a76 100644 --- a/t/openresty.t +++ b/t/openresty.t @@ -8,7 +8,7 @@ repeat_each(2); worker_connections(128); workers(1); -master_on; +#master_on; log_level('warn'); plan tests => repeat_each() * 3 * blocks(); From abd7433fc3add36867d0686e389b64e9631b764d Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 19 Oct 2013 14:49:59 -0700 Subject: [PATCH 26/72] massive coding style fixes. --- src/ngx_http_rds_json_filter_module.c | 92 ++++----- src/ngx_http_rds_json_output.c | 286 +++++++++++++------------- src/ngx_http_rds_json_output.h | 18 +- src/ngx_http_rds_json_processor.c | 102 ++++----- src/ngx_http_rds_json_util.c | 14 +- src/ngx_http_rds_json_util.h | 11 +- src/ngx_http_rds_utils.h | 66 +++--- 7 files changed, 303 insertions(+), 286 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index ca75a92..d4caea8 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -1,6 +1,6 @@ /* - * Copyright (C) agentzh + * Copyright (C) Yichun Zhang (agentzh) */ @@ -41,21 +41,21 @@ ngx_http_output_body_filter_pt ngx_http_rds_json_next_body_filter; static void * ngx_http_rds_json_create_main_conf(ngx_conf_t *cf); static char *ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static void *ngx_http_rds_json_create_loc_conf(ngx_conf_t *cf); static char *ngx_http_rds_json_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); static ngx_int_t ngx_http_rds_json_filter_init(ngx_conf_t *cf); static char * ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char * ngx_http_rds_json_success_property(ngx_conf_t *cf, - ngx_command_t *cmd, void *conf); + ngx_command_t *cmd, void *conf); static char * ngx_http_rds_json_user_property(ngx_conf_t *cf, - ngx_command_t *cmd, void *conf); + ngx_command_t *cmd, void *conf); static char * ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char * ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char * ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -204,8 +204,8 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) ngx_http_set_ctx(r, NULL, ngx_http_rds_json_filter_module); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json: skipped due to bad status: %ui", - r->headers_out.status); + "rds json: skipped due to bad status: %ui", + r->headers_out.status); return ngx_http_rds_json_next_header_filter(r); } @@ -216,16 +216,17 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) if (!conf->enabled) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json: skipped because not enabled in the current " - "location"); + "rds json: skipped because not enabled in the current " + "location"); return ngx_http_rds_json_next_header_filter(r); } if (ngx_http_rds_json_test_content_type(r) != NGX_OK) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json: skipped due to unmatched Content-Type response " - "header \"%V\"", &r->headers_out.content_type); + "rds json: skipped due to unmatched Content-Type " + "response header \"%V\"", + &r->headers_out.content_type); return ngx_http_rds_json_next_header_filter(r); } @@ -269,7 +270,7 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) r->filter_need_in_memory = 1; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json header filter postponed header sending"); + "rds json header filter postponed header sending"); /* we do postpone the header sending to the body filter */ return NGX_OK; @@ -296,7 +297,7 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json body filter postponed header sending"); + "rds json body filter postponed header sending"); switch (ctx->state) { case state_expect_header: @@ -322,7 +323,8 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) case state_done: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json body filter discarding unexpected trailing buffers"); + "rds json body filter discarding unexpected trailing " + "buffers"); /* mark the remaining bufs as consumed */ @@ -332,8 +334,8 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) default: ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: invalid internal state: %d", - ctx->state); + "rds_json: invalid internal state: %d", + ctx->state); rc = NGX_ERROR; @@ -345,7 +347,7 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) { ctx->state = state_done; - if (! ctx->header_sent) { + if (!ctx->header_sent) { ctx->header_sent = 1; if (rc == NGX_ERROR) { @@ -355,7 +357,7 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) r->headers_out.status = rc; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json body filter sending error page headers"); + "rds json body filter sending error page headers"); ngx_http_rds_json_next_header_filter(r); ngx_http_send_special(r, NGX_HTTP_LAST); @@ -478,8 +480,7 @@ ngx_http_rds_json_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) static char * -ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_http_core_loc_conf_t *clcf; @@ -494,7 +495,7 @@ ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, if (jlcf->errcode.len == 0) { ngx_log_error(NGX_LOG_ERR, cf->log, 0, - "rds_json: rds_json_ret: the errcode argument is empty"); + "rds_json: rds_json_ret: the errcode argument is empty"); return NGX_CONF_ERROR; } @@ -505,8 +506,8 @@ ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, if (c < '0' || c > '9') { ngx_log_error(NGX_LOG_ERR, cf->log, 0, - "rds_json: rds_json_ret: invalid errcode argument: " - "\"%V\"", &jlcf->errcode); + "rds_json: rds_json_ret: invalid errcode argument: " + "\"%V\"", &jlcf->errcode); return NGX_CONF_ERROR; } @@ -547,8 +548,7 @@ ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, static char * -ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_str_t *value; @@ -566,7 +566,7 @@ ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, } escape = ngx_http_rds_json_escape_json_str(NULL, value[1].data, - value[1].len); + value[1].len); jlcf->root.len = value[1].len + escape + sizeof("\"\"") - 1; @@ -584,7 +584,7 @@ ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, } else { p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data, - value[1].len); + value[1].len); } *p++ = '"'; @@ -599,7 +599,7 @@ ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, static char * ngx_http_rds_json_success_property(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) + void *conf) { ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_str_t *value; @@ -617,7 +617,7 @@ ngx_http_rds_json_success_property(ngx_conf_t *cf, ngx_command_t *cmd, } escape = ngx_http_rds_json_escape_json_str(NULL, value[1].data, - value[1].len); + value[1].len); jlcf->success.len = value[1].len + escape + sizeof("\"\"") - 1; @@ -635,7 +635,7 @@ ngx_http_rds_json_success_property(ngx_conf_t *cf, ngx_command_t *cmd, } else { p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data, - value[1].len); + value[1].len); } *p++ = '"'; @@ -650,15 +650,14 @@ ngx_http_rds_json_success_property(ngx_conf_t *cf, ngx_command_t *cmd, static char * ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) + void *conf) { - ngx_http_rds_json_loc_conf_t *jlcf = conf; + u_char *p; ngx_str_t *value; - ngx_http_rds_json_property_t *prop; uintptr_t escape; - u_char *p; - - ngx_http_compile_complex_value_t ccv; + ngx_http_rds_json_property_t *prop; + ngx_http_rds_json_loc_conf_t *jlcf = conf; + ngx_http_compile_complex_value_t ccv; value = cf->args->elts; @@ -672,7 +671,7 @@ ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, if (jlcf->user_props == NULL) { jlcf->user_props = ngx_array_create(cf->pool, 4, - sizeof(ngx_http_rds_json_property_t)); + sizeof(ngx_http_rds_json_property_t)); if (jlcf->user_props == NULL) { return NGX_CONF_ERROR; @@ -684,7 +683,7 @@ ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, /* process the user property key */ escape = ngx_http_rds_json_escape_json_str(NULL, value[1].data, - value[1].len); + value[1].len); prop->key.len = value[1].len + escape + sizeof("\"\"") - 1; @@ -702,7 +701,7 @@ ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, } else { p = (u_char *) ngx_http_rds_json_escape_json_str(p, value[1].data, - value[1].len); + value[1].len); } *p++ = '"'; @@ -727,13 +726,12 @@ ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, static char * -ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_rds_json_loc_conf_t *jlcf = conf; + u_char *p; ngx_str_t *value; uintptr_t escape; - u_char *p; value = cf->args->elts; @@ -746,7 +744,7 @@ ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, } escape = ngx_http_rds_json_escape_json_str(NULL, value[1].data, - value[1].len); + value[1].len); jlcf->errcode_key.len = value[1].len + escape + sizeof("\"\"") - 1; @@ -778,8 +776,7 @@ ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, static char * -ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_rds_json_loc_conf_t *jlcf = conf; ngx_str_t *value; @@ -860,4 +857,3 @@ ngx_http_rds_json_create_main_conf(ngx_conf_t *cf) return rmcf; } - diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index 88ee7df..456cc6c 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -9,6 +9,7 @@ #endif #include "ddebug.h" + #include "ngx_http_rds_json_filter_module.h" #include "ngx_http_rds_json_output.h" #include "ngx_http_rds_json_util.h" @@ -17,24 +18,21 @@ static u_char * ngx_http_rds_json_request_mem(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, size_t len); - + ngx_http_rds_json_ctx_t *ctx, size_t len); static ngx_int_t ngx_http_rds_json_get_buf(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx); - + ngx_http_rds_json_ctx_t *ctx); static u_char * ngx_http_rds_json_get_postponed(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, size_t len); - + ngx_http_rds_json_ctx_t *ctx, size_t len); static ngx_int_t ngx_http_rds_json_submit_mem(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, size_t len, unsigned last_buf); + ngx_http_rds_json_ctx_t *ctx, size_t len, unsigned last_buf); + static size_t ngx_get_num_size(uint64_t i); ngx_int_t ngx_http_rds_json_output_literal(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, - u_char *data, size_t len, ngx_flag_t last_buf) + ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len, int last_buf) { u_char *pos; @@ -61,7 +59,7 @@ ngx_http_rds_json_output_literal(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_output_bufs(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx) + ngx_http_rds_json_ctx_t *ctx) { ngx_int_t rc; ngx_chain_t *cl; @@ -104,10 +102,10 @@ ngx_http_rds_json_output_bufs(ngx_http_request_t *r, #if defined(nginx_version) && nginx_version >= 1001004 ngx_chain_update_chains(r->pool, &ctx->free_bufs, &ctx->busy_bufs, - &ctx->out, ctx->tag); + &ctx->out, ctx->tag); #else ngx_chain_update_chains(&ctx->free_bufs, &ctx->busy_bufs, &ctx->out, - ctx->tag); + ctx->tag); #endif ctx->last_out = &ctx->out; @@ -120,7 +118,7 @@ ngx_http_rds_json_output_bufs(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_output_header(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_header_t *header) + ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_header_t *header) { u_char *pos, *last; size_t size; @@ -138,11 +136,10 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, /* calculate the buffer size */ size = sizeof("{") - 1 - + conf->errcode_key.len - + sizeof(":") - 1 - + ngx_get_num_size(header->std_errcode) - + sizeof("}") - 1 - ; + + conf->errcode_key.len + + sizeof(":") - 1 + + ngx_get_num_size(header->std_errcode) + + sizeof("}") - 1; if (conf->success.len) { size += conf->success.len + sizeof(":,") - 1; @@ -156,15 +153,15 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, if (conf->user_props) { values = ngx_pnalloc(r->pool, - conf->user_props->nelts * (sizeof(ngx_str_t) + - sizeof(uintptr_t))); + conf->user_props->nelts * (sizeof(ngx_str_t) + + sizeof(uintptr_t))); if (values == NULL) { return NGX_ERROR; } - escapes = (uintptr_t *) ((u_char *) values + - conf->user_props->nelts * sizeof(ngx_str_t)); + escapes = (uintptr_t *) ((u_char *) values + + conf->user_props->nelts * sizeof(ngx_str_t)); prop = conf->user_props->elts; for (i = 0; i < conf->user_props->nelts; i++) { @@ -174,27 +171,27 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, return NGX_ERROR; } - escapes[i] = ngx_http_rds_json_escape_json_str(NULL, values[i].data, - values[i].len); + escapes[i] = ngx_http_rds_json_escape_json_str(NULL, + values[i].data, + values[i].len); size += sizeof(":\"\",") - 1 + prop[i].key.len + values[i].len - + escapes[i]; + + escapes[i]; } } if (header->errstr.len) { escape = ngx_http_rds_json_escape_json_str(NULL, header->errstr.data, - header->errstr.len); + header->errstr.len); size += sizeof(",") - 1 - + conf->errstr_key.len - + sizeof(":") - 1 - + sizeof("\"") - 1 - + header->errstr.len - + escape - + sizeof("\"") - 1 - ; + + conf->errstr_key.len + + sizeof(":") - 1 + + sizeof("\"") - 1 + + header->errstr.len + + escape + + sizeof("\"") - 1; } else { escape = (uintptr_t) 0; @@ -202,14 +199,12 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, if (header->insert_id) { size += sizeof(",\"insert_id\":") - 1 - + ngx_get_num_size(header->insert_id) - ; + + ngx_get_num_size(header->insert_id); } if (header->affected_rows) { size += sizeof(",\"affected_rows\":") - 1 - + ngx_get_num_size(header->affected_rows) - ; + + ngx_get_num_size(header->affected_rows); } /* create the buffer */ @@ -246,8 +241,10 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, last = ngx_copy(last, values[i].data, values[i].len); } else { - last = (u_char *) ngx_http_rds_json_escape_json_str(last, - values[i].data, values[i].len); + last = (u_char *) + ngx_http_rds_json_escape_json_str(last, + values[i].data, + values[i].len); } *last++ = '"'; @@ -259,22 +256,22 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, *last++ = ':'; last = ngx_snprintf(last, NGX_UINT16_LEN, "%uD", - (uint32_t) header->std_errcode); + (uint32_t) header->std_errcode); if (header->errstr.len) { *last++ = ','; - last = ngx_copy(last, - conf->errstr_key.data, conf->errstr_key.len); + last = ngx_copy(last, conf->errstr_key.data, conf->errstr_key.len); *last++ = ':'; *last++ = '"'; if (escape == 0) { - last = ngx_copy(last, header->errstr.data, - header->errstr.len); + last = ngx_copy(last, header->errstr.data, header->errstr.len); } else { - last = (u_char *) ngx_http_rds_json_escape_json_str(last, - header->errstr.data, header->errstr.len); + last = (u_char *) + ngx_http_rds_json_escape_json_str(last, + header->errstr.data, + header->errstr.len); } *last++ = '"'; @@ -282,22 +279,21 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, if (header->insert_id) { last = ngx_copy_literal(last, ",\"insert_id\":"); - last = ngx_snprintf(last, NGX_UINT64_LEN, "%uL", - header->insert_id); + last = ngx_snprintf(last, NGX_UINT64_LEN, "%uL", header->insert_id); } if (header->affected_rows) { last = ngx_copy_literal(last, ",\"affected_rows\":"); last = ngx_snprintf(last, NGX_UINT64_LEN, "%uL", - header->affected_rows); + header->affected_rows); } *last++ = '}'; if ((size_t) (last - pos) != size) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: output header buffer error: %O != %uz", - (off_t) (last - pos), size); + "rds_json: output header buffer error: %O != %uz", + (off_t) (last - pos), size); return NGX_ERROR; } @@ -314,7 +310,7 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_output_props(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_json_loc_conf_t *conf) + ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_json_loc_conf_t *conf) { size_t size; u_char *pos, *last; @@ -332,15 +328,15 @@ ngx_http_rds_json_output_props(ngx_http_request_t *r, if (conf->user_props) { values = ngx_pnalloc(r->pool, - conf->user_props->nelts * (sizeof(ngx_str_t) + - sizeof(uintptr_t))); + conf->user_props->nelts * (sizeof(ngx_str_t) + + sizeof(uintptr_t))); if (values == NULL) { return NGX_ERROR; } - escapes = (uintptr_t *) ((u_char *) values + - conf->user_props->nelts * sizeof(ngx_str_t)); + escapes = (uintptr_t *) ((u_char *) values + + conf->user_props->nelts * sizeof(ngx_str_t)); prop = conf->user_props->elts; for (i = 0; i < conf->user_props->nelts; i++) { @@ -350,11 +346,12 @@ ngx_http_rds_json_output_props(ngx_http_request_t *r, return NGX_ERROR; } - escapes[i] = ngx_http_rds_json_escape_json_str(NULL, values[i].data, - values[i].len); + escapes[i] = ngx_http_rds_json_escape_json_str(NULL, + values[i].data, + values[i].len); size += sizeof(":\"\",") - 1 + prop[i].key.len + values[i].len - + escapes[i]; + + escapes[i]; } } @@ -382,8 +379,10 @@ ngx_http_rds_json_output_props(ngx_http_request_t *r, last = ngx_copy(last, values[i].data, values[i].len); } else { - last = (u_char *) ngx_http_rds_json_escape_json_str(last, - values[i].data, values[i].len); + last = (u_char *) + ngx_http_rds_json_escape_json_str(last, + values[i].data, + values[i].len); } *last++ = '"'; @@ -396,8 +395,8 @@ ngx_http_rds_json_output_props(ngx_http_request_t *r, if (last - pos != (ssize_t) size) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: output props begin: buffer error: %O != %uz", - (off_t) (last - pos), size); + "rds_json: output props begin: buffer error: %O != %uz", + (off_t) (last - pos), size); return NGX_ERROR; } @@ -408,7 +407,7 @@ ngx_http_rds_json_output_props(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_output_cols(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx) + ngx_http_rds_json_ctx_t *ctx) { ngx_uint_t i; ngx_http_rds_column_t *col; @@ -420,14 +419,12 @@ ngx_http_rds_json_output_cols(ngx_http_request_t *r, for (i = 0; i < ctx->col_count; i++) { col = &ctx->cols[i]; - key_escape = ngx_http_rds_json_escape_json_str(NULL, - col->name.data, col->name.len); + key_escape = ngx_http_rds_json_escape_json_str(NULL, col->name.data, + col->name.len); dd("key_escape: %d", (int) key_escape); - size += col->name.len + key_escape - + sizeof("\"\"") - 1 - ; + size += col->name.len + key_escape + sizeof("\"\"") - 1; if (i != ctx->col_count - 1) { /* not the last column */ @@ -452,7 +449,8 @@ ngx_http_rds_json_output_cols(ngx_http_request_t *r, *last++ = '"'; last = (u_char *) ngx_http_rds_json_escape_json_str(last, - col->name.data, col->name.len); + col->name.data, + col->name.len); *last++ = '"'; @@ -469,8 +467,7 @@ ngx_http_rds_json_output_cols(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_output_field(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len, - ngx_flag_t is_null) + ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len, int is_null) { u_char *pos, *last; ngx_http_rds_column_t *col; @@ -488,8 +485,8 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, format = conf->format; dd("reading row %llu, col %d, len %d", - (unsigned long long) ctx->row, - (int) ctx->cur_col, (int) len); + (unsigned long long) ctx->row, + (int) ctx->cur_col, (int) len); /* calculate the buffer size */ @@ -499,9 +496,11 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, if (ctx->row == 1) { dd("first column, first row"); size = sizeof("{\"") - 1; + } else { size = sizeof(",{\"") - 1; } + } else { size = sizeof(",\"") - 1; } @@ -510,9 +509,11 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, if (ctx->cur_col == 0) { dd("first column"); size = sizeof(",[") - 1; + } else { size = sizeof(",") - 1; } + } else { return NGX_ERROR; } @@ -521,24 +522,23 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, if (format == json_format_normal) { key_escape = ngx_http_rds_json_escape_json_str(NULL, col->name.data, - col->name.len); + col->name.len); dd("key_escape: %d", (int) key_escape); - size += col->name.len + key_escape - + sizeof("\":") - 1 - ; + size += col->name.len + key_escape + sizeof("\":") - 1; } else if (format == json_format_compact) { /* do nothing */ + } else { return NGX_ERROR; } if (len == 0 && ctx->field_data_rest > 0) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: at least one octet should go with the field size " - "in one buf"); + "rds_json: at least one octet should go with the " + "field size in one buf"); return NGX_ERROR; } @@ -569,8 +569,8 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, if (*p < '0' || *p > '9') { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: invalid integral field value: \"%*s\"", - len, data); + "rds_json: invalid integral field value: " + "\"%*s\"", len, data); return NGX_ERROR; } } @@ -582,28 +582,31 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, dd("bool field found"); if (*data == '0' || *data == 'f' || *data == 'F' - || *data == '1' || *data == 't' || *data == 'T' ) + || *data == '1' || *data == 't' || *data == 'T' ) { if (len != 1 || ctx->field_data_rest) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: invalid boolean field value leading " - "by \"%*s\"", len, data); + "rds_json: invalid boolean field value " + "leading by \"%*s\"", len, data); return NGX_ERROR; } if (*data == '0' || *data == 'f' || *data == 'F') { bool_val = 0; size += sizeof("false") - 1; + } else { bool_val = 1; size += sizeof("true") - 1; } + } else { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: output field: invalid boolean value " - "leading by \"%*s\"", len, data); + "rds_json: output field: invalid boolean value " + "leading by \"%*s\"", len, data); return NGX_ERROR; } + break; default: @@ -613,9 +616,7 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, val_escape = ngx_http_rds_json_escape_json_str(NULL, data, len); - size += sizeof("\"") - 1 - + len + val_escape - ; + size += sizeof("\"") - 1 + len + val_escape; if (ctx->field_data_rest == 0) { size += sizeof("\"") - 1; @@ -624,7 +625,7 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, } if (ctx->field_data_rest == 0 - && ctx->cur_col == ctx->col_count - 1) + && ctx->cur_col == ctx->col_count - 1) { /* last column in the row */ if (format == json_format_normal) { @@ -632,6 +633,7 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, } else if (format == json_format_compact) { size += sizeof("]") - 1; + } else { return NGX_ERROR; } @@ -654,9 +656,11 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, if (ctx->row == 1) { dd("first column, first row"); *last++ = '{'; + } else { *last++ = ','; *last++ = '{'; } + } else { *last++ = ','; } @@ -667,16 +671,20 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, last = ngx_copy(last, col->name.data, col->name.len); } else { - last = (u_char *) ngx_http_rds_json_escape_json_str(last, - col->name.data, col->name.len); + last = (u_char *) + ngx_http_rds_json_escape_json_str(last, col->name.data, + col->name.len); } *last++ = '"'; *last++ = ':'; } else if (format == json_format_compact) { + if (ctx->cur_col == 0) { dd("first column"); - *last++ = ','; *last++ = '['; + *last++ = ','; + *last++ = '['; + } else { *last++ = ','; } @@ -692,6 +700,7 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, } else if (len == 0) { dd("copy emtpy string over"); last = ngx_copy_literal(last, "\"\""); + } else { switch (col->std_type & 0xc000) { case rds_rough_col_type_int: @@ -705,9 +714,11 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, case rds_rough_col_type_bool: if (bool_val) { last = ngx_copy_literal(last, "true"); + } else { last = ngx_copy_literal(last, "false"); } + break; default: @@ -716,22 +727,23 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, if (val_escape == 0) { last = ngx_copy(last, data, len); + } else { dd("field: string value escape non-zero: %d", - (int) val_escape); + (int) val_escape); #if DDEBUG p = last; #endif - last = (u_char *) ngx_http_rds_json_escape_json_str(last, - data, len); + last = (u_char *) + ngx_http_rds_json_escape_json_str(last, data, len); dd("escaped value \"%.*s\" (len %d, escape %d, escape2 %d)", - (int) (len + val_escape), - p, (int) (len + val_escape), - (int) val_escape, - (int) ((last - p) - len)); + (int) (len + val_escape), + p, (int) (len + val_escape), + (int) val_escape, + (int) ((last - p) - len)); } if (ctx->field_data_rest == 0) { @@ -742,14 +754,14 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, } } - if (ctx->field_data_rest == 0 - && ctx->cur_col == ctx->col_count - 1) - { + if (ctx->field_data_rest == 0 && ctx->cur_col == ctx->col_count - 1) { dd("last column in the row"); if (format == json_format_normal) { *last++ = '}'; + } else if (format == json_format_compact) { *last++ = ']'; + } else { return NGX_ERROR; } @@ -757,8 +769,8 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, if ((size_t) (last - pos) != size) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: output field: buffer error (%d left)", - (int) size - (last - pos)); + "rds_json: output field: buffer error (%d left)", + (int) size - (last - pos)); return NGX_ERROR; } @@ -769,7 +781,7 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len) + ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len) { u_char *pos, *last; size_t size = 0; @@ -790,8 +802,8 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, for (p = data, i = 0; i < len; i++, p++) { if (*p < '0' || *p > '9') { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: invalid integral field value: \"%*s\"", - len, data); + "rds_json: invalid integral field value: \"%*s\"", + len, data); return NGX_ERROR; } } @@ -819,14 +831,14 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, break; } - if (ctx->field_data_rest == 0 - && ctx->cur_col == ctx->col_count - 1) - { + if (ctx->field_data_rest == 0 && ctx->cur_col == ctx->col_count - 1) { /* last column in the row */ if (conf->format == json_format_normal) { size += sizeof("}") - 1; + } else if (conf->format == json_format_compact) { size += sizeof("]") - 1; + } else { return NGX_ERROR; } @@ -860,7 +872,7 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, } else { dd("more field data: string value escape non-zero: %d", - (int) escape); + (int) escape); #if DDEBUG p = last; @@ -870,11 +882,10 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, data, len); dd("escaped value \"%.*s\" (len %d, escape %d, escape2 %d)", - (int) (len + escape), - p, (int) (len + escape), - (int) escape, - (int) ((last - p) - len)); - + (int) (len + escape), + p, (int) (len + escape), + (int) escape, + (int) ((last - p) - len)); } if (ctx->field_data_rest == 0) { @@ -884,14 +895,14 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, break; } /* switch */ - if (ctx->field_data_rest == 0 && - ctx->cur_col == ctx->col_count - 1) - { + if (ctx->field_data_rest == 0 && ctx->cur_col == ctx->col_count - 1) { /* last column in the row */ if (conf->format == json_format_normal) { *last++ = '}'; + } else if (conf->format == json_format_compact) { *last++ = ']'; + } else { return NGX_ERROR; } @@ -899,9 +910,8 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, if ((size_t) (last - pos) != size) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: output more field data: buffer error " - "(%d left)", (int) (size - (last - pos))); - + "rds_json: output more field data: buffer error " + "(%d left)", (int) (size - (last - pos))); return NGX_ERROR; } @@ -911,7 +921,7 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, static u_char * ngx_http_rds_json_request_mem(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, size_t len) + ngx_http_rds_json_ctx_t *ctx, size_t len) { ngx_int_t rc; u_char *p; @@ -940,7 +950,7 @@ ngx_http_rds_json_request_mem(ngx_http_request_t *r, static ngx_int_t ngx_http_rds_json_get_buf(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx) + ngx_http_rds_json_ctx_t *ctx) { ngx_http_rds_json_loc_conf_t *conf; @@ -960,8 +970,7 @@ ngx_http_rds_json_get_buf(ngx_http_request_t *r, } else { dd("MEM creating temp buf with size: %d", (int) conf->buf_size); - ctx->out_buf = ngx_create_temp_buf(r->pool, - conf->buf_size); + ctx->out_buf = ngx_create_temp_buf(r->pool, conf->buf_size); if (ctx->out_buf == NULL) { return NGX_ERROR; @@ -979,7 +988,7 @@ ngx_http_rds_json_get_buf(ngx_http_request_t *r, static u_char * ngx_http_rds_json_get_postponed(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, size_t len) + ngx_http_rds_json_ctx_t *ctx, size_t len) { u_char *p; @@ -997,21 +1006,21 @@ ngx_http_rds_json_get_postponed(ngx_http_request_t *r, return ctx->cached.start; alloc: - p = ngx_palloc(r->pool, len); - if (p == NULL) { - return NULL; - } + p = ngx_palloc(r->pool, len); + if (p == NULL) { + return NULL; + } - ctx->cached.start = p; - ctx->cached.end = p + len; + ctx->cached.start = p; + ctx->cached.end = p + len; - return p; + return p; } static ngx_int_t ngx_http_rds_json_submit_mem(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, size_t len, unsigned last_buf) + ngx_http_rds_json_ctx_t *ctx, size_t len, unsigned last_buf) { ngx_chain_t *cl; ngx_int_t rc; @@ -1026,7 +1035,7 @@ ngx_http_rds_json_submit_mem(ngx_http_request_t *r, } ctx->out_buf->last = ngx_copy(ctx->out_buf->last, - ctx->postponed.pos, len); + ctx->postponed.pos, len); ctx->avail_out -= len; @@ -1102,4 +1111,3 @@ ngx_get_num_size(uint64_t i) return n; } - diff --git a/src/ngx_http_rds_json_output.h b/src/ngx_http_rds_json_output.h index b56a29a..6575f92 100644 --- a/src/ngx_http_rds_json_output.h +++ b/src/ngx_http_rds_json_output.h @@ -3,6 +3,7 @@ * Copyright (C) agentzh */ + #ifndef NGX_HTTP_RDS_JSON_OUTPUT_H #define NGX_HTTP_RDS_JSON_OUTPUT_H @@ -16,22 +17,19 @@ ngx_int_t ngx_http_rds_json_output_header(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_header_t *header); + ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_header_t *header); ngx_int_t ngx_http_rds_json_output_cols(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx); + ngx_http_rds_json_ctx_t *ctx); ngx_int_t ngx_http_rds_json_output_literal(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len, - ngx_flag_t last_buf); + ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len, int last_buf); ngx_int_t ngx_http_rds_json_output_bufs(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx); + ngx_http_rds_json_ctx_t *ctx); ngx_int_t ngx_http_rds_json_output_field(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len, - ngx_flag_t is_null); + ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len, int is_null); ngx_int_t ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len); + ngx_http_rds_json_ctx_t *ctx, u_char *data, size_t len); ngx_int_t ngx_http_rds_json_output_props(ngx_http_request_t *r, - ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_json_loc_conf_t *conf); + ngx_http_rds_json_ctx_t *ctx, ngx_http_rds_json_loc_conf_t *conf); #endif /* NGX_HTTP_RDS_JSON_OUTPUT_H */ - diff --git a/src/ngx_http_rds_json_processor.c b/src/ngx_http_rds_json_processor.c index 0400afb..eb2bfc1 100644 --- a/src/ngx_http_rds_json_processor.c +++ b/src/ngx_http_rds_json_processor.c @@ -1,3 +1,4 @@ + /* * Copyright (C) agentzh */ @@ -8,6 +9,7 @@ #endif #include "ddebug.h" + #include "ngx_http_rds_json_util.h" #include "ngx_http_rds_json_processor.h" #include "ngx_http_rds_json_output.h" @@ -17,9 +19,10 @@ #include #include + ngx_int_t ngx_http_rds_json_process_header(ngx_http_request_t *r, - ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx) + ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx) { ngx_buf_t *b; ngx_http_rds_header_t header; @@ -31,11 +34,11 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, b = in->buf; - if ( ! ngx_buf_in_memory(b) ) { - if ( ! ngx_buf_special(b) ) { + if (!ngx_buf_in_memory(b)) { + if (!ngx_buf_special(b)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: process header: buf from " - "upstream not in memory"); + "rds_json: process header: buf from " + "upstream not in memory"); goto invalid; } @@ -64,16 +67,15 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, if (b->pos != b->last) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: header: there's unexpected remaining data " - "in the buf"); - + "rds_json: header: there's unexpected remaining data " + "in the buf"); goto invalid; } ctx->state = state_done; /* now we send the postponed response header */ - if (! ctx->header_sent) { + if (!ctx->header_sent) { ctx->header_sent = 1; rc = ngx_http_rds_json_next_header_filter(r); @@ -95,7 +97,7 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, } ctx->cols = ngx_palloc(r->pool, - header.col_count * sizeof(ngx_http_rds_column_t)); + header.col_count * sizeof(ngx_http_rds_column_t)); if (ctx->cols == NULL) { goto invalid; @@ -106,7 +108,7 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, ctx->col_count = header.col_count; /* now we send the postponed response header */ - if (! ctx->header_sent) { + if (!ctx->header_sent) { ctx->header_sent = 1; rc = ngx_http_rds_json_next_header_filter(r); @@ -115,13 +117,13 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, } } - return ngx_http_rds_json_process_col(r, - b->pos == b->last ? in->next : in, ctx); + return ngx_http_rds_json_process_col(r, b->pos == b->last ? in->next : in, + ctx); invalid: dd("return 500"); - if (! ctx->header_sent) { + if (!ctx->header_sent) { ctx->header_sent = 1; r->headers_out.status = NGX_HTTP_INTERNAL_SERVER_ERROR; @@ -136,8 +138,8 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, ngx_int_t -ngx_http_rds_json_process_col(ngx_http_request_t *r, - ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx) +ngx_http_rds_json_process_col(ngx_http_request_t *r, ngx_chain_t *in, + ngx_http_rds_json_ctx_t *ctx) { ngx_buf_t *b; ngx_int_t rc; @@ -149,11 +151,11 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, b = in->buf; - if ( ! ngx_buf_in_memory(b) ) { - if ( ! ngx_buf_special(b) ) { + if (!ngx_buf_in_memory(b) ) { + if (!ngx_buf_special(b) ) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: process col: buf from " - "upstream not in memory"); + "rds_json: process col: buf from " + "upstream not in memory"); return NGX_ERROR; } @@ -190,7 +192,6 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, ctx->row = 0; dd("output \"[\""); - dd("before output literal"); conf = ngx_http_get_module_loc_conf(r, ngx_http_rds_json_filter_module); @@ -206,7 +207,8 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, } rc = ngx_http_rds_json_output_literal(r, ctx, - (u_char *)"[", sizeof("[") - 1, 0 /* last buf */); + (u_char *)"[", sizeof("[") - 1, + 0 /* last buf */); dd("after output literal"); @@ -228,7 +230,6 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, return rc; } - dd("process col is entering process row..."); return ngx_http_rds_json_process_row(r, in, ctx); } @@ -238,8 +239,8 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, ngx_int_t -ngx_http_rds_json_process_row(ngx_http_request_t *r, - ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx) +ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in, + ngx_http_rds_json_ctx_t *ctx) { ngx_buf_t *b; ngx_int_t rc; @@ -254,11 +255,11 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, b = in->buf; - if ( ! ngx_buf_in_memory(b) ) { - if ( ! ngx_buf_special(b) ) { + if (!ngx_buf_in_memory(b) ) { + if (!ngx_buf_special(b) ) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: process row: buf from " - "upstream not in memory"); + "rds_json: process row: buf from " + "upstream not in memory"); return NGX_ERROR; } @@ -273,7 +274,7 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, if (b->last - b->pos < (ssize_t) sizeof(uint8_t)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: row flag is incomplete in the buf"); + "rds_json: row flag is incomplete in the buf"); return NGX_ERROR; } @@ -287,8 +288,8 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, if (b->pos != b->last) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: row: there's unexpected remaining data " - "in the buf"); + "rds_json: row: there's unexpected remaining data " + "in the buf"); return NGX_ERROR; } @@ -296,11 +297,15 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, if (conf->root.len) { rc = ngx_http_rds_json_output_literal(r, ctx, - (u_char *)"]}", sizeof("]}") - 1, 1 /* last buf*/); + (u_char *)"]}", + sizeof("]}") - 1, + 1 /* last buf*/); } else { rc = ngx_http_rds_json_output_literal(r, ctx, - (u_char *)"]", sizeof("]") - 1, 1 /* last buf*/); + (u_char *)"]", + sizeof("]") - 1, + 1 /* last buf*/); } if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) { @@ -326,8 +331,8 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_int_t -ngx_http_rds_json_process_field(ngx_http_request_t *r, - ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx) +ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in, + ngx_http_rds_json_ctx_t *ctx) { size_t total, len; ngx_buf_t *b; @@ -340,13 +345,13 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, b = in->buf; - if ( ! ngx_buf_in_memory(b) ) { + if (!ngx_buf_in_memory(b) ) { dd("buf not in memory"); - if ( ! ngx_buf_special(b) ) { + if (!ngx_buf_special(b) ) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: process field: buf from " - "upstream not in memory"); + "rds_json: process field: buf from " + "upstream not in memory"); return NGX_ERROR; } @@ -363,9 +368,9 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, if (b->last - b->pos < (ssize_t) sizeof(uint32_t)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: field size is incomplete in the buf: %*s " - "(len: %d)", b->last - b->pos, b->pos, - (int) (b->last - b->pos)); + "rds_json: field size is incomplete in the buf: %*s " + "(len: %d)", b->last - b->pos, b->pos, + (int) (b->last - b->pos)); return NGX_ERROR; } @@ -383,7 +388,7 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ctx->field_data_rest = 0; rc = ngx_http_rds_json_output_field(r, ctx, b->pos, len, - 1 /* is null */); + 1 /* is null */); } else { len = (uint32_t) (b->last - b->pos); @@ -395,7 +400,7 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ctx->field_data_rest = total - len; rc = ngx_http_rds_json_output_field(r, ctx, b->pos, len, - 0 /* not null */); + 0 /* not null */); } if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) { @@ -437,7 +442,7 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_int_t ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, - ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx) + ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx) { ngx_int_t rc; ngx_buf_t *b; @@ -450,9 +455,9 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, b = in->buf; - if ( ! ngx_buf_in_memory(b)) { + if (!ngx_buf_in_memory(b)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: buf from upstream not in memory"); + "rds_json: buf from upstream not in memory"); return NGX_ERROR; } @@ -506,4 +511,3 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, return NGX_ERROR; } - diff --git a/src/ngx_http_rds_json_util.c b/src/ngx_http_rds_json_util.c index 60148fd..8a7616b 100644 --- a/src/ngx_http_rds_json_util.c +++ b/src/ngx_http_rds_json_util.c @@ -1,8 +1,15 @@ + +/* + * Copyright (C) Yichun Zhang (agentzh) + */ + + #ifndef DDEBUG #define DDEBUG 0 #endif #include "ddebug.h" + #include "resty_dbd_stream.h" #include "ngx_http_rds_json_util.h" @@ -119,9 +126,9 @@ ngx_http_rds_json_test_content_type(ngx_http_request_t *r) ngx_str_t *type; type = &r->headers_out.content_type; - if (type->len != rds_content_type_len || - ngx_strncmp(type->data, rds_content_type, - rds_content_type_len) != 0) + if (type->len != rds_content_type_len + || ngx_strncmp(type->data, rds_content_type, rds_content_type_len) + != 0) { return NGX_DECLINED; } @@ -146,4 +153,3 @@ ngx_http_rds_json_discard_bufs(ngx_pool_t *pool, ngx_chain_t *in) cl->buf->pos = cl->buf->last; } } - diff --git a/src/ngx_http_rds_json_util.h b/src/ngx_http_rds_json_util.h index 6530c8c..bce303c 100644 --- a/src/ngx_http_rds_json_util.h +++ b/src/ngx_http_rds_json_util.h @@ -1,6 +1,13 @@ + +/* + * Copyright (C) Yichun Zhang (agentzh) + */ + + #ifndef NGX_HTTP_RDS_JSON_UTIL_H #define NGX_HTTP_RDS_JSON_UTIL_H + #include #include #include @@ -20,9 +27,8 @@ #endif - uintptr_t ngx_http_rds_json_escape_json_str(u_char *dst, u_char *src, - size_t size); + size_t size); ngx_int_t ngx_http_rds_json_test_content_type(ngx_http_request_t *r); @@ -30,4 +36,3 @@ void ngx_http_rds_json_discard_bufs(ngx_pool_t *pool, ngx_chain_t *in); #endif /* NGX_HTTP_RDS_JSON_UTIL_H */ - diff --git a/src/ngx_http_rds_utils.h b/src/ngx_http_rds_utils.h index 67e6f79..25d44d2 100644 --- a/src/ngx_http_rds_utils.h +++ b/src/ngx_http_rds_utils.h @@ -3,39 +3,40 @@ * Copyright (C) agentzh */ + #ifndef NGX_HTTP_RDS_UTILS_H #define NGX_HTTP_RDS_UTILS_H static ngx_inline ngx_int_t ngx_http_rds_parse_header(ngx_http_request_t *r, ngx_buf_t *b, - ngx_http_rds_header_t *header) + ngx_http_rds_header_t *header) { ssize_t rest; - rest = sizeof(uint8_t) /* endian type */ - + sizeof(uint32_t) /* format version */ - + sizeof(uint8_t) /* result type */ + rest = sizeof(uint8_t) /* endian type */ + + sizeof(uint32_t) /* format version */ + + sizeof(uint8_t) /* result type */ - + sizeof(uint16_t) /* standard error code */ - + sizeof(uint16_t) /* driver-specific error code */ + + sizeof(uint16_t) /* standard error code */ + + sizeof(uint16_t) /* driver-specific error code */ - + sizeof(uint16_t) /* driver-specific errstr len */ - + 0 /* driver-specific errstr data */ - + sizeof(uint64_t) /* affected rows */ - + sizeof(uint64_t) /* insert id */ - + sizeof(uint16_t) /* column count */ - ; + + sizeof(uint16_t) /* driver-specific errstr len */ + + 0 /* driver-specific errstr data */ + + sizeof(uint64_t) /* affected rows */ + + sizeof(uint64_t) /* insert id */ + + sizeof(uint16_t) /* column count */ + ; if (b->last - b->pos < rest) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds: header is incomplete in the buf"); + "rds: header is incomplete in the buf"); return NGX_ERROR; } /* check endian type */ - if ( *(uint8_t *) b->pos != + if (*(uint8_t *) b->pos != #if (NGX_HAVE_LITTLE_ENDIAN) 0 #else /* big endian */ @@ -44,7 +45,7 @@ ngx_http_rds_parse_header(ngx_http_request_t *r, ngx_buf_t *b, ) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds: endian type in the header differ"); + "rds: endian type in the header differ"); return NGX_ERROR; } @@ -52,9 +53,9 @@ ngx_http_rds_parse_header(ngx_http_request_t *r, ngx_buf_t *b, /* check RDS format version number */ - if ( *(uint32_t *) b->pos != (uint32_t) resty_dbd_stream_version) { + if (*(uint32_t *) b->pos != (uint32_t) resty_dbd_stream_version) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds: RDS format version differ"); + "rds: RDS format version differ"); return NGX_ERROR; } @@ -66,7 +67,7 @@ ngx_http_rds_parse_header(ngx_http_request_t *r, ngx_buf_t *b, if (*b->pos != 0) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds: RDS result type must be 0 for now"); + "rds: RDS result type must be 0 for now"); return NGX_ERROR; } @@ -95,14 +96,14 @@ ngx_http_rds_parse_header(ngx_http_request_t *r, ngx_buf_t *b, /* check the rest data's size */ rest = header->errstr.len - + sizeof(uint64_t) /* affected rows */ - + sizeof(uint64_t) /* insert id */ - + sizeof(uint16_t) /* column count */ - ; + + sizeof(uint64_t) /* affected rows */ + + sizeof(uint64_t) /* insert id */ + + sizeof(uint16_t) /* column count */ + ; if (b->last - b->pos < rest) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds: header is incomplete in the buf"); + "rds: header is incomplete in the buf"); return NGX_ERROR; } @@ -138,18 +139,18 @@ ngx_http_rds_parse_header(ngx_http_request_t *r, ngx_buf_t *b, static ngx_inline ngx_int_t ngx_http_rds_parse_col(ngx_http_request_t *r, ngx_buf_t *b, - ngx_http_rds_column_t *col) + ngx_http_rds_column_t *col) { ssize_t rest; rest = sizeof(uint16_t) /* std col type */ - + sizeof(uint16_t) /* driver col type */ - + sizeof(uint16_t) /* col name str len */ - ; + + sizeof(uint16_t) /* driver col type */ + + sizeof(uint16_t) /* col name str len */ + ; if (b->last - b->pos < rest) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds: column spec is incomplete in the buf"); + "rds: column spec is incomplete in the buf"); return NGX_ERROR; } @@ -168,7 +169,7 @@ ngx_http_rds_parse_col(ngx_http_request_t *r, ngx_buf_t *b, if (col->name.len == 0) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: column name empty"); + "rds_json: column name empty"); return NGX_ERROR; } @@ -176,7 +177,7 @@ ngx_http_rds_parse_col(ngx_http_request_t *r, ngx_buf_t *b, if (b->last - b->pos < rest) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds: column name string is incomplete in the buf"); + "rds: column name string is incomplete in the buf"); return NGX_ERROR; } @@ -191,12 +192,11 @@ ngx_http_rds_parse_col(ngx_http_request_t *r, ngx_buf_t *b, b->pos += col->name.len; dd("saved column name \"%.*s\" (len %d, offset %d)", - (int) col->name.len, col->name.data, - (int) col->name.len, (int) (b->pos - b->start)); + (int) col->name.len, col->name.data, + (int) col->name.len, (int) (b->pos - b->start)); return NGX_OK; } #endif /* NGX_HTTP_RDS_UTILS_H */ - From bfeac07cddda8162fce2fe138a5c899c671469fd Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 19 Oct 2013 14:51:17 -0700 Subject: [PATCH 27/72] bugix: we did not check the NULL pointer returned by an array element allocation. --- src/ngx_http_rds_json_filter_module.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index d4caea8..6290c0f 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -679,6 +679,9 @@ ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, } prop = ngx_array_push(jlcf->user_props); + if (prop == NULL) { + return NGX_CONF_ERROR; + } /* process the user property key */ From b6caee58d3c349ce2e0383c83e9bcfe5d89d7377 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sun, 27 Oct 2013 22:05:57 -0700 Subject: [PATCH 28/72] updated docs to reflect recent changes. --- README | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README b/README index ece327e..2006dbf 100644 --- a/README +++ b/README @@ -152,12 +152,12 @@ Directives Installation Grab the nginx source code from nginx.net (), for - example, the version 1.0.9 (see nginx compatibility), and then build + example, the version 1.4.3 (see nginx compatibility), and then build the source with this module: - wget 'http://sysoev.ru/nginx/nginx-1.0.9.tar.gz' - tar -xzvf nginx-1.0.9.tar.gz - cd nginx-1.0.9/ + wget 'http://nginx.org/download/nginx-1.4.3.tar.gz' + tar -xzvf nginx-1.4.3.tar.gz + cd nginx-1.4.3/ # Here we assume you would install you nginx under /opt/nginx/. ./configure --prefix=/opt/nginx \ @@ -174,6 +174,10 @@ Installation Compatibility The following versions of Nginx should work with this module: + * 1.4.x (last tested: 1.4.3) + + * 1.2.x (last tested: 1.2.9) + * 1.1.x (last tested: 1.1.5) * 1.0.x (last tested: 1.0.9) @@ -200,14 +204,12 @@ See Also * ngx_postgres ( http://github.com/FRiCKLE/ngx_postgres/ ) Author - Zhang "agentzh" Yichun (章亦春) + Yichun "agentzh" Zhang (章亦春) , CloudFlare Inc. Copyright & License This module is licenced under the BSD license. - Copyright (c) 2009, 2010, 2011, Taobao Inc., Alibaba Group ( http://www.taobao.com ). - - Copyright (C) 2009, 2010, 2011, Zhang "agentzh" Yichun (章亦春) . + Copyright (C) 2009-2013, Yichun Zhang (agentzh) , CloudFlare Inc. All rights reserved. From 14ef5576ef464c4e8bfdef34e29a51049967bac6 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Wed, 11 Dec 2013 13:09:19 -0800 Subject: [PATCH 29/72] fixed warnings from the Microsoft Visual C++ compiler. thanks Edwin Cleton for the report. --- src/ngx_http_rds_json_output.c | 5 ++++- src/ngx_http_rds_json_processor.c | 4 ---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index 456cc6c..535a1b8 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -112,7 +112,6 @@ ngx_http_rds_json_output_bufs(ngx_http_request_t *r, } /* impossible to reach here */ - return NGX_ERROR; } @@ -739,11 +738,13 @@ ngx_http_rds_json_output_field(ngx_http_request_t *r, last = (u_char *) ngx_http_rds_json_escape_json_str(last, data, len); +#if DDEBUG dd("escaped value \"%.*s\" (len %d, escape %d, escape2 %d)", (int) (len + val_escape), p, (int) (len + val_escape), (int) val_escape, (int) ((last - p) - len)); +#endif } if (ctx->field_data_rest == 0) { @@ -881,11 +882,13 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, last = (u_char *) ngx_http_rds_json_escape_json_str(last, data, len); +#if DDEBUG dd("escaped value \"%.*s\" (len %d, escape %d, escape2 %d)", (int) (len + escape), p, (int) (len + escape), (int) escape, (int) ((last - p) - len)); +#endif } if (ctx->field_data_rest == 0) { diff --git a/src/ngx_http_rds_json_processor.c b/src/ngx_http_rds_json_processor.c index eb2bfc1..f22b6a1 100644 --- a/src/ngx_http_rds_json_processor.c +++ b/src/ngx_http_rds_json_processor.c @@ -435,8 +435,6 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in, } /* impossible to reach here */ - - return NGX_ERROR; } @@ -508,6 +506,4 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, } /* impossible to reach here */ - - return NGX_ERROR; } From fb99d316338b40103665858572ed3d1ee59680bb Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 14 Dec 2013 14:25:01 -0800 Subject: [PATCH 30/72] doc: claims that we work with nginx 1.4.4. --- README | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README b/README index 2006dbf..315a894 100644 --- a/README +++ b/README @@ -152,12 +152,12 @@ Directives Installation Grab the nginx source code from nginx.net (), for - example, the version 1.4.3 (see nginx compatibility), and then build + example, the version 1.4.4 (see nginx compatibility), and then build the source with this module: - wget 'http://nginx.org/download/nginx-1.4.3.tar.gz' - tar -xzvf nginx-1.4.3.tar.gz - cd nginx-1.4.3/ + wget 'http://nginx.org/download/nginx-1.4.4.tar.gz' + tar -xzvf nginx-1.4.4.tar.gz + cd nginx-1.4.4/ # Here we assume you would install you nginx under /opt/nginx/. ./configure --prefix=/opt/nginx \ @@ -174,7 +174,7 @@ Installation Compatibility The following versions of Nginx should work with this module: - * 1.4.x (last tested: 1.4.3) + * 1.4.x (last tested: 1.4.4) * 1.2.x (last tested: 1.2.9) From 8292070c78db157d03db8b8215c981f0cc808569 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 14 Dec 2013 14:26:48 -0800 Subject: [PATCH 31/72] minor coding style fixes. --- src/ngx_http_rds_json_processor.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ngx_http_rds_json_processor.c b/src/ngx_http_rds_json_processor.c index f22b6a1..9a242f3 100644 --- a/src/ngx_http_rds_json_processor.c +++ b/src/ngx_http_rds_json_processor.c @@ -151,8 +151,8 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, ngx_chain_t *in, b = in->buf; - if (!ngx_buf_in_memory(b) ) { - if (!ngx_buf_special(b) ) { + if (!ngx_buf_in_memory(b)) { + if (!ngx_buf_special(b)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "rds_json: process col: buf from " "upstream not in memory"); @@ -255,8 +255,8 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in, b = in->buf; - if (!ngx_buf_in_memory(b) ) { - if (!ngx_buf_special(b) ) { + if (!ngx_buf_in_memory(b)) { + if (!ngx_buf_special(b)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "rds_json: process row: buf from " "upstream not in memory"); @@ -279,8 +279,8 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in, } dd("row flag: %d (offset %d)", - (char) *b->pos, - (int) (b->pos - b->start)); + (char) *b->pos, + (int) (b->pos - b->start)); if (*b->pos++ == 0) { /* end of row list */ @@ -345,10 +345,10 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in, b = in->buf; - if (!ngx_buf_in_memory(b) ) { + if (!ngx_buf_in_memory(b)) { dd("buf not in memory"); - if (!ngx_buf_special(b) ) { + if (!ngx_buf_special(b)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "rds_json: process field: buf from " "upstream not in memory"); From b6e76c07c222e2af89fbb1b2b5527a7756236a9e Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 5 Apr 2014 21:36:09 -0700 Subject: [PATCH 32/72] suppressed a valgrind false positive in libdl. --- valgrind.suppress | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/valgrind.suppress b/valgrind.suppress index e8bff1b..53e342f 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -303,4 +303,14 @@ fun:ngx_http_core_server fun:ngx_conf_parse } - +{ + + Memcheck:Cond + fun:index + fun:expand_dynamic_string_token + fun:_dl_map_object + fun:map_doit + fun:_dl_catch_error + fun:do_preload + fun:dl_main +} From d116551ae932ca77648897c642dba7970c51037c Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Mon, 18 Aug 2014 12:50:36 -0700 Subject: [PATCH 33/72] style: fixed the label syntax. --- src/ngx_http_rds_json_output.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index 535a1b8..9929744 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -1009,6 +1009,7 @@ ngx_http_rds_json_get_postponed(ngx_http_request_t *r, return ctx->cached.start; alloc: + p = ngx_palloc(r->pool, len); if (p == NULL) { return NULL; From 54a5125744a905afb48ca2131e5431feb7d56479 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Thu, 2 Apr 2015 12:27:20 -0700 Subject: [PATCH 34/72] fixed compilation failures with nginx 1.7.11+ configured with --with-threads. --- src/ddebug.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ddebug.h b/src/ddebug.h index 8f57f86..6a52e4a 100644 --- a/src/ddebug.h +++ b/src/ddebug.h @@ -1,6 +1,7 @@ #ifndef DDEBUG_H #define DDEBUG_H +#include #include #if defined(DDEBUG) && (DDEBUG) From 2d8b492e75f09fa7193149f7969ddfc2446c88e8 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Mon, 22 Jun 2015 22:01:55 +0800 Subject: [PATCH 35/72] minor coding style fixes. --- src/ngx_http_rds_json_filter_module.c | 14 +++++++------- src/ngx_http_rds_json_output.c | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 6290c0f..1a26583 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -39,24 +39,24 @@ ngx_http_output_header_filter_pt ngx_http_rds_json_next_header_filter; ngx_http_output_body_filter_pt ngx_http_rds_json_next_body_filter; -static void * ngx_http_rds_json_create_main_conf(ngx_conf_t *cf); +static void *ngx_http_rds_json_create_main_conf(ngx_conf_t *cf); static char *ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static void *ngx_http_rds_json_create_loc_conf(ngx_conf_t *cf); static char *ngx_http_rds_json_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child); static ngx_int_t ngx_http_rds_json_filter_init(ngx_conf_t *cf); -static char * ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, +static char *ngx_http_rds_json_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static char * ngx_http_rds_json_success_property(ngx_conf_t *cf, +static char *ngx_http_rds_json_success_property(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static char * ngx_http_rds_json_user_property(ngx_conf_t *cf, +static char *ngx_http_rds_json_user_property(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static char * ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, +static char *ngx_http_rds_json_errcode_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static char * ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, +static char *ngx_http_rds_json_errstr_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -static char * ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static char *ngx_http_rds_json(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static ngx_command_t ngx_http_rds_json_commands[] = { diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index 9929744..f266808 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -17,11 +17,11 @@ #include -static u_char * ngx_http_rds_json_request_mem(ngx_http_request_t *r, +static u_char *ngx_http_rds_json_request_mem(ngx_http_request_t *r, ngx_http_rds_json_ctx_t *ctx, size_t len); static ngx_int_t ngx_http_rds_json_get_buf(ngx_http_request_t *r, ngx_http_rds_json_ctx_t *ctx); -static u_char * ngx_http_rds_json_get_postponed(ngx_http_request_t *r, +static u_char *ngx_http_rds_json_get_postponed(ngx_http_request_t *r, ngx_http_rds_json_ctx_t *ctx, size_t len); static ngx_int_t ngx_http_rds_json_submit_mem(ngx_http_request_t *r, ngx_http_rds_json_ctx_t *ctx, size_t len, unsigned last_buf); From b73fc29f3981f49e0465aea2505b132f22a40ace Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Mon, 22 Jun 2015 22:23:52 +0800 Subject: [PATCH 36/72] doc: use markdown instead. --- README | 237 -------------------------------------- README.md | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 339 insertions(+), 237 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 315a894..0000000 --- a/README +++ /dev/null @@ -1,237 +0,0 @@ -Name - ngx_rds_json - an output filter that formats Resty - DBD Streams generated by ngx_drizzle and others to JSON - -Status - This module is considered production ready. - - We need your help! If you find this module useful and/or - interesting, please consider joining the development! - Commit bit can be freely delivered at your request ;) - -Synopsis - - server { - location /mysql { - drizzle_query 'select * from cats'; - drizzle_pass my_mysql_upstream; - - rds_json on; - } - - location /foo { - if ($arg_limit !~ '^\d{2}$') { - rds_json_ret 400 'Bad "limit" argument'; - } - - drizzle_query "select * from dogs limit $arg_limit"; - drizzle_pass my_mysql_upstream; - - rds_json on; - } - ... - } - -Description - This module provides an output filter that can format the RDS outputs - generated by ngx_drizzle and ngx_postgres modules to JSON. - -Directives - rds_json - syntax: rds_json on|off - default: rds_json off - - Enables or disables the output filter of this module. - - rds_json_buffer_size - syntax: rds_json_buffer_size - default: rds_json_buffer_size - - Controls the buffer size used by this module. default to the page size (4k/8k). - The bigger the buffer size, the less streammy the conversion - will be. But usually increasing the buffer size - does help reduce CPU time. - - rds_json_format - syntax: rds_json_format normal|compact - default: rds_json_format normal - - Controls the output JSON format. A sample of the default "normal" format - looks like this - - [{"id":1,"name":"marry"},{"id":2,"name":"bob"}] - - while it looks like below when in the "compact" format - - [["id","name"],[1,"marry"],[2,"bob"]] - - that is, the first row holds the column name list. - - rds_json_root - syntax: rds_json_root - default: no - - Specify the "root" key for data rows (if any). - - For example, - - rds_json on; - rds_json_root rows; - - will return JSON output like this: - - {"rows":[{"id":2,"name":null},{"id":3,"name":"bob"}]} - - if "rds_json_format compact" is also specified, then the - output will look like this: - - {"rows":[["id","name"],[2,null],[3,"bob"]]} - - Nginx variables are not supported in the argument of - this directive. - - If this directive is not defined, neither are rds_json_success_property, - nor rds_json_extra_property, the JSON output for select queries will - just be an array at the - top level. - - When either rds_json_success_property or rds_json_extra_property are specified, - this directive takes a default argument of "data". - - rds_json_success_property - syntax: rds_json_success_property - default: no - - Specify the top-level object property name used in the JSON output - for indicating success or false of the query. - - rds_json_user_property - syntax: rds_json_user_property - default: no - - Specify additonal user properties for the top-level object - of the JSON output. - - Multiple instances of this directives are allowed in a single scope. - - Nginx variables are supported in the argument. - - Both of the and arguments will be automatically - quoted according to JSON strings' notation. - - rds_json_errcode_key - syntax: rds_json_errcode_key - default: rds_json_errcode_key errcode - - Specify the errcode key name used in the JSON output. - - rds_json_errstr_key - syntax: rds_json_errstr_key - default: rds_json_errstr_key errstr - - Specify the errstr key name used in the JSON output. - - rds_json_ret - syntax: rds_json_ret - default: no - - This directive enables a content handler that simply emits - an response body like this: - - {"errcode":,"errstr":""} - - while the string will be properly quoted as - a JSON string. - - rds_json_content_type - syntax: rds_json_content_type - default: rds_json_content_type application/json - - Controls the Content-Type header of the response generated by - this module's output filter. - -Installation - Grab the nginx source code from nginx.net (), for - example, the version 1.4.4 (see nginx compatibility), and then build - the source with this module: - - wget 'http://nginx.org/download/nginx-1.4.4.tar.gz' - tar -xzvf nginx-1.4.4.tar.gz - cd nginx-1.4.4/ - - # Here we assume you would install you nginx under /opt/nginx/. - ./configure --prefix=/opt/nginx \ - --add-module=/path/to/drizzle-nginx-module - --add-module=/path/to/rds-json-nginx-module - - make -j2 - make install - - Download the latest version of the release tarball of this module from - rds-json-nginx-module file list - (). - -Compatibility - The following versions of Nginx should work with this module: - - * 1.4.x (last tested: 1.4.4) - - * 1.2.x (last tested: 1.2.9) - - * 1.1.x (last tested: 1.1.5) - - * 1.0.x (last tested: 1.0.9) - - * 0.9.x (last tested: 0.9.4) - - * 0.8.x (last tested: 0.8.55) - - * 0.7.x >= 0.7.46 (last tested: 0.7.68) - - Earlier versions of Nginx like 0.6.x and 0.5.x will *not* work. - - If you find that any particular version of Nginx above 0.7.44 does not - work with this module, please consider reporting a bug. - -TODO - -Known Issues - -See Also - - * ngx_drizzle ( http://github.com/chaoslawful/drizzle-nginx-module ) - - * ngx_postgres ( http://github.com/FRiCKLE/ngx_postgres/ ) - -Author - Yichun "agentzh" Zhang (章亦春) , CloudFlare Inc. - -Copyright & License - This module is licenced under the BSD license. - - Copyright (C) 2009-2013, Yichun Zhang (agentzh) , CloudFlare Inc. - - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * 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 - HOLDER 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7efc837 --- /dev/null +++ b/README.md @@ -0,0 +1,339 @@ +Name +==== + +ngx_rds_json - an output filter that formats Resty DBD Streams generated by ngx_drizzle and others to JSON + +Table of Contents +================= + +* [Name](#name) +* [Status](#status) +* [Synopsis](#synopsis) +* [Description](#description) +* [Directives](#directives) + * [rds_json](#rds_json) + * [rds_json_buffer_size](#rds_json_buffer_size) + * [rds_json_format](#rds_json_format) + * [rds_json_root](#rds_json_root) + * [rds_json_success_property](#rds_json_success_property) + * [rds_json_user_property](#rds_json_user_property) + * [rds_json_errcode_key](#rds_json_errcode_key) + * [rds_json_errstr_key](#rds_json_errstr_key) + * [rds_json_ret](#rds_json_ret) + * [rds_json_content_type](#rds_json_content_type) +* [Installation](#installation) +* [Compatibility](#compatibility) +* [Author](#author) +* [Copyright & License](#copyright--license) +* [See Also](#see-also) + +Status +====== + +This module is considered production ready. + +We need your help! If you find this module useful and/or interesting, please consider joining the development! +Commit bit can be freely delivered at your request ;) + +Synopsis +======== + +```nginx +server { + location /mysql { + drizzle_query 'select * from cats'; + drizzle_pass my_mysql_upstream; + + rds_json on; + } + + location /foo { + if ($arg_limit !~ '^\d{2}$') { + rds_json_ret 400 'Bad "limit" argument'; + } + + drizzle_query "select * from dogs limit $arg_limit"; + drizzle_pass my_mysql_upstream; + + rds_json on; + } + ... +} +``` + +Description +=========== + +This module provides an output filter that can format the RDS outputs +generated by [ngx_drizzle](https://github.com/openresty/drizzle-nginx-module) +and [ngx_postgres](https://github.com/FRiCKLE/ngx_postgres/) modules to JSON. + +[Back to TOC](#table-of-contents) + +Directives +========== + +[Back to TOC](#table-of-contents) + +rds_json +-------- +**syntax:** *rds_json on|off* + +**default:** *rds_json off* + +Enables or disables the output filter of this module. + +[Back to TOC](#table-of-contents) + +rds_json_buffer_size +-------------------- +**syntax:** *rds_json_buffer_size <bytes>* + +**default:** *rds_json_buffer_size <page-size>* + +Controls the buffer size used by this module. default to the page size (4k/8k). +The bigger the buffer size, the less streammy the conversion +will be. But usually increasing the buffer size +does help reduce CPU time. + +[Back to TOC](#table-of-contents) + +rds_json_format +--------------- +**syntax:** *rds_json_format normal|compact* + +**default:** *rds_json_format normal* + +Controls the output JSON format. A sample of the default "normal" format +looks like this + +```json + [{"id":1,"name":"marry"},{"id":2,"name":"bob"}] +``` + +while it looks like below when in the "compact" format + +```json + [["id","name"],[1,"marry"],[2,"bob"]] +``` + +that is, the first row holds the column name list. + +[Back to TOC](#table-of-contents) + +rds_json_root +------------- +**syntax:** *rds_json_root <key>* + +**default:** *no* + +Specifies the "root" key for data rows (if any). For example, + +```nginx + rds_json on; + rds_json_root rows; +``` + +will return JSON output like this: + +```json + {"rows":[{"id":2,"name":null},{"id":3,"name":"bob"}]} +``` + +if `rds_json_format compact` is also specified, then the +output will look like this: + +```json + {"rows":[["id","name"],[2,null],[3,"bob"]]} +``` + +Nginx variables are not supported in the argument of +this directive. + +If this directive is not defined, neither are [rds_json_success_property](#rds_json_success_property), +nor [rds_json_user_property](#rds_json_user_property), the JSON output for select queries will +just be an array at the top level. + +When either [rds_json_success_property](#rds_json_success_property) or [rds_json_user_property](#rds_json_user_property) are specified, +this directive takes a default argument of "data". + +[Back to TOC](#table-of-contents) + +rds_json_success_property +------------------------- +**syntax:** *rds_json_success_property <key>* + +**default:** *no* + +Specifies the top-level object property name used in the JSON output +for indicating success or false of the query. + +[Back to TOC](#table-of-contents) + +rds_json_user_property +----------------------- +**syntax:** *rds_json_user_property <key> <value>* + +**default:** *no* + +Specifies additonal user properties for the top-level object +of the JSON output. + +Multiple instances of this directives are allowed in a single scope. + +Nginx variables are supported in the `value` argument. + +Both of the `key` and `value` arguments will be automatically +quoted according to JSON strings' notation. + +[Back to TOC](#table-of-contents) + +rds_json_errcode_key +--------------------- +**syntax:** *rds_json_errcode_key <key>* + +**default:** *rds_json_errcode_key errcode* + +Specifies the errcode key name used in the JSON output. + +[Back to TOC](#table-of-contents) + +rds_json_errstr_key +------------------- +**syntax:** *rds_json_errstr_key <key>* + +**default:** *rds_json_errstr_key errstr* + +Specifies the errstr key name used in the JSON output. + +[Back to TOC](#table-of-contents) + +rds_json_ret +------------ +**syntax:** *rds_json_ret <error-code> <descrption>* + +**default:** *no* + +This directive enables a content handler that simply emits +an response body like this: + +```json + {"errcode":,"errstr":""} +``` + +while the `` string will be properly quoted as +a JSON string. + +[Back to TOC](#table-of-contents) + +rds_json_content_type +--------------------- +**syntax:** *rds_json_content_type <mime-type>* + +**default:** *rds_json_content_type application/json* + +Controls the `Content-Type` header of the response generated by +this module's output filter. + +[Back to TOC](#table-of-contents) + +Installation +============ + +You're recommended to install this module (as well as the Nginx core and many other goodies) via the [ngx_openresty bundle](http://openresty.org). See [the detailed instructions](http://openresty.org/#Installation) for downloading and installing ngx_openresty into your system. This is the easiest and most safe way to set things up. + +Alternatively, you can install this module manually with the Nginx source: + +Grab the nginx source code from [nginx.org](http://nginx.org/), for example, +the version 1.7.10 (see [nginx compatibility](#compatibility)), and then build the source with this module: + +```bash + + $ wget 'http://nginx.org/download/nginx-1.7.10.tar.gz' + $ tar -xzvf nginx-1.7.10.tar.gz + $ cd nginx-1.7.10/ + + # Here we assume you would install you nginx under /opt/nginx/. + $ ./configure --prefix=/opt/nginx \ + --add-module=/path/to/rds-json-nginx-module + + $ make -j2 + $ make install +``` + +ownload the latest version of the release tarball of this module from [echo-nginx-module file list](https://github.com/agentzh/echo-nginx-module/tags). + +Also, this module is included and enabled by default in the [ngx_openresty bundle](http://openresty.org). + +[Back to TOC](#table-of-contents) + +Compatibility +============= +The following versions of Nginx should work with this module: + +* **1.7.x** (last tested: 1.7.10) +* **1.6.x** +* **1.5.x** (last tested: 1.5.12) +* **1.4.x** (last tested: 1.4.4) +* **1.2.x** (last tested: 1.2.9) +* **1.1.x** (last tested: 1.1.5) +* **1.0.x** (last tested: 1.0.9) +* **0.9.x** (last tested: 0.9.4) +* **0.8.x** (last tested: 0.8.55) +* **0.7.x >= 0.7.46** (last tested: 0.7.68) + +Earlier versions of Nginx like 0.6.x and 0.5.x will *not* work. + +If you find that any particular version of Nginx above 0.7.44 does not +work with this module, please consider reporting a bug. + +[Back to TOC](#table-of-contents) + +Author +====== +Yichun "agentzh" Zhang (章亦春) *<agentzh@gmail.com>*, CloudFlare Inc. + +[Back to TOC](#table-of-contents) + +Copyright & License +=================== + +This module is licenced under the BSD license. + +Copyright (C) 2009-2015, Yichun Zhang (agentzh) <agentzh@gmail.com>, CloudFlare Inc. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +* Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. +* 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 +HOLDER 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. + +[Back to TOC](#table-of-contents) + +See Also +======== + +* [ngx_drizzle](https://github.com/openresty/drizzle-nginx-module) +* [ngx_postgres](https://github.com/FRiCKLE/ngx_postgres/) +* [ngx_rds_csv](https://github.com/openresty/rds-csv-nginx-module) + +[Back to TOC](#table-of-contents) + From 5a704c68cccbfb536ab7f7886431cc3ec11c088d Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Tue, 23 Jun 2015 15:15:11 +0800 Subject: [PATCH 37/72] doc: added context info for all the config directives. --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7efc837..7a0cf73 100644 --- a/README.md +++ b/README.md @@ -77,10 +77,12 @@ Directives rds_json -------- -**syntax:** *rds_json on|off* +**syntax:** *rds_json on|off* **default:** *rds_json off* +**context:** *http, server, location, if location* + Enables or disables the output filter of this module. [Back to TOC](#table-of-contents) @@ -91,6 +93,8 @@ rds_json_buffer_size **default:** *rds_json_buffer_size <page-size>* +**context:** *http, server, location, if location* + Controls the buffer size used by this module. default to the page size (4k/8k). The bigger the buffer size, the less streammy the conversion will be. But usually increasing the buffer size @@ -104,6 +108,8 @@ rds_json_format **default:** *rds_json_format normal* +**context:** *http, server, location, if location* + Controls the output JSON format. A sample of the default "normal" format looks like this @@ -127,6 +133,8 @@ rds_json_root **default:** *no* +**context:** *http, server, location, if location* + Specifies the "root" key for data rows (if any). For example, ```nginx @@ -165,6 +173,8 @@ rds_json_success_property **default:** *no* +**context:** *http, server, location, if location* + Specifies the top-level object property name used in the JSON output for indicating success or false of the query. @@ -176,6 +186,8 @@ rds_json_user_property **default:** *no* +**context:** *http, server, location, if location* + Specifies additonal user properties for the top-level object of the JSON output. @@ -194,6 +206,8 @@ rds_json_errcode_key **default:** *rds_json_errcode_key errcode* +**context:** *http, server, location, if location* + Specifies the errcode key name used in the JSON output. [Back to TOC](#table-of-contents) @@ -204,6 +218,8 @@ rds_json_errstr_key **default:** *rds_json_errstr_key errstr* +**context:** *http, server, location, if location* + Specifies the errstr key name used in the JSON output. [Back to TOC](#table-of-contents) @@ -214,6 +230,8 @@ rds_json_ret **default:** *no* +**context:** *location, if location* + This directive enables a content handler that simply emits an response body like this: @@ -232,6 +250,8 @@ rds_json_content_type **default:** *rds_json_content_type application/json* +**context:** *http, server, location, if location* + Controls the `Content-Type` header of the response generated by this module's output filter. From 62a8e0c15d40127cd6b79ec0feeccde9f25bfa18 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Tue, 23 Jun 2015 15:21:17 +0800 Subject: [PATCH 38/72] doc: typo fixes. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a0cf73..7459916 100644 --- a/README.md +++ b/README.md @@ -281,7 +281,7 @@ the version 1.7.10 (see [nginx compatibility](#compatibility)), and then build t $ make install ``` -ownload the latest version of the release tarball of this module from [echo-nginx-module file list](https://github.com/agentzh/echo-nginx-module/tags). +Download the latest version of the release tarball of this module from [rds-json-nginx-module file list](https://github.com/openresty/rds-json-nginx-module/tags). Also, this module is included and enabled by default in the [ngx_openresty bundle](http://openresty.org). From 4c53734bfe970b244f051437a4f66adba970cecd Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Fri, 17 Jul 2015 11:51:46 +0800 Subject: [PATCH 39/72] tests: disabled the test cases exercising multiple http {} blocks since this undocumented feature has been disabled since nginx 1.9.3. --- t/unused.t | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/unused.t b/t/unused.t index a5d2d07..7b3fe76 100644 --- a/t/unused.t +++ b/t/unused.t @@ -69,6 +69,9 @@ rds json body filter, "/foo" === TEST 4: multiple http {} blocks +This test case won't run with nginx 1.9.3+ since duplicate http {} blocks +have been prohibited since then. +--- SKIP --- config location /foo { echo Hello; From 8623f0bc57d344a3103fddb83fc3d4eafc04782f Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sun, 1 Nov 2015 12:15:35 +0800 Subject: [PATCH 40/72] bugfix: fixed warnings with C compilers without variadic macro support. --- src/ddebug.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ddebug.h b/src/ddebug.h index 6a52e4a..0bfa9b2 100644 --- a/src/ddebug.h +++ b/src/ddebug.h @@ -29,7 +29,8 @@ #include -static void dd(const char * fmt, ...) { +static ngx_inline void +dd(const char * fmt, ...) { } # endif @@ -46,7 +47,8 @@ static void dd(const char * fmt, ...) { #include -static void dd(const char * fmt, ...) { +static ngx_inline void +dd(const char * fmt, ...) { } # endif From 3c79c051ad1e2b984ea31a9e5a09a69a6db995fe Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Mon, 23 Nov 2015 23:16:11 +0800 Subject: [PATCH 41/72] added a .gitattributes file to correct GitHub's language tag. --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6fe6f35 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.t linguist-language=Text From 2faf479524536760cece3427a9f861e59e9507ff Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Mon, 25 Jan 2016 15:03:46 -0800 Subject: [PATCH 42/72] doc: various updates. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7459916..ffb3f6b 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ this module's output filter. Installation ============ -You're recommended to install this module (as well as the Nginx core and many other goodies) via the [ngx_openresty bundle](http://openresty.org). See [the detailed instructions](http://openresty.org/#Installation) for downloading and installing ngx_openresty into your system. This is the easiest and most safe way to set things up. +You're recommended to install this module (as well as the Nginx core and many other goodies) via the [OpenResty bundle](http://openresty.org). See [the detailed instructions](http://openresty.org/#Installation) for downloading and installing OpenResty into your system. This is the easiest and most safe way to set things up. Alternatively, you can install this module manually with the Nginx source: @@ -283,7 +283,7 @@ the version 1.7.10 (see [nginx compatibility](#compatibility)), and then build t Download the latest version of the release tarball of this module from [rds-json-nginx-module file list](https://github.com/openresty/rds-json-nginx-module/tags). -Also, this module is included and enabled by default in the [ngx_openresty bundle](http://openresty.org). +Also, this module is included and enabled by default in the [OpenResty bundle](http://openresty.org). [Back to TOC](#table-of-contents) @@ -291,6 +291,8 @@ Compatibility ============= The following versions of Nginx should work with this module: +* **1.9.x** (last tested: 1.9.7) +* **1.8.x** * **1.7.x** (last tested: 1.7.10) * **1.6.x** * **1.5.x** (last tested: 1.5.12) @@ -320,7 +322,7 @@ Copyright & License This module is licenced under the BSD license. -Copyright (C) 2009-2015, Yichun Zhang (agentzh) <agentzh@gmail.com>, CloudFlare Inc. +Copyright (C) 2009-2016, Yichun Zhang (agentzh) <agentzh@gmail.com>, CloudFlare Inc. All rights reserved. From df01245387c6b0f1d05e35f5d462dbcfae892198 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Mon, 25 Jan 2016 15:04:53 -0800 Subject: [PATCH 43/72] doc: various updates. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ffb3f6b..8df8e25 100644 --- a/README.md +++ b/README.md @@ -265,13 +265,13 @@ You're recommended to install this module (as well as the Nginx core and many ot Alternatively, you can install this module manually with the Nginx source: Grab the nginx source code from [nginx.org](http://nginx.org/), for example, -the version 1.7.10 (see [nginx compatibility](#compatibility)), and then build the source with this module: +the version 1.9.7 (see [nginx compatibility](#compatibility)), and then build the source with this module: ```bash - $ wget 'http://nginx.org/download/nginx-1.7.10.tar.gz' - $ tar -xzvf nginx-1.7.10.tar.gz - $ cd nginx-1.7.10/ + $ wget 'http://nginx.org/download/nginx-1.9.7.tar.gz' + $ tar -xzvf nginx-1.9.7.tar.gz + $ cd nginx-1.9.7/ # Here we assume you would install you nginx under /opt/nginx/. $ ./configure --prefix=/opt/nginx \ From 93d0b7e43e19f3fd24b292d2e4e70f1553508cea Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Fri, 10 Jun 2016 10:06:08 +0500 Subject: [PATCH 44/72] feature: added travis-ci support. Signed-off-by: Yichun Zhang (agentzh) --- .travis.yml | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..add52fb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,79 @@ +sudo: required +dist: trusty + +os: linux + +language: c + +cache: + directories: + - download-cache + +addons: + apt: + packages: + - mysql-server + +compiler: + - gcc + - clang + +env: + global: + - LUAJIT_PREFIX=/opt/luajit21 + - LUAJIT_LIB=$LUAJIT_PREFIX/lib + - LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH + - LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1 + - LUA_INCLUDE_DIR=$LUAJIT_INC + - LUA_CMODULE_DIR=/lib + - JOBS=3 + - NGX_BUILD_JOBS=$JOBS + - TEST_NGINX_SLEEP=0.006 + matrix: + - NGINX_VERSION=1.9.15 + +services: + - postgresql + +before_install: + - sudo apt-get install -qq -y axel cpanminus libtest-base-perl libtext-diff-perl liburi-perl libwww-perl libtest-longstring-perl liblist-moreutils-perl > build.log 2>&1 || (cat build.log && exit 1) + +install: + - if [ ! -d download-cache ]; then mkdir download-cache; fi + - if [ ! -f download-cache/drizzle7-2011.07.21.tar.gz ]; then wget -O download-cache/drizzle7-2011.07.21.tar.gz http://openresty.org/download/drizzle7-2011.07.21.tar.gz; fi + - git clone https://github.com/openresty/nginx-devel-utils.git + - git clone https://github.com/openresty/openresty.git ../openresty + - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx + - git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module + - git clone https://github.com/openresty/test-nginx.git + - git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git + - git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module + - git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module + - git clone https://github.com/openresty/nginx-eval-module.git ../eval-nginx-module + - git clone https://github.com/openresty/xss-nginx-module.git ../xss-nginx-module + - git clone https://github.com/openresty/set-misc-nginx-module.git ../set-misc-nginx-module + - git clone https://github.com/openresty/array-var-nginx-module.git ../array-var-nginx-module + - git clone https://github.com/openresty/drizzle-nginx-module.git ../drizzle-nginx-module + - git clone https://github.com/calio/form-input-nginx-module.git ../form-input-nginx-module + - git clone https://github.com/FRiCKLE/ngx_postgres.git ../postgres-nginx-module + - git clone https://github.com/openresty/openresty.git ../ngx_openresty + +before_script: + - mysql -uroot -e 'create database ngx_test; grant all on ngx_test.* to "ngx_test"@"%" identified by "ngx_test"; flush privileges;' + - psql -c "create database ngx_test;" -U postgres + - psql -c "create user ngx_test with password 'ngx_test';" -U postgres + - psql -c "grant all privileges on database ngx_test to ngx_test;" -U postgres + +script: + - tar xzf download-cache/drizzle7-2011.07.21.tar.gz && cd drizzle7-2011.07.21 + - ./configure --prefix=/usr --without-server > build.log 2>&1 || (cat build.log && exit 1) + - sudo PATH=$PATH make libdrizzle-1.0 install-libdrizzle-1.0 > build.log 2>&1 || (cat build.log && exit 1) + - cd ../luajit2 + - make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT' > build.log 2>&1 || (cat build.log && exit 1) + - sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1) + - cd ../test-nginx && sudo cpanm . && cd .. + - export PATH=$PWD/work/nginx/sbin:$PWD/nginx-devel-utils:$PATH + - export NGX_BUILD_CC=$CC + - sh util/build.sh $NGINX_VERSION > build.log 2>&1 || (cat build.log && exit 1) + - nginx -V + - prove -r t From d143cf71e87066aa90b01cd6d9e59c5ca9f760e1 Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Thu, 10 Nov 2016 11:02:22 +0500 Subject: [PATCH 45/72] travis-ci: added nginx-1.11.2 to build matrix, moved package management under "apt" plugin --- .travis.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index add52fb..14a4fcc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,15 @@ os: linux language: c +addons: + apt: + packages: [ mysql-server, axel, cpanminus, libtest-base-perl, libtext-diff-perl, liburi-perl, libwww-perl, libtest-longstring-perl, liblist-moreutils-perl ] + cache: + apt: true directories: - download-cache -addons: - apt: - packages: - - mysql-server - compiler: - gcc - clang @@ -31,16 +31,13 @@ env: - TEST_NGINX_SLEEP=0.006 matrix: - NGINX_VERSION=1.9.15 + - NGINX_VERSION=1.11.2 services: - postgresql -before_install: - - sudo apt-get install -qq -y axel cpanminus libtest-base-perl libtext-diff-perl liburi-perl libwww-perl libtest-longstring-perl liblist-moreutils-perl > build.log 2>&1 || (cat build.log && exit 1) - install: - - if [ ! -d download-cache ]; then mkdir download-cache; fi - - if [ ! -f download-cache/drizzle7-2011.07.21.tar.gz ]; then wget -O download-cache/drizzle7-2011.07.21.tar.gz http://openresty.org/download/drizzle7-2011.07.21.tar.gz; fi + - if [ ! -f download-cache/drizzle7-2011.07.21.tar.gz ]; then wget -P download-cache/ http://openresty.org/download/drizzle7-2011.07.21.tar.gz; fi - git clone https://github.com/openresty/nginx-devel-utils.git - git clone https://github.com/openresty/openresty.git ../openresty - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx From 75e0f89ebf77654d0cdaad63bcdc68c1b743fe97 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sun, 18 Dec 2016 15:18:58 -0800 Subject: [PATCH 46/72] doc: updated copyright notice. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8df8e25..c430d78 100644 --- a/README.md +++ b/README.md @@ -313,7 +313,7 @@ work with this module, please consider reporting a bug. Author ====== -Yichun "agentzh" Zhang (章亦春) *<agentzh@gmail.com>*, CloudFlare Inc. +Yichun "agentzh" Zhang (章亦春) *<agentzh@gmail.com>*, OpenResty Inc. [Back to TOC](#table-of-contents) @@ -322,7 +322,7 @@ Copyright & License This module is licenced under the BSD license. -Copyright (C) 2009-2016, Yichun Zhang (agentzh) <agentzh@gmail.com>, CloudFlare Inc. +Copyright (C) 2009-2017, Yichun Zhang (agentzh) <agentzh@gmail.com>, OpenResty Inc. All rights reserved. From 2b704eb55ca796871856bb2217c8ec072159ff69 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sun, 18 Dec 2016 16:07:07 -0800 Subject: [PATCH 47/72] travis-ci: attempted a fix. --- .travis.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 14a4fcc..5f96fee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,16 @@ language: c addons: apt: - packages: [ mysql-server, axel, cpanminus, libtest-base-perl, libtext-diff-perl, liburi-perl, libwww-perl, libtest-longstring-perl, liblist-moreutils-perl ] + packages: + - axel + - cpanminus + - libtest-base-perl + - libtext-diff-perl + - liburi-perl + - libwww-perl + - libtest-longstring-perl + - liblist-moreutils-perl + - libgd-dev cache: apt: true @@ -34,6 +43,7 @@ env: - NGINX_VERSION=1.11.2 services: + - mysql - postgresql install: From 307241e93525d19e3da935fcaa7981c8527055f8 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Thu, 26 Oct 2017 17:55:25 -0700 Subject: [PATCH 48/72] tests: skipped a test case that relies on the mysql default charset setting. --- t/sanity.t | 1 + 1 file changed, 1 insertion(+) diff --git a/t/sanity.t b/t/sanity.t index 2c7ea61..d05d1fa 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -364,6 +364,7 @@ GET /test === TEST 14: strings need to be escaped +--- SKIP --- http_config eval: $::http_config --- config location /test { From bbebdace480498ad37a0fba42420edf993967f47 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Thu, 26 Oct 2017 20:13:39 -0700 Subject: [PATCH 49/72] travis: added nginx 1.13.6 to the test matrix. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5f96fee..71c1950 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,8 +39,8 @@ env: - NGX_BUILD_JOBS=$JOBS - TEST_NGINX_SLEEP=0.006 matrix: - - NGINX_VERSION=1.9.15 - NGINX_VERSION=1.11.2 + - NGINX_VERSION=1.13.6 services: - mysql From 99209311c8248fdddf2edf4076286f78fbb168b7 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Thu, 26 Oct 2017 20:21:13 -0700 Subject: [PATCH 50/72] travis: use openresty's fork of ngx_postgres. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 71c1950..3bfecd1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,7 +62,7 @@ install: - git clone https://github.com/openresty/array-var-nginx-module.git ../array-var-nginx-module - git clone https://github.com/openresty/drizzle-nginx-module.git ../drizzle-nginx-module - git clone https://github.com/calio/form-input-nginx-module.git ../form-input-nginx-module - - git clone https://github.com/FRiCKLE/ngx_postgres.git ../postgres-nginx-module + - git clone https://github.com/openresty/ngx_postgres.git ../postgres-nginx-module - git clone https://github.com/openresty/openresty.git ../ngx_openresty before_script: From 7a27a0ce22d30c41c3a903e0ad7ce67305d5e662 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Fri, 27 Oct 2017 12:02:15 -0700 Subject: [PATCH 51/72] tests: minor tweaks in valgrind.suppress. --- valgrind.suppress | 1 - 1 file changed, 1 deletion(-) diff --git a/valgrind.suppress b/valgrind.suppress index 53e342f..8963841 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -25,7 +25,6 @@ fun:ngx_alloc fun:ngx_event_process_init fun:ngx_single_process_cycle - fun:(below main) } { nginx-core-process-init From 058a135e3e4b0cc626d36caae560667b418bdd57 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Fri, 27 Oct 2017 13:13:37 -0700 Subject: [PATCH 52/72] tests: valgrind.suppress: removed too aggressive suppressions in nginx mem pools and luajit lj_str_new. --- valgrind.suppress | 8 -------- 1 file changed, 8 deletions(-) diff --git a/valgrind.suppress b/valgrind.suppress index 8963841..ba6e33d 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -1,10 +1,3 @@ -{ - - Memcheck:Leak - fun:malloc - fun:ngx_alloc - fun:ngx_palloc_large -} { Memcheck:Leak @@ -135,7 +128,6 @@ fun:ngx_init_cycle fun:main } - { Memcheck:Leak From 580284636250db451a2a709b94b8514bb5d8bd47 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Fri, 27 Oct 2017 13:53:28 -0700 Subject: [PATCH 53/72] tests: added new valgrind false positives in the latest nginx core. --- valgrind.suppress | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/valgrind.suppress b/valgrind.suppress index ba6e33d..8632e25 100644 --- a/valgrind.suppress +++ b/valgrind.suppress @@ -305,3 +305,22 @@ fun:do_preload fun:dl_main } +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:ngx_alloc + fun:ngx_set_environment + fun:ngx_single_process_cycle +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:ngx_alloc + fun:ngx_set_environment + fun:ngx_worker_process_init + fun:ngx_worker_process_cycle +} From 0cde4c784c68e61acc0bc4941c30a42b932a7a9d Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Fri, 3 Nov 2017 16:09:00 -0700 Subject: [PATCH 54/72] doc: we now work with nginx cores as new as 1.13.6. --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c430d78..f13e827 100644 --- a/README.md +++ b/README.md @@ -265,13 +265,13 @@ You're recommended to install this module (as well as the Nginx core and many ot Alternatively, you can install this module manually with the Nginx source: Grab the nginx source code from [nginx.org](http://nginx.org/), for example, -the version 1.9.7 (see [nginx compatibility](#compatibility)), and then build the source with this module: +the version 1.13.6 (see [nginx compatibility](#compatibility)), and then build the source with this module: ```bash - $ wget 'http://nginx.org/download/nginx-1.9.7.tar.gz' - $ tar -xzvf nginx-1.9.7.tar.gz - $ cd nginx-1.9.7/ + $ wget 'http://nginx.org/download/nginx-1.13.6.tar.gz' + $ tar -xzvf nginx-1.13.6.tar.gz + $ cd nginx-1.13.6/ # Here we assume you would install you nginx under /opt/nginx/. $ ./configure --prefix=/opt/nginx \ @@ -291,6 +291,10 @@ Compatibility ============= The following versions of Nginx should work with this module: +* **1.13.x** (last tested: 1.13.6) +* **1.12.x** +* **1.11.x** (last tested: 1.11.2) +* **1.10.x** * **1.9.x** (last tested: 1.9.7) * **1.8.x** * **1.7.x** (last tested: 1.7.10) From 6b10a63f53e34c3e4566e8b6b7cc9e89daf3085f Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sat, 20 Jan 2018 16:50:29 -0800 Subject: [PATCH 55/72] style: fixed minor coding style issues found by ngx-releng. --- src/ngx_http_rds_json_filter_module.c | 3 +-- src/ngx_http_rds_json_handler.c | 22 +++++++++++----------- src/ngx_http_rds_json_output.c | 17 +++++++++-------- src/ngx_http_rds_json_util.c | 3 ++- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 1a26583..8954abc 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -535,8 +535,7 @@ ngx_http_rds_json_ret(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) done: - clcf = ngx_http_conf_get_module_loc_conf(cf, - ngx_http_core_module); + clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); if (clcf == NULL) { return NGX_CONF_ERROR; } diff --git a/src/ngx_http_rds_json_handler.c b/src/ngx_http_rds_json_handler.c index 756e007..28f53d4 100644 --- a/src/ngx_http_rds_json_handler.c +++ b/src/ngx_http_rds_json_handler.c @@ -24,8 +24,7 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) dd("entered ret handler"); - conf = ngx_http_get_module_loc_conf(r, - ngx_http_rds_json_filter_module); + conf = ngx_http_get_module_loc_conf(r, ngx_http_rds_json_filter_module); /* evaluate the final value of conf->errstr */ @@ -43,8 +42,8 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) ; if (errstr.len) { - escape = ngx_http_rds_json_escape_json_str(NULL, - errstr.data, errstr.len); + escape = ngx_http_rds_json_escape_json_str(NULL, errstr.data, + errstr.len); len += sizeof(",") - 1 + conf->errstr_key.len @@ -58,6 +57,7 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) if (conf->success.len) { len += conf->success.len + sizeof(":,") - 1; + if (ngx_atoi(conf->errcode.data, conf->errcode.len) == 0) { len += sizeof("true") - 1; @@ -68,15 +68,15 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) if (conf->user_props) { values = ngx_pnalloc(r->pool, - conf->user_props->nelts * (sizeof(ngx_str_t) + - sizeof(uintptr_t))); + conf->user_props->nelts + * (sizeof(ngx_str_t) + sizeof(uintptr_t))); if (values == NULL) { return NGX_ERROR; } escapes = (uintptr_t *) ((u_char *) values + - conf->user_props->nelts * sizeof(ngx_str_t)); + conf->user_props->nelts * sizeof(ngx_str_t)); prop = conf->user_props->elts; for (i = 0; i < conf->user_props->nelts; i++) { @@ -87,7 +87,7 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) } escapes[i] = ngx_http_rds_json_escape_json_str(NULL, values[i].data, - values[i].len); + values[i].len); len += sizeof(":\"\",") - 1 + prop[i].key.len + values[i].len + escapes[i]; @@ -124,8 +124,8 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) if (errstr.len) { *b->last++ = ','; - b->last = ngx_copy(b->last, - conf->errstr_key.data, conf->errstr_key.len); + b->last = ngx_copy(b->last, conf->errstr_key.data, + conf->errstr_key.len); *b->last++ = ':'; *b->last++ = '"'; @@ -174,7 +174,7 @@ ngx_http_rds_json_ret_handler(ngx_http_request_t *r) if (b->last != b->end) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "rds_json: rds_json_ret: buffer error"); + "rds_json: rds_json_ret: buffer error"); return NGX_ERROR; } diff --git a/src/ngx_http_rds_json_output.c b/src/ngx_http_rds_json_output.c index f266808..6f85904 100644 --- a/src/ngx_http_rds_json_output.c +++ b/src/ngx_http_rds_json_output.c @@ -152,15 +152,15 @@ ngx_http_rds_json_output_header(ngx_http_request_t *r, if (conf->user_props) { values = ngx_pnalloc(r->pool, - conf->user_props->nelts * (sizeof(ngx_str_t) - + sizeof(uintptr_t))); + conf->user_props->nelts + * (sizeof(ngx_str_t) + sizeof(uintptr_t))); if (values == NULL) { return NGX_ERROR; } escapes = (uintptr_t *) ((u_char *) values - + conf->user_props->nelts * sizeof(ngx_str_t)); + + conf->user_props->nelts * sizeof(ngx_str_t)); prop = conf->user_props->elts; for (i = 0; i < conf->user_props->nelts; i++) { @@ -327,15 +327,16 @@ ngx_http_rds_json_output_props(ngx_http_request_t *r, if (conf->user_props) { values = ngx_pnalloc(r->pool, - conf->user_props->nelts * (sizeof(ngx_str_t) - + sizeof(uintptr_t))); + conf->user_props->nelts + * (sizeof(ngx_str_t) + sizeof(uintptr_t))); if (values == NULL) { return NGX_ERROR; } escapes = (uintptr_t *) ((u_char *) values - + conf->user_props->nelts * sizeof(ngx_str_t)); + + conf->user_props->nelts + * sizeof(ngx_str_t)); prop = conf->user_props->elts; for (i = 0; i < conf->user_props->nelts; i++) { @@ -873,14 +874,14 @@ ngx_http_rds_json_output_more_field_data(ngx_http_request_t *r, } else { dd("more field data: string value escape non-zero: %d", - (int) escape); + (int) escape); #if DDEBUG p = last; #endif last = (u_char *) ngx_http_rds_json_escape_json_str(last, - data, len); + data, len); #if DDEBUG dd("escaped value \"%.*s\" (len %d, escape %d, escape2 %d)", diff --git a/src/ngx_http_rds_json_util.c b/src/ngx_http_rds_json_util.c index 8a7616b..d0080e6 100644 --- a/src/ngx_http_rds_json_util.c +++ b/src/ngx_http_rds_json_util.c @@ -145,7 +145,8 @@ ngx_http_rds_json_discard_bufs(ngx_pool_t *pool, ngx_chain_t *in) for (cl = in; cl; cl = cl->next) { #if 0 if (cl->buf->temporary - && ngx_buf_size(cl->buf) > 0) { + && ngx_buf_size(cl->buf) > 0) + { ngx_pfree(pool, cl->buf->start); } #endif From 730f546f7378de20fb49a51506b302320d0e710e Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Tue, 29 Jan 2019 19:43:03 -0800 Subject: [PATCH 56/72] travis: bumped the nginx core version to 1.15.8. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3bfecd1..8dd15eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ env: - TEST_NGINX_SLEEP=0.006 matrix: - NGINX_VERSION=1.11.2 - - NGINX_VERSION=1.13.6 + - NGINX_VERSION=1.15.8 services: - mysql From 95f317c1a4a3bcba28078c2747cd974b02dbe799 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 11 Jul 2019 14:41:51 -0700 Subject: [PATCH 57/72] travis: clone the lua-resty-core and lua-resty-lrucache repositories. Those are required with recent versions of ngx_lua. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8dd15eb..5372984 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,6 +55,8 @@ install: - git clone https://github.com/openresty/test-nginx.git - git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git - git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module + - git clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core + - git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache - git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module - git clone https://github.com/openresty/nginx-eval-module.git ../eval-nginx-module - git clone https://github.com/openresty/xss-nginx-module.git ../xss-nginx-module From 59e5ab993d9f88c55189b1412de653dcad55dffc Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 11 Jul 2019 14:42:08 -0700 Subject: [PATCH 58/72] travis: bumped the nginx core version to 1.17.1. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5372984..feb3e9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ env: - TEST_NGINX_SLEEP=0.006 matrix: - NGINX_VERSION=1.11.2 - - NGINX_VERSION=1.15.8 + - NGINX_VERSION=1.17.1 services: - mysql From d05fffac5ec8819bccd834c6e4896f4d2a8a55a2 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Mon, 30 Sep 2019 11:56:26 -0700 Subject: [PATCH 59/72] travis-ci: bumped the NGINX core to 1.17.4. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index feb3e9c..8ff8dc3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ env: - TEST_NGINX_SLEEP=0.006 matrix: - NGINX_VERSION=1.11.2 - - NGINX_VERSION=1.17.1 + - NGINX_VERSION=1.17.4 services: - mysql From 283eecb4242a787c6d67bab4ffdc50ae9cd30e5f Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Wed, 22 Jan 2020 15:13:50 -0800 Subject: [PATCH 60/72] travis-ci: bumped the NGINX core to 1.17.8. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8ff8dc3..b75d3f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ env: - TEST_NGINX_SLEEP=0.006 matrix: - NGINX_VERSION=1.11.2 - - NGINX_VERSION=1.17.4 + - NGINX_VERSION=1.17.8 services: - mysql From 3fdea72aecdfd2be3f33066ceeb821a47cb43124 Mon Sep 17 00:00:00 2001 From: Johnny Date: Thu, 1 Oct 2020 23:04:37 +0800 Subject: [PATCH 61/72] travis-ci: bumped the NGINX core to 1.19.3. (#18) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b75d3f1..efee7b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ env: - TEST_NGINX_SLEEP=0.006 matrix: - NGINX_VERSION=1.11.2 - - NGINX_VERSION=1.17.8 + - NGINX_VERSION=1.19.3 services: - mysql From 1641874b9ba8046d59ae88cef71f96577991c0e0 Mon Sep 17 00:00:00 2001 From: Johnny Wang Date: Wed, 20 Oct 2021 10:21:27 +0800 Subject: [PATCH 62/72] travis-ci: upgrade dist of travis-ci to ubuntu bionic. (#21) tests: update encoding of MySQL server since MySQL is newer than 5.5. --- .travis.yml | 10 +++++----- t/sanity.t | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index efee7b1..6dd3823 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ sudo: required -dist: trusty +dist: bionic os: linux @@ -25,7 +25,6 @@ cache: compiler: - gcc - - clang env: global: @@ -39,8 +38,8 @@ env: - NGX_BUILD_JOBS=$JOBS - TEST_NGINX_SLEEP=0.006 matrix: - - NGINX_VERSION=1.11.2 - - NGINX_VERSION=1.19.3 + - NGINX_VERSION=1.17.8 + - NGINX_VERSION=1.19.9 services: - mysql @@ -69,6 +68,7 @@ install: before_script: - mysql -uroot -e 'create database ngx_test; grant all on ngx_test.* to "ngx_test"@"%" identified by "ngx_test"; flush privileges;' + - mysql -uroot -e 'alter database ngx_test character set utf8mb4 collate utf8mb4_unicode_ci;' - psql -c "create database ngx_test;" -U postgres - psql -c "create user ngx_test with password 'ngx_test';" -U postgres - psql -c "grant all privileges on database ngx_test to ngx_test;" -U postgres @@ -85,4 +85,4 @@ script: - export NGX_BUILD_CC=$CC - sh util/build.sh $NGINX_VERSION > build.log 2>&1 || (cat build.log && exit 1) - nginx -V - - prove -r t + - prove -I. -r t diff --git a/t/sanity.t b/t/sanity.t index d05d1fa..94af304 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -332,7 +332,7 @@ GET /test upstream backend { drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql dbname=ngx_test user=ngx_test password=ngx_test - charset=utf8; + charset=utf8mb4; } --- config @@ -358,7 +358,7 @@ GET /test {"errcode":0} {"errcode":0} {"errcode":0,"insert_id":1,"affected_rows":1} -[{"id":1,"body":"a\r\nb\b??\u001a"}] +[{"id":1,"body":"a\r\nb\b你好\u001a"}] --- timeout: 5 From dfbad7cbaed23dd6ffb739a133ff5db514e92329 Mon Sep 17 00:00:00 2001 From: Johnny Wang Date: Sun, 9 Jan 2022 21:40:20 +0800 Subject: [PATCH 63/72] travis-ci: upgrade version number of NGINX core, remove clang compiler mode from travis to save credits. (#19) From 47c8f3c45914fe3e0a87cf9b926c530ebaa38646 Mon Sep 17 00:00:00 2001 From: Pavlo Bashynskyi Date: Thu, 13 Jan 2022 07:41:32 +0200 Subject: [PATCH 64/72] feature: this module can now be compiled as a dynamic module with NGINX (#17) Co-authored-by: lijunlong --- README.md | 8 ++++++++ config | 31 ++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f13e827..5ba6455 100644 --- a/README.md +++ b/README.md @@ -283,6 +283,14 @@ the version 1.13.6 (see [nginx compatibility](#compatibility)), and then build t Download the latest version of the release tarball of this module from [rds-json-nginx-module file list](https://github.com/openresty/rds-json-nginx-module/tags). +Starting from NGINX 1.9.11, you can also compile this module as a dynamic module, by using the `--add-dynamic-module=PATH` option +instead of `--add-module=PATH` on the `./configure` command line above. +And then you can explicitly load the module in your `nginx.conf` via the [load_module](http://nginx.org/en/docs/ngx_core_module.html#load_module) directive, for example, + +```nginx +load_module /path/to/modules/ngx_http_rds_json_filter_module.so; +``` + Also, this module is included and enabled by default in the [OpenResty bundle](http://openresty.org). [Back to TOC](#table-of-contents) diff --git a/config b/config index f9f65d5..d6c0f89 100644 --- a/config +++ b/config @@ -1,5 +1,30 @@ ngx_addon_name=ngx_http_rds_json_filter_module -HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_rds_json_filter_module" -NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_rds_json_filter_module.c $ngx_addon_dir/src/ngx_http_rds_json_processor.c $ngx_addon_dir/src/ngx_http_rds_json_util.c $ngx_addon_dir/src/ngx_http_rds_json_output.c $ngx_addon_dir/src/ngx_http_rds_json_handler.c" -NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/resty_dbd_stream.h $ngx_addon_dir/src/ngx_http_rds_json_filter_module.h $ngx_addon_dir/src/ngx_http_rds_json_processor.h $ngx_addon_dir/src/ngx_http_rds_json_util.h $ngx_addon_dir/src/ngx_http_rds.h $ngx_addon_dir/src/resty_dbd_stream.h $ngx_addon_dir/src/ngx_http_rds_json_output.h $ngx_addon_dir/src/ngx_http_rds_utils.h $ngx_addon_dir/src/ngx_http_rds_json_handler.h" +RDS_JSON_FILTER_SRCS=" \ + $ngx_addon_dir/src/ngx_http_rds_json_filter_module.c \ + $ngx_addon_dir/src/ngx_http_rds_json_processor.c \ + $ngx_addon_dir/src/ngx_http_rds_json_util.c \ + $ngx_addon_dir/src/ngx_http_rds_json_output.c \ + $ngx_addon_dir/src/ngx_http_rds_json_handler.c \ + " + +RDS_JSON_FILTER_DEPS=" \ + $ngx_addon_dir/src/ddebug.h \ + $ngx_addon_dir/src/resty_dbd_stream.h \ + $ngx_addon_dir/src/ngx_http_rds_json_filter_module.h \ + $ngx_addon_dir/src/ngx_http_rds_json_processor.h \ + $ngx_addon_dir/src/ngx_http_rds_json_util.h \ + $ngx_addon_dir/src/ngx_http_rds.h \ + $ngx_addon_dir/src/resty_dbd_stream.h \ + $ngx_addon_dir/src/ngx_http_rds_json_output.h \ + $ngx_addon_dir/src/ngx_http_rds_utils.h \ + $ngx_addon_dir/src/ngx_http_rds_json_handler.h \ + " + + +ngx_module_type=HTTP_AUX_FILTER +ngx_module_name=$ngx_addon_name +ngx_module_srcs="$RDS_JSON_FILTER_SRCS" +ngx_module_deps="$RDS_JSON_FILTER_DEPS" + +. auto/module From 4572b71ad19370a63c299eabecdc1d4ecb3ce43c Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Tue, 24 May 2022 20:40:17 +0500 Subject: [PATCH 65/72] tests: enable daily coverity scan (#22) --- .github/workflows/coverity.yml | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/coverity.yml diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml new file mode 100644 index 0000000..595a4c1 --- /dev/null +++ b/.github/workflows/coverity.yml @@ -0,0 +1,68 @@ +name: Coverity + +on: + schedule: + - cron: "0 0 * * *" + +jobs: + scan: + runs-on: ubuntu-18.04 + if: ${{ github.repository_owner == 'openresty' }} + env: + COVERITY_SCAN_PROJECT_NAME: 'rds-json-nginx-module' + COVERITY_SCAN_BRANCH_PATTERN: '*' + COVERITY_SCAN_NOTIFICATION_EMAIL: 'chipitsine@gmail.com' + LUAJIT_PREFIX: '/opt/luajit21' + LUAJIT_LIB: '/opt/luajit21/lib' + LUAJIT_INC: '/opt/luajit21/include/luajit-2.1' + LUA_INCLUDE_DIR: '/opt/luajit21/include/luajit-2.1' + LUA_CMODULE_DIR: '/lib' + JOBS: 3 + NGX_BUILD_JOBS: 3 + NGINX_VERSION: 1.19.9 + CC: gcc + steps: + - uses: actions/checkout@v3 + - name: Install apt dependencies + run: | + sudo apt-get update + sudo apt-get install -y axel libgd-dev + - name: clone OpenResty satellites + run: | + git clone https://github.com/openresty/nginx-devel-utils.git + git clone https://github.com/openresty/openresty.git ../openresty + git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx + git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module + git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module + git clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core + git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache + git clone https://github.com/openresty/nginx-eval-module.git ../eval-nginx-module + git clone https://github.com/openresty/xss-nginx-module.git ../xss-nginx-module + git clone https://github.com/openresty/set-misc-nginx-module.git ../set-misc-nginx-module + git clone https://github.com/openresty/headers-more-nginx-module.git ../headers-more-nginx-module + git clone https://github.com/openresty/drizzle-nginx-module.git ../drizzle-nginx-module + git clone https://github.com/calio/form-input-nginx-module.git ../form-input-nginx-module + git clone https://github.com/openresty/ngx_postgres.git ../postgres-nginx-module + git clone https://github.com/openresty/openresty.git ../ngx_openresty + git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module + git clone https://github.com/openresty/array-var-nginx-module.git ../array-var-nginx-module + - name: Install libdrizzle + run: | + wget http://openresty.org/download/drizzle7-2011.07.21.tar.gz + tar xzf drizzle7-2011.07.21.tar.gz && cd drizzle7-2011.07.21 + ./configure --prefix=/usr --without-server + sudo PATH=$PATH make libdrizzle-1.0 install-libdrizzle-1.0 + - name: Install luajit2 + run: | + git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git + cd luajit2 + make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT' + sudo make install PREFIX=$LUAJIT_PREFIX + - name: Run Coverity Scan + env: + COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} + run: | + export COVERITY_SCAN_BUILD_COMMAND="sh util/build.sh $NGINX_VERSION" + export PATH=$PWD/work/nginx/sbin:$PWD/nginx-devel-utils:$PATH + export NGX_BUILD_CC=gcc + curl -fsSL "https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh" | bash || true From 9f9690f59afaacfd52a6ca89556b339a2ae0af86 Mon Sep 17 00:00:00 2001 From: Johnny Wang Date: Thu, 19 Jan 2023 15:28:47 +0800 Subject: [PATCH 66/72] style: remove trailing space. --- config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config b/config index d6c0f89..5ebf3b2 100644 --- a/config +++ b/config @@ -26,5 +26,5 @@ ngx_module_type=HTTP_AUX_FILTER ngx_module_name=$ngx_addon_name ngx_module_srcs="$RDS_JSON_FILTER_SRCS" ngx_module_deps="$RDS_JSON_FILTER_DEPS" - + . auto/module From c784adb5bfb6f500ce0f8cf5cb8b8f03e27ead8f Mon Sep 17 00:00:00 2001 From: lijunlong Date: Sat, 18 Nov 2023 21:02:15 +0800 Subject: [PATCH 67/72] tests: update nginx to 1.25.1. --- .travis.yml | 18 +++++++++++------- util/build.sh | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6dd3823..5bf28d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,11 @@ sudo: required -dist: bionic +dist: focal os: linux +branches: + only: + - "master" language: c addons: @@ -17,6 +20,7 @@ addons: - libtest-longstring-perl - liblist-moreutils-perl - libgd-dev + postgresql: "13" cache: apt: true @@ -35,19 +39,19 @@ env: - LUA_INCLUDE_DIR=$LUAJIT_INC - LUA_CMODULE_DIR=/lib - JOBS=3 + - DRIZZLE_VER=2011.07.21 - NGX_BUILD_JOBS=$JOBS - TEST_NGINX_SLEEP=0.006 matrix: - - NGINX_VERSION=1.17.8 - - NGINX_VERSION=1.19.9 + - NGINX_VERSION=1.25.1 NGX_EXTRA_OPT=--without-pcre2 services: - mysql - postgresql install: - - if [ ! -f download-cache/drizzle7-2011.07.21.tar.gz ]; then wget -P download-cache/ http://openresty.org/download/drizzle7-2011.07.21.tar.gz; fi - - git clone https://github.com/openresty/nginx-devel-utils.git + - if [ ! -f download-cache/drizzle7-$DRIZZLE_VER.tar.gz ]; then wget -P download-cache https://github.com/openresty/openresty-deps-prebuild/releases/download/v20230902/drizzle7-$DRIZZLE_VER.tar.gz; fi + - git clone https://github.com/openresty/openresty-devel-utils.git - git clone https://github.com/openresty/openresty.git ../openresty - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx - git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module @@ -67,7 +71,7 @@ install: - git clone https://github.com/openresty/openresty.git ../ngx_openresty before_script: - - mysql -uroot -e 'create database ngx_test; grant all on ngx_test.* to "ngx_test"@"%" identified by "ngx_test"; flush privileges;' + - mysql -uroot -e "create database ngx_test; CREATE USER 'ngx_test'@'%' IDENTIFIED WITH mysql_native_password BY 'ngx_test'; grant all on ngx_test.* to 'ngx_test'@'%'; flush privileges;" - mysql -uroot -e 'alter database ngx_test character set utf8mb4 collate utf8mb4_unicode_ci;' - psql -c "create database ngx_test;" -U postgres - psql -c "create user ngx_test with password 'ngx_test';" -U postgres @@ -81,7 +85,7 @@ script: - make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT' > build.log 2>&1 || (cat build.log && exit 1) - sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1) - cd ../test-nginx && sudo cpanm . && cd .. - - export PATH=$PWD/work/nginx/sbin:$PWD/nginx-devel-utils:$PATH + - export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:$PATH - export NGX_BUILD_CC=$CC - sh util/build.sh $NGINX_VERSION > build.log 2>&1 || (cat build.log && exit 1) - nginx -V diff --git a/util/build.sh b/util/build.sh index ff093db..630a3eb 100755 --- a/util/build.sh +++ b/util/build.sh @@ -10,17 +10,18 @@ force=$2 ngx-build $force $version \ --with-cc-opt="-O1" \ - --with-ld-opt="-Wl,-rpath,/opt/drizzle/lib:/opt/pg9/lib" \ - --without-mail_pop3_module \ - --without-mail_imap_module \ - --without-mail_smtp_module \ - --without-http_upstream_ip_hash_module \ - --without-http_empty_gif_module \ - --without-http_memcached_module \ - --without-http_referer_module \ - --without-http_autoindex_module \ - --without-http_auth_basic_module \ - --without-http_userid_module \ + $NGX_EXTRA_OPT \ + --with-ld-opt="-Wl,-rpath,/opt/drizzle/lib:/opt/pg9/lib" \ + --without-mail_pop3_module \ + --without-mail_imap_module \ + --without-mail_smtp_module \ + --without-http_upstream_ip_hash_module \ + --without-http_empty_gif_module \ + --without-http_memcached_module \ + --without-http_referer_module \ + --without-http_autoindex_module \ + --without-http_auth_basic_module \ + --without-http_userid_module \ --add-module=$root/../eval-nginx-module \ --add-module=$root/../echo-nginx-module \ --add-module=$root/../xss-nginx-module \ From e4fb76a93e170b05f9382436683d556a727e80d2 Mon Sep 17 00:00:00 2001 From: lijunlong Date: Thu, 23 Nov 2023 19:41:58 +0800 Subject: [PATCH 68/72] tests: update nginx to 1.25.3. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5bf28d9..b48e080 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ env: - NGX_BUILD_JOBS=$JOBS - TEST_NGINX_SLEEP=0.006 matrix: - - NGINX_VERSION=1.25.1 NGX_EXTRA_OPT=--without-pcre2 + - NGINX_VERSION=1.25.3 NGX_EXTRA_OPT=--without-pcre2 services: - mysql From 07941c9224c6066b42d0e827c94a7e48d1ebe4b8 Mon Sep 17 00:00:00 2001 From: lijunlong Date: Sun, 26 May 2024 21:36:13 +0800 Subject: [PATCH 69/72] bugfix: failed to compilation on rocky-9. Error: implicit truncation from 'unsigned int' to a one-bit wide bit-field changes value from 1 to -1 --- src/ngx_http_rds_json_filter_module.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.h b/src/ngx_http_rds_json_filter_module.h index 18019b6..9ad044d 100644 --- a/src/ngx_http_rds_json_filter_module.h +++ b/src/ngx_http_rds_json_filter_module.h @@ -106,9 +106,9 @@ typedef struct { uint32_t field_data_rest; - ngx_flag_t header_sent:1; - ngx_flag_t seen_stream_end:1; - ngx_flag_t generated_col_names:1; + ngx_uint_t header_sent:1; + ngx_uint_t seen_stream_end:1; + ngx_uint_t generated_col_names:1; } ngx_http_rds_json_ctx_t; From 2d7e07f7c39f98bbb2a8b07f4bae4d892f00329d Mon Sep 17 00:00:00 2001 From: Johnny Wang Date: Thu, 8 Aug 2024 23:54:59 +0800 Subject: [PATCH 70/72] tests: bumped the NGINX core to 1.27.0. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b48e080..6818b44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ env: - NGX_BUILD_JOBS=$JOBS - TEST_NGINX_SLEEP=0.006 matrix: - - NGINX_VERSION=1.25.3 NGX_EXTRA_OPT=--without-pcre2 + - NGINX_VERSION=1.27.0 NGX_EXTRA_OPT=--without-pcre2 services: - mysql From 476bfd12d4da50dabe54bade9bf44deda2de3cfe Mon Sep 17 00:00:00 2001 From: lijunlong Date: Sat, 17 Aug 2024 20:07:53 +0800 Subject: [PATCH 71/72] feature: update nginx to .1.27.1. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6818b44..7b6efa7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ env: - NGX_BUILD_JOBS=$JOBS - TEST_NGINX_SLEEP=0.006 matrix: - - NGINX_VERSION=1.27.0 NGX_EXTRA_OPT=--without-pcre2 + - NGINX_VERSION=1.27.1 NGX_EXTRA_OPT=--without-pcre2 services: - mysql From e6517b9f939748ccb153f661d97595f749e51670 Mon Sep 17 00:00:00 2001 From: Johnny Wang Date: Sat, 17 Aug 2024 20:35:58 +0800 Subject: [PATCH 72/72] tests: bumped the NGINX core to 1.27.1.