Exchange ========== --------------------------------------------------------------- Types --------------------------------------------------------------- .. c:type:: http_state Enum type used to track HTTP exchange parse state. .. code-block:: c :caption: Definition YMO_ENUM8_TYPEDEF(http_state) { HTTP_STATE_CONNECTED, HTTP_STATE_REQUEST_METHOD, HTTP_STATE_REQUEST_URI_PATH, HTTP_STATE_REQUEST_QUERY, HTTP_STATE_REQUEST_FRAGMENT, HTTP_STATE_REQUEST_VERSION, HTTP_STATE_CRLF, HTTP_STATE_HEADER_NAME, HTTP_STATE_HEADER_VALUE_LEADING_SPACE, HTTP_STATE_HEADER_VALUE, HTTP_STATE_HEADERS_COMPLETE, HTTP_STATE_EXPECT, HTTP_STATE_BODY_CHUNK_HEADER, HTTP_STATE_BODY, HTTP_STATE_BODY_CHUNK_TRAILER, HTTP_STATE_COMPLETE, } YMO_ENUM8_AS(http_state_t); .. c:type:: crlf_state Enum type used to track HTTP end of line state. .. code-block:: c :caption: Definition YMO_ENUM8_TYPEDEF(crlf_state) { HTTP_EXPECT_CRLF, HTTP_EXPECT_LF, } YMO_ENUM8_AS(crlf_state_t); .. c:struct:: ymo_http_exchange Struct used to store HTTP exchange data. .. TODO:: Move parse info stuff to separate struct and move to ymo_http_parse. .. code-block:: c :caption: Definition struct ymo_http_exchange { /* Request: */ struct ymo_http_request request; /* Parse info: */ union { /* These are used for mutually exclusive parse phases: */ struct { char* hdr_name; char* hdr_value; ymo_http_hdr_id_t h_id; }; size_t body_remain; }; http_state_t state; http_state_t next_state; char* recv_current; size_t remain; char recv_buf[YMO_HTTP_RECV_BUF_SIZE]; /* Response: * * (TODO: just add this to the exchange and skip the malloc/free). */ ymo_http_response_t* response; }; --------------------------------------------------------------- Functions --------------------------------------------------------------- .. c:function:: ymo_http_exchange_t* ymo_http_exchange_create(void) Create a new http exchange object. :returns: pointer to a new exchange, or NULL on failure. .. c:function:: void ymo_http_exchange_reset(ymo_http_exchange_t* exchange) Reset an HTTP exchange struct to handle a new incoming exchange .. c:function:: void ymo_http_exchange_free(ymo_http_exchange_t* exchange) Free an http exchange object. :param exchange: exchange to free .. c:function:: ymo_http_flags_t ymo_http_request_flags(const ymo_http_exchange_t* exchange) Used to get common HTTP exchange traits :param exchange: the HTTP exchange instance to query :returns: ymo_http_flags_t type indicating exchange traits