annotate src/http/modules/ngx_http_dav_module.c @ 182:13710a1813ad NGINX_0_3_38

nginx 0.3.38 *) Feature: the ngx_http_dav_module. *) Change: the ngx_http_perl_module optimizations. Thanks to Sergey Skvortsov. *) Feature: the ngx_http_perl_module supports the $r->request_body_file method. *) Feature: the "client_body_in_file_only" directive. *) Workaround: now on disk overflow nginx tries to write access logs once a second only. Thanks to Anton Yuzhaninov and Maxim Dounin. *) Bugfix: now the "limit_rate" directive more precisely limits rate if rate is more than 100 Kbyte/s. Thanks to ForJest. *) Bugfix: now the IMAP/POP3 proxy escapes the "\r" and "\n" symbols in login and password to pass authorization server. Thanks to Maxim Dounin.
author Igor Sysoev <http://sysoev.ru>
date Fri, 14 Apr 2006 00:00:00 +0400
parents
children 54aabf2b0bc6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 #define NGX_HTTP_DAV_OFF 2
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 typedef struct {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 ngx_uint_t methods;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 } ngx_http_dav_loc_conf_t;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 static ngx_int_t ngx_http_dav_handler(ngx_http_request_t *r);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 static void ngx_http_dav_put_handler(ngx_http_request_t *r);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 static void *ngx_http_dav_create_loc_conf(ngx_conf_t *cf);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22 static char *ngx_http_dav_merge_loc_conf(ngx_conf_t *cf,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23 void *parent, void *child);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 static ngx_int_t ngx_http_dav_init(ngx_cycle_t *cycle);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 static ngx_conf_bitmask_t ngx_http_dav_methods_mask[] = {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 { ngx_string("off"), NGX_HTTP_DAV_OFF },
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29 { ngx_string("put"), NGX_HTTP_PUT },
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 { ngx_string("delete"), NGX_HTTP_DELETE },
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 { ngx_null_string, 0 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 };
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 static ngx_command_t ngx_http_dav_commands[] = {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 { ngx_string("dav_methods"),
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 ngx_conf_set_bitmask_slot,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 NGX_HTTP_LOC_CONF_OFFSET,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 offsetof(ngx_http_dav_loc_conf_t, methods),
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 &ngx_http_dav_methods_mask },
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 ngx_null_command
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 };
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48 ngx_http_module_t ngx_http_dav_module_ctx = {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 NULL, /* preconfiguration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50 NULL, /* postconfiguration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 NULL, /* create main configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53 NULL, /* init main configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 NULL, /* create server configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 NULL, /* merge server configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 ngx_http_dav_create_loc_conf, /* create location configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 ngx_http_dav_merge_loc_conf /* merge location configuration */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 };
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 ngx_module_t ngx_http_dav_module = {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 NGX_MODULE_V1,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 &ngx_http_dav_module_ctx, /* module context */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 ngx_http_dav_commands, /* module directives */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 NGX_HTTP_MODULE, /* module type */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 NULL, /* init master */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 ngx_http_dav_init, /* init module */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 NULL, /* init process */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 NULL, /* init thread */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 NULL, /* exit thread */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 NULL, /* exit process */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 NULL, /* exit master */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 NGX_MODULE_V1_PADDING
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 };
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 static ngx_int_t
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 ngx_http_dav_handler(ngx_http_request_t *r)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 ngx_int_t rc;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 ngx_str_t path;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 ngx_http_dav_loc_conf_t *dlcf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86 /* TODO: Win32 */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 if (r->zero_in_uri) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 if (!(r->method & dlcf->methods)) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 switch (r->method) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 case NGX_HTTP_PUT:
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101 if (r->uri.data[r->uri.len - 1] == '/') {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 r->request_body_in_file_only = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106 r->request_body_in_persistent_file = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107 r->request_body_delete_incomplete_file = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 r->request_body_file_group_access = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 rc = ngx_http_read_client_request_body(r, ngx_http_dav_put_handler);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 return rc;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 return NGX_DONE;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 case NGX_HTTP_DELETE:
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 if (r->uri.data[r->uri.len - 1] == '/') {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124 ngx_http_map_uri_to_path(r, &path, 0);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 "http delete filename: \"%s\"", path.data);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 if (ngx_delete_file(path.data) == NGX_FILE_ERROR) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 ngx_delete_file_n " \"%s\" failed", path.data);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 return NGX_HTTP_INTERNAL_SERVER_ERROR;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 return NGX_HTTP_NO_CONTENT;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 return NGX_DECLINED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 static void
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 ngx_http_dav_put_handler(ngx_http_request_t *r)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 u_char *location;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 ngx_err_t err;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148 ngx_str_t *temp, path;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149 ngx_uint_t status;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 ngx_file_info_t fi;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
151 ngx_http_core_loc_conf_t *clcf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153 ngx_http_map_uri_to_path(r, &path, 0);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156 "http put filename: \"%s\"", path.data);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 temp = &r->request_body->temp_file->file.name;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160 if (ngx_file_info(path.data, &fi) == -1) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161 status = NGX_HTTP_CREATED;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163 } else {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164 status = NGX_HTTP_NO_CONTENT;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
165 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
166
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 goto ok;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 err = ngx_errno;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 #if (NGX_WIN32)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
175 if (err == NGX_EEXIST) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
176 if (ngx_win32_rename_file(temp, &path, r->pool) != NGX_ERROR) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
178 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179 goto ok;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
180 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
181 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183 err = ngx_errno;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
186 #endif
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
187
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
188 ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189 ngx_rename_file_n " \"%s\" failed", path.data);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192 return;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194 ok:
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
196 if (status == NGX_HTTP_CREATED) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
197
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
198 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
199 if (r->headers_out.location == NULL) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
200 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201 return;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
204 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206 if (!clcf->alias && clcf->root_lengths == NULL) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207 location = path.data + clcf->root.len;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
209 } else {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 location = ngx_palloc(r->pool, r->uri.len);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 if (location == NULL) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213 return;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
216 ngx_memcpy(location, r->uri.data, r->uri.len);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
217 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219 /*
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
220 * we do not need to set the r->headers_out.location->hash and
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 * r->headers_out.location->key fields
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222 */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
223
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
224 r->headers_out.location->value.len = r->uri.len;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225 r->headers_out.location->value.data = location;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229 r->headers_out.status = status;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230 r->header_only = 1;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232 ngx_http_finalize_request(r, ngx_http_send_header(r));
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 return;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237 static void *
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 ngx_http_dav_create_loc_conf(ngx_conf_t *cf)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 ngx_http_dav_loc_conf_t *conf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
242 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_dav_loc_conf_t));
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243 if (conf == NULL) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244 return NGX_CONF_ERROR;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247 /*
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 * set by ngx_pcalloc():
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 *
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 * conf->methods = 0;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 */
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 return conf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 static char *
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258 ngx_http_dav_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259 {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 ngx_http_dav_loc_conf_t *prev = parent;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261 ngx_http_dav_loc_conf_t *conf = child;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263 ngx_conf_merge_bitmask_value(conf->methods, prev->methods,
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264 (NGX_CONF_BITMASK_SET|NGX_HTTP_DAV_OFF));
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266 return NGX_CONF_OK;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270 static ngx_int_t
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 ngx_http_dav_init(ngx_cycle_t *cycle)
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273 ngx_http_handler_pt *h;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274 ngx_http_core_main_conf_t *cmcf;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
279 if (h == NULL) {
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 return NGX_ERROR;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281 }
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 *h = ngx_http_dav_handler;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285 return NGX_OK;
13710a1813ad nginx 0.3.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286 }