libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Typedefs | Functions
request_parser.c File Reference
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include "dict.h"
#include "request.h"
#include "types_internal.h"
#include "codecs.h"
#include "log.h"
#include "block.h"
#include "low.h"
#include "ptr_list.h"
#include "utils.h"

Data Structures

struct  onion_token_s
struct  onion_buffer_s
struct  onion_multipart_buffer_s
 This struct is mapped at token->extra. The token, _start and data are maped to token->extra area too.

Typedefs

typedef struct onion_token_s onion_token
typedef struct onion_buffer_s onion_buffer
typedef struct
onion_multipart_buffer_s 
onion_multipart_buffer
 This struct is mapped at token->extra. The token, _start and data are maped to token->extra area too.

Functions

int token_read_STRING (onion_token *token, onion_buffer *data)
 Reads a string until a non-string char. Returns an onion_token.
int token_read_until (onion_token *token, onion_buffer *data, char delimiter)
 Reads a string until a delimiter is found. Returns an onion_token. Also detects an empty line.
int token_read_KEY (onion_token *token, onion_buffer *data)
 Reads a key, that is a string ended with ':'.
int token_read_LINE (onion_token *token, onion_buffer *data)
 Reads a string until a '
|
' is found. Returns an onion_token.
int token_read_URLENCODE (onion_token *token, onion_buffer *data)
 Reads a string until a '
|
' is found. Returns an onion_token.
int token_read_MULTIPART_BOUNDARY (onion_token *token, onion_buffer *data)
 Reads as much as possible from the boundary.
int token_read_MULTIPART_next (onion_token *token, onion_buffer *data)
 Reads as much as possible from the boundary.
int token_read_NEW_LINE (onion_token *token, onion_buffer *data)
onion_connection_status onion_request_write (onion_request *req, const char *data, size_t size)
 Write some data into the request, and passes it line by line to onion_request_fill.
void onion_request_parser_data_free (void *t)
 Frees the parser data.

Typedef Documentation

typedef struct onion_buffer_s onion_buffer
typedef struct onion_multipart_buffer_s onion_multipart_buffer

This struct is mapped at token->extra. The token, _start and data are maped to token->extra area too.

This is a bit juggling with pointers, but needed to keep the deallocation simple, and the token object minimal in most cases.

token->pos is the pointer to the free area and token->extra_size is the real size.

typedef struct onion_token_s onion_token

Function Documentation

void onion_request_parser_data_free ( void *  t)
onion_connection_status onion_request_write ( onion_request req,
const char *  data,
size_t  size 
)

Write some data into the request, and passes it line by line to onion_request_fill.

Reads some data from the input (net, file...) and performs the onion_request_fill.

It features a state machine, from req->parse_state.

Depending on the state input is redirected to a diferent parser, one for headers, POST url encoded data...

Returns
Returns the number of bytes writen, or <=0 if connection should close, according to onion_connection_status
See Also
onion_connection_status

References OCS_INTERNAL_ERROR, OCS_NEED_MORE_DATA, onion_low_calloc(), onion_request_t::parser, and onion_request_t::parser_data.

Referenced by onion_http_t::onion_http_read_ready().

int token_read_KEY ( onion_token token,
onion_buffer data 
)

Reads a key, that is a string ended with ':'.

References KEY, OCS_INTERNAL_ERROR, ONION_ERROR, STRING, STRING_NEW_LINE, and token_read_until().

int token_read_LINE ( onion_token token,
onion_buffer data 
)

Reads a string until a '
|
' is found. Returns an onion_token.

References LINE, OCS_NEED_MORE_DATA, ONION_DEBUG, and ONION_WARNING.

int token_read_MULTIPART_BOUNDARY ( onion_token token,
onion_buffer data 
)

Reads as much as possible from the boundary.

References MULTIPART_BOUNDARY, OCS_INTERNAL_ERROR, OCS_NEED_MORE_DATA, and ONION_ERROR.

int token_read_MULTIPART_next ( onion_token token,
onion_buffer data 
)

Reads as much as possible from the boundary.

References MULTIPART_END, MULTIPART_NEXT, OCS_INTERNAL_ERROR, and OCS_NEED_MORE_DATA.

int token_read_NEW_LINE ( onion_token token,
onion_buffer data 
)
int token_read_STRING ( onion_token token,
onion_buffer data 
)

Reads a string until a non-string char. Returns an onion_token.

References OCS_INTERNAL_ERROR, OCS_NEED_MORE_DATA, ONION_ERROR, STRING, and STRING_NEW_LINE.

int token_read_until ( onion_token token,
onion_buffer data,
char  delimiter 
)

Reads a string until a delimiter is found. Returns an onion_token. Also detects an empty line.

Returns
error code | STRING | STRING_NEW_LINE | NEW_LINE

STRING is a delimited string, string new line is that the string finished witha new line, new line is that I fuond only a new line char.

References NEW_LINE, OCS_INTERNAL_ERROR, OCS_NEED_MORE_DATA, ONION_ERROR, STRING, and STRING_NEW_LINE.

Referenced by token_read_KEY().

int token_read_URLENCODE ( onion_token token,
onion_buffer data 
)

Reads a string until a '
|
' is found. Returns an onion_token.

References OCS_NEED_MORE_DATA, and URLENCODE.