Commit Graph

149 Commits

Author SHA1 Message Date
Emil Mikulic
f246f24acb . Remove expand_tilde().
. Remove commented-out SIGINT/SIGQUIT handling.
2013-04-28 19:40:39 +10:00
Emil Mikulic
e70a830c2c . Add TODO reminders.
. Optimize string reassembly in make_safe_uri().
2013-04-28 19:40:39 +10:00
Emil Mikulic
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()
2013-04-28 19:40:39 +10:00
Emil Mikulic
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.
2013-04-28 19:40:39 +10:00
Emil Mikulic
9988849ea7 Change 0 to '\0' in a character context. 2013-04-28 19:40:33 +10:00
Emil Mikulic
813d4463bc . Add read_line() and chomp().
. Greatly simplify parse_extension_map_file().
2013-04-28 19:40:21 +10:00
Emil Mikulic
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.
2013-04-28 19:40:02 +10:00
Emil Mikulic
b1b9432123 Changes to comments that have been waiting since Aug 4 07:54. 2013-04-28 19:30:35 +10:00
Emil Mikulic
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.
2013-04-28 19:30:35 +10:00
Emil Mikulic
f56dcd2b76 Borged parts of sys/queue.h since non-BSDs don't have the header. 2013-04-28 19:30:35 +10:00
Emil Mikulic
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.
2013-04-28 19:30:35 +10:00
Emil Mikulic
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().
2013-04-28 19:30:35 +10:00
Emil Mikulic
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.
2013-04-28 19:30:35 +10:00
Emil Mikulic
295cd40bbb int type fixes to keep splint happy. 2013-04-28 19:30:35 +10:00
Emil Mikulic
7090baae35 . Added range fields to struct connection.
. Added sanity check in split_string(): left <= right
. Implemented parse_range_field()
2013-04-28 19:30:35 +10:00
Emil Mikulic
6ee7a85231 . Got rid of conn->lastmod field.
. rfc1123_date() takes a destination buffer instead of having the one,
  static, global buffer.
2013-04-28 19:30:35 +10:00
Emil Mikulic
6e0103cbc4 Fiddling with signed-ness and types to make splint happy. 2013-04-28 19:30:35 +10:00
Emil Mikulic
0c1ff8a258 Cleared up parse_field() synopsis. 2013-04-28 19:30:35 +10:00
Emil Mikulic
3dc4ce1216 . Made all sockets non-blocking
. Used simpler way of ignoring SIGPIPE
. Made sure closed sockets aren't written to
2013-04-28 19:30:35 +10:00
Emil Mikulic
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
2013-04-28 19:30:35 +10:00
Emil Mikulic
ce7cfceabb Worked out warning flags from gcc manpage 2013-04-28 19:30:35 +10:00
Emil Mikulic
0d755c3618 . Added ogg mimetype
. Added xvasprintf()
. Added xasprintf()
. Some signed/unsigned clarifications
. Simplified asprintf() error handling using xasprintf()
. Check for failure of signal()
2013-04-28 19:30:35 +10:00
Emil Mikulic
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()
2013-04-28 19:30:35 +10:00
Emil Mikulic
72d0b5b301 . Use reasm instead of checking for a NULL reassembly element (safer) 2013-04-28 19:30:35 +10:00
Emil Mikulic
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)
2013-04-28 19:30:35 +10:00
Emil Mikulic
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
2013-04-28 19:30:35 +10:00
Emil Mikulic
7a2daecf22 . Added debugf() to parse_mimetype_line()
. Added parse_extension_map_file()
. Added --mimetypes to usage() and parse_commandline()
2013-04-28 19:30:35 +10:00
Emil Mikulic
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
2013-04-28 19:30:35 +10:00
Emil Mikulic
d6b7871ade . TODO: dir entries -> dir listings
. TODO: minor cleanup
. --help as first parameter results in usage()
2013-04-28 19:30:35 +10:00
Emil Mikulic
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()
2013-04-28 19:30:35 +10:00
Emil Mikulic
aa2245e867 . Added expand_tilde()
. Added strip_endslash()
. wwwroot gets its tilde expanded and trailing slash clipped off
2013-04-28 19:30:35 +10:00
Emil Mikulic
f5703a9c82 . Added TODO entries
. Minor whitespace fixes
2013-04-28 19:30:35 +10:00
Emil Mikulic
09d69063bd . Ignoring SIGPIPE
. httpd_poll()'s select() will timeout after IDLETIME seconds if
  there are any connections currently in a send/recv state
2013-04-28 19:30:35 +10:00
Emil Mikulic
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()
2013-04-28 19:30:35 +10:00
Emil Mikulic
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)
2013-04-28 19:30:35 +10:00
Emil Mikulic
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()
2013-04-28 19:30:35 +10:00
Emil Mikulic
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()
2013-04-28 19:30:35 +10:00
Emil Mikulic
98c9fd318e . Added TODO list
. Changed a comment
2013-04-28 19:30:35 +10:00
Emil Mikulic
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
2013-04-28 19:30:34 +10:00
Emil Mikulic
fd0a618d34 Initial implementation of parse_request() 2013-04-28 19:30:28 +10:00
Emil Mikulic
3759104f07 . Added rfc1123_date() and Date: header field to default_reply()
. Skeleton for parse_request()
2013-04-28 19:21:12 +10:00
Emil Mikulic
9074924be5 . Added MAX_REQUEST_LENGTH and a check for it in poll_recv_request()
. Fixed comment DEFAULT_PORT -> bindport
. "options:\n" -> "options:\n\n"
2013-04-28 19:21:12 +10:00
Emil Mikulic
cb3342472b . default_reply() ensures reply_type is REPLY_GENERATED
. Implemented poll_send_header()
. Partial implementation of poll_send_file() - can't send FROMFILE yet
2013-04-28 19:21:12 +10:00
Emil Mikulic
23b191239e . Added to struct connection:
o in_addr_t client
	o time last_active
	o {header,reply}_dont_free
. Added IDLETIME and poll_check_timeout()
. Added new_connection() and moved conn initialisation there
. Added default_reply()
. Skeleton for process_request()
. connnection.request is now null-terminated
. Removed debug code from poll_recv_request()
2013-04-28 19:21:12 +10:00
Emil Mikulic
ebe1e1bfa0 . Added LIST (sys/queue.h) of struct connection
. Added xmalloc()
. Filled out accept_connection()
. Added free_connection()
. Added xrealloc()
. Started poll_recv_request()
. Skeletons for poll_send_header(), poll_send_reply()
. Filled out httpd_poll()
2013-04-28 19:21:12 +10:00
Emil Mikulic
345c214212 . Added struct connection
. Skeleton accept_connection()
. Incomplete httpd_poll()
2013-04-28 19:21:12 +10:00
Emil Mikulic
7a8ff37bb3 . Changed argument --bind' -> --addr'
. Implemented arg parsing for port, addr, maxconn, log, chroot
. init_sockin() prints the addr:port that sockin is bound to
2013-04-28 19:21:12 +10:00
Emil Mikulic
79e52dfae2 . Moved pkgname, copyright to top of file to avoid having to duplicate
it in the comments.
. Got rid of DEFAULT_* defines in favour of initializers.
. Moved existing socket creation code to init_sockin().
. Added usage(). [needs work]
. Added parse_commandline() skeleton. [needs a lot of work]
2013-04-28 19:21:12 +10:00
Emil Mikulic
26aeb38a81 Initial revision - open and close a socket. 2013-04-28 19:21:00 +10:00