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

« back to all changes in this revision

Viewing changes to modules/nginx-echo/src/ngx_http_echo_handler.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Lustfield, Micheal Lustfield, Kartik Mistry
  • Date: 2011-03-03 23:39:07 UTC
  • mfrom: (4.2.29 sid)
  • Revision ID: james.westby@ubuntu.com-20110303233907-y48yifhfnn5qjuxz
Tags: 0.8.54-4
[Micheal Lustfield]
* debian/nginx-{full,light,extras}.default:
  + Added comment about alternative to ULIMIT.
* debian/nginx-{full,light,extras}.init.d:
  + Added quotes around a test variable. (Closes: #610946, LP: #699736)
* debian/patches/609343-log-time-iso8601.diff:
  + Added patch to add $time_iso8601 variable to logs. (Closes: #609343)
* Clean up old logrotate files. (Closes: #608983, Closes: #610289)
  + Added Files:
    - debian/nginx-common.preinst
  + Modified Files:
    - debian/rules
  + Moved debian/nginx-common.logrotate to debian/logrotate.
* Added common files to nginx-common package. (Closes: #610290)
  + Removed Files:
    - debian/nginx-full.dirs
    - debian/nginx-light.dirs
    - debian/nginx-full.install
    - debian/nginx-light.install
    - debian/nginx-extras.install
    - debian/nginx.*
  + Added Files:
    - debian/nginx-common.default
    - debian/nginx-common.dirs
    - debian/nginx-common.init.d
    - debian/nginx-common.install
    - debian/nginx-common.manpages
    - debian/logrotate
  + Modified Files:
    - debian/nginx-extras.dirs
    - debian/control
    - debian/rules
* debian/nginx-*.install: (Closes: #609797)
  + Removed NEWS.Debian from nginx-{full,light,extras}.install.
  + Added NEWS.Debian to nginx-common.install.
* nginx-common.postinst:
  + Enforce /var/log/nginx mode and user:group. (Closes: #610983)
  + Enforce /var/log/nginx/*.log mode and user:group. (Closes: #612832)
* debian/rules:
  + Added --with-file-aio to nginx-extras. (Closes: #613175)
  + Removed split clients and user id modules from nginx-light.
* debian/conf/sites-available/default:
  + Fixed a minor typo ( s/Quickstart/QuickStart/ ). (Closes: #613355)
* debian/conf/mime.types:
  + Changed xml type to application/xhtml+xml. (Closes: #613851)
* debian/help/docs/fcgiwrap:
  + Removed Ubuntu specific line in docs. (Closes: #614987)
* debian/conf/sites-available/default:
  + Fixed a pointer to a file. (Closes: #614980)

[Kartik Mistry]
* debian/*.lintian-overrides:
  + Add Lintian overrides for nginx man page. We've manpage in nginx-common
    binary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define DDEBUG 0
2
 
 
3
 
#include "ddebug.h"
4
 
 
5
 
#include "ngx_http_echo_handler.h"
6
 
#include "ngx_http_echo_echo.h"
7
 
#include "ngx_http_echo_util.h"
8
 
#include "ngx_http_echo_sleep.h"
9
 
#include "ngx_http_echo_var.h"
10
 
#include "ngx_http_echo_timer.h"
11
 
#include "ngx_http_echo_location.h"
12
 
#include "ngx_http_echo_subrequest.h"
13
 
#include "ngx_http_echo_request_info.h"
14
 
#include "ngx_http_echo_foreach.h"
15
 
 
16
 
#include <nginx.h>
17
 
#include <ngx_log.h>
18
 
 
19
 
ngx_int_t
20
 
ngx_http_echo_handler_init(ngx_conf_t *cf)
21
 
{
22
 
    ngx_int_t         rc;
23
 
 
24
 
    rc = ngx_http_echo_echo_init(cf);
25
 
    if (rc != NGX_OK) {
26
 
        return rc;
27
 
    }
28
 
 
29
 
    return ngx_http_echo_add_variables(cf);
30
 
}
31
 
 
32
 
 
33
 
void
34
 
ngx_http_echo_wev_handler(ngx_http_request_t *r)
35
 
{
36
 
    ngx_int_t                    rc;
37
 
    ngx_http_echo_ctx_t         *ctx;
38
 
 
39
 
    dd_enter();
40
 
 
41
 
    ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
42
 
 
43
 
    if (ctx == NULL) {
44
 
        ngx_http_finalize_request(r, NGX_ERROR);
45
 
        return;
46
 
    }
47
 
 
48
 
    if (ctx->waiting && ! ctx->done) {
49
 
        if (r->main->posted_requests
50
 
                && r->main->posted_requests->request != r)
51
 
        {
52
 
            dd("HOT SPIN");
53
 
 
54
 
#if defined(nginx_version) && nginx_version >= 8012
55
 
            ngx_http_post_request(r, NULL);
56
 
#else
57
 
            ngx_http_post_request(r);
58
 
#endif
59
 
 
60
 
            return;
61
 
        }
62
 
    }
63
 
 
64
 
    ctx->done = 0;
65
 
 
66
 
    ctx->next_handler_cmd++;
67
 
 
68
 
    rc = ngx_http_echo_run_cmds(r);
69
 
 
70
 
    dd("rc: %d", (int) rc);
71
 
 
72
 
    if (rc == NGX_DONE) {
73
 
        return;
74
 
    }
75
 
 
76
 
    if (rc == NGX_AGAIN) {
77
 
        dd("mark busy %d", (int) ctx->next_handler_cmd);
78
 
        ctx->waiting = 1;
79
 
        ctx->done = 0;
80
 
 
81
 
    } else {
82
 
        dd("mark ready %d", (int) ctx->next_handler_cmd);
83
 
        ctx->waiting = 0;
84
 
        ctx->done = 1;
85
 
 
86
 
        dd("finalizing with rc %d", (int) rc);
87
 
 
88
 
        dd("finalize request %.*s with %d", (int) r->uri.len, r->uri.data, (int) rc);
89
 
 
90
 
        ngx_http_finalize_request(r, rc);
91
 
    }
92
 
}
93
 
 
94
 
 
95
 
ngx_int_t
96
 
ngx_http_echo_handler(ngx_http_request_t *r)
97
 
{
98
 
    ngx_int_t                    rc;
99
 
    ngx_http_echo_ctx_t         *ctx;
100
 
 
101
 
    rc = ngx_http_echo_run_cmds(r);
102
 
 
103
 
    if (rc == NGX_ERROR) {
104
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
105
 
    }
106
 
 
107
 
    if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
108
 
        return rc;
109
 
    }
110
 
 
111
 
    if (rc == NGX_DONE) {
112
 
        return NGX_DONE;
113
 
    }
114
 
 
115
 
    if (rc == NGX_AGAIN) {
116
 
#if defined(nginx_version) && nginx_version >= 8011
117
 
        r->main->count++;
118
 
#endif
119
 
 
120
 
        /* XXX we need this for 0.7.x and 0.8.x < 0.8.11 */
121
 
        dd("%d", r->connection->destroyed);
122
 
        dd("%d", r->done);
123
 
 
124
 
        ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
125
 
        if (ctx) {
126
 
            dd("mark busy %d", (int) ctx->next_handler_cmd);
127
 
            ctx->waiting = 1;
128
 
            ctx->done = 0;
129
 
        }
130
 
 
131
 
        return NGX_DONE;
132
 
    }
133
 
 
134
 
    return NGX_OK;
135
 
}
136
 
 
137
 
 
138
 
ngx_int_t
139
 
ngx_http_echo_run_cmds(ngx_http_request_t *r)
140
 
{
141
 
    ngx_http_echo_loc_conf_t    *elcf;
142
 
    ngx_http_echo_ctx_t         *ctx;
143
 
    ngx_int_t                    rc;
144
 
    ngx_array_t                 *cmds;
145
 
    ngx_array_t                 *computed_args = NULL;
146
 
    ngx_http_echo_cmd_t         *cmd;
147
 
    ngx_http_echo_cmd_t         *cmd_elts;
148
 
    ngx_array_t                 *opts = NULL;
149
 
 
150
 
 
151
 
    elcf = ngx_http_get_module_loc_conf(r, ngx_http_echo_module);
152
 
    cmds = elcf->handler_cmds;
153
 
    if (cmds == NULL) {
154
 
        return NGX_DECLINED;
155
 
    }
156
 
 
157
 
    ctx = ngx_http_get_module_ctx(r, ngx_http_echo_module);
158
 
    if (ctx == NULL) {
159
 
        rc = ngx_http_echo_init_ctx(r, &ctx);
160
 
        if (rc != NGX_OK) {
161
 
            return rc;
162
 
        }
163
 
 
164
 
        ngx_http_set_ctx(r, ctx, ngx_http_echo_module);
165
 
    }
166
 
 
167
 
    dd("exec handler: %.*s: %i", (int) r->uri.len, r->uri.data,
168
 
            (int) ctx->next_handler_cmd);
169
 
 
170
 
    cmd_elts = cmds->elts;
171
 
 
172
 
    for (; ctx->next_handler_cmd < cmds->nelts; ctx->next_handler_cmd++) {
173
 
 
174
 
        cmd = &cmd_elts[ctx->next_handler_cmd];
175
 
 
176
 
        /* evaluate arguments for the current cmd (if any) */
177
 
        if (cmd->args) {
178
 
            computed_args = ngx_array_create(r->pool, cmd->args->nelts,
179
 
                    sizeof(ngx_str_t));
180
 
 
181
 
            if (computed_args == NULL) {
182
 
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
183
 
            }
184
 
 
185
 
            opts = ngx_array_create(r->pool, 1, sizeof(ngx_str_t));
186
 
 
187
 
            if (opts == NULL) {
188
 
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
189
 
            }
190
 
 
191
 
            rc = ngx_http_echo_eval_cmd_args(r, cmd, computed_args, opts);
192
 
            if (rc != NGX_OK) {
193
 
                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
194
 
                        "Failed to evaluate arguments for "
195
 
                        "the directive.");
196
 
                return rc;
197
 
            }
198
 
        }
199
 
 
200
 
        /* do command dispatch based on the opcode */
201
 
        switch (cmd->opcode) {
202
 
        case echo_opcode_echo:
203
 
            /* XXX moved the following code to a separate
204
 
             * function */
205
 
            dd("found echo opcode");
206
 
            rc = ngx_http_echo_exec_echo(r, ctx, computed_args,
207
 
                    0 /* in filter */, opts);
208
 
            break;
209
 
 
210
 
        case echo_opcode_echo_request_body:
211
 
            rc = ngx_http_echo_exec_echo_request_body(r, ctx);
212
 
            break;
213
 
 
214
 
        case echo_opcode_echo_location_async:
215
 
            dd("found opcode echo location async...");
216
 
            rc = ngx_http_echo_exec_echo_location_async(r, ctx,
217
 
                    computed_args);
218
 
            break;
219
 
 
220
 
        case echo_opcode_echo_location:
221
 
            return ngx_http_echo_exec_echo_location(r, ctx, computed_args);
222
 
            break;
223
 
 
224
 
        case echo_opcode_echo_subrequest_async:
225
 
            dd("found opcode echo subrequest async...");
226
 
            rc = ngx_http_echo_exec_echo_subrequest_async(r, ctx,
227
 
                    computed_args);
228
 
            break;
229
 
 
230
 
        case echo_opcode_echo_subrequest:
231
 
            return ngx_http_echo_exec_echo_subrequest(r, ctx, computed_args);
232
 
            break;
233
 
 
234
 
        case echo_opcode_echo_sleep:
235
 
            return ngx_http_echo_exec_echo_sleep(r, ctx, computed_args);
236
 
            break;
237
 
 
238
 
        case echo_opcode_echo_flush:
239
 
            rc = ngx_http_echo_exec_echo_flush(r, ctx);
240
 
            break;
241
 
 
242
 
        case echo_opcode_echo_blocking_sleep:
243
 
            rc = ngx_http_echo_exec_echo_blocking_sleep(r, ctx,
244
 
                    computed_args);
245
 
            break;
246
 
 
247
 
        case echo_opcode_echo_reset_timer:
248
 
            rc = ngx_http_echo_exec_echo_reset_timer(r, ctx);
249
 
            break;
250
 
 
251
 
        case echo_opcode_echo_duplicate:
252
 
            rc = ngx_http_echo_exec_echo_duplicate(r, ctx, computed_args);
253
 
            break;
254
 
 
255
 
        case echo_opcode_echo_read_request_body:
256
 
            ctx->wait_read_request_body = 0;
257
 
 
258
 
            rc = ngx_http_echo_exec_echo_read_request_body(r, ctx);
259
 
 
260
 
#if defined(nginx_version) && nginx_version >= 8011
261
 
            /* XXX read_client_request_body always increments the counter */
262
 
            r->main->count--;
263
 
#endif
264
 
 
265
 
            dd("read request body: %d", (int) rc);
266
 
 
267
 
            if (rc == NGX_OK) {
268
 
                continue;
269
 
            }
270
 
 
271
 
            ctx->wait_read_request_body = 1;
272
 
 
273
 
            /* r->write_event_handler = ngx_http_request_empty_handler; */
274
 
 
275
 
            return rc;
276
 
            break;
277
 
 
278
 
        case echo_opcode_echo_foreach_split:
279
 
            rc = ngx_http_echo_exec_echo_foreach_split(r, ctx, computed_args);
280
 
            break;
281
 
 
282
 
        case echo_opcode_echo_end:
283
 
            rc = ngx_http_echo_exec_echo_end(r, ctx);
284
 
            break;
285
 
 
286
 
        case echo_opcode_echo_exec:
287
 
            dd("echo_exec");
288
 
            return ngx_http_echo_exec_exec(r, ctx, computed_args);
289
 
            break;
290
 
 
291
 
        default:
292
 
            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
293
 
                    "Unknown opcode: %d", cmd->opcode);
294
 
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
295
 
            break;
296
 
        }
297
 
 
298
 
        if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
299
 
            return rc;
300
 
        }
301
 
    }
302
 
 
303
 
    rc = ngx_http_echo_send_chain_link(r, ctx, NULL /* indicate LAST */);
304
 
 
305
 
    if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
306
 
        return rc;
307
 
    }
308
 
 
309
 
    return NGX_OK;
310
 
}
311
 
 
312
 
 
313
 
ngx_int_t
314
 
ngx_http_echo_post_subrequest(ngx_http_request_t *r,
315
 
        void *data, ngx_int_t rc)
316
 
{
317
 
    ngx_http_request_t          *pr;
318
 
    ngx_http_echo_ctx_t         *pr_ctx;
319
 
 
320
 
 
321
 
    dd_enter();
322
 
 
323
 
    pr = r->parent;
324
 
 
325
 
    pr_ctx = ngx_http_get_module_ctx(pr, ngx_http_echo_module);
326
 
    if (pr_ctx == NULL) {
327
 
        return NGX_ERROR;
328
 
    }
329
 
 
330
 
    dd("mark ready %d", (int) pr_ctx->next_handler_cmd);
331
 
 
332
 
    pr_ctx->waiting = 0;
333
 
    pr_ctx->done = 1;
334
 
 
335
 
    pr->write_event_handler = ngx_http_echo_wev_handler;
336
 
 
337
 
    /* ensure that the parent request is (or will be)
338
 
     *  posted out the head of the r->posted_requests chain */
339
 
 
340
 
    if (r->main->posted_requests
341
 
            && r->main->posted_requests->request != pr)
342
 
    {
343
 
        rc = ngx_http_echo_post_request_at_head(pr, NULL);
344
 
        if (rc != NGX_OK) {
345
 
            return NGX_ERROR;
346
 
        }
347
 
    }
348
 
 
349
 
    return rc;
350
 
}
351