annotate src/http/modules/ngx_http_flv_module.c @ 754:4ac89c5aa10d

style fix: remove trailing spaces
author Igor Sysoev <igor@sysoev.ru>
date Mon, 09 Oct 2006 15:38:59 +0000
parents af72ac9c3dbf
children 761a94247118
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
753
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6 #include <ngx_config.h>
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_core.h>
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_http.h>
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11 static char *ngx_http_flv(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 static ngx_command_t ngx_http_flv_commands[] = {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 { ngx_string("flv"),
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 ngx_http_flv,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 0,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 0,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 NULL },
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 ngx_null_command
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 };
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 static u_char ngx_flv_header[] = "FLV\x1\x1\0\0\0\x9\0\0\0\x9";
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 static ngx_http_module_t ngx_http_flv_module_ctx = {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 NULL, /* preconfiguration */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 NULL, /* postconfiguration */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 NULL, /* create main configuration */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 NULL, /* init main configuration */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 NULL, /* create server configuration */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37 NULL, /* merge server configuration */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 NULL, /* create location configuration */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 NULL /* merge location configuration */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 };
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 ngx_module_t ngx_http_flv_module = {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 NGX_MODULE_V1,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 &ngx_http_flv_module_ctx, /* module context */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47 ngx_http_flv_commands, /* module directives */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 NGX_HTTP_MODULE, /* module type */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 NULL, /* init master */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 NULL, /* init module */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 NULL, /* init process */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 NULL, /* init thread */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53 NULL, /* exit thread */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54 NULL, /* exit process */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 NULL, /* exit master */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 NGX_MODULE_V1_PADDING
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 };
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 static ngx_int_t
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 ngx_http_flv_handler(ngx_http_request_t *r)
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 u_char *p;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 off_t start, len;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 ngx_fd_t fd;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66 ngx_int_t rc;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67 ngx_uint_t level;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 ngx_str_t path;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69 ngx_err_t err;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 ngx_log_t *log;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 ngx_buf_t *b;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 ngx_chain_t out[2];
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 ngx_file_info_t fi;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 ngx_pool_cleanup_t *cln;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 ngx_pool_cleanup_file_t *clnf;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 ngx_http_core_loc_conf_t *clcf;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 return NGX_HTTP_NOT_ALLOWED;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 if (r->uri.data[r->uri.len - 1] == '/') {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 return NGX_DECLINED;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 /* TODO: Win32 */
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 if (r->zero_in_uri) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 return NGX_DECLINED;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 rc = ngx_http_discard_body(r);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 if (rc != NGX_OK && rc != NGX_AGAIN) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 return rc;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 if (ngx_http_map_uri_to_path(r, &path, 0) == NULL) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 return NGX_HTTP_INTERNAL_SERVER_ERROR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 log = r->connection->log;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 "http flv filename: \"%s\"", path.data);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_pool_cleanup_file_t));
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 if (cln == NULL) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 return NGX_HTTP_INTERNAL_SERVER_ERROR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 fd = ngx_open_file(path.data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113 if (fd == NGX_INVALID_FILE) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 err = ngx_errno;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 if (err == NGX_ENOENT
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117 || err == NGX_ENOTDIR
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 || err == NGX_ENAMETOOLONG)
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 level = NGX_LOG_ERR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 rc = NGX_HTTP_NOT_FOUND;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 } else if (err == NGX_EACCES) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124 level = NGX_LOG_ERR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 rc = NGX_HTTP_FORBIDDEN;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 } else {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 level = NGX_LOG_CRIT;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 ngx_log_error(level, log, err,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 ngx_open_file_n " \"%s\" failed", path.data);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 return rc;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 ngx_fd_info_n " \"%s\" failed", path.data);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 ngx_close_file_n " \"%s\" failed", path.data);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 return NGX_HTTP_INTERNAL_SERVER_ERROR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 if (!ngx_is_file(&fi)) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 ngx_close_file_n " \"%s\" failed", path.data);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 return NGX_DECLINED;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 start = 0;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 len = ngx_file_size(&fi);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167 if (r->args.len) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 p = (u_char *) ngx_strstr(r->args.data, "start=");
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 if (p) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 p += 6;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 start = ngx_atoof(p, r->args.len - (p - r->args.data));
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 if (start == NGX_ERROR || start >= len) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 start = 0;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 len -= start;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 log->action = "sending flv to client";
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 cln->handler = ngx_pool_cleanup_file;
754
4ac89c5aa10d style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents: 753
diff changeset
186 clnf = cln->data;
753
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 clnf->fd = fd;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 clnf->name = path.data;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190 clnf->log = r->pool->log;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 r->headers_out.status = NGX_HTTP_OK;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 r->headers_out.content_length_n = sizeof(ngx_flv_header) - 1 + len;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 r->headers_out.last_modified_time = ngx_file_mtime(&fi);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 if (ngx_http_set_content_type(r) != NGX_OK) {
754
4ac89c5aa10d style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents: 753
diff changeset
197 return NGX_HTTP_INTERNAL_SERVER_ERROR;
753
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201 if (b == NULL) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 return NGX_HTTP_INTERNAL_SERVER_ERROR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 b->pos = ngx_flv_header;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 b->last = ngx_flv_header + sizeof(ngx_flv_header) - 1;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 b->memory = 1;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209 out[0].buf = b;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 out[0].next = &out[1];
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 if (b == NULL) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 return NGX_HTTP_INTERNAL_SERVER_ERROR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 if (b->file == NULL) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 return NGX_HTTP_INTERNAL_SERVER_ERROR;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 rc = ngx_http_send_header(r);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225 return rc;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 b->file_pos = start;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229 b->file_last = ngx_file_size(&fi);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231 b->in_file = b->file_last ? 1: 0;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232 b->last_buf = 1;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 b->last_in_chain = 1;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 b->file->fd = fd;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 b->file->name = path;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 b->file->log = log;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 out[1].buf = b;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 out[1].next = NULL;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 return ngx_http_output_filter(r, out);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 }
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246 static char *
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
247 ngx_http_flv(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 {
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249 ngx_http_core_loc_conf_t *clcf;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
251 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252 clcf->handler = ngx_http_flv_handler;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 return NGX_CONF_OK;
af72ac9c3dbf ngx_http_flv_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255 }