Skip to content

Commit

Permalink
change: removed compatibility code for unsupported NGINX versions (< …
Browse files Browse the repository at this point in the history
…1.6.0).
  • Loading branch information
thibaultcha committed Aug 5, 2019
1 parent 947fa00 commit c5135a0
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 344 deletions.
5 changes: 0 additions & 5 deletions src/ngx_http_lua_accessby.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ ngx_http_lua_access_handler(ngx_http_request_t *r)
ngx_http_lua_generic_phase_post_read);

if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
#if (nginx_version < 1002006) || \
(nginx_version >= 1003000 && nginx_version < 1003009)
r->main->count--;
#endif

return rc;
}

Expand Down
4 changes: 0 additions & 4 deletions src/ngx_http_lua_bodyfilterby.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,7 @@ ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
return NGX_ERROR;
}

#if nginx_version >= 1001004
ngx_chain_update_chains(r->pool,
#else
ngx_chain_update_chains(
#endif
&ctx->free_bufs, &ctx->busy_bufs, &out,
(ngx_buf_tag_t) &ngx_http_lua_module);

Expand Down
4 changes: 2 additions & 2 deletions src/ngx_http_lua_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#endif

#ifndef NGX_HAVE_SHA1
# if (nginx_version >= 1011002)
# if defined(nginx_version) && (nginx_version >= 1011002)
# define NGX_HAVE_SHA1 1
# endif
#endif
Expand Down Expand Up @@ -256,7 +256,7 @@ struct ngx_http_lua_main_conf_s {
of reqeusts */
ngx_uint_t malloc_trim_req_count;

#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
/* the following 2 fields are only used by ngx.req.raw_headers() for now */
ngx_buf_t **busy_buf_ptrs;
ngx_int_t busy_buf_ptr_count;
Expand Down
2 changes: 0 additions & 2 deletions src/ngx_http_lua_consts.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ ngx_http_lua_inject_http_consts(lua_State *L)
lua_pushinteger(L, NGX_HTTP_MOVED_TEMPORARILY);
lua_setfield(L, -2, "HTTP_MOVED_TEMPORARILY");

#if defined(nginx_version) && nginx_version >= 8042
lua_pushinteger(L, NGX_HTTP_SEE_OTHER);
lua_setfield(L, -2, "HTTP_SEE_OTHER");
#endif

lua_pushinteger(L, NGX_HTTP_PERMANENT_REDIRECT);
lua_setfield(L, -2, "HTTP_PERMANENT_REDIRECT");
Expand Down
4 changes: 0 additions & 4 deletions src/ngx_http_lua_contentby.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ ngx_http_lua_content_handler(ngx_http_request_t *r)
ngx_http_lua_content_phase_post_read);

if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
#if (nginx_version < 1002006) || \
(nginx_version >= 1003000 && nginx_version < 1003009)
r->main->count--;
#endif
return rc;
}

Expand Down
10 changes: 3 additions & 7 deletions src/ngx_http_lua_directive.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,6 @@ ngx_http_lua_rewrite_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

dd("enter");

#if defined(nginx_version) && nginx_version >= 8042 && nginx_version <= 8053
return "does not work with " NGINX_VER;
#endif

/* must specify a content handler */
if (cmd->post == NULL) {
return NGX_CONF_ERROR;
Expand Down Expand Up @@ -1437,12 +1433,12 @@ ngx_http_lua_conf_read_lua_token(ngx_conf_t *cf,
ngx_uint_t start_line;
ngx_str_t *word;
ngx_buf_t *b;
#if nginx_version >= 1009002
#if defined(nginx_version) && (nginx_version >= 1009002)
ngx_buf_t *dump;
#endif

b = cf->conf_file->buffer;
#if nginx_version >= 1009002
#if defined(nginx_version) && (nginx_version >= 1009002)
dump = cf->conf_file->dump;
#endif
start = b->pos;
Expand Down Expand Up @@ -1513,7 +1509,7 @@ ngx_http_lua_conf_read_lua_token(ngx_conf_t *cf,
b->last = b->start + len + n;
start = b->start;

#if nginx_version >= 1009002
#if defined(nginx_version) && (nginx_version >= 1009002)
if (dump) {
dump->last = ngx_cpymem(dump->last, b->start + len, size);
}
Expand Down
16 changes: 8 additions & 8 deletions src/ngx_http_lua_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int ngx_http_lua_ngx_req_raw_header(lua_State *L);
static int ngx_http_lua_ngx_req_header_set_helper(lua_State *L);
static int ngx_http_lua_ngx_resp_get_headers(lua_State *L);
static int ngx_http_lua_ngx_req_header_set(lua_State *L);
#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
void ngx_http_lua_ngx_raw_header_cleanup(void *data);
#endif

Expand Down Expand Up @@ -102,7 +102,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
size_t size;
ngx_buf_t *b, *first = NULL;
ngx_int_t i, j;
#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
ngx_buf_t **bb;
ngx_chain_t *cl;
ngx_http_lua_main_conf_t *lmcf;
Expand All @@ -123,7 +123,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
return luaL_error(L, "no request object found");
}

#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
#endif

Expand All @@ -143,7 +143,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
dd("hc->nbusy: %d", (int) hc->nbusy);

if (hc->nbusy) {
#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
dd("hc->busy: %p %p %p %p", hc->busy->buf->start, hc->busy->buf->pos,
hc->busy->buf->last, hc->busy->buf->end);
#else
Expand Down Expand Up @@ -185,7 +185,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
dd("size: %d", (int) size);

if (hc->nbusy) {
#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
if (hc->nbusy > lmcf->busy_buf_ptr_count) {
if (lmcf->busy_buf_ptrs) {
ngx_free(lmcf->busy_buf_ptrs);
Expand All @@ -208,7 +208,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
#endif
b = NULL;

#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
bb = lmcf->busy_buf_ptrs;
for (i = hc->nbusy; i > 0; i--) {
b = bb[i - 1];
Expand Down Expand Up @@ -291,7 +291,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)

if (hc->nbusy) {

#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
bb = lmcf->busy_buf_ptrs;
for (i = hc->nbusy - 1; i >= 0; i--) {
b = bb[i];
Expand Down Expand Up @@ -1138,7 +1138,7 @@ ngx_http_lua_ffi_get_resp_header(ngx_http_request_t *r,
}


#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
void
ngx_http_lua_ngx_raw_header_cleanup(void *data)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ngx_http_lua_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
void ngx_http_lua_inject_resp_header_api(lua_State *L);
void ngx_http_lua_inject_req_header_api(lua_State *L);
void ngx_http_lua_create_headers_metatable(ngx_log_t *log, lua_State *L);
#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
void ngx_http_lua_ngx_raw_header_cleanup(void *data);
#endif

Expand Down
6 changes: 0 additions & 6 deletions src/ngx_http_lua_headers_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,17 @@ static ngx_http_lua_set_header_t ngx_http_lua_set_handlers[] = {
offsetof(ngx_http_headers_in_t, if_modified_since),
ngx_http_set_builtin_header },

#if defined(nginx_version) && nginx_version >= 9002
{ ngx_string("If-Unmodified-Since"),
offsetof(ngx_http_headers_in_t, if_unmodified_since),
ngx_http_set_builtin_header },
#endif

#if defined(nginx_version) && nginx_version >= 1003003
{ ngx_string("If-Match"),
offsetof(ngx_http_headers_in_t, if_match),
ngx_http_set_builtin_header },

{ ngx_string("If-None-Match"),
offsetof(ngx_http_headers_in_t, if_none_match),
ngx_http_set_builtin_header },
#endif

{ ngx_string("User-Agent"),
offsetof(ngx_http_headers_in_t, user_agent),
Expand Down Expand Up @@ -104,11 +100,9 @@ static ngx_http_lua_set_header_t ngx_http_lua_set_handlers[] = {
offsetof(ngx_http_headers_in_t, expect),
ngx_http_set_builtin_header },

#if defined(nginx_version) && nginx_version >= 1003013
{ ngx_string("Upgrade"),
offsetof(ngx_http_headers_in_t, upgrade),
ngx_http_set_builtin_header },
#endif

#if (NGX_HTTP_GZIP)
{ ngx_string("Accept-Encoding"),
Expand Down
27 changes: 2 additions & 25 deletions src/ngx_http_lua_initworkerby.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,8 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)

ngx_memcpy(fake_cycle, cycle, sizeof(ngx_cycle_t));

#if defined(nginx_version) && nginx_version >= 9007

ngx_queue_init(&fake_cycle->reusable_connections_queue);

#endif

if (ngx_array_init(&fake_cycle->listening, cycle->pool,
cycle->listening.nelts || 1,
sizeof(ngx_listening_t))
Expand All @@ -128,17 +124,13 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)
goto failed;
}

#if defined(nginx_version) && nginx_version >= 1003007

if (ngx_array_init(&fake_cycle->paths, cycle->pool, cycle->paths.nelts || 1,
sizeof(ngx_path_t *))
!= NGX_OK)
{
goto failed;
}

#endif

part = &cycle->open_files.part;
ofile = part->elts;

Expand Down Expand Up @@ -302,26 +294,11 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)

clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

#if defined(nginx_version) && nginx_version >= 1003014

# if nginx_version >= 1009000

#if defined(nginx_version) && (nginx_version >= 1009000)
ngx_set_connection_log(r->connection, clcf->error_log);

# else

ngx_http_set_connection_log(r->connection, clcf->error_log);

# endif

#else

c->log->file = clcf->error_log->file;

if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
c->log->log_level = clcf->error_log->log_level;
}

ngx_http_set_connection_log(r->connection, clcf->error_log);
#endif

ctx = ngx_http_lua_create_ctx(r);
Expand Down
39 changes: 9 additions & 30 deletions src/ngx_http_lua_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static ngx_conf_post_t ngx_http_lua_lowat_post =
static volatile ngx_cycle_t *ngx_http_lua_prev_cycle = NULL;


#if (NGX_HTTP_SSL) && defined(nginx_version) && nginx_version >= 1001013
#if (NGX_HTTP_SSL)

static ngx_conf_bitmask_t ngx_http_lua_ssl_protocols[] = {
{ ngx_string("SSLv2"), NGX_SSL_SSLv2 },
Expand Down Expand Up @@ -515,17 +515,13 @@ static ngx_command_t ngx_http_lua_cmds[] = {

#if (NGX_HTTP_SSL)

# if defined(nginx_version) && nginx_version >= 1001013

{ ngx_string("lua_ssl_protocols"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
ngx_conf_set_bitmask_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_lua_loc_conf_t, ssl_protocols),
&ngx_http_lua_ssl_protocols },

# endif

{ ngx_string("lua_ssl_ciphers"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
Expand Down Expand Up @@ -650,7 +646,7 @@ ngx_http_lua_init(ngx_conf_t *cf)
volatile ngx_cycle_t *saved_cycle;
ngx_http_core_main_conf_t *cmcf;
ngx_http_lua_main_conf_t *lmcf;
#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
ngx_pool_cleanup_t *cln;
#endif
ngx_str_t name = ngx_string("host");
Expand Down Expand Up @@ -754,7 +750,7 @@ ngx_http_lua_init(ngx_conf_t *cf)
ngx_http_lua_pipe_init();
#endif

#if nginx_version >= 1011011
#if defined(nginx_version) && (nginx_version >= 1011011)
cln = ngx_pool_cleanup_add(cf->pool, 0);
if (cln == NULL) {
return NGX_ERROR;
Expand Down Expand Up @@ -1232,15 +1228,11 @@ ngx_http_lua_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)

#if (NGX_HTTP_SSL)

# if defined(nginx_version) && nginx_version >= 1001013

ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
(NGX_CONF_BITMASK_SET|NGX_SSL_SSLv3
|NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
|NGX_SSL_TLSv1_2));

# endif

ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
"DEFAULT");

Expand Down Expand Up @@ -1328,26 +1320,13 @@ ngx_http_lua_set_ssl(ngx_conf_t *cf, ngx_http_lua_loc_conf_t *llcf)
return NGX_ERROR;
}

if (llcf->ssl_trusted_certificate.len) {

#if defined(nginx_version) && nginx_version >= 1003007

if (ngx_ssl_trusted_certificate(cf, llcf->ssl,
&llcf->ssl_trusted_certificate,
llcf->ssl_verify_depth)
!= NGX_OK)
{
return NGX_ERROR;
}

#else

ngx_log_error(NGX_LOG_CRIT, cf->log, 0, "at least nginx 1.3.7 is "
"required for the \"lua_ssl_trusted_certificate\" "
"directive");
if (llcf->ssl_trusted_certificate.len
&& ngx_ssl_trusted_certificate(cf, llcf->ssl,
&llcf->ssl_trusted_certificate,
llcf->ssl_verify_depth)
!= NGX_OK)
{
return NGX_ERROR;

#endif
}

dd("ssl crl: %.*s", (int) llcf->ssl_crl.len, llcf->ssl_crl.data);
Expand Down
8 changes: 0 additions & 8 deletions src/ngx_http_lua_req_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ ngx_http_lua_ngx_req_read_body(lua_State *L)

rc = ngx_http_read_client_request_body(r, ngx_http_lua_req_body_post_read);

#if (nginx_version < 1002006) || \
(nginx_version >= 1003000 && nginx_version < 1003009)
r->main->count--;
#endif

if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
ctx->exit_code = rc;
ctx->exited = 1;
Expand All @@ -130,11 +125,8 @@ ngx_http_lua_ngx_req_read_body(lua_State *L)
return lua_yield(L, 0);
}

#if (nginx_version >= 1002006 && nginx_version < 1003000) || \
nginx_version >= 1003009
r->main->count--;
dd("decrement r->main->count: %d", (int) r->main->count);
#endif

if (rc == NGX_AGAIN) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Expand Down
Loading

0 comments on commit c5135a0

Please sign in to comment.