src/microspdy/applicationlayer.c File Reference

SPDY application or HTTP layer. More...

#include "platform.h"
#include "applicationlayer.h"
#include "alstructures.h"
#include "structures.h"
#include "internal.h"
#include "daemon.h"
#include "session.h"
Include dependency graph for applicationlayer.c:

Go to the source code of this file.

Functions

void spdy_callback_response_done (void *cls, struct SPDY_Response *response, struct SPDY_Request *request, enum SPDY_RESPONSE_RESULT status, bool streamopened)
static int spdy_handler_new_stream (void *cls, struct SPDYF_Stream *stream)
static int spdy_handler_new_data (void *cls, struct SPDYF_Stream *stream, const void *buf, size_t size, bool more)
static void spdy_handler_response_queue_result (void *cls, struct SPDYF_Response_Queue *response_queue, enum SPDY_RESPONSE_RESULT status)
int() SPDY_init (enum SPDY_IO_SUBSYSTEM io_subsystem,...)
void SPDY_deinit ()
void SPDY_run (struct SPDY_Daemon *daemon)
int SPDY_get_timeout (struct SPDY_Daemon *daemon, unsigned long long *timeout)
int SPDY_get_fdset (struct SPDY_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set)
struct SPDY_DaemonSPDY_start_daemon (uint16_t port, const char *certfile, const char *keyfile, SPDY_NewSessionCallback nscb, SPDY_SessionClosedCallback sccb, SPDY_NewRequestCallback nrcb, SPDY_NewDataCallback npdcb, void *cls,...)
void SPDY_stop_daemon (struct SPDY_Daemon *daemon)
struct SPDY_ResponseSPDY_build_response (int status, const char *statustext, const char *version, struct SPDY_NameValue *headers, const void *data, size_t size)
struct SPDY_ResponseSPDY_build_response_with_callback (int status, const char *statustext, const char *version, struct SPDY_NameValue *headers, SPDY_ResponseCallback rcb, void *rcb_cls, uint32_t block_size)
int SPDY_queue_response (struct SPDY_Request *request, struct SPDY_Response *response, bool closestream, bool consider_priority, SPDY_ResponseResultCallback rrcb, void *rrcb_cls)
socklen_t SPDY_get_remote_addr (struct SPDY_Session *session, struct sockaddr **addr)
struct SPDY_SessionSPDY_get_session_for_request (const struct SPDY_Request *request)
void * SPDY_get_cls_from_session (struct SPDY_Session *session)
void SPDY_set_cls_to_session (struct SPDY_Session *session, void *cls)
void * SPDY_get_cls_from_request (struct SPDY_Request *request)
void SPDY_set_cls_to_request (struct SPDY_Request *request, void *cls)

Detailed Description

SPDY application or HTTP layer.

Author:
Andrey Uzunov

Definition in file applicationlayer.c.


Function Documentation

struct SPDY_Response* SPDY_build_response ( int  status,
const char *  statustext,
const char *  version,
struct SPDY_NameValue headers,
const void *  data,
size_t  size 
) [read]

Create response object containing all needed headers and data. The response object is not bound to a request, so it can be used multiple times with SPDY_queue_response() and schould be destroied by calling the SPDY_destroy_response().

Currently the library does not provide compression of the body data. It is up to the user to pass already compressed data and the appropriate headers to this function when desired.

Parameters:
status HTTP status code for the response (e.g. 404)
statustext HTTP status message for the response, which will be appended to the status code (e.g. "OK"). Can be NULL
version HTTP version for the response (e.g. "http/1.1")
headers name/value structure containing additional HTTP headers. Can be NULL. Can be used multiple times, it is up to the user to destoy the object when not needed anymore.
data the body of the response. The lib will make a copy of it, so it is up to the user to take care of the memory pointed by data
size length of data. It can be 0, then the lib will send only headers
Returns:
NULL on error, handle to response object on success

Definition at line 391 of file applicationlayer.c.

References SPDY_Response::data, SPDY_Response::data_size, SPDY_Response::headers, SPDY_Response::headers_size, NULL, SPDY_name_value_add(), SPDY_name_value_create(), SPDY_name_value_destroy(), SPDY_YES, SPDYF_DEBUG, SPDYF_name_value_is_empty(), and SPDYF_name_value_to_stream().

Referenced by run(), and SPDY_build_response_with_callback().

Here is the call graph for this function:

Here is the caller graph for this function:

struct SPDY_Response* SPDY_build_response_with_callback ( int  status,
const char *  statustext,
const char *  version,
struct SPDY_NameValue headers,
SPDY_ResponseCallback  rcb,
void *  rcb_cls,
uint32_t  block_size 
) [read]

Create response object containing all needed headers. The data will be provided later when the lib calls the callback function (just before writing it to the TLS socket). The response object is not bound to a request, so it can be used multiple times with SPDY_queue_response() and schould be destroied by calling the SPDY_destroy_response().

Currently the library does not provide compression of the body data. It is up to the user to pass already compressed data and the appropriate headers to this function and the callback when desired.

Parameters:
status HTTP status code for the response (e.g. 404)
statustext HTTP status message for the response, which will be appended to the status code (e.g. "OK"). Can be NULL
version HTTP version for the response (e.g. "http/1.1")
headers name/value structure containing additional HTTP headers. Can be NULL. Can be used multiple times, it is up to the user to destoy the object when not needed anymore.
rcb callback to use to obtain response data
rcb_cls extra argument to rcb
block_size preferred block size for querying rcb (advisory only, the lib will call rcb specifying the block size); clients should pick a value that is appropriate for IO and memory performance requirements. The function will fail if the value is bigger than the maximum supported value (SPDY_MAX_SUPPORTED_FRAME_SIZE). Can be 0, then the lib will use SPDY_MAX_SUPPORTED_FRAME_SIZE instead.
Returns:
NULL on error, handle to response object on success

Definition at line 480 of file applicationlayer.c.

References NULL, SPDY_Response::rcb, SPDY_Response::rcb_block_size, SPDY_Response::rcb_cls, SPDY_build_response(), SPDY_MAX_SUPPORTED_FRAME_SIZE, and SPDYF_DEBUG.

Referenced by curl_header_cb().

Here is the call graph for this function:

Here is the caller graph for this function:

void spdy_callback_response_done ( void *  cls,
struct SPDY_Response response,
struct SPDY_Request request,
enum SPDY_RESPONSE_RESULT  status,
bool  streamopened 
)

Definition at line 35 of file applicationlayer.c.

References SPDY_destroy_request(), and SPDY_destroy_response().

Here is the call graph for this function:

void SPDY_deinit (  ) 

Deinit function for the whole lib. It can be called after finishing using the library. It frees and cleans up resources allocated in SPDY_init. Currently the function does not do anything.

Definition at line 260 of file applicationlayer.c.

References SPDY_IO_SUBSYSTEM_NONE, SPDY_IO_SUBSYSTEM_OPENSSL, SPDY_IO_SUBSYSTEM_RAW, SPDYF_ASSERT, spdyf_io_initialized, SPDYF_openssl_global_deinit(), and SPDYF_raw_global_deinit().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

void* SPDY_get_cls_from_request ( struct SPDY_Request request  ) 

Retrieves the pointer associated with the request by SPDY_set_cls_to_request().

Parameters:
request to get its cls
Returns:
same pointer added by SPDY_set_cls_to_request() or NULL when nothing was associated

Definition at line 725 of file applicationlayer.c.

References NULL, SPDYF_DEBUG, and SPDY_Request::user_cls.

Referenced by spdy_post_data_cb(), and standard_request_handler().

Here is the caller graph for this function:

void* SPDY_get_cls_from_session ( struct SPDY_Session session  ) 

Retrieves the pointer associated with SPDY_set_cls_to_session().

Parameters:
session handler to get its cls
Returns:
same pointer added by SPDY_set_cls_to_session() or NULL when nothing was associated

Definition at line 698 of file applicationlayer.c.

References NULL, SPDYF_DEBUG, and SPDY_Session::user_cls.

Referenced by session_closed_cb(), and standard_request_handler().

Here is the caller graph for this function:

int SPDY_get_fdset ( struct SPDY_Daemon daemon,
fd_set *  read_fd_set,
fd_set *  write_fd_set,
fd_set *  except_fd_set 
)

Obtain the select sets for this daemon. Only those are retrieved, which some processing should be done for, i.e. not all sockets are added to write_fd_set.

It is possible that there is nothing to be read from a socket but there is data either in the TLS subsystem's read buffers or in libmicrospdy's read buffers, which waits for being processed. In such case the file descriptor will be added to write_fd_set. Since it is very likely for the socket to be ready for writing, the select used in the application's event loop will return with success, SPDY_run will be called, the data will be processed and maybe something will be written to the socket. Without this behaviour, considering a proper event loop, data may stay in the buffers, but run is never called.

Parameters:
daemon to get sets from
read_fd_set read set
write_fd_set write set
except_fd_set except set
Returns:
largest FD added to any of the sets

Definition at line 302 of file applicationlayer.c.

References NULL, SPDY_INPUT_ERROR, SPDYF_DEBUG, and SPDYF_get_fdset().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

socklen_t SPDY_get_remote_addr ( struct SPDY_Session session,
struct sockaddr **  addr 
)

Retrieves the remote address of a given session.

Parameters:
session handler to get its remote address
addr out parameter; pointing to remote address
Returns:
length of the address structure

Definition at line 669 of file applicationlayer.c.

References SPDY_Session::addr, SPDY_Session::addr_len, NULL, and SPDYF_DEBUG.

struct SPDY_Session* SPDY_get_session_for_request ( const struct SPDY_Request request  )  [read]

Gets the session responsible for the given request.

Parameters:
request for which the session is wanted
Returns:
session handler for the request

Definition at line 685 of file applicationlayer.c.

References NULL, SPDYF_Stream::session, SPDYF_DEBUG, and SPDY_Request::stream.

Referenced by standard_request_handler().

Here is the caller graph for this function:

int SPDY_get_timeout ( struct SPDY_Daemon daemon,
unsigned long long *  timeout 
)

Obtain timeout value for select for this daemon. The returned value is how long select should at most block, not the timeout value set for connections.

Parameters:
daemon to query for timeout
timeout will be set to the timeout value (in milliseconds)
Returns:
SPDY_YES on success SPDY_NO if no connections exist that would necessiate the use of a timeout right now

Definition at line 288 of file applicationlayer.c.

References NULL, SPDY_INPUT_ERROR, SPDYF_DEBUG, and SPDYF_get_timeout().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

static int spdy_handler_new_data ( void *  cls,
struct SPDYF_Stream stream,
const void *  buf,
size_t  size,
bool  more 
) [static]

TODO

Definition at line 187 of file applicationlayer.c.

References SPDYF_Stream::cls, SPDY_Session::daemon, SPDY_Daemon::received_data_cb, and SPDYF_Stream::session.

Referenced by SPDY_start_daemon().

Here is the caller graph for this function:

static int spdy_handler_new_stream ( void *  cls,
struct SPDYF_Stream stream 
) [static]

Callback called when new stream is created. It extracts the info from the stream to create (HTTP) request object and pass it to the client.

Parameters:
cls 
stream the new SPDY stream
Returns:
SPDY_YES on success, SPDY_NO on memomry error

Definition at line 59 of file applicationlayer.c.

References SPDYF_Stream::cls, SPDY_Daemon::cls, SPDY_Session::daemon, SPDY_Request::headers, SPDYF_Stream::headers, SPDY_Request::host, SPDYF_Stream::is_in_closed, SPDY_Request::method, SPDY_NameValue::name, SPDY_Daemon::new_request_cb, SPDY_NameValue::next, NULL, SPDY_NameValue::num_values, SPDY_Request::path, SPDYF_Stream::priority, SPDY_Request::scheme, SPDYF_Stream::session, SPDY_destroy_request(), SPDY_name_value_add(), SPDY_name_value_create(), SPDY_name_value_destroy(), SPDY_NO, SPDY_YES, SPDYF_DEBUG, SPDY_Request::stream, SPDY_NameValue::value, and SPDY_Request::version.

Referenced by SPDY_start_daemon().

Here is the call graph for this function:

Here is the caller graph for this function:

static void spdy_handler_response_queue_result ( void *  cls,
struct SPDYF_Response_Queue response_queue,
enum SPDY_RESPONSE_RESULT  status 
) [static]

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

Parameters:
cls 
response_queue the object which is being handled
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 parts of the response headers and/or body (in one or several frames) were already sent to the client.

Definition at line 212 of file applicationlayer.c.

References SPDYF_Response_Queue::control_frame, SPDYF_Response_Queue::data_frame, SPDYF_Stream::is_out_closed, NULL, SPDYF_Response_Queue::response, SPDYF_Response_Queue::rrcb, SPDYF_Response_Queue::rrcb_cls, SPDYF_ASSERT, and SPDYF_Response_Queue::stream.

Referenced by SPDY_queue_response().

Here is the caller graph for this function:

int() SPDY_init ( enum SPDY_IO_SUBSYSTEM  io_subsystem,
  ... 
)

Init function for the whole library. It MUST be called before any other function of the library to initialize things like TLS context and possibly other stuff needed by the lib. Currently the call always returns SPDY_YES.

Parameters:
io_subsystem the IO subsystem that will be initialized. Several can be used with bitwise OR. If no parameter is set, the default openssl subsystem will be used.
Returns:
SPDY_YES if the library was correctly initialized and its functions can be used now; SPDY_NO on error

Definition at line 232 of file applicationlayer.c.

References SPDY_IO_SUBSYSTEM_NONE, SPDY_IO_SUBSYSTEM_OPENSSL, SPDY_IO_SUBSYSTEM_RAW, SPDY_MAX_SUPPORTED_FRAME_SIZE, SPDY_YES, SPDYF_ASSERT, SPDYF_BUFFER_SIZE, spdyf_io_initialized, SPDYF_openssl_global_init(), and SPDYF_raw_global_init().

Here is the call graph for this function:

int SPDY_queue_response ( struct SPDY_Request request,
struct SPDY_Response response,
bool  closestream,
bool  consider_priority,
SPDY_ResponseResultCallback  rrcb,
void *  rrcb_cls 
)

Queue response object to be sent to the client. A successfully queued response may never be sent, e.g. when the stream gets closed. The data will be added to the output queue. The call will fail, if the output for this session is closed (i.e. the session is closed, half or full) or the output channel for the stream, on which the request was received, is closed (i.e. the stream is closed, half or full).

Parameters:
request object identifying the request to which the response is returned
response object containg headers and data to be sent
closestream TRUE if the server does NOT intend to PUSH something more associated to this request/response later, FALSE otherwise
consider_priority if FALSE, the response will be added to the end of the queue. If TRUE, the response will be added after the last previously added response with priority of the request grater or equal to that of the current one. This means that the function should be called with TRUE each time if one wants to be sure that the output queue behaves like a priority queue
rrcb callback called when all the data was sent (last frame from response) or when that frame was discarded (e.g. the stream has been closed meanwhile)
rrcb_cls extra argument to rcb
Returns:
SPDY_NO on error or SPDY_YES on success

Definition at line 525 of file applicationlayer.c.

References SPDY_Response::data, SPDY_Response::data_size, SPDYF_Response_Queue::frqcb, SPDYF_Response_Queue::frqcb_cls, SPDY_Response::headers, SPDY_Response::headers_size, SPDYF_Stream::is_out_closed, NULL, SPDY_Response::rcb, SPDYF_Stream::session, spdy_handler_response_queue_result(), SPDY_INPUT_ERROR, SPDY_NO, SPDY_SESSION_STATUS_CLOSING, SPDY_YES, SPDYF_DEBUG, SPDYF_queue_response(), SPDYF_response_queue_create(), SPDYF_response_queue_destroy(), SPDY_Session::status, and SPDY_Request::stream.

Referenced by curl_header_cb(), and run().

Here is the call graph for this function:

Here is the caller graph for this function:

void SPDY_run ( struct SPDY_Daemon daemon  ) 

Run webserver operations. This method must be called in the client event loop.

Parameters:
daemon to run

Definition at line 275 of file applicationlayer.c.

References NULL, SPDYF_DEBUG, and SPDYF_run().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

void SPDY_set_cls_to_request ( struct SPDY_Request request,
void *  cls 
)

Associate a void pointer with a request. The data accessible by the pointer can later be used wherever the request handler is available.

Parameters:
request with which to associate a pointer
cls any data pointed by a pointer to be accessible later

Definition at line 738 of file applicationlayer.c.

References NULL, SPDYF_DEBUG, and SPDY_Request::user_cls.

Referenced by standard_request_handler().

Here is the caller graph for this function:

void SPDY_set_cls_to_session ( struct SPDY_Session session,
void *  cls 
)

Associate a void pointer with a session. The data accessible by the pointer can later be used wherever the session handler is available.

Parameters:
session handler
cls any data pointed by a pointer to be accessible later

Definition at line 711 of file applicationlayer.c.

References NULL, SPDYF_DEBUG, and SPDY_Session::user_cls.

Referenced by new_session_cb().

Here is the caller graph for this function:

struct SPDY_Daemon* SPDY_start_daemon ( uint16_t  port,
const char *  certfile,
const char *  keyfile,
SPDY_NewSessionCallback  nscb,
SPDY_SessionClosedCallback  sccb,
SPDY_NewRequestCallback  nrcb,
SPDY_NewDataCallback  npdcb,
void *  cls,
  ... 
) [read]

Start a SPDY webserver on the given port.

Parameters:
port to bind to. The value is ignored if address structure is passed as daemon option
certfile path to the certificate that will be used by server
keyfile path to the keyfile for the certificate
nscb callback called when a new SPDY session is established by a client
sccb callback called when a session is closed
nrcb callback called when a client sends request
npdcb callback called when HTTP body (POST data) is received after request
cls common extra argument to all of the callbacks
... list of options (type-value pairs, terminated with SPDY_DAEMON_OPTION_END).
Returns:
NULL on error, handle to daemon on success

Definition at line 325 of file applicationlayer.c.

References NULL, spdy_handler_new_data(), spdy_handler_new_stream(), SPDY_IO_SUBSYSTEM_NONE, SPDYF_DEBUG, spdyf_io_initialized, and SPDYF_start_daemon_va().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:

void SPDY_stop_daemon ( struct SPDY_Daemon daemon  ) 

Shutdown the daemon. First all sessions are closed. It is NOT safe to call this function in user callbacks.

Parameters:
daemon to stop

Definition at line 378 of file applicationlayer.c.

References NULL, SPDYF_DEBUG, and SPDYF_stop_daemon().

Referenced by run().

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on 14 Oct 2014 for GNU libmicrohttpd by  doxygen 1.6.1