Files
cweb/http/http_server.h
cdricms e24c207bdc Final
2024-11-20 18:29:11 +01:00

50 lines
1.4 KiB
C

#ifndef HTTP_SERVER_H
#define HTTP_SERVER_H
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/types.h>
#ifndef DEFAULT_HTML
#define DEFAULT_HTML "index.html"
#endif
typedef enum {
HTTP_SRS_RUNNING = 0,
HTTP_SRS_SETUP,
HTTP_SRS_STOPPED,
HTTP_SRS_SOCKET_FAILED,
HTTP_SRS_SETSOCKOPT_FAILED,
HTTP_SRS_BIND_FAILED,
HTTP_SRS_LISTEN_FAILED,
HTTP_SRS_ACCEPT_FAILED,
HTTP_SRS_READ_FAILED,
HTTP_SRS_HANDLE_REQUEST_FAILED,
HTTP_SRS_FORK_FAILED,
HTTP_SRS_WONT_HANDLE,
HTTP_SRS_FILE_NOT_FOUND,
} HttpServerRunStatus;
// Structure ayant pour objectif de stocker tout ce qui est nécessaire au bon
// fonctionnement du serveur.
typedef struct {
int port; // Port du host
int server_fd; // File descriptor du server
unsigned int
backlog; // Le nombre de clients possibles pouvant être en attente.
struct sockaddr_in *address; // L'adresse décrivant une socket internet.
pid_t pid; // Le pid du parent en attente de requêtes.
} HttpServer;
// On setup le server, avec son file descriptor, ses options, le bind et le
// listen.
HttpServerRunStatus http_server_setup(HttpServer *s);
// Si tout est ok, on peut lancer le server, tant qu'il tourne, il peut
// recevoir des clients.
HttpServerRunStatus http_server_run(HttpServer *s);
// Si pour quelques raisons il s'arrête, on free tout ce qu'il doit être
// free.
HttpServerRunStatus http_server_stop(HttpServer *s);
#endif