From: Laurent Mazet Date: Sat, 27 May 2023 21:22:28 +0000 (+0200) Subject: Revert "major fixes and better tests" X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=7ce2d62a9438cce56d0df6f7141d9f83db177904;p=webserver.git Revert "major fixes and better tests" This reverts commit 7a559b2cdf3c9060af1645ae73420c4b91b19cf1. --- diff --git a/http.c b/http.c index fbd18ef..f0e53af 100644 --- a/http.c +++ b/http.c @@ -1,5 +1,4 @@ #include -#include #include #include @@ -222,7 +221,7 @@ int add_entity (char **buffer, char *entity, int size, char *type, char *encodin /* Content-Encoding */ if (encoding != NULL) { - sprintf (tmp, "Content-Encoding: %s", encoding); + sprintf (tmp, "Content-Encoding: %sn", encoding); add_line (buffer, tmp); } @@ -303,12 +302,11 @@ char *trim (char *str) int processing (char *data, int len, conf_t *conf, char **pdata) { - char *saved_data = data; char location[BUFFER_SIZE] = {0}; VERBOSE (DEBUG, PRINT ("Start processing\n")); /* check method */ - char *line = find_sequence (data, len + data - saved_data, "\r\n", &data); + char *line = find_sequence (data, len, "\r\n", &data); if (line == NULL) { VERBOSE (WARNING, PRINT ("Unknown received data\n")); if (pdata != NULL) { @@ -335,15 +333,13 @@ int processing (char *data, int len, conf_t *conf, char **pdata) VERBOSE (INFO, PRINT ("%s %s (%s)\n", (type == get_e) ? "Get" : (type == head_e) ? "Head" : "Post", uri, version)); /* analyse uri */ - char *filename = strtok (uri, "&"); - char *variables = strtok (NULL, "\n"); - char *path = (char *) calloc (strlen (conf->root) + strlen (filename) + 2, 1); + char *filename = (char *)calloc (strlen (conf->root) + strlen (uri) + 2, 1); //sprintf (filename, "%s%s%s", conf->root, ((conf->root[strlen (conf->root) - 1] != '/') && (uri[0] != '/')) ? "/" : "", uri); - sprintf (path, "%s/%s", conf->root, filename); + sprintf (filename, "%s/%s", conf->root, uri); /* check header */ header_t header = {0}; - while (strcmp (line = find_sequence (data, len + data - saved_data, "\r\n", &data), "") != 0) { + while (strcmp (line = find_sequence (data, len, "\r\n", &data), "") != 0) { VERBOSE (DEBUG, PRINT ("Header line: '%s'\n", line)); char *field = strtok (line, ":"); char *value = trim (strtok (NULL, "\r")); @@ -373,51 +369,46 @@ int processing (char *data, int len, conf_t *conf, char **pdata) } VERBOSE (DEBUG, print_header_values (&header)); - /* body */ - char *body = data; - len -= saved_data - data; - if (len != (header.content_length ? atoi (header.content_length) : 0)) { - VERBOSE (WARNING, PRINT ("Incoherent size (%d <> %s)\n", len, header.content_length)); - } - /* response */ char *buffer = NULL; FILE *fid = NULL; switch (type) { case get_e: - case post_e: /* fall through */ - VERBOSE (DEBUG, PRINT ("Read file %s\n", path)); - len = readfile (&buffer, path); + VERBOSE (DEBUG, PRINT ("Read file %s\n", filename)); + len = readfile (&buffer, filename); if (len < 0) { sprintf (location, "http://%s/", conf->servername); len = error_404 (pdata, location); } else { - sprintf (location, "http://%s%s", conf->servername, path); + sprintf (location, "http://%s%s", conf->servername, filename); len = generic_response (pdata, location, buffer, len); free (buffer); } break; case head_e: - VERBOSE (DEBUG, PRINT ("Test file %s\n", path)); - fid = fopen (path, "rb"); + VERBOSE (DEBUG, PRINT ("Read file %s\n", filename)); + fid = fopen (filename, "rb"); if (fid == NULL) { sprintf (location, "http://%s/", conf->servername); len = error_404 (pdata, location); } else { fclose (fid); - sprintf (location, "http://%s%s", conf->servername, path); + sprintf (location, "http://%s%s", conf->servername, filename); len = generic_response (pdata, location, NULL, 0); } break; + case post_e: + VERBOSE (DEBUG, PRINT ("Write file %s\n", filename)); + break; case not_supported_e: break; } /* cleaning */ VERBOSE (DEBUG, PRINT ("Cleaning\n")); - if (path) { - VERBOSE (DEBUG, PRINT ("Cleaning path\n")); - free (path); + if (filename) { + VERBOSE (DEBUG, PRINT ("Cleaning filename\n")); + free (filename); } return len; diff --git a/webroot/image.png b/webroot/image.png deleted file mode 100644 index c4a5f3c..0000000 Binary files a/webroot/image.png and /dev/null differ diff --git a/webroot/index.html b/webroot/index.html deleted file mode 100644 index 1a973c7..0000000 --- a/webroot/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - Test - - -

This is a test

- - diff --git a/webserver.c b/webserver.c index 2f54227..d74145f 100644 --- a/webserver.c +++ b/webserver.c @@ -206,12 +206,12 @@ int main (int argc, char *argv[]) // test: webserver.exe -p -1 2>&1 | grep -q 'incorrect port number' // test: webserver.exe -s 2>&1 | grep -q 'missing server name' // test: webserver.exe -r 2>&1 | grep -q 'missing directory name' -// test: webserver.exe >& test.log & pid=$!; sleep 1; kill -ABRT $pid; sleep 1; grep -q 'Listening socket on port 8080' test.log -// test: webserver.exe -p 8000 >& test.log & pid=$!; sleep 1; kill -TERM $pid; sleep 1; grep -q 'Listening socket on port 8000' test.log -// test: webserver.exe -p 8001 -c iso-8859-1 -r webroot -s localhost >&/dev/null & pid=$!; sleep 1; curl http://localhost:8001/index.html > test.log; kill -TERM $pid; sleep 1; grep -q 'Test' test.log -// test: webserver.exe -v 3 -p 8002 >&/dev/null & pid=$!; sleep 1; curl -v http://localhost:8002/index.html >& test.log; kill -TERM $pid; sleep 1; grep -q 200 test.log -// test: webserver.exe -v 3 -p 8003 >&/dev/null & pid=$!; sleep 1; curl -v http://localhost:8003/not_found.html >& test.log; kill -TERM $pid; sleep 1; grep -q 404 test.log -// test: webserver.exe -v 3 -p 8004 >&/dev/null & pid=$!; sleep 1; curl -v -I http://localhost:8004/index.html >& test.log; kill -TERM $pid; sleep 1; grep -q Content-Length test.log; test $? -eq 1 -// test: webserver.exe -v 3 -p 8005 >&/dev/null & pid=$!; sleep 1; curl -v -d '' http://localhost:8005/index.html >& test.log; kill -TERM $pid; sleep 1; grep -q 'Test' test.log +// test: webserver.exe >& test.log & pid=$!; sleep 1; kill -INT $pid; grep -q 'Listening socket on port 8080' test.log +// test: webserver.exe -p 8000 >& test.log & pid=$!; sleep 1; kill -INT $pid; grep -q 'Listening socket on port 8000' test.log +// test: webserver.exe -c iso-8859-1 -r webroot -s localhost >&/dev/null & pid=$!; sleep 1; curl http://localhost:8080/index.html > test; kill -TERM $pid; grep -q 'Test' test +// test: webserver.exe -v 3 -p 8001 >&/dev/null & pid=$!; sleep 1; curl http://localhost:8001/index.html > test; kill -TERM $pid +// test: webserver.exe -v 3 -p 8002 >&/dev/null & pid=$!; sleep 1; curl http://localhost:8002/not_found.html > test; kill -TERM $pid; grep -q '404' test +// test: webserver.exe -v 3 -p 8003 >&/dev/null & pid=$!; sleep 1; curl -I http://localhost:8003/index.html > test; kill -TERM $pid + /* vim: set ts=4 sw=4 et: */