1 Index: lighttpd.spec.in
2 ===================================================================
3 --- lighttpd.spec.in (.../tags/lighttpd-1.4.19) (revision 2303)
4 +++ lighttpd.spec.in (.../branches/lighttpd-1.4.x) (revision 2303)
6 -Summary: A fast webserver with minimal memory-footprint (lighttpd)
10 -Source: http://jan.kneschke.de/projects/lighttpd/download/lighttpd-%version.tar.gz
11 -Packager: Jan Kneschke <jan@kneschke.de>
13 -Group: Networking/Daemons
14 -URL: http://www.lighttpd.net/
15 -Requires: pcre >= 3.1 zlib
16 -BuildRequires: libtool zlib-devel
17 -BuildRoot: %{_tmppath}/%{name}-root
20 -lighttpd is intented to be a frontend for ad-servers which have to deliver
21 -small files concurrently to many connections.
23 -Available rpmbuild rebuild options:
24 ---with: ssl mysql lua memcache
32 - %{?_with_mysql: --with-mysql} \
33 - %{?_with_lua: --with-lua} \
34 - %{?_with_memcache: --with-memcache} \
35 - %{?_with_ssl: --with-openssl}
41 -mkdir -p %{buildroot}%{_sysconfdir}/{init.d,sysconfig}
42 -if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then
43 - install -m 755 doc/rc.lighttpd.redhat %{buildroot}%{_sysconfdir}/init.d/lighttpd
45 - install -m 755 doc/rc.lighttpd %{buildroot}%{_sysconfdir}/init.d/lighttpd
47 -install -m 644 doc/sysconfig.lighttpd %{buildroot}%{_sysconfdir}/sysconfig/lighttpd
53 -## read http://www.fedora.us/docs/spec.html next time :)
54 -if [ "$1" = "1" ]; then
55 - # real install, not upgrade
56 - /sbin/chkconfig --add lighttpd
60 -if [ "$1" = "0"]; then
61 - # real uninstall, not upgrade
62 - %{_sysconfdir}/init.d/lighttpd stop
63 - /sbin/chkconfig --del lighttpd
67 -%defattr(-,root,root)
68 -%doc doc/lighttpd.conf doc/lighttpd.user README INSTALL ChangeLog COPYING AUTHORS
70 -%config(noreplace) %attr(0755,root,root) %{_sysconfdir}/init.d/lighttpd
71 -%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/sysconfig/lighttpd
78 -* Thu Sep 30 2004 12:41 <jan@kneschke.de> 1.3.1
81 -* Tue Jun 29 2004 17:26 <jan@kneschke.de> 1.2.3
82 -- rpmlint'ed the package
84 -- added (noreplace) to start-script
85 -- change group to Networking/Daemon (like apache)
87 -* Sun Feb 23 2003 15:04 <jan@kneschke.de>
90 ===================================================================
91 Index: src/mod_ssi_exprparser.h
92 ===================================================================
93 --- src/mod_ssi_exprparser.h (.../tags/lighttpd-1.4.19) (revision 2303)
94 +++ src/mod_ssi_exprparser.h (.../branches/lighttpd-1.4.x) (revision 2303)
105 -#define TK_LPARAN 10
106 -#define TK_RPARAN 11
108 Index: src/configfile-glue.c
109 ===================================================================
110 --- src/configfile-glue.c (.../tags/lighttpd-1.4.19) (revision 2303)
111 +++ src/configfile-glue.c (.../branches/lighttpd-1.4.x) (revision 2303)
114 touched = data_string_init();
116 - buffer_copy_string(touched->value, "");
117 + buffer_copy_string_len(touched->value, CONST_STR_LEN(""));
118 buffer_copy_string_buffer(touched->key, du->key);
120 array_insert_unique(srv->config_touched, (data_unset *)touched);
123 /* condition "host:port" but client send "host" */
124 buffer_copy_string_buffer(srv->cond_check_buf, l);
125 - BUFFER_APPEND_STRING_CONST(srv->cond_check_buf, ":");
126 + buffer_append_string_len(srv->cond_check_buf, CONST_STR_LEN(":"));
127 buffer_append_long(srv->cond_check_buf, sock_addr_get_port(&(srv_sock->addr)));
128 l = srv->cond_check_buf;
129 } else if (!ck_colon) {
131 int config_append_cond_match_buffer(connection *con, data_config *dc, buffer *buf, int n)
133 cond_cache_t *cache = &con->cond_cache[dc->context_ndx];
134 - if (n > cache->patterncount) {
135 + if (n >= cache->patterncount) {
140 ===================================================================
141 --- src/mod_cgi.c (.../tags/lighttpd-1.4.19) (revision 2303)
142 +++ src/mod_cgi.c (.../branches/lighttpd-1.4.x) (revision 2303)
144 buffer_reset(p->tmp_buf);
146 if (0 != strcasecmp(ds->key->ptr, "CONTENT-TYPE")) {
147 - buffer_copy_string(p->tmp_buf, "HTTP_");
148 + buffer_copy_string_len(p->tmp_buf, CONST_STR_LEN("HTTP_"));
149 p->tmp_buf->used--; /* strip \0 after HTTP_ */
154 for (j = 0; j < ds->key->used - 1; j++) {
155 p->tmp_buf->ptr[p->tmp_buf->used++] =
156 - isalpha((unsigned char)ds->key->ptr[j]) ?
157 + light_isalnum((unsigned char)ds->key->ptr[j]) ?
158 toupper((unsigned char)ds->key->ptr[j]) : '_';
160 p->tmp_buf->ptr[p->tmp_buf->used++] = '\0';
165 + openDevNull(STDERR_FILENO);
167 /* we don't need the client socket */
168 for (i = 3; i < 256; i++) {
169 if (i != srv->errorlog_fd) close(i);
172 execve(args[0], args, env.ptr);
174 - log_error_write(srv, __FILE__, __LINE__, "sss", "CGI failed:", strerror(errno), args[0]);
175 + /* log_error_write(srv, __FILE__, __LINE__, "sss", "CGI failed:", strerror(errno), args[0]); */
179 @@ -1058,8 +1060,9 @@
182 con->http_status = 507;
188 con->http_status = 403;
190 @@ -1071,8 +1074,9 @@
193 con->http_status = 507;
199 con->http_status = 403;
201 @@ -1087,6 +1091,8 @@
205 + log_error_write(srv, __FILE__, __LINE__, "ss", "write() failed due to: ", strerror(errno));
206 + con->http_status = 500;
209 chunkqueue_remove_finished_chunks(cq);
210 @@ -1174,6 +1180,8 @@
211 plugin_data *p = p_d;
212 buffer *fn = con->physical.path;
214 + if (con->mode != DIRECT) return HANDLER_GO_ON;
216 if (fn->used == 0) return HANDLER_GO_ON;
218 mod_cgi_patch_connection(srv, con, p);
219 @@ -1189,6 +1197,7 @@
221 if (0 == strncmp(fn->ptr + s_len - ct_len, ds->key->ptr, ct_len)) {
222 if (cgi_create_env(srv, con, p, ds->value)) {
223 + con->mode = DIRECT;
224 con->http_status = 500;
226 buffer_reset(con->physical.path);
227 Index: src/mod_secure_download.c
228 ===================================================================
229 --- src/mod_secure_download.c (.../tags/lighttpd-1.4.19) (revision 2303)
230 +++ src/mod_secure_download.c (.../branches/lighttpd-1.4.x) (revision 2303)
235 + if (con->mode != DIRECT) return HANDLER_GO_ON;
237 if (con->uri.path->used == 0) return HANDLER_GO_ON;
239 mod_secdownload_patch_connection(srv, con, p);
244 - if (srv->cur_ts - ts > p->conf.timeout ||
245 - srv->cur_ts - ts < -p->conf.timeout) {
246 + if ( (srv->cur_ts > ts && srv->cur_ts - ts > p->conf.timeout) ||
247 + (srv->cur_ts < ts && ts - srv->cur_ts > p->conf.timeout) ) {
248 /* "Gone" as the url will never be valid again instead of "408 - Timeout" where the request may be repeated */
249 con->http_status = 410;
253 buffer_copy_string_hex(p->md5, (char *)HA1, 16);
255 - if (0 != strncmp(md5_str, p->md5->ptr, 32)) {
256 + if (0 != strncasecmp(md5_str, p->md5->ptr, 32)) {
257 con->http_status = 403;
259 log_error_write(srv, __FILE__, __LINE__, "sss",
261 ===================================================================
262 --- src/array.c (.../tags/lighttpd-1.4.19) (revision 2303)
263 +++ src/array.c (.../branches/lighttpd-1.4.x) (revision 2303)
264 @@ -330,30 +330,30 @@
267 ds = data_string_init();
268 - buffer_copy_string(ds->key, "abc");
269 - buffer_copy_string(ds->value, "alfrag");
270 + buffer_copy_string_len(ds->key, CONST_STR_LEN("abc"));
271 + buffer_copy_string_len(ds->value, CONST_STR_LEN("alfrag"));
273 array_insert_unique(a, (data_unset *)ds);
275 ds = data_string_init();
276 - buffer_copy_string(ds->key, "abc");
277 - buffer_copy_string(ds->value, "hameplman");
278 + buffer_copy_string_len(ds->key, CONST_STR_LEN("abc"));
279 + buffer_copy_string_len(ds->value, CONST_STR_LEN("hameplman"));
281 array_insert_unique(a, (data_unset *)ds);
283 ds = data_string_init();
284 - buffer_copy_string(ds->key, "123");
285 - buffer_copy_string(ds->value, "alfrag");
286 + buffer_copy_string_len(ds->key, CONST_STR_LEN("123"));
287 + buffer_copy_string_len(ds->value, CONST_STR_LEN("alfrag"));
289 array_insert_unique(a, (data_unset *)ds);
291 dc = data_count_init();
292 - buffer_copy_string(dc->key, "def");
293 + buffer_copy_string_len(dc->key, CONST_STR_LEN("def"));
295 array_insert_unique(a, (data_unset *)dc);
297 dc = data_count_init();
298 - buffer_copy_string(dc->key, "def");
299 + buffer_copy_string_len(dc->key, CONST_STR_LEN("def"));
301 array_insert_unique(a, (data_unset *)dc);
304 ===================================================================
305 --- src/base.h (.../tags/lighttpd-1.4.19) (revision 2303)
306 +++ src/base.h (.../branches/lighttpd-1.4.x) (revision 2303)
308 unsigned short log_request_handling;
309 unsigned short log_response_header;
310 unsigned short log_condition_handling;
311 + unsigned short log_ssl_noise;
315 Index: src/mod_rewrite.c
316 ===================================================================
317 --- src/mod_rewrite.c (.../tags/lighttpd-1.4.19) (revision 2303)
318 +++ src/mod_rewrite.c (.../branches/lighttpd-1.4.x) (revision 2303)
321 if (!p->conf.rewrite) return HANDLER_GO_ON;
323 - buffer_copy_string_buffer(p->match_buf, con->request.uri);
324 + buffer_copy_string_buffer(p->match_buf, con->uri.path);
325 + if (con->uri.query->used > 0) {
326 + buffer_append_string_len(p->match_buf, CONST_STR_LEN("?"));
327 + buffer_append_string_buffer(p->match_buf, con->uri.query);
330 for (i = 0; i < p->conf.rewrite->used; i++) {
334 start = 0; end = pattern_len;
335 for (k = 0; k < pattern_len; k++) {
336 - if ((pattern[k] == '$' || pattern[k] == '%') &&
337 - isdigit((unsigned char)pattern[k + 1])) {
338 + if (pattern[k] == '$' || pattern[k] == '%') {
341 size_t num = pattern[k + 1] - '0';
344 buffer_append_string_len(con->request.uri, pattern + start, end - start);
346 - if (pattern[k] == '$') {
347 + if (!isdigit((unsigned char)pattern[k + 1])) {
348 + /* enable escape: "%%" => "%", "%a" => "%a", "$$" => "$" */
349 + buffer_append_string_len(con->request.uri, pattern+k, pattern[k] == pattern[k+1] ? 1 : 2);
350 + } else if (pattern[k] == '$') {
351 /* n is always > 0 */
352 if (num < (size_t)n) {
353 buffer_append_string(con->request.uri, list[num]);
355 ===================================================================
356 --- src/lempar.c (.../tags/lighttpd-1.4.19) (revision 2303)
357 +++ src/lempar.c (.../branches/lighttpd-1.4.x) (revision 2303)
360 const char *ParseTokenName(int tokenType){
362 - if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
363 + if( tokenType>0 && (size_t)tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
364 return yyTokenName[tokenType];
371 - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
372 + if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
374 int iFallback; /* Fallback token */
375 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
380 - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
381 + if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
382 return yy_default[stateno];
386 yymsp = &yypParser->yystack[yypParser->yyidx];
388 if( yyTraceFILE && yyruleno>=0
389 - && yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
390 + && (size_t)yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
391 fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
392 yyRuleName[yyruleno]);
395 int yymajor, /* The major type of the error token */
396 YYMINORTYPE yyminor /* The minor type of the error token */
401 #define TOKEN (yyminor.yy0)
403 Index: src/connections.c
404 ===================================================================
405 --- src/connections.c (.../tags/lighttpd-1.4.19) (revision 2303)
406 +++ src/connections.c (.../branches/lighttpd-1.4.x) (revision 2303)
409 /* don't resize the buffer if we were in SSL_ERROR_WANT_* */
413 if (!con->ssl_error_want_reuse_buffer) {
418 while((ssl_err = ERR_get_error())) {
419 + switch (ERR_GET_REASON(ssl_err)) {
420 + case SSL_R_SSL_HANDSHAKE_FAILURE:
421 + case SSL_R_TLSV1_ALERT_UNKNOWN_CA:
422 + case SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN:
423 + case SSL_R_SSLV3_ALERT_BAD_CERTIFICATE:
424 + if (!con->conf.log_ssl_noise) continue;
429 /* get all errors from the error-queue */
430 log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:",
431 - r, ERR_error_string(ssl_err, NULL));
432 + r, ERR_error_string(ssl_err, NULL));
445 @@ -427,21 +440,22 @@
448 switch(con->http_status) {
449 - case 400: /* class: header + custom body */
462 + case 204: /* class: header only */
465 + /* disable chunked encoding again as we have no body */
466 + con->response.transfer_encoding &= ~HTTP_TRANSFER_ENCODING_CHUNKED;
467 + con->parsed_response &= ~HTTP_CONTENT_LENGTH;
468 + chunkqueue_reset(con->write_queue);
470 + con->file_finished = 1;
472 + default: /* class: header + body */
473 if (con->mode != DIRECT) break;
475 + /* only custom body for 4xx and 5xx */
476 + if (con->http_status < 400 || con->http_status >= 600) break;
478 con->file_finished = 0;
480 buffer_reset(con->physical.path);
482 stat_cache_entry *sce = NULL;
484 buffer_copy_string_buffer(con->physical.path, con->conf.errorfile_prefix);
485 - buffer_append_string(con->physical.path, get_http_status_body_name(con->http_status));
486 + buffer_append_long(con->physical.path, con->http_status);
487 + buffer_append_string_len(con->physical.path, CONST_STR_LEN(".html"));
489 if (HANDLER_ERROR != stat_cache_get_entry(srv, con, con->physical.path, &sce)) {
490 con->file_finished = 1;
491 @@ -470,57 +485,34 @@
492 b = chunkqueue_get_append_buffer(con->write_queue);
494 /* build default error-page */
495 - buffer_copy_string(b,
496 + buffer_copy_string_len(b, CONST_STR_LEN(
497 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
498 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
499 " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
500 "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
504 buffer_append_long(b, con->http_status);
505 - buffer_append_string(b, " - ");
506 + buffer_append_string_len(b, CONST_STR_LEN(" - "));
507 buffer_append_string(b, get_http_status_name(con->http_status));
509 - buffer_append_string(b,
510 + buffer_append_string_len(b, CONST_STR_LEN(
516 buffer_append_long(b, con->http_status);
517 - buffer_append_string(b, " - ");
518 + buffer_append_string_len(b, CONST_STR_LEN(" - "));
519 buffer_append_string(b, get_http_status_name(con->http_status));
521 - buffer_append_string(b,"</h1>\n"
522 + buffer_append_string_len(b, CONST_STR_LEN("</h1>\n"
528 response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
532 - case 200: /* class: header + body */
541 - case 206: /* write_queue is already prepared */
544 - case 205: /* class: header only */
547 - /* disable chunked encoding again as we have no body */
548 - con->response.transfer_encoding &= ~HTTP_TRANSFER_ENCODING_CHUNKED;
549 - con->parsed_response &= ~HTTP_CONTENT_LENGTH;
550 - chunkqueue_reset(con->write_queue);
552 - con->file_finished = 1;
556 if (con->file_finished) {
559 /* no Content-Body, no Content-Length */
560 if (NULL != (ds = (data_string*) array_get_element(con->response.headers, "Content-Length"))) {
561 - buffer_reset(ds->value); // Headers with empty values are ignored for output
562 + buffer_reset(ds->value); /* Headers with empty values are ignored for output */
564 } else if (qlen > 0 || con->request.http_method != HTTP_METHOD_HEAD) {
565 /* qlen = 0 is important for Redirects (301, ...) as they MAY have
569 /* The cond_cache gets reset in response.c */
570 -// config_cond_cache_reset(srv, con);
571 + /* config_cond_cache_reset(srv, con); */
574 if (con->ssl_error_want_reuse_buffer) {
575 @@ -1668,21 +1660,51 @@
578 if (srv_sock->is_ssl) {
583 switch ((ret = SSL_shutdown(con->ssl))) {
588 - SSL_shutdown(con->ssl);
591 + if (-1 != (ret = SSL_shutdown(con->ssl))) break;
595 - log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:",
596 - SSL_get_error(con->ssl, ret),
597 - ERR_error_string(ERR_get_error(), NULL));
600 + switch ((ssl_r = SSL_get_error(con->ssl, ret))) {
601 + case SSL_ERROR_WANT_WRITE:
602 + case SSL_ERROR_WANT_READ:
604 + case SSL_ERROR_SYSCALL:
605 + /* perhaps we have error waiting in our error-queue */
606 + if (0 != (err = ERR_get_error())) {
608 + log_error_write(srv, __FILE__, __LINE__, "sdds", "SSL:",
610 + ERR_error_string(err, NULL));
611 + } while((err = ERR_get_error()));
613 + log_error_write(srv, __FILE__, __LINE__, "sddds", "SSL (error):",
620 + while((err = ERR_get_error())) {
621 + log_error_write(srv, __FILE__, __LINE__, "sdds", "SSL:",
623 + ERR_error_string(err, NULL));
634 Index: src/mod_staticfile.c
635 ===================================================================
636 --- src/mod_staticfile.c (.../tags/lighttpd-1.4.19) (revision 2303)
637 +++ src/mod_staticfile.c (.../branches/lighttpd-1.4.x) (revision 2303)
638 @@ -282,22 +282,22 @@
640 b = chunkqueue_get_append_buffer(con->write_queue);
642 - buffer_copy_string(b, "\r\n--");
643 + buffer_copy_string_len(b, CONST_STR_LEN("\r\n--"));
644 buffer_append_string(b, boundary);
646 /* write Content-Range */
647 - buffer_append_string(b, "\r\nContent-Range: bytes ");
648 + buffer_append_string_len(b, CONST_STR_LEN("\r\nContent-Range: bytes "));
649 buffer_append_off_t(b, start);
650 - buffer_append_string(b, "-");
651 + buffer_append_string_len(b, CONST_STR_LEN("-"));
652 buffer_append_off_t(b, end);
653 - buffer_append_string(b, "/");
654 + buffer_append_string_len(b, CONST_STR_LEN("/"));
655 buffer_append_off_t(b, sce->st.st_size);
657 - buffer_append_string(b, "\r\nContent-Type: ");
658 + buffer_append_string_len(b, CONST_STR_LEN("\r\nContent-Type: "));
659 buffer_append_string_buffer(b, content_type);
661 /* write END-OF-HEADER */
662 - buffer_append_string(b, "\r\n\r\n");
663 + buffer_append_string_len(b, CONST_STR_LEN("\r\n\r\n"));
665 con->response.content_length += b->used - 1;
669 /* set header-fields */
671 - buffer_copy_string(p->range_buf, "multipart/byteranges; boundary=");
672 + buffer_copy_string_len(p->range_buf, CONST_STR_LEN("multipart/byteranges; boundary="));
673 buffer_append_string(p->range_buf, boundary);
675 /* overwrite content-type */
676 @@ -333,11 +333,11 @@
678 /* add Content-Range-header */
680 - buffer_copy_string(p->range_buf, "bytes ");
681 + buffer_copy_string_len(p->range_buf, CONST_STR_LEN("bytes "));
682 buffer_append_off_t(p->range_buf, start);
683 - buffer_append_string(p->range_buf, "-");
684 + buffer_append_string_len(p->range_buf, CONST_STR_LEN("-"));
685 buffer_append_off_t(p->range_buf, end);
686 - buffer_append_string(p->range_buf, "/");
687 + buffer_append_string_len(p->range_buf, CONST_STR_LEN("/"));
688 buffer_append_off_t(p->range_buf, sce->st.st_size);
690 response_header_insert(srv, con, CONST_STR_LEN("Content-Range"), CONST_BUF_LEN(p->range_buf));
692 ===================================================================
693 --- src/network.c (.../tags/lighttpd-1.4.19) (revision 2303)
694 +++ src/network.c (.../branches/lighttpd-1.4.x) (revision 2303)
698 buffer_copy_string_buffer(b, srv->srvconf.bindhost);
699 - buffer_append_string(b, ":");
700 + buffer_append_string_len(b, CONST_STR_LEN(":"));
701 buffer_append_long(b, srv->srvconf.port);
703 if (0 != network_server_init(srv, b, srv->config_storage[0])) {
704 Index: src/configfile.c
705 ===================================================================
706 --- src/configfile.c (.../tags/lighttpd-1.4.19) (revision 2303)
707 +++ src/configfile.c (.../branches/lighttpd-1.4.x) (revision 2303)
717 { "debug.log-request-handling", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 32 */
718 { "debug.log-response-header", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 33 */
719 { "debug.log-request-header", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 34 */
720 + { "debug.log-ssl-noise", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 35 */
722 - { "server.protocol-http11", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 35 */
723 - { "debug.log-request-header-on-error", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 36 */
724 - { "debug.log-state-handling", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 37 */
725 - { "ssl.ca-file", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 38 */
726 + { "server.protocol-http11", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 36 */
727 + { "debug.log-request-header-on-error", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 37 */
728 + { "debug.log-state-handling", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 38 */
729 + { "ssl.ca-file", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 39 */
731 - { "server.errorlog-use-syslog", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 39 */
732 - { "server.range-requests", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 40 */
733 - { "server.stat-cache-engine", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 41 */
734 - { "server.max-connections", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_SERVER }, /* 42 */
735 - { "server.network-backend", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 43 */
736 - { "server.upload-dirs", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 44 */
737 - { "server.core-files", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 45 */
738 - { "ssl.cipher-list", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 46 */
739 - { "ssl.use-sslv2", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 47 */
740 - { "etag.use-inode", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 48 */
741 - { "etag.use-mtime", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 49 */
742 - { "etag.use-size", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 50 */
743 + { "server.errorlog-use-syslog", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 40 */
744 + { "server.range-requests", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 41 */
745 + { "server.stat-cache-engine", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 42 */
746 + { "server.max-connections", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_SERVER }, /* 43 */
747 + { "server.network-backend", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 44 */
748 + { "server.upload-dirs", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 45 */
749 + { "server.core-files", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 46 */
750 + { "ssl.cipher-list", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 47 */
751 + { "ssl.use-sslv2", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 48 */
752 + { "etag.use-inode", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 49 */
753 + { "etag.use-mtime", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 50 */
754 + { "etag.use-size", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 51 */
755 { "server.host", "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
756 { "server.docroot", "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
757 { "server.virtual-root", "load mod_simple_vhost and use simple-vhost.server-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
758 @@ -120,18 +122,18 @@
760 cv[13].destination = &(srv->srvconf.max_worker);
761 cv[23].destination = &(srv->srvconf.max_fds);
762 - cv[36].destination = &(srv->srvconf.log_request_header_on_error);
763 - cv[37].destination = &(srv->srvconf.log_state_handling);
764 + cv[37].destination = &(srv->srvconf.log_request_header_on_error);
765 + cv[38].destination = &(srv->srvconf.log_state_handling);
767 - cv[39].destination = &(srv->srvconf.errorlog_use_syslog);
768 + cv[40].destination = &(srv->srvconf.errorlog_use_syslog);
770 stat_cache_string = buffer_init();
771 - cv[41].destination = stat_cache_string;
772 - cv[43].destination = srv->srvconf.network_backend;
773 - cv[44].destination = srv->srvconf.upload_tempdirs;
774 - cv[45].destination = &(srv->srvconf.enable_cores);
775 + cv[42].destination = stat_cache_string;
776 + cv[44].destination = srv->srvconf.network_backend;
777 + cv[45].destination = srv->srvconf.upload_tempdirs;
778 + cv[46].destination = &(srv->srvconf.enable_cores);
780 - cv[42].destination = &(srv->srvconf.max_conns);
781 + cv[43].destination = &(srv->srvconf.max_conns);
782 cv[12].destination = &(srv->srvconf.max_request_size);
783 srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
785 @@ -204,16 +206,17 @@
786 cv[32].destination = &(s->log_request_handling);
787 cv[33].destination = &(s->log_response_header);
788 cv[34].destination = &(s->log_request_header);
789 + cv[35].destination = &(s->log_ssl_noise);
791 - cv[35].destination = &(s->allow_http11);
792 - cv[38].destination = s->ssl_ca_file;
793 - cv[40].destination = &(s->range_requests);
794 + cv[36].destination = &(s->allow_http11);
795 + cv[39].destination = s->ssl_ca_file;
796 + cv[41].destination = &(s->range_requests);
798 - cv[46].destination = s->ssl_cipher_list;
799 - cv[47].destination = &(s->ssl_use_sslv2);
800 - cv[48].destination = &(s->etag_use_inode);
801 - cv[49].destination = &(s->etag_use_mtime);
802 - cv[50].destination = &(s->etag_use_size);
803 + cv[47].destination = s->ssl_cipher_list;
804 + cv[48].destination = &(s->ssl_use_sslv2);
805 + cv[49].destination = &(s->etag_use_inode);
806 + cv[50].destination = &(s->etag_use_mtime);
807 + cv[51].destination = &(s->etag_use_size);
809 srv->config_storage[i] = s;
812 PATCH(log_request_handling);
813 PATCH(log_condition_handling);
814 PATCH(log_file_not_found);
815 + PATCH(log_ssl_noise);
817 PATCH(range_requests);
818 PATCH(force_lowercase_filenames);
820 data_config *dc = (data_config *)srv->config_context->data[i];
821 specific_config *s = srv->config_storage[i];
823 - /* not our stage */
824 - if (comp != dc->comp) continue;
826 /* condition didn't match */
827 if (!config_check_cond(srv, con, dc)) continue;
830 PATCH(log_condition_handling);
831 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("debug.log-file-not-found"))) {
832 PATCH(log_file_not_found);
833 + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("debug.log-ssl-noise"))) {
834 + PATCH(log_ssl_noise);
835 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.protocol-http11"))) {
837 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.force-lowercase-filenames"))) {
841 static int tokenizer_open(server *srv, tokenizer_t *t, buffer *basedir, const char *fn) {
842 - if (buffer_is_empty(basedir) &&
843 - (fn[0] == '/' || fn[0] == '\\') &&
844 + if (buffer_is_empty(basedir) ||
845 + (fn[0] == '/' || fn[0] == '\\') ||
846 (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) {
847 t->file = buffer_init_string(fn);
850 if (t->input[t->offset + 1] == '>') {
853 - buffer_copy_string(token, "=>");
854 + buffer_copy_string_len(token, CONST_STR_LEN("=>"));
856 tid = TK_ARRAY_ASSIGN;
858 @@ -494,13 +497,13 @@
859 if (t->input[t->offset + 1] == '=') {
862 - buffer_copy_string(token, "==");
863 + buffer_copy_string_len(token, CONST_STR_LEN("=="));
866 } else if (t->input[t->offset + 1] == '~') {
869 - buffer_copy_string(token, "=~");
870 + buffer_copy_string_len(token, CONST_STR_LEN("=~"));
874 @@ -533,13 +536,13 @@
875 if (t->input[t->offset + 1] == '=') {
878 - buffer_copy_string(token, "!=");
879 + buffer_copy_string_len(token, CONST_STR_LEN("!="));
882 } else if (t->input[t->offset + 1] == '~') {
885 - buffer_copy_string(token, "!~");
886 + buffer_copy_string_len(token, CONST_STR_LEN("!~"));
894 - buffer_copy_string(token, "(EOL)");
895 + buffer_copy_string_len(token, CONST_STR_LEN("(EOL)"));
897 config_skip_newline(t);
900 if (t->in_brace > 0) {
903 - buffer_copy_string(token, "(COMMA)");
904 + buffer_copy_string_len(token, CONST_STR_LEN("(COMMA)"));
910 /* search for the terminating " */
911 start = t->input + t->offset + 1;
912 - buffer_copy_string(token, "");
913 + buffer_copy_string_len(token, CONST_STR_LEN(""));
915 for (i = 1; t->input[t->offset + i]; i++) {
916 if (t->input[t->offset + i] == '\\' &&
921 - buffer_copy_string(token, "(");
922 + buffer_copy_string_len(token, CONST_STR_LEN("("));
930 - buffer_copy_string(token, ")");
931 + buffer_copy_string_len(token, CONST_STR_LEN(")"));
935 @@ -677,19 +680,19 @@
939 - buffer_copy_string(token, "$");
940 + buffer_copy_string_len(token, CONST_STR_LEN("$"));
945 if (t->input[t->offset + 1] == '=') {
947 - buffer_copy_string(token, "+=");
948 + buffer_copy_string_len(token, CONST_STR_LEN("+="));
953 - buffer_copy_string(token, "+");
954 + buffer_copy_string_len(token, CONST_STR_LEN("+"));
962 - buffer_copy_string(token, "{");
963 + buffer_copy_string_len(token, CONST_STR_LEN("{"));
971 - buffer_copy_string(token, "}");
972 + buffer_copy_string_len(token, CONST_STR_LEN("}"));
980 - buffer_copy_string(token, "[");
981 + buffer_copy_string_len(token, CONST_STR_LEN("["));
989 - buffer_copy_string(token, "]");
990 + buffer_copy_string_len(token, CONST_STR_LEN("]"));
998 - if (buffer_is_empty(context->basedir) &&
999 - (fn[0] == '/' || fn[0] == '\\') &&
1000 + if (buffer_is_empty(context->basedir) ||
1001 + (fn[0] == '/' || fn[0] == '\\') ||
1002 (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) {
1003 filename = buffer_init_string(fn);
1005 @@ -912,15 +915,39 @@
1009 +static char* getCWD() {
1019 + if (!s) return NULL;
1020 + while (NULL == getcwd(s, len)) {
1021 + if (errno != ERANGE || SSIZE_MAX - len < len) return NULL;
1023 + s1 = realloc(s, len);
1033 int config_parse_cmd(server *srv, config_t *context, const char *cmd) {
1034 proc_handler_t proc;
1039 - char oldpwd[PATH_MAX];
1042 - if (NULL == getcwd(oldpwd, sizeof(oldpwd))) {
1043 + if (NULL == (oldpwd = getCWD())) {
1044 log_error_write(srv, __FILE__, __LINE__, "s",
1045 "cannot get cwd", strerror(errno));
1048 buffer_free(source);
1055 @@ -986,7 +1014,7 @@
1058 dc = data_config_init();
1059 - buffer_copy_string(dc->key, "global");
1060 + buffer_copy_string_len(dc->key, CONST_STR_LEN("global"));
1062 assert(context.all_configs->used == 0);
1063 dc->context_ndx = context.all_configs->used;
1064 @@ -997,14 +1025,14 @@
1065 srv->config = dc->value;
1066 dpid = data_integer_init();
1067 dpid->value = getpid();
1068 - buffer_copy_string(dpid->key, "var.PID");
1069 + buffer_copy_string_len(dpid->key, CONST_STR_LEN("var.PID"));
1070 array_insert_unique(srv->config, (data_unset *)dpid);
1072 dcwd = data_string_init();
1073 buffer_prepare_copy(dcwd->value, 1024);
1074 if (NULL != getcwd(dcwd->value->ptr, dcwd->value->size - 1)) {
1075 dcwd->value->used = strlen(dcwd->value->ptr) + 1;
1076 - buffer_copy_string(dcwd->key, "var.CWD");
1077 + buffer_copy_string_len(dcwd->key, CONST_STR_LEN("var.CWD"));
1078 array_insert_unique(srv->config, (data_unset *)dcwd);
1081 @@ -1038,7 +1066,7 @@
1082 /* prepend default modules */
1083 if (NULL == array_get_element(modules->value, "mod_indexfile")) {
1084 ds = data_string_init();
1085 - buffer_copy_string(ds->value, "mod_indexfile");
1086 + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_indexfile"));
1087 array_insert_unique(prepends->value, (data_unset *)ds);
1090 @@ -1051,13 +1079,13 @@
1091 /* append default modules */
1092 if (NULL == array_get_element(modules->value, "mod_dirlisting")) {
1093 ds = data_string_init();
1094 - buffer_copy_string(ds->value, "mod_dirlisting");
1095 + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_dirlisting"));
1096 array_insert_unique(modules->value, (data_unset *)ds);
1099 if (NULL == array_get_element(modules->value, "mod_staticfile")) {
1100 ds = data_string_init();
1101 - buffer_copy_string(ds->value, "mod_staticfile");
1102 + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_staticfile"));
1103 array_insert_unique(modules->value, (data_unset *)ds);
1106 @@ -1067,18 +1095,18 @@
1108 /* server.modules is not set */
1109 ds = data_string_init();
1110 - buffer_copy_string(ds->value, "mod_indexfile");
1111 + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_indexfile"));
1112 array_insert_unique(modules->value, (data_unset *)ds);
1114 ds = data_string_init();
1115 - buffer_copy_string(ds->value, "mod_dirlisting");
1116 + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_dirlisting"));
1117 array_insert_unique(modules->value, (data_unset *)ds);
1119 ds = data_string_init();
1120 - buffer_copy_string(ds->value, "mod_staticfile");
1121 + buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_staticfile"));
1122 array_insert_unique(modules->value, (data_unset *)ds);
1124 - buffer_copy_string(modules->key, "server.modules");
1125 + buffer_copy_string_len(modules->key, CONST_STR_LEN("server.modules"));
1126 array_insert_unique(srv->config, (data_unset *)modules);
1129 Index: src/mod_trigger_b4_dl.c
1130 ===================================================================
1131 --- src/mod_trigger_b4_dl.c (.../tags/lighttpd-1.4.19) (revision 2303)
1132 +++ src/mod_trigger_b4_dl.c (.../branches/lighttpd-1.4.x) (revision 2303)
1137 + if (con->mode != DIRECT) return HANDLER_GO_ON;
1139 if (con->uri.path->used == 0) return HANDLER_GO_ON;
1141 mod_trigger_b4_dl_patch_connection(srv, con, p);
1143 /* not found, redirect */
1145 response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->conf.deny_url));
1147 con->http_status = 307;
1148 + con->file_finished = 1;
1150 return HANDLER_FINISHED;
1154 response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->conf.deny_url));
1155 con->http_status = 307;
1156 + con->file_finished = 1;
1159 if (0 != gdbm_delete(p->conf.db, key)) {
1161 response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->conf.deny_url));
1163 con->http_status = 307;
1164 + con->file_finished = 1;
1166 return HANDLER_FINISHED;
1168 Index: src/mod_evhost.c
1169 ===================================================================
1170 --- src/mod_evhost.c (.../tags/lighttpd-1.4.19) (revision 2303)
1171 +++ src/mod_evhost.c (.../branches/lighttpd-1.4.x) (revision 2303)
1173 s->path_pieces = realloc(s->path_pieces,(s->len+1) * sizeof(*s->path_pieces));
1174 s->path_pieces[s->len] = buffer_init();
1176 - buffer_append_memory(s->path_pieces[s->len],pos,ptr-pos);
1177 + buffer_copy_string_len(s->path_pieces[s->len],pos,ptr-pos);
1184 ds = data_string_init();
1185 - buffer_copy_string(ds->key,"%0");
1186 + buffer_copy_string_len(ds->key,CONST_STR_LEN("%0"));
1188 /* if we stopped at a dot, skip the dot */
1189 if (*ptr == '.') ptr++;
1191 if (ptr != colon - 1) {
1192 /* is something between the dots */
1193 ds = data_string_init();
1194 - buffer_copy_string(ds->key,"%");
1195 + buffer_copy_string_len(ds->key,CONST_STR_LEN("%"));
1196 buffer_append_long(ds->key, i++);
1197 buffer_copy_string_len(ds->value,ptr+1,colon-ptr-1);
1200 /* if the . is not the first charactor of the hostname */
1202 ds = data_string_init();
1203 - buffer_copy_string(ds->key,"%");
1204 + buffer_copy_string_len(ds->key,CONST_STR_LEN("%"));
1205 buffer_append_long(ds->key, i++);
1206 buffer_copy_string_len(ds->value,ptr,colon-ptr);
1210 if (*(ptr+1) == '%') {
1212 - BUFFER_APPEND_STRING_CONST(p->tmp_buf,"%");
1213 + buffer_append_string_len(p->tmp_buf,CONST_STR_LEN("%"));
1214 } else if (NULL != (ds = (data_string *)array_get_element(parsed_host,p->conf.path_pieces[i]->ptr))) {
1215 if (ds->value->used) {
1216 buffer_append_string_buffer(p->tmp_buf,ds->value);
1218 ===================================================================
1219 --- src/chunk.c (.../tags/lighttpd-1.4.19) (revision 2303)
1220 +++ src/chunk.c (.../branches/lighttpd-1.4.x) (revision 2303)
1223 buffer_copy_string_buffer(template, ds->value);
1224 BUFFER_APPEND_SLASH(template);
1225 - BUFFER_APPEND_STRING_CONST(template, "lighttpd-upload-XXXXXX");
1226 + buffer_append_string_len(template, CONST_STR_LEN("lighttpd-upload-XXXXXX"));
1228 if (-1 != (c->file.fd = mkstemp(template->ptr))) {
1229 /* only trigger the unlink if we created the temp-file successfully */
1231 ===================================================================
1232 --- src/lemon.c (.../tags/lighttpd-1.4.19) (revision 2303)
1233 +++ src/lemon.c (.../branches/lighttpd-1.4.x) (revision 2303)
1238 +#ifdef HAVE_CONFIG_H
1239 +#include "config.h"
1242 +#ifdef HAVE_STDINT_H
1243 +# include <stdint.h>
1245 +#ifdef HAVE_INTTYPES_H
1246 +# include <inttypes.h>
1249 +#define UNUSED(x) ( (void)(x) )
1251 extern void qsort();
1252 extern double strtod();
1253 extern long strtol();
1256 struct symbol *spx, *spy;
1259 assert( apx->sp==apy->sp ); /* Otherwise there would be no conflict */
1260 if( apx->type==SHIFT && apy->type==REDUCE ){
1262 @@ -1347,6 +1361,7 @@
1264 char *def_tmpl_name = "lempar.c";
1267 OptInit(argv,options,stderr);
1269 printf("Lemon version 1.0\n");
1270 @@ -1651,7 +1666,7 @@
1271 }else if( op[j].type==OPT_FLAG ){
1272 *((int*)op[j].arg) = v;
1273 }else if( op[j].type==OPT_FFLAG ){
1274 - (*(void(*)())(op[j].arg))(v);
1275 + (*(void(*)())(intptr_t)(op[j].arg))(v);
1278 fprintf(err,"%smissing argument on switch.\n",emsg);
1279 @@ -1733,19 +1748,19 @@
1280 *(double*)(op[j].arg) = dv;
1283 - (*(void(*)())(op[j].arg))(dv);
1284 + (*(void(*)())(intptr_t)(op[j].arg))(dv);
1287 *(int*)(op[j].arg) = lv;
1290 - (*(void(*)())(op[j].arg))((int)lv);
1291 + (*(void(*)())(intptr_t)(op[j].arg))((int)lv);
1294 *(char**)(op[j].arg) = sv;
1297 - (*(void(*)())(op[j].arg))(sv);
1298 + (*(void(*)())(intptr_t)(op[j].arg))(sv);
1302 @@ -2286,10 +2301,10 @@
1303 ** token is passed to the function "parseonetoken" which builds all
1304 ** the appropriate data structures in the global state vector "gp".
1314 Index: src/mod_skeleton.c
1315 ===================================================================
1316 --- src/mod_skeleton.c (.../tags/lighttpd-1.4.19) (revision 2303)
1317 +++ src/mod_skeleton.c (.../branches/lighttpd-1.4.x) (revision 2303)
1322 + if (con->mode != DIRECT) return HANDLER_GO_ON;
1324 if (con->uri.path->used == 0) return HANDLER_GO_ON;
1326 mod_skeleton_patch_connection(srv, con, p);
1327 Index: src/mod_scgi.c
1328 ===================================================================
1329 --- src/mod_scgi.c (.../tags/lighttpd-1.4.19) (revision 2303)
1330 +++ src/mod_scgi.c (.../branches/lighttpd-1.4.x) (revision 2303)
1331 @@ -202,6 +202,15 @@
1336 + * workaround for program when prefix="/"
1338 + * rule to build PATH_INFO is hardcoded for when check_local is disabled
1339 + * enable this option to use the workaround
1343 + unsigned short fix_root_path_name;
1344 ssize_t load; /* replace by host->load */
1346 size_t max_id; /* corresponds most of the time to
1349 buffer *key; /* like .php */
1352 scgi_extension_host **hosts;
1357 static int env_add(char_array *env, const char *key, size_t key_len, const char *val, size_t val_len) {
1361 if (!key || !val) return -1;
1363 @@ -592,6 +603,15 @@
1364 /* add the \0 from the value */
1365 memcpy(dst + key_len + 1, val, val_len + 1);
1367 + for (i = 0; i < env->used; i++) {
1368 + if (0 == strncmp(dst, env->ptr[i], key_len + 1)) {
1369 + /* don't care about free as we are in a forked child which is going to exec(...) */
1370 + /* free(env->ptr[i]); */
1371 + env->ptr[i] = dst;
1376 if (env->size == 0) {
1378 env->ptr = malloc(env->size * sizeof(*env->ptr));
1379 @@ -749,11 +769,20 @@
1383 + if (scgi_fd != 0) {
1390 /* we don't need the client socket */
1391 for (fd = 3; fd < 256; fd++) {
1392 - if (fd != 2 && fd != scgi_fd) close(fd);
1396 + openDevNull(STDERR_FILENO);
1398 /* build clean environment */
1399 if (host->bin_env_copy->used) {
1400 for (i = 0; i < host->bin_env_copy->used; i++) {
1402 env.ptr[env.used] = NULL;
1405 - buffer_copy_string(b, "exec ");
1406 + buffer_copy_string_len(b, CONST_STR_LEN("exec "));
1407 buffer_append_string_buffer(b, host->bin_path);
1412 { "bin-environment", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 11 */
1413 { "bin-copy-environment", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 12 */
1414 + { "fix-root-scriptname", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 13 */
1417 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
1418 @@ -990,6 +1020,7 @@
1419 df->max_load_per_proc = 1;
1420 df->idle_timeout = 60;
1421 df->disable_time = 60;
1422 + df->fix_root_path_name = 0;
1424 fcv[0].destination = df->host;
1425 fcv[1].destination = df->docroot;
1426 @@ -1006,6 +1037,7 @@
1428 fcv[11].destination = df->bin_env;
1429 fcv[12].destination = df->bin_env_copy;
1430 + fcv[13].destination = &(df->fix_root_path_name);
1433 if (0 != config_insert_values_internal(srv, da_host->value, fcv)) {
1434 @@ -1084,7 +1116,7 @@
1435 proc->port = df->port + pno;
1437 buffer_copy_string_buffer(proc->socket, df->unixsocket);
1438 - buffer_append_string(proc->socket, "-");
1439 + buffer_append_string_len(proc->socket, CONST_STR_LEN("-"));
1440 buffer_append_long(proc->socket, pno);
1443 @@ -1155,11 +1187,6 @@
1444 p = hctx->plugin_data;
1445 con = hctx->remote_conn;
1447 - if (con->mode != p->id) {
1452 if (hctx->fd != -1) {
1453 fdevent_event_del(srv->ev, &(hctx->fde_ndx), hctx->fd);
1454 fdevent_unregister(srv->ev, hctx->fd);
1455 @@ -1366,7 +1393,7 @@
1456 buffer_reset(srv->tmp_buf);
1458 if (0 != strcasecmp(ds->key->ptr, "CONTENT-TYPE")) {
1459 - BUFFER_COPY_STRING_CONST(srv->tmp_buf, "HTTP_");
1460 + buffer_copy_string_len(srv->tmp_buf, CONST_STR_LEN("HTTP_"));
1461 srv->tmp_buf->used--;
1464 @@ -1394,7 +1421,7 @@
1465 buffer_prepare_append(srv->tmp_buf, ds->key->used + 2);
1466 for (j = 0; j < ds->key->used - 1; j++) {
1467 srv->tmp_buf->ptr[srv->tmp_buf->used++] =
1468 - isalpha((unsigned char)ds->key->ptr[j]) ?
1469 + light_isalnum((unsigned char)ds->key->ptr[j]) ?
1470 toupper((unsigned char)ds->key->ptr[j]) : '_';
1472 srv->tmp_buf->ptr[srv->tmp_buf->used++] = '\0';
1473 @@ -1673,9 +1700,8 @@
1475 status = strtol(s+9, NULL, 10);
1477 - if (con->http_status >= 100 &&
1478 - con->http_status < 1000) {
1479 - /* we expected 3 digits and didn't got them */
1480 + if (status >= 100 && status < 1000) {
1481 + /* we expected 3 digits got them */
1482 con->parsed_response |= HTTP_STATUS;
1483 con->http_status = status;
1485 @@ -2438,15 +2464,11 @@
1486 p = hctx->plugin_data;
1487 con = hctx->remote_conn;
1489 - if (con->mode != p->id) return HANDLER_GO_ON;
1491 log_error_write(srv, __FILE__, __LINE__, "ssdsd",
1492 "emergency exit: scgi:",
1493 "connection-fd:", con->fd,
1494 "fcgi-fd:", hctx->fd);
1498 scgi_connection_cleanup(srv, hctx);
1500 return HANDLER_FINISHED;
1501 @@ -2668,11 +2690,13 @@
1502 plugin_data *p = p_d;
1508 scgi_extension *extension = NULL;
1509 + scgi_extension_host *host = NULL;
1511 + if (con->mode != DIRECT) return HANDLER_GO_ON;
1513 /* Possibly, we processed already this request */
1514 if (con->file_started == 1) return HANDLER_GO_ON;
1516 @@ -2712,95 +2736,59 @@
1519 /* get best server */
1520 - for (k = 0, ndx = -1; k < extension->used; k++) {
1521 - scgi_extension_host *host = extension->hosts[k];
1522 + for (k = 0; k < extension->used; k++) {
1523 + scgi_extension_host *h = extension->hosts[k];
1525 - /* we should have at least one proc that can do somthing */
1526 - if (host->active_procs == 0) continue;
1527 + /* we should have at least one proc that can do something */
1528 + if (h->active_procs == 0) {
1532 - if (used == -1 || host->load < used) {
1533 - used = host->load;
1534 + if (used == -1 || h->load < used) {
1542 - /* found a server */
1544 - scgi_extension_host *host = extension->hosts[ndx];
1546 + /* sorry, we don't have a server alive for this ext */
1547 + buffer_reset(con->physical.path);
1548 + con->http_status = 500;
1551 - * if check-local is disabled, use the uri.path handler
1554 + /* only send the 'no handler' once */
1555 + if (!extension->note_is_sent) {
1556 + extension->note_is_sent = 1;
1558 - /* init handler-context */
1559 - if (uri_path_handler) {
1560 - if (host->check_local == 0) {
1561 - handler_ctx *hctx;
1563 + log_error_write(srv, __FILE__, __LINE__, "sbsbs",
1564 + "all handlers for ", con->uri.path,
1565 + "on", extension->key,
1569 - hctx = handler_ctx_init();
1570 + return HANDLER_FINISHED;
1573 - hctx->remote_conn = con;
1574 - hctx->plugin_data = p;
1575 - hctx->host = host;
1576 - hctx->proc = NULL;
1577 + /* a note about no handler is not sent yet */
1578 + extension->note_is_sent = 0;
1580 - hctx->conf.exts = p->conf.exts;
1581 - hctx->conf.debug = p->conf.debug;
1583 + * if check-local is disabled, use the uri.path handler
1587 - con->plugin_ctx[p->id] = hctx;
1588 + /* init handler-context */
1589 + if (uri_path_handler) {
1590 + if (host->check_local == 0) {
1591 + handler_ctx *hctx;
1596 - con->mode = p->id;
1598 - if (con->conf.log_request_handling) {
1599 - log_error_write(srv, __FILE__, __LINE__, "s", "handling it in mod_scgi");
1602 - /* the prefix is the SCRIPT_NAME,
1603 - * everthing from start to the next slash
1604 - * this is important for check-local = "disable"
1606 - * if prefix = /admin.fcgi
1608 - * /admin.fcgi/foo/bar
1610 - * SCRIPT_NAME = /admin.fcgi
1611 - * PATH_INFO = /foo/bar
1613 - * if prefix = /fcgi-bin/
1615 - * /fcgi-bin/foo/bar
1617 - * SCRIPT_NAME = /fcgi-bin/foo
1618 - * PATH_INFO = /bar
1622 - /* the rewrite is only done for /prefix/? matches */
1623 - if (extension->key->ptr[0] == '/' &&
1624 - con->uri.path->used > extension->key->used &&
1625 - NULL != (pathinfo = strchr(con->uri.path->ptr + extension->key->used - 1, '/'))) {
1626 - /* rewrite uri.path and pathinfo */
1628 - buffer_copy_string(con->request.pathinfo, pathinfo);
1630 - con->uri.path->used -= con->request.pathinfo->used - 1;
1631 - con->uri.path->ptr[con->uri.path->used - 1] = '\0';
1634 - return HANDLER_GO_ON;
1636 - handler_ctx *hctx;
1637 hctx = handler_ctx_init();
1639 hctx->remote_conn = con;
1640 hctx->plugin_data = p;
1642 - hctx->proc = NULL;
1643 + hctx->proc = NULL;
1645 hctx->conf.exts = p->conf.exts;
1646 hctx->conf.debug = p->conf.debug;
1647 @@ -2812,22 +2800,69 @@
1650 if (con->conf.log_request_handling) {
1651 - log_error_write(srv, __FILE__, __LINE__, "s", "handling it in mod_fastcgi");
1652 + log_error_write(srv, __FILE__, __LINE__, "s",
1653 + "handling it in mod_fastcgi");
1656 - return HANDLER_GO_ON;
1657 + /* the prefix is the SCRIPT_NAME,
1658 + * everything from start to the next slash
1659 + * this is important for check-local = "disable"
1661 + * if prefix = /admin.fcgi
1663 + * /admin.fcgi/foo/bar
1665 + * SCRIPT_NAME = /admin.fcgi
1666 + * PATH_INFO = /foo/bar
1668 + * if prefix = /fcgi-bin/
1670 + * /fcgi-bin/foo/bar
1672 + * SCRIPT_NAME = /fcgi-bin/foo
1673 + * PATH_INFO = /bar
1677 + /* the rewrite is only done for /prefix/? matches */
1678 + if (extension->key->ptr[0] == '/' &&
1679 + con->uri.path->used > extension->key->used &&
1680 + NULL != (pathinfo = strchr(con->uri.path->ptr + extension->key->used - 1, '/'))) {
1681 + /* rewrite uri.path and pathinfo */
1683 + buffer_copy_string(con->request.pathinfo, pathinfo);
1685 + con->uri.path->used -= con->request.pathinfo->used - 1;
1686 + con->uri.path->ptr[con->uri.path->used - 1] = '\0';
1687 + } else if (host->fix_root_path_name && extension->key->ptr[0] == '/' && extension->key->ptr[1] == '\0') {
1688 + buffer_copy_string(con->request.pathinfo, con->uri.path->ptr);
1689 + con->uri.path->used = 1;
1690 + con->uri.path->ptr[con->uri.path->used - 1] = '\0';
1694 - /* no handler found */
1695 - buffer_reset(con->physical.path);
1696 - con->http_status = 500;
1697 + handler_ctx *hctx;
1698 + hctx = handler_ctx_init();
1700 - log_error_write(srv, __FILE__, __LINE__, "sb",
1701 - "no fcgi-handler found for:",
1703 + hctx->remote_conn = con;
1704 + hctx->plugin_data = p;
1705 + hctx->host = host;
1706 + hctx->proc = NULL;
1708 - return HANDLER_FINISHED;
1709 + hctx->conf.exts = p->conf.exts;
1710 + hctx->conf.debug = p->conf.debug;
1712 + con->plugin_ctx[p->id] = hctx;
1716 + con->mode = p->id;
1718 + if (con->conf.log_request_handling) {
1719 + log_error_write(srv, __FILE__, __LINE__, "s", "handling it in mod_fastcgi");
1723 return HANDLER_GO_ON;
1726 @@ -2949,7 +2984,7 @@
1727 fp->port = host->port + fp->id;
1729 buffer_copy_string_buffer(fp->socket, host->unixsocket);
1730 - buffer_append_string(fp->socket, "-");
1731 + buffer_append_string_len(fp->socket, CONST_STR_LEN("-"));
1732 buffer_append_long(fp->socket, fp->id);
1735 Index: src/mod_mysql_vhost.c
1736 ===================================================================
1737 --- src/mod_mysql_vhost.c (.../tags/lighttpd-1.4.19) (revision 2303)
1738 +++ src/mod_mysql_vhost.c (.../branches/lighttpd-1.4.x) (revision 2303)
1741 ERR500: if (result) mysql_free_result(result);
1742 con->http_status = 500; /* Internal Error */
1743 + con->mode = DIRECT;
1744 return HANDLER_FINISHED;
1747 Index: src/mod_flv_streaming.c
1748 ===================================================================
1749 --- src/mod_flv_streaming.c (.../tags/lighttpd-1.4.19) (revision 2303)
1750 +++ src/mod_flv_streaming.c (.../branches/lighttpd-1.4.x) (revision 2303)
1755 + if (con->mode != DIRECT) return HANDLER_GO_ON;
1757 if (buffer_is_empty(con->physical.path)) return HANDLER_GO_ON;
1759 mod_flv_streaming_patch_connection(srv, con, p);
1762 /* we are safe now, let's build a flv header */
1763 b = chunkqueue_get_append_buffer(con->write_queue);
1764 - BUFFER_COPY_STRING_CONST(b, "FLV\x1\x1\0\0\0\x9\0\0\0\x9");
1765 + buffer_copy_string_len(b, CONST_STR_LEN("FLV\x1\x1\0\0\0\x9\0\0\0\x9"));
1767 http_chunk_append_file(srv, con, con->physical.path, start, sce->st.st_size - start);
1769 Index: src/lighttpd-angel.c
1770 ===================================================================
1771 --- src/lighttpd-angel.c (.../tags/lighttpd-1.4.19) (revision 2303)
1772 +++ src/lighttpd-angel.c (.../branches/lighttpd-1.4.x) (revision 2303)
1774 static volatile sig_atomic_t graceful_restart = 0;
1775 static volatile pid_t pid = -1;
1777 +#define UNUSED(x) ( (void)(x) )
1779 static void sigaction_handler(int sig, siginfo_t *si, void *context) {
1787 int is_shutdown = 0;
1788 struct sigaction act;
1793 * we are running as root BEWARE
1795 Index: src/mod_rrdtool.c
1796 ===================================================================
1797 --- src/mod_rrdtool.c (.../tags/lighttpd-1.4.19) (revision 2303)
1798 +++ src/mod_rrdtool.c (.../branches/lighttpd-1.4.x) (revision 2303)
1803 + openDevNull(STDERR_FILENO);
1805 /* we don't need the client socket */
1806 for (i = 3; i < 256; i++) {
1810 execv(args[0], args);
1812 - log_error_write(srv, __FILE__, __LINE__, "sss", "spawing rrdtool failed: ", strerror(errno), args[0]);
1813 + /* log_error_write(srv, __FILE__, __LINE__, "sss", "spawing rrdtool failed: ", strerror(errno), args[0]); */
1817 @@ -202,24 +204,25 @@
1819 /* create a new one */
1821 - BUFFER_COPY_STRING_CONST(p->cmd, "create ");
1822 + buffer_copy_string_len(p->cmd, CONST_STR_LEN("create "));
1823 buffer_append_string_buffer(p->cmd, s->path_rrd);
1824 - buffer_append_string(p->cmd, " --step 60 ");
1825 - buffer_append_string(p->cmd, "DS:InOctets:ABSOLUTE:600:U:U ");
1826 - buffer_append_string(p->cmd, "DS:OutOctets:ABSOLUTE:600:U:U ");
1827 - buffer_append_string(p->cmd, "DS:Requests:ABSOLUTE:600:U:U ");
1828 - buffer_append_string(p->cmd, "RRA:AVERAGE:0.5:1:600 ");
1829 - buffer_append_string(p->cmd, "RRA:AVERAGE:0.5:6:700 ");
1830 - buffer_append_string(p->cmd, "RRA:AVERAGE:0.5:24:775 ");
1831 - buffer_append_string(p->cmd, "RRA:AVERAGE:0.5:288:797 ");
1832 - buffer_append_string(p->cmd, "RRA:MAX:0.5:1:600 ");
1833 - buffer_append_string(p->cmd, "RRA:MAX:0.5:6:700 ");
1834 - buffer_append_string(p->cmd, "RRA:MAX:0.5:24:775 ");
1835 - buffer_append_string(p->cmd, "RRA:MAX:0.5:288:797 ");
1836 - buffer_append_string(p->cmd, "RRA:MIN:0.5:1:600 ");
1837 - buffer_append_string(p->cmd, "RRA:MIN:0.5:6:700 ");
1838 - buffer_append_string(p->cmd, "RRA:MIN:0.5:24:775 ");
1839 - buffer_append_string(p->cmd, "RRA:MIN:0.5:288:797\n");
1840 + buffer_append_string_len(p->cmd, CONST_STR_LEN(
1842 + "DS:InOctets:ABSOLUTE:600:U:U "
1843 + "DS:OutOctets:ABSOLUTE:600:U:U "
1844 + "DS:Requests:ABSOLUTE:600:U:U "
1845 + "RRA:AVERAGE:0.5:1:600 "
1846 + "RRA:AVERAGE:0.5:6:700 "
1847 + "RRA:AVERAGE:0.5:24:775 "
1848 + "RRA:AVERAGE:0.5:288:797 "
1849 + "RRA:MAX:0.5:1:600 "
1850 + "RRA:MAX:0.5:6:700 "
1851 + "RRA:MAX:0.5:24:775 "
1852 + "RRA:MAX:0.5:288:797 "
1853 + "RRA:MIN:0.5:1:600 "
1854 + "RRA:MIN:0.5:6:700 "
1855 + "RRA:MIN:0.5:24:775 "
1856 + "RRA:MIN:0.5:288:797\n"));
1858 if (-1 == (r = write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) {
1859 log_error_write(srv, __FILE__, __LINE__, "ss",
1860 @@ -372,15 +375,15 @@
1862 if (HANDLER_GO_ON != mod_rrdtool_create_rrd(srv, p, s)) return HANDLER_ERROR;
1864 - BUFFER_COPY_STRING_CONST(p->cmd, "update ");
1865 + buffer_copy_string_len(p->cmd, CONST_STR_LEN("update "));
1866 buffer_append_string_buffer(p->cmd, s->path_rrd);
1867 - BUFFER_APPEND_STRING_CONST(p->cmd, " N:");
1868 + buffer_append_string_len(p->cmd, CONST_STR_LEN(" N:"));
1869 buffer_append_off_t(p->cmd, s->bytes_read);
1870 - BUFFER_APPEND_STRING_CONST(p->cmd, ":");
1871 + buffer_append_string_len(p->cmd, CONST_STR_LEN(":"));
1872 buffer_append_off_t(p->cmd, s->bytes_written);
1873 - BUFFER_APPEND_STRING_CONST(p->cmd, ":");
1874 + buffer_append_string_len(p->cmd, CONST_STR_LEN(":"));
1875 buffer_append_long(p->cmd, s->requests);
1876 - BUFFER_APPEND_STRING_CONST(p->cmd, "\n");
1877 + buffer_append_string_len(p->cmd, CONST_STR_LEN("\n"));
1879 if (-1 == (r = write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) {
1880 p->rrdtool_running = 0;
1881 Index: src/mod_ssi_expr.c
1882 ===================================================================
1883 --- src/mod_ssi_expr.c (.../tags/lighttpd-1.4.19) (revision 2303)
1884 +++ src/mod_ssi_expr.c (.../branches/lighttpd-1.4.x) (revision 2303)
1889 - buffer_copy_string(token, "(=)");
1890 + buffer_copy_string_len(token, CONST_STR_LEN("(=)"));
1898 - buffer_copy_string(token, "(>=)");
1899 + buffer_copy_string_len(token, CONST_STR_LEN("(>=)"));
1906 - buffer_copy_string(token, "(>)");
1907 + buffer_copy_string_len(token, CONST_STR_LEN("(>)"));
1915 - buffer_copy_string(token, "(<=)");
1916 + buffer_copy_string_len(token, CONST_STR_LEN("(<=)"));
1923 - buffer_copy_string(token, "(<)");
1924 + buffer_copy_string_len(token, CONST_STR_LEN("(<)"));
1928 @@ -106,14 +106,14 @@
1932 - buffer_copy_string(token, "(!=)");
1933 + buffer_copy_string_len(token, CONST_STR_LEN("(!=)"));
1940 - buffer_copy_string(token, "(!)");
1941 + buffer_copy_string_len(token, CONST_STR_LEN("(!)"));
1949 - buffer_copy_string(token, "(&&)");
1950 + buffer_copy_string_len(token, CONST_STR_LEN("(&&)"));
1952 log_error_write(srv, __FILE__, __LINE__, "sds",
1953 "pos:", t->line_pos,
1958 - buffer_copy_string(token, "(||)");
1959 + buffer_copy_string_len(token, CONST_STR_LEN("(||)"));
1961 log_error_write(srv, __FILE__, __LINE__, "sds",
1962 "pos:", t->line_pos,
1967 - buffer_copy_string(token, "(");
1968 + buffer_copy_string_len(token, CONST_STR_LEN("("));
1976 - buffer_copy_string(token, ")");
1977 + buffer_copy_string_len(token, CONST_STR_LEN(")"));
1980 if (t->input[t->offset + 1] == '{') {
1982 } else if (NULL != (ds = (data_string *)array_get_element(p->ssi_vars, token->ptr))) {
1983 buffer_copy_string_buffer(token, ds->value);
1985 - buffer_copy_string(token, "");
1986 + buffer_copy_string_len(token, CONST_STR_LEN(""));
1990 Index: src/stat_cache.c
1991 ===================================================================
1992 --- src/stat_cache.c (.../tags/lighttpd-1.4.19) (revision 2303)
1993 +++ src/stat_cache.c (.../branches/lighttpd-1.4.x) (revision 2303)
1996 if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM) {
1997 if (0 != buffer_copy_dirname(sc->dir_name, name)) {
1999 + log_error_write(srv, __FILE__, __LINE__, "sb",
2000 + "no '/' found in filename:", name);
2001 + return HANDLER_ERROR;
2004 buffer_copy_string_buffer(sc->hash_key, sc->dir_name);
2005 Index: src/response.c
2006 ===================================================================
2007 --- src/response.c (.../tags/lighttpd-1.4.19) (revision 2303)
2008 +++ src/response.c (.../branches/lighttpd-1.4.x) (revision 2303)
2010 b = chunkqueue_get_prepend_buffer(con->write_queue);
2012 if (con->request.http_version == HTTP_VERSION_1_1) {
2013 - BUFFER_COPY_STRING_CONST(b, "HTTP/1.1 ");
2014 + buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.1 "));
2016 - BUFFER_COPY_STRING_CONST(b, "HTTP/1.0 ");
2017 + buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.0 "));
2019 buffer_append_long(b, con->http_status);
2020 - BUFFER_APPEND_STRING_CONST(b, " ");
2021 + buffer_append_string_len(b, CONST_STR_LEN(" "));
2022 buffer_append_string(b, get_http_status_name(con->http_status));
2024 if (con->request.http_version != HTTP_VERSION_1_1 || con->keep_alive == 0) {
2025 - BUFFER_APPEND_STRING_CONST(b, "\r\nConnection: ");
2026 - buffer_append_string(b, con->keep_alive ? "keep-alive" : "close");
2027 + buffer_append_string_len(b, CONST_STR_LEN("\r\nConnection: "));
2028 + if (con->keep_alive) {
2029 + buffer_append_string_len(b, CONST_STR_LEN("keep-alive"));
2031 + buffer_append_string_len(b, CONST_STR_LEN("close"));
2035 if (con->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED) {
2036 - BUFFER_APPEND_STRING_CONST(b, "\r\nTransfer-Encoding: chunked");
2037 + buffer_append_string_len(b, CONST_STR_LEN("\r\nTransfer-Encoding: chunked"));
2042 ds = (data_string *)con->response.headers->data[i];
2044 if (ds->value->used && ds->key->used &&
2045 - 0 != strncmp(ds->key->ptr, "X-LIGHTTPD-", sizeof("X-LIGHTTPD-") - 1) &&
2046 - 0 != strncmp(ds->key->ptr, "X-Sendfile", sizeof("X-Sendfile") - 1)) {
2047 - if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Date"))) have_date = 1;
2048 - if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Server"))) have_server = 1;
2049 + 0 != strncasecmp(ds->key->ptr, CONST_STR_LEN("X-LIGHTTPD-")) &&
2050 + 0 != strcasecmp(ds->key->ptr, "X-Sendfile")) {
2051 + if (0 == strcasecmp(ds->key->ptr, "Date")) have_date = 1;
2052 + if (0 == strcasecmp(ds->key->ptr, "Server")) have_server = 1;
2053 + if (0 == strcasecmp(ds->key->ptr, "Content-Encoding") && 304 == con->http_status) continue;
2055 - BUFFER_APPEND_STRING_CONST(b, "\r\n");
2056 + buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
2057 buffer_append_string_buffer(b, ds->key);
2058 - BUFFER_APPEND_STRING_CONST(b, ": ");
2059 + buffer_append_string_len(b, CONST_STR_LEN(": "));
2062 * the value might contain newlines, encode them with at least one white-space
2066 /* HTTP/1.1 requires a Date: header */
2067 - BUFFER_APPEND_STRING_CONST(b, "\r\nDate: ");
2068 + buffer_append_string_len(b, CONST_STR_LEN("\r\nDate: "));
2070 /* cache the generated timestamp */
2071 if (srv->cur_ts != srv->last_generated_date_ts) {
2072 @@ -100,14 +105,14 @@
2075 if (buffer_is_empty(con->conf.server_tag)) {
2076 - BUFFER_APPEND_STRING_CONST(b, "\r\nServer: " PACKAGE_NAME "/" PACKAGE_VERSION);
2078 - BUFFER_APPEND_STRING_CONST(b, "\r\nServer: ");
2079 + buffer_append_string_len(b, CONST_STR_LEN("\r\nServer: " PACKAGE_NAME "/" PACKAGE_VERSION));
2080 + } else if (con->conf.server_tag->used > 1) {
2081 + buffer_append_string_len(b, CONST_STR_LEN("\r\nServer: "));
2082 buffer_append_string_encoded(b, CONST_BUF_LEN(con->conf.server_tag), ENCODING_HTTP_HEADER);
2086 - BUFFER_APPEND_STRING_CONST(b, "\r\n\r\n");
2087 + buffer_append_string_len(b, CONST_STR_LEN("\r\n\r\n"));
2090 con->bytes_header = b->used - 1;
2094 config_cond_cache_reset(srv, con);
2095 - config_setup_connection(srv, con); // Perhaps this could be removed at other places.
2096 + config_setup_connection(srv, con); /* Perhaps this could be removed at other places. */
2098 if (con->conf.log_condition_handling) {
2099 log_error_write(srv, __FILE__, __LINE__, "s", "run condition");
2100 @@ -181,7 +186,11 @@
2104 - buffer_copy_string(con->uri.scheme, con->conf.is_ssl ? "https" : "http");
2105 + if (con->conf.is_ssl) {
2106 + buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("https"));
2108 + buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("http"));
2110 buffer_copy_string_buffer(con->uri.authority, con->request.http_host);
2111 buffer_to_lower(con->uri.authority);
2113 @@ -224,27 +233,6 @@
2121 - * - based on the raw URL
2125 - switch(r = plugins_call_handle_uri_raw(srv, con)) {
2126 - case HANDLER_GO_ON:
2128 - case HANDLER_FINISHED:
2129 - case HANDLER_COMEBACK:
2130 - case HANDLER_WAIT_FOR_EVENT:
2131 - case HANDLER_ERROR:
2134 - log_error_write(srv, __FILE__, __LINE__, "sd", "handle_uri_raw: unknown return value", r);
2140 * - decode url-encodings (e.g. %20 -> ' ')
2146 if (con->request.http_method == HTTP_METHOD_OPTIONS &&
2147 con->uri.path_raw->ptr[0] == '*' && con->uri.path_raw->ptr[1] == '\0') {
2149 @@ -268,10 +255,32 @@
2150 log_error_write(srv, __FILE__, __LINE__, "sb", "URI-path : ", con->uri.path);
2158 + * - based on the raw URL
2162 + switch(r = plugins_call_handle_uri_raw(srv, con)) {
2163 + case HANDLER_GO_ON:
2165 + case HANDLER_FINISHED:
2166 + case HANDLER_COMEBACK:
2167 + case HANDLER_WAIT_FOR_EVENT:
2168 + case HANDLER_ERROR:
2171 + log_error_write(srv, __FILE__, __LINE__, "sd", "handle_uri_raw: unknown return value", r);
2179 * - based on the clean URL
2183 ===================================================================
2184 --- src/plugin.c (.../tags/lighttpd-1.4.19) (revision 2303)
2185 +++ src/plugin.c (.../branches/lighttpd-1.4.x) (revision 2303)
2186 @@ -131,12 +131,12 @@
2188 buffer_copy_string_buffer(srv->tmp_buf, srv->srvconf.modules_dir);
2190 - buffer_append_string(srv->tmp_buf, "/");
2191 + buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("/"));
2192 buffer_append_string(srv->tmp_buf, modules);
2193 #if defined(__WIN32) || defined(__CYGWIN__)
2194 - buffer_append_string(srv->tmp_buf, ".dll");
2195 + buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN(".dll"));
2197 - buffer_append_string(srv->tmp_buf, ".so");
2198 + buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN(".so"));
2204 buffer_reset(srv->tmp_buf);
2205 buffer_copy_string(srv->tmp_buf, modules);
2206 - buffer_append_string(srv->tmp_buf, "_plugin_init");
2207 + buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("_plugin_init"));
2210 init = GetProcAddress(p->lib, srv->tmp_buf->ptr);
2215 - init = (int (*)(plugin *))dlsym(p->lib, srv->tmp_buf->ptr);
2216 + init = (int (*)(plugin *))(intptr_t)dlsym(p->lib, srv->tmp_buf->ptr);
2218 *(void **)(&init) = dlsym(p->lib, srv->tmp_buf->ptr);
2220 Index: src/SConscript
2221 ===================================================================
2222 --- src/SConscript (.../tags/lighttpd-1.4.19) (revision 2303)
2223 +++ src/SConscript (.../branches/lighttpd-1.4.x) (revision 2303)
2225 'mod_cgi' : { 'src' : [ 'mod_cgi.c' ] },
2226 'mod_fastcgi' : { 'src' : [ 'mod_fastcgi.c' ] },
2227 'mod_scgi' : { 'src' : [ 'mod_scgi.c' ] },
2228 + 'mod_extforward' : { 'src' : [ 'mod_extforward.c' ] },
2229 'mod_staticfile' : { 'src' : [ 'mod_staticfile.c' ] },
2230 'mod_dirlisting' : { 'src' : [ 'mod_dirlisting.c' ], 'lib' : [ env['LIBPCRE'] ] },
2231 'mod_indexfile' : { 'src' : [ 'mod_indexfile.c' ] },
2233 ===================================================================
2234 --- src/buffer.c (.../tags/lighttpd-1.4.19) (revision 2303)
2235 +++ src/buffer.c (.../branches/lighttpd-1.4.x) (revision 2303)
2240 + } else if (b->size) {
2249 +/* everything except: ! ( ) * - . 0-9 A-Z _ a-z */
2250 const char encoded_chars_rel_uri_part[] = {
2252 0 1 2 3 4 5 6 7 8 9 A B C D E F
2253 @@ -633,11 +636,11 @@
2254 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F control chars */
2255 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */
2256 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, /* 20 - 2F space " # $ % & ' + , / */
2257 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, /* 30 - 3F : ; = ? @ < > */
2258 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F */
2259 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50 - 5F */
2260 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
2261 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 70 - 7F DEL */
2262 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, /* 30 - 3F : ; < = > ? */
2263 + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F @ */
2264 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, /* 50 - 5F [ \ ] ^ */
2265 + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F ` */
2266 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, /* 70 - 7F { | } ~ DEL */
2267 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80 - 8F */
2268 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 90 - 9F */
2269 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* A0 - AF */
2270 @@ -648,18 +651,19 @@
2271 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* F0 - FF */
2274 +/* everything except: ! ( ) * - . / 0-9 A-Z _ a-z */
2275 const char encoded_chars_rel_uri[] = {
2277 0 1 2 3 4 5 6 7 8 9 A B C D E F
2279 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 00 - 0F control chars */
2280 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 - 1F */
2281 - 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, /* 20 - 2F space " # $ % & ' + , / */
2282 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, /* 30 - 3F : ; = ? @ < > */
2283 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F */
2284 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 50 - 5F */
2285 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */
2286 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* 70 - 7F DEL */
2287 + 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, /* 20 - 2F space " # $ % & ' + , */
2288 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, /* 30 - 3F : ; < = > ? */
2289 + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 40 - 4F @ */
2290 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, /* 50 - 5F [ \ ] ^ */
2291 + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F ` */
2292 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, /* 70 - 7F { | } ~ DEL */
2293 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80 - 8F */
2294 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 90 - 9F */
2295 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* A0 - AF */
2296 Index: src/mod_userdir.c
2297 ===================================================================
2298 --- src/mod_userdir.c (.../tags/lighttpd-1.4.19) (revision 2303)
2299 +++ src/mod_userdir.c (.../branches/lighttpd-1.4.x) (revision 2303)
2301 return HANDLER_GO_ON;
2304 + if (con->conf.force_lowercase_filenames) {
2305 + buffer_to_lower(p->username);
2308 buffer_copy_string_buffer(p->temp_path, p->conf.basepath);
2309 BUFFER_APPEND_SLASH(p->temp_path);
2310 @@ -284,8 +287,24 @@
2314 + /* the physical rel_path is basically the same as uri.path;
2315 + * but it is converted to lowercase in case of force_lowercase_filenames and some special handling
2316 + * for trailing '.', ' ' and '/' on windows
2317 + * we assume that no docroot/physical handler changed this
2318 + * (docroot should only set the docroot/server name, phyiscal should only change the phyiscal.path;
2319 + * the exception mod_secure_download doesn't work with userdir anyway)
2321 BUFFER_APPEND_SLASH(p->temp_path);
2322 - buffer_append_string(p->temp_path, rel_url + 1); /* skip the / */
2323 + /* if no second '/' is found, we assume that it was stripped from the uri.path for the special handling
2325 + * we do not care about the trailing slash here on windows, as we already ensured it is a directory
2327 + * TODO: what to do with trailing dots in usernames on windows? they may result in the same directory
2328 + * as a username without them.
2330 + if (NULL != (rel_url = strchr(con->physical.rel_path->ptr + 2, '/'))) {
2331 + buffer_append_string(p->temp_path, rel_url + 1); /* skip the / */
2333 buffer_copy_string_buffer(con->physical.path, p->temp_path);
2335 buffer_reset(p->temp_path);
2336 Index: src/mod_proxy.c
2337 ===================================================================
2338 --- src/mod_proxy.c (.../tags/lighttpd-1.4.19) (revision 2303)
2339 +++ src/mod_proxy.c (.../branches/lighttpd-1.4.x) (revision 2303)
2340 @@ -432,10 +432,10 @@
2343 buffer_copy_string(b, get_http_method_name(con->request.http_method));
2344 - BUFFER_APPEND_STRING_CONST(b, " ");
2345 + buffer_append_string_len(b, CONST_STR_LEN(" "));
2347 buffer_append_string_buffer(b, con->request.uri);
2348 - BUFFER_APPEND_STRING_CONST(b, " HTTP/1.0\r\n");
2349 + buffer_append_string_len(b, CONST_STR_LEN(" HTTP/1.0\r\n"));
2351 proxy_append_header(con, "X-Forwarded-For", (char *)inet_ntop_cache_get_ip(srv, &(con->dst_addr)));
2352 /* http_host is NOT is just a pointer to a buffer
2353 @@ -456,13 +456,13 @@
2354 if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Connection"))) continue;
2356 buffer_append_string_buffer(b, ds->key);
2357 - BUFFER_APPEND_STRING_CONST(b, ": ");
2358 + buffer_append_string_len(b, CONST_STR_LEN(": "));
2359 buffer_append_string_buffer(b, ds->value);
2360 - BUFFER_APPEND_STRING_CONST(b, "\r\n");
2361 + buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
2365 - BUFFER_APPEND_STRING_CONST(b, "\r\n");
2366 + buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
2368 hctx->wb->bytes_in += b->used - 1;
2370 @@ -1060,6 +1060,8 @@
2371 data_array *extension = NULL;
2372 size_t path_info_offset;
2374 + if (con->mode != DIRECT) return HANDLER_GO_ON;
2376 /* Possibly, we processed already this request */
2377 if (con->file_started == 1) return HANDLER_GO_ON;
2379 @@ -1118,7 +1120,13 @@
2380 log_error_write(srv, __FILE__, __LINE__, "s", "proxy - ext found");
2383 - switch(p->conf.balance) {
2384 + if (extension->value->used == 1) {
2385 + if ( ((data_proxy *)extension->value->data[0])->is_disabled ) {
2390 + } else if (extension->value->used != 0) switch(p->conf.balance) {
2391 case PROXY_BALANCE_HASH:
2392 /* hash balancing */
2394 @@ -1175,7 +1183,9 @@
2398 - case PROXY_BALANCE_RR:
2399 + case PROXY_BALANCE_RR: {
2403 if (p->conf.debug) {
2404 log_error_write(srv, __FILE__, __LINE__, "s",
2405 @@ -1185,31 +1195,32 @@
2406 /* just to be sure */
2407 assert(extension->value->used < INT_MAX);
2409 - for (k = 0, ndx = -1, max_usage = INT_MAX; k < extension->value->used; k++) {
2410 - data_proxy *host = (data_proxy *)extension->value->data[k];
2411 + host = (data_proxy *)extension->value->data[0];
2413 - if (host->is_disabled) continue;
2414 + /* Use last_used_ndx from first host in list */
2415 + k = ndx = host->last_used_ndx;
2416 + if (ndx < 0) ndx = 0;
2418 - /* first usable ndx */
2419 - if (max_usage == INT_MAX) {
2422 + /* Search first active host after last_used_ndx */
2423 + while ( ndx < (int) extension->value->used
2424 + && (host = (data_proxy *)extension->value->data[ndx])->is_disabled ) ndx++;
2426 - /* get next ndx */
2427 - if ((int)k > host->last_used_ndx) {
2429 - host->last_used_ndx = k;
2432 + if (ndx >= (int) extension->value->used) {
2433 + /* didn't found a higher id, wrap to the start */
2434 + for (ndx = 0; ndx < (int) k; ndx++) {
2435 + host = (data_proxy *)extension->value->data[ndx];
2436 + if (!host->is_disabled) break;
2440 - /* didn't found a higher id, wrap to the start */
2441 - if (ndx == -1 && max_usage != INT_MAX) {
2443 + /* No active host found */
2444 + if (host->is_disabled) ndx = -1;
2447 + /* Save new index for next round */
2448 + ((data_proxy *)extension->value->data[0])->last_used_ndx = ndx;
2455 Index: src/mod_extforward.c
2456 ===================================================================
2457 --- src/mod_extforward.c (.../tags/lighttpd-1.4.19) (revision 2303)
2458 +++ src/mod_extforward.c (.../branches/lighttpd-1.4.x) (revision 2303)
2460 static const char *last_not_in_array(array *a, plugin_data *p)
2462 array *forwarder = p->conf.forwarder;
2465 - for (int i = a->used - 1; i >= 0; i--) {
2466 + for (i = a->used - 1; i >= 0; i--) {
2467 data_string *ds = (data_string *)a->data[i];
2468 const char *ip = ds->value->ptr;
2470 Index: src/Makefile.am
2471 ===================================================================
2472 --- src/Makefile.am (.../tags/lighttpd-1.4.19) (revision 2303)
2473 +++ src/Makefile.am (.../branches/lighttpd-1.4.x) (revision 2303)
2475 noinst_PROGRAMS=proc_open lemon # simple-fcgi #graphic evalo bench ajp ssl error_test adserver gen-license
2476 sbin_PROGRAMS=lighttpd lighttpd-angel
2477 bin_PROGRAMS=spawn-fcgi
2478 -LEMON=$(top_builddir)/src/lemon
2479 +LEMON=$(top_builddir)/src/lemon$(EXEEXT)
2481 lemon_SOURCES=lemon.c
2485 configparser.c configparser.h:
2486 mod_ssi_exprparser.c mod_ssi_exprparser.h:
2491 -$(srcdir)/configparser.y: lemon
2492 -$(srcdir)/mod_ssi_exprparser.y: lemon
2494 -configparser.c configparser.h: $(srcdir)/configparser.y
2495 +configparser.h: configparser.c
2496 +configparser.c: $(srcdir)/configparser.y $(srcdir)/lempar.c lemon$(EXEEXT)
2497 rm -f configparser.h
2498 $(LEMON) -q $(srcdir)/configparser.y $(srcdir)/lempar.c
2500 -mod_ssi_exprparser.c mod_ssi_exprparser.h: $(srcdir)/mod_ssi_exprparser.y
2501 +mod_ssi_exprparser.h: mod_ssi_exprparser.c
2502 +mod_ssi_exprparser.c: $(srcdir)/mod_ssi_exprparser.y $(srcdir)/lempar.c lemon$(EXEEXT)
2503 rm -f mod_ssi_exprparser.h
2504 $(LEMON) -q $(srcdir)/mod_ssi_exprparser.y $(srcdir)/lempar.c
2507 +parsers: configparser.c mod_ssi_exprparser.c
2510 -$(srcdir)/configfile.c: configparser.h
2511 -$(srcdir)/mod_ssi_expr.c: mod_ssi_exprparser.h
2512 +BUILT_SOURCES = parsers
2513 +MAINTAINERCLEANFILES = configparser.c configparser.h mod_ssi_exprparser.c mod_ssi_exprparser.h
2515 common_src=buffer.c log.c \
2516 keyvalue.c chunk.c \
2517 Index: src/mod_expire.c
2518 ===================================================================
2519 --- src/mod_expire.c (.../tags/lighttpd-1.4.19) (revision 2303)
2520 +++ src/mod_expire.c (.../branches/lighttpd-1.4.x) (revision 2303)
2522 response_header_overwrite(srv, con, CONST_STR_LEN("Expires"), CONST_BUF_LEN(p->expire_tstmp));
2525 - buffer_copy_string(p->expire_tstmp, "max-age=");
2526 + buffer_copy_string_len(p->expire_tstmp, CONST_STR_LEN("max-age="));
2527 buffer_append_long(p->expire_tstmp, ts);
2529 response_header_overwrite(srv, con, CONST_STR_LEN("Cache-Control"), CONST_BUF_LEN(p->expire_tstmp));
2530 Index: src/network_openssl.c
2531 ===================================================================
2532 --- src/network_openssl.c (.../tags/lighttpd-1.4.19) (revision 2303)
2533 +++ src/network_openssl.c (.../branches/lighttpd-1.4.x) (revision 2303)
2538 + ERR_clear_error();
2539 if ((r = SSL_write(ssl, offset, toSend)) <= 0) {
2546 + ERR_clear_error();
2547 if ((r = SSL_write(ssl, s, toSend)) <= 0) {
2550 Index: src/network_freebsd_sendfile.c
2551 ===================================================================
2552 --- src/network_freebsd_sendfile.c (.../tags/lighttpd-1.4.19) (revision 2303)
2553 +++ src/network_freebsd_sendfile.c (.../branches/lighttpd-1.4.x) (revision 2303)
2555 if (-1 == sendfile(c->file.fd, fd, offset, toSend, NULL, &r, 0)) {
2567 + if (r == 0 && (errno != EAGAIN && errno != EINTR)) {
2569 /* We got an event to write but we wrote nothing
2571 Index: src/mod_redirect.c
2572 ===================================================================
2573 --- src/mod_redirect.c (.../tags/lighttpd-1.4.19) (revision 2303)
2574 +++ src/mod_redirect.c (.../branches/lighttpd-1.4.x) (revision 2303)
2577 start = 0; end = pattern_len;
2578 for (k = 0; k < pattern_len; k++) {
2579 - if ((pattern[k] == '$' || pattern[k] == '%') &&
2580 - isdigit((unsigned char)pattern[k + 1])) {
2581 + if (pattern[k] == '$' || pattern[k] == '%') {
2584 size_t num = pattern[k + 1] - '0';
2585 @@ -225,7 +224,10 @@
2587 buffer_append_string_len(p->location, pattern + start, end - start);
2589 - if (pattern[k] == '$') {
2590 + if (!isdigit((unsigned char)pattern[k + 1])) {
2591 + /* enable escape: "%%" => "%", "%a" => "%a", "$$" => "$" */
2592 + buffer_append_string_len(p->location, pattern+k, pattern[k] == pattern[k+1] ? 1 : 2);
2593 + } else if (pattern[k] == '$') {
2594 /* n is always > 0 */
2595 if (num < (size_t)n) {
2596 buffer_append_string(p->location, list[num]);
2598 response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->location));
2600 con->http_status = 301;
2601 + con->mode = DIRECT;
2602 con->file_finished = 1;
2604 return HANDLER_FINISHED;
2605 Index: src/http_auth.c
2606 ===================================================================
2607 --- src/http_auth.c (.../tags/lighttpd-1.4.19) (revision 2303)
2608 +++ src/http_auth.c (.../branches/lighttpd-1.4.x) (revision 2303)
2611 } else if (p->conf.auth_backend == AUTH_BACKEND_LDAP) {
2614 + LDAP *ldap = NULL;
2615 LDAPMessage *lm, *first;
2618 @@ -742,39 +742,56 @@
2619 buffer_append_string_buffer(p->ldap_filter, username);
2620 buffer_append_string_buffer(p->ldap_filter, p->conf.ldap_filter_post);
2624 if (p->conf.ldap == NULL ||
2625 LDAP_SUCCESS != (ret = ldap_search_s(p->conf.ldap, p->conf.auth_ldap_basedn->ptr, LDAP_SCOPE_SUBTREE, p->ldap_filter->ptr, attrs, 0, &lm))) {
2626 - if (auth_ldap_init(srv, &p->conf) != HANDLER_GO_ON)
2628 - if (LDAP_SUCCESS != (ret = ldap_search_s(p->conf.ldap, p->conf.auth_ldap_basedn->ptr, LDAP_SCOPE_SUBTREE, p->ldap_filter->ptr, attrs, 0, &lm))) {
2629 + /* try again if ldap was only temporary down */
2630 + if (p->conf.ldap == NULL || ret != LDAP_SERVER_DOWN || LDAP_SUCCESS != (ret = ldap_search_s(p->conf.ldap, p->conf.auth_ldap_basedn->ptr, LDAP_SCOPE_SUBTREE, p->ldap_filter->ptr, attrs, 0, &lm))) {
2631 + if (auth_ldap_init(srv, &p->conf) != HANDLER_GO_ON)
2634 - log_error_write(srv, __FILE__, __LINE__, "sssb",
2635 - "ldap:", ldap_err2string(ret), "filter:", p->ldap_filter);
2638 + ldap = p->conf.ldap; /* save temporary ldap connection (TODO: redo ldap) */
2639 + if (LDAP_SUCCESS != (ret = ldap_search_s(p->conf.ldap, p->conf.auth_ldap_basedn->ptr, LDAP_SCOPE_SUBTREE, p->ldap_filter->ptr, attrs, 0, &lm))) {
2640 + log_error_write(srv, __FILE__, __LINE__, "sssb",
2641 + "ldap:", ldap_err2string(ret), "filter:", p->ldap_filter);
2642 + /* destroy temporary ldap connection (TODO: redo ldap) */
2643 + ldap_unbind_s(ldap);
2649 if (NULL == (first = ldap_first_entry(p->conf.ldap, lm))) {
2650 - log_error_write(srv, __FILE__, __LINE__, "s", "ldap ...");
2651 + /* No matching entry is not an error */
2652 + /* log_error_write(srv, __FILE__, __LINE__, "s", "ldap ..."); */
2656 + /* destroy temporary ldap connection (TODO: redo ldap) */
2657 + if (NULL != ldap) {
2658 + ldap_unbind_s(ldap);
2663 if (NULL == (dn = ldap_get_dn(p->conf.ldap, first))) {
2664 - log_error_write(srv, __FILE__, __LINE__, "s", "ldap ...");
2665 + log_error_write(srv, __FILE__, __LINE__, "s", "ldap: ldap_get_dn failed");
2669 + /* destroy temporary ldap connection (TODO: redo ldap) */
2670 + if (NULL != ldap) {
2671 + ldap_unbind_s(ldap);
2678 + /* destroy temporary ldap connection (TODO: redo ldap) */
2679 + if (NULL != ldap) {
2680 + ldap_unbind_s(ldap);
2684 if (NULL == (ldap = ldap_init(p->conf.auth_ldap_hostname->ptr, LDAP_PORT))) {
2685 Index: src/mod_usertrack.c
2686 ===================================================================
2687 --- src/mod_usertrack.c (.../tags/lighttpd-1.4.19) (revision 2303)
2688 +++ src/mod_usertrack.c (.../branches/lighttpd-1.4.x) (revision 2303)
2692 if (buffer_is_empty(s->cookie_name)) {
2693 - buffer_copy_string(s->cookie_name, "TRACKID");
2694 + buffer_copy_string_len(s->cookie_name, CONST_STR_LEN("TRACKID"));
2697 for (j = 0; j < s->cookie_name->used - 1; j++) {
2699 if (NULL == (ds = (data_string *)array_get_unused_element(con->response.headers, TYPE_STRING))) {
2700 ds = data_response_init();
2702 - buffer_copy_string(ds->key, "Set-Cookie");
2703 + buffer_copy_string_len(ds->key, CONST_STR_LEN("Set-Cookie"));
2704 buffer_copy_string_buffer(ds->value, p->conf.cookie_name);
2705 - buffer_append_string(ds->value, "=");
2706 + buffer_append_string_len(ds->value, CONST_STR_LEN("="));
2709 /* taken from mod_auth.c */
2710 @@ -235,16 +235,16 @@
2711 MD5_Final(h, &Md5Ctx);
2713 buffer_append_string_encoded(ds->value, (char *)h, 16, ENCODING_HEX);
2714 - buffer_append_string(ds->value, "; Path=/");
2715 - buffer_append_string(ds->value, "; Version=1");
2716 + buffer_append_string_len(ds->value, CONST_STR_LEN("; Path=/"));
2717 + buffer_append_string_len(ds->value, CONST_STR_LEN("; Version=1"));
2719 if (!buffer_is_empty(p->conf.cookie_domain)) {
2720 - buffer_append_string(ds->value, "; Domain=");
2721 + buffer_append_string_len(ds->value, CONST_STR_LEN("; Domain="));
2722 buffer_append_string_encoded(ds->value, CONST_BUF_LEN(p->conf.cookie_domain), ENCODING_REL_URI);
2725 if (p->conf.cookie_max_age) {
2726 - buffer_append_string(ds->value, "; max-age=");
2727 + buffer_append_string_len(ds->value, CONST_STR_LEN("; max-age="));
2728 buffer_append_long(ds->value, p->conf.cookie_max_age);
2731 Index: src/mod_webdav.c
2732 ===================================================================
2733 --- src/mod_webdav.c (.../tags/lighttpd-1.4.19) (revision 2303)
2734 +++ src/mod_webdav.c (.../branches/lighttpd-1.4.x) (revision 2303)
2735 @@ -485,23 +485,23 @@
2739 - buffer_append_string(b,"<");
2740 + buffer_append_string_len(b,CONST_STR_LEN("<"));
2741 buffer_append_string(b, prop_name);
2742 - buffer_append_string(b, " xmlns=\"");
2743 + buffer_append_string_len(b, CONST_STR_LEN(" xmlns=\""));
2744 buffer_append_string(b, prop_ns);
2745 - buffer_append_string(b, "\">");
2746 + buffer_append_string_len(b, CONST_STR_LEN("\">"));
2748 buffer_append_string(b, value);
2750 - buffer_append_string(b,"</");
2751 + buffer_append_string_len(b,CONST_STR_LEN("</"));
2752 buffer_append_string(b, prop_name);
2753 - buffer_append_string(b, ">");
2754 + buffer_append_string_len(b, CONST_STR_LEN(">"));
2756 - buffer_append_string(b,"<");
2757 + buffer_append_string_len(b,CONST_STR_LEN("<"));
2758 buffer_append_string(b, prop_name);
2759 - buffer_append_string(b, " xmlns=\"");
2760 + buffer_append_string_len(b, CONST_STR_LEN(" xmlns=\""));
2761 buffer_append_string(b, prop_ns);
2762 - buffer_append_string(b, "\"/>");
2763 + buffer_append_string_len(b, CONST_STR_LEN("\"/>"));
2767 @@ -511,24 +511,24 @@
2768 static int webdav_gen_response_status_tag(server *srv, connection *con, physical *dst, int status, buffer *b) {
2771 - buffer_append_string(b,"<D:response xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n");
2772 + buffer_append_string_len(b,CONST_STR_LEN("<D:response xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"));
2774 - buffer_append_string(b,"<D:href>\n");
2775 + buffer_append_string_len(b,CONST_STR_LEN("<D:href>\n"));
2776 buffer_append_string_buffer(b, dst->rel_path);
2777 - buffer_append_string(b,"</D:href>\n");
2778 - buffer_append_string(b,"<D:status>\n");
2779 + buffer_append_string_len(b,CONST_STR_LEN("</D:href>\n"));
2780 + buffer_append_string_len(b,CONST_STR_LEN("<D:status>\n"));
2782 if (con->request.http_version == HTTP_VERSION_1_1) {
2783 - BUFFER_COPY_STRING_CONST(b, "HTTP/1.1 ");
2784 + buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.1 "));
2786 - BUFFER_COPY_STRING_CONST(b, "HTTP/1.0 ");
2787 + buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.0 "));
2789 buffer_append_long(b, status);
2790 - BUFFER_APPEND_STRING_CONST(b, " ");
2791 + buffer_append_string_len(b, CONST_STR_LEN(" "));
2792 buffer_append_string(b, get_http_status_name(status));
2794 - buffer_append_string(b,"</D:status>\n");
2795 - buffer_append_string(b,"</D:response>\n");
2796 + buffer_append_string_len(b,CONST_STR_LEN("</D:status>\n"));
2797 + buffer_append_string_len(b,CONST_STR_LEN("</D:response>\n"));
2819 @@ -840,12 +844,12 @@
2821 if (0 == strcmp(prop_name, "resourcetype")) {
2822 if (S_ISDIR(sce->st.st_mode)) {
2823 - buffer_append_string(b, "<D:resourcetype><D:collection/></D:resourcetype>");
2824 + buffer_append_string_len(b, CONST_STR_LEN("<D:resourcetype><D:collection/></D:resourcetype>"));
2827 } else if (0 == strcmp(prop_name, "getcontenttype")) {
2828 if (S_ISDIR(sce->st.st_mode)) {
2829 - buffer_append_string(b, "<D:getcontenttype>httpd/unix-directory</D:getcontenttype>");
2830 + buffer_append_string_len(b, CONST_STR_LEN("<D:getcontenttype>httpd/unix-directory</D:getcontenttype>"));
2832 } else if(S_ISREG(sce->st.st_mode)) {
2833 for (k = 0; k < con->conf.mimetypes->used; k++) {
2835 if (ds->key->used == 0) continue;
2837 if (buffer_is_equal_right_len(dst->path, ds->key, ds->key->used - 1)) {
2838 - buffer_append_string(b,"<D:getcontenttype>");
2839 + buffer_append_string_len(b,CONST_STR_LEN("<D:getcontenttype>"));
2840 buffer_append_string_buffer(b, ds->value);
2841 - buffer_append_string(b, "</D:getcontenttype>");
2842 + buffer_append_string_len(b, CONST_STR_LEN("</D:getcontenttype>"));
2846 @@ -864,26 +868,26 @@
2849 } else if (0 == strcmp(prop_name, "creationdate")) {
2850 - buffer_append_string(b, "<D:creationdate ns0:dt=\"dateTime.tz\">");
2851 + buffer_append_string_len(b, CONST_STR_LEN("<D:creationdate ns0:dt=\"dateTime.tz\">"));
2852 strftime(ctime_buf, sizeof(ctime_buf), "%Y-%m-%dT%H:%M:%SZ", gmtime(&(sce->st.st_ctime)));
2853 buffer_append_string(b, ctime_buf);
2854 - buffer_append_string(b, "</D:creationdate>");
2855 + buffer_append_string_len(b, CONST_STR_LEN("</D:creationdate>"));
2857 } else if (0 == strcmp(prop_name, "getlastmodified")) {
2858 - buffer_append_string(b,"<D:getlastmodified ns0:dt=\"dateTime.rfc1123\">");
2859 + buffer_append_string_len(b,CONST_STR_LEN("<D:getlastmodified ns0:dt=\"dateTime.rfc1123\">"));
2860 strftime(mtime_buf, sizeof(mtime_buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&(sce->st.st_mtime)));
2861 buffer_append_string(b, mtime_buf);
2862 - buffer_append_string(b, "</D:getlastmodified>");
2863 + buffer_append_string_len(b, CONST_STR_LEN("</D:getlastmodified>"));
2865 } else if (0 == strcmp(prop_name, "getcontentlength")) {
2866 - buffer_append_string(b,"<D:getcontentlength>");
2867 + buffer_append_string_len(b,CONST_STR_LEN("<D:getcontentlength>"));
2868 buffer_append_off_t(b, sce->st.st_size);
2869 - buffer_append_string(b, "</D:getcontentlength>");
2870 + buffer_append_string_len(b, CONST_STR_LEN("</D:getcontentlength>"));
2872 } else if (0 == strcmp(prop_name, "getcontentlanguage")) {
2873 - buffer_append_string(b,"<D:getcontentlanguage>");
2874 - buffer_append_string(b, "en");
2875 - buffer_append_string(b, "</D:getcontentlanguage>");
2876 + buffer_append_string_len(b,CONST_STR_LEN("<D:getcontentlanguage>"));
2877 + buffer_append_string_len(b, CONST_STR_LEN("en"));
2878 + buffer_append_string_len(b, CONST_STR_LEN("</D:getcontentlanguage>"));
2882 @@ -1103,44 +1107,44 @@
2884 b = chunkqueue_get_append_buffer(con->write_queue);
2886 - buffer_copy_string(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2887 + buffer_copy_string_len(b, CONST_STR_LEN("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"));
2889 - buffer_append_string(b,"<D:prop xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n");
2890 - buffer_append_string(b,"<D:lockdiscovery>\n");
2891 - buffer_append_string(b,"<D:activelock>\n");
2892 + buffer_append_string_len(b,CONST_STR_LEN("<D:prop xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"));
2893 + buffer_append_string_len(b,CONST_STR_LEN("<D:lockdiscovery>\n"));
2894 + buffer_append_string_len(b,CONST_STR_LEN("<D:activelock>\n"));
2896 - buffer_append_string(b,"<D:lockscope>");
2897 - buffer_append_string(b,"<D:");
2898 + buffer_append_string_len(b,CONST_STR_LEN("<D:lockscope>"));
2899 + buffer_append_string_len(b,CONST_STR_LEN("<D:"));
2900 buffer_append_string(b, lockscope);
2901 - buffer_append_string(b, "/>");
2902 - buffer_append_string(b,"</D:lockscope>\n");
2903 + buffer_append_string_len(b, CONST_STR_LEN("/>"));
2904 + buffer_append_string_len(b,CONST_STR_LEN("</D:lockscope>\n"));
2906 - buffer_append_string(b,"<D:locktype>");
2907 - buffer_append_string(b,"<D:");
2908 + buffer_append_string_len(b,CONST_STR_LEN("<D:locktype>"));
2909 + buffer_append_string_len(b,CONST_STR_LEN("<D:"));
2910 buffer_append_string(b, locktype);
2911 - buffer_append_string(b, "/>");
2912 - buffer_append_string(b,"</D:locktype>\n");
2913 + buffer_append_string_len(b, CONST_STR_LEN("/>"));
2914 + buffer_append_string_len(b,CONST_STR_LEN("</D:locktype>\n"));
2916 - buffer_append_string(b,"<D:depth>");
2917 + buffer_append_string_len(b,CONST_STR_LEN("<D:depth>"));
2918 buffer_append_string(b, depth == 0 ? "0" : "infinity");
2919 - buffer_append_string(b,"</D:depth>\n");
2920 + buffer_append_string_len(b,CONST_STR_LEN("</D:depth>\n"));
2922 - buffer_append_string(b,"<D:timeout>");
2923 - buffer_append_string(b, "Second-600");
2924 - buffer_append_string(b,"</D:timeout>\n");
2925 + buffer_append_string_len(b,CONST_STR_LEN("<D:timeout>"));
2926 + buffer_append_string_len(b, CONST_STR_LEN("Second-600"));
2927 + buffer_append_string_len(b,CONST_STR_LEN("</D:timeout>\n"));
2929 - buffer_append_string(b,"<D:owner>");
2930 - buffer_append_string(b,"</D:owner>\n");
2931 + buffer_append_string_len(b,CONST_STR_LEN("<D:owner>"));
2932 + buffer_append_string_len(b,CONST_STR_LEN("</D:owner>\n"));
2934 - buffer_append_string(b,"<D:locktoken>");
2935 - buffer_append_string(b, "<D:href>");
2936 + buffer_append_string_len(b,CONST_STR_LEN("<D:locktoken>"));
2937 + buffer_append_string_len(b, CONST_STR_LEN("<D:href>"));
2938 buffer_append_string_buffer(b, locktoken);
2939 - buffer_append_string(b, "</D:href>");
2940 - buffer_append_string(b,"</D:locktoken>\n");
2941 + buffer_append_string_len(b, CONST_STR_LEN("</D:href>"));
2942 + buffer_append_string_len(b,CONST_STR_LEN("</D:locktoken>\n"));
2944 - buffer_append_string(b,"</D:activelock>\n");
2945 - buffer_append_string(b,"</D:lockdiscovery>\n");
2946 - buffer_append_string(b,"</D:prop>\n");
2947 + buffer_append_string_len(b,CONST_STR_LEN("</D:activelock>\n"));
2948 + buffer_append_string_len(b,CONST_STR_LEN("</D:lockdiscovery>\n"));
2949 + buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
2953 @@ -1154,6 +1158,7 @@
2961 @@ -1192,6 +1197,11 @@
2973 @@ -1334,9 +1344,9 @@
2975 b = chunkqueue_get_append_buffer(con->write_queue);
2977 - buffer_copy_string(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
2978 + buffer_copy_string_len(b, CONST_STR_LEN("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"));
2980 - buffer_append_string(b,"<D:multistatus xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n");
2981 + buffer_append_string_len(b,CONST_STR_LEN("<D:multistatus xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n"));
2985 @@ -1348,40 +1358,40 @@
2987 webdav_get_props(srv, con, p, &(con->physical), req_props, prop_200, prop_404);
2989 - buffer_append_string(b,"<D:response>\n");
2990 - buffer_append_string(b,"<D:href>");
2991 + buffer_append_string_len(b,CONST_STR_LEN("<D:response>\n"));
2992 + buffer_append_string_len(b,CONST_STR_LEN("<D:href>"));
2993 buffer_append_string_buffer(b, con->uri.scheme);
2994 - buffer_append_string(b,"://");
2995 + buffer_append_string_len(b,CONST_STR_LEN("://"));
2996 buffer_append_string_buffer(b, con->uri.authority);
2997 buffer_append_string_encoded(b, CONST_BUF_LEN(con->uri.path), ENCODING_REL_URI);
2998 - buffer_append_string(b,"</D:href>\n");
2999 + buffer_append_string_len(b,CONST_STR_LEN("</D:href>\n"));
3001 if (!buffer_is_empty(prop_200)) {
3002 - buffer_append_string(b,"<D:propstat>\n");
3003 - buffer_append_string(b,"<D:prop>\n");
3004 + buffer_append_string_len(b,CONST_STR_LEN("<D:propstat>\n"));
3005 + buffer_append_string_len(b,CONST_STR_LEN("<D:prop>\n"));
3007 buffer_append_string_buffer(b, prop_200);
3009 - buffer_append_string(b,"</D:prop>\n");
3010 + buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
3012 - buffer_append_string(b,"<D:status>HTTP/1.1 200 OK</D:status>\n");
3013 + buffer_append_string_len(b,CONST_STR_LEN("<D:status>HTTP/1.1 200 OK</D:status>\n"));
3015 - buffer_append_string(b,"</D:propstat>\n");
3016 + buffer_append_string_len(b,CONST_STR_LEN("</D:propstat>\n"));
3018 if (!buffer_is_empty(prop_404)) {
3019 - buffer_append_string(b,"<D:propstat>\n");
3020 - buffer_append_string(b,"<D:prop>\n");
3021 + buffer_append_string_len(b,CONST_STR_LEN("<D:propstat>\n"));
3022 + buffer_append_string_len(b,CONST_STR_LEN("<D:prop>\n"));
3024 buffer_append_string_buffer(b, prop_404);
3026 - buffer_append_string(b,"</D:prop>\n");
3027 + buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
3029 - buffer_append_string(b,"<D:status>HTTP/1.1 404 Not Found</D:status>\n");
3030 + buffer_append_string_len(b,CONST_STR_LEN("<D:status>HTTP/1.1 404 Not Found</D:status>\n"));
3032 - buffer_append_string(b,"</D:propstat>\n");
3033 + buffer_append_string_len(b,CONST_STR_LEN("</D:propstat>\n"));
3036 - buffer_append_string(b,"</D:response>\n");
3037 + buffer_append_string_len(b,CONST_STR_LEN("</D:response>\n"));
3041 @@ -1417,40 +1427,40 @@
3043 webdav_get_props(srv, con, p, &d, req_props, prop_200, prop_404);
3045 - buffer_append_string(b,"<D:response>\n");
3046 - buffer_append_string(b,"<D:href>");
3047 + buffer_append_string_len(b,CONST_STR_LEN("<D:response>\n"));
3048 + buffer_append_string_len(b,CONST_STR_LEN("<D:href>"));
3049 buffer_append_string_buffer(b, con->uri.scheme);
3050 - buffer_append_string(b,"://");
3051 + buffer_append_string_len(b,CONST_STR_LEN("://"));
3052 buffer_append_string_buffer(b, con->uri.authority);
3053 buffer_append_string_encoded(b, CONST_BUF_LEN(d.rel_path), ENCODING_REL_URI);
3054 - buffer_append_string(b,"</D:href>\n");
3055 + buffer_append_string_len(b,CONST_STR_LEN("</D:href>\n"));
3057 if (!buffer_is_empty(prop_200)) {
3058 - buffer_append_string(b,"<D:propstat>\n");
3059 - buffer_append_string(b,"<D:prop>\n");
3060 + buffer_append_string_len(b,CONST_STR_LEN("<D:propstat>\n"));
3061 + buffer_append_string_len(b,CONST_STR_LEN("<D:prop>\n"));
3063 buffer_append_string_buffer(b, prop_200);
3065 - buffer_append_string(b,"</D:prop>\n");
3066 + buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
3068 - buffer_append_string(b,"<D:status>HTTP/1.1 200 OK</D:status>\n");
3069 + buffer_append_string_len(b,CONST_STR_LEN("<D:status>HTTP/1.1 200 OK</D:status>\n"));
3071 - buffer_append_string(b,"</D:propstat>\n");
3072 + buffer_append_string_len(b,CONST_STR_LEN("</D:propstat>\n"));
3074 if (!buffer_is_empty(prop_404)) {
3075 - buffer_append_string(b,"<D:propstat>\n");
3076 - buffer_append_string(b,"<D:prop>\n");
3077 + buffer_append_string_len(b,CONST_STR_LEN("<D:propstat>\n"));
3078 + buffer_append_string_len(b,CONST_STR_LEN("<D:prop>\n"));
3080 buffer_append_string_buffer(b, prop_404);
3082 - buffer_append_string(b,"</D:prop>\n");
3083 + buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
3085 - buffer_append_string(b,"<D:status>HTTP/1.1 404 Not Found</D:status>\n");
3086 + buffer_append_string_len(b,CONST_STR_LEN("<D:status>HTTP/1.1 404 Not Found</D:status>\n"));
3088 - buffer_append_string(b,"</D:propstat>\n");
3089 + buffer_append_string_len(b,CONST_STR_LEN("</D:propstat>\n"));
3092 - buffer_append_string(b,"</D:response>\n");
3093 + buffer_append_string_len(b,CONST_STR_LEN("</D:response>\n"));
3096 buffer_free(d.path);
3097 @@ -1473,7 +1483,7 @@
3098 buffer_free(prop_200);
3099 buffer_free(prop_404);
3101 - buffer_append_string(b,"</D:multistatus>\n");
3102 + buffer_append_string_len(b,CONST_STR_LEN("</D:multistatus>\n"));
3104 if (p->conf.log_xml) {
3105 log_error_write(srv, __FILE__, __LINE__, "sb", "XML-response-body:", b);
3106 @@ -1548,13 +1558,13 @@
3108 b = chunkqueue_get_append_buffer(con->write_queue);
3110 - buffer_copy_string(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
3111 + buffer_copy_string_len(b, CONST_STR_LEN("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"));
3113 - buffer_append_string(b,"<D:multistatus xmlns:D=\"DAV:\">\n");
3114 + buffer_append_string_len(b,CONST_STR_LEN("<D:multistatus xmlns:D=\"DAV:\">\n"));
3116 buffer_append_string_buffer(b, multi_status_resp);
3118 - buffer_append_string(b,"</D:multistatus>\n");
3119 + buffer_append_string_len(b,CONST_STR_LEN("</D:multistatus>\n"));
3121 if (p->conf.log_xml) {
3122 log_error_write(srv, __FILE__, __LINE__, "sb", "XML-response-body:", b);
3123 @@ -2286,7 +2296,7 @@
3125 uuid_unparse(id, uuid);
3127 - buffer_copy_string(p->tmp_buf, "opaquelocktoken:");
3128 + buffer_copy_string_len(p->tmp_buf, CONST_STR_LEN("opaquelocktoken:"));
3129 buffer_append_string(p->tmp_buf, uuid);
3131 /* "CREATE TABLE locks ("
3132 Index: src/configparser.y
3133 ===================================================================
3134 --- src/configparser.y (.../tags/lighttpd-1.4.19) (revision 2303)
3135 +++ src/configparser.y (.../branches/lighttpd-1.4.x) (revision 2303)
3137 dc->parent = ctx->current;
3138 array_insert_unique(dc->parent->childs, (data_unset *)dc);
3140 + if (ctx->configs_stack->used > 0 && ctx->current->context_ndx == 0) {
3141 + fprintf(stderr, "Cannot use conditionals inside a global { ... } block\n");
3144 array_insert_unique(ctx->configs_stack, (data_unset *)ctx->current);
3147 Index: src/mod_status.c
3148 ===================================================================
3149 --- src/mod_status.c (.../tags/lighttpd-1.4.19) (revision 2303)
3150 +++ src/mod_status.c (.../branches/lighttpd-1.4.x) (revision 2303)
3151 @@ -143,24 +143,24 @@
3154 static int mod_status_row_append(buffer *b, const char *key, const char *value) {
3155 - BUFFER_APPEND_STRING_CONST(b, " <tr>\n");
3156 - BUFFER_APPEND_STRING_CONST(b, " <td><b>");
3157 + buffer_append_string_len(b, CONST_STR_LEN(" <tr>\n"));
3158 + buffer_append_string_len(b, CONST_STR_LEN(" <td><b>"));
3159 buffer_append_string(b, key);
3160 - BUFFER_APPEND_STRING_CONST(b, "</b></td>\n");
3161 - BUFFER_APPEND_STRING_CONST(b, " <td>");
3162 + buffer_append_string_len(b, CONST_STR_LEN("</b></td>\n"));
3163 + buffer_append_string_len(b, CONST_STR_LEN(" <td>"));
3164 buffer_append_string(b, value);
3165 - BUFFER_APPEND_STRING_CONST(b, "</td>\n");
3166 - BUFFER_APPEND_STRING_CONST(b, " </tr>\n");
3167 + buffer_append_string_len(b, CONST_STR_LEN("</td>\n"));
3168 + buffer_append_string_len(b, CONST_STR_LEN(" </tr>\n"));
3173 static int mod_status_header_append(buffer *b, const char *key) {
3174 - BUFFER_APPEND_STRING_CONST(b, " <tr>\n");
3175 - BUFFER_APPEND_STRING_CONST(b, " <th colspan=\"2\">");
3176 + buffer_append_string_len(b, CONST_STR_LEN(" <tr>\n"));
3177 + buffer_append_string_len(b, CONST_STR_LEN(" <th colspan=\"2\">"));
3178 buffer_append_string(b, key);
3179 - BUFFER_APPEND_STRING_CONST(b, "</th>\n");
3180 - BUFFER_APPEND_STRING_CONST(b, " </tr>\n");
3181 + buffer_append_string_len(b, CONST_STR_LEN("</th>\n"));
3182 + buffer_append_string_len(b, CONST_STR_LEN(" </tr>\n"));
3186 @@ -169,13 +169,13 @@
3187 plugin_data *p = p_d;
3190 - BUFFER_APPEND_STRING_CONST(b, "<th class=\"status\"><a href=\"#\" class=\"sortheader\" onclick=\"resort(this);return false;\">");
3191 + buffer_append_string_len(b, CONST_STR_LEN("<th class=\"status\"><a href=\"#\" class=\"sortheader\" onclick=\"resort(this);return false;\">"));
3192 buffer_append_string(b, key);
3193 - BUFFER_APPEND_STRING_CONST(b, "<span class=\"sortarrow\">:</span></a></th>\n");
3194 + buffer_append_string_len(b, CONST_STR_LEN("<span class=\"sortarrow\">:</span></a></th>\n"));
3196 - BUFFER_APPEND_STRING_CONST(b, "<th class=\"status\">");
3197 + buffer_append_string_len(b, CONST_STR_LEN("<th class=\"status\">"));
3198 buffer_append_string(b, key);
3199 - BUFFER_APPEND_STRING_CONST(b, "</th>\n");
3200 + buffer_append_string_len(b, CONST_STR_LEN("</th>\n"));
3204 @@ -209,15 +209,14 @@
3206 b = chunkqueue_get_append_buffer(con->write_queue);
3208 - BUFFER_COPY_STRING_CONST(b,
3209 + buffer_copy_string_len(b, CONST_STR_LEN(
3210 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
3211 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
3212 " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
3213 "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
3215 - " <title>Status</title>\n");
3216 + " <title>Status</title>\n"
3218 - BUFFER_APPEND_STRING_CONST(b,
3219 " <style type=\"text/css\">\n"
3220 " table.status { border: black solid thin; }\n"
3221 " td { white-space: nowrap; }\n"
3222 @@ -226,16 +225,15 @@
3223 " th.status { background-color: black; color: white; font-weight: bold; }\n"
3224 " a.sortheader { background-color: black; color: white; font-weight: bold; text-decoration: none; display: block; }\n"
3225 " span.sortarrow { color: white; text-decoration: none; }\n"
3230 - BUFFER_APPEND_STRING_CONST(b,
3231 + buffer_append_string_len(b, CONST_STR_LEN(
3232 "<script type=\"text/javascript\">\n"
3234 "var sort_column;\n"
3235 - "var prev_span = null;\n");
3236 + "var prev_span = null;\n"
3238 - BUFFER_APPEND_STRING_CONST(b,
3239 "function get_inner_text(el) {\n"
3240 " if((typeof el == 'string')||(typeof el == 'undefined'))\n"
3249 - BUFFER_APPEND_STRING_CONST(b,
3250 "function sortfn(a,b) {\n"
3251 " var at = get_inner_text(a.cells[sort_column]);\n"
3252 " var bt = get_inner_text(b.cells[sort_column]);\n"
3254 " else if (aa<bb) return -1;\n"
3260 - BUFFER_APPEND_STRING_CONST(b,
3261 "function resort(lnk) {\n"
3262 " var span = lnk.childNodes[1];\n"
3263 " var table = lnk.parentNode.parentNode.parentNode.parentNode;\n"
3265 " for (j=1;j<table.rows.length;j++)\n"
3266 " rows[j-1] = table.rows[j];\n"
3267 " sort_column = lnk.parentNode.cellIndex;\n"
3268 - " rows.sort(sortfn);\n");
3269 + " rows.sort(sortfn);\n"
3271 - BUFFER_APPEND_STRING_CONST(b,
3272 " if (prev_span != null) prev_span.innerHTML = '';\n"
3273 " if (span.getAttribute('sortdir')=='down') {\n"
3274 " span.innerHTML = '↑';\n"
3275 @@ -293,25 +288,25 @@
3276 " prev_span = span;\n"
3283 - BUFFER_APPEND_STRING_CONST(b,
3284 + buffer_append_string_len(b, CONST_STR_LEN(
3291 /* connection listing */
3292 - BUFFER_APPEND_STRING_CONST(b, "<h1>Server-Status</h1>");
3293 + buffer_append_string_len(b, CONST_STR_LEN("<h1>Server-Status</h1>"));
3295 - BUFFER_APPEND_STRING_CONST(b, "<table summary=\"status\" class=\"status\">");
3296 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Hostname</td><td class=\"string\">");
3297 + buffer_append_string_len(b, CONST_STR_LEN("<table summary=\"status\" class=\"status\">"));
3298 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Hostname</td><td class=\"string\">"));
3299 buffer_append_string_buffer(b, con->uri.authority);
3300 - BUFFER_APPEND_STRING_CONST(b, " (");
3301 + buffer_append_string_len(b, CONST_STR_LEN(" ("));
3302 buffer_append_string_buffer(b, con->server_name);
3303 - BUFFER_APPEND_STRING_CONST(b, ")</td></tr>\n");
3304 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Uptime</td><td class=\"string\">");
3305 + buffer_append_string_len(b, CONST_STR_LEN(")</td></tr>\n"));
3306 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Uptime</td><td class=\"string\">"));
3308 ts = srv->cur_ts - srv->startup_ts;
3310 @@ -328,98 +323,98 @@
3313 buffer_append_long(b, days);
3314 - BUFFER_APPEND_STRING_CONST(b, " days ");
3315 + buffer_append_string_len(b, CONST_STR_LEN(" days "));
3319 buffer_append_long(b, hours);
3320 - BUFFER_APPEND_STRING_CONST(b, " hours ");
3321 + buffer_append_string_len(b, CONST_STR_LEN(" hours "));
3325 buffer_append_long(b, mins);
3326 - BUFFER_APPEND_STRING_CONST(b, " min ");
3327 + buffer_append_string_len(b, CONST_STR_LEN(" min "));
3330 buffer_append_long(b, seconds);
3331 - BUFFER_APPEND_STRING_CONST(b, " s");
3332 + buffer_append_string_len(b, CONST_STR_LEN(" s"));
3334 - BUFFER_APPEND_STRING_CONST(b, "</td></tr>\n");
3335 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Started at</td><td class=\"string\">");
3336 + buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
3337 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Started at</td><td class=\"string\">"));
3339 ts = srv->startup_ts;
3341 strftime(buf, sizeof(buf) - 1, "%Y-%m-%d %H:%M:%S", localtime(&ts));
3342 buffer_append_string(b, buf);
3343 - BUFFER_APPEND_STRING_CONST(b, "</td></tr>\n");
3344 + buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
3347 - BUFFER_APPEND_STRING_CONST(b, "<tr><th colspan=\"2\">absolute (since start)</th></tr>\n");
3348 + buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">absolute (since start)</th></tr>\n"));
3350 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\">");
3351 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
3352 avg = p->abs_requests;
3354 mod_status_get_multiplier(&avg, &multiplier, 1000);
3356 buffer_append_long(b, avg);
3357 - BUFFER_APPEND_STRING_CONST(b, " ");
3358 + buffer_append_string_len(b, CONST_STR_LEN(" "));
3359 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
3360 - BUFFER_APPEND_STRING_CONST(b, "req</td></tr>\n");
3361 + buffer_append_string_len(b, CONST_STR_LEN("req</td></tr>\n"));
3363 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\">");
3364 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
3365 avg = p->abs_traffic_out;
3367 mod_status_get_multiplier(&avg, &multiplier, 1024);
3369 sprintf(buf, "%.2f", avg);
3370 buffer_append_string(b, buf);
3371 - BUFFER_APPEND_STRING_CONST(b, " ");
3372 + buffer_append_string_len(b, CONST_STR_LEN(" "));
3373 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
3374 - BUFFER_APPEND_STRING_CONST(b, "byte</td></tr>\n");
3375 + buffer_append_string_len(b, CONST_STR_LEN("byte</td></tr>\n"));
3379 - BUFFER_APPEND_STRING_CONST(b, "<tr><th colspan=\"2\">average (since start)</th></tr>\n");
3380 + buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">average (since start)</th></tr>\n"));
3382 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\">");
3383 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
3384 avg = p->abs_requests / (srv->cur_ts - srv->startup_ts);
3386 mod_status_get_multiplier(&avg, &multiplier, 1000);
3388 buffer_append_long(b, avg);
3389 - BUFFER_APPEND_STRING_CONST(b, " ");
3390 + buffer_append_string_len(b, CONST_STR_LEN(" "));
3391 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
3392 - BUFFER_APPEND_STRING_CONST(b, "req/s</td></tr>\n");
3393 + buffer_append_string_len(b, CONST_STR_LEN("req/s</td></tr>\n"));
3395 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\">");
3396 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
3397 avg = p->abs_traffic_out / (srv->cur_ts - srv->startup_ts);
3399 mod_status_get_multiplier(&avg, &multiplier, 1024);
3401 sprintf(buf, "%.2f", avg);
3402 buffer_append_string(b, buf);
3403 - BUFFER_APPEND_STRING_CONST(b, " ");
3404 + buffer_append_string_len(b, CONST_STR_LEN(" "));
3405 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
3406 - BUFFER_APPEND_STRING_CONST(b, "byte/s</td></tr>\n");
3407 + buffer_append_string_len(b, CONST_STR_LEN("byte/s</td></tr>\n"));
3411 - BUFFER_APPEND_STRING_CONST(b, "<tr><th colspan=\"2\">average (5s sliding average)</th></tr>\n");
3412 + buffer_append_string_len(b, CONST_STR_LEN("<tr><th colspan=\"2\">average (5s sliding average)</th></tr>\n"));
3413 for (j = 0, avg = 0; j < 5; j++) {
3414 avg += p->mod_5s_requests[j];
3419 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\">");
3420 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Requests</td><td class=\"string\">"));
3422 mod_status_get_multiplier(&avg, &multiplier, 1000);
3424 buffer_append_long(b, avg);
3425 - BUFFER_APPEND_STRING_CONST(b, " ");
3426 + buffer_append_string_len(b, CONST_STR_LEN(" "));
3427 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
3429 - BUFFER_APPEND_STRING_CONST(b, "req/s</td></tr>\n");
3430 + buffer_append_string_len(b, CONST_STR_LEN("req/s</td></tr>\n"));
3432 for (j = 0, avg = 0; j < 5; j++) {
3433 avg += p->mod_5s_traffic_out[j];
3434 @@ -427,28 +422,29 @@
3438 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\">");
3439 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td>Traffic</td><td class=\"string\">"));
3441 mod_status_get_multiplier(&avg, &multiplier, 1024);
3443 sprintf(buf, "%.2f", avg);
3444 buffer_append_string(b, buf);
3445 - BUFFER_APPEND_STRING_CONST(b, " ");
3446 + buffer_append_string_len(b, CONST_STR_LEN(" "));
3447 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
3448 - BUFFER_APPEND_STRING_CONST(b, "byte/s</td></tr>\n");
3449 + buffer_append_string_len(b, CONST_STR_LEN("byte/s</td></tr>\n"));
3451 - BUFFER_APPEND_STRING_CONST(b, "</table>\n");
3452 + buffer_append_string_len(b, CONST_STR_LEN("</table>\n"));
3455 - BUFFER_APPEND_STRING_CONST(b, "<hr />\n<pre><b>legend</b>\n");
3456 - BUFFER_APPEND_STRING_CONST(b, ". = connect, C = close, E = hard error\n");
3457 - BUFFER_APPEND_STRING_CONST(b, "r = read, R = read-POST, W = write, h = handle-request\n");
3458 - BUFFER_APPEND_STRING_CONST(b, "q = request-start, Q = request-end\n");
3459 - BUFFER_APPEND_STRING_CONST(b, "s = response-start, S = response-end\n");
3460 + buffer_append_string_len(b, CONST_STR_LEN(
3461 + "<hr />\n<pre><b>legend</b>\n"
3462 + ". = connect, C = close, E = hard error\n"
3463 + "r = read, R = read-POST, W = write, h = handle-request\n"
3464 + "q = request-start, Q = request-end\n"
3465 + "s = response-start, S = response-end\n"));
3467 - BUFFER_APPEND_STRING_CONST(b, "<b>");
3468 + buffer_append_string_len(b, CONST_STR_LEN("<b>"));
3469 buffer_append_long(b, srv->conns->used);
3470 - BUFFER_APPEND_STRING_CONST(b, " connections</b>\n");
3471 + buffer_append_string_len(b, CONST_STR_LEN(" connections</b>\n"));
3473 for (j = 0; j < srv->conns->used; j++) {
3474 connection *c = srv->conns->ptr[j];
3475 @@ -457,14 +453,14 @@
3476 buffer_append_string_len(b, state, 1);
3478 if (((j + 1) % 50) == 0) {
3479 - BUFFER_APPEND_STRING_CONST(b, "\n");
3480 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
3484 - BUFFER_APPEND_STRING_CONST(b, "\n</pre><hr />\n<h2>Connections</h2>\n");
3485 + buffer_append_string_len(b, CONST_STR_LEN("\n</pre><hr />\n<h2>Connections</h2>\n"));
3487 - BUFFER_APPEND_STRING_CONST(b, "<table summary=\"status\" class=\"status\">\n");
3488 - BUFFER_APPEND_STRING_CONST(b, "<tr>");
3489 + buffer_append_string_len(b, CONST_STR_LEN("<table summary=\"status\" class=\"status\">\n"));
3490 + buffer_append_string_len(b, CONST_STR_LEN("<tr>"));
3491 mod_status_header_append_sort(b, p_d, "Client IP");
3492 mod_status_header_append_sort(b, p_d, "Read");
3493 mod_status_header_append_sort(b, p_d, "Written");
3494 @@ -473,40 +469,40 @@
3495 mod_status_header_append_sort(b, p_d, "Host");
3496 mod_status_header_append_sort(b, p_d, "URI");
3497 mod_status_header_append_sort(b, p_d, "File");
3498 - BUFFER_APPEND_STRING_CONST(b, "</tr>\n");
3499 + buffer_append_string_len(b, CONST_STR_LEN("</tr>\n"));
3501 for (j = 0; j < srv->conns->used; j++) {
3502 connection *c = srv->conns->ptr[j];
3504 - BUFFER_APPEND_STRING_CONST(b, "<tr><td class=\"string\">");
3505 + buffer_append_string_len(b, CONST_STR_LEN("<tr><td class=\"string\">"));
3507 buffer_append_string(b, inet_ntop_cache_get_ip(srv, &(c->dst_addr)));
3509 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
3510 + buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
3512 if (con->request.content_length) {
3513 buffer_append_long(b, c->request_content_queue->bytes_in);
3514 - BUFFER_APPEND_STRING_CONST(b, "/");
3515 + buffer_append_string_len(b, CONST_STR_LEN("/"));
3516 buffer_append_long(b, c->request.content_length);
3518 - BUFFER_APPEND_STRING_CONST(b, "0/0");
3519 + buffer_append_string_len(b, CONST_STR_LEN("0/0"));
3522 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
3523 + buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
3525 buffer_append_off_t(b, chunkqueue_written(c->write_queue));
3526 - BUFFER_APPEND_STRING_CONST(b, "/");
3527 + buffer_append_string_len(b, CONST_STR_LEN("/"));
3528 buffer_append_off_t(b, chunkqueue_length(c->write_queue));
3530 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
3531 + buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
3533 buffer_append_string(b, connection_get_state(c->state));
3535 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
3536 + buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
3538 buffer_append_long(b, srv->cur_ts - c->request_start);
3540 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
3541 + buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
3543 if (buffer_is_empty(c->server_name)) {
3544 buffer_append_string_buffer(b, c->uri.authority);
3545 @@ -515,38 +511,38 @@
3546 buffer_append_string_buffer(b, c->server_name);
3549 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
3550 + buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
3552 if (!buffer_is_empty(c->uri.path)) {
3553 buffer_append_string_encoded(b, CONST_BUF_LEN(c->uri.path), ENCODING_HTML);
3556 if (!buffer_is_empty(c->uri.query)) {
3557 - BUFFER_APPEND_STRING_CONST(b, "?");
3558 + buffer_append_string_len(b, CONST_STR_LEN("?"));
3559 buffer_append_string_encoded(b, CONST_BUF_LEN(c->uri.query), ENCODING_HTML);
3562 if (!buffer_is_empty(c->request.orig_uri)) {
3563 - BUFFER_APPEND_STRING_CONST(b, " (");
3564 + buffer_append_string_len(b, CONST_STR_LEN(" ("));
3565 buffer_append_string_encoded(b, CONST_BUF_LEN(c->request.orig_uri), ENCODING_HTML);
3566 - BUFFER_APPEND_STRING_CONST(b, ")");
3567 + buffer_append_string_len(b, CONST_STR_LEN(")"));
3569 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
3570 + buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
3572 buffer_append_string_buffer(b, c->physical.path);
3574 - BUFFER_APPEND_STRING_CONST(b, "</td></tr>\n");
3575 + buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
3579 - BUFFER_APPEND_STRING_CONST(b,
3581 + buffer_append_string_len(b, CONST_STR_LEN(
3585 - BUFFER_APPEND_STRING_CONST(b,
3586 + buffer_append_string_len(b, CONST_STR_LEN(
3592 response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
3594 @@ -566,45 +562,45 @@
3595 b = chunkqueue_get_append_buffer(con->write_queue);
3597 /* output total number of requests */
3598 - BUFFER_APPEND_STRING_CONST(b, "Total Accesses: ");
3599 + buffer_append_string_len(b, CONST_STR_LEN("Total Accesses: "));
3600 avg = p->abs_requests;
3601 snprintf(buf, sizeof(buf) - 1, "%.0f", avg);
3602 buffer_append_string(b, buf);
3603 - BUFFER_APPEND_STRING_CONST(b, "\n");
3604 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
3606 /* output total traffic out in kbytes */
3607 - BUFFER_APPEND_STRING_CONST(b, "Total kBytes: ");
3608 + buffer_append_string_len(b, CONST_STR_LEN("Total kBytes: "));
3609 avg = p->abs_traffic_out / 1024;
3610 snprintf(buf, sizeof(buf) - 1, "%.0f", avg);
3611 buffer_append_string(b, buf);
3612 - BUFFER_APPEND_STRING_CONST(b, "\n");
3613 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
3616 - BUFFER_APPEND_STRING_CONST(b, "Uptime: ");
3617 + buffer_append_string_len(b, CONST_STR_LEN("Uptime: "));
3618 ts = srv->cur_ts - srv->startup_ts;
3619 buffer_append_long(b, ts);
3620 - BUFFER_APPEND_STRING_CONST(b, "\n");
3621 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
3623 /* output busy servers */
3624 - BUFFER_APPEND_STRING_CONST(b, "BusyServers: ");
3625 + buffer_append_string_len(b, CONST_STR_LEN("BusyServers: "));
3626 buffer_append_long(b, srv->conns->used);
3627 - BUFFER_APPEND_STRING_CONST(b, "\n");
3628 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
3630 - BUFFER_APPEND_STRING_CONST(b, "IdleServers: ");
3631 + buffer_append_string_len(b, CONST_STR_LEN("IdleServers: "));
3632 buffer_append_long(b, srv->conns->size - srv->conns->used);
3633 - BUFFER_APPEND_STRING_CONST(b, "\n");
3634 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
3636 /* output scoreboard */
3637 - BUFFER_APPEND_STRING_CONST(b, "Scoreboard: ");
3638 + buffer_append_string_len(b, CONST_STR_LEN("Scoreboard: "));
3639 for (k = 0; k < srv->conns->used; k++) {
3640 connection *c = srv->conns->ptr[k];
3641 const char *state = connection_get_short_state(c->state);
3642 buffer_append_string_len(b, state, 1);
3644 for (l = 0; l < srv->conns->size - srv->conns->used; l++) {
3645 - BUFFER_APPEND_STRING_CONST(b, "_");
3646 + buffer_append_string_len(b, CONST_STR_LEN("_"));
3648 - BUFFER_APPEND_STRING_CONST(b, "\n");
3649 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
3651 /* set text/plain output */
3654 size_t ndx = st->sorted[i];
3656 buffer_append_string_buffer(b, st->data[ndx]->key);
3657 - buffer_append_string(b, ": ");
3658 + buffer_append_string_len(b, CONST_STR_LEN(": "));
3659 buffer_append_long(b, ((data_integer *)(st->data[ndx]))->value);
3660 - buffer_append_string(b, "\n");
3661 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
3664 response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain"));
3667 b = chunkqueue_get_append_buffer(con->write_queue);
3669 - BUFFER_COPY_STRING_CONST(b,
3670 + buffer_copy_string_len(b, CONST_STR_LEN(
3671 "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
3672 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
3673 " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
3677 " <h1>" PACKAGE_NAME " " PACKAGE_VERSION "</h1>\n"
3678 - " <table summary=\"status\" border=\"1\">\n");
3679 + " <table summary=\"status\" border=\"1\">\n"));
3681 mod_status_header_append(b, "Server-Features");
3683 @@ -733,19 +729,19 @@
3685 buffer_copy_string_buffer(m, pl->name);
3687 - BUFFER_APPEND_STRING_CONST(m, "<br />");
3688 + buffer_append_string_len(m, CONST_STR_LEN("<br />"));
3689 buffer_append_string_buffer(m, pl->name);
3693 mod_status_row_append(b, "Loaded Modules", m->ptr);
3695 - BUFFER_APPEND_STRING_CONST(b, " </table>\n");
3696 + buffer_append_string_len(b, CONST_STR_LEN(" </table>\n"));
3698 - BUFFER_APPEND_STRING_CONST(b,
3699 + buffer_append_string_len(b, CONST_STR_LEN(
3705 response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
3708 static handler_t mod_status_handler(server *srv, connection *con, void *p_d) {
3709 plugin_data *p = p_d;
3711 + if (con->mode != DIRECT) return HANDLER_GO_ON;
3713 mod_status_patch_connection(srv, con, p);
3715 if (!buffer_is_empty(p->conf.status_url) &&
3717 ===================================================================
3718 --- src/md5.c (.../tags/lighttpd-1.4.19) (revision 2303)
3719 +++ src/md5.c (.../branches/lighttpd-1.4.x) (revision 2303)
3724 -static void MD5Transform (UINT4 [4], unsigned char [64]);
3725 +static void MD5Transform (UINT4 [4], const unsigned char [64]);
3726 static void Encode (unsigned char *, UINT4 *, unsigned int);
3727 -static void Decode (UINT4 *, unsigned char *, unsigned int);
3728 +static void Decode (UINT4 *, const unsigned char *, unsigned int);
3731 #define MD5_memcpy(output, input, len) memcpy((output), (input), (len))
3732 @@ -126,12 +126,13 @@
3733 operation, processing another message block, and updating the
3736 -void MD5_Update (context, input, inputLen)
3737 +void MD5_Update (context, _input, inputLen)
3738 MD5_CTX *context; /* context */
3739 -unsigned char *input; /* input block */
3740 +const void *_input; /* input block */
3741 unsigned int inputLen; /* length of input block */
3743 unsigned int i, ndx, partLen;
3744 + const unsigned char *input = (const unsigned char*) _input;
3746 /* Compute number of bytes mod 64 */
3747 ndx = (unsigned int)((context->count[0] >> 3) & 0x3F);
3750 static void MD5Transform (state, block)
3752 -unsigned char block[64];
3753 +const unsigned char block[64];
3755 UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
3759 static void Decode (output, input, len)
3761 -unsigned char *input;
3762 +const unsigned char *input;
3766 Index: src/mod_compress.c
3767 ===================================================================
3768 --- src/mod_compress.c (.../tags/lighttpd-1.4.19) (revision 2303)
3769 +++ src/mod_compress.c (.../branches/lighttpd-1.4.x) (revision 2303)
3771 return HANDLER_GO_ON;
3774 -// 0 on success, -1 for error
3775 +/* 0 on success, -1 for error */
3776 int mkdir_recursive(char *dir) {
3779 @@ -118,13 +118,13 @@
3783 - if (!*p) return 0; // Ignore trailing slash
3784 + if (!*p) return 0; /* Ignore trailing slash */
3787 return (mkdir(dir, 0700) != 0) && (errno != EEXIST) ? -1 : 0;
3790 -// 0 on success, -1 for error
3791 +/* 0 on success, -1 for error */
3792 int mkdir_for_file(char *filename) {
3799 - if (!*p) return -1; // Unexpected trailing slash in filename
3800 + if (!*p) return -1; /* Unexpected trailing slash in filename */
3807 if (!buffer_is_empty(s->compress_cache_dir)) {
3809 mkdir_recursive(s->compress_cache_dir->ptr);
3812 if (0 != stat(s->compress_cache_dir->ptr, &st)) {
3813 log_error_write(srv, __FILE__, __LINE__, "sbs", "can't stat compress.cache-dir",
3814 s->compress_cache_dir, strerror(errno));
3815 @@ -396,13 +396,13 @@
3818 case HTTP_ACCEPT_ENCODING_GZIP:
3819 - buffer_append_string(p->ofn, "-gzip-");
3820 + buffer_append_string_len(p->ofn, CONST_STR_LEN("-gzip-"));
3822 case HTTP_ACCEPT_ENCODING_DEFLATE:
3823 - buffer_append_string(p->ofn, "-deflate-");
3824 + buffer_append_string_len(p->ofn, CONST_STR_LEN("-deflate-"));
3826 case HTTP_ACCEPT_ENCODING_BZIP2:
3827 - buffer_append_string(p->ofn, "-bzip2-");
3828 + buffer_append_string_len(p->ofn, CONST_STR_LEN("-bzip2-"));
3831 log_error_write(srv, __FILE__, __LINE__, "sd", "unknown compression type", type);
3833 ===================================================================
3834 --- src/md5.h (.../tags/lighttpd-1.4.19) (revision 2303)
3835 +++ src/md5.h (.../branches/lighttpd-1.4.x) (revision 2303)
3839 void MD5_Init (MD5_CTX *);
3840 -void MD5_Update (MD5_CTX *, unsigned char *, unsigned int);
3841 +void MD5_Update (MD5_CTX *, const void *, unsigned int);
3842 void MD5_Final (unsigned char [16], MD5_CTX *);
3844 Index: src/mod_ssi.c
3845 ===================================================================
3846 --- src/mod_ssi.c (.../tags/lighttpd-1.4.19) (revision 2303)
3847 +++ src/mod_ssi.c (.../branches/lighttpd-1.4.x) (revision 2303)
3851 if (0 != strcasecmp(ds->key->ptr, "CONTENT-TYPE")) {
3852 - buffer_copy_string(srv->tmp_buf, "HTTP_");
3853 + buffer_copy_string_len(srv->tmp_buf, CONST_STR_LEN("HTTP_"));
3854 srv->tmp_buf->used--;
3859 b = chunkqueue_get_append_buffer(con->write_queue);
3860 if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) {
3861 - buffer_copy_string(b, "(none)");
3862 + buffer_copy_string_len(b, CONST_STR_LEN("(none)"));
3864 buffer_copy_string(b, buf);
3868 b = chunkqueue_get_append_buffer(con->write_queue);
3869 if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) {
3870 - buffer_copy_string(b, "(none)");
3871 + buffer_copy_string_len(b, CONST_STR_LEN("(none)"));
3873 buffer_copy_string(b, buf);
3877 b = chunkqueue_get_append_buffer(con->write_queue);
3878 if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, gmtime(&t))) {
3879 - buffer_copy_string(b, "(none)");
3880 + buffer_copy_string_len(b, CONST_STR_LEN("(none)"));
3882 buffer_copy_string(b, buf);
3885 if (NULL != (ds = (data_string *)array_get_element(p->ssi_cgi_env, var_val))) {
3886 buffer_copy_string_buffer(b, ds->value);
3888 - buffer_copy_string(b, "(none)");
3889 + buffer_copy_string_len(b, CONST_STR_LEN("(none)"));
3895 /* current doc-root */
3896 if (NULL == (sl = strrchr(con->physical.path->ptr, '/'))) {
3897 - buffer_copy_string(p->stat_fn, "/");
3898 + buffer_copy_string_len(p->stat_fn, CONST_STR_LEN("/"));
3900 buffer_copy_string_len(p->stat_fn, con->physical.path->ptr, sl - con->physical.path->ptr + 1);
3904 b = chunkqueue_get_append_buffer(con->write_queue);
3905 if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) {
3906 - buffer_copy_string(b, "(none)");
3907 + buffer_copy_string_len(b, CONST_STR_LEN("(none)"));
3909 buffer_copy_string(b, buf);
3911 @@ -656,17 +656,17 @@
3912 if (p->if_is_false) break;
3914 b = chunkqueue_get_append_buffer(con->write_queue);
3915 - buffer_copy_string(b, "<pre>");
3916 + buffer_copy_string_len(b, CONST_STR_LEN("<pre>"));
3917 for (i = 0; i < p->ssi_vars->used; i++) {
3918 data_string *ds = (data_string *)p->ssi_vars->data[p->ssi_vars->sorted[i]];
3920 buffer_append_string_buffer(b, ds->key);
3921 - buffer_append_string(b, ": ");
3922 + buffer_append_string_len(b, CONST_STR_LEN(": "));
3923 buffer_append_string_buffer(b, ds->value);
3924 - buffer_append_string(b, "<br />");
3925 + buffer_append_string_len(b, CONST_STR_LEN("<br />"));
3928 - buffer_append_string(b, "</pre>");
3929 + buffer_append_string_len(b, CONST_STR_LEN("</pre>"));
3935 array_reset(p->ssi_vars);
3936 array_reset(p->ssi_cgi_env);
3937 - buffer_copy_string(p->timefmt, "%a, %d %b %Y %H:%M:%S %Z");
3938 + buffer_copy_string_len(p->timefmt, CONST_STR_LEN("%a, %d %b %Y %H:%M:%S %Z"));
3940 build_ssi_cgi_vars(srv, con, p);
3942 @@ -1027,6 +1027,7 @@
3944 con->file_started = 1;
3945 con->file_finished = 1;
3946 + con->mode = p->id;
3948 response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
3950 @@ -1094,6 +1095,8 @@
3951 plugin_data *p = p_d;
3954 + if (con->mode != DIRECT) return HANDLER_GO_ON;
3956 if (con->physical.path->used == 0) return HANDLER_GO_ON;
3958 mod_ssi_patch_connection(srv, con, p);
3959 @@ -1109,6 +1112,7 @@
3960 if (mod_ssi_handle_request(srv, con, p)) {
3962 con->http_status = 500;
3963 + con->mode = DIRECT;
3966 return HANDLER_FINISHED;
3967 Index: src/spawn-fcgi.c
3968 ===================================================================
3969 --- src/spawn-fcgi.c (.../tags/lighttpd-1.4.19) (revision 2303)
3970 +++ src/spawn-fcgi.c (.../branches/lighttpd-1.4.x) (revision 2303)
3974 #ifdef HAVE_SYS_UN_H
3975 -int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned short port, const char *unixsocket, int child_count, int pid_fd, int nofork) {
3976 +int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned short port, const char *unixsocket, int fork_count, int child_count, int pid_fd, int nofork) {
3978 - int socket_type, status;
3979 + int socket_type, status, rc = 0;
3980 struct timeval tv = { 0, 100 * 1000 };
3982 struct sockaddr_un fcgi_addr_un;
3990 if (child_count < 2) {
3995 socket_type = AF_UNIX;
3996 fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
3998 - /* check if some backend is listening on the socket
3999 - * as if we delete the socket-file and rebind there will be no "socket already in use" error
4001 - if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
4002 - fprintf(stderr, "%s.%d\n",
4003 - __FILE__, __LINE__);
4007 - if (-1 != connect(fcgi_fd, fcgi_addr, servlen)) {
4008 - fprintf(stderr, "%s.%d: socket is already used, can't spawn\n",
4009 - __FILE__, __LINE__);
4013 - /* cleanup previous socket if it exists */
4014 - unlink(unixsocket);
4017 fcgi_addr_in.sin_family = AF_INET;
4019 @@ -107,133 +85,176 @@
4020 fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
4024 if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
4025 fprintf(stderr, "%s.%d\n",
4026 __FILE__, __LINE__);
4031 - if (setsockopt(fcgi_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
4032 - fprintf(stderr, "%s.%d\n",
4033 - __FILE__, __LINE__);
4036 + if (-1 == connect(fcgi_fd, fcgi_addr, servlen)) {
4037 + /* server is not up, spawn in */
4041 - /* create socket */
4042 - if (-1 == bind(fcgi_fd, fcgi_addr, servlen)) {
4043 - fprintf(stderr, "%s.%d: bind failed: %s\n",
4044 - __FILE__, __LINE__,
4048 + if (unixsocket) unlink(unixsocket);
4050 - if (-1 == listen(fcgi_fd, 1024)) {
4051 - fprintf(stderr, "%s.%d: fd = -1\n",
4052 - __FILE__, __LINE__);
4062 + /* reopen socket */
4063 + if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
4064 + fprintf(stderr, "%s.%d\n",
4065 + __FILE__, __LINE__);
4071 - char cgi_childs[64];
4073 + if (setsockopt(fcgi_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
4074 + fprintf(stderr, "%s.%d\n",
4075 + __FILE__, __LINE__);
4081 - /* is safe as we limit to 256 childs */
4082 - sprintf(cgi_childs, "PHP_FCGI_CHILDREN=%d", child_count);
4084 - if(fcgi_fd != FCGI_LISTENSOCK_FILENO) {
4085 - close(FCGI_LISTENSOCK_FILENO);
4086 - dup2(fcgi_fd, FCGI_LISTENSOCK_FILENO);
4088 + /* create socket */
4089 + if (-1 == bind(fcgi_fd, fcgi_addr, servlen)) {
4090 + fprintf(stderr, "%s.%d: bind failed: %s\n",
4091 + __FILE__, __LINE__,
4096 - /* we don't need the client socket */
4097 - for (i = 3; i < 256; i++) {
4099 + if (-1 == listen(fcgi_fd, 1024)) {
4100 + fprintf(stderr, "%s.%d: fd = -1\n",
4101 + __FILE__, __LINE__);
4105 - /* create environment */
4106 + while (fork_count-- > 0) {
4108 - putenv(cgi_childs);
4115 - /* fork and replace shell */
4117 - execv(appArgv[0], appArgv);
4120 + char cgi_childs[64];
4124 - char *b = malloc(strlen("exec ") + strlen(appPath) + 1);
4125 - strcpy(b, "exec ");
4126 - strcat(b, appPath);
4129 - /* exec the cgi */
4130 - execl("/bin/sh", "sh", "-c", b, (char *)NULL);
4132 + /* loose control terminal */
4136 + /* is safe as we limit to 256 childs */
4137 + sprintf(cgi_childs, "PHP_FCGI_CHILDREN=%d", child_count);
4146 + if(fcgi_fd != FCGI_LISTENSOCK_FILENO) {
4147 + close(FCGI_LISTENSOCK_FILENO);
4148 + dup2(fcgi_fd, FCGI_LISTENSOCK_FILENO);
4153 - select(0, NULL, NULL, NULL, &tv);
4154 + max_fd = open("/dev/null", O_RDWR);
4155 + close(STDERR_FILENO);
4156 + dup2(max_fd, STDERR_FILENO);
4159 - switch (waitpid(child, &status, WNOHANG)) {
4161 - fprintf(stderr, "%s.%d: child spawned successfully: PID: %d\n",
4162 - __FILE__, __LINE__,
4164 + max_fd = open("/dev/null", O_RDWR);
4165 + close(STDOUT_FILENO);
4166 + dup2(max_fd, STDOUT_FILENO);
4169 - /* write pid file */
4170 - if (pid_fd != -1) {
4171 - /* assume a 32bit pid_t */
4173 + /* we don't need the client socket */
4174 + for (i = 3; i < max_fd; i++) {
4175 + if (i != FCGI_LISTENSOCK_FILENO) close(i);
4178 - snprintf(pidbuf, sizeof(pidbuf) - 1, "%d", child);
4179 + /* create environment */
4181 - write(pid_fd, pidbuf, strlen(pidbuf));
4184 + putenv(cgi_childs);
4186 + /* fork and replace shell */
4188 + execv(appArgv[0], appArgv);
4191 + char *b = malloc(strlen("exec ") + strlen(appPath) + 1);
4192 + strcpy(b, "exec ");
4193 + strcat(b, appPath);
4195 + /* exec the cgi */
4196 + execl("/bin/sh", "sh", "-c", b, (char *)NULL);
4213 - if (WIFEXITED(status)) {
4214 - fprintf(stderr, "%s.%d: child exited with: %d, %s\n",
4215 - __FILE__, __LINE__,
4216 - WEXITSTATUS(status), strerror(WEXITSTATUS(status)));
4217 - } else if (WIFSIGNALED(status)) {
4218 - fprintf(stderr, "%s.%d: child signaled: %d\n",
4219 - __FILE__, __LINE__,
4220 - WTERMSIG(status));
4222 - fprintf(stderr, "%s.%d: child died somehow: %d\n",
4223 - __FILE__, __LINE__,
4226 + select(0, NULL, NULL, NULL, &tv);
4228 + switch (waitpid(child, &status, WNOHANG)) {
4230 + fprintf(stdout, "%s.%d: child spawned successfully: PID: %d\n",
4231 + __FILE__, __LINE__,
4234 + /* write pid file */
4235 + if (pid_fd != -1) {
4236 + /* assume a 32bit pid_t */
4239 + snprintf(pidbuf, sizeof(pidbuf) - 1, "%d", child);
4241 + write(pid_fd, pidbuf, strlen(pidbuf));
4242 + /* avoid eol for the last one */
4243 + if (fork_count != 0) {
4244 + write(pid_fd, "\n", 1);
4252 + if (WIFEXITED(status)) {
4253 + fprintf(stderr, "%s.%d: child exited with: %d\n",
4254 + __FILE__, __LINE__, WEXITSTATUS(status));
4255 + rc = WEXITSTATUS(status);
4256 + } else if (WIFSIGNALED(status)) {
4257 + fprintf(stderr, "%s.%d: child signaled: %d\n",
4258 + __FILE__, __LINE__,
4259 + WTERMSIG(status));
4262 + fprintf(stderr, "%s.%d: child died somehow: %d\n",
4263 + __FILE__, __LINE__,
4277 + fprintf(stderr, "%s.%d: socket is already used, can't spawn\n",
4278 + __FILE__, __LINE__);
4290 " -p <port> bind to tcp-port\n" \
4291 " -s <path> bind to unix-domain socket\n" \
4292 " -C <childs> (PHP only) numbers of childs to spawn (default 5)\n" \
4293 +" -F <childs> numbers of childs to fork (default 1)\n" \
4294 " -P <path> name of PID-file for spawed process\n" \
4295 " -n no fork (for daemontools)\n" \
4296 " -v show version\n" \
4297 @@ -276,20 +298,21 @@
4298 char **fcgi_app_argv = { NULL };
4299 unsigned short port = 0;
4300 int child_count = 5;
4301 + int fork_count = 1;
4305 struct sockaddr_un un;
4306 - const size_t sun_path_len = sizeof(un.sun_path);
4308 i_am_root = (getuid() == 0);
4310 - while(-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:s:P:"))) {
4311 + while (-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:F:s:P:"))) {
4313 case 'f': fcgi_app = optarg; break;
4314 case 'a': addr = optarg;/* ip addr */ break;
4315 case 'p': port = strtol(optarg, NULL, 10);/* port */ break;
4316 case 'C': child_count = strtol(optarg, NULL, 10);/* */ break;
4317 + case 'F': fork_count = strtol(optarg, NULL, 10);/* */ break;
4318 case 's': unixsocket = optarg; /* unix-domain socket */ break;
4319 case 'c': if (i_am_root) { changeroot = optarg; }/* chroot() */ break;
4320 case 'u': if (i_am_root) { username = optarg; } /* set user */ break;
4325 - if (unixsocket && strlen(unixsocket) > sun_path_len - 1) {
4326 + if (unixsocket && strlen(unixsocket) > sizeof(un.sun_path) - 1) {
4327 fprintf(stderr, "%s.%d: %s\n",
4329 "path of the unix socket is too long\n");
4330 @@ -416,18 +439,15 @@
4331 "I will not set gid to 0\n");
4337 - * Change group before chroot, when we have access
4341 + /* do the change before we do the chroot() */
4342 setgid(grp->gr_gid);
4343 - setgroups(0, NULL);
4344 + setgroups(0, NULL);
4347 initgroups(username, grp->gr_gid);
4357 - return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, addr, port, unixsocket, child_count, pid_fd, nofork);
4358 + return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, addr, port, unixsocket, fork_count, child_count, pid_fd, nofork);
4362 Index: src/mod_auth.c
4363 ===================================================================
4364 --- src/mod_auth.c (.../tags/lighttpd-1.4.19) (revision 2303)
4365 +++ src/mod_auth.c (.../branches/lighttpd-1.4.x) (revision 2303)
4366 @@ -150,13 +150,15 @@
4367 PATCH(auth_ldap_hostname);
4370 - PATCH(ldap_filter_pre);
4371 - PATCH(ldap_filter_post);
4373 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.base-dn"))) {
4374 PATCH(auth_ldap_basedn);
4375 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.filter"))) {
4376 PATCH(auth_ldap_filter);
4378 + PATCH(ldap_filter_pre);
4379 + PATCH(ldap_filter_post);
4381 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.ca-file"))) {
4382 PATCH(auth_ldap_cafile);
4383 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.starttls"))) {
4385 if (0 == strcmp(method->value->ptr, "digest")) {
4386 if (-1 == (auth_satisfied = http_auth_digest_check(srv, con, p, req, con->uri.path, auth_realm+1))) {
4387 con->http_status = 400;
4388 + con->mode = DIRECT;
4390 /* a field was missing */
4392 @@ -268,22 +271,23 @@
4393 realm = (data_string *)array_get_element(req, "realm");
4395 con->http_status = 401;
4396 + con->mode = DIRECT;
4398 if (0 == strcmp(method->value->ptr, "basic")) {
4399 - buffer_copy_string(p->tmp_buf, "Basic realm=\"");
4400 + buffer_copy_string_len(p->tmp_buf, CONST_STR_LEN("Basic realm=\""));
4401 buffer_append_string_buffer(p->tmp_buf, realm->value);
4402 - buffer_append_string(p->tmp_buf, "\"");
4403 + buffer_append_string_len(p->tmp_buf, CONST_STR_LEN("\""));
4405 response_header_insert(srv, con, CONST_STR_LEN("WWW-Authenticate"), CONST_BUF_LEN(p->tmp_buf));
4406 } else if (0 == strcmp(method->value->ptr, "digest")) {
4408 http_auth_digest_generate_nonce(srv, p, srv->tmp_buf, hh);
4410 - buffer_copy_string(p->tmp_buf, "Digest realm=\"");
4411 + buffer_copy_string_len(p->tmp_buf, CONST_STR_LEN("Digest realm=\""));
4412 buffer_append_string_buffer(p->tmp_buf, realm->value);
4413 - buffer_append_string(p->tmp_buf, "\", nonce=\"");
4414 + buffer_append_string_len(p->tmp_buf, CONST_STR_LEN("\", nonce=\""));
4415 buffer_append_string(p->tmp_buf, hh);
4416 - buffer_append_string(p->tmp_buf, "\", qop=\"auth\"");
4417 + buffer_append_string_len(p->tmp_buf, CONST_STR_LEN("\", qop=\"auth\""));
4419 response_header_insert(srv, con, CONST_STR_LEN("WWW-Authenticate"), CONST_BUF_LEN(p->tmp_buf));
4421 @@ -393,6 +397,23 @@
4426 + if (s->auth_ldap_filter->used) {
4429 + /* parse filter */
4431 + if (NULL == (dollar = strchr(s->auth_ldap_filter->ptr, '$'))) {
4432 + log_error_write(srv, __FILE__, __LINE__, "s", "ldap: auth.backend.ldap.filter is missing a replace-operator '$'");
4434 + return HANDLER_ERROR;
4437 + buffer_copy_string_len(s->ldap_filter_pre, s->auth_ldap_filter->ptr, dollar - s->auth_ldap_filter->ptr);
4438 + buffer_copy_string(s->ldap_filter_post, dollar+1);
4442 /* no auth.require for this section */
4443 if (NULL == (da = (data_array *)array_get_element(ca, "auth.require"))) continue;
4445 @@ -479,21 +500,21 @@
4447 ds = data_string_init();
4449 - buffer_copy_string(ds->key, "method");
4450 + buffer_copy_string_len(ds->key, CONST_STR_LEN("method"));
4451 buffer_copy_string(ds->value, method);
4453 array_insert_unique(a->value, (data_unset *)ds);
4455 ds = data_string_init();
4457 - buffer_copy_string(ds->key, "realm");
4458 + buffer_copy_string_len(ds->key, CONST_STR_LEN("realm"));
4459 buffer_copy_string(ds->value, realm);
4461 array_insert_unique(a->value, (data_unset *)ds);
4463 ds = data_string_init();
4465 - buffer_copy_string(ds->key, "require");
4466 + buffer_copy_string_len(ds->key, CONST_STR_LEN("require"));
4467 buffer_copy_string(ds->value, require);
4469 array_insert_unique(a->value, (data_unset *)ds);
4470 @@ -507,97 +528,83 @@
4471 handler_t ret = auth_ldap_init(srv, s);
4472 if (ret == HANDLER_ERROR)
4486 - return HANDLER_GO_ON;
4487 + return HANDLER_GO_ON;
4490 handler_t auth_ldap_init(server *srv, mod_auth_plugin_config *s) {
4495 - if (s->auth_ldap_basedn->used == 0) {
4496 - log_error_write(srv, __FILE__, __LINE__, "s", "ldap: auth.backend.ldap.base-dn has to be set");
4497 + if (s->auth_ldap_basedn->used == 0) {
4498 + log_error_write(srv, __FILE__, __LINE__, "s", "ldap: auth.backend.ldap.base-dn has to be set");
4500 - return HANDLER_ERROR;
4502 + return HANDLER_ERROR;
4506 - if (s->auth_ldap_filter->used) {
4508 + if (s->auth_ldap_hostname->used) {
4509 + if (NULL == (s->ldap = ldap_init(s->auth_ldap_hostname->ptr, LDAP_PORT))) {
4510 + log_error_write(srv, __FILE__, __LINE__, "ss", "ldap ...", strerror(errno));
4512 - /* parse filter */
4513 + return HANDLER_ERROR;
4516 - if (NULL == (dollar = strchr(s->auth_ldap_filter->ptr, '$'))) {
4517 - log_error_write(srv, __FILE__, __LINE__, "s", "ldap: auth.backend.ldap.filter is missing a replace-operator '$'");
4518 + ret = LDAP_VERSION3;
4519 + if (LDAP_OPT_SUCCESS != (ret = ldap_set_option(s->ldap, LDAP_OPT_PROTOCOL_VERSION, &ret))) {
4520 + log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
4522 - return HANDLER_ERROR;
4524 + return HANDLER_ERROR;
4527 - buffer_copy_string_len(s->ldap_filter_pre, s->auth_ldap_filter->ptr, dollar - s->auth_ldap_filter->ptr);
4528 - buffer_copy_string(s->ldap_filter_post, dollar+1);
4530 + if (s->auth_ldap_starttls) {
4531 + /* if no CA file is given, it is ok, as we will use encryption
4532 + * if the server requires a CAfile it will tell us */
4533 + if (!buffer_is_empty(s->auth_ldap_cafile)) {
4534 + if (LDAP_OPT_SUCCESS != (ret = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE,
4535 + s->auth_ldap_cafile->ptr))) {
4536 + log_error_write(srv, __FILE__, __LINE__, "ss",
4537 + "Loading CA certificate failed:", ldap_err2string(ret));
4539 - if (s->auth_ldap_hostname->used) {
4540 - if (NULL == (s->ldap = ldap_init(s->auth_ldap_hostname->ptr, LDAP_PORT))) {
4541 - log_error_write(srv, __FILE__, __LINE__, "ss", "ldap ...", strerror(errno));
4543 return HANDLER_ERROR;
4547 - ret = LDAP_VERSION3;
4548 - if (LDAP_OPT_SUCCESS != (ret = ldap_set_option(s->ldap, LDAP_OPT_PROTOCOL_VERSION, &ret))) {
4549 - log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
4550 + if (LDAP_OPT_SUCCESS != (ret = ldap_start_tls_s(s->ldap, NULL, NULL))) {
4551 + log_error_write(srv, __FILE__, __LINE__, "ss", "ldap startTLS failed:", ldap_err2string(ret));
4553 - return HANDLER_ERROR;
4555 + return HANDLER_ERROR;
4559 - if (s->auth_ldap_starttls) {
4560 - /* if no CA file is given, it is ok, as we will use encryption
4561 - * if the server requires a CAfile it will tell us */
4562 - if (!buffer_is_empty(s->auth_ldap_cafile)) {
4563 - if (LDAP_OPT_SUCCESS != (ret = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE,
4564 - s->auth_ldap_cafile->ptr))) {
4565 - log_error_write(srv, __FILE__, __LINE__, "ss",
4566 - "Loading CA certificate failed:", ldap_err2string(ret));
4568 - return HANDLER_ERROR;
4572 + if (s->auth_ldap_binddn->used) {
4573 + if (LDAP_SUCCESS != (ret = ldap_simple_bind_s(s->ldap, s->auth_ldap_binddn->ptr, s->auth_ldap_bindpw->ptr))) {
4574 + log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
4576 - if (LDAP_OPT_SUCCESS != (ret = ldap_start_tls_s(s->ldap, NULL, NULL))) {
4577 - log_error_write(srv, __FILE__, __LINE__, "ss", "ldap startTLS failed:", ldap_err2string(ret));
4578 + return HANDLER_ERROR;
4581 + if (LDAP_SUCCESS != (ret = ldap_simple_bind_s(s->ldap, NULL, NULL))) {
4582 + log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
4584 - return HANDLER_ERROR;
4590 - if (s->auth_ldap_binddn->used) {
4591 - if (LDAP_SUCCESS != (ret = ldap_simple_bind_s(s->ldap, s->auth_ldap_binddn->ptr, s->auth_ldap_bindpw->ptr))) {
4592 - log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
4594 - return HANDLER_ERROR;
4597 - if (LDAP_SUCCESS != (ret = ldap_simple_bind_s(s->ldap, NULL, NULL))) {
4598 - log_error_write(srv, __FILE__, __LINE__, "ss", "ldap:", ldap_err2string(ret));
4600 - return HANDLER_ERROR;
4603 + return HANDLER_ERROR;
4607 + return HANDLER_GO_ON;
4609 - log_error_write(srv, __FILE__, __LINE__, "s", "no ldap support available");
4610 - return HANDLER_ERROR;
4612 + log_error_write(srv, __FILE__, __LINE__, "s", "no ldap support available");
4613 + return HANDLER_ERROR;
4615 - return HANDLER_GO_ON;
4618 int mod_auth_plugin_init(plugin *p) {
4619 Index: src/data_string.c
4620 ===================================================================
4621 --- src/data_string.c (.../tags/lighttpd-1.4.19) (revision 2303)
4622 +++ src/data_string.c (.../branches/lighttpd-1.4.x) (revision 2303)
4624 data_string *ds_src = (data_string *)src;
4626 if (ds_dst->value->used) {
4627 - buffer_append_string(ds_dst->value, ", ");
4628 + buffer_append_string_len(ds_dst->value, CONST_STR_LEN(", "));
4629 buffer_append_string_buffer(ds_dst->value, ds_src->value);
4631 buffer_copy_string_buffer(ds_dst->value, ds_src->value);
4633 data_string *ds_src = (data_string *)src;
4635 if (ds_dst->value->used) {
4636 - buffer_append_string(ds_dst->value, "\r\n");
4637 + buffer_append_string_len(ds_dst->value, CONST_STR_LEN("\r\n"));
4638 buffer_append_string_buffer(ds_dst->value, ds_dst->key);
4639 - buffer_append_string(ds_dst->value, ": ");
4640 + buffer_append_string_len(ds_dst->value, CONST_STR_LEN(": "));
4641 buffer_append_string_buffer(ds_dst->value, ds_src->value);
4643 buffer_copy_string_buffer(ds_dst->value, ds_src->value);
4644 Index: src/http-header-glue.c
4645 ===================================================================
4646 --- src/http-header-glue.c (.../tags/lighttpd-1.4.19) (revision 2303)
4647 +++ src/http-header-glue.c (.../branches/lighttpd-1.4.x) (revision 2303)
4651 if (con->conf.is_ssl) {
4652 - buffer_copy_string(o, "https://");
4653 + buffer_copy_string_len(o, CONST_STR_LEN("https://"));
4655 - buffer_copy_string(o, "http://");
4656 + buffer_copy_string_len(o, CONST_STR_LEN("http://"));
4658 if (con->uri.authority->used) {
4659 buffer_append_string_buffer(o, con->uri.authority);
4660 @@ -180,14 +180,14 @@
4662 if (!((con->conf.is_ssl == 0 && srv->srvconf.port == 80) ||
4663 (con->conf.is_ssl == 1 && srv->srvconf.port == 443))) {
4664 - buffer_append_string(o, ":");
4665 + buffer_append_string_len(o, CONST_STR_LEN(":"));
4666 buffer_append_long(o, srv->srvconf.port);
4669 buffer_append_string_buffer(o, con->uri.path);
4670 - buffer_append_string(o, "/");
4671 + buffer_append_string_len(o, CONST_STR_LEN("/"));
4672 if (!buffer_is_empty(con->uri.query)) {
4673 - buffer_append_string(o, "?");
4674 + buffer_append_string_len(o, CONST_STR_LEN("?"));
4675 buffer_append_string_buffer(o, con->uri.query);
4679 con->request.http_if_modified_since, used_len, sizeof(buf) - 1);
4681 con->http_status = 412;
4682 + con->mode = DIRECT;
4683 return HANDLER_FINISHED;
4688 if (NULL == strptime(buf, "%a, %d %b %Y %H:%M:%S GMT", &tm)) {
4689 con->http_status = 412;
4690 + con->mode = DIRECT;
4691 return HANDLER_FINISHED;
4693 t_header = mktime(&tm);
4697 con->http_status = 412;
4698 + con->mode = DIRECT;
4699 return HANDLER_FINISHED;
4702 Index: src/mod_evasive.c
4703 ===================================================================
4704 --- src/mod_evasive.c (.../tags/lighttpd-1.4.19) (revision 2303)
4705 +++ src/mod_evasive.c (.../branches/lighttpd-1.4.x) (revision 2303)
4706 @@ -138,24 +138,47 @@
4707 /* no limit set, nothing to block */
4708 if (p->conf.max_conns == 0) return HANDLER_GO_ON;
4710 + switch (con->dst_addr.plain.sa_family) {
4716 + default: // Address family not supported
4717 + return HANDLER_GO_ON;
4720 for (j = 0; j < srv->conns->used; j++) {
4721 connection *c = srv->conns->ptr[j];
4723 /* check if other connections are already actively serving data for the same IP
4724 * we can only ban connections which are already behind the 'read request' state
4726 - if (c->dst_addr.ipv4.sin_addr.s_addr == con->dst_addr.ipv4.sin_addr.s_addr &&
4727 - c->state > CON_STATE_REQUEST_END) {
4729 + if (c->dst_addr.plain.sa_family != con->dst_addr.plain.sa_family) continue;
4730 + if (c->state <= CON_STATE_REQUEST_END) continue;
4732 - if (conns_by_ip > p->conf.max_conns) {
4733 - log_error_write(srv, __FILE__, __LINE__, "ss",
4734 - inet_ntop_cache_get_ip(srv, &(con->dst_addr)),
4735 - "turned away. Too many connections.");
4736 + switch (con->dst_addr.plain.sa_family) {
4738 + if (c->dst_addr.ipv4.sin_addr.s_addr != con->dst_addr.ipv4.sin_addr.s_addr) continue;
4742 + if (0 != memcmp(c->dst_addr.ipv6.sin6_addr.s6_addr, con->dst_addr.ipv6.sin6_addr.s6_addr, 16)) continue;
4745 + default: /* Address family not supported, should never be reached */
4750 - con->http_status = 403;
4751 - return HANDLER_FINISHED;
4753 + if (conns_by_ip > p->conf.max_conns) {
4754 + log_error_write(srv, __FILE__, __LINE__, "ss",
4755 + inet_ntop_cache_get_ip(srv, &(con->dst_addr)),
4756 + "turned away. Too many connections.");
4758 + con->http_status = 403;
4759 + con->mode = DIRECT;
4760 + return HANDLER_FINISHED;
4764 Index: src/mod_indexfile.c
4765 ===================================================================
4766 --- src/mod_indexfile.c (.../tags/lighttpd-1.4.19) (revision 2303)
4767 +++ src/mod_indexfile.c (.../branches/lighttpd-1.4.x) (revision 2303)
4770 stat_cache_entry *sce = NULL;
4772 + if (con->mode != DIRECT) return HANDLER_GO_ON;
4774 if (con->uri.path->used == 0) return HANDLER_GO_ON;
4775 if (con->uri.path->ptr[con->uri.path->used - 2] != '/') return HANDLER_GO_ON;
4777 Index: src/mod_uploadprogress.c
4778 ===================================================================
4779 Index: src/mod_fastcgi.c
4780 ===================================================================
4781 --- src/mod_fastcgi.c (.../tags/lighttpd-1.4.19) (revision 2303)
4782 +++ src/mod_fastcgi.c (.../branches/lighttpd-1.4.x) (revision 2303)
4783 @@ -236,6 +236,16 @@
4784 unsigned short break_scriptfilename_for_php;
4787 + * workaround for program when prefix="/"
4789 + * rule to build PATH_INFO is hardcoded for when check_local is disabled
4790 + * enable this option to use the workaround
4794 + unsigned short fix_root_path_name;
4797 * If the backend includes X-LIGHTTPD-send-file in the response
4798 * we use the value as filename and ignore the content.
4800 @@ -380,10 +390,10 @@
4801 static handler_t fcgi_handle_fdevent(void *s, void *ctx, int revents);
4803 int fastcgi_status_copy_procname(buffer *b, fcgi_extension_host *host, fcgi_proc *proc) {
4804 - buffer_copy_string(b, "fastcgi.backend.");
4805 + buffer_copy_string_len(b, CONST_STR_LEN("fastcgi.backend."));
4806 buffer_append_string_buffer(b, host->id);
4808 - buffer_append_string(b, ".");
4809 + buffer_append_string_len(b, CONST_STR_LEN("."));
4810 buffer_append_long(b, proc->id);
4814 int fastcgi_status_init(server *srv, buffer *b, fcgi_extension_host *host, fcgi_proc *proc) {
4816 fastcgi_status_copy_procname(b, host, proc); \
4817 - buffer_append_string(b, x); \
4818 + buffer_append_string_len(b, CONST_STR_LEN(x)); \
4819 status_counter_set(srv, CONST_BUF_LEN(b), 0);
4825 fastcgi_status_copy_procname(b, host, NULL); \
4826 - buffer_append_string(b, x); \
4827 + buffer_append_string_len(b, CONST_STR_LEN(x)); \
4828 status_counter_set(srv, CONST_BUF_LEN(b), 0);
4833 static int env_add(char_array *env, const char *key, size_t key_len, const char *val, size_t val_len) {
4837 if (!key || !val) return -1;
4839 @@ -702,6 +713,15 @@
4840 /* add the \0 from the value */
4841 memcpy(dst + key_len + 1, val, val_len + 1);
4843 + for (i = 0; i < env->used; i++) {
4844 + if (0 == strncmp(dst, env->ptr[i], key_len + 1)) {
4845 + /* don't care about free as we are in a forked child which is going to exec(...) */
4846 + /* free(env->ptr[i]); */
4847 + env->ptr[i] = dst;
4852 if (env->size == 0) {
4854 env->ptr = malloc(env->size * sizeof(*env->ptr));
4856 socket_type = AF_UNIX;
4857 fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
4859 - buffer_copy_string(proc->connection_name, "unix:");
4860 + buffer_copy_string_len(proc->connection_name, CONST_STR_LEN("unix:"));
4861 buffer_append_string_buffer(proc->connection_name, proc->unixsocket);
4864 @@ -857,13 +877,13 @@
4865 socket_type = AF_INET;
4866 fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
4868 - buffer_copy_string(proc->connection_name, "tcp:");
4869 + buffer_copy_string_len(proc->connection_name, CONST_STR_LEN("tcp:"));
4870 if (!buffer_is_empty(host->host)) {
4871 buffer_append_string_buffer(proc->connection_name, host->host);
4873 - buffer_append_string(proc->connection_name, "localhost");
4874 + buffer_append_string_len(proc->connection_name, CONST_STR_LEN("localhost"));
4876 - buffer_append_string(proc->connection_name, ":");
4877 + buffer_append_string_len(proc->connection_name, CONST_STR_LEN(":"));
4878 buffer_append_long(proc->connection_name, proc->port);
4885 + openDevNull(STDERR_FILENO);
4887 /* we don't need the client socket */
4888 for (i = 3; i < 256; i++) {
4890 @@ -1000,8 +1022,8 @@
4892 execve(arg.ptr[0], arg.ptr, env.ptr);
4894 - log_error_write(srv, __FILE__, __LINE__, "sbs",
4895 - "execve failed for:", host->bin_path, strerror(errno));
4896 + /* log_error_write(srv, __FILE__, __LINE__, "sbs",
4897 + "execve failed for:", host->bin_path, strerror(errno)); */
4901 @@ -1193,6 +1215,7 @@
4902 { "allow-x-send-file", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 15 */
4903 { "strip-request-uri", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 16 */
4904 { "kill-signal", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 17 */
4905 + { "fix-root-scriptname", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 18 */
4907 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
4909 @@ -1220,6 +1243,7 @@
4910 host->break_scriptfilename_for_php = 0;
4911 host->allow_xsendfile = 0; /* handle X-LIGHTTPD-send-file */
4912 host->kill_signal = SIGTERM;
4913 + host->fix_root_path_name = 0;
4915 fcv[0].destination = host->host;
4916 fcv[1].destination = host->docroot;
4917 @@ -1241,6 +1265,7 @@
4918 fcv[15].destination = &(host->allow_xsendfile);
4919 fcv[16].destination = host->strip_request_uri;
4920 fcv[17].destination = &(host->kill_signal);
4921 + fcv[18].destination = &(host->fix_root_path_name);
4923 if (0 != config_insert_values_internal(srv, da_host->value, fcv)) {
4924 return HANDLER_ERROR;
4925 @@ -1324,7 +1349,7 @@
4926 proc->port = host->port + pno;
4928 buffer_copy_string_buffer(proc->unixsocket, host->unixsocket);
4929 - buffer_append_string(proc->unixsocket, "-");
4930 + buffer_append_string_len(proc->unixsocket, CONST_STR_LEN("-"));
4931 buffer_append_long(proc->unixsocket, pno);
4934 @@ -1482,7 +1507,7 @@
4935 status_counter_dec(srv, CONST_STR_LEN("fastcgi.active-requests"));
4937 fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
4938 - buffer_append_string(p->statuskey, ".load");
4939 + buffer_append_string_len(p->statuskey, CONST_STR_LEN(".load"));
4941 status_counter_set(srv, CONST_BUF_LEN(p->statuskey), hctx->proc->load);
4943 @@ -1683,7 +1708,7 @@
4945 if (buffer_is_empty(proc->connection_name)) {
4946 /* on remote spawing we have to set the connection-name now */
4947 - buffer_copy_string(proc->connection_name, "unix:");
4948 + buffer_copy_string_len(proc->connection_name, CONST_STR_LEN("unix:"));
4949 buffer_append_string_buffer(proc->connection_name, proc->unixsocket);
4952 @@ -1709,13 +1734,13 @@
4954 if (buffer_is_empty(proc->connection_name)) {
4955 /* on remote spawing we have to set the connection-name now */
4956 - buffer_copy_string(proc->connection_name, "tcp:");
4957 + buffer_copy_string_len(proc->connection_name, CONST_STR_LEN("tcp:"));
4958 if (!buffer_is_empty(host->host)) {
4959 buffer_append_string_buffer(proc->connection_name, host->host);
4961 - buffer_append_string(proc->connection_name, "localhost");
4962 + buffer_append_string_len(proc->connection_name, CONST_STR_LEN("localhost"));
4964 - buffer_append_string(proc->connection_name, ":");
4965 + buffer_append_string_len(proc->connection_name, CONST_STR_LEN(":"));
4966 buffer_append_long(proc->connection_name, proc->port);
4969 @@ -1771,7 +1796,7 @@
4970 buffer_reset(srv->tmp_buf);
4972 if (0 != strcasecmp(ds->key->ptr, "CONTENT-TYPE")) {
4973 - BUFFER_COPY_STRING_CONST(srv->tmp_buf, "HTTP_");
4974 + buffer_copy_string_len(srv->tmp_buf, CONST_STR_LEN("HTTP_"));
4975 srv->tmp_buf->used--;
4978 @@ -2026,7 +2051,7 @@
4980 if ('/' != host->strip_request_uri->ptr[host->strip_request_uri->used - 2]) {
4981 /* fix the user-input to have / as last char */
4982 - buffer_append_string(host->strip_request_uri, "/");
4983 + buffer_append_string_len(host->strip_request_uri, CONST_STR_LEN("/"));
4986 if (con->request.orig_uri->used >= host->strip_request_uri->used &&
4987 @@ -2094,12 +2119,12 @@
4988 hctx->wb->bytes_in += sizeof(header);
4990 if (p->conf.debug > 10) {
4991 - fprintf(stderr, "%s.%d: tosend: %lld / %lld\n", __FILE__, __LINE__, offset, req_cq->bytes_in);
4992 + log_error_write(srv, __FILE__, __LINE__, "soso", "tosend:", offset, "/", req_cq->bytes_in);
4995 for (written = 0; written != weWant; ) {
4996 if (p->conf.debug > 10) {
4997 - fprintf(stderr, "%s.%d: chunk: %lld / %lld\n", __FILE__, __LINE__, written, weWant);
4998 + log_error_write(srv, __FILE__, __LINE__, "soso", "chunk:", written, "/", weWant);
5001 switch (req_c->type) {
5002 @@ -2109,12 +2134,10 @@
5003 if (weHave > weWant - written) weHave = weWant - written;
5005 if (p->conf.debug > 10) {
5006 - fprintf(stderr, "%s.%d: sending %lld bytes from (%lld / %lld) %s\n",
5007 - __FILE__, __LINE__,
5010 - req_c->file.length,
5011 - req_c->file.name->ptr);
5012 + log_error_write(srv, __FILE__, __LINE__, "soSosOsb",
5013 + "sending", weHave, "bytes from (",
5014 + req_c->offset, "/", req_c->file.length, ")",
5015 + req_c->file.name);
5018 assert(weHave != 0);
5019 @@ -2143,7 +2166,7 @@
5022 if (p->conf.debug > 10) {
5023 - fprintf(stderr, "%s.%d: next chunk\n", __FILE__, __LINE__);
5024 + log_error_write(srv, __FILE__, __LINE__, "s", "next chunk");
5028 @@ -2173,7 +2196,7 @@
5030 hctx->wb->bytes_in += weHave;
5032 - if (req_c->offset == req_c->mem->used - 1) {
5033 + if (req_c->offset == (off_t) req_c->mem->used - 1) {
5034 chunkqueue_remove_finished_chunks(req_cq);
5036 req_c = req_cq->first;
5037 @@ -2368,7 +2391,7 @@
5038 offset = sizeof(*header);
5040 /* ->b should only be the content */
5041 - buffer_copy_string(packet->b, ""); /* used == 1 */
5042 + buffer_copy_string_len(packet->b, CONST_STR_LEN("")); /* used == 1 */
5045 /* copy the content */
5046 @@ -2544,7 +2567,10 @@
5047 stat_cache_entry *sce;
5049 if (HANDLER_ERROR != stat_cache_get_entry(srv, con, ds->value, &sce)) {
5050 - data_string *dcls = data_string_init();
5051 + data_string *dcls;
5052 + if (NULL == (dcls = (data_string *)array_get_unused_element(con->response.headers, TYPE_STRING))) {
5053 + dcls = data_response_init();
5056 http_chunk_append_file(srv, con, ds->value, 0, sce->st.st_size);
5057 hctx->send_content_body = 0; /* ignore the content */
5058 @@ -2663,30 +2689,48 @@
5060 /* the child should not terminate at all */
5062 - switch(waitpid(proc->pid, &status, WNOHANG)) {
5064 - /* child is still alive */
5069 - if (WIFEXITED(status)) {
5071 + switch(waitpid(proc->pid, &status, WNOHANG)) {
5073 + /* child is still alive */
5074 + if (srv->cur_ts <= proc->disabled_until) break;
5076 + proc->state = PROC_STATE_RUNNING;
5077 + host->active_procs++;
5079 + log_error_write(srv, __FILE__, __LINE__, "sbdb",
5080 + "fcgi-server re-enabled:",
5081 + host->host, host->port,
5082 + host->unixsocket);
5085 + if (errno == EINTR) continue;
5087 + log_error_write(srv, __FILE__, __LINE__, "sd",
5088 + "child died somehow, waitpid failed:",
5090 + proc->state = PROC_STATE_DIED;
5093 + if (WIFEXITED(status)) {
5095 - log_error_write(srv, __FILE__, __LINE__, "sdsd",
5096 - "child exited, pid:", proc->pid,
5097 - "status:", WEXITSTATUS(status));
5098 + log_error_write(srv, __FILE__, __LINE__, "sdsd",
5099 + "child exited, pid:", proc->pid,
5100 + "status:", WEXITSTATUS(status));
5102 - } else if (WIFSIGNALED(status)) {
5103 - log_error_write(srv, __FILE__, __LINE__, "sd",
5104 - "child signaled:",
5105 - WTERMSIG(status));
5107 - log_error_write(srv, __FILE__, __LINE__, "sd",
5108 - "child died somehow:",
5110 + } else if (WIFSIGNALED(status)) {
5111 + log_error_write(srv, __FILE__, __LINE__, "sd",
5112 + "child signaled:",
5113 + WTERMSIG(status));
5115 + log_error_write(srv, __FILE__, __LINE__, "sd",
5116 + "child died somehow:",
5120 + proc->state = PROC_STATE_DIED;
5124 - proc->state = PROC_STATE_DIED;
5128 @@ -2797,7 +2841,7 @@
5129 hctx->proc->state = PROC_STATE_DIED;
5131 fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
5132 - buffer_append_string(p->statuskey, ".died");
5133 + buffer_append_string_len(p->statuskey, CONST_STR_LEN(".died"));
5135 status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
5137 @@ -2889,7 +2933,7 @@
5138 hctx->proc->state = PROC_STATE_OVERLOADED;
5140 fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
5141 - buffer_append_string(p->statuskey, ".overloaded");
5142 + buffer_append_string_len(p->statuskey, CONST_STR_LEN(".overloaded"));
5144 status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
5146 @@ -2915,7 +2959,7 @@
5147 "load:", host->load);
5149 fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
5150 - buffer_append_string(p->statuskey, ".died");
5151 + buffer_append_string_len(p->statuskey, CONST_STR_LEN(".died"));
5153 status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
5155 @@ -2941,19 +2985,19 @@
5156 status_counter_inc(srv, CONST_STR_LEN("fastcgi.active-requests"));
5158 fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
5159 - buffer_append_string(p->statuskey, ".connected");
5160 + buffer_append_string_len(p->statuskey, CONST_STR_LEN(".connected"));
5162 status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
5165 fastcgi_status_copy_procname(p->statuskey, hctx->host, hctx->proc);
5166 - buffer_append_string(p->statuskey, ".load");
5167 + buffer_append_string_len(p->statuskey, CONST_STR_LEN(".load"));
5169 status_counter_set(srv, CONST_BUF_LEN(p->statuskey), hctx->proc->load);
5172 fastcgi_status_copy_procname(p->statuskey, hctx->host, NULL);
5173 - buffer_append_string(p->statuskey, ".load");
5174 + buffer_append_string_len(p->statuskey, CONST_STR_LEN(".load"));
5176 status_counter_set(srv, CONST_BUF_LEN(p->statuskey), hctx->host->load);
5178 @@ -3074,7 +3118,7 @@
5180 /* check if the next server has no load. */
5181 ndx = hctx->ext->last_used_ndx + 1;
5182 - if(ndx >= hctx->ext->used || ndx < 0) ndx = 0;
5183 + if(ndx >= (int) hctx->ext->used || ndx < 0) ndx = 0;
5184 host = hctx->ext->hosts[ndx];
5185 if (host->load > 0) {
5186 /* get backend with the least load. */
5187 @@ -3418,6 +3462,8 @@
5188 fcgi_extension *extension = NULL;
5189 fcgi_extension_host *host = NULL;
5191 + if (con->mode != DIRECT) return HANDLER_GO_ON;
5193 /* Possibly, we processed already this request */
5194 if (con->file_started == 1) return HANDLER_GO_ON;
5196 @@ -3480,13 +3526,12 @@
5198 ct_len = extension->key->used - 1;
5200 - if (s_len < ct_len) continue;
5202 - /* check extension in the form "/fcgi_pattern" */
5203 - if (*(extension->key->ptr) == '/') {
5204 - if (strncmp(fn->ptr, extension->key->ptr, ct_len) == 0)
5205 + /* check _url_ in the form "/fcgi_pattern" */
5206 + if (extension->key->ptr[0] == '/') {
5207 + if ((ct_len <= con->uri.path->used -1) &&
5208 + (strncmp(con->uri.path->ptr, extension->key->ptr, ct_len) == 0))
5210 - } else if (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len)) {
5211 + } else if ((ct_len <= s_len) && (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len))) {
5212 /* check extension in the form ".fcg" */
5215 @@ -3499,16 +3544,15 @@
5217 /* check if we have at least one server for this extension up and running */
5218 for (k = 0; k < extension->used; k++) {
5219 - host = extension->hosts[k];
5220 + fcgi_extension_host *h = extension->hosts[k];
5222 /* we should have at least one proc that can do something */
5223 - if (host->active_procs == 0) {
5226 + if (h->active_procs == 0) {
5230 /* we found one host that is alive */
5235 @@ -3582,6 +3626,13 @@
5236 * SCRIPT_NAME = /fcgi-bin/foo
5239 + * if prefix = /, and fix-root-path-name is enable
5241 + * /fcgi-bin/foo/bar
5243 + * SCRIPT_NAME = /fcgi-bin/foo
5244 + * PATH_INFO = /bar
5248 /* the rewrite is only done for /prefix/? matches */
5249 @@ -3594,6 +3645,10 @@
5251 con->uri.path->used -= con->request.pathinfo->used - 1;
5252 con->uri.path->ptr[con->uri.path->used - 1] = '\0';
5253 + } else if (host->fix_root_path_name && extension->key->ptr[0] == '/' && extension->key->ptr[1] == '\0') {
5254 + buffer_copy_string(con->request.pathinfo, con->uri.path->ptr);
5255 + con->uri.path->used = 1;
5256 + con->uri.path->ptr[con->uri.path->used - 1] = '\0';
5260 @@ -3738,7 +3793,7 @@
5261 proc->port = host->port + proc->id;
5263 buffer_copy_string_buffer(proc->unixsocket, host->unixsocket);
5264 - buffer_append_string(proc->unixsocket, "-");
5265 + buffer_append_string_len(proc->unixsocket, CONST_STR_LEN("-"));
5266 buffer_append_long(proc->unixsocket, proc->id);
5269 Index: src/mod_ssi_exprparser.y
5270 ===================================================================
5271 --- src/mod_ssi_exprparser.y (.../tags/lighttpd-1.4.19) (revision 2303)
5272 +++ src/mod_ssi_exprparser.y (.../branches/lighttpd-1.4.x) (revision 2303)
5273 @@ -105,12 +105,13 @@
5276 value(A) ::= VALUE(B). {
5277 - A = buffer_init_string(B->ptr);
5281 value(A) ::= value(B) VALUE(C). {
5283 buffer_append_string_buffer(A, C);
5287 cond(A) ::= EQ. { A = SSI_COND_EQ; }
5288 Index: src/mod_access.c
5289 ===================================================================
5290 --- src/mod_access.c (.../tags/lighttpd-1.4.19) (revision 2303)
5291 +++ src/mod_access.c (.../branches/lighttpd-1.4.x) (revision 2303)
5295 con->http_status = 403;
5296 + con->mode = DIRECT;
5298 if (con->conf.log_request_handling) {
5299 log_error_write(srv, __FILE__, __LINE__, "sb",
5300 Index: src/mod_accesslog.c
5301 ===================================================================
5302 --- src/mod_accesslog.c (.../tags/lighttpd-1.4.19) (revision 2303)
5303 +++ src/mod_accesslog.c (.../branches/lighttpd-1.4.x) (revision 2303)
5305 if (s->use_syslog) {
5306 # ifdef HAVE_SYSLOG_H
5307 if (s->access_logbuffer->used > 2) {
5308 - syslog(LOG_INFO, "%*s", s->access_logbuffer->used - 2, s->access_logbuffer->ptr);
5309 + syslog(LOG_INFO, "%*s", (int) s->access_logbuffer->used - 2, s->access_logbuffer->ptr);
5312 } else if (s->log_access_fd != -1) {
5314 if (i == 0 && buffer_is_empty(s->format)) {
5315 /* set a default logfile string */
5317 - buffer_copy_string(s->format, "%h %V %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"");
5318 + buffer_copy_string_len(s->format, CONST_STR_LEN("%h %V %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""));
5326 - if (buffer_is_empty(s->access_logfile)) continue;
5327 + if (s->access_logfile->used < 2) continue;
5329 if (s->access_logfile->ptr[0] == '|') {
5333 close(to_log_fds[1]);
5335 + openDevNull(STDERR_FILENO);
5337 /* we don't need the client socket */
5338 for (i = 3; i < 256; i++) {
5341 #ifdef HAVE_SYSLOG_H
5342 if (s->access_logbuffer->used > 2) {
5343 /* syslog appends a \n on its own */
5344 - syslog(LOG_INFO, "%*s", s->access_logbuffer->used - 2, s->access_logbuffer->ptr);
5345 + syslog(LOG_INFO, "%*s", (int) s->access_logbuffer->used - 2, s->access_logbuffer->ptr);
5348 } else if (s->log_access_fd != -1) {
5352 if (s->use_syslog == 0 &&
5353 - !buffer_is_empty(s->access_logfile) &&
5354 + s->access_logfile->used > 1 &&
5355 s->access_logfile->ptr[0] != '|') {
5357 close(s->log_access_fd);
5358 @@ -647,9 +649,12 @@
5360 mod_accesslog_patch_connection(srv, con, p);
5362 + /* No output device, nothing to do */
5363 + if (!p->conf.use_syslog && p->conf.log_access_fd == -1) return HANDLER_GO_ON;
5365 b = p->conf.access_logbuffer;
5367 - buffer_copy_string(b, "");
5368 + buffer_copy_string_len(b, CONST_STR_LEN(""));
5371 for (j = 0; j < p->conf.parsed_format->used; j++) {
5372 @@ -674,23 +679,23 @@
5373 localtime_r(&(srv->cur_ts), &tm);
5374 strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S ", &tm);
5376 - strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S ", localtime_r(&(srv->cur_ts)));
5377 + strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S ", localtime(&(srv->cur_ts)));
5379 p->conf.ts_accesslog_str->used = strlen(p->conf.ts_accesslog_str->ptr) + 1;
5381 - buffer_append_string(p->conf.ts_accesslog_str, tm.tm_gmtoff >= 0 ? "+" : "-");
5382 + buffer_append_string_len(p->conf.ts_accesslog_str, tm.tm_gmtoff >= 0 ? "+" : "-", 1);
5384 scd = abs(tm.tm_gmtoff);
5386 min = (scd % 3600) / 60;
5389 - if (hrs < 10) buffer_append_string(p->conf.ts_accesslog_str, "0");
5390 + if (hrs < 10) buffer_append_string_len(p->conf.ts_accesslog_str, CONST_STR_LEN("0"));
5391 buffer_append_long(p->conf.ts_accesslog_str, hrs);
5393 - if (min < 10) buffer_append_string(p->conf.ts_accesslog_str, "0");
5394 + if (min < 10) buffer_append_string_len(p->conf.ts_accesslog_str, CONST_STR_LEN("0"));
5395 buffer_append_long(p->conf.ts_accesslog_str, min);
5396 - BUFFER_APPEND_STRING_CONST(p->conf.ts_accesslog_str, "]");
5397 + buffer_append_string_len(p->conf.ts_accesslog_str, CONST_STR_LEN("]"));
5399 #ifdef HAVE_GMTIME_R
5400 gmtime_r(&(srv->cur_ts), &tm);
5401 @@ -717,13 +722,13 @@
5403 case FORMAT_REMOTE_IDENT:
5405 - BUFFER_APPEND_STRING_CONST(b, "-");
5406 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5408 case FORMAT_REMOTE_USER:
5409 if (con->authed_user->used > 1) {
5410 buffer_append_string_buffer(b, con->authed_user);
5412 - BUFFER_APPEND_STRING_CONST(b, "-");
5413 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5416 case FORMAT_REQUEST_LINE:
5417 @@ -740,42 +745,42 @@
5418 buffer_append_off_t(b,
5419 con->bytes_written - con->bytes_header <= 0 ? 0 : con->bytes_written - con->bytes_header);
5421 - BUFFER_APPEND_STRING_CONST(b, "-");
5422 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5426 if (NULL != (ds = (data_string *)array_get_element(con->request.headers, p->conf.parsed_format->ptr[j]->string->ptr))) {
5427 buffer_append_string_buffer(b, ds->value);
5429 - BUFFER_APPEND_STRING_CONST(b, "-");
5430 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5433 case FORMAT_RESPONSE_HEADER:
5434 if (NULL != (ds = (data_string *)array_get_element(con->response.headers, p->conf.parsed_format->ptr[j]->string->ptr))) {
5435 buffer_append_string_buffer(b, ds->value);
5437 - BUFFER_APPEND_STRING_CONST(b, "-");
5438 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5441 case FORMAT_FILENAME:
5442 if (con->physical.path->used > 1) {
5443 buffer_append_string_buffer(b, con->physical.path);
5445 - BUFFER_APPEND_STRING_CONST(b, "-");
5446 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5449 case FORMAT_BYTES_OUT:
5450 if (con->bytes_written > 0) {
5451 buffer_append_off_t(b, con->bytes_written);
5453 - BUFFER_APPEND_STRING_CONST(b, "-");
5454 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5457 case FORMAT_BYTES_IN:
5458 if (con->bytes_read > 0) {
5459 buffer_append_off_t(b, con->bytes_read);
5461 - BUFFER_APPEND_STRING_CONST(b, "-");
5462 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5465 case FORMAT_TIME_USED:
5466 @@ -785,28 +790,35 @@
5467 if (con->server_name->used > 1) {
5468 buffer_append_string_buffer(b, con->server_name);
5470 - BUFFER_APPEND_STRING_CONST(b, "-");
5471 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5474 case FORMAT_HTTP_HOST:
5475 if (con->uri.authority->used > 1) {
5476 buffer_append_string_buffer(b, con->uri.authority);
5478 - BUFFER_APPEND_STRING_CONST(b, "-");
5479 + buffer_append_string_len(b, CONST_STR_LEN("-"));
5482 case FORMAT_REQUEST_PROTOCOL:
5483 - buffer_append_string(b,
5484 - con->request.http_version == HTTP_VERSION_1_1 ? "HTTP/1.1" : "HTTP/1.0");
5485 + buffer_append_string_len(b,
5486 + con->request.http_version == HTTP_VERSION_1_1 ? "HTTP/1.1" : "HTTP/1.0", 8);
5488 case FORMAT_REQUEST_METHOD:
5489 buffer_append_string(b, get_http_method_name(con->request.http_method));
5491 case FORMAT_PERCENT:
5492 - buffer_append_string(b, "%");
5493 + buffer_append_string_len(b, CONST_STR_LEN("%"));
5495 case FORMAT_SERVER_PORT:
5496 - buffer_append_long(b, srv->srvconf.port);
5498 + char *colon = strchr(((server_socket*)(con->srv_socket))->srv_token->ptr, ':');
5500 + buffer_append_string(b, colon+1);
5502 + buffer_append_long(b, srv->srvconf.port);
5506 case FORMAT_QUERY_STRING:
5507 buffer_append_string_buffer(b, con->uri.query);
5510 case FORMAT_CONNECTION_STATUS:
5511 switch(con->keep_alive) {
5512 - case 0: buffer_append_string(b, "-"); break;
5513 - default: buffer_append_string(b, "+"); break;
5514 + case 0: buffer_append_string_len(b, CONST_STR_LEN("-")); break;
5515 + default: buffer_append_string_len(b, CONST_STR_LEN("+")); break;
5523 - BUFFER_APPEND_STRING_CONST(b, "\n");
5524 + buffer_append_string_len(b, CONST_STR_LEN("\n"));
5526 if (p->conf.use_syslog || /* syslog doesn't cache */
5527 (p->conf.access_logfile->used && p->conf.access_logfile->ptr[0] == '|') || /* pipes don't cache */
5529 #ifdef HAVE_SYSLOG_H
5531 /* syslog appends a \n on its own */
5532 - syslog(LOG_INFO, "%*s", b->used - 2, b->ptr);
5533 + syslog(LOG_INFO, "%*s", (int) b->used - 2, b->ptr);
5536 } else if (p->conf.log_access_fd != -1) {
5538 ===================================================================
5539 --- src/server.c (.../tags/lighttpd-1.4.19) (revision 2303)
5540 +++ src/server.c (.../branches/lighttpd-1.4.x) (revision 2303)
5545 - memcpy(&last_sigterm_info, si, sizeof(*si));
5546 + last_sigterm_info = *si;
5549 if (graceful_shutdown) {
5552 graceful_shutdown = 1;
5554 - memcpy(&last_sigterm_info, si, sizeof(*si));
5555 + last_sigterm_info = *si;
5561 if (!forwarded_sig_hup) {
5563 - memcpy(&last_sighup_info, si, sizeof(*si));
5564 + last_sighup_info = *si;
5566 forwarded_sig_hup = 0;
5568 @@ -573,20 +573,9 @@
5571 /* close stdin and stdout, as they are not needed */
5572 - /* move stdin to /dev/null */
5573 - if (-1 != (fd = open("/dev/null", O_RDONLY))) {
5574 - close(STDIN_FILENO);
5575 - dup2(fd, STDIN_FILENO);
5578 + openDevNull(STDIN_FILENO);
5579 + openDevNull(STDOUT_FILENO);
5581 - /* move stdout to /dev/null */
5582 - if (-1 != (fd = open("/dev/null", O_WRONLY))) {
5583 - close(STDOUT_FILENO);
5584 - dup2(fd, STDOUT_FILENO);
5588 if (0 != config_set_defaults(srv)) {
5589 log_error_write(srv, __FILE__, __LINE__, "s",
5590 "setting default values failed");
5591 @@ -887,14 +876,14 @@
5592 /* write pid file */
5594 buffer_copy_long(srv->tmp_buf, getpid());
5595 - buffer_append_string(srv->tmp_buf, "\n");
5596 + buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN("\n"));
5597 write(pid_fd, srv->tmp_buf->ptr, srv->tmp_buf->used - 1);
5602 - // Close stderr ASAP in the child process to make sure that nothing
5603 - // is being written to that fd which may not be valid anymore.
5604 + /* Close stderr ASAP in the child process to make sure that nothing
5605 + * is being written to that fd which may not be valid anymore. */
5606 if (-1 == log_error_open(srv)) {
5607 log_error_write(srv, __FILE__, __LINE__, "s", "Opening errorlog failed. Going down.");
5609 Index: src/mod_dirlisting.c
5610 ===================================================================
5611 --- src/mod_dirlisting.c (.../tags/lighttpd-1.4.19) (revision 2303)
5612 +++ src/mod_dirlisting.c (.../branches/lighttpd-1.4.x) (revision 2303)
5613 @@ -454,21 +454,21 @@
5614 static void http_list_directory_header(server *srv, connection *con, plugin_data *p, buffer *out) {
5617 - BUFFER_APPEND_STRING_CONST(out,
5618 + buffer_append_string_len(out, CONST_STR_LEN(
5619 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
5620 "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"
5625 buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML);
5626 - BUFFER_APPEND_STRING_CONST(out, "</title>\n");
5627 + buffer_append_string_len(out, CONST_STR_LEN("</title>\n"));
5629 if (p->conf.external_css->used > 1) {
5630 - BUFFER_APPEND_STRING_CONST(out, "<link rel=\"stylesheet\" type=\"text/css\" href=\"");
5631 + buffer_append_string_len(out, CONST_STR_LEN("<link rel=\"stylesheet\" type=\"text/css\" href=\""));
5632 buffer_append_string_buffer(out, p->conf.external_css);
5633 - BUFFER_APPEND_STRING_CONST(out, "\" />\n");
5634 + buffer_append_string_len(out, CONST_STR_LEN("\" />\n"));
5636 - BUFFER_APPEND_STRING_CONST(out,
5637 + buffer_append_string_len(out, CONST_STR_LEN(
5638 "<style type=\"text/css\">\n"
5639 "a, a:active {text-decoration: none; color: blue;}\n"
5640 "a:visited {color: #48468F;}\n"
5642 " padding-right: 14px;"
5643 " padding-bottom: 3px;"
5646 - BUFFER_APPEND_STRING_CONST(out,
5647 "td {padding-right: 14px;}\n"
5648 "td.s, th.s {text-align: right;}\n"
5650 @@ -502,10 +500,10 @@
5651 " padding-top: 4px;"
5658 - BUFFER_APPEND_STRING_CONST(out, "</head>\n<body>\n");
5659 + buffer_append_string_len(out, CONST_STR_LEN("</head>\n<body>\n"));
5662 if (p->conf.show_header) {
5663 @@ -514,19 +512,19 @@
5665 buffer_copy_string_buffer(p->tmp_buf, con->physical.path);
5666 BUFFER_APPEND_SLASH(p->tmp_buf);
5667 - BUFFER_APPEND_STRING_CONST(p->tmp_buf, "HEADER.txt");
5668 + buffer_append_string_len(p->tmp_buf, CONST_STR_LEN("HEADER.txt"));
5670 if (-1 != stream_open(&s, p->tmp_buf)) {
5671 - BUFFER_APPEND_STRING_CONST(out, "<pre class=\"header\">");
5672 + buffer_append_string_len(out, CONST_STR_LEN("<pre class=\"header\">"));
5673 buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
5674 - BUFFER_APPEND_STRING_CONST(out, "</pre>");
5675 + buffer_append_string_len(out, CONST_STR_LEN("</pre>"));
5680 - BUFFER_APPEND_STRING_CONST(out, "<h2>Index of ");
5681 + buffer_append_string_len(out, CONST_STR_LEN("<h2>Index of "));
5682 buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML);
5683 - BUFFER_APPEND_STRING_CONST(out,
5684 + buffer_append_string_len(out, CONST_STR_LEN(
5686 "<div class=\"list\">\n"
5687 "<table summary=\"Directory Listing\" cellpadding=\"0\" cellspacing=\"0\">\n"
5688 @@ -545,17 +543,17 @@
5689 "<td class=\"s\">- </td>"
5690 "<td class=\"t\">Directory</td>"
5696 static void http_list_directory_footer(server *srv, connection *con, plugin_data *p, buffer *out) {
5699 - BUFFER_APPEND_STRING_CONST(out,
5700 + buffer_append_string_len(out, CONST_STR_LEN(
5707 if (p->conf.show_readme) {
5709 @@ -563,33 +561,33 @@
5711 buffer_copy_string_buffer(p->tmp_buf, con->physical.path);
5712 BUFFER_APPEND_SLASH(p->tmp_buf);
5713 - BUFFER_APPEND_STRING_CONST(p->tmp_buf, "README.txt");
5714 + buffer_append_string_len(p->tmp_buf, CONST_STR_LEN("README.txt"));
5716 if (-1 != stream_open(&s, p->tmp_buf)) {
5717 - BUFFER_APPEND_STRING_CONST(out, "<pre class=\"readme\">");
5718 + buffer_append_string_len(out, CONST_STR_LEN("<pre class=\"readme\">"));
5719 buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
5720 - BUFFER_APPEND_STRING_CONST(out, "</pre>");
5721 + buffer_append_string_len(out, CONST_STR_LEN("</pre>"));
5726 - BUFFER_APPEND_STRING_CONST(out,
5727 + buffer_append_string_len(out, CONST_STR_LEN(
5728 "<div class=\"foot\">"
5732 if (p->conf.set_footer->used > 1) {
5733 buffer_append_string_buffer(out, p->conf.set_footer);
5734 } else if (buffer_is_empty(con->conf.server_tag)) {
5735 - BUFFER_APPEND_STRING_CONST(out, PACKAGE_NAME "/" PACKAGE_VERSION);
5736 + buffer_append_string_len(out, CONST_STR_LEN(PACKAGE_NAME "/" PACKAGE_VERSION));
5738 buffer_append_string_buffer(out, con->conf.server_tag);
5741 - BUFFER_APPEND_STRING_CONST(out,
5742 + buffer_append_string_len(out, CONST_STR_LEN(
5750 static int http_list_directory(server *srv, connection *con, plugin_data *p, buffer *dir) {
5751 @@ -742,13 +740,13 @@
5752 if (files.used) http_dirls_sort(files.ent, files.used);
5754 out = chunkqueue_get_append_buffer(con->write_queue);
5755 - BUFFER_COPY_STRING_CONST(out, "<?xml version=\"1.0\" encoding=\"");
5756 + buffer_copy_string_len(out, CONST_STR_LEN("<?xml version=\"1.0\" encoding=\""));
5757 if (buffer_is_empty(p->conf.encoding)) {
5758 - BUFFER_APPEND_STRING_CONST(out, "iso-8859-1");
5759 + buffer_append_string_len(out, CONST_STR_LEN("iso-8859-1"));
5761 buffer_append_string_buffer(out, p->conf.encoding);
5763 - BUFFER_APPEND_STRING_CONST(out, "\"?>\n");
5764 + buffer_append_string_len(out, CONST_STR_LEN("\"?>\n"));
5765 http_list_directory_header(srv, con, p, out);
5768 @@ -762,13 +760,13 @@
5769 strftime(datebuf, sizeof(datebuf), "%Y-%b-%d %H:%M:%S", localtime(&(tmp->mtime)));
5772 - BUFFER_APPEND_STRING_CONST(out, "<tr><td class=\"n\"><a href=\"");
5773 + buffer_append_string_len(out, CONST_STR_LEN("<tr><td class=\"n\"><a href=\""));
5774 buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_REL_URI_PART);
5775 - BUFFER_APPEND_STRING_CONST(out, "/\">");
5776 + buffer_append_string_len(out, CONST_STR_LEN("/\">"));
5777 buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_MINIMAL_XML);
5778 - BUFFER_APPEND_STRING_CONST(out, "</a>/</td><td class=\"m\">");
5779 + buffer_append_string_len(out, CONST_STR_LEN("</a>/</td><td class=\"m\">"));
5780 buffer_append_string_len(out, datebuf, sizeof(datebuf) - 1);
5781 - BUFFER_APPEND_STRING_CONST(out, "</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>\n");
5782 + buffer_append_string_len(out, CONST_STR_LEN("</td><td class=\"s\">- </td><td class=\"t\">Directory</td></tr>\n"));
5786 @@ -818,17 +816,17 @@
5788 http_list_directory_sizefmt(sizebuf, tmp->size);
5790 - BUFFER_APPEND_STRING_CONST(out, "<tr><td class=\"n\"><a href=\"");
5791 + buffer_append_string_len(out, CONST_STR_LEN("<tr><td class=\"n\"><a href=\""));
5792 buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_REL_URI_PART);
5793 - BUFFER_APPEND_STRING_CONST(out, "\">");
5794 + buffer_append_string_len(out, CONST_STR_LEN("\">"));
5795 buffer_append_string_encoded(out, DIRLIST_ENT_NAME(tmp), tmp->namelen, ENCODING_MINIMAL_XML);
5796 - BUFFER_APPEND_STRING_CONST(out, "</a></td><td class=\"m\">");
5797 + buffer_append_string_len(out, CONST_STR_LEN("</a></td><td class=\"m\">"));
5798 buffer_append_string_len(out, datebuf, sizeof(datebuf) - 1);
5799 - BUFFER_APPEND_STRING_CONST(out, "</td><td class=\"s\">");
5800 + buffer_append_string_len(out, CONST_STR_LEN("</td><td class=\"s\">"));
5801 buffer_append_string(out, sizebuf);
5802 - BUFFER_APPEND_STRING_CONST(out, "</td><td class=\"t\">");
5803 + buffer_append_string_len(out, CONST_STR_LEN("</td><td class=\"t\">"));
5804 buffer_append_string(out, content_type);
5805 - BUFFER_APPEND_STRING_CONST(out, "</td></tr>\n");
5806 + buffer_append_string_len(out, CONST_STR_LEN("</td></tr>\n"));
5810 @@ -841,11 +839,11 @@
5812 /* Insert possible charset to Content-Type */
5813 if (buffer_is_empty(p->conf.encoding)) {
5814 - response_header_insert(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
5815 + response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
5817 - buffer_copy_string(p->content_charset, "text/html; charset=");
5818 + buffer_copy_string_len(p->content_charset, CONST_STR_LEN("text/html; charset="));
5819 buffer_append_string_buffer(p->content_charset, p->conf.encoding);
5820 - response_header_insert(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(p->content_charset));
5821 + response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(p->content_charset));
5824 con->file_finished = 1;
5825 @@ -861,6 +859,18 @@
5829 + /* we only handle GET, POST and HEAD */
5830 + switch(con->request.http_method) {
5831 + case HTTP_METHOD_GET:
5832 + case HTTP_METHOD_POST:
5833 + case HTTP_METHOD_HEAD:
5836 + return HANDLER_GO_ON;
5839 + if (con->mode != DIRECT) return HANDLER_GO_ON;
5841 if (con->physical.path->used == 0) return HANDLER_GO_ON;
5842 if (con->uri.path->used == 0) return HANDLER_GO_ON;
5843 if (con->uri.path->ptr[con->uri.path->used - 2] != '/') return HANDLER_GO_ON;
5844 Index: src/http_chunk.c
5845 ===================================================================
5846 --- src/http_chunk.c (.../tags/lighttpd-1.4.19) (revision 2303)
5847 +++ src/http_chunk.c (.../branches/lighttpd-1.4.x) (revision 2303)
5849 b = srv->tmp_chunk_len;
5852 - buffer_copy_string(b, "0");
5853 + buffer_copy_string_len(b, CONST_STR_LEN("0"));
5855 for (i = 0; i < 8 && len; i++) {
5858 b->ptr[b->used++] = '\0';
5861 - buffer_append_string(b, "\r\n");
5862 + buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
5863 chunkqueue_append_buffer(con->write_queue, b);
5866 Index: src/mod_magnet.c
5867 ===================================================================
5868 --- src/mod_magnet.c (.../tags/lighttpd-1.4.19) (revision 2303)
5869 +++ src/mod_magnet.c (.../branches/lighttpd-1.4.x) (revision 2303)
5870 @@ -414,10 +414,16 @@
5871 case MAGNET_ENV_URI_AUTHORITY: dest = con->uri.authority; break;
5872 case MAGNET_ENV_URI_QUERY: dest = con->uri.query; break;
5874 - case MAGNET_ENV_REQUEST_METHOD: break;
5875 + case MAGNET_ENV_REQUEST_METHOD:
5876 + buffer_copy_string(srv->tmp_buf, get_http_method_name(con->request.http_method));
5877 + dest = srv->tmp_buf;
5879 case MAGNET_ENV_REQUEST_URI: dest = con->request.uri; break;
5880 case MAGNET_ENV_REQUEST_ORIG_URI: dest = con->request.orig_uri; break;
5881 - case MAGNET_ENV_REQUEST_PROTOCOL: break;
5882 + case MAGNET_ENV_REQUEST_PROTOCOL:
5883 + buffer_copy_string(srv->tmp_buf, get_http_version_name(con->request.http_version));
5884 + dest = srv->tmp_buf;
5887 case MAGNET_ENV_UNSET: break;
5890 assert(lua_gettop(L) == 0); /* only the function should be on the stack */
5892 con->http_status = 500;
5893 + con->mode = DIRECT;
5895 return HANDLER_FINISHED;
5898 assert(lua_gettop(L) == 1); /* only the function should be on the stack */
5900 con->http_status = 500;
5901 + con->mode = DIRECT;
5903 return HANDLER_FINISHED;
5905 @@ -766,9 +774,13 @@
5907 if (0 == setjmp(exceptionjmp)) {
5908 magnet_attach_content(srv, con, p, L);
5909 + if (!chunkqueue_is_empty(con->write_queue)) {
5910 + con->mode = p->id;
5914 con->http_status = 500;
5915 + con->mode = DIRECT;
5918 assert(lua_gettop(L) == 1); /* only the function should be on the stack */
5920 ===================================================================
5921 --- src/log.c (.../tags/lighttpd-1.4.19) (revision 2303)
5922 +++ src/log.c (.../branches/lighttpd-1.4.x) (revision 2303)
5924 # define O_LARGEFILE 0
5927 +/* Close fd and _try_ to get a /dev/null for it instead.
5928 + * close() alone may trigger some bugs when a
5929 + * process opens another file and gets fd = STDOUT_FILENO or STDERR_FILENO
5930 + * and later tries to just print on stdout/stderr
5932 + * Returns 0 on success and -1 on failure (fd gets closed in all cases)
5934 +int openDevNull(int fd) {
5937 +#if defined(__WIN32)
5938 + /* Cygwin should work with /dev/null */
5939 + tmpfd = open("nul", O_RDWR);
5941 + tmpfd = open("/dev/null", O_RDWR);
5943 + if (tmpfd != -1 && tmpfd != fd) {
5947 + return (tmpfd != -1) ? 0 : -1;
5956 int log_error_open(server *srv) {
5958 int close_stderr = 1;
5960 #ifdef HAVE_SYSLOG_H
5961 @@ -78,15 +100,16 @@
5962 /* don't close stderr for debugging purposes if run in valgrind */
5963 if (RUNNING_ON_VALGRIND) close_stderr = 0;
5965 - if (srv->errorlog_mode == ERRORLOG_STDERR) close_stderr = 0;
5967 + if (srv->errorlog_mode == ERRORLOG_STDERR && srv->srvconf.dont_daemonize) {
5968 + /* We can only log to stderr in dont-daemonize mode;
5969 + * if we do daemonize and no errorlog file is specified, we log into /dev/null
5974 /* move stderr to /dev/null */
5975 - if (close_stderr &&
5976 - -1 != (fd = open("/dev/null", O_WRONLY))) {
5977 - close(STDERR_FILENO);
5978 - dup2(fd, STDERR_FILENO);
5981 + if (close_stderr) openDevNull(STDERR_FILENO);
5985 @@ -162,18 +185,18 @@
5988 buffer_copy_string_buffer(srv->errorlog_buf, srv->ts_debug_str);
5989 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, ": (");
5990 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(": ("));
5992 case ERRORLOG_SYSLOG:
5993 /* syslog is generating its own timestamps */
5994 - BUFFER_COPY_STRING_CONST(srv->errorlog_buf, "(");
5995 + buffer_copy_string_len(srv->errorlog_buf, CONST_STR_LEN("("));
5999 buffer_append_string(srv->errorlog_buf, filename);
6000 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, ".");
6001 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("."));
6002 buffer_append_long(srv->errorlog_buf, line);
6003 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, ") ");
6004 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(") "));
6007 for(va_start(ap, fmt); *fmt; fmt++) {
6008 @@ -186,28 +209,28 @@
6009 case 's': /* string */
6010 s = va_arg(ap, char *);
6011 buffer_append_string(srv->errorlog_buf, s);
6012 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " ");
6013 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
6015 case 'b': /* buffer */
6016 b = va_arg(ap, buffer *);
6017 buffer_append_string_buffer(srv->errorlog_buf, b);
6018 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " ");
6019 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
6022 d = va_arg(ap, int);
6023 buffer_append_long(srv->errorlog_buf, d);
6024 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " ");
6025 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
6027 case 'o': /* off_t */
6028 o = va_arg(ap, off_t);
6029 buffer_append_off_t(srv->errorlog_buf, o);
6030 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " ");
6031 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
6033 case 'x': /* int (hex) */
6034 d = va_arg(ap, int);
6035 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "0x");
6036 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("0x"));
6037 buffer_append_long_hex(srv->errorlog_buf, d);
6038 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, " ");
6039 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN(" "));
6041 case 'S': /* string */
6042 s = va_arg(ap, char *);
6043 @@ -221,6 +244,15 @@
6044 d = va_arg(ap, int);
6045 buffer_append_long(srv->errorlog_buf, d);
6047 + case 'O': /* off_t */
6048 + o = va_arg(ap, off_t);
6049 + buffer_append_off_t(srv->errorlog_buf, o);
6051 + case 'X': /* int (hex) */
6052 + d = va_arg(ap, int);
6053 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("0x"));
6054 + buffer_append_long_hex(srv->errorlog_buf, d);
6059 @@ -235,11 +267,11 @@
6061 switch(srv->errorlog_mode) {
6063 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "\n");
6064 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("\n"));
6065 write(srv->errorlog_fd, srv->errorlog_buf->ptr, srv->errorlog_buf->used - 1);
6067 case ERRORLOG_STDERR:
6068 - BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "\n");
6069 + buffer_append_string_len(srv->errorlog_buf, CONST_STR_LEN("\n"));
6070 write(STDERR_FILENO, srv->errorlog_buf->ptr, srv->errorlog_buf->used - 1);
6072 case ERRORLOG_SYSLOG:
6073 Index: src/proc_open.c
6074 ===================================================================
6075 --- src/proc_open.c (.../tags/lighttpd-1.4.19) (revision 2303)
6076 +++ src/proc_open.c (.../branches/lighttpd-1.4.x) (revision 2303)
6078 buffer_append_string(cmdline, shell);
6080 buffer_append_string(cmdline, windir);
6081 - buffer_append_string(cmdline, "\\system32\\cmd.exe");
6082 + buffer_append_string_len(cmdline, CONST_STR_LEN("\\system32\\cmd.exe"));
6084 buffer_append_string_len(cmdline, CONST_STR_LEN(" /c "));
6085 buffer_append_string(cmdline, command);
6087 ===================================================================
6088 --- src/log.h (.../tags/lighttpd-1.4.19) (revision 2303)
6089 +++ src/log.h (.../branches/lighttpd-1.4.x) (revision 2303)
6094 +/* Close fd and _try_ to get a /dev/null for it instead.
6095 + * Returns 0 on success and -1 on failure (fd gets closed in all cases)
6097 +int openDevNull(int fd);
6099 #define WP() log_error_write(srv, __FILE__, __LINE__, "");
6101 int log_error_open(server *srv);
6102 Index: tests/env-variables.conf
6103 ===================================================================
6104 --- tests/env-variables.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6105 +++ tests/env-variables.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6107 -server.document-root = env.CWD
6108 Index: tests/env-variables.t
6109 ===================================================================
6110 --- tests/env-variables.t (.../tags/lighttpd-1.4.19) (revision 2303)
6111 +++ tests/env-variables.t (.../branches/lighttpd-1.4.x) (revision 2303)
6115 - # add current source dir to the include-path
6116 - # we need this for make distcheck
6117 - (my $srcdir = $0) =~ s,/[^/]+$,/,;
6118 - unshift @INC, $srcdir;
6123 -use Test::More tests => 2;
6126 -my $tf = LightyTest->new();
6127 -$tf->{CONFIGFILE} = 'env-variables.conf';
6130 - local $TODO = 'we still crash on undefined environment variables';
6131 - ok($tf->start_proc == 0, "Starting lighttpd");
6132 - ok($tf->stop_proc == 0, "Stopping lighttpd");
6134 Index: tests/bug-12.conf
6135 ===================================================================
6136 --- tests/bug-12.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6137 +++ tests/bug-12.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6139 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6140 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6142 ## bind to port (default: 80)
6144 Index: tests/fastcgi-10.conf
6145 ===================================================================
6146 --- tests/fastcgi-10.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6147 +++ tests/fastcgi-10.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6149 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6150 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6152 ## bind to port (default: 80)
6154 Index: tests/bug-06.conf
6155 ===================================================================
6156 --- tests/bug-06.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6157 +++ tests/bug-06.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6159 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6160 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6162 ## bind to port (default: 80)
6164 Index: tests/mod-extforward.conf
6165 ===================================================================
6167 Property changes on: tests/symlink.t
6168 ___________________________________________________________________
6169 Added: svn:executable
6172 Index: tests/request.t
6173 ===================================================================
6174 --- tests/request.t (.../tags/lighttpd-1.4.19) (revision 2303)
6175 +++ tests/request.t (.../branches/lighttpd-1.4.x) (revision 2303)
6177 Expect: 100-continue
6180 -$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417, '-HTTP-Content' => ''} ];
6181 +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417 } ];
6182 ok($tf->handle_http($t) == 0, 'Continue, Expect');
6185 Index: tests/var-include.conf
6186 ===================================================================
6187 --- tests/var-include.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6188 +++ tests/var-include.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6190 debug.log-condition-handling = "enable"
6192 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6193 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6195 ## bind to port (default: 80)
6197 Index: tests/mod-proxy.t
6198 ===================================================================
6199 --- tests/mod-proxy.t (.../tags/lighttpd-1.4.19) (revision 2303)
6200 +++ tests/mod-proxy.t (.../branches/lighttpd-1.4.x) (revision 2303)
6203 $tf_real->{PORT} = 2048;
6204 $tf_real->{CONFIGFILE} = 'lighttpd.conf';
6205 -$tf_real->{LIGHTTPD_PIDFILE} = $tf_real->{TESTDIR}.'/tmp/lighttpd/lighttpd.pid';
6207 $tf_proxy->{PORT} = 2050;
6208 $tf_proxy->{CONFIGFILE} = 'proxy.conf';
6209 -$tf_proxy->{LIGHTTPD_PIDFILE} = $tf_proxy->{TESTDIR}.'/tmp/lighttpd/lighttpd-proxy.pid';
6211 ok($tf_real->start_proc == 0, "Starting lighttpd") or die();
6213 Index: tests/404-handler.conf
6214 ===================================================================
6215 --- tests/404-handler.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6216 +++ tests/404-handler.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6218 debug.log-request-header = "enable"
6220 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6221 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6223 ## bind to port (default: 80)
6225 Index: tests/lowercase.conf
6226 ===================================================================
6227 --- tests/lowercase.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6228 +++ tests/lowercase.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6230 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6231 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6233 ## bind to port (default: 80)
6235 Index: tests/condition.conf
6236 ===================================================================
6237 --- tests/condition.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6238 +++ tests/condition.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6240 debug.log-condition-handling = "enable"
6242 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6243 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6245 ## bind to port (default: 80)
6247 Index: tests/fastcgi-13.conf
6248 ===================================================================
6249 --- tests/fastcgi-13.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6250 +++ tests/fastcgi-13.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6252 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6253 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6255 debug.log-request-header = "enable"
6256 debug.log-response-header = "enable"
6259 "host" => "127.0.0.1",
6261 - "bin-path" => "/usr/bin/php-cgi",
6262 + "bin-path" => env.PHP,
6263 "bin-copy-environment" => ( "PATH", "SHELL", "USER" ),
6266 Index: tests/mod-fastcgi.t
6267 ===================================================================
6268 --- tests/mod-fastcgi.t (.../tags/lighttpd-1.4.19) (revision 2303)
6269 +++ tests/mod-fastcgi.t (.../branches/lighttpd-1.4.x) (revision 2303)
6274 -use Test::More tests => 47;
6275 +use Test::More tests => 49;
6278 my $tf = LightyTest->new();
6281 +my $php_child = -1;
6283 +my $phpbin = (defined $ENV{'PHP'} ? $ENV{'PHP'} : '/usr/bin/php-cgi');
6284 +$ENV{'PHP'} = $phpbin;
6287 + skip "PHP already running on port 1026", 1 if $tf->listening_on(1026);
6288 + skip "no php binary found", 1 unless -x $phpbin;
6289 + ok(-1 != ($php_child = $tf->spawnfcgi($phpbin, 1026)), "Spawning php");
6293 skip "no PHP running on port 1026", 29 unless $tf->listening_on(1026);
6295 - ok($tf->start_proc == 0, "Starting lighttpd") or die();
6296 + ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
6298 $t->{REQUEST} = ( <<EOF
6299 GET /phpinfo.php HTTP/1.0
6303 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/get-server-env.php' } ];
6304 - ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
6305 + ok($tf->handle_http($t) == 0, '$_SERVER["SCRIPT_NAME"]');
6307 $t->{REQUEST} = ( <<EOF
6308 GET /get-server-env.php/foo?env=PATH_INFO HTTP/1.0
6312 $tf->{CONFIGFILE} = 'fastcgi-10.conf';
6313 - ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
6314 + ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or goto cleanup;
6315 $t->{REQUEST} = ( <<EOF
6316 GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
6317 Host: zzz.example.org
6319 ok($tf->stop_proc == 0, "Stopping lighttpd");
6321 $tf->{CONFIGFILE} = 'bug-06.conf';
6322 - ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
6323 + ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or goto cleanup;
6324 $t->{REQUEST} = ( <<EOF
6325 GET /indexfile/ HTTP/1.0
6326 Host: www.example.org
6328 ok($tf->stop_proc == 0, "Stopping lighttpd");
6330 $tf->{CONFIGFILE} = 'bug-12.conf';
6331 - ok($tf->start_proc == 0, "Starting lighttpd with bug-12.conf") or die();
6332 + ok($tf->start_proc == 0, "Starting lighttpd with bug-12.conf") or goto cleanup;
6333 $t->{REQUEST} = ( <<EOF
6334 POST /indexfile/abc HTTP/1.0
6335 Host: www.example.org
6336 @@ -199,6 +209,12 @@
6340 + skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
6341 + ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
6346 skip "no fcgi-auth found", 4 unless -x $tf->{BASEDIR}."/tests/fcgi-auth" || -x $tf->{BASEDIR}."/tests/fcgi-auth.exe";
6348 $tf->{CONFIGFILE} = 'fastcgi-auth.conf';
6353 - skip "no php found", 5 unless -x "/usr/bin/php-cgi";
6354 + skip "no php found", 5 unless -x $phpbin;
6355 $tf->{CONFIGFILE} = 'fastcgi-13.conf';
6356 ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
6357 $t->{REQUEST} = ( <<EOF
6358 @@ -325,3 +341,10 @@
6359 ok($tf->stop_proc == 0, "Stopping lighttpd");
6366 +$tf->endspawnfcgi($php_child) if $php_child != -1;
6369 Index: tests/mod-rewrite.t
6370 ===================================================================
6371 --- tests/mod-rewrite.t (.../tags/lighttpd-1.4.19) (revision 2303)
6372 +++ tests/mod-rewrite.t (.../branches/lighttpd-1.4.x) (revision 2303)
6377 -use Test::More tests => 5;
6378 +use Test::More tests => 8;
6381 my $tf = LightyTest->new();
6383 +my $php_child = -1;
6385 +my $phpbin = (defined $ENV{'PHP'} ? $ENV{'PHP'} : '/usr/bin/php-cgi');
6388 - skip "no PHP running on port 1026", 5 unless $tf->listening_on(1026);
6389 + skip "PHP already running on port 1026", 1 if $tf->listening_on(1026);
6390 + skip "no php binary found", 1 unless -x $phpbin;
6391 + ok(-1 != ($php_child = $tf->spawnfcgi($phpbin, 1026)), "Spawning php");
6394 - ok($tf->start_proc == 0, "Starting lighttpd") or die();
6396 + skip "no PHP running on port 1026", 6 unless $tf->listening_on(1026);
6398 + ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
6400 $t->{REQUEST} = ( <<EOF
6401 GET /rewrite/foo HTTP/1.0
6402 Host: www.example.org
6404 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'bar&a=b' } ];
6405 ok($tf->handle_http($t) == 0, 'valid request');
6407 + $t->{REQUEST} = ( <<EOF
6408 +GET %2Frewrite/f%6Fo?a=b HTTP/1.0
6409 +Host: www.example.org
6412 + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'a=b' } ];
6413 + ok($tf->handle_http($t) == 0, 'valid request with url encoded characters');
6415 ok($tf->stop_proc == 0, "Stopping lighttpd");
6419 + skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
6420 + ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
6428 +$tf->endspawnfcgi($php_child) if $php_child != -1;
6431 Index: tests/lighttpd.conf
6432 ===================================================================
6433 --- tests/lighttpd.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6434 +++ tests/lighttpd.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6436 debug.log-response-header = "enable"
6437 debug.log-condition-handling = "enable"
6438 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6439 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6441 ## 64 Mbyte ... nice limit
6442 server.max-request-size = 65000
6443 Index: tests/fastcgi-responder.conf
6444 ===================================================================
6445 --- tests/fastcgi-responder.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6446 +++ tests/fastcgi-responder.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6448 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6449 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6451 #debug.log-request-header = "enable"
6452 #debug.log-response-header = "enable"
6453 Index: tests/fastcgi-auth.conf
6454 ===================================================================
6455 --- tests/fastcgi-auth.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6456 +++ tests/fastcgi-auth.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6458 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6459 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6461 debug.log-request-header = "enable"
6462 debug.log-response-header = "enable"
6463 Index: tests/proxy.conf
6464 ===================================================================
6465 --- tests/proxy.conf (.../tags/lighttpd-1.4.19) (revision 2303)
6466 +++ tests/proxy.conf (.../branches/lighttpd-1.4.x) (revision 2303)
6468 server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6469 -server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd-proxy.pid"
6471 ## bind to port (default: 80)
6473 Index: tests/docroot/www/get-env.php
6474 ===================================================================
6475 --- tests/docroot/www/get-env.php (.../tags/lighttpd-1.4.19) (revision 2303)
6476 +++ tests/docroot/www/get-env.php (.../branches/lighttpd-1.4.x) (revision 2303)
6479 - print $_ENV[$_GET["env"]];
6480 + $env = $_GET["env"];
6481 + print isset($_ENV[$env]) ? $_ENV[$env] : '';
6483 Index: tests/docroot/www/Makefile.am
6484 ===================================================================
6485 --- tests/docroot/www/Makefile.am (.../tags/lighttpd-1.4.19) (revision 2303)
6486 +++ tests/docroot/www/Makefile.am (.../branches/lighttpd-1.4.x) (revision 2303)
6488 -EXTRA_DIST=cgi.php cgi.pl dummydir index.html index.txt phpinfo.php \
6489 +EXTRA_DIST=cgi.php cgi.pl index.html index.txt phpinfo.php \
6490 redirect.php cgi-pathinfo.pl get-env.php get-server-env.php \
6491 nph-status.pl prefix.fcgi get-header.pl ssi.shtml get-post-len.pl \
6492 exec-date.shtml index.html~ 404.fcgi 404.html 404.pl send404.pl crlfcrash.pl
6493 Index: tests/Makefile.am
6494 ===================================================================
6495 --- tests/Makefile.am (.../tags/lighttpd-1.4.19) (revision 2303)
6496 +++ tests/Makefile.am (.../branches/lighttpd-1.4.x) (revision 2303)
6502 - env-variables.conf \
6507 Property changes on: tests/core-404-handler.t
6508 ___________________________________________________________________
6509 Added: svn:executable
6512 Index: tests/LightyTest.pm
6513 ===================================================================
6514 --- tests/LightyTest.pm (.../tags/lighttpd-1.4.19) (revision 2303)
6515 +++ tests/LightyTest.pm (.../branches/lighttpd-1.4.x) (revision 2303)
6520 +use POSIX ":sys_wait_h";
6527 if (mtime($self->{BASEDIR}.'/src/lighttpd') > mtime($self->{BASEDIR}.'/build/lighttpd')) {
6528 - $self->{LIGHTTPD_PATH} = $self->{BASEDIR}.'/src/lighttpd';
6529 - $self->{MODULES_PATH} = $self->{BASEDIR}.'/src/.libs';
6530 + $self->{BINDIR} = $self->{BASEDIR}.'/src';
6531 + if (mtime($self->{BASEDIR}.'/src/.libs')) {
6532 + $self->{MODULES_PATH} = $self->{BASEDIR}.'/src/.libs';
6534 + $self->{MODULES_PATH} = $self->{BASEDIR}.'/src';
6537 - $self->{LIGHTTPD_PATH} = $self->{BASEDIR}.'/build/lighttpd';
6538 + $self->{BINDIR} = $self->{BASEDIR}.'/build';
6539 $self->{MODULES_PATH} = $self->{BASEDIR}.'/build';
6541 - $self->{LIGHTTPD_PIDFILE} = $self->{TESTDIR}.'/tmp/lighttpd/lighttpd.pid';
6542 - $self->{PIDOF_PIDFILE} = $self->{TESTDIR}.'/tmp/lighttpd/pidof.pid';
6543 + $self->{LIGHTTPD_PATH} = $self->{BINDIR}.'/lighttpd';
6544 $self->{PORT} = 2048;
6546 my ($name, $aliases, $addrtype, $net) = gethostbyaddr(inet_aton("127.0.0.1"), AF_INET);
6551 - open F, $self->{LIGHTTPD_PIDFILE} or return -1;
6554 + my $pid = $self->{LIGHTTPD_PID};
6555 + if (defined $pid && $pid != -1) {
6556 + kill('TERM', $pid) or return -1;
6557 + return -1 if ($pid != waitpid($pid, 0));
6559 + diag("Process not started, nothing to stop");
6563 - if (defined $pid) {
6564 - kill('TERM',$pid) or return -1;
6568 +sub wait_for_port_with_proc {
6571 + my $child = shift;
6573 + while (0 == $self->listening_on($port)) {
6574 select(undef, undef, undef, 0.1);
6576 + # the process is gone, we failed
6577 + if (0 != waitpid($child, WNOHANG)) {
6588 # kill old proc if necessary
6590 + #$self->stop_proc;
6592 # pre-process configfile if necessary
6595 $ENV{'SRCDIR'} = $self->{BASEDIR}.'/tests';
6596 + $ENV{'PORT'} = $self->{PORT};
6598 - unlink($self->{LIGHTTPD_PIDFILE});
6599 + my $cmdline = $self->{LIGHTTPD_PATH}." -D -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH};
6600 if (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'strace') {
6601 - system("strace -tt -s 512 -o strace ".$self->{LIGHTTPD_PATH}." -D -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH}." &");
6602 + $cmdline = "strace -tt -s 512 -o strace ".$cmdline;
6603 } elsif (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'truss') {
6604 - system("/usr/dtrctkit/bin/dtruss -d -e ".$self->{LIGHTTPD_PATH}." -D -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH}." 2> strace &");
6605 + $cmdline = "truss -a -l -w all -v all -o strace ".$cmdline;
6606 + } elsif (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'gdb') {
6607 + $cmdline = "gdb --batch --ex 'run' --ex 'bt' --args ".$cmdline." > gdb.out";
6608 } elsif (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'valgrind') {
6609 - system("valgrind --tool=memcheck --show-reachable=yes --leak-check=yes --log-file=valgrind ".$self->{LIGHTTPD_PATH}." -D -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH}." &");
6611 - system($self->{LIGHTTPD_PATH}." -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH});
6612 + $cmdline = "valgrind --tool=memcheck --show-reachable=yes --leak-check=yes --log-file=valgrind ".$cmdline;
6615 - select(undef, undef, undef, 0.1);
6616 - if (not -e $self->{LIGHTTPD_PIDFILE} or 0 == kill 0, `cat $self->{LIGHTTPD_PIDFILE}`) {
6617 - select(undef, undef, undef, 2);
6620 - unlink($self->{TESTDIR}."/tmp/cfg.file");
6622 - # no pidfile, we failed
6623 - if (not -e $self->{LIGHTTPD_PIDFILE}) {
6624 - diag(sprintf('Could not find pidfile: %s', $self->{LIGHTTPD_PIDFILE}));
6625 + # diag("starting lighttpd at :".$self->{PORT}.", cmdline: ".$cmdline );
6626 + my $child = fork();
6627 + if (not defined $child) {
6628 + diag("Fork failed");
6631 + if ($child == 0) {
6632 + exec $cmdline or die($?);
6635 - # the process is gone, we failed
6636 - if (0 == kill 0, `cat $self->{LIGHTTPD_PIDFILE}`) {
6637 - diag(sprintf('the process referenced by %s is not up', $self->{LIGHTTPD_PIDFILE}));
6638 + if (0 != $self->wait_for_port_with_proc($self->{PORT}, $child)) {
6639 + diag(sprintf('The process %i is not up', $child));
6643 + $self->{LIGHTTPD_PID} = $child;
6650 my @request = $t->{REQUEST};
6651 my @response = $t->{RESPONSE};
6652 + my $is_debug = $ENV{"TRACE_HTTP"};
6655 IO::Socket::INET->new(Proto => "tcp",
6656 @@ -144,20 +163,27 @@
6658 $remote->autoflush(1);
6660 + diag("sending request header to ".$host.":".$self->{PORT}) if $is_debug;
6666 - print $remote $_.$BLANK;
6667 + print $remote $_.$BLANK;
6668 + diag("<< ".$_) if $is_debug;
6670 + shutdown($remote, 1); # I've stopped writing data
6671 + diag("... done") if $is_debug;
6675 + diag("receiving response") if $is_debug;
6679 + diag(">> ".$_) if $is_debug;
6681 + diag("... done") if $is_debug;
6685 @@ -187,18 +213,24 @@
6686 (my $h = $1) =~ tr/[A-Z]/[a-z]/;
6688 if (defined $resp_hdr{$h}) {
6689 - diag(sprintf("header %s is duplicated: %s and %s\n",
6690 - $h, $resp_hdr{$h}, $2));
6691 +# diag(sprintf("header '%s' is duplicated: '%s' and '%s'\n",
6692 +# $h, $resp_hdr{$h}, $2));
6693 + $resp_hdr{$h} .= ', '.$2;
6698 - diag(sprintf("unexpected line '$line'\n"));
6699 + diag(sprintf("unexpected line '%s'\n", $line));
6705 + if (not defined($resp_line)) {
6706 + diag(sprintf("empty response\n"));
6710 $t->{etag} = $resp_hdr{'etag'};
6711 $t->{date} = $resp_hdr{'date'};
6717 - diag(sprintf("unexpected resp_line '$resp_line'\n"));
6718 + diag(sprintf("unexpected resp_line '%s'\n", $resp_line));
6723 diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
6726 - } elsif (defined $href->{'-HTTP-Content'}) {
6729 + if (defined $href->{'-HTTP-Content'}) {
6730 if (defined $resp_body && $resp_body ne '') {
6731 diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
6736 foreach (keys %{ $href }) {
6737 - ## filter special keys
6738 next if $_ eq 'HTTP-Protocol';
6739 next if $_ eq 'HTTP-Status';
6740 next if $_ eq 'HTTP-Content';
6742 my $key_inverted = 0;
6744 if (substr($k, 0, 1) eq '+') {
6745 - ## the key has to exist, but the value is ignored
6748 } elsif (substr($k, 0, 1) eq '-') {
6749 @@ -265,11 +297,11 @@
6752 $verify_value = 0; ## skip the value check
6756 if ($key_inverted) {
6757 if (defined $resp_hdr{$k}) {
6758 - diag(sprintf("required header '%s' is missing\n", $k));
6759 + diag(sprintf("header '%s' MUST not be set\n", $k));
6763 @@ -297,12 +329,38 @@
6765 # we should have sucked up everything
6766 if (defined $lines) {
6767 - diag(sprintf("unexpected lines '$lines'\n"));
6768 + diag(sprintf("unexpected lines '%s'\n", $lines));
6777 + my ($self, $binary, $port) = @_;
6778 + my $child = fork();
6779 + if (not defined $child) {
6780 + diag("Couldn't fork\n");
6783 + if ($child == 0) {
6784 + my $cmd = $self->{BINDIR}.'/spawn-fcgi -n -p '.$port.' -f "'.$binary.'"';
6785 + exec $cmd or die($?);
6787 + if (0 != $self->wait_for_port_with_proc($port, $child)) {
6788 + diag(sprintf('The process %i is not up (port %i, %s)', $child, $port, $binary));
6796 + my ($self, $pid) = @_;
6797 + return -1 if (-1 == $pid);
6805 Index: tests/run-tests.pl
6806 ===================================================================
6807 --- tests/run-tests.pl (.../tags/lighttpd-1.4.19) (revision 2303)
6808 +++ tests/run-tests.pl (.../branches/lighttpd-1.4.x) (revision 2303)
6812 use Test::Harness qw(&runtests $verbose);
6813 -$verbose = (defined $ENV{'VERBOSE'} ? $ENV{'VERBOSE'} : 0);;
6814 +$verbose = (defined $ENV{'VERBOSE'} ? $ENV{'VERBOSE'} : 0);
6815 +my $tests = (defined $ENV{'TESTS'} ? $ENV{'TESTS'} : '');
6817 my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
6819 opendir DIR, $srcdir;
6821 while ($f = readdir(DIR)) {
6822 - if ($f =~ /\.t$/) {
6823 + if ($f =~ /^(.*)\.t$/) {
6824 + next if ($tests ne '' and $tests !~ /(^|\s+)$1(\s+|$)/);
6825 push @fs, $srcdir.'/'.$f;
6831 Index: doc/userdir.txt
6832 ===================================================================
6833 --- doc/userdir.txt (.../tags/lighttpd-1.4.19) (revision 2303)
6834 +++ doc/userdir.txt (.../branches/lighttpd-1.4.x) (revision 2303)
6840 +userdir.path (required option)
6841 usually it should be set to "public_html" to take ~/public_html/ as the document root
6843 - Default: empty (document root is the home directory)
6844 + Default: unset (mod_userdir disabled; set it to "" if you want the home directory to be the document root as it was the default before 1.4.19)
6847 userdir.path = "public_html"
6848 Index: doc/configuration.txt
6849 ===================================================================
6850 --- doc/configuration.txt (.../tags/lighttpd-1.4.19) (revision 2303)
6851 +++ doc/configuration.txt (.../branches/lighttpd-1.4.x) (revision 2303)
6854 debug.log-request-handling
6857 +debug.log-ssl-noise
6860 ===================================================================
6861 --- SConstruct (.../tags/lighttpd-1.4.19) (revision 2303)
6862 +++ SConstruct (.../branches/lighttpd-1.4.x) (revision 2303)
6866 package = 'lighttpd'
6870 def checkCHeaders(autoconf, hdrs):
6871 p = re.compile('[^A-Z0-9]')
6873 ===================================================================
6874 --- Makefile.am (.../tags/lighttpd-1.4.19) (revision 2303)
6875 +++ Makefile.am (.../branches/lighttpd-1.4.x) (revision 2303)
6877 SUBDIRS=src doc tests cygwin openwrt
6879 -EXTRA_DIST=lighttpd.spec autogen.sh SConstruct
6880 +EXTRA_DIST=autogen.sh SConstruct
6882 +distcleancheck_listfiles = find -type f -exec sh -c 'test -f $(srcdir)/{} || echo {}' ';'
6884 ===================================================================
6885 --- NEWS (.../tags/lighttpd-1.4.19) (revision 2303)
6886 +++ NEWS (.../branches/lighttpd-1.4.x) (revision 2303)
6894 + * Fix mod_compress to compile with old gcc version (#1592)
6895 + * Fix mod_extforward to compile with old gcc version (#1591)
6896 + * Update documentation for #1587
6897 + * Fix #285 again: read error after SSL_shutdown (thx marton.illes@balabit.com) and clear the error queue before some other calls (CVE-2008-1531)
6898 + * Fix mod_magnet: enable "request.method" and "request.protocol" in lighty.env (#1308)
6899 + * Fix segfault for appending matched parts if there was no regex matching (just give empty strings) (#1601)
6900 + * Use data_response_init in mod_fastcgi x-sendfile handling for response.headers, fix a small "memleak" (#1628)
6901 + * Don't send empty Server headers (#1620)
6902 + * Fix conditional interpretation of core options
6903 + * Enable escaping of % and $ in redirect/rewrite; only two cases changed their behaviour: "%%" => "%", "$$" => "$"
6904 + * Fix accesslog port (should be port from the connection, not the "server.port") (#1618)
6905 + * Fix mod_fastcgi prefix matching: match the prefix always against url, not the absolute filepath (regardless of check-local)
6906 + * Overwrite Content-Type header in mod_dirlisting instead of inserting (#1614), patch by Henrik Holst
6907 + * Handle EINTR in mod_cgi during write() (#1640)
6908 + * Allow all http status codes by default; disable body only for 204,205 and 304; generate error pages for 4xx and 5xx (#1639)
6909 + * Fix mod_magnet to set con->mode = p->id if it generates content, so returning 4xx/5xx doesn't append an error page
6910 + * Remove lighttpd.spec* from source, fixing all problems with it ;-)
6911 + * Do not rely on PATH_MAX (POSIX does not require it) (#580)
6912 + * Disable logging to access.log if filename is an empty string
6913 + * Implement a clean way to open /dev/null and use it to close stdin/out/err in the needed places (#624)
6914 + * merge spawn-fcgi changes from trunk (from @2191)
6915 + * let spawn-fcgi propagate exit code from spawned fcgi application
6916 + * close connection after redirect in trigger_b4_dl (thx icy)
6917 + * close connection in mod_magnet if returned status code
6918 + * fix bug with IPv6 in mod_evasive (#1579)
6919 + * fix scgi HTTP/1.* status parsing (#1638), found by met@uberstats.com
6920 + * [tests] fixed system, use foreground daemons and waitpid
6921 + * [tests] removed pidfile from test system
6922 + * [tests] fixed tests needing php running (if not running on port 1026, search php in env[PHP] or /usr/bin/php-cgi)
6923 + * fixed typo in mod_accesslog (#1699)
6924 + * replaced buffer_{append,copy}_string with the _len variant where possible (#1732) (thx crypt)
6925 + * case insensitive match for secdownload md5 token (#1710)
6926 + * Handle only HEAD, GET and POST in mod_dirlisting (same as in staticfile) (#1687)
6927 + * fixed mod_secdownload problem with unsigned time_t (#1688)
6928 + * handle EAGAIN and EINTR for freebsd sendfile (#1675)
6929 + * Use filedescriptor 0 for mod_scgi spawn socket, redirect STDERR to /dev/null (#1716)
6930 + * fixed round-robin balancing in mod_proxy (#1715)
6931 + * fixed EINTR handling for waitpid in mod_fastcgi
6932 + * mod_{fast,s}cgi: overwrite environment variables (#1722)
6933 + * inserted many con->mode checks; they should prevent two modules to handle the same request if they shouldn't (#631)
6934 + * fixed url encoding to encode more characters (#266)
6935 + * allow digits in [s]cgi env vars (#1712)
6936 + * fixed dropping last character of evhost pattern (#161)
6937 + * print helpful error message on conditionals in global block (#1550)
6938 + * decode url before matching in mod_rewrite (#1720)
6939 + * fixed conditional patching of ldap filter (#1564)
6940 + * Match headers case insensitive in response (removing of X-{Sendfile,LIGHTTPD-*}, catching Date/Server)
6941 + * fixed bug with case-insensitive filenames in mod_userdir (#1589), spotted by "anders1"
6942 + * fixed format string bugs in mod_accesslog for SYSLOG
6943 + * replaced fprintf with log_error_write in fastcgi debug
6944 + * fixed mem leak in ssi expression parser (#1753), thx Take5k
6945 + * hide some ssl errors per default, enable them with debug.log-ssl-noise (#397)
6946 + * do not send content-encoding for 304 (#1754), thx yzlai
6947 + * fix segfault for stat_cache(fam) calls with relative path (without '/', can be triggered by x-sendfile) (#1750)
6948 + * fix splitting of auth-ldap filter
6949 + * workaround ldap connection leak if a ldap connection failed (restarting ldap)
6951 +- 1.4.19 - 2008-03-10
6953 * added support for If-Range: <date> (#1346)
6954 * added support for matching $HTTP["scheme"] in configs
6955 * fixed initgroups() called after chroot (#1384)
6957 ===================================================================
6959 Property changes on: .
6960 ___________________________________________________________________
6962 - 152afb58-edef-0310-8abb-c4023f1b3aa9:/branches/lighttpd-1.3.x:499
6963 152afb58-edef-0310-8abb-c4023f1b3aa9:/branches/lighttpd-1.4.11-ssl-fixes:1346
6964 152afb58-edef-0310-8abb-c4023f1b3aa9:/branches/lighttpd-merge-1.4.x:1041
6965 152afb58-edef-0310-8abb-c4023f1b3aa9:/tags/lighttpd-1.4.11:1042
6966 152afb58-edef-0310-8abb-c4023f1b3aa9:/tags/release-1.3.13:105
6967 152afb58-edef-0310-8abb-c4023f1b3aa9:/trunk:104
6968 a98e19e4-a712-0410-8832-6551a15ffc53:/local/branches/lighttpd-1.4.x:1557
6969 ebd0e9cf-3e47-4385-9dd4-f0e25e97baa2:/local/lighttpd/branches/lighttpd-1.4.x:2164
6970 + 152afb58-edef-0310-8abb-c4023f1b3aa9:/branches/lighttpd-1.3.x:499
6971 152afb58-edef-0310-8abb-c4023f1b3aa9:/branches/lighttpd-1.4.11-ssl-fixes:1346
6972 152afb58-edef-0310-8abb-c4023f1b3aa9:/branches/lighttpd-merge-1.4.x:1041
6973 152afb58-edef-0310-8abb-c4023f1b3aa9:/tags/lighttpd-1.4.11:1042
6974 152afb58-edef-0310-8abb-c4023f1b3aa9:/tags/release-1.3.13:105
6975 152afb58-edef-0310-8abb-c4023f1b3aa9:/trunk:104
6976 a98e19e4-a712-0410-8832-6551a15ffc53:/local/branches/lighttpd-1.4.x:1557
6977 ebd0e9cf-3e47-4385-9dd4-f0e25e97baa2:/local/lighttpd/branches/lighttpd-1.4.x:2250
6978 Added: bzr:revision-info
6979 + timestamp: 2008-09-17 16:23:00.644000053 +0200
6980 committer: Stefan Bühler <stbuehler@web.de>
6982 branch-nick: lighttpd-1.4.x
6986 Added: bzr:revision-id:v3-trunk0
6987 + 1127 stbuehler@web.de-20080728081644-j4cxnhduw8kbt8um
6988 1128 stbuehler@web.de-20080728084246-axvxdtjsrratxixs
6989 1129 stbuehler@web.de-20080729211700-s8v6nq2cu06qesls
6990 1130 stbuehler@web.de-20080729211726-4yxb6e5dva1cn0lz
6991 1131 stbuehler@web.de-20080729211750-4ulzigswx17uciyu
6992 1132 stbuehler@web.de-20080729211850-nliz3kd0m576ztuu
6993 1133 stbuehler@web.de-20080730163440-dg2y2sbf0u4grmn4
6994 1134 stbuehler@web.de-20080730173952-kiutzg6geqy7mick
6995 1135 stbuehler@web.de-20080730193616-9kc2ms7rrhv1lkn7
6996 1136 stbuehler@web.de-20080730211457-z4a6uth1y29glbqh
6997 1137 stbuehler@web.de-20080730213517-b6sjcrdwbmipl334
6998 1138 stbuehler@web.de-20080731102617-2xw8unjfqic7lsew
6999 1139 stbuehler@web.de-20080731102703-q4tu5a6em9y8xdg0
7000 1140 stbuehler@web.de-20080731102729-l6vn5b05w9swqbg5
7001 1141 stbuehler@web.de-20080731102756-oj3d4tnk0l90mj77
7002 1142 stbuehler@web.de-20080731204442-blw14cj2fkr3l8ly
7003 1143 stbuehler@web.de-20080731204508-imtfnurf922mg7tj
7004 1144 stbuehler@web.de-20080801112347-girnwswdkwm8wuip
7005 1145 stbuehler@web.de-20080801161245-kx1temr529o7xko9
7006 1146 stbuehler@web.de-20080801175332-oc9e7x8edn1owcc0
7007 1147 stbuehler@web.de-20080801183454-5i66v0gsdv0cgmia
7008 1148 stbuehler@web.de-20080801192849-6zklfbb832sx0hvr
7009 1149 stbuehler@web.de-20080801203119-o16elp8w854s6lol
7010 1150 stbuehler@web.de-20080802162146-a4v57svc788pwdsv
7011 1151 stbuehler@web.de-20080802162202-9udlc1wuwt09pyh2
7012 1152 stbuehler@web.de-20080804135803-yuor9ze06px7qta4
7013 1153 stbuehler@web.de-20080812194728-fupt781o6q058unh
7014 1154 stbuehler@web.de-20080818162116-piz0ukqsaecv2li2
7015 1155 stbuehler@web.de-20080818235700-94t0xc6ml70zojwq
7016 1156 stbuehler@web.de-20080819163650-1qhwsqszr78cr4xx
7017 1157 stbuehler@web.de-20080819163757-1qq3t1f1wj69t8xs
7018 1158 stbuehler@web.de-20080819163914-rklhkurg8apv85l2
7019 1159 stbuehler@web.de-20080819163953-tlqew751e43phf5b
7020 1160 stbuehler@web.de-20080819164108-8ogh68sm1uyteawe
7021 1161 stbuehler@web.de-20080819173911-w5bqpb7cp9jmdqye
7022 1162 stbuehler@web.de-20080819222242-c0ta5gnli9p3j35a
7023 1163 stbuehler@web.de-20080820100730-g1bwdh4nqb53ag9u
7024 1164 stbuehler@web.de-20080820100752-9pggugdyfnnps8qu
7025 1165 stbuehler@web.de-20080820164258-v2j00motsrsc5esp
7026 1166 stbuehler@web.de-20080827144628-hi9hf4ch3n1wf9ao
7027 1167 stbuehler@web.de-20080827144903-tfxu4yehlyu5kegc
7028 1168 stbuehler@web.de-20080827155155-7mt92orehbxkh2lh
7029 1169 stbuehler@web.de-20080917142048-zbcwpk39q9ewd516
7030 1170 stbuehler@web.de-20080917142300-16gzt21x4nbjtj87