Commit Graph

  • 27a35821a1 wwwroot = strdup(argv[1]) so we don't end up stripping the only existing slash out of the commandline shown by ps(1). And free it on shutdown. Emil Mikulic 2003-12-13 14:11:49 +00:00
  • e18f533945 . Tell people to use Makefile for building. . Make a few things clearer by improving examples. Emil Mikulic 2003-12-13 14:09:05 +00:00
  • af46f81440 User specifies platform, like mpg123. Emil Mikulic 2003-12-13 14:08:36 +00:00
  • 108eb4cce3 . Split usage() into many printfs() to keep GCC3 happy about ISO limits. . Knock out the REPLY_GENERATED length assertion since ap_buf doesn't null-terminate strings and it's never been tripped by xasprintf() consumers. . Cast rusage times when printing, and don't print too many zeroes. Emil Mikulic 2003-12-13 08:56:05 +00:00
  • ecb3d8adb3 Optimize generate_dir_listing(): . Split appendf() calls into a number of append() calls. . To insert spaces, instead of sitting in a loop, use a spaces[] buffer and insert a chunk of it with appendl(). Emil Mikulic 2003-12-13 08:45:06 +00:00
  • 4ce4eabdbd . Version upped to 1.1 for append buffer optimizations. . Don't keep the apbuf strings null-terminated. . Compile-time optimise append() if we have GCC. Emil Mikulic 2003-12-13 08:42:34 +00:00
  • fd4e271d57 Before exiting, getrusage() and print time spent on CPU. Emil Mikulic 2003-12-13 07:50:16 +00:00
  • 0f798c0d71 Merge two lines. Emil Mikulic 2003-12-13 07:37:52 +00:00
  • b2e4f924b9 NDEBUG gets defined in the source file. Emil Mikulic 2003-12-13 07:24:43 +00:00
  • 020b4d20e2 Fix whitespace and disclaimer comment. Emil Mikulic 2003-12-13 06:27:03 +00:00
  • 84e59c72ac Use FALLTHROUGH instead of goto. Emil Mikulic 2003-12-03 09:39:16 +00:00
  • 1623dee16a Initial revision - this and the source are the only files in the 1.0 tarball. Emil Mikulic 2003-11-30 13:22:04 +00:00
  • 6ab21a586e . Don't expect user to define NDEBUG. Emil Mikulic 2003-11-30 11:31:40 +00:00
  • 761462e4e5 . __sun__ -> __sun since Sun's CC doesn't use the former. Emil Mikulic 2003-11-30 11:30:20 +00:00
  • 7df4b55839 . Fix chomp()'s checking of empty strings. Emil Mikulic 2003-11-30 11:04:37 +00:00
  • c58880c10a . Added third BSD clause. . Got rid of Solaris hint - it belongs in the README. . Got rid of a tab. Emil Mikulic 2003-11-30 04:46:06 +00:00
  • b175db347d . Added --accf instead of compile-time NO_ACCEPTFILTER. . Fixed const issues in dlent_cmp(). . Fixed uninitialized from/to warning. Emil Mikulic 2003-11-29 07:36:01 +00:00
  • 36f027c8c8 Fix two memory leaks. Emil Mikulic 2003-11-28 05:26:31 +00:00
  • a4be99dc3f . USE_ACCEPTFILTER -> NO_ACCEPTFILTER and document it. Emil Mikulic 2003-11-28 05:12:43 +00:00
  • a0dddaf19a . Add USE_ACCEPTFILTER knob. . debugf() sweep - turn non-verbose ones into printf()s Emil Mikulic 2003-11-28 05:08:21 +00:00
  • 3f6c57ca70 -DNDEBUG Emil Mikulic 2003-11-28 05:08:21 +00:00
  • a4347fa196 . Added BSD license. . Version is now 1.0. . Display [!]NDEBUG in --version output. Emil Mikulic 2003-11-28 04:26:56 +00:00
  • 01f231eaea . -O won't hurt, and it catches uninitialized vars. Emil Mikulic 2003-11-28 04:08:47 +00:00
  • 3e378caaf0 . Implemented apbuf API. . Reworked generate_dir_listing() to use apbuf - much nicer now. Emil Mikulic 2003-11-27 13:04:08 +00:00
  • 2776f8c35e . Cosmetics in mime_mapping_cmp(). . Added make_sorted_dirlist(), cleanup_sorted_dirlist(). . generate_dir_listing() works better and produces sorted output, but still looks awful. Emil Mikulic 2003-11-27 12:20:55 +00:00
  • 3dbf2f15b4 . Got rid of pretty top-of-file. . Moved $Id$ into static rcsid[]. . Preened TODO list. . Removed LIST_EMPTY() - it wasn't being used. . Got rid of "mapping x -> y" debugf. . Move exit() out of usage() and into caller to make program flow more obvious. . Added --version handling that prints rcsid. Emil Mikulic 2003-11-27 10:52:43 +00:00
  • fb2e40cae5 . Added file_exists(). . Added skeleton for generate_dir_listing(). . Tied it into process_get(). Emil Mikulic 2003-11-27 10:37:02 +00:00
  • 917e7a2cc4 . De-constify offset for Linux. Emil Mikulic 2003-11-27 10:12:09 +00:00
  • 132757b8fe . Do a non-blocking open and only stat once. Emil Mikulic 2003-11-27 10:07:25 +00:00
  • 7abf59ea32 . Removed test_make_safe_uri(). Emil Mikulic 2003-11-27 08:04:19 +00:00
  • 19f70a46a9 . Added xclose(). . Changed reply_file from FILE to a file descriptor - using regular syscalls instead of stdio f* calls. Emil Mikulic 2003-11-27 08:03:36 +00:00
  • 6312e230fb . Implement chroot. Emil Mikulic 2003-11-27 05:45:43 +00:00
  • 45ac8883e0 . Correct order of checking name and id for --uid and --gid. Emil Mikulic 2003-11-27 05:18:00 +00:00
  • 7ef872fd6a Added handling of --uid. Emil Mikulic 2003-11-27 05:14:55 +00:00
  • b5f0992e7e . Added str_to_num(). . Added handling of --uid. Emil Mikulic 2003-11-27 05:10:20 +00:00
  • b2b6d75a05 . In NDEBUG, safefree() is just free(). . Originally there were three places where a pointer was NULL'd after being freed. One of these is actually important, so annotate it. Emil Mikulic 2003-11-24 12:21:33 +00:00
  • 7014380256 Cosmetics. Emil Mikulic 2003-11-24 12:09:08 +00:00
  • 850543f7d6 . Patch up a leak by freeing target when needed. Emil Mikulic 2003-11-24 11:54:34 +00:00
  • 832851b83d . Add safefree(x) macro to set x to NULL after freeing. Emil Mikulic 2003-11-24 11:48:49 +00:00
  • e74bb5a077 . Added redirect(). . Moved 404 reply up to stat() section. . Redirect /dir to /dir/ . Separate permissions (403 Forbidden) from other fopen() failures (500 Internal Server Error) Emil Mikulic 2003-11-24 11:44:22 +00:00
  • eee798c571 . stat() the file before opening it to avoid opening FIFOs, sockets, etc. Emil Mikulic 2003-11-24 11:24:26 +00:00
  • db6517c62d . Use goto instead of code duplication. Emil Mikulic 2003-11-24 11:11:20 +00:00
  • 5563889b66 Make keep_alive() a macro instead of a tiny function. Emil Mikulic 2003-11-22 13:16:13 +00:00
  • df4f6910de send_from_file(): Use sendfile() on Linux. Emil Mikulic 2003-11-22 13:10:57 +00:00
  • 8f4a5e6b60 . Split file sending into send_from_file(). . Optimize it with sendfile() on FreeBSD. Emil Mikulic 2003-11-22 12:56:46 +00:00
  • e127c6acda make_safe_uri() improvements. Emil Mikulic 2003-11-22 12:22:14 +00:00
  • b082fa213f Faster, simpler, not yet completely correct reimplementation of make_safe_uri(). It still has a lot of debugging cruft inside. Emil Mikulic 2003-11-22 12:09:56 +00:00
  • b2f504f975 . Add consolidate_slashes(). . make_safe_uri() may modify the URI string given to it. . SAFE() and UNSAFE() don't pass const strings to make_safe_uri(). Emil Mikulic 2003-11-22 11:29:44 +00:00
  • 41d2f5867a Solaris compatibility fixes. Emil Mikulic 2003-11-18 12:33:02 +00:00
  • 466de20e2e . Cosmetics. Emil Mikulic 2003-11-18 11:33:08 +00:00
  • 255a78d0c4 . strip_endslash() should not have been reallocating argv[1] . Remove strip_endslash() by boiling it down to one line and putting that line where the function call used to be. Emil Mikulic 2003-11-18 11:05:03 +00:00
  • f7c0995234 . Don't need to nonblock the listening socket. . Use acceptfilter. Emil Mikulic 2003-11-18 11:00:08 +00:00
  • f0766d80f3 . Don't kill the whole server if recv() error occurs. . Set conn_close to 1 on error to ensure connection closure. Emil Mikulic 2003-11-18 10:32:11 +00:00
  • 376c8b29fb . Make parse_request return int so it can return failure on malformed requests. . Make it bomb out on malformed requests like "moo\r\n\r\n" Emil Mikulic 2003-11-18 10:19:29 +00:00
  • 00fea650ed . IDLETIME -> idletime . Construct keep_alive_field from idletime. . Send keep_alive_field when there's no `Connection: close' Emil Mikulic 2003-11-18 10:09:43 +00:00
  • dd4a217817 Fix conn->close logic: . HTTP/1.1 protocol enables keep-alive. . Connection: keep-alive' enables keep-alive, regardless of protocol. . Connection: close' disables keep-alive. Emil Mikulic 2003-11-18 09:38:45 +00:00
  • 3389cc39d4 . Keep-alive connections work now. . free_connection() now calls log_connection() for us. . keepalive_connection() -> recycle_connection(). . recycle_connection() calls free_connection() (results in logging). . Don't reset conn->client in recycle. . Before main select loop, recycle keep-alive DONE connections. Emil Mikulic 2003-11-18 09:32:39 +00:00
  • a07492c1a8 . In poll_send_{header,reply}(), don't bother deallocating stuff that free_connection will deallocate anyway. Emil Mikulic 2003-11-18 09:22:33 +00:00
  • 2080b05d4c Starting work on Keep-Alive: . Added conn_close to struct connection. 0 = Keep-Alive, 1 = Connection: close . Added keepalive_connection() for recycling connection structs. . Made "Connection: close\r\n" in reply headers optional. . If protocol is HTTP/1.1, use Keep-Alive, unless Connection: close is given in the request. Emil Mikulic 2003-11-18 09:16:27 +00:00
  • 1e3b874dca Import LIST_FOREACH_SAFE macro from FreeBSD. Emil Mikulic 2003-11-18 08:28:33 +00:00
  • 34db7c9e68 . Traditional C sucks. Emil Mikulic 2003-11-18 08:07:51 +00:00
  • f246f24acb . Remove expand_tilde(). . Remove commented-out SIGINT/SIGQUIT handling. Emil Mikulic 2003-11-18 07:22:51 +00:00
  • e70a830c2c . Add TODO reminders. . Optimize string reassembly in make_safe_uri(). Emil Mikulic 2003-11-18 07:14:00 +00:00
  • 8a05f349d8 . Fix assertions in split_string(). . Don't split_string() outside of the string in make_safe_uri() . Added test_make_safe_uri(), called from main() Emil Mikulic 2003-11-18 06:41:07 +00:00
  • f65f8520a0 . More assertions in split_string(). . Make some empty for() loops more obvious. . Missed a 0 -> '\0' last time. . err(EXIT_FAILURE, ...) -> err(1, ...) to retain existing style. . Annotate default_extension_map[] - it must be NULL terminated. . Don't expand_tilde() -- unsure about this. Emil Mikulic 2003-11-17 13:02:32 +00:00
  • 9988849ea7 Change 0 to '\0' in a character context. Emil Mikulic 2003-11-17 12:46:03 +00:00
  • 813d4463bc . Add read_line() and chomp(). . Greatly simplify parse_extension_map_file(). Emil Mikulic 2003-11-17 12:42:42 +00:00
  • a4740dfda2 . Uncast xmalloc() and xrealloc() returns. . Changed #if IDLETIME' to if (IDLETIME)' - it will be optimized away by the compiler. . Some casts and an int->size_t change to keep splint happy about integer types. Emil Mikulic 2003-11-15 05:16:19 +00:00
  • b1b9432123 Changes to comments that have been waiting since Aug 4 07:54. Emil Mikulic 2003-11-15 04:41:17 +00:00
  • 6bb5b5af42 . Make mime_map a sorted array instead of a LIST_. . Added add_mime_mapping() to add to mime_map in unsorted order. . Added sort_mime_map() - uses qsort() and mime_mapping_cmp() to sort the mime_map. . uri_content_type() uses bsearch() and mime_mapping_cmp_str() to search through the mime_map for an extension parsed out of a specified URI. . Free mime_map in exit_quickly() . Completely deallocate connlist in exit_quickly() . In main(), parse_commandline() after parse_default_extension_map() so that a specified --mimetypes file will -override- the defaults. Emil Mikulic 2003-06-30 02:11:24 +00:00
  • f56dcd2b76 Borged parts of sys/queue.h since non-BSDs don't have the header. Emil Mikulic 2003-06-28 04:13:19 +00:00
  • 9d6d7533fe . Linux needs _GNU_SOURCE defined. . bindport is uint16_t like in Linux. . Fix a bounds error in make_safe_uri(). . Remember to free temporaries in make_safe_uri(). . Free if_mod_since in process_get() . Set reply_file to NULL after closing it in poll_send_reply() to avoid double fclose() in free_connection(). . Don't log connections with http_code == 0; these are connections that failed while receiving the request string. . Initialise timeout more cleanly in httpd_poll(). . Made MAX_FD_SET use a { block } to keep gcc 3 happy. . Don't free items in a LIST_FOREACH() block; use a temporary next pointer and LIST_NEXT(). . exit_quickly() closes logfile if it's open. . exit_quickly() doesn't re-throw the signal that triggered it. Emil Mikulic 2003-06-27 08:16:48 +00:00
  • d7bfc32d6d . Partial content is done, mark off TODO. . Decrease send BUFSIZE to 40,000 (max I've seen is 33,000). . Remove a debugf() from poll_send_reply(). . Add exit_quickly(). . SIGINT and SIGQUIT exit_quickly(). Emil Mikulic 2003-06-27 07:01:28 +00:00
  • 67604878ec . Initialise range_* in struct connection. . Added reply_start to struct connection. . Added debugf() to free_connection(). . Construct HTTP 206 reply if Range specified. . Take reply_start into consideration in poll_send_reply(). . Added fread() error handling - eof is non-fatal. Emil Mikulic 2003-06-27 06:42:42 +00:00
  • 295cd40bbb int type fixes to keep splint happy. Emil Mikulic 2003-06-27 05:38:10 +00:00
  • 7090baae35 . Added range fields to struct connection. . Added sanity check in split_string(): left <= right . Implemented parse_range_field() Emil Mikulic 2003-06-27 05:31:55 +00:00
  • 6ee7a85231 . Got rid of conn->lastmod field. . rfc1123_date() takes a destination buffer instead of having the one, static, global buffer. Emil Mikulic 2003-06-07 00:51:57 +00:00
  • 6e0103cbc4 Fiddling with signed-ness and types to make splint happy. Emil Mikulic 2003-06-07 00:09:53 +00:00
  • 0c1ff8a258 Cleared up parse_field() synopsis. Emil Mikulic 2003-06-06 21:08:54 +00:00
  • 3dc4ce1216 . Made all sockets non-blocking . Used simpler way of ignoring SIGPIPE . Made sure closed sockets aren't written to Emil Mikulic 2003-06-04 16:07:01 +00:00
  • 70cbd12463 . Tested If-Modified-Since functionality . Update last_active so connections don't time out (this also tested out the timeout functionality) . Sprinkling of debugf()s Emil Mikulic 2003-06-04 14:56:29 +00:00
  • ce7cfceabb Worked out warning flags from gcc manpage Emil Mikulic 2003-06-04 14:29:28 +00:00
  • 0d755c3618 . Added ogg mimetype . Added xvasprintf() . Added xasprintf() . Some signed/unsigned clarifications . Simplified asprintf() error handling using xasprintf() . Check for failure of signal() Emil Mikulic 2003-06-04 14:29:28 +00:00
  • 5a6c7cf08e . Added lastmod (reply, not request) to struct connection . Added xstrdup() . Made expand_tilde use xstrdup() instead of strdup() (whoops) . process_get() now handles "If-Modified-Since:" . lastmod is generated before Date: so that only one asprintf() is needed to construct the header in process_get() Emil Mikulic 2003-03-08 11:54:58 +00:00
  • 72d0b5b301 . Use reasm instead of checking for a NULL reassembly element (safer) Emil Mikulic 2003-03-08 11:33:17 +00:00
  • ce5eaa9f94 . Made split_string() return a string instead of taking char **dest . Added make_safe_uri() . Modified split_string() calls to match new prototype . process_get() uses make_safe_uri() to prevent walking out of wwwroot . free(target) AFTER we finish using it in process_get (whoops) Emil Mikulic 2003-03-08 11:30:14 +00:00
  • 5c0c18798c . Content-Type is now derived from mime_map . Reordered default_extension_map[] for search speed . Added uri_content_type() . process_get() calls uri_content_type() when needed . Removed a couple of debugf()s from process_request Emil Mikulic 2003-03-08 08:33:24 +00:00
  • 7a2daecf22 . Added debugf() to parse_mimetype_line() . Added parse_extension_map_file() . Added --mimetypes to usage() and parse_commandline() Emil Mikulic 2003-03-08 05:43:20 +00:00
  • a0d608d1e3 . Added LIST mime_map . Added struct mime_mapping . Added default_extension_map[] . Moved xmalloc() to top of file . Added split_string() . Added parse_mimetype_line() . Added parse_default_extension_map() . Made new_connection(), parse_request() use split_string() . Comment in log_connection(): client -> client_ip Emil Mikulic 2003-03-08 04:58:07 +00:00
  • d6b7871ade . TODO: dir entries -> dir listings . TODO: minor cleanup . --help as first parameter results in usage() Emil Mikulic 2003-03-07 08:25:04 +00:00
  • 7c29be2b7d . Added referer, user_agent to struct connection . Moved xrealloc() to top of file . Added parse_field() . parse_request() calls parse_field() for referer, ua . Logfile is opened in append mode, not write mode . strip_endslash() calls xrealloc(), not realloc() Emil Mikulic 2003-03-07 08:10:03 +00:00
  • aa2245e867 . Added expand_tilde() . Added strip_endslash() . wwwroot gets its tilde expanded and trailing slash clipped off Emil Mikulic 2003-03-07 05:58:35 +00:00
  • f5703a9c82 . Added TODO entries . Minor whitespace fixes Emil Mikulic 2003-03-07 02:35:27 +00:00
  • 09d69063bd . Ignoring SIGPIPE . httpd_poll()'s select() will timeout after IDLETIME seconds if there are any connections currently in a send/recv state Emil Mikulic 2003-03-01 10:10:27 +00:00
  • 4456c044e5 . Implemented logging to file . Moved parse_request's {method|url} to conn->{method|uri} . Added http_code, total_sent to struct connection . Added out-of-memory checks on a few asprintf()s . Added assert()s where I tripped up before or could again . Added log_connection() . Open logfile from logfile_name in main() Emil Mikulic 2003-03-01 10:00:06 +00:00
  • 02964cc5a6 . TODO: Added If-Modified-Since . TODO: Marked off Actually serve files . Added min(a,b) macro . Moved header_only from process_get() to struct connection . MAX_REQUEST_LENGTH from 20000 to 4000 . xrealloc() to strlen+1 in urldecode() . Made default_reply() take variable arguments like printf . Mostly implemented process_get() . Handling of file-not-found . Handling of other fopen() errors . Header generation (except Content-Type) . Made default_replies more specific . poll_send_header() advances state to DONE if header_only . Completed poll_send_reply() (implemented REPLY_FROMFILE) Emil Mikulic 2003-03-01 09:07:56 +00:00
  • 32b3855aeb . Added SIGPIPE ignoring to TODO . Clear reply_sent and reply_length in new_connection() This was causing a bug that couldn't be seen on the first web request. . Added urldecode() . Started work on process_get() Emil Mikulic 2003-03-01 07:44:51 +00:00
  • 0615eb6a88 . Added to TODO list . Default value for sockin is -1 . Added index_name default, parsing of --index, usage of --index . Dereference char **method when passing to strntoupper() Emil Mikulic 2003-03-01 07:13:12 +00:00
  • 98c9fd318e . Added TODO list . Changed a comment Emil Mikulic 2003-03-01 07:01:56 +00:00
  • b959c6bc3a . Added strntoupper() . rfc1123_date() now takes a time_t argument . default_reply() now takes a `reason' string . Skeleton process_get() . Implemented process_request() completely (for now) (I hope) . Changed oversized request error from 400 Bad Request to 413 Request Entity Too Large Emil Mikulic 2003-02-28 11:21:31 +00:00