mirror of
https://github.com/opus-tango/http-server-in-c.git
synced 2026-03-20 03:55:25 +00:00
add file comments
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -5,6 +5,7 @@
|
|||||||
"random": "c",
|
"random": "c",
|
||||||
"request_handler.h": "c",
|
"request_handler.h": "c",
|
||||||
"response_builder.h": "c",
|
"response_builder.h": "c",
|
||||||
"time.h": "c"
|
"time.h": "c",
|
||||||
|
"string_view": "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 "client_handler.h"
|
||||||
|
|
||||||
#include "request_handler.h"
|
#include "request_handler.h"
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
#ifndef CLIENT_HANDLER_H
|
#ifndef CLIENT_HANDLER_H
|
||||||
#define CLIENT_HANDLER_H
|
#define CLIENT_HANDLER_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Header file for client_handler.c
|
||||||
|
*
|
||||||
|
* Nothing special here
|
||||||
|
*/
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|||||||
11
http_stuff.c
11
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"
|
#include "http_stuff.h"
|
||||||
|
|
||||||
http_request* create_http_request() {
|
http_request* create_http_request() {
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
#ifndef HTTP_STUFF_H
|
#ifndef HTTP_STUFF_H
|
||||||
#define 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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
@@ -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"
|
#include "logging.h"
|
||||||
|
|
||||||
FILE* log_file = NULL;
|
FILE* log_file = NULL;
|
||||||
|
|||||||
14
logging.h
14
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 <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -51,3 +63,5 @@ void close_log_file();
|
|||||||
* @param ... The variadic arguments to format the string with
|
* @param ... The variadic arguments to format the string with
|
||||||
*/
|
*/
|
||||||
void log_message(int level, const char* fmt, ...);
|
void log_message(int level, const char* fmt, ...);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -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"
|
#include "request_handler.h"
|
||||||
|
|
||||||
void handle_request(char* request, int length, http_response* response) {
|
void handle_request(char* request, int length, http_response* response) {
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
#ifndef REQUEST_HANDLER_H
|
#ifndef REQUEST_HANDLER_H
|
||||||
#define 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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|||||||
@@ -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"
|
#include "response_builder.h"
|
||||||
|
|
||||||
void response_handle_get(http_request* req, http_response* res) {
|
void response_handle_get(http_request* req, http_response* res) {
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
#ifndef RESPONSE_BUILDER_H
|
#ifndef RESPONSE_BUILDER_H
|
||||||
#define 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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* webserver.c
|
||||||
|
*
|
||||||
|
* This file contains the main function for managing sockets, clients, user
|
||||||
|
* input, and threads.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user