GNU libmicrohttpd 0.9.77
Loading...
Searching...
No Matches
internal.h File Reference

internal shared structures More...

#include "mhd_options.h"
#include "platform.h"
#include "microhttpd2.h"
#include "microhttpd_tls.h"
#include "mhd_assert.h"
#include "mhd_compat.h"
#include "mhd_itc.h"
#include "mhd_mono_clock.h"
#include "memorypool.h"
#include "mhd_threads.h"
#include "mhd_locks.h"
#include "mhd_sockets.h"
#include "mhd_str.h"
#include "mhd_itc_types.h"
Include dependency graph for internal.h:

Go to the source code of this file.

Data Structures

struct  MHD_HTTP_Header
 
struct  MHD_Request
 
struct  MHD_Connection
 
struct  MHD_Daemon
 
struct  MHD_Action
 
struct  MHD_Response
 

Macros

#define MHD_PANIC(msg)
 
#define MHD_fd_close_chk_(fd)
 
#define EXTRA_CHECKS   MHD_NO
 
#define MHD_MAX(a, b)   (((a)<(b)) ? (b) : (a))
 
#define MHD_MIN(a, b)   (((a)<(b)) ? (a) : (b))
 
#define MHD_BUF_INC_SIZE   1024
 
#define BUILTIN_NOT_REACHED
 
#define POOL_SIZE_DEFAULT   (32 * 1024)
 
#define BUF_INC_SIZE_DEFAULT   1024
 
#define LISTEN_BACKLOG_DEFAULT   511
 
#define FO_QUEUE_LENGTH_DEFAULT   50
 
#define DLL_insert(head, tail, element)
 
#define DLL_remove(head, tail, element)
 
#define XDLL_insert(head, tail, element)
 
#define XDLL_remove(head, tail, element)
 
#define EDLL_insert(head, tail, element)
 
#define EDLL_remove(head, tail, element)
 
#define MHD_ERR_AGAIN_   (-3073)
 
#define MHD_ERR_CONNRESET_   (-3074)
 
#define MHD_ERR_NOTCONN_   (-3075)
 
#define MHD_ERR_NOMEM_   (-3076)
 
#define MHD_ERR_BADF_   (-3077)
 
#define MHD_ERR_INVAL_   (-3078)
 

Typedefs

typedef ssize_t(* ReceiveCallback) (struct MHD_Connection *conn, void *write_to, size_t max_bytes)
 
typedef ssize_t(* TransmitCallback) (struct MHD_Connection *conn, const void *read_from, size_t max_bytes)
 
typedef enum MHD_StatusCode(* ActionCallback) (void *cls, struct MHD_Request *request)
 
typedef bool(* MHD_ArgumentIterator_) (struct MHD_Request *request, const char *key, const char *value, enum MHD_ValueKind kind)
 

Enumerations

enum  MHD_ConnKeepAlive { MHD_CONN_MUST_CLOSE = -1 , MHD_CONN_KEEPALIVE_UNKOWN = 0 , MHD_CONN_USE_KEEPALIVE = 1 }
 
enum  MHD_REQUEST_STATE {
  MHD_REQUEST_INIT = 0 , MHD_REQUEST_URL_RECEIVED = MHD_REQUEST_INIT + 1 , MHD_REQUEST_HEADER_PART_RECEIVED = MHD_REQUEST_URL_RECEIVED + 1 , MHD_REQUEST_HEADERS_RECEIVED = MHD_REQUEST_HEADER_PART_RECEIVED + 1 ,
  MHD_REQUEST_HEADERS_PROCESSED = MHD_REQUEST_HEADERS_RECEIVED + 1 , MHD_REQUEST_CONTINUE_SENDING = MHD_REQUEST_HEADERS_PROCESSED + 1 , MHD_REQUEST_CONTINUE_SENT = MHD_REQUEST_CONTINUE_SENDING + 1 , MHD_REQUEST_BODY_RECEIVED = MHD_REQUEST_CONTINUE_SENT + 1 ,
  MHD_REQUEST_FOOTER_PART_RECEIVED = MHD_REQUEST_BODY_RECEIVED + 1 , MHD_REQUEST_FOOTERS_RECEIVED = MHD_REQUEST_FOOTER_PART_RECEIVED + 1 , MHD_REQUEST_HEADERS_SENDING = MHD_REQUEST_FOOTERS_RECEIVED + 1 , MHD_REQUEST_HEADERS_SENT = MHD_REQUEST_HEADERS_SENDING + 1 ,
  MHD_REQUEST_NORMAL_BODY_READY = MHD_REQUEST_HEADERS_SENT + 1 , MHD_REQUEST_NORMAL_BODY_UNREADY = MHD_REQUEST_NORMAL_BODY_READY + 1 , MHD_REQUEST_CHUNKED_BODY_READY = MHD_REQUEST_NORMAL_BODY_UNREADY + 1 , MHD_REQUEST_CHUNKED_BODY_UNREADY = MHD_REQUEST_CHUNKED_BODY_READY + 1 ,
  MHD_REQUEST_BODY_SENT = MHD_REQUEST_CHUNKED_BODY_UNREADY + 1 , MHD_REQUEST_FOOTERS_SENDING = MHD_REQUEST_BODY_SENT + 1 , MHD_REQUEST_FOOTERS_SENT = MHD_REQUEST_FOOTERS_SENDING + 1 , MHD_REQUEST_CLOSED = MHD_REQUEST_FOOTERS_SENT + 1
}
 
enum  MHD_EpollState {
  MHD_EPOLL_STATE_UNREADY = 0 , MHD_EPOLL_STATE_READ_READY = 1 , MHD_EPOLL_STATE_WRITE_READY = 2 , MHD_EPOLL_STATE_IN_EREADY_EDLL = 4 ,
  MHD_EPOLL_STATE_IN_EPOLL_SET = 8 , MHD_EPOLL_STATE_SUSPENDED = 16 , MHD_EPOLL_STATE_ERROR = 128
}
 

Functions

bool MHD_parse_arguments_ (struct MHD_Request *request, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, unsigned int *num_headers)
 

Variables

MHD_PanicCallback mhd_panic
 
void * mhd_panic_cls
 

Detailed Description

internal shared structures

Author
Daniel Pittman
Christian Grothoff

Definition in file internal.h.

Macro Definition Documentation

◆ BUF_INC_SIZE_DEFAULT

#define BUF_INC_SIZE_DEFAULT   1024

Default minimum size by which MHD tries to increment read/write buffers. We usually begin with half the available pool space for the IO-buffer, but if absolutely needed we additively grow by the number of bytes given here (up to – theoretically – the full pool space).

Definition at line 1290 of file internal.h.

◆ BUILTIN_NOT_REACHED

#define BUILTIN_NOT_REACHED

Definition at line 140 of file internal.h.

◆ DLL_insert

#define DLL_insert (   head,
  tail,
  element 
)
Value:
do { \
mhd_assert (NULL == (element)->next); \
mhd_assert (NULL == (element)->prev); \
(element)->next = (head); \
(element)->prev = NULL; \
if ((tail) == NULL) \
(tail) = element; \
else \
(head)->prev = element; \
(head) = (element); } while (0)
#define NULL

Insert an element at the head of a DLL. Assumes that head, tail and element are structs with prev and next fields.

Parameters
headpointer to the head of the DLL
tailpointer to the tail of the DLL
elementelement to insert

Definition at line 1743 of file internal.h.

◆ DLL_remove

#define DLL_remove (   head,
  tail,
  element 
)
Value:
do { \
mhd_assert ( (NULL != (element)->next) || ((element) == (tail))); \
mhd_assert ( (NULL != (element)->prev) || ((element) == (head))); \
if ((element)->prev == NULL) \
(head) = (element)->next; \
else \
(element)->prev->next = (element)->next; \
if ((element)->next == NULL) \
(tail) = (element)->prev; \
else \
(element)->next->prev = (element)->prev; \
(element)->next = NULL; \
(element)->prev = NULL; } while (0)

Remove an element from a DLL. Assumes that head, tail and element are structs with prev and next fields.

Parameters
headpointer to the head of the DLL
tailpointer to the tail of the DLL
elementelement to remove

Definition at line 1763 of file internal.h.

◆ EDLL_insert

#define EDLL_insert (   head,
  tail,
  element 
)
Value:
do { \
(element)->nextE = (head); \
(element)->prevE = NULL; \
if ((tail) == NULL) \
(tail) = element; \
else \
(head)->prevE = element; \
(head) = (element); } while (0)

Insert an element at the head of a EDLL. Assumes that head, tail and element are structs with prevE and nextE fields.

Parameters
headpointer to the head of the EDLL
tailpointer to the tail of the EDLL
elementelement to insert

Definition at line 1829 of file internal.h.

◆ EDLL_remove

#define EDLL_remove (   head,
  tail,
  element 
)
Value:
do { \
if ((element)->prevE == NULL) \
(head) = (element)->nextE; \
else \
(element)->prevE->nextE = (element)->nextE; \
if ((element)->nextE == NULL) \
(tail) = (element)->prevE; \
else \
(element)->nextE->prevE = (element)->prevE; \
(element)->nextE = NULL; \
(element)->prevE = NULL; } while (0)

Remove an element from a EDLL. Assumes that head, tail and element are structs with prevE and nextE fields.

Parameters
headpointer to the head of the EDLL
tailpointer to the tail of the EDLL
elementelement to remove

Definition at line 1847 of file internal.h.

◆ EXTRA_CHECKS

#define EXTRA_CHECKS   MHD_NO

Should we perform additional sanity checks at runtime (on our internal invariants)? This may lead to aborts, but can be useful for debugging.

Definition at line 107 of file internal.h.

◆ FO_QUEUE_LENGTH_DEFAULT

#define FO_QUEUE_LENGTH_DEFAULT   50

Default queue length to use with fast open.

Definition at line 1341 of file internal.h.

◆ LISTEN_BACKLOG_DEFAULT

#define LISTEN_BACKLOG_DEFAULT   511

Default value we use for the listen backlog.

Definition at line 1329 of file internal.h.

◆ MHD_BUF_INC_SIZE

#define MHD_BUF_INC_SIZE   1024

Minimum size by which MHD tries to increment read/write buffers. We usually begin with half the available pool space for the IO-buffer, but if absolutely needed we additively grow by the number of bytes given here (up to – theoretically – the full pool space).

Definition at line 120 of file internal.h.

◆ MHD_ERR_AGAIN_

#define MHD_ERR_AGAIN_   (-3073)

Error code similar to EGAIN or EINTR

Definition at line 1863 of file internal.h.

◆ MHD_ERR_BADF_

#define MHD_ERR_BADF_   (-3077)

"Bad FD" error code

Definition at line 1884 of file internal.h.

◆ MHD_ERR_CONNRESET_

#define MHD_ERR_CONNRESET_   (-3074)

Connection was hard-closed by remote peer.

Definition at line 1868 of file internal.h.

◆ MHD_ERR_INVAL_

#define MHD_ERR_INVAL_   (-3078)

Error code similar to EINVAL

Definition at line 1889 of file internal.h.

◆ MHD_ERR_NOMEM_

#define MHD_ERR_NOMEM_   (-3076)

"Not enough memory" error code

Definition at line 1879 of file internal.h.

◆ MHD_ERR_NOTCONN_

#define MHD_ERR_NOTCONN_   (-3075)

Connection is not connected anymore due to network error or any other reason.

Definition at line 1874 of file internal.h.

◆ MHD_fd_close_chk_

#define MHD_fd_close_chk_ (   fd)
Value:
do { \
if ( (0 != close ((fd)) && (EBADF == errno)) ) \
MHD_PANIC (_ ("Failed to close FD.\n")); \
} while (0)
#define _(String)
Definition mhd_options.h:42
int fd

Close FD and abort execution if error is detected.

Parameters
fdthe FD to close

Definition at line 98 of file internal.h.

◆ MHD_MAX

#define MHD_MAX (   a,
 
)    (((a)<(b)) ? (b) : (a))

Definition at line 109 of file internal.h.

◆ MHD_MIN

#define MHD_MIN (   a,
 
)    (((a)<(b)) ? (a) : (b))

Definition at line 110 of file internal.h.

◆ MHD_PANIC

#define MHD_PANIC (   msg)
Value:
do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
BUILTIN_NOT_REACHED; } while (0)
MHD_PanicCallback mhd_panic
Definition panic.c:31
#define BUILTIN_NOT_REACHED
Definition internal.h:140
void * mhd_panic_cls
Definition panic.c:36

Trigger 'panic' action based on fatal errors.

Parameters
msgerror message (const char *)

Definition at line 69 of file internal.h.

◆ POOL_SIZE_DEFAULT

#define POOL_SIZE_DEFAULT   (32 * 1024)

Default size of the per-connection memory pool.

Definition at line 1276 of file internal.h.

◆ XDLL_insert

#define XDLL_insert (   head,
  tail,
  element 
)
Value:
do { \
mhd_assert (NULL == (element)->nextX); \
mhd_assert (NULL == (element)->prevX); \
(element)->nextX = (head); \
(element)->prevX = NULL; \
if (NULL == (tail)) \
(tail) = element; \
else \
(head)->prevX = element; \
(head) = (element); } while (0)

Insert an element at the head of a XDLL. Assumes that head, tail and element are structs with prevX and nextX fields.

Parameters
headpointer to the head of the XDLL
tailpointer to the tail of the XDLL
elementelement to insert

Definition at line 1786 of file internal.h.

◆ XDLL_remove

#define XDLL_remove (   head,
  tail,
  element 
)
Value:
do { \
mhd_assert ( (NULL != (element)->nextX) || ((element) == (tail))); \
mhd_assert ( (NULL != (element)->prevX) || ((element) == (head))); \
if (NULL == (element)->prevX) \
(head) = (element)->nextX; \
else \
(element)->prevX->nextX = (element)->nextX; \
if (NULL == (element)->nextX) \
(tail) = (element)->prevX; \
else \
(element)->nextX->prevX = (element)->prevX; \
(element)->nextX = NULL; \
(element)->prevX = NULL; } while (0)

Remove an element from a XDLL. Assumes that head, tail and element are structs with prevX and nextX fields.

Parameters
headpointer to the head of the XDLL
tailpointer to the tail of the XDLL
elementelement to remove

Definition at line 1806 of file internal.h.

Typedef Documentation

◆ ActionCallback

typedef enum MHD_StatusCode(* ActionCallback) (void *cls, struct MHD_Request *request)

Action function implementing some action to be performed on a request.

Parameters
clsaction-specfic closure
requestthe request on which the action is to be performed
Returns
#MHD_SC_OK on success, otherwise an error code

Definition at line 195 of file internal.h.

◆ MHD_ArgumentIterator_

typedef bool(* MHD_ArgumentIterator_) (struct MHD_Request *request, const char *key, const char *value, enum MHD_ValueKind kind)

Callback invoked when iterating over key / value argument pairs during parsing.

Parameters
requestcontext of the iteration
key0-terminated key string, never NULL
value0-terminated value string, may be NULL
kindorigin of the key-value pair
Returns
true on success (continue to iterate) false to signal failure (and abort iteration)

Definition at line 1706 of file internal.h.

◆ ReceiveCallback

typedef ssize_t(* ReceiveCallback) (struct MHD_Connection *conn, void *write_to, size_t max_bytes)

Function to receive plaintext data.

Parameters
connthe connection struct
write_towhere to write received data
max_bytesmaximum number of bytes to receive
Returns
number of bytes written to write_to

Definition at line 181 of file internal.h.

◆ TransmitCallback

typedef ssize_t(* TransmitCallback) (struct MHD_Connection *conn, const void *read_from, size_t max_bytes)

Function to transmit plaintext data.

Parameters
connthe connection struct
read_fromwhere to read data to transmit
max_bytesmaximum number of bytes to transmit
Returns
number of bytes transmitted

Definition at line 195 of file internal.h.

Enumeration Type Documentation

◆ MHD_ConnKeepAlive

Ability to use same connection for next request

Enumerator
MHD_CONN_MUST_CLOSE 

Connection must be closed after sending response.

MHD_CONN_KEEPALIVE_UNKOWN 

KeelAlive state is not yet determined

MHD_CONN_USE_KEEPALIVE 

Connection can be used for serving next request

Definition at line 154 of file internal.h.

◆ MHD_EpollState

State of the socket with respect to epoll (bitmask).

Enumerator
MHD_EPOLL_STATE_UNREADY 

The socket is not involved with a defined state in epoll() right now.

MHD_EPOLL_STATE_READ_READY 

epoll() told us that data was ready for reading, and we did not consume all of it yet.

MHD_EPOLL_STATE_WRITE_READY 

epoll() told us that space was available for writing, and we did not consume all of it yet.

MHD_EPOLL_STATE_IN_EREADY_EDLL 

Is this connection currently in the 'eready' EDLL?

MHD_EPOLL_STATE_IN_EPOLL_SET 

Is this connection currently in the epoll() set?

MHD_EPOLL_STATE_SUSPENDED 

Is this connection currently suspended?

MHD_EPOLL_STATE_ERROR 

Is this connection in some error state?

Definition at line 587 of file internal.h.

◆ MHD_REQUEST_STATE

States in a state machine for a request.

The main transitions are any-state to MHD_REQUEST_CLOSED, any state to state+1, MHD_REQUEST_FOOTERS_SENT to MHD_REQUEST_INIT. MHD_REQUEST_CLOSED is the terminal state and MHD_REQUEST_INIT the initial state.

Note that transitions for reading happen only after the input has been processed; transitions for writing happen after the respective data has been put into the write buffer (the write does not have to be completed yet). A transition to MHD_REQUEST_CLOSED or MHD_REQUEST_INIT requires the write to be complete.

Enumerator
MHD_REQUEST_INIT 

Request just started (no headers received). Waiting for the line with the request type, URL and version.

MHD_REQUEST_URL_RECEIVED 

1: We got the URL (and request type and version). Wait for a header line.

MHD_REQUEST_HEADER_PART_RECEIVED 

2: We got part of a multi-line request header. Wait for the rest.

MHD_REQUEST_HEADERS_RECEIVED 

3: We got the request headers. Process them.

MHD_REQUEST_HEADERS_PROCESSED 

4: We have processed the request headers. Send 100 continue.

MHD_REQUEST_CONTINUE_SENDING 

5: We have processed the headers and need to send 100 CONTINUE.

MHD_REQUEST_CONTINUE_SENT 

6: We have sent 100 CONTINUE (or do not need to). Read the message body.

MHD_REQUEST_BODY_RECEIVED 

7: We got the request body. Wait for a line of the footer.

MHD_REQUEST_FOOTER_PART_RECEIVED 

8: We got part of a line of the footer. Wait for the rest.

MHD_REQUEST_FOOTERS_RECEIVED 

9: We received the entire footer. Wait for a response to be queued and prepare the response headers.

MHD_REQUEST_HEADERS_SENDING 

10: We have prepared the response headers in the writ buffer. Send the response headers.

MHD_REQUEST_HEADERS_SENT 

11: We have sent the response headers. Get ready to send the body.

MHD_REQUEST_NORMAL_BODY_READY 

12: We are ready to send a part of a non-chunked body. Send it.

MHD_REQUEST_NORMAL_BODY_UNREADY 

13: We are waiting for the client to provide more data of a non-chunked body.

MHD_REQUEST_CHUNKED_BODY_READY 

14: We are ready to send a chunk.

MHD_REQUEST_CHUNKED_BODY_UNREADY 

15: We are waiting for the client to provide a chunk of the body.

MHD_REQUEST_BODY_SENT 

16: We have sent the response body. Prepare the footers.

MHD_REQUEST_FOOTERS_SENDING 

17: We have prepared the response footer. Send it.

MHD_REQUEST_FOOTERS_SENT 

18: We have sent the response footer. Shutdown or restart.

MHD_REQUEST_CLOSED 

19: This request is to be closed.

Definition at line 216 of file internal.h.

Function Documentation

◆ MHD_parse_arguments_()

bool MHD_parse_arguments_ ( struct MHD_Request request,
enum MHD_ValueKind  kind,
char *  args,
MHD_ArgumentIterator_  cb,
unsigned int *  num_headers 
)

Parse and unescape the arguments given by the client as part of the HTTP request URI.

Parameters
requestrequest to add headers to
kindheader kind to pass to cb
[in,out]argsargument URI string (after "?" in URI), clobbered in the process!
cbfunction to call on each key-value pair found
[out]num_headersset to the number of headers found
Returns
false on failure (cb returned false), true for success (parsing succeeded, cb always returned true)

Definition at line 190 of file internal.c.

References MHD_Request::daemon, MHD_unescape_plus(), NULL, MHD_Daemon::unescape_cb, and MHD_Daemon::unescape_cb_cls.

Referenced by check_argument_match(), parse_initial_message_line(), and parse_initial_message_line().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ mhd_panic

◆ mhd_panic_cls

void* mhd_panic_cls
extern

Closure argument for "mhd_panic".

Closure argument for mhd_panic.

Definition at line 36 of file panic.c.

Referenced by build_header_response(), MHD_create_post_processor(), post_process_multipart(), post_process_urlencoded(), process_request_body(), and process_request_body().