~ubuntu-branches/ubuntu/saucy/nginx/saucy-updates

« back to all changes in this revision

Viewing changes to debian/modules/nginx-lua/src/ngx_http_lua_output.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:
15
15
static int ngx_http_lua_ngx_eof(lua_State *L);
16
16
static int ngx_http_lua_ngx_send_headers(lua_State *L);
17
17
static int ngx_http_lua_ngx_echo(lua_State *L, unsigned newline);
18
 
static size_t ngx_http_lua_calc_strlen_in_table(lua_State *L, int arg_i);
19
 
static u_char * ngx_http_lua_copy_str_in_table(lua_State *L, u_char *dst);
20
18
 
21
19
 
22
20
static int
50
48
    int                          nargs;
51
49
    int                          type;
52
50
    const char                  *msg;
 
51
    ngx_buf_tag_t                tag;
53
52
 
54
53
    lua_getglobal(L, GLOBALS_SYMBOL_REQUEST);
55
54
    r = lua_touserdata(L, -1);
77
76
    size = 0;
78
77
 
79
78
    for (i = 1; i <= nargs; i++) {
 
79
 
80
80
        type = lua_type(L, i);
 
81
 
81
82
        switch (type) {
82
83
            case LUA_TNUMBER:
83
84
            case LUA_TSTRING:
 
85
 
84
86
                lua_tolstring(L, i, &len);
85
87
                size += len;
86
88
                break;
87
89
 
88
90
            case LUA_TNIL:
 
91
 
89
92
                size += sizeof("nil") - 1;
90
93
                break;
91
94
 
92
95
            case LUA_TBOOLEAN:
 
96
 
93
97
                if (lua_toboolean(L, i)) {
94
98
                    size += sizeof("true") - 1;
95
99
 
100
104
                break;
101
105
 
102
106
            case LUA_TTABLE:
103
 
                size += ngx_http_lua_calc_strlen_in_table(L, i);
 
107
 
 
108
                size += ngx_http_lua_calc_strlen_in_table(L, i, 0);
104
109
                break;
105
110
 
 
111
            case LUA_TLIGHTUSERDATA:
 
112
 
 
113
                dd("userdata: %p", lua_touserdata(L, i));
 
114
 
 
115
                if (lua_touserdata(L, i) == NULL) {
 
116
                    size += sizeof("null") - 1;
 
117
                    break;
 
118
                }
 
119
 
 
120
                continue;
 
121
 
106
122
            default:
 
123
 
107
124
                msg = lua_pushfstring(L, "string, number, boolean, nil, "
108
 
                        "or array table expected, got %s",
109
 
                        lua_typename(L, type));
 
125
                                      "ngx.null, or array table expected, "
 
126
                                      "but got %s", lua_typename(L, type));
110
127
 
111
128
                return luaL_argerror(L, i, msg);
112
129
        }
121
138
        return 0;
122
139
    }
123
140
 
124
 
    b = ngx_create_temp_buf(r->pool, size);
125
 
    if (b == NULL) {
 
141
    tag = (ngx_buf_tag_t) &ngx_http_lua_module;
 
142
 
 
143
    cl = ngx_http_lua_chains_get_free_buf(r->connection->log, r->pool,
 
144
                                          &ctx->free_bufs, size, tag);
 
145
 
 
146
    if (cl == NULL) {
126
147
        return luaL_error(L, "out of memory");
127
148
    }
128
149
 
 
150
    b = cl->buf;
 
151
 
129
152
    for (i = 1; i <= nargs; i++) {
130
153
        type = lua_type(L, i);
131
154
        switch (type) {
162
185
                b->last = ngx_http_lua_copy_str_in_table(L, b->last);
163
186
                break;
164
187
 
 
188
            case LUA_TLIGHTUSERDATA:
 
189
                *b->last++ = 'n';
 
190
                *b->last++ = 'u';
 
191
                *b->last++ = 'l';
 
192
                *b->last++ = 'l';
 
193
                break;
 
194
 
165
195
            default:
166
196
                return luaL_error(L, "impossible to reach here");
167
197
        }
171
201
        *b->last++ = '\n';
172
202
    }
173
203
 
 
204
#if 0
174
205
    if (b->last != b->end) {
175
206
        return luaL_error(L, "buffer error: %p != %p", b->last, b->end);
176
207
    }
177
 
 
178
 
    cl = ngx_alloc_chain_link(r->pool);
179
 
    if (cl == NULL) {
180
 
        return luaL_error(L, "out of memory");
181
 
    }
182
 
 
183
 
    cl->next = NULL;
184
 
    cl->buf = b;
 
208
#endif
185
209
 
186
210
    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
187
211
                   newline ? "lua say response" : "lua print response");
192
216
        return luaL_error(L, "failed to send data through the output filters");
193
217
    }
194
218
 
 
219
    dd("downstream write: %d, buf len: %d", (int) rc,
 
220
            (int) (b->last - b->pos));
 
221
 
 
222
    if (!ctx->out) {
 
223
#if nginx_version >= 1001004
 
224
        ngx_chain_update_chains(r->pool,
 
225
#else
 
226
        ngx_chain_update_chains(
 
227
#endif
 
228
                                &ctx->free_bufs, &ctx->busy_bufs, &cl, tag);
 
229
 
 
230
        dd("out lua buf tag: %p, buffered: %x, busy bufs: %p",
 
231
            &ngx_http_lua_module, (int) r->connection->buffered,
 
232
            ctx->busy_bufs);
 
233
    }
 
234
 
195
235
    return 0;
196
236
}
197
237
 
198
238
 
199
 
static size_t
200
 
ngx_http_lua_calc_strlen_in_table(lua_State *L, int arg_i)
 
239
size_t
 
240
ngx_http_lua_calc_strlen_in_table(lua_State *L, int arg_i, unsigned strict)
201
241
{
202
242
    double              key;
203
243
    int                 max;
225
265
        /* not an array (non positive integer key) */
226
266
        lua_pop(L, 2); /* stack: table */
227
267
 
228
 
        msg = lua_pushfstring(L, "on-array table found");
 
268
        msg = lua_pushfstring(L, "non-array table found");
229
269
        luaL_argerror(L, arg_i, msg);
230
270
        return 0;
231
271
    }
235
275
    for (i = 1; i <= max; i++) {
236
276
        lua_rawgeti(L, -1, i); /* stack: table value */
237
277
        type = lua_type(L, -1);
 
278
 
238
279
        switch (type) {
239
280
            case LUA_TNUMBER:
240
281
            case LUA_TSTRING:
 
282
 
241
283
                lua_tolstring(L, -1, &len);
242
284
                size += len;
243
285
                break;
244
286
 
245
287
            case LUA_TNIL:
 
288
 
 
289
                if (strict) {
 
290
                    goto bad_type;
 
291
                }
 
292
 
246
293
                size += sizeof("nil") - 1;
247
294
                break;
248
295
 
249
296
            case LUA_TBOOLEAN:
 
297
 
 
298
                if (strict) {
 
299
                    goto bad_type;
 
300
                }
 
301
 
250
302
                if (lua_toboolean(L, -1)) {
251
303
                    size += sizeof("true") - 1;
252
304
 
257
309
                break;
258
310
 
259
311
            case LUA_TTABLE:
260
 
                size += ngx_http_lua_calc_strlen_in_table(L, arg_i);
 
312
 
 
313
                size += ngx_http_lua_calc_strlen_in_table(L, arg_i, strict);
261
314
                break;
262
315
 
 
316
            case LUA_TLIGHTUSERDATA:
 
317
 
 
318
                if (strict) {
 
319
                    goto bad_type;
 
320
                }
 
321
 
 
322
                if (lua_touserdata(L, -1) == NULL) {
 
323
                    size += sizeof("null") - 1;
 
324
                    break;
 
325
                }
 
326
 
 
327
                continue;
 
328
 
263
329
            default:
 
330
 
 
331
bad_type:
264
332
                msg = lua_pushfstring(L, "bad data type %s found",
265
333
                        lua_typename(L, type));
266
 
                luaL_argerror(L, arg_i, msg);
267
 
                return 0;
 
334
                return luaL_argerror(L, arg_i, msg);
268
335
        }
269
336
 
270
337
        lua_pop(L, 1); /* stack: table */
274
341
}
275
342
 
276
343
 
277
 
static u_char *
 
344
u_char *
278
345
ngx_http_lua_copy_str_in_table(lua_State *L, u_char *dst)
279
346
{
280
347
    double               key;
333
400
                dst = ngx_http_lua_copy_str_in_table(L, dst);
334
401
                break;
335
402
 
 
403
            case LUA_TLIGHTUSERDATA:
 
404
 
 
405
                *dst++ = 'n';
 
406
                *dst++ = 'u';
 
407
                *dst++ = 'l';
 
408
                *dst++ = 'l';
 
409
                break;
 
410
 
336
411
            default:
337
412
                luaL_error(L, "impossible to reach here");
338
413
                return NULL;
389
464
        return luaL_error(L, "already seen eof");
390
465
    }
391
466
 
392
 
    buf = ngx_calloc_buf(r->pool);
393
 
    if (buf == NULL) {
394
 
        return luaL_error(L, "memory allocation error");
395
 
    }
396
 
 
397
 
    buf->flush = 1;
398
 
 
399
 
    cl = ngx_alloc_chain_link(r->pool);
400
 
    if (cl == NULL) {
401
 
        return luaL_error(L, "out of memory");
402
 
    }
403
 
 
404
 
    cl->next = NULL;
405
 
    cl->buf = buf;
 
467
    if (ctx->buffering) {
 
468
        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
 
469
                       "lua http 1.0 buffering makes ngx.flush() a no-op");
 
470
 
 
471
        return 0;
 
472
    }
 
473
 
 
474
    if (ctx->flush_buf) {
 
475
        cl = ctx->flush_buf;
 
476
 
 
477
    } else {
 
478
        dd("allocating new flush buf");
 
479
        buf = ngx_calloc_buf(r->pool);
 
480
        if (buf == NULL) {
 
481
            return luaL_error(L, "memory allocation error");
 
482
        }
 
483
 
 
484
        buf->flush = 1;
 
485
 
 
486
        dd("allocating new flush chain");
 
487
        cl = ngx_alloc_chain_link(r->pool);
 
488
        if (cl == NULL) {
 
489
            return luaL_error(L, "out of memory");
 
490
        }
 
491
 
 
492
        cl->next = NULL;
 
493
        cl->buf = buf;
 
494
 
 
495
        ctx->flush_buf = cl;
 
496
    }
406
497
 
407
498
    rc = ngx_http_lua_send_chain_link(r, ctx, cl);
408
499