HTP  0.3
Functions
htp_util.c File Reference
#include "htp.h"
#include "utf8_decoder.h"
#include <inttypes.h>
Include dependency graph for htp_util.c:

Functions

int htp_is_lws (int c)
int htp_is_separator (int c)
int htp_is_text (int c)
int htp_is_token (int c)
int htp_chomp (unsigned char *data, size_t *len)
int htp_is_space (int c)
int htp_convert_method_to_number (bstr *method)
int htp_is_line_empty (unsigned char *data, size_t len)
int htp_is_line_whitespace (unsigned char *data, size_t len)
int htp_parse_content_length (bstr *b)
int htp_parse_chunked_length (unsigned char *data, size_t len)
int htp_parse_positive_integer_whitespace (unsigned char *data, size_t len, int base)
void htp_print_log (FILE *stream, htp_log_t *log)
void htp_log (htp_connp_t *connp, const char *file, int line, int level, int code, const char *fmt,...)
int htp_connp_is_line_folded (unsigned char *data, size_t len)
int htp_connp_is_line_terminator (htp_connp_t *connp, unsigned char *data, size_t len)
int htp_connp_is_line_ignorable (htp_connp_t *connp, unsigned char *data, size_t len)
int htp_parse_authority (htp_connp_t *connp, bstr *authority, htp_uri_t **uri)
int htp_parse_uri (bstr *input, htp_uri_t **uri)
void htp_utf8_decode_path_inplace (htp_cfg_t *cfg, htp_tx_t *tx, bstr *path)
void htp_utf8_validate_path (htp_tx_t *tx, bstr *path)
int htp_decode_path_inplace (htp_cfg_t *cfg, htp_tx_t *tx, bstr *path)
int htp_decode_urlencoded_inplace (htp_cfg_t *cfg, htp_tx_t *tx, bstr *input)
int htp_normalize_parsed_uri (htp_connp_t *connp, htp_uri_t *incomplete, htp_uri_t *normalized)
bstrhtp_normalize_hostname_inplace (bstr *hostname)
void htp_replace_hostname (htp_connp_t *connp, htp_uri_t *parsed_uri, bstr *hostname)
int htp_is_uri_unreserved (unsigned char c)
void htp_uriencoding_normalize_inplace (bstr *s)
void htp_normalize_uri_path_inplace (bstr *s)
void fprint_bstr (FILE *stream, const char *name, bstr *b)
void fprint_raw_data (FILE *stream, const char *name, unsigned char *data, size_t len)
void fprint_raw_data_ex (FILE *stream, const char *name, unsigned char *data, size_t offset, size_t printlen)
char * htp_connp_in_state_as_string (htp_connp_t *connp)
char * htp_connp_out_state_as_string (htp_connp_t *connp)
char * htp_tx_progress_as_string (htp_tx_t *tx)
bstrhtp_unparse_uri_noencode (htp_uri_t *uri)
int htp_resembles_response_line (htp_tx_t *tx)
bstrhtp_tx_generate_request_headers_raw (htp_tx_t *tx)
bstrhtp_tx_get_request_headers_raw (htp_tx_t *tx)
int htp_req_run_hook_body_data (htp_connp_t *connp, htp_tx_data_t *d)
int htp_res_run_hook_body_data (htp_connp_t *connp, htp_tx_data_t *d)
bstrhtp_extract_quoted_string_as_bstr (char *data, size_t len, size_t *endoffset)

Detailed Description

Author:
Ivan Ristic <ivanr@webkreator.com>

Function Documentation

void fprint_bstr ( FILE *  stream,
const char *  name,
bstr b 
)

Here is the call graph for this function:

void fprint_raw_data ( FILE *  stream,
const char *  name,
unsigned char *  data,
size_t  len 
)

Here is the call graph for this function:

Here is the caller graph for this function:

void fprint_raw_data_ex ( FILE *  stream,
const char *  name,
unsigned char *  data,
size_t  offset,
size_t  printlen 
)

Here is the caller graph for this function:

int htp_chomp ( unsigned char *  data,
size_t *  len 
)

Remove one or more line terminators (LF or CRLF) from the end of the line provided as input.

Returns:
0 if nothing was removed, 1 if one or more LF characters were removed, or 2 if one or more CR and/or LF characters were removed.

Here is the caller graph for this function:

char* htp_connp_in_state_as_string ( htp_connp_t connp)

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_connp_is_line_folded ( unsigned char *  data,
size_t  len 
)

Determines if the given line is a continuation (of some previous line).

Parameters:
connp
data
len
Returns:
0 or 1

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_connp_is_line_ignorable ( htp_connp_t connp,
unsigned char *  data,
size_t  len 
)

Determines if the given line can be ignored when it appears before a request.

Parameters:
connp
data
len
Returns:
0 or 1

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_connp_is_line_terminator ( htp_connp_t connp,
unsigned char *  data,
size_t  len 
)

Determines if the given line is a request terminator.

Parameters:
connp
data
len
Returns:
0 or 1

Here is the call graph for this function:

Here is the caller graph for this function:

char* htp_connp_out_state_as_string ( htp_connp_t connp)

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_convert_method_to_number ( bstr method)

Converts request method, given as a string, into a number.

Parameters:
method
Returns:
Method number of M_UNKNOWN

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_decode_path_inplace ( htp_cfg_t cfg,
htp_tx_t tx,
bstr path 
)

Decode a request path according to the settings in the provided configuration structure.

Parameters:
cfg
tx
path

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_decode_urlencoded_inplace ( htp_cfg_t cfg,
htp_tx_t tx,
bstr input 
)

Here is the call graph for this function:

bstr* htp_extract_quoted_string_as_bstr ( char *  data,
size_t  len,
size_t *  endoffset 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_is_line_empty ( unsigned char *  data,
size_t  len 
)

Is the given line empty? This function expects the line to have a terminating LF.

Parameters:
data
len
Returns:
0 or 1

Here is the caller graph for this function:

int htp_is_line_whitespace ( unsigned char *  data,
size_t  len 
)

Does line consist entirely of whitespace characters?

Parameters:
data
len
Returns:
0 or 1

Here is the caller graph for this function:

int htp_is_lws ( int  c)

Is character a linear white space character?

Parameters:
c
Returns:
0 or 1

Here is the caller graph for this function:

int htp_is_separator ( int  c)

Is character a separator character?

Parameters:
c
Returns:
0 or 1

Here is the caller graph for this function:

int htp_is_space ( int  c)

Is character a white space character?

Parameters:
c
Returns:
0 or 1

Here is the caller graph for this function:

int htp_is_text ( int  c)

Is character a text character?

Parameters:
c
Returns:
0 or 1
int htp_is_token ( int  c)

Is character a token character?

Parameters:
c
Returns:
0 or 1

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_is_uri_unreserved ( unsigned char  c)

Is URI character reserved?

Parameters:
c
Returns:
1 if it is, 0 if it isn't

Here is the caller graph for this function:

void htp_log ( htp_connp_t connp,
const char *  file,
int  line,
int  level,
int  code,
const char *  fmt,
  ... 
)

Records one log message.

Parameters:
connp
file
line
level
code
fmt

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* htp_normalize_hostname_inplace ( bstr hostname)

Normalize request hostname. Convert all characters to lowercase and remove trailing dots from the end, if present.

Parameters:
hostname
Returns:
normalized hostnanme

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_normalize_parsed_uri ( htp_connp_t connp,
htp_uri_t incomplete,
htp_uri_t normalized 
)

Normalize a previously-parsed request URI.

Parameters:
connp
incomplete
normalized
Returns:
HTP_OK or HTP_ERROR

Here is the call graph for this function:

Here is the caller graph for this function:

void htp_normalize_uri_path_inplace ( bstr s)

Normalize URL path. This function implements the remove dot segments algorithm specified in RFC 3986, section 5.2.4.

Parameters:
s

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_parse_authority ( htp_connp_t connp,
bstr authority,
htp_uri_t **  uri 
)

Parses request URI, making no attempt to validate the contents.

Parameters:
connp
authority
uri
Returns:
HTP_ERROR on memory allocation failure, HTP_OK otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_parse_chunked_length ( unsigned char *  data,
size_t  len 
)

Parses chunk length (positive hexadecimal number). White space is allowed before and after the number.

Parameters:
data
len
Returns:
Chunk length, or -1 on error.

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_parse_content_length ( bstr b)

Parses Content-Length string (positive decimal number). White space is allowed before and after the number.

Parameters:
b
Returns:
Content-Length as a number, or -1 on error.

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_parse_positive_integer_whitespace ( unsigned char *  data,
size_t  len,
int  base 
)

A forgiving parser for a positive integer in a given base. White space is allowed before and after the number.

Parameters:
data
len
base
Returns:
The parsed number, or -1 on error.

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_parse_uri ( bstr input,
htp_uri_t **  uri 
)

Parses request URI, making no attempt to validate the contents.

Parameters:
input
uri
Returns:
HTP_ERROR on memory allocation failure, HTP_OK otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

void htp_print_log ( FILE *  stream,
htp_log_t log 
)

Prints one log message to stderr.

Parameters:
log
void htp_replace_hostname ( htp_connp_t connp,
htp_uri_t parsed_uri,
bstr hostname 
)

Replace the URI in the structure with the one provided as the parameter to this function (which will typically be supplied in a Host header).

Parameters:
connp
parsed_uri
hostname

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_req_run_hook_body_data ( htp_connp_t connp,
htp_tx_data_t d 
)

Run the REQUEST_BODY_DATA hook.

Parameters:
connp
d

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_res_run_hook_body_data ( htp_connp_t connp,
htp_tx_data_t d 
)

Run the RESPONSE_BODY_DATA hook.

Parameters:
connp
d

Here is the call graph for this function:

Here is the caller graph for this function:

int htp_resembles_response_line ( htp_tx_t tx)

Determine if the information provided on the response line is good enough. Browsers are lax when it comes to response line parsing. In most cases they will only look for the words "http" at the beginning.

Parameters:
tx
Returns:
1 for good enough or 0 for not good enough

Here is the caller graph for this function:

bstr* htp_tx_generate_request_headers_raw ( htp_tx_t tx)

Construct a bstr that contains the raw request headers.

Parameters:
tx
Returns:

Here is the call graph for this function:

Here is the caller graph for this function:

bstr* htp_tx_get_request_headers_raw ( htp_tx_t tx)

Get a bstr that contains the raw request headers. This method will always return an up-to-date buffer, containing the last known headers. Thus, if it is called once after REQUEST_HEADERS phase it will return one buffer, but it may return a different buffer if called after REQUEST_TRAILERS phase (but only if the request actually contains trailer headers). Do not retain the bstr pointer, as the buffer may change. If there are no changes to the request header structure, only one buffer will be constructed and used. (Multiple invocations of this method will not cause multiple buffers to be created.)

Parameters:
tx
Returns:

Here is the call graph for this function:

char* htp_tx_progress_as_string ( htp_tx_t tx)

Here is the caller graph for this function:

bstr* htp_unparse_uri_noencode ( htp_uri_t uri)

Here is the call graph for this function:

Here is the caller graph for this function:

void htp_uriencoding_normalize_inplace ( bstr s)

Decode a URL-encoded string, leaving the reserved characters and invalid encodings alone.

Parameters:
s

Here is the call graph for this function:

Here is the caller graph for this function:

void htp_utf8_decode_path_inplace ( htp_cfg_t cfg,
htp_tx_t tx,
bstr path 
)

Decode a UTF-8 encoded path. Overlong characters will be decoded, invalid characters will be left as-is. Best-fit mapping will be used to convert UTF-8 into a single-byte stream.

Parameters:
cfg
tx
path

Here is the call graph for this function:

Here is the caller graph for this function:

void htp_utf8_validate_path ( htp_tx_t tx,
bstr path 
)

Validate a path that is quite possibly UTF-8 encoded.

Parameters:
cfg
tx
path

Here is the call graph for this function:

Here is the caller graph for this function: