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

« back to all changes in this revision

Viewing changes to modules/nginx-echo/src/ngx_http_echo_echo.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
 
#include "ddebug.h"
3
 
 
4
 
#include "ngx_http_echo_echo.h"
5
 
#include "ngx_http_echo_util.h"
6
 
#include "ngx_http_echo_filter.h"
7
 
 
8
 
#include <nginx.h>
9
 
 
10
 
static ngx_buf_t ngx_http_echo_space_buf;
11
 
 
12
 
static ngx_buf_t ngx_http_echo_newline_buf;
13
 
 
14
 
ngx_int_t
15
 
ngx_http_echo_echo_init(ngx_conf_t *cf)
16
 
{
17
 
    static u_char space_str[]   = " ";
18
 
    static u_char newline_str[] = "\n";
19
 
 
20
 
    dd("global init...");
21
 
 
22
 
    ngx_memzero(&ngx_http_echo_space_buf, sizeof(ngx_buf_t));
23
 
    ngx_http_echo_space_buf.memory = 1;
24
 
    ngx_http_echo_space_buf.start =
25
 
        ngx_http_echo_space_buf.pos =
26
 
            space_str;
27
 
    ngx_http_echo_space_buf.end =
28
 
        ngx_http_echo_space_buf.last =
29
 
            space_str + sizeof(space_str) - 1;
30
 
 
31
 
    ngx_memzero(&ngx_http_echo_newline_buf, sizeof(ngx_buf_t));
32
 
    ngx_http_echo_newline_buf.memory = 1;
33
 
    ngx_http_echo_newline_buf.start =
34
 
        ngx_http_echo_newline_buf.pos =
35
 
            newline_str;
36
 
    ngx_http_echo_newline_buf.end =
37
 
        ngx_http_echo_newline_buf.last =
38
 
            newline_str + sizeof(newline_str) - 1;
39
 
 
40
 
    return NGX_OK;
41
 
}
42
 
 
43
 
 
44
 
ngx_int_t
45
 
ngx_http_echo_exec_echo(ngx_http_request_t *r,
46
 
        ngx_http_echo_ctx_t *ctx, ngx_array_t *computed_args,
47
 
        ngx_flag_t in_filter, ngx_array_t *opts)
48
 
{
49
 
    ngx_uint_t                  i;
50
 
 
51
 
    ngx_buf_t                   *space_buf;
52
 
    ngx_buf_t                   *newline_buf;
53
 
    ngx_buf_t                   *buf;
54
 
 
55
 
    ngx_str_t                   *computed_arg;
56
 
    ngx_str_t                   *computed_arg_elts;
57
 
    ngx_str_t                   *opt;
58
 
 
59
 
    ngx_chain_t *cl  = NULL; /* the head of the chain link */
60
 
    ngx_chain_t **ll = &cl;  /* always point to the address of the last link */
61
 
 
62
 
 
63
 
    dd_enter();
64
 
 
65
 
    if (computed_args == NULL) {
66
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
67
 
    }
68
 
 
69
 
    computed_arg_elts = computed_args->elts;
70
 
    for (i = 0; i < computed_args->nelts; i++) {
71
 
        computed_arg = &computed_arg_elts[i];
72
 
 
73
 
        if (computed_arg->len == 0) {
74
 
            buf = NULL;
75
 
 
76
 
        } else {
77
 
            buf = ngx_calloc_buf(r->pool);
78
 
            if (buf == NULL) {
79
 
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
80
 
            }
81
 
 
82
 
            buf->start = buf->pos = computed_arg->data;
83
 
            buf->last = buf->end = computed_arg->data +
84
 
                computed_arg->len;
85
 
 
86
 
            buf->memory = 1;
87
 
        }
88
 
 
89
 
        if (cl == NULL) {
90
 
            cl = ngx_alloc_chain_link(r->pool);
91
 
            if (cl == NULL) {
92
 
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
93
 
            }
94
 
            cl->buf  = buf;
95
 
            cl->next = NULL;
96
 
            ll = &cl->next;
97
 
        } else {
98
 
            /* append a space first */
99
 
            *ll = ngx_alloc_chain_link(r->pool);
100
 
 
101
 
            if (*ll == NULL) {
102
 
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
103
 
            }
104
 
 
105
 
            space_buf = ngx_calloc_buf(r->pool);
106
 
 
107
 
            if (space_buf == NULL) {
108
 
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
109
 
            }
110
 
 
111
 
            /* nginx clears buf flags at the end of each request handling,
112
 
             * so we have to make a clone here. */
113
 
            *space_buf = ngx_http_echo_space_buf;
114
 
 
115
 
            (*ll)->buf = space_buf;
116
 
            (*ll)->next = NULL;
117
 
 
118
 
            ll = &(*ll)->next;
119
 
 
120
 
            /* then append the buf only if it's non-empty */
121
 
            if (buf) {
122
 
                *ll = ngx_alloc_chain_link(r->pool);
123
 
                if (*ll == NULL) {
124
 
                    return NGX_HTTP_INTERNAL_SERVER_ERROR;
125
 
                }
126
 
                (*ll)->buf  = buf;
127
 
                (*ll)->next = NULL;
128
 
 
129
 
                ll = &(*ll)->next;
130
 
            }
131
 
        }
132
 
    } /* end for */
133
 
 
134
 
    if (opts && opts->nelts > 0) {
135
 
        opt = opts->elts;
136
 
        if (opt[0].len == 1 && opt[0].data[0] == 'n') {
137
 
            goto done;
138
 
        }
139
 
    }
140
 
 
141
 
    /* append the newline character */
142
 
 
143
 
    if (cl && cl->buf == NULL) {
144
 
        cl = cl->next;
145
 
    }
146
 
 
147
 
    newline_buf = ngx_calloc_buf(r->pool);
148
 
 
149
 
    if (newline_buf == NULL) {
150
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
151
 
    }
152
 
 
153
 
    *newline_buf = ngx_http_echo_newline_buf;
154
 
 
155
 
    if (cl == NULL) {
156
 
        cl = ngx_alloc_chain_link(r->pool);
157
 
 
158
 
        if (cl == NULL) {
159
 
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
160
 
        }
161
 
 
162
 
        cl->buf = newline_buf;
163
 
        cl->next = NULL;
164
 
        /* ll = &cl->next; */
165
 
 
166
 
    } else {
167
 
        *ll = ngx_alloc_chain_link(r->pool);
168
 
 
169
 
        if (*ll == NULL) {
170
 
            return NGX_HTTP_INTERNAL_SERVER_ERROR;
171
 
        }
172
 
 
173
 
        (*ll)->buf  = newline_buf;
174
 
        (*ll)->next = NULL;
175
 
        /* ll = &(*ll)->next; */
176
 
    }
177
 
 
178
 
done:
179
 
 
180
 
    if (cl == NULL || cl->buf == NULL) {
181
 
        return NGX_OK;
182
 
    }
183
 
 
184
 
    if (in_filter) {
185
 
        return ngx_http_echo_next_body_filter(r, cl);
186
 
    }
187
 
 
188
 
    return ngx_http_echo_send_chain_link(r, ctx, cl);
189
 
}
190
 
 
191
 
 
192
 
ngx_int_t
193
 
ngx_http_echo_exec_echo_flush(ngx_http_request_t *r, ngx_http_echo_ctx_t *ctx)
194
 
{
195
 
    return ngx_http_send_special(r, NGX_HTTP_FLUSH);
196
 
}
197
 
 
198
 
 
199
 
ngx_int_t
200
 
ngx_http_echo_exec_echo_request_body(ngx_http_request_t *r, ngx_http_echo_ctx_t *ctx)
201
 
{
202
 
    if (r->request_body && r->request_body->bufs) {
203
 
        return ngx_http_echo_send_chain_link(r, ctx, r->request_body->bufs);
204
 
    }
205
 
 
206
 
    return NGX_OK;
207
 
}
208
 
 
209
 
 
210
 
ngx_int_t
211
 
ngx_http_echo_exec_echo_duplicate(ngx_http_request_t *r,
212
 
        ngx_http_echo_ctx_t *ctx, ngx_array_t *computed_args)
213
 
{
214
 
    ngx_str_t                   *computed_arg;
215
 
    ngx_str_t                   *computed_arg_elts;
216
 
    ssize_t                     i, count;
217
 
    ngx_str_t                   *str;
218
 
    u_char                      *p;
219
 
    ngx_int_t                   rc;
220
 
 
221
 
    ngx_buf_t                   *buf;
222
 
    ngx_chain_t                 *cl;
223
 
 
224
 
 
225
 
    dd_enter();
226
 
 
227
 
    computed_arg_elts = computed_args->elts;
228
 
 
229
 
    computed_arg = &computed_arg_elts[0];
230
 
 
231
 
    count = ngx_http_echo_atosz(computed_arg->data, computed_arg->len);
232
 
 
233
 
    if (count == NGX_ERROR) {
234
 
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
235
 
                   "invalid size specified: \"%V\"", computed_arg);
236
 
 
237
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
238
 
    }
239
 
 
240
 
    str = &computed_arg_elts[1];
241
 
 
242
 
    if (count == 0 || str->len == 0) {
243
 
        rc = ngx_http_echo_send_header_if_needed(r, ctx);
244
 
        if (r->header_only || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
245
 
            return rc;
246
 
        }
247
 
        return NGX_OK;
248
 
    }
249
 
 
250
 
    buf = ngx_create_temp_buf(r->pool, count * str->len);
251
 
    if (buf == NULL) {
252
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
253
 
    }
254
 
 
255
 
    p = buf->pos;
256
 
    for (i = 0; i < count; i++) {
257
 
        p = ngx_copy(p, str->data, str->len);
258
 
    }
259
 
    buf->last = p;
260
 
 
261
 
    cl = ngx_alloc_chain_link(r->pool);
262
 
    if (cl == NULL) {
263
 
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
264
 
    }
265
 
    cl->next = NULL;
266
 
    cl->buf = buf;
267
 
 
268
 
    return ngx_http_echo_send_chain_link(r, ctx, cl);
269
 
}
270