From 2ad38632dd39f27fbaa60a4dfbe2fe20921d0007 Mon Sep 17 00:00:00 2001 From: mutantturkey Date: Sun, 2 Jan 2011 13:47:49 -0500 Subject: cleaning up pointless formatting of notes --- CHANGELOG | 2 + shttpd.c | 124 +++++++++++++++----------------------------------------------- 2 files changed, 31 insertions(+), 95 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b774675..0392a32 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,5 +9,7 @@ 01-02-2011: darkhttpd.c renamed shttpd.c, rebranded at Version 0.1 01-02-2011: Makefile: replaced darkhttpd with shttpd/shttpd.c 01-02-2011: shttpd.c: more mimetype mappings added to original list +01-02-2011: shttpd.c: main(), fixed %llu to %lu for correct data type +01-02-2011: shttpd.c: total in/out is now in Kilobytes instead of Bytes (simple / 1024) diff --git a/shttpd.c b/shttpd.c index 3f81349..121e94b 100644 --- a/shttpd.c +++ b/shttpd.c @@ -227,13 +227,6 @@ size_t mime_map_size = 0; size_t longest_ext = 0; -/* If a connection is idle for idletime seconds or more, it gets closed and - * removed from the connlist. Set to 0 to remove the timeout - * functionality. - */ -static int idletime = 60; -static char *keep_alive_field = NULL; - /* Time is cached in the event loop to avoid making an excessive number of * gettimeofday() calls. */ @@ -245,8 +238,9 @@ static time_t now; #define MAX_REQUEST_LENGTH 4000 - /* Defaults can be overridden on the command-line */ +static int idletime = 60; /*idle time before timeout*/ +static char *keep_alive_field = NULL; static in_addr_t bindaddr = INADDR_ANY; static unsigned short bindport = 80; static int max_connections = -1; /* kern.ipc.somaxconn */ @@ -309,35 +303,31 @@ static void poll_send_reply(struct connection *conn); /* --------------------------------------------------------------------------- * close that dies on error. */ -static void xclose(const int fd) -{ +static void xclose(const int fd) { if (close(fd) == -1) err(1, "close()"); } - /* --------------------------------------------------------------------------- * malloc that errx()s if it can't allocate. */ -static void *xmalloc(const size_t size) -{ +static void *xmalloc(const size_t size) { void *ptr = malloc(size); if (ptr == NULL) errx(1, "can't allocate %u bytes", size); return ptr; } + /* --------------------------------------------------------------------------- * realloc() that errx()s if it can't allocate. */ -static void *xrealloc(void *original, const size_t size) -{ +static void *xrealloc(void *original, const size_t size) { void *ptr = realloc(original, size); if (ptr == NULL) errx(1, "can't reallocate %u bytes", size); return ptr; } - /* --------------------------------------------------------------------------- * strdup() that errx()s if it can't allocate. Do this by hand since strdup() * isn't C89. @@ -351,7 +341,6 @@ static char *xstrdup(const char *src) } - #ifdef __sun /* unimpressed by Solaris */ static int vasprintf(char **strp, const char *fmt, va_list ap) { @@ -364,10 +353,7 @@ static int vasprintf(char **strp, const char *fmt, va_list ap) #endif - -/* --------------------------------------------------------------------------- - * vasprintf() that errx()s if it fails. - */ +// vasprintf() that errx()s if it fails. static unsigned int xvasprintf(char **ret, const char *format, va_list ap) { int len = vasprintf(ret, format, ap); @@ -376,10 +362,7 @@ static unsigned int xvasprintf(char **ret, const char *format, va_list ap) } - -/* --------------------------------------------------------------------------- - * asprintf() that errx()s if it fails. - */ +// asprintf() that errx()s if it fails. static unsigned int xasprintf(char **ret, const char *format, ...) { va_list va; @@ -392,7 +375,6 @@ static unsigned int xasprintf(char **ret, const char *format, ...) } - /* --------------------------------------------------------------------------- * Append buffer code. A somewhat efficient string buffer with pool-based * reallocation. @@ -406,7 +388,6 @@ struct apbuf }; - static struct apbuf *make_apbuf(void) { struct apbuf *buf = xmalloc(sizeof(struct apbuf)); @@ -417,7 +398,6 @@ static struct apbuf *make_apbuf(void) } - static void appendl(struct apbuf *buf, const char *s, const size_t len) { if (buf->pool < buf->length + len) @@ -432,7 +412,6 @@ static void appendl(struct apbuf *buf, const char *s, const size_t len) } - #ifdef __GNUC__ #define append(buf, s) appendl(buf, s, \ (__builtin_constant_p(s) ? sizeof(s)-1 : strlen(s)) ) @@ -444,7 +423,6 @@ static void append(struct apbuf *buf, const char *s) #endif - static void appendf(struct apbuf *buf, const char *format, ...) { char *tmp; @@ -460,10 +438,7 @@ static void appendf(struct apbuf *buf, const char *format, ...) } - -/* --------------------------------------------------------------------------- - * Make the specified socket non-blocking. - */ +// Make the specified socket non-blocking. static void nonblock_socket(const int sock) { @@ -478,9 +453,7 @@ nonblock_socket(const int sock) -/* --------------------------------------------------------------------------- - * Split string out of src with range [left:right-1] - */ +//Split string out of src with range [left:right-1] static char *split_string(const char *src, const size_t left, const size_t right) { @@ -497,10 +470,7 @@ static char *split_string(const char *src, -/* --------------------------------------------------------------------------- - * Consolidate slashes in-place by shifting parts of the string over repeated - * slashes. - */ +// Consolidate slashes in-place by shifting parts of the string over repeated slashes. static void consolidate_slashes(char *s) { size_t left = 0, right = 0; @@ -529,11 +499,8 @@ static void consolidate_slashes(char *s) } - -/* --------------------------------------------------------------------------- - * Resolve /./ and /../ in a URI, in-place. Returns NULL if the URI is - * invalid/unsafe, or the original buffer if successful. - */ +// Resolve /./ and /../ in a URI, in-place. Returns NULL if the URI is +//invalid/unsafe, or the original buffer if successful. static char *make_safe_uri(char *uri) { struct { @@ -609,11 +576,8 @@ static char *make_safe_uri(char *uri) } - -/* --------------------------------------------------------------------------- - * Associates an extension with a mimetype in the mime_map. Entries are in - * unsorted order. Makes copies of extension and mimetype strings. - */ +// Associates an extension with a mimetype in the mime_map. Entries are in +// unsorted order. Makes copies of extension and mimetype strings. static void add_mime_mapping(const char *extension, const char *mimetype) { size_t i; @@ -642,11 +606,7 @@ static void add_mime_mapping(const char *extension, const char *mimetype) } - -/* --------------------------------------------------------------------------- - * qsort() the mime_map. The map must be sorted before it can be searched - * through. - */ +//qsort() the mime_map. The map must be sorted before it can be searched through. static int mime_mapping_cmp(const void *a, const void *b) { return strcmp( ((const struct mime_mapping *)a)->extension, @@ -661,9 +621,7 @@ static void sort_mime_map(void) -/* --------------------------------------------------------------------------- - * Parses a mime.types line and adds the parsed data to the mime_map. - */ +//Parses a mime.types line and adds the parsed data to the mime_map. static void parse_mimetype_line(const char *line) { unsigned int pad, bound1, lbound, rbound; @@ -711,12 +669,8 @@ static void parse_mimetype_line(const char *line) -/* --------------------------------------------------------------------------- - * Adds contents of default_extension_map[] to mime_map list. The array must - * be NULL terminated. - */ -static void parse_default_extension_map(void) -{ +//Adds contents of default_extension_map[] to mime_map list. The array must be NULL terminated +static void parse_default_extension_map(void) { int i; for (i=0; default_extension_map[i] != NULL; i++) @@ -724,7 +678,6 @@ static void parse_default_extension_map(void) } - /* --------------------------------------------------------------------------- * read_line - read a line from [fp], return its contents in a * dynamically allocated buffer, not including the line ending. @@ -733,8 +686,7 @@ static void parse_default_extension_map(void) * already at EOF, returns NULL. Will err() or errx() in case of * unexpected file error or running out of memory. */ -static char *read_line(FILE *fp) -{ +static char *read_line(FILE *fp) { char *buf; long startpos, endpos; size_t linelen, numread; @@ -779,10 +731,7 @@ static char *read_line(FILE *fp) } - -/* --------------------------------------------------------------------------- - * Removes the ending newline in a string, if there is one. - */ +//Removes the ending newline in a string, if there is one. static void chomp(char *str) { size_t len = strlen(str); @@ -791,12 +740,8 @@ static void chomp(char *str) } - -/* --------------------------------------------------------------------------- - * Adds contents of specified file to mime_map list. - */ -static void parse_extension_map_file(const char *filename) -{ +//Adds contents of specified file to mime_map list. +static void parse_extension_map_file(const char *filename) { char *buf; FILE *fp = fopen(filename, "rb"); if (fp == NULL) err(1, "fopen(\"%s\")", filename); @@ -813,20 +758,16 @@ static void parse_extension_map_file(const char *filename) -/* --------------------------------------------------------------------------- - * Uses the mime_map to determine a Content-Type: for a requested URI. This - * bsearch()es mime_map, so make sure it's sorted first. - */ -static int mime_mapping_cmp_str(const void *a, const void *b) -{ +//Uses the mime_map to determine a Content-Type: for a requested URI. This +//bsearch()es mime_map, so make sure it's sorted first. +static int mime_mapping_cmp_str(const void *a, const void *b) { return strcmp( (const char *)a, ((const struct mime_mapping *)b)->extension ); } -static const char *uri_content_type(const char *uri) -{ +static const char *uri_content_type(const char *uri) { size_t period, urilen = strlen(uri); for (period=urilen-1; @@ -853,11 +794,7 @@ static const char *uri_content_type(const char *uri) } - -/* --------------------------------------------------------------------------- - * Initialize the sockin global. This is the socket that we accept - * connections from. - */ +//Initialize the sockin global. This is the socket that we accept connections from. static void init_sockin(void) { struct sockaddr_in addrin; @@ -924,10 +861,7 @@ static void init_sockin(void) } - -/* --------------------------------------------------------------------------- - * Prints a usage statement. - */ + //Prints usage statement. static void usage(void) { printf("\n" -- cgit v1.2.1