diff options
Diffstat (limited to 'src/daemon/internal.h')
-rw-r--r-- | src/daemon/internal.h | 171 |
1 files changed, 169 insertions, 2 deletions
diff --git a/src/daemon/internal.h b/src/daemon/internal.h index 2f7fd194..61653d8e 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h @@ -35,7 +35,8 @@ #include <netdb.h> #include <string.h> #include <unistd.h> -#include <stdarg> +#include <stdarg.h> +#include <errno.h> #include <fcntl.h> #include <pthread.h> #include <netinet/in.h> @@ -45,7 +46,7 @@ #define MHD_MAX_BUF_SIZE 2048 - +#define MAX(a,b) ((a)<(b)) ? (b) : (a) /** * Header or cookie in HTTP request or response. @@ -72,6 +73,172 @@ struct MHD_Access_Handler { }; +/** + * Representation of a response. + */ +struct MHD_Response { + + /** + * Headers to send for the response. Initially + * the linked list is created in inverse order; + * the order should be inverted before sending! + */ + struct MHD_HTTP_Header * first_header; + + /** + * Buffer pointing to data that we are supposed + * to send as a response. + */ + char * data; + + /** + * Closure to give to the content reader + * free callback. + */ + void * crc_cls; + + /** + * How do we get more data? NULL if we are + * given all of the data up front. + */ + MHD_ContentReaderCallback crc; + + /** + * NULL if data must not be freed, otherwise + * either user-specified callback or "&free". + */ + MHD_ContentReaderFreeCallback crfc; + + /** + * Mutex to synchronize access to data/size and + * reference counts. + */ + pthread_mutex_t mutex; + + /** + * Reference count for this response. Free + * once the counter hits zero. + */ + unsigned int reference_count; + + /** + * Set to -1 if size is not known. + */ + size_t total_size; + + /** + * Size of data. + */ + size_t data_size; + + /** + * At what offset in the stream is the + * beginning of data located? + */ + size_t data_start; + +}; + + + +struct MHD_Session { + struct MHD_Session * next; + + struct MHD_Daemon * daemon; + + struct MHD_HTTP_Header * headers_received; + + struct MHD_Response * response; + + char * method; + + char * url; + + /** + * Buffer for reading requests. + */ + char * read_buffer; + + /** + * Buffer for writing response. + */ + char * write_buffer; + + /** + * Foreign address (of length addr_len). + */ + struct sockaddr_in * addr; + + /** + * Thread for this session (if we are using + * one thread per connection). + */ + pthread_t pid; + + size_t read_buffer_size; + + size_t readLoc; + + size_t write_buffer_size; + + size_t writeLoc; + + /** + * Current write position in the actual response + * (excluding headers, content only; should be 0 + * while sending headers). + */ + size_t messagePos; + + /** + * Remaining (!) number of bytes in the upload. + * Set to -1 for unknown (connection will close + * to indicate end of upload). + */ + size_t uploadSize; + + /** + * Length of the foreign address. + */ + socklen_t addr_len; + + /** + * Socket for this connection. Set to -1 if + * this connection has died (daemon should clean + * up in that case). + */ + int socket_fd; + + /** + * Have we finished receiving all of the headers yet? + * Set to 1 once we are done processing all of the + * headers. Note that due to pipelining, it is + * possible that the NEXT request is already + * (partially) waiting in the read buffer. + */ + int headersReceived; + + /** + * Have we finished receiving the data from a + * potential file-upload? + */ + int bodyReceived; + + /** + * Have we finished sending all of the headers yet? + */ + int headersSent; + + /** + * HTTP response code. Only valid if response object + * is already set. + */ + unsigned int responseCode; + +}; + + + struct MHD_Daemon { struct MHD_Access_Handler * handlers; |