comparison src/http/modules/ngx_http_dav_module.c @ 230:38e7b94d63ac NGINX_0_4_0

nginx 0.4.0 *) Change in internal API: the HTTP modules initialization was moved from the init module phase to the HTTP postconfiguration phase. *) Change: now the request body is not read beforehand for the ngx_http_perl_module: it's required to start the reading using the $r->has_request_body method. *) Feature: the ngx_http_perl_module supports the DECLINED return code. *) Feature: the ngx_http_dav_module supports the incoming "Date" header line for the PUT method. *) Feature: the "ssi" directive is available inside the "if" block. *) Bugfix: a segmentation fault occurred if there was an "index" directive with variables and the first index name was without variables; bug appeared in 0.1.29.
author Igor Sysoev <http://sysoev.ru>
date Wed, 30 Aug 2006 00:00:00 +0400
parents 9909a161eb28
children acd2ec3541cb
comparison
equal deleted inserted replaced
229:1965c8e23be7 230:38e7b94d63ac
26 static char *ngx_http_dav_access(ngx_conf_t *cf, ngx_command_t *cmd, 26 static char *ngx_http_dav_access(ngx_conf_t *cf, ngx_command_t *cmd,
27 void *conf); 27 void *conf);
28 static void *ngx_http_dav_create_loc_conf(ngx_conf_t *cf); 28 static void *ngx_http_dav_create_loc_conf(ngx_conf_t *cf);
29 static char *ngx_http_dav_merge_loc_conf(ngx_conf_t *cf, 29 static char *ngx_http_dav_merge_loc_conf(ngx_conf_t *cf,
30 void *parent, void *child); 30 void *parent, void *child);
31 static ngx_int_t ngx_http_dav_init(ngx_cycle_t *cycle); 31 static ngx_int_t ngx_http_dav_init(ngx_conf_t *cf);
32 32
33 33
34 static ngx_conf_bitmask_t ngx_http_dav_methods_mask[] = { 34 static ngx_conf_bitmask_t ngx_http_dav_methods_mask[] = {
35 { ngx_string("off"), NGX_HTTP_DAV_OFF }, 35 { ngx_string("off"), NGX_HTTP_DAV_OFF },
36 { ngx_string("put"), NGX_HTTP_PUT }, 36 { ngx_string("put"), NGX_HTTP_PUT },
67 }; 67 };
68 68
69 69
70 static ngx_http_module_t ngx_http_dav_module_ctx = { 70 static ngx_http_module_t ngx_http_dav_module_ctx = {
71 NULL, /* preconfiguration */ 71 NULL, /* preconfiguration */
72 NULL, /* postconfiguration */ 72 ngx_http_dav_init, /* postconfiguration */
73 73
74 NULL, /* create main configuration */ 74 NULL, /* create main configuration */
75 NULL, /* init main configuration */ 75 NULL, /* init main configuration */
76 76
77 NULL, /* create server configuration */ 77 NULL, /* create server configuration */
86 NGX_MODULE_V1, 86 NGX_MODULE_V1,
87 &ngx_http_dav_module_ctx, /* module context */ 87 &ngx_http_dav_module_ctx, /* module context */
88 ngx_http_dav_commands, /* module directives */ 88 ngx_http_dav_commands, /* module directives */
89 NGX_HTTP_MODULE, /* module type */ 89 NGX_HTTP_MODULE, /* module type */
90 NULL, /* init master */ 90 NULL, /* init master */
91 ngx_http_dav_init, /* init module */ 91 NULL, /* init module */
92 NULL, /* init process */ 92 NULL, /* init process */
93 NULL, /* init thread */ 93 NULL, /* init thread */
94 NULL, /* exit thread */ 94 NULL, /* exit thread */
95 NULL, /* exit process */ 95 NULL, /* exit process */
96 NULL, /* exit master */ 96 NULL, /* exit master */
243 static void 243 static void
244 ngx_http_dav_put_handler(ngx_http_request_t *r) 244 ngx_http_dav_put_handler(ngx_http_request_t *r)
245 { 245 {
246 char *failed; 246 char *failed;
247 u_char *name; 247 u_char *name;
248 time_t date;
248 ngx_err_t err; 249 ngx_err_t err;
249 ngx_str_t *temp, path; 250 ngx_str_t *temp, path;
250 ngx_uint_t status; 251 ngx_uint_t status;
251 ngx_file_info_t fi; 252 ngx_file_info_t fi;
252 ngx_http_dav_loc_conf_t *dlcf; 253 ngx_http_dav_loc_conf_t *dlcf;
293 goto failed; 294 goto failed;
294 } 295 }
295 296
296 #endif 297 #endif
297 298
299 if (r->headers_in.date) {
300 date = ngx_http_parse_time(r->headers_in.date->value.data,
301 r->headers_in.date->value.len);
302
303 if (date != NGX_ERROR) {
304 if (ngx_set_file_time(temp->data,
305 r->request_body->temp_file->file.fd, date)
306 != NGX_OK)
307 {
308 err = ngx_errno;
309 failed = ngx_set_file_time_n;
310 name = temp->data;
311
312 goto failed;
313 }
314 }
315 }
316
298 failed = ngx_rename_file_n; 317 failed = ngx_rename_file_n;
299 name = path.data; 318 name = path.data;
300 319
301 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) { 320 if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
302 goto ok; 321 goto ok;
330 } 349 }
331 350
332 err = ngx_errno; 351 err = ngx_errno;
333 } 352 }
334 353
335 354 #endif
336 #else
337 355
338 failed: 356 failed:
339
340 #endif
341 357
342 if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) { 358 if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
343 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, 359 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
344 ngx_delete_file_n " \"%s\" failed", 360 ngx_delete_file_n " \"%s\" failed",
345 temp->data); 361 temp->data);
541 return NGX_CONF_OK; 557 return NGX_CONF_OK;
542 } 558 }
543 559
544 560
545 static ngx_int_t 561 static ngx_int_t
546 ngx_http_dav_init(ngx_cycle_t *cycle) 562 ngx_http_dav_init(ngx_conf_t *cf)
547 { 563 {
548 ngx_http_handler_pt *h; 564 ngx_http_handler_pt *h;
549 ngx_http_core_main_conf_t *cmcf; 565 ngx_http_core_main_conf_t *cmcf;
550 566
551 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module); 567 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
552 568
553 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); 569 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
554 if (h == NULL) { 570 if (h == NULL) {
555 return NGX_ERROR; 571 return NGX_ERROR;
556 } 572 }