HTP  0.5
htp.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) 2009-2010 Open Information Security Foundation
3  * Copyright (c) 2010-2013 Qualys, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * - Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12 
13  * - Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16 
17  * - Neither the name of the Qualys, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  ***************************************************************************/
33 
39 #ifndef _HTP_H
40 #define _HTP_H
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #include <sys/time.h>
47 
48 #include "htp_version.h"
49 #include "htp_core.h"
50 
51 #include "bstr.h"
52 #include "htp_base64.h"
53 #include "htp_config.h"
54 #include "htp_connection_parser.h"
55 #include "htp_decompressors.h"
56 #include "htp_hooks.h"
57 #include "htp_list.h"
58 #include "htp_multipart.h"
59 #include "htp_table.h"
60 #include "htp_transaction.h"
61 #include "htp_urlencoded.h"
62 #include "htp_utf8_decoder.h"
63 
67 struct htp_conn_t {
69  char *client_addr;
70 
73 
75  char *server_addr;
76 
79 
86 
89 
91  uint8_t flags;
92 
95 
98 
101 
104 };
105 
111 struct htp_file_t {
114 
117 
119  int64_t len;
120 
122  char *tmpname;
123 
125  int fd;
126 };
127 
134 
136  const unsigned char *data;
137 
139  size_t len;
140 };
141 
145 struct htp_log_t {
148 
151 
153  const char *msg;
154 
157 
159  int code;
160 
162  const char *file;
163 
165  unsigned int line;
166 };
167 
171 struct htp_header_t {
174 
177 
179  uint64_t flags;
180 };
181 
185 struct htp_param_t {
188 
191 
194 
197 
202  void *parser_data;
203 };
204 
208 struct htp_tx_t {
211 
214 
217 
223 
225  void *user_data;
226 
227 
228  // Request fields
229 
231  unsigned int request_ignored_lines;
232 
235 
238 
241 
250 
253 
259 
267 
276 
284 
285  /* HTTP 1.1 RFC
286  *
287  * 4.3 Message Body
288  *
289  * The message-body (if any) of an HTTP message is used to carry the
290  * entity-body associated with the request or response. The message-body
291  * differs from the entity-body only when a transfer-coding has been
292  * applied, as indicated by the Transfer-Encoding header field (section
293  * 14.41).
294  *
295  * message-body = entity-body
296  * | <entity-body encoded as per Transfer-Encoding>
297  */
298 
308 
318 
321 
328 
331 
338 
346 
352 
358 
364 
370 
376 
379 
382 
385 
388 
391 
399 
405 
406 
407  // Response fields
408 
411 
414 
417 
423 
429 
435 
441 
444 
447 
450 
451  /* HTTP 1.1 RFC
452  *
453  * 4.3 Message Body
454  *
455  * The message-body (if any) of an HTTP message is used to carry the
456  * entity-body associated with the request or response. The message-body
457  * differs from the entity-body only when a transfer-coding has been
458  * applied, as indicated by the Transfer-Encoding header field (section
459  * 14.41).
460  *
461  * message-body = entity-body
462  * | <entity-body encoded as per Transfer-Encoding>
463  */
464 
474 
484 
492 
498 
505 
514 
521 
522 
523  // Common fields
524 
529  uint64_t flags;
530 
533 
536 
538  size_t index;
539 
542 
545 };
546 
554 
556  const unsigned char *data;
557 
559  size_t len;
560 
566  int is_last;
567 };
568 
575 struct htp_uri_t {
578 
581 
584 
587 
590 
597 
600 
603 
608 };
609 
615 void htp_uri_free(htp_uri_t *uri);
616 
622 htp_uri_t *htp_uri_alloc(void);
623 
636 void htp_log(htp_connp_t *connp, const char *file, int line, enum htp_log_level_t level, int code, const char *fmt, ...);
637 
649 htp_status_t htp_urldecode_inplace(htp_cfg_t *cfg, enum htp_decoder_ctx_t ctx, bstr *input, uint64_t *flags);
650 
665 htp_status_t htp_urldecode_inplace_ex(htp_cfg_t *cfg, enum htp_decoder_ctx_t ctx, bstr *input, uint64_t *flags, int *expected_status_code);
666 
672 char *htp_get_version(void);
673 
674 #ifdef __cplusplus
675 }
676 #endif
677 
678 #endif /* _HTP_H */
htp_file_data_t
Definition: htp.h:131
htp_conn_t::close_timestamp
htp_time_t close_timestamp
Definition: htp.h:97
htp_tx_t::response_status_number
int response_status_number
Definition: htp.h:434
htp_method_t
htp_method_t
Definition: htp_core.h:259
htp_tx_t
Definition: htp.h:208
htp_decompressors.h
htp_tx_t::response_content_encoding
enum htp_content_encoding_t response_content_encoding
Definition: htp.h:504
htp_tx_t::conn
htp_conn_t * conn
Definition: htp.h:213
htp_file_data_t::data
const unsigned char * data
Definition: htp.h:136
htp_tx_t::request_progress
enum htp_tx_req_progress_t request_progress
Definition: htp.h:532
htp_tx_t::response_message
bstr * response_message
Definition: htp.h:443
htp_header_t::flags
uint64_t flags
Definition: htp.h:179
htp_log_level_t
htp_log_level_t
Definition: htp_core.h:246
htp_header_t
Definition: htp.h:171
htp_param_t::parser_id
enum htp_parser_id_t parser_id
Definition: htp.h:196
htp_uri_t::port
bstr * port
Definition: htp.h:589
htp_header_t::value
bstr * value
Definition: htp.h:176
htp_transfer_coding_t
htp_transfer_coding_t
Definition: htp_core.h:167
htp_tx_t::response_line
bstr * response_line
Definition: htp.h:413
htp_conn_t::client_port
int client_port
Definition: htp.h:72
htp_tx_t::request_protocol
bstr * request_protocol
Definition: htp.h:252
htp_tx_t::request_method
bstr * request_method
Definition: htp.h:237
htp_conn_t::in_data_counter
int64_t in_data_counter
Definition: htp.h:100
htp_uri_t::fragment
bstr * fragment
Definition: htp.h:607
htp_param_t::name
bstr * name
Definition: htp.h:187
htp_uri_free
void htp_uri_free(htp_uri_t *uri)
Definition: htp_util.c:2472
htp_hook_t
Definition: htp_hooks.h:52
htp_core.h
htp_urldecode_inplace_ex
htp_status_t htp_urldecode_inplace_ex(htp_cfg_t *cfg, enum htp_decoder_ctx_t ctx, bstr *input, uint64_t *flags, int *expected_status_code)
Definition: htp_util.c:1539
htp_conn_t::server_port
int server_port
Definition: htp.h:78
htp_file_source_t
htp_file_source_t
Definition: htp_core.h:184
htp_conn_t::open_timestamp
htp_time_t open_timestamp
Definition: htp.h:94
htp_auth_type_t
htp_auth_type_t
Definition: htp_core.h:122
htp_tx_t::request_urlenp_body
htp_urlenp_t * request_urlenp_body
Definition: htp.h:369
htp_file_t::filename
bstr * filename
Definition: htp.h:116
htp_tx_t::response_protocol
bstr * response_protocol
Definition: htp.h:416
htp_param_t::parser_data
void * parser_data
Definition: htp.h:202
htp_tx_t::response_message_len
int64_t response_message_len
Definition: htp.h:473
htp_tx_data_t::is_last
int is_last
Definition: htp.h:566
htp_tx_t::res_header_repetitions
uint16_t res_header_repetitions
Definition: htp.h:544
htp_tx_t::response_content_encoding_processing
enum htp_content_encoding_t response_content_encoding_processing
Definition: htp.h:513
htp_log_t::code
int code
Definition: htp.h:159
htp_config.h
htp_table.h
htp_conn_t::flags
uint8_t flags
Definition: htp.h:91
htp_tx_t::request_auth_password
bstr * request_auth_password
Definition: htp.h:390
htp_file_data_t::file
htp_file_t * file
Definition: htp.h:133
htp_content_encoding_t
htp_content_encoding_t
Definition: htp_core.h:143
htp_param_t::value
bstr * value
Definition: htp.h:190
htp_log_t::level
enum htp_log_level_t level
Definition: htp.h:156
htp_conn_t
Definition: htp.h:67
htp_conn_t::messages
htp_list_t * messages
Definition: htp.h:88
htp_tx_t::request_content_encoding
enum htp_content_encoding_t request_content_encoding
Definition: htp.h:330
htp_tx_t::request_content_length
int64_t request_content_length
Definition: htp.h:345
htp_get_version
char * htp_get_version(void)
Definition: htp_util.c:2496
htp_conn_t::server_addr
char * server_addr
Definition: htp.h:75
htp_tx_t::request_cookies
htp_table_t * request_cookies
Definition: htp.h:381
htp_conn_t::client_addr
char * client_addr
Definition: htp.h:69
htp_tx_t::response_ignored_lines
unsigned int response_ignored_lines
Definition: htp.h:410
htp_version.h
htp_uri_t::path
bstr * path
Definition: htp.h:599
htp_list_t
#define htp_list_t
Definition: htp_list.h:48
htp_uri_alloc
htp_uri_t * htp_uri_alloc(void)
Definition: htp_util.c:2487
htp_urlenp_t
Definition: htp_urlencoded.h:63
htp_tx_t::index
size_t index
Definition: htp.h:538
htp_tx_t::request_content_type
bstr * request_content_type
Definition: htp.h:337
htp_tx_t::request_port_number
int request_port_number
Definition: htp.h:404
htp_uri_t::username
bstr * username
Definition: htp.h:580
htp_cfg_t
Definition: htp_config_private.h:123
htp_tx_data_t::data
const unsigned char * data
Definition: htp.h:556
htp_file_t::len
int64_t len
Definition: htp.h:119
htp_parser_id_t
htp_parser_id_t
Definition: htp_core.h:296
htp_tx_t::request_mpartp
htp_mpartp_t * request_mpartp
Definition: htp.h:375
htp_uri_t::port_number
int port_number
Definition: htp.h:596
htp_uri_t
Definition: htp.h:575
htp_tx_t::connp
htp_connp_t * connp
Definition: htp.h:210
htp_log
void htp_log(htp_connp_t *connp, const char *file, int line, enum htp_log_level_t level, int code, const char *fmt,...)
Definition: htp_util.c:391
htp_tx_t::request_line
bstr * request_line
Definition: htp.h:234
htp_file_t::tmpname
char * tmpname
Definition: htp.h:122
htp_param_t
Definition: htp.h:185
htp_tx_t::is_config_shared
int is_config_shared
Definition: htp.h:222
htp_tx_t::req_header_repetitions
uint16_t req_header_repetitions
Definition: htp.h:541
htp_status_t
int htp_status_t
Definition: htp_core.h:46
htp_connection_parser.h
htp_tx_t::hook_response_body_data
htp_hook_t * hook_response_body_data
Definition: htp.h:357
htp_decoder_ctx_t
htp_decoder_ctx_t
Definition: htp_config.h:51
htp_connp_t
Definition: htp_connection_parser_private.h:51
bstr_t
Definition: bstr.h:57
htp_urlencoded.h
htp_file_data_t::len
size_t len
Definition: htp.h:139
htp_tx_t::response_transfer_coding
enum htp_transfer_coding_t response_transfer_coding
Definition: htp.h:497
htp_tx_res_progress_t
htp_tx_res_progress_t
Definition: htp_transaction.h:84
htp_tx_t::flags
uint64_t flags
Definition: htp.h:529
htp_tx_t::response_entity_len
int64_t response_entity_len
Definition: htp.h:483
htp_tx_t::request_message_len
int64_t request_message_len
Definition: htp.h:307
htp_time_t
struct timeval htp_time_t
Definition: htp_core.h:60
htp_log_t::file
const char * file
Definition: htp.h:162
htp_conn_t::out_data_counter
int64_t out_data_counter
Definition: htp.h:103
htp_transaction.h
htp_tx_t::response_headers
htp_table_t * response_headers
Definition: htp.h:449
htp_tx_t::response_progress
enum htp_tx_res_progress_t response_progress
Definition: htp.h:535
htp_tx_t::request_hostname
bstr * request_hostname
Definition: htp.h:398
htp_tx_t::request_params
htp_table_t * request_params
Definition: htp.h:378
htp_tx_t::response_content_length
int64_t response_content_length
Definition: htp.h:491
htp_tx_t::request_method_number
enum htp_method_t request_method_number
Definition: htp.h:240
htp_tx_data_t::len
size_t len
Definition: htp.h:559
htp_file_t::fd
int fd
Definition: htp.h:125
htp_tx_t::response_status_expected_number
int response_status_expected_number
Definition: htp.h:440
htp_log_t::tx
htp_tx_t * tx
Definition: htp.h:150
htp_tx_t::hook_request_body_data
htp_hook_t * hook_request_body_data
Definition: htp.h:351
htp_log_t::msg
const char * msg
Definition: htp.h:153
htp_tx_t::response_content_type
bstr * response_content_type
Definition: htp.h:520
htp_tx_t::request_ignored_lines
unsigned int request_ignored_lines
Definition: htp.h:231
htp_multipart.h
htp_tx_t::seen_100continue
int seen_100continue
Definition: htp.h:446
htp_tx_t::request_protocol_number
int request_protocol_number
Definition: htp.h:258
htp_tx_t::cfg
htp_cfg_t * cfg
Definition: htp.h:216
htp_log_t::line
unsigned int line
Definition: htp.h:165
htp_tx_t::response_protocol_number
int response_protocol_number
Definition: htp.h:422
htp_hooks.h
bstr.h
htp_tx_t::request_entity_len
int64_t request_entity_len
Definition: htp.h:317
htp_conn_t::transactions
htp_list_t * transactions
Definition: htp.h:85
htp_base64.h
htp_urldecode_inplace
htp_status_t htp_urldecode_inplace(htp_cfg_t *cfg, enum htp_decoder_ctx_t ctx, bstr *input, uint64_t *flags)
Definition: htp_util.c:1534
htp_param_t::source
enum htp_data_source_t source
Definition: htp.h:193
htp_uri_t::query
bstr * query
Definition: htp.h:602
htp_tx_t::request_uri
bstr * request_uri
Definition: htp.h:249
htp_tx_t::parsed_uri_raw
htp_uri_t * parsed_uri_raw
Definition: htp.h:283
htp_data_source_t
htp_data_source_t
Definition: htp_core.h:314
htp_tx_data_t
Definition: htp.h:551
htp_uri_t::hostname
bstr * hostname
Definition: htp.h:586
htp_tx_req_progress_t
htp_tx_req_progress_t
Definition: htp_transaction.h:75
htp_mpartp_t
Definition: htp_multipart_private.h:85
htp_file_t
Definition: htp.h:111
htp_uri_t::scheme
bstr * scheme
Definition: htp.h:577
htp_tx_t::parsed_uri
htp_uri_t * parsed_uri
Definition: htp.h:275
htp_header_t::name
bstr * name
Definition: htp.h:173
htp_tx_t::request_auth_username
bstr * request_auth_username
Definition: htp.h:387
htp_tx_t::request_urlenp_query
htp_urlenp_t * request_urlenp_query
Definition: htp.h:363
htp_tx_t::request_headers
htp_table_t * request_headers
Definition: htp.h:320
htp_uri_t::password
bstr * password
Definition: htp.h:583
htp_file_t::source
enum htp_file_source_t source
Definition: htp.h:113
htp_log_t::connp
htp_connp_t * connp
Definition: htp.h:147
htp_tx_t::user_data
void * user_data
Definition: htp.h:225
htp_tx_t::request_auth_type
enum htp_auth_type_t request_auth_type
Definition: htp.h:384
htp_tx_data_t::tx
htp_tx_t * tx
Definition: htp.h:553
htp_table_t
Definition: htp_table_private.h:63
htp_log_t
Definition: htp.h:145
htp_tx_t::request_transfer_coding
enum htp_transfer_coding_t request_transfer_coding
Definition: htp.h:327
htp_list.h
htp_utf8_decoder.h
htp_tx_t::response_status
bstr * response_status
Definition: htp.h:428
htp_tx_t::is_protocol_0_9
int is_protocol_0_9
Definition: htp.h:266