src/microspdy/structures.h File Reference

internal and public structures -- most of the structs used by the library are defined here More...

#include "platform.h"
#include "microspdy.h"
#include "io.h"
Include dependency graph for structures.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SPDYF_Response_Queue
struct  SPDY_NameValue
struct  SPDYF_Stream
struct  SPDY_Session
struct  SPDY_Daemon
struct  SPDY_Response

Defines

#define DLL_insert(head, tail, element)
#define DLL_remove(head, tail, element)
#define SPDYF_CONTROL_FRAME_HTON(frame)
#define SPDYF_CONTROL_FRAME_NTOH(frame)
#define SPDYF_DATA_FRAME_HTON(frame)
#define SPDYF_DATA_FRAME_NTOH(frame)

Typedefs

typedef int(* SPDYF_NewDataCallback )(void *cls, struct SPDYF_Stream *stream, const void *buf, size_t size, bool more)
typedef int(* SPDYF_NewStreamCallback )(void *cls, struct SPDYF_Stream *stream)
typedef void(* SPDYF_ResponseQueueResultCallback )(void *cls, struct SPDYF_Response_Queue *response_queue, enum SPDY_RESPONSE_RESULT status)

Enumerations

enum  SPDY_CONTROL_FRAME_TYPES {
  SPDY_CONTROL_FRAME_TYPES_SYN_STREAM = 1, SPDY_CONTROL_FRAME_TYPES_SYN_REPLY = 2, SPDY_CONTROL_FRAME_TYPES_RST_STREAM = 3, SPDY_CONTROL_FRAME_TYPES_SETTINGS = 4,
  SPDY_CONTROL_FRAME_TYPES_PING = 6, SPDY_CONTROL_FRAME_TYPES_GOAWAY = 7, SPDY_CONTROL_FRAME_TYPES_HEADERS = 8, SPDY_CONTROL_FRAME_TYPES_WINDOW_UPDATE = 9,
  SPDY_CONTROL_FRAME_TYPES_CREDENTIAL = 11
}
enum  SPDY_SESSION_STATUS {
  SPDY_SESSION_STATUS_CLOSING = 0, SPDY_SESSION_STATUS_WAIT_FOR_HEADER = 1, SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER = 2, SPDY_SESSION_STATUS_WAIT_FOR_BODY = 3,
  SPDY_SESSION_STATUS_IGNORE_BYTES = 4, SPDY_SESSION_STATUS_FLUSHING = 5
}
enum  SPDY_SYN_STREAM_FLAG { SPDY_SYN_STREAM_FLAG_FIN = 1, SPDY_SYN_STREAM_FLAG_UNIDIRECTIONAL = 2 }
enum  SPDY_SYN_REPLY_FLAG { SPDY_SYN_REPLY_FLAG_FIN = 1 }
enum  SPDY_DATA_FLAG { SPDY_DATA_FLAG_FIN = 1, SPDY_DATA_FLAG_COMPRESS = 2 }
enum  SPDY_RST_STREAM_STATUS {
  SPDY_RST_STREAM_STATUS_PROTOCOL_ERROR = 1, SPDY_RST_STREAM_STATUS_INVALID_STREAM = 2, SPDY_RST_STREAM_STATUS_REFUSED_STREAM = 3, SPDY_RST_STREAM_STATUS_UNSUPPORTED_VERSION = 4,
  SPDY_RST_STREAM_STATUS_CANCEL = 5, SPDY_RST_STREAM_STATUS_INTERNAL_ERROR = 6, SPDY_RST_STREAM_STATUS_FLOW_CONTROL_ERROR = 7, SPDY_RST_STREAM_STATUS_STREAM_IN_USE = 8,
  SPDY_RST_STREAM_STATUS_STREAM_ALREADY_CLOSED = 9, SPDY_RST_STREAM_STATUS_INVALID_CREDENTIALS = 10, SPDY_RST_STREAM_STATUS_FRAME_TOO_LARGE = 11
}
enum  SPDY_GOAWAY_STATUS { SPDY_GOAWAY_STATUS_OK = 0, SPDY_GOAWAY_STATUS_PROTOCOL_ERROR = 1, SPDY_GOAWAY_STATUS_INTERNAL_ERROR = 11 }

Functions

struct __attribute__ ((__packed__)) SPDYF_Control_Frame
struct SPDYF_Response_QueueSPDYF_response_queue_create (bool is_data, void *data, size_t data_size, struct SPDY_Response *response, struct SPDYF_Stream *stream, bool closestream, SPDYF_ResponseQueueResultCallback frqcb, void *frqcb_cls, SPDY_ResponseResultCallback rrcb, void *rrcb_cls)
void SPDYF_response_queue_destroy (struct SPDYF_Response_Queue *response_queue)
int SPDYF_name_value_is_empty (struct SPDY_NameValue *container)
int SPDYF_name_value_from_stream (void *stream, size_t size, struct SPDY_NameValue **container)
ssize_t SPDYF_name_value_to_stream (struct SPDY_NameValue *container[], int num_containers, void **stream)

Detailed Description

internal and public structures -- most of the structs used by the library are defined here

Author:
Andrey Uzunov

Definition in file structures.h.


Define Documentation

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

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

Parameters:
head pointer to the head of the DLL (struct ? *)
tail pointer to the tail of the DLL (struct ? *)
element element to insert (struct ? *)

Definition at line 1059 of file structures.h.

#define DLL_remove ( head,
tail,
element   ) 
Value:
do { \
        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:
head pointer to the head of the DLL (struct ? *)
tail pointer to the tail of the DLL (struct ? *)
element element to remove (struct ? *)

Definition at line 1078 of file structures.h.

#define SPDYF_CONTROL_FRAME_HTON ( frame   ) 
Value:
do { \
        (*((uint16_t *) frame  )) = (*((uint8_t *) (frame) +1 )) | ((*((uint8_t *) frame  ))<<8);\
        (frame)->type = htons((frame)->type); \
        (frame)->length = HTON24((frame)->length); \
        } while (0)

Convert all integers in a SPDY control frame headers structure from host byte order to network byte order.

Parameters:
frame input and output structure (struct SPDY_Control_Frame *)

Definition at line 1100 of file structures.h.

Referenced by SPDYF_handler_write_goaway(), SPDYF_handler_write_rst_stream(), SPDYF_handler_write_syn_reply(), and SPDYF_handler_write_window_update().

#define SPDYF_CONTROL_FRAME_NTOH ( frame   ) 
Value:
do { \
        (*((uint16_t *) frame  )) = (*((uint8_t *) (frame) +1 )) | ((*((uint8_t *) frame  ))<<8);\
        (frame)->type = ntohs((frame)->type); \
        (frame)->length = NTOH24((frame)->length); \
        } while (0)

Convert all integers in a SPDY control frame headers structure from network byte order to host byte order.

Parameters:
frame input and output structure (struct SPDY_Control_Frame *)

Definition at line 1117 of file structures.h.

Referenced by SPDYF_session_idle().

#define SPDYF_DATA_FRAME_HTON ( frame   ) 
Value:
do { \
        *((uint32_t *) frame  ) = htonl(*((uint32_t *) frame  ));\
        (frame)->length = HTON24((frame)->length); \
        } while (0)

Convert all integers in a SPDY data frame headers structure from host byte order to network byte order.

Parameters:
frame input and output structure (struct SPDY_Data_Frame *)

Definition at line 1134 of file structures.h.

Referenced by SPDYF_handler_write_data().

#define SPDYF_DATA_FRAME_NTOH ( frame   ) 
Value:
do { \
        *((uint32_t *) frame  ) = ntohl(*((uint32_t *) frame  ));\
        (frame)->length = NTOH24((frame)->length); \
        } while (0)

Convert all integers in a SPDY data frame headers structure from network byte order to host byte order.

Parameters:
frame input and output structure (struct SPDY_Data_Frame *)

Definition at line 1150 of file structures.h.

Referenced by SPDYF_session_idle().


Typedef Documentation

typedef int(* SPDYF_NewDataCallback)(void *cls, struct SPDYF_Stream *stream, const void *buf, size_t size, bool more)

Callback for received new data chunk.

Parameters:
cls client-defined closure
stream handler
buf data chunk from the data
size the size of the data chunk 'buf' in bytes
more false if this is the last frame received on this stream. Note: true does not mean that more data will come, exceptional situation is possible
Returns:
SPDY_YES to continue calling the function, SPDY_NO to stop calling the function for this stream

Definition at line 335 of file structures.h.

typedef int(* SPDYF_NewStreamCallback)(void *cls, struct SPDYF_Stream *stream)

Callback for new stream. To be used in the application layer of the lib.

Parameters:
cls 
stream the new stream
Returns:
SPDY_YES on success, SPDY_NO if error occurs

Definition at line 352 of file structures.h.

typedef void(* SPDYF_ResponseQueueResultCallback)(void *cls, struct SPDYF_Response_Queue *response_queue, enum SPDY_RESPONSE_RESULT status)

Callback to be called when the response queue object was handled and the data was already sent.

Parameters:
cls 
response_queue the SPDYF_Response_Queue structure which will be cleaned very soon
status shows if actually the response was sent or it was discarded by the lib for any reason (e.g., closing session, closing stream, stopping daemon, etc.). It is possible that status indicates an error but part of the response (in one or several frames) was sent to the client.

Definition at line 370 of file structures.h.


Enumeration Type Documentation

All possible SPDY control frame types. The number is used in the header of the control frame.

Enumerator:
SPDY_CONTROL_FRAME_TYPES_SYN_STREAM 

The SYN_STREAM control frame allows the sender to asynchronously create a stream between the endpoints.

SPDY_CONTROL_FRAME_TYPES_SYN_REPLY 

SYN_REPLY indicates the acceptance of a stream creation by the recipient of a SYN_STREAM frame.

SPDY_CONTROL_FRAME_TYPES_RST_STREAM 

The RST_STREAM frame allows for abnormal termination of a stream. When sent by the creator of a stream, it indicates the creator wishes to cancel the stream. When sent by the recipient of a stream, it indicates an error or that the recipient did not want to accept the stream, so the stream should be closed.

SPDY_CONTROL_FRAME_TYPES_SETTINGS 

A SETTINGS frame contains a set of id/value pairs for communicating configuration data about how the two endpoints may communicate. SETTINGS frames can be sent at any time by either endpoint, are optionally sent, and are fully asynchronous. When the server is the sender, the sender can request that configuration data be persisted by the client across SPDY sessions and returned to the server in future communications.

SPDY_CONTROL_FRAME_TYPES_PING 

The PING control frame is a mechanism for measuring a minimal round-trip time from the sender. It can be sent from the client or the server. Recipients of a PING frame should send an identical frame to the sender as soon as possible (if there is other pending data waiting to be sent, PING should take highest priority). Each ping sent by a sender should use a unique ID.

SPDY_CONTROL_FRAME_TYPES_GOAWAY 

The GOAWAY control frame is a mechanism to tell the remote side of the connection to stop creating streams on this session. It can be sent from the client or the server.

SPDY_CONTROL_FRAME_TYPES_HEADERS 

The HEADERS frame augments a stream with additional headers. It may be optionally sent on an existing stream at any time. Specific application of the headers in this frame is application-dependent. The name/value header block within this frame is compressed.

SPDY_CONTROL_FRAME_TYPES_WINDOW_UPDATE 

The WINDOW_UPDATE control frame is used to implement per stream flow control in SPDY. Flow control in SPDY is per hop, that is, only between the two endpoints of a SPDY connection. If there are one or more intermediaries between the client and the origin server, flow control signals are not explicitly forwarded by the intermediaries.

SPDY_CONTROL_FRAME_TYPES_CREDENTIAL 

The CREDENTIAL control frame is used by the client to send additional client certificates to the server. A SPDY client may decide to send requests for resources from different origins on the same SPDY session if it decides that that server handles both origins. For example if the IP address associated with both hostnames matches and the SSL server certificate presented in the initial handshake is valid for both hostnames. However, because the SSL connection can contain at most one client certificate, the client needs a mechanism to send additional client certificates to the server.

Definition at line 38 of file structures.h.

Specific flags for the data frame.

Enumerator:
SPDY_DATA_FLAG_FIN 

The sender won't send any more frames on this stream.

SPDY_DATA_FLAG_COMPRESS 

The data in the frame is compressed. This flag appears only in the draft on ietf.org but not on chromium.org.

Definition at line 201 of file structures.h.

Status code within GOAWAY control frame.

Enumerator:
SPDY_GOAWAY_STATUS_OK 

This is a normal session teardown.

SPDY_GOAWAY_STATUS_PROTOCOL_ERROR 

This is a generic error, and should only be used if a more specific error is not available.

SPDY_GOAWAY_STATUS_INTERNAL_ERROR 

This is a generic error which can be used when the implementation has internally failed, not due to anything in the protocol.

Definition at line 295 of file structures.h.

Status code within RST_STREAM control frame.

Enumerator:
SPDY_RST_STREAM_STATUS_PROTOCOL_ERROR 

This is a generic error, and should only be used if a more specific error is not available.

SPDY_RST_STREAM_STATUS_INVALID_STREAM 

This is returned when a frame is received for a stream which is not active.

SPDY_RST_STREAM_STATUS_REFUSED_STREAM 

Indicates that the stream was refused before any processing has been done on the stream.

SPDY_RST_STREAM_STATUS_UNSUPPORTED_VERSION 

Indicates that the recipient of a stream does not support the SPDY version requested.

SPDY_RST_STREAM_STATUS_CANCEL 

Used by the creator of a stream to indicate that the stream is no longer needed.

SPDY_RST_STREAM_STATUS_INTERNAL_ERROR 

This is a generic error which can be used when the implementation has internally failed, not due to anything in the protocol.

SPDY_RST_STREAM_STATUS_FLOW_CONTROL_ERROR 

The endpoint detected that its peer violated the flow control protocol.

SPDY_RST_STREAM_STATUS_STREAM_IN_USE 

The endpoint received a SYN_REPLY for a stream already open.

SPDY_RST_STREAM_STATUS_STREAM_ALREADY_CLOSED 

The endpoint received a data or SYN_REPLY frame for a stream which is half closed.

SPDY_RST_STREAM_STATUS_INVALID_CREDENTIALS 

The server received a request for a resource whose origin does not have valid credentials in the client certificate vector.

SPDY_RST_STREAM_STATUS_FRAME_TOO_LARGE 

The endpoint received a frame which this implementation could not support. If FRAME_TOO_LARGE is sent for a SYN_STREAM, HEADERS, or SYN_REPLY frame without fully processing the compressed portion of those frames, then the compression state will be out-of-sync with the other endpoint. In this case, senders of FRAME_TOO_LARGE MUST close the session.

Definition at line 219 of file structures.h.

SPDY_SESSION_STATUS is used to show the current receiving state of each session, i.e. what is expected to come now, and how it should be handled.

Enumerator:
SPDY_SESSION_STATUS_CLOSING 

The session is in closing state, do not read read anything from it. Do not write anything to it.

SPDY_SESSION_STATUS_WAIT_FOR_HEADER 

Wait for new SPDY frame to come.

SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER 

The standard 8 byte header of the SPDY frame was received and handled. Wait for the specific (sub)headers according to the frame type.

SPDY_SESSION_STATUS_WAIT_FOR_BODY 

The specific (sub)headers were received and handled. Wait for the "body", i.e. wait for the name/value pairs compressed by zlib.

SPDY_SESSION_STATUS_IGNORE_BYTES 

Ignore all the bytes read from the socket, e.g. larger frames.

SPDY_SESSION_STATUS_FLUSHING 

The session is in pre-closing state, do not read read anything from it. In this state the output queue will be written to the socket.

Definition at line 129 of file structures.h.

Specific flags for the SYN_REPLY control frame.

Enumerator:
SPDY_SYN_REPLY_FLAG_FIN 

The sender won't send any more frames on this stream.

Definition at line 189 of file structures.h.

Specific flags for the SYN_STREAM control frame.

Enumerator:
SPDY_SYN_STREAM_FLAG_FIN 

The sender won't send any more frames on this stream.

SPDY_SYN_STREAM_FLAG_UNIDIRECTIONAL 

The sender creates this stream as unidirectional.

Definition at line 172 of file structures.h.


Function Documentation

struct __attribute__ ( (__packed__)   )  [read]

Representation of the control frame's headers, which are common for all types.

Representation of the data frame's headers.

Definition at line 392 of file structures.h.

int SPDYF_name_value_from_stream ( void *  stream,
size_t  size,
struct SPDY_NameValue **  container 
)

Transforms raw binary decomressed stream of headers into SPDY_NameValue, containing all of the headers and values.

Parameters:
stream that is to be transformed
size length of the stream
container will contain the newly created SPDY_NameValue container. Should point to NULL.
Returns:
SPDY_YES on success SPDY_NO on memory error SPDY_INPUT_ERROR if the provided stream is not valid

Definition at line 539 of file structures.c.

References SPDY_NameValue::name, NULL, SPDY_INPUT_ERROR, SPDY_name_value_add(), SPDY_name_value_create(), SPDY_name_value_destroy(), SPDY_NO, SPDY_YES, and SPDY_NameValue::value.

Referenced by spdyf_handler_read_syn_stream().

Here is the call graph for this function:

Here is the caller graph for this function:

int SPDYF_name_value_is_empty ( struct SPDY_NameValue container  ) 

Checks if the container is empty, i.e. created but no values were added to it.

Parameters:
container 
Returns:
SPDY_YES if empty SPDY_NO if not

Definition at line 35 of file structures.c.

References SPDY_NameValue::name, NULL, SPDY_NO, SPDY_YES, SPDYF_ASSERT, and SPDY_NameValue::value.

Referenced by SPDY_build_response(), SPDY_name_value_add(), SPDY_name_value_iterate(), and SPDY_name_value_lookup().

Here is the caller graph for this function:

ssize_t SPDYF_name_value_to_stream ( struct SPDY_NameValue container[],
int  num_containers,
void **  stream 
)

Transforms array of objects of name/values tuples, containing HTTP headers, into raw binary stream. The resulting stream is ready to be compressed and sent.

Parameters:
container one or more SPDY_NameValue objects. Each object contains multiple number of name/value tuples.
num_containers length of the array
stream will contain the resulting stream. Should point to NULL.
Returns:
length of stream or value less than 0 indicating error

Definition at line 449 of file structures.c.

References SPDY_NameValue::name, SPDY_NameValue::next, NULL, SPDY_NameValue::num_values, SPDYF_ASSERT, and SPDY_NameValue::value.

Referenced by SPDY_build_response().

Here is the caller graph for this function:

struct SPDYF_Response_Queue* SPDYF_response_queue_create ( bool  is_data,
void *  data,
size_t  data_size,
struct SPDY_Response response,
struct SPDYF_Stream stream,
bool  closestream,
SPDYF_ResponseQueueResultCallback  frqcb,
void *  frqcb_cls,
SPDY_ResponseResultCallback  rrcb,
void *  rrcb_cls 
) [read]

Creates one or more new SPDYF_Response_Queue object to be put on the response queue.

Parameters:
is_data whether new data frame or new control frame will be crerated
data the row stream which will be used as the body of the frame
data_size length of data
response object, part of which is the frame
stream on which data is to be sent
closestream TRUE if the frame must close the stream (with flag)
frqcb callback to notify application layer when the frame has been sent or discarded
frqcb_cls closure for frqcb
rrcb callback used by the application layer to notify the application when the frame has been sent or discarded. frqcb will call it
rrcb_cls closure for rrcb
Returns:
double linked list of SPDYF_Response_Queue structures: one or more frames are returned based on the size of the data

Definition at line 284 of file structures.c.

References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, SPDYF_Response_Queue::data_frame, SPDYF_Response_Queue::data_size, SPDYF_Response_Queue::frqcb, SPDYF_Response_Queue::frqcb_cls, SPDYF_Response_Queue::is_data, SPDYF_Response_Queue::next, NULL, SPDYF_Response_Queue::prev, SPDYF_Response_Queue::process_response_handler, SPDY_Response::rcb, SPDYF_Response_Queue::response, SPDYF_Response_Queue::rrcb, SPDYF_Response_Queue::rrcb_cls, SPDY_CONTROL_FRAME_TYPES_SYN_REPLY, SPDY_DATA_FLAG_FIN, SPDY_MAX_SUPPORTED_FRAME_SIZE, SPDY_SYN_REPLY_FLAG_FIN, SPDY_VERSION, SPDYF_ASSERT, SPDYF_handler_write_data(), SPDYF_handler_write_syn_reply(), SPDYF_Response_Queue::stream, and SPDYF_Stream::stream_id.

Referenced by SPDY_queue_response(), and SPDYF_handler_write_data().

Here is the call graph for this function:

Here is the caller graph for this function:

void SPDYF_response_queue_destroy ( struct SPDYF_Response_Queue response_queue  ) 

Destroys SPDYF_Response_Queue structure and whatever is in it.

Parameters:
response_queue to destroy

Definition at line 429 of file structures.c.

References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data, SPDYF_Response_Queue::data_frame, SPDYF_Response_Queue::is_data, SPDY_CONTROL_FRAME_TYPES_GOAWAY, and SPDY_CONTROL_FRAME_TYPES_RST_STREAM.

Referenced by SPDY_queue_response(), SPDYF_session_destroy(), and SPDYF_session_write().

Here is the caller graph for this function:


Generated on 15 Oct 2014 for GNU libmicrohttpd by  doxygen 1.6.1