]> git.pld-linux.org Git - packages/lighttpd.git/blob - lighttpd-branch.diff
- disable patch for files that didn't exist in 1.4.9 tarball
[packages/lighttpd.git] / lighttpd-branch.diff
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)
5 @@ -1,83 +0,0 @@
6 -Summary: A fast webserver with minimal memory-footprint (lighttpd)
7 -Name: lighttpd
8 -Version: @VERSION@
9 -Release: 1
10 -Source: http://jan.kneschke.de/projects/lighttpd/download/lighttpd-%version.tar.gz
11 -Packager: Jan Kneschke <jan@kneschke.de>
12 -License: BSD
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
18 -
19 -%description
20 -lighttpd is intented to be a frontend for ad-servers which have to deliver
21 -small files concurrently to many connections.
22 -
23 -Available rpmbuild rebuild options:
24 ---with: ssl mysql lua memcache
25 -
26 -%prep
27 -%setup -q
28 -
29 -%build
30 -rm -rf %{buildroot}
31 -%configure \
32 -    %{?_with_mysql:       --with-mysql} \
33 -    %{?_with_lua:         --with-lua} \
34 -    %{?_with_memcache:    --with-memcache} \
35 -    %{?_with_ssl:         --with-openssl}
36 -make
37 -
38 -%install
39 -%makeinstall
40 -
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
44 -else
45 -       install -m 755 doc/rc.lighttpd %{buildroot}%{_sysconfdir}/init.d/lighttpd
46 -fi
47 -install -m 644 doc/sysconfig.lighttpd %{buildroot}%{_sysconfdir}/sysconfig/lighttpd
48 -
49 -%clean
50 -rm -rf %{buildroot}
51 -
52 -%post
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
57 -fi
58 -
59 -%preun
60 -if [ "$1" = "0"]; then
61 -       # real uninstall, not upgrade
62 -       %{_sysconfdir}/init.d/lighttpd stop
63 -       /sbin/chkconfig --del lighttpd
64 -fi
65 -
66 -%files
67 -%defattr(-,root,root)
68 -%doc doc/lighttpd.conf doc/lighttpd.user README INSTALL ChangeLog COPYING AUTHORS
69 -%doc doc/*.txt
70 -%config(noreplace) %attr(0755,root,root) %{_sysconfdir}/init.d/lighttpd
71 -%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/sysconfig/lighttpd
72 -%{_mandir}/*
73 -%{_libdir}/*
74 -%{_sbindir}/*
75 -%{_bindir}/*
76 -
77 -%changelog
78 -* Thu Sep 30 2004 12:41 <jan@kneschke.de> 1.3.1
79 -- upgraded to 1.3.1
80 -
81 -* Tue Jun 29 2004 17:26 <jan@kneschke.de> 1.2.3
82 -- rpmlint'ed the package
83 -- added URL
84 -- added (noreplace) to start-script
85 -- change group to Networking/Daemon (like apache)
86 -
87 -* Sun Feb 23 2003 15:04 <jan@kneschke.de>
88 -- initial version
89 Index: configure.in
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)
95 @@ -1,12 +0,0 @@
96 -#define TK_AND                             1
97 -#define TK_OR                              2
98 -#define TK_EQ                              3
99 -#define TK_NE                              4
100 -#define TK_GT                              5
101 -#define TK_GE                              6
102 -#define TK_LT                              7
103 -#define TK_LE                              8
104 -#define TK_NOT                             9
105 -#define TK_LPARAN                         10
106 -#define TK_RPARAN                         11
107 -#define TK_VALUE                          12
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)
112 @@ -155,7 +155,7 @@
113                 /* touched */
114                 touched = data_string_init();
115  
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);
119  
120                 array_insert_unique(srv->config_touched, (data_unset *)touched);
121 @@ -260,7 +260,7 @@
122                                 if (ck_colon) {
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) {
130 @@ -529,7 +529,7 @@
131  int config_append_cond_match_buffer(connection *con, data_config *dc, buffer *buf, int n)
132  {
133         cond_cache_t *cache = &con->cond_cache[dc->context_ndx];
134 -       if (n > cache->patterncount) {
135 +       if (n >= cache->patterncount) {
136                 return 0;
137         }
138  
139 Index: src/mod_cgi.c
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)
143 @@ -912,7 +912,7 @@
144                                 buffer_reset(p->tmp_buf);
145  
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_ */
150                                 }
151  
152 @@ -949,7 +949,7 @@
153  
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]) : '_';
159                                 }
160                                 p->tmp_buf->ptr[p->tmp_buf->used++] = '\0';
161 @@ -987,6 +987,8 @@
162                         *c = '/';
163                 }
164  
165 +               openDevNull(STDERR_FILENO);
166 +
167                 /* we don't need the client socket */
168                 for (i = 3; i < 256; i++) {
169                         if (i != srv->errorlog_fd) close(i);
170 @@ -995,7 +997,7 @@
171                 /* exec the cgi */
172                 execve(args[0], args, env.ptr);
173  
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]); */
176  
177                 /* */
178                 SEGFAULT();
179 @@ -1058,8 +1060,9 @@
180                                                 switch(errno) {
181                                                 case ENOSPC:
182                                                         con->http_status = 507;
183 -
184                                                         break;
185 +                                               case EINTR:
186 +                                                       continue;
187                                                 default:
188                                                         con->http_status = 403;
189                                                         break;
190 @@ -1071,8 +1074,9 @@
191                                                 switch(errno) {
192                                                 case ENOSPC:
193                                                         con->http_status = 507;
194 -
195                                                         break;
196 +                                               case EINTR:
197 +                                                       continue;
198                                                 default:
199                                                         con->http_status = 403;
200                                                         break;
201 @@ -1087,6 +1091,8 @@
202                                         c->offset += r;
203                                         cq->bytes_out += r;
204                                 } else {
205 +                                       log_error_write(srv, __FILE__, __LINE__, "ss", "write() failed due to: ", strerror(errno)); 
206 +                                       con->http_status = 500;
207                                         break;
208                                 }
209                                 chunkqueue_remove_finished_chunks(cq);
210 @@ -1174,6 +1180,8 @@
211         plugin_data *p = p_d;
212         buffer *fn = con->physical.path;
213  
214 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
215 +
216         if (fn->used == 0) return HANDLER_GO_ON;
217  
218         mod_cgi_patch_connection(srv, con, p);
219 @@ -1189,6 +1197,7 @@
220  
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;
225  
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)
231 @@ -204,6 +204,8 @@
232         time_t ts = 0;
233         size_t i;
234  
235 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
236 +
237         if (con->uri.path->used == 0) return HANDLER_GO_ON;
238  
239         mod_secdownload_patch_connection(srv, con, p);
240 @@ -243,8 +245,8 @@
241         }
242  
243         /* timed-out */
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;
250  
251 @@ -268,7 +270,7 @@
252  
253         buffer_copy_string_hex(p->md5, (char *)HA1, 16);
254  
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;
258  
259                 log_error_write(srv, __FILE__, __LINE__, "sss",
260 Index: src/array.c
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 @@
265         a = array_init();
266  
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"));
272  
273         array_insert_unique(a, (data_unset *)ds);
274  
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"));
280  
281         array_insert_unique(a, (data_unset *)ds);
282  
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"));
288  
289         array_insert_unique(a, (data_unset *)ds);
290  
291         dc = data_count_init();
292 -       buffer_copy_string(dc->key, "def");
293 +       buffer_copy_string_len(dc->key, CONST_STR_LEN("def"));
294  
295         array_insert_unique(a, (data_unset *)dc);
296  
297         dc = data_count_init();
298 -       buffer_copy_string(dc->key, "def");
299 +       buffer_copy_string_len(dc->key, CONST_STR_LEN("def"));
300  
301         array_insert_unique(a, (data_unset *)dc);
302  
303 Index: src/base.h
304 ===================================================================
305 --- src/base.h  (.../tags/lighttpd-1.4.19)      (revision 2303)
306 +++ src/base.h  (.../branches/lighttpd-1.4.x)   (revision 2303)
307 @@ -259,6 +259,7 @@
308         unsigned short log_request_handling;
309         unsigned short log_response_header;
310         unsigned short log_condition_handling;
311 +       unsigned short log_ssl_noise;
312  
313  
314         /* server wide */
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)
319 @@ -350,7 +350,11 @@
320  
321         if (!p->conf.rewrite) return HANDLER_GO_ON;
322  
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);
328 +       }
329  
330         for (i = 0; i < p->conf.rewrite->used; i++) {
331                 pcre *match;
332 @@ -385,8 +389,7 @@
333  
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] == '%') {
339                                         /* got one */
340  
341                                         size_t num = pattern[k + 1] - '0';
342 @@ -395,7 +398,10 @@
343  
344                                         buffer_append_string_len(con->request.uri, pattern + start, end - start);
345  
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]);
354 Index: src/lempar.c
355 ===================================================================
356 --- src/lempar.c        (.../tags/lighttpd-1.4.19)      (revision 2303)
357 +++ src/lempar.c        (.../branches/lighttpd-1.4.x)   (revision 2303)
358 @@ -210,7 +210,7 @@
359  */
360  const char *ParseTokenName(int tokenType){
361  #ifndef NDEBUG
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];
365    }else{
366      return "Unknown";
367 @@ -335,7 +335,7 @@
368      return YY_NO_ACTION;
369    }
370    i += iLookAhead;
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 ){
373  #ifdef YYFALLBACK
374      int iFallback;            /* Fallback token */
375      if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
376 @@ -378,7 +378,7 @@
377      return YY_NO_ACTION;
378    }
379    i += iLookAhead;
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];
383    }else{
384      return yy_action[i];
385 @@ -456,7 +456,7 @@
386    yymsp = &yypParser->yystack[yypParser->yyidx];
387  #ifndef NDEBUG
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]);
393    }
394 @@ -511,6 +511,8 @@
395    int yymajor,                   /* The major type of the error token */
396    YYMINORTYPE yyminor            /* The minor type of the error token */
397  ){
398 +  UNUSED(yymajor);
399 +  UNUSED(yyminor);
400    ParseARG_FETCH;
401  #define TOKEN (yyminor.yy0)
402  %%
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)
407 @@ -199,6 +199,7 @@
408  
409         /* don't resize the buffer if we were in SSL_ERROR_WANT_* */
410  
411 +       ERR_clear_error();
412         do {
413                 if (!con->ssl_error_want_reuse_buffer) {
414                         b = buffer_init();
415 @@ -275,9 +276,19 @@
416                         /* fall thourgh */
417                 default:
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;
425 +                                       break;
426 +                               default:
427 +                                       break;
428 +                               }
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));
433                         }
434                         break;
435                 }
436 @@ -299,6 +310,8 @@
437  
438         return 0;
439  #else
440 +       UNUSED(srv);
441 +       UNUSED(con);
442         return -1;
443  #endif
444  }
445 @@ -427,21 +440,22 @@
446         }
447  
448         switch(con->http_status) {
449 -       case 400: /* class: header + custom body */
450 -       case 401:
451 -       case 403:
452 -       case 404:
453 -       case 408:
454 -       case 409:
455 -       case 411:
456 -       case 416:
457 -       case 423:
458 -       case 500:
459 -       case 501:
460 -       case 503:
461 -       case 505:
462 +       case 204: /* class: header only */
463 +       case 205:
464 +       case 304:
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);
469 +
470 +               con->file_finished = 1;
471 +               break;
472 +       default: /* class: header + body */
473                 if (con->mode != DIRECT) break;
474  
475 +               /* only custom body for 4xx and 5xx */
476 +               if (con->http_status < 400 || con->http_status >= 600) break;
477 +
478                 con->file_finished = 0;
479  
480                 buffer_reset(con->physical.path);
481 @@ -451,7 +465,8 @@
482                         stat_cache_entry *sce = NULL;
483  
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"));
488  
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);
493  
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"
501                                            " <head>\n"
502 -                                          "  <title>");
503 +                                          "  <title>"));
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));
508  
509 -                       buffer_append_string(b,
510 +                       buffer_append_string_len(b, CONST_STR_LEN(
511                                              "</title>\n"
512                                              " </head>\n"
513                                              " <body>\n"
514 -                                            "  <h1>");
515 +                                            "  <h1>"));
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));
520  
521 -                       buffer_append_string(b,"</h1>\n"
522 +                       buffer_append_string_len(b, CONST_STR_LEN("</h1>\n"
523                                              " </body>\n"
524                                              "</html>\n"
525 -                                            );
526 +                                            ));
527  
528                         response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
529                 }
530 -               /* fall through */
531 -       case 207:
532 -       case 200: /* class: header + body */
533 -       case 201:
534 -       case 300:
535 -       case 301:
536 -       case 302:
537 -       case 303:
538 -       case 307:
539                 break;
540 -
541 -       case 206: /* write_queue is already prepared */
542 -               break;
543 -       case 204:
544 -       case 205: /* class: header only */
545 -       case 304:
546 -       default:
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);
551 -
552 -               con->file_finished = 1;
553 -               break;
554         }
555  
556         if (con->file_finished) {
557 @@ -544,7 +536,7 @@
558                                 data_string *ds;
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 */
563                                 }
564                         } else if (qlen > 0 || con->request.http_method != HTTP_METHOD_HEAD) {
565                                 /* qlen = 0 is important for Redirects (301, ...) as they MAY have
566 @@ -846,7 +838,7 @@
567         }
568  
569         /* The cond_cache gets reset in response.c */
570 -//     config_cond_cache_reset(srv, con);
571 +       /* config_cond_cache_reset(srv, con); */
572  
573  #ifdef USE_OPENSSL
574         if (con->ssl_error_want_reuse_buffer) {
575 @@ -1668,21 +1660,51 @@
576                         }
577  #ifdef USE_OPENSSL
578                         if (srv_sock->is_ssl) {
579 -                               int ret;
580 +                               int ret, ssl_r;
581 +                               unsigned long err;
582 +                               ERR_clear_error();
583                                 switch ((ret = SSL_shutdown(con->ssl))) {
584                                 case 1:
585                                         /* ok */
586                                         break;
587                                 case 0:
588 -                                       SSL_shutdown(con->ssl);
589 -                                       break;
590 +                                       ERR_clear_error();
591 +                                       if (-1 != (ret = SSL_shutdown(con->ssl))) break;
592 +
593 +                                       /* fall through */
594                                 default:
595 -                                       log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:",
596 -                                                       SSL_get_error(con->ssl, ret),
597 -                                                       ERR_error_string(ERR_get_error(), NULL));
598 -                                       return -1;
599 +
600 +                                       switch ((ssl_r = SSL_get_error(con->ssl, ret))) {
601 +                                       case SSL_ERROR_WANT_WRITE:
602 +                                       case SSL_ERROR_WANT_READ:
603 +                                               break;
604 +                                       case SSL_ERROR_SYSCALL:
605 +                                               /* perhaps we have error waiting in our error-queue */
606 +                                               if (0 != (err = ERR_get_error())) {
607 +                                                       do {
608 +                                                               log_error_write(srv, __FILE__, __LINE__, "sdds", "SSL:",
609 +                                                                               ssl_r, ret,
610 +                                                                               ERR_error_string(err, NULL));
611 +                                                       } while((err = ERR_get_error()));
612 +                                               } else {
613 +                                                       log_error_write(srv, __FILE__, __LINE__, "sddds", "SSL (error):",
614 +                                                                       ssl_r, ret, errno,
615 +                                                                       strerror(errno));
616 +                                               }
617 +       
618 +                                               break;
619 +                                       default:
620 +                                               while((err = ERR_get_error())) {
621 +                                                       log_error_write(srv, __FILE__, __LINE__, "sdds", "SSL:",
622 +                                                                       ssl_r, ret,
623 +                                                                       ERR_error_string(err, NULL));
624 +                                               }
625 +       
626 +                                               break;
627 +                                       }
628                                 }
629                         }
630 +                       ERR_clear_error();
631  #endif
632  
633                         switch(con->mode) {
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 @@
639  
640                                 b = chunkqueue_get_append_buffer(con->write_queue);
641  
642 -                               buffer_copy_string(b, "\r\n--");
643 +                               buffer_copy_string_len(b, CONST_STR_LEN("\r\n--"));
644                                 buffer_append_string(b, boundary);
645  
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);
656  
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);
660  
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"));
664  
665                                 con->response.content_length += b->used - 1;
666  
667 @@ -325,7 +325,7 @@
668  
669                 /* set header-fields */
670  
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);
674  
675                 /* overwrite content-type */
676 @@ -333,11 +333,11 @@
677         } else {
678                 /* add Content-Range-header */
679  
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);
689  
690                 response_header_insert(srv, con, CONST_STR_LEN("Content-Range"), CONST_BUF_LEN(p->range_buf));
691 Index: src/network.c
692 ===================================================================
693 --- src/network.c       (.../tags/lighttpd-1.4.19)      (revision 2303)
694 +++ src/network.c       (.../branches/lighttpd-1.4.x)   (revision 2303)
695 @@ -494,7 +494,7 @@
696         b = buffer_init();
697  
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);
702  
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)
708 @@ -7,6 +7,7 @@
709  #include <string.h>
710  #include <stdio.h>
711  #include <ctype.h>
712 +#include <limits.h>
713  #include <assert.h>
714  
715  #include "server.h"
716 @@ -74,24 +75,25 @@
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 */
721  
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 */
730  
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 @@
759  
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);
766  
767 -       cv[39].destination = &(srv->srvconf.errorlog_use_syslog);
768 +       cv[40].destination = &(srv->srvconf.errorlog_use_syslog);
769  
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);
779  
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 *));
784  
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);
790  
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);
797  
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);
808  
809                 srv->config_storage[i] = s;
810  
811 @@ -279,6 +282,7 @@
812         PATCH(log_request_handling);
813         PATCH(log_condition_handling);
814         PATCH(log_file_not_found);
815 +       PATCH(log_ssl_noise);
816  
817         PATCH(range_requests);
818         PATCH(force_lowercase_filenames);
819 @@ -305,9 +309,6 @@
820                 data_config *dc = (data_config *)srv->config_context->data[i];
821                 specific_config *s = srv->config_storage[i];
822  
823 -               /* not our stage */
824 -               if (comp != dc->comp) continue;
825 -
826                 /* condition didn't match */
827                 if (!config_check_cond(srv, con, dc)) continue;
828  
829 @@ -371,6 +372,8 @@
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"))) {
836                                 PATCH(allow_http11);
837                         } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.force-lowercase-filenames"))) {
838 @@ -410,8 +413,8 @@
839  
840  #if 0
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);
848         } else {
849 @@ -480,7 +483,7 @@
850                                 if (t->input[t->offset + 1] == '>') {
851                                         t->offset += 2;
852  
853 -                                       buffer_copy_string(token, "=>");
854 +                                       buffer_copy_string_len(token, CONST_STR_LEN("=>"));
855  
856                                         tid = TK_ARRAY_ASSIGN;
857                                 } else {
858 @@ -494,13 +497,13 @@
859                                 if (t->input[t->offset + 1] == '=') {
860                                         t->offset += 2;
861  
862 -                                       buffer_copy_string(token, "==");
863 +                                       buffer_copy_string_len(token, CONST_STR_LEN("=="));
864  
865                                         tid = TK_EQ;
866                                 } else if (t->input[t->offset + 1] == '~') {
867                                         t->offset += 2;
868  
869 -                                       buffer_copy_string(token, "=~");
870 +                                       buffer_copy_string_len(token, CONST_STR_LEN("=~"));
871  
872                                         tid = TK_MATCH;
873                                 } else {
874 @@ -533,13 +536,13 @@
875                                 if (t->input[t->offset + 1] == '=') {
876                                         t->offset += 2;
877  
878 -                                       buffer_copy_string(token, "!=");
879 +                                       buffer_copy_string_len(token, CONST_STR_LEN("!="));
880  
881                                         tid = TK_NE;
882                                 } else if (t->input[t->offset + 1] == '~') {
883                                         t->offset += 2;
884  
885 -                                       buffer_copy_string(token, "!~");
886 +                                       buffer_copy_string_len(token, CONST_STR_LEN("!~"));
887  
888                                         tid = TK_NOMATCH;
889                                 } else {
890 @@ -594,7 +597,7 @@
891                                 }
892                                 t->in_key = 1;
893                                 tid = TK_EOL;
894 -                               buffer_copy_string(token, "(EOL)");
895 +                               buffer_copy_string_len(token, CONST_STR_LEN("(EOL)"));
896                         } else {
897                                 config_skip_newline(t);
898                                 t->line_pos = 1;
899 @@ -605,7 +608,7 @@
900                         if (t->in_brace > 0) {
901                                 tid = TK_COMMA;
902  
903 -                               buffer_copy_string(token, "(COMMA)");
904 +                               buffer_copy_string_len(token, CONST_STR_LEN("(COMMA)"));
905                         }
906  
907                         t->offset++;
908 @@ -614,7 +617,7 @@
909                 case '"':
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(""));
914  
915                         for (i = 1; t->input[t->offset + i]; i++) {
916                                 if (t->input[t->offset + i] == '\\' &&
917 @@ -660,7 +663,7 @@
918  
919                         tid = TK_LPARAN;
920  
921 -                       buffer_copy_string(token, "(");
922 +                       buffer_copy_string_len(token, CONST_STR_LEN("("));
923                         break;
924                 case ')':
925                         t->offset++;
926 @@ -668,7 +671,7 @@
927  
928                         tid = TK_RPARAN;
929  
930 -                       buffer_copy_string(token, ")");
931 +                       buffer_copy_string_len(token, CONST_STR_LEN(")"));
932                         break;
933                 case '$':
934                         t->offset++;
935 @@ -677,19 +680,19 @@
936                         t->in_cond = 1;
937                         t->in_key = 0;
938  
939 -                       buffer_copy_string(token, "$");
940 +                       buffer_copy_string_len(token, CONST_STR_LEN("$"));
941  
942                         break;
943  
944                 case '+':
945                         if (t->input[t->offset + 1] == '=') {
946                                 t->offset += 2;
947 -                               buffer_copy_string(token, "+=");
948 +                               buffer_copy_string_len(token, CONST_STR_LEN("+="));
949                                 tid = TK_APPEND;
950                         } else {
951                                 t->offset++;
952                                 tid = TK_PLUS;
953 -                               buffer_copy_string(token, "+");
954 +                               buffer_copy_string_len(token, CONST_STR_LEN("+"));
955                         }
956                         break;
957  
958 @@ -698,7 +701,7 @@
959  
960                         tid = TK_LCURLY;
961  
962 -                       buffer_copy_string(token, "{");
963 +                       buffer_copy_string_len(token, CONST_STR_LEN("{"));
964  
965                         break;
966  
967 @@ -707,7 +710,7 @@
968  
969                         tid = TK_RCURLY;
970  
971 -                       buffer_copy_string(token, "}");
972 +                       buffer_copy_string_len(token, CONST_STR_LEN("}"));
973  
974                         break;
975  
976 @@ -716,7 +719,7 @@
977  
978                         tid = TK_LBRACKET;
979  
980 -                       buffer_copy_string(token, "[");
981 +                       buffer_copy_string_len(token, CONST_STR_LEN("["));
982  
983                         break;
984  
985 @@ -725,7 +728,7 @@
986  
987                         tid = TK_RBRACKET;
988  
989 -                       buffer_copy_string(token, "]");
990 +                       buffer_copy_string_len(token, CONST_STR_LEN("]"));
991  
992                         break;
993                 case '#':
994 @@ -884,8 +887,8 @@
995         int ret;
996         buffer *filename;
997  
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);
1004         } else {
1005 @@ -912,15 +915,39 @@
1006         return ret;
1007  }
1008  
1009 +static char* getCWD() {
1010 +       char *s, *s1;
1011 +       size_t len;
1012 +#ifdef PATH_MAX
1013 +       len = PATH_MAX;
1014 +#else
1015 +       len = 4096;
1016 +#endif
1017 +
1018 +       s = malloc(len);
1019 +       if (!s) return NULL;
1020 +       while (NULL == getcwd(s, len)) {
1021 +               if (errno != ERANGE || SSIZE_MAX - len < len) return NULL;
1022 +               len *= 2;
1023 +               s1 = realloc(s, len);
1024 +               if (!s1) {
1025 +                       free(s);
1026 +                       return NULL;
1027 +               }
1028 +               s = s1;
1029 +       }
1030 +       return s;
1031 +}
1032 +
1033  int config_parse_cmd(server *srv, config_t *context, const char *cmd) {
1034         proc_handler_t proc;
1035         tokenizer_t t;
1036         int ret;
1037         buffer *source;
1038         buffer *out;
1039 -       char oldpwd[PATH_MAX];
1040 +       char *oldpwd;
1041  
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));
1046                 return -1;
1047 @@ -945,6 +972,7 @@
1048         buffer_free(source);
1049         buffer_free(out);
1050         chdir(oldpwd);
1051 +       free(oldpwd);
1052         return ret;
1053  }
1054  
1055 @@ -986,7 +1014,7 @@
1056         }
1057  
1058         dc = data_config_init();
1059 -       buffer_copy_string(dc->key, "global");
1060 +       buffer_copy_string_len(dc->key, CONST_STR_LEN("global"));
1061  
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);
1071  
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);
1079         }
1080  
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);
1088                 }
1089  
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);
1097                 }
1098  
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);
1104                 }
1105         } else {
1106 @@ -1067,18 +1095,18 @@
1107  
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);
1113  
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);
1118  
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);
1123  
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);
1127         }
1128  
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)
1133 @@ -316,6 +316,8 @@
1134  # define N 10
1135         int ovec[N * 3];
1136  
1137 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
1138 +
1139         if (con->uri.path->used == 0) return HANDLER_GO_ON;
1140  
1141         mod_trigger_b4_dl_patch_connection(srv, con, p);
1142 @@ -425,8 +427,8 @@
1143                                 /* not found, redirect */
1144  
1145                                 response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->conf.deny_url));
1146 -
1147                                 con->http_status = 307;
1148 +                               con->file_finished = 1;
1149  
1150                                 return HANDLER_FINISHED;
1151                         }
1152 @@ -440,6 +442,7 @@
1153  
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;
1157  
1158                                 if (p->conf.db) {
1159                                         if (0 != gdbm_delete(p->conf.db, key)) {
1160 @@ -490,6 +493,7 @@
1161                                 response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->conf.deny_url));
1162  
1163                                 con->http_status = 307;
1164 +                               con->file_finished = 1;
1165  
1166                                 return HANDLER_FINISHED;
1167                         }
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)
1172 @@ -95,7 +95,7 @@
1173                 s->path_pieces = realloc(s->path_pieces,(s->len+1) * sizeof(*s->path_pieces));
1174                 s->path_pieces[s->len] = buffer_init();
1175  
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);
1178  
1179                 s->len += 1;
1180         }
1181 @@ -181,7 +181,7 @@
1182         }
1183  
1184         ds = data_string_init();
1185 -       buffer_copy_string(ds->key,"%0");
1186 +       buffer_copy_string_len(ds->key,CONST_STR_LEN("%0"));
1187  
1188         /* if we stopped at a dot, skip the dot */
1189         if (*ptr == '.') ptr++;
1190 @@ -197,7 +197,7 @@
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);
1198  
1199 @@ -210,7 +210,7 @@
1200                 /* if the . is not the first charactor of the hostname */
1201                 if (colon != ptr) {
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);
1207  
1208 @@ -286,7 +286,7 @@
1209  
1210                         if (*(ptr+1) == '%') {
1211                                 /* %% */
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);
1217 Index: src/chunk.c
1218 ===================================================================
1219 --- src/chunk.c (.../tags/lighttpd-1.4.19)      (revision 2303)
1220 +++ src/chunk.c (.../branches/lighttpd-1.4.x)   (revision 2303)
1221 @@ -296,7 +296,7 @@
1222  
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"));
1227  
1228                         if (-1 != (c->file.fd = mkstemp(template->ptr))) {
1229                                 /* only trigger the unlink if we created the temp-file successfully */
1230 Index: src/lemon.c
1231 ===================================================================
1232 --- src/lemon.c (.../tags/lighttpd-1.4.19)      (revision 2303)
1233 +++ src/lemon.c (.../branches/lighttpd-1.4.x)   (revision 2303)
1234 @@ -12,6 +12,19 @@
1235  #include <ctype.h>
1236  #include <stdlib.h>
1237  
1238 +#ifdef HAVE_CONFIG_H
1239 +#include "config.h"
1240 +#endif
1241 +
1242 +#ifdef HAVE_STDINT_H
1243 +# include <stdint.h>
1244 +#endif
1245 +#ifdef HAVE_INTTYPES_H
1246 +# include <inttypes.h>
1247 +#endif
1248 +
1249 +#define UNUSED(x) ( (void)(x) )
1250 +
1251  extern void qsort();
1252  extern double strtod();
1253  extern long strtol();
1254 @@ -983,6 +996,7 @@
1255  {
1256    struct symbol *spx, *spy;
1257    int errcnt = 0;
1258 +  UNUSED(errsym);
1259    assert( apx->sp==apy->sp );  /* Otherwise there would be no conflict */
1260    if( apx->type==SHIFT && apy->type==REDUCE ){
1261      spx = apx->sp;
1262 @@ -1347,6 +1361,7 @@
1263    struct lemon lem;
1264    char *def_tmpl_name = "lempar.c";
1265  
1266 +  UNUSED(argc);
1267    OptInit(argv,options,stderr);
1268    if( version ){
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);
1276    }else{
1277      if( err ){
1278        fprintf(err,"%smissing argument on switch.\n",emsg);
1279 @@ -1733,19 +1748,19 @@
1280          *(double*)(op[j].arg) = dv;
1281          break;
1282        case OPT_FDBL:
1283 -        (*(void(*)())(op[j].arg))(dv);
1284 +        (*(void(*)())(intptr_t)(op[j].arg))(dv);
1285          break;
1286        case OPT_INT:
1287          *(int*)(op[j].arg) = lv;
1288          break;
1289        case OPT_FINT:
1290 -        (*(void(*)())(op[j].arg))((int)lv);
1291 +        (*(void(*)())(intptr_t)(op[j].arg))((int)lv);
1292          break;
1293        case OPT_STR:
1294          *(char**)(op[j].arg) = sv;
1295          break;
1296        case OPT_FSTR:
1297 -        (*(void(*)())(op[j].arg))(sv);
1298 +        (*(void(*)())(intptr_t)(op[j].arg))(sv);
1299          break;
1300      }
1301    }
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".
1305  */
1306 +struct pstate ps;
1307  void Parse(gp)
1308  struct lemon *gp;
1309  {
1310 -  struct pstate ps;
1311    FILE *fp;
1312    char *filebuf;
1313    size_t filesize;
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)
1318 @@ -169,6 +169,8 @@
1319  
1320         UNUSED(srv);
1321  
1322 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
1323 +
1324         if (con->uri.path->used == 0) return HANDLER_GO_ON;
1325  
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 @@
1332          *
1333          */
1334  
1335 +       /*
1336 +        * workaround for program when prefix="/"
1337 +        *
1338 +        * rule to build PATH_INFO is hardcoded for when check_local is disabled
1339 +        * enable this option to use the workaround
1340 +        *
1341 +        */
1342 +
1343 +       unsigned short fix_root_path_name;
1344         ssize_t load; /* replace by host->load */
1345  
1346         size_t max_id; /* corresponds most of the time to
1347 @@ -233,6 +242,7 @@
1348  typedef struct {
1349         buffer *key; /* like .php */
1350  
1351 +       int note_is_sent;
1352         scgi_extension_host **hosts;
1353  
1354         size_t used;
1355 @@ -583,6 +593,7 @@
1356  
1357  static int env_add(char_array *env, const char *key, size_t key_len, const char *val, size_t val_len) {
1358         char *dst;
1359 +       size_t i;
1360  
1361         if (!key || !val) return -1;
1362  
1363 @@ -592,6 +603,15 @@
1364         /* add the \0 from the value */
1365         memcpy(dst + key_len + 1, val, val_len + 1);
1366  
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;
1372 +                       return 0;
1373 +               }
1374 +       }
1375 +
1376         if (env->size == 0) {
1377                 env->size = 16;
1378                 env->ptr = malloc(env->size * sizeof(*env->ptr));
1379 @@ -749,11 +769,20 @@
1380                         env.size = 0;
1381                         env.used = 0;
1382  
1383 +                       if (scgi_fd != 0) {
1384 +                               close(0);
1385 +                               dup2(scgi_fd, 0);
1386 +                               close(scgi_fd);
1387 +                               scgi_fd = 0;
1388 +                       }
1389 +
1390                         /* we don't need the client socket */
1391                         for (fd = 3; fd < 256; fd++) {
1392 -                               if (fd != 2 && fd != scgi_fd) close(fd);
1393 +                               close(fd);
1394                         }
1395  
1396 +                       openDevNull(STDERR_FILENO);
1397 +
1398                         /* build clean environment */
1399                         if (host->bin_env_copy->used) {
1400                                 for (i = 0; i < host->bin_env_copy->used; i++) {
1401 @@ -794,7 +823,7 @@
1402                         env.ptr[env.used] = NULL;
1403  
1404                         b = buffer_init();
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);
1408  
1409                         /* exec the cgi */
1410 @@ -968,6 +997,7 @@
1411  
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 */
1415  
1416  
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;
1423  
1424                                         fcv[0].destination = df->host;
1425                                         fcv[1].destination = df->docroot;
1426 @@ -1006,6 +1037,7 @@
1427  
1428                                         fcv[11].destination = df->bin_env;
1429                                         fcv[12].destination = df->bin_env_copy;
1430 +                                       fcv[13].destination = &(df->fix_root_path_name);
1431  
1432  
1433                                         if (0 != config_insert_values_internal(srv, da_host->value, fcv)) {
1434 @@ -1084,7 +1116,7 @@
1435                                                                 proc->port = df->port + pno;
1436                                                         } else {
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);
1441                                                         }
1442  
1443 @@ -1155,11 +1187,6 @@
1444         p    = hctx->plugin_data;
1445         con  = hctx->remote_conn;
1446  
1447 -       if (con->mode != p->id) {
1448 -               WP();
1449 -               return;
1450 -       }
1451 -
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);
1457  
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--;
1462                         }
1463  
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]) : '_';
1471                         }
1472                         srv->tmp_buf->ptr[srv->tmp_buf->used++] = '\0';
1473 @@ -1673,9 +1700,8 @@
1474  
1475                                 status = strtol(s+9, NULL, 10);
1476  
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;
1484                                 }
1485 @@ -2438,15 +2464,11 @@
1486         p    = hctx->plugin_data;
1487         con  = hctx->remote_conn;
1488  
1489 -       if (con->mode != p->id) return HANDLER_GO_ON;
1490 -
1491         log_error_write(srv, __FILE__, __LINE__, "ssdsd",
1492                         "emergency exit: scgi:",
1493                         "connection-fd:", con->fd,
1494                         "fcgi-fd:", hctx->fd);
1495  
1496 -
1497 -
1498         scgi_connection_cleanup(srv, hctx);
1499  
1500         return HANDLER_FINISHED;
1501 @@ -2668,11 +2690,13 @@
1502         plugin_data *p = p_d;
1503         size_t s_len;
1504         int used = -1;
1505 -       int ndx;
1506         size_t k;
1507         buffer *fn;
1508         scgi_extension *extension = NULL;
1509 +       scgi_extension_host *host = NULL;
1510  
1511 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
1512 +
1513         /* Possibly, we processed already this request */
1514         if (con->file_started == 1) return HANDLER_GO_ON;
1515  
1516 @@ -2712,95 +2736,59 @@
1517         }
1518  
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];
1524  
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) {
1529 +                       continue;
1530 +               }
1531  
1532 -               if (used == -1 || host->load < used) {
1533 -                       used = host->load;
1534 +               if (used == -1 || h->load < used) {
1535 +                       used = h->load;
1536  
1537 -                       ndx = k;
1538 +                       host = h;
1539                 }
1540         }
1541  
1542 -       /* found a server */
1543 -       if (ndx != -1) {
1544 -               scgi_extension_host *host = extension->hosts[ndx];
1545 +       if (!host) {
1546 +               /* sorry, we don't have a server alive for this ext */
1547 +               buffer_reset(con->physical.path);
1548 +               con->http_status = 500;
1549  
1550 -               /*
1551 -                * if check-local is disabled, use the uri.path handler
1552 -                *
1553 -                */
1554 +               /* only send the 'no handler' once */
1555 +               if (!extension->note_is_sent) {
1556 +                       extension->note_is_sent = 1;
1557  
1558 -               /* init handler-context */
1559 -               if (uri_path_handler) {
1560 -                       if (host->check_local == 0) {
1561 -                               handler_ctx *hctx;
1562 -                               char *pathinfo;
1563 +                       log_error_write(srv, __FILE__, __LINE__, "sbsbs",
1564 +                                       "all handlers for ", con->uri.path,
1565 +                                       "on", extension->key,
1566 +                                       "are down.");
1567 +               }
1568  
1569 -                               hctx = handler_ctx_init();
1570 +               return HANDLER_FINISHED;
1571 +       }
1572  
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;
1579  
1580 -                               hctx->conf.exts        = p->conf.exts;
1581 -                               hctx->conf.debug       = p->conf.debug;
1582 +       /*
1583 +        * if check-local is disabled, use the uri.path handler
1584 +        *
1585 +        */
1586  
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;
1592 +                       char *pathinfo;
1593  
1594 -                               host->load++;
1595 -
1596 -                               con->mode = p->id;
1597 -
1598 -                               if (con->conf.log_request_handling) {
1599 -                                       log_error_write(srv, __FILE__, __LINE__, "s", "handling it in mod_scgi");
1600 -                               }
1601 -
1602 -                               /* the prefix is the SCRIPT_NAME,
1603 -                                * everthing from start to the next slash
1604 -                                * this is important for check-local = "disable"
1605 -                                *
1606 -                                * if prefix = /admin.fcgi
1607 -                                *
1608 -                                * /admin.fcgi/foo/bar
1609 -                                *
1610 -                                * SCRIPT_NAME = /admin.fcgi
1611 -                                * PATH_INFO   = /foo/bar
1612 -                                *
1613 -                                * if prefix = /fcgi-bin/
1614 -                                *
1615 -                                * /fcgi-bin/foo/bar
1616 -                                *
1617 -                                * SCRIPT_NAME = /fcgi-bin/foo
1618 -                                * PATH_INFO   = /bar
1619 -                                *
1620 -                                */
1621 -
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 */
1627 -
1628 -                                       buffer_copy_string(con->request.pathinfo, pathinfo);
1629 -
1630 -                                       con->uri.path->used -= con->request.pathinfo->used - 1;
1631 -                                       con->uri.path->ptr[con->uri.path->used - 1] = '\0';
1632 -                               }
1633 -                       }
1634 -                       return HANDLER_GO_ON;
1635 -               } else {
1636 -                       handler_ctx *hctx;
1637                         hctx = handler_ctx_init();
1638  
1639                         hctx->remote_conn      = con;
1640                         hctx->plugin_data      = p;
1641                         hctx->host             = host;
1642 -                       hctx->proc             = NULL;
1643 +                       hctx->proc             = NULL;
1644  
1645                         hctx->conf.exts        = p->conf.exts;
1646                         hctx->conf.debug       = p->conf.debug;
1647 @@ -2812,22 +2800,69 @@
1648                         con->mode = p->id;
1649  
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");
1654                         }
1655  
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"
1660 +                        *
1661 +                        * if prefix = /admin.fcgi
1662 +                        *
1663 +                        * /admin.fcgi/foo/bar
1664 +                        *
1665 +                        * SCRIPT_NAME = /admin.fcgi
1666 +                        * PATH_INFO   = /foo/bar
1667 +                        *
1668 +                        * if prefix = /fcgi-bin/
1669 +                        *
1670 +                        * /fcgi-bin/foo/bar
1671 +                        *
1672 +                        * SCRIPT_NAME = /fcgi-bin/foo
1673 +                        * PATH_INFO   = /bar
1674 +                        *
1675 +                        */
1676 +
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 */
1682 +
1683 +                               buffer_copy_string(con->request.pathinfo, pathinfo);
1684 +
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';
1691 +                       }
1692                 }
1693         } else {
1694 -               /* no handler found */
1695 -               buffer_reset(con->physical.path);
1696 -               con->http_status = 500;
1697 +               handler_ctx *hctx;
1698 +               hctx = handler_ctx_init();
1699  
1700 -               log_error_write(srv, __FILE__, __LINE__,  "sb",
1701 -                               "no fcgi-handler found for:",
1702 -                               fn);
1703 +               hctx->remote_conn      = con;
1704 +               hctx->plugin_data      = p;
1705 +               hctx->host             = host;
1706 +               hctx->proc             = NULL;
1707  
1708 -               return HANDLER_FINISHED;
1709 +               hctx->conf.exts        = p->conf.exts;
1710 +               hctx->conf.debug       = p->conf.debug;
1711 +
1712 +               con->plugin_ctx[p->id] = hctx;
1713 +
1714 +               host->load++;
1715 +
1716 +               con->mode = p->id;
1717 +
1718 +               if (con->conf.log_request_handling) {
1719 +                       log_error_write(srv, __FILE__, __LINE__, "s", "handling it in mod_fastcgi");
1720 +               }
1721         }
1722 +
1723         return HANDLER_GO_ON;
1724  }
1725  
1726 @@ -2949,7 +2984,7 @@
1727                                                 fp->port = host->port + fp->id;
1728                                         } else {
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);
1733                                         }
1734  
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)
1739 @@ -410,6 +410,7 @@
1740  
1741  ERR500:        if (result) mysql_free_result(result);
1742         con->http_status = 500; /* Internal Error */
1743 +       con->mode = DIRECT;
1744         return HANDLER_FINISHED;
1745  }
1746  
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)
1751 @@ -193,6 +193,8 @@
1752  
1753         UNUSED(srv);
1754  
1755 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
1756 +
1757         if (buffer_is_empty(con->physical.path)) return HANDLER_GO_ON;
1758  
1759         mod_flv_streaming_patch_connection(srv, con, p);
1760 @@ -245,7 +247,7 @@
1761  
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"));
1766  
1767                         http_chunk_append_file(srv, con, con->physical.path, start, sce->st.st_size - start);
1768  
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)
1773 @@ -28,9 +28,12 @@
1774  static volatile sig_atomic_t graceful_restart = 0;
1775  static volatile pid_t pid = -1;
1776  
1777 +#define UNUSED(x) ( (void)(x) )
1778 +
1779  static void sigaction_handler(int sig, siginfo_t *si, void *context) {
1780         int exitcode;
1781  
1782 +       UNUSED(context);
1783         switch (sig) {
1784         case SIGINT: 
1785         case SIGTERM:
1786 @@ -60,6 +63,8 @@
1787         int is_shutdown = 0;
1788         struct sigaction act;
1789  
1790 +       UNUSED(argc);
1791 +
1792         /**
1793          * we are running as root BEWARE
1794          */
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)
1799 @@ -148,6 +148,8 @@
1800                 args[i++] = dash;
1801                 args[i++] = NULL;
1802  
1803 +               openDevNull(STDERR_FILENO);
1804 +       
1805                 /* we don't need the client socket */
1806                 for (i = 3; i < 256; i++) {
1807                         close(i);
1808 @@ -156,7 +158,7 @@
1809                 /* exec the cgi */
1810                 execv(args[0], args);
1811  
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]); */
1814  
1815                 /* */
1816                 SEGFAULT();
1817 @@ -202,24 +204,25 @@
1818                 int r ;
1819                 /* create a new one */
1820  
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(
1841 +                       " --step 60 "
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"));
1857  
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 @@
1861  
1862                 if (HANDLER_GO_ON != mod_rrdtool_create_rrd(srv, p, s)) return HANDLER_ERROR;
1863  
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"));
1878  
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)
1885 @@ -59,7 +59,7 @@
1886                         t->offset++;
1887                         t->line_pos++;
1888  
1889 -                       buffer_copy_string(token, "(=)");
1890 +                       buffer_copy_string_len(token, CONST_STR_LEN("(=)"));
1891  
1892                         break;
1893                 case '>':
1894 @@ -69,14 +69,14 @@
1895  
1896                                 tid = TK_GE;
1897  
1898 -                               buffer_copy_string(token, "(>=)");
1899 +                               buffer_copy_string_len(token, CONST_STR_LEN("(>=)"));
1900                         } else {
1901                                 t->offset += 1;
1902                                 t->line_pos += 1;
1903  
1904                                 tid = TK_GT;
1905  
1906 -                               buffer_copy_string(token, "(>)");
1907 +                               buffer_copy_string_len(token, CONST_STR_LEN("(>)"));
1908                         }
1909  
1910                         break;
1911 @@ -87,14 +87,14 @@
1912  
1913                                 tid = TK_LE;
1914  
1915 -                               buffer_copy_string(token, "(<=)");
1916 +                               buffer_copy_string_len(token, CONST_STR_LEN("(<=)"));
1917                         } else {
1918                                 t->offset += 1;
1919                                 t->line_pos += 1;
1920  
1921                                 tid = TK_LT;
1922  
1923 -                               buffer_copy_string(token, "(<)");
1924 +                               buffer_copy_string_len(token, CONST_STR_LEN("(<)"));
1925                         }
1926  
1927                         break;
1928 @@ -106,14 +106,14 @@
1929  
1930                                 tid = TK_NE;
1931  
1932 -                               buffer_copy_string(token, "(!=)");
1933 +                               buffer_copy_string_len(token, CONST_STR_LEN("(!=)"));
1934                         } else {
1935                                 t->offset += 1;
1936                                 t->line_pos += 1;
1937  
1938                                 tid = TK_NOT;
1939  
1940 -                               buffer_copy_string(token, "(!)");
1941 +                               buffer_copy_string_len(token, CONST_STR_LEN("(!)"));
1942                         }
1943  
1944                         break;
1945 @@ -124,7 +124,7 @@
1946  
1947                                 tid = TK_AND;
1948  
1949 -                               buffer_copy_string(token, "(&&)");
1950 +                               buffer_copy_string_len(token, CONST_STR_LEN("(&&)"));
1951                         } else {
1952                                 log_error_write(srv, __FILE__, __LINE__, "sds",
1953                                                 "pos:", t->line_pos,
1954 @@ -140,7 +140,7 @@
1955  
1956                                 tid = TK_OR;
1957  
1958 -                               buffer_copy_string(token, "(||)");
1959 +                               buffer_copy_string_len(token, CONST_STR_LEN("(||)"));
1960                         } else {
1961                                 log_error_write(srv, __FILE__, __LINE__, "sds",
1962                                                 "pos:", t->line_pos,
1963 @@ -183,7 +183,7 @@
1964  
1965                         tid = TK_LPARAN;
1966  
1967 -                       buffer_copy_string(token, "(");
1968 +                       buffer_copy_string_len(token, CONST_STR_LEN("("));
1969                         break;
1970                 case ')':
1971                         t->offset++;
1972 @@ -191,7 +191,7 @@
1973  
1974                         tid = TK_RPARAN;
1975  
1976 -                       buffer_copy_string(token, ")");
1977 +                       buffer_copy_string_len(token, CONST_STR_LEN(")"));
1978                         break;
1979                 case '$':
1980                         if (t->input[t->offset + 1] == '{') {
1981 @@ -219,7 +219,7 @@
1982                         } else if (NULL != (ds = (data_string *)array_get_element(p->ssi_vars, token->ptr))) {
1983                                 buffer_copy_string_buffer(token, ds->value);
1984                         } else {
1985 -                               buffer_copy_string(token, "");
1986 +                               buffer_copy_string_len(token, CONST_STR_LEN(""));
1987                         }
1988  
1989                         t->offset += i;
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)
1994 @@ -445,7 +445,9 @@
1995         /* dir-check */
1996         if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM) {
1997                 if (0 != buffer_copy_dirname(sc->dir_name, name)) {
1998 -                       SEGFAULT();
1999 +                       log_error_write(srv, __FILE__, __LINE__, "sb",
2000 +                               "no '/' found in filename:", name);
2001 +                       return HANDLER_ERROR;
2002                 }
2003  
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)
2009 @@ -35,21 +35,25 @@
2010         b = chunkqueue_get_prepend_buffer(con->write_queue);
2011  
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 "));
2015         } else {
2016 -               BUFFER_COPY_STRING_CONST(b, "HTTP/1.0 ");
2017 +               buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.0 "));
2018         }
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));
2023  
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"));
2030 +               } else {
2031 +                       buffer_append_string_len(b, CONST_STR_LEN("close"));
2032 +               }
2033         }
2034  
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"));
2038         }
2039  
2040  
2041 @@ -60,14 +64,15 @@
2042                 ds = (data_string *)con->response.headers->data[i];
2043  
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;
2054  
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(": "));
2060  #if 0
2061                         /** 
2062                          * the value might contain newlines, encode them with at least one white-space
2063 @@ -81,7 +86,7 @@
2064  
2065         if (!have_date) {
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: "));
2069  
2070                 /* cache the generated timestamp */
2071                 if (srv->cur_ts != srv->last_generated_date_ts) {
2072 @@ -100,14 +105,14 @@
2073  
2074         if (!have_server) {
2075                 if (buffer_is_empty(con->conf.server_tag)) {
2076 -                       BUFFER_APPEND_STRING_CONST(b, "\r\nServer: " PACKAGE_NAME "/" PACKAGE_VERSION);
2077 -               } else {
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);
2083                 }
2084         }
2085  
2086 -       BUFFER_APPEND_STRING_CONST(b, "\r\n\r\n");
2087 +       buffer_append_string_len(b, CONST_STR_LEN("\r\n\r\n"));
2088  
2089  
2090         con->bytes_header = b->used - 1;
2091 @@ -152,7 +157,7 @@
2092                  *  */
2093  
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. */
2097  
2098                 if (con->conf.log_condition_handling) {
2099                         log_error_write(srv, __FILE__, __LINE__,  "s",  "run condition");
2100 @@ -181,7 +186,11 @@
2101                  *
2102                  */
2103  
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"));
2107 +               } else {
2108 +                       buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("http"));
2109 +               }
2110                 buffer_copy_string_buffer(con->uri.authority, con->request.http_host);
2111                 buffer_to_lower(con->uri.authority);
2112  
2113 @@ -224,27 +233,6 @@
2114                 }
2115  
2116  
2117 -               /**
2118 -                *
2119 -                * call plugins
2120 -                *
2121 -                * - based on the raw URL
2122 -                *
2123 -                */
2124 -
2125 -               switch(r = plugins_call_handle_uri_raw(srv, con)) {
2126 -               case HANDLER_GO_ON:
2127 -                       break;
2128 -               case HANDLER_FINISHED:
2129 -               case HANDLER_COMEBACK:
2130 -               case HANDLER_WAIT_FOR_EVENT:
2131 -               case HANDLER_ERROR:
2132 -                       return r;
2133 -               default:
2134 -                       log_error_write(srv, __FILE__, __LINE__, "sd", "handle_uri_raw: unknown return value", r);
2135 -                       break;
2136 -               }
2137 -
2138                 /* build filename
2139                  *
2140                  * - decode url-encodings  (e.g. %20 -> ' ')
2141 @@ -252,7 +240,6 @@
2142                  */
2143  
2144  
2145 -
2146                 if (con->request.http_method == HTTP_METHOD_OPTIONS &&
2147                     con->uri.path_raw->ptr[0] == '*' && con->uri.path_raw->ptr[1] == '\0') {
2148                         /* OPTIONS * ... */
2149 @@ -268,10 +255,32 @@
2150                         log_error_write(srv, __FILE__, __LINE__,  "sb", "URI-path     : ", con->uri.path);
2151                 }
2152  
2153 +
2154                 /**
2155                  *
2156                  * call plugins
2157                  *
2158 +                * - based on the raw URL
2159 +                *
2160 +                */
2161 +
2162 +               switch(r = plugins_call_handle_uri_raw(srv, con)) {
2163 +               case HANDLER_GO_ON:
2164 +                       break;
2165 +               case HANDLER_FINISHED:
2166 +               case HANDLER_COMEBACK:
2167 +               case HANDLER_WAIT_FOR_EVENT:
2168 +               case HANDLER_ERROR:
2169 +                       return r;
2170 +               default:
2171 +                       log_error_write(srv, __FILE__, __LINE__, "sd", "handle_uri_raw: unknown return value", r);
2172 +                       break;
2173 +               }
2174 +
2175 +               /**
2176 +                *
2177 +                * call plugins
2178 +                *
2179                  * - based on the clean URL
2180                  *
2181                  */
2182 Index: src/plugin.c
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 @@
2187  
2188                 buffer_copy_string_buffer(srv->tmp_buf, srv->srvconf.modules_dir);
2189  
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"));
2196  #else
2197 -               buffer_append_string(srv->tmp_buf, ".so");
2198 +               buffer_append_string_len(srv->tmp_buf, CONST_STR_LEN(".so"));
2199  #endif
2200  
2201                 p = plugin_init();
2202 @@ -173,7 +173,7 @@
2203  #endif
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"));
2208  
2209  #ifdef __WIN32
2210                 init = GetProcAddress(p->lib, srv->tmp_buf->ptr);
2211 @@ -197,7 +197,7 @@
2212  
2213  #else
2214  #if 1
2215 -               init = (int (*)(plugin *))dlsym(p->lib, srv->tmp_buf->ptr);
2216 +               init = (int (*)(plugin *))(intptr_t)dlsym(p->lib, srv->tmp_buf->ptr);
2217  #else
2218                 *(void **)(&init) = dlsym(p->lib, srv->tmp_buf->ptr);
2219  #endif
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)
2224 @@ -43,6 +43,7 @@
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' ] },
2232 Index: src/buffer.c
2233 ===================================================================
2234 --- src/buffer.c        (.../tags/lighttpd-1.4.19)      (revision 2303)
2235 +++ src/buffer.c        (.../branches/lighttpd-1.4.x)   (revision 2303)
2236 @@ -55,6 +55,8 @@
2237                 free(b->ptr);
2238                 b->ptr = NULL;
2239                 b->size = 0;
2240 +       } else if (b->size) {
2241 +               b->ptr[0] = '\0';
2242         }
2243  
2244         b->used = 0;
2245 @@ -626,6 +628,7 @@
2246         return 0;
2247  }
2248  
2249 +/* everything except: ! ( ) * - . 0-9 A-Z _ a-z */
2250  const char encoded_chars_rel_uri_part[] = {
2251         /*
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 */
2272  };
2273  
2274 +/* everything except: ! ( ) * - . / 0-9 A-Z _ a-z */
2275  const char encoded_chars_rel_uri[] = {
2276         /*
2277         0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
2278         */
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)
2300 @@ -262,6 +262,9 @@
2301                                 return HANDLER_GO_ON;
2302                         }
2303                 }
2304 +               if (con->conf.force_lowercase_filenames) {
2305 +                       buffer_to_lower(p->username);
2306 +               }
2307  
2308                 buffer_copy_string_buffer(p->temp_path, p->conf.basepath);
2309                 BUFFER_APPEND_SLASH(p->temp_path);
2310 @@ -284,8 +287,24 @@
2311                 }
2312         }
2313  
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)
2320 +        */
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
2324 +        * on windows.
2325 +        * we do not care about the trailing slash here on windows, as we already ensured it is a directory
2326 +        *
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.
2329 +        */
2330 +       if (NULL != (rel_url = strchr(con->physical.rel_path->ptr + 2, '/'))) {
2331 +               buffer_append_string(p->temp_path, rel_url + 1); /* skip the / */
2332 +       }
2333         buffer_copy_string_buffer(con->physical.path, p->temp_path);
2334  
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 @@
2341  
2342         /* request line */
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(" "));
2346  
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"));
2350  
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;
2355  
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"));
2362                 }
2363         }
2364  
2365 -       BUFFER_APPEND_STRING_CONST(b, "\r\n");
2366 +       buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
2367  
2368         hctx->wb->bytes_in += b->used - 1;
2369         /* body */
2370 @@ -1060,6 +1060,8 @@
2371         data_array *extension = NULL;
2372         size_t path_info_offset;
2373  
2374 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
2375 +
2376         /* Possibly, we processed already this request */
2377         if (con->file_started == 1) return HANDLER_GO_ON;
2378  
2379 @@ -1118,7 +1120,13 @@
2380                 log_error_write(srv, __FILE__, __LINE__,  "s", "proxy - ext found");
2381         }
2382  
2383 -       switch(p->conf.balance) {
2384 +       if (extension->value->used == 1) {
2385 +               if ( ((data_proxy *)extension->value->data[0])->is_disabled ) {
2386 +                       ndx = -1;
2387 +               } else {
2388 +                       ndx = 0;
2389 +               }
2390 +       } else if (extension->value->used != 0) switch(p->conf.balance) {
2391         case PROXY_BALANCE_HASH:
2392                 /* hash balancing */
2393  
2394 @@ -1175,7 +1183,9 @@
2395                 }
2396  
2397                 break;
2398 -       case PROXY_BALANCE_RR:
2399 +       case PROXY_BALANCE_RR: {
2400 +               data_proxy *host;
2401 +
2402                 /* round robin */
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);
2408  
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];
2412  
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;
2417  
2418 -                       /* first usable ndx */
2419 -                       if (max_usage == INT_MAX) {
2420 -                               max_usage = k;
2421 -                       }
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++;
2425  
2426 -                       /* get next ndx */
2427 -                       if ((int)k > host->last_used_ndx) {
2428 -                               ndx = k;
2429 -                               host->last_used_ndx = k;
2430 -
2431 -                               break;
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;
2437                         }
2438 -               }
2439  
2440 -               /* didn't found a higher id, wrap to the start */
2441 -               if (ndx == -1 && max_usage != INT_MAX) {
2442 -                       ndx = max_usage;
2443 +                       /* No active host found */
2444 +                       if (host->is_disabled) ndx = -1;
2445                 }
2446  
2447 +               /* Save new index for next round */
2448 +               ((data_proxy *)extension->value->data[0])->last_used_ndx = ndx;
2449 +
2450                 break;
2451 +       }
2452         default:
2453                 break;
2454         }
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)
2459 @@ -281,8 +281,9 @@
2460  static const char *last_not_in_array(array *a, plugin_data *p)
2461  {
2462         array *forwarder = p->conf.forwarder;
2463 +       int i;
2464  
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;
2469  
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)
2474 @@ -3,7 +3,7 @@
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)
2480  
2481  lemon_SOURCES=lemon.c
2482  
2483 @@ -15,21 +15,26 @@
2484  if CROSS_COMPILING
2485  configparser.c configparser.h:
2486  mod_ssi_exprparser.c mod_ssi_exprparser.h:
2487 +
2488 +.PHONY: parsers
2489 +parsers:
2490  else
2491 -$(srcdir)/configparser.y: lemon
2492 -$(srcdir)/mod_ssi_exprparser.y: lemon
2493 -
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
2499  
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
2505 +
2506 +.PHONY: parsers
2507 +parsers: configparser.c mod_ssi_exprparser.c
2508  endif
2509  
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
2514  
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)
2521 @@ -339,7 +339,7 @@
2522                         response_header_overwrite(srv, con, CONST_STR_LEN("Expires"), CONST_BUF_LEN(p->expire_tstmp));
2523  
2524                         /* HTTP/1.1 */
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);
2528  
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)
2534 @@ -85,6 +85,7 @@
2535                          *
2536                          */
2537  
2538 +                       ERR_clear_error();
2539                         if ((r = SSL_write(ssl, offset, toSend)) <= 0) {
2540                                 unsigned long err;
2541  
2542 @@ -187,6 +188,7 @@
2543  
2544                                 close(ifd);
2545  
2546 +                               ERR_clear_error();
2547                                 if ((r = SSL_write(ssl, s, toSend)) <= 0) {
2548                                         unsigned long err;
2549  
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)
2554 @@ -166,6 +166,7 @@
2555                         if (-1 == sendfile(c->file.fd, fd, offset, toSend, NULL, &r, 0)) {
2556                                 switch(errno) {
2557                                 case EAGAIN:
2558 +                               case EINTR:
2559                                         break;
2560                                 case ENOTCONN:
2561                                         return -2;
2562 @@ -175,7 +176,7 @@
2563                                 }
2564                         }
2565  
2566 -                       if (r == 0) {
2567 +                       if (r == 0 && (errno != EAGAIN && errno != EINTR)) {
2568                                 int oerrno = errno;
2569                                 /* We got an event to write but we wrote nothing
2570                                  *
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)
2575 @@ -215,8 +215,7 @@
2576  
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] == '%') {
2582                                         /* got one */
2583  
2584                                         size_t num = pattern[k + 1] - '0';
2585 @@ -225,7 +224,10 @@
2586  
2587                                         buffer_append_string_len(p->location, pattern + start, end - start);
2588  
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]);
2597 @@ -251,6 +253,7 @@
2598                         response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->location));
2599  
2600                         con->http_status = 301;
2601 +                       con->mode = DIRECT;
2602                         con->file_finished = 1;
2603  
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)
2609 @@ -697,7 +697,7 @@
2610                 }
2611         } else if (p->conf.auth_backend == AUTH_BACKEND_LDAP) {
2612  #ifdef USE_LDAP
2613 -               LDAP *ldap;
2614 +               LDAP *ldap = NULL;
2615                 LDAPMessage *lm, *first;
2616                 char *dn;
2617                 int ret;
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);
2621  
2622 -
2623                 /* 2. */
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)
2627 -                               return -1;
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)
2632 +                                       return -1;
2633  
2634 -                       log_error_write(srv, __FILE__, __LINE__, "sssb",
2635 -                                       "ldap:", ldap_err2string(ret), "filter:", p->ldap_filter);
2636 -
2637 -                       return -1;
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);
2644 +                                       return -1;
2645 +                               }
2646                         }
2647                 }
2648  
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 ..."); */
2653  
2654                         ldap_msgfree(lm);
2655  
2656 +                       /* destroy temporary ldap connection (TODO: redo ldap) */
2657 +                       if (NULL != ldap) {
2658 +                               ldap_unbind_s(ldap);
2659 +                       }
2660                         return -1;
2661                 }
2662  
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");
2666  
2667                         ldap_msgfree(lm);
2668  
2669 +                       /* destroy temporary ldap connection (TODO: redo ldap) */
2670 +                       if (NULL != ldap) {
2671 +                               ldap_unbind_s(ldap);
2672 +                       }
2673                         return -1;
2674                 }
2675  
2676                 ldap_msgfree(lm);
2677  
2678 +               /* destroy temporary ldap connection (TODO: redo ldap) */
2679 +               if (NULL != ldap) {
2680 +                       ldap_unbind_s(ldap);
2681 +               }
2682  
2683                 /* 3. */
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)
2689 @@ -103,7 +103,7 @@
2690                 }
2691  
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"));
2695                 } else {
2696                         size_t j;
2697                         for (j = 0; j < s->cookie_name->used - 1; j++) {
2698 @@ -214,9 +214,9 @@
2699         if (NULL == (ds = (data_string *)array_get_unused_element(con->response.headers, TYPE_STRING))) {
2700                 ds = data_response_init();
2701         }
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("="));
2707  
2708  
2709         /* taken from mod_auth.c */
2710 @@ -235,16 +235,16 @@
2711         MD5_Final(h, &Md5Ctx);
2712  
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"));
2718  
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);
2723         }
2724  
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);
2729         }
2730  
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 @@
2736         UNUSED(con);
2737  
2738         if (value) {
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("\">"));
2747  
2748                 buffer_append_string(b, value);
2749  
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(">"));
2755         } else {
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("\"/>"));
2764         }
2765  
2766         return 0;
2767 @@ -511,24 +511,24 @@
2768  static int webdav_gen_response_status_tag(server *srv, connection *con, physical *dst, int status, buffer *b) {
2769         UNUSED(srv);
2770  
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"));
2773  
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"));
2781  
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 "));
2785         } else {
2786 -               BUFFER_COPY_STRING_CONST(b, "HTTP/1.0 ");
2787 +               buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.0 "));
2788         }
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));
2793  
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"));
2798  
2799         return 0;
2800  }
2801 @@ -570,6 +570,8 @@
2802                                 /* */
2803                         }
2804                 }
2805 +#else
2806 +               UNUSED(p);
2807  #endif
2808         }
2809  
2810 @@ -730,6 +732,8 @@
2811                         }
2812                 }
2813         }
2814 +#else
2815 +       UNUSED(p);
2816  #endif
2817         return status;
2818  }
2819 @@ -840,12 +844,12 @@
2820  
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>"));
2825                                 found = 1;
2826                         }
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>"));
2831                                 found = 1;
2832                         } else if(S_ISREG(sce->st.st_mode)) {
2833                                 for (k = 0; k < con->conf.mimetypes->used; k++) {
2834 @@ -854,9 +858,9 @@
2835                                         if (ds->key->used == 0) continue;
2836  
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>"));
2843                                                 found = 1;
2844  
2845                                                 break;
2846 @@ -864,26 +868,26 @@
2847                                 }
2848                         }
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>"));
2856                         found = 1;
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>"));
2864                         found = 1;
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>"));
2871                         found = 1;
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>"));
2879                         found = 1;
2880                 }
2881         }
2882 @@ -1103,44 +1107,44 @@
2883  
2884         b = chunkqueue_get_append_buffer(con->write_queue);
2885  
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"));
2888  
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"));
2895  
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"));
2905  
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"));
2915  
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"));
2921  
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"));
2928  
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"));
2933  
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"));
2943  
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"));
2950  
2951         return 0;
2952  }
2953 @@ -1154,6 +1158,7 @@
2954         int has_lock = 1;
2955  
2956  #ifdef USE_LOCKS
2957 +       UNUSED(srv);
2958         data_string *ds;
2959  
2960         /**
2961 @@ -1192,6 +1197,11 @@
2962                         has_lock = 0;
2963                 }
2964         }
2965 +#else
2966 +       UNUSED(srv);
2967 +       UNUSED(con);
2968 +       UNUSED(p);
2969 +       UNUSED(uri);
2970  #endif
2971  
2972         return has_lock;
2973 @@ -1334,9 +1344,9 @@
2974  
2975                 b = chunkqueue_get_append_buffer(con->write_queue);
2976  
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"));
2979  
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"));
2982  
2983                 /* allprop */
2984  
2985 @@ -1348,40 +1358,40 @@
2986                         /* Depth: 0 */
2987                         webdav_get_props(srv, con, p, &(con->physical), req_props, prop_200, prop_404);
2988  
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"));
3000  
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"));
3006  
3007                                 buffer_append_string_buffer(b, prop_200);
3008  
3009 -                               buffer_append_string(b,"</D:prop>\n");
3010 +                               buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
3011  
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"));
3014  
3015 -                               buffer_append_string(b,"</D:propstat>\n");
3016 +                               buffer_append_string_len(b,CONST_STR_LEN("</D:propstat>\n"));
3017                         }
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"));
3023  
3024                                 buffer_append_string_buffer(b, prop_404);
3025  
3026 -                               buffer_append_string(b,"</D:prop>\n");
3027 +                               buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
3028  
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"));
3031  
3032 -                               buffer_append_string(b,"</D:propstat>\n");
3033 +                               buffer_append_string_len(b,CONST_STR_LEN("</D:propstat>\n"));
3034                         }
3035  
3036 -                       buffer_append_string(b,"</D:response>\n");
3037 +                       buffer_append_string_len(b,CONST_STR_LEN("</D:response>\n"));
3038  
3039                         break;
3040                 case 1:
3041 @@ -1417,40 +1427,40 @@
3042  
3043                                         webdav_get_props(srv, con, p, &d, req_props, prop_200, prop_404);
3044  
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"));
3056  
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"));
3062  
3063                                                 buffer_append_string_buffer(b, prop_200);
3064  
3065 -                                               buffer_append_string(b,"</D:prop>\n");
3066 +                                               buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
3067  
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"));
3070  
3071 -                                               buffer_append_string(b,"</D:propstat>\n");
3072 +                                               buffer_append_string_len(b,CONST_STR_LEN("</D:propstat>\n"));
3073                                         }
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"));
3079  
3080                                                 buffer_append_string_buffer(b, prop_404);
3081  
3082 -                                               buffer_append_string(b,"</D:prop>\n");
3083 +                                               buffer_append_string_len(b,CONST_STR_LEN("</D:prop>\n"));
3084  
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"));
3087  
3088 -                                               buffer_append_string(b,"</D:propstat>\n");
3089 +                                               buffer_append_string_len(b,CONST_STR_LEN("</D:propstat>\n"));
3090                                         }
3091  
3092 -                                       buffer_append_string(b,"</D:response>\n");
3093 +                                       buffer_append_string_len(b,CONST_STR_LEN("</D:response>\n"));
3094                                 }
3095                                 closedir(dir);
3096                                 buffer_free(d.path);
3097 @@ -1473,7 +1483,7 @@
3098                 buffer_free(prop_200);
3099                 buffer_free(prop_404);
3100  
3101 -               buffer_append_string(b,"</D:multistatus>\n");
3102 +               buffer_append_string_len(b,CONST_STR_LEN("</D:multistatus>\n"));
3103  
3104                 if (p->conf.log_xml) {
3105                         log_error_write(srv, __FILE__, __LINE__, "sb", "XML-response-body:", b);
3106 @@ -1548,13 +1558,13 @@
3107  
3108                                 b = chunkqueue_get_append_buffer(con->write_queue);
3109  
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"));
3112  
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"));
3115  
3116                                 buffer_append_string_buffer(b, multi_status_resp);
3117  
3118 -                               buffer_append_string(b,"</D:multistatus>\n");
3119 +                               buffer_append_string_len(b,CONST_STR_LEN("</D:multistatus>\n"));
3120  
3121                                 if (p->conf.log_xml) {
3122                                         log_error_write(srv, __FILE__, __LINE__, "sb", "XML-response-body:", b);
3123 @@ -2286,7 +2296,7 @@
3124                                                         uuid_generate(id);
3125                                                         uuid_unparse(id, uuid);
3126  
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);
3130  
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)
3136 @@ -21,6 +21,10 @@
3137      dc->parent = ctx->current;
3138      array_insert_unique(dc->parent->childs, (data_unset *)dc);
3139    }
3140 +  if (ctx->configs_stack->used > 0 && ctx->current->context_ndx == 0) {
3141 +    fprintf(stderr, "Cannot use conditionals inside a global { ... } block\n");
3142 +    exit(-1);
3143 +  }
3144    array_insert_unique(ctx->configs_stack, (data_unset *)ctx->current);
3145    ctx->current = dc;
3146  }
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 @@
3152  
3153  
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"));
3169  
3170         return 0;
3171  }
3172  
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"));
3183  
3184         return 0;
3185  }
3186 @@ -169,13 +169,13 @@
3187         plugin_data *p = p_d;
3188  
3189         if (p->conf.sort) {
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"));
3195         } else {
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"));
3201         }
3202  
3203         return 0;
3204 @@ -209,15 +209,14 @@
3205  
3206         b = chunkqueue_get_append_buffer(con->write_queue);
3207  
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"
3214                                  " <head>\n"
3215 -                                "  <title>Status</title>\n");
3216 +                                "  <title>Status</title>\n"
3217  
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"
3226 -                                  "  </style>\n");
3227 +                                  "  </style>\n"));
3228  
3229         if (p->conf.sort) {
3230 -               BUFFER_APPEND_STRING_CONST(b,
3231 +               buffer_append_string_len(b, CONST_STR_LEN(
3232                                            "<script type=\"text/javascript\">\n"
3233                                            "// <!--\n"
3234                                            "var sort_column;\n"
3235 -                                          "var prev_span = null;\n");
3236 +                                          "var prev_span = null;\n"
3237  
3238 -               BUFFER_APPEND_STRING_CONST(b,
3239                                            "function get_inner_text(el) {\n"
3240                                            " if((typeof el == 'string')||(typeof el == 'undefined'))\n"
3241                                            "  return el;\n"
3242 @@ -251,9 +249,8 @@
3243                                            "  }\n"
3244                                            " }\n"
3245                                            " return str;\n"
3246 -                                          "}\n");
3247 +                                          "}\n"
3248  
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"
3253 @@ -266,9 +263,8 @@
3254                                            "  else if (aa<bb) return -1;\n"
3255                                            "  else return 1;\n"
3256                                            " }\n"
3257 -                                          "}\n");
3258 +                                          "}\n"
3259  
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"
3264 @@ -276,9 +272,8 @@
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"
3270  
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 = '&uarr;';\n"
3275 @@ -293,25 +288,25 @@
3276                                            " prev_span = span;\n"
3277                                            "}\n"
3278                                            "// -->\n"
3279 -                                          "</script>\n");
3280 +                                          "</script>\n"));
3281         }
3282  
3283 -       BUFFER_APPEND_STRING_CONST(b,
3284 +       buffer_append_string_len(b, CONST_STR_LEN(
3285                                  " </head>\n"
3286 -                                " <body>\n");
3287 +                                " <body>\n"));
3288  
3289  
3290  
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>"));
3294  
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\">"));
3307  
3308         ts = srv->cur_ts - srv->startup_ts;
3309  
3310 @@ -328,98 +323,98 @@
3311  
3312         if (days) {
3313                 buffer_append_long(b, days);
3314 -               BUFFER_APPEND_STRING_CONST(b, " days ");
3315 +               buffer_append_string_len(b, CONST_STR_LEN(" days "));
3316         }
3317  
3318         if (hours) {
3319                 buffer_append_long(b, hours);
3320 -               BUFFER_APPEND_STRING_CONST(b, " hours ");
3321 +               buffer_append_string_len(b, CONST_STR_LEN(" hours "));
3322         }
3323  
3324         if (mins) {
3325                 buffer_append_long(b, mins);
3326 -               BUFFER_APPEND_STRING_CONST(b, " min ");
3327 +               buffer_append_string_len(b, CONST_STR_LEN(" min "));
3328         }
3329  
3330         buffer_append_long(b, seconds);
3331 -       BUFFER_APPEND_STRING_CONST(b, " s");
3332 +       buffer_append_string_len(b, CONST_STR_LEN(" s"));
3333  
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\">"));
3338  
3339         ts = srv->startup_ts;
3340  
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"));
3345  
3346  
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"));
3349  
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;
3353  
3354         mod_status_get_multiplier(&avg, &multiplier, 1000);
3355  
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"));
3362  
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;
3366  
3367         mod_status_get_multiplier(&avg, &multiplier, 1024);
3368  
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"));
3376  
3377  
3378  
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"));
3381  
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);
3385  
3386         mod_status_get_multiplier(&avg, &multiplier, 1000);
3387  
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"));
3394  
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);
3398  
3399         mod_status_get_multiplier(&avg, &multiplier, 1024);
3400  
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"));
3408  
3409  
3410  
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];
3415         }
3416  
3417         avg /= 5;
3418  
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\">"));
3421  
3422         mod_status_get_multiplier(&avg, &multiplier, 1000);
3423  
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);
3428  
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"));
3431  
3432         for (j = 0, avg = 0; j < 5; j++) {
3433                 avg += p->mod_5s_traffic_out[j];
3434 @@ -427,28 +422,29 @@
3435  
3436         avg /= 5;
3437  
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\">"));
3440  
3441         mod_status_get_multiplier(&avg, &multiplier, 1024);
3442  
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"));
3450  
3451 -       BUFFER_APPEND_STRING_CONST(b, "</table>\n");
3452 +       buffer_append_string_len(b, CONST_STR_LEN("</table>\n"));
3453  
3454  
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"));
3466  
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"));
3472  
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);
3477  
3478                 if (((j + 1) % 50) == 0) {
3479 -                       BUFFER_APPEND_STRING_CONST(b, "\n");
3480 +                       buffer_append_string_len(b, CONST_STR_LEN("\n"));
3481                 }
3482         }
3483  
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"));
3486  
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"));
3500  
3501         for (j = 0; j < srv->conns->used; j++) {
3502                 connection *c = srv->conns->ptr[j];
3503  
3504 -               BUFFER_APPEND_STRING_CONST(b, "<tr><td class=\"string\">");
3505 +               buffer_append_string_len(b, CONST_STR_LEN("<tr><td class=\"string\">"));
3506  
3507                 buffer_append_string(b, inet_ntop_cache_get_ip(srv, &(c->dst_addr)));
3508  
3509 -               BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
3510 +               buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
3511  
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);
3517                 } else {
3518 -                       BUFFER_APPEND_STRING_CONST(b, "0/0");
3519 +                       buffer_append_string_len(b, CONST_STR_LEN("0/0"));
3520                 }
3521  
3522 -               BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
3523 +               buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
3524  
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));
3529  
3530 -               BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
3531 +               buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
3532  
3533                 buffer_append_string(b, connection_get_state(c->state));
3534  
3535 -               BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
3536 +               buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
3537  
3538                 buffer_append_long(b, srv->cur_ts - c->request_start);
3539  
3540 -               BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
3541 +               buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
3542  
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);
3547                 }
3548  
3549 -               BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
3550 +               buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
3551  
3552                 if (!buffer_is_empty(c->uri.path)) {
3553                         buffer_append_string_encoded(b, CONST_BUF_LEN(c->uri.path), ENCODING_HTML);
3554                 }
3555  
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);
3560                 }
3561  
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(")"));
3568                 }
3569 -               BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
3570 +               buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"string\">"));
3571  
3572                 buffer_append_string_buffer(b, c->physical.path);
3573  
3574 -               BUFFER_APPEND_STRING_CONST(b, "</td></tr>\n");
3575 +               buffer_append_string_len(b, CONST_STR_LEN("</td></tr>\n"));
3576         }
3577  
3578  
3579 -       BUFFER_APPEND_STRING_CONST(b,
3580 -                     "</table>\n");
3581 +       buffer_append_string_len(b, CONST_STR_LEN(
3582 +                     "</table>\n"));
3583  
3584  
3585 -       BUFFER_APPEND_STRING_CONST(b,
3586 +       buffer_append_string_len(b, CONST_STR_LEN(
3587                       " </body>\n"
3588                       "</html>\n"
3589 -                     );
3590 +                     ));
3591  
3592         response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
3593  
3594 @@ -566,45 +562,45 @@
3595         b = chunkqueue_get_append_buffer(con->write_queue);
3596  
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"));
3605  
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"));
3614  
3615         /* output uptime */
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"));
3622  
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"));
3629  
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"));
3635  
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);
3643         }
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("_"));
3647         }
3648 -       BUFFER_APPEND_STRING_CONST(b, "\n");
3649 +       buffer_append_string_len(b, CONST_STR_LEN("\n"));
3650  
3651         /* set text/plain output */
3652  
3653 @@ -633,9 +629,9 @@
3654                 size_t ndx = st->sorted[i];
3655  
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"));
3662         }
3663  
3664         response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/plain"));
3665 @@ -696,7 +692,7 @@
3666  
3667         b = chunkqueue_get_append_buffer(con->write_queue);
3668  
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"
3674 @@ -706,7 +702,7 @@
3675                            " </head>\n"
3676                            " <body>\n"
3677                            "  <h1>" PACKAGE_NAME " " PACKAGE_VERSION "</h1>\n"
3678 -                          "  <table summary=\"status\" border=\"1\">\n");
3679 +                          "  <table summary=\"status\" border=\"1\">\n"));
3680  
3681         mod_status_header_append(b, "Server-Features");
3682  #ifdef HAVE_PCRE_H
3683 @@ -733,19 +729,19 @@
3684                 if (i == 0) {
3685                         buffer_copy_string_buffer(m, pl->name);
3686                 } else {
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);
3690                 }
3691         }
3692  
3693         mod_status_row_append(b, "Loaded Modules", m->ptr);
3694  
3695 -       BUFFER_APPEND_STRING_CONST(b, "  </table>\n");
3696 +       buffer_append_string_len(b, CONST_STR_LEN("  </table>\n"));
3697  
3698 -       BUFFER_APPEND_STRING_CONST(b,
3699 +       buffer_append_string_len(b, CONST_STR_LEN(
3700                       " </body>\n"
3701                       "</html>\n"
3702 -                     );
3703 +                     ));
3704  
3705         response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
3706  
3707 @@ -796,6 +792,8 @@
3708  static handler_t mod_status_handler(server *srv, connection *con, void *p_d) {
3709         plugin_data *p = p_d;
3710  
3711 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
3712 +
3713         mod_status_patch_connection(srv, con, p);
3714  
3715         if (!buffer_is_empty(p->conf.status_url) &&
3716 Index: src/md5.c
3717 ===================================================================
3718 --- src/md5.c   (.../tags/lighttpd-1.4.19)      (revision 2303)
3719 +++ src/md5.c   (.../branches/lighttpd-1.4.x)   (revision 2303)
3720 @@ -52,9 +52,9 @@
3721  #define S43 15
3722  #define S44 21
3723  
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);
3729  
3730  #ifdef HAVE_MEMCPY
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
3734    context.
3735   */
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 */
3742  {
3743    unsigned int i, ndx, partLen;
3744 +  const unsigned char *input = (const unsigned char*) _input;
3745  
3746    /* Compute number of bytes mod 64 */
3747    ndx = (unsigned int)((context->count[0] >> 3) & 0x3F);
3748 @@ -200,7 +201,7 @@
3749   */
3750  static void MD5Transform (state, block)
3751  UINT4 state[4];
3752 -unsigned char block[64];
3753 +const unsigned char block[64];
3754  {
3755    UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
3756  
3757 @@ -313,7 +314,7 @@
3758   */
3759  static void Decode (output, input, len)
3760  UINT4 *output;
3761 -unsigned char *input;
3762 +const unsigned char *input;
3763  unsigned int len;
3764  {
3765    unsigned int i, j;
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)
3770 @@ -102,7 +102,7 @@
3771         return HANDLER_GO_ON;
3772  }
3773  
3774 -// 0 on success, -1 for error
3775 +/* 0 on success, -1 for error */
3776  int mkdir_recursive(char *dir) {
3777         char *p = dir;
3778  
3779 @@ -118,13 +118,13 @@
3780                 }
3781  
3782                 *p++ = '/';
3783 -               if (!*p) return 0; // Ignore trailing slash
3784 +               if (!*p) return 0; /* Ignore trailing slash */
3785         }
3786  
3787         return (mkdir(dir, 0700) != 0) && (errno != EEXIST) ? -1 : 0;
3788  }
3789  
3790 -// 0 on success, -1 for error
3791 +/* 0 on success, -1 for error */
3792  int mkdir_for_file(char *filename) {
3793         char *p = filename;
3794  
3795 @@ -140,7 +140,7 @@
3796                 }
3797  
3798                 *p++ = '/';
3799 -               if (!*p) return -1; // Unexpected trailing slash in filename
3800 +               if (!*p) return -1; /* Unexpected trailing slash in filename */
3801         }
3802  
3803         return 0;
3804 @@ -178,9 +178,9 @@
3805                 }
3806  
3807                 if (!buffer_is_empty(s->compress_cache_dir)) {
3808 +                       struct stat st;
3809                         mkdir_recursive(s->compress_cache_dir->ptr);
3810  
3811 -                       struct stat st;
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 @@
3816  
3817         switch(type) {
3818         case HTTP_ACCEPT_ENCODING_GZIP:
3819 -               buffer_append_string(p->ofn, "-gzip-");
3820 +               buffer_append_string_len(p->ofn, CONST_STR_LEN("-gzip-"));
3821                 break;
3822         case HTTP_ACCEPT_ENCODING_DEFLATE:
3823 -               buffer_append_string(p->ofn, "-deflate-");
3824 +               buffer_append_string_len(p->ofn, CONST_STR_LEN("-deflate-"));
3825                 break;
3826         case HTTP_ACCEPT_ENCODING_BZIP2:
3827 -               buffer_append_string(p->ofn, "-bzip2-");
3828 +               buffer_append_string_len(p->ofn, CONST_STR_LEN("-bzip2-"));
3829                 break;
3830         default:
3831                 log_error_write(srv, __FILE__, __LINE__, "sd", "unknown compression type", type);
3832 Index: src/md5.h
3833 ===================================================================
3834 --- src/md5.h   (.../tags/lighttpd-1.4.19)      (revision 2303)
3835 +++ src/md5.h   (.../branches/lighttpd-1.4.x)   (revision 2303)
3836 @@ -42,6 +42,6 @@
3837  } MD5_CTX;
3838  
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 *);
3843  
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)
3848 @@ -177,7 +177,7 @@
3849                         }
3850  
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--;
3855                         }
3856  
3857 @@ -419,7 +419,7 @@
3858  
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)"));
3863                         } else {
3864                                 buffer_copy_string(b, buf);
3865                         }
3866 @@ -430,7 +430,7 @@
3867  
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)"));
3872                         } else {
3873                                 buffer_copy_string(b, buf);
3874                         }
3875 @@ -441,7 +441,7 @@
3876  
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)"));
3881                         } else {
3882                                 buffer_copy_string(b, buf);
3883                         }
3884 @@ -472,7 +472,7 @@
3885                         if (NULL != (ds = (data_string *)array_get_element(p->ssi_cgi_env, var_val))) {
3886                                 buffer_copy_string_buffer(b, ds->value);
3887                         } else {
3888 -                               buffer_copy_string(b, "(none)");
3889 +                               buffer_copy_string_len(b, CONST_STR_LEN("(none)"));
3890                         }
3891  
3892                         break;
3893 @@ -519,7 +519,7 @@
3894                 if (file_path) {
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("/"));
3899                         } else {
3900                                 buffer_copy_string_len(p->stat_fn, con->physical.path->ptr, sl - con->physical.path->ptr + 1);
3901                         }
3902 @@ -573,7 +573,7 @@
3903                         case SSI_FLASTMOD:
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)"));
3908                                 } else {
3909                                         buffer_copy_string(b, buf);
3910                                 }
3911 @@ -656,17 +656,17 @@
3912                 if (p->if_is_false) break;
3913  
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]];
3919  
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 />"));
3926  
3927                 }
3928 -               buffer_append_string(b, "</pre>");
3929 +               buffer_append_string_len(b, CONST_STR_LEN("</pre>"));
3930  
3931                 break;
3932         case SSI_EXEC: {
3933 @@ -924,7 +924,7 @@
3934  
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"));
3939         p->sizefmt = 0;
3940         build_ssi_cgi_vars(srv, con, p);
3941         p->if_is_false = 0;
3942 @@ -1027,6 +1027,7 @@
3943  
3944         con->file_started  = 1;
3945         con->file_finished = 1;
3946 +       con->mode = p->id;
3947  
3948         response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
3949  
3950 @@ -1094,6 +1095,8 @@
3951         plugin_data *p = p_d;
3952         size_t k;
3953  
3954 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
3955 +
3956         if (con->physical.path->used == 0) return HANDLER_GO_ON;
3957  
3958         mod_ssi_patch_connection(srv, con, p);
3959 @@ -1109,6 +1112,7 @@
3960                         if (mod_ssi_handle_request(srv, con, p)) {
3961                                 /* on error */
3962                                 con->http_status = 500;
3963 +                               con->mode = DIRECT;
3964                         }
3965  
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)
3971 @@ -37,9 +37,9 @@
3972  #endif
3973  
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) {
3977         int fcgi_fd;
3978 -       int socket_type, status;
3979 +       int socket_type, status, rc = 0;
3980         struct timeval tv = { 0, 100 * 1000 };
3981  
3982         struct sockaddr_un fcgi_addr_un;
3983 @@ -48,9 +48,6 @@
3984  
3985         socklen_t servlen;
3986  
3987 -       pid_t child;
3988 -       int val;
3989 -
3990         if (child_count < 2) {
3991                 child_count = 5;
3992         }
3993 @@ -74,25 +71,6 @@
3994  #endif
3995                 socket_type = AF_UNIX;
3996                 fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
3997 -
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
4000 -                */
4001 -               if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
4002 -                       fprintf(stderr, "%s.%d\n",
4003 -                               __FILE__, __LINE__);
4004 -                       return -1;
4005 -               }
4006 -
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__);
4010 -                       return -1;
4011 -               }
4012 -
4013 -               /* cleanup previous socket if it exists */
4014 -               unlink(unixsocket);
4015 -               close(fcgi_fd);
4016         } else {
4017                 fcgi_addr_in.sin_family = AF_INET;
4018                  if (addr != NULL) {
4019 @@ -107,133 +85,176 @@
4020                 fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
4021         }
4022  
4023 -       /* open socket */
4024         if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
4025                 fprintf(stderr, "%s.%d\n",
4026                         __FILE__, __LINE__);
4027                 return -1;
4028         }
4029  
4030 -       val = 1;
4031 -       if (setsockopt(fcgi_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
4032 -               fprintf(stderr, "%s.%d\n",
4033 -                       __FILE__, __LINE__);
4034 -               return -1;
4035 -       }
4036 +       if (-1 == connect(fcgi_fd, fcgi_addr, servlen)) {
4037 +               /* server is not up, spawn in  */
4038 +               pid_t child;
4039 +               int val;
4040  
4041 -       /* create socket */
4042 -       if (-1 == bind(fcgi_fd, fcgi_addr, servlen)) {
4043 -               fprintf(stderr, "%s.%d: bind failed: %s\n",
4044 -                       __FILE__, __LINE__,
4045 -                       strerror(errno));
4046 -               return -1;
4047 -       }
4048 +               if (unixsocket) unlink(unixsocket);
4049  
4050 -       if (-1 == listen(fcgi_fd, 1024)) {
4051 -               fprintf(stderr, "%s.%d: fd = -1\n",
4052 -                       __FILE__, __LINE__);
4053 -               return -1;
4054 -       }
4055 +               close(fcgi_fd);
4056  
4057 -       if (!nofork) {
4058 -               child = fork();
4059 -       } else {
4060 -               child = 0;
4061 -       }
4062 +               /* reopen socket */
4063 +               if (-1 == (fcgi_fd = socket(socket_type, SOCK_STREAM, 0))) {
4064 +                       fprintf(stderr, "%s.%d\n",
4065 +                               __FILE__, __LINE__);
4066 +                       return -1;
4067 +               }
4068  
4069 -       switch (child) {
4070 -       case 0: {
4071 -               char cgi_childs[64];
4072 +               val = 1;
4073 +               if (setsockopt(fcgi_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) {
4074 +                       fprintf(stderr, "%s.%d\n",
4075 +                               __FILE__, __LINE__);
4076 +                       return -1;
4077 +               }
4078  
4079 -               int i = 0;
4080 -
4081 -               /* is safe as we limit to 256 childs */
4082 -               sprintf(cgi_childs, "PHP_FCGI_CHILDREN=%d", child_count);
4083 -
4084 -               if(fcgi_fd != FCGI_LISTENSOCK_FILENO) {
4085 -                       close(FCGI_LISTENSOCK_FILENO);
4086 -                       dup2(fcgi_fd, FCGI_LISTENSOCK_FILENO);
4087 -                       close(fcgi_fd);
4088 +               /* create socket */
4089 +               if (-1 == bind(fcgi_fd, fcgi_addr, servlen)) {
4090 +                       fprintf(stderr, "%s.%d: bind failed: %s\n",
4091 +                               __FILE__, __LINE__,
4092 +                               strerror(errno));
4093 +                       return -1;
4094                 }
4095  
4096 -               /* we don't need the client socket */
4097 -               for (i = 3; i < 256; i++) {
4098 -                       close(i);
4099 +               if (-1 == listen(fcgi_fd, 1024)) {
4100 +                       fprintf(stderr, "%s.%d: fd = -1\n",
4101 +                               __FILE__, __LINE__);
4102 +                       return -1;
4103                 }
4104  
4105 -               /* create environment */
4106 +               while (fork_count-- > 0) {
4107  
4108 -               putenv(cgi_childs);
4109 +                       if (!nofork) {
4110 +                               child = fork();
4111 +                       } else {
4112 +                               child = 0;
4113 +                       }
4114  
4115 -               /* fork and replace shell */
4116 -               if (appArgv) {
4117 -                       execv(appArgv[0], appArgv);
4118 +                       switch (child) {
4119 +                       case 0: {
4120 +                               char cgi_childs[64];
4121 +                               int max_fd = 0;
4122  
4123 -               } else {
4124 -                       char *b = malloc(strlen("exec ") + strlen(appPath) + 1);
4125 -                       strcpy(b, "exec ");
4126 -                       strcat(b, appPath);
4127 +                               int i = 0;
4128  
4129 -                       /* exec the cgi */
4130 -                       execl("/bin/sh", "sh", "-c", b, (char *)NULL);
4131 -               }
4132 +                               /* loose control terminal */
4133 +                               setsid();
4134  
4135 -               exit(errno);
4136 +                               /* is safe as we limit to 256 childs */
4137 +                               sprintf(cgi_childs, "PHP_FCGI_CHILDREN=%d", child_count);
4138  
4139 -               break;
4140 -       }
4141 -       case -1:
4142 -               /* error */
4143 -               break;
4144 -       default:
4145 -               /* father */
4146 +                               if(fcgi_fd != FCGI_LISTENSOCK_FILENO) {
4147 +                                       close(FCGI_LISTENSOCK_FILENO);
4148 +                                       dup2(fcgi_fd, FCGI_LISTENSOCK_FILENO);
4149 +                                       close(fcgi_fd);
4150 +                               }
4151  
4152 -               /* wait */
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);
4157 +                               close(max_fd);
4158  
4159 -               switch (waitpid(child, &status, WNOHANG)) {
4160 -               case 0:
4161 -                       fprintf(stderr, "%s.%d: child spawned successfully: PID: %d\n",
4162 -                               __FILE__, __LINE__,
4163 -                               child);
4164 +                               max_fd = open("/dev/null", O_RDWR);
4165 +                               close(STDOUT_FILENO);
4166 +                               dup2(max_fd, STDOUT_FILENO);
4167 +                               close(max_fd);
4168  
4169 -                       /* write pid file */
4170 -                       if (pid_fd != -1) {
4171 -                               /* assume a 32bit pid_t */
4172 -                               char pidbuf[12];
4173 +                               /* we don't need the client socket */
4174 +                               for (i = 3; i < max_fd; i++) {
4175 +                                       if (i != FCGI_LISTENSOCK_FILENO) close(i);
4176 +                               }
4177  
4178 -                               snprintf(pidbuf, sizeof(pidbuf) - 1, "%d", child);
4179 +                               /* create environment */
4180  
4181 -                               write(pid_fd, pidbuf, strlen(pidbuf));
4182 -                               close(pid_fd);
4183 -                               pid_fd = -1;
4184 +                               putenv(cgi_childs);
4185 +
4186 +                               /* fork and replace shell */
4187 +                               if (appArgv) {
4188 +                                       execv(appArgv[0], appArgv);
4189 +
4190 +                               } else {
4191 +                                       char *b = malloc(strlen("exec ") + strlen(appPath) + 1);
4192 +                                       strcpy(b, "exec ");
4193 +                                       strcat(b, appPath);
4194 +
4195 +                                       /* exec the cgi */
4196 +                                       execl("/bin/sh", "sh", "-c", b, (char *)NULL);
4197 +                               }
4198 +
4199 +                               exit(errno);
4200 +
4201 +                               break;
4202                         }
4203 +                       case -1:
4204 +                               /* error */
4205 +                               break;
4206 +                       default:
4207 +                               /* father */
4208  
4209 -                       break;
4210 -               case -1:
4211 -                       break;
4212 -               default:
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));
4221 -                       } else {
4222 -                               fprintf(stderr, "%s.%d: child died somehow: %d\n",
4223 -                                       __FILE__, __LINE__,
4224 -                                       status);
4225 +                               /* wait */
4226 +                               select(0, NULL, NULL, NULL, &tv);
4227 +
4228 +                               switch (waitpid(child, &status, WNOHANG)) {
4229 +                               case 0:
4230 +                                       fprintf(stdout, "%s.%d: child spawned successfully: PID: %d\n",
4231 +                                               __FILE__, __LINE__,
4232 +                                               child);
4233 +
4234 +                                       /* write pid file */
4235 +                                       if (pid_fd != -1) {
4236 +                                               /* assume a 32bit pid_t */
4237 +                                               char pidbuf[12];
4238 +
4239 +                                               snprintf(pidbuf, sizeof(pidbuf) - 1, "%d", child);
4240 +
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);
4245 +                                               }
4246 +                                       }
4247 +
4248 +                                       break;
4249 +                               case -1:
4250 +                                       break;
4251 +                               default:
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));
4260 +                                               rc = 1;
4261 +                                       } else {
4262 +                                               fprintf(stderr, "%s.%d: child died somehow: %d\n",
4263 +                                                       __FILE__, __LINE__,
4264 +                                                       status);
4265 +                                               rc = status;
4266 +                                       }
4267 +                               }
4268 +
4269 +                               break;
4270                         }
4271                 }
4272 -
4273 -               break;
4274 +               close(pid_fd);
4275 +               pid_fd = -1;
4276 +       } else {
4277 +               fprintf(stderr, "%s.%d: socket is already used, can't spawn\n",
4278 +                       __FILE__, __LINE__);
4279 +               return -1;
4280         }
4281  
4282         close(fcgi_fd);
4283  
4284 -       return 0;
4285 +       return rc;
4286  }
4287  
4288  
4289 @@ -256,6 +277,7 @@
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;
4302         int i_am_root, o;
4303         int pid_fd = -1;
4304         int nofork = 0;
4305         struct sockaddr_un un;
4306 -       const size_t sun_path_len = sizeof(un.sun_path);
4307  
4308         i_am_root = (getuid() == 0);
4309  
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:"))) {
4312                 switch(o) {
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;
4321 @@ -321,7 +344,7 @@
4322                 return -1;
4323         }
4324  
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",
4328                         __FILE__, __LINE__,
4329                         "path of the unix socket is too long\n");
4330 @@ -416,18 +439,15 @@
4331                                         "I will not set gid to 0\n");
4332                                 return -1;
4333                         }
4334 -               }
4335  
4336 -               /*
4337 -                * Change group before chroot, when we have access
4338 -                * to /etc/group
4339 -                */
4340 -               if (groupname) {
4341 +                       /* do the change before we do the chroot() */
4342                         setgid(grp->gr_gid);
4343 -                       setgroups(0, NULL);
4344 +                       setgroups(0, NULL); 
4345 +
4346                         if (username) {
4347                                 initgroups(username, grp->gr_gid);
4348                         }
4349 +
4350                 }
4351  
4352                 if (changeroot) {
4353 @@ -451,7 +471,7 @@
4354                 }
4355         }
4356  
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);
4359  }
4360  #else
4361  int main() {
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);
4368  #ifdef USE_LDAP
4369                                 PATCH(ldap);
4370 -                               PATCH(ldap_filter_pre);
4371 -                               PATCH(ldap_filter_post);
4372  #endif
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);
4377 +#ifdef USE_LDAP
4378 +                               PATCH(ldap_filter_pre);
4379 +                               PATCH(ldap_filter_post);
4380 +#endif
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"))) {
4384 @@ -248,6 +250,7 @@
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;
4389  
4390                                                 /* a field was missing */
4391  
4392 @@ -268,22 +271,23 @@
4393                 realm = (data_string *)array_get_element(req, "realm");
4394  
4395                 con->http_status = 401;
4396 +               con->mode = DIRECT;
4397  
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("\""));
4404  
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")) {
4407                         char hh[33];
4408                         http_auth_digest_generate_nonce(srv, p, srv->tmp_buf, hh);
4409  
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\""));
4418  
4419                         response_header_insert(srv, con, CONST_STR_LEN("WWW-Authenticate"), CONST_BUF_LEN(p->tmp_buf));
4420                 } else {
4421 @@ -393,6 +397,23 @@
4422                         }
4423                 }
4424  
4425 +#ifdef USE_LDAP
4426 +               if (s->auth_ldap_filter->used) {
4427 +                       char *dollar;
4428 +
4429 +                       /* parse filter */
4430 +
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 '$'");
4433 +
4434 +                               return HANDLER_ERROR;
4435 +                       }
4436 +
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);
4439 +               }
4440 +#endif
4441 +
4442                 /* no auth.require for this section */
4443                 if (NULL == (da = (data_array *)array_get_element(ca, "auth.require"))) continue;
4444  
4445 @@ -479,21 +500,21 @@
4446  
4447                                 ds = data_string_init();
4448  
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);
4452  
4453                                 array_insert_unique(a->value, (data_unset *)ds);
4454  
4455                                 ds = data_string_init();
4456  
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);
4460  
4461                                 array_insert_unique(a->value, (data_unset *)ds);
4462  
4463                                 ds = data_string_init();
4464  
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);
4468  
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)
4473                                 return (ret);
4474 -                        break;
4475 +                       break;
4476                 }
4477 -                default:
4478 -                        break;
4479 -                }
4480 -        }
4481 +               default:
4482 +                       break;
4483 +               }
4484 +       }
4485  
4486 -        return HANDLER_GO_ON;
4487 +       return HANDLER_GO_ON;
4488  }
4489  
4490  handler_t auth_ldap_init(server *srv, mod_auth_plugin_config *s) {
4491  #ifdef USE_LDAP
4492 -                       int ret;
4493 +       int ret;
4494  #if 0
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");
4499  
4500 -                               return HANDLER_ERROR;
4501 -                       }
4502 +               return HANDLER_ERROR;
4503 +       }
4504  #endif
4505  
4506 -                       if (s->auth_ldap_filter->used) {
4507 -                               char *dollar;
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));
4511  
4512 -                               /* parse filter */
4513 +                       return HANDLER_ERROR;
4514 +               }
4515  
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));
4521  
4522 -                                       return HANDLER_ERROR;
4523 -                               }
4524 +                       return HANDLER_ERROR;
4525 +               }
4526  
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);
4529 -                       }
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));
4538  
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));
4542 -
4543                                         return HANDLER_ERROR;
4544                                 }
4545 +                       }
4546  
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));
4552  
4553 -                                       return HANDLER_ERROR;
4554 -                               }
4555 +                               return HANDLER_ERROR;
4556 +                       }
4557 +               }
4558  
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));
4567  
4568 -                                                       return HANDLER_ERROR;
4569 -                                               }
4570 -                                       }
4571 +               /* 1. */
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));
4575  
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;
4579 +                       }
4580 +               } else {
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));
4583  
4584 -                                               return HANDLER_ERROR;
4585 -                                       }
4586 -                               }
4587 -
4588 -
4589 -                               /* 1. */
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));
4593 -
4594 -                                               return HANDLER_ERROR;
4595 -                                       }
4596 -                               } else {
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));
4599 -
4600 -                                               return HANDLER_ERROR;
4601 -                                       }
4602 -                               }
4603 +                               return HANDLER_ERROR;
4604                         }
4605 +               }
4606 +       }
4607 +       return HANDLER_GO_ON;
4608  #else
4609 -                       log_error_write(srv, __FILE__, __LINE__, "s", "no ldap support available");
4610 -                       return HANDLER_ERROR;
4611 +       UNUSED(s);
4612 +       log_error_write(srv, __FILE__, __LINE__, "s", "no ldap support available");
4613 +       return HANDLER_ERROR;
4614  #endif
4615 -               return HANDLER_GO_ON;
4616  }
4617  
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)
4623 @@ -37,7 +37,7 @@
4624         data_string *ds_src = (data_string *)src;
4625  
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);
4630         } else {
4631                 buffer_copy_string_buffer(ds_dst->value, ds_src->value);
4632 @@ -53,9 +53,9 @@
4633         data_string *ds_src = (data_string *)src;
4634  
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);
4642         } else {
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)
4648 @@ -109,9 +109,9 @@
4649         o = buffer_init();
4650  
4651         if (con->conf.is_ssl) {
4652 -               buffer_copy_string(o, "https://");
4653 +               buffer_copy_string_len(o, CONST_STR_LEN("https://"));
4654         } else {
4655 -               buffer_copy_string(o, "http://");
4656 +               buffer_copy_string_len(o, CONST_STR_LEN("http://"));
4657         }
4658         if (con->uri.authority->used) {
4659                 buffer_append_string_buffer(o, con->uri.authority);
4660 @@ -180,14 +180,14 @@
4661  
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);
4667                 }
4668         }
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);
4676         }
4677  
4678 @@ -272,6 +272,7 @@
4679                                                                         con->request.http_if_modified_since, used_len, sizeof(buf) - 1);
4680  
4681                                                         con->http_status = 412;
4682 +                                                       con->mode = DIRECT;
4683                                                         return HANDLER_FINISHED;
4684                                                 }
4685  
4686 @@ -281,6 +282,7 @@
4687  
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;
4692                                                 }
4693                                                 t_header = mktime(&tm);
4694 @@ -299,6 +301,7 @@
4695                                 }
4696                         } else {
4697                                 con->http_status = 412;
4698 +                               con->mode = DIRECT;
4699                                 return HANDLER_FINISHED;
4700                         }
4701                 }
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;
4709  
4710 +       switch (con->dst_addr.plain.sa_family) {
4711 +               case AF_INET:
4712 +#ifdef HAVE_IPV6
4713 +               case AF_INET6:
4714 +#endif
4715 +                       break;
4716 +               default: // Address family not supported
4717 +                       return HANDLER_GO_ON;
4718 +       };
4719 +
4720         for (j = 0; j < srv->conns->used; j++) {
4721                 connection *c = srv->conns->ptr[j];
4722  
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
4725                  * */
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) {
4728 -                       conns_by_ip++;
4729 +               if (c->dst_addr.plain.sa_family != con->dst_addr.plain.sa_family) continue;
4730 +               if (c->state <= CON_STATE_REQUEST_END) continue;
4731  
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) {
4737 +                       case AF_INET:
4738 +                               if (c->dst_addr.ipv4.sin_addr.s_addr != con->dst_addr.ipv4.sin_addr.s_addr) continue;
4739 +                               break;
4740 +#ifdef HAVE_IPV6
4741 +                       case AF_INET6:
4742 +                               if (0 != memcmp(c->dst_addr.ipv6.sin6_addr.s6_addr, con->dst_addr.ipv6.sin6_addr.s6_addr, 16)) continue;
4743 +                               break;
4744 +#endif
4745 +                       default: /* Address family not supported, should never be reached */
4746 +                               continue;
4747 +               };
4748 +               conns_by_ip++;
4749  
4750 -                               con->http_status = 403;
4751 -                               return HANDLER_FINISHED;
4752 -                       }
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.");
4757 +
4758 +                       con->http_status = 403;
4759 +                       con->mode = DIRECT;
4760 +                       return HANDLER_FINISHED;
4761                 }
4762         }
4763  
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)
4768 @@ -140,6 +140,8 @@
4769         size_t k;
4770         stat_cache_entry *sce = NULL;
4771  
4772 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
4773 +
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;
4776  
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;
4785  
4786         /*
4787 +        * workaround for program when prefix="/"
4788 +        *
4789 +        * rule to build PATH_INFO is hardcoded for when check_local is disabled
4790 +        * enable this option to use the workaround
4791 +        *
4792 +        */
4793 +
4794 +       unsigned short fix_root_path_name;
4795 +
4796 +       /*
4797          * If the backend includes X-LIGHTTPD-send-file in the response
4798          * we use the value as filename and ignore the content.
4799          *
4800 @@ -380,10 +390,10 @@
4801  static handler_t fcgi_handle_fdevent(void *s, void *ctx, int revents);
4802  
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);
4807         if (proc) {
4808 -               buffer_append_string(b, ".");
4809 +               buffer_append_string_len(b, CONST_STR_LEN("."));
4810                 buffer_append_long(b, proc->id);
4811         }
4812  
4813 @@ -393,7 +403,7 @@
4814  int fastcgi_status_init(server *srv, buffer *b, fcgi_extension_host *host, fcgi_proc *proc) {
4815  #define CLEAN(x) \
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);
4820  
4821         CLEAN(".disabled");
4822 @@ -406,7 +416,7 @@
4823  
4824  #define CLEAN(x) \
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);
4829  
4830         CLEAN(".load");
4831 @@ -693,6 +703,7 @@
4832  
4833  static int env_add(char_array *env, const char *key, size_t key_len, const char *val, size_t val_len) {
4834         char *dst;
4835 +       size_t i;
4836  
4837         if (!key || !val) return -1;
4838  
4839 @@ -702,6 +713,15 @@
4840         /* add the \0 from the value */
4841         memcpy(dst + key_len + 1, val, val_len + 1);
4842  
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;
4848 +                       return 0;
4849 +               }
4850 +       }
4851 +
4852         if (env->size == 0) {
4853                 env->size = 16;
4854                 env->ptr = malloc(env->size * sizeof(*env->ptr));
4855 @@ -811,7 +831,7 @@
4856                 socket_type = AF_UNIX;
4857                 fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
4858  
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);
4862  
4863  #else
4864 @@ -857,13 +877,13 @@
4865                 socket_type = AF_INET;
4866                 fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
4867  
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);
4872                 } else {
4873 -                       buffer_append_string(proc->connection_name, "localhost");
4874 +                       buffer_append_string_len(proc->connection_name, CONST_STR_LEN("localhost"));
4875                 }
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);
4879         }
4880  
4881 @@ -937,6 +957,8 @@
4882                                 close(fcgi_fd);
4883                         }
4884  
4885 +                       openDevNull(STDERR_FILENO);
4886 +
4887                         /* we don't need the client socket */
4888                         for (i = 3; i < 256; i++) {
4889                                 close(i);
4890 @@ -1000,8 +1022,8 @@
4891                         /* exec the cgi */
4892                         execve(arg.ptr[0], arg.ptr, env.ptr);
4893  
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)); */
4898  
4899                         exit(errno);
4900  
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 */
4906  
4907                                                 { NULL,                NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
4908                                         };
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;
4914  
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);
4922  
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;
4927                                                         } else {
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);
4932                                                         }
4933  
4934 @@ -1482,7 +1507,7 @@
4935                         status_counter_dec(srv, CONST_STR_LEN("fastcgi.active-requests"));
4936  
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"));
4940  
4941                         status_counter_set(srv, CONST_BUF_LEN(p->statuskey), hctx->proc->load);
4942  
4943 @@ -1683,7 +1708,7 @@
4944  
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);
4950                 }
4951  #else
4952 @@ -1709,13 +1734,13 @@
4953  
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);
4960                         } else {
4961 -                               buffer_append_string(proc->connection_name, "localhost");
4962 +                               buffer_append_string_len(proc->connection_name, CONST_STR_LEN("localhost"));
4963                         }
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);
4967                 }
4968         }
4969 @@ -1771,7 +1796,7 @@
4970                         buffer_reset(srv->tmp_buf);
4971  
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--;
4976                         }
4977  
4978 @@ -2026,7 +2051,7 @@
4979                  */
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("/"));
4984                 }
4985  
4986                 if (con->request.orig_uri->used >= host->strip_request_uri->used &&
4987 @@ -2094,12 +2119,12 @@
4988                         hctx->wb->bytes_in += sizeof(header);
4989  
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);
4993                         }
4994  
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);
4999                                 }
5000  
5001                                 switch (req_c->type) {
5002 @@ -2109,12 +2134,10 @@
5003                                         if (weHave > weWant - written) weHave = weWant - written;
5004  
5005                                         if (p->conf.debug > 10) {
5006 -                                               fprintf(stderr, "%s.%d: sending %lld bytes from (%lld / %lld) %s\n",
5007 -                                                               __FILE__, __LINE__,
5008 -                                                               weHave,
5009 -                                                               req_c->offset,
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);
5016                                         }
5017  
5018                                         assert(weHave != 0);
5019 @@ -2143,7 +2166,7 @@
5020                                                 chunk *c;
5021  
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");
5025                                                 }
5026                                                 c = hctx->wb->last;
5027  
5028 @@ -2173,7 +2196,7 @@
5029  
5030                                         hctx->wb->bytes_in += weHave;
5031  
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);
5035  
5036                                                 req_c = req_cq->first;
5037 @@ -2368,7 +2391,7 @@
5038         offset = sizeof(*header);
5039  
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 */
5043  
5044         if (packet->len) {
5045                 /* copy the content */
5046 @@ -2544,7 +2567,10 @@
5047                                         stat_cache_entry *sce;
5048  
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();
5054 +                                               }
5055                                                 /* found */
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 @@
5059  
5060                         /* the child should not terminate at all */
5061  
5062 -                       switch(waitpid(proc->pid, &status, WNOHANG)) {
5063 -                       case 0:
5064 -                               /* child is still alive */
5065 -                               break;
5066 -                       case -1:
5067 -                               break;
5068 -                       default:
5069 -                               if (WIFEXITED(status)) {
5070 +                       for ( ;; ) {
5071 +                               switch(waitpid(proc->pid, &status, WNOHANG)) {
5072 +                               case 0:
5073 +                                       /* child is still alive */
5074 +                                       if (srv->cur_ts <= proc->disabled_until) break;
5075 +                                       
5076 +                                       proc->state = PROC_STATE_RUNNING;
5077 +                                       host->active_procs++;
5078 +               
5079 +                                       log_error_write(srv, __FILE__, __LINE__,  "sbdb",
5080 +                                                       "fcgi-server re-enabled:",
5081 +                                                       host->host, host->port,
5082 +                                                       host->unixsocket);
5083 +                                       break;
5084 +                               case -1:
5085 +                                       if (errno == EINTR) continue;
5086 +
5087 +                                       log_error_write(srv, __FILE__, __LINE__, "sd",
5088 +                                                       "child died somehow, waitpid failed:",
5089 +                                                       errno);
5090 +                                       proc->state = PROC_STATE_DIED;
5091 +                                       break;
5092 +                               default:
5093 +                                       if (WIFEXITED(status)) {
5094  #if 0
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));
5101  #endif
5102 -                               } else if (WIFSIGNALED(status)) {
5103 -                                       log_error_write(srv, __FILE__, __LINE__, "sd",
5104 -                                                       "child signaled:",
5105 -                                                       WTERMSIG(status));
5106 -                               } else {
5107 -                                       log_error_write(srv, __FILE__, __LINE__, "sd",
5108 -                                                       "child died somehow:",
5109 -                                                       status);
5110 +                                       } else if (WIFSIGNALED(status)) {
5111 +                                               log_error_write(srv, __FILE__, __LINE__, "sd",
5112 +                                                               "child signaled:",
5113 +                                                               WTERMSIG(status));
5114 +                                       } else {
5115 +                                               log_error_write(srv, __FILE__, __LINE__, "sd",
5116 +                                                               "child died somehow:",
5117 +                                                               status);
5118 +                                       }
5119 +       
5120 +                                       proc->state = PROC_STATE_DIED;
5121 +                                       break;
5122                                 }
5123 -
5124 -                               proc->state = PROC_STATE_DIED;
5125                                 break;
5126                         }
5127  
5128 @@ -2797,7 +2841,7 @@
5129                         hctx->proc->state = PROC_STATE_DIED;
5130  
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"));
5134  
5135                         status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
5136  
5137 @@ -2889,7 +2933,7 @@
5138                         hctx->proc->state = PROC_STATE_OVERLOADED;
5139  
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"));
5143  
5144                         status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
5145  
5146 @@ -2915,7 +2959,7 @@
5147                                 "load:", host->load);
5148  
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"));
5152  
5153                         status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
5154  
5155 @@ -2941,19 +2985,19 @@
5156                 status_counter_inc(srv, CONST_STR_LEN("fastcgi.active-requests"));
5157  
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"));
5161  
5162                 status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
5163  
5164                 /* the proc-load */
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"));
5168  
5169                 status_counter_set(srv, CONST_BUF_LEN(p->statuskey), hctx->proc->load);
5170  
5171                 /* the host-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"));
5175  
5176                 status_counter_set(srv, CONST_BUF_LEN(p->statuskey), hctx->host->load);
5177  
5178 @@ -3074,7 +3118,7 @@
5179  
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;
5190  
5191 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
5192 +
5193         /* Possibly, we processed already this request */
5194         if (con->file_started == 1) return HANDLER_GO_ON;
5195  
5196 @@ -3480,13 +3526,12 @@
5197  
5198                         ct_len = extension->key->used - 1;
5199  
5200 -                       if (s_len < ct_len) continue;
5201 -
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))
5209                                         break;
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" */
5213                                 break;
5214                         }
5215 @@ -3499,16 +3544,15 @@
5216  
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];
5221  
5222                 /* we should have at least one proc that can do something */
5223 -               if (host->active_procs == 0) {
5224 -                       host = NULL;
5225 -
5226 +               if (h->active_procs == 0) {
5227                         continue;
5228                 }
5229  
5230                 /* we found one host that is alive */
5231 +               host = h;
5232                 break;
5233         }
5234  
5235 @@ -3582,6 +3626,13 @@
5236                          * SCRIPT_NAME = /fcgi-bin/foo
5237                          * PATH_INFO   = /bar
5238                          *
5239 +                        * if prefix = /, and fix-root-path-name is enable
5240 +                        *
5241 +                        * /fcgi-bin/foo/bar
5242 +                        *
5243 +                        * SCRIPT_NAME = /fcgi-bin/foo
5244 +                        * PATH_INFO   = /bar
5245 +                        *
5246                          */
5247  
5248                         /* the rewrite is only done for /prefix/? matches */
5249 @@ -3594,6 +3645,10 @@
5250  
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';
5257                         }
5258                 }
5259         } else {
5260 @@ -3738,7 +3793,7 @@
5261                                                 proc->port = host->port + proc->id;
5262                                         } else {
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);
5267                                         }
5268  
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 @@
5274  }
5275  
5276  value(A) ::= VALUE(B). {
5277 -  A = buffer_init_string(B->ptr);
5278 +  A = B;
5279  }
5280  
5281  value(A) ::= value(B) VALUE(C). {
5282    A = B;
5283    buffer_append_string_buffer(A, C);
5284 +  buffer_free(C);
5285  }
5286  
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)
5292 @@ -159,6 +159,7 @@
5293  
5294                 if (denied) {
5295                         con->http_status = 403;
5296 +                       con->mode = DIRECT;
5297  
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)
5304 @@ -356,7 +356,7 @@
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);
5310                                         }
5311  # endif
5312                                 } else if (s->log_access_fd != -1) {
5313 @@ -433,7 +433,7 @@
5314                 if (i == 0 && buffer_is_empty(s->format)) {
5315                         /* set a default logfile string */
5316  
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\""));
5319                 }
5320  
5321                 /* parse */
5322 @@ -473,7 +473,7 @@
5323                         continue;
5324                 }
5325  
5326 -               if (buffer_is_empty(s->access_logfile)) continue;
5327 +               if (s->access_logfile->used < 2) continue;
5328  
5329                 if (s->access_logfile->ptr[0] == '|') {
5330  #ifdef HAVE_FORK
5331 @@ -498,6 +498,8 @@
5332                                 /* not needed */
5333                                 close(to_log_fds[1]);
5334  
5335 +                               openDevNull(STDERR_FILENO);
5336 +
5337                                 /* we don't need the client socket */
5338                                 for (i = 3; i < 256; i++) {
5339                                         close(i);
5340 @@ -559,7 +561,7 @@
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);
5346                                 }
5347  #endif
5348                         } else if (s->log_access_fd != -1) {
5349 @@ -570,7 +572,7 @@
5350                 }
5351  
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] != '|') {
5356  
5357                         close(s->log_access_fd);
5358 @@ -647,9 +649,12 @@
5359  
5360         mod_accesslog_patch_connection(srv, con, p);
5361  
5362 +       /* No output device, nothing to do */
5363 +       if (!p->conf.use_syslog && p->conf.log_access_fd == -1) return HANDLER_GO_ON;
5364 +
5365         b = p->conf.access_logbuffer;
5366         if (b->used == 0) {
5367 -               buffer_copy_string(b, "");
5368 +               buffer_copy_string_len(b, CONST_STR_LEN(""));
5369         }
5370  
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);
5375  # else
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)));
5378  # endif
5379                                         p->conf.ts_accesslog_str->used = strlen(p->conf.ts_accesslog_str->ptr) + 1;
5380  
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);
5383  
5384                                         scd = abs(tm.tm_gmtoff);
5385                                         hrs = scd / 3600;
5386                                         min = (scd % 3600) / 60;
5387  
5388                                         /* hours */
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);
5392  
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("]"));
5398  #else
5399  #ifdef HAVE_GMTIME_R
5400                                         gmtime_r(&(srv->cur_ts), &tm);
5401 @@ -717,13 +722,13 @@
5402                                 break;
5403                         case FORMAT_REMOTE_IDENT:
5404                                 /* ident */
5405 -                               BUFFER_APPEND_STRING_CONST(b, "-");
5406 +                               buffer_append_string_len(b, CONST_STR_LEN("-"));
5407                                 break;
5408                         case FORMAT_REMOTE_USER:
5409                                 if (con->authed_user->used > 1) {
5410                                         buffer_append_string_buffer(b, con->authed_user);
5411                                 } else {
5412 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5413 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5414                                 }
5415                                 break;
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);
5420                                 } else {
5421 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5422 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5423                                 }
5424                                 break;
5425                         case FORMAT_HEADER:
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);
5428                                 } else {
5429 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5430 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5431                                 }
5432                                 break;
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);
5436                                 } else {
5437 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5438 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5439                                 }
5440                                 break;
5441                         case FORMAT_FILENAME:
5442                                 if (con->physical.path->used > 1) {
5443                                         buffer_append_string_buffer(b, con->physical.path);
5444                                 } else {
5445 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5446 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5447                                 }
5448                                 break;
5449                         case FORMAT_BYTES_OUT:
5450                                 if (con->bytes_written > 0) {
5451                                         buffer_append_off_t(b, con->bytes_written);
5452                                 } else {
5453 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5454 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5455                                 }
5456                                 break;
5457                         case FORMAT_BYTES_IN:
5458                                 if (con->bytes_read > 0) {
5459                                         buffer_append_off_t(b, con->bytes_read);
5460                                 } else {
5461 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5462 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5463                                 }
5464                                 break;
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);
5469                                 } else {
5470 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5471 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5472                                 }
5473                                 break;
5474                         case FORMAT_HTTP_HOST:
5475                                 if (con->uri.authority->used > 1) {
5476                                         buffer_append_string_buffer(b, con->uri.authority);
5477                                 } else {
5478 -                                       BUFFER_APPEND_STRING_CONST(b, "-");
5479 +                                       buffer_append_string_len(b, CONST_STR_LEN("-"));
5480                                 }
5481                                 break;
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);
5487                                 break;
5488                         case FORMAT_REQUEST_METHOD:
5489                                 buffer_append_string(b, get_http_method_name(con->request.http_method));
5490                                 break;
5491                         case FORMAT_PERCENT:
5492 -                               buffer_append_string(b, "%");
5493 +                               buffer_append_string_len(b, CONST_STR_LEN("%"));
5494                                 break;
5495                         case FORMAT_SERVER_PORT:
5496 -                               buffer_append_long(b, srv->srvconf.port);
5497 +                               {
5498 +                                       char *colon = strchr(((server_socket*)(con->srv_socket))->srv_token->ptr, ':');
5499 +                                       if (colon) {
5500 +                                               buffer_append_string(b, colon+1);
5501 +                                       } else {
5502 +                                               buffer_append_long(b, srv->srvconf.port);
5503 +                                       }
5504 +                               }
5505                                 break;
5506                         case FORMAT_QUERY_STRING:
5507                                 buffer_append_string_buffer(b, con->uri.query);
5508 @@ -816,8 +828,8 @@
5509                                 break;
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;
5516                                 }
5517                                 break;
5518                         default:
5519 @@ -837,7 +849,7 @@
5520                 }
5521         }
5522  
5523 -       BUFFER_APPEND_STRING_CONST(b, "\n");
5524 +       buffer_append_string_len(b, CONST_STR_LEN("\n"));
5525  
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 */
5528 @@ -847,7 +859,7 @@
5529  #ifdef HAVE_SYSLOG_H
5530                         if (b->used > 2) {
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);
5534                         }
5535  #endif
5536                 } else if (p->conf.log_access_fd != -1) {
5537 Index: src/server.c
5538 ===================================================================
5539 --- src/server.c        (.../tags/lighttpd-1.4.19)      (revision 2303)
5540 +++ src/server.c        (.../branches/lighttpd-1.4.x)   (revision 2303)
5541 @@ -80,7 +80,7 @@
5542         switch (sig) {
5543         case SIGTERM:
5544                 srv_shutdown = 1;
5545 -               memcpy(&last_sigterm_info, si, sizeof(*si));
5546 +               last_sigterm_info = *si;
5547                 break;
5548         case SIGINT:
5549                 if (graceful_shutdown) {
5550 @@ -88,7 +88,7 @@
5551                 } else {
5552                         graceful_shutdown = 1;
5553                 }
5554 -               memcpy(&last_sigterm_info, si, sizeof(*si));
5555 +               last_sigterm_info = *si;
5556  
5557                 break;
5558         case SIGALRM: 
5559 @@ -104,7 +104,7 @@
5560                  */
5561                 if (!forwarded_sig_hup) {
5562                         handle_sig_hup = 1;
5563 -                       memcpy(&last_sighup_info, si, sizeof(*si));
5564 +                       last_sighup_info = *si;
5565                 } else {
5566                         forwarded_sig_hup = 0;
5567                 }
5568 @@ -573,20 +573,9 @@
5569         }
5570  
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);
5576 -               close(fd);
5577 -       }
5578 +       openDevNull(STDIN_FILENO);
5579 +       openDevNull(STDOUT_FILENO);
5580  
5581 -       /* move stdout to /dev/null */
5582 -       if (-1 != (fd = open("/dev/null", O_WRONLY))) {
5583 -               close(STDOUT_FILENO);
5584 -               dup2(fd, STDOUT_FILENO);
5585 -               close(fd);
5586 -       }
5587 -
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 */
5593         if (pid_fd != -1) {
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);
5598                 close(pid_fd);
5599                 pid_fd = -1;
5600         }
5601  
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.");
5608  
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) {
5615         UNUSED(srv);
5616  
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"
5621                 "<head>\n"
5622                 "<title>Index of "
5623 -       );
5624 +       ));
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"));
5628  
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"));
5635         } else {
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"
5641 @@ -485,8 +485,6 @@
5642                         " padding-right: 14px;"
5643                         " padding-bottom: 3px;"
5644                         "}\n"
5645 -               );
5646 -               BUFFER_APPEND_STRING_CONST(out,
5647                         "td {padding-right: 14px;}\n"
5648                         "td.s, th.s {text-align: right;}\n"
5649                         "div.list {"
5650 @@ -502,10 +500,10 @@
5651                         " padding-top: 4px;"
5652                         "}\n"
5653                         "</style>\n"
5654 -               );
5655 +               ));
5656         }
5657  
5658 -       BUFFER_APPEND_STRING_CONST(out, "</head>\n<body>\n");
5659 +       buffer_append_string_len(out, CONST_STR_LEN("</head>\n<body>\n"));
5660  
5661         /* HEADER.txt */
5662         if (p->conf.show_header) {
5663 @@ -514,19 +512,19 @@
5664  
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"));
5669  
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>"));
5676                 }
5677                 stream_close(&s);
5678         }
5679  
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(
5685                 "</h2>\n"
5686                 "<div class=\"list\">\n"
5687                 "<table summary=\"Directory Listing\" cellpadding=\"0\" cellspacing=\"0\">\n"
5688 @@ -545,17 +543,17 @@
5689                         "<td class=\"s\">- &nbsp;</td>"
5690                         "<td class=\"t\">Directory</td>"
5691                 "</tr>\n"
5692 -       );
5693 +       ));
5694  }
5695  
5696  static void http_list_directory_footer(server *srv, connection *con, plugin_data *p, buffer *out) {
5697         UNUSED(srv);
5698  
5699 -       BUFFER_APPEND_STRING_CONST(out,
5700 +       buffer_append_string_len(out, CONST_STR_LEN(
5701                 "</tbody>\n"
5702                 "</table>\n"
5703                 "</div>\n"
5704 -       );
5705 +       ));
5706  
5707         if (p->conf.show_readme) {
5708                 stream s;
5709 @@ -563,33 +561,33 @@
5710  
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"));
5715  
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>"));
5722                 }
5723                 stream_close(&s);
5724         }
5725  
5726 -       BUFFER_APPEND_STRING_CONST(out,
5727 +       buffer_append_string_len(out, CONST_STR_LEN(
5728                 "<div class=\"foot\">"
5729 -       );
5730 +       ));
5731  
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));
5737         } else {
5738                 buffer_append_string_buffer(out, con->conf.server_tag);
5739         }
5740  
5741 -       BUFFER_APPEND_STRING_CONST(out,
5742 +       buffer_append_string_len(out, CONST_STR_LEN(
5743                 "</div>\n"
5744                 "</body>\n"
5745                 "</html>\n"
5746 -       );
5747 +       ));
5748  }
5749  
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);
5753  
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"));
5760         } else {
5761                 buffer_append_string_buffer(out, p->conf.encoding);
5762         }
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);
5766  
5767         /* directories */
5768 @@ -762,13 +760,13 @@
5769                 strftime(datebuf, sizeof(datebuf), "%Y-%b-%d %H:%M:%S", localtime(&(tmp->mtime)));
5770  #endif
5771  
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\">- &nbsp;</td><td class=\"t\">Directory</td></tr>\n");
5782 +               buffer_append_string_len(out, CONST_STR_LEN("</td><td class=\"s\">- &nbsp;</td><td class=\"t\">Directory</td></tr>\n"));
5783  
5784                 free(tmp);
5785         }
5786 @@ -818,17 +816,17 @@
5787  #endif
5788                 http_list_directory_sizefmt(sizebuf, tmp->size);
5789  
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"));
5807  
5808                 free(tmp);
5809         }
5810 @@ -841,11 +839,11 @@
5811  
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"));
5816         } else {
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));
5822         }
5823  
5824         con->file_finished = 1;
5825 @@ -861,6 +859,18 @@
5826  
5827         UNUSED(srv);
5828  
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:
5834 +               break;
5835 +       default:
5836 +               return HANDLER_GO_ON;
5837 +       }
5838 +
5839 +       if (con->mode != DIRECT) return HANDLER_GO_ON;
5840 +
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)
5848 @@ -27,7 +27,7 @@
5849         b = srv->tmp_chunk_len;
5850  
5851         if (len == 0) {
5852 -               buffer_copy_string(b, "0");
5853 +               buffer_copy_string_len(b, CONST_STR_LEN("0"));
5854         } else {
5855                 for (i = 0; i < 8 && len; i++) {
5856                         len >>= 4;
5857 @@ -44,7 +44,7 @@
5858                 b->ptr[b->used++] = '\0';
5859         }
5860  
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);
5864  
5865         return 0;
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;
5873  
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;
5878 +               break;
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;
5885 +               break;
5886  
5887         case MAGNET_ENV_UNSET: break;
5888         }
5889 @@ -647,6 +653,7 @@
5890                 assert(lua_gettop(L) == 0); /* only the function should be on the stack */
5891  
5892                 con->http_status = 500;
5893 +               con->mode = DIRECT;
5894  
5895                 return HANDLER_FINISHED;
5896         }
5897 @@ -744,6 +751,7 @@
5898                 assert(lua_gettop(L) == 1); /* only the function should be on the stack */
5899  
5900                 con->http_status = 500;
5901 +               con->mode = DIRECT;
5902  
5903                 return HANDLER_FINISHED;
5904         }
5905 @@ -766,9 +774,13 @@
5906                 /* try { ...*/
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;
5911 +                       }
5912                 } else {
5913                         /* } catch () { */
5914                         con->http_status = 500;
5915 +                       con->mode = DIRECT;
5916                 }
5917  
5918                 assert(lua_gettop(L) == 1); /* only the function should be on the stack */
5919 Index: src/log.c
5920 ===================================================================
5921 --- src/log.c   (.../tags/lighttpd-1.4.19)      (revision 2303)
5922 +++ src/log.c   (.../branches/lighttpd-1.4.x)   (revision 2303)
5923 @@ -31,6 +31,29 @@
5924  # define O_LARGEFILE 0
5925  #endif
5926  
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
5931 + *
5932 + * Returns 0 on success and -1 on failure (fd gets closed in all cases)
5933 + */
5934 +int openDevNull(int fd) {
5935 +       int tmpfd;
5936 +       close(fd);
5937 +#if defined(__WIN32)
5938 +       /* Cygwin should work with /dev/null */
5939 +       tmpfd = open("nul", O_RDWR);
5940 +#else
5941 +       tmpfd = open("/dev/null", O_RDWR);
5942 +#endif
5943 +       if (tmpfd != -1 && tmpfd != fd) {
5944 +               dup2(tmpfd, fd);
5945 +               close(tmpfd);
5946 +       }
5947 +       return (tmpfd != -1) ? 0 : -1;
5948 +}
5949 +
5950  /**
5951   * open the errorlog
5952   *
5953 @@ -44,7 +67,6 @@
5954   */
5955  
5956  int log_error_open(server *srv) {
5957 -       int fd;
5958         int close_stderr = 1;
5959  
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;
5964  #endif
5965 -       if (srv->errorlog_mode == ERRORLOG_STDERR) close_stderr = 0;
5966  
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
5970 +                */
5971 +               close_stderr = 0;
5972 +       }
5973 +
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);
5979 -               close(fd);
5980 -       }
5981 +       if (close_stderr) openDevNull(STDERR_FILENO);
5982         return 0;
5983  }
5984  
5985 @@ -162,18 +185,18 @@
5986                 }
5987  
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(": ("));
5991                 break;
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("("));
5996                 break;
5997         }
5998  
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(") "));
6005  
6006  
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(" "));
6014                         break;
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(" "));
6020                         break;
6021                 case 'd':           /* int */
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(" "));
6026                         break;
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(" "));
6032                         break;
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(" "));
6040                         break;
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);
6046                         break;
6047 +               case 'O':           /* off_t */
6048 +                       o = va_arg(ap, off_t);
6049 +                       buffer_append_off_t(srv->errorlog_buf, o);
6050 +                       break;
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);
6055 +                       break;
6056                 case '(':
6057                 case ')':
6058                 case '<':
6059 @@ -235,11 +267,11 @@
6060  
6061         switch(srv->errorlog_mode) {
6062         case ERRORLOG_FILE:
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);
6066                 break;
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);
6071                 break;
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)
6077 @@ -184,7 +184,7 @@
6078                 buffer_append_string(cmdline, shell);
6079         } else {
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"));
6083         }
6084         buffer_append_string_len(cmdline, CONST_STR_LEN(" /c "));
6085         buffer_append_string(cmdline, command);
6086 Index: src/log.h
6087 ===================================================================
6088 --- src/log.h   (.../tags/lighttpd-1.4.19)      (revision 2303)
6089 +++ src/log.h   (.../branches/lighttpd-1.4.x)   (revision 2303)
6090 @@ -3,6 +3,11 @@
6091  
6092  #include "server.h"
6093  
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)
6096 + */
6097 +int openDevNull(int fd);
6098 +
6099  #define WP() log_error_write(srv, __FILE__, __LINE__, "");
6100  
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)
6106 @@ -1 +0,0 @@
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)
6112 @@ -1,21 +0,0 @@
6113 -#!/usr/bin/perl
6114 -BEGIN {
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;
6119 -}
6120 -
6121 -use strict;
6122 -use IO::Socket;
6123 -use Test::More tests => 2;
6124 -use LightyTest;
6125 -
6126 -my $tf = LightyTest->new();
6127 -$tf->{CONFIGFILE} = 'env-variables.conf';
6128 -
6129 -TODO: {
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");
6133 -};
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)
6138 @@ -1,5 +1,4 @@
6139  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6140 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6141  
6142  ## bind to port (default: 80)
6143  server.port                 = 2048
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)
6148 @@ -1,5 +1,4 @@
6149  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6150 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6151  
6152  ## bind to port (default: 80)
6153  server.port                 = 2048
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)
6158 @@ -1,5 +1,4 @@
6159  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6160 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6161  
6162  ## bind to port (default: 80)
6163  server.port                 = 2048
6164 Index: tests/mod-extforward.conf
6165 ===================================================================
6166
6167 Property changes on: tests/symlink.t
6168 ___________________________________________________________________
6169 Added: svn:executable
6170    + *
6171
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)
6176 @@ -101,7 +101,7 @@
6177  Expect: 100-continue
6178  EOF
6179   );
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');
6183  
6184  ## ranges
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)
6189 @@ -3,7 +3,6 @@
6190  debug.log-condition-handling = "enable"
6191  
6192  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6193 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6194  
6195  ## bind to port (default: 80)
6196  server.port                 = 2048
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)
6201 @@ -22,11 +22,9 @@
6202  
6203  $tf_real->{PORT} = 2048;
6204  $tf_real->{CONFIGFILE} = 'lighttpd.conf';
6205 -$tf_real->{LIGHTTPD_PIDFILE} = $tf_real->{TESTDIR}.'/tmp/lighttpd/lighttpd.pid';
6206  
6207  $tf_proxy->{PORT} = 2050;
6208  $tf_proxy->{CONFIGFILE} = 'proxy.conf';
6209 -$tf_proxy->{LIGHTTPD_PIDFILE} = $tf_proxy->{TESTDIR}.'/tmp/lighttpd/lighttpd-proxy.pid';
6210  
6211  ok($tf_real->start_proc == 0, "Starting lighttpd") or die();
6212  
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)
6217 @@ -3,7 +3,6 @@
6218  debug.log-request-header   = "enable"
6219  
6220  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6221 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6222  
6223  ## bind to port (default: 80)
6224  server.port                 = 2048
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)
6229 @@ -1,5 +1,4 @@
6230  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6231 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6232  
6233  ## bind to port (default: 80)
6234  server.port                 = 2048
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)
6239 @@ -3,7 +3,6 @@
6240  debug.log-condition-handling = "enable"
6241  
6242  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6243 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6244  
6245  ## bind to port (default: 80)
6246  server.port                 = 2048
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)
6251 @@ -1,5 +1,4 @@
6252  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6253 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6254  
6255  debug.log-request-header   = "enable"
6256  debug.log-response-header  = "enable"
6257 @@ -85,7 +84,7 @@
6258                                    "grisu" => ( 
6259                                     "host" => "127.0.0.1",
6260                                     "port" => 1048,
6261 -                                   "bin-path" => "/usr/bin/php-cgi",
6262 +                                   "bin-path" => env.PHP,
6263                                     "bin-copy-environment" => ( "PATH", "SHELL", "USER" ),
6264                                   )
6265                                 )
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)
6270 @@ -7,17 +7,27 @@
6271  }
6272  
6273  use strict;
6274 -use Test::More tests => 47;
6275 +use Test::More tests => 49;
6276  use LightyTest;
6277  
6278  my $tf = LightyTest->new();
6279  
6280  my $t;
6281 +my $php_child = -1;
6282  
6283 +my $phpbin = (defined $ENV{'PHP'} ? $ENV{'PHP'} : '/usr/bin/php-cgi');
6284 +$ENV{'PHP'} = $phpbin;
6285 +
6286  SKIP: {
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");
6290 +}
6291 +
6292 +SKIP: {
6293         skip "no PHP running on port 1026", 29 unless $tf->listening_on(1026);
6294  
6295 -       ok($tf->start_proc == 0, "Starting lighttpd") or die();
6296 +       ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
6297  
6298         $t->{REQUEST} = ( <<EOF
6299  GET /phpinfo.php HTTP/1.0
6300 @@ -65,7 +75,7 @@
6301  EOF
6302   );
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"]');
6306  
6307         $t->{REQUEST}  = ( <<EOF
6308  GET /get-server-env.php/foo?env=PATH_INFO HTTP/1.0
6309 @@ -161,7 +171,7 @@
6310  
6311  
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
6318 @@ -173,7 +183,7 @@
6319         ok($tf->stop_proc == 0, "Stopping lighttpd");
6320         
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
6327 @@ -185,7 +195,7 @@
6328         ok($tf->stop_proc == 0, "Stopping lighttpd");
6329  
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 @@
6337  }
6338  
6339  SKIP: {
6340 +       skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
6341 +       ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
6342 +       $php_child = -1;
6343 +}
6344 +
6345 +SKIP: {
6346         skip "no fcgi-auth found", 4 unless -x $tf->{BASEDIR}."/tests/fcgi-auth" || -x $tf->{BASEDIR}."/tests/fcgi-auth.exe"; 
6347  
6348         $tf->{CONFIGFILE} = 'fastcgi-auth.conf';
6349 @@ -223,7 +239,7 @@
6350  }
6351  
6352  SKIP: {
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");
6360  }
6361  
6362 +exit 0;
6363 +
6364 +cleanup: ;
6365 +
6366 +$tf->endspawnfcgi($php_child) if $php_child != -1;
6367 +
6368 +die();
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)
6373 @@ -8,18 +8,26 @@
6374  
6375  use strict;
6376  use IO::Socket;
6377 -use Test::More tests => 5;
6378 +use Test::More tests => 8;
6379  use LightyTest;
6380  
6381  my $tf = LightyTest->new();
6382  my $t;
6383 +my $php_child = -1;
6384  
6385 +my $phpbin = (defined $ENV{'PHP'} ? $ENV{'PHP'} : '/usr/bin/php-cgi');
6386  
6387  SKIP: {
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");
6392 +}
6393  
6394 -       ok($tf->start_proc == 0, "Starting lighttpd") or die();
6395 +SKIP: {
6396 +       skip "no PHP running on port 1026", 6 unless $tf->listening_on(1026);
6397  
6398 +       ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
6399 +
6400         $t->{REQUEST}  = ( <<EOF
6401  GET /rewrite/foo HTTP/1.0
6402  Host: www.example.org
6403 @@ -44,5 +52,27 @@
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');
6406  
6407 +       $t->{REQUEST}  = ( <<EOF
6408 +GET %2Frewrite/f%6Fo?a=b HTTP/1.0
6409 +Host: www.example.org
6410 +EOF
6411 + );
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');
6414 +
6415         ok($tf->stop_proc == 0, "Stopping lighttpd");
6416  }
6417 +
6418 +SKIP: {
6419 +       skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
6420 +       ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
6421 +}
6422 +
6423 +
6424 +exit 0;
6425 +
6426 +cleanup: ;
6427 +
6428 +$tf->endspawnfcgi($php_child) if $php_child != -1;
6429 +
6430 +die();
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)
6435 @@ -3,7 +3,6 @@
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"
6440  
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)
6447 @@ -1,5 +1,4 @@
6448  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6449 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6450  
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)
6457 @@ -1,5 +1,4 @@
6458  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6459 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
6460  
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)
6467 @@ -1,5 +1,4 @@
6468  server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
6469 -server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd-proxy.pid"
6470  
6471  ## bind to port (default: 80)
6472  server.port                 = 2050
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)
6477 @@ -1,3 +1,4 @@
6478  <?php
6479 -       print $_ENV[$_GET["env"]];
6480 +       $env = $_GET["env"];
6481 +       print isset($_ENV[$env]) ? $_ENV[$env] : '';
6482  ?>
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)
6487 @@ -1,4 +1,4 @@
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)
6497 @@ -42,8 +42,6 @@
6498        mod-redirect.t \
6499        mod-rewrite.t \
6500        mod-userdir.t \
6501 -         env-variables.t \
6502 -         env-variables.conf \
6503           symlink.t \
6504        request.t \
6505        mod-ssi.t \
6506
6507 Property changes on: tests/core-404-handler.t
6508 ___________________________________________________________________
6509 Added: svn:executable
6510    + *
6511
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)
6516 @@ -6,6 +6,7 @@
6517  use Test::More;
6518  use Socket;
6519  use Cwd 'abs_path';
6520 +use POSIX ":sys_wait_h";
6521  
6522  sub mtime {
6523         my $file = shift;
6524 @@ -30,14 +31,17 @@
6525  
6526  
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';
6533 +               } else {
6534 +                       $self->{MODULES_PATH} = $self->{BASEDIR}.'/src';
6535 +               }
6536         } else {
6537 -               $self->{LIGHTTPD_PATH} = $self->{BASEDIR}.'/build/lighttpd';
6538 +               $self->{BINDIR} = $self->{BASEDIR}.'/build';
6539                 $self->{MODULES_PATH} = $self->{BASEDIR}.'/build';
6540         }
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;
6545  
6546         my ($name, $aliases, $addrtype, $net) = gethostbyaddr(inet_aton("127.0.0.1"), AF_INET);
6547 @@ -66,59 +70,73 @@
6548  sub stop_proc {
6549         my $self = shift;
6550  
6551 -       open F, $self->{LIGHTTPD_PIDFILE} or return -1;
6552 -       my $pid = <F>;
6553 -       close F;
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));
6558 +       } else {
6559 +               diag("Process not started, nothing to stop");
6560 +               return -1;
6561 +       }
6562  
6563 -       if (defined $pid) {
6564 -               kill('TERM',$pid) or return -1;
6565 +       return 0;
6566 +}
6567 +
6568 +sub wait_for_port_with_proc {
6569 +       my $self = shift;
6570 +       my $port = shift;
6571 +       my $child = shift;
6572 +
6573 +       while (0 == $self->listening_on($port)) {
6574                 select(undef, undef, undef, 0.1);
6575 +
6576 +               # the process is gone, we failed
6577 +               if (0 != waitpid($child, WNOHANG)) {
6578 +                       return -1;
6579 +               }
6580         }
6581  
6582         return 0;
6583  }
6584  
6585 -
6586  sub start_proc {
6587         my $self = shift;
6588         # kill old proc if necessary
6589 -       $self->stop_proc;
6590 +       #$self->stop_proc;
6591  
6592         # pre-process configfile if necessary
6593         #
6594  
6595         $ENV{'SRCDIR'} = $self->{BASEDIR}.'/tests';
6596 +       $ENV{'PORT'} = $self->{PORT};
6597  
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}." &");
6610 -       } else {
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;
6613         }
6614 -
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); 
6618 -       }
6619 -
6620 -       unlink($self->{TESTDIR}."/tmp/cfg.file");
6621 -
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");
6629                 return -1;
6630         }
6631 +       if ($child == 0) {
6632 +               exec $cmdline or die($?);
6633 +       }
6634  
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));
6640                 return -1;
6641         }
6642  
6643 +       $self->{LIGHTTPD_PID} = $child;
6644 +
6645         0;
6646  }
6647  
6648 @@ -131,6 +149,7 @@
6649  
6650         my @request = $t->{REQUEST};
6651         my @response = $t->{RESPONSE};
6652 +       my $is_debug = $ENV{"TRACE_HTTP"};
6653  
6654         my $remote = 
6655           IO::Socket::INET->new(Proto    => "tcp",
6656 @@ -144,20 +163,27 @@
6657  
6658         $remote->autoflush(1);
6659  
6660 +       diag("sending request header to ".$host.":".$self->{PORT}) if $is_debug;
6661         foreach(@request) {
6662                 # pipeline requests
6663                 s/\r//g;
6664                 s/\n/$EOL/g;
6665  
6666 -               print $remote $_.$BLANK;        
6667 +               print $remote $_.$BLANK;
6668 +               diag("<< ".$_) if $is_debug;
6669         }
6670 +       shutdown($remote, 1); # I've stopped writing data
6671 +       diag("... done") if $is_debug;
6672  
6673         my $lines = "";
6674  
6675 +       diag("receiving response") if $is_debug;
6676         # read everything
6677         while(<$remote>) {
6678                 $lines .= $_;
6679 +               diag(">> ".$_) if $is_debug;
6680         }
6681 +       diag("... done") if $is_debug;
6682         
6683         close $remote;
6684  
6685 @@ -187,18 +213,24 @@
6686                                         (my $h = $1) =~ tr/[A-Z]/[a-z]/;
6687  
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;
6694                                         } else {
6695                                                 $resp_hdr{$h} = $2;
6696                                         }
6697                                 } else {
6698 -                                       diag(sprintf("unexpected line '$line'\n"));
6699 +                                       diag(sprintf("unexpected line '%s'\n", $line));
6700                                         return -1;
6701                                 }
6702                         }
6703                 }
6704  
6705 +               if (not defined($resp_line)) {
6706 +                       diag(sprintf("empty response\n"));
6707 +                       return -1;
6708 +               }
6709 +
6710                 $t->{etag} = $resp_hdr{'etag'};
6711                 $t->{date} = $resp_hdr{'date'};
6712  
6713 @@ -227,7 +259,7 @@
6714                                 return -1;
6715                         }
6716                 } else {
6717 -                       diag(sprintf("unexpected resp_line '$resp_line'\n"));
6718 +                       diag(sprintf("unexpected resp_line '%s'\n", $resp_line));
6719                         return -1;
6720                 }
6721  
6722 @@ -237,7 +269,9 @@
6723                                 diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
6724                                 return -1;
6725                         }
6726 -               } elsif (defined $href->{'-HTTP-Content'}) {
6727 +               }
6728 +               
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));
6732                                 return -1;
6733 @@ -245,7 +279,6 @@
6734                 }
6735  
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';
6741 @@ -257,7 +290,6 @@
6742                         my $key_inverted = 0;
6743  
6744                         if (substr($k, 0, 1) eq '+') {
6745 -                               ## the key has to exist, but the value is ignored
6746                                 $k = substr($k, 1);
6747                                 $verify_value = 0;
6748                         } elsif (substr($k, 0, 1) eq '-') {
6749 @@ -265,11 +297,11 @@
6750                                 $k = substr($k, 1);
6751                                 $key_inverted = 1;
6752                                 $verify_value = 0; ## skip the value check
6753 -                       }
6754 +                        }
6755  
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));
6760                                         return -1;
6761                                 }
6762                         } else {
6763 @@ -297,12 +329,38 @@
6764  
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));
6769                 return -1;
6770         }
6771  
6772         return 0;
6773  }
6774 -    
6775 +
6776 +sub spawnfcgi {
6777 +       my ($self, $binary, $port) = @_;
6778 +       my $child = fork();
6779 +       if (not defined $child) {
6780 +               diag("Couldn't fork\n");
6781 +               return -1;
6782 +       }
6783 +       if ($child == 0) {
6784 +               my $cmd = $self->{BINDIR}.'/spawn-fcgi -n -p '.$port.' -f "'.$binary.'"';
6785 +               exec $cmd or die($?);
6786 +       } else {
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));
6789 +                       return -1;
6790 +               }
6791 +               return $child;
6792 +       }
6793 +}
6794 +
6795 +sub endspawnfcgi {
6796 +       my ($self, $pid) = @_;
6797 +       return -1 if (-1 == $pid);
6798 +       kill(2, $pid);
6799 +       waitpid($pid, 0);
6800 +       return 0;
6801 +}
6802 +
6803  1;
6804 -
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)
6809 @@ -3,17 +3,18 @@
6810  use strict;
6811  
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'} : '');
6816  
6817  my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
6818  
6819  opendir DIR, $srcdir;
6820  my (@fs, $f);
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;
6826         }
6827  }
6828  closedir DIR;
6829  runtests @fs;
6830 -
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)
6835 @@ -46,10 +46,10 @@
6836  Options
6837  =======
6838  
6839 -userdir.path
6840 +userdir.path (required option)
6841    usually it should be set to "public_html" to take ~/public_html/ as the document root
6842  
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)
6845    Example: ::
6846  
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)
6852 @@ -513,3 +513,6 @@
6853  
6854  debug.log-request-handling
6855    default: disabled
6856 +
6857 +debug.log-ssl-noise
6858 +  default: disabled
6859 Index: SConstruct
6860 ===================================================================
6861 --- SConstruct  (.../tags/lighttpd-1.4.19)      (revision 2303)
6862 +++ SConstruct  (.../branches/lighttpd-1.4.x)   (revision 2303)
6863 @@ -5,7 +5,7 @@
6864  from stat import *
6865  
6866  package = 'lighttpd'
6867 -version = '1.4.19'
6868 +version = '1.4.20'
6869  
6870  def checkCHeaders(autoconf, hdrs):
6871         p = re.compile('[^A-Z0-9]')
6872 Index: Makefile.am
6873 ===================================================================
6874 --- Makefile.am (.../tags/lighttpd-1.4.19)      (revision 2303)
6875 +++ Makefile.am (.../branches/lighttpd-1.4.x)   (revision 2303)
6876 @@ -1,3 +1,5 @@
6877  SUBDIRS=src doc tests cygwin openwrt
6878  
6879 -EXTRA_DIST=lighttpd.spec autogen.sh SConstruct
6880 +EXTRA_DIST=autogen.sh SConstruct
6881 +
6882 +distcleancheck_listfiles = find -type f -exec sh -c 'test -f $(srcdir)/{} || echo {}' ';'
6883 Index: NEWS
6884 ===================================================================
6885 --- NEWS        (.../tags/lighttpd-1.4.19)      (revision 2303)
6886 +++ NEWS        (.../branches/lighttpd-1.4.x)   (revision 2303)
6887 @@ -3,8 +3,67 @@
6888  NEWS
6889  ====
6890  
6891 -- 1.4.19 -
6892 +- 1.4.20 -
6893  
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)
6950 +
6951 +- 1.4.19 - 2008-03-10
6952 +
6953    * added support for If-Range: <date> (#1346)
6954    * added support for matching $HTTP["scheme"] in configs
6955    * fixed initgroups() called after chroot (#1384)
6956 Index: .cvsignore
6957 ===================================================================
6958
6959 Property changes on: .
6960 ___________________________________________________________________
6961 Modified: svk:merge
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>
6981 properties: 
6982         branch-nick: lighttpd-1.4.x
6983
6984 Added: bzr:file-ids
6985    + 
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
7031
7032
This page took 1.386305 seconds and 4 git commands to generate.