~ubuntu-branches/ubuntu/trusty/nginx/trusty-updates

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/src/ngx_http_lua_util.c

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry, Cyril Lavier, Michael Lustfield, Kartik Mistry
  • Date: 2012-05-14 11:15:00 UTC
  • mfrom: (4.2.49 sid)
  • Revision ID: package-import@ubuntu.com-20120514111500-1y9ij7zulu9xnmry
Tags: 1.2.0-1
[Cyril Lavier]
* New upstream release. (Closes: #670306)
  + 1.2.x is stable release now.
* debian/modules/chunkin-nginx-module:
  + Updated chunkin-nginx-module to v0.23rc2-3-g85eca98.
* debian/modules/headers-more-module:
  + Updated headers-more-module to v0.17rc1-4-g33a82ed.
* debian/modules/nginx-development-kit:
  + Updated nginx-development-kit to v0.2.17-7-g24202b4.
* debian/modules/nginx-echo:
  + Updated nginx-echo to v0.38rc2-7-g080c0a1.
* debian/modules/nginx-lua:
  + Updated nginx-lua to v0.5.0rc25-5-g8d28785.
* debian/modules/nginx-upstream-fair:
  + Updated nginx-upstream-fair to a18b409.
* debian/modules/nginx-upload-progress:
  + Updated nginx-upload-progress to v0.9.0-0-ga788dea.
* debian/modules/naxsi:
  + Updated naxsi to 0.46
* debian/modules/README.Modules-versions:
  + Updated versions and URLs for modules.
* debian/naxsi-ui-extract, debian/naxsi-ui-intercept,
  debian/nginx-naxsi-ui.*, debian/naxsi-ui-extract.1,
  debian/naxsi-ui-intercept.1, debian/rules:
  + Added nginx-naxsi-ui package containing the learning daemon
    and the WebUI.
* debian/nginx-common.nginx.default, debian/nginx-common.nginx.init:
  + Renamed files to be compliant with the nginx-naxsi-ui package.
* debian/po:
  + Added needed files for using po-debconf.
  + Added French translation.
* debian/control:
  + Applied the modifications given after the review by Justin Rye.

[Michael Lustfield]
* debian/conf/uwsgi_params:
  + Added UWSGI_SCHEME to uwsgi_params. (Closes: #664878)
* debian/conf/sites-available/default:
  + Added allow directive for ipv6 localhost. (Closes: #664271)

[Kartik Mistry]
* debian/control:
  + wrap-and-sort.
* debian/copyright:
  + Added missing copyrights, minor formatting fixes.
* debian/nginx-common.nginx.init:
  + Added ulimit for restarts, Thanks to Daniel Roschka
    <danielroschka@phoenitydawn.de> for patch. (Closes: #673580)
* debian/conf/sites-available/default:
  + Added patch to fix deprecated "listen" directive, Thanks to
    Guillaume Plessis <gui@dotdeb.org> for patch. (Closes: #672632)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "ngx_http_lua_misc.h"
27
27
#include "ngx_http_lua_consts.h"
28
28
#include "ngx_http_lua_shdict.h"
 
29
#include "ngx_http_lua_socket.h"
29
30
 
30
31
 
31
32
static ngx_int_t ngx_http_lua_send_http10_headers(ngx_http_request_t *r,
97
98
 
98
99
    lua_getglobal(L, "package");
99
100
 
100
 
    if (! lua_istable(L, -1)) {
 
101
    if (!lua_istable(L, -1)) {
101
102
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
102
103
                "the \"package\" table does not exist");
103
104
        return NULL;
198
199
        *ref = luaL_ref(L, -2);
199
200
 
200
201
        if (*ref == LUA_NOREF) {
201
 
            lua_settop(L, top);    /*  restore main trhead stack */
 
202
            lua_settop(L, top);  /* restore main thread stack */
202
203
            return NULL;
203
204
        }
204
205
    }
205
206
 
206
 
    /*  pop coroutine refernece on main thread's stack after anchoring it
207
 
     *  in registery */
 
207
    /*  pop coroutine reference on main thread's stack after anchoring it
 
208
     *  in registry */
208
209
    lua_pop(L, 1);
209
210
 
210
211
    return cr;
212
213
 
213
214
 
214
215
void
215
 
ngx_http_lua_del_thread(ngx_http_request_t *r, lua_State *L, int ref,
216
 
        int force_quit)
 
216
ngx_http_lua_del_thread(ngx_http_request_t *r, lua_State *L, int ref)
217
217
{
218
 
    ngx_http_lua_ctx_t  *ctx;
219
 
 
220
218
    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
221
219
            "lua deleting thread");
222
220
 
223
221
    lua_getfield(L, LUA_REGISTRYINDEX, NGX_LUA_CORT_REF);
224
222
 
225
 
    lua_rawgeti(L, -1, ref);
226
 
    lua_State *cr = lua_tothread(L, -1);
227
 
    lua_pop(L, 1);
228
 
 
229
 
    dd("cr: %p, force quit: %d", cr, (int) force_quit);
230
 
 
231
 
    if (cr && force_quit) {
232
 
 
233
 
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
234
 
                       "lua terminate thread forcibly");
235
 
 
236
 
        ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
237
 
        ctx->aborted = 1;
238
 
 
239
 
        /* {{{ save orig code closure's env */
240
 
        lua_getglobal(cr, GLOBALS_SYMBOL_RUNCODE);
241
 
        lua_getfenv(cr, -1);
242
 
        lua_xmove(cr, L, 1);
243
 
        /* }}} */
244
 
 
245
 
        /* {{{ clean code closure's env */
246
 
        lua_newtable(cr);
247
 
        lua_setfenv(cr, -2);
248
 
        /* }}} */
249
 
 
250
 
        /* {{{ blocking run code till ending */
251
 
        do {
252
 
            lua_settop(cr, 0);
253
 
        } while (lua_resume(cr, 0) == LUA_YIELD);
254
 
        /* }}} */
255
 
 
256
 
        /* {{{ restore orig code closure's env */
257
 
        lua_settop(cr, 0);
258
 
        lua_getglobal(cr, GLOBALS_SYMBOL_RUNCODE);
259
 
        lua_xmove(L, cr, 1);
260
 
        lua_setfenv(cr, -2);
261
 
        lua_pop(cr, 1);
262
 
        /* }}} */
263
 
    }
264
 
 
265
223
    /* release reference to coroutine */
266
224
    luaL_unref(L, -1, ref);
267
225
    lua_pop(L, 1);
318
276
{
319
277
    ngx_int_t            rc;
320
278
 
321
 
    if ( ! ctx->headers_sent ) {
 
279
    if (!ctx->headers_sent ) {
322
280
        if (r->headers_out.status == 0) {
323
281
            r->headers_out.status = NGX_HTTP_OK;
324
282
        }
325
283
 
326
 
        if (! ctx->headers_set && ngx_http_set_content_type(r) != NGX_OK) {
 
284
        if (!ctx->headers_set && ngx_http_set_content_type(r) != NGX_OK) {
327
285
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
328
286
        }
329
287
 
330
 
        if (! ctx->headers_set) {
 
288
        if (!ctx->headers_set) {
331
289
            ngx_http_clear_content_length(r);
332
290
            ngx_http_clear_accept_ranges(r);
333
291
        }
334
292
 
335
 
        if (r->http_version >= NGX_HTTP_VERSION_11
336
 
            || r->headers_out.content_length)
337
 
        {
338
 
            /* Send response headers for HTTP version <= 1.0 elsewhere */
 
293
        if (!ctx->buffering) {
339
294
            dd("sending headers");
340
295
            rc = ngx_http_send_header(r);
341
296
            ctx->headers_sent = 1;
351
306
ngx_http_lua_send_chain_link(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
352
307
        ngx_chain_t *in)
353
308
{
354
 
    ngx_int_t            rc;
355
 
    ngx_chain_t         *cl;
356
 
    ngx_chain_t        **ll;
 
309
    ngx_int_t                     rc;
 
310
    ngx_chain_t                  *cl;
 
311
    ngx_chain_t                 **ll;
 
312
    ngx_http_lua_loc_conf_t      *llcf;
357
313
 
358
314
#if 1
359
315
    if (ctx->eof) {
366
322
        r->header_only = 1;
367
323
    }
368
324
 
 
325
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
 
326
 
 
327
    if (llcf->http10_buffering
 
328
        && !ctx->buffering
 
329
        && !ctx->headers_sent
 
330
        && r->http_version < NGX_HTTP_VERSION_11
 
331
        && r->headers_out.content_length_n < 0)
 
332
    {
 
333
        ctx->buffering = 1;
 
334
    }
 
335
 
369
336
    rc = ngx_http_lua_send_header_if_needed(r, ctx);
370
337
 
371
338
    if (rc == NGX_ERROR || rc > NGX_OK) {
375
342
    if (r->header_only) {
376
343
        ctx->eof = 1;
377
344
 
378
 
        if (!ctx->headers_sent && r->http_version < NGX_HTTP_VERSION_11)
379
 
        {
 
345
        if (ctx->buffering) {
380
346
            return ngx_http_lua_send_http10_headers(r, ctx);
381
347
        }
382
348
 
384
350
    }
385
351
 
386
352
    if (in == NULL) {
387
 
        if (!ctx->headers_sent && r->http_version < NGX_HTTP_VERSION_11) {
 
353
        if (ctx->buffering) {
388
354
            rc = ngx_http_lua_send_http10_headers(r, ctx);
389
355
            if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
390
356
                return rc;
426
392
 
427
393
    /* in != NULL */
428
394
 
429
 
    if (r->http_version < NGX_HTTP_VERSION_11 && !ctx->headers_sent) {
 
395
    if (ctx->buffering) {
430
396
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
431
397
                "lua buffering output bufs for the HTTP 1.0 request");
432
398
 
487
453
    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0,
488
454
            "lua initializing lua registry");
489
455
 
490
 
    /* {{{ register table to anchor lua coroutines reliablly:
 
456
    /* {{{ register a table to anchor lua coroutines reliably:
491
457
     * {([int]ref) = [cort]} */
492
458
    lua_newtable(L);
493
459
    lua_setfield(L, LUA_REGISTRYINDEX, NGX_LUA_CORT_REF);
494
460
    /* }}} */
495
461
 
496
 
    /* create registry entry for the Lua request ctx data table */
 
462
    /* create the registry entry for the Lua request ctx data table */
497
463
    lua_newtable(L);
498
464
    lua_setfield(L, LUA_REGISTRYINDEX, NGX_LUA_REQ_CTX_REF);
499
465
 
500
 
    /* create registry entry for the Lua request ctx data table */
 
466
    /* create the registry entry for the Lua socket connection pool table */
 
467
    lua_newtable(L);
 
468
    lua_setfield(L, LUA_REGISTRYINDEX, NGX_LUA_SOCKET_POOL);
 
469
 
 
470
    /* create the registry entry for the Lua precompiled regex object cache */
501
471
    lua_newtable(L);
502
472
    lua_setfield(L, LUA_REGISTRYINDEX, NGX_LUA_REGEX_CACHE);
503
473
 
528
498
    ngx_http_lua_inject_ndk_api(L);
529
499
#endif /* defined(NDK) && NDK */
530
500
 
531
 
    lua_createtable(L, 0 /* narr */, 80 /* nrec */);    /* ngx.* */
 
501
    lua_createtable(L, 0 /* narr */, 87 /* nrec */);    /* ngx.* */
532
502
 
533
503
    ngx_http_lua_inject_internal_utils(cf->log, L);
534
504
 
548
518
    ngx_http_lua_inject_resp_header_api(L);
549
519
    ngx_http_lua_inject_variable_api(L);
550
520
    ngx_http_lua_inject_shdict_api(lmcf, L);
 
521
    ngx_http_lua_inject_socket_api(cf->log, L);
 
522
 
551
523
    ngx_http_lua_inject_misc_api(L);
552
524
 
553
525
    lua_getglobal(L, "package"); /* ngx package */
598
570
        return NGX_OK;
599
571
    }
600
572
 
601
 
    cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
 
573
    cl = ngx_http_lua_chains_get_free_buf(r->connection->log, r->pool,
 
574
                                          &ctx->free_bufs, len,
 
575
                                          (ngx_buf_tag_t) &ngx_http_lua_module);
 
576
 
602
577
    if (cl == NULL) {
603
578
        return NGX_ERROR;
604
579
    }
605
580
 
 
581
    dd("chains get free buf: %d == %d", (int) (cl->buf->end - cl->buf->start),
 
582
       (int) len);
 
583
 
606
584
    b = cl->buf;
607
585
 
608
 
    b->start = ngx_palloc(r->pool, len);
609
 
    if (b->start == NULL) {
610
 
        return NGX_ERROR;
611
 
    }
612
 
 
613
 
    b->end = b->start + len;
614
 
 
615
 
    b->pos  = b->start;
616
 
    b->last = b->pos;
617
 
    b->memory = 1;
618
 
 
619
 
#if 1
620
 
    b->tag = (ngx_buf_tag_t) &ngx_http_lua_module;
621
 
#endif
622
 
 
623
586
    while (in) {
624
587
        if (ngx_buf_in_memory(in->buf)) {
625
588
            b->last = ngx_copy(b->last, in->buf->pos,
630
593
    }
631
594
 
632
595
    *ll = cl;
633
 
    cl->next = NULL;
634
596
 
635
597
    return NGX_OK;
636
598
}
644
606
            "lua reset ctx");
645
607
 
646
608
    if (ctx->cc_ref != LUA_NOREF) {
647
 
        ngx_http_lua_del_thread(r, L, ctx->cc_ref, 0);
 
609
        ngx_http_lua_del_thread(r, L, ctx->cc_ref);
648
610
        ctx->cc_ref = LUA_NOREF;
649
611
    }
650
612
 
738
700
 
739
701
    if (lua_isthread(L, -1)) {
740
702
        /*  coroutine not finished yet, force quit */
741
 
        ngx_http_lua_del_thread(r, L, ctx->cc_ref, 1);
 
703
        ngx_http_lua_del_thread(r, L, ctx->cc_ref);
742
704
        ctx->cc_ref = LUA_NOREF;
743
705
 
744
706
    } else {
764
726
    ngx_int_t                rc;
765
727
#if (NGX_PCRE)
766
728
    ngx_pool_t              *old_pool;
 
729
    unsigned                 pcre_pool_resumed = 0;
767
730
#endif
768
731
 
769
732
    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
774
737
 
775
738
    dd("ctx = %p", ctx);
776
739
 
 
740
    cc = ctx->cc;
 
741
    cc_ref = ctx->cc_ref;
 
742
 
 
743
#if (NGX_PCRE)
 
744
        /* XXX: work-around to nginx regex subsystem */
 
745
    old_pool = ngx_http_lua_pcre_malloc_init(r->pool);
 
746
#endif
 
747
 
777
748
    NGX_LUA_EXCEPTION_TRY {
778
 
        cc = ctx->cc;
779
 
        cc_ref = ctx->cc_ref;
780
 
 
781
 
#if (NGX_PCRE)
782
 
        /* XXX: work-around to nginx regex subsystem */
783
 
        old_pool = ngx_http_lua_pcre_malloc_init(r->pool);
784
 
#endif
785
 
 
786
749
        dd("calling lua_resume: vm %p, nret %d", cc, (int) nret);
787
750
 
788
751
        /*  run code */
791
754
#if (NGX_PCRE)
792
755
        /* XXX: work-around to nginx regex subsystem */
793
756
        ngx_http_lua_pcre_malloc_done(old_pool);
 
757
        pcre_pool_resumed = 1;
 
758
#endif
 
759
 
 
760
#if 0
 
761
        /* test the longjmp thing */
 
762
        if (rand() % 2 == 0) {
 
763
            NGX_LUA_EXCEPTION_THROW(1);
 
764
        }
794
765
#endif
795
766
 
796
767
        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
831
802
                ngx_http_lua_dump_postponed(r);
832
803
#endif
833
804
 
834
 
                ngx_http_lua_del_thread(r, L, cc_ref, 0);
 
805
                ngx_http_lua_del_thread(r, L, cc_ref);
835
806
                ctx->cc_ref = LUA_NOREF;
836
807
 
837
808
                if (ctx->entered_content_phase) {
877
848
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
878
849
                "lua handler aborted: %s: %s", err, msg);
879
850
 
880
 
        ngx_http_lua_del_thread(r, L, cc_ref, 0);
 
851
        ngx_http_lua_del_thread(r, L, cc_ref);
881
852
        ctx->cc_ref = LUA_NOREF;
 
853
 
882
854
        ngx_http_lua_request_cleanup(r);
883
855
 
884
856
        dd("headers sent? %d", ctx->headers_sent ? 1 : 0);
886
858
        return ctx->headers_sent ? NGX_ERROR : NGX_HTTP_INTERNAL_SERVER_ERROR;
887
859
 
888
860
    } NGX_LUA_EXCEPTION_CATCH {
 
861
 
889
862
        dd("nginx execution restored");
 
863
 
 
864
#if (NGX_PCRE)
 
865
        if (!pcre_pool_resumed) {
 
866
            ngx_http_lua_pcre_malloc_done(old_pool);
 
867
        }
 
868
#endif
890
869
    }
891
870
 
892
871
    return NGX_ERROR;
903
882
    ngx_connection_t            *c;
904
883
    ngx_event_t                 *wev;
905
884
    ngx_http_core_loc_conf_t    *clcf;
 
885
    ngx_chain_t                 *cl;
 
886
 
 
887
    ngx_http_lua_socket_upstream_t      *u;
906
888
 
907
889
    c = r->connection;
908
890
 
1032
1014
            return rc;
1033
1015
        }
1034
1016
 
 
1017
        if (ctx->busy_bufs) {
 
1018
            cl = NULL;
 
1019
 
 
1020
            dd("updating chains...");
 
1021
 
 
1022
#if nginx_version >= 1001004
 
1023
            ngx_chain_update_chains(r->pool,
 
1024
#else
 
1025
            ngx_chain_update_chains(
 
1026
#endif
 
1027
                                    &ctx->free_bufs, &ctx->busy_bufs, &cl,
 
1028
                                    (ngx_buf_tag_t) &ngx_http_lua_module);
 
1029
 
 
1030
            dd("update lua buf tag: %p, buffered: %x, busy bufs: %p",
 
1031
                &ngx_http_lua_module, (int) c->buffered, ctx->busy_bufs);
 
1032
        }
 
1033
 
1035
1034
        if (c->buffered) {
1036
1035
 
1037
1036
            if (!wev->delayed) {
1057
1056
        }
1058
1057
    }
1059
1058
 
1060
 
    if (ctx->waiting_flush) {
 
1059
    if (ctx->socket_busy && !ctx->socket_ready) {
 
1060
        return NGX_DONE;
 
1061
    }
 
1062
 
 
1063
    if (!ctx->socket_busy && ctx->socket_ready) {
 
1064
 
 
1065
        dd("resuming socket api");
 
1066
 
 
1067
        dd("setting socket_ready to 0");
 
1068
 
 
1069
        ctx->socket_ready = 0;
 
1070
 
 
1071
        u = ctx->data;
 
1072
        nret = u->prepare_retvals(r, u, ctx->cc);
 
1073
        if (nret == NGX_AGAIN) {
 
1074
            return NGX_DONE;
 
1075
        }
 
1076
 
 
1077
        goto run;
 
1078
 
 
1079
    } else if (ctx->waiting_flush) {
1061
1080
 
1062
1081
        ctx->waiting_flush = 0;
1063
1082
        nret = 0;
1065
1084
        goto run;
1066
1085
 
1067
1086
    } else if (ctx->req_read_body_done) {
 
1087
 
1068
1088
        dd("turned off req read body done");
1069
1089
 
1070
1090
        ctx->req_read_body_done = 0;
1077
1097
        goto run;
1078
1098
 
1079
1099
    } else if (ctx->done) {
 
1100
 
1080
1101
        ctx->done = 0;
1081
1102
 
1082
1103
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
1098
1119
 
1099
1120
        nret = ctx->nsubreqs;
1100
1121
 
 
1122
        dd("location capture nret: %d", (int) nret);
 
1123
 
1101
1124
        goto run;
1102
1125
    }
1103
1126
 
1136
1159
        return NGX_DONE;
1137
1160
    }
1138
1161
 
1139
 
    if (rc == NGX_OK) {
1140
 
        return NGX_DECLINED;
1141
 
    }
1142
 
 
1143
1162
    return rc;
1144
1163
 
1145
1164
error:
1205
1224
 
1206
1225
        ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
1207
1226
                "postponed request for %V: "
1208
 
 
1209
 
#if defined(nginx_version) && nginx_version >= 8011
1210
1227
                "c:%d, "
1211
 
#endif
1212
 
 
1213
1228
                "a:%d, i:%d, r:%V, out:%V",
1214
1229
                &r->uri,
1215
 
 
1216
 
#if defined(nginx_version) && nginx_version >= 8011
1217
1230
                r->main->count,
1218
 
#endif
1219
 
 
1220
1231
                r == r->connection->data, i,
1221
1232
                pr->request ? &pr->request->uri : &nil_str, &out);
1222
1233
    }
1251
1262
        lua_rawset(L, index); /* stack: table */
1252
1263
 
1253
1264
    } else {
1254
 
        if (! lua_istable(L, -1)) {
 
1265
        if (!lua_istable(L, -1)) {
1255
1266
            /* just inserted one value */
1256
1267
            lua_createtable(L, 4, 0);
1257
1268
                /* stack: table key value value table */
1508
1519
                    }
1509
1520
 
1510
1521
                    *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
1511
 
 
1512
1522
                    break;
1513
1523
                }
1514
1524
 
1586
1596
{
1587
1597
    /* ngx.req table */
1588
1598
 
1589
 
    lua_createtable(L, 0 /* narr */, 15 /* nrec */);    /* .req */
 
1599
    lua_createtable(L, 0 /* narr */, 16 /* nrec */);    /* .req */
1590
1600
 
1591
1601
    ngx_http_lua_inject_req_header_api(L);
1592
1602
 
1596
1606
 
1597
1607
    ngx_http_lua_inject_req_body_api(L);
1598
1608
 
 
1609
    ngx_http_lua_inject_req_socket_api(L);
 
1610
 
1599
1611
    lua_setfield(L, -2, "req");
1600
1612
}
1601
1613
 
1610
1622
            "lua thread initiated internal redirect to %V",
1611
1623
            &ctx->exec_uri);
1612
1624
 
1613
 
    ngx_http_lua_del_thread(r, L, cc_ref, 1 /* force quit */);
 
1625
    ngx_http_lua_del_thread(r, L, cc_ref);
1614
1626
    ctx->cc_ref = LUA_NOREF;
 
1627
 
1615
1628
    ngx_http_lua_request_cleanup(r);
1616
1629
 
1617
1630
    if (ctx->exec_uri.data[0] == '@') {
1690
1703
            "lua thread aborting request with status %d",
1691
1704
            ctx->exit_code);
1692
1705
 
1693
 
    ngx_http_lua_del_thread(r, L, cc_ref, 1 /* force quit */);
 
1706
    ngx_http_lua_del_thread(r, L, cc_ref);
1694
1707
    ctx->cc_ref = LUA_NOREF;
 
1708
 
1695
1709
    ngx_http_lua_request_cleanup(r);
1696
1710
 
1697
1711
    if ((ctx->exit_code == NGX_OK &&
1735
1749
    lua_pushnil(L);
1736
1750
    while (lua_next(L, table) != 0) {
1737
1751
        if (lua_type(L, -2) != LUA_TSTRING) {
1738
 
            luaL_error(L, "attemp to use a non-string key in the "
 
1752
            luaL_error(L, "attempt to use a non-string key in the "
1739
1753
                    "\"args\" option table");
1740
1754
            return;
1741
1755
        }
1942
1956
            "lua thread aborting request with URI rewrite jump: \"%V?%V\"",
1943
1957
            &r->uri, &r->args);
1944
1958
 
1945
 
    ngx_http_lua_del_thread(r, L, cc_ref, 1 /* force quit */);
 
1959
    ngx_http_lua_del_thread(r, L, cc_ref);
1946
1960
    ctx->cc_ref = LUA_NOREF;
 
1961
 
1947
1962
    ngx_http_lua_request_cleanup(r);
1948
1963
 
1949
1964
    return NGX_OK;
2137
2152
    return 0;
2138
2153
}
2139
2154
 
 
2155
 
 
2156
ngx_chain_t *
 
2157
ngx_http_lua_chains_get_free_buf(ngx_log_t *log, ngx_pool_t *p,
 
2158
    ngx_chain_t **free, size_t len, ngx_buf_tag_t tag)
 
2159
{
 
2160
    ngx_chain_t  *cl;
 
2161
    ngx_buf_t    *b;
 
2162
 
 
2163
    if (*free) {
 
2164
        cl = *free;
 
2165
        *free = cl->next;
 
2166
        cl->next = NULL;
 
2167
 
 
2168
        b = cl->buf;
 
2169
        if ((size_t) (b->end - b->start) >= len) {
 
2170
            ngx_log_debug4(NGX_LOG_DEBUG_HTTP, log, 0,
 
2171
                    "lua reuse free buf memory %O >= %uz, cl:%p, p:%p",
 
2172
                    (off_t) (b->end - b->start), len, cl, b->start);
 
2173
 
 
2174
            b->pos = b->start;
 
2175
            b->last = b->start;
 
2176
            b->tag = tag;
 
2177
            return cl;
 
2178
        }
 
2179
 
 
2180
        ngx_log_debug4(NGX_LOG_DEBUG_HTTP, log, 0,
 
2181
                       "lua reuse free buf chain, but reallocate memory "
 
2182
                       "because %uz >= %O, cl:%p, p:%p", len,
 
2183
                       (off_t) (b->end - b->start), cl, b->start);
 
2184
 
 
2185
        if (ngx_buf_in_memory(b) && b->start) {
 
2186
            ngx_pfree(p, b->start);
 
2187
        }
 
2188
 
 
2189
        b->start = ngx_palloc(p, len);
 
2190
        if (b->start == NULL) {
 
2191
            return NULL;
 
2192
        }
 
2193
 
 
2194
        dd("buf start: %p", cl->buf->start);
 
2195
 
 
2196
        b->end = b->start + len;
 
2197
        b->pos = b->start;
 
2198
        b->last = b->start;
 
2199
        b->tag = tag;
 
2200
 
 
2201
        return cl;
 
2202
    }
 
2203
 
 
2204
    cl = ngx_alloc_chain_link(p);
 
2205
    if (cl == NULL) {
 
2206
        return NULL;
 
2207
    }
 
2208
 
 
2209
    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, log, 0,
 
2210
                   "lua allocate new chainlink and new buf of size %uz, cl:%p",
 
2211
                   len, cl);
 
2212
 
 
2213
    cl->buf = ngx_create_temp_buf(p, len);
 
2214
    if (cl->buf == NULL) {
 
2215
        return NULL;
 
2216
    }
 
2217
 
 
2218
    dd("buf start: %p", cl->buf->start);
 
2219
 
 
2220
    cl->buf->tag = tag;
 
2221
    cl->next = NULL;
 
2222
 
 
2223
    return cl;
 
2224
}
 
2225