~ubuntu-branches/ubuntu/quantal/nginx/quantal-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry, Kartik Mistry
  • Date: 2011-09-26 10:17:04 UTC
  • mfrom: (4.2.38 sid)
  • Revision ID: package-import@ubuntu.com-20110926101704-x8pxngiujrmkxnn3
Tags: 1.1.4-2
[Kartik Mistry]
* debian/modules:
  + Updated nginx-upload-progress module, Thanks to upstream for fixing issue
    that FTBFS nginx on kFreeBSD-* archs.
  + Updated nginx-lua module to latest upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef DDEBUG
 
2
#define DDEBUG 0
 
3
#endif
 
4
#include "ddebug.h"
 
5
 
 
6
#include "ngx_http_lua_ctx.h"
 
7
 
 
8
 
 
9
int
 
10
ngx_http_lua_ngx_get_ctx(lua_State *L)
 
11
{
 
12
    ngx_http_request_t          *r;
 
13
    ngx_http_lua_ctx_t          *ctx;
 
14
 
 
15
    lua_getglobal(L, GLOBALS_SYMBOL_REQUEST);
 
16
    r = lua_touserdata(L, -1);
 
17
    lua_pop(L, 1);
 
18
 
 
19
    if (r == NULL) {
 
20
        return luaL_error(L, "no request object found");
 
21
    }
 
22
 
 
23
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
24
    if (ctx == NULL) {
 
25
        return luaL_error(L, "no request ctx found");
 
26
    }
 
27
 
 
28
    if (ctx->ctx_ref == LUA_NOREF) {
 
29
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
 
30
                "lua create ngx.ctx table for the current request");
 
31
 
 
32
        lua_getfield(L, LUA_REGISTRYINDEX, NGX_LUA_REQ_CTX_REF);
 
33
        lua_newtable(L);
 
34
        lua_pushvalue(L, -1);
 
35
        ctx->ctx_ref = luaL_ref(L, -3);
 
36
        return 1;
 
37
 
 
38
    } else {
 
39
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
 
40
                "lua fetching existing ngx.ctx table for the current request");
 
41
 
 
42
        lua_getfield(L, LUA_REGISTRYINDEX, NGX_LUA_REQ_CTX_REF);
 
43
        lua_rawgeti(L, -1, ctx->ctx_ref);
 
44
    }
 
45
 
 
46
    return 1;
 
47
}
 
48
 
 
49
 
 
50
int
 
51
ngx_http_lua_ngx_set_ctx(lua_State *L)
 
52
{
 
53
    ngx_http_request_t          *r;
 
54
    ngx_http_lua_ctx_t          *ctx;
 
55
 
 
56
    lua_getglobal(L, GLOBALS_SYMBOL_REQUEST);
 
57
    r = lua_touserdata(L, -1);
 
58
    lua_pop(L, 1);
 
59
 
 
60
    if (r == NULL) {
 
61
        return luaL_error(L, "no request object found");
 
62
    }
 
63
 
 
64
    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
 
65
    if (ctx == NULL) {
 
66
        return luaL_error(L, "no request ctx found");
 
67
    }
 
68
 
 
69
    if (ctx->ctx_ref == LUA_NOREF) {
 
70
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
 
71
                "lua create ngx.ctx table for the current request");
 
72
 
 
73
        lua_getfield(L, LUA_REGISTRYINDEX, NGX_LUA_REQ_CTX_REF);
 
74
        lua_pushvalue(L, 3);
 
75
        ctx->ctx_ref = luaL_ref(L, -2);
 
76
        return 0;
 
77
    }
 
78
 
 
79
    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
 
80
            "lua fetching existing ngx.ctx table for the current request");
 
81
 
 
82
    lua_getfield(L, LUA_REGISTRYINDEX, NGX_LUA_REQ_CTX_REF);
 
83
    luaL_unref(L, -1, ctx->ctx_ref);
 
84
    lua_pushvalue(L, 3);
 
85
    ctx->ctx_ref = luaL_ref(L, -2);
 
86
 
 
87
    return 0;
 
88
}
 
89