1 --- lighttpd-1.4.11/NEWS 2006-03-09 19:34:33.000000000 +0200
2 +++ lighttpd/NEWS 2006-07-11 21:23:42.928033114 +0300
9 + * added handling of Content-Range to PUT requests in mod_webdav
10 + * added handling of ETag and If-Modified-Since to mod_compress if
11 + cache-dir is not set
12 + * added experimental LOCK support for mod_webdav
13 + * added support for X-Sendfile as addition to X-LIGHTTPD-send-file.
14 + This allows compatibility with mod_xsendfile for apache
15 + (http://celebnamer.celebworld.ws/stuff/mod_xsendfile/)
16 + * fixed handling of If-Modified-Since if Etag is not set
17 + * fixed hanging fastcgi connections
18 + * fixed stalling SSL POST requests
19 + * fixed round-robin load-balancing in mod_proxy
20 + * TODO: add fail-over to mod-proxy
21 + * TODO: fix CACHE_HIT/MISS in mod_cml
22 + * TODO: finish LOCK/UNLOCK in mod_webdav
26 * added ability to specify which ip address spawn-fci listens on
27 --- lighttpd-1.4.11/configure.in 2006-03-04 16:32:38.000000000 +0200
28 +++ lighttpd/configure.in 2006-07-11 21:23:42.880030107 +0300
31 # Process this file with autoconf to produce a configure script.
33 -AC_INIT(lighttpd, 1.4.11, jan@kneschke.de)
34 +AC_INIT(lighttpd, 1.4.12, jan@kneschke.de)
35 AC_CONFIG_SRCDIR([src/server.c])
42 -AC_CHECK_MEMBER(struct tm.tm_gmtoff,AC_DEFINE([HAVE_STRUCT_TM_GMTOFF],[1],[gmtoff in struct tm]),,[#include <time.h>])
43 +AC_CHECK_MEMBER(struct tm.tm_gmtoff,[AC_DEFINE([HAVE_STRUCT_TM_GMTOFF],[1],[gmtoff in struct tm])],,[#include <time.h>])
44 AC_CHECK_TYPES(struct sockaddr_storage,,,[#include <sys/socket.h>])
45 AC_CHECK_TYPES(socklen_t,,,[#include <sys/types.h>
46 #include <sys/socket.h>])
48 AC_DEFINE([HAVE_SQLITE3], [1], [libsqlite3])
49 AC_DEFINE([HAVE_SQLITE3_H], [1], [sqlite3.h])
52 + AC_MSG_CHECKING(for locks in mod_webdav)
53 + AC_ARG_WITH(webdav-locks, AC_HELP_STRING([--with-webdav-locks],[locks in mod_webdav]),
54 + [WITH_WEBDAV_LOCKS=$withval],[WITH_WEBDAV_LOCKS=no])
55 + AC_MSG_RESULT([$WITH_WEBDAV_LOCKS])
57 + if test "$WITH_WEBDAV_LOCKS" != "no"; then
58 + AC_CHECK_LIB(uuid, uuid_unparse, [
59 + AC_CHECK_HEADERS([uuid/uuid.h],[
61 + AC_DEFINE([HAVE_UUID], [1], [libuuid])
62 + AC_DEFINE([HAVE_UUID_H], [1], [uuid/uuid.h is available])
72 AC_MSG_RESULT($WITH_LUA)
73 if test "$WITH_LUA" != "no"; then
74 - AC_PATH_PROG(LUACONFIG, lua-config)
76 - if test x"$LUACONFIG" != x; then
77 - LUA_CFLAGS=`$LUACONFIG --include`
78 - LUA_LIBS=`$LUACONFIG --libs --extralibs`
79 - AC_DEFINE([HAVE_LUA], [1], [liblua])
80 - AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
82 - AC_CHECK_LIB(lua, lua_open, [
83 - AC_CHECK_HEADERS([lua.h],[
84 - LUA_LIBS="-llua -llualib"
85 - AC_DEFINE([HAVE_LUA], [1], [liblua])
86 - AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
91 - if test x"$LUA_LIBS" = x; then
93 - PKG_CHECK_MODULES(LUA, lua, [
94 + PKG_CHECK_MODULES(LUA, lua >= 5.1, [
95 AC_DEFINE([HAVE_LUA], [1], [liblua])
96 AC_DEFINE([HAVE_LUA_H], [1], [lua.h])
105 AC_CHECK_FUNCS([dup2 getcwd inet_ntoa inet_ntop memset mmap munmap strchr \
106 - strdup strerror strstr strtol sendfile getopt socket \
107 + strdup strerror strstr strtol sendfile getopt socket lstat \
108 gethostbyname poll sigtimedwait epoll_ctl getrlimit chroot \
109 getuid select signal pathconf madvise posix_fadvise posix_madvise \
110 writev sigaction sendfile64 send_file kqueue port_create localtime_r])
115 -do_build="mod_cgi mod_fastcgi mod_proxy mod_evhost mod_simple_vhost mod_access mod_alias mod_setenv mod_usertrack mod_auth mod_status mod_accesslog mod_rrdtool mod_secdownload mod_expire mod_compress mod_dirlisting mod_indexfiles mod_userdir mod_webdav mod_staticfile mod_scgi"
116 +do_build="mod_cgi mod_fastcgi mod_proxy mod_evhost mod_simple_vhost mod_access mod_alias mod_setenv mod_usertrack mod_auth mod_status mod_accesslog mod_rrdtool mod_secdownload mod_expire mod_compress mod_dirlisting mod_indexfiles mod_userdir mod_webdav mod_staticfile mod_scgi mod_flv_streaming"
118 plugins="mod_rewrite mod_redirect mod_ssi mod_trigger_b4_dl"
119 features="regex-conditionals"
121 disable_feature="$disable_feature $features"
124 +features="webdav-locks"
125 +if test "x$UUID_LIB" \!= x; then
126 + enable_feature="$enable_feature $features"
128 + disable_feature="$disable_feature $features"
135 --- lighttpd-1.4.11/doc/authentication.txt 2006-01-12 20:34:26.000000000 +0200
136 +++ lighttpd/doc/authentication.txt 2006-07-11 21:23:42.708019334 +0300
140 :Author: Jan Kneschke
142 -:Revision: $Revision$
144 +:Revision: $Revision$
147 The auth module provides ...
148 --- lighttpd-1.4.11/doc/compress.txt 2005-08-11 01:26:16.000000000 +0300
149 +++ lighttpd/doc/compress.txt 2006-07-11 21:23:42.680017580 +0300
153 Output compression reduces the network load and can improve the overall
154 -throughput of the webserver.
155 +throughput of the webserver. All major http-clients support compression by
156 +announcing it in the Accept-Encoding header. This is used to negotiate the
157 +most suitable compression method. We support deflate, gzip and bzip2.
159 -Only static content is supported up to now.
160 +deflate (RFC1950, RFC1951) and gzip (RFC1952) depend on zlib while bzip2
161 +depends on libbzip2. bzip2 is only supported by lynx and some other console
164 -The server negotiates automaticly which compression method is used.
165 -Supported are gzip, deflate, bzip.
166 +Currently we limit to compression support to static files.
171 +mod_compress can stored compressed files on disk to optimized the compression
172 +on a second request away. As soon as compress.cache-dir is set the files are
175 +The names of the cache files are made of the filename, the compression method
176 +and the etag associated to the file.
178 +Cleaning the cache is left to the user. A cron job deleting files older than
179 +10 days should do fine.
184 +The module limits the compression of files to files larger than 128 Byte and
185 +smaller than 128 MByte.
187 +The lower limit is set as small files tend to become larger by compressing due
188 +to the compression headers, the upper limit is set to work sensable with
189 +memory and cpu-time.
194 Default: not set, compress the file for every request
197 - mimetypes where might get compressed
198 + mimetypes which might get compressed
202 compress.filetype = ("text/plain", "text/html")
204 + Keep in mind that compressed JavaScript and CSS files are broken in some
209 +compress.max-file-size
210 + maximum size of the original file to be compressed kBytes.
212 + This is meant to protect the server against DoSing as compressing large
213 + (let's say 1Gbyte) takes a lot of time and would delay the whole operation
216 + There is a hard upper limit of 128Mbyte.
218 + Default: unlimited (== hard-limit of 128MByte)
220 Compressing Dynamic Content
221 ===========================
222 --- lighttpd-1.4.11/doc/configuration.txt 2006-03-09 02:10:40.000000000 +0200
223 +++ lighttpd/doc/configuration.txt 2006-07-11 21:23:42.696018582 +0300
227 :Author: Jan Kneschke
229 -:Revision: $Revision$
231 +:Revision: $Revision$
234 the layout of the configuration file
237 debug.log-request-handling
240 +debug.log-condition-handling
243 +debug.log-condition-cache-handling
244 + for developers only
246 --- lighttpd-1.4.11/doc/fastcgi.txt 2006-02-16 17:03:52.000000000 +0200
247 +++ lighttpd/doc/fastcgi.txt 2006-07-11 21:23:42.712019584 +0300
249 PHP can extract PATH_INFO from it (default: disabled)
250 :"disable-time": time to wait before a disabled backend is checked
252 - :"allow-x-send-file": controls if X-LIGHTTPD-send-file headers
254 + :"allow-x-send-file": controls if X-LIGHTTPD-send-file and X-Sendfile
255 + headers are allowed
259 --- lighttpd-1.4.11/doc/lighttpd.conf 2006-03-04 14:41:12.000000000 +0200
260 +++ lighttpd/doc/lighttpd.conf 2006-07-11 21:23:42.736021088 +0300
262 #debug.log-response-header = "enable"
263 #debug.log-request-handling = "enable"
264 #debug.log-file-not-found = "enable"
265 +#debug.log-condition-handling = "enable"
267 ### only root can use these options
269 --- lighttpd-1.4.11/doc/performance.txt 2006-02-02 13:01:08.000000000 +0200
270 +++ lighttpd/doc/performance.txt 2006-07-11 21:23:42.632014574 +0300
273 server.stat-cache-engine = "fam" # either fam, simple or disabled
275 +See http://oss.sgi.com/projects/fam/faq.html for information about FAM.
276 +See http://www.gnome.org/~veillard/gamin/overview.html for information about gamin.
278 Platform-Specific Notes
279 =======================
280 --- lighttpd-1.4.11/doc/secdownload.txt 2005-12-20 15:58:58.000000000 +0200
281 +++ lighttpd/doc/secdownload.txt 2006-07-11 21:23:42.640015075 +0300
283 $secret = "verysecret";
284 $uri_prefix = "/dl/";
287 + # filename, make sure it's started with a "/" or you'll get 404 in the browser
288 $f = "/secret-file.txt";
291 --- lighttpd-1.4.11/src/Makefile.am 2006-03-07 14:20:20.000000000 +0200
292 +++ lighttpd/src/Makefile.am 2006-07-11 21:23:40.099855979 +0300
295 configparser.y: lemon
296 mod_ssi_exprparser.y: lemon
297 +http_resp_parser.y: lemon
299 configparser.c configparser.h: configparser.y
301 - $(LEMON) -q $(srcdir)/configparser.y $(srcdir)/lempar.c
302 + $(LEMON) -q $(srcdir)/$< $(srcdir)/lempar.c
304 +http_resp_parser.c http_resp_parser.h: http_resp_parser.y
305 + rm -f http_resp_parser.h
306 + $(LEMON) -q $(srcdir)/$< $(srcdir)/lempar.c
308 mod_ssi_exprparser.c mod_ssi_exprparser.h: mod_ssi_exprparser.y
309 rm -f mod_ssi_exprparser.h
310 - $(LEMON) -q $(srcdir)/mod_ssi_exprparser.y $(srcdir)/lempar.c
311 + $(LEMON) -q $(srcdir)/$< $(srcdir)/lempar.c
314 configfile.c: configparser.h
316 network_write.c network_linux_sendfile.c \
317 network_freebsd_sendfile.c network_writev.c \
318 network_solaris_sendfilev.c network_openssl.c \
320 + splaytree.c http_resp.c http_resp_parser.c
322 src = server.c response.c connections.c network.c \
323 configfile.c configparser.c request.c proc_open.c
325 mod_webdav_la_SOURCES = mod_webdav.c
326 mod_webdav_la_CFLAGS = $(AM_CFLAGS) $(XML_CFLAGS) $(SQLITE_CFLAGS)
327 mod_webdav_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
328 -mod_webdav_la_LIBADD = $(common_libadd) $(XML_LIBS) $(SQLITE_LIBS)
329 +mod_webdav_la_LIBADD = $(common_libadd) $(XML_LIBS) $(SQLITE_LIBS) $(UUID_LIB)
331 lib_LTLIBRARIES += mod_cml.la
332 mod_cml_la_SOURCES = mod_cml.c mod_cml_lua.c mod_cml_funcs.c
334 mod_mysql_vhost_la_LIBADD = $(MYSQL_LIBS) $(common_libadd)
335 mod_mysql_vhost_la_CPPFLAGS = $(MYSQL_INCLUDE)
337 +lib_LTLIBRARIES += mod_sql_vhost_core.la
338 +mod_sql_vhost_core_la_SOURCES = mod_sql_vhost_core.c
339 +mod_sql_vhost_core_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
340 +mod_sql_vhost_core_la_LIBADD = $(common_libadd)
342 lib_LTLIBRARIES += mod_cgi.la
343 mod_cgi_la_SOURCES = mod_cgi.c
344 mod_cgi_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
346 mod_ssi.h mod_ssi_expr.h inet_ntop_cache.h \
347 configparser.h mod_ssi_exprparser.h \
348 sys-mmap.h sys-socket.h mod_cml.h mod_cml_funcs.h \
349 - splaytree.h proc_open.h
350 + splaytree.h proc_open.h http_resp.h mod_sql_vhost_core.h
352 DEFS= @DEFS@ -DLIBRARY_DIR="\"$(libdir)\""
354 --- lighttpd-1.4.11/src/array.c 2005-11-18 13:58:32.000000000 +0200
355 +++ lighttpd/src/array.c 2006-07-11 21:23:39.943846207 +0300
360 - /* generate unique index if neccesary */
361 + /* generate unique index if necessary */
362 if (str->key->used == 0 || str->is_index_key) {
363 buffer_copy_long(str->key, a->unique_ndx++);
364 str->is_index_key = 1;
369 - /* move everything on step to the right */
370 + /* move everything one step to the right */
372 memmove(a->sorted + (pos + 1), a->sorted + (pos), (ndx - pos) * sizeof(*a->sorted));
374 --- lighttpd-1.4.11/src/array.h 2005-09-23 21:24:18.000000000 +0300
375 +++ lighttpd/src/array.h 2006-07-11 21:23:39.963847460 +0300
380 - int is_index_key; /* 1 if key is a array index (autogenerated keys) */ \
381 + int is_index_key; /* 1 if key is an array index (auto-generated keys) */ \
382 struct data_unset *(*copy)(const struct data_unset *src); \
383 void (* free)(struct data_unset *p); \
384 void (* reset)(struct data_unset *p); \
385 --- lighttpd-1.4.11/src/base.h 2006-01-11 16:51:04.000000000 +0200
386 +++ lighttpd/src/base.h 2006-07-11 21:23:39.947846458 +0300
390 #include <sys/types.h>
391 -#include <sys/time.h>
392 #include <sys/stat.h>
396 #include "sys-socket.h"
397 #include "splaytree.h"
400 #if defined HAVE_LIBSSL && defined HAVE_OPENSSL_SSL_H
402 # include <openssl/ssl.h>
408 -# define O_LARGEFILE 0
413 # define SIZE_MAX SIZE_T_MAX
416 /* solaris and NetBSD 1.3.x again */
417 #if (!defined(HAVE_STDINT_H)) && (!defined(HAVE_INTTYPES_H)) && (!defined(uint32_t))
418 -# define uint32_t u_int32_t
419 +/* # define uint32_t u_int32_t */
420 +typedef unsigned __int32 uint32_t;
427 off_t content_length;
428 - int keep_alive; /* used by the subrequests in proxy, cgi and fcgi to say the subrequest was keep-alive or not */
429 + int keep_alive; /* used by the subrequests in proxy, cgi and fcgi to say whether the subrequest was keep-alive or not */
437 - splay_tree *files; /* the nodes of the tree are stat_cache_entry's */
438 + splay_tree *files; /* the nodes of the tree are stat_cache_entries */
440 buffer *dir_name; /* for building the dirname from the filename */
443 unsigned short log_request_handling;
444 unsigned short log_response_header;
445 unsigned short log_condition_handling;
446 + unsigned short log_condition_cache_handling;
450 @@ -272,13 +268,13 @@
451 /* server-wide traffic-shaper
453 * each context has the counter which is inited once
454 - * a second by the global_kbytes_per_second config-var
455 + * per second by the global_kbytes_per_second config-var
457 * as soon as global_kbytes_per_second gets below 0
458 * the connected conns are "offline" a little bit
461 - * we somehow have to loose our "we are writable" signal
462 + * we somehow have to lose our "we are writable" signal
470 - int keep_alive; /* only request.c can enable it, all other just disable */
471 + int keep_alive; /* only request.c can enable it, all others just disable */
480 + NETWORK_STATUS_UNSET,
481 + NETWORK_STATUS_SUCCESS,
482 + NETWORK_STATUS_FATAL_ERROR,
483 + NETWORK_STATUS_CONNECTION_CLOSE,
484 + NETWORK_STATUS_WAIT_FOR_EVENT,
485 + NETWORK_STATUS_INTERRUPTED
491 @@ -591,15 +596,17 @@
493 fdevent_handler_t event_handler;
495 - int (* network_backend_write)(struct server *srv, connection *con, int fd, chunkqueue *cq);
496 - int (* network_backend_read)(struct server *srv, connection *con, int fd, chunkqueue *cq);
497 + network_status_t (* network_backend_write)(struct server *srv, connection *con, int fd, chunkqueue *cq);
498 + network_status_t (* network_backend_read)(struct server *srv, connection *con, int fd, chunkqueue *cq);
500 - int (* network_ssl_backend_write)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
501 - int (* network_ssl_backend_read)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
502 + network_status_t (* network_ssl_backend_write)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
503 + network_status_t (* network_ssl_backend_read)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
513 --- lighttpd-1.4.11/src/buffer.c 2006-01-13 00:00:45.000000000 +0200
514 +++ lighttpd/src/buffer.c 2006-07-11 21:23:40.087855227 +0300
519 - * allocate (if neccessary) enough space for 'size' bytes and
520 + * allocate (if necessary) enough space for 'size' bytes and
521 * set the 'used' counter to 0
528 - /* always allocate a multiply of BUFFER_PIECE_SIZE */
529 + /* always allocate a multiple of BUFFER_PIECE_SIZE */
530 b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE);
532 b->ptr = malloc(b->size);
537 - * increase the internal buffer (if neccessary) to append another 'size' byte
538 + * increase the internal buffer (if necessary) to append another 'size' byte
539 * ->used isn't changed
546 - /* always allocate a multiply of BUFFER_PIECE_SIZE */
547 + /* always allocate a multiple of BUFFER_PIECE_SIZE */
548 b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE);
550 b->ptr = malloc(b->size);
552 } else if (b->used + size > b->size) {
555 - /* always allocate a multiply of BUFFER_PIECE_SIZE */
556 + /* always allocate a multiple of BUFFER_PIECE_SIZE */
557 b->size += BUFFER_PIECE_SIZE - (b->size % BUFFER_PIECE_SIZE);
559 b->ptr = realloc(b->ptr, b->size);
561 * append a string to the end of the buffer
563 * the resulting buffer is terminated with a '\0'
564 - * s is treated as a un-terminated string (a \0 is handled a normal character)
565 + * s is treated as an un-terminated string (a \0 is handled as a normal character)
568 * @param s the string
573 + * init the ptr buffer
576 +buffer_ptr *buffer_ptr_init(buffer_ptr_free_t freer)
578 + buffer_ptr *l = calloc(1, sizeof(buffer_ptr));
585 + * free the buffer_array
588 +void buffer_ptr_free(buffer_ptr *l)
591 + buffer_ptr_clear(l);
596 +void buffer_ptr_clear(buffer_ptr *l)
600 + if (l->free && l->used) {
602 + for (i = 0; i < l->used; i ++) {
603 + l->free(l->ptr[i]);
615 +void buffer_ptr_append(buffer_ptr* l, void *item)
618 + if (l->ptr == NULL) {
620 + l->ptr = (void **)malloc(sizeof(void *) * l->size);
622 + else if (l->used == l->size) {
624 + l->ptr = realloc(l->ptr, sizeof(void *) * l->size);
626 + l->ptr[l->used++] = item;
629 +void *buffer_ptr_pop(buffer_ptr* l)
631 + assert(NULL != l && l->used > 0);
632 + return l->ptr[--l->used];
635 +void *buffer_ptr_top(buffer_ptr* l)
637 + assert(NULL != l && l->used > 0);
638 + return l->ptr[l->used-1];
649 - * check if two buffer contain the same data
650 + * check if two buffers contain the same data
652 * HISTORY: this function was pretty much optimized, but didn't handled
653 * alignment properly.
656 /* simple-assumption:
658 - * most parts are equal and doing a case conversion needs time
659 + * most parts are equal and doing a case conversion takes time
662 int buffer_caseless_compare(const char *a, size_t a_len, const char *b, size_t b_len) {
664 if (b1->used == 0 || b2->used == 0) return 0;
666 /* buffers too small -> not equal */
667 - if (b1->used - 1 < len || b1->used - 1 < len) return 0;
668 + if (b1->used - 1 < len || b2->used - 1 < len) return 0;
670 if (0 == strncmp(b1->ptr + b1->used - 1 - len,
671 b2->ptr + b2->used - 1 - len, len)) {
672 @@ -760,12 +829,12 @@
673 map = encoded_chars_hex;
677 + return buffer_append_string_len(b, s, s_len);
682 - /* count to-be-encoded-characters */
683 + /* count to-be-encoded characters */
684 for (ds = (unsigned char *)s, d_len = 0, ndx = 0; ndx < s_len; ds++, ndx++) {
691 -/* decodes url-special-chars inplace.
692 +/* decodes url-special chars in-place.
693 * replaces non-printable characters with '_'
698 high = (high << 4) | low;
700 - /* map control-characters out */
701 + /* map out control characters */
702 if (high < 32 || high == 127) high = '_';
706 * /abc/./xyz gets /abc/xyz
707 * /abc//xyz gets /abc/xyz
709 - * NOTE: src and dest can point to the same buffer, in which case,
710 + * NOTE: src and dest can point to the same buffer, in which case
711 * the operation is performed in-place.
714 @@ -993,6 +1062,31 @@
715 return light_isdigit(c) || light_isalpha(c);
718 +#undef BUFFER_CTYPE_FUNC
719 +#define BUFFER_CTYPE_FUNC(type) \
720 + int buffer_is##type(buffer *b) { \
722 + if (b->used < 2) return 0; \
724 + len = b->used - 1; \
725 + /* c-string only */ \
726 + if (b->ptr[len] != '\0') { \
729 + /* check on the whole string */ \
730 + for (i = 0; i < len; i ++) { \
731 + if (!light_is##type(b->ptr[i])) { \
738 +BUFFER_CTYPE_FUNC(digit)
739 +BUFFER_CTYPE_FUNC(xdigit)
740 +BUFFER_CTYPE_FUNC(alpha)
741 +BUFFER_CTYPE_FUNC(alnum)
743 int buffer_to_lower(buffer *b) {
746 --- lighttpd-1.4.11/src/buffer.h 2006-01-13 00:00:45.000000000 +0200
747 +++ lighttpd/src/buffer.h 2006-07-11 21:23:40.095855728 +0300
753 +typedef void (*buffer_ptr_free_t)(void *p);
759 + buffer_ptr_free_t free;
769 - size_t offset; /* input-pointer */
770 + size_t offset; /* input pointer */
772 - size_t used; /* output-pointer */
773 + size_t used; /* output pointer */
777 +buffer_ptr *buffer_ptr_init(buffer_ptr_free_t freer);
778 +void buffer_ptr_free(buffer_ptr *b);
779 +void buffer_ptr_clear(buffer_ptr *b);
780 +void buffer_ptr_append(buffer_ptr *b, void *item);
781 +void *buffer_ptr_pop(buffer_ptr *b);
782 +void *buffer_ptr_top(buffer_ptr *b);
784 buffer_array* buffer_array_init(void);
785 void buffer_array_free(buffer_array *b);
786 void buffer_array_reset(buffer_array *b);
791 - ENCODING_REL_URI, /* for coding a rel-uri (/with space/and%percent) nicely as part of a href */
792 - ENCODING_REL_URI_PART, /* same as ENC_REL_URL plus coding / too as %2F */
793 - ENCODING_HTML, /* & becomes & and so on */
794 + ENCODING_REL_URI, /* for coding a rel-uri (/with space/and%percent) nicely as part of an href */
795 + ENCODING_REL_URI_PART, /* same as ENC_REL_URL plus encoding "/" as "%2F" */
796 + ENCODING_HTML, /* "&" becomes "&" and so on */
797 ENCODING_MINIMAL_XML, /* minimal encoding for xml */
798 ENCODING_HEX /* encode string as hex */
800 @@ -111,19 +128,21 @@
801 int light_isalpha(int c);
802 int light_isalnum(int c);
804 +#define BUFFER_CTYPE_FUNC(type) int buffer_is##type(buffer *b);
805 +BUFFER_CTYPE_FUNC(digit)
806 +BUFFER_CTYPE_FUNC(xdigit)
807 +BUFFER_CTYPE_FUNC(alpha)
808 +BUFFER_CTYPE_FUNC(alnum)
810 #define BUFFER_APPEND_STRING_CONST(x, y) \
811 buffer_append_string_len(x, y, sizeof(y) - 1)
813 #define BUFFER_COPY_STRING_CONST(x, y) \
814 buffer_copy_string_len(x, y, sizeof(y) - 1)
816 -#define BUFFER_APPEND_SLASH(x) \
817 - if (x->used > 1 && x->ptr[x->used - 2] != '/') { BUFFER_APPEND_STRING_CONST(x, "/"); }
819 #define CONST_STR_LEN(x) x, x ? sizeof(x) - 1 : 0
820 #define CONST_BUF_LEN(x) x->ptr, x->used ? x->used - 1 : 0
823 #define SEGFAULT() do { fprintf(stderr, "%s.%d: aborted\n", __FILE__, __LINE__); abort(); } while(0)
824 #define UNUSED(x) ( (void)(x) )
826 --- lighttpd-1.4.11/src/chunk.c 2005-11-18 15:18:19.000000000 +0200
827 +++ lighttpd/src/chunk.c 2006-07-11 21:23:39.995849464 +0300
830 #include <sys/types.h>
831 #include <sys/stat.h>
832 -#include <sys/mman.h>
844 +#include "sys-mmap.h"
845 +#include "sys-files.h"
847 chunkqueue *chunkqueue_init(void) {
851 static chunk *chunkqueue_get_unused_chunk(chunkqueue *cq) {
854 - /* check if we have a unused chunk */
855 + /* check if we have an unused chunk */
860 data_string *ds = (data_string *)cq->tempdirs->data[i];
862 buffer_copy_string_buffer(template, ds->value);
863 - BUFFER_APPEND_SLASH(template);
864 + PATHNAME_APPEND_SLASH(template);
865 BUFFER_APPEND_STRING_CONST(template, "lighttpd-upload-XXXXXX");
867 if (-1 != (c->file.fd = mkstemp(template->ptr))) {
868 --- lighttpd-1.4.11/src/chunk.h 2005-11-01 09:32:21.000000000 +0200
869 +++ lighttpd/src/chunk.h 2006-07-11 21:23:40.015850717 +0300
872 char *start; /* the start pointer of the mmap'ed area */
873 size_t length; /* size of the mmap'ed area */
874 - off_t offset; /* start is <n> octet away from the start of the file */
875 + off_t offset; /* start is <n> octets away from the start of the file */
878 - int is_temp; /* file is temporary and will be deleted if on cleanup */
879 + int is_temp; /* file is temporary and will be deleted on cleanup */
882 off_t offset; /* octets sent from this chunk
883 --- lighttpd-1.4.11/src/configfile-glue.c 2006-03-03 20:14:56.000000000 +0200
884 +++ lighttpd/src/configfile-glue.c 2006-07-11 21:23:39.879842199 +0300
892 data_string *ds = (data_string *)du;
894 buffer_copy_string_buffer(cv[i].destination, ds->value);
895 + } else if (du->type == TYPE_INTEGER) {
896 + data_integer *di = (data_integer *)du;
898 + buffer_copy_long(cv[i].destination, di->value);
900 log_error_write(srv, __FILE__, __LINE__, "ssss", "unexpected type for key: ", cv[i].key, "(string)", "\"...\"");
904 data_string *ds = (data_string *)du;
906 + if (buffer_isdigit(ds->value)) {
907 + *((unsigned short *)(cv[i].destination)) = strtol(ds->value->ptr, NULL, 10);
911 log_error_write(srv, __FILE__, __LINE__, "ssb", "get a string but expected a short:", cv[i].key, ds->value);
919 + l = srv->empty_string;
925 struct in_addr val_inp;
927 + if (con->conf.log_condition_handling) {
928 + l = srv->empty_string;
930 + log_error_write(srv, __FILE__, __LINE__, "bsbsb", dc->comp_key,
931 + "(", l, ") compare to", dc->string);
934 if (*(nm_slash+1) == '\0') {
935 log_error_write(srv, __FILE__, __LINE__, "sb", "ERROR: no number after / ", dc->string);
939 /* take IP convert to the native */
940 buffer_copy_string_len(srv->cond_check_buf, dc->string->ptr, nm_slash - dc->string->ptr);
943 if (INADDR_NONE == (val_inp.s_addr = inet_addr(srv->cond_check_buf->ptr))) {
944 log_error_write(srv, __FILE__, __LINE__, "sb", "ERROR: ip addr is invalid:", srv->cond_check_buf);
947 cond_cache_t *caches = con->cond_cache;
949 if (COND_RESULT_UNSET == caches[dc->context_ndx].result) {
950 + if (con->conf.log_condition_handling) {
951 + log_error_write(srv, __FILE__, __LINE__, "sds", "=== start of", dc->context_ndx, "condition block ===");
953 if (COND_RESULT_TRUE == (caches[dc->context_ndx].result = config_check_cond_nocache(srv, con, dc))) {
956 @@ -409,11 +429,11 @@
958 if (con->conf.log_condition_handling) {
959 log_error_write(srv, __FILE__, __LINE__, "dss", dc->context_ndx,
960 - "(uncached) result:",
962 caches[dc->context_ndx].result == COND_RESULT_TRUE ? "true" : "false");
965 - if (con->conf.log_condition_handling) {
966 + if (con->conf.log_condition_cache_handling) {
967 log_error_write(srv, __FILE__, __LINE__, "dss", dc->context_ndx,
969 caches[dc->context_ndx].result == COND_RESULT_TRUE ? "true" : "false");
973 int config_check_cond(server *srv, connection *con, data_config *dc) {
974 - if (con->conf.log_condition_handling) {
975 - log_error_write(srv, __FILE__, __LINE__, "s", "=== start of condition block ===");
977 return (config_check_cond_cached(srv, con, dc) == COND_RESULT_TRUE);
984 +/* return <0 on error
985 + * return 0-x if matched (and replaced)
987 +int config_exec_pcre_keyvalue_buffer(connection *con, pcre_keyvalue_buffer *kvb, data_config *context, buffer *match_buf, buffer *result)
992 + const char *pattern;
993 + size_t pattern_len;
1000 + for (i = 0; i < kvb->used; i++) {
1004 + extra = kv->key_extra;
1005 + pattern = kv->value->ptr;
1006 + pattern_len = kv->value->used - 1;
1008 + if ((n = pcre_exec(match, extra, match_buf->ptr, match_buf->used - 1, 0, 0, ovec, 3 * N)) < 0) {
1009 + if (n != PCRE_ERROR_NOMATCH) {
1013 + const char **list;
1014 + size_t start, end;
1018 + pcre_get_substring_list(match_buf->ptr, ovec, n, &list);
1020 + /* search for $[0-9] */
1022 + buffer_reset(result);
1024 + start = 0; end = pattern_len;
1025 + for (k = 0; k < pattern_len; k++) {
1026 + if ((pattern[k] == '$' || pattern[k] == '%') &&
1027 + isdigit((unsigned char)pattern[k + 1])) {
1030 + size_t num = pattern[k + 1] - '0';
1034 + buffer_append_string_len(result, pattern + start, end - start);
1036 + if (pattern[k] == '$') {
1037 + /* n is always > 0 */
1038 + if (num < (size_t)n) {
1039 + buffer_append_string(result, list[num]);
1042 + config_append_cond_match_buffer(con, context, result, num);
1050 + buffer_append_string_len(result, pattern + start, pattern_len - start);
1058 + return PCRE_ERROR_NOMATCH;
1066 --- lighttpd-1.4.11/src/configfile.c 2006-02-15 14:26:42.000000000 +0200
1067 +++ lighttpd/src/configfile.c 2006-07-11 21:23:39.987848963 +0300
1072 -#include <unistd.h>
1081 -#include "license.h"
1084 #include "configparser.h"
1085 #include "configfile.h"
1086 #include "proc_open.h"
1088 +#include "sys-files.h"
1089 +#include "sys-process.h"
1093 +#define PATH_MAX 64
1096 static int config_insert(server *srv) {
1099 { "server.network-backend", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 43 */
1100 { "server.upload-dirs", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 44 */
1101 { "server.core-files", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 45 */
1102 + { "debug.log-condition-cache-handling", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER }, /* 46 */
1104 { "server.host", "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
1105 { "server.docroot", "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET },
1107 cv[14].destination = s->document_root;
1108 cv[15].destination = &(s->force_lowercase_filenames);
1109 cv[16].destination = &(s->log_condition_handling);
1110 + cv[46].destination = &(s->log_condition_cache_handling);
1111 cv[17].destination = &(s->max_keep_alive_requests);
1112 cv[18].destination = s->server_name;
1113 cv[19].destination = &(s->max_keep_alive_idle);
1119 -#define PATCH(x) con->conf.x = s->x
1121 + con->conf.x = s->x
1122 int config_setup_connection(server *srv, connection *con) {
1123 specific_config *s = srv->config_storage[0];
1126 PATCH(log_response_header);
1127 PATCH(log_request_handling);
1128 PATCH(log_condition_handling);
1129 + PATCH(log_condition_cache_handling);
1130 PATCH(log_file_not_found);
1132 PATCH(range_requests);
1134 PATCH(log_response_header);
1135 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("debug.log-condition-handling"))) {
1136 PATCH(log_condition_handling);
1137 + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("debug.log-condition-cache-handling"))) {
1138 + PATCH(log_condition_cache_handling);
1139 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("debug.log-file-not-found"))) {
1140 PATCH(log_file_not_found);
1141 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.protocol-http11"))) {
1142 @@ -699,21 +706,13 @@
1143 for (i = 0; t->input[t->offset + i] && isdigit((unsigned char)t->input[t->offset + i]); i++);
1145 /* was there it least a digit ? */
1146 - if (i && t->input[t->offset + i]) {
1150 buffer_copy_string_len(token, t->input + t->offset, i);
1156 - log_error_write(srv, __FILE__, __LINE__, "sbsdsds",
1157 - "source:", t->source,
1158 - "line:", t->line, "pos:", t->line_pos,
1159 - "unexpected EOF");
1164 /* the key might consist of [-.0-9a-z] */
1166 pParser = configparserAlloc( malloc );
1167 lasttoken = buffer_init();
1168 token = buffer_init();
1170 while((1 == (ret = config_tokenizer(srv, t, &token_id, token))) && context->ok) {
1171 buffer_copy_string_buffer(lasttoken, token);
1172 configparser(pParser, token_id, token, context);
1173 @@ -896,13 +896,12 @@
1174 static void context_init(server *srv, config_t *context) {
1177 - context->configs_stack = array_init();
1178 - context->configs_stack->is_weakref = 1;
1179 + context->configs_stack = buffer_ptr_init(NULL);
1180 context->basedir = buffer_init();
1183 static void context_free(config_t *context) {
1184 - array_free(context->configs_stack);
1185 + buffer_ptr_free(context->configs_stack);
1186 buffer_free(context->basedir);
1189 @@ -918,13 +917,10 @@
1190 context_init(srv, &context);
1191 context.all_configs = srv->config_context;
1200 + /* use the current dir as basedir for all other includes
1202 + pos = strrchr(fn, DIR_SEPERATOR);
1205 buffer_copy_string_len(context.basedir, fn, pos - fn + 1);
1207 @@ -1035,6 +1031,7 @@
1212 int config_set_defaults(server *srv) {
1214 specific_config *s = srv->config_storage[0];
1215 @@ -1077,10 +1074,11 @@
1218 if (buffer_is_empty(srv->srvconf.changeroot)) {
1219 + pathname_unix2local(s->document_root);
1220 if (-1 == stat(s->document_root->ptr, &st1)) {
1221 - log_error_write(srv, __FILE__, __LINE__, "sb",
1222 + log_error_write(srv, __FILE__, __LINE__, "sbs",
1223 "base-docroot doesn't exist:",
1224 - s->document_root);
1225 + s->document_root, strerror(errno));
1229 --- lighttpd-1.4.11/src/configfile.h 2005-08-23 17:36:12.000000000 +0300
1230 +++ lighttpd/src/configfile.h 2006-07-11 21:23:39.995849464 +0300
1235 - array *configs_stack; /* to parse nested block */
1236 + buffer_ptr *configs_stack; /* to parse nested block */
1237 data_config *current; /* current started with { */
1240 --- lighttpd-1.4.11/src/configparser.y 2006-01-26 18:46:25.000000000 +0200
1241 +++ lighttpd/src/configparser.y 2006-07-11 21:23:40.127857732 +0300
1243 dc->parent = ctx->current;
1244 array_insert_unique(dc->parent->childs, (data_unset *)dc);
1246 - array_insert_unique(ctx->configs_stack, (data_unset *)ctx->current);
1247 + buffer_ptr_append(ctx->configs_stack, (void *)ctx->current);
1251 static data_config *configparser_pop(config_t *ctx) {
1252 data_config *old = ctx->current;
1253 - ctx->current = (data_config *) array_pop(ctx->configs_stack);
1254 + ctx->current = (data_config *) buffer_ptr_pop(ctx->configs_stack);
1258 /* return a copied variable */
1259 static data_unset *configparser_get_variable(config_t *ctx, const buffer *key) {
1260 - if (strncmp(key->ptr, "env.", sizeof("env.") - 1) == 0) {
1263 - if (NULL != (env = getenv(key->ptr + 4))) {
1265 - ds = data_string_init();
1266 - buffer_append_string(ds->value, env);
1267 - return (data_unset *)ds;
1270 - fprintf(stderr, "Undefined env variable: %s\n", key->ptr + 4);
1279 return du->copy(du);
1282 - fprintf(stderr, "Undefined config variable: %s\n", key->ptr);
1288 /* op1 is to be eat/return by this function, op1->key is not cared
1289 op2 is left untouch, unreferenced
1291 %type aelement {data_unset *}
1292 %type condline {data_config *}
1293 %type condlines {data_config *}
1294 +%type global {data_config *}
1295 %type aelements {array *}
1296 %type array {array *}
1297 %type key {buffer *}
1298 @@ -161,7 +144,12 @@
1300 varline ::= key(A) ASSIGN expression(B). {
1301 buffer_copy_string_buffer(B->key, A);
1302 - if (NULL == array_get_element(ctx->current->value, B->key->ptr)) {
1303 + if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {
1304 + fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n",
1305 + ctx->current->context_ndx,
1306 + ctx->current->key->ptr, A->ptr);
1308 + } else if (NULL == array_get_element(ctx->current->value, B->key->ptr)) {
1309 array_insert_unique(ctx->current->value, B);
1312 @@ -180,7 +168,12 @@
1313 array *vars = ctx->current->value;
1316 - if (NULL != (du = array_get_element(vars, A->ptr))) {
1317 + if (strncmp(A->ptr, "env.", sizeof("env.") - 1) == 0) {
1318 + fprintf(stderr, "Appending env variable is not supported in conditional %d %s: %s\n",
1319 + ctx->current->context_ndx,
1320 + ctx->current->key->ptr, A->ptr);
1322 + } else if (NULL != (du = array_get_element(vars, A->ptr))) {
1323 /* exists in current block */
1324 du = configparser_merge_data(du, B);
1327 buffer_copy_string_buffer(du->key, A);
1328 array_replace(vars, du);
1331 } else if (NULL != (du = configparser_get_variable(ctx, A))) {
1332 du = configparser_merge_data(du, B);
1334 @@ -199,15 +193,13 @@
1335 buffer_copy_string_buffer(du->key, A);
1336 array_insert_unique(ctx->current->value, du);
1340 - fprintf(stderr, "Undefined config variable in conditional %d %s: %s\n",
1341 - ctx->current->context_ndx,
1342 - ctx->current->key->ptr, A->ptr);
1344 + buffer_copy_string_buffer(B->key, A);
1345 + array_insert_unique(ctx->current->value, B);
1353 @@ -239,7 +231,24 @@
1356 value(A) ::= key(B). {
1357 - A = configparser_get_variable(ctx, B);
1358 + if (strncmp(B->ptr, "env.", sizeof("env.") - 1) == 0) {
1361 + if (NULL != (env = getenv(B->ptr + 4))) {
1363 + ds = data_string_init();
1364 + buffer_append_string(ds->value, env);
1365 + A = (data_unset *)ds;
1369 + fprintf(stderr, "Undefined env variable: %s\n", B->ptr + 4);
1372 + } else if (NULL == (A = configparser_get_variable(ctx, B))) {
1373 + fprintf(stderr, "Undefined config variable: %s\n", B->ptr);
1377 /* make a dummy so it won't crash */
1378 A = (data_unset *)data_string_init();
1380 ((data_array *)(A))->value = B;
1383 +array(A) ::= LPARAN RPARAN. {
1386 array(A) ::= LPARAN aelements(B) RPARAN. {
1389 --- lighttpd-1.4.11/src/connections.c 2006-03-05 22:14:53.000000000 +0200
1390 +++ lighttpd/src/connections.c 2006-07-11 21:23:39.955846959 +0300
1395 -#include <unistd.h>
1402 #include "sys-socket.h"
1403 +#include "sys-files.h"
1408 int connection_close(server *srv, connection *con) {
1410 server_socket *srv_sock = con->srv_socket;
1414 if (srv_sock->is_ssl) {
1415 if (con->ssl) SSL_free(con->ssl);
1419 fdevent_event_del(srv->ev, &(con->fde_ndx), con->fd);
1420 fdevent_unregister(srv->ev, con->fd);
1423 if (closesocket(con->fd)) {
1424 log_error_write(srv, __FILE__, __LINE__, "sds",
1425 "(warning) close:", con->fd, strerror(errno));
1426 @@ -190,150 +188,39 @@
1430 -static int connection_handle_read(server *srv, connection *con) {
1435 - server_socket *srv_sock = con->srv_socket;
1438 - b = chunkqueue_get_append_buffer(con->read_queue);
1439 - buffer_prepare_copy(b, 4096);
1442 - if (srv_sock->is_ssl) {
1443 - len = SSL_read(con->ssl, b->ptr, b->size - 1);
1445 - if (ioctl(con->fd, FIONREAD, &toread)) {
1446 - log_error_write(srv, __FILE__, __LINE__, "sd",
1447 - "unexpected end-of-file:",
1451 - buffer_prepare_copy(b, toread);
1453 - len = read(con->fd, b->ptr, b->size - 1);
1455 -#elif defined(__WIN32)
1456 - len = recv(con->fd, b->ptr, b->size - 1, 0);
1458 - if (ioctl(con->fd, FIONREAD, &toread)) {
1459 - log_error_write(srv, __FILE__, __LINE__, "sd",
1460 - "unexpected end-of-file:",
1464 - buffer_prepare_copy(b, toread);
1466 - len = read(con->fd, b->ptr, b->size - 1);
1470 - con->is_readable = 0;
1473 - if (srv_sock->is_ssl) {
1476 - switch ((r = SSL_get_error(con->ssl, len))) {
1477 - case SSL_ERROR_WANT_READ:
1479 - case SSL_ERROR_SYSCALL:
1481 - * man SSL_get_error()
1483 - * SSL_ERROR_SYSCALL
1484 - * Some I/O error occurred. The OpenSSL error queue may contain more
1485 - * information on the error. If the error queue is empty (i.e.
1486 - * ERR_get_error() returns 0), ret can be used to find out more about
1487 - * the error: If ret == 0, an EOF was observed that violates the
1488 - * protocol. If ret == -1, the underlying BIO reported an I/O error
1489 - * (for socket I/O on Unix systems, consult errno for details).
1492 - while((ssl_err = ERR_get_error())) {
1493 - /* get all errors from the error-queue */
1494 - log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:",
1495 - r, ERR_error_string(ssl_err, NULL));
1500 - log_error_write(srv, __FILE__, __LINE__, "sddds", "SSL:",
1507 - case SSL_ERROR_ZERO_RETURN:
1508 - /* clean shutdown on the remote side */
1509 +static network_status_t connection_handle_read(server *srv, connection *con) {
1510 + off_t oldlen, newlen;
1513 - /* FIXME: later */
1515 + oldlen = chunkqueue_length(con->read_queue);
1517 - /* fall thourgh */
1519 - while((ssl_err = ERR_get_error())) {
1520 - /* get all errors from the error-queue */
1521 - log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:",
1522 - r, ERR_error_string(ssl_err, NULL));
1524 + switch(network_read_chunkqueue(srv, con, con->read_queue)) {
1525 + case NETWORK_STATUS_SUCCESS:
1529 - if (errno == EAGAIN) return 0;
1530 - if (errno == EINTR) {
1531 - /* we have been interrupted before we could read */
1532 - con->is_readable = 1;
1536 - if (errno != ECONNRESET) {
1537 - /* expected for keep-alive */
1538 - log_error_write(srv, __FILE__, __LINE__, "ssd", "connection closed - read failed: ", strerror(errno), errno);
1542 - if (errno == EAGAIN) return 0;
1543 - if (errno == EINTR) {
1544 - /* we have been interrupted before we could read */
1545 - con->is_readable = 1;
1549 - if (errno != ECONNRESET) {
1550 - /* expected for keep-alive */
1551 - log_error_write(srv, __FILE__, __LINE__, "ssd", "connection closed - read failed: ", strerror(errno), errno);
1554 - connection_set_state(srv, con, CON_STATE_ERROR);
1557 - } else if (len == 0) {
1558 + case NETWORK_STATUS_WAIT_FOR_EVENT:
1559 con->is_readable = 0;
1560 - /* the other end close the connection -> KEEP-ALIVE */
1562 + return NETWORK_STATUS_WAIT_FOR_EVENT;
1563 + case NETWORK_STATUS_INTERRUPTED:
1564 + con->is_readable = 1;
1565 + return NETWORK_STATUS_WAIT_FOR_EVENT;
1566 + case NETWORK_STATUS_CONNECTION_CLOSE:
1570 - } else if ((size_t)len < b->size - 1) {
1571 - /* we got less then expected, wait for the next fd-event */
1573 con->is_readable = 0;
1574 + return NETWORK_STATUS_CONNECTION_CLOSE;
1575 + case NETWORK_STATUS_FATAL_ERROR:
1576 + con->is_readable = 0;
1578 + connection_set_state(srv, con, CON_STATE_ERROR);
1579 + return NETWORK_STATUS_FATAL_ERROR;
1586 - b->ptr[b->used++] = '\0';
1587 + newlen = chunkqueue_length(con->read_queue);
1589 - con->bytes_read += len;
1591 - dump_packet(b->ptr, len);
1593 + con->bytes_read += (newlen - oldlen);
1596 + return NETWORK_STATUS_SUCCESS;
1599 static int connection_handle_write_prepare(server *srv, connection *con) {
1601 case HTTP_METHOD_GET:
1602 case HTTP_METHOD_POST:
1603 case HTTP_METHOD_HEAD:
1605 case HTTP_METHOD_PUT:
1606 case HTTP_METHOD_MKCOL:
1607 case HTTP_METHOD_DELETE:
1609 case HTTP_METHOD_MOVE:
1610 case HTTP_METHOD_PROPFIND:
1611 case HTTP_METHOD_PROPPATCH:
1612 + case HTTP_METHOD_LOCK:
1613 + case HTTP_METHOD_UNLOCK:
1615 case HTTP_METHOD_OPTIONS:
1631 if (con->mode != DIRECT) break;
1633 con->file_finished = 0;
1634 @@ -528,34 +421,37 @@
1636 static int connection_handle_write(server *srv, connection *con) {
1637 switch(network_write_chunkqueue(srv, con, con->write_queue)) {
1639 + case NETWORK_STATUS_SUCCESS:
1640 if (con->file_finished) {
1641 connection_set_state(srv, con, CON_STATE_RESPONSE_END);
1642 joblist_append(srv, con);
1645 - case -1: /* error on our side */
1646 + case NETWORK_STATUS_FATAL_ERROR: /* error on our side */
1647 log_error_write(srv, __FILE__, __LINE__, "sd",
1648 "connection closed: write failed on fd", con->fd);
1649 connection_set_state(srv, con, CON_STATE_ERROR);
1650 joblist_append(srv, con);
1652 - case -2: /* remote close */
1653 + case NETWORK_STATUS_CONNECTION_CLOSE: /* remote close */
1654 connection_set_state(srv, con, CON_STATE_ERROR);
1655 joblist_append(srv, con);
1658 + case NETWORK_STATUS_WAIT_FOR_EVENT:
1659 con->is_writable = 0;
1661 /* not finished yet -> WRITE */
1663 + case NETWORK_STATUS_INTERRUPTED:
1664 + con->is_writable = 1;
1666 + case NETWORK_STATUS_UNSET:
1675 connection *connection_init(server *srv) {
1678 @@ -845,17 +741,20 @@
1679 con->read_idle_ts = srv->cur_ts;
1681 switch(connection_handle_read(srv, con)) {
1683 + case NETWORK_STATUS_FATAL_ERROR:
1686 + case NETWORK_STATUS_CONNECTION_CLOSE:
1687 /* remote side closed the connection
1688 * if we still have content, handle it, if not leave here */
1690 if (cq->first == cq->last &&
1691 - cq->first->mem->used == 0) {
1692 + (NULL == cq->first ||
1693 + cq->first->mem->used == 0)) {
1695 /* conn-closed, leave here */
1696 connection_set_state(srv, con, CON_STATE_ERROR);
1704 /* the buffer has been read up to the terminator */
1705 c->offset += h_term - b.ptr + 4;
1708 /* not found, copy everything */
1709 buffer_copy_string_len(con->request.request, c->mem->ptr + c->offset, c->mem->used - c->offset - 1);
1710 @@ -1177,6 +1077,13 @@
1711 if (con->state == CON_STATE_READ ||
1712 con->state == CON_STATE_READ_POST) {
1713 connection_handle_read_state(srv, con);
1715 + * if SSL_read() is not readin in the full packet we won't get
1716 + * a fdevent as the low-level has already fetched everything.
1718 + * we have to call the state-engine to read the rest of the packet
1720 + if (con->is_readable) joblist_append(srv, con);
1723 if (con->state == CON_STATE_WRITE &&
1724 @@ -1233,9 +1140,13 @@
1725 cnt_len = sizeof(cnt_addr);
1727 if (-1 == (cnt = accept(srv_socket->fd, (struct sockaddr *) &cnt_addr, &cnt_len))) {
1729 + errno = WSAGetLastError();
1731 if ((errno != EAGAIN) &&
1732 + (errno != EWOULDBLOCK) &&
1734 - log_error_write(srv, __FILE__, __LINE__, "ssd", "accept failed:", strerror(errno), errno);
1735 + log_error_write(srv, __FILE__, __LINE__, "ssd", "accept failed:", strerror(errno), srv_socket->fd);
1739 @@ -1251,7 +1162,6 @@
1742 con = connections_get_new_connection(srv);
1747 @@ -1268,6 +1178,7 @@
1749 if (-1 == (fdevent_fcntl_set(srv->ev, con->fd))) {
1750 log_error_write(srv, __FILE__, __LINE__, "ss", "fcntl failed: ", strerror(errno));
1751 + connection_close(srv, con);
1755 @@ -1276,7 +1187,7 @@
1756 if (NULL == (con->ssl = SSL_new(srv_socket->ssl_ctx))) {
1757 log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:",
1758 ERR_error_string(ERR_get_error(), NULL));
1760 + connection_close(srv, con);
1764 @@ -1286,6 +1197,7 @@
1765 if (1 != (SSL_set_fd(con->ssl, cnt))) {
1766 log_error_write(srv, __FILE__, __LINE__, "ss", "SSL:",
1767 ERR_error_string(ERR_get_error(), NULL));
1768 + connection_close(srv, con);
1772 --- lighttpd-1.4.11/src/crc32.h 2005-09-30 20:18:59.000000000 +0300
1773 +++ lighttpd/src/crc32.h 2006-07-11 21:23:40.131857983 +0300
1777 #include <sys/types.h>
1778 +#include <stdlib.h>
1780 #if defined HAVE_STDINT_H
1783 #include <inttypes.h>
1787 +#define uint32_t unsigned __int32
1790 uint32_t generate_crc32c(char *string, size_t length);
1793 --- lighttpd-1.4.11/src/etag.h 2005-08-11 01:26:40.000000000 +0300
1794 +++ lighttpd/src/etag.h 2006-07-11 21:23:40.027851469 +0300
1797 #include <sys/types.h>
1798 #include <sys/stat.h>
1799 -#include <unistd.h>
1803 --- lighttpd-1.4.11/src/fdevent.c 2005-11-15 10:51:05.000000000 +0200
1804 +++ lighttpd/src/fdevent.c 2006-07-11 21:23:40.287867754 +0300
1807 #include "settings.h"
1809 -#include <unistd.h>
1814 #include "fdevent.h"
1817 +#include "sys-socket.h"
1819 fdevents *fdevent_init(size_t maxfds, fdevent_handler_t type) {
1825 int fdevent_fcntl_set(fdevents *ev, int fd) {
1830 /* close fd on exec (cgi) */
1831 fcntl(fd, F_SETFD, FD_CLOEXEC);
1833 if ((ev) && (ev->fcntl_set)) return ev->fcntl_set(ev, fd);
1835 return fcntl(fd, F_SETFL, O_NONBLOCK | O_RDWR);
1836 +#elif defined _WIN32
1837 + return ioctlsocket(fd, FIONBIO, &i);
1841 --- lighttpd-1.4.11/src/fdevent.h 2005-09-27 11:26:33.000000000 +0300
1842 +++ lighttpd/src/fdevent.h 2006-07-11 21:23:39.883842449 +0300
1844 # include <signal.h>
1849 +# define HAVE_SELECT
1851 #if defined HAVE_SELECT
1854 # include <winsock2.h>
1857 --- lighttpd-1.4.11/src/fdevent_freebsd_kqueue.c 2005-09-01 10:46:24.000000000 +0300
1858 +++ lighttpd/src/fdevent_freebsd_kqueue.c 2006-07-11 21:23:39.987848963 +0300
1860 #include <sys/types.h>
1862 -#include <unistd.h>
1866 --- lighttpd-1.4.11/src/fdevent_linux_rtsig.c 2005-11-21 19:56:11.000000000 +0200
1867 +++ lighttpd/src/fdevent_linux_rtsig.c 2006-07-11 21:23:40.179860989 +0300
1869 #include <sys/types.h>
1871 -#include <unistd.h>
1876 #include "fdevent.h"
1877 #include "settings.h"
1879 +#include "sys-process.h"
1881 #ifdef USE_LINUX_SIGIO
1882 static void fdevent_linux_rtsig_free(fdevents *ev) {
1883 --- lighttpd-1.4.11/src/fdevent_linux_sysepoll.c 2005-09-30 20:29:27.000000000 +0300
1884 +++ lighttpd/src/fdevent_linux_sysepoll.c 2006-07-11 21:23:40.223863745 +0300
1886 #include <sys/types.h>
1888 -#include <unistd.h>
1893 #include "settings.h"
1896 +#include "sys-files.h"
1898 #ifdef USE_LINUX_EPOLL
1899 static void fdevent_linux_sysepoll_free(fdevents *ev) {
1900 close(ev->epoll_fd);
1901 --- lighttpd-1.4.11/src/fdevent_poll.c 2005-11-18 13:59:16.000000000 +0200
1902 +++ lighttpd/src/fdevent_poll.c 2006-07-11 21:23:40.207862743 +0300
1904 #include <sys/types.h>
1906 -#include <unistd.h>
1910 --- lighttpd-1.4.11/src/fdevent_select.c 2005-08-31 11:12:46.000000000 +0300
1911 +++ lighttpd/src/fdevent_select.c 2006-07-11 21:23:40.211862994 +0300
1913 -#include <sys/time.h>
1914 #include <sys/types.h>
1916 -#include <unistd.h>
1925 #include "fdevent.h"
1926 #include "settings.h"
1929 +#include "sys-socket.h"
1933 static int fdevent_select_reset(fdevents *ev) {
1937 /* we should be protected by max-fds, but you never know */
1939 assert(fd < FD_SETSIZE);
1942 if (events & FDEVENT_IN) {
1943 FD_SET(fd, &(ev->select_set_read));
1944 --- lighttpd-1.4.11/src/fdevent_solaris_devpoll.c 2005-09-01 10:45:26.000000000 +0300
1945 +++ lighttpd/src/fdevent_solaris_devpoll.c 2006-07-11 21:23:40.015850717 +0300
1947 #include <sys/types.h>
1949 -#include <unistd.h>
1953 --- lighttpd-1.4.11/src/http-header-glue.c 2006-02-08 15:31:36.000000000 +0200
1954 +++ lighttpd/src/http-header-glue.c 2006-07-11 21:23:40.187861491 +0300
1955 @@ -261,13 +261,22 @@
1956 con->http_status = 304;
1957 return HANDLER_FINISHED;
1959 +#ifdef HAVE_STRPTIME
1960 char buf[sizeof("Sat, 23 Jul 2005 21:20:01 GMT")];
1962 - /* convert to timestamp */
1963 - if (used_len < sizeof(buf)) {
1964 time_t t_header, t_file;
1967 + /* check if we can safely copy the string */
1968 + if (used_len >= sizeof(buf)) {
1969 + log_error_write(srv, __FILE__, __LINE__, "ssdd",
1970 + "DEBUG: Last-Modified check failed as the received timestamp was too long:",
1971 + con->request.http_if_modified_since, used_len, sizeof(buf) - 1);
1973 + con->http_status = 412;
1974 + return HANDLER_FINISHED;
1978 strncpy(buf, con->request.http_if_modified_since, used_len);
1979 buf[used_len] = '\0';
1981 @@ -277,18 +286,13 @@
1982 strptime(mtime->ptr, "%a, %d %b %Y %H:%M:%S GMT", &tm);
1983 t_file = mktime(&tm);
1985 - if (t_file > t_header) {
1986 - con->http_status = 304;
1987 - return HANDLER_FINISHED;
1990 - log_error_write(srv, __FILE__, __LINE__, "ssdd",
1991 - "DEBUG: Last-Modified check failed as the received timestamp was too long:",
1992 - con->request.http_if_modified_since, used_len, sizeof(buf) - 1);
1993 + if (t_file > t_header) return HANDLER_GO_ON;
1995 - con->http_status = 412;
1996 + con->http_status = 304;
1997 return HANDLER_FINISHED;
2000 + return HANDLER_GO_ON;
2004 con->http_status = 304;
2005 @@ -312,6 +316,31 @@
2006 if (0 == strncmp(con->request.http_if_modified_since, mtime->ptr, used_len)) {
2007 con->http_status = 304;
2008 return HANDLER_FINISHED;
2010 +#ifdef HAVE_STRPTIME
2011 + char buf[sizeof("Sat, 23 Jul 2005 21:20:01 GMT")];
2012 + time_t t_header, t_file;
2015 + /* convert to timestamp */
2016 + if (used_len >= sizeof(buf)) return HANDLER_GO_ON;
2018 + strncpy(buf, con->request.http_if_modified_since, used_len);
2019 + buf[used_len] = '\0';
2021 + strptime(buf, "%a, %d %b %Y %H:%M:%S GMT", &tm);
2022 + t_header = mktime(&tm);
2024 + strptime(mtime->ptr, "%a, %d %b %Y %H:%M:%S GMT", &tm);
2025 + t_file = mktime(&tm);
2027 + if (t_file > t_header) return HANDLER_GO_ON;
2029 + con->http_status = 304;
2030 + return HANDLER_FINISHED;
2032 + return HANDLER_GO_ON;
2037 --- lighttpd-1.4.11/src/http_auth.c 2006-02-01 13:02:52.000000000 +0200
2038 +++ lighttpd/src/http_auth.c 2006-07-11 21:23:40.115856981 +0300
2043 -#include <unistd.h>
2048 #include "http_auth_digest.h"
2051 +#include "sys-strings.h"
2054 # include <openssl/md5.h>
2061 -#include <security/pam_appl.h>
2062 -#include <security/pam_misc.h>
2064 -static struct pam_conv conv = {
2070 handler_t auth_ldap_init(server *srv, mod_auth_plugin_config *s);
2072 static const char base64_pad = '=';
2073 @@ -509,33 +499,6 @@
2074 if (0 == strcmp(password->ptr, pw)) {
2077 - } else if (p->conf.auth_backend == AUTH_BACKEND_PAM) {
2079 - pam_handle_t *pamh=NULL;
2082 - retval = pam_start("lighttpd", username->ptr, &conv, &pamh);
2084 - if (retval == PAM_SUCCESS)
2085 - retval = pam_authenticate(pamh, 0); /* is user really user? */
2087 - if (retval == PAM_SUCCESS)
2088 - retval = pam_acct_mgmt(pamh, 0); /* permitted access? */
2090 - /* This is where we have been authorized or not. */
2092 - if (pam_end(pamh,retval) != PAM_SUCCESS) { /* close Linux-PAM */
2094 - log_error_write(srv, __FILE__, __LINE__, "s", "failed to release authenticator");
2097 - if (retval == PAM_SUCCESS) {
2098 - log_error_write(srv, __FILE__, __LINE__, "s", "Authenticated");
2101 - log_error_write(srv, __FILE__, __LINE__, "s", "Not Authenticated");
2104 } else if (p->conf.auth_backend == AUTH_BACKEND_LDAP) {
2107 --- lighttpd-1.4.11/src/http_auth.h 2005-08-14 17:12:31.000000000 +0300
2108 +++ lighttpd/src/http_auth.h 2006-07-11 21:23:40.119857231 +0300
2113 -typedef enum { AUTH_BACKEND_UNSET, AUTH_BACKEND_PLAIN,
2114 - AUTH_BACKEND_LDAP, AUTH_BACKEND_HTPASSWD,
2115 - AUTH_BACKEND_HTDIGEST, AUTH_BACKEND_PAM } auth_backend_t;
2117 + AUTH_BACKEND_UNSET,
2118 + AUTH_BACKEND_PLAIN,
2119 + AUTH_BACKEND_LDAP,
2120 + AUTH_BACKEND_HTPASSWD,
2121 + AUTH_BACKEND_HTDIGEST
2126 --- lighttpd-1.4.11/src/http_chunk.c 2005-08-11 01:26:50.000000000 +0300
2127 +++ lighttpd/src/http_chunk.c 2006-07-11 21:23:40.251865499 +0300
2132 -#include <unistd.h>
2136 --- lighttpd-1.4.11/src/keyvalue.c 2006-03-02 16:08:06.000000000 +0200
2137 +++ lighttpd/src/keyvalue.c 2006-07-11 21:23:40.027851469 +0300
2139 { 504, "Gateway Timeout" },
2140 { 505, "HTTP Version Not Supported" },
2141 { 507, "Insufficient Storage" }, /* WebDAV */
2142 + { 509, "Bandwidth Limit exceeded" },
2146 --- lighttpd-1.4.11/src/log.c 2005-11-07 15:01:35.000000000 +0200
2147 +++ lighttpd/src/log.c 2006-07-11 21:23:40.275867002 +0300
2152 -#include <unistd.h>
2161 +#undef HAVE_SYSLOG_H
2164 #ifdef HAVE_SYSLOG_H
2171 +#include "sys-files.h"
2173 #ifdef HAVE_VALGRIND_VALGRIND_H
2174 #include <valgrind/valgrind.h>
2176 @@ -246,9 +251,11 @@
2177 BUFFER_APPEND_STRING_CONST(srv->errorlog_buf, "\n");
2178 write(STDERR_FILENO, srv->errorlog_buf->ptr, srv->errorlog_buf->used - 1);
2180 +#ifdef HAVE_SYSLOG_H
2181 case ERRORLOG_SYSLOG:
2182 syslog(LOG_ERR, "%s", srv->errorlog_buf->ptr);
2188 --- lighttpd-1.4.11/src/md5.h 2005-11-17 16:20:40.000000000 +0200
2189 +++ lighttpd/src/md5.h 2006-07-11 21:23:40.155859486 +0300
2191 # include <inttypes.h>
2195 +#define UINT4 unsigned __int32
2196 +#define UINT2 unsigned __int16
2197 +#define POINTER unsigned char *
2199 #define UINT4 uint32_t
2200 #define UINT2 uint16_t
2201 #define POINTER unsigned char *
2206 --- lighttpd-1.4.11/src/mod_access.c 2006-01-14 19:44:54.000000000 +0200
2207 +++ lighttpd/src/mod_access.c 2006-07-11 21:23:40.219863495 +0300
2212 +#include "sys-strings.h"
2218 return HANDLER_GO_ON;
2223 static int mod_access_patch_connection(server *srv, connection *con, plugin_data *p) {
2225 plugin_config *s = p->config_storage[0];
2227 - PATCH(access_deny);
2228 + PATCH_OPTION(access_deny);
2230 /* skip the first, the global context */
2231 for (i = 1; i < srv->config_context->used; i++) {
2232 @@ -102,14 +102,13 @@
2233 data_unset *du = dc->value->data[j];
2235 if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.access-deny"))) {
2236 - PATCH(access_deny);
2237 + PATCH_OPTION(access_deny);
2246 URIHANDLER_FUNC(mod_access_uri_handler) {
2247 plugin_data *p = p_d;
2248 --- lighttpd-1.4.11/src/mod_accesslog.c 2006-01-31 14:01:43.000000000 +0200
2249 +++ lighttpd/src/mod_accesslog.c 2006-07-11 21:23:40.219863495 +0300
2255 -#include <unistd.h>
2256 +#include <fcntl.h> /* only the defines on windows */
2261 #include "inet_ntop_cache.h"
2263 #include "sys-socket.h"
2264 +#include "sys-files.h"
2266 #ifdef HAVE_SYSLOG_H
2267 # include <syslog.h>
2270 return HANDLER_ERROR;
2273 fcntl(s->log_access_fd, F_SETFD, FD_CLOEXEC);
2278 return HANDLER_GO_ON;
2279 @@ -567,20 +568,18 @@
2280 return HANDLER_GO_ON;
2285 static int mod_accesslog_patch_connection(server *srv, connection *con, plugin_data *p) {
2287 plugin_config *s = p->config_storage[0];
2289 - PATCH(access_logfile);
2291 - PATCH(log_access_fd);
2292 - PATCH(last_generated_accesslog_ts_ptr);
2293 - PATCH(access_logbuffer);
2294 - PATCH(ts_accesslog_str);
2295 - PATCH(parsed_format);
2296 - PATCH(use_syslog);
2297 + PATCH_OPTION(access_logfile);
2298 + PATCH_OPTION(format);
2299 + PATCH_OPTION(log_access_fd);
2300 + PATCH_OPTION(last_generated_accesslog_ts_ptr);
2301 + PATCH_OPTION(access_logbuffer);
2302 + PATCH_OPTION(ts_accesslog_str);
2303 + PATCH_OPTION(parsed_format);
2304 + PATCH_OPTION(use_syslog);
2306 /* skip the first, the global context */
2307 for (i = 1; i < srv->config_context->used; i++) {
2308 @@ -595,23 +594,22 @@
2309 data_unset *du = dc->value->data[j];
2311 if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.filename"))) {
2312 - PATCH(access_logfile);
2313 - PATCH(log_access_fd);
2314 - PATCH(last_generated_accesslog_ts_ptr);
2315 - PATCH(access_logbuffer);
2316 - PATCH(ts_accesslog_str);
2317 + PATCH_OPTION(access_logfile);
2318 + PATCH_OPTION(log_access_fd);
2319 + PATCH_OPTION(last_generated_accesslog_ts_ptr);
2320 + PATCH_OPTION(access_logbuffer);
2321 + PATCH_OPTION(ts_accesslog_str);
2322 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.format"))) {
2324 - PATCH(parsed_format);
2325 + PATCH_OPTION(format);
2326 + PATCH_OPTION(parsed_format);
2327 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("accesslog.use-syslog"))) {
2328 - PATCH(use_syslog);
2329 + PATCH_OPTION(use_syslog);
2338 REQUESTDONE_FUNC(log_access_write) {
2339 plugin_data *p = p_d;
2340 --- lighttpd-1.4.11/src/mod_alias.c 2006-03-01 23:18:51.000000000 +0200
2341 +++ lighttpd/src/mod_alias.c 2006-07-11 21:23:39.979848462 +0300
2346 +#include "sys-strings.h"
2348 /* plugin config for all request/connections */
2350 @@ -114,13 +115,11 @@
2351 return HANDLER_GO_ON;
2356 static int mod_alias_patch_connection(server *srv, connection *con, plugin_data *p) {
2358 plugin_config *s = p->config_storage[0];
2361 + PATCH_OPTION(alias);
2363 /* skip the first, the global context */
2364 for (i = 1; i < srv->config_context->used; i++) {
2365 @@ -135,14 +134,13 @@
2366 data_unset *du = dc->value->data[j];
2368 if (buffer_is_equal_string(du->key, CONST_STR_LEN("alias.url"))) {
2370 + PATCH_OPTION(alias);
2379 PHYSICALPATH_FUNC(mod_alias_physical_handler) {
2380 plugin_data *p = p_d;
2381 --- lighttpd-1.4.11/src/mod_auth.c 2006-02-15 20:01:31.000000000 +0200
2382 +++ lighttpd/src/mod_auth.c 2006-07-11 21:23:40.171860488 +0300
2387 -#include <unistd.h>
2390 #include "http_auth.h"
2392 #include "response.h"
2394 +#include "sys-strings.h"
2395 +#include "sys-files.h"
2397 handler_t auth_ldap_init(server *srv, mod_auth_plugin_config *s);
2401 return HANDLER_GO_ON;
2406 static int mod_auth_patch_connection(server *srv, connection *con, mod_auth_plugin_data *p) {
2408 mod_auth_plugin_config *s = p->config_storage[0];
2410 - PATCH(auth_backend);
2411 - PATCH(auth_plain_groupfile);
2412 - PATCH(auth_plain_userfile);
2413 - PATCH(auth_htdigest_userfile);
2414 - PATCH(auth_htpasswd_userfile);
2415 - PATCH(auth_require);
2416 - PATCH(auth_debug);
2417 - PATCH(auth_ldap_hostname);
2418 - PATCH(auth_ldap_basedn);
2419 - PATCH(auth_ldap_binddn);
2420 - PATCH(auth_ldap_bindpw);
2421 - PATCH(auth_ldap_filter);
2422 - PATCH(auth_ldap_cafile);
2423 - PATCH(auth_ldap_starttls);
2424 + PATCH_OPTION(auth_backend);
2425 + PATCH_OPTION(auth_plain_groupfile);
2426 + PATCH_OPTION(auth_plain_userfile);
2427 + PATCH_OPTION(auth_htdigest_userfile);
2428 + PATCH_OPTION(auth_htpasswd_userfile);
2429 + PATCH_OPTION(auth_require);
2430 + PATCH_OPTION(auth_debug);
2431 + PATCH_OPTION(auth_ldap_hostname);
2432 + PATCH_OPTION(auth_ldap_basedn);
2433 + PATCH_OPTION(auth_ldap_binddn);
2434 + PATCH_OPTION(auth_ldap_bindpw);
2435 + PATCH_OPTION(auth_ldap_filter);
2436 + PATCH_OPTION(auth_ldap_cafile);
2437 + PATCH_OPTION(auth_ldap_starttls);
2440 - PATCH(ldap_filter_pre);
2441 - PATCH(ldap_filter_post);
2442 + PATCH_OPTION(ldap);
2443 + PATCH_OPTION(ldap_filter_pre);
2444 + PATCH_OPTION(ldap_filter_post);
2447 /* skip the first, the global context */
2448 @@ -132,41 +132,40 @@
2449 data_unset *du = dc->value->data[j];
2451 if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend"))) {
2452 - PATCH(auth_backend);
2453 + PATCH_OPTION(auth_backend);
2454 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.plain.groupfile"))) {
2455 - PATCH(auth_plain_groupfile);
2456 + PATCH_OPTION(auth_plain_groupfile);
2457 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.plain.userfile"))) {
2458 - PATCH(auth_plain_userfile);
2459 + PATCH_OPTION(auth_plain_userfile);
2460 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.htdigest.userfile"))) {
2461 - PATCH(auth_htdigest_userfile);
2462 + PATCH_OPTION(auth_htdigest_userfile);
2463 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.htpasswd.userfile"))) {
2464 - PATCH(auth_htpasswd_userfile);
2465 + PATCH_OPTION(auth_htpasswd_userfile);
2466 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.require"))) {
2467 - PATCH(auth_require);
2468 + PATCH_OPTION(auth_require);
2469 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.debug"))) {
2470 - PATCH(auth_debug);
2471 + PATCH_OPTION(auth_debug);
2472 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.hostname"))) {
2473 - PATCH(auth_ldap_hostname);
2474 + PATCH_OPTION(auth_ldap_hostname);
2477 - PATCH(ldap_filter_pre);
2478 - PATCH(ldap_filter_post);
2479 + PATCH_OPTION(ldap);
2480 + PATCH_OPTION(ldap_filter_pre);
2481 + PATCH_OPTION(ldap_filter_post);
2483 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.base-dn"))) {
2484 - PATCH(auth_ldap_basedn);
2485 + PATCH_OPTION(auth_ldap_basedn);
2486 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.filter"))) {
2487 - PATCH(auth_ldap_filter);
2488 + PATCH_OPTION(auth_ldap_filter);
2489 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.ca-file"))) {
2490 - PATCH(auth_ldap_cafile);
2491 + PATCH_OPTION(auth_ldap_cafile);
2492 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.starttls"))) {
2493 - PATCH(auth_ldap_starttls);
2494 + PATCH_OPTION(auth_ldap_starttls);
2503 static handler_t mod_auth_uri_handler(server *srv, connection *con, void *p_d) {
2505 --- lighttpd-1.4.11/src/mod_cgi.c 2006-02-22 15:15:10.000000000 +0200
2506 +++ lighttpd/src/mod_cgi.c 2006-07-11 21:23:39.887842700 +0300
2508 #include <sys/types.h>
2510 -#include <winsock2.h>
2512 -#include <sys/socket.h>
2513 -#include <sys/wait.h>
2514 -#include <sys/mman.h>
2516 -#include <netinet/in.h>
2518 -#include <arpa/inet.h>
2521 -#include <unistd.h>
2525 -#include <fdevent.h>
2530 #include "connections.h"
2531 #include "joblist.h"
2532 #include "http_chunk.h"
2533 +#include "fdevent.h"
2537 +#include "sys-files.h"
2538 +#include "sys-mmap.h"
2539 +#include "sys-socket.h"
2540 +#include "sys-strings.h"
2541 +#include "sys-process.h"
2543 #ifdef HAVE_SYS_FILIO_H
2544 # include <sys/filio.h>
2556 if (con->mode != p->id) return HANDLER_GO_ON;
2561 /* the connection to the browser went away, but we still have a connection
2564 /* if waitpid hasn't been called by response.c yet, do it here */
2566 /* check if the CGI-script is already gone */
2568 switch(waitpid(pid, &status, WNOHANG)) {
2570 /* not finished yet */
2577 /* cgi-script is still alive, queue the PID for removal */
2578 cgi_pid_add(srv, p, pid);
2581 int from_cgi_fds[2];
2587 if (cgi_handler->used > 1) {
2588 /* stat the exec file */
2590 cgi_env_add(&env, CONST_STR_LEN("REDIRECT_STATUS"), CONST_STR_LEN("200"));
2591 if (!buffer_is_empty(con->uri.query)) {
2592 cgi_env_add(&env, CONST_STR_LEN("QUERY_STRING"), CONST_BUF_LEN(con->uri.query));
2594 + /* set a empty QUERY_STRING */
2595 + cgi_env_add(&env, CONST_STR_LEN("QUERY_STRING"), CONST_STR_LEN(""));
2597 if (!buffer_is_empty(con->request.orig_uri)) {
2598 cgi_env_add(&env, CONST_STR_LEN("REQUEST_URI"), CONST_BUF_LEN(con->request.orig_uri));
2599 @@ -1101,13 +1100,11 @@
2605 static int mod_cgi_patch_connection(server *srv, connection *con, plugin_data *p) {
2607 plugin_config *s = p->config_storage[0];
2610 + PATCH_OPTION(cgi);
2612 /* skip the first, the global context */
2613 for (i = 1; i < srv->config_context->used; i++) {
2614 @@ -1122,14 +1119,13 @@
2615 data_unset *du = dc->value->data[j];
2617 if (buffer_is_equal_string(du->key, CONST_STR_LEN("cgi.assign"))) {
2619 + PATCH_OPTION(cgi);
2628 URIHANDLER_FUNC(cgi_is_handled) {
2630 @@ -1168,7 +1164,7 @@
2631 plugin_data *p = p_d;
2633 /* the trigger handle only cares about lonely PID which we have to wait for */
2637 for (ndx = 0; ndx < p->cgi_pid.used; ndx++) {
2639 @@ -1218,7 +1214,7 @@
2640 log_error_write(srv, __FILE__, __LINE__, "sdd", "subrequest, pid =", hctx, hctx->pid);
2642 if (hctx->pid == 0) return HANDLER_FINISHED;
2645 switch(waitpid(hctx->pid, &status, WNOHANG)) {
2647 /* we only have for events here if we don't have the header yet,
2648 --- lighttpd-1.4.11/src/mod_cml.c 2006-01-30 13:51:48.000000000 +0200
2649 +++ lighttpd/src/mod_cml.c 2006-07-11 21:23:39.931845456 +0300
2654 -#include <unistd.h>
2658 @@ -135,18 +134,16 @@
2659 return HANDLER_GO_ON;
2664 static int mod_cml_patch_connection(server *srv, connection *con, plugin_data *p) {
2666 plugin_config *s = p->config_storage[0];
2669 + PATCH_OPTION(ext);
2670 #if defined(HAVE_MEMCACHE_H)
2674 - PATCH(mc_namespace);
2675 - PATCH(power_magnet);
2676 + PATCH_OPTION(mc_namespace);
2677 + PATCH_OPTION(power_magnet);
2679 /* skip the first, the global context */
2680 for (i = 1; i < srv->config_context->used; i++) {
2681 @@ -161,22 +158,21 @@
2682 data_unset *du = dc->value->data[j];
2684 if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.extension"))) {
2686 + PATCH_OPTION(ext);
2687 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-hosts"))) {
2688 #if defined(HAVE_MEMCACHE_H)
2692 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.memcache-namespace"))) {
2693 - PATCH(mc_namespace);
2694 + PATCH_OPTION(mc_namespace);
2695 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("cml.power-magnet"))) {
2696 - PATCH(power_magnet);
2697 + PATCH_OPTION(power_magnet);
2706 int cache_call_lua(server *srv, connection *con, plugin_data *p, buffer *cml_file) {
2708 --- lighttpd-1.4.11/src/mod_cml_funcs.c 2005-11-17 16:15:08.000000000 +0200
2709 +++ lighttpd/src/mod_cml_funcs.c 2006-07-11 21:23:40.083854976 +0300
2714 -#include <unistd.h>
2715 -#include <dirent.h>
2723 #include "response.h"
2724 +#include "sys-files.h"
2726 #include "mod_cml.h"
2727 #include "mod_cml_funcs.h"
2734 int f_dir_files_iter(lua_State *L) {
2743 int f_file_isreg(lua_State *L) {
2745 int n = lua_gettop(L);
2746 --- lighttpd-1.4.11/src/mod_cml_lua.c 2006-01-30 13:56:40.000000000 +0200
2747 +++ lighttpd/src/mod_cml_lua.c 2006-07-11 21:23:40.179860989 +0300
2752 +#include <lauxlib.h>
2756 @@ -220,13 +221,8 @@
2757 stream_open(&rm.st, fn);
2759 /* push the lua file to the interpreter and see what happends */
2764 - luaopen_string(L);
2767 + L = luaL_newstate();
2770 /* register functions */
2771 lua_register(L, "md5", f_crypto_md5);
2772 --- lighttpd-1.4.11/src/mod_compress.c 2005-11-18 13:49:14.000000000 +0200
2773 +++ lighttpd/src/mod_compress.c 2006-07-11 21:23:40.139858484 +0300
2775 #include <sys/stat.h>
2778 -#include <unistd.h>
2784 #include "response.h"
2785 #include "stat_cache.h"
2786 +#include "http_chunk.h"
2793 #include "sys-mmap.h"
2794 +#include "sys-files.h"
2796 /* request: accept-encoding */
2797 #define HTTP_ACCEPT_ENCODING_IDENTITY BV(0)
2798 @@ -102,6 +103,28 @@
2799 return HANDLER_GO_ON;
2802 +void mkdir_recursive(const char *dir) {
2804 + char dir_copy[256];
2805 + char *p = dir_copy;
2807 + if (!dir || !dir[0])
2810 + strncpy(dir_copy, dir, sizeof(dir_copy) / sizeof(dir_copy[0]));
2812 + while ((p = strchr(p + 1, '/')) != NULL) {
2815 + if ((mkdir(dir_copy, 0700) != 0) && (errno != EEXIST))
2824 SETDEFAULTS_FUNC(mod_compress_setdefaults) {
2825 plugin_data *p = p_d;
2827 @@ -136,13 +159,21 @@
2828 if (!buffer_is_empty(s->compress_cache_dir)) {
2830 if (0 != stat(s->compress_cache_dir->ptr, &st)) {
2831 - log_error_write(srv, __FILE__, __LINE__, "sbs", "can't stat compress.cache-dir",
2833 + log_error_write(srv, __FILE__, __LINE__, "sbs", "can't stat compress.cache-dir, attempting to create",
2834 + s->compress_cache_dir, strerror(errno));
2835 + mkdir_recursive(s->compress_cache_dir->ptr);
2837 + if (0 != stat(s->compress_cache_dir->ptr, &st)) {
2839 + log_error_write(srv, __FILE__, __LINE__, "sbs", "can't stat compress.cache-dir, create failed",
2840 s->compress_cache_dir, strerror(errno));
2842 return HANDLER_ERROR;
2848 return HANDLER_GO_ON;
2852 const char *filename = fn->ptr;
2854 + stat_cache_entry *compressed_sce = NULL;
2856 + if (buffer_is_empty(p->conf.compress_cache_dir)) return -1;
2859 if ((off_t)(sce->st.st_size * 1.1) < sce->st.st_size) return -1;
2862 buffer_reset(p->ofn);
2863 buffer_copy_string_buffer(p->ofn, p->conf.compress_cache_dir);
2864 - BUFFER_APPEND_SLASH(p->ofn);
2865 + PATHNAME_APPEND_SLASH(p->ofn);
2867 if (0 == strncmp(con->physical.path->ptr, con->physical.doc_root->ptr, con->physical.doc_root->used-1)) {
2868 size_t offset = p->ofn->used - 1;
2869 @@ -384,26 +418,33 @@
2871 buffer_append_string_buffer(p->ofn, sce->etag);
2874 + if (HANDLER_ERROR != stat_cache_get_entry(srv, con, p->ofn, &compressed_sce)) {
2877 + http_chunk_append_file(srv, con, p->ofn, 0, compressed_sce->st.st_size);
2878 + con->file_finished = 1;
2883 if (-1 == (ofd = open(p->ofn->ptr, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))) {
2884 if (errno == EEXIST) {
2885 /* cache-entry exists */
2887 - log_error_write(srv, __FILE__, __LINE__, "bs", p->ofn, "compress-cache hit");
2889 - buffer_copy_string_buffer(con->physical.path, p->ofn);
2894 - log_error_write(srv, __FILE__, __LINE__, "sbss", "creating cachefile", p->ofn, "failed", strerror(errno));
2895 + log_error_write(srv, __FILE__, __LINE__, "sbss",
2896 + "creating cachefile", p->ofn,
2897 + "failed", strerror(errno));
2902 - log_error_write(srv, __FILE__, __LINE__, "bs", p->ofn, "compress-cache miss");
2905 if (-1 == (ifd = open(filename, O_RDONLY | O_BINARY))) {
2906 - log_error_write(srv, __FILE__, __LINE__, "sbss", "opening plain-file", fn, "failed", strerror(errno));
2907 + log_error_write(srv, __FILE__, __LINE__, "sbss",
2908 + "opening plain-file", fn,
2909 + "failed", strerror(errno));
2916 if (MAP_FAILED == (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
2917 - log_error_write(srv, __FILE__, __LINE__, "sbss", "mmaping", fn, "failed", strerror(errno));
2918 + log_error_write(srv, __FILE__, __LINE__, "sbss",
2920 + "failed", strerror(errno));
2926 if (ret != 0) return -1;
2928 - buffer_copy_string_buffer(con->physical.path, p->ofn);
2929 + http_chunk_append_file(srv, con, p->ofn, 0, r);
2930 + con->file_finished = 1;
2934 @@ -476,18 +520,19 @@
2936 if (sce->st.st_size > 128 * 1024 * 1024) return -1;
2939 if (-1 == (ifd = open(fn->ptr, O_RDONLY | O_BINARY))) {
2940 log_error_write(srv, __FILE__, __LINE__, "sbss", "opening plain-file", fn, "failed", strerror(errno));
2945 + start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0);
2947 - if (MAP_FAILED == (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) {
2950 + if (MAP_FAILED == start) {
2951 log_error_write(srv, __FILE__, __LINE__, "sbss", "mmaping", fn, "failed", strerror(errno));
2960 munmap(start, sce->st.st_size);
2963 if (ret != 0) return -1;
2965 @@ -527,16 +571,13 @@
2972 static int mod_compress_patch_connection(server *srv, connection *con, plugin_data *p) {
2974 plugin_config *s = p->config_storage[0];
2976 - PATCH(compress_cache_dir);
2978 - PATCH(compress_max_filesize);
2979 + PATCH_OPTION(compress_cache_dir);
2980 + PATCH_OPTION(compress);
2981 + PATCH_OPTION(compress_max_filesize);
2983 /* skip the first, the global context */
2984 for (i = 1; i < srv->config_context->used; i++) {
2985 @@ -551,18 +592,17 @@
2986 data_unset *du = dc->value->data[j];
2988 if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.cache-dir"))) {
2989 - PATCH(compress_cache_dir);
2990 + PATCH_OPTION(compress_cache_dir);
2991 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.filetype"))) {
2993 + PATCH_OPTION(compress);
2994 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.max-filesize"))) {
2995 - PATCH(compress_max_filesize);
2996 + PATCH_OPTION(compress_max_filesize);
3005 PHYSICALPATH_FUNC(mod_compress_physical) {
3006 plugin_data *p = p_d;
3008 /* don't compress files that are too large as we need to much time to handle them */
3009 if (max_fsize && (sce->st.st_size >> 10) > max_fsize) return HANDLER_GO_ON;
3011 + /* compressing the file might lead to larger files instead */
3012 + if (sce->st.st_size < 128) return HANDLER_GO_ON;
3014 /* check if mimetype is in compress-config */
3015 for (m = 0; m < p->conf.compress->used; m++) {
3016 data_string *compress_ds = (data_string *)p->conf.compress->data[m];
3017 @@ -638,6 +681,19 @@
3019 const char *compression_name = NULL;
3020 int compression_type = 0;
3023 + mtime = strftime_cache_get(srv, sce->st.st_mtime);
3024 + etag_mutate(con->physical.etag, sce->etag);
3026 + response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
3027 + response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
3029 + /* perhaps we don't even have to compress the file as the browser still has the
3030 + * current version */
3031 + if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) {
3032 + return HANDLER_FINISHED;
3035 /* select best matching encoding */
3036 if (matched_encodings & HTTP_ACCEPT_ENCODING_BZIP2) {
3037 @@ -651,29 +707,19 @@
3038 compression_name = dflt_deflate;
3042 - if (p->conf.compress_cache_dir->used) {
3043 + /* deflate it to file (cached) or to memory */
3044 if (0 == deflate_file_to_file(srv, con, p,
3045 - con->physical.path, sce, compression_type)) {
3048 - response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name));
3050 - mtime = strftime_cache_get(srv, sce->st.st_mtime);
3051 - response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime));
3053 - etag_mutate(con->physical.etag, sce->etag);
3054 - response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
3056 - response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
3058 - return HANDLER_GO_ON;
3060 - } else if (0 == deflate_file_to_buffer(srv, con, p,
3061 + con->physical.path, sce, compression_type) ||
3062 + 0 == deflate_file_to_buffer(srv, con, p,
3063 con->physical.path, sce, compression_type)) {
3065 - response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name));
3066 - response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
3067 + response_header_overwrite(srv, con,
3068 + CONST_STR_LEN("Content-Encoding"),
3069 + compression_name, strlen(compression_name));
3071 + response_header_overwrite(srv, con,
3072 + CONST_STR_LEN("Content-Type"),
3073 + CONST_BUF_LEN(sce->content_type));
3075 return HANDLER_FINISHED;
3077 --- lighttpd-1.4.11/src/mod_dirlisting.c 2006-01-13 00:00:45.000000000 +0200
3078 +++ lighttpd/src/mod_dirlisting.c 2006-07-11 21:23:40.247865249 +0300
3083 -#include <dirent.h>
3087 -#include <unistd.h>
3092 #include <attr/attributes.h>
3095 +#include "sys-files.h"
3096 +#include "sys-strings.h"
3098 /* plugin config for all request/connections */
3101 @@ -292,21 +293,19 @@
3102 return HANDLER_GO_ON;
3107 static int mod_dirlisting_patch_connection(server *srv, connection *con, plugin_data *p) {
3109 plugin_config *s = p->config_storage[0];
3111 - PATCH(dir_listing);
3112 - PATCH(external_css);
3113 - PATCH(hide_dot_files);
3115 - PATCH(show_readme);
3116 - PATCH(hide_readme_file);
3117 - PATCH(show_header);
3118 - PATCH(hide_header_file);
3120 + PATCH_OPTION(dir_listing);
3121 + PATCH_OPTION(external_css);
3122 + PATCH_OPTION(hide_dot_files);
3123 + PATCH_OPTION(encoding);
3124 + PATCH_OPTION(show_readme);
3125 + PATCH_OPTION(hide_readme_file);
3126 + PATCH_OPTION(show_header);
3127 + PATCH_OPTION(hide_header_file);
3128 + PATCH_OPTION(excludes);
3130 /* skip the first, the global context */
3131 for (i = 1; i < srv->config_context->used; i++) {
3132 @@ -322,30 +321,29 @@
3134 if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.activate")) ||
3135 buffer_is_equal_string(du->key, CONST_STR_LEN("server.dir-listing"))) {
3136 - PATCH(dir_listing);
3137 + PATCH_OPTION(dir_listing);
3138 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.hide-dotfiles"))) {
3139 - PATCH(hide_dot_files);
3140 + PATCH_OPTION(hide_dot_files);
3141 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.external-css"))) {
3142 - PATCH(external_css);
3143 + PATCH_OPTION(external_css);
3144 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.encoding"))) {
3146 + PATCH_OPTION(encoding);
3147 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.show-readme"))) {
3148 - PATCH(show_readme);
3149 + PATCH_OPTION(show_readme);
3150 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.hide-readme-file"))) {
3151 - PATCH(hide_readme_file);
3152 + PATCH_OPTION(hide_readme_file);
3153 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.show-header"))) {
3154 - PATCH(show_header);
3155 + PATCH_OPTION(show_header);
3156 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.hide-header-file"))) {
3157 - PATCH(hide_header_file);
3158 + PATCH_OPTION(hide_header_file);
3159 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.excludes"))) {
3161 + PATCH_OPTION(excludes);
3173 /* if we have a HEADER file, display it in <pre class="header"></pre> */
3175 buffer_copy_string_buffer(p->tmp_buf, con->physical.path);
3176 - BUFFER_APPEND_SLASH(p->tmp_buf);
3177 + PATHNAME_APPEND_SLASH(p->tmp_buf);
3178 BUFFER_APPEND_STRING_CONST(p->tmp_buf, "HEADER.txt");
3180 if (-1 != stream_open(&s, p->tmp_buf)) {
3182 /* if we have a README file, display it in <pre class="readme"></pre> */
3184 buffer_copy_string_buffer(p->tmp_buf, con->physical.path);
3185 - BUFFER_APPEND_SLASH(p->tmp_buf);
3186 + PATHNAME_APPEND_SLASH(p->tmp_buf);
3187 BUFFER_APPEND_STRING_CONST(p->tmp_buf, "README.txt");
3189 if (-1 != stream_open(&s, p->tmp_buf)) {
3191 name_max = 256; /* stupid default */
3194 -#elif defined __WIN32
3195 +#elif defined _WIN32
3196 name_max = FILENAME_MAX;
3198 name_max = NAME_MAX;
3199 @@ -615,6 +613,11 @@
3200 path = malloc(dir->used + name_max);
3202 strcpy(path, dir->ptr);
3204 + /* append \*.* to the path and keep the \ as part of the pathname */
3205 + strcat(path, "\\*.*");
3208 path_file = path + i;
3210 if (NULL == (dp = opendir(path))) {
3211 @@ -693,8 +696,10 @@
3212 if (i > (size_t)name_max) continue;
3214 memcpy(path_file, dent->d_name, i + 1);
3215 - if (stat(path, &st) != 0)
3216 + if (stat(path, &st) != 0) {
3217 + fprintf(stderr, "%s.%d: %s, %s\r\n", __FILE__, __LINE__, path, strerror(errno));
3222 if (S_ISDIR(st.st_mode))
3223 --- lighttpd-1.4.11/src/mod_evasive.c 2006-01-04 15:24:51.000000000 +0200
3224 +++ lighttpd/src/mod_evasive.c 2006-07-11 21:23:40.187861491 +0300
3226 return HANDLER_GO_ON;
3231 static int mod_evasive_patch_connection(server *srv, connection *con, plugin_data *p) {
3233 plugin_config *s = p->config_storage[0];
3236 + PATCH_OPTION(max_conns);
3238 /* skip the first, the global context */
3239 for (i = 1; i < srv->config_context->used; i++) {
3240 @@ -117,14 +115,13 @@
3241 data_unset *du = dc->value->data[j];
3243 if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.max-conns-per-ip"))) {
3245 + PATCH_OPTION(max_conns);
3254 URIHANDLER_FUNC(mod_evasive_uri_handler) {
3255 plugin_data *p = p_d;
3256 --- lighttpd-1.4.11/src/mod_evhost.c 2005-08-17 10:42:03.000000000 +0300
3257 +++ lighttpd/src/mod_evhost.c 2006-07-11 21:23:39.991849214 +0300
3259 #include "response.h"
3260 #include "stat_cache.h"
3262 +#include "sys-files.h"
3265 /* unparsed pieces */
3266 buffer *path_pieces_raw;
3267 @@ -221,14 +223,12 @@
3273 static int mod_evhost_patch_connection(server *srv, connection *con, plugin_data *p) {
3275 plugin_config *s = p->config_storage[0];
3277 - PATCH(path_pieces);
3279 + PATCH_OPTION(path_pieces);
3280 + PATCH_OPTION(len);
3282 /* skip the first, the global context */
3283 for (i = 1; i < srv->config_context->used; i++) {
3284 @@ -243,16 +243,14 @@
3285 data_unset *du = dc->value->data[j];
3287 if (buffer_is_equal_string(du->key, CONST_STR_LEN("evhost.path-pattern"))) {
3288 - PATCH(path_pieces);
3290 + PATCH_OPTION(path_pieces);
3291 + PATCH_OPTION(len);
3301 static handler_t mod_evhost_uri_handler(server *srv, connection *con, void *p_d) {
3302 plugin_data *p = p_d;
3307 - BUFFER_APPEND_SLASH(p->tmp_buf);
3308 + PATHNAME_APPEND_SLASH(p->tmp_buf);
3310 array_free(parsed_host);
3312 --- lighttpd-1.4.11/src/mod_expire.c 2005-11-03 09:52:13.000000000 +0200
3313 +++ lighttpd/src/mod_expire.c 2006-07-11 21:23:40.103856229 +0300
3314 @@ -245,13 +245,11 @@
3315 return HANDLER_GO_ON;
3320 static int mod_expire_patch_connection(server *srv, connection *con, plugin_data *p) {
3322 plugin_config *s = p->config_storage[0];
3324 - PATCH(expire_url);
3325 + PATCH_OPTION(expire_url);
3327 /* skip the first, the global context */
3328 for (i = 1; i < srv->config_context->used; i++) {
3329 @@ -266,14 +264,13 @@
3330 data_unset *du = dc->value->data[j];
3332 if (buffer_is_equal_string(du->key, CONST_STR_LEN("expire.url"))) {
3333 - PATCH(expire_url);
3334 + PATCH_OPTION(expire_url);
3343 URIHANDLER_FUNC(mod_expire_path_handler) {
3344 plugin_data *p = p_d;
3345 --- lighttpd-1.4.11/src/mod_fastcgi.c 2006-03-09 13:18:39.000000000 +0200
3346 +++ lighttpd/src/mod_fastcgi.c 2006-07-11 21:23:40.207862743 +0300
3348 #include <sys/types.h>
3349 -#include <unistd.h>
3354 #include "inet_ntop_cache.h"
3355 #include "stat_cache.h"
3357 -#include <fastcgi.h>
3358 +#include "fastcgi.h"
3361 #ifdef HAVE_SYS_FILIO_H
3365 #include "sys-socket.h"
3366 +#include "sys-files.h"
3367 +#include "sys-strings.h"
3368 +#include "sys-process.h"
3370 +#include "http_resp.h"
3372 #ifndef UNIX_PATH_MAX
3373 # define UNIX_PATH_MAX 108
3375 #include <sys/wait.h>
3382 @@ -310,10 +312,11 @@
3386 - buffer *parse_response;
3392 plugin_config **config_storage;
3394 plugin_config conf; /* this is only used as long as no handler_ctx is setup */
3395 @@ -339,11 +342,10 @@
3397 int reconnects; /* number of reconnect attempts */
3399 - chunkqueue *rb; /* read queue */
3400 + chunkqueue *rb; /* the raw fcgi read-queue */
3401 + chunkqueue *http_rb; /* the decoded read-queue for http-parsing */
3402 chunkqueue *wb; /* write queue */
3404 - buffer *response_header;
3407 int fd; /* fd to the fastcgi process */
3408 int fde_ndx; /* index into the fd-event buffer */
3413 - hctx->response_header = buffer_init();
3415 hctx->request_id = 0;
3416 hctx->state = FCGI_STATE_INIT;
3419 hctx->send_content_body = 1;
3421 hctx->rb = chunkqueue_init();
3422 + hctx->http_rb = chunkqueue_init();
3423 hctx->wb = chunkqueue_init();
3430 - buffer_free(hctx->response_header);
3432 chunkqueue_free(hctx->rb);
3433 + chunkqueue_free(hctx->http_rb);
3434 chunkqueue_free(hctx->wb);
3438 p->fcgi_env = buffer_init();
3440 p->path = buffer_init();
3441 - p->parse_response = buffer_init();
3443 + p->resp = http_response_init();
3445 p->statuskey = buffer_init();
3447 @@ -657,9 +658,10 @@
3449 buffer_free(p->fcgi_env);
3450 buffer_free(p->path);
3451 - buffer_free(p->parse_response);
3452 buffer_free(p->statuskey);
3454 + http_response_free(p->resp);
3456 if (p->config_storage) {
3458 for (i = 0; i < srv->config_context->used; i++) {
3459 @@ -825,12 +827,8 @@
3460 fcgi_addr_un.sun_family = AF_UNIX;
3461 strcpy(fcgi_addr_un.sun_path, proc->unixsocket->ptr);
3464 servlen = SUN_LEN(&fcgi_addr_un);
3466 - /* stevens says: */
3467 - servlen = proc->unixsocket->used + sizeof(fcgi_addr_un.sun_family);
3470 socket_type = AF_UNIX;
3471 fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
3479 switch ((child = fork())) {
3482 @@ -1677,12 +1675,9 @@
3483 /* use the unix domain socket */
3484 fcgi_addr_un.sun_family = AF_UNIX;
3485 strcpy(fcgi_addr_un.sun_path, proc->unixsocket->ptr);
3488 servlen = SUN_LEN(&fcgi_addr_un);
3490 - /* stevens says: */
3491 - servlen = proc->unixsocket->used + sizeof(fcgi_addr_un.sun_family);
3494 fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
3496 if (buffer_is_empty(proc->connection_name)) {
3497 @@ -1695,6 +1690,7 @@
3500 fcgi_addr_in.sin_family = AF_INET;
3502 if (0 == inet_aton(host->host->ptr, &(fcgi_addr_in.sin_addr))) {
3503 log_error_write(srv, __FILE__, __LINE__, "sbs",
3504 "converting IP-adress failed for", host->host,
3505 @@ -1702,6 +1698,7 @@
3510 fcgi_addr_in.sin_port = htons(proc->port);
3511 servlen = sizeof(fcgi_addr_in);
3513 @@ -2186,105 +2183,6 @@
3517 -static int fcgi_response_parse(server *srv, connection *con, plugin_data *p, buffer *in) {
3520 - handler_ctx *hctx = con->plugin_ctx[p->id];
3521 - fcgi_extension_host *host= hctx->host;
3525 - buffer_copy_string_buffer(p->parse_response, in);
3527 - /* search for \n */
3528 - for (s = p->parse_response->ptr; NULL != (ns = strchr(s, '\n')); s = ns + 1) {
3529 - char *key, *value;
3533 - /* a good day. Someone has read the specs and is sending a \r\n to us */
3535 - if (ns > p->parse_response->ptr &&
3536 - *(ns-1) == '\r') {
3543 - if (NULL == (value = strchr(s, ':'))) {
3544 - /* we expect: "<key>: <value>\n" */
3548 - key_len = value - key;
3552 - while (*value == ' ' || *value == '\t') value++;
3554 - if (host->mode != FCGI_AUTHORIZER ||
3555 - !(con->http_status == 0 ||
3556 - con->http_status == 200)) {
3557 - /* authorizers shouldn't affect the response headers sent back to the client */
3559 - /* don't forward Status: */
3560 - if (0 != strncasecmp(key, "Status", key_len)) {
3561 - if (NULL == (ds = (data_string *)array_get_unused_element(con->response.headers, TYPE_STRING))) {
3562 - ds = data_response_init();
3564 - buffer_copy_string_len(ds->key, key, key_len);
3565 - buffer_copy_string(ds->value, value);
3567 - array_insert_unique(con->response.headers, (data_unset *)ds);
3573 - if (0 == strncasecmp(key, "Date", key_len)) {
3574 - con->parsed_response |= HTTP_DATE;
3578 - if (0 == strncasecmp(key, "Status", key_len)) {
3579 - con->http_status = strtol(value, NULL, 10);
3580 - con->parsed_response |= HTTP_STATUS;
3584 - if (0 == strncasecmp(key, "Location", key_len)) {
3585 - con->parsed_response |= HTTP_LOCATION;
3589 - if (0 == strncasecmp(key, "Connection", key_len)) {
3590 - con->response.keep_alive = (0 == strcasecmp(value, "Keep-Alive")) ? 1 : 0;
3591 - con->parsed_response |= HTTP_CONNECTION;
3595 - if (0 == strncasecmp(key, "Content-Length", key_len)) {
3596 - con->response.content_length = strtol(value, NULL, 10);
3597 - con->parsed_response |= HTTP_CONTENT_LENGTH;
3599 - if (con->response.content_length < 0) con->response.content_length = 0;
3607 - /* CGI/1.1 rev 03 - 7.2.1.2 */
3608 - if ((con->parsed_response & HTTP_LOCATION) &&
3609 - !(con->parsed_response & HTTP_STATUS)) {
3610 - con->http_status = 302;
3619 @@ -2386,52 +2284,24 @@
3621 static int fcgi_demux_response(server *srv, handler_ctx *hctx) {
3626 plugin_data *p = hctx->plugin_data;
3627 connection *con = hctx->remote_conn;
3628 - int fcgi_fd = hctx->fd;
3629 fcgi_extension_host *host= hctx->host;
3630 fcgi_proc *proc = hctx->proc;
3633 - * check how much we have to read
3635 - if (ioctl(hctx->fd, FIONREAD, &toread)) {
3636 - log_error_write(srv, __FILE__, __LINE__, "sd",
3637 - "unexpected end-of-file (perhaps the fastcgi process died):",
3642 - /* init read-buffer */
3647 - b = chunkqueue_get_append_buffer(hctx->rb);
3648 - buffer_prepare_copy(b, toread + 1);
3650 - /* append to read-buffer */
3651 - if (-1 == (r = read(hctx->fd, b->ptr, toread))) {
3652 - log_error_write(srv, __FILE__, __LINE__, "sds",
3653 - "unexpected end-of-file (perhaps the fastcgi process died):",
3654 - fcgi_fd, strerror(errno));
3658 - /* this should be catched by the b > 0 above */
3661 - b->used = r + 1; /* one extra for the fake \0 */
3662 - b->ptr[b->used - 1] = '\0';
3664 + switch(srv->network_backend_read(srv, con, hctx->fd, hctx->rb)) {
3665 + case NETWORK_STATUS_WAIT_FOR_EVENT:
3666 + /* we are only triggered when there is a event */
3667 log_error_write(srv, __FILE__, __LINE__, "ssdsb",
3668 "unexpected end-of-file (perhaps the fastcgi process died):",
3670 "socket:", proc->connection_name);
3673 + case NETWORK_STATUS_SUCCESS:
3676 + log_error_write(srv, __FILE__, __LINE__, "s", "fastcgi-read failed");
3680 @@ -2454,80 +2324,123 @@
3682 /* is the header already finished */
3683 if (0 == con->file_started) {
3688 - /* search for header terminator
3690 - * if we start with \r\n check if last packet terminated with \r\n
3691 - * if we start with \n check if last packet terminated with \n
3692 - * search for \r\n\r\n
3696 - if (hctx->response_header->used == 0) {
3697 - buffer_copy_string_buffer(hctx->response_header, packet.b);
3699 - buffer_append_string_buffer(hctx->response_header, packet.b);
3701 + int have_content_length = 0;
3702 + int need_more = 0;
3705 - if (NULL != (c = buffer_search_string_len(hctx->response_header, CONST_STR_LEN("\r\n\r\n")))) {
3706 - blen = hctx->response_header->used - (c - hctx->response_header->ptr) - 4;
3707 - hctx->response_header->used = (c - hctx->response_header->ptr) + 3;
3708 - c += 4; /* point the the start of the response */
3709 - } else if (NULL != (c = buffer_search_string_len(hctx->response_header, CONST_STR_LEN("\n\n")))) {
3710 - blen = hctx->response_header->used - (c - hctx->response_header->ptr) - 2;
3711 - hctx->response_header->used = c - hctx->response_header->ptr + 2;
3712 - c += 2; /* point the the start of the response */
3714 - /* no luck, no header found */
3715 + /* append the current packet to the chunk queue */
3716 + chunkqueue_append_buffer(hctx->http_rb, packet.b);
3717 + http_response_reset(p->resp);
3719 + switch(http_response_parse_cq(hctx->http_rb, p->resp)) {
3721 + /* parsing the response header failed */
3723 + con->http_status = 502; /* Bad Gateway */
3726 + case PARSE_NEED_MORE:
3728 + break; /* leave the loop */
3729 + case PARSE_SUCCESS:
3732 + /* should not happen */
3736 - /* parse the response header */
3737 - fcgi_response_parse(srv, con, p, hctx->response_header);
3738 + if (need_more) break;
3740 - con->file_started = 1;
3741 + chunkqueue_remove_finished_chunks(hctx->http_rb);
3743 - if (host->mode == FCGI_AUTHORIZER &&
3744 - (con->http_status == 0 ||
3745 - con->http_status == 200)) {
3746 + con->http_status = p->resp->status;
3748 + /* handle the header fields */
3749 + if (host->mode == FCGI_AUTHORIZER) {
3750 + /* auth mode is a bit different */
3752 + if (con->http_status == 0 ||
3753 + con->http_status == 200) {
3754 /* a authorizer with approved the static request, ignore the content here */
3755 hctx->send_content_body = 0;
3759 - if (host->allow_xsendfile &&
3760 - NULL != (ds = (data_string *) array_get_element(con->response.headers, "X-LIGHTTPD-send-file"))) {
3761 - stat_cache_entry *sce;
3762 + /* copy the http-headers */
3763 + for (i = 0; i < p->resp->headers->used; i++) {
3764 + const char *ign[] = { "Status", NULL };
3768 - if (HANDLER_ERROR != stat_cache_get_entry(srv, con, ds->value, &sce)) {
3770 + data_string *header = (data_string *)p->resp->headers->data[i];
3772 + /* ignore all headers in AUTHORIZER mode */
3773 + if (host->mode == FCGI_AUTHORIZER) continue;
3775 + /* some headers are ignored by default */
3776 + for (j = 0; ign[j]; j++) {
3777 + if (0 == strcasecmp(ign[j], header->key->ptr)) break;
3779 + if (ign[j]) continue;
3781 + if (0 == buffer_caseless_compare(CONST_BUF_LEN(header->key), CONST_STR_LEN("Location"))) {
3782 + /* CGI/1.1 rev 03 - 7.2.1.2 */
3783 + con->http_status = 302;
3784 + } else if (0 == buffer_caseless_compare(CONST_BUF_LEN(header->key), CONST_STR_LEN("Content-Length"))) {
3785 + have_content_length = 1;
3786 + } else if (0 == buffer_caseless_compare(CONST_BUF_LEN(header->key), CONST_STR_LEN("X-Sendfile")) ||
3787 + 0 == buffer_caseless_compare(CONST_BUF_LEN(header->key), CONST_STR_LEN("X-LIGHTTPD-send-file"))) {
3789 - http_chunk_append_file(srv, con, ds->value, 0, sce->st.st_size);
3790 + stat_cache_entry *sce;
3792 + if (host->allow_xsendfile &&
3793 + HANDLER_ERROR != stat_cache_get_entry(srv, con, header->value, &sce)) {
3794 + http_chunk_append_file(srv, con, header->value, 0, sce->st.st_size);
3795 hctx->send_content_body = 0; /* ignore the content */
3797 joblist_append(srv, con);
3800 + continue; /* ignore header */
3803 + if (NULL == (ds = (data_string *)array_get_unused_element(con->response.headers, TYPE_STRING))) {
3804 + ds = data_response_init();
3806 + buffer_copy_string_buffer(ds->key, header->key);
3807 + buffer_copy_string_buffer(ds->value, header->value);
3809 - if (hctx->send_content_body && blen > 1) {
3810 - /* enable chunked-transfer-encoding */
3811 + array_insert_unique(con->response.headers, (data_unset *)ds);
3814 + /* header is complete ... go on with the body */
3816 + con->file_started = 1;
3818 + if (hctx->send_content_body) {
3819 + chunk *c = hctx->http_rb->first;
3821 + /* if we don't have a content-length enable chunked encoding
3824 + * TODO: move this to a later stage in the filter-queue
3826 if (con->request.http_version == HTTP_VERSION_1_1 &&
3827 - !(con->parsed_response & HTTP_CONTENT_LENGTH)) {
3828 + !have_content_length) {
3829 con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
3832 - http_chunk_append_mem(srv, con, c, blen);
3833 + /* copy the rest of the data */
3834 + for (c = hctx->http_rb->first; c; c = c->next) {
3835 + if (c->mem->used > 1) {
3836 + http_chunk_append_mem(srv, con, c->mem->ptr + c->offset, c->mem->used - c->offset);
3837 + c->offset = c->mem->used - 1;
3840 + chunkqueue_remove_finished_chunks(hctx->http_rb);
3841 joblist_append(srv, con);
3843 } else if (hctx->send_content_body && packet.b->used > 1) {
3844 - if (con->request.http_version == HTTP_VERSION_1_1 &&
3845 - !(con->parsed_response & HTTP_CONTENT_LENGTH)) {
3846 - /* enable chunked-transfer-encoding */
3847 - con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
3850 http_chunk_append_mem(srv, con, packet.b->ptr, packet.b->used);
3851 joblist_append(srv, con);
3853 @@ -2606,7 +2519,7 @@
3854 if (!proc->is_local) break;
3856 /* the child should not terminate at all */
3859 switch(waitpid(proc->pid, &status, WNOHANG)) {
3861 /* child is still alive */
3862 @@ -2633,7 +2546,7 @@
3863 proc->state = PROC_STATE_DIED;
3868 /* fall through if we have a dead proc now */
3869 if (proc->state != PROC_STATE_DIED) break;
3871 @@ -2934,10 +2847,11 @@
3873 if (hctx->wb->bytes_out == 0 &&
3874 hctx->reconnects < 5) {
3876 usleep(10000); /* take away the load of the webserver
3877 * to let the php a chance to restart
3881 fcgi_reconnect(srv, hctx);
3883 return HANDLER_WAIT_FOR_FD;
3884 @@ -2949,7 +2863,7 @@
3888 - log_error_write(srv, __FILE__, __LINE__, "ssdsd",
3889 + log_error_write(srv, __FILE__, __LINE__, "ssosd",
3890 "[REPORT ME] connection was dropped after accept(). reconnect() denied:",
3891 "write-offset:", hctx->wb->bytes_out,
3892 "reconnect attempts:", hctx->reconnects);
3893 @@ -3155,7 +3069,7 @@
3896 /* only fetch the zombie if it is not already done */
3899 switch(waitpid(proc->pid, &status, WNOHANG)) {
3901 /* child is still alive */
3902 @@ -3195,6 +3109,7 @@
3909 if (con->file_started == 0) {
3910 @@ -3307,15 +3222,14 @@
3912 return HANDLER_FINISHED;
3917 static int fcgi_patch_connection(server *srv, connection *con, plugin_data *p) {
3919 plugin_config *s = p->config_storage[0];
3923 - PATCH(ext_mapping);
3924 + PATCH_OPTION(exts);
3925 + PATCH_OPTION(debug);
3926 + PATCH_OPTION(ext_mapping);
3928 /* skip the first, the global context */
3929 for (i = 1; i < srv->config_context->used; i++) {
3930 @@ -3330,19 +3244,17 @@
3931 data_unset *du = dc->value->data[j];
3933 if (buffer_is_equal_string(du->key, CONST_STR_LEN("fastcgi.server"))) {
3935 + PATCH_OPTION(exts);
3936 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("fastcgi.debug"))) {
3938 + PATCH_OPTION(debug);
3939 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("fastcgi.map-extensions"))) {
3940 - PATCH(ext_mapping);
3941 + PATCH_OPTION(ext_mapping);
3951 static handler_t fcgi_check_extension(server *srv, connection *con, void *p_d, int uri_path_handler) {
3952 plugin_data *p = p_d;
3953 @@ -3610,10 +3522,33 @@
3955 * currently we wait for the TCP timeout which is on Linux 180 seconds
3961 + for (i = 0; i < srv->conns->used; i++) {
3962 + connection *con = srv->conns->ptr[i];
3963 + handler_ctx *hctx = con->plugin_ctx[p->id];
3965 + /* if a connection is ours and is in handle-req for more than max-request-time
3966 + * kill the connection */
3968 + if (con->mode != p->id) continue;
3969 + if (con->state != CON_STATE_HANDLE_REQUEST) continue;
3970 + if (srv->cur_ts < con->request_start + 60) continue;
3972 + /* the request is waiting for a FCGI_STDOUT since 60 seconds */
3974 + /* kill the connection */
3976 + log_error_write(srv, __FILE__, __LINE__, "s", "fastcgi backend didn't responded after 60 seconds");
3978 + fcgi_connection_close(srv, hctx);
3980 + con->mode = DIRECT;
3981 + con->http_status = 500;
3983 + joblist_append(srv, con);
3986 /* check all childs if they are still up */
3988 for (i = 0; i < srv->config_context->used; i++) {
3989 @@ -3737,7 +3672,7 @@
3992 if (proc->pid == 0) continue;
3995 switch (waitpid(proc->pid, &status, WNOHANG)) {
3997 /* child still running after timeout, good */
3998 @@ -3781,6 +3716,7 @@
3999 proc->state = PROC_STATE_UNSET;
4006 --- lighttpd-1.4.11/src/mod_flv_streaming.c 2006-03-07 14:06:26.000000000 +0200
4007 +++ lighttpd/src/mod_flv_streaming.c 2006-07-11 21:23:40.043852471 +0300
4008 @@ -108,13 +108,11 @@
4009 return HANDLER_GO_ON;
4014 static int mod_flv_streaming_patch_connection(server *srv, connection *con, plugin_data *p) {
4016 plugin_config *s = p->config_storage[0];
4018 - PATCH(extensions);
4019 + PATCH_OPTION(extensions);
4021 /* skip the first, the global context */
4022 for (i = 1; i < srv->config_context->used; i++) {
4023 @@ -129,16 +127,15 @@
4024 data_unset *du = dc->value->data[j];
4026 if (buffer_is_equal_string(du->key, CONST_STR_LEN("flv-streaming.extensions"))) {
4027 - PATCH(extensions);
4028 + PATCH_OPTION(extensions);
4037 -static int split_get_params(server *srv, connection *con, array *get_params, buffer *qrystr) {
4038 +static int split_get_params(array *get_params, buffer *qrystr) {
4041 char *key = NULL, *val = NULL;
4043 /* terminate the value */
4044 qrystr->ptr[i] = '\0';
4046 - if (NULL == (ds = (data_string *)array_get_unused_element(con->request.headers, TYPE_STRING))) {
4047 + if (NULL == (ds = (data_string *)array_get_unused_element(get_params, TYPE_STRING))) {
4048 ds = data_string_init();
4050 buffer_copy_string_len(ds->key, key, strlen(key));
4053 array_reset(p->get_params);
4054 buffer_copy_string_buffer(p->query_str, con->uri.query);
4055 - split_get_params(srv, con, p->get_params, p->query_str);
4056 + split_get_params(p->get_params, p->query_str);
4058 if (NULL == (get_param = (data_string *)array_get_element(p->get_params, "start"))) {
4059 return HANDLER_GO_ON;
4060 --- lighttpd-1.4.11/src/mod_indexfile.c 2005-09-30 01:08:53.000000000 +0300
4061 +++ lighttpd/src/mod_indexfile.c 2006-07-11 21:23:40.191861741 +0300
4062 @@ -103,13 +103,11 @@
4063 return HANDLER_GO_ON;
4068 static int mod_indexfile_patch_connection(server *srv, connection *con, plugin_data *p) {
4070 plugin_config *s = p->config_storage[0];
4072 - PATCH(indexfiles);
4073 + PATCH_OPTION(indexfiles);
4075 /* skip the first, the global context */
4076 for (i = 1; i < srv->config_context->used; i++) {
4077 @@ -124,16 +122,15 @@
4078 data_unset *du = dc->value->data[j];
4080 if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.indexfiles"))) {
4081 - PATCH(indexfiles);
4082 + PATCH_OPTION(indexfiles);
4083 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("index-file.names"))) {
4084 - PATCH(indexfiles);
4085 + PATCH_OPTION(indexfiles);
4094 URIHANDLER_FUNC(mod_indexfile_subrequest) {
4095 plugin_data *p = p_d;
4096 --- lighttpd-1.4.11/src/mod_mysql_vhost.c 2006-01-14 20:35:10.000000000 +0200
4097 +++ lighttpd/src/mod_mysql_vhost.c 2006-07-11 21:23:40.031851719 +0300
4099 -#include <unistd.h>
4103 -#include <strings.h>
4104 +#include <string.h>
4106 #ifdef HAVE_CONFIG_H
4110 +#ifdef HAVE_MYSQL_H
4111 +# ifdef HAVE_LIBMYSQL
4112 +# define HAVE_MYSQL
4122 #include "stat_cache.h"
4123 -#ifdef DEBUG_MOD_MYSQL_VHOST
4126 +#include "sys-files.h"
4129 - * Plugin for lighttpd to use MySQL
4130 - * for domain to directory lookups,
4131 - * i.e virtual hosts (vhosts).
4133 - * Optionally sets fcgi_offset and fcgi_arg
4134 - * in preparation for fcgi.c to handle
4135 - * per-user fcgi chroot jails.
4137 - * /ada@riksnet.se 2004-12-06
4139 +#include "mod_sql_vhost_core.h"
4149 +#define CORE_PLUGIN "mod_sql_vhost_core"
4152 - unsigned short port;
4159 + mod_sql_vhost_core_plugin_config *core;
4162 /* global plugin data */
4167 -/* per connection plugin data */
4169 - buffer *server_name;
4170 - buffer *document_root;
4172 - unsigned fcgi_offset;
4173 -} plugin_connection_data;
4174 +SQLVHOST_BACKEND_GETVHOST(mod_mysql_vhost_get_vhost);
4176 /* init the plugin data */
4177 INIT_FUNC(mod_mysql_vhost_init) {
4183 - log_error_write(srv, __FILE__, __LINE__, "ss",
4184 - "mod_mysql_vhost_cleanup", p ? "yes" : "NO");
4186 if (!p) return HANDLER_GO_ON;
4188 if (p->config_storage) {
4191 mysql_close(s->mysql);
4193 - buffer_free(s->mydb);
4194 - buffer_free(s->myuser);
4195 - buffer_free(s->mypass);
4196 - buffer_free(s->mysock);
4197 buffer_free(s->mysql_pre);
4198 buffer_free(s->mysql_post);
4200 @@ -117,109 +93,50 @@
4201 return HANDLER_GO_ON;
4204 -/* handle the plugin per connection data */
4205 -static void* mod_mysql_vhost_connection_data(server *srv, connection *con, void *p_d)
4207 - plugin_data *p = p_d;
4208 - plugin_connection_data *c = con->plugin_ctx[p->id];
4213 - log_error_write(srv, __FILE__, __LINE__, "ss",
4214 - "mod_mysql_connection_data", c ? "old" : "NEW");
4218 - c = calloc(1, sizeof(*c));
4220 - c->server_name = buffer_init();
4221 - c->document_root = buffer_init();
4222 - c->fcgi_arg = buffer_init();
4223 - c->fcgi_offset = 0;
4225 - return con->plugin_ctx[p->id] = c;
4228 -/* destroy the plugin per connection data */
4229 -CONNECTION_FUNC(mod_mysql_vhost_handle_connection_close) {
4230 - plugin_data *p = p_d;
4231 - plugin_connection_data *c = con->plugin_ctx[p->id];
4236 - log_error_write(srv, __FILE__, __LINE__, "ss",
4237 - "mod_mysql_vhost_handle_connection_close", c ? "yes" : "NO");
4240 - if (!c) return HANDLER_GO_ON;
4242 - buffer_free(c->server_name);
4243 - buffer_free(c->document_root);
4244 - buffer_free(c->fcgi_arg);
4245 - c->fcgi_offset = 0;
4249 - con->plugin_ctx[p->id] = NULL;
4250 - return HANDLER_GO_ON;
4253 /* set configuration values */
4254 SERVER_FUNC(mod_mysql_vhost_set_defaults) {
4255 plugin_data *p = p_d;
4256 + mod_sql_vhost_core_plugin_data *core_config;
4261 - config_values_t cv[] = {
4262 - { "mysql-vhost.db", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
4263 - { "mysql-vhost.user", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
4264 - { "mysql-vhost.pass", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
4265 - { "mysql-vhost.sock", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
4266 - { "mysql-vhost.sql", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
4267 - { "mysql-vhost.hostname", NULL, T_CONFIG_STRING,T_CONFIG_SCOPE_SERVER },
4268 - { "mysql-vhost.port", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_SERVER },
4269 - { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
4272 + /* our very own plugin storage, one entry for each conditional
4274 + * srv->config_context->used is the number of conditionals
4276 p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
4278 + /* get the config of the core-plugin */
4279 + core_config = plugin_get_config(srv, CORE_PLUGIN);
4282 + /* walk through all conditionals and check for assignments */
4283 for (i = 0; i < srv->config_context->used; i++) {
4289 + /* get the config from the core plugin for this conditional-context */
4290 s = calloc(1, sizeof(plugin_config));
4291 - s->mydb = buffer_init();
4292 - s->myuser = buffer_init();
4293 - s->mypass = buffer_init();
4294 - s->mysock = buffer_init();
4295 - s->hostname = buffer_init();
4296 - s->port = 0; /* default port for mysql */
4297 - sel = buffer_init();
4299 + s->core = core_config->config_storage[i];
4303 s->mysql_pre = buffer_init();
4304 s->mysql_post = buffer_init();
4306 - cv[0].destination = s->mydb;
4307 - cv[1].destination = s->myuser;
4308 - cv[2].destination = s->mypass;
4309 - cv[3].destination = s->mysock;
4310 - cv[4].destination = sel;
4311 - cv[5].destination = s->hostname;
4312 - cv[6].destination = &(s->port);
4314 p->config_storage[i] = s;
4316 - if (config_insert_values_global(srv,
4317 - ((data_config *)srv->config_context->data[i])->value,
4318 - cv)) return HANDLER_ERROR;
4319 + /* check if we are the plugin for this backend */
4320 + if (!buffer_is_equal_string(s->core->backend, CONST_STR_LEN("mysql"))) continue;
4322 - s->mysql_pre = buffer_init();
4323 - s->mysql_post = buffer_init();
4324 + /* attach us to the core-plugin */
4325 + s->core->backend_data = p;
4326 + s->core->get_vhost = mod_mysql_vhost_get_vhost;
4328 + sel = buffer_init();
4329 + buffer_copy_string_buffer(sel, s->core->select_vhost);
4331 if (sel->used && (qmark = index(sel->ptr, '?'))) {
4336 /* all have to be set */
4337 - if (!(buffer_is_empty(s->myuser) ||
4338 - buffer_is_empty(s->mydb))) {
4339 + if (!(buffer_is_empty(s->core->user) ||
4340 + buffer_is_empty(s->core->db))) {
4344 @@ -251,10 +168,10 @@
4346 return HANDLER_ERROR;
4348 -#define FOO(x) (s->x->used ? s->x->ptr : NULL)
4349 +#define FOO(x) (s->core->x->used ? s->core->x->ptr : NULL)
4351 - if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass),
4352 - FOO(mydb), s->port, FOO(mysock), 0)) {
4353 + if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(user), FOO(pass),
4354 + FOO(db), s->core->port, FOO(sock), 0)) {
4355 log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql));
4357 return HANDLER_ERROR;
4358 @@ -275,17 +192,13 @@
4359 return HANDLER_GO_ON;
4364 static int mod_mysql_vhost_patch_connection(server *srv, connection *con, plugin_data *p) {
4367 plugin_config *s = p->config_storage[0];
4370 - PATCH(mysql_post);
4374 + PATCH_OPTION(mysql_pre);
4375 + PATCH_OPTION(mysql_post);
4376 + PATCH_OPTION(mysql);
4378 /* skip the first, the global context */
4379 for (i = 1; i < srv->config_context->used; i++) {
4380 @@ -295,31 +208,21 @@
4381 /* condition didn't match */
4382 if (!config_check_cond(srv, con, dc)) continue;
4384 - /* merge config */
4385 - for (j = 0; j < dc->value->used; j++) {
4386 - data_unset *du = dc->value->data[j];
4388 - if (buffer_is_equal_string(du->key, CONST_STR_LEN("mysql-vhost.sql"))) {
4390 - PATCH(mysql_post);
4396 + PATCH_OPTION(mysql);
4397 + PATCH_OPTION(mysql_pre);
4398 + PATCH_OPTION(mysql_post);
4407 -/* handle document root request */
4408 -CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) {
4410 + * get the vhost info from the database
4412 +SQLVHOST_BACKEND_GETVHOST(mod_mysql_vhost_get_vhost) {
4413 plugin_data *p = p_d;
4414 - plugin_connection_data *c;
4415 - stat_cache_entry *sce;
4419 @@ -332,13 +235,6 @@
4421 if (!p->conf.mysql) return HANDLER_GO_ON;
4423 - /* sets up connection data if not done yet */
4424 - c = mod_mysql_vhost_connection_data(srv, con, p_d);
4426 - /* check if cached this connection */
4427 - if (c->server_name->used && /* con->uri.authority->used && */
4428 - buffer_is_equal(c->server_name, con->uri.authority)) goto GO_ON;
4430 /* build and run SQL query */
4431 buffer_copy_string_buffer(p->tmp_buf, p->conf.mysql_pre);
4432 if (p->conf.mysql_post->used) {
4433 @@ -347,76 +243,42 @@
4435 if (mysql_query(p->conf.mysql, p->tmp_buf->ptr)) {
4436 log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(p->conf.mysql));
4439 + mysql_free_result(result);
4440 + return HANDLER_GO_ON;
4442 result = mysql_store_result(p->conf.mysql);
4443 cols = mysql_num_fields(result);
4444 row = mysql_fetch_row(result);
4446 if (!row || cols < 1) {
4447 /* no such virtual host */
4448 mysql_free_result(result);
4449 return HANDLER_GO_ON;
4452 - /* sanity check that really is a directory */
4453 - buffer_copy_string(p->tmp_buf, row[0]);
4454 - BUFFER_APPEND_SLASH(p->tmp_buf);
4456 - if (HANDLER_ERROR == stat_cache_get_entry(srv, con, p->tmp_buf, &sce)) {
4457 - log_error_write(srv, __FILE__, __LINE__, "sb", strerror(errno), p->tmp_buf);
4460 - if (!S_ISDIR(sce->st.st_mode)) {
4461 - log_error_write(srv, __FILE__, __LINE__, "sb", "Not a directory", p->tmp_buf);
4465 - /* cache the data */
4466 - buffer_copy_string_buffer(c->server_name, con->uri.authority);
4467 - buffer_copy_string_buffer(c->document_root, p->tmp_buf);
4468 + buffer_copy_string(docroot, row[0]);
4470 - /* fcgi_offset and fcgi_arg are optional */
4471 - if (cols > 1 && row[1]) {
4472 - c->fcgi_offset = atoi(row[1]);
4474 - if (cols > 2 && row[2]) {
4475 - buffer_copy_string(c->fcgi_arg, row[2]);
4477 - c->fcgi_arg->used = 0;
4480 - c->fcgi_offset = c->fcgi_arg->used = 0;
4482 mysql_free_result(result);
4484 - /* fix virtual server and docroot */
4485 -GO_ON: buffer_copy_string_buffer(con->server_name, c->server_name);
4486 - buffer_copy_string_buffer(con->physical.doc_root, c->document_root);
4489 - log_error_write(srv, __FILE__, __LINE__, "sbbdb",
4490 - result ? "NOT CACHED" : "cached",
4491 - con->server_name, con->physical.doc_root,
4492 - c->fcgi_offset, c->fcgi_arg);
4494 return HANDLER_GO_ON;
4496 -ERR500: if (result) mysql_free_result(result);
4497 - con->http_status = 500; /* Internal Error */
4498 - return HANDLER_FINISHED;
4501 /* this function is called at dlopen() time and inits the callbacks */
4502 int mod_mysql_vhost_plugin_init(plugin *p) {
4505 p->version = LIGHTTPD_VERSION_ID;
4506 p->name = buffer_init_string("mysql_vhost");
4508 p->init = mod_mysql_vhost_init;
4509 p->cleanup = mod_mysql_vhost_cleanup;
4510 - p->handle_request_done = mod_mysql_vhost_handle_connection_close;
4512 p->set_defaults = mod_mysql_vhost_set_defaults;
4513 - p->handle_docroot = mod_mysql_vhost_handle_docroot;
4515 + ds = data_string_init();
4516 + buffer_copy_string(ds->value, CORE_PLUGIN);
4517 + array_insert_unique(p->required_plugins, (data_unset *)ds);
4521 --- lighttpd-1.4.11/src/mod_proxy.c 2006-01-31 13:01:22.000000000 +0200
4522 +++ lighttpd/src/mod_proxy.c 2006-07-11 21:23:40.099855979 +0300
4524 #include <sys/types.h>
4526 -#include <unistd.h>
4532 #include "inet_ntop_cache.h"
4534 +#include "network.h"
4536 +#include "http_resp.h"
4543 #include "sys-socket.h"
4544 +#include "sys-files.h"
4545 +#include "sys-strings.h"
4547 #define data_proxy data_fastcgi
4548 #define data_proxy_init data_fastcgi_init
4552 proxy_balance_t balance;
4554 + array *last_used_backends; /* "extension" : last_used_backend */
4559 buffer *parse_response;
4560 buffer *balance_buf;
4562 + array *ignore_headers;
4564 plugin_config **config_storage;
4568 PROXY_STATE_CONNECT,
4569 PROXY_STATE_PREPARE_WRITE,
4572 + PROXY_STATE_RESPONSE_HEADER,
4573 + PROXY_STATE_RESPONSE_CONTENT,
4575 } proxy_connection_state_t;
4578 buffer *response_header;
4583 int fd; /* fd to the proxy process */
4584 int fde_ndx; /* index into the fd-event buffer */
4586 hctx->response_header = buffer_init();
4588 hctx->wb = chunkqueue_init();
4589 + hctx->rb = chunkqueue_init();
4593 @@ -138,17 +149,38 @@
4594 buffer_free(hctx->response);
4595 buffer_free(hctx->response_header);
4596 chunkqueue_free(hctx->wb);
4597 + chunkqueue_free(hctx->rb);
4602 INIT_FUNC(mod_proxy_init) {
4606 + char *hop2hop_headers[] = {
4613 p = calloc(1, sizeof(*p));
4615 p->parse_response = buffer_init();
4616 p->balance_buf = buffer_init();
4617 + p->ignore_headers = array_init();
4619 + for (i = 0; hop2hop_headers[i]; i++) {
4622 + if (NULL == (ds = (data_string *)array_get_unused_element(p->ignore_headers, TYPE_STRING))) {
4623 + ds = data_string_init();
4626 + buffer_copy_string(ds->value, hop2hop_headers[i]);
4627 + array_insert_unique(p->ignore_headers, (data_unset *)ds);
4633 plugin_config *s = p->config_storage[i];
4637 array_free(s->extensions);
4638 + array_free(s->last_used_backends);
4643 free(p->config_storage);
4646 + free(p->ignore_headers);
4650 return HANDLER_GO_ON;
4653 s = malloc(sizeof(plugin_config));
4654 s->extensions = array_init();
4655 + s->last_used_backends = array_init();
4658 cv[0].destination = s->extensions;
4659 @@ -372,14 +407,22 @@
4660 proxy_addr = (struct sockaddr *) &proxy_addr_in;
4662 if (-1 == connect(proxy_fd, proxy_addr, servlen)) {
4663 - if (errno == EINPROGRESS || errno == EALREADY) {
4665 + errno = WSAGetLastError();
4669 + case WSAEWOULDBLOCK:
4673 if (p->conf.debug) {
4674 log_error_write(srv, __FILE__, __LINE__, "sd",
4675 "connect delayed:", proxy_fd);
4682 log_error_write(srv, __FILE__, __LINE__, "sdsd",
4683 "connect failed:", proxy_fd, strerror(errno), errno);
4688 + fprintf(stderr, "%s.%d: connected fd = %d\r\n", __FILE__, __LINE__, proxy_fd);
4689 if (p->conf.debug) {
4690 log_error_write(srv, __FILE__, __LINE__, "sd",
4691 "connect succeeded: ", proxy_fd);
4695 connection *con = hctx->remote_conn;
4696 + plugin_data *p = hctx->plugin_data;
4701 ds = (data_string *)con->request.headers->data[i];
4703 if (ds->value->used && ds->key->used) {
4704 - if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Connection"))) continue;
4706 + /* don't copy hop-to-hop headers */
4707 + if (array_get_element(p->ignore_headers, ds->key->ptr)) continue;
4709 buffer_append_string_buffer(b, ds->key);
4710 BUFFER_APPEND_STRING_CONST(b, ": ");
4711 @@ -531,199 +578,101 @@
4715 -static int proxy_response_parse(server *srv, connection *con, plugin_data *p, buffer *in) {
4717 - int http_response_status = -1;
4721 - /* \r\n -> \0\0 */
4723 - buffer_copy_string_buffer(p->parse_response, in);
4725 - for (s = p->parse_response->ptr; NULL != (ns = strstr(s, "\r\n")); s = ns + 2) {
4726 - char *key, *value;
4734 - if (-1 == http_response_status) {
4735 - /* The first line of a Response message is the Status-Line */
4737 - for (key=s; *key && *key != ' '; key++);
4738 +static void chunkqueue_print(chunkqueue *cq) {
4742 - http_response_status = (int) strtol(key, NULL, 10);
4743 - if (http_response_status <= 0) http_response_status = 502;
4745 - http_response_status = 502;
4746 + for (c = cq->first; c; c = c->next) {
4747 + fprintf(stderr, "%s", c->mem->ptr + c->offset);
4750 - con->http_status = http_response_status;
4751 - con->parsed_response |= HTTP_STATUS;
4753 + fprintf(stderr, "\r\n");
4756 - if (NULL == (value = strchr(s, ':'))) {
4757 - /* now we expect: "<key>: <value>\n" */
4763 - key_len = value - key;
4767 - while (*value == ' ' || *value == '\t') value++;
4770 +static int proxy_demux_response(server *srv, handler_ctx *hctx) {
4771 + plugin_data *p = hctx->plugin_data;
4772 + connection *con = hctx->remote_conn;
4773 + int proxy_fd = hctx->fd;
4774 + chunkqueue *next_queue = NULL;
4779 - if (0 == strncasecmp(key, "Date", key_len)) {
4780 - con->parsed_response |= HTTP_DATE;
4784 - if (0 == strncasecmp(key, "Location", key_len)) {
4785 - con->parsed_response |= HTTP_LOCATION;
4789 - if (0 == strncasecmp(key, "Connection", key_len)) {
4792 + switch(srv->network_backend_read(srv, con, proxy_fd, hctx->rb)) {
4793 + case NETWORK_STATUS_SUCCESS:
4794 + /* we got content */
4797 - if (0 == strncasecmp(key, "Content-Length", key_len)) {
4798 - con->response.content_length = strtol(value, NULL, 10);
4799 - con->parsed_response |= HTTP_CONTENT_LENGTH;
4805 + case NETWORK_STATUS_CONNECTION_CLOSE:
4806 + /* we are done, get out of here */
4807 + con->file_finished = 1;
4809 - if (copy_header) {
4810 - if (NULL == (ds = (data_string *)array_get_unused_element(con->response.headers, TYPE_STRING))) {
4811 - ds = data_response_init();
4813 - buffer_copy_string_len(ds->key, key, key_len);
4814 - buffer_copy_string(ds->value, value);
4815 + /* close the chunk-queue with a empty chunk */
4816 + http_chunk_append_mem(srv, con, NULL, 0);
4817 + joblist_append(srv, con);
4819 - array_insert_unique(con->response.headers, (data_unset *)ds);
4829 + /* looks like we got some content
4831 + * split off the header from the incoming stream
4834 + if (hctx->state == PROXY_STATE_RESPONSE_HEADER) {
4835 + http_resp *resp = http_response_init();
4837 -static int proxy_demux_response(server *srv, handler_ctx *hctx) {
4841 + /* the response header is not fully received yet,
4843 + * extract the http-response header from the rb-cq
4845 + fprintf(stderr, "%s.%d: network-read\r\n", __FILE__, __LINE__);
4846 + chunkqueue_print(hctx->rb);
4848 - plugin_data *p = hctx->plugin_data;
4849 - connection *con = hctx->remote_conn;
4850 - int proxy_fd = hctx->fd;
4851 + switch (http_response_parse_cq(hctx->rb, resp)) {
4853 + /* parsing failed */
4855 - /* check how much we have to read */
4856 - if (ioctl(hctx->fd, FIONREAD, &b)) {
4857 - log_error_write(srv, __FILE__, __LINE__, "sd",
4862 + con->http_status = 502; /* Bad Gateway */
4864 + case PARSE_NEED_MORE:
4866 + case PARSE_SUCCESS:
4867 + con->http_status = resp->status;
4869 + fprintf(stderr, "%s.%d: parsing done\r\n", __FILE__, __LINE__);
4870 + chunkqueue_print(hctx->rb);
4872 - if (p->conf.debug) {
4873 - log_error_write(srv, __FILE__, __LINE__, "sd",
4874 - "proxy - have to read:", b);
4876 + con->file_started = 1;
4879 - if (hctx->response->used == 0) {
4880 - /* avoid too small buffer */
4881 - buffer_prepare_append(hctx->response, b + 1);
4882 - hctx->response->used = 1;
4884 - buffer_prepare_append(hctx->response, hctx->response->used + b);
4885 + hctx->state = PROXY_STATE_RESPONSE_CONTENT;
4889 - if (-1 == (r = read(hctx->fd, hctx->response->ptr + hctx->response->used - 1, b))) {
4890 - log_error_write(srv, __FILE__, __LINE__, "sds",
4891 - "unexpected end-of-file (perhaps the proxy process died):",
4892 - proxy_fd, strerror(errno));
4896 - /* this should be catched by the b > 0 above */
4898 + /* FIXME: pass the response-header to the other plugins to
4899 + * setup the filter-queue
4901 + * - use next-queue instead of con->write_queue
4904 - hctx->response->used += r;
4905 - hctx->response->ptr[hctx->response->used - 1] = '\0';
4906 + next_queue = con->write_queue;
4909 - log_error_write(srv, __FILE__, __LINE__, "sdsbs",
4910 - "demux: Response buffer len", hctx->response->used, ":", hctx->response, ":");
4912 + assert(hctx->state == PROXY_STATE_RESPONSE_CONTENT);
4914 - if (0 == con->got_response) {
4915 - con->got_response = 1;
4916 - buffer_prepare_copy(hctx->response_header, 128);
4919 - if (0 == con->file_started) {
4922 - /* search for the \r\n\r\n in the string */
4923 - if (NULL != (c = buffer_search_string_len(hctx->response, "\r\n\r\n", 4))) {
4924 - size_t hlen = c - hctx->response->ptr + 4;
4925 - size_t blen = hctx->response->used - hlen - 1;
4928 - buffer_append_string_len(hctx->response_header, hctx->response->ptr, c - hctx->response->ptr + 4);
4930 - log_error_write(srv, __FILE__, __LINE__, "sb", "Header:", hctx->response_header);
4932 - /* parse the response header */
4933 - proxy_response_parse(srv, con, p, hctx->response_header);
4934 + /* FIXME: if we have a content-length or chunked-encoding
4937 + * for now we wait for EOF on the socket */
4939 - /* enable chunked-transfer-encoding */
4940 - if (con->request.http_version == HTTP_VERSION_1_1 &&
4941 - !(con->parsed_response & HTTP_CONTENT_LENGTH)) {
4942 - con->response.transfer_encoding = HTTP_TRANSFER_ENCODING_CHUNKED;
4944 + /* copy the content to the next cq */
4945 + for (c = hctx->rb->first; c; c = c->next) {
4946 + http_chunk_append_mem(srv, con, c->mem->ptr + c->offset, c->mem->used - c->offset);
4948 - con->file_started = 1;
4950 - http_chunk_append_mem(srv, con, c + 4, blen + 1);
4951 - joblist_append(srv, con);
4952 + c->offset = c->mem->used - 1;
4954 - hctx->response->used = 0;
4957 - http_chunk_append_mem(srv, con, hctx->response->ptr, hctx->response->used);
4958 - joblist_append(srv, con);
4959 - hctx->response->used = 0;
4963 - /* reading from upstream done */
4964 - con->file_finished = 1;
4966 - http_chunk_append_mem(srv, con, NULL, 0);
4967 - joblist_append(srv, con);
4971 + chunkqueue_remove_finished_chunks(hctx->rb);
4979 if (p->conf.debug) {
4980 log_error_write(srv, __FILE__, __LINE__, "s", "proxy - connect - delayed success");
4982 + fprintf(stderr, "%s.%d: connected fd = %d\r\n", __FILE__, __LINE__, hctx->fd);
4985 proxy_set_state(srv, hctx, PROXY_STATE_PREPARE_WRITE);
4986 @@ -818,21 +768,20 @@
4988 chunkqueue_remove_finished_chunks(hctx->wb);
4991 - if (errno != EAGAIN &&
4994 + case NETWORK_STATUS_FATAL_ERROR:
4995 log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed:", strerror(errno), errno);
4997 return HANDLER_ERROR;
4999 + case NETWORK_STATUS_WAIT_FOR_EVENT:
5001 fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
5003 return HANDLER_WAIT_FOR_EVENT;
5007 if (hctx->wb->bytes_out == hctx->wb->bytes_in) {
5008 - proxy_set_state(srv, hctx, PROXY_STATE_READ);
5009 + proxy_set_state(srv, hctx, PROXY_STATE_RESPONSE_HEADER);
5011 fdevent_event_del(srv->ev, &(hctx->fde_ndx), hctx->fd);
5012 fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
5016 return HANDLER_WAIT_FOR_EVENT;
5017 - case PROXY_STATE_READ:
5018 + case PROXY_STATE_RESPONSE_HEADER:
5019 /* waiting for a response */
5021 return HANDLER_WAIT_FOR_EVENT;
5023 log_error_write(srv, __FILE__, __LINE__, "s", "(debug) unknown state");
5024 @@ -854,15 +804,14 @@
5025 return HANDLER_GO_ON;
5030 static int mod_proxy_patch_connection(server *srv, connection *con, plugin_data *p) {
5032 plugin_config *s = p->config_storage[0];
5034 - PATCH(extensions);
5037 + PATCH_OPTION(extensions);
5038 + PATCH_OPTION(debug);
5039 + PATCH_OPTION(balance);
5040 + PATCH_OPTION(last_used_backends);
5042 /* skip the first, the global context */
5043 for (i = 1; i < srv->config_context->used; i++) {
5044 @@ -877,18 +826,18 @@
5045 data_unset *du = dc->value->data[j];
5047 if (buffer_is_equal_string(du->key, CONST_STR_LEN("proxy.server"))) {
5048 - PATCH(extensions);
5049 + PATCH_OPTION(extensions);
5050 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("proxy.debug"))) {
5052 + PATCH_OPTION(debug);
5053 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("proxy.balance"))) {
5055 + PATCH_OPTION(balance);
5056 + PATCH_OPTION(last_used_backends);
5065 SUBREQUEST_FUNC(mod_proxy_handle_subrequest) {
5066 plugin_data *p = p_d;
5070 if ((revents & FDEVENT_IN) &&
5071 - hctx->state == PROXY_STATE_READ) {
5072 + (hctx->state == PROXY_STATE_RESPONSE_HEADER ||
5073 + hctx->state == PROXY_STATE_RESPONSE_CONTENT)) {
5075 if (p->conf.debug) {
5076 log_error_write(srv, __FILE__, __LINE__, "sd",
5077 @@ -1058,6 +1008,11 @@
5079 data_array *extension = NULL;
5080 size_t path_info_offset;
5081 + data_integer *last_used_backend;
5082 + data_proxy *host = NULL;
5083 + handler_ctx *hctx = NULL;
5085 + array *backends = NULL;
5087 /* Possibly, we processed already this request */
5088 if (con->file_started == 1) return HANDLER_GO_ON;
5089 @@ -1111,6 +1066,8 @@
5090 return HANDLER_GO_ON;
5093 + backends = extension->value;
5095 if (p->conf.debug) {
5096 log_error_write(srv, __FILE__, __LINE__, "s", "proxy - ext found");
5098 @@ -1121,33 +1078,33 @@
5100 if (p->conf.debug) {
5101 log_error_write(srv, __FILE__, __LINE__, "sd",
5102 - "proxy - used hash balancing, hosts:", extension->value->used);
5103 + "proxy - used hash balancing, hosts:", backends->used);
5106 - for (k = 0, ndx = -1, last_max = ULONG_MAX; k < extension->value->used; k++) {
5107 - data_proxy *host = (data_proxy *)extension->value->data[k];
5108 + for (k = 0, ndx = -1, last_max = ULONG_MAX; k < backends->used; k++) {
5109 unsigned long cur_max;
5111 - if (host->is_disabled) continue;
5112 + data_proxy *cur = (data_proxy *)backends->data[k];
5114 + if (cur->is_disabled) continue;
5116 cur_max = generate_crc32c(CONST_BUF_LEN(con->uri.path)) +
5117 - generate_crc32c(CONST_BUF_LEN(host->host)) + /* we can cache this */
5118 + generate_crc32c(CONST_BUF_LEN(cur->host)) + /* we can cache this */
5119 generate_crc32c(CONST_BUF_LEN(con->uri.authority));
5121 if (p->conf.debug) {
5122 log_error_write(srv, __FILE__, __LINE__, "sbbbd",
5123 "proxy - election:",
5131 - if ((last_max == ULONG_MAX) || /* first round */
5132 - (cur_max > last_max)) {
5133 + if (host == NULL || (cur_max > last_max)) {
5141 @@ -1159,15 +1116,16 @@
5142 "proxy - used fair balancing");
5145 - for (k = 0, ndx = -1, max_usage = INT_MAX; k < extension->value->used; k++) {
5146 - data_proxy *host = (data_proxy *)extension->value->data[k];
5147 + /* try to find the host with the lowest load */
5148 + for (k = 0, max_usage = 0; k < backends->used; k++) {
5149 + data_proxy *cur = (data_proxy *)backends->data[k];
5151 - if (host->is_disabled) continue;
5152 + if (cur->is_disabled) continue;
5154 - if (host->usage < max_usage) {
5155 - max_usage = host->usage;
5156 + if (NULL == host || cur->usage < max_usage) {
5157 + max_usage = cur->usage;
5164 @@ -1180,30 +1138,50 @@
5167 /* just to be sure */
5168 - assert(extension->value->used < INT_MAX);
5169 + assert(backends->used < INT_MAX);
5171 + /* send each request to another host:
5175 + * if we have three hosts it is
5177 + * 1 .. 2 .. 3 .. 1 .. 2 .. 3
5181 + /* walk through the list */
5182 + last_used_backend = (data_integer *)array_get_element(p->conf.last_used_backends, extension->key->ptr);
5184 - for (k = 0, ndx = -1, max_usage = INT_MAX; k < extension->value->used; k++) {
5185 - data_proxy *host = (data_proxy *)extension->value->data[k];
5186 + if (NULL == last_used_backend) {
5187 + last_used_backend = data_integer_init();
5189 - if (host->is_disabled) continue;
5190 + buffer_copy_string_buffer(last_used_backend->key, extension->key);
5191 + last_used_backend->value = 0;
5193 - /* first usable ndx */
5194 - if (max_usage == INT_MAX) {
5196 + array_insert_unique(p->conf.last_used_backends, (data_unset *)last_used_backend);
5199 - /* get next ndx */
5200 - if ((int)k > host->last_used_ndx) {
5202 - host->last_used_ndx = k;
5203 + /* scan all but the last host to see if they are up
5204 + * take the first running host */
5205 + for (k = last_used_backend->value + 1; (int)(k % backends->used) != last_used_backend->value; k++) {
5206 + data_proxy *cur = (data_proxy *)backends->data[k % backends->used];
5208 + if (cur->is_disabled) continue;
5212 + last_used_backend->value = k;
5218 - /* didn't found a higher id, wrap to the start */
5219 - if (ndx != -1 && max_usage != INT_MAX) {
5221 + if (NULL == host) {
5222 + /* we found nothing better, fallback to the last used backend
5223 + * and check if it is still up */
5224 + host = (data_proxy *)backends->data[last_used_backend->value];
5226 + if (host->is_disabled) host = NULL;
5230 @@ -1211,17 +1189,18 @@
5234 - /* found a server */
5236 - data_proxy *host = (data_proxy *)extension->value->data[ndx];
5237 + /* we havn't found a host */
5238 + if (NULL == host) {
5239 + con->http_status = 500;
5242 - * if check-local is disabled, use the uri.path handler
5245 + log_error_write(srv, __FILE__, __LINE__, "sb",
5246 + "no proxy-handler found for:",
5249 + return HANDLER_FINISHED;
5252 /* init handler-context */
5253 - handler_ctx *hctx;
5254 hctx = handler_ctx_init();
5256 hctx->path_info_offset = path_info_offset;
5257 @@ -1233,6 +1212,7 @@
5261 + /* we handle this request */
5264 if (p->conf.debug) {
5265 @@ -1242,17 +1222,6 @@
5268 return HANDLER_GO_ON;
5270 - /* no handler found */
5271 - con->http_status = 500;
5273 - log_error_write(srv, __FILE__, __LINE__, "sb",
5274 - "no proxy-handler found for:",
5277 - return HANDLER_FINISHED;
5279 - return HANDLER_GO_ON;
5282 static handler_t mod_proxy_connection_close_callback(server *srv, connection *con, void *p_d) {
5283 --- lighttpd-1.4.11/src/mod_redirect.c 2006-02-08 15:38:06.000000000 +0200
5284 +++ lighttpd/src/mod_redirect.c 2006-07-11 21:23:40.111856730 +0300
5286 static handler_t mod_redirect_uri_handler(server *srv, connection *con, void *p_data) {
5288 plugin_data *p = p_data;
5294 @@ -178,70 +178,9 @@
5295 mod_redirect_patch_connection(srv, con, p);
5297 buffer_copy_string_buffer(p->match_buf, con->request.uri);
5298 + i = config_exec_pcre_keyvalue_buffer(con, p->conf.redirect, p->conf.context, p->match_buf, p->location);
5300 - for (i = 0; i < p->conf.redirect->used; i++) {
5302 - pcre_extra *extra;
5303 - const char *pattern;
5304 - size_t pattern_len;
5306 - pcre_keyvalue *kv = p->conf.redirect->kv[i];
5311 - extra = kv->key_extra;
5312 - pattern = kv->value->ptr;
5313 - pattern_len = kv->value->used - 1;
5315 - if ((n = pcre_exec(match, extra, p->match_buf->ptr, p->match_buf->used - 1, 0, 0, ovec, 3 * N)) < 0) {
5316 - if (n != PCRE_ERROR_NOMATCH) {
5317 - log_error_write(srv, __FILE__, __LINE__, "sd",
5318 - "execution error while matching: ", n);
5319 - return HANDLER_ERROR;
5322 - const char **list;
5323 - size_t start, end;
5327 - pcre_get_substring_list(p->match_buf->ptr, ovec, n, &list);
5329 - /* search for $[0-9] */
5331 - buffer_reset(p->location);
5333 - start = 0; end = pattern_len;
5334 - for (k = 0; k < pattern_len; k++) {
5335 - if ((pattern[k] == '$' || pattern[k] == '%') &&
5336 - isdigit((unsigned char)pattern[k + 1])) {
5339 - size_t num = pattern[k + 1] - '0';
5343 - buffer_append_string_len(p->location, pattern + start, end - start);
5345 - if (pattern[k] == '$') {
5346 - /* n is always > 0 */
5347 - if (num < (size_t)n) {
5348 - buffer_append_string(p->location, list[num]);
5351 - config_append_cond_match_buffer(con, p->conf.context, p->location, num);
5359 - buffer_append_string_len(p->location, pattern + start, pattern_len - start);
5364 response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->location));
5366 con->http_status = 301;
5369 return HANDLER_FINISHED;
5371 + else if (i != PCRE_ERROR_NOMATCH) {
5372 + log_error_write(srv, __FILE__, __LINE__, "s",
5373 + "execution error while matching", i);
5377 --- lighttpd-1.4.11/src/mod_rewrite.c 2005-09-29 20:59:10.000000000 +0300
5378 +++ lighttpd/src/mod_rewrite.c 2006-07-11 21:23:39.947846458 +0300
5393 - rewrite_rule **ptr;
5397 -} rewrite_rule_buffer;
5400 - rewrite_rule_buffer *rewrite;
5401 + pcre_keyvalue_buffer *rewrite;
5403 data_config *context; /* to which apply me */
5410 -rewrite_rule_buffer *rewrite_rule_buffer_init(void) {
5411 - rewrite_rule_buffer *kvb;
5413 - kvb = calloc(1, sizeof(*kvb));
5418 -int rewrite_rule_buffer_append(rewrite_rule_buffer *kvb, buffer *key, buffer *value, int once) {
5421 - const char *errptr;
5424 - if (!key) return -1;
5426 - if (kvb->size == 0) {
5430 - kvb->ptr = malloc(kvb->size * sizeof(*kvb->ptr));
5432 - for(i = 0; i < kvb->size; i++) {
5433 - kvb->ptr[i] = calloc(1, sizeof(**kvb->ptr));
5435 - } else if (kvb->used == kvb->size) {
5438 - kvb->ptr = realloc(kvb->ptr, kvb->size * sizeof(*kvb->ptr));
5440 - for(i = kvb->used; i < kvb->size; i++) {
5441 - kvb->ptr[i] = calloc(1, sizeof(**kvb->ptr));
5445 - if (NULL == (kvb->ptr[kvb->used]->key = pcre_compile(key->ptr,
5446 - 0, &errptr, &erroff, NULL))) {
5451 - kvb->ptr[kvb->used]->value = buffer_init();
5452 - buffer_copy_string_buffer(kvb->ptr[kvb->used]->value, value);
5453 - kvb->ptr[kvb->used]->once = once;
5468 -void rewrite_rule_buffer_free(rewrite_rule_buffer *kvb) {
5472 - for (i = 0; i < kvb->size; i++) {
5473 - if (kvb->ptr[i]->key) pcre_free(kvb->ptr[i]->key);
5474 - if (kvb->ptr[i]->value) buffer_free(kvb->ptr[i]->value);
5475 - free(kvb->ptr[i]);
5478 - if (kvb->ptr) free(kvb->ptr);
5485 INIT_FUNC(mod_rewrite_init) {
5489 for (i = 0; i < srv->config_context->used; i++) {
5490 plugin_config *s = p->config_storage[i];
5491 - rewrite_rule_buffer_free(s->rewrite);
5492 + pcre_keyvalue_buffer_free(s->rewrite);
5493 + buffer_free(s->once);
5497 @@ -198,10 +109,9 @@
5498 return HANDLER_ERROR;
5501 - if (0 != rewrite_rule_buffer_append(s->rewrite,
5502 - ((data_string *)(da->value->data[j]))->key,
5503 - ((data_string *)(da->value->data[j]))->value,
5505 + if (0 != pcre_keyvalue_buffer_append(s->rewrite,
5506 + ((data_string *)(da->value->data[j]))->key->ptr,
5507 + ((data_string *)(da->value->data[j]))->value->ptr)) {
5509 log_error_write(srv, __FILE__, __LINE__, "sb",
5510 "pcre-compile failed for", da->value->data[j]->key);
5511 @@ -210,6 +120,12 @@
5512 "pcre support is missing, please install libpcre and the headers");
5517 + buffer_append_string_len(s->once, CONST_STR_LEN("1"));
5519 + buffer_append_string_len(s->once, CONST_STR_LEN("0"));
5524 @@ -245,11 +161,8 @@
5527 s = calloc(1, sizeof(plugin_config));
5528 - s->rewrite = rewrite_rule_buffer_init();
5530 - cv[0].destination = s->rewrite;
5531 - cv[1].destination = s->rewrite;
5532 - cv[2].destination = s->rewrite;
5533 + s->rewrite = pcre_keyvalue_buffer_init();
5534 + s->once = buffer_init();
5536 p->config_storage[i] = s;
5537 ca = ((data_config *)srv->config_context->data[i])->value;
5540 plugin_config *s = p->config_storage[0];
5541 p->conf.rewrite = s->rewrite;
5542 + p->conf.once = s->once;
5544 /* skip the first, the global context */
5545 for (i = 1; i < srv->config_context->used; i++) {
5546 @@ -288,15 +202,19 @@
5548 if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.rewrite"))) {
5549 p->conf.rewrite = s->rewrite;
5550 + p->conf.once = s->once;
5551 p->conf.context = dc;
5552 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.rewrite-once"))) {
5553 p->conf.rewrite = s->rewrite;
5554 + p->conf.once = s->once;
5555 p->conf.context = dc;
5556 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.rewrite-repeat"))) {
5557 p->conf.rewrite = s->rewrite;
5558 + p->conf.once = s->once;
5559 p->conf.context = dc;
5560 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("url.rewrite-final"))) {
5561 p->conf.rewrite = s->rewrite;
5562 + p->conf.once = s->once;
5563 p->conf.context = dc;
5567 URIHANDLER_FUNC(mod_rewrite_uri_handler) {
5569 plugin_data *p = p_d;
5575 @@ -349,76 +267,21 @@
5576 if (!p->conf.rewrite) return HANDLER_GO_ON;
5578 buffer_copy_string_buffer(p->match_buf, con->request.uri);
5579 + i = config_exec_pcre_keyvalue_buffer(con, p->conf.rewrite, p->conf.context, p->match_buf, con->request.uri);
5581 - for (i = 0; i < p->conf.rewrite->used; i++) {
5583 - const char *pattern;
5584 - size_t pattern_len;
5586 - rewrite_rule *rule = p->conf.rewrite->ptr[i];
5590 - match = rule->key;
5591 - pattern = rule->value->ptr;
5592 - pattern_len = rule->value->used - 1;
5594 - if ((n = pcre_exec(match, NULL, p->match_buf->ptr, p->match_buf->used - 1, 0, 0, ovec, 3 * N)) < 0) {
5595 - if (n != PCRE_ERROR_NOMATCH) {
5596 - log_error_write(srv, __FILE__, __LINE__, "sd",
5597 - "execution error while matching: ", n);
5598 - return HANDLER_ERROR;
5601 - const char **list;
5602 - size_t start, end;
5606 - pcre_get_substring_list(p->match_buf->ptr, ovec, n, &list);
5608 - /* search for $[0-9] */
5610 - buffer_reset(con->request.uri);
5612 - start = 0; end = pattern_len;
5613 - for (k = 0; k < pattern_len; k++) {
5614 - if ((pattern[k] == '$' || pattern[k] == '%') &&
5615 - isdigit((unsigned char)pattern[k + 1])) {
5618 - size_t num = pattern[k + 1] - '0';
5622 - buffer_append_string_len(con->request.uri, pattern + start, end - start);
5624 - if (pattern[k] == '$') {
5625 - /* n is always > 0 */
5626 - if (num < (size_t)n) {
5627 - buffer_append_string(con->request.uri, list[num]);
5630 - config_append_cond_match_buffer(con, p->conf.context, con->request.uri, num);
5638 - buffer_append_string_len(con->request.uri, pattern + start, pattern_len - start);
5643 hctx = handler_ctx_init();
5645 con->plugin_ctx[p->id] = hctx;
5647 - if (rule->once) hctx->state = REWRITE_STATE_FINISHED;
5648 + if (p->conf.once->ptr[i] == '1')
5649 + hctx->state = REWRITE_STATE_FINISHED;
5651 return HANDLER_COMEBACK;
5653 + else if (i != PCRE_ERROR_NOMATCH) {
5654 + log_error_write(srv, __FILE__, __LINE__, "s",
5655 + "execution error while matching", i);
5659 --- lighttpd-1.4.11/src/mod_rrdtool.c 2005-08-22 01:52:24.000000000 +0300
5660 +++ lighttpd/src/mod_rrdtool.c 2006-07-11 21:23:40.059853473 +0300
5665 -#include <unistd.h>
5670 /* no need for waitpid if we don't have fork */
5671 #include <sys/wait.h>
5674 +#include "sys-files.h"
5675 +#include "sys-process.h"
5678 buffer *path_rrdtool_bin;
5680 @@ -250,14 +253,12 @@
5681 return HANDLER_GO_ON;
5686 static int mod_rrd_patch_connection(server *srv, connection *con, plugin_data *p) {
5688 plugin_config *s = p->config_storage[0];
5690 - PATCH(path_rrdtool_bin);
5692 + PATCH_OPTION(path_rrdtool_bin);
5693 + PATCH_OPTION(path_rrd);
5695 p->conf.bytes_written_ptr = &(s->bytes_written);
5696 p->conf.bytes_read_ptr = &(s->bytes_read);
5698 data_unset *du = dc->value->data[j];
5700 if (buffer_is_equal_string(du->key, CONST_STR_LEN("rrdtool.db-name"))) {
5702 + PATCH_OPTION(path_rrd);
5703 /* get pointers to double values */
5705 p->conf.bytes_written_ptr = &(s->bytes_written);
5712 SETDEFAULTS_FUNC(mod_rrd_set_defaults) {
5713 plugin_data *p = p_d;
5714 --- lighttpd-1.4.11/src/mod_scgi.c 2006-03-04 17:15:26.000000000 +0200
5715 +++ lighttpd/src/mod_scgi.c 2006-07-11 21:23:40.023851218 +0300
5717 #include <sys/types.h>
5718 -#include <unistd.h>
5725 #include "sys-socket.h"
5727 +#include "sys-files.h"
5728 +#include "sys-strings.h"
5729 +#include "sys-process.h"
5731 #ifndef UNIX_PATH_MAX
5732 # define UNIX_PATH_MAX 108
5735 pid_t pid; /* PID of the spawned process (0 if not spawned locally) */
5738 size_t load; /* number of requests waiting on this process */
5740 time_t last_used; /* see idle_timeout */
5743 int fd; /* fd to the scgi process */
5744 int fde_ndx; /* index into the fd-event buffer */
5750 host = ex->hosts[n];
5752 for (proc = host->first; proc; proc = proc->next) {
5754 if (proc->pid != 0) kill(proc->pid, SIGTERM);
5757 if (proc->is_local &&
5758 !buffer_is_empty(proc->socket)) {
5762 for (proc = host->unused_procs; proc; proc = proc->next) {
5764 if (proc->pid != 0) kill(proc->pid, SIGTERM);
5767 if (proc->is_local &&
5768 !buffer_is_empty(proc->socket)) {
5769 @@ -641,12 +644,8 @@
5770 scgi_addr_un.sun_family = AF_UNIX;
5771 strcpy(scgi_addr_un.sun_path, proc->socket->ptr);
5774 servlen = SUN_LEN(&scgi_addr_un);
5776 - /* stevens says: */
5777 - servlen = proc->socket->used + sizeof(scgi_addr_un.sun_family);
5780 socket_type = AF_UNIX;
5781 scgi_addr = (struct sockaddr *) &scgi_addr_un;
5783 @@ -1292,12 +1291,9 @@
5784 /* use the unix domain socket */
5785 scgi_addr_un.sun_family = AF_UNIX;
5786 strcpy(scgi_addr_un.sun_path, proc->socket->ptr);
5789 servlen = SUN_LEN(&scgi_addr_un);
5791 - /* stevens says: */
5792 - servlen = proc->socket->used + sizeof(scgi_addr_un.sun_family);
5795 scgi_addr = (struct sockaddr *) &scgi_addr_un;
5798 @@ -2058,6 +2054,7 @@
5801 if (proc->state == PROC_STATE_DIED_WAIT_FOR_PID) {
5803 switch(waitpid(proc->pid, &status, WNOHANG)) {
5805 /* child is still alive */
5806 @@ -2084,6 +2081,7 @@
5807 proc->state = PROC_STATE_DIED;
5814 @@ -2271,10 +2269,11 @@
5816 if (hctx->wb->bytes_out == 0 &&
5817 hctx->reconnects < 5) {
5819 usleep(10000); /* take away the load of the webserver
5820 * to let the php a chance to restart
5824 scgi_reconnect(srv, hctx);
5826 return HANDLER_WAIT_FOR_FD;
5827 @@ -2286,7 +2285,7 @@
5831 - log_error_write(srv, __FILE__, __LINE__, "ssdsd",
5832 + log_error_write(srv, __FILE__, __LINE__, "ssosd",
5833 "[REPORT ME] connection was dropped after accept(). reconnect() denied:",
5834 "write-offset:", hctx->wb->bytes_out,
5835 "reconnect attempts:", hctx->reconnects);
5836 @@ -2479,7 +2478,7 @@
5839 /* only fetch the zombie if it is not already done */
5842 switch(waitpid(proc->pid, &status, WNOHANG)) {
5844 /* child is still alive */
5845 @@ -2519,6 +2518,7 @@
5852 if (con->file_started == 0) {
5853 @@ -2536,7 +2536,7 @@
5854 return HANDLER_WAIT_FOR_FD;
5857 - log_error_write(srv, __FILE__, __LINE__, "sdsdsd",
5858 + log_error_write(srv, __FILE__, __LINE__, "sosdsd",
5859 "response not sent, request sent:", hctx->wb->bytes_out,
5860 "connection-fd:", con->fd,
5861 "fcgi-fd:", hctx->fd);
5862 @@ -2631,14 +2631,13 @@
5864 return HANDLER_FINISHED;
5869 static int scgi_patch_connection(server *srv, connection *con, plugin_data *p) {
5871 plugin_config *s = p->config_storage[0];
5875 + PATCH_OPTION(exts);
5876 + PATCH_OPTION(debug);
5878 /* skip the first, the global context */
5879 for (i = 1; i < srv->config_context->used; i++) {
5880 @@ -2653,17 +2652,15 @@
5881 data_unset *du = dc->value->data[j];
5883 if (buffer_is_equal_string(du->key, CONST_STR_LEN("scgi.server"))) {
5885 + PATCH_OPTION(exts);
5886 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("scgi.debug"))) {
5888 + PATCH_OPTION(debug);
5898 static handler_t scgi_check_extension(server *srv, connection *con, void *p_d, int uri_path_handler) {
5899 plugin_data *p = p_d;
5900 @@ -2971,7 +2968,7 @@
5901 if (proc->load != 0) break;
5902 if (host->num_procs <= host->min_procs) break;
5903 if (proc->pid == 0) continue;
5906 if (srv->cur_ts - proc->last_used > host->idle_timeout) {
5907 /* a proc is idling for a long time now,
5909 @@ -3009,13 +3006,14 @@
5910 /* proc is now in unused, let the next second handle the next process */
5916 for (proc = host->unused_procs; proc; proc = proc->next) {
5919 if (proc->pid == 0) continue;
5922 switch (waitpid(proc->pid, &status, WNOHANG)) {
5924 /* child still running after timeout, good */
5925 @@ -3059,6 +3057,7 @@
5926 proc->state = PROC_STATE_UNSET;
5933 --- lighttpd-1.4.11/src/mod_secure_download.c 2005-12-14 14:37:29.000000000 +0200
5934 +++ lighttpd/src/mod_secure_download.c 2006-07-11 21:23:39.935845706 +0300
5935 @@ -156,16 +156,14 @@
5941 static int mod_secdownload_patch_connection(server *srv, connection *con, plugin_data *p) {
5943 plugin_config *s = p->config_storage[0];
5947 - PATCH(uri_prefix);
5949 + PATCH_OPTION(secret);
5950 + PATCH_OPTION(doc_root);
5951 + PATCH_OPTION(uri_prefix);
5952 + PATCH_OPTION(timeout);
5954 /* skip the first, the global context */
5955 for (i = 1; i < srv->config_context->used; i++) {
5956 @@ -180,21 +178,19 @@
5957 data_unset *du = dc->value->data[j];
5959 if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.secret"))) {
5961 + PATCH_OPTION(secret);
5962 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.document-root"))) {
5964 + PATCH_OPTION(doc_root);
5965 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.uri-prefix"))) {
5966 - PATCH(uri_prefix);
5967 + PATCH_OPTION(uri_prefix);
5968 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.timeout"))) {
5970 + PATCH_OPTION(timeout);
5980 URIHANDLER_FUNC(mod_secdownload_uri_handler) {
5981 plugin_data *p = p_d;
5982 --- lighttpd-1.4.11/src/mod_setenv.c 2006-01-14 20:33:12.000000000 +0200
5983 +++ lighttpd/src/mod_setenv.c 2006-07-11 21:23:40.191861741 +0300
5984 @@ -120,15 +120,13 @@
5985 return HANDLER_GO_ON;
5990 static int mod_setenv_patch_connection(server *srv, connection *con, plugin_data *p) {
5992 plugin_config *s = p->config_storage[0];
5994 - PATCH(request_header);
5995 - PATCH(response_header);
5996 - PATCH(environment);
5997 + PATCH_OPTION(request_header);
5998 + PATCH_OPTION(response_header);
5999 + PATCH_OPTION(environment);
6001 /* skip the first, the global context */
6002 for (i = 1; i < srv->config_context->used; i++) {
6003 @@ -143,18 +141,17 @@
6004 data_unset *du = dc->value->data[j];
6006 if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-request-header"))) {
6007 - PATCH(request_header);
6008 + PATCH_OPTION(request_header);
6009 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-response-header"))) {
6010 - PATCH(response_header);
6011 + PATCH_OPTION(response_header);
6012 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-environment"))) {
6013 - PATCH(environment);
6014 + PATCH_OPTION(environment);
6023 URIHANDLER_FUNC(mod_setenv_uri_handler) {
6024 plugin_data *p = p_d;
6025 --- lighttpd-1.4.11/src/mod_simple_vhost.c 2005-11-18 15:16:13.000000000 +0200
6026 +++ lighttpd/src/mod_simple_vhost.c 2006-07-11 21:23:40.087855227 +0300
6031 +#include "sys-files.h"
6033 #ifdef HAVE_CONFIG_H
6040 - BUFFER_APPEND_SLASH(out);
6041 + PATHNAME_APPEND_SLASH(out);
6043 if (NULL == (dp = strchr(host->ptr, ':'))) {
6044 buffer_append_string_buffer(out, host);
6045 @@ -147,17 +149,17 @@
6046 buffer_append_string_len(out, host->ptr, dp - host->ptr);
6049 - BUFFER_APPEND_SLASH(out);
6050 + PATHNAME_APPEND_SLASH(out);
6052 if (p->conf.document_root->used > 2 && p->conf.document_root->ptr[0] == '/') {
6053 buffer_append_string_len(out, p->conf.document_root->ptr + 1, p->conf.document_root->used - 2);
6055 buffer_append_string_buffer(out, p->conf.document_root);
6056 - BUFFER_APPEND_SLASH(out);
6057 + PATHNAME_APPEND_SLASH(out);
6060 buffer_copy_string_buffer(out, con->conf.document_root);
6061 - BUFFER_APPEND_SLASH(out);
6062 + PATHNAME_APPEND_SLASH(out);
6065 if (HANDLER_ERROR == stat_cache_get_entry(srv, con, out, &sce)) {
6066 @@ -173,22 +175,19 @@
6073 static int mod_simple_vhost_patch_connection(server *srv, connection *con, plugin_data *p) {
6075 plugin_config *s = p->config_storage[0];
6077 - PATCH(server_root);
6078 - PATCH(default_host);
6079 - PATCH(document_root);
6081 - PATCH(docroot_cache_key);
6082 - PATCH(docroot_cache_value);
6083 - PATCH(docroot_cache_servername);
6084 + PATCH_OPTION(server_root);
6085 + PATCH_OPTION(default_host);
6086 + PATCH_OPTION(document_root);
6088 + PATCH_OPTION(docroot_cache_key);
6089 + PATCH_OPTION(docroot_cache_value);
6090 + PATCH_OPTION(docroot_cache_servername);
6093 + PATCH_OPTION(debug);
6095 /* skip the first, the global context */
6096 for (i = 1; i < srv->config_context->used; i++) {
6097 @@ -203,23 +202,22 @@
6098 data_unset *du = dc->value->data[j];
6100 if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.server-root"))) {
6101 - PATCH(server_root);
6102 - PATCH(docroot_cache_key);
6103 - PATCH(docroot_cache_value);
6104 - PATCH(docroot_cache_servername);
6105 + PATCH_OPTION(server_root);
6106 + PATCH_OPTION(docroot_cache_key);
6107 + PATCH_OPTION(docroot_cache_value);
6108 + PATCH_OPTION(docroot_cache_servername);
6109 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.default-host"))) {
6110 - PATCH(default_host);
6111 + PATCH_OPTION(default_host);
6112 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.document-root"))) {
6113 - PATCH(document_root);
6114 + PATCH_OPTION(document_root);
6115 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.debug"))) {
6117 + PATCH_OPTION(debug);
6126 static handler_t mod_simple_vhost_docroot(server *srv, connection *con, void *p_data) {
6127 plugin_data *p = p_data;
6128 --- lighttpd-1.4.11/src/mod_skeleton.c 2005-10-02 18:30:51.000000000 +0300
6129 +++ lighttpd/src/mod_skeleton.c 2006-07-11 21:23:40.019850968 +0300
6130 @@ -132,13 +132,11 @@
6131 return HANDLER_GO_ON;
6136 static int mod_skeleton_patch_connection(server *srv, connection *con, plugin_data *p) {
6138 plugin_config *s = p->config_storage[0];
6141 + PATCH_OPTION(match);
6143 /* skip the first, the global context */
6144 for (i = 1; i < srv->config_context->used; i++) {
6145 @@ -153,14 +151,13 @@
6146 data_unset *du = dc->value->data[j];
6148 if (buffer_is_equal_string(du->key, CONST_STR_LEN("skeleton.array"))) {
6150 + PATCH_OPTION(match);
6159 URIHANDLER_FUNC(mod_skeleton_uri_handler) {
6160 plugin_data *p = p_d;
6161 --- lighttpd-1.4.11/src/mod_ssi.c 2006-03-04 17:09:48.000000000 +0200
6162 +++ lighttpd/src/mod_ssi.c 2006-07-11 21:23:40.159859737 +0300
6167 -#include <unistd.h>
6172 #include "inet_ntop_cache.h"
6174 #include "sys-socket.h"
6175 +#include "sys-strings.h"
6176 +#include "sys-files.h"
6186 const char *cmd = NULL;
6188 int from_exec_fds[2];
6195 if (pipe(from_exec_fds)) {
6196 log_error_write(srv, __FILE__, __LINE__, "ss",
6197 "pipe failed: ", strerror(errno));
6206 @@ -1008,13 +1010,11 @@
6212 static int mod_ssi_patch_connection(server *srv, connection *con, plugin_data *p) {
6214 plugin_config *s = p->config_storage[0];
6216 - PATCH(ssi_extension);
6217 + PATCH_OPTION(ssi_extension);
6219 /* skip the first, the global context */
6220 for (i = 1; i < srv->config_context->used; i++) {
6221 @@ -1029,14 +1029,13 @@
6222 data_unset *du = dc->value->data[j];
6224 if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.extension"))) {
6225 - PATCH(ssi_extension);
6226 + PATCH_OPTION(ssi_extension);
6235 URIHANDLER_FUNC(mod_ssi_physical_path) {
6236 plugin_data *p = p_d;
6237 --- lighttpd-1.4.11/src/mod_staticfile.c 2006-02-15 14:31:14.000000000 +0200
6238 +++ lighttpd/src/mod_staticfile.c 2006-07-11 21:23:39.979848462 +0300
6240 #include "http_chunk.h"
6241 #include "response.h"
6243 +#include "sys-files.h"
6244 +#include "sys-strings.h"
6246 * this is a staticfile for a lighttpd plugin
6252 -/* detroy the plugin data */
6253 +/* destroy the plugin data */
6254 FREE_FUNC(mod_staticfile_free) {
6255 plugin_data *p = p_d;
6257 @@ -107,13 +109,11 @@
6258 return HANDLER_GO_ON;
6263 static int mod_staticfile_patch_connection(server *srv, connection *con, plugin_data *p) {
6265 plugin_config *s = p->config_storage[0];
6267 - PATCH(exclude_ext);
6268 + PATCH_OPTION(exclude_ext);
6270 /* skip the first, the global context */
6271 for (i = 1; i < srv->config_context->used; i++) {
6272 @@ -128,14 +128,13 @@
6273 data_unset *du = dc->value->data[j];
6275 if (buffer_is_equal_string(du->key, CONST_STR_LEN("static-file.exclude-extensions"))) {
6276 - PATCH(exclude_ext);
6277 + PATCH_OPTION(exclude_ext);
6286 static int http_response_parse_range(server *srv, connection *con, plugin_data *p) {
6289 return HANDLER_FINISHED;
6292 - /* we only handline regular files */
6293 + /* we only handle regular files */
6294 if (!S_ISREG(sce->st.st_mode)) {
6295 con->http_status = 404;
6298 return HANDLER_FINISHED;
6301 - /* mod_compress might set several data directly, don't overwrite them */
6302 + /* mod_compress might set several parameters directly; don't overwrite them */
6304 /* set response content-type, if not set already */
6306 --- lighttpd-1.4.11/src/mod_status.c 2006-01-10 21:45:32.000000000 +0200
6307 +++ lighttpd/src/mod_status.c 2006-07-11 21:23:40.131857983 +0300
6312 -#include <unistd.h>
6319 char multiplier = '\0';
6324 int days, hours, mins, seconds;
6325 @@ -304,13 +303,13 @@
6326 /* connection listing */
6327 BUFFER_APPEND_STRING_CONST(b, "<h1>Server-Status</h1>");
6329 - BUFFER_APPEND_STRING_CONST(b, "<table class=\"status\">");
6330 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Hostname</td><td class=\"string\">");
6331 + BUFFER_APPEND_STRING_CONST(b, "<table class=\"status\" id=\"status\" summary=\"Server Status\">");
6332 + BUFFER_APPEND_STRING_CONST(b, "<tr><td>Hostname</td><td class=\"string\"><span id=\"host_addr\">");
6333 buffer_append_string_buffer(b, con->uri.authority);
6334 - BUFFER_APPEND_STRING_CONST(b, " (");
6335 + BUFFER_APPEND_STRING_CONST(b, "</span> (<span id=\"host_name\">");
6336 buffer_append_string_buffer(b, con->server_name);
6337 - BUFFER_APPEND_STRING_CONST(b, ")</td></tr>\n");
6338 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Uptime</td><td class=\"string\">");
6339 + BUFFER_APPEND_STRING_CONST(b, "</span>)</td></tr>\n");
6340 + BUFFER_APPEND_STRING_CONST(b, "<tr><td>Uptime</td><td class=\"string\" id=\"uptime\">");
6342 ts = srv->cur_ts - srv->startup_ts;
6344 @@ -348,58 +347,58 @@
6346 ts = srv->startup_ts;
6348 - strftime(buf, sizeof(buf) - 1, "%Y-%m-%d %H:%M:%S", localtime(&ts));
6349 + strftime(buf, sizeof(buf) - 1, "<span id=\"start_date\">%Y-%m-%d</span> <span id=\"start_time\">%H:%M:%S</span>", localtime(&ts));
6350 buffer_append_string(b, buf);
6351 BUFFER_APPEND_STRING_CONST(b, "</td></tr>\n");
6354 BUFFER_APPEND_STRING_CONST(b, "<tr><th colspan=\"2\">absolute (since start)</th></tr>\n");
6356 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\">");
6357 + BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\" ><span id=\"requests\">");
6358 avg = p->abs_requests;
6360 mod_status_get_multiplier(&avg, &multiplier, 1000);
6362 buffer_append_long(b, avg);
6363 - BUFFER_APPEND_STRING_CONST(b, " ");
6364 + BUFFER_APPEND_STRING_CONST(b, "</span> <span id=\"requests_mult\">");
6365 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
6366 - BUFFER_APPEND_STRING_CONST(b, "req</td></tr>\n");
6367 + BUFFER_APPEND_STRING_CONST(b, "</span>req</td></tr>\n");
6369 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\">");
6370 + BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\"><span id=\"traffic\">");
6371 avg = p->abs_traffic_out;
6373 mod_status_get_multiplier(&avg, &multiplier, 1024);
6375 sprintf(buf, "%.2f", avg);
6376 buffer_append_string(b, buf);
6377 - BUFFER_APPEND_STRING_CONST(b, " ");
6378 + BUFFER_APPEND_STRING_CONST(b, "</span> <span id=\"traffic_mult\">");
6379 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
6380 - BUFFER_APPEND_STRING_CONST(b, "byte</td></tr>\n");
6381 + BUFFER_APPEND_STRING_CONST(b, "</span>byte</td></tr>\n");
6385 BUFFER_APPEND_STRING_CONST(b, "<tr><th colspan=\"2\">average (since start)</th></tr>\n");
6387 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\">");
6388 + BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\"><span id=\"requests_avg\">");
6389 avg = p->abs_requests / (srv->cur_ts - srv->startup_ts);
6391 mod_status_get_multiplier(&avg, &multiplier, 1000);
6393 buffer_append_long(b, avg);
6394 - BUFFER_APPEND_STRING_CONST(b, " ");
6395 + BUFFER_APPEND_STRING_CONST(b, "</span> <span id=\"requests_avg_mult\">");
6396 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
6397 - BUFFER_APPEND_STRING_CONST(b, "req/s</td></tr>\n");
6398 + BUFFER_APPEND_STRING_CONST(b, "</span>req/s</td></tr>\n");
6400 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\">");
6401 + BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\"><span id=\"traffic_avg\">");
6402 avg = p->abs_traffic_out / (srv->cur_ts - srv->startup_ts);
6404 mod_status_get_multiplier(&avg, &multiplier, 1024);
6406 sprintf(buf, "%.2f", avg);
6407 buffer_append_string(b, buf);
6408 - BUFFER_APPEND_STRING_CONST(b, " ");
6409 + BUFFER_APPEND_STRING_CONST(b, "</span> <span id=\"traffic_avg_mult\">");
6410 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
6411 - BUFFER_APPEND_STRING_CONST(b, "byte/s</td></tr>\n");
6412 + BUFFER_APPEND_STRING_CONST(b, "</span>byte/s</td></tr>\n");
6416 @@ -410,15 +409,15 @@
6420 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\">");
6421 + BUFFER_APPEND_STRING_CONST(b, "<tr><td>Requests</td><td class=\"string\"><span id=\"requests_sliding_avg\">");
6423 mod_status_get_multiplier(&avg, &multiplier, 1000);
6425 buffer_append_long(b, avg);
6426 - BUFFER_APPEND_STRING_CONST(b, " ");
6427 + BUFFER_APPEND_STRING_CONST(b, "</span> <span id=\"requests_sliding_avg_mult\">");
6428 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
6430 - BUFFER_APPEND_STRING_CONST(b, "req/s</td></tr>\n");
6431 + BUFFER_APPEND_STRING_CONST(b, "</span>req/s</td></tr>\n");
6433 for (j = 0, avg = 0; j < 5; j++) {
6434 avg += p->mod_5s_traffic_out[j];
6435 @@ -426,15 +425,15 @@
6439 - BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\">");
6440 + BUFFER_APPEND_STRING_CONST(b, "<tr><td>Traffic</td><td class=\"string\"><span id=\"requests_sliding_traffic\">");
6442 mod_status_get_multiplier(&avg, &multiplier, 1024);
6444 sprintf(buf, "%.2f", avg);
6445 buffer_append_string(b, buf);
6446 - BUFFER_APPEND_STRING_CONST(b, " ");
6447 + BUFFER_APPEND_STRING_CONST(b, "</span> <span id=\"requests_sliding_traffic_mult\">");
6448 if (multiplier) buffer_append_string_len(b, &multiplier, 1);
6449 - BUFFER_APPEND_STRING_CONST(b, "byte/s</td></tr>\n");
6450 + BUFFER_APPEND_STRING_CONST(b, "</span>byte/s</td></tr>\n");
6452 BUFFER_APPEND_STRING_CONST(b, "</table>\n");
6455 BUFFER_APPEND_STRING_CONST(b, "q = request-start, Q = request-end\n");
6456 BUFFER_APPEND_STRING_CONST(b, "s = response-start, S = response-end\n");
6458 - BUFFER_APPEND_STRING_CONST(b, "<b>");
6459 + BUFFER_APPEND_STRING_CONST(b, "<strong><span id=\"connections\">");
6460 buffer_append_long(b, srv->conns->used);
6461 - BUFFER_APPEND_STRING_CONST(b, " connections</b>\n");
6462 + BUFFER_APPEND_STRING_CONST(b, "</span> connections</strong>\n");
6464 for (j = 0; j < srv->conns->used; j++) {
6465 connection *c = srv->conns->ptr[j];
6468 BUFFER_APPEND_STRING_CONST(b, "\n</pre><hr />\n<h2>Connections</h2>\n");
6470 - BUFFER_APPEND_STRING_CONST(b, "<table class=\"status\">\n");
6471 + BUFFER_APPEND_STRING_CONST(b, "<table class=\"status\" summary=\"Current connections\" id=\"clients\">\n");
6472 BUFFER_APPEND_STRING_CONST(b, "<tr>");
6473 mod_status_header_append_sort(b, p_d, "Client IP");
6474 mod_status_header_append_sort(b, p_d, "Read");
6475 @@ -477,11 +476,11 @@
6476 for (j = 0; j < srv->conns->used; j++) {
6477 connection *c = srv->conns->ptr[j];
6479 - BUFFER_APPEND_STRING_CONST(b, "<tr><td class=\"string\">");
6480 + BUFFER_APPEND_STRING_CONST(b, "<tr><td class=\"string ip\">");
6482 buffer_append_string(b, inet_ntop_cache_get_ip(srv, &(c->dst_addr)));
6484 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
6485 + BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int bytes_read\">");
6487 if (con->request.content_length) {
6488 buffer_append_long(b, c->request_content_queue->bytes_in);
6489 @@ -491,21 +490,21 @@
6490 BUFFER_APPEND_STRING_CONST(b, "0/0");
6493 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
6494 + BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int bytes_written\">");
6496 buffer_append_off_t(b, chunkqueue_written(c->write_queue));
6497 BUFFER_APPEND_STRING_CONST(b, "/");
6498 buffer_append_off_t(b, chunkqueue_length(c->write_queue));
6500 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
6501 + BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string state\">");
6503 buffer_append_string(b, connection_get_state(c->state));
6505 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int\">");
6506 + BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"int time\">");
6508 buffer_append_long(b, srv->cur_ts - c->request_start);
6510 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
6511 + BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string host\">");
6513 if (buffer_is_empty(c->server_name)) {
6514 buffer_append_string_buffer(b, c->uri.authority);
6515 @@ -514,13 +513,13 @@
6516 buffer_append_string_buffer(b, c->server_name);
6519 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
6520 + BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string uri\">");
6522 if (!buffer_is_empty(c->uri.path)) {
6523 buffer_append_string_encoded(b, CONST_BUF_LEN(c->uri.path), ENCODING_HTML);
6526 - BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string\">");
6527 + BUFFER_APPEND_STRING_CONST(b, "</td><td class=\"string file\">");
6529 buffer_append_string_buffer(b, c->physical.path);
6531 @@ -723,16 +722,14 @@
6532 return HANDLER_FINISHED;
6537 static int mod_status_patch_connection(server *srv, connection *con, plugin_data *p) {
6539 plugin_config *s = p->config_storage[0];
6541 - PATCH(status_url);
6542 - PATCH(config_url);
6544 - PATCH(statistics_url);
6545 + PATCH_OPTION(status_url);
6546 + PATCH_OPTION(config_url);
6547 + PATCH_OPTION(sort);
6548 + PATCH_OPTION(statistics_url);
6550 /* skip the first, the global context */
6551 for (i = 1; i < srv->config_context->used; i++) {
6552 @@ -747,13 +744,13 @@
6553 data_unset *du = dc->value->data[j];
6555 if (buffer_is_equal_string(du->key, CONST_STR_LEN("status.status-url"))) {
6556 - PATCH(status_url);
6557 + PATCH_OPTION(status_url);
6558 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("status.config-url"))) {
6559 - PATCH(config_url);
6560 + PATCH_OPTION(config_url);
6561 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("status.enable-sort"))) {
6563 + PATCH_OPTION(sort);
6564 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("status.statistics-url"))) {
6565 - PATCH(statistics_url);
6566 + PATCH_OPTION(statistics_url);
6570 --- lighttpd-1.4.11/src/mod_trigger_b4_dl.c 2005-09-23 22:53:55.000000000 +0300
6571 +++ lighttpd/src/mod_trigger_b4_dl.c 2006-07-11 21:23:39.991849214 +0300
6572 @@ -241,25 +241,23 @@
6573 return HANDLER_GO_ON;
6578 static int mod_trigger_b4_dl_patch_connection(server *srv, connection *con, plugin_data *p) {
6580 plugin_config *s = p->config_storage[0];
6582 #if defined(HAVE_GDBM)
6586 #if defined(HAVE_PCRE_H)
6587 - PATCH(download_regex);
6588 - PATCH(trigger_regex);
6589 + PATCH_OPTION(download_regex);
6590 + PATCH_OPTION(trigger_regex);
6592 - PATCH(trigger_timeout);
6594 - PATCH(mc_namespace);
6596 + PATCH_OPTION(trigger_timeout);
6597 + PATCH_OPTION(deny_url);
6598 + PATCH_OPTION(mc_namespace);
6599 + PATCH_OPTION(debug);
6600 #if defined(HAVE_MEMCACHE_H)
6605 /* skip the first, the global context */
6606 @@ -276,27 +274,27 @@
6608 if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.download-url"))) {
6609 #if defined(HAVE_PCRE_H)
6610 - PATCH(download_regex);
6611 + PATCH_OPTION(download_regex);
6613 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.trigger-url"))) {
6614 # if defined(HAVE_PCRE_H)
6615 - PATCH(trigger_regex);
6616 + PATCH_OPTION(trigger_regex);
6618 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.gdbm-filename"))) {
6619 #if defined(HAVE_GDBM_H)
6623 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.trigger-timeout"))) {
6624 - PATCH(trigger_timeout);
6625 + PATCH_OPTION(trigger_timeout);
6626 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.debug"))) {
6628 + PATCH_OPTION(debug);
6629 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.deny-url"))) {
6631 + PATCH_OPTION(deny_url);
6632 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.memcache-namespace"))) {
6633 - PATCH(mc_namespace);
6634 + PATCH_OPTION(mc_namespace);
6635 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("trigger-before-download.memcache-hosts"))) {
6636 #if defined(HAVE_MEMCACHE_H)
6648 URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
6649 plugin_data *p = p_d;
6650 --- lighttpd-1.4.11/src/mod_userdir.c 2005-10-28 16:48:28.000000000 +0300
6651 +++ lighttpd/src/mod_userdir.c 2006-07-11 21:23:40.091855478 +0300
6653 #include "response.h"
6656 +#include "sys-files.h"
6660 @@ -118,16 +119,14 @@
6661 return HANDLER_GO_ON;
6666 static int mod_userdir_patch_connection(server *srv, connection *con, plugin_data *p) {
6668 plugin_config *s = p->config_storage[0];
6671 - PATCH(exclude_user);
6672 - PATCH(include_user);
6674 + PATCH_OPTION(path);
6675 + PATCH_OPTION(exclude_user);
6676 + PATCH_OPTION(include_user);
6677 + PATCH_OPTION(basepath);
6679 /* skip the first, the global context */
6680 for (i = 1; i < srv->config_context->used; i++) {
6681 @@ -142,20 +141,19 @@
6682 data_unset *du = dc->value->data[j];
6684 if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.path"))) {
6686 + PATCH_OPTION(path);
6687 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.exclude-user"))) {
6688 - PATCH(exclude_user);
6689 + PATCH_OPTION(exclude_user);
6690 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.include-user"))) {
6691 - PATCH(include_user);
6692 + PATCH_OPTION(include_user);
6693 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.basepath"))) {
6695 + PATCH_OPTION(basepath);
6704 URIHANDLER_FUNC(mod_userdir_docroot_handler) {
6705 plugin_data *p = p_d;
6706 @@ -252,10 +250,10 @@
6709 buffer_copy_string_buffer(p->temp_path, p->conf.basepath);
6710 - BUFFER_APPEND_SLASH(p->temp_path);
6711 + PATHNAME_APPEND_SLASH(p->temp_path);
6712 buffer_append_string_buffer(p->temp_path, p->username);
6714 - BUFFER_APPEND_SLASH(p->temp_path);
6715 + PATHNAME_APPEND_SLASH(p->temp_path);
6716 buffer_append_string_buffer(p->temp_path, p->conf.path);
6718 if (buffer_is_empty(p->conf.basepath)) {
6723 - BUFFER_APPEND_SLASH(p->temp_path);
6724 + PATHNAME_APPEND_SLASH(p->temp_path);
6725 buffer_append_string(p->temp_path, rel_url + 1); /* skip the / */
6726 buffer_copy_string_buffer(con->physical.path, p->temp_path);
6728 --- lighttpd-1.4.11/src/mod_usertrack.c 2006-01-31 15:01:20.000000000 +0200
6729 +++ lighttpd/src/mod_usertrack.c 2006-07-11 21:23:40.115856981 +0300
6730 @@ -136,15 +136,13 @@
6731 return HANDLER_GO_ON;
6736 static int mod_usertrack_patch_connection(server *srv, connection *con, plugin_data *p) {
6738 plugin_config *s = p->config_storage[0];
6740 - PATCH(cookie_name);
6741 - PATCH(cookie_domain);
6742 - PATCH(cookie_max_age);
6743 + PATCH_OPTION(cookie_name);
6744 + PATCH_OPTION(cookie_domain);
6745 + PATCH_OPTION(cookie_max_age);
6747 /* skip the first, the global context */
6748 for (i = 1; i < srv->config_context->used; i++) {
6749 @@ -159,18 +157,17 @@
6750 data_unset *du = dc->value->data[j];
6752 if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-name"))) {
6753 - PATCH(cookie_name);
6754 + PATCH_OPTION(cookie_name);
6755 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-max-age"))) {
6756 - PATCH(cookie_max_age);
6757 + PATCH_OPTION(cookie_max_age);
6758 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-domain"))) {
6759 - PATCH(cookie_domain);
6760 + PATCH_OPTION(cookie_domain);
6769 URIHANDLER_FUNC(mod_usertrack_uri_handler) {
6770 plugin_data *p = p_d;
6771 --- lighttpd-1.4.11/src/mod_webdav.c 2006-03-03 01:28:58.000000000 +0200
6772 +++ lighttpd/src/mod_webdav.c 2006-07-11 21:23:40.123857482 +0300
6777 -#include <dirent.h>
6779 -#include <unistd.h>
6783 -#include <sys/mman.h>
6785 #ifdef HAVE_CONFIG_H
6788 #include <sqlite3.h>
6791 +#if defined(HAVE_LIBXML_H) && defined(HAVE_SQLITE3_H) && defined(HAVE_UUID_H)
6793 +#include <uuid/uuid.h>
6801 #include "stat_cache.h"
6803 +#include "sys-files.h"
6804 +#include "sys-mmap.h"
6805 +#include "sys-strings.h"
6808 * this is a webdav for a lighttpd plugin
6810 sqlite3_stmt *stmt_delete_uri;
6811 sqlite3_stmt *stmt_move_uri;
6812 sqlite3_stmt *stmt_copy_uri;
6814 + sqlite3_stmt *stmt_remove_lock;
6815 + sqlite3_stmt *stmt_create_lock;
6816 + sqlite3_stmt *stmt_read_lock;
6817 + sqlite3_stmt *stmt_read_lock_by_uri;
6818 + sqlite3_stmt *stmt_refresh_lock;
6822 @@ -123,6 +134,12 @@
6823 sqlite3_finalize(s->stmt_update_prop);
6824 sqlite3_finalize(s->stmt_select_prop);
6825 sqlite3_finalize(s->stmt_select_propnames);
6827 + sqlite3_finalize(s->stmt_read_lock);
6828 + sqlite3_finalize(s->stmt_read_lock_by_uri);
6829 + sqlite3_finalize(s->stmt_create_lock);
6830 + sqlite3_finalize(s->stmt_remove_lock);
6831 + sqlite3_finalize(s->stmt_refresh_lock);
6832 sqlite3_close(s->sql);
6835 @@ -193,6 +210,24 @@
6836 return HANDLER_ERROR;
6839 + if (SQLITE_OK != sqlite3_exec(s->sql,
6840 + "CREATE TABLE properties ("
6841 + " resource TEXT NOT NULL,"
6842 + " prop TEXT NOT NULL,"
6843 + " ns TEXT NOT NULL,"
6844 + " value TEXT NOT NULL,"
6845 + " PRIMARY KEY(resource, prop, ns))",
6846 + NULL, NULL, &err)) {
6848 + if (0 != strcmp(err, "table properties already exists")) {
6849 + log_error_write(srv, __FILE__, __LINE__, "ss", "can't open transaction:", err);
6850 + sqlite3_free(err);
6852 + return HANDLER_ERROR;
6854 + sqlite3_free(err);
6857 if (SQLITE_OK != sqlite3_prepare(s->sql,
6858 CONST_STR_LEN("SELECT value FROM properties WHERE resource = ? AND prop = ? AND ns = ?"),
6859 &(s->stmt_select_prop), &next_stmt)) {
6860 @@ -211,23 +246,6 @@
6861 return HANDLER_ERROR;
6864 - if (SQLITE_OK != sqlite3_exec(s->sql,
6865 - "CREATE TABLE properties ("
6866 - " resource TEXT NOT NULL,"
6867 - " prop TEXT NOT NULL,"
6868 - " ns TEXT NOT NULL,"
6869 - " value TEXT NOT NULL,"
6870 - " PRIMARY KEY(resource, prop, ns))",
6871 - NULL, NULL, &err)) {
6873 - if (0 != strcmp(err, "table properties already exists")) {
6874 - log_error_write(srv, __FILE__, __LINE__, "ss", "can't open transaction:", err);
6875 - sqlite3_free(err);
6877 - return HANDLER_ERROR;
6879 - sqlite3_free(err);
6882 if (SQLITE_OK != sqlite3_prepare(s->sql,
6883 CONST_STR_LEN("REPLACE INTO properties (resource, prop, ns, value) VALUES (?, ?, ?, ?)"),
6884 @@ -273,6 +291,76 @@
6886 return HANDLER_ERROR;
6891 + if (SQLITE_OK != sqlite3_exec(s->sql,
6892 + "CREATE TABLE locks ("
6893 + " locktoken TEXT NOT NULL,"
6894 + " resource TEXT NOT NULL,"
6895 + " lockscope TEXT NOT NULL,"
6896 + " locktype TEXT NOT NULL,"
6897 + " owner TEXT NOT NULL,"
6898 + " depth INT NOT NULL,"
6899 + " timeout TIMESTAMP NOT NULL,"
6900 + " PRIMARY KEY(locktoken))",
6901 + NULL, NULL, &err)) {
6903 + if (0 != strcmp(err, "table locks already exists")) {
6904 + log_error_write(srv, __FILE__, __LINE__, "ss", "can't open transaction:", err);
6905 + sqlite3_free(err);
6907 + return HANDLER_ERROR;
6909 + sqlite3_free(err);
6912 + if (SQLITE_OK != sqlite3_prepare(s->sql,
6913 + CONST_STR_LEN("INSERT INTO locks (locktoken, resource, lockscope, locktype, owner, depth, timeout) VALUES (?,?,?,?,?,?, CURRENT_TIME + 600)"),
6914 + &(s->stmt_create_lock), &next_stmt)) {
6915 + /* prepare failed */
6916 + log_error_write(srv, __FILE__, __LINE__, "ss", "sqlite3_prepare failed", sqlite3_errmsg(s->sql));
6918 + return HANDLER_ERROR;
6921 + if (SQLITE_OK != sqlite3_prepare(s->sql,
6922 + CONST_STR_LEN("DELETE FROM locks WHERE locktoken = ?"),
6923 + &(s->stmt_remove_lock), &next_stmt)) {
6924 + /* prepare failed */
6925 + log_error_write(srv, __FILE__, __LINE__, "ss", "sqlite3_prepare failed", sqlite3_errmsg(s->sql));
6927 + return HANDLER_ERROR;
6930 + if (SQLITE_OK != sqlite3_prepare(s->sql,
6931 + CONST_STR_LEN("SELECT locktoken, resource, lockscope, locktype, owner, depth, timeout FROM locks WHERE locktoken = ?"),
6932 + &(s->stmt_read_lock), &next_stmt)) {
6933 + /* prepare failed */
6934 + log_error_write(srv, __FILE__, __LINE__, "ss", "sqlite3_prepare failed", sqlite3_errmsg(s->sql));
6936 + return HANDLER_ERROR;
6939 + if (SQLITE_OK != sqlite3_prepare(s->sql,
6940 + CONST_STR_LEN("SELECT locktoken, resource, lockscope, locktype, owner, depth, timeout FROM locks WHERE resource = ?"),
6941 + &(s->stmt_read_lock_by_uri), &next_stmt)) {
6942 + /* prepare failed */
6943 + log_error_write(srv, __FILE__, __LINE__, "ss", "sqlite3_prepare failed", sqlite3_errmsg(s->sql));
6945 + return HANDLER_ERROR;
6948 + if (SQLITE_OK != sqlite3_prepare(s->sql,
6949 + CONST_STR_LEN("UPDATE locks SET timeout = CURRENT_TIME + 600 WHERE locktoken = ?"),
6950 + &(s->stmt_refresh_lock), &next_stmt)) {
6951 + /* prepare failed */
6952 + log_error_write(srv, __FILE__, __LINE__, "ss", "sqlite3_prepare failed", sqlite3_errmsg(s->sql));
6954 + return HANDLER_ERROR;
6959 log_error_write(srv, __FILE__, __LINE__, "s", "Sorry, no sqlite3 and libxml2 support include, compile with --with-webdav-props");
6960 return HANDLER_ERROR;
6961 @@ -283,26 +371,30 @@
6962 return HANDLER_GO_ON;
6967 static int mod_webdav_patch_connection(server *srv, connection *con, plugin_data *p) {
6969 plugin_config *s = p->config_storage[0];
6972 - PATCH(is_readonly);
6974 + PATCH_OPTION(enabled);
6975 + PATCH_OPTION(is_readonly);
6976 + PATCH_OPTION(log_xml);
6978 #ifdef USE_PROPPATCH
6980 - PATCH(stmt_update_prop);
6981 - PATCH(stmt_delete_prop);
6982 - PATCH(stmt_select_prop);
6983 - PATCH(stmt_select_propnames);
6985 - PATCH(stmt_delete_uri);
6986 - PATCH(stmt_move_uri);
6987 - PATCH(stmt_copy_uri);
6988 + PATCH_OPTION(sql);
6989 + PATCH_OPTION(stmt_update_prop);
6990 + PATCH_OPTION(stmt_delete_prop);
6991 + PATCH_OPTION(stmt_select_prop);
6992 + PATCH_OPTION(stmt_select_propnames);
6994 + PATCH_OPTION(stmt_delete_uri);
6995 + PATCH_OPTION(stmt_move_uri);
6996 + PATCH_OPTION(stmt_copy_uri);
6998 + PATCH_OPTION(stmt_remove_lock);
6999 + PATCH_OPTION(stmt_refresh_lock);
7000 + PATCH_OPTION(stmt_create_lock);
7001 + PATCH_OPTION(stmt_read_lock);
7002 + PATCH_OPTION(stmt_read_lock_by_uri);
7004 /* skip the first, the global context */
7005 for (i = 1; i < srv->config_context->used; i++) {
7006 @@ -317,22 +409,28 @@
7007 data_unset *du = dc->value->data[j];
7009 if (buffer_is_equal_string(du->key, CONST_STR_LEN("webdav.activate"))) {
7011 + PATCH_OPTION(enabled);
7012 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("webdav.is-readonly"))) {
7013 - PATCH(is_readonly);
7014 + PATCH_OPTION(is_readonly);
7015 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("webdav.log-xml"))) {
7017 + PATCH_OPTION(log_xml);
7018 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("webdav.sqlite-db-name"))) {
7019 #ifdef USE_PROPPATCH
7021 - PATCH(stmt_update_prop);
7022 - PATCH(stmt_delete_prop);
7023 - PATCH(stmt_select_prop);
7024 - PATCH(stmt_select_propnames);
7026 - PATCH(stmt_delete_uri);
7027 - PATCH(stmt_move_uri);
7028 - PATCH(stmt_copy_uri);
7029 + PATCH_OPTION(sql);
7030 + PATCH_OPTION(stmt_update_prop);
7031 + PATCH_OPTION(stmt_delete_prop);
7032 + PATCH_OPTION(stmt_select_prop);
7033 + PATCH_OPTION(stmt_select_propnames);
7035 + PATCH_OPTION(stmt_delete_uri);
7036 + PATCH_OPTION(stmt_move_uri);
7037 + PATCH_OPTION(stmt_copy_uri);
7039 + PATCH_OPTION(stmt_remove_lock);
7040 + PATCH_OPTION(stmt_refresh_lock);
7041 + PATCH_OPTION(stmt_create_lock);
7042 + PATCH_OPTION(stmt_read_lock);
7043 + PATCH_OPTION(stmt_read_lock_by_uri);
7053 URIHANDLER_FUNC(mod_webdav_uri_handler) {
7054 plugin_data *p = p_d;
7056 if (p->conf.is_readonly) {
7057 response_header_insert(srv, con, CONST_STR_LEN("Allow"), CONST_STR_LEN("PROPFIND"));
7059 - response_header_insert(srv, con, CONST_STR_LEN("Allow"), CONST_STR_LEN("PROPFIND, DELETE, MKCOL, PUT, MOVE, COPY, PROPPATCH"));
7060 + response_header_insert(srv, con, CONST_STR_LEN("Allow"), CONST_STR_LEN("PROPFIND, DELETE, MKCOL, PUT, MOVE, COPY, PROPPATCH, LOCK, UNLOCK"));
7064 @@ -496,11 +593,11 @@
7067 buffer_copy_string_buffer(d.path, dst->path);
7068 - BUFFER_APPEND_SLASH(d.path);
7069 + PATHNAME_APPEND_SLASH(d.path);
7070 buffer_append_string(d.path, de->d_name);
7072 buffer_copy_string_buffer(d.rel_path, dst->rel_path);
7073 - BUFFER_APPEND_SLASH(d.rel_path);
7074 + PATHNAME_APPEND_SLASH(d.rel_path);
7075 buffer_append_string(d.rel_path, de->d_name);
7077 /* stat and unlink afterwards */
7078 @@ -657,19 +754,19 @@
7081 buffer_copy_string_buffer(s.path, src->path);
7082 - BUFFER_APPEND_SLASH(s.path);
7083 + PATHNAME_APPEND_SLASH(s.path);
7084 buffer_append_string(s.path, de->d_name);
7086 buffer_copy_string_buffer(d.path, dst->path);
7087 - BUFFER_APPEND_SLASH(d.path);
7088 + PATHNAME_APPEND_SLASH(d.path);
7089 buffer_append_string(d.path, de->d_name);
7091 buffer_copy_string_buffer(s.rel_path, src->rel_path);
7092 - BUFFER_APPEND_SLASH(s.rel_path);
7093 + PATHNAME_APPEND_SLASH(s.rel_path);
7094 buffer_append_string(s.rel_path, de->d_name);
7096 buffer_copy_string_buffer(d.rel_path, dst->rel_path);
7097 - BUFFER_APPEND_SLASH(d.rel_path);
7098 + PATHNAME_APPEND_SLASH(d.rel_path);
7099 buffer_append_string(d.rel_path, de->d_name);
7101 if (-1 == stat(s.path->ptr, &st)) {
7106 - while (SQLITE_ROW == sqlite3_step(p->conf.stmt_select_prop)) {
7107 + while (SQLITE_ROW == sqlite3_step(stmt)) {
7108 /* there is a row for us, we only expect a single col 'value' */
7109 - webdav_gen_prop_tag(srv, con, prop_name, prop_ns, (char *)sqlite3_column_text(p->conf.stmt_select_prop, 0), b);
7110 + webdav_gen_prop_tag(srv, con, prop_name, prop_ns, (char *)sqlite3_column_text(stmt, 0), b);
7114 @@ -991,6 +1088,113 @@
7118 +int webdav_lockdiscovery(server *srv, connection *con,
7119 + buffer *locktoken, const char *lockscope, const char *locktype, int depth) {
7123 + response_header_overwrite(srv, con, CONST_STR_LEN("Lock-Token"), CONST_BUF_LEN(locktoken));
7125 + response_header_overwrite(srv, con,
7126 + CONST_STR_LEN("Content-Type"),
7127 + CONST_STR_LEN("text/xml; charset=\"utf-8\""));
7129 + b = chunkqueue_get_append_buffer(con->write_queue);
7131 + buffer_copy_string(b, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
7133 + buffer_append_string(b,"<D:prop xmlns:D=\"DAV:\" xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\">\n");
7134 + buffer_append_string(b,"<D:lockdiscovery>\n");
7135 + buffer_append_string(b,"<D:activelock>\n");
7137 + buffer_append_string(b,"<D:lockscope>");
7138 + buffer_append_string(b,"<D:");
7139 + buffer_append_string(b, lockscope);
7140 + buffer_append_string(b, "/>");
7141 + buffer_append_string(b,"</D:lockscope>\n");
7143 + buffer_append_string(b,"<D:locktype>");
7144 + buffer_append_string(b,"<D:");
7145 + buffer_append_string(b, locktype);
7146 + buffer_append_string(b, "/>");
7147 + buffer_append_string(b,"</D:locktype>\n");
7149 + buffer_append_string(b,"<D:depth>");
7150 + buffer_append_string(b, depth == 0 ? "0" : "infinity");
7151 + buffer_append_string(b,"</D:depth>\n");
7153 + buffer_append_string(b,"<D:timeout>");
7154 + buffer_append_string(b, "Second-600");
7155 + buffer_append_string(b,"</D:timeout>\n");
7157 + buffer_append_string(b,"<D:owner>");
7158 + buffer_append_string(b,"</D:owner>\n");
7160 + buffer_append_string(b,"<D:locktoken>");
7161 + buffer_append_string(b, "<D:href>");
7162 + buffer_append_string_buffer(b, locktoken);
7163 + buffer_append_string(b, "</D:href>");
7164 + buffer_append_string(b,"</D:locktoken>\n");
7166 + buffer_append_string(b,"</D:activelock>\n");
7167 + buffer_append_string(b,"</D:lockdiscovery>\n");
7168 + buffer_append_string(b,"</D:prop>\n");
7173 + * check if resource is having the right locks to access to resource
7178 +int webdav_has_lock(server *srv, connection *con, plugin_data *p, buffer *uri) {
7189 + * there is NOT, AND and OR
7190 + * and a list can be tagged
7192 + * (<lock-token>) is untagged
7193 + * <tag> (<lock-token>) is tagged
7195 + * as long as we don't handle collections it is simple. :)
7197 + * X-Litmus: locks: 11 (owner_modify)
7198 + * If: <http://127.0.0.1:1025/dav/litmus/lockme> (<opaquelocktoken:2165478d-0611-49c4-be92-e790d68a38f1>)
7200 + * X-Litmus: locks: 16 (fail_cond_put)
7201 + * If: (<DAV:no-lock> ["-1622396671"])
7203 + if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "If"))) {
7205 + /* we didn't provided a lock-token -> */
7206 + /* if the resource is locked -> 423 */
7208 + sqlite3_stmt *stmt = p->conf.stmt_read_lock_by_uri;
7210 + sqlite3_reset(stmt);
7212 + sqlite3_bind_text(stmt, 1,
7213 + CONST_BUF_LEN(uri),
7214 + SQLITE_TRANSIENT);
7216 + while (SQLITE_ROW == sqlite3_step(stmt)) {
7225 URIHANDLER_FUNC(mod_webdav_subrequest_handler) {
7226 plugin_data *p = p_d;
7228 @@ -1001,6 +1205,7 @@
7231 webdav_properties *req_props;
7232 + stat_cache_entry *sce = NULL;
7236 @@ -1020,6 +1225,18 @@
7238 /* is there a content-body ? */
7240 + switch (stat_cache_get_entry(srv, con, con->physical.path, &sce)) {
7241 + case HANDLER_ERROR:
7242 + if (errno == ENOENT) {
7243 + con->http_status = 404;
7244 + return HANDLER_FINISHED;
7252 #ifdef USE_PROPPATCH
7253 /* any special requests or just allprop ? */
7254 if (con->request.content_length) {
7255 @@ -1182,10 +1399,10 @@
7258 buffer_copy_string_buffer(d.path, dst->path);
7259 - BUFFER_APPEND_SLASH(d.path);
7260 + PATHNAME_APPEND_SLASH(d.path);
7262 buffer_copy_string_buffer(d.rel_path, dst->rel_path);
7263 - BUFFER_APPEND_SLASH(d.rel_path);
7264 + PATHNAME_APPEND_SLASH(d.rel_path);
7266 if (de->d_name[0] == '.' && de->d_name[1] == '\0') {
7267 /* don't append the . */
7268 @@ -1304,6 +1521,12 @@
7269 return HANDLER_FINISHED;
7272 + /* does the client have a lock for this connection ? */
7273 + if (!webdav_has_lock(srv, con, p, con->uri.path)) {
7274 + con->http_status = 423;
7275 + return HANDLER_FINISHED;
7278 /* stat and unlink afterwards */
7279 if (-1 == stat(con->physical.path->ptr, &st)) {
7280 /* don't about it yet, unlink will fail too */
7281 @@ -1375,22 +1598,100 @@
7282 case HTTP_METHOD_PUT: {
7284 chunkqueue *cq = con->request_content_queue;
7286 + data_string *ds_range;
7288 if (p->conf.is_readonly) {
7289 con->http_status = 403;
7290 return HANDLER_FINISHED;
7293 + /* is a exclusive lock set on the source */
7294 + if (!webdav_has_lock(srv, con, p, con->uri.path)) {
7295 + con->http_status = 423;
7296 + return HANDLER_FINISHED;
7300 assert(chunkqueue_length(cq) == (off_t)con->request.content_length);
7302 - /* taken what we have in the request-body and write it to a file */
7303 - if (-1 == (fd = open(con->physical.path->ptr, O_WRONLY|O_CREAT|O_TRUNC, 0600))) {
7304 + /* RFC2616 Section 9.6 PUT requires us to send 501 on all Content-* we don't support
7305 + * - most important Content-Range
7308 + * Example: Content-Range: bytes 100-1037/1038 */
7310 + if (NULL != (ds_range = (data_string *)array_get_element(con->request.headers, "Content-Range"))) {
7311 + const char *num = ds_range->value->ptr;
7315 + if (0 != strncmp(num, "bytes ", 6)) {
7316 + con->http_status = 501; /* not implemented */
7318 + return HANDLER_FINISHED;
7321 + /* we only support <num>- ... */
7326 + while (*num == ' ' || *num == '\t') num++;
7328 + if (*num == '\0') {
7329 + con->http_status = 501; /* not implemented */
7331 + return HANDLER_FINISHED;
7334 + offset = strtoll(num, &err, 10);
7336 + if (*err != '-' || offset < 0) {
7337 + con->http_status = 501; /* not implemented */
7339 + return HANDLER_FINISHED;
7342 + if (-1 == (fd = open(con->physical.path->ptr, O_WRONLY, 0600))) {
7345 + con->http_status = 404; /* not found */
7348 + con->http_status = 403; /* not found */
7351 + return HANDLER_FINISHED;
7354 + if (-1 == lseek(fd, offset, SEEK_SET)) {
7355 + con->http_status = 501; /* not implemented */
7359 + return HANDLER_FINISHED;
7361 + con->http_status = 200; /* modified */
7363 + /* take what we have in the request-body and write it to a file */
7365 + /* if the file doesn't exist, create it */
7366 + if (-1 == (fd = open(con->physical.path->ptr, O_WRONLY|O_TRUNC, 0600))) {
7367 + if (errno == ENOENT &&
7368 + -1 == (fd = open(con->physical.path->ptr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0600))) {
7369 /* we can't open the file */
7370 con->http_status = 403;
7374 + return HANDLER_FINISHED;
7376 con->http_status = 201; /* created */
7379 + con->http_status = 200; /* modified */
7383 con->file_finished = 1;
7385 for (c = cq->first; c; c = cq->first) {
7386 @@ -1462,7 +1763,6 @@
7391 return HANDLER_FINISHED;
7393 case HTTP_METHOD_MOVE:
7394 @@ -1476,6 +1776,14 @@
7395 return HANDLER_FINISHED;
7398 + /* is a exclusive lock set on the source */
7399 + if (con->request.http_method == HTTP_METHOD_MOVE) {
7400 + if (!webdav_has_lock(srv, con, p, con->uri.path)) {
7401 + con->http_status = 423;
7402 + return HANDLER_FINISHED;
7406 if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "Destination"))) {
7407 destination = ds->value;
7409 @@ -1549,7 +1857,7 @@
7412 buffer_copy_string_buffer(p->physical.path, p->physical.doc_root);
7413 - BUFFER_APPEND_SLASH(p->physical.path);
7414 + PATHNAME_APPEND_SLASH(p->physical.path);
7415 buffer_copy_string_buffer(p->physical.basedir, p->physical.path);
7417 /* don't add a second / */
7418 @@ -1613,6 +1921,12 @@
7419 /* it is just a file, good */
7422 + /* does the client have a lock for this connection ? */
7423 + if (!webdav_has_lock(srv, con, p, p->uri.path)) {
7424 + con->http_status = 423;
7425 + return HANDLER_FINISHED;
7428 /* destination exists */
7429 if (0 == (r = stat(p->physical.path->ptr, &st))) {
7430 if (S_ISDIR(st.st_mode)) {
7431 @@ -1691,12 +2005,17 @@
7433 return HANDLER_FINISHED;
7435 - case HTTP_METHOD_PROPPATCH: {
7436 + case HTTP_METHOD_PROPPATCH:
7437 if (p->conf.is_readonly) {
7438 con->http_status = 403;
7439 return HANDLER_FINISHED;
7442 + if (!webdav_has_lock(srv, con, p, con->uri.path)) {
7443 + con->http_status = 423;
7444 + return HANDLER_FINISHED;
7447 /* check if destination exists */
7448 if (-1 == stat(con->physical.path->ptr, &st)) {
7450 @@ -1789,7 +2108,8 @@
7453 if (SQLITE_DONE != (r = sqlite3_step(stmt))) {
7454 - log_error_write(srv, __FILE__, __LINE__, "ss", "sql-set failed:", sqlite3_errmsg(p->conf.sql));
7455 + log_error_write(srv, __FILE__, __LINE__, "ss",
7456 + "sql-set failed:", sqlite3_errmsg(p->conf.sql));
7460 @@ -1821,6 +2141,7 @@
7467 con->http_status = 400;
7468 @@ -1830,7 +2151,303 @@
7470 con->http_status = 501;
7471 return HANDLER_FINISHED;
7472 + case HTTP_METHOD_LOCK:
7474 + * a mac wants to write
7476 + * LOCK /dav/expire.txt HTTP/1.1\r\n
7477 + * User-Agent: WebDAVFS/1.3 (01308000) Darwin/8.1.0 (Power Macintosh)\r\n
7478 + * Accept: * / *\r\n
7480 + * Timeout: Second-600\r\n
7481 + * Content-Type: text/xml; charset=\"utf-8\"\r\n
7482 + * Content-Length: 229\r\n
7483 + * Connection: keep-alive\r\n
7484 + * Host: 192.168.178.23:1025\r\n
7486 + * <?xml version=\"1.0\" encoding=\"utf-8\"?>\n
7487 + * <D:lockinfo xmlns:D=\"DAV:\">\n
7488 + * <D:lockscope><D:exclusive/></D:lockscope>\n
7489 + * <D:locktype><D:write/></D:locktype>\n
7491 + * <D:href>http://www.apple.com/webdav_fs/</D:href>\n
7496 + if (depth != 0 && depth != -1) {
7497 + con->http_status = 400;
7499 + return HANDLER_FINISHED;
7503 + if (con->request.content_length) {
7505 + buffer *hdr_if = NULL;
7507 + if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "If"))) {
7508 + hdr_if = ds->value;
7511 + /* we don't support Depth: Infinity on locks */
7512 + if (hdr_if == NULL && depth == -1) {
7513 + con->http_status = 409; /* Conflict */
7515 + return HANDLER_FINISHED;
7518 + if (1 == webdav_parse_chunkqueue(srv, con, p, con->request_content_queue, &xml)) {
7519 + xmlNode *rootnode = xmlDocGetRootElement(xml);
7523 + if (0 == xmlStrcmp(rootnode->name, BAD_CAST "lockinfo")) {
7524 + xmlNode *lockinfo;
7525 + const xmlChar *lockscope = NULL, *locktype = NULL, *owner = NULL;
7527 + for (lockinfo = rootnode->children; lockinfo; lockinfo = lockinfo->next) {
7528 + if (0 == xmlStrcmp(lockinfo->name, BAD_CAST "lockscope")) {
7530 + for (value = lockinfo->children; value; value = value->next) {
7531 + if ((0 == xmlStrcmp(value->name, BAD_CAST "exclusive")) ||
7532 + (0 == xmlStrcmp(value->name, BAD_CAST "shared"))) {
7533 + lockscope = value->name;
7535 + con->http_status = 400;
7538 + return HANDLER_FINISHED;
7541 + } else if (0 == xmlStrcmp(lockinfo->name, BAD_CAST "locktype")) {
7543 + for (value = lockinfo->children; value; value = value->next) {
7544 + if ((0 == xmlStrcmp(value->name, BAD_CAST "write"))) {
7545 + locktype = value->name;
7547 + con->http_status = 400;
7550 + return HANDLER_FINISHED;
7554 + } else if (0 == xmlStrcmp(lockinfo->name, BAD_CAST "owner")) {
7558 + if (lockscope && locktype) {
7559 + sqlite3_stmt *stmt = p->conf.stmt_read_lock_by_uri;
7561 + /* is this resourse already locked ? */
7563 + /* SELECT locktoken, resource, lockscope, locktype, owner, depth, timeout
7565 + * WHERE resource = ? */
7569 + sqlite3_reset(stmt);
7571 + sqlite3_bind_text(stmt, 1,
7573 + p->uri.path->used - 1,
7574 + SQLITE_TRANSIENT);
7576 + /* it is the PK */
7577 + while (SQLITE_ROW == sqlite3_step(stmt)) {
7578 + /* we found a lock
7579 + * 1. is it compatible ?
7580 + * 2. is it ours */
7581 + char *sql_lockscope = (char *)sqlite3_column_text(stmt, 2);
7583 + if (strcmp(sql_lockscope, "exclusive")) {
7584 + con->http_status = 423;
7585 + } else if (0 == xmlStrcmp(lockscope, BAD_CAST "exclusive")) {
7586 + /* resourse is locked with a shared lock
7587 + * client wants exclusive */
7588 + con->http_status = 423;
7591 + if (con->http_status == 423) {
7593 + return HANDLER_FINISHED;
7597 + stmt = p->conf.stmt_create_lock;
7599 + /* create a lock-token */
7601 + char uuid[37] /* 36 + \0 */;
7603 + uuid_generate(id);
7604 + uuid_unparse(id, uuid);
7606 + buffer_copy_string(p->tmp_buf, "opaquelocktoken:");
7607 + buffer_append_string(p->tmp_buf, uuid);
7609 + /* "CREATE TABLE locks ("
7610 + * " locktoken TEXT NOT NULL,"
7611 + * " resource TEXT NOT NULL,"
7612 + * " lockscope TEXT NOT NULL,"
7613 + * " locktype TEXT NOT NULL,"
7614 + * " owner TEXT NOT NULL,"
7615 + * " depth INT NOT NULL,"
7618 + sqlite3_reset(stmt);
7620 + sqlite3_bind_text(stmt, 1,
7621 + CONST_BUF_LEN(p->tmp_buf),
7622 + SQLITE_TRANSIENT);
7624 + sqlite3_bind_text(stmt, 2,
7625 + CONST_BUF_LEN(con->uri.path),
7626 + SQLITE_TRANSIENT);
7628 + sqlite3_bind_text(stmt, 3,
7630 + xmlStrlen(lockscope),
7631 + SQLITE_TRANSIENT);
7633 + sqlite3_bind_text(stmt, 4,
7635 + xmlStrlen(locktype),
7636 + SQLITE_TRANSIENT);
7639 + sqlite3_bind_text(stmt, 5,
7642 + SQLITE_TRANSIENT);
7645 + sqlite3_bind_int(stmt, 6,
7649 + if (SQLITE_DONE != sqlite3_step(stmt)) {
7650 + log_error_write(srv, __FILE__, __LINE__, "ss",
7651 + "create lock:", sqlite3_errmsg(p->conf.sql));
7654 + /* looks like we survived */
7655 + webdav_lockdiscovery(srv, con, p->tmp_buf, lockscope, locktype, depth);
7657 + con->http_status = 201;
7658 + con->file_finished = 1;
7664 + return HANDLER_FINISHED;
7666 + con->http_status = 400;
7667 + return HANDLER_FINISHED;
7671 + if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "If"))) {
7672 + buffer *locktoken = ds->value;
7673 + sqlite3_stmt *stmt = p->conf.stmt_refresh_lock;
7675 + /* remove the < > around the token */
7676 + if (locktoken->used < 6) {
7677 + con->http_status = 400;
7679 + return HANDLER_FINISHED;
7682 + buffer_copy_string_len(p->tmp_buf, locktoken->ptr + 2, locktoken->used - 5);
7684 + sqlite3_reset(stmt);
7686 + sqlite3_bind_text(stmt, 1,
7687 + CONST_BUF_LEN(p->tmp_buf),
7688 + SQLITE_TRANSIENT);
7690 + if (SQLITE_DONE != sqlite3_step(stmt)) {
7691 + log_error_write(srv, __FILE__, __LINE__, "ss",
7692 + "refresh lock:", sqlite3_errmsg(p->conf.sql));
7695 + webdav_lockdiscovery(srv, con, p->tmp_buf, "exclusive", "write", 0);
7697 + con->http_status = 200;
7698 + con->file_finished = 1;
7699 + return HANDLER_FINISHED;
7701 + /* we need a lock-token to refresh */
7702 + con->http_status = 400;
7704 + return HANDLER_FINISHED;
7709 + con->http_status = 501;
7710 + return HANDLER_FINISHED;
7712 + case HTTP_METHOD_UNLOCK:
7714 + if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "Lock-Token"))) {
7715 + buffer *locktoken = ds->value;
7716 + sqlite3_stmt *stmt = p->conf.stmt_remove_lock;
7718 + /* remove the < > around the token */
7719 + if (locktoken->used < 4) {
7720 + con->http_status = 400;
7722 + return HANDLER_FINISHED;
7728 + * if the resourse is locked:
7730 + * - by someone else: 401
7731 + * if the resource is not locked:
7735 + buffer_copy_string_len(p->tmp_buf, locktoken->ptr + 1, locktoken->used - 3);
7737 + sqlite3_reset(stmt);
7739 + sqlite3_bind_text(stmt, 1,
7740 + CONST_BUF_LEN(p->tmp_buf),
7741 + SQLITE_TRANSIENT);
7743 + sqlite3_bind_text(stmt, 2,
7744 + CONST_BUF_LEN(con->uri.path),
7745 + SQLITE_TRANSIENT);
7747 + if (SQLITE_DONE != sqlite3_step(stmt)) {
7748 + log_error_write(srv, __FILE__, __LINE__, "ss",
7749 + "remove lock:", sqlite3_errmsg(p->conf.sql));
7752 + if (0 == sqlite3_changes(p->conf.sql)) {
7753 + con->http_status = 401;
7755 + con->http_status = 204;
7757 + return HANDLER_FINISHED;
7759 + /* we need a lock-token to unlock */
7760 + con->http_status = 400;
7762 + return HANDLER_FINISHED;
7766 + con->http_status = 501;
7767 + return HANDLER_FINISHED;
7772 --- lighttpd-1.4.11/src/network.c 2006-03-04 16:45:46.000000000 +0200
7773 +++ lighttpd/src/network.c 2006-07-11 21:23:39.983848713 +0300
7775 #include <sys/types.h>
7776 #include <sys/stat.h>
7777 -#include <sys/time.h>
7781 -#include <unistd.h>
7788 #include "network.h"
7789 #include "fdevent.h"
7792 #include "network_backends.h"
7793 #include "sys-mmap.h"
7794 #include "sys-socket.h"
7795 +#include "sys-files.h"
7798 # include <openssl/ssl.h>
7800 struct accept_filter_arg afa;
7805 WORD wVersionRequested;
7809 addr_len = sizeof(struct sockaddr_in);
7814 srv_socket->addr.un.sun_family = AF_UNIX;
7815 strcpy(srv_socket->addr.un.sun_path, host);
7827 srv->srv_sockets.ptr[srv->srv_sockets.used++] = srv_socket;
7832 @@ -425,11 +427,20 @@
7833 close(srv_socket->fd);
7836 + if (srv_socket->is_ssl) {
7838 + SSL_CTX_free(srv_socket->ssl_ctx);
7842 buffer_free(srv_socket->srv_token);
7848 + ERR_free_strings();
7850 free(srv->srv_sockets.ptr);
7853 @@ -437,11 +448,15 @@
7856 NETWORK_BACKEND_UNSET,
7858 NETWORK_BACKEND_WRITE,
7859 NETWORK_BACKEND_WRITEV,
7860 NETWORK_BACKEND_LINUX_SENDFILE,
7861 NETWORK_BACKEND_FREEBSD_SENDFILE,
7862 - NETWORK_BACKEND_SOLARIS_SENDFILEV
7863 + NETWORK_BACKEND_SOLARIS_SENDFILEV,
7865 + NETWORK_BACKEND_WIN32_SEND,
7866 + NETWORK_BACKEND_WIN32_TRANSMITFILE,
7867 } network_backend_t;
7869 int network_init(server *srv) {
7870 @@ -466,7 +481,16 @@
7871 #if defined USE_WRITEV
7872 { NETWORK_BACKEND_WRITEV, "writev" },
7874 +#if defined USE_WRITE
7875 { NETWORK_BACKEND_WRITE, "write" },
7877 +#if defined USE_WIN32_TRANSMITFILE
7878 + { NETWORK_BACKEND_WIN32_TRANSMITFILE, "win32-transmitfile" },
7880 +#if defined USE_WIN32_SEND
7881 + { NETWORK_BACKEND_WIN32_SEND, "win32-send" },
7884 { NETWORK_BACKEND_UNSET, NULL }
7887 @@ -508,33 +532,59 @@
7891 +#define SET_NETWORK_BACKEND(read, write) \
7892 + srv->network_backend_write = network_write_chunkqueue_##write;\
7893 + srv->network_backend_read = network_read_chunkqueue_##read
7895 +#define SET_NETWORK_BACKEND_SSL(read, write) \
7896 + srv->network_ssl_backend_write = network_write_chunkqueue_##write;\
7897 + srv->network_ssl_backend_read = network_read_chunkqueue_##read
7901 +#ifdef USE_WIN32_SEND
7902 + case NETWORK_BACKEND_WIN32_SEND:
7903 + SET_NETWORK_BACKEND(win32recv, win32send);
7905 +#ifdef USE_WIN32_TRANSMITFILE
7906 + case NETWORK_BACKEND_WIN32_TRANSMITFILE:
7907 + SET_NETWORK_BACKEND(win32recv, win32transmitfile);
7913 case NETWORK_BACKEND_WRITE:
7914 - srv->network_backend_write = network_write_chunkqueue_write;
7915 + SET_NETWORK_BACKEND(read, write);
7919 case NETWORK_BACKEND_WRITEV:
7920 - srv->network_backend_write = network_write_chunkqueue_writev;
7921 + SET_NETWORK_BACKEND(read, writev);
7924 #ifdef USE_LINUX_SENDFILE
7925 case NETWORK_BACKEND_LINUX_SENDFILE:
7926 - srv->network_backend_write = network_write_chunkqueue_linuxsendfile;
7927 + SET_NETWORK_BACKEND(read, linuxsendfile);
7930 #ifdef USE_FREEBSD_SENDFILE
7931 case NETWORK_BACKEND_FREEBSD_SENDFILE:
7932 - srv->network_backend_write = network_write_chunkqueue_freebsdsendfile;
7933 + SET_NETWORK_BACKEND(read, freebsdsendfile);
7936 #ifdef USE_SOLARIS_SENDFILEV
7937 case NETWORK_BACKEND_SOLARIS_SENDFILEV:
7938 - srv->network_backend_write = network_write_chunkqueue_solarissendfilev;
7939 + SET_NETWORK_BACKEND(read, solarissendfilev);
7947 + SET_NETWORK_BACKEND_SSL(openssl, openssl);
7950 /* check for $SERVER["socket"] */
7951 for (i = 1; i < srv->config_context->used; i++) {
7952 @@ -569,23 +619,34 @@
7954 int network_register_fdevents(server *srv) {
7957 if (-1 == fdevent_reset(srv->ev)) {
7961 /* register fdevents after reset */
7962 for (i = 0; i < srv->srv_sockets.used; i++) {
7963 server_socket *srv_socket = srv->srv_sockets.ptr[i];
7965 fdevent_register(srv->ev, srv_socket->fd, network_server_handle_fdevent, srv_socket);
7966 fdevent_event_add(srv->ev, &(srv_socket->fde_ndx), srv_socket->fd, FDEVENT_IN);
7971 -int network_write_chunkqueue(server *srv, connection *con, chunkqueue *cq) {
7973 +network_status_t network_read_chunkqueue(server *srv, connection *con, chunkqueue *cq) {
7974 + server_socket *srv_socket = con->srv_socket;
7976 + if (srv_socket->is_ssl) {
7978 + return srv->network_ssl_backend_read(srv, con, con->ssl, cq);
7980 + return NETWORK_STATUS_FATAL_ERROR;
7983 + return srv->network_backend_read(srv, con, con->fd, cq);
7987 +network_status_t network_write_chunkqueue(server *srv, connection *con, chunkqueue *cq) {
7988 + network_status_t ret = NETWORK_STATUS_UNSET;
7992 @@ -622,9 +683,14 @@
7993 ret = srv->network_backend_write(srv, con, con->fd, cq);
7998 + case NETWORK_STATUS_WAIT_FOR_EVENT:
7999 + case NETWORK_STATUS_SUCCESS:
8000 chunkqueue_remove_finished_chunks(cq);
8001 - ret = chunkqueue_is_empty(cq) ? 0 : 1;
8009 --- lighttpd-1.4.11/src/network.h 2005-08-11 01:26:42.000000000 +0300
8010 +++ lighttpd/src/network.h 2006-07-11 21:23:39.983848713 +0300
8015 -int network_write_chunkqueue(server *srv, connection *con, chunkqueue *c);
8016 +network_status_t network_write_chunkqueue(server *srv, connection *con, chunkqueue *c);
8017 +network_status_t network_read_chunkqueue(server *srv, connection *con, chunkqueue *c);
8019 int network_init(server *srv);
8020 int network_close(server *srv);
8021 --- lighttpd-1.4.11/src/network_backends.h 2005-10-24 15:13:51.000000000 +0300
8022 +++ lighttpd/src/network_backends.h 2006-07-11 21:23:40.035851970 +0300
8024 # define USE_AIX_SENDFILE
8028 +* unix can use read/write or recv/send on sockets
8029 +* win32 only recv/send
8032 +# define USE_WIN32_SEND
8033 +/* wait for async-io support
8034 +# define USE_WIN32_TRANSMITFILE
8041 +#include "network.h"
8043 +#define NETWORK_BACKEND_WRITE_CHUNK(x) \
8044 + network_status_t network_write_chunkqueue_##x(server *srv, connection *con, int fd, chunkqueue *cq, chunk *c)
8046 +#define NETWORK_BACKEND_WRITE(x) \
8047 + network_status_t network_write_chunkqueue_##x(server *srv, connection *con, int fd, chunkqueue *cq)
8048 +#define NETWORK_BACKEND_READ(x) \
8049 + network_status_t network_read_chunkqueue_##x(server *srv, connection *con, int fd, chunkqueue *cq)
8051 +NETWORK_BACKEND_WRITE_CHUNK(writev_mem);
8053 +NETWORK_BACKEND_WRITE(write);
8054 +NETWORK_BACKEND_WRITE(writev);
8055 +NETWORK_BACKEND_WRITE(linuxsendfile);
8056 +NETWORK_BACKEND_WRITE(freebsdsendfile);
8057 +NETWORK_BACKEND_WRITE(solarissendfilev);
8059 +NETWORK_BACKEND_WRITE(win32transmitfile);
8060 +NETWORK_BACKEND_WRITE(win32send);
8062 +NETWORK_BACKEND_READ(read);
8063 +NETWORK_BACKEND_READ(win32recv);
8065 -int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqueue *cq);
8066 -int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkqueue *cq);
8067 -int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd, chunkqueue *cq);
8068 -int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, int fd, chunkqueue *cq);
8069 -int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int fd, chunkqueue *cq);
8071 -int network_write_chunkqueue_openssl(server *srv, connection *con, SSL *ssl, chunkqueue *cq);
8072 +#define NETWORK_BACKEND_WRITE_SSL(x) \
8073 + network_status_t network_write_chunkqueue_##x(server *srv, connection *con, SSL *ssl, chunkqueue *cq)
8074 +#define NETWORK_BACKEND_READ_SSL(x) \
8075 + network_status_t network_read_chunkqueue_##x(server *srv, connection *con, SSL *ssl, chunkqueue *cq)
8077 +NETWORK_BACKEND_WRITE_SSL(openssl);
8078 +NETWORK_BACKEND_READ_SSL(openssl);
8082 --- lighttpd-1.4.11/src/network_freebsd_sendfile.c 2005-10-22 12:28:18.000000000 +0300
8083 +++ lighttpd/src/network_freebsd_sendfile.c 2006-07-11 21:23:40.107856480 +0300
8084 @@ -31,106 +31,25 @@
8088 -int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, int fd, chunkqueue *cq) {
8089 +NETWORK_BACKEND_WRITE(freebsdsendfile) {
8091 size_t chunks_written = 0;
8093 for(c = cq->first; c; c = c->next, chunks_written++) {
8094 int chunk_finished = 0;
8095 + network_status_t ret;
8103 - size_t num_chunks, i;
8104 - struct iovec chunks[UIO_MAXIOV];
8106 - size_t num_bytes = 0;
8108 - /* we can't send more then SSIZE_MAX bytes in one chunk */
8110 - /* build writev list
8112 - * 1. limit: num_chunks < UIO_MAXIOV
8113 - * 2. limit: num_bytes < SSIZE_MAX
8115 - for(num_chunks = 0, tc = c; tc && tc->type == MEM_CHUNK && num_chunks < UIO_MAXIOV; num_chunks++, tc = tc->next);
8117 - for(tc = c, i = 0; i < num_chunks; tc = tc->next, i++) {
8118 - if (tc->mem->used == 0) {
8119 - chunks[i].iov_base = tc->mem->ptr;
8120 - chunks[i].iov_len = 0;
8122 - offset = tc->mem->ptr + tc->offset;
8123 - toSend = tc->mem->used - 1 - tc->offset;
8125 - chunks[i].iov_base = offset;
8127 - /* protect the return value of writev() */
8128 - if (toSend > SSIZE_MAX ||
8129 - num_bytes + toSend > SSIZE_MAX) {
8130 - chunks[i].iov_len = SSIZE_MAX - num_bytes;
8132 - num_chunks = i + 1;
8135 - chunks[i].iov_len = toSend;
8138 - num_bytes += toSend;
8142 - if ((r = writev(fd, chunks, num_chunks)) < 0) {
8152 - log_error_write(srv, __FILE__, __LINE__, "ssd",
8153 - "writev failed:", strerror(errno), fd);
8161 + ret = network_write_chunkqueue_writev_mem(srv, con, fd, cq, &c);
8163 - /* check which chunks have been written */
8164 - cq->bytes_out += r;
8166 - for(i = 0, tc = c; i < num_chunks; i++, tc = tc->next) {
8167 - if (r >= (ssize_t)chunks[i].iov_len) {
8169 - r -= chunks[i].iov_len;
8170 - tc->offset += chunks[i].iov_len;
8172 - if (chunk_finished) {
8173 - /* skip the chunks from further touches */
8177 - /* chunks_written + c = c->next is done in the for()*/
8179 + if (ret != NETWORK_STATUS_SUCCESS) {
8183 - /* partially written */
8186 - chunk_finished = 0;
8191 + chunk_finished = 1;
8199 if (HANDLER_ERROR == stat_cache_get_entry(srv, con, c->file.name, &sce)) {
8200 log_error_write(srv, __FILE__, __LINE__, "sb",
8201 strerror(errno), c->file.name);
8203 + return NETWORK_STATUS_FATAL_ERROR;
8206 offset = c->file.start + c->offset;
8207 @@ -151,13 +70,13 @@
8208 if (offset > sce->st.st_size) {
8209 log_error_write(srv, __FILE__, __LINE__, "sb", "file was shrinked:", c->file.name);
8212 + return NETWORK_STATUS_FATAL_ERROR;
8215 if (-1 == (ifd = open(c->file.name->ptr, O_RDONLY))) {
8216 log_error_write(srv, __FILE__, __LINE__, "ss", "open failed: ", strerror(errno));
8219 + return NETWORK_STATUS_FATAL_ERROR;
8223 @@ -169,11 +88,11 @@
8228 + return NETWORK_STATUS_CONNECTION_CLOSE;
8230 log_error_write(srv, __FILE__, __LINE__, "ssd", "sendfile: ", strerror(errno), errno);
8233 + return NETWORK_STATUS_FATAL_ERROR;
8241 - return chunks_written;
8242 + return NETWORK_STATUS_SUCCESS;
8246 --- lighttpd-1.4.11/src/network_linux_sendfile.c 2006-02-15 20:02:36.000000000 +0200
8247 +++ lighttpd/src/network_linux_sendfile.c 2006-07-11 21:23:40.271866752 +0300
8248 @@ -26,106 +26,38 @@
8249 /* on linux 2.4.29 + debian/ubuntu we have crashes if this is enabled */
8250 #undef HAVE_POSIX_FADVISE
8252 -int network_write_chunkqueue_linuxsendfile(server *srv, connection *con, int fd, chunkqueue *cq) {
8254 +NETWORK_BACKEND_WRITE(linuxsendfile) {
8256 size_t chunks_written = 0;
8258 for(c = cq->first; c; c = c->next, chunks_written++) {
8259 int chunk_finished = 0;
8260 + network_status_t ret;
8268 - size_t num_chunks, i;
8269 - struct iovec chunks[UIO_MAXIOV];
8271 - size_t num_bytes = 0;
8273 - /* we can't send more then SSIZE_MAX bytes in one chunk */
8275 - /* build writev list
8277 - * 1. limit: num_chunks < UIO_MAXIOV
8278 - * 2. limit: num_bytes < SSIZE_MAX
8280 - for (num_chunks = 0, tc = c;
8281 - tc && tc->type == MEM_CHUNK && num_chunks < UIO_MAXIOV;
8282 - tc = tc->next, num_chunks++);
8284 - for (tc = c, i = 0; i < num_chunks; tc = tc->next, i++) {
8285 - if (tc->mem->used == 0) {
8286 - chunks[i].iov_base = tc->mem->ptr;
8287 - chunks[i].iov_len = 0;
8289 - offset = tc->mem->ptr + tc->offset;
8290 - toSend = tc->mem->used - 1 - tc->offset;
8292 - chunks[i].iov_base = offset;
8294 - /* protect the return value of writev() */
8295 - if (toSend > SSIZE_MAX ||
8296 - num_bytes + toSend > SSIZE_MAX) {
8297 - chunks[i].iov_len = SSIZE_MAX - num_bytes;
8299 - num_chunks = i + 1;
8302 - chunks[i].iov_len = toSend;
8305 - num_bytes += toSend;
8309 - if ((r = writev(fd, chunks, num_chunks)) < 0) {
8319 - log_error_write(srv, __FILE__, __LINE__, "ssd",
8320 - "writev failed:", strerror(errno), fd);
8326 - /* check which chunks have been written */
8327 - cq->bytes_out += r;
8329 - for(i = 0, tc = c; i < num_chunks; i++, tc = tc->next) {
8330 - if (r >= (ssize_t)chunks[i].iov_len) {
8332 - r -= chunks[i].iov_len;
8333 - tc->offset += chunks[i].iov_len;
8335 + ret = network_write_chunkqueue_writev_mem(srv, con, fd, cq, c);
8337 + /* check which chunks are finished now */
8338 + for (tc = c; tc; tc = tc->next) {
8339 + /* finished the chunk */
8340 + if (tc->offset == tc->mem->used - 1) {
8341 + /* skip the first c->next as that will be done by the c = c->next in the other for()-loop */
8342 if (chunk_finished) {
8343 - /* skip the chunks from further touches */
8347 - /* chunks_written + c = c->next is done in the for()*/
8349 + chunk_finished = 1;
8352 - /* partially written */
8355 - chunk_finished = 0;
8362 + if (ret != NETWORK_STATUS_SUCCESS) {
8370 --- lighttpd-1.4.11/src/network_openssl.c 2005-11-17 14:53:29.000000000 +0200
8371 +++ lighttpd/src/network_openssl.c 2006-07-11 21:23:40.107856480 +0300
8373 # include <openssl/ssl.h>
8374 # include <openssl/err.h>
8376 -int network_write_chunkqueue_openssl(server *srv, connection *con, SSL *ssl, chunkqueue *cq) {
8377 +NETWORK_BACKEND_READ_SSL(openssl) {
8381 + b = chunkqueue_get_append_buffer(cq);
8382 + buffer_prepare_copy(b, 8192);
8383 + len = SSL_read(ssl, b->ptr, b->size - 1);
8385 + log_error_write(srv, __FILE__, __LINE__, "so", "SSL:", len);
8390 + switch ((r = SSL_get_error(con->ssl, len))) {
8391 + case SSL_ERROR_WANT_READ:
8392 + return NETWORK_STATUS_WAIT_FOR_EVENT;
8393 + case SSL_ERROR_SYSCALL:
8395 + * man SSL_get_error()
8397 + * SSL_ERROR_SYSCALL
8398 + * Some I/O error occurred. The OpenSSL error queue may contain more
8399 + * information on the error. If the error queue is empty (i.e.
8400 + * ERR_get_error() returns 0), ret can be used to find out more about
8401 + * the error: If ret == 0, an EOF was observed that violates the
8402 + * protocol. If ret == -1, the underlying BIO reported an I/O error
8403 + * (for socket I/O on Unix systems, consult errno for details).
8406 + while((ssl_err = ERR_get_error())) {
8407 + /* get all errors from the error-queue */
8408 + log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:",
8409 + r, ERR_error_string(ssl_err, NULL));
8414 + log_error_write(srv, __FILE__, __LINE__, "sddds", "SSL:",
8421 + case SSL_ERROR_ZERO_RETURN:
8422 + /* clean shutdown on the remote side */
8425 + /* FIXME: later */
8428 + /* fall thourgh */
8430 + while((ssl_err = ERR_get_error())) {
8431 + /* get all errors from the error-queue */
8432 + log_error_write(srv, __FILE__, __LINE__, "sds", "SSL:",
8433 + r, ERR_error_string(ssl_err, NULL));
8441 + b->ptr[b->used - 1] = '\0';
8443 + return NETWORK_STATUS_SUCCESS;
8447 +NETWORK_BACKEND_WRITE_SSL(openssl) {
8450 size_t chunks_written = 0;
8458 if (c->mem->used == 0) {
8461 * SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, it must be
8462 * repeated with the same arguments.
8464 + * SSL_write(..., 0) return 0 which is handle as an error (Success)
8465 + * checking toSend and not calling SSL_write() is simpler
8468 - if ((r = SSL_write(ssl, offset, toSend)) <= 0) {
8469 + if (toSend != 0 && (r = SSL_write(ssl, offset, toSend)) <= 0) {
8472 switch ((ssl_r = SSL_get_error(ssl, r))) {
8473 --- lighttpd-1.4.11/src/network_solaris_sendfilev.c 2005-10-22 12:28:27.000000000 +0300
8474 +++ lighttpd/src/network_solaris_sendfilev.c 2006-07-11 21:23:40.211862994 +0300
8475 @@ -38,105 +38,25 @@
8479 -int network_write_chunkqueue_solarissendfilev(server *srv, connection *con, int fd, chunkqueue *cq) {
8480 +NETWORK_BACKEND_WRITE(solarissendfilev) {
8482 size_t chunks_written = 0;
8484 for(c = cq->first; c; c = c->next, chunks_written++) {
8485 int chunk_finished = 0;
8486 + network_status_t ret;
8494 - size_t num_chunks, i;
8495 - struct iovec chunks[UIO_MAXIOV];
8498 - size_t num_bytes = 0;
8500 - /* we can't send more then SSIZE_MAX bytes in one chunk */
8502 - /* build writev list
8504 - * 1. limit: num_chunks < UIO_MAXIOV
8505 - * 2. limit: num_bytes < SSIZE_MAX
8507 - for(num_chunks = 0, tc = c; tc && tc->type == MEM_CHUNK && num_chunks < UIO_MAXIOV; num_chunks++, tc = tc->next);
8509 - for(tc = c, i = 0; i < num_chunks; tc = tc->next, i++) {
8510 - if (tc->mem->used == 0) {
8511 - chunks[i].iov_base = tc->mem->ptr;
8512 - chunks[i].iov_len = 0;
8514 - offset = tc->mem->ptr + tc->offset;
8515 - toSend = tc->mem->used - 1 - tc->offset;
8517 - chunks[i].iov_base = offset;
8519 - /* protect the return value of writev() */
8520 - if (toSend > SSIZE_MAX ||
8521 - num_bytes + toSend > SSIZE_MAX) {
8522 - chunks[i].iov_len = SSIZE_MAX - num_bytes;
8524 - num_chunks = i + 1;
8527 - chunks[i].iov_len = toSend;
8530 - num_bytes += toSend;
8534 - if ((r = writev(fd, chunks, num_chunks)) < 0) {
8544 - log_error_write(srv, __FILE__, __LINE__, "ssd",
8545 - "writev failed:", strerror(errno), fd);
8551 + ret = network_write_chunkqueue_writev_mem(srv, con, fd, cq, &c);
8553 - /* check which chunks have been written */
8554 - cq->bytes_out += r;
8556 - for(i = 0, tc = c; i < num_chunks; i++, tc = tc->next) {
8557 - if (r >= (ssize_t)chunks[i].iov_len) {
8559 - r -= chunks[i].iov_len;
8560 - tc->offset += chunks[i].iov_len;
8562 - if (chunk_finished) {
8563 - /* skip the chunks from further touches */
8567 - /* chunks_written + c = c->next is done in the for()*/
8569 + if (ret != NETWORK_STATUS_SUCCESS) {
8573 - /* partially written */
8576 - chunk_finished = 0;
8581 + chunk_finished = 1;
8589 log_error_write(srv, __FILE__, __LINE__, "ssd", "sendfile: ", strerror(errno), errno);
8593 + return NETWORK_STATUS_FATAL_ERROR;
8597 @@ -194,10 +114,9 @@
8602 log_error_write(srv, __FILE__, __LINE__, "ds", c, "type not known");
8605 + return NETWORK_STATUS_FATAL_ERROR;
8608 if (!chunk_finished) {
8613 - return chunks_written;
8614 + return NETWORK_STATUS_SUCCESS;
8618 --- lighttpd-1.4.11/src/network_write.c 2005-10-22 12:27:56.000000000 +0300
8619 +++ lighttpd/src/network_write.c 2006-07-11 21:23:39.887842700 +0300
8621 #include <sys/types.h>
8622 #include <sys/stat.h>
8623 -#include <sys/time.h>
8627 -#include <unistd.h>
8630 +#include <assert.h>
8632 #include "network.h"
8633 #include "fdevent.h"
8635 #include "stat_cache.h"
8637 #include "sys-socket.h"
8638 +#include "sys-files.h"
8640 #include "network_backends.h"
8644 #ifdef HAVE_SYS_FILIO_H
8645 # include <sys/filio.h>
8648 #include <sys/resource.h>
8651 -int network_write_chunkqueue_write(server *srv, connection *con, int fd, chunkqueue *cq) {
8653 +* fill the chunkqueue will all the data that we can get
8655 +* this might be optimized into a readv() which uses the chunks
8658 +NETWORK_BACKEND_READ(read) {
8663 + /* check how much we have to read */
8664 + if (ioctl(fd, FIONREAD, &toread)) {
8665 + log_error_write(srv, __FILE__, __LINE__, "sd",
8668 + return NETWORK_STATUS_FATAL_ERROR;
8671 + if (toread == 0) return NETWORK_STATUS_WAIT_FOR_EVENT;
8674 + * our chunk queue is quiet large already
8676 + * let's buffer it to disk
8679 + b = chunkqueue_get_append_buffer(cq);
8681 + buffer_prepare_copy(b, toread);
8683 + if (-1 == (r = read(fd, b->ptr, toread))) {
8684 + log_error_write(srv, __FILE__, __LINE__, "sds",
8685 + "unexpected end-of-file (perhaps the proxy process died):",
8686 + fd, strerror(errno));
8687 + return NETWORK_STATUS_FATAL_ERROR;
8690 + /* this should be catched by the b > 0 above */
8693 + b->ptr[b->used - 1] = '\0';
8695 + return NETWORK_STATUS_SUCCESS;
8698 +NETWORK_BACKEND_WRITE(write) {
8700 size_t chunks_written = 0;
8704 offset = c->mem->ptr + c->offset;
8705 toSend = c->mem->used - 1 - c->offset;
8707 - if ((r = send(fd, offset, toSend, 0)) < 0) {
8708 - log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed: ", strerror(errno), fd);
8713 if ((r = write(fd, offset, toSend)) < 0) {
8714 log_error_write(srv, __FILE__, __LINE__, "ssd", "write failed: ", strerror(errno), fd);
8717 + return NETWORK_STATUS_FATAL_ERROR;
8724 if (HANDLER_ERROR == stat_cache_get_entry(srv, con, c->file.name, &sce)) {
8725 log_error_write(srv, __FILE__, __LINE__, "sb",
8726 strerror(errno), c->file.name);
8728 + return NETWORK_STATUS_FATAL_ERROR;
8731 offset = c->file.start + c->offset;
8732 @@ -89,13 +131,13 @@
8733 if (offset > sce->st.st_size) {
8734 log_error_write(srv, __FILE__, __LINE__, "sb", "file was shrinked:", c->file.name);
8737 + return NETWORK_STATUS_FATAL_ERROR;
8740 if (-1 == (ifd = open(c->file.name->ptr, O_RDONLY))) {
8741 log_error_write(srv, __FILE__, __LINE__, "ss", "open failed: ", strerror(errno));
8744 + return NETWORK_STATUS_FATAL_ERROR;
8747 #if defined USE_MMAP
8748 @@ -104,14 +146,14 @@
8753 + return NETWORK_STATUS_FATAL_ERROR;
8757 if ((r = write(fd, p + offset, toSend)) <= 0) {
8758 log_error_write(srv, __FILE__, __LINE__, "ss", "write failed: ", strerror(errno));
8759 munmap(p, sce->st.st_size);
8761 + return NETWORK_STATUS_FATAL_ERROR;
8764 munmap(p, sce->st.st_size);
8765 @@ -123,14 +165,14 @@
8766 log_error_write(srv, __FILE__, __LINE__, "ss", "read: ", strerror(errno));
8770 + return NETWORK_STATUS_FATAL_ERROR;
8774 if (-1 == (r = send(fd, srv->tmp_buf->ptr, toSend, 0))) {
8775 log_error_write(srv, __FILE__, __LINE__, "ss", "write: ", strerror(errno));
8778 + return NETWORK_STATUS_FATAL_ERROR;
8784 log_error_write(srv, __FILE__, __LINE__, "ds", c, "type not known");
8787 + return NETWORK_STATUS_FATAL_ERROR;
8790 if (!chunk_finished) {
8791 @@ -158,11 +200,7 @@
8795 - return chunks_written;
8796 + return NETWORK_STATUS_SUCCESS;
8800 -network_write_init(void) {
8801 - p->write = network_write_write_chunkset;
8804 --- lighttpd-1.4.11/src/network_writev.c 2006-02-15 01:02:36.000000000 +0200
8805 +++ lighttpd/src/network_writev.c 2006-07-11 21:23:40.103856229 +0300
8807 #define LOCAL_BUFFERING 1
8810 -int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkqueue *cq) {
8812 - size_t chunks_written = 0;
8814 - for(c = cq->first; c; c = c->next) {
8815 - int chunk_finished = 0;
8819 +NETWORK_BACKEND_WRITE_CHUNK(writev_mem) {
8824 size_t num_chunks, i;
8825 struct iovec chunks[UIO_MAXIOV];
8827 + chunk *tc; /* transfer chunks */
8828 size_t num_bytes = 0;
8830 /* we can't send more then SSIZE_MAX bytes in one chunk */
8831 @@ -111,12 +103,12 @@
8836 + return NETWORK_STATUS_CONNECTION_CLOSE;
8838 log_error_write(srv, __FILE__, __LINE__, "ssd",
8839 "writev failed:", strerror(errno), fd);
8842 + return NETWORK_STATUS_FATAL_ERROR;
8846 @@ -129,27 +121,49 @@
8848 r -= chunks[i].iov_len;
8849 tc->offset += chunks[i].iov_len;
8851 + /* partially written */
8858 + return NETWORK_STATUS_SUCCESS;
8861 +NETWORK_BACKEND_WRITE(writev) {
8863 + size_t chunks_written = 0;
8865 + for(c = cq->first; c; c = c->next) {
8866 + int chunk_finished = 0;
8867 + network_status_t ret;
8871 + ret = network_write_chunkqueue_writev_mem(srv, con, fd, cq, c);
8873 + /* check which chunks are finished now */
8874 + for (tc = c; tc; tc = tc->next) {
8875 + /* finished the chunk */
8876 + if (tc->offset == tc->mem->used - 1) {
8877 + /* skip the first c->next as that will be done by the c = c->next in the other for()-loop */
8878 if (chunk_finished) {
8879 - /* skip the chunks from further touches */
8883 - /* chunks_written + c = c->next is done in the for()*/
8885 + chunk_finished = 1;
8888 - /* partially written */
8891 - chunk_finished = 0;
8898 + if (ret != NETWORK_STATUS_SUCCESS) {
8907 if (HANDLER_ERROR == stat_cache_get_entry(srv, con, c->file.name, &sce)) {
8908 log_error_write(srv, __FILE__, __LINE__, "sb",
8909 strerror(errno), c->file.name);
8911 + return NETWORK_STATUS_FATAL_ERROR;
8914 abs_offset = c->file.start + c->offset;
8916 log_error_write(srv, __FILE__, __LINE__, "sb",
8917 "file was shrinked:", c->file.name);
8920 + return NETWORK_STATUS_FATAL_ERROR;
8925 if (-1 == (c->file.fd = open(c->file.name->ptr, O_RDONLY))) {
8926 log_error_write(srv, __FILE__, __LINE__, "sbs", "open failed for:", c->file.name, strerror(errno));
8929 + return NETWORK_STATUS_FATAL_ERROR;
8932 fcntl(c->file.fd, F_SETFD, FD_CLOEXEC);
8934 log_error_write(srv, __FILE__, __LINE__, "ssbd", "mmap failed:",
8935 strerror(errno), c->file.name, c->file.fd);
8938 + return NETWORK_STATUS_FATAL_ERROR;
8941 c->file.mmap.length = to_mmap;
8942 @@ -297,12 +311,12 @@
8947 + return NETWORK_STATUS_CONNECTION_CLOSE;
8949 log_error_write(srv, __FILE__, __LINE__, "ssd",
8950 "write failed:", strerror(errno), fd);
8953 + return NETWORK_STATUS_FATAL_ERROR;
8959 log_error_write(srv, __FILE__, __LINE__, "ds", c, "type not known");
8962 + return NETWORK_STATUS_FATAL_ERROR;
8965 if (!chunk_finished) {
8970 - return chunks_written;
8971 + return NETWORK_STATUS_SUCCESS;
8975 --- lighttpd-1.4.11/src/plugin.c 2006-02-08 14:00:54.000000000 +0200
8976 +++ lighttpd/src/plugin.c 2006-07-11 21:23:40.067853974 +0300
8978 #include <valgrind/valgrind.h>
8988 p = calloc(1, sizeof(*p));
8990 + p->required_plugins = array_init();
8995 static void plugin_free(plugin *p) {
8996 int use_dlclose = 1;
8997 if (p->name) buffer_free(p->name);
8999 + array_free(p->required_plugins);
9000 #ifdef HAVE_VALGRIND_VALGRIND_H
9001 /*if (RUNNING_ON_VALGRIND) use_dlclose = 0;*/
9004 #ifndef LIGHTTPD_STATIC
9005 if (use_dlclose && p->lib) {
9008 FreeLibrary(p->lib);
9011 @@ -121,9 +125,14 @@
9013 int plugins_load(server *srv) {
9018 int (*init)(plugin *pl);
9025 for (i = 0; i < srv->srvconf.modules->used; i++) {
9026 data_string *d = (data_string *)srv->srvconf.modules->data[i];
9027 @@ -133,14 +142,14 @@
9029 buffer_append_string(srv->tmp_buf, "/");
9030 buffer_append_string(srv->tmp_buf, modules);
9031 -#if defined(__WIN32) || defined(__CYGWIN__)
9032 +#if defined(_WIN32) || defined(__CYGWIN__)
9033 buffer_append_string(srv->tmp_buf, ".dll");
9035 buffer_append_string(srv->tmp_buf, ".so");
9041 if (NULL == (p->lib = LoadLibrary(srv->tmp_buf->ptr))) {
9045 buffer_copy_string(srv->tmp_buf, modules);
9046 buffer_append_string(srv->tmp_buf, "_plugin_init");
9050 init = GetProcAddress(p->lib, srv->tmp_buf->ptr);
9053 @@ -218,6 +227,25 @@
9055 log_error_write(srv, __FILE__, __LINE__, "ss", modules, "plugin loaded" );
9057 + /* check if the required plugin is loaded */
9058 + for (k = 0; k < p->required_plugins->used; k++) {
9059 + data_string *req = (data_string *)p->required_plugins->data[k];
9061 + for (j = 0; j < i; j++) {
9062 + data_string *mod = (data_string *)srv->srvconf.modules->data[j];
9064 + if (buffer_is_equal(req->value, mod->value)) break;
9069 + log_error_write(srv, __FILE__, __LINE__, "ssbs", modules, "failed to load. required plugin", req->value, "was not loaded" );
9076 plugins_register(srv, p);
9079 @@ -426,6 +454,23 @@
9080 return HANDLER_GO_ON;
9084 + * get the config-storage of the named plugin
9086 +void *plugin_get_config(server *srv, const char *name) {
9089 + for (i = 0; i < srv->plugins.used; i++) {
9090 + plugin *p = ((plugin **)srv->plugins.ptr)[i];
9092 + if (buffer_is_equal_string(p->name, name, strlen(name))) {
9100 void plugins_free(server *srv) {
9102 plugins_call_cleanup(srv);
9103 --- lighttpd-1.4.11/src/plugin.h 2005-08-15 12:28:56.000000000 +0300
9104 +++ lighttpd/src/plugin.h 2006-07-11 21:23:40.075854475 +0300
9107 #define INIT_FUNC(x) \
9110 + * The PATCH_OPTION() macro is used in the patch_connection() functions
9111 + * of the modules to update the config object for the current request.
9113 +#define PATCH_OPTION(x) \
9116 #define FREE_FUNC SERVER_FUNC
9117 #define TRIGGER_FUNC SERVER_FUNC
9123 + array *required_plugins;
9126 int plugins_load(server *srv);
9128 int config_patch_connection(server *srv, connection *con, comp_key_t comp);
9129 int config_check_cond(server *srv, connection *con, data_config *dc);
9130 int config_append_cond_match_buffer(connection *con, data_config *dc, buffer *buf, int n);
9131 +int config_exec_pcre_keyvalue_buffer(connection *con, pcre_keyvalue_buffer *kvb, data_config *context, buffer *match_buf, buffer *result);
9133 +void *plugin_get_config(server *srv, const char *name);
9136 --- lighttpd-1.4.11/src/proc_open.c 2005-08-11 01:26:39.000000000 +0300
9137 +++ lighttpd/src/proc_open.c 2006-07-11 21:23:40.283867504 +0300
9144 /* {{{ win32 stuff */
9145 # define SHELLENV "ComSpec"
9146 # define SECURITY_DC , SECURITY_ATTRIBUTES *security
9147 # define SECURITY_CC , security
9148 # define pipe(pair) (CreatePipe(&pair[0], &pair[1], security, 2048L) ? 0 : -1)
9149 -static inline HANDLE dup_handle(HANDLE src, BOOL inherit, BOOL closeorig)
9150 +static HANDLE dup_handle(HANDLE src, BOOL inherit, BOOL closeorig)
9152 HANDLE copy, self = GetCurrentProcess();
9154 @@ -148,11 +148,14 @@
9157 SECURITY_ATTRIBUTES security;
9158 - const char *shell;
9159 + const char *shell = NULL;
9160 + const char *windir = NULL;
9163 - if (NULL == (shell = getenv(SHELLENV))) {
9164 - fprintf(stderr, "env %s is required", SHELLENV);
9165 + if (NULL == (shell = getenv(SHELLENV)) &&
9166 + NULL == (windir = getenv("SystemRoot")) &&
9167 + NULL == (windir = getenv("windir"))) {
9168 + fprintf(stderr, "One of %s,%%SystemRoot,%%windir is required", SHELLENV);
9172 @@ -177,17 +180,23 @@
9173 memset(&pi, 0, sizeof(pi));
9175 cmdline = buffer_init();
9177 buffer_append_string(cmdline, shell);
9179 + buffer_append_string(cmdline, windir);
9180 + buffer_append_string(cmdline, "\\system32\\cmd.exe");
9182 buffer_append_string_len(cmdline, CONST_STR_LEN(" /c "));
9183 buffer_append_string(cmdline, command);
9184 procok = CreateProcess(NULL, cmdline->ptr, &security, &security, TRUE,
9185 NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
9186 - buffer_free(cmdline);
9188 if (FALSE == procok) {
9189 - fprintf(stderr, "failed to CreateProcess");
9190 + fprintf(stderr, "failed to CreateProcess: %s", cmdline->ptr);
9191 + buffer_free(cmdline);
9194 + buffer_free(cmdline);
9196 proc->child = pi.hProcess;
9197 CloseHandle(pi.hThread);
9201 if (NULL == (shell = getenv(SHELLENV))) {
9202 - fprintf(stderr, "env %s is required", SHELLENV);
9204 + shell = "/bin/sh";
9207 if (proc_open_pipes(proc) != 0) {
9208 @@ -262,11 +270,11 @@
9213 +#endif /* _WIN32 */
9215 /* {{{ proc_read_fd_to_buffer */
9216 static void proc_read_fd_to_buffer(int fd, buffer *b) {
9218 + int s; /* win32 has not ssize_t */
9221 buffer_prepare_append(b, 512);
9222 --- lighttpd-1.4.11/src/proc_open.h 2005-08-11 01:26:39.000000000 +0300
9223 +++ lighttpd/src/proc_open.h 2006-07-11 21:23:40.287867754 +0300
9230 #include <windows.h>
9231 typedef HANDLE descriptor_t;
9232 typedef HANDLE proc_pid_t;
9233 --- lighttpd-1.4.11/src/request.c 2006-03-05 11:58:09.000000000 +0200
9234 +++ lighttpd/src/request.c 2006-07-11 21:23:40.035851970 +0300
9236 #include "keyvalue.h"
9239 +#include "sys-strings.h"
9241 static int request_check_hostname(server *srv, connection *con, buffer *host) {
9242 enum { DOMAINLABEL, TOPLABEL } stage = TOPLABEL;
9247 if (major_num == 1 && minor_num == 1) {
9248 - con->request.http_version = con->conf.allow_http11 ? HTTP_VERSION_1_1 : HTTP_VERSION_1_0;
9249 + con->request.http_version = HTTP_VERSION_1_1;
9250 } else if (major_num == 1 && minor_num == 0) {
9251 con->request.http_version = HTTP_VERSION_1_0;
9254 "request-header:\n",
9255 con->request.request);
9257 + ds->free((data_unset *) ds);
9262 "request-header:\n",
9263 con->request.request);
9265 + ds->free((data_unset *) ds);
9268 } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("Expect")))) {
9270 "request-header:\n",
9271 con->request.request);
9273 + ds->free((data_unset *) ds);
9276 } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("If-Modified-Since")))) {
9278 "request-header:\n",
9279 con->request.request);
9281 + ds->free((data_unset *) ds);
9284 } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("If-None-Match")))) {
9286 "request-header:\n",
9287 con->request.request);
9289 + ds->free((data_unset *) ds);
9292 } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("Range")))) {
9294 "request-header:\n",
9295 con->request.request);
9297 + ds->free((data_unset *) ds);
9301 --- lighttpd-1.4.11/src/response.c 2006-03-04 16:41:39.000000000 +0200
9302 +++ lighttpd/src/response.c 2006-07-11 21:23:40.067853974 +0300
9307 -#include <unistd.h>
9314 #include "sys-socket.h"
9315 +#include "sys-files.h"
9316 +#include "sys-strings.h"
9318 int http_response_write_header(server *srv, connection *con) {
9321 ds = (data_string *)con->response.headers->data[i];
9323 if (ds->value->used && ds->key->used &&
9324 - 0 != strncmp(ds->key->ptr, "X-LIGHTTPD-", sizeof("X-LIGHTTPD-") - 1)) {
9325 + 0 != strncmp(ds->key->ptr, "X-LIGHTTPD-", sizeof("X-LIGHTTPD-") - 1) &&
9326 + 0 != strcasecmp(ds->key->ptr, "X-Sendfile")) {
9327 if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Date"))) have_date = 1;
9328 if (buffer_is_equal_string(ds->key, CONST_STR_LEN("Server"))) have_server = 1;
9331 handler_t http_response_prepare(server *srv, connection *con) {
9334 - /* looks like someone has already done a decision */
9335 + /* looks like someone has already made a decision */
9336 if (con->mode == DIRECT &&
9337 (con->http_status != 0 && con->http_status != 200)) {
9338 /* remove a packets in the queue */
9340 if (con->mode == DIRECT && con->physical.path->used == 0) {
9343 - /* we only come here when we have the parse the full request again
9344 + /* we only come here when we have to parse the full request again
9346 * a HANDLER_COMEBACK from mod_rewrite and mod_fastcgi might be a
9347 * problem here as mod_setenv might get called multiple times
9348 @@ -262,6 +264,11 @@
9350 config_patch_connection(srv, con, COMP_HTTP_URL); /* HTTPurl */
9352 + /* do we have to downgrade to 1.0 ? */
9353 + if (!con->conf.allow_http11) {
9354 + con->request.http_version = HTTP_VERSION_1_0;
9357 switch(r = plugins_call_handle_uri_clean(srv, con)) {
9362 if (con->request.http_method == HTTP_METHOD_OPTIONS &&
9363 con->uri.path->ptr[0] == '*' && con->uri.path_raw->ptr[1] == '\0') {
9364 - /* option requests are handled directly without checking of the path */
9365 + /* option requests are handled directly without checking the path */
9367 response_header_insert(srv, con, CONST_STR_LEN("Allow"), CONST_STR_LEN("OPTIONS, GET, HEAD, POST"));
9369 @@ -320,14 +327,15 @@
9370 buffer_copy_string_buffer(con->physical.doc_root, con->conf.document_root);
9371 buffer_copy_string_buffer(con->physical.rel_path, con->uri.path);
9373 -#if defined(__WIN32) || defined(__CYGWIN__)
9374 - /* strip dots from the end and spaces
9375 + filename_unix2local(con->physical.rel_path);
9376 +#if defined(_WIN32) || defined(__CYGWIN__)
9377 + /* strip dots and spaces from the end
9379 * windows/dos handle those filenames as the same file
9381 * foo == foo. == foo..... == "foo... " == "foo.. ./"
9383 - * This will affect in some cases PATHINFO
9384 + * This will affect PATHINFO in some cases
9386 * on native windows we could prepend the filename with \\?\ to circumvent
9387 * this behaviour. I have no idea how to push this through cygwin
9388 @@ -378,15 +386,14 @@
9392 - /* MacOS X and Windows can't distiguish between upper and lower-case
9394 - * convert to lower-case
9395 + /* The default Mac OS X and Windows filesystems can't distiguish between
9396 + * upper- and lowercase, so convert to lowercase
9398 if (con->conf.force_lowercase_filenames) {
9399 buffer_to_lower(con->physical.rel_path);
9402 - /* the docroot plugins might set the servername, if they don't we take http-host */
9403 + /* the docroot plugins might set the servername; if they don't we take http-host */
9404 if (buffer_is_empty(con->server_name)) {
9405 buffer_copy_string_buffer(con->server_name, con->uri.authority);
9407 @@ -398,15 +405,21 @@
9410 buffer_copy_string_buffer(con->physical.path, con->physical.doc_root);
9411 - BUFFER_APPEND_SLASH(con->physical.path);
9412 + PATHNAME_APPEND_SLASH(con->physical.path);
9413 buffer_copy_string_buffer(con->physical.basedir, con->physical.path);
9414 if (con->physical.rel_path->used &&
9415 - con->physical.rel_path->ptr[0] == '/') {
9416 + con->physical.rel_path->ptr[0] == DIR_SEPERATOR) {
9417 buffer_append_string_len(con->physical.path, con->physical.rel_path->ptr + 1, con->physical.rel_path->used - 2);
9419 buffer_append_string_buffer(con->physical.path, con->physical.rel_path);
9422 + /* win32: directories can't have a trailing slash */
9423 + if (con->physical.path->ptr[con->physical.path->used - 2] == DIR_SEPERATOR) {
9424 + con->physical.path->ptr[con->physical.path->used - 2] = '\0';
9425 + con->physical.path->used--;
9428 if (con->conf.log_request_handling) {
9429 log_error_write(srv, __FILE__, __LINE__, "s", "-- after doc_root");
9430 log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root);
9435 - * Noone catched away the file from normal path of execution yet (like mod_access)
9436 + * No one took the file away from the normal path of execution yet (like mod_access)
9438 * Go on and check of the file exists at all
9443 if (S_ISDIR(sce->st.st_mode)) {
9444 - if (con->physical.path->ptr[con->physical.path->used - 2] != '/') {
9445 + if (con->uri.path->ptr[con->uri.path->used - 2] != '/') {
9446 /* redirect to .../ */
9448 http_response_redirect_to_directory(srv, con);
9450 /* PATH_INFO ! :) */
9453 - /* we have no idea what happend. let's tell the user so. */
9454 + /* we have no idea what happened, so tell the user. */
9455 con->http_status = 500;
9456 buffer_reset(con->physical.path);
9459 } while ((found == 0) && (slash != NULL) && (slash - srv->tmp_buf->ptr > con->physical.basedir->used - 2));
9462 - /* no it really doesn't exists */
9463 + /* no, it really doesn't exists */
9464 con->http_status = 404;
9466 if (con->conf.log_file_not_found) {
9467 @@ -594,11 +607,11 @@
9468 log_error_write(srv, __FILE__, __LINE__, "s", "-- subrequest finished");
9471 - /* something strange happend */
9472 + /* something strange happened */
9476 - /* if we are still here, no one wanted the file, status 403 is ok I think */
9477 + /* if we are still here, no one wanted the file; status 403 is ok I think */
9479 if (con->mode == DIRECT) {
9480 con->http_status = 403;
9481 @@ -610,12 +623,12 @@
9483 switch(r = plugins_call_handle_subrequest(srv, con)) {
9485 - /* request was not handled, looks like we are done */
9486 + /* request was not handled; looks like we are done */
9487 return HANDLER_FINISHED;
9488 case HANDLER_FINISHED:
9489 /* request is finished */
9491 - /* something strange happend */
9492 + /* something strange happened */
9496 --- lighttpd-1.4.11/src/server.c 2006-03-04 19:12:17.000000000 +0200
9497 +++ lighttpd/src/server.c 2006-07-11 21:23:40.247865249 +0300
9499 #include <sys/types.h>
9500 -#include <sys/time.h>
9501 #include <sys/stat.h>
9506 -#include <unistd.h>
9512 #include "joblist.h"
9513 #include "network_backends.h"
9516 +/* use local getopt implementation */
9517 +# undef HAVE_GETOPT_H
9519 #ifdef HAVE_GETOPT_H
9522 +#include "getopt.h"
9525 #ifdef HAVE_VALGRIND_VALGRIND_H
9527 /* #define USE_ALARM */
9534 +#include "sys-files.h"
9535 +#include "sys-process.h"
9537 static volatile sig_atomic_t srv_shutdown = 0;
9538 static volatile sig_atomic_t graceful_shutdown = 0;
9539 +static volatile sig_atomic_t graceful_restart = 0;
9540 static volatile sig_atomic_t handle_sig_alarm = 1;
9541 static volatile sig_atomic_t handle_sig_hup = 0;
9545 server *srv = calloc(1, sizeof(*srv));
9547 + srv->max_fds = 1024;
9549 srv->x = buffer_init();
9554 static void show_features (void) {
9556 - printf("\nEvent Handlers:\n\n%s",
9558 + const char *s = ""
9560 "\t+ select (generic)\n"
9562 @@ -355,11 +365,6 @@
9564 "\t- crypt support\n"
9567 - "\t+ PAM support\n"
9569 - "\t- PAM support\n"
9575 "\t- PCRE support\n"
9578 - "\t+ mySQL support\n"
9579 + "\t+ MySQL support\n"
9581 - "\t- mySQL support\n"
9582 + "\t- MySQL support\n"
9584 #if defined(HAVE_LDAP_H) && defined(HAVE_LBER_H) && defined(HAVE_LIBLDAP) && defined(HAVE_LIBLBER)
9585 "\t+ LDAP support\n"
9586 @@ -410,8 +415,11 @@
9588 "\t- GDBM support\n"
9596 + printf("\nEvent Handlers:\n\n%s", s);
9599 static void show_help (void) {
9601 write(STDOUT_FILENO, b, strlen(b));
9604 -int main (int argc, char **argv) {
9605 +int main (int argc, char **argv, char **envp) {
9607 int print_config = 0;
9608 int test_config = 0;
9609 @@ -447,6 +455,10 @@
9611 int pid_fd = -1, fd;
9614 + char *optarg = NULL;
9617 #ifdef HAVE_SIGACTION
9618 struct sigaction act;
9620 @@ -485,10 +497,15 @@
9621 while(-1 != (o = getopt(argc, argv, "f:m:hvVDpt"))) {
9625 + /* evil HACK for windows, optarg is not set */
9626 + optarg = argv[optind-1];
9628 if (config_read(srv, optarg)) {
9635 buffer_copy_string(srv->srvconf.modules_dir, optarg);
9641 /* open pid file BEFORE chroot */
9642 if (srv->srvconf.pid_file->used) {
9643 if (-1 == (pid_fd = open(srv->srvconf.pid_file->ptr, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) {
9644 @@ -617,13 +635,14 @@
9650 if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
9651 /* select limits itself
9653 * as it is a hard limit and will lead to a segfault we add some safety
9655 - srv->max_fds = FD_SETSIZE - 200;
9656 + fprintf(stderr, "%s.%d: max parallel connections: %d\r\n", __FILE__, __LINE__, FD_SETSIZE);
9657 + srv->max_fds = FD_SETSIZE - 4;
9659 srv->max_fds = 4096;
9664 if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
9665 - srv->max_fds = rlim.rlim_cur < FD_SETSIZE - 200 ? rlim.rlim_cur : FD_SETSIZE - 200;
9666 + srv->max_fds = rlim.rlim_cur < FD_SETSIZE - 4 ? rlim.rlim_cur : FD_SETSIZE - 4;
9668 srv->max_fds = rlim.rlim_cur;
9672 if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
9673 /* don't raise the limit above FD_SET_SIZE */
9674 - if (srv->max_fds > FD_SETSIZE - 200) {
9675 + if (srv->max_fds > FD_SETSIZE - 4) {
9676 log_error_write(srv, __FILE__, __LINE__, "sd",
9677 - "can't raise max filedescriptors above", FD_SETSIZE - 200,
9678 + "can't raise max filedescriptors above", FD_SETSIZE - 4,
9679 "if event-handler is 'select'. Use 'poll' or something else or reduce server.max-fds.");
9682 @@ -818,8 +837,10 @@
9683 if (srv->srvconf.dont_daemonize == 0) daemonize();
9687 srv->gid = getgid();
9688 srv->uid = getuid();
9691 /* write pid file */
9698 #ifdef HAVE_SIGACTION
9699 memset(&act, 0, sizeof(act));
9700 act.sa_handler = SIG_IGN;
9705 - if (NULL == (srv->ev = fdevent_init(srv->max_fds + 1, srv->event_handler))) {
9706 + if (NULL == (srv->ev = fdevent_init(/*srv->max_fds + 1*/ 4096, srv->event_handler))) {
9707 log_error_write(srv, __FILE__, __LINE__,
9708 "s", "fdevent_init failed");
9710 @@ -1025,7 +1045,31 @@
9711 /* reset notification */
9717 + /* send the old process into a graceful-shutdown and start a
9718 + * new process right away
9721 + * - if webserver is running on port < 1024 (e.g. 80, 433)
9722 + * we don't have the permissions to bind to that port anymore
9726 + if (0 == (pid = fork())) {
9727 + execve(argv[0], argv, envp);
9730 + } else if (pid == -1) {
9735 + graceful_shutdown = 1; /* shutdown without killing running connections */
9736 + graceful_restart = 1; /* don't delete pid file */
9739 /* cycle logfiles */
9741 switch(r = plugins_call_handle_sighup(srv)) {
9742 @@ -1041,6 +1085,7 @@
9749 if (handle_sig_alarm) {
9750 @@ -1312,7 +1357,8 @@
9751 srv->joblist->used = 0;
9754 - if (srv->srvconf.pid_file->used &&
9755 + if (0 == graceful_restart &&
9756 + srv->srvconf.pid_file->used &&
9757 srv->srvconf.changeroot->used == 0) {
9758 if (0 != unlink(srv->srvconf.pid_file->ptr)) {
9759 if (errno != EACCES && errno != EPERM) {
9760 --- lighttpd-1.4.11/src/spawn-fcgi.c 2006-03-07 14:18:10.000000000 +0200
9761 +++ lighttpd/src/spawn-fcgi.c 2006-07-11 21:23:40.167860238 +0300
9763 #include <sys/types.h>
9764 -#include <sys/time.h>
9765 #include <sys/stat.h>
9771 -#include <unistd.h>
9775 #ifdef HAVE_CONFIG_H
9786 #include "sys-socket.h"
9787 +#include "sys-files.h"
9789 #ifdef HAVE_SYS_WAIT_H
9790 #include <sys/wait.h>
9795 + /* loose control terminal */
9798 /* is save as we limit to 256 childs */
9799 sprintf(cgi_childs, "PHP_FCGI_CHILDREN=%d", child_count);
9801 --- lighttpd-1.4.11/src/stat_cache.c 2005-11-22 15:23:51.000000000 +0200
9802 +++ lighttpd/src/stat_cache.c 2006-07-11 21:23:40.067853974 +0300
9807 -#include <unistd.h>
9814 #include "sys-mmap.h"
9816 -/* NetBSD 1.3.x needs it */
9818 -# define MAP_FAILED -1
9821 -#ifndef O_LARGEFILE
9822 -# define O_LARGEFILE 0
9828 +#include "sys-files.h"
9829 +#include "sys-strings.h"
9832 /* enables debug code for testing if all nodes in the stat-cache as accessable */
9833 --- lighttpd-1.4.11/src/stream.c 2005-09-23 21:50:15.000000000 +0300
9834 +++ lighttpd/src/stream.c 2006-07-11 21:23:40.215863244 +0300
9836 #include <sys/types.h>
9837 #include <sys/stat.h>
9839 -#include <unistd.h>
9846 #include "sys-mmap.h"
9847 +#include "sys-files.h"
9855 -#elif defined __WIN32
9856 +#elif defined _WIN32
9864 -#elif defined __WIN32
9865 +#elif defined _WIN32
9866 fh = CreateFile(fn->ptr,
9869 --- lighttpd-1.4.11/src/sys-mmap.h 2005-08-11 01:26:34.000000000 +0300
9870 +++ lighttpd/src/sys-mmap.h 2006-07-11 21:23:40.051852972 +0300
9872 #ifndef WIN32_MMAP_H
9873 #define WIN32_MMAP_H
9878 #define MAP_FAILED -1
9879 #define PROT_SHARED 0
9880 --- lighttpd-1.4.11/src/sys-socket.h 2005-08-11 01:26:39.000000000 +0300
9881 +++ lighttpd/src/sys-socket.h 2006-07-11 21:23:40.051852972 +0300
9883 #ifndef WIN32_SOCKET_H
9884 #define WIN32_SOCKET_H
9889 #include <winsock2.h>
9891 #define ECONNRESET WSAECONNRESET
9892 #define EINPROGRESS WSAEINPROGRESS
9893 #define EALREADY WSAEALREADY
9894 +#define ENOTCONN WSAENOTCONN
9895 +#define EWOULDBLOCK WSAEWOULDBLOCK
9896 #define ioctl ioctlsocket
9897 #define hstrerror(x) ""
9898 +#define STDIN_FILENO 0
9899 +#define STDOUT_FILENO 1
9900 +#define STDERR_FILENO 2
9901 +#define ssize_t int
9903 +int inet_aton(const char *cp, struct in_addr *inp);
9904 +#define HAVE_INET_ADDR
9905 +#undef HAVE_INET_ATON
9908 #include <sys/socket.h>
9909 #include <sys/ioctl.h>
9912 #include <arpa/inet.h>
9915 +#define SUN_LEN(su) \
9916 + (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
9922 --- lighttpd-1.4.11/tests/LightyTest.pm 2006-01-14 20:32:31.000000000 +0200
9923 +++ lighttpd/tests/LightyTest.pm 2006-07-11 21:23:42.047977994 +0300
9925 # pre-process configfile if necessary
9928 - unlink($self->{TESTDIR}."/tmp/cfg.file");
9929 - system("cat ".$self->{SRCDIR}."/".$self->{CONFIGFILE}.' | perl -pe "s#\@SRCDIR\@#'.$self->{BASEDIR}.'/tests/#" > '.$self->{TESTDIR}.'/tmp/cfg.file');
9930 + $ENV{'SRCDIR'} = $self->{BASEDIR}.'/tests';
9931 + $ENV{'PORT'} = $self->{PORT};
9933 unlink($self->{LIGHTTPD_PIDFILE});
9935 - system($self->{LIGHTTPD_PATH}." -f ".$self->{TESTDIR}."/tmp/cfg.file -m ".$self->{MODULES_PATH});
9936 + system($self->{LIGHTTPD_PATH}." -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH});
9938 - system("valgrind --tool=memcheck --show-reachable=yes --leak-check=yes --logfile=foo ".$self->{LIGHTTPD_PATH}." -D -f ".$self->{TESTDIR}."/tmp/cfg.file -m ".$self->{MODULES_PATH}." &");
9939 + system("valgrind --tool=memcheck --show-reachable=yes --leak-check=yes --logfile=foo ".$self->{LIGHTTPD_PATH}." -D -f ".$self->{SRCDIR}."/".$self->{CONFIGFILE}." -m ".$self->{MODULES_PATH}." &");
9942 select(undef, undef, undef, 0.1);
9944 (my $h = $1) =~ tr/[A-Z]/[a-z]/;
9946 if (defined $resp_hdr{$h}) {
9947 - diag(sprintf("header %s is duplicated: %s and %s\n",
9948 + diag(sprintf("header '%s' is duplicated: '%s' and '%s'\n",
9949 $h, $resp_hdr{$h}, $2));
9956 + $t->{etag} = $resp_hdr{'etag'};
9957 + $t->{date} = $resp_hdr{'date'};
9960 if (defined $resp_hdr{"content-length"}) {
9961 $resp_body = substr($lines, 0, $resp_hdr{"content-length"});
9962 --- lighttpd-1.4.11/tests/Makefile.am 2005-09-16 15:48:40.000000000 +0300
9963 +++ lighttpd/tests/Makefile.am 2006-07-11 21:23:42.039977492 +0300
9980 TESTS_ENVIRONMENT=$(srcdir)/wrapper.sh $(srcdir) $(top_builddir)
9981 --- lighttpd-1.4.11/tests/bug-06.conf 2005-08-27 17:44:19.000000000 +0300
9982 +++ lighttpd/tests/bug-06.conf 2006-07-11 21:23:41.915969726 +0300
9984 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
9985 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
9986 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
9987 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
9989 ## bind to port (default: 80)
9993 ## bind to localhost (default: all interfaces)
9994 server.bind = "localhost"
9995 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
9996 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
9997 server.name = "www.example.org"
9998 server.tag = "Apache 1.3.29"
10001 ######################## MODULE CONFIG ############################
10004 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10005 +accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
10007 mimetype.assign = ( ".png" => "image/png",
10008 ".jpg" => "image/jpeg",
10010 ".c" => "text/plain",
10011 ".conf" => "text/plain" )
10013 -compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
10014 +compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
10015 compress.filetype = ("text/plain", "text/html")
10017 setenv.add-environment = ( "TRAC_ENV" => "foo")
10019 "host" => "127.0.0.1",
10021 # "mode" => "authorizer",
10022 -# "docroot" => "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/",
10023 +# "docroot" => env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/",
10027 @@ -106,7 +106,7 @@
10028 ssl.pemfile = "server.pem"
10030 auth.backend = "plain"
10031 -auth.backend.plain.userfile = "@SRCDIR@/tmp/lighttpd/lighttpd.user"
10032 +auth.backend.plain.userfile = env.SRCDIR + "/tmp/lighttpd/lighttpd.user"
10033 auth.backend.plain.groupfile = "lighttpd.group"
10035 auth.backend.ldap.hostname = "localhost"
10036 @@ -149,15 +149,15 @@
10037 status.config-url = "/server-config"
10039 simple-vhost.document-root = "pages"
10040 -simple-vhost.server-root = "@SRCDIR@/tmp/lighttpd/servers/"
10041 +simple-vhost.server-root = env.SRCDIR + "/tmp/lighttpd/servers/"
10042 simple-vhost.default-host = "www.example.org"
10044 $HTTP["host"] == "vvv.example.org" {
10045 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10046 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10049 $HTTP["host"] == "zzz.example.org" {
10050 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10051 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10052 server.name = "zzz.example.org"
10055 --- lighttpd-1.4.11/tests/bug-12.conf 2005-08-27 17:44:19.000000000 +0300
10056 +++ lighttpd/tests/bug-12.conf 2006-07-11 21:23:41.907969224 +0300
10058 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10059 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
10060 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10061 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
10063 ## bind to port (default: 80)
10067 ## bind to localhost (default: all interfaces)
10068 server.bind = "localhost"
10069 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
10070 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
10071 server.name = "www.example.org"
10072 server.tag = "Apache 1.3.29"
10075 ######################## MODULE CONFIG ############################
10078 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10079 +accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
10081 mimetype.assign = ( ".png" => "image/png",
10082 ".jpg" => "image/jpeg",
10084 ".c" => "text/plain",
10085 ".conf" => "text/plain" )
10087 -compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
10088 +compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
10089 compress.filetype = ("text/plain", "text/html")
10091 setenv.add-environment = ( "TRAC_ENV" => "foo")
10093 "host" => "127.0.0.1",
10095 # "mode" => "authorizer",
10096 -# "docroot" => "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/",
10097 +# "docroot" => env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/",
10101 @@ -108,7 +108,7 @@
10102 ssl.pemfile = "server.pem"
10104 auth.backend = "plain"
10105 -auth.backend.plain.userfile = "@SRCDIR@/tmp/lighttpd/lighttpd.user"
10106 +auth.backend.plain.userfile = env.SRCDIR + "/tmp/lighttpd/lighttpd.user"
10107 auth.backend.plain.groupfile = "lighttpd.group"
10109 auth.backend.ldap.hostname = "localhost"
10110 @@ -151,15 +151,15 @@
10111 status.config-url = "/server-config"
10113 simple-vhost.document-root = "pages"
10114 -simple-vhost.server-root = "@SRCDIR@/tmp/lighttpd/servers/"
10115 +simple-vhost.server-root = env.SRCDIR + "/tmp/lighttpd/servers/"
10116 simple-vhost.default-host = "www.example.org"
10118 $HTTP["host"] == "vvv.example.org" {
10119 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10120 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10123 $HTTP["host"] == "zzz.example.org" {
10124 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10125 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10126 server.name = "zzz.example.org"
10129 --- lighttpd-1.4.11/tests/condition.conf 2005-08-27 17:44:19.000000000 +0300
10130 +++ lighttpd/tests/condition.conf 2006-07-11 21:23:41.951971980 +0300
10132 debug.log-request-handling = "enable"
10133 debug.log-condition-handling = "enable"
10135 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10136 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
10137 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10138 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
10140 ## bind to port (default: 80)
10143 ## bind to localhost (default: all interfaces)
10144 server.bind = "localhost"
10145 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
10146 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
10147 server.name = "www.example.org"
10148 server.tag = "Apache 1.3.29"
10150 @@ -22,25 +22,25 @@
10151 ######################## MODULE CONFIG ############################
10154 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10155 +accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
10157 mimetype.assign = ( ".html" => "text/html" )
10159 url.redirect = ("^" => "/default")
10161 $HTTP["host"] == "www.example.org" {
10162 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10163 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10164 server.name = "www.example.org"
10165 url.redirect = ("^" => "/match_1")
10167 else $HTTP["host"] == "test1.example.org" {
10168 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10169 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10170 server.name = "test1.example.org"
10171 url.redirect = ("^" => "/match_2")
10174 else $HTTP["host"] == "test2.example.org" {
10175 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10176 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10177 server.name = "test2.example.org"
10178 url.redirect = ("^" => "/match_3")
10183 else $HTTP["host"] == "test3.example.org" {
10184 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10185 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10186 server.name = "test3.example.org"
10187 url.redirect = ("^" => "/match_4")
10189 --- lighttpd-1.4.11/tests/core-keepalive.t 2005-11-17 15:54:19.000000000 +0200
10190 +++ lighttpd/tests/core-keepalive.t 2006-07-11 21:23:41.939971229 +0300
10193 GET /12345.txt HTTP/1.0
10194 Host: 123.example.org
10195 -Connection: keep-alive
10199 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } , { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
10200 --- lighttpd-1.4.11/tests/docroot/www/dummydir/.svn/entries 2006-03-09 19:21:49.000000000 +0200
10201 +++ lighttpd/tests/docroot/www/dummydir/.svn/entries 2006-07-11 21:23:41.575948429 +0300
10205 uuid="152afb58-edef-0310-8abb-c4023f1b3aa9"
10206 - revision="1040"/>
10207 + repos="svn://svn.lighttpd.net/lighttpd"
10208 + revision="1159"/>
10210 --- lighttpd-1.4.11/tests/fastcgi-10.conf 2005-08-31 23:36:34.000000000 +0300
10211 +++ lighttpd/tests/fastcgi-10.conf 2006-07-11 21:23:41.911969475 +0300
10213 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10214 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
10215 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10216 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
10218 ## bind to port (default: 80)
10221 ## bind to localhost (default: all interfaces)
10222 server.bind = "localhost"
10223 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
10224 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
10225 server.name = "www.example.org"
10226 server.tag = "Apache 1.3.29"
10229 ######################## MODULE CONFIG ############################
10232 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10233 +accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
10235 mimetype.assign = ( ".png" => "image/png",
10236 ".jpg" => "image/jpeg",
10238 ".c" => "text/plain",
10239 ".conf" => "text/plain" )
10241 -compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
10242 +compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
10243 compress.filetype = ("text/plain", "text/html")
10247 ssl.pemfile = "server.pem"
10249 auth.backend = "plain"
10250 -auth.backend.plain.userfile = "@SRCDIR@/tmp/lighttpd/lighttpd.user"
10251 +auth.backend.plain.userfile = env.SRCDIR + "/tmp/lighttpd/lighttpd.user"
10252 auth.backend.plain.groupfile = "lighttpd.group"
10254 auth.backend.ldap.hostname = "localhost"
10255 @@ -128,11 +128,11 @@
10256 status.config-url = "/server-config"
10258 $HTTP["host"] == "vvv.example.org" {
10259 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10260 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10263 $HTTP["host"] == "zzz.example.org" {
10264 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10265 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10266 server.name = "zzz.example.org"
10269 --- lighttpd-1.4.11/tests/fastcgi-13.conf 2006-01-03 12:38:17.000000000 +0200
10270 +++ lighttpd/tests/fastcgi-13.conf 2006-07-11 21:23:41.971973233 +0300
10272 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10273 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
10274 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10275 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
10277 debug.log-request-header = "enable"
10278 debug.log-response-header = "enable"
10281 ## bind to localhost (default: all interfaces)
10282 server.bind = "localhost"
10283 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
10284 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
10285 server.name = "www.example.org"
10286 server.tag = "Apache 1.3.29"
10289 ######################## MODULE CONFIG ############################
10292 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10293 +accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
10295 mimetype.assign = ( ".png" => "image/png",
10296 ".jpg" => "image/jpeg",
10298 ".c" => "text/plain",
10299 ".conf" => "text/plain" )
10301 -compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
10302 +compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
10303 compress.filetype = ("text/plain", "text/html")
10306 @@ -102,7 +102,7 @@
10307 ssl.pemfile = "server.pem"
10309 auth.backend = "plain"
10310 -auth.backend.plain.userfile = "@SRCDIR@/tmp/lighttpd/lighttpd.user"
10311 +auth.backend.plain.userfile = env.SRCDIR + "/tmp/lighttpd/lighttpd.user"
10312 auth.backend.plain.groupfile = "lighttpd.group"
10314 auth.backend.ldap.hostname = "localhost"
10315 @@ -145,11 +145,11 @@
10316 status.config-url = "/server-config"
10318 $HTTP["host"] == "vvv.example.org" {
10319 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10320 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10323 $HTTP["host"] == "zzz.example.org" {
10324 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10325 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10326 server.name = "zzz.example.org"
10329 --- lighttpd-1.4.11/tests/fastcgi-auth.conf 2005-08-27 17:44:19.000000000 +0300
10330 +++ lighttpd/tests/fastcgi-auth.conf 2006-07-11 21:23:42.003975238 +0300
10332 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10333 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
10334 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10335 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
10337 debug.log-request-header = "enable"
10338 debug.log-response-header = "enable"
10341 ## bind to localhost (default: all interfaces)
10342 server.bind = "localhost"
10343 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
10344 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
10345 server.name = "www.example.org"
10346 server.tag = "Apache 1.3.29"
10349 ######################## MODULE CONFIG ############################
10352 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10353 +accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
10355 mimetype.assign = ( ".png" => "image/png",
10356 ".jpg" => "image/jpeg",
10358 ".c" => "text/plain",
10359 ".conf" => "text/plain" )
10361 -compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
10362 +compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
10363 compress.filetype = ("text/plain", "text/html")
10368 "host" => "127.0.0.1",
10370 - "bin-path" => "@SRCDIR@/fcgi-auth",
10371 + "bin-path" => env.SRCDIR + "/fcgi-auth",
10372 "mode" => "authorizer",
10373 - "docroot" => "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/",
10374 + "docroot" => env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/",
10378 @@ -106,7 +106,7 @@
10379 ssl.pemfile = "server.pem"
10381 auth.backend = "plain"
10382 -auth.backend.plain.userfile = "@SRCDIR@/tmp/lighttpd/lighttpd.user"
10383 +auth.backend.plain.userfile = env.SRCDIR + "/tmp/lighttpd/lighttpd.user"
10384 auth.backend.plain.groupfile = "lighttpd.group"
10386 auth.backend.ldap.hostname = "localhost"
10387 @@ -149,11 +149,11 @@
10388 status.config-url = "/server-config"
10390 $HTTP["host"] == "vvv.example.org" {
10391 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10392 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10395 $HTTP["host"] == "zzz.example.org" {
10396 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10397 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10398 server.name = "zzz.example.org"
10401 --- lighttpd-1.4.11/tests/fastcgi-responder.conf 2005-08-27 17:44:19.000000000 +0300
10402 +++ lighttpd/tests/fastcgi-responder.conf 2006-07-11 21:23:41.999974987 +0300
10404 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10405 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
10406 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10407 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
10409 #debug.log-request-header = "enable"
10410 #debug.log-response-header = "enable"
10413 ## bind to localhost (default: all interfaces)
10414 server.bind = "localhost"
10415 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
10416 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
10417 server.name = "www.example.org"
10418 server.tag = "Apache 1.3.29"
10421 ######################## MODULE CONFIG ############################
10424 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10425 +accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
10427 mimetype.assign = ( ".png" => "image/png",
10428 ".jpg" => "image/jpeg",
10430 ".c" => "text/plain",
10431 ".conf" => "text/plain" )
10433 -compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
10434 +compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
10435 compress.filetype = ("text/plain", "text/html")
10438 @@ -90,10 +90,11 @@
10440 "host" => "127.0.0.1",
10442 - "bin-path" => "@SRCDIR@/fcgi-responder",
10443 + "bin-path" => env.SRCDIR + "/fcgi-responder",
10444 "check-local" => "disable",
10447 + "min-procs" => 1,
10448 + "allow-x-send-file" => "enable",
10452 @@ -109,7 +110,7 @@
10453 ssl.pemfile = "server.pem"
10455 auth.backend = "plain"
10456 -auth.backend.plain.userfile = "@SRCDIR@/tmp/lighttpd/lighttpd.user"
10457 +auth.backend.plain.userfile = env.SRCDIR + "/tmp/lighttpd/lighttpd.user"
10458 auth.backend.plain.groupfile = "lighttpd.group"
10460 auth.backend.ldap.hostname = "localhost"
10461 @@ -152,11 +153,11 @@
10462 status.config-url = "/server-config"
10464 $HTTP["host"] == "vvv.example.org" {
10465 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10466 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10469 $HTTP["host"] == "zzz.example.org" {
10470 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10471 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10472 server.name = "zzz.example.org"
10475 --- lighttpd-1.4.11/tests/fcgi-responder.c 2005-08-11 01:26:55.000000000 +0300
10476 +++ lighttpd/tests/fcgi-responder.c 2006-07-11 21:23:41.979973734 +0300
10479 int num_requests = 2;
10481 - while (num_requests > 0 &&
10482 - FCGI_Accept() >= 0) {
10484 + while (num_requests > 0 && FCGI_Accept() >= 0) {
10486 + char* doc_root = NULL;
10487 + char fname[4096];
10488 + char* pfname = (char *)fname;
10490 - if (NULL != (p = getenv("QUERY_STRING"))) {
10491 + doc_root = getenv("DOCUMENT_ROOT");
10492 + p = getenv("QUERY_STRING");
10494 + if (NULL != p && NULL != doc_root) {
10495 + snprintf(pfname, sizeof(fname), "%s/phpinfo.php", doc_root);
10496 if (0 == strcmp(p, "lf")) {
10497 printf("Status: 200 OK\n\n");
10498 } else if (0 == strcmp(p, "crlf")) {
10500 printf("Status: 200 OK\r\n");
10503 + } else if (0 == strcmp(p,"x-lighttpd-send-file")) {
10504 + printf("Status: 200 OK\r\n");
10505 + printf("X-LIGHTTPD-send-file: %s\r\n", pfname);
10507 + } else if (0 == strcmp(p,"xsendfile")) {
10508 + printf("Status: 200 OK\r\n");
10509 + printf("X-Sendfile: %s\r\n", pfname);
10511 + } else if (0 == strcmp(p,"xsendfile-mixed-case")) {
10512 + printf("Status: 200 OK\r\n");
10513 + printf("X-SeNdFiLe: %s\r\n", pfname);
10515 } else if (0 == strcmp(p, "die-at-end")) {
10516 printf("Status: 200 OK\r\n\r\n");
10518 --- lighttpd-1.4.11/tests/lighttpd.conf 2006-03-09 15:26:58.000000000 +0200
10519 +++ lighttpd/tests/lighttpd.conf 2006-07-11 21:23:41.999974987 +0300
10521 -debug.log-request-handling = "enable"
10522 -debug.log-condition-handling = "enable"
10523 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10524 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
10525 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10526 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
10527 +server.tag = "Apache 1.3.29"
10529 ## 64 Mbyte ... nice limit
10530 server.max-request-size = 65000
10532 -## bind to port (default: 80)
10533 -server.port = 2048
10535 -## bind to localhost (default: all interfaces)
10536 -server.bind = "localhost"
10537 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
10538 -server.name = "www.example.org"
10539 -server.tag = "Apache 1.3.29"
10541 -server.dir-listing = "enable"
10542 +include "default.conf"
10544 -#server.event-handler = "linux-sysepoll"
10545 -#server.event-handler = "linux-rtsig"
10547 -#server.modules.path = ""
10548 -server.modules = (
10551 - "mod_secdownload",
10557 - "mod_simple_vhost",
10560 -# "mod_localizer",
10566 - "mod_accesslog" )
10568 -server.indexfiles = ( "index.php", "index.html",
10569 - "index.htm", "default.htm" )
10572 -######################## MODULE CONFIG ############################
10574 -ssi.extension = ( ".shtml" )
10576 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10578 -mimetype.assign = ( ".png" => "image/png",
10579 - ".jpg" => "image/jpeg",
10580 - ".jpeg" => "image/jpeg",
10581 - ".gif" => "image/gif",
10582 - ".html" => "text/html",
10583 - ".htm" => "text/html",
10584 - ".pdf" => "application/pdf",
10585 - ".swf" => "application/x-shockwave-flash",
10586 - ".spl" => "application/futuresplash",
10587 - ".txt" => "text/plain",
10588 - ".tar.gz" => "application/x-tgz",
10589 - ".tgz" => "application/x-tgz",
10590 - ".gz" => "application/x-gzip",
10591 - ".c" => "text/plain",
10592 - ".conf" => "text/plain" )
10593 +setenv.add-request-header = ( "FOO" => "foo")
10594 +setenv.add-response-header = ( "BAR" => "foo")
10596 $HTTP["host"] == "cache.example.org" {
10597 - compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
10598 + compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
10600 -compress.filetype = ("text/plain", "text/html")
10602 -setenv.add-environment = ( "TRAC_ENV" => "tracenv", "SETENV" => "setenv")
10603 -setenv.add-request-header = ( "FOO" => "foo")
10604 -setenv.add-response-header = ( "BAR" => "foo")
10606 $HTTP["url"] =~ "\.pdf$" {
10607 server.range-requests = "disable"
10608 @@ -85,76 +23,31 @@
10609 "/prefix.fcgi" => ( ( "host" => "127.0.0.1", "port" => 1026, "check-local" => "disable", "broken-scriptfilename" => "enable" ) )
10613 -cgi.assign = ( ".pl" => "/usr/bin/perl",
10614 - ".cgi" => "/usr/bin/perl",
10615 - ".py" => "/usr/bin/python" )
10617 -userdir.include-user = ( "jan" )
10618 -userdir.path = "/"
10620 -ssl.engine = "disable"
10621 -ssl.pemfile = "server.pem"
10623 $HTTP["host"] == "auth-htpasswd.example.org" {
10624 auth.backend = "htpasswd"
10627 -auth.backend = "plain"
10628 -auth.backend.plain.userfile = "@SRCDIR@/tmp/lighttpd/lighttpd.user"
10630 -auth.backend.htpasswd.userfile = "@SRCDIR@/tmp/lighttpd/lighttpd.htpasswd"
10633 -auth.require = ( "/server-status" =>
10635 - "method" => "digest",
10636 - "realm" => "download archiv",
10637 - "require" => "group=www|user=jan|host=192.168.2.10"
10639 - "/server-config" =>
10641 - "method" => "basic",
10642 - "realm" => "download archiv",
10643 - "require" => "valid-user"
10647 -url.access-deny = ( "~", ".inc")
10649 -url.rewrite = ( "^/rewrite/foo($|\?.+)" => "/indexfile/rewrite.php$1",
10650 - "^/rewrite/bar(?:$|\?(.+))" => "/indexfile/rewrite.php?bar&$1" )
10652 -expire.url = ( "/expire/access" => "access 2 hours",
10653 - "/expire/modification" => "access plus 1 seconds 2 minutes")
10655 -#cache.cache-dir = "/home/weigon/wwwroot/cache/"
10657 -#### status module
10658 -status.status-url = "/server-status"
10659 -status.config-url = "/server-config"
10661 $HTTP["host"] == "vvv.example.org" {
10662 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10663 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10664 secdownload.secret = "verysecret"
10665 - secdownload.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10666 + secdownload.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10667 secdownload.uri-prefix = "/sec/"
10668 secdownload.timeout = 120
10671 $HTTP["host"] == "zzz.example.org" {
10672 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10673 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10674 server.name = "zzz.example.org"
10677 $HTTP["host"] == "no-simple.example.org" {
10678 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/123.example.org/pages/"
10679 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/123.example.org/pages/"
10680 server.name = "zzz.example.org"
10683 $HTTP["host"] !~ "(no-simple\.example\.org)" {
10684 simple-vhost.document-root = "pages"
10685 - simple-vhost.server-root = "@SRCDIR@/tmp/lighttpd/servers/"
10686 + simple-vhost.server-root = env.SRCDIR + "/tmp/lighttpd/servers/"
10687 simple-vhost.default-host = "www.example.org"
10690 --- lighttpd-1.4.11/tests/mod-fastcgi.t 2006-03-09 15:30:45.000000000 +0200
10691 +++ lighttpd/tests/mod-fastcgi.t 2006-07-11 21:23:41.995974736 +0300
10696 -use Test::More tests => 47;
10697 +use Test::More tests => 49;
10700 my $tf = LightyTest->new();
10705 - skip "no PHP running on port 1026", 30 unless $tf->listening_on(1026);
10706 + skip "no PHP running on port 1026", 29 unless $tf->listening_on(1026);
10708 ok($tf->start_proc == 0, "Starting lighttpd") or die();
10710 @@ -285,6 +285,34 @@
10711 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
10712 ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
10714 + # X-LIGHTTPD-send-file
10715 + $t->{REQUEST} = ( <<EOF
10716 +GET /index.fcgi?x-lighttpd-send-file HTTP/1.0
10717 +Host: www.example.org
10720 + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '<?php phpinfo(); ?>
10722 + ok($tf->handle_http($t) == 0, 'X-LIGHTTPD-send-file');
10724 + $t->{REQUEST} = ( <<EOF
10725 +GET /index.fcgi?xsendfile HTTP/1.0
10726 +Host: www.example.org
10729 + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '<?php phpinfo(); ?>
10731 + ok($tf->handle_http($t) == 0, 'X-Sendfile');
10733 + $t->{REQUEST} = ( <<EOF
10734 +GET /index.fcgi?xsendfile-mixed-case HTTP/1.0
10735 +Host: www.example.org
10738 + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '<?php phpinfo(); ?>
10740 + ok($tf->handle_http($t) == 0, 'X-SeNdFiLe in mixed case');
10742 $t->{REQUEST} = ( <<EOF
10743 GET /index.fcgi?die-at-end HTTP/1.0
10744 Host: www.example.org
10745 --- lighttpd-1.4.11/tests/var-include.conf 2005-08-27 17:44:19.000000000 +0300
10746 +++ lighttpd/tests/var-include.conf 2006-07-11 21:23:41.943971479 +0300
10748 debug.log-request-handling = "enable"
10749 debug.log-condition-handling = "enable"
10751 -server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10752 -server.pid-file = "@SRCDIR@/tmp/lighttpd/lighttpd.pid"
10753 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10754 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
10756 ## bind to port (default: 80)
10759 ## bind to localhost (default: all interfaces)
10760 server.bind = "localhost"
10761 -server.errorlog = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.error.log"
10762 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
10763 server.name = "www.example.org"
10764 server.tag = "Apache 1.3.29"
10766 @@ -21,19 +21,19 @@
10767 ######################## MODULE CONFIG ############################
10770 -accesslog.filename = "@SRCDIR@/tmp/lighttpd/logs/lighttpd.access.log"
10771 +accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
10773 mimetype.assign = ( ".html" => "text/html" )
10775 url.redirect = ("^" => "/default")
10777 $HTTP["host"] == "www.example.org" {
10778 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10779 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10780 server.name = "www.example.org"
10781 url.redirect = ("^" => "/redirect")
10783 $HTTP["host"] == "test.example.org" {
10784 - server.document-root = "@SRCDIR@/tmp/lighttpd/servers/www.example.org/pages/"
10785 + server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
10786 server.name = "test.example.org"