libasyncd
ad_http_handler.c File Reference

HTTP protocol request/response handler. More...

Go to the source code of this file.

Functions

int ad_http_handler (short event, ad_conn_t *conn, void *userdata)
 HTTP protocol handler hook. More...
 
enum ad_http_request_status_e ad_http_get_status (ad_conn_t *conn)
 Return the request status. More...
 
struct evbuffer * ad_http_get_inbuf (ad_conn_t *conn)
 
struct evbuffer * ad_http_get_outbuf (ad_conn_t *conn)
 
const char * ad_http_get_request_header (ad_conn_t *conn, const char *name)
 Get request header. More...
 
off_t ad_http_get_content_length (ad_conn_t *conn)
 Return the size of content from the request. More...
 
size_t ad_http_get_content_length_stored (ad_conn_t *conn)
 Return the actual size of data stored in in-buffer. More...
 
void * ad_http_get_content (ad_conn_t *conn, size_t maxsize, size_t *storedsize)
 Remove content from the in-buffer. More...
 
int ad_http_is_keepalive_request (ad_conn_t *conn)
 Return whether the request is keep-alive request or not. More...
 
int ad_http_set_response_header (ad_conn_t *conn, const char *name, const char *value)
 Set response header. More...
 
const char * ad_http_get_response_header (ad_conn_t *conn, const char *name)
 Get response header. More...
 
int ad_http_set_response_code (ad_conn_t *conn, int code, const char *reason)
 
int ad_http_set_response_content (ad_conn_t *conn, const char *contenttype, off_t size)
 
size_t ad_http_response (ad_conn_t *conn, int code, const char *contenttype, const void *data, off_t size)
 
size_t ad_http_send_header (ad_conn_t *conn)
 
size_t ad_http_send_data (ad_conn_t *conn, const void *data, size_t size)
 
size_t ad_http_send_chunk (ad_conn_t *conn, const void *data, size_t size)
 
const char * ad_http_get_reason (int code)
 

Detailed Description

HTTP protocol request/response handler.

Definition in file ad_http_handler.c.

Function Documentation

int ad_http_handler ( short  event,
ad_conn_t conn,
void *  userdata 
)

HTTP protocol handler hook.

This hook provides an easy way to handle HTTP request/response.

Note
This hook must be registered at the top of hook chain.

Definition at line 84 of file ad_http_handler.c.

enum ad_http_request_status_e ad_http_get_status ( ad_conn_t conn)

Return the request status.

Definition at line 116 of file ad_http_handler.c.

struct evbuffer* ad_http_get_inbuf ( ad_conn_t conn)

Definition at line 123 of file ad_http_handler.c.

struct evbuffer* ad_http_get_outbuf ( ad_conn_t conn)

Definition at line 128 of file ad_http_handler.c.

const char* ad_http_get_request_header ( ad_conn_t conn,
const char *  name 
)

Get request header.

Parameters
namename of header.
Returns
value of string if found, otherwise NULL.

Definition at line 140 of file ad_http_handler.c.

off_t ad_http_get_content_length ( ad_conn_t conn)

Return the size of content from the request.

Definition at line 148 of file ad_http_handler.c.

size_t ad_http_get_content_length_stored ( ad_conn_t conn)

Return the actual size of data stored in in-buffer.

Definition at line 157 of file ad_http_handler.c.

void* ad_http_get_content ( ad_conn_t conn,
size_t  maxsize,
size_t *  storedsize 
)

Remove content from the in-buffer.

The return data gets null terminated for convenience. For an example, if it reads 3 bytes, it will allocate 4 bytes and the 4th byte will be set to null terminator. storedsized will still return 3.

Parameters
maxsizemaximum length of data to read. 0 to read everything.
storedsizethe size of data read and stored in the return.

Definition at line 172 of file ad_http_handler.c.

int ad_http_is_keepalive_request ( ad_conn_t conn)

Return whether the request is keep-alive request or not.

Returns
1 if keep-alive request, otherwise 0.

Definition at line 199 of file ad_http_handler.c.

int ad_http_set_response_header ( ad_conn_t conn,
const char *  name,
const char *  value 
)

Set response header.

Parameters
namename of header.
valuevalue string to set. NULL to remove the header.
Returns
0 on success, -1 if we already sent it out.

Definition at line 231 of file ad_http_handler.c.

const char* ad_http_get_response_header ( ad_conn_t conn,
const char *  name 
)

Get response header.

Parameters
namename of header.
Returns
value of string if found, otherwise NULL.

Definition at line 254 of file ad_http_handler.c.

int ad_http_set_response_code ( ad_conn_t conn,
int  code,
const char *  reason 
)
Returns
0 on success, -1 if we already sent it out.

Definition at line 263 of file ad_http_handler.c.

int ad_http_set_response_content ( ad_conn_t conn,
const char *  contenttype,
off_t  size 
)
Parameters
sizecontent size. -1 for chunked transfer encoding.
Returns
0 on success, -1 if we already sent it out.

Definition at line 281 of file ad_http_handler.c.

size_t ad_http_response ( ad_conn_t conn,
int  code,
const char *  contenttype,
const void *  data,
off_t  size 
)
Returns
total bytes sent, 0 on error.

Definition at line 308 of file ad_http_handler.c.

size_t ad_http_send_header ( ad_conn_t conn)
Returns
0 total bytes put in out buffer, -1 if we already sent it out.

Definition at line 331 of file ad_http_handler.c.

size_t ad_http_send_data ( ad_conn_t conn,
const void *  data,
size_t  size 
)
Returns
0 on success, -1 if we already sent it out.

Definition at line 367 of file ad_http_handler.c.

size_t ad_http_send_chunk ( ad_conn_t conn,
const void *  data,
size_t  size 
)

Definition at line 394 of file ad_http_handler.c.

const char* ad_http_get_reason ( int  code)

Definition at line 428 of file ad_http_handler.c.