HTP  0.5
Functions
htp_util.c File Reference
#include "htp_private.h"

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)
 
int64_t htp_parse_content_length (bstr *b)
 
int64_t htp_parse_chunked_length (unsigned char *data, size_t len)
 
int64_t 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, enum htp_log_level_t level, int code, const char *fmt,...)
 
int htp_connp_is_line_folded (unsigned char *data, size_t len)
 
int htp_is_folding_char (int c)
 
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)
 
htp_status_t htp_parse_hostport (bstr *hostport, bstr **hostname, int *port, int *invalid)
 
int htp_parse_uri_hostport (htp_connp_t *connp, bstr *hostport, htp_uri_t *uri)
 
htp_status_t htp_parse_header_hostport (bstr *hostport, bstr **hostname, int *port, uint64_t *flags)
 
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, const void *data, size_t len)
 
void fprint_raw_data_ex (FILE *stream, const char *name, const void *_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_request_progress_as_string (htp_tx_t *tx)
 
char * htp_tx_response_progress_as_string (htp_tx_t *tx)
 
bstrhtp_unparse_uri_noencode (htp_uri_t *uri)
 
int htp_treat_response_line_as_body (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 (unsigned char *data, size_t len, size_t *endoffset)
 
htp_status_t htp_parse_ct_header (bstr *header, bstr **ct)
 
int htp_validate_hostname (bstr *hostname)
 
void htp_uri_free (htp_uri_t *uri)
 
htp_uri_thtp_uri_alloc ()
 

Detailed Description

Author
Ivan Ristic ivanr.nosp@m.@web.nosp@m.kreat.nosp@m.or.c.nosp@m.om

Function Documentation

void fprint_bstr ( FILE *  stream,
const char *  name,
bstr b 
)
void fprint_raw_data ( FILE *  stream,
const char *  name,
const void *  data,
size_t  len 
)
void fprint_raw_data_ex ( FILE *  stream,
const char *  name,
const void *  _data,
size_t  offset,
size_t  printlen 
)
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.
char* htp_connp_in_state_as_string ( htp_connp_t connp)
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
[in]data
[in]len
Returns
0 or 1 for false and true, respectively. Returns -1 on error (NULL pointer or length zero).
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
[in]connp
[in]data
[in]len
Returns
0 or 1
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
[in]connp
[in]data
[in]len
Returns
0 or 1
char* htp_connp_out_state_as_string ( htp_connp_t connp)
int htp_convert_method_to_number ( bstr method)

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

Parameters
[in]method
Returns
Method number of M_UNKNOWN
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
[in]cfg
[in]tx
[in]path
int htp_decode_urlencoded_inplace ( htp_cfg_t cfg,
htp_tx_t tx,
bstr input 
)
bstr* htp_extract_quoted_string_as_bstr ( unsigned char *  data,
size_t  len,
size_t *  endoffset 
)
int htp_is_folding_char ( int  c)
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
[in]data
[in]len
Returns
0 or 1
int htp_is_line_whitespace ( unsigned char *  data,
size_t  len 
)

Does line consist entirely of whitespace characters?

Parameters
[in]data
[in]len
Returns
0 or 1
int htp_is_lws ( int  c)

Is character a linear white space character?

Parameters
[in]c
Returns
0 or 1
int htp_is_separator ( int  c)

Is character a separator character?

Parameters
[in]c
Returns
0 or 1
int htp_is_space ( int  c)

Is character a white space character?

Parameters
[in]c
Returns
0 or 1
int htp_is_text ( int  c)

Is character a text character?

Parameters
[in]c
Returns
0 or 1
int htp_is_token ( int  c)

Is character a token character?

Parameters
[in]c
Returns
0 or 1
int htp_is_uri_unreserved ( unsigned char  c)

Is URI character reserved?

Parameters
[in]c
Returns
1 if it is, 0 if it isn't
void htp_log ( htp_connp_t connp,
const char *  file,
int  line,
enum htp_log_level_t  level,
int  code,
const char *  fmt,
  ... 
)

Records one log message.

Parameters
[in]connp
[in]file
[in]line
[in]level
[in]code
[in]fmt
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
[in]hostname
Returns
Normalized hostname.
int htp_normalize_parsed_uri ( htp_connp_t connp,
htp_uri_t incomplete,
htp_uri_t normalized 
)

Normalize a previously-parsed request URI.

Parameters
[in]connp
[in]incomplete
[in]normalized
Returns
HTP_OK or HTP_ERROR
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
[in]s
int64_t 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
[in]data
[in]len
Returns
Chunk length, or -1 on error.
int64_t htp_parse_content_length ( bstr b)

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

Parameters
[in]b
Returns
Content-Length as a number, or -1 on error.
htp_status_t htp_parse_ct_header ( bstr header,
bstr **  ct 
)
htp_status_t htp_parse_header_hostport ( bstr hostport,
bstr **  hostname,
int *  port,
uint64_t *  flags 
)

Parses hostport provided in the Host header.

Parameters
[in]hostport
[out]hostname
[out]port
[out]flags
Returns
HTP_OK on success or HTP_ERROR error.
htp_status_t htp_parse_hostport ( bstr hostport,
bstr **  hostname,
int *  port,
int *  invalid 
)

Parses an authority string, which consists of a hostname with an optional port number; username and password are not allowed and will not be handled.

Parameters
[in]hostport
[out]hostnameA bstring containing the hostname, or NULL if the hostname is invalid. If this value is not NULL, the caller assumes responsibility for memory management.
[out]portPort number, or -1 if the port is not present or invalid.
[out]invalidSet to 1 if any part of the authority is invalid.
Returns
HTP_OK on success, HTP_ERROR on memory allocation failure.
int64_t htp_parse_positive_integer_whitespace ( unsigned char *  data,
size_t  len,
int  base 
)

A somewhat forgiving parser for a positive integer in a given base. Only LWS is allowed before and after the number.

Parameters
[in]data
[in]len
[in]base
Returns
The parsed number on success; a negative number on error.
int htp_parse_uri ( bstr input,
htp_uri_t **  uri 
)

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

Parameters
[in]input
[in]uri
Returns
HTP_ERROR on memory allocation failure, HTP_OK otherwise
int htp_parse_uri_hostport ( htp_connp_t connp,
bstr hostport,
htp_uri_t uri 
)

Parses hostport provided in the URI.

Parameters
[in]connp
[in]hostport
[in]uri
Returns
HTP_OK on success or HTP_ERROR error.
void htp_print_log ( FILE *  stream,
htp_log_t log 
)

Prints one log message to stderr.

Parameters
[in]stream
[in]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
[in]connp
[in]parsed_uri
[in]hostname
int htp_req_run_hook_body_data ( htp_connp_t connp,
htp_tx_data_t d 
)

Run the REQUEST_BODY_DATA hook.

Parameters
[in]connp
[in]d
int htp_res_run_hook_body_data ( htp_connp_t connp,
htp_tx_data_t d 
)

Run the RESPONSE_BODY_DATA hook.

Parameters
[in]connp
[in]d
int htp_treat_response_line_as_body ( 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
[in]tx
Returns
1 for good enough or 0 for not good enough
char* htp_tx_request_progress_as_string ( htp_tx_t tx)
char* htp_tx_response_progress_as_string ( htp_tx_t tx)
bstr* htp_unparse_uri_noencode ( htp_uri_t uri)
htp_uri_t* htp_uri_alloc ( void  )

Allocates and initializes a new htp_uri_t structure.

Returns
New structure, or NULL on memory allocation failure.
void htp_uri_free ( htp_uri_t uri)

Frees all data contained in the uri, and then the uri itself.

Parameters
[in]uri
void htp_uriencoding_normalize_inplace ( bstr s)

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

Parameters
[in]s
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
[in]cfg
[in]tx
[in]path
void htp_utf8_validate_path ( htp_tx_t tx,
bstr path 
)

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

Parameters
[in]tx
[in]path
int htp_validate_hostname ( bstr hostname)

Implements relaxed (not strictly RFC) hostname validation.

Parameters
[in]hostname
Returns
1 if the supplied hostname is valid; 0 if it is not.