libs/libhttp.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include "libhttp.h"

Defines

#define MAX_SIZE   4096
#define MAX_BODY_LEN   (10 * 1024 * 1024)

Functions

int http_read (http_t *http, int fd)
 Reads an HTTP request from the file descriptor fd and parses it filling the http_t structure with: request status; request headers; request body (if any).
const char * http_get_header (http_t *http, char *key)
 Returns the value of a HTTP header with the given key.
const char * http_get_status (http_t *http)
 Returns the status of a HTTP request, i.e.
const char * http_get_body (http_t *http, size_t *length)
 Returns the body of a HTTP request.
void http_free (http_t *http)
 Deallocates the resources used for a HTTP request.

Detailed Description


Function Documentation

void http_free ( http_t http  ) 

Deallocates the resources used for a HTTP request.

Parameters:
http a pointer to an http_t structure to deallocate.
const char* http_get_body ( http_t http,
size_t *  length 
)

Returns the body of a HTTP request.

Parameters:
http a pointer to an http_t structure to retrieve the body from.
length if specified, *length gets filled with the total length in bytes of the HTTP body
Returns:
a null-terminated string containing the value of the body of a HTTP request, or NULL if the HTTP request did not contain a body.
const char* http_get_header ( http_t http,
char *  key 
)

Returns the value of a HTTP header with the given key.

Parameters:
http a pointer to an http_t structure to retrieve the headers from.
key the searched key.
Returns:
a null-terminated string containing the value for the given key, or NULL if the HTTP request did not contain the searched header.
const char* http_get_status ( http_t http  ) 

Returns the status of a HTTP request, i.e.

the fist line which terminates with "\r\n".

Parameters:
http a pointer to an http_t structure to retrieve the status from.
Returns:
a null-terminated string containing the value of the HTTP status, or NULL if it was unable to retrieve the status of the HTTP request.
int http_read ( http_t http,
int  fd 
)

Reads an HTTP request from the file descriptor fd and parses it filling the http_t structure with: request status; request headers; request body (if any).

Parameters:
http an pointer to an http_t structure to be filled with the data of the HTTP request.
fd a file descriptor where the HTTP stream is read from.
Returns:
the total length of the HTTP request in bytes or -1 if no HTTP request could be processed. This happens in case: the connection has been closed; the length of the request exceeds the limits or the data stream ends prematurely.

Generated on 18 Nov 2013 for MP8 Web Server by  doxygen 1.6.1