tcpflow
1.6.1
About: tcpflow is a TCP/IP packet demultiplexer that captures data transmitted as part of TCP connections (flows), and stores the data in a way that is convenient for protocol analysis and debugging.
![]() ![]() |
#include "http_parser.h"
#include <assert.h>
#include <stddef.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
Go to the source code of this file.
Macros | |
#define | ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */ |
#define | MIN(a, b) ((a) < (b) ? (a) : (b)) |
#define | ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
#define | BIT_AT(a, i) |
#define | ELEM_AT(a, i, v) ((unsigned int) (i) < ARRAY_SIZE(a) ? (a)[(i)] : (v)) |
#define | SET_ERRNO(e) |
#define | CURRENT_STATE() p_state |
#define | UPDATE_STATE(V) p_state = (enum state) (V); |
#define | RETURN(V) |
#define | REEXECUTE() goto reexecute; \ |
#define | LIKELY(X) (X) |
#define | UNLIKELY(X) (X) |
#define | CALLBACK_NOTIFY_(FOR, ER) |
#define | CALLBACK_NOTIFY(FOR) CALLBACK_NOTIFY_(FOR, p - data + 1) |
#define | CALLBACK_NOTIFY_NOADVANCE(FOR) CALLBACK_NOTIFY_(FOR, p - data) |
#define | CALLBACK_DATA_(FOR, LEN, ER) |
#define | CALLBACK_DATA(FOR) CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1) |
#define | CALLBACK_DATA_NOADVANCE(FOR) CALLBACK_DATA_(FOR, p - FOR##_mark, p - data) |
#define | MARK(FOR) |
#define | COUNT_HEADER_SIZE(V) |
#define | PROXY_CONNECTION "proxy-connection" |
#define | CONNECTION "connection" |
#define | CONTENT_LENGTH "content-length" |
#define | TRANSFER_ENCODING "transfer-encoding" |
#define | UPGRADE "upgrade" |
#define | CHUNKED "chunked" |
#define | KEEP_ALIVE "keep-alive" |
#define | CLOSE "close" |
#define | XX(num, name, string) #string, |
#define | T(v) 0 |
#define | PARSING_HEADER(state) (state <= s_headers_done) |
#define | CR '\r' |
#define | LF '\n' |
#define | LOWER(c) (unsigned char)(c | 0x20) |
#define | IS_ALPHA(c) (LOWER(c) >= 'a' && LOWER(c) <= 'z') |
#define | IS_NUM(c) ((c) >= '0' && (c) <= '9') |
#define | IS_ALPHANUM(c) (IS_ALPHA(c) || IS_NUM(c)) |
#define | IS_HEX(c) (IS_NUM(c) || (LOWER(c) >= 'a' && LOWER(c) <= 'f')) |
#define | IS_MARK(c) |
#define | IS_USERINFO_CHAR(c) |
#define | STRICT_TOKEN(c) (tokens[(unsigned char)c]) |
#define | TOKEN(c) (tokens[(unsigned char)c]) |
#define | IS_URL_CHAR(c) (BIT_AT(normal_url_char, (unsigned char)c)) |
#define | IS_HOST_CHAR(c) (IS_ALPHANUM(c) || (c) == '.' || (c) == '-') |
#define | IS_HEADER_CHAR(ch) (ch == CR || ch == LF || ch == 9 || ((unsigned char)ch > 31 && ch != 127)) |
#define | start_state (parser->type == HTTP_REQUEST ? s_start_req : s_start_res) |
#define | STRICT_CHECK(cond) |
#define | NEW_MESSAGE() (http_should_keep_alive(parser) ? start_state : s_dead) |
#define | HTTP_STRERROR_GEN(n, s) { "HPE_" #n, s }, |
#define | XX(meth, pos, ch, new_meth) |
Variables | |
static const char * | method_strings [] |
static const char | tokens [256] |
static const int8_t | unhex [256] |
static const uint8_t | normal_url_char [32] |
struct { | |
const char * name | |
const char * description | |
} | http_strerror_tab [] |
#define ARRAY_SIZE | ( | a | ) | (sizeof(a) / sizeof((a)[0])) |
Definition at line 41 of file http_parser.c.
#define BIT_AT | ( | a, | |
i | |||
) |
Definition at line 45 of file http_parser.c.
#define CALLBACK_DATA | ( | FOR | ) | CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1) |
Definition at line 128 of file http_parser.c.
#define CALLBACK_DATA_ | ( | FOR, | |
LEN, | |||
ER | |||
) |
Definition at line 105 of file http_parser.c.
#define CALLBACK_DATA_NOADVANCE | ( | FOR | ) | CALLBACK_DATA_(FOR, p - FOR##_mark, p - data) |
Definition at line 132 of file http_parser.c.
#define CALLBACK_NOTIFY | ( | FOR | ) | CALLBACK_NOTIFY_(FOR, p - data + 1) |
Definition at line 99 of file http_parser.c.
#define CALLBACK_NOTIFY_ | ( | FOR, | |
ER | |||
) |
Definition at line 80 of file http_parser.c.
#define CALLBACK_NOTIFY_NOADVANCE | ( | FOR | ) | CALLBACK_NOTIFY_(FOR, p - data) |
Definition at line 102 of file http_parser.c.
#define CHUNKED "chunked" |
Definition at line 169 of file http_parser.c.
#define CLOSE "close" |
Definition at line 171 of file http_parser.c.
#define CONNECTION "connection" |
Definition at line 165 of file http_parser.c.
#define CONTENT_LENGTH "content-length" |
Definition at line 166 of file http_parser.c.
#define COUNT_HEADER_SIZE | ( | V | ) |
Definition at line 154 of file http_parser.c.
#define CR '\r' |
Definition at line 409 of file http_parser.c.
#define CURRENT_STATE | ( | ) | p_state |
Definition at line 59 of file http_parser.c.
#define ELEM_AT | ( | a, | |
i, | |||
v | |||
) | ((unsigned int) (i) < ARRAY_SIZE(a) ? (a)[(i)] : (v)) |
Definition at line 51 of file http_parser.c.
#define HTTP_STRERROR_GEN | ( | n, | |
s | |||
) | { "HPE_" #n, s }, |
Definition at line 463 of file http_parser.c.
Definition at line 412 of file http_parser.c.
#define IS_HEADER_CHAR | ( | ch | ) | (ch == CR || ch == LF || ch == 9 || ((unsigned char)ch > 31 && ch != 127)) |
Verify that a char is a valid visible (printable) US-ASCII character or x80-FF
Definition at line 441 of file http_parser.c.
Definition at line 415 of file http_parser.c.
#define IS_HOST_CHAR | ( | c | ) | (IS_ALPHANUM(c) || (c) == '.' || (c) == '-') |
Definition at line 428 of file http_parser.c.
#define IS_MARK | ( | c | ) |
Definition at line 413 of file http_parser.c.
#define IS_URL_CHAR | ( | c | ) | (BIT_AT(normal_url_char, (unsigned char)c)) |
Definition at line 427 of file http_parser.c.
#define IS_USERINFO_CHAR | ( | c | ) |
Definition at line 419 of file http_parser.c.
#define KEEP_ALIVE "keep-alive" |
Definition at line 170 of file http_parser.c.
#define LF '\n' |
Definition at line 410 of file http_parser.c.
#define LIKELY | ( | X | ) | (X) |
Definition at line 74 of file http_parser.c.
Definition at line 411 of file http_parser.c.
#define MARK | ( | FOR | ) |
Definition at line 136 of file http_parser.c.
#define MIN | ( | a, | |
b | |||
) | ((a) < (b) ? (a) : (b)) |
Definition at line 37 of file http_parser.c.
#define NEW_MESSAGE | ( | ) | (http_should_keep_alive(parser) ? start_state : s_dead) |
Definition at line 455 of file http_parser.c.
#define PARSING_HEADER | ( | state | ) | (state <= s_headers_done) |
Definition at line 359 of file http_parser.c.
#define PROXY_CONNECTION "proxy-connection" |
Definition at line 164 of file http_parser.c.
#define REEXECUTE | ( | ) | goto reexecute; \ |
Definition at line 66 of file http_parser.c.
#define RETURN | ( | V | ) |
Definition at line 61 of file http_parser.c.
#define SET_ERRNO | ( | e | ) |
Definition at line 54 of file http_parser.c.
#define start_state (parser->type == HTTP_REQUEST ? s_start_req : s_start_res) |
Definition at line 444 of file http_parser.c.
#define STRICT_CHECK | ( | cond | ) |
Definition at line 448 of file http_parser.c.
Definition at line 423 of file http_parser.c.
#define T | ( | v | ) | 0 |
Definition at line 236 of file http_parser.c.
Definition at line 426 of file http_parser.c.
#define TRANSFER_ENCODING "transfer-encoding" |
Definition at line 167 of file http_parser.c.
#define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */ |
Definition at line 33 of file http_parser.c.
#define UNLIKELY | ( | X | ) | (X) |
Definition at line 75 of file http_parser.c.
#define UPDATE_STATE | ( | V | ) | p_state = (enum state) (V); |
Definition at line 60 of file http_parser.c.
#define UPGRADE "upgrade" |
Definition at line 168 of file http_parser.c.
#define XX | ( | meth, | |
pos, | |||
ch, | |||
new_meth | |||
) |
#define XX | ( | num, | |
name, | |||
string | |||
) | #string, |
enum header_states |
Definition at line 362 of file http_parser.c.
enum http_host_state |
Definition at line 392 of file http_parser.c.
enum state |
Definition at line 278 of file http_parser.c.
int http_body_is_final | ( | const struct http_parser * | parser | ) |
Definition at line 2400 of file http_parser.c.
References s_message_done, and http_parser::state.
const char* http_errno_description | ( | enum http_errno | err | ) |
Definition at line 2107 of file http_parser.c.
References ARRAY_SIZE, err(), and http_strerror_tab.
const char* http_errno_name | ( | enum http_errno | err | ) |
Definition at line 2101 of file http_parser.c.
References ARRAY_SIZE, err(), and http_strerror_tab.
int http_message_needs_eof | ( | const http_parser * | parser | ) |
Definition at line 2035 of file http_parser.c.
References http_parser::content_length, F_CHUNKED, F_SKIPBODY, http_parser::flags, HTTP_REQUEST, http_parser::status_code, http_parser::type, and ULLONG_MAX.
Referenced by http_should_keep_alive().
const char* http_method_str | ( | enum http_method | m | ) |
Definition at line 2077 of file http_parser.c.
References ELEM_AT, and method_strings.
|
static |
Definition at line 2195 of file http_parser.c.
References http_parser_url::field_data, http_parser_url::field_set, http_parse_host_char(), http_parser_url::len, http_parser_url::off, s_http_host, s_http_host_dead, s_http_host_port, s_http_host_port_start, s_http_host_start, s_http_host_v6, s_http_host_v6_start, s_http_host_v6_zone, s_http_host_v6_zone_start, s_http_userinfo, s_http_userinfo_start, UF_HOST, UF_PORT, and UF_USERINFO.
Referenced by http_parser_parse_url().
|
static |
Definition at line 2107 of file http_parser.c.
Referenced by http_parse_host().
size_t http_parser_execute | ( | http_parser * | parser, |
const http_parser_settings * | settings, | ||
const char * | data, | ||
size_t | len | ||
) |
Definition at line 632 of file http_parser.c.
Referenced by scan_http().
void http_parser_init | ( | http_parser * | parser, |
enum http_parser_type | t | ||
) |
Definition at line 2084 of file http_parser.c.
References http_parser::data, HPE_OK, http_parser::http_errno, HTTP_REQUEST, HTTP_RESPONSE, s_start_req, s_start_req_or_res, s_start_res, http_parser::state, and http_parser::type.
Referenced by scan_http().
int http_parser_parse_url | ( | const char * | buf, |
size_t | buflen, | ||
int | is_connect, | ||
struct http_parser_url * | u | ||
) |
Definition at line 2282 of file http_parser.c.
References http_parser_url::field_data, http_parser_url::field_set, http_parse_host(), http_parser_url::len, http_parser_url::off, parse_url_char(), http_parser_url::port, s_dead, s_req_fragment, s_req_fragment_start, s_req_path, s_req_query_string, s_req_query_string_start, s_req_schema, s_req_schema_slash, s_req_schema_slash_slash, s_req_server, s_req_server_start, s_req_server_with_at, s_req_spaces_before_url, UF_FRAGMENT, UF_HOST, UF_MAX, UF_PATH, UF_PORT, UF_QUERY, and UF_SCHEMA.
void http_parser_pause | ( | http_parser * | parser, |
int | paused | ||
) |
Definition at line 2386 of file http_parser.c.
References HPE_OK, HPE_PAUSED, HTTP_PARSER_ERRNO, and SET_ERRNO.
void http_parser_settings_init | ( | http_parser_settings * | settings | ) |
Definition at line 2095 of file http_parser.c.
void http_parser_url_init | ( | struct http_parser_url * | u | ) |
Definition at line 2277 of file http_parser.c.
unsigned long http_parser_version | ( | void | ) |
Definition at line 2405 of file http_parser.c.
References HTTP_PARSER_VERSION_MAJOR, HTTP_PARSER_VERSION_MINOR, and HTTP_PARSER_VERSION_PATCH.
int http_should_keep_alive | ( | const http_parser * | parser | ) |
Definition at line 2058 of file http_parser.c.
References F_CONNECTION_CLOSE, F_CONNECTION_KEEP_ALIVE, http_parser::flags, http_parser::http_major, http_message_needs_eof(), and http_parser::http_minor.
Definition at line 471 of file http_parser.c.
Referenced by http_parser_parse_url().
const char* description |
Definition at line 466 of file http_parser.c.
struct { ... } http_strerror_tab[] |
Referenced by http_errno_description(), and http_errno_name().
|
static |
Definition at line 174 of file http_parser.c.
Referenced by http_method_str().
const char* name |
Definition at line 465 of file http_parser.c.
Referenced by feature_recorder_set::create_name(), scanner_info::get_config(), feature_recorder_set::get_name(), feature_recorder_set::has_name(), Wifipcap::Init(), main(), process_infile(), be13::plugin::process_sbuf(), be13::plugin::scanners_disable(), be13::plugin::scanners_enable(), be13::plugin::set_scanner_enabled(), validASCIIName(), and Wifipcap::Wifipcap().
|
static |
Definition at line 242 of file http_parser.c.
|
static |
Definition at line 188 of file http_parser.c.
Referenced by comma_number_string().
|
static |
Definition at line 223 of file http_parser.c.