~ubuntu-branches/ubuntu/trusty/nginx/trusty-proposed

« back to all changes in this revision

Viewing changes to src/http/modules/ngx_http_flv_module.c

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2013-04-25 12:51:45 UTC
  • mfrom: (1.3.28)
  • mto: (1.3.29) (15.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: package-import@ubuntu.com-20130425125145-ugl0wor6bq0u5eae
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
3
 * Copyright (C) Igor Sysoev
 
4
 * Copyright (C) Nginx, Inc.
4
5
 */
5
6
 
6
7
#include <ngx_config.h>
23
24
};
24
25
 
25
26
 
26
 
static u_char  ngx_flv_header[] = "FLV\x1\x1\0\0\0\x9\0\0\0\x9";
 
27
static u_char  ngx_flv_header[] = "FLV\x1\x5\0\0\0\x9\0\0\0\0";
27
28
 
28
29
 
29
30
static ngx_http_module_t  ngx_http_flv_module_ctx = {
60
61
static ngx_int_t
61
62
ngx_http_flv_handler(ngx_http_request_t *r)
62
63
{
63
 
    u_char                    *p, *n, *last;
 
64
    u_char                    *last;
64
65
    off_t                      start, len;
65
66
    size_t                     root;
66
67
    ngx_int_t                  rc;
67
68
    ngx_uint_t                 level, i;
68
 
    ngx_str_t                  path;
 
69
    ngx_str_t                  path, value;
69
70
    ngx_log_t                 *log;
70
71
    ngx_buf_t                 *b;
71
72
    ngx_chain_t                out[2];
80
81
        return NGX_DECLINED;
81
82
    }
82
83
 
83
 
    /* TODO: Win32 */
84
 
    if (r->zero_in_uri) {
85
 
        return NGX_DECLINED;
86
 
    }
87
 
 
88
84
    rc = ngx_http_discard_request_body(r);
89
85
 
90
86
    if (rc != NGX_OK) {
105
101
 
106
102
    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
107
103
 
108
 
    of.test_dir = 0;
 
104
    ngx_memzero(&of, sizeof(ngx_open_file_info_t));
 
105
 
 
106
    of.read_ahead = clcf->read_ahead;
 
107
    of.directio = clcf->directio;
109
108
    of.valid = clcf->open_file_cache_valid;
110
109
    of.min_uses = clcf->open_file_cache_min_uses;
111
110
    of.errors = clcf->open_file_cache_errors;
112
111
    of.events = clcf->open_file_cache_events;
113
112
 
 
113
    if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) {
 
114
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
115
    }
 
116
 
114
117
    if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
115
118
        != NGX_OK)
116
119
    {
128
131
            break;
129
132
 
130
133
        case NGX_EACCES:
 
134
#if (NGX_HAVE_OPENAT)
 
135
        case NGX_EMLINK:
 
136
        case NGX_ELOOP:
 
137
#endif
131
138
 
132
139
            level = NGX_LOG_ERR;
133
140
            rc = NGX_HTTP_FORBIDDEN;
142
149
 
143
150
        if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
144
151
            ngx_log_error(level, log, of.err,
145
 
                          ngx_open_file_n " \"%s\" failed", path.data);
 
152
                          "%s \"%s\" failed", of.failed, path.data);
146
153
        }
147
154
 
148
155
        return rc;
158
165
        return NGX_DECLINED;
159
166
    }
160
167
 
 
168
    r->root_tested = !r->error_page;
 
169
 
161
170
    start = 0;
162
171
    len = of.size;
163
172
    i = 1;
164
173
 
165
174
    if (r->args.len) {
166
 
        p = (u_char *) ngx_strnstr(r->args.data, "start=", r->args.len);
167
 
 
168
 
        if (p) {
169
 
            p += 6;
170
 
 
171
 
            for (n = p; n < r->args.data + r->args.len; n++) {
172
 
                if (*n == '&') {
173
 
                    break;
174
 
                }
175
 
            }
176
 
 
177
 
            start = ngx_atoof(p, n - p);
 
175
 
 
176
        if (ngx_http_arg(r, (u_char *) "start", 5, &value) == NGX_OK) {
 
177
 
 
178
            start = ngx_atoof(value.data, value.len);
178
179
 
179
180
            if (start == NGX_ERROR || start >= len) {
180
181
                start = 0;
193
194
    r->headers_out.content_length_n = len;
194
195
    r->headers_out.last_modified_time = of.mtime;
195
196
 
 
197
    if (ngx_http_set_etag(r) != NGX_OK) {
 
198
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
 
199
    }
 
200
 
196
201
    if (ngx_http_set_content_type(r) != NGX_OK) {
197
202
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
198
203
    }
209
214
 
210
215
        out[0].buf = b;
211
216
        out[0].next = &out[1];
212
 
 
213
 
    } else {
214
 
        r->allow_ranges = 1;
215
217
    }
216
218
 
217
219
 
225
227
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
226
228
    }
227
229
 
 
230
    r->allow_ranges = 1;
 
231
 
228
232
    rc = ngx_http_send_header(r);
229
233
 
230
234
    if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
235
239
    b->file_last = of.size;
236
240
 
237
241
    b->in_file = b->file_last ? 1: 0;
238
 
    b->last_buf = 1;
 
242
    b->last_buf = (r == r->main) ? 1 : 0;
239
243
    b->last_in_chain = 1;
240
244
 
241
245
    b->file->fd = of.fd;
242
246
    b->file->name = path;
243
247
    b->file->log = log;
 
248
    b->file->directio = of.is_directio;
244
249
 
245
250
    out[1].buf = b;
246
251
    out[1].next = NULL;