25 #ifndef _HTTP_SERVER_H_
26 #define _HTTP_SERVER_H_
32 #include <http_parser.h>
35 #include <sys/socket.h>
36 #include <sys/select.h>
40 #include <selectLib.h>
42 #include <arpa/inet.h>
43 #include <sys/types.h>
44 #include <netinet/in.h>
60 #ifndef HTTP_MAX_HANDLERS
65 #define HTTP_MAX_HANDLERS 128
68 #ifndef HTTP_MAX_WORKERS
73 #define HTTP_MAX_WORKERS 4
86 #define IMPORT_FILE(file, sym) \
88 ".section \".rodata\" \n" \
89 ".global " #sym "\n" \
92 ".incbin \"" file "\"\n" \
95 ".global _sizeof_" #sym "\n" \
96 "_sizeof_" #sym":\n" \
97 ".long " #sym "_end - " #sym "\n" \
98 ".section \".text\" \n" \
100 extern __attribute__((aligned(16))) const size_t _sizeof_ ## sym; \
101 extern __attribute__((aligned(16))) __attribute__((nonstring)) const char sym[]
113 int send_http_response(
int socket,
enum http_status status,
const char* header,
const char* content,
size_t content_lenght);
132 enum http_method method;
142 enum HttpRequestState {
146 HTTP_WORKER_REQUEST_EMPTY,
148 HTTP_WORKER_REQUEST_READY,
150 HTTP_WORKER_REQUEST_RUNNING
175 enum HttpRequestState state;
204 struct sockaddr_in _addr;
214 pthread_mutex_t _mutex_sync;
216 pthread_cond_t _cond_sync;
int(* HttpCallback)(int socket, void *data)
Funzione di callback.
Definition: http_server.h:125
HttpServerState
Stati del server.
Definition: http_server.h:157
#define HTTP_MAX_HANDLERS
Numero massimo di handlers.
Definition: http_server.h:65
int http_server_init(struct HttpServer *this, const char address[], uint16_t port)
Inizializza la struttura Server.
Definition: http_server.c:123
int http_server_stop(struct HttpServer *this)
Termina forzatamente il server.
Definition: http_server.c:174
int http_server_start(struct HttpServer *this)
Avvia il server.
Definition: http_server.c:574
#define HTTP_MAX_WORKERS
Numero massimo di worker.
Definition: http_server.h:73
int http_server_add_handler(struct HttpServer *this, enum http_method method, const char *url, HttpCallback callback, void *data)
Aggiunge un handler al server.
Definition: http_server.c:644
int http_server_join(struct HttpServer *this)
Attende che il server sia terminato.
Definition: http_server.c:629
@ HTTP_SERVER_INITIALIZED
Server inizializzato.
Definition: http_server.h:161
@ HTTP_SERVER_RUNNING
Server in esecuzione.
Definition: http_server.h:163
@ HTTP_SERVER_STOPPING
Server in spegnimento.
Definition: http_server.h:165
@ HTTP_SERVER_STOPPED
Server fermo.
Definition: http_server.h:159
int send_http_response(int socket, enum http_status status, const char *header, const char *content, size_t content_lenght)
Invia una risposta HTTP/1.1.
Definition: http_server.c:50
Struttura utilizzata per memorizzare tutti gli handler.
Definition: http_server.h:128
Struttura per il contesto della richiesta.
Definition: http_server.h:169
const struct HttpHandler * handlers
lista degli handler
Definition: http_server.h:178
const struct HttpHandler * handler
handler che ha fatto match
Definition: http_server.h:180
Struttura del server.
Definition: http_server.h:191
enum HttpServerState state
Indica lo stato del server.
Definition: http_server.h:195