HTP  0.3
htp.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (c) 2009-2010, Open Information Security Foundation
3  * Copyright (c) 2009-2012, 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  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Qualys, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  ***************************************************************************/
31 
37 #ifndef _HTP_H
38 #define _HTP_H
39 
40 typedef struct htp_cfg_t htp_cfg_t;
41 typedef struct htp_conn_t htp_conn_t;
42 typedef struct htp_connp_t htp_connp_t;
43 typedef struct htp_file_t htp_file_t;
45 typedef struct htp_header_t htp_header_t;
47 typedef struct htp_log_t htp_log_t;
49 typedef struct htp_tx_t htp_tx_t;
50 typedef struct htp_uri_t htp_uri_t;
51 
52 #include <ctype.h>
53 #include <iconv.h>
54 #include <stdarg.h>
55 #include <stddef.h>
56 #include <stdio.h>
57 #include <stdint.h>
58 #include <stdlib.h>
59 #include <string.h>
60 #include <sys/time.h>
61 
62 #include "bstr.h"
63 #include "dslib.h"
64 #include "hooks.h"
65 #include "htp_decompressors.h"
66 #include "htp_urlencoded.h"
67 #include "htp_multipart.h"
68 
69 // -- Defines -------------------------------------------------------------------------------------
70 
71 #define HTP_BASE_VERSION_TEXT "0.3.0"
72 
73 #define HTP_ERROR -1
74 #define HTP_OK 0
75 #define HTP_DATA 1
76 #define HTP_DATA_OTHER 2
77 #define HTP_DECLINED 3
78 
79 #define PROTOCOL_UNKNOWN -1
80 #define HTTP_0_9 9
81 #define HTTP_1_0 100
82 #define HTTP_1_1 101
83 
84 #define HTP_LOG_MARK __FILE__,__LINE__
85 
86 #define HTP_LOG_ERROR 1
87 #define HTP_LOG_WARNING 2
88 #define HTP_LOG_NOTICE 3
89 #define HTP_LOG_INFO 4
90 #define HTP_LOG_DEBUG 5
91 #define HTP_LOG_DEBUG2 6
92 
93 #define HTP_HEADER_MISSING_COLON 1
94 #define HTP_HEADER_INVALID_NAME 2
95 #define HTP_HEADER_LWS_AFTER_FIELD_NAME 3
96 #define HTP_LINE_TOO_LONG_HARD 4
97 #define HTP_LINE_TOO_LONG_SOFT 5
98 
99 #define HTP_HEADER_LIMIT_HARD 18000
100 #define HTP_HEADER_LIMIT_SOFT 9000
101 
102 #define HTP_VALID_STATUS_MIN 100
103 #define HTP_VALID_STATUS_MAX 999
104 
105 #define LOG_NO_CODE 0
106 
107 #define CR '\r'
108 #define LF '\n'
109 
110 #define M_UNKNOWN -1
111 
112 // The following request method are defined in Apache 2.2.13, in httpd.h.
113 #define M_GET 0
114 #define M_PUT 1
115 #define M_POST 2
116 #define M_DELETE 3
117 #define M_CONNECT 4
118 #define M_OPTIONS 5
119 #define M_TRACE 6
120 #define M_PATCH 7
121 #define M_PROPFIND 8
122 #define M_PROPPATCH 9
123 #define M_MKCOL 10
124 #define M_COPY 11
125 #define M_MOVE 12
126 #define M_LOCK 13
127 #define M_UNLOCK 14
128 #define M_VERSION_CONTROL 15
129 #define M_CHECKOUT 16
130 #define M_UNCHECKOUT 17
131 #define M_CHECKIN 18
132 #define M_UPDATE 19
133 #define M_LABEL 20
134 #define M_REPORT 21
135 #define M_MKWORKSPACE 22
136 #define M_MKACTIVITY 23
137 #define M_BASELINE_CONTROL 24
138 #define M_MERGE 25
139 #define M_INVALID 26
140 
141 // Interestingly, Apache does not define M_HEAD
142 #define M_HEAD 1000
143 
144 #define HTP_FIELD_UNPARSEABLE 0x000001
145 #define HTP_FIELD_INVALID 0x000002
146 #define HTP_FIELD_FOLDED 0x000004
147 #define HTP_FIELD_REPEATED 0x000008
148 #define HTP_FIELD_LONG 0x000010
149 #define HTP_FIELD_NUL_BYTE 0x000020
150 #define HTP_REQUEST_SMUGGLING 0x000040
151 #define HTP_INVALID_FOLDING 0x000080
152 #define HTP_INVALID_CHUNKING 0x000100
153 #define HTP_MULTI_PACKET_HEAD 0x000200
154 #define HTP_HOST_MISSING 0x000400
155 #define HTP_AMBIGUOUS_HOST 0x000800
156 #define HTP_PATH_ENCODED_NUL 0x001000
157 #define HTP_PATH_INVALID_ENCODING 0x002000
158 #define HTP_PATH_INVALID 0x004000
159 #define HTP_PATH_OVERLONG_U 0x008000
160 #define HTP_PATH_ENCODED_SEPARATOR 0x010000
161 
162 #define HTP_PATH_UTF8_VALID 0x020000 /* At least one valid UTF-8 character and no invalid ones */
163 #define HTP_PATH_UTF8_INVALID 0x040000
164 #define HTP_PATH_UTF8_OVERLONG 0x080000
165 #define HTP_PATH_FULLWIDTH_EVASION 0x100000 /* Range U+FF00 - U+FFFF detected */
166 
167 #define HTP_STATUS_LINE_INVALID 0x200000
168 
169 #define PIPELINED_CONNECTION 1
170 
171 #define HTP_SERVER_MINIMAL 0
172 #define HTP_SERVER_GENERIC 1
173 #define HTP_SERVER_IDS 2
174 #define HTP_SERVER_IIS_4_0 4 /* Windows NT 4.0 */
175 #define HTP_SERVER_IIS_5_0 5 /* Windows 2000 */
176 #define HTP_SERVER_IIS_5_1 6 /* Windows XP Professional */
177 #define HTP_SERVER_IIS_6_0 7 /* Windows 2003 */
178 #define HTP_SERVER_IIS_7_0 8 /* Windows 2008 */
179 #define HTP_SERVER_IIS_7_5 9 /* Windows 7 */
180 #define HTP_SERVER_TOMCAT_6_0 10 /* Unused */
181 #define HTP_SERVER_APACHE 11
182 #define HTP_SERVER_APACHE_2_2 12
183 
184 #define NONE 0
185 #define IDENTITY 1
186 #define CHUNKED 2
187 
188 #define TX_PROGRESS_NEW 0
189 #define TX_PROGRESS_REQ_LINE 1
190 #define TX_PROGRESS_REQ_HEADERS 2
191 #define TX_PROGRESS_REQ_BODY 3
192 #define TX_PROGRESS_REQ_TRAILER 4
193 #define TX_PROGRESS_WAIT 5
194 #define TX_PROGRESS_RES_LINE 6
195 #define TX_PROGRESS_RES_HEADERS 7
196 #define TX_PROGRESS_RES_BODY 8
197 #define TX_PROGRESS_RES_TRAILER 9
198 #define TX_PROGRESS_DONE 10
199 
200 #define STREAM_STATE_NEW 0
201 #define STREAM_STATE_OPEN 1
202 #define STREAM_STATE_CLOSED 2
203 #define STREAM_STATE_ERROR 3
204 #define STREAM_STATE_TUNNEL 4
205 #define STREAM_STATE_DATA_OTHER 5
206 #define STREAM_STATE_DATA 9
207 
208 #define URL_DECODER_PRESERVE_PERCENT 0
209 #define URL_DECODER_REMOVE_PERCENT 1
210 #define URL_DECODER_DECODE_INVALID 2
211 #define URL_DECODER_STATUS_400 400
212 
213 #define NONE 0
214 #define NO 0
215 #define BESTFIT 0
216 #define YES 1
217 #define TERMINATE 1
218 #define STATUS_400 400
219 #define STATUS_404 401
220 
221 #define HTP_AUTH_NONE 0
222 #define HTP_AUTH_BASIC 1
223 #define HTP_AUTH_DIGEST 2
224 #define HTP_AUTH_UNKNOWN 9
225 
226 #define HTP_FILE_MULTIPART 1
227 #define HTP_FILE_PUT 2
228 
229 #define IN_TEST_NEXT_BYTE_OR_RETURN(X) \
230 if ((X)->in_current_offset >= (X)->in_current_len) { \
231  return HTP_DATA; \
232 }
233 
234 #define IN_NEXT_BYTE(X) \
235 if ((X)->in_current_offset < (X)->in_current_len) { \
236  (X)->in_next_byte = (X)->in_current_data[(X)->in_current_offset]; \
237  (X)->in_current_offset++; \
238  (X)->in_stream_offset++; \
239 } else { \
240  (X)->in_next_byte = -1; \
241 }
242 
243 #define IN_NEXT_BYTE_OR_RETURN(X) \
244 if ((X)->in_current_offset < (X)->in_current_len) { \
245  (X)->in_next_byte = (X)->in_current_data[(X)->in_current_offset]; \
246  (X)->in_current_offset++; \
247  (X)->in_stream_offset++; \
248 } else { \
249  return HTP_DATA; \
250 }
251 
252 #define IN_COPY_BYTE_OR_RETURN(X) \
253 if ((X)->in_current_offset < (X)->in_current_len) { \
254  (X)->in_next_byte = (X)->in_current_data[(X)->in_current_offset]; \
255  (X)->in_current_offset++; \
256  (X)->in_stream_offset++; \
257 } else { \
258  return HTP_DATA; \
259 } \
260 \
261 if ((X)->in_line_len < (X)->in_line_size) { \
262  (X)->in_line[(X)->in_line_len] = (X)->in_next_byte; \
263  (X)->in_line_len++; \
264  if (((X)->in_line_len == HTP_HEADER_LIMIT_SOFT)&&(!((X)->in_tx->flags & HTP_FIELD_LONG))) { \
265  (X)->in_tx->flags |= HTP_FIELD_LONG; \
266  htp_log((X), HTP_LOG_MARK, HTP_LOG_ERROR, HTP_LINE_TOO_LONG_SOFT, "Request field over soft limit"); \
267  } \
268 } else { \
269  htp_log((X), HTP_LOG_MARK, HTP_LOG_ERROR, HTP_LINE_TOO_LONG_HARD, "Request field over hard limit"); \
270  return HTP_ERROR; \
271 }
272 
273 #define OUT_TEST_NEXT_BYTE_OR_RETURN(X) \
274 if ((X)->out_current_offset >= (X)->out_current_len) { \
275  return HTP_DATA; \
276 }
277 
278 #define OUT_NEXT_BYTE(X) \
279 if ((X)->out_current_offset < (X)->out_current_len) { \
280  (X)->out_next_byte = (X)->out_current_data[(X)->out_current_offset]; \
281  (X)->out_current_offset++; \
282  (X)->out_stream_offset++; \
283 } else { \
284  (X)->out_next_byte = -1; \
285 }
286 
287 #define OUT_NEXT_BYTE_OR_RETURN(X) \
288 if ((X)->out_current_offset < (X)->out_current_len) { \
289  (X)->out_next_byte = (X)->out_current_data[(X)->out_current_offset]; \
290  (X)->out_current_offset++; \
291  (X)->out_stream_offset++; \
292 } else { \
293  return HTP_DATA; \
294 }
295 
296 #define OUT_COPY_BYTE_OR_RETURN(X) \
297 if ((X)->out_current_offset < (X)->out_current_len) { \
298  (X)->out_next_byte = (X)->out_current_data[(X)->out_current_offset]; \
299  (X)->out_current_offset++; \
300  (X)->out_stream_offset++; \
301 } else { \
302  return HTP_DATA; \
303 } \
304 \
305 if ((X)->out_line_len < (X)->out_line_size) { \
306  (X)->out_line[(X)->out_line_len] = (X)->out_next_byte; \
307  (X)->out_line_len++; \
308  if (((X)->out_line_len == HTP_HEADER_LIMIT_SOFT)&&(!((X)->out_tx->flags & HTP_FIELD_LONG))) { \
309  (X)->out_tx->flags |= HTP_FIELD_LONG; \
310  htp_log((X), HTP_LOG_MARK, HTP_LOG_ERROR, HTP_LINE_TOO_LONG_SOFT, "Response field over soft limit"); \
311  } \
312 } else { \
313  htp_log((X), HTP_LOG_MARK, HTP_LOG_ERROR, HTP_LINE_TOO_LONG_HARD, "Response field over hard limit"); \
314  return HTP_ERROR; \
315 }
316 
317 #ifdef __cplusplus
318 extern "C" {
319 #endif
320 
321 typedef struct timeval htp_time_t;
322 
323 // -- Data structures -----------------------------------------------------------------------------
324 
325 struct htp_cfg_t {
332 
337 
342 
347 
352 
355 
358 
361 
364 
366  int (*parameter_processor)(table_t *params, bstr *name, bstr *value);
367 
368 
369  // Path handling
370 
373 
376 
379 
385 
390 
393 
396 
401 
404 
407 
410 
413 
418 
421 
424 
426  unsigned char *bestfit_map;
427 
430 
433 
435 
437 
441  char *tmpdir;
442 
443  // Hooks
444 
449 
452 
455 
458 
466 
468 
473 
476 
479 
482 
491 
496 
502 
507 
509  void *user_data;
510 };
511 
512 struct htp_conn_t {
515 
517  char *remote_addr;
518 
521 
523  char *local_addr;
524 
527 
533 
536 
538  unsigned int flags;
539 
542 
545 
548 
551 
554 
557 };
558 
559 struct htp_connp_t {
560  // General fields
561 
564 
570 
573 
575  void *user_data;
576 
582 
583  // Request parser fields
584 
586  unsigned int in_status;
587 
589  unsigned int out_status;
590 
592 
595 
597  unsigned char *in_current_data;
598 
600  int64_t in_current_len;
601 
604 
607 
610 
613 
616 
618  unsigned char *in_line;
619 
621  size_t in_line_size;
622 
624  size_t in_line_len;
625 
628 
631 
637 
640 
647 
653 
658 
661 
662  // Response parser fields
663 
669 
672 
674  unsigned char *out_current_data;
675 
678 
681 
684 
687 
689  unsigned char *out_line;
690 
693 
695  size_t out_line_len;
696 
699 
702 
708 
711 
717 
720 
725 
728 
731 
733 };
734 
735 struct htp_file_t {
737  int source;
738 
741 
743  size_t len;
744 
746  char *tmpname;
747 
749  int fd;
750 };
751 
755 
758 
760  unsigned char *data;
761 
763  size_t len;
764 };
765 
766 struct htp_log_t {
769 
772 
774  const char *msg;
775 
777  int level;
778 
780  int code;
781 
783  const char *file;
784 
786  unsigned int line;
787 };
788 
792 
794  size_t name_offset;
795 
797  size_t name_len;
798 
800  size_t value_offset;
801 
803  size_t value_len;
804 
806  unsigned int has_nulls;
807 
810 
812  unsigned int flags;
813 
816 };
817 
818 struct htp_header_t {
821 
824 
826  unsigned int flags;
827 };
828 
829 struct htp_tx_t {
832 
835 
838 
844 
846  void *user_data;
847 
848  // Request
849  unsigned int request_ignored_lines;
850 
853 
856 
859 
862 
865 
868 
871 
878 
881 
886 
889 
896 
904 
911 
918 
927 
933 
936 
939 
942 
947 
952 
955 
960 
963 
969 
970 
975 
980 
985 
990 
996 
1000 
1004 
1007 
1011 
1012  // Response
1013 
1016 
1019 
1022 
1025 
1030 
1033 
1036 
1041 
1044 
1047 
1050 
1053 
1056 
1063 
1070 
1073 
1076 
1077  // Common
1078 
1082  unsigned int flags;
1083 
1085  unsigned int progress;
1086 };
1087 
1092 
1094  unsigned char *data;
1095 
1097  size_t len;
1098 };
1099 
1104 struct htp_uri_t {
1107 
1110 
1113 
1116 
1119 
1122 
1125 
1128 
1131 };
1132 
1133 // -- Functions -----------------------------------------------------------------------------------
1134 
1135 const char *htp_get_version(void);
1136 
1139  void htp_config_destroy(htp_cfg_t *cfg);
1140 
1141 void htp_config_register_transaction_start(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1142 void htp_config_register_request_line(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1143 void htp_config_register_request_uri_normalize(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1144 void htp_config_register_request_headers(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1145 void htp_config_register_request_body_data(htp_cfg_t *cfg, int (*callback_fn)(htp_tx_data_t *));
1146 void htp_config_register_request_file_data(htp_cfg_t *cfg, int (*callback_fn)(htp_file_data_t *));
1147 void htp_config_register_request_trailer(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1148 void htp_config_register_request(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1149 
1150 void htp_config_register_response_line(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1151 void htp_config_register_response_headers(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1152 void htp_config_register_response_body_data(htp_cfg_t *cfg, int (*callback_fn)(htp_tx_data_t *));
1153 void htp_config_register_response_trailer(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1154 void htp_config_register_response(htp_cfg_t *cfg, int (*callback_fn)(htp_connp_t *));
1155 
1156 void htp_config_register_log(htp_cfg_t *cfg, int (*callback_fn)(htp_log_t *));
1157 
1158 void htp_config_set_tx_auto_destroy(htp_cfg_t *cfg, int tx_auto_destroy);
1159 
1160  int htp_config_set_server_personality(htp_cfg_t *cfg, int personality);
1161 void htp_config_set_response_decompression(htp_cfg_t *cfg, int enabled);
1162 
1163 void htp_config_set_bestfit_map(htp_cfg_t *cfg, unsigned char *map);
1164 void htp_config_set_path_backslash_separators(htp_cfg_t *cfg, int backslash_separators);
1165 void htp_config_set_path_case_insensitive(htp_cfg_t *cfg, int path_case_insensitive);
1166 void htp_config_set_path_compress_separators(htp_cfg_t *cfg, int compress_separators);
1167 void htp_config_set_path_control_char_handling(htp_cfg_t *cfg, int control_char_handling);
1168 void htp_config_set_path_convert_utf8(htp_cfg_t *cfg, int convert_utf8);
1169 void htp_config_set_path_decode_separators(htp_cfg_t *cfg, int backslash_separators);
1170 void htp_config_set_path_decode_u_encoding(htp_cfg_t *cfg, int decode_u_encoding);
1171 void htp_config_set_path_invalid_encoding_handling(htp_cfg_t *cfg, int invalid_encoding_handling);
1172 void htp_config_set_path_invalid_utf8_handling(htp_cfg_t *cfg, int invalid_utf8_handling);
1173 void htp_config_set_path_nul_encoded_handling(htp_cfg_t *cfg, int nul_encoded_handling);
1174 void htp_config_set_path_nul_raw_handling(htp_cfg_t *cfg, int nul_raw_handling);
1175 void htp_config_set_path_replacement_char(htp_cfg_t *cfg, int replacement_char);
1176 void htp_config_set_path_unicode_mapping(htp_cfg_t *cfg, int unicode_mapping);
1177 void htp_config_set_path_utf8_overlong_handling(htp_cfg_t *cfg, int utf8_overlong_handling);
1178 
1180 
1183 
1184 
1187 void htp_connp_open(htp_connp_t *connp, const char *remote_addr, int remote_port, const char *local_addr, int local_port, htp_time_t *timestamp);
1188 void htp_connp_close(htp_connp_t *connp, htp_time_t *timestamp);
1189 void htp_connp_destroy(htp_connp_t *connp);
1190 void htp_connp_destroy_all(htp_connp_t *connp);
1191 
1192  void htp_connp_set_user_data(htp_connp_t *connp, void *user_data);
1193 void *htp_connp_get_user_data(htp_connp_t *connp);
1194 
1196  void htp_conn_destroy(htp_conn_t *conn);
1197  int htp_conn_remove_tx(htp_conn_t *conn, htp_tx_t *tx);
1198 
1199  int htp_connp_req_data(htp_connp_t *connp, htp_time_t *timestamp, unsigned char *data, size_t len);
1201  int htp_connp_res_data(htp_connp_t *connp, htp_time_t *timestamp, unsigned char *data, size_t len);
1203 
1204  void htp_connp_clear_error(htp_connp_t *connp);
1206 
1207 htp_header_t *htp_connp_header_parse(htp_connp_t *, unsigned char *, size_t);
1208 
1209 #define CFG_NOT_SHARED 0
1210 #define CFG_SHARED 1
1211 
1212 htp_tx_t *htp_tx_create(htp_cfg_t *cfg, int is_cfg_shared, htp_conn_t *conn);
1213  void htp_tx_destroy(htp_tx_t *tx);
1214  void htp_tx_set_config(htp_tx_t *tx, htp_cfg_t *cfg, int is_cfg_shared);
1215 
1216  void htp_tx_set_user_data(htp_tx_t *tx, void *user_data);
1217  void *htp_tx_get_user_data(htp_tx_t *tx);
1218 
1219 // void htp_tx_register_response_body_data(htp_tx_t *tx, int (*callback_fn)(htp_tx_data_t *));
1220 
1221 // Parsing functions
1222 
1224 int htp_parse_request_header_generic(htp_connp_t *connp, htp_header_t *h, unsigned char *data, size_t len);
1226 
1227 int htp_parse_request_header_apache_2_2(htp_connp_t *connp, htp_header_t *h, unsigned char *data, size_t len);
1230 
1232 int htp_parse_response_header_generic(htp_connp_t *connp, htp_header_t *h, char *data, size_t len);
1234 
1235 // Parser states
1236 
1237 int htp_connp_REQ_IDLE(htp_connp_t *connp);
1238 int htp_connp_REQ_LINE(htp_connp_t *connp);
1246 
1249 
1250 int htp_connp_RES_IDLE(htp_connp_t *connp);
1251 int htp_connp_RES_LINE(htp_connp_t *connp);
1258 
1259 // Utility functions
1260 
1262 int htp_is_lws(int c);
1263 int htp_is_separator(int c);
1264 int htp_is_text(int c);
1265 int htp_is_token(int c);
1266 int htp_chomp(unsigned char *data, size_t *len);
1267 int htp_is_space(int c);
1268 
1269 int htp_parse_protocol(bstr *protocol);
1270 
1271 int htp_is_line_empty(unsigned char *data, size_t len);
1272 int htp_is_line_whitespace(unsigned char *data, size_t len);
1273 
1274 int htp_connp_is_line_folded(unsigned char *data, size_t len);
1275 int htp_connp_is_line_terminator(htp_connp_t *connp, unsigned char *data, size_t len);
1276 int htp_connp_is_line_ignorable(htp_connp_t *connp, unsigned char *data, size_t len);
1277 
1278 int htp_parse_uri(bstr *input, htp_uri_t **uri);
1279 int htp_parse_authority(htp_connp_t *connp, bstr *input, htp_uri_t **uri);
1280 int htp_normalize_parsed_uri(htp_connp_t *connp, htp_uri_t *parsed_uri_incomplete, htp_uri_t *parsed_uri);
1282 void htp_replace_hostname(htp_connp_t *connp, htp_uri_t *parsed_uri, bstr *hostname);
1283 int htp_is_uri_unreserved(unsigned char c);
1284 
1285 int htp_decode_path_inplace(htp_cfg_t *cfg, htp_tx_t *tx, bstr *path);
1286 
1288 
1289  int htp_prenormalize_uri_path_inplace(bstr *s, int *flags, int case_insensitive, int backslash, int decode_separators, int remove_consecutive);
1291 
1292 void htp_utf8_decode_path_inplace(htp_cfg_t *cfg, htp_tx_t *tx, bstr *path);
1293 void htp_utf8_validate_path(htp_tx_t *tx, bstr *path);
1294 
1296 int htp_parse_chunked_length(unsigned char *data, size_t len);
1297 int htp_parse_positive_integer_whitespace(unsigned char *data, size_t len, int base);
1298 int htp_parse_status(bstr *status);
1299 int htp_parse_authorization_digest(htp_connp_t *connp, htp_header_t *auth_header);
1300 int htp_parse_authorization_basic(htp_connp_t *connp, htp_header_t *auth_header);
1301 
1302 void htp_log(htp_connp_t *connp, const char *file, int line, int level, int code, const char *fmt, ...);
1303 void htp_print_log(FILE *stream, htp_log_t *log);
1304 
1305 void fprint_bstr(FILE *stream, const char *name, bstr *b);
1306 void fprint_raw_data(FILE *stream, const char *name, unsigned char *data, size_t len);
1307 void fprint_raw_data_ex(FILE *stream, const char *name, unsigned char *data, size_t offset, size_t len);
1308 
1312 
1314 
1316 
1319 
1322 
1323 void htp_tx_register_request_body_data(htp_tx_t *tx, int (*callback_fn)(htp_tx_data_t *));
1324 void htp_tx_register_response_body_data(htp_tx_t *tx, int (*callback_fn)(htp_tx_data_t *));
1325 
1331 
1332 int htp_php_parameter_processor(table_t *params, bstr *name, bstr *value);
1333 
1334 int htp_transcode_params(htp_connp_t *connp, table_t **params, int destroy_old);
1335 int htp_transcode_bstr(iconv_t cd, bstr *input, bstr **output);
1336 
1337 int htp_parse_single_cookie_v0(htp_connp_t *connp, char *data, size_t len);
1338 int htp_parse_cookies_v0(htp_connp_t *connp);
1340 
1341 int htp_decode_urlencoded_inplace(htp_cfg_t *cfg, htp_tx_t *tx, bstr *input);
1342 
1343 bstr *htp_extract_quoted_string_as_bstr(char *data, size_t len, size_t *endoffset);
1344 
1346 int htp_mpartp_parse_header(htp_mpart_part_t *part, unsigned char *data, size_t len);
1347 int htp_mpart_part_handle_data(htp_mpart_part_t *part, unsigned char *data, size_t len, int is_line);
1349 
1350 #ifdef __cplusplus
1351 }
1352 #endif
1353 
1354 #endif /* _HTP_H */
1355 
1356