~spuul/nginx/trunk

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-02-15 03:05:42 UTC
  • mfrom: (4.3.10 sid)
  • Revision ID: package-import@ubuntu.com-20140215030542-71ubtowl24vf7nfn
Tags: 1.4.5-1ubuntu1
* Resynchronise with Debian (LP: #1280511).  Remaining changes:
  - debian/patches/ubuntu-branding.patch:
    + Add Ubuntu branding to server_tokens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "ngx_http_lua_initby.h"
25
25
#include "ngx_http_lua_shdict.h"
26
26
 
 
27
 
27
28
#if defined(NDK) && NDK
28
29
#include "ngx_http_lua_setby.h"
 
30
 
 
31
 
 
32
static ngx_int_t ngx_http_lua_set_by_lua_init(ngx_http_request_t *r);
29
33
#endif
30
34
 
31
35
 
124
128
    fp = (ngx_flag_t *) (p + cmd->offset);
125
129
 
126
130
    if (!*fp) {
127
 
        ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
 
131
        ngx_conf_log_error(NGX_LOG_ALERT, cf, 0,
128
132
                           "lua_code_cache is off; this will hurt "
129
133
                           "performance");
130
134
    }
277
281
 
278
282
ngx_int_t
279
283
ngx_http_lua_filter_set_by_lua_inline(ngx_http_request_t *r, ngx_str_t *val,
280
 
        ngx_http_variable_value_t *v, void *data)
 
284
    ngx_http_variable_value_t *v, void *data)
281
285
{
282
286
    lua_State                   *L;
283
287
    ngx_int_t                    rc;
284
 
    ngx_http_lua_main_conf_t    *lmcf;
285
 
    ngx_http_lua_loc_conf_t     *llcf;
286
 
    char                        *err = NULL;
287
288
 
288
289
    ngx_http_lua_set_var_data_t     *filter_data = data;
289
290
 
290
 
    lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
291
 
 
292
 
    L = lmcf->lua;
293
 
 
294
 
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
 
291
    if (ngx_http_lua_set_by_lua_init(r) != NGX_OK) {
 
292
        return NGX_ERROR;
 
293
    }
 
294
 
 
295
    L = ngx_http_lua_get_lua_vm(r, NULL);
295
296
 
296
297
    /*  load Lua inline script (w/ cache)        sp = 1 */
297
298
    rc = ngx_http_lua_cache_loadbuffer(L, filter_data->script.data,
298
299
                                       filter_data->script.len,
299
 
                                       filter_data->key, "set_by_lua", &err,
300
 
                                       llcf->enable_code_cache ? 1 : 0);
301
 
 
 
300
                                       filter_data->key, "set_by_lua");
302
301
    if (rc != NGX_OK) {
303
 
        if (err == NULL) {
304
 
            err = "unknown error";
305
 
        }
306
 
 
307
 
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
308
 
                "failed to load Lua inlined code: %s", err);
309
 
 
310
302
        return NGX_ERROR;
311
303
    }
312
304
 
322
314
 
323
315
ngx_int_t
324
316
ngx_http_lua_filter_set_by_lua_file(ngx_http_request_t *r, ngx_str_t *val,
325
 
        ngx_http_variable_value_t *v, void *data)
 
317
    ngx_http_variable_value_t *v, void *data)
326
318
{
327
319
    lua_State                   *L;
328
320
    ngx_int_t                    rc;
329
321
    u_char                      *script_path;
330
 
    ngx_http_lua_main_conf_t    *lmcf;
331
 
    ngx_http_lua_loc_conf_t     *llcf;
332
 
    char                        *err;
333
322
    size_t                       nargs;
334
323
 
335
324
    ngx_http_lua_set_var_data_t     *filter_data = data;
336
325
 
337
326
    dd("set by lua file");
338
327
 
 
328
    if (ngx_http_lua_set_by_lua_init(r) != NGX_OK) {
 
329
        return NGX_ERROR;
 
330
    }
 
331
 
339
332
    filter_data->script.data = v[0].data;
340
333
    filter_data->script.len = v[0].len;
341
334
 
352
345
        return NGX_ERROR;
353
346
    }
354
347
 
355
 
    lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
356
 
 
357
 
    L = lmcf->lua;
358
 
 
359
 
    llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
 
348
    L = ngx_http_lua_get_lua_vm(r, NULL);
360
349
 
361
350
    /*  load Lua script file (w/ cache)        sp = 1 */
362
 
    rc = ngx_http_lua_cache_loadfile(L, script_path, filter_data->key,
363
 
                                     &err, llcf->enable_code_cache ? 1 : 0);
364
 
 
 
351
    rc = ngx_http_lua_cache_loadfile(L, script_path, filter_data->key);
365
352
    if (rc != NGX_OK) {
366
 
        if (err == NULL) {
367
 
            err = "unknown error";
368
 
        }
369
 
 
370
 
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
371
 
                      "failed to load Lua file: %s", err);
372
 
 
373
353
        return NGX_ERROR;
374
354
    }
375
355
 
458
438
        }
459
439
    }
460
440
 
461
 
    llcf->rewrite_handler = cmd->post;
 
441
    llcf->rewrite_handler = (ngx_http_handler_pt) cmd->post;
462
442
 
463
443
    lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
464
444
 
540
520
        }
541
521
    }
542
522
 
543
 
    llcf->access_handler = cmd->post;
 
523
    llcf->access_handler = (ngx_http_handler_pt) cmd->post;
544
524
 
545
525
    lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
546
526
 
622
602
        }
623
603
    }
624
604
 
625
 
    llcf->content_handler = cmd->post;
 
605
    llcf->content_handler = (ngx_http_handler_pt) cmd->post;
626
606
 
627
607
    lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
628
608
 
711
691
        }
712
692
    }
713
693
 
714
 
    llcf->log_handler = cmd->post;
 
694
    llcf->log_handler = (ngx_http_handler_pt) cmd->post;
715
695
 
716
696
    lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
717
697
 
723
703
 
724
704
char *
725
705
ngx_http_lua_header_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
726
 
        void *conf)
 
706
    void *conf)
727
707
{
728
708
    u_char                      *p;
729
709
    ngx_str_t                   *value;
792
772
        }
793
773
    }
794
774
 
795
 
    llcf->header_filter_handler = cmd->post;
 
775
    llcf->header_filter_handler = (ngx_http_handler_pt) cmd->post;
796
776
 
797
777
    lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
798
778
 
804
784
 
805
785
char *
806
786
ngx_http_lua_body_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
807
 
        void *conf)
 
787
    void *conf)
808
788
{
809
789
    u_char                      *p;
810
790
    ngx_str_t                   *value;
873
853
        }
874
854
    }
875
855
 
876
 
    llcf->body_filter_handler = cmd->post;
 
856
    llcf->body_filter_handler = (ngx_http_output_body_filter_pt) cmd->post;
877
857
 
878
858
    lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
879
859
 
886
866
 
887
867
char *
888
868
ngx_http_lua_init_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
889
 
        void *conf)
 
869
    void *conf)
890
870
{
891
871
    u_char                      *name;
892
872
    ngx_str_t                   *value;
912
892
        return NGX_CONF_ERROR;
913
893
    }
914
894
 
915
 
    lmcf->init_handler = cmd->post;
 
895
    lmcf->init_handler = (ngx_http_lua_conf_handler_pt) cmd->post;
916
896
 
917
897
    if (cmd->post == ngx_http_lua_init_by_file) {
918
898
        name = ngx_http_lua_rebase_path(cf->pool, value[1].data,
931
911
    return NGX_CONF_OK;
932
912
}
933
913
 
 
914
 
 
915
#if defined(NDK) && NDK
 
916
static ngx_int_t
 
917
ngx_http_lua_set_by_lua_init(ngx_http_request_t *r)
 
918
{
 
919
    lua_State                   *L;
 
920
    ngx_http_lua_ctx_t          *ctx;
 
921
    ngx_http_cleanup_t          *cln;
 
922
 
 
923
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
924
    if (ctx == NULL) {
 
925
        ctx = ngx_http_lua_create_ctx(r);
 
926
        if (ctx == NULL) {
 
927
            return NGX_ERROR;
 
928
        }
 
929
 
 
930
    } else {
 
931
        L = ngx_http_lua_get_lua_vm(r, ctx);
 
932
        ngx_http_lua_reset_ctx(r, L, ctx);
 
933
    }
 
934
 
 
935
    if (ctx->cleanup == NULL) {
 
936
        cln = ngx_http_cleanup_add(r, 0);
 
937
        if (cln == NULL) {
 
938
            return NGX_ERROR;
 
939
        }
 
940
 
 
941
        cln->handler = ngx_http_lua_request_cleanup_handler;
 
942
        cln->data = ctx;
 
943
        ctx->cleanup = &cln->handler;
 
944
    }
 
945
 
 
946
    ctx->context = NGX_HTTP_LUA_CONTEXT_SET;
 
947
    return NGX_OK;
 
948
}
 
949
#endif
 
950
 
934
951
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */