00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00039 #ifndef _HTP_H
00040 #define _HTP_H
00041
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045
00046 #include <sys/time.h>
00047
00048 #include "htp_version.h"
00049 #include "htp_core.h"
00050
00051 #include "bstr.h"
00052 #include "htp_base64.h"
00053 #include "htp_config.h"
00054 #include "htp_connection_parser.h"
00055 #include "htp_decompressors.h"
00056 #include "htp_hooks.h"
00057 #include "htp_list.h"
00058 #include "htp_multipart.h"
00059 #include "htp_table.h"
00060 #include "htp_transaction.h"
00061 #include "htp_urlencoded.h"
00062 #include "htp_utf8_decoder.h"
00063
00067 struct htp_conn_t {
00069 char *client_addr;
00070
00072 int client_port;
00073
00075 char *server_addr;
00076
00078 int server_port;
00079
00085 htp_list_t *transactions;
00086
00088 htp_list_t *messages;
00089
00091 uint8_t flags;
00092
00094 htp_time_t open_timestamp;
00095
00097 htp_time_t close_timestamp;
00098
00100 int64_t in_data_counter;
00101
00103 int64_t out_data_counter;
00104 };
00105
00111 struct htp_file_t {
00113 enum htp_file_source_t source;
00114
00116 bstr *filename;
00117
00119 int64_t len;
00120
00122 char *tmpname;
00123
00125 int fd;
00126 };
00127
00131 struct htp_file_data_t {
00133 htp_file_t *file;
00134
00136 const unsigned char *data;
00137
00139 size_t len;
00140 };
00141
00145 struct htp_log_t {
00147 htp_connp_t *connp;
00148
00150 htp_tx_t *tx;
00151
00153 const char *msg;
00154
00156 enum htp_log_level_t level;
00157
00159 int code;
00160
00162 const char *file;
00163
00165 unsigned int line;
00166 };
00167
00171 struct htp_header_t {
00173 bstr *name;
00174
00176 bstr *value;
00177
00179 uint64_t flags;
00180 };
00181
00185 struct htp_param_t {
00187 bstr *name;
00188
00190 bstr *value;
00191
00193 enum htp_data_source_t source;
00194
00196 enum htp_parser_id_t parser_id;
00197
00202 void *parser_data;
00203 };
00204
00208 struct htp_tx_t {
00210 htp_connp_t *connp;
00211
00213 htp_conn_t *conn;
00214
00216 htp_cfg_t *cfg;
00217
00222 int is_config_shared;
00223
00225 void *user_data;
00226
00227
00228
00229
00231 unsigned int request_ignored_lines;
00232
00234 bstr *request_line;
00235
00237 bstr *request_method;
00238
00240 enum htp_method_t request_method_number;
00241
00249 bstr *request_uri;
00250
00252 bstr *request_protocol;
00253
00258 int request_protocol_number;
00259
00266 int is_protocol_0_9;
00267
00275 htp_uri_t *parsed_uri;
00276
00283 htp_uri_t *parsed_uri_raw;
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00307 int64_t request_message_len;
00308
00317 int64_t request_entity_len;
00318
00320 htp_table_t *request_headers;
00321
00327 enum htp_transfer_coding_t request_transfer_coding;
00328
00330 enum htp_content_encoding_t request_content_encoding;
00331
00337 bstr *request_content_type;
00338
00345 int64_t request_content_length;
00346
00351 htp_hook_t *hook_request_body_data;
00352
00357 htp_hook_t *hook_response_body_data;
00358
00363 htp_urlenp_t *request_urlenp_query;
00364
00369 htp_urlenp_t *request_urlenp_body;
00370
00375 htp_mpartp_t *request_mpartp;
00376
00378 htp_table_t *request_params;
00379
00381 htp_table_t *request_cookies;
00382
00384 enum htp_auth_type_t request_auth_type;
00385
00387 bstr *request_auth_username;
00388
00390 bstr *request_auth_password;
00391
00398 bstr *request_hostname;
00399
00404 int request_port_number;
00405
00406
00407
00408
00410 unsigned int response_ignored_lines;
00411
00413 bstr *response_line;
00414
00416 bstr *response_protocol;
00417
00422 int response_protocol_number;
00423
00428 bstr *response_status;
00429
00434 int response_status_number;
00435
00440 int response_status_expected_number;
00441
00443 bstr *response_message;
00444
00446 int seen_100continue;
00447
00449 htp_table_t *response_headers;
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00473 int64_t response_message_len;
00474
00483 int64_t response_entity_len;
00484
00491 int64_t response_content_length;
00492
00497 enum htp_transfer_coding_t response_transfer_coding;
00498
00504 enum htp_content_encoding_t response_content_encoding;
00505
00513 enum htp_content_encoding_t response_content_encoding_processing;
00514
00520 bstr *response_content_type;
00521
00522
00523
00524
00529 uint64_t flags;
00530
00532 enum htp_tx_req_progress_t request_progress;
00533
00535 enum htp_tx_res_progress_t response_progress;
00536
00538 size_t index;
00539 };
00540
00545 struct htp_tx_data_t {
00547 htp_tx_t *tx;
00548
00550 const unsigned char *data;
00551
00553 size_t len;
00554
00560 int is_last;
00561 };
00562
00569 struct htp_uri_t {
00571 bstr *scheme;
00572
00574 bstr *username;
00575
00577 bstr *password;
00578
00580 bstr *hostname;
00581
00583 bstr *port;
00584
00590 int port_number;
00591
00593 bstr *path;
00594
00596 bstr *query;
00597
00601 bstr *fragment;
00602 };
00603
00609 void htp_uri_free(htp_uri_t *uri);
00610
00616 htp_uri_t *htp_uri_alloc(void);
00617
00630 void htp_log(htp_connp_t *connp, const char *file, int line, enum htp_log_level_t level, int code, const char *fmt, ...);
00631
00643 htp_status_t htp_urldecode_inplace(htp_cfg_t *cfg, enum htp_decoder_ctx_t ctx, bstr *input, uint64_t *flags);
00644
00659 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);
00660
00666 char *htp_get_version(void);
00667
00668 #ifdef __cplusplus
00669 }
00670 #endif
00671
00672 #endif