#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include "config.h"
#include "include/connection.h"
#include "include/mtp_http.h"
#include "include/macros.h"
#include "include/mc_error.h"
#include "include/message.h"
#include "include/dynstring.h"
Go to the source code of this file.
Defines | |
#define | SAFE_FREE(elem) |
#define | HTTP_PARSE_EXPR(parse_name, struct_name) |
#define | SAFE_FREE(object) |
Functions | |
int | mtp_http_Destroy (mtp_http_p http) |
mtp_http_p | mtp_http_New (void) |
int | rece_de_msg (char *buffer, connection_p con, char *privatekey) |
int | mtp_http_InitializeFromConnection (mtp_http_p http, connection_p connection, char *privatekey) |
const char * | http_GetExpression (const char *string, char **expr) |
Parse an html expression. | |
int | http_ParseExpression (const char *expression_string, char **name, char **value) |
Parse an expression into its name and value. | |
const char * | mtp_http_ParseHeader (struct mtp_http_s *http, const char *string) |
int | mtp_http_Parse (struct mtp_http_s *http, const char *string) |
const char * | http_ParseRequest (mtp_http_p http, const char *string) |
const char * | http_GetToken (const char *string, char **token) |
int | mtp_http_ParseResponse (struct mtp_http_s *http, const char *string) |
int | mtp_http_ComposeMessage (message_p message) |
struct message_s * | mtp_http_CreateMessage (mtp_http_t *mtp_http, char *hostname, int port) |
#define HTTP_PARSE_EXPR | ( | parse_name, | |||
struct_name | ) |
if ( !strcmp(name, parse_name) ) { \ http->struct_name = (char*)malloc \ ( \ sizeof(char) * \ (strlen(value)+1) \ ); \ strcpy(http->struct_name, value); \ } else
Referenced by mtp_http_ParseHeader().
#define SAFE_FREE | ( | object | ) |
if(object) free(object); \ object = NULL
#define SAFE_FREE | ( | elem | ) |
if(elem) \
free(elem)
Referenced by mtp_http_Destroy(), and mtp_http_ParseHeader().
const char* http_GetExpression | ( | const char * | string, | |
char ** | expr | |||
) |
Parse an html expression.
string | (input) The html block of text: Will parse the first expression pointed to by 'string'. | |
expr | (output) The allocated expression |
Definition at line 349 of file mtp_http.c.
Referenced by mtp_http_Parse(), and mtp_http_ParseHeader().
const char* http_GetToken | ( | const char * | string, | |
char ** | token | |||
) |
int http_ParseExpression | ( | const char * | expression_string, | |
char ** | name, | |||
char ** | value | |||
) |
Parse an expression into its name and value.
expression_string | (input) The expression | |
name | (output) An allocated name string or NULL | |
value | (output) An allocated value string or NULL |
Definition at line 408 of file mtp_http.c.
References CHECK_NULL, MC_ERR_PARSE, and MC_SUCCESS.
Referenced by mtp_http_Parse(), and mtp_http_ParseHeader().
const char* http_ParseRequest | ( | mtp_http_p | http, | |
const char * | string | |||
) |
Definition at line 701 of file mtp_http.c.
References cur, HTTP_CONNECT, HTTP_DELETE, HTTP_GET, http_GetToken(), HTTP_HEAD, HTTP_OPTIONS, mtp_http_s::http_performative, HTTP_PERFORMATIVE_UNDEF, HTTP_POST, HTTP_PUT, HTTP_RESPONSE, HTTP_TRACE, mtp_http_s::response_code, mtp_http_s::response_string, and mtp_http_s::target.
Referenced by mtp_http_ParseHeader().
Definition at line 829 of file mtp_http.c.
References buf, message_s::isHTTP, MC_SUCCESS, message_s::message_body, PACKAGE_VERSION, message_s::target, and message_s::to_address.
struct message_s* mtp_http_CreateMessage | ( | mtp_http_t * | mtp_http, | |
char * | hostname, | |||
int | port | |||
) | [read] |
Definition at line 875 of file mtp_http.c.
References buf, mtp_http_s::content, mtp_http_content_s::content_type, mtp_http_content_s::data, dynstring_Append(), dynstring_Destroy(), dynstring_New(), mtp_http_s::host, message_s::isHTTP, dynstring_s::len, dynstring_s::message, message_s::message_body, message_New(), mtp_http_s::message_parts, PACKAGE_VERSION, mtp_http_s::target, and message_s::to_address.
Referenced by MC_AclSend().
int mtp_http_Destroy | ( | mtp_http_p | http | ) |
Definition at line 54 of file mtp_http.c.
References mtp_http_s::accept_ranges, mtp_http_s::boundary, mtp_http_s::cache_control, mtp_http_s::connection, mtp_http_s::content, mtp_http_s::content_length, mtp_http_content_s::content_type, mtp_http_s::content_type, mtp_http_content_s::data, mtp_http_s::date, mtp_http_s::host, mtp_http_s::http_version, mtp_http_s::message_parts, mtp_http_s::mime_version, mtp_http_s::response_string, mtp_http_s::return_code, SAFE_FREE, mtp_http_s::server, mtp_http_s::target, and mtp_http_s::user_agent.
Referenced by acc_connection_Thread(), MC_AclSend(), message_send_Thread(), and mtp_http_InitializeFromConnection().
int mtp_http_InitializeFromConnection | ( | mtp_http_p | http, | |
connection_p | connection, | |||
char * | privatekey | |||
) |
Definition at line 180 of file mtp_http.c.
References CHECK_NULL, connection_s::clientfd, mtp_http_s::content_length, dynstring_Append(), dynstring_Destroy(), dynstring_New(), ERR, mtp_http_s::header_length, HTTP_HEAD, mtp_http_s::http_performative, MC_ERR_CONNECT, mtp_http_Destroy(), mtp_http_New(), mtp_http_Parse(), mtp_http_ParseHeader(), PACKAGE_STRING, rece_de_msg(), send, SOCKET_ERROR, SOCKET_INPUT_SIZE, and strdup.
mtp_http_p mtp_http_New | ( | void | ) |
Definition at line 89 of file mtp_http.c.
References CHECK_NULL, and mtp_http_s::content.
Referenced by acc_connection_Thread(), MC_AclSend(), message_send_Thread(), and mtp_http_InitializeFromConnection().
int mtp_http_Parse | ( | struct mtp_http_s * | http, | |
const char * | string | |||
) |
Definition at line 551 of file mtp_http.c.
References mtp_http_s::boundary, mtp_http_s::content, mtp_http_s::content_length, mtp_http_content_s::content_type, mtp_http_s::content_type, mtp_http_content_s::data, http_GetExpression(), HTTP_HEAD, http_ParseExpression(), mtp_http_s::http_performative, HTTP_POST, HTTP_PUT, HTTP_RESPONSE, MC_SUCCESS, mtp_http_s::message_parts, mtp_http_ParseHeader(), and strdup.
Referenced by message_send_Thread(), and mtp_http_InitializeFromConnection().
const char* mtp_http_ParseHeader | ( | struct mtp_http_s * | http, | |
const char * | string | |||
) |
Definition at line 467 of file mtp_http.c.
References mtp_http_s::header_length, http_GetExpression(), HTTP_PARSE_EXPR, http_ParseExpression(), http_ParseRequest(), MC_SUCCESS, and SAFE_FREE.
Referenced by mtp_http_InitializeFromConnection(), and mtp_http_Parse().
int mtp_http_ParseResponse | ( | struct mtp_http_s * | http, | |
const char * | string | |||
) |
Definition at line 823 of file mtp_http.c.
int rece_de_msg | ( | char * | buffer, | |
connection_p | con, | |||
char * | privatekey | |||
) |
Definition at line 100 of file mtp_http.c.
References aes_en_de(), connection_s::AES_key, connection_s::clientfd, int, connection_s::nonce, and receive_AES_en_MA().
Referenced by mtp_http_InitializeFromConnection().