Commit Graph

50 Commits

Author SHA1 Message Date
Glenn Strauss 7c7f8c467c [multiple] split con, request (very large change)
NB: r->tmp_buf == srv->tmp_buf (pointer is copied for quicker access)

NB: request read and write chunkqueues currently point to connection
    chunkqueues; per-request and per-connection chunkqueues are
    not distinct from one another
      con->read_queue  == r->read_queue
      con->write_queue == r->write_queue

NB: in the future, a separate connection config may be needed for
    connection-level module hooks.  Similarly, might need to have
    per-request chunkqueues separate from per-connection chunkqueues.
    Should probably also have a request_reset() which is distinct from
2020-07-08 19:54:29 -04:00
Glenn Strauss 8131e4396d [core] move addtl request-specific struct members 2020-07-08 19:54:29 -04:00
Glenn Strauss 1474be7859 [core] move addtl request-specific struct members 2020-07-08 19:54:29 -04:00
Glenn Strauss 010c28949c [multiple] prefer (connection *) to (srv *)
convert all log_error_write() to log_error() and pass (log_error_st *)

use con->errh in preference to srv->errh (even though currently same)

avoid passing (server *) when previously used only for logging (errh)
2020-07-08 19:54:28 -04:00
Glenn Strauss 4b0c9c9853 [mod_cml] use config_plugin_values_init() 2020-05-23 17:59:30 -04:00
Glenn Strauss 6eb34ef5ab [core] add const to callers of http_header_*_get()
(The few places where value is modified in-place were not made const)
2020-02-24 11:15:32 -05:00
Glenn Strauss 37bd124ae4 [core] pass conf.follow_symlink in more places 2019-03-10 23:22:58 -04:00
Glenn Strauss 685f4ed62c [mod_cml,mod_flv_streaming] fix NULL ptr deref
fix possible NULL pointer dereference when query string not present
and no previous query strings processed by that specific connection

regression in lighttpd 1.4.51 (mod_flv_streaming)
regression in lighttpd 1.4.52 (mod_cml)

workaround for mod_flv_streaming:
  url.rewrite-once = ( "\.flv$" => "${url.path}?" )
(similar workaround for mod_cml)

(thx fab)

  "segfault with mod_flv_streaming"
2018-12-02 00:52:11 -05:00
Glenn Strauss cced512116 [mod_cml] parse query string without modifying it 2018-11-25 19:52:08 -05:00
Glenn Strauss f69bd9cdb8 [core] perf: simple, quick buffer_clear()
quickly clear buffer instead of buffer_string_set_length(b, 0) or
buffer_reset(b).  Avoids free() of large buffers about to be reused,
or buffers that are module-scoped, persistent, and reused.

(buffer_reset() should still be used with buffers in connection *con
 when the data in the buffers is supplied by external, untrusted source)
2018-11-23 00:37:38 -05:00
Glenn Strauss 3dd3cde902 [core] abstraction layer for HTTP header manip
convert existing calls to manip request/response headers
convert existing calls to manip environment array (often header-related)
2018-09-23 18:01:58 -04:00
Glenn Strauss 04d76e7afd [core] some header cleanup
provide standard types in first.h instead of base.h
provide lighttpd types in base_decls.h instead of settings.h
reduce headers exposed by headers for core data structures
  do not expose <pcre.h> or <stdlib.h> in headers
move stat_cache_entry to stat_cache.h
reduce use of "server.h" and "base.h" in headers
2018-04-08 22:22:23 -04:00
Glenn Strauss a53f662a30 [core] remove some unused header includes
remove exposure of stdio.h in buffer.h for print_backtrace(), now static
2017-03-28 02:17:33 -04:00
Glenn Strauss 445bc2914a [mod_cml] include lua headers before base.h
to avoid (historical) conflict with IN and OUT macros used in lua
and openssl headers (since base.h includes openssl headers when present)
2016-12-05 17:47:35 -05:00
Glenn Strauss 431bc346df remove #include "stream.h" where not used 2016-12-05 17:43:59 -05:00
Glenn Strauss ac90699d28 [autobuild] rm module stub code for missing deps
remove module stub code since the build system(s) no longer build any
module when the dependencies for a given module are not present.
2016-10-17 14:15:50 -04:00
Glenn Strauss a0a7b9fbf5 [mod_ssi, mod_cml] set DOCUMENT_ROOT to basedir (fixes #2383)
fixes inconsistency w/ mod_fastcgi, mod_scgi, mod_cgi change in adc97e5b

  "mod_alias: use alias directory as doc-root too"
  "mod_userdir doesn't set environment variable DOCUMENT_ROOT"
2016-05-02 14:31:36 -04:00
Glenn Strauss a65c57a548 [core] open fd when appending file to cq (fixes #2655)
http_chunk_append_file() opens fd when appending file to chunkqueue.
Defers calculation of content length until response is finished.

This reduces race conditions pertaining to stat() and then (later)
open(), when the result of the stat() was used for Content-Length
or to generate chunked headers.

Note: this does not change how lighttpd handles files that are modified
in-place by another process after having been opened by lighttpd --
don't do that.  This *does* improve handling of files that are
frequently modified via a temporary file and then atomically renamed
into place.

mod_fastcgi has been modified to use http_chunk_append_file_range() with
X-Sendfile2 and will open the target file multiple times if there are
multiple ranges.

Note: (future todo) not implemented for chunk.[ch] interfaces used by
range requests in mod_staticfile or by mod_ssi.  Those uses could lead
to too many open fds.  For mod_staticfile, limits should be put in place
for max number of ranges accepted by mod_staticfile.  For mod_ssi,
limits would need to be placed on the maximum number of includes, and
the primary SSI file split across lots of SSI directives should either
copy the pieces or perhaps chunk.h could be extended to allow for an
open fd to be shared across multiple chunks.  Doing either of these
would improve the performance of SSI since they would replace many file
opens on the pieces of the SSI file around the SSI directives.

  "Serving a file that is getting updated can cause an empty response or incorrect content-length error"

Closes #49
2016-04-18 04:27:08 -04:00
Glenn Strauss 8abd06a7ff consistent inclusion of config.h at top of files (fixes #2073)
From: Glenn Strauss <>

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-03-19 15:14:35 +00:00
Stefan Bühler f3b577ddee use libmemcached instead of deprecated libmemcache
Differential Revision:

From: Stefan Bühler <>

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-01-03 14:48:11 +00:00
Stefan Bühler c354229f42 add handling for lua 5.2 and 5.3 (fixes #2674)
Reviewers: stbuehler

Differential Revision:

From: Stefan Bühler <>

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2016-01-03 14:48:09 +00:00
Stefan Bühler ad3e93ea96 Use buffer API to read and modify "used" member
- a lot of code tried to handle manually adding terminating zeroes and
  keeping track of the correct "used" count.
  Replaced all "external" usages with simple wrapper functions:
  * buffer_string_is_empty (used <= 1), buffer_is_empty (used == 0);
    prefer buffer_string_is_empty
  * buffer_string_set_length
  * buffer_string_length
  * CONST_BUF_LEN() macro
- removed "static" buffer hacks (buffers pointing to constant/stack
  memory instead of malloc()ed data)
- buffer_append_strftime(): refactor buffer+strftime uses
- li_tohex(): no need for a buffer for binary-to-hex conversion:
  the output data length is easy to predict
- remove "-Winline" from extra warnings: the "inline" keyword just
  supresses the warning about unused but defined (static) functions;
  don't care whether it actually gets inlined or not.

From: Stefan Bühler <>

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-08 19:10:44 +00:00
Stefan Bühler 6afad87d2e fix buffer, chunk and http_chunk API
* remove unused structs and functions
    (buffer_array, read_buffer)
  * change return type from int to void for many functions,
    as the return value (indicating error/success) was never checked,
    and the function would only fail on programming errors and not on
    invalid input; changed functions to use force_assert instead of
    returning an error.
  * all "len" parameters now are the real size of the memory to be read.
    the length of strings is given always without the terminating 0.
  * the "buffer" struct still counts the terminating 0 in ->used,
    provide buffer_string_length() to get the length of a string in a
    unset config "strings" have used == 0, which is used in some places
    to distinguish unset values from "" (empty string) values.
  * most buffer usages should now use it as string container.
  * optimise some buffer copying by "moving" data to other buffers
  * use (u)intmax_t for generic int-to-string functions
  * remove unused enum values: UNUSED_CHUNK, ENCODING_UNSET
  * converted BUFFER_APPEND_SLASH to inline function (no macro feature
  * refactor: create chunkqueue_steal: moving (partial) chunks into another
  * http_chunk: added separate function to terminate chunked body instead of
    magic handling in http_chunk_append_mem().
    http_chunk_append_* now handle empty chunks, and never terminate the
    chunked body.

From: Stefan Bühler <>

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2015-02-08 12:37:10 +00:00
Stefan Bühler 57c661c191 fix unchecked return values from stream_open/stat_cache_get_entry
From: Stefan Bühler <>

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-16 13:08:34 +00:00
Stefan Bühler ef0b353fee [mod_cml_lua] fix null pointer dereference
a local lua script could trigger it by not sending any files and not
  setting a last-modified header, leading to zero mtime and a buffer
  ptr = NULL which was used in http_response_handle_cachable

From: Stefan Bühler <>

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-16 13:08:27 +00:00
Stefan Bühler 07dd0bd0a5 add force_assert() to enforce assertions as simple assert()s are disabled by -DNDEBUG (fixes #2546)
From: Stefan Bühler <>

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2014-02-16 13:08:20 +00:00
Stefan Bühler 90dd8af32b Always use our 'own' md5 implementation, fixes linking issues on MacOS (fixes #2331)
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2011-07-30 09:16:03 +00:00
Stefan Bühler c66d21bc2b [md5] fix md5 includes if openssl is not available (#2269)
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2011-04-24 16:14:54 +00:00
Stefan Bühler 22e8b456a9 Fix header inclusion order, always include "config.h" before any system header
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-10-11 14:31:42 +00:00
Stefan Bühler f5fccea003 Fix missing header <string.h> in mod_cml_lua.c
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-07-10 16:22:39 +00:00
Stefan Bühler 63f785a2f8 Added some extra warning options in cmake and fix the resulting warnings (unused/static functions)
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-03-07 21:05:37 +00:00
Stefan Bühler 76f7b9543d Fix wrong lua type for CACHE_MISS/CACHE_HIT in mod_cml (fixes #533)
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2009-02-17 13:38:22 +00:00
Marcus Rückert 8cd1471cb3 - white space cleanup part 2 this time 1.4 ;)
i hope it helps with merging stuff back to 1.5

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-10-04 13:26:23 +00:00
Marcus Rückert 15fde9cf07 - mark a few parameters as unused
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-10-03 22:15:55 +00:00
Jan Kneschke 9ddae28ab5 removed duplicate lua-load calls which crash lua 5.0
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-21 13:31:55 +00:00
Jan Kneschke 08c093b940 fixed mod_cml + lua 5.1
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-15 12:52:53 +00:00
Jan Kneschke 1b47e99a34 luaL_newstate() is from lauxlib.h, #include it
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-09-14 11:55:26 +00:00
Jan Kneschke ca33bec31a - removed the session-id code
- prepared exporting cookies to cml
- CACHE_HIT and _MISS are booleans now

git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2006-01-31 10:57:36 +00:00
Jan Kneschke 44cef4913a added the power-magnet to mod_cml
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-12-29 12:16:10 +00:00
Jan Kneschke a4be52451f more unsigned/sign compare fixes
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-11-18 12:00:48 +00:00
Jan Kneschke 62d8d1ef53 fixed md5 on 64bit platforms
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-11-17 14:39:07 +00:00
Jan Kneschke 5ae22303f4 fixed last-modified handling and handle absolute path names correctly (fixed #244)
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-09-02 13:30:44 +00:00
Jan Kneschke e45388fc44 added file_isdir
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-08-31 23:06:59 +00:00
Jan Kneschke 9dd464a72b moved last-modifed handling to response.c and let mod_cml_lua.c use it.
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-08-31 13:39:09 +00:00
Jan Kneschke fdfaf11367 added CACHE_HIT and CACHE_MISS (#187)
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-07-31 11:58:49 +00:00
Jan Kneschke d576e0ad64 added functions file_isreg() and dir_files() and added last-modified handling
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-07-24 06:58:03 +00:00
Jan Kneschke b4b428f482 fixed typo
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-07-23 20:42:08 +00:00
Jan Kneschke ab054446f4 moved last-modified handling into a exported function and let mod_cml use it
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-07-23 20:30:54 +00:00
Jan Kneschke 5d1792ad71 removed debug
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-07-16 11:35:05 +00:00
Jan Kneschke d30d9ca055 those are in the release .15
git-svn-id: svn:// 152afb58-edef-0310-8abb-c4023f1b3aa9
2005-07-16 11:33:10 +00:00