diff --git a/src/simplehttpd.c b/src/simplehttpd.c index 8b9f337094134aed47aa5ca717110a8407546e47..d4b943da2ee39efca3a678214655457d50bc66ff 100644 --- a/src/simplehttpd.c +++ b/src/simplehttpd.c @@ -310,20 +310,6 @@ void post_process(int client, const char *path, const char *method, const char * } } -void get_process(int client, const char *path, const char *method, const char *query_string) -{ - char buf[MAX_BUFFER_SIZE]; - int numchars = 1; - buf[0] = 'A'; - buf[1] = '\0'; - while ((numchars > 0) && strcmp("\n", buf)) - { - numchars = get_line(client, buf, sizeof(buf)); - // Todo... - } - response_ok(client); -} - void *accept_request(void *arg) { int client = *(int *)arg; @@ -346,7 +332,7 @@ void *accept_request(void *arg) } method[i] = '\0'; - if (strcasecmp(method, "GET") && strcasecmp(method, "POST")) + if (strcasecmp(method, "POST")) { unimplemented(client); close(client); @@ -364,84 +350,13 @@ void *accept_request(void *arg) j++; } url[i] = '\0'; - - if (strcasecmp(method, "GET") == 0) - { - query_string = url; - while ((*query_string != '?') && (*query_string != '\0')) - query_string++; - - if (*query_string == '?') - { - *query_string = '\0'; - query_string++; - } - } - - if (strcasecmp(method, "POST") == 0) - { - post_process(client, url, method, query_string); - } - else - { - get_process(client, url, method, query_string); - } + + post_process(client, url, method, query_string); close(client); return NULL; } -void cat(int client, FILE *resource) -{ - char buf[MAX_BUFFER_SIZE]; - - fgets(buf, sizeof(buf), resource); - while (!feof(resource)) - { - send(client, buf, strlen(buf), MSG_NOSIGNAL); - fgets(buf, sizeof(buf), resource); - } -} - -void headers(int client, const char *filename) -{ - char buf[MAX_BUFFER_SIZE]; - (void)filename; - - strcpy(buf, "HTTP/1.0 200 OK\r\n"); - send(client, buf, strlen(buf), MSG_NOSIGNAL); - - strcpy(buf, SERVER_STRING); - send(client, buf, strlen(buf), MSG_NOSIGNAL); - sprintf(buf, "Content-Type: text/html\r\n"); - send(client, buf, strlen(buf), MSG_NOSIGNAL); - strcpy(buf, "\r\n"); - send(client, buf, strlen(buf), MSG_NOSIGNAL); -} - -void serve_file(int client, const char *filename) -{ - FILE *resource = NULL; - int numchars = 1; - char buf[MAX_BUFFER_SIZE]; - - buf[0] = 'A'; - buf[1] = '\0'; - while ((numchars > 0) && strcmp("\n", buf)) - numchars = get_line(client, buf, sizeof(buf)); - - resource = fopen(filename, "r"); - if (resource == NULL) - not_found(client); - else - { - headers(client, filename); - - cat(client, resource); - } - fclose(resource); -} - int RegisterPostProcessDoneCallback(PostProcessDoneCallback callback) { post_process_done_callback = callback;