From f243b0dc21952c1c0ea68a359a65027e3ebd7597 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Sat, 30 Apr 2016 12:25:30 +0000 Subject: [PATCH 1/3] building as dynamic module support --- config | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/config b/config index f9f65d5..e900306 100644 --- a/config +++ b/config @@ -1,5 +1,15 @@ ngx_addon_name=ngx_http_rds_json_filter_module + +if test -n "$ngx_module_link"; then + $ngx_addon_dir/src/ngx_http_rds_json_output.c $ngx_addon_dir/src/ngx_http_rds_json_handler.c" + $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 + ngx_module_name=ngx_http_rds_json_filter_module + ngx_module_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" + . auto/module +else 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" - +fi From 04c3f25b207994726df9b476d733587e670bbf93 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Sat, 30 Apr 2016 13:35:55 +0000 Subject: [PATCH 2/3] apply pull 4 --- src/ngx_http_rds_json_filter_module.c | 19 ++++++++++++++++++- src/ngx_http_rds_json_filter_module.h | 12 ++++++++++-- src/ngx_http_rds_json_processor.c | 9 +++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 1a26583..729c7fa 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -243,6 +243,7 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) ctx->tag = (ngx_buf_tag_t) &ngx_http_rds_json_filter_module; ctx->state = state_expect_header; + ctx->handler = ngx_http_rds_json_process_header; ctx->header_sent = 0; @@ -299,6 +300,22 @@ 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"); + if (ctx->handler) { + rc = ctx->handler(r, in, ctx); + } else { + /* status done */ + + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "rds json body filter discarding unexpected trailing buffers"); + + /* mark the remaining bufs as consumed */ + + ngx_http_rds_json_discard_bufs(r->pool, in); + + return NGX_OK; + } + +#if 0 switch (ctx->state) { case state_expect_header: rc = ngx_http_rds_json_process_header(r, in, ctx); @@ -341,7 +358,7 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) break; } - +#endif dd("body filter rc: %d", (int) rc); if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) { diff --git a/src/ngx_http_rds_json_filter_module.h b/src/ngx_http_rds_json_filter_module.h index 18019b6..db80c8a 100644 --- a/src/ngx_http_rds_json_filter_module.h +++ b/src/ngx_http_rds_json_filter_module.h @@ -78,7 +78,12 @@ typedef enum { } ngx_http_rds_json_state_t; -typedef struct { +typedef struct ngx_http_rds_json_ctx_s ngx_http_rds_json_ctx_t; + +typedef ngx_int_t (*rds_json_process_handler_pt)(ngx_http_request_t *r, + ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx); + +struct ngx_http_rds_json_ctx_s { ngx_http_rds_json_state_t state; ngx_str_t *col_name; @@ -106,10 +111,13 @@ typedef struct { uint32_t field_data_rest; + rds_json_process_handler_pt handler; + ngx_flag_t header_sent:1; ngx_flag_t seen_stream_end:1; ngx_flag_t generated_col_names:1; -} ngx_http_rds_json_ctx_t; +}; + #endif /* 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 9a242f3..628f21c 100644 --- a/src/ngx_http_rds_json_processor.c +++ b/src/ngx_http_rds_json_processor.c @@ -73,6 +73,7 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, } ctx->state = state_done; + ctx->handler = NULL; /* now we send the postponed response header */ if (!ctx->header_sent) { @@ -104,6 +105,7 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, } ctx->state = state_expect_col; + ctx->handler = ngx_http_rds_json_process_col; ctx->cur_col = 0; ctx->col_count = header.col_count; @@ -189,6 +191,7 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, ngx_chain_t *in, dd("end of column list"); ctx->state = state_expect_row; + ctx->handler = ngx_http_rds_json_process_row; ctx->row = 0; dd("output \"[\""); @@ -285,6 +288,7 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in, if (*b->pos++ == 0) { /* end of row list */ ctx->state = state_done; + ctx->handler = NULL; if (b->pos != b->last) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, @@ -318,6 +322,7 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in, ctx->row++; ctx->cur_col = 0; ctx->state = state_expect_field; + ctx->handler = ngx_http_rds_json_process_field; if (b->pos == b->last) { in = in->next; @@ -417,6 +422,7 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in, dd("process field: need to read more field data"); ctx->state = state_expect_more_field_data; + ctx->handler = ngx_http_rds_json_process_more_field_data; return ngx_http_rds_json_process_more_field_data(r, in, ctx); } @@ -427,6 +433,7 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in, dd("reached the end of the current row"); ctx->state = state_expect_row; + ctx->handler = ngx_http_rds_json_process_row; return ngx_http_rds_json_process_row(r, in, ctx); } @@ -494,6 +501,7 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, dd("process more field data: reached the end of the current row"); ctx->state = state_expect_row; + ctx->handler = ngx_http_rds_json_process_row; return ngx_http_rds_json_process_row(r, in, ctx); } @@ -501,6 +509,7 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, dd("proces more field data: read the next field"); ctx->state = state_expect_field; + ctx->handler = ngx_http_rds_json_process_field; return ngx_http_rds_json_process_field(r, in, ctx); } From 09532903a919179de6cb595dbd56446148afc2cd Mon Sep 17 00:00:00 2001 From: Anonymous Date: Wed, 4 May 2016 07:52:06 +0000 Subject: [PATCH 3/3] Revert "apply pull 4" This reverts commit 04c3f25b207994726df9b476d733587e670bbf93. --- src/ngx_http_rds_json_filter_module.c | 19 +------------------ src/ngx_http_rds_json_filter_module.h | 12 ++---------- src/ngx_http_rds_json_processor.c | 9 --------- 3 files changed, 3 insertions(+), 37 deletions(-) diff --git a/src/ngx_http_rds_json_filter_module.c b/src/ngx_http_rds_json_filter_module.c index 729c7fa..1a26583 100644 --- a/src/ngx_http_rds_json_filter_module.c +++ b/src/ngx_http_rds_json_filter_module.c @@ -243,7 +243,6 @@ ngx_http_rds_json_header_filter(ngx_http_request_t *r) ctx->tag = (ngx_buf_tag_t) &ngx_http_rds_json_filter_module; ctx->state = state_expect_header; - ctx->handler = ngx_http_rds_json_process_header; ctx->header_sent = 0; @@ -300,22 +299,6 @@ 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"); - if (ctx->handler) { - rc = ctx->handler(r, in, ctx); - } else { - /* status done */ - - ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "rds json body filter discarding unexpected trailing buffers"); - - /* mark the remaining bufs as consumed */ - - ngx_http_rds_json_discard_bufs(r->pool, in); - - return NGX_OK; - } - -#if 0 switch (ctx->state) { case state_expect_header: rc = ngx_http_rds_json_process_header(r, in, ctx); @@ -358,7 +341,7 @@ ngx_http_rds_json_body_filter(ngx_http_request_t *r, ngx_chain_t *in) break; } -#endif + dd("body filter rc: %d", (int) rc); if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) { diff --git a/src/ngx_http_rds_json_filter_module.h b/src/ngx_http_rds_json_filter_module.h index db80c8a..18019b6 100644 --- a/src/ngx_http_rds_json_filter_module.h +++ b/src/ngx_http_rds_json_filter_module.h @@ -78,12 +78,7 @@ typedef enum { } ngx_http_rds_json_state_t; -typedef struct ngx_http_rds_json_ctx_s ngx_http_rds_json_ctx_t; - -typedef ngx_int_t (*rds_json_process_handler_pt)(ngx_http_request_t *r, - ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx); - -struct ngx_http_rds_json_ctx_s { +typedef struct { ngx_http_rds_json_state_t state; ngx_str_t *col_name; @@ -111,13 +106,10 @@ struct ngx_http_rds_json_ctx_s { uint32_t field_data_rest; - rds_json_process_handler_pt handler; - ngx_flag_t header_sent:1; ngx_flag_t seen_stream_end:1; ngx_flag_t generated_col_names:1; -}; - +} ngx_http_rds_json_ctx_t; #endif /* 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 628f21c..9a242f3 100644 --- a/src/ngx_http_rds_json_processor.c +++ b/src/ngx_http_rds_json_processor.c @@ -73,7 +73,6 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, } ctx->state = state_done; - ctx->handler = NULL; /* now we send the postponed response header */ if (!ctx->header_sent) { @@ -105,7 +104,6 @@ ngx_http_rds_json_process_header(ngx_http_request_t *r, } ctx->state = state_expect_col; - ctx->handler = ngx_http_rds_json_process_col; ctx->cur_col = 0; ctx->col_count = header.col_count; @@ -191,7 +189,6 @@ ngx_http_rds_json_process_col(ngx_http_request_t *r, ngx_chain_t *in, dd("end of column list"); ctx->state = state_expect_row; - ctx->handler = ngx_http_rds_json_process_row; ctx->row = 0; dd("output \"[\""); @@ -288,7 +285,6 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in, if (*b->pos++ == 0) { /* end of row list */ ctx->state = state_done; - ctx->handler = NULL; if (b->pos != b->last) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, @@ -322,7 +318,6 @@ ngx_http_rds_json_process_row(ngx_http_request_t *r, ngx_chain_t *in, ctx->row++; ctx->cur_col = 0; ctx->state = state_expect_field; - ctx->handler = ngx_http_rds_json_process_field; if (b->pos == b->last) { in = in->next; @@ -422,7 +417,6 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in, dd("process field: need to read more field data"); ctx->state = state_expect_more_field_data; - ctx->handler = ngx_http_rds_json_process_more_field_data; return ngx_http_rds_json_process_more_field_data(r, in, ctx); } @@ -433,7 +427,6 @@ ngx_http_rds_json_process_field(ngx_http_request_t *r, ngx_chain_t *in, dd("reached the end of the current row"); ctx->state = state_expect_row; - ctx->handler = ngx_http_rds_json_process_row; return ngx_http_rds_json_process_row(r, in, ctx); } @@ -501,7 +494,6 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, dd("process more field data: reached the end of the current row"); ctx->state = state_expect_row; - ctx->handler = ngx_http_rds_json_process_row; return ngx_http_rds_json_process_row(r, in, ctx); } @@ -509,7 +501,6 @@ ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, dd("proces more field data: read the next field"); ctx->state = state_expect_field; - ctx->handler = ngx_http_rds_json_process_field; return ngx_http_rds_json_process_field(r, in, ctx); }