ecen5273

ECEN5273 Coursework
git clone https://git.pngu.org/ecen5273
Log | Files | Refs | README

proxy.h (1607B)


// HTTP Caching Proxy
// Jack Sangdahl
// 28 October 2024
#include <arpa/inet.h>
#include <dirent.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <openssl/evp.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#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                                                         \
  "<html><body>400 Bad Request Reason: Invalid Method:<<request "              \
  "method>></body></html>\r\n\r\n"
#define MSG_400_URL                                                            \
  "<html><body>400 Bad Request Reason: Invalid URL: <<requested "              \
  "url>></body></html>\r\n\r\n"
#define RSP_403 "HTTP/1.1 403 Forbidden\r\nContent-Type: text/html\r\n"
#define MSG_403 "<html><body>403 Blocked Website</body></html>\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);