~spuul/nginx/trunk

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Christos Trochalakis, Christos Trochalakis
  • Date: 2014-02-13 11:41:49 UTC
  • mfrom: (1.3.32)
  • mto: This revision was merged to the branch mainline in revision 72.
  • Revision ID: package-import@ubuntu.com-20140213114149-tkp78c45rzu3wr6y
Tags: 1.4.5-1
[ Christos Trochalakis ]
* New upstream release.
* debian/modules/nginx-lua:
  + Update nginx-lua to v0.9.4
* debian/nginx-naxsi-ui.preinst:
  + Fix exit status issue (Closes: #735152)
* debian/control:
  + Fix arch:all to arch:any dependencies
  + Make nginx depend on specific flavor version
* debian/nginx-*.postinst:
  + Make nginx start by default (Closes: #735551)
* debian/nginx-*.prerm:
  + No need to check for invoke-rc.d,
    correctly set the exit code on error
* debian/nginx-common.nginx.init:
  + Rewrite some parts of the initscript
  + Introduce rotate command
  + Introduce upgrade command

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 * */
51
51
static void
52
52
ngx_http_lua_body_filter_by_lua_env(lua_State *L, ngx_http_request_t *r,
53
 
        ngx_chain_t *in)
 
53
    ngx_chain_t *in)
54
54
{
55
55
    /*  set nginx request pointer to current lua thread's globals table */
56
 
    lua_pushlightuserdata(L, &ngx_http_lua_request_key);
57
 
    lua_pushlightuserdata(L, r);
58
 
    lua_rawset(L, LUA_GLOBALSINDEX);
 
56
    ngx_http_lua_set_req(L, r);
59
57
 
60
58
    lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
61
59
    lua_pushlightuserdata(L, in);
75
73
    ngx_http_lua_create_new_global_table(L, 0 /* narr */, 1 /* nrec */);
76
74
 
77
75
    /*  {{{ make new env inheriting main thread's globals table */
78
 
    lua_newtable(L);    /*  the metatable for the new env */
 
76
    lua_createtable(L, 0, 1 /* nrec */);    /*  the metatable for the new
 
77
                                                env */
79
78
    lua_pushvalue(L, LUA_GLOBALSINDEX);
80
79
    lua_setfield(L, -2, "__index");
81
80
    lua_setmetatable(L, -2);    /*  setmetatable({}, {__index = _G}) */
87
86
 
88
87
ngx_int_t
89
88
ngx_http_lua_body_filter_by_chunk(lua_State *L, ngx_http_request_t *r,
90
 
        ngx_chain_t *in)
 
89
    ngx_chain_t *in)
91
90
{
92
91
    ngx_int_t        rc;
93
92
    u_char          *err_msg;
156
155
{
157
156
    lua_State                   *L;
158
157
    ngx_int_t                    rc;
159
 
    ngx_http_lua_main_conf_t    *lmcf;
160
158
    ngx_http_lua_loc_conf_t     *llcf;
161
 
    char                        *err;
162
159
 
163
160
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
164
 
    lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
165
161
 
166
 
    L = lmcf->lua;
 
162
    L = ngx_http_lua_get_lua_vm(r, NULL);
167
163
 
168
164
    /*  load Lua inline script (w/ cache) sp = 1 */
169
165
    rc = ngx_http_lua_cache_loadbuffer(L, llcf->body_filter_src.value.data,
170
166
                                       llcf->body_filter_src.value.len,
171
167
                                       llcf->body_filter_src_key,
172
 
                                       "body_filter_by_lua", &err,
173
 
                                       llcf->enable_code_cache ? 1 : 0);
174
 
 
 
168
                                       "body_filter_by_lua");
175
169
    if (rc != NGX_OK) {
176
 
        if (err == NULL) {
177
 
            err = "unknown error";
178
 
        }
179
 
 
180
 
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
181
 
                      "Failed to load Lua inlined code: %s", err);
182
 
 
183
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
170
        return NGX_ERROR;
184
171
    }
185
172
 
186
173
    rc = ngx_http_lua_body_filter_by_chunk(L, r, in);
201
188
    lua_State                       *L;
202
189
    ngx_int_t                        rc;
203
190
    u_char                          *script_path;
204
 
    ngx_http_lua_main_conf_t        *lmcf;
205
191
    ngx_http_lua_loc_conf_t         *llcf;
206
 
    char                            *err;
207
192
    ngx_str_t                        eval_src;
208
193
 
209
194
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
222
207
        return NGX_ERROR;
223
208
    }
224
209
 
225
 
    lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
226
 
    L = lmcf->lua;
 
210
    L = ngx_http_lua_get_lua_vm(r, NULL);
227
211
 
228
212
    /*  load Lua script file (w/ cache)        sp = 1 */
229
213
    rc = ngx_http_lua_cache_loadfile(L, script_path,
230
 
                                     llcf->body_filter_src_key, &err,
231
 
                                     llcf->enable_code_cache ? 1 : 0);
232
 
 
 
214
                                     llcf->body_filter_src_key);
233
215
    if (rc != NGX_OK) {
234
 
        if (err == NULL) {
235
 
            err = "unknown error";
236
 
        }
237
 
 
238
 
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
239
 
                      "failed to load Lua inlined code: %s", err);
240
 
 
241
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
216
        return NGX_ERROR;
242
217
    }
243
218
 
244
219
    /*  make sure we have a valid code chunk */
260
235
    ngx_http_lua_loc_conf_t     *llcf;
261
236
    ngx_http_lua_ctx_t          *ctx;
262
237
    ngx_int_t                    rc;
263
 
    uint8_t                      old_context;
 
238
    uint16_t                     old_context;
264
239
    ngx_http_cleanup_t          *cln;
265
 
    ngx_http_lua_main_conf_t    *lmcf;
266
240
    lua_State                   *L;
267
241
    ngx_chain_t                 *out;
268
242
    ngx_buf_tag_t                tag;
308
282
            return NGX_ERROR;
309
283
        }
310
284
 
311
 
        cln->handler = ngx_http_lua_request_cleanup;
312
 
        cln->data = r;
 
285
        cln->handler = ngx_http_lua_request_cleanup_handler;
 
286
        cln->data = ctx;
313
287
        ctx->cleanup = &cln->handler;
314
288
    }
315
289
 
327
301
        return NGX_ERROR;
328
302
    }
329
303
 
330
 
    lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
331
 
 
332
 
    L = lmcf->lua;
 
304
    L = ngx_http_lua_get_lua_vm(r, ctx);
333
305
 
334
306
    lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
335
307
    lua_rawget(L, LUA_GLOBALSINDEX);
361
333
 
362
334
 
363
335
ngx_int_t
364
 
ngx_http_lua_body_filter_init()
 
336
ngx_http_lua_body_filter_init(void)
365
337
{
366
338
    dd("calling body filter init");
367
339
    ngx_http_next_body_filter = ngx_http_top_body_filter;
394
366
    lua_rawget(L, LUA_GLOBALSINDEX);
395
367
    in = lua_touserdata(L, -1);
396
368
 
397
 
    if (in == NULL) {
398
 
        lua_pushnil(L);
399
 
        return 1;
400
 
    }
401
 
 
402
369
    if (idx == 2) {
403
370
        /* asking for the eof argument */
404
371
 
415
382
 
416
383
    /* idx == 1 */
417
384
 
418
 
    if (in == NULL) {
419
 
        lua_pushnil(L);
420
 
        return 1;
421
 
    }
422
 
 
423
385
    size = 0;
424
386
 
425
387
    if (in->next == NULL) {
461
423
 
462
424
int
463
425
ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
464
 
        ngx_http_lua_ctx_t *ctx)
 
426
    ngx_http_lua_ctx_t *ctx)
465
427
{
466
428
    int                      type;
467
429
    int                      idx;
491
453
        if (last) {
492
454
            ctx->seen_last_in_filter = 1;
493
455
 
494
 
            if (in) {
495
 
                for (cl = in; cl; cl = cl->next) {
496
 
                    if (cl->next == NULL) {
497
 
                        if (r == r->main) {
498
 
                            cl->buf->last_buf = 1;
499
 
 
500
 
                        } else {
501
 
                            cl->buf->last_in_chain = 1;
502
 
                        }
503
 
 
504
 
                        break;
 
456
            for (cl = in; cl; cl = cl->next) {
 
457
                if (cl->next == NULL) {
 
458
                    if (r == r->main) {
 
459
                        cl->buf->last_buf = 1;
 
460
 
 
461
                    } else {
 
462
                        cl->buf->last_in_chain = 1;
505
463
                    }
506
 
                }
507
 
 
508
 
            } else {
509
 
                tag = (ngx_buf_tag_t) &ngx_http_lua_module;
510
 
 
511
 
                cl = ngx_http_lua_chains_get_free_buf(r->connection->log,
512
 
                                                      r->pool, &ctx->free_bufs,
513
 
                                                      0, tag);
514
 
 
515
 
                if (cl == NULL) {
516
 
                    return luaL_error(L, "out of memory");
517
 
                }
518
 
 
519
 
                if (r == r->main) {
520
 
                    cl->buf->last_buf = 1;
521
 
 
522
 
                } else {
523
 
                    cl->buf->last_in_chain = 1;
524
 
                }
525
 
 
526
 
                lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
527
 
                lua_pushlightuserdata(L, cl);
528
 
                lua_rawset(L, LUA_GLOBALSINDEX);
 
464
 
 
465
                    break;
 
466
                }
529
467
            }
530
468
 
531
469
        } else {
532
470
            /* last == 0 */
533
471
 
534
 
            if (in) {
535
 
                for (size = 0, cl = in; cl; cl = cl->next) {
536
 
                    if (cl->buf->last_buf) {
537
 
                        cl->buf->last_buf = 0;
538
 
                    }
539
 
 
540
 
                    if (cl->buf->last_in_chain) {
541
 
                        cl->buf->last_in_chain = 0;
542
 
                    }
543
 
 
544
 
                    size += cl->buf->last - cl->buf->pos;
545
 
                }
546
 
 
547
 
                if (size == 0) {
548
 
                    lua_pushlightuserdata(L,
549
 
                                          &ngx_http_lua_body_filter_chain_key);
550
 
                    lua_pushlightuserdata(L, NULL);
551
 
                    lua_rawset(L, LUA_GLOBALSINDEX);
 
472
            for (cl = in; cl; cl = cl->next) {
 
473
                if (cl->buf->last_buf) {
 
474
                    cl->buf->last_buf = 0;
 
475
                }
 
476
 
 
477
                if (cl->buf->last_in_chain) {
 
478
                    cl->buf->last_in_chain = 0;
 
479
                }
 
480
 
 
481
                if (cl->buf->last - cl->buf->pos == 0) {
 
482
                    cl->buf->temporary = 0;
 
483
                    cl->buf->memory = 0;
 
484
                    cl->buf->mmap = 0;
 
485
                    cl->buf->in_file = 0;
 
486
                    cl->buf->sync = 1;
552
487
                }
553
488
            }
554
489
        }
578
513
            dd("mark the buf as consumed: %d", (int) ngx_buf_size(cl->buf));
579
514
            cl->buf->pos = cl->buf->last;
580
515
            cl->buf->file_pos = cl->buf->file_last;
 
516
 
 
517
            cl->buf->temporary = 0;
 
518
            cl->buf->memory = 0;
 
519
            cl->buf->mmap = 0;
 
520
            cl->buf->in_file = 0;
 
521
            cl->buf->sync = 1;
581
522
        }
582
523
 
583
 
        lua_pushlightuserdata(L, NULL); /* key val */
584
 
        lua_rawset(L, LUA_GLOBALSINDEX);
585
524
        return 0;
586
525
 
587
526
    case LUA_TTABLE:
612
551
 
613
552
    if (size == 0) {
614
553
        if (last) {
615
 
            if (in) {
616
 
                if (r == r->main) {
617
 
                    in->buf->last_buf = 1;
618
 
 
619
 
                } else {
620
 
                    in->buf->last_in_chain = 1;
621
 
                }
 
554
            if (r == r->main) {
 
555
                in->buf->last_buf = 1;
622
556
 
623
557
            } else {
624
 
 
625
 
                tag = (ngx_buf_tag_t) &ngx_http_lua_module;
626
 
 
627
 
                cl = ngx_http_lua_chains_get_free_buf(r->connection->log,
628
 
                                                      r->pool, &ctx->free_bufs,
629
 
                                                      0, tag);
630
 
 
631
 
                if (cl == NULL) {
632
 
                    return luaL_error(L, "out of memory");
633
 
                }
634
 
 
635
 
                if (r == r->main) {
636
 
                    cl->buf->last_buf = 1;
637
 
 
638
 
                } else {
639
 
                    in->buf->last_in_chain = 1;
640
 
                }
641
 
 
642
 
                lua_pushlightuserdata(L, &ngx_http_lua_body_filter_chain_key);
643
 
                lua_pushlightuserdata(L, cl);
644
 
                lua_rawset(L, LUA_GLOBALSINDEX);
 
558
                in->buf->last_in_chain = 1;
 
559
            }
 
560
 
 
561
        } else {
 
562
            for (cl = in; cl; cl = cl->next) {
 
563
                cl->buf->sync = 1;
 
564
                cl->buf->temporary = 0;
 
565
                cl->buf->memory = 0;
 
566
                cl->buf->mmap = 0;
 
567
                cl->buf->in_file = 0;
645
568
            }
646
569
        }
647
570