comparison src/http/modules/ngx_http_autoindex_handler.c @ 10:46833bd150cb NGINX_0_1_5

nginx 0.1.5 *) Bugfix: on Solaris and Linux there may be too many "recvmsg() returned not enough data" alerts. *) Bugfix: there were the "writev() failed (22: Invalid argument)" errors on Solaris in proxy mode without sendfile. On other platforms that do not support sendfile at all the process got caught in an endless loop. *) Bugfix: segmentation fault on Solaris in proxy mode and using sendfile. *) Bugfix: segmentation fault on Solaris. *) Bugfix: on-line upgrade did not work on Linux. *) Bugfix: the ngx_http_autoindex_module module did not escape the spaces, the quotes, and the percent signs in the directory listing. *) Change: the decrease of the copy operations. *) Feature: the userid_p3p directive.
author Igor Sysoev <http://sysoev.ru>
date Thu, 11 Nov 2004 00:00:00 +0300
parents 983306b77348
children 74b1868dd3cd
comparison
equal deleted inserted replaced
9:77eee314ddbd 10:46833bd150cb
22 #endif 22 #endif
23 23
24 24
25 typedef struct { 25 typedef struct {
26 ngx_str_t name; 26 ngx_str_t name;
27 ngx_uint_t escape;
27 ngx_uint_t dir; 28 ngx_uint_t dir;
28 time_t mtime; 29 time_t mtime;
29 off_t size; 30 off_t size;
30 } ngx_http_autoindex_entry_t; 31 } ngx_http_autoindex_entry_t;
31 32
267 if (!(entry = ngx_array_push(&entries))) { 268 if (!(entry = ngx_array_push(&entries))) {
268 return ngx_http_autoindex_error(r, &dir, dname.data); 269 return ngx_http_autoindex_error(r, &dir, dname.data);
269 } 270 }
270 271
271 entry->name.len = len; 272 entry->name.len = len;
272 273 entry->escape = 2 * ngx_escape_uri(NULL, ngx_de_name(&dir), len,
273 if (!(entry->name.data = ngx_palloc(pool, len + 1))) { 274 NGX_ESCAPE_HTML);
275
276 if (!(entry->name.data = ngx_palloc(pool, len + entry->escape + 1))) {
274 return ngx_http_autoindex_error(r, &dir, dname.data); 277 return ngx_http_autoindex_error(r, &dir, dname.data);
275 } 278 }
279
276 ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1); 280 ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1);
277 281
278 entry->dir = ngx_de_is_dir(&dir); 282 entry->dir = ngx_de_is_dir(&dir);
279 entry->mtime = ngx_de_mtime(&dir); 283 entry->mtime = ngx_de_mtime(&dir);
280 entry->size = ngx_de_size(&dir); 284 entry->size = ngx_de_size(&dir);
296 300
297 entry = entries.elts; 301 entry = entries.elts;
298 for (i = 0; i < entries.nelts; i++) { 302 for (i = 0; i < entries.nelts; i++) {
299 len += sizeof("<a href=\"") - 1 303 len += sizeof("<a href=\"") - 1
300 + 1 /* 1 is for "/" */ 304 + 1 /* 1 is for "/" */
301 + entry[i].name.len 305 + entry[i].name.len + entry[i].escape
302 + sizeof("\">") - 1 306 + sizeof("\">") - 1
303 + NGX_HTTP_AUTOINDEX_NAME_LEN 307 + NGX_HTTP_AUTOINDEX_NAME_LEN
304 + sizeof("</a>") - 1 308 + sizeof("</a>") - 1
305 + 1 309 + 1
306 + sizeof("28-Sep-1970 12:00 ") - 1 310 + sizeof("28-Sep-1970 12:00 ") - 1
327 b->last = ngx_cpymem(b->last, "<hr><pre><a href=\"../\">../</a>" CRLF, 331 b->last = ngx_cpymem(b->last, "<hr><pre><a href=\"../\">../</a>" CRLF,
328 sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1); 332 sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1);
329 333
330 for (i = 0; i < entries.nelts; i++) { 334 for (i = 0; i < entries.nelts; i++) {
331 b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1); 335 b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1);
332 b->last = ngx_cpymem(b->last, entry[i].name.data, entry[i].name.len); 336
337 if (entry[i].escape) {
338 ngx_escape_uri(b->last, entry[i].name.data, entry[i].name.len,
339 NGX_ESCAPE_HTML);
340
341 b->last += entry[i].name.len + entry[i].escape;
342
343 } else {
344 b->last = ngx_cpymem(b->last, entry[i].name.data,
345 entry[i].name.len);
346 }
333 347
334 if (entry[i].dir) { 348 if (entry[i].dir) {
335 *b->last++ = '/'; 349 *b->last++ = '/';
336 } 350 }
337 351
373 b->last = ngx_cpymem(b->last, " -", sizeof(" -") - 1); 387 b->last = ngx_cpymem(b->last, " -", sizeof(" -") - 1);
374 388
375 } else { 389 } else {
376 length = entry[i].size; 390 length = entry[i].size;
377 391
378 if (length > 1024 * 1024 * 1024) { 392 if (length > 1024 * 1024 * 1024 - 1) {
379 size = (ngx_int_t) (length / (1024 * 1024 * 1024)); 393 size = (ngx_int_t) (length / (1024 * 1024 * 1024));
380 if ((length % (1024 * 1024 * 1024)) 394 if ((length % (1024 * 1024 * 1024))
381 > (1024 * 1024 * 1024 / 2 - 1)) 395 > (1024 * 1024 * 1024 / 2 - 1))
382 { 396 {
383 size++; 397 size++;
384 } 398 }
385 scale = 'G'; 399 scale = 'G';
386 400
387 } else if (length > 1024 * 1024) { 401 } else if (length > 1024 * 1024 - 1) {
388 size = (ngx_int_t) (length / (1024 * 1024)); 402 size = (ngx_int_t) (length / (1024 * 1024));
389 if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) { 403 if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) {
390 size++; 404 size++;
391 } 405 }
392 scale = 'M'; 406 scale = 'M';