// HTTP Caching Proxy // Jack Sangdahl // 28 October 2024 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define DATA_SIZE 10240 #define CACHE_DIRECTORY "./cache/" #define HOST_CACHE_FILENAME "./cache/hostnames" #define BLOCKLIST_FILENAME "./blocklist" #define RSP_400 "HTTP/1.1 400 Bad Request\r\nContent-Type: text/html\r\n\r\n" #define MSG_400_METHOD \ "400 Bad Request Reason: Invalid Method:<>\r\n\r\n" #define MSG_400_URL \ "400 Bad Request Reason: Invalid URL: <>\r\n\r\n" #define RSP_403 "HTTP/1.1 403 Forbidden\r\nContent-Type: text/html\r\n" #define MSG_403 "403 Blocked Website\r\n\r\n" struct prefetcher_args { char filename[50]; char hostname[100]; char ipaddr[20]; }; bool blacklisted(char *ipaddr); bool file_cached(char *url); bool hostname_cached(char *hostname, char *ipaddr); void *handle_connection(void *a); void *prefetcher(void *a); void calculate_md5sum(char *url, char *md5string); void send_cached_file(char *url, int connection); void cache_hostname(char *hostname, char *ipaddr); void handle_sigint(int sig);