Loading http.c +0 −4 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ HTTP_VERB get_http_verb(char *request) { void get_http_path(char *request, char *path) { char verb[50]; sscanf(request, "%49[^ ] /%1022[^ ]", verb, path); fprintf(stdout, "\nVerb: %s, Path: %s\n", verb, path); } Loading @@ -50,7 +49,6 @@ int parseHeaders(char *request, struct tm *tm, int *hasDate) { do { char key[100], value[100]; sscanf(line, "%99[^:]: %99[^\r]", key, value); fprintf(stderr, "\nc:%d key: %s value: %s\n", c, key, value); char *headerName = "If-Modified-Since"; if (strncmp(headerName, key, strlen(headerName)) == 0) { time_t t; Loading @@ -59,8 +57,6 @@ int parseHeaders(char *request, struct tm *tm, int *hasDate) { } char buf[255]; strftime(buf, sizeof(buf), "%d %b %Y %H:%M", tm); fprintf(stderr, "\nParsed date: %s\n", buf); fprintf(stderr, "Has date"); *hasDate = 1; } c++; Loading main.c +10 −9 Original line number Diff line number Diff line Loading @@ -3,35 +3,36 @@ // #include <stdio.h> #include <sys/socket.h> #include <errno.h> #include <string.h> #include <netinet/in.h> #include <sys/socket.h> #include <netinet/ip.h> #include <arpa/inet.h> #include <stdlib.h> #include <poll.h> #include "buffer.h" #include "http.h" #include "network.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wmissing-noreturn" /// Main function /// The function that runs the web server program /// \return No return int main() { // Setup server int firstRun = TRUE; fprintf(stdout, "Burket HTTP Server Starting...\n"); fprintf(stdout, "Trying to bind to %d\n", PORT); int socketfd = bind_socket(); int clientfd; while (TRUE) { // First run, let the user know that we are listening if (firstRun == TRUE) { firstRun = 0; fprintf(stdout, "Accepting connections on port %d\n", PORT); } // Accept Connections clientfd = accept_connection(socketfd); // Handle the connection errno = 0; if (clientfd == -1) { fprintf(stderr, "\nUnable to accept client Error: %d\n", errno); fprintf(stderr, "\nUnable to accept client [Error: %d] %s\n", errno, strerror(errno)); fprintf(stderr, "Error: %s", strerror(errno)); } else { handle_client(clientfd); Loading network.c +0 −6 Original line number Diff line number Diff line Loading @@ -53,7 +53,6 @@ int handle_client(int clientfd) { // Get the path char *path = malloc(sizeof(char) * 1024); get_http_path(request.array, path); fprintf(stdout, "Verb:%d Path:%s\n", verb, path); int hasDate; struct tm tm; parseHeaders(request.array, &tm, &hasDate); Loading @@ -63,12 +62,10 @@ int handle_client(int clientfd) { // If the exsits return 200 if (checkFile(path) != -1) { if (hasDate == 1) { fprintf(stderr, "DEUBG: started date secton"); struct stat statbuff; stat(path, &statbuff); time_t headerTime = mktime(&tm); time_t fileTime = statbuff.st_ctime; fprintf(stderr, "\nfileTime = %d", fileTime); if (difftime(fileTime, headerTime) < 0.0) { char *basicHeader = "HTTP/1.1 304 Not Modified\r\n\r\n"; write(clientfd, basicHeader, strlen(basicHeader)); Loading Loading @@ -96,9 +93,6 @@ int handle_client(int clientfd) { freeBuffer(&request); exit(EXIT_SUCCESS); } #ifdef DEBUG fprintf(stdout, "\nProcessing client on pid %d\n", pid); #endif } /// This creates and binds the socket Loading network.h +0 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,5 @@ int bind_socket(); void getRequest(int clientfd, GrowthBuffer *request); #define PORT 26884 #define DEBUG 0 #define TRUE 1 #endif //COMS352_PROJECT2_PART2_NETWORK_H Loading
http.c +0 −4 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ HTTP_VERB get_http_verb(char *request) { void get_http_path(char *request, char *path) { char verb[50]; sscanf(request, "%49[^ ] /%1022[^ ]", verb, path); fprintf(stdout, "\nVerb: %s, Path: %s\n", verb, path); } Loading @@ -50,7 +49,6 @@ int parseHeaders(char *request, struct tm *tm, int *hasDate) { do { char key[100], value[100]; sscanf(line, "%99[^:]: %99[^\r]", key, value); fprintf(stderr, "\nc:%d key: %s value: %s\n", c, key, value); char *headerName = "If-Modified-Since"; if (strncmp(headerName, key, strlen(headerName)) == 0) { time_t t; Loading @@ -59,8 +57,6 @@ int parseHeaders(char *request, struct tm *tm, int *hasDate) { } char buf[255]; strftime(buf, sizeof(buf), "%d %b %Y %H:%M", tm); fprintf(stderr, "\nParsed date: %s\n", buf); fprintf(stderr, "Has date"); *hasDate = 1; } c++; Loading
main.c +10 −9 Original line number Diff line number Diff line Loading @@ -3,35 +3,36 @@ // #include <stdio.h> #include <sys/socket.h> #include <errno.h> #include <string.h> #include <netinet/in.h> #include <sys/socket.h> #include <netinet/ip.h> #include <arpa/inet.h> #include <stdlib.h> #include <poll.h> #include "buffer.h" #include "http.h" #include "network.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wmissing-noreturn" /// Main function /// The function that runs the web server program /// \return No return int main() { // Setup server int firstRun = TRUE; fprintf(stdout, "Burket HTTP Server Starting...\n"); fprintf(stdout, "Trying to bind to %d\n", PORT); int socketfd = bind_socket(); int clientfd; while (TRUE) { // First run, let the user know that we are listening if (firstRun == TRUE) { firstRun = 0; fprintf(stdout, "Accepting connections on port %d\n", PORT); } // Accept Connections clientfd = accept_connection(socketfd); // Handle the connection errno = 0; if (clientfd == -1) { fprintf(stderr, "\nUnable to accept client Error: %d\n", errno); fprintf(stderr, "\nUnable to accept client [Error: %d] %s\n", errno, strerror(errno)); fprintf(stderr, "Error: %s", strerror(errno)); } else { handle_client(clientfd); Loading
network.c +0 −6 Original line number Diff line number Diff line Loading @@ -53,7 +53,6 @@ int handle_client(int clientfd) { // Get the path char *path = malloc(sizeof(char) * 1024); get_http_path(request.array, path); fprintf(stdout, "Verb:%d Path:%s\n", verb, path); int hasDate; struct tm tm; parseHeaders(request.array, &tm, &hasDate); Loading @@ -63,12 +62,10 @@ int handle_client(int clientfd) { // If the exsits return 200 if (checkFile(path) != -1) { if (hasDate == 1) { fprintf(stderr, "DEUBG: started date secton"); struct stat statbuff; stat(path, &statbuff); time_t headerTime = mktime(&tm); time_t fileTime = statbuff.st_ctime; fprintf(stderr, "\nfileTime = %d", fileTime); if (difftime(fileTime, headerTime) < 0.0) { char *basicHeader = "HTTP/1.1 304 Not Modified\r\n\r\n"; write(clientfd, basicHeader, strlen(basicHeader)); Loading Loading @@ -96,9 +93,6 @@ int handle_client(int clientfd) { freeBuffer(&request); exit(EXIT_SUCCESS); } #ifdef DEBUG fprintf(stdout, "\nProcessing client on pid %d\n", pid); #endif } /// This creates and binds the socket Loading
network.h +0 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,5 @@ int bind_socket(); void getRequest(int clientfd, GrowthBuffer *request); #define PORT 26884 #define DEBUG 0 #define TRUE 1 #endif //COMS352_PROJECT2_PART2_NETWORK_H