From f060c35f7d81a215403aae5bbffab4100c2101d2 Mon Sep 17 00:00:00 2001 From: Nayan <33187059+GShadow5@users.noreply.github.com> Date: Thu, 8 May 2025 22:34:36 -0400 Subject: [PATCH] add file comments --- .vscode/settings.json | 3 ++- client_handler.c | 10 ++++++++++ client_handler.h | 6 ++++++ http_stuff.c | 11 +++++++++++ http_stuff.h | 8 ++++++++ logging.c | 9 +++++++++ logging.h | 14 ++++++++++++++ request_handler.c | 11 +++++++++++ request_handler.h | 11 +++++++++++ response_builder.c | 8 ++++++++ response_builder.h | 8 ++++++++ webserver.c | 7 +++++++ 12 files changed, 105 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 1905e88..cec88fd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "random": "c", "request_handler.h": "c", "response_builder.h": "c", - "time.h": "c" + "time.h": "c", + "string_view": "c" } } \ No newline at end of file diff --git a/client_handler.c b/client_handler.c index 9f078ce..26615d4 100644 --- a/client_handler.c +++ b/client_handler.c @@ -1,3 +1,13 @@ +/* + * client_handler.c + * + * Handles a single client connection. Meant to be run in a separate thread. + * + * This function is designed to be run in a separate thread. It will receive + * requests from the client until the client disconnects, at which point it will + * return. + */ + #include "client_handler.h" #include "request_handler.h" diff --git a/client_handler.h b/client_handler.h index 5d0c7c4..9d137ca 100644 --- a/client_handler.h +++ b/client_handler.h @@ -1,6 +1,12 @@ #ifndef CLIENT_HANDLER_H #define CLIENT_HANDLER_H +/** + * Header file for client_handler.c + * + * Nothing special here + */ + #include #include #include diff --git a/http_stuff.c b/http_stuff.c index 279f1c0..37ad863 100644 --- a/http_stuff.c +++ b/http_stuff.c @@ -1,3 +1,14 @@ +/** + * http_stuff.c + * + * This file contains functions dealing with http requests and responses, and + * the corresponding structs defined in http_stuff.h + * + * Included functionality is allocation and freeing of the structs, printing for + * debug purposes, string conversion, and utility functions for dealing with + * headers and parsing + */ + #include "http_stuff.h" http_request* create_http_request() { diff --git a/http_stuff.h b/http_stuff.h index 9956314..01dd13a 100644 --- a/http_stuff.h +++ b/http_stuff.h @@ -1,6 +1,14 @@ #ifndef HTTP_STUFF_H #define HTTP_STUFF_H +/** + * http_stuff.h + * + * Header file for http_stuff.c + * + * The http structs and enums are defined here + */ + #include #include #include diff --git a/logging.c b/logging.c index 39789cd..bd25073 100644 --- a/logging.c +++ b/logging.c @@ -1,3 +1,12 @@ +/** + * logging.c + * + * This file contains functions for logging messages. + * + * Included functionality is opening and closing the log file, setting the log + * level, and logging messages + */ + #include "logging.h" FILE* log_file = NULL; diff --git a/logging.h b/logging.h index 3b858ff..7b593a1 100644 --- a/logging.h +++ b/logging.h @@ -1,3 +1,15 @@ +#ifndef LOGGING_H +#define LOGGING_H + +/** + * logging.h + * + * This file contains functions for logging messages. + * + * Included functionality is opening and closing the log file, setting the log + * level, and logging messages + */ + #include #include #include @@ -51,3 +63,5 @@ void close_log_file(); * @param ... The variadic arguments to format the string with */ void log_message(int level, const char* fmt, ...); + +#endif \ No newline at end of file diff --git a/request_handler.c b/request_handler.c index 0a0ba9b..8b3ac34 100644 --- a/request_handler.c +++ b/request_handler.c @@ -1,3 +1,14 @@ +/** + * request_handler.c + * + * This file contains functions for handling an HTTP request and constructing + * an appropriate response. + * + * Included functionality is parsing the request into an http_request struct, + * and using a switch statement to call the appropriate response handler based + * on the request type. + */ + #include "request_handler.h" void handle_request(char* request, int length, http_response* response) { diff --git a/request_handler.h b/request_handler.h index 1982b2b..dc55d0a 100644 --- a/request_handler.h +++ b/request_handler.h @@ -1,6 +1,17 @@ #ifndef REQUEST_HANDLER_H #define REQUEST_HANDLER_H +/** + * request_handler.h + * + * This file contains functions for handling an HTTP request and constructing + * an appropriate response. + * + * Included functionality is parsing the request into an http_request struct, + * and using a switch statement to call the appropriate response handler based + * on the request type. + */ + #include #include #include diff --git a/response_builder.c b/response_builder.c index 2300b97..8f70234 100644 --- a/response_builder.c +++ b/response_builder.c @@ -1,3 +1,11 @@ +/** + * response_builder.c + * + * This file contains functions for handling the different types of HTTP + * requests. Currently, it only handles GET requests and serves static files. + * + */ + #include "response_builder.h" void response_handle_get(http_request* req, http_response* res) { diff --git a/response_builder.h b/response_builder.h index 0347524..d49ba0c 100644 --- a/response_builder.h +++ b/response_builder.h @@ -1,6 +1,14 @@ #ifndef RESPONSE_BUILDER_H #define RESPONSE_BUILDER_H +/** + * response_builder.h + * + * This header files contains functions for building HTTP responses, and also + * contains the enum types for content types and status codes. + * + */ + #include #include #include diff --git a/webserver.c b/webserver.c index 8e6cfde..53c7e52 100644 --- a/webserver.c +++ b/webserver.c @@ -1,3 +1,10 @@ +/* + * webserver.c + * + * This file contains the main function for managing sockets, clients, user + * input, and threads. + */ + #include #include #include