Changeset 2055
- Timestamp:
- 01/18/2008 10:54:15 AM (6 months ago)
- Files:
-
- trunk/src/mod_deflate.c (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/mod_deflate.c
r2033 r2055 262 262 if((s->compression_level < 1 || s->compression_level > 9) && 263 263 s->compression_level != Z_DEFAULT_COMPRESSION) { 264 log_error_write(srv, __FILE__, __LINE__, "sd", 265 "compression-level must be between 1 and 9:", s->compression_level); 264 ERROR("compression-level must be between 1 and 9: %i", s->compression_level); 266 265 return HANDLER_ERROR; 267 266 } 268 267 269 268 if(s->mem_level < 1 || s->mem_level > 9) { 270 log_error_write(srv, __FILE__, __LINE__, "sd", 271 "mem-level must be between 1 and 9:", s->mem_level); 269 ERROR("mem-level must be between 1 and 9: %i", s->mem_level); 272 270 return HANDLER_ERROR; 273 271 } 274 272 275 273 if(s->window_size < 1 || s->window_size > 15) { 276 log_error_write(srv, __FILE__, __LINE__, "sd", 277 "window-size must be between 1 and 15:", s->window_size); 274 ERROR("window-size must be between 1 and 15: %i", s->window_size); 278 275 return HANDLER_ERROR; 279 276 } … … 320 317 321 318 if(p->conf.debug) { 322 log_error_write(srv, __FILE__, __LINE__, "sd", 323 "output-buffer-size:", p->conf.output_buffer_size); 324 log_error_write(srv, __FILE__, __LINE__, "sd", 325 "compression-level:", p->conf.compression_level); 326 log_error_write(srv, __FILE__, __LINE__, "sd", 327 "mem-level:", p->conf.mem_level); 328 log_error_write(srv, __FILE__, __LINE__, "sd", 329 "window-size:", p->conf.window_size); 330 log_error_write(srv, __FILE__, __LINE__, "sd", 331 "min-compress-size:", p->conf.min_compress_size); 332 log_error_write(srv, __FILE__, __LINE__, "sd", 333 "work-block-size:", p->conf.work_block_size); 319 TRACE("output-buffer-size: %i", p->conf.output_buffer_size); 320 TRACE("compression-level: %i", p->conf.compression_level); 321 TRACE("mem-level: %i", p->conf.mem_level); 322 TRACE("window-size: %i", p->conf.window_size); 323 TRACE("min-compress-size: %i", p->conf.min_compress_size); 324 TRACE("work-block-size: %i", p->conf.work_block_size); 334 325 } 335 326 if (Z_OK != (r = deflateInit2(z, … … 369 360 buffer_copy_memory(hctx->output, gzip_header, sizeof(gzip_header)); 370 361 if(p->conf.debug) { 371 log_error_write(srv, __FILE__, __LINE__, "sd", 372 "gzip_header len=", sizeof(gzip_header)); 362 TRACE("gzip_header len=%i", sizeof(gzip_header)); 373 363 } 374 364 /* initialize crc32 */ … … 404 394 405 395 if(p->conf.debug) { 406 log_error_write(srv, __FILE__, __LINE__, "sdsd", 407 "compress: in=", in, ", out=", out); 396 TRACE("compress: in=%i, out=%i", in, out); 408 397 } 409 398 return st_size; … … 470 459 471 460 if(p->conf.debug) { 472 log_error_write(srv, __FILE__, __LINE__, "sdsd", 473 "flush: in=", in, ", out=", out); 461 TRACE("flush: in=%i, out=%i", in, out); 474 462 } 475 463 if(p->conf.sync_flush) { … … 508 496 hctx->out->bytes_in += 8; 509 497 if(p->conf.debug) { 510 log_error_write(srv, __FILE__, __LINE__, "sd", 511 "gzip_footer len=", 8); 498 TRACE("gzip_footer len=%i", 8); 512 499 } 513 500 } … … 516 503 if(rc == Z_DATA_ERROR) return 0; 517 504 if(z->msg != NULL) { 518 log_error_write(srv, __FILE__, __LINE__, "sdss", 519 "deflateEnd error ret=", rc, ", msg=", z->msg); 505 ERROR("deflateEnd error ret=%i, msg='%s'", rc, z->msg); 520 506 } else { 521 log_error_write(srv, __FILE__, __LINE__, "sd", 522 "deflateEnd error ret=", rc); 507 ERROR("deflateEnd error ret=%i", rc); 523 508 } 524 509 return -1; … … 547 532 548 533 if(p->conf.debug) { 549 log_error_write(srv, __FILE__, __LINE__, "sd", 550 "output-buffer-size:", p->conf.output_buffer_size); 551 log_error_write(srv, __FILE__, __LINE__, "sd", 552 "compression-level:", p->conf.compression_level); 553 log_error_write(srv, __FILE__, __LINE__, "sd", 554 "mem-level:", p->conf.mem_level); 555 log_error_write(srv, __FILE__, __LINE__, "sd", 556 "window-size:", p->conf.window_size); 557 log_error_write(srv, __FILE__, __LINE__, "sd", 558 "min-compress-size:", p->conf.min_compress_size); 559 log_error_write(srv, __FILE__, __LINE__, "sd", 560 "work-block-size:", p->conf.work_block_size); 534 TRACE("output-buffer-size: %i", p->conf.output_buffer_size); 535 TRACE("compression-level: %i", p->conf.compression_level); 536 TRACE("mem-level: %i", p->conf.mem_level); 537 TRACE("window-size: %i", p->conf.window_size); 538 TRACE("min-compress-size: %i", p->conf.min_compress_size); 539 TRACE("work-block-size: %i", p->conf.work_block_size); 561 540 } 562 541 if (BZ_OK != BZ2_bzCompressInit(bz, … … 612 591 } while (bz->avail_in > 0); 613 592 if(p->conf.debug) { 614 log_error_write(srv, __FILE__, __LINE__, "sdsd", 615 "compress: in=", in, ", out=", out); 593 TRACE("compress: in=%i, out=%i", in, out); 616 594 } 617 595 return st_size; … … 669 647 } while (bz->avail_in != 0 || !done); 670 648 if(p->conf.debug) { 671 log_error_write(srv, __FILE__, __LINE__, "sdsd", 672 "flush: in=", in, ", out=", out); 649 TRACE("flush: in=%i, out=%i", in, out); 673 650 } 674 651 if(p->conf.sync_flush) { … … 685 662 686 663 UNUSED(p); 664 UNUSED(srv); 687 665 UNUSED(con); 688 666 … … 693 671 if ((rc = BZ2_bzCompressEnd(bz)) != BZ_OK) { 694 672 if(rc == BZ_DATA_ERROR) return 0; 695 log_error_write(srv, __FILE__, __LINE__, "sd", 696 "BZ2_bzCompressEnd error ret=", rc); 673 ERROR("BZ2_bzCompressEnd error ret=%i", rc); 697 674 return -1; 698 675 } … … 781 758 782 759 if (HANDLER_ERROR == stat_cache_get_entry(srv, con, c->file.name, &sce)) { 783 ERROR("stat_cache_get_entry( %s) failed: %s",760 ERROR("stat_cache_get_entry('%s') failed: %s", 784 761 BUF_STR(c->file.name), strerror(errno)); 785 762 return -1; … … 788 765 abs_offset = c->file.start + c->offset; 789 766 790 if ( abs_offset > sce->st.st_size) {767 if (c->file.length + c->file.start > sce->st.st_size) { 791 768 ERROR("file '%s' was shrinked: was %lld, is %lld (%lld, %lld)", 792 BUF_STR(c->file.name), abs_offset, sce->st.st_size,769 BUF_STR(c->file.name), c->file.length + c->file.start, sce->st.st_size, 793 770 c->file.start, c->offset); 794 771 … … 848 825 if (-1 == c->file.fd) { /* open the file if not already open */ 849 826 if (-1 == (c->file.fd = open(c->file.name->ptr, O_RDONLY))) { 850 log_error_write(srv, __FILE__, __LINE__, "sbs", "open failed for:", c->file.name, strerror(errno)); 851 827 ERROR("open failed for '%s': %s", BUF_STR(c->file.name), strerror(errno)); 852 828 return -1; 853 829 } … … 860 836 /* close it here, otherwise we'd have to set FD_CLOEXEC */ 861 837 862 log_error_write(srv, __FILE__, __LINE__, "ssbd", "mmap failed:", 863 strerror(errno), c->file.name, c->file.fd); 864 838 ERROR("mmap failed for '%s' (%i): %s", BUF_STR(c->file.name), c->file.fd, strerror(errno)); 865 839 return -1; 866 840 } … … 874 848 if (c->file.mmap.length > (64 KByte) && 875 849 0 != madvise(c->file.mmap.start, c->file.mmap.length, MADV_WILLNEED)) { 876 log_error_write(srv, __FILE__, __LINE__, "ssbd", "madvise failed:", 877 strerror(errno), c->file.name, c->file.fd); 850 ERROR("madvise failed for '%s' (%i): %s", BUF_STR(c->file.name), c->file.fd, strerror(errno)); 878 851 } 879 852 #endif … … 888 861 889 862 if (toSend < 0) { 890 log_error_write(srv, __FILE__, __LINE__, "soooo", 891 "toSend is negative:", 892 toSend, 893 c->file.mmap.length, 894 abs_offset, 895 c->file.mmap.offset); 863 ERROR("toSend is negative: %u %u %u %u", 864 (unsigned int) toSend, 865 (unsigned int) c->file.mmap.length, 866 (unsigned int) abs_offset, 867 (unsigned int) c->file.mmap.offset); 896 868 assert(toSend < 0); 897 869 } … … 904 876 905 877 if(p->conf.debug) { 906 log_error_write(srv, __FILE__, __LINE__, "sdsd", 907 "compress file chunk: offset=", (int)c->offset, 908 ", toSend=", (int)toSend); 878 TRACE("compress file chunk: offset=%i, toSend=%i", (int)c->offset, (int)toSend); 909 879 } 910 880 if (mod_deflate_compress(srv, con, hctx, 911 881 (unsigned char *)start + (abs_offset - c->file.mmap.offset), toSend) < 0) { 912 log_error_write(srv, __FILE__, __LINE__, "s", 913 "compress failed."); 882 ERROR("compress failed.", 0); 914 883 return -1; 915 884 } … … 929 898 930 899 if(p->conf.debug && hctx->bytes_in < hctx->out->bytes_in) { 931 TRACE(" (debug) compressing uri '%s' increased the sent content-size from %lldto %lld",900 TRACE("compressing uri '%s' increased the sent content-size from %i to %lld", 932 901 BUF_STR(con->uri.path_raw), hctx->bytes_in, hctx->out->bytes_in); 933 902 } … … 958 927 we_have = chunkqueue_length(hctx->in); 959 928 if (p->conf.debug) { 960 log_error_write(srv, __FILE__, __LINE__, "sd", 961 "compress: in_queue len=", we_have); 929 TRACE("compress: in_queue len=%i", we_have); 962 930 } 963 931 /* calculate max bytes to compress for this call. */ … … 985 953 986 954 if (mod_deflate_compress(srv, con, hctx, (unsigned char *)(c->mem->ptr + c->offset), we_want) < 0) { 987 log_error_write(srv, __FILE__, __LINE__, "s", 988 "compress failed."); 955 ERROR("compress failed.", 0); 989 956 return HANDLER_ERROR; 990 957 } … … 1000 967 1001 968 if ((we_want = mod_deflate_file_chunk(srv, con, hctx, c, we_want)) < 0) { 1002 log_error_write(srv, __FILE__, __LINE__, "s", 1003 "compress file chunk failed."); 969 ERROR("compress file chunk failed.", 0); 1004 970 return HANDLER_ERROR; 1005 971 } … … 1035 1001 1036 1002 if (p->conf.debug) { 1037 log_error_write(srv, __FILE__, __LINE__, "sd", 1038 "compressed bytes:", out); 1003 TRACE("compressed bytes: %i", out); 1039 1004 } 1040 1005 … … 1054 1019 1055 1020 if (rc < 0) { 1056 log_error_write(srv, __FILE__, __LINE__, "s", "flush error");1021 ERROR("flush error", 0); 1057 1022 } 1058 1023 … … 1060 1025 hctx->out->is_closed = 1; 1061 1026 if(p->conf.debug) { 1062 log_error_write(srv, __FILE__, __LINE__, "sbsb", 1063 "finished uri:", con->uri.path_raw, ", query:", con->uri.query); 1027 TRACE("finished uri: '%s', query: '%s'", BUF_STR(con->uri.path_raw), BUF_STR(con->uri.query)); 1064 1028 } 1065 1029 } else { … … 1161 1125 if(!p->conf.enabled) { 1162 1126 if(p->conf.debug) { 1163 log_error_write(srv, __FILE__, __LINE__, "s", "compression disabled.");1127 TRACE("compression disabled.", 0); 1164 1128 } 1165 1129 return HANDLER_GO_ON; … … 1201 1165 */ 1202 1166 /* most of buggy clients are Yahoo Slurp;) */ 1203 if (p->conf.debug) log_error_write(srv, __FILE__, __LINE__, "ss", 1204 "Buggy HTTP 1.0 client sending Accept Encoding: gzip, deflate", 1167 if (p->conf.debug) TRACE("Buggy HTTP 1.0 client sending 'Accept Encoding: gzip, deflate': %i", 1205 1168 (char *) inet_ntop_cache_get_ip(srv, &(con->dst_addr))); 1206 1169 return HANDLER_GO_ON; … … 1211 1174 fl = filter_chain_get_filter(con->send_filters, p->id); 1212 1175 if (!fl) { 1213 if(p->conf.debug) TRACE(" %s", "add deflate filter to filter chain");1176 if(p->conf.debug) TRACE("add deflate filter to filter chain", 0); 1214 1177 fl = filter_chain_create_filter(con->send_filters, p->id); 1215 1178 } … … 1234 1197 if(file_len > 0 && p->conf.min_compress_size > 0 && file_len < p->conf.min_compress_size) { 1235 1198 if(p->conf.debug) { 1236 log_error_write(srv, __FILE__, __LINE__, "sd", 1237 "Content-Length smaller then min_compress_size: file_len=", file_len); 1199 TRACE("Content-Length smaller then min_compress_size: file_len=%i", file_len); 1238 1200 } 1239 1201 filter_chain_remove_filter(con->send_filters, fl); … … 1245 1207 int found = 0; 1246 1208 if(p->conf.debug) { 1247 log_error_write(srv, __FILE__, __LINE__, "sb", 1248 "Content-Type:", ds->value); 1209 TRACE("Content-Type: %s", BUF_STR(ds->value)); 1249 1210 } 1250 1211 for (m = 0; m < p->conf.mimetypes->used; m++) { … … 1252 1213 1253 1214 if(p->conf.debug) { 1254 log_error_write(srv, __FILE__, __LINE__, "sb", 1255 "mime-type:", mimetype->value); 1215 TRACE("mime-type:", BUF_STR(mimetype->value)); 1256 1216 } 1257 1217 if (strncmp(mimetype->value->ptr, ds->value->ptr, mimetype->value->used-1) == 0) { … … 1263 1223 if(!found && p->conf.mimetypes->used > 0) { 1264 1224 if(p->conf.debug) { 1265 log_error_write(srv, __FILE__, __LINE__, "sb", 1266 "No compression for mimetype:", ds->value); 1225 TRACE("No compression for mimetype: %s", BUF_STR(ds->value)); 1267 1226 } 1268 1227 filter_chain_remove_filter(con->send_filters, fl); … … 1285 1244 buffer_append_string(ds->value, ",Accept-Encoding"); 1286 1245 if (p->conf.debug) { 1287 log_error_write(srv, __FILE__, __LINE__, "sb", 1288 "appending ,Accept-Encoding for ", con->uri.path); 1246 TRACE("appending ,Accept-Encoding for '%s'", BUF_STR(con->uri.path)); 1289 1247 } 1290 1248 } 1291 1249 } else { 1292 1250 if (p->conf.debug) { 1293 log_error_write(srv, __FILE__, __LINE__, "sb", 1294 "add Vary: Accept-Encoding for ", con->uri.path); 1251 TRACE("add Vary: Accept-Encoding for '%s'", BUF_STR(con->uri.path)); 1295 1252 } 1296 1253 response_header_insert(srv, con, CONST_STR_LEN("Vary"), … … 1371 1328 end = 1; 1372 1329 if(p->conf.debug) { 1373 log_error_write(srv, __FILE__, __LINE__, "sd", 1374 "Compress all content and use Content-Length header: uncompress len=", file_len); 1330 TRACE("Compress all content and use Content-Length header: uncompress len=%i", file_len); 1375 1331 } 1376 1332 } 1377 1333 1378 1334 if (p->conf.debug) 1379 log_error_write(srv, __FILE__, __LINE__, "sdsb", "end =", end, "for uri", con->uri.path);1335 TRACE("end = %i for uri '%s'", end, BUF_STR(con->uri.path)); 1380 1336 1381 1337 rc = deflate_compress_response(srv, con, hctx, end); … … 1419 1375 1420 1376 if(p->conf.debug && hctx->stream_open) { 1421 log_error_write(srv, __FILE__, __LINE__, "sbsb", 1422 "stream open at cleanup. uri=", con->uri.path_raw, ", query=", con->uri.query); 1377 TRACE("stream open at cleanup. uri='%s', query='%s'", BUF_STR(con->uri.path_raw), BUF_STR(con->uri.query)); 1423 1378 } 1424 1379

