HTP 0.5
htp_core.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
38
39#ifndef HTP_CORE_H
40#define HTP_CORE_H
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/* Define SCAN_BUILD_X64_PADDING to add padding to structs for
47 * when clang scan-build is used with the optin.performance.Padding
48 * checker. */
49#if defined(__clang_analyzer__)
51#ifndef __WORDSIZE
52 #ifdef __LONG_BIT
53 #define __WORDSIZE __LONG_BIT
54 #else
55 #ifdef LONG_BIT
56 #define __WORDSIZE LONG_BIT
57 #endif
58 #endif
59#endif
60
62#ifndef __WORDSIZE
63 #if defined(__X86__) || defined(_X86_) || defined(_M_IX86)
64 #define __WORDSIZE 32
65 #else
66 #if defined(__X86_64__) || defined(_X86_64_) || \
67 defined(__x86_64) || defined(__x86_64__) || \
68 defined(__amd64) || defined(__amd64__)
69 #define __WORDSIZE 64
70 #endif
71 #endif
72#endif
73
75#ifndef __WORDSIZE
76 #if defined(_ILP32) || defined(__ILP32__)
77 #define __WORDSIZE 32
78 #endif
79 #if defined(_LP64) || defined(__LP64__)
80 #define __WORDSIZE 64
81 #endif
82#endif
83
84#ifndef __WORDSIZE
85 #define __WORDSIZE 64
86#endif
87
88#if __WORDSIZE==64
89#define SCAN_BUILD_X64_PADDING(x) x
90#else
91#define SCAN_BUILD_X64_PADDING(_x)
92#endif
93#else /* else __clang_analyzer__ */
94#define SCAN_BUILD_X64_PADDING(_x)
95#endif /* end __clang_analyzer__ */
96
97typedef int htp_status_t;
98
99typedef struct htp_cfg_t htp_cfg_t;
100typedef struct htp_conn_t htp_conn_t;
102typedef struct htp_file_t htp_file_t;
106typedef struct htp_log_t htp_log_t;
109typedef struct htp_tx_t htp_tx_t;
110typedef struct htp_uri_t htp_uri_t;
111typedef struct timeval htp_time_t;
112
113// Below are all htp_status_t return codes used by LibHTP. Enum is not
114// used here to allow applications to define their own codes.
115
119#define HTP_ERROR_RESERVED -1000
120
122#define HTP_ERROR -1
123
129#define HTP_DECLINED 0
130
132#define HTP_OK 1
133
138#define HTP_DATA 2
139
150#define HTP_DATA_OTHER 3
151
157#define HTP_STOP 4
158
163#define HTP_DATA_BUFFER 5
164
168#define HTP_STATUS_RESERVED 1000
169
196
220
240
247
248// Various flag bits. Even though we have a flag field in several places
249// (header, transaction, connection), these fields are all in the same namespace
250// because we may want to set the same flag in several locations. For example, we
251// may set HTP_FIELD_FOLDED on the actual folded header, but also on the transaction
252// that contains the header. Both uses are useful.
253
254// Connection flags are 8 bits wide.
255#define HTP_CONN_PIPELINED 0x000000001ULL
256#define HTP_CONN_HTTP_0_9_EXTRA 0x000000002ULL
257
258// All other flags are 64 bits wide.
259#define HTP_FIELD_UNPARSEABLE 0x000000004ULL
260#define HTP_FIELD_INVALID 0x000000008ULL
261#define HTP_FIELD_FOLDED 0x000000010ULL
262#define HTP_FIELD_REPEATED 0x000000020ULL
263#define HTP_FIELD_LONG 0x000000040ULL
264#define HTP_FIELD_RAW_NUL 0x000000080ULL
265#define HTP_REQUEST_SMUGGLING 0x000000100ULL
266#define HTP_INVALID_FOLDING 0x000000200ULL
267#define HTP_REQUEST_INVALID_T_E 0x000000400ULL
268#define HTP_MULTI_PACKET_HEAD 0x000000800ULL
269#define HTP_HOST_MISSING 0x000001000ULL
270#define HTP_HOST_AMBIGUOUS 0x000002000ULL
271#define HTP_PATH_ENCODED_NUL 0x000004000ULL
272#define HTP_PATH_RAW_NUL 0x000008000ULL
273#define HTP_PATH_INVALID_ENCODING 0x000010000ULL
274#define HTP_PATH_INVALID 0x000020000ULL
275#define HTP_PATH_OVERLONG_U 0x000040000ULL
276#define HTP_PATH_ENCODED_SEPARATOR 0x000080000ULL
277#define HTP_PATH_UTF8_VALID 0x000100000ULL /* At least one valid UTF-8 character and no invalid ones. */
278#define HTP_PATH_UTF8_INVALID 0x000200000ULL
279#define HTP_PATH_UTF8_OVERLONG 0x000400000ULL
280#define HTP_PATH_HALF_FULL_RANGE 0x000800000ULL /* Range U+FF00 - U+FFEF detected. */
281#define HTP_STATUS_LINE_INVALID 0x001000000ULL
282#define HTP_HOSTU_INVALID 0x002000000ULL /* Host in the URI. */
283#define HTP_HOSTH_INVALID 0x004000000ULL /* Host in the Host header. */
284#define HTP_URLEN_ENCODED_NUL 0x008000000ULL
285#define HTP_URLEN_INVALID_ENCODING 0x010000000ULL
286#define HTP_URLEN_OVERLONG_U 0x020000000ULL
287#define HTP_URLEN_HALF_FULL_RANGE 0x040000000ULL /* Range U+FF00 - U+FFEF detected. */
288#define HTP_URLEN_RAW_NUL 0x080000000ULL
289#define HTP_REQUEST_INVALID 0x100000000ULL
290#define HTP_REQUEST_INVALID_C_L 0x200000000ULL
291#define HTP_AUTH_INVALID 0x400000000ULL
292#define HTP_HEADERS_TOO_MANY 0x800000000ULL
293
294#define HTP_MAX_HEADERS_REPETITIONS 64
295
296#define HTP_HOST_INVALID ( HTP_HOSTU_INVALID | HTP_HOSTH_INVALID )
297
298// Logging-related constants.
299#define HTP_LOG_MARK __FILE__,__LINE__
300
313
352
353// A collection of unique parser IDs.
361
362// Protocol version constants; an enum cannot be
363// used here because we allow any properly-formatted protocol
364// version (e.g., 1.3), even those that do not actually exist.
365#define HTP_PROTOCOL_INVALID -2
366#define HTP_PROTOCOL_UNKNOWN -1
367#define HTP_PROTOCOL_0_9 9
368#define HTP_PROTOCOL_1_0 100
369#define HTP_PROTOCOL_1_1 101
370
371// A collection of possible data sources.
385
386#define HTP_STATUS_INVALID -1
387#define HTP_STATUS_UNKNOWN 0
388
403
404#ifdef __cplusplus
405}
406#endif
407
408#endif /* HTP_CORE_H */
htp_auth_type_t
Definition htp_core.h:173
@ HTP_AUTH_DIGEST
Definition htp_core.h:188
@ HTP_AUTH_BEARER
Definition htp_core.h:191
@ HTP_AUTH_UNRECOGNIZED
Definition htp_core.h:194
@ HTP_AUTH_BASIC
Definition htp_core.h:185
@ HTP_AUTH_NONE
Definition htp_core.h:182
@ HTP_AUTH_UNKNOWN
Definition htp_core.h:179
struct timeval htp_time_t
Definition htp_core.h:111
htp_data_source_t
Definition htp_core.h:372
@ HTP_SOURCE_QUERY_STRING
Definition htp_core.h:377
@ HTP_SOURCE_URL
Definition htp_core.h:374
@ HTP_SOURCE_BODY
Definition htp_core.h:383
@ HTP_SOURCE_COOKIE
Definition htp_core.h:380
htp_content_encoding_t
Definition htp_core.h:197
@ HTP_COMPRESSION_OVER
Definition htp_core.h:218
@ HTP_COMPRESSION_DEFLATE
Definition htp_core.h:212
@ HTP_COMPRESSION_LZMA
Definition htp_core.h:215
@ HTP_COMPRESSION_GZIP
Definition htp_core.h:209
@ HTP_COMPRESSION_NONE
Definition htp_core.h:206
@ HTP_COMPRESSION_UNKNOWN
Definition htp_core.h:203
htp_method_t
Definition htp_core.h:317
@ HTP_M_GET
Definition htp_core.h:324
@ HTP_M_COPY
Definition htp_core.h:335
@ HTP_M_MKACTIVITY
Definition htp_core.h:347
@ HTP_M_TRACE
Definition htp_core.h:330
@ HTP_M_CHECKOUT
Definition htp_core.h:340
@ HTP_M_CHECKIN
Definition htp_core.h:342
@ HTP_M_HEAD
Definition htp_core.h:323
@ HTP_M_CONNECT
Definition htp_core.h:328
@ HTP_M_PROPFIND
Definition htp_core.h:332
@ HTP_M_POST
Definition htp_core.h:326
@ HTP_M_INVALID
Definition htp_core.h:350
@ HTP_M_PUT
Definition htp_core.h:325
@ HTP_M_REPORT
Definition htp_core.h:345
@ HTP_M_OPTIONS
Definition htp_core.h:329
@ HTP_M_UNCHECKOUT
Definition htp_core.h:341
@ HTP_M_UNKNOWN
Definition htp_core.h:322
@ HTP_M_LABEL
Definition htp_core.h:344
@ HTP_M_PATCH
Definition htp_core.h:331
@ HTP_M_BASELINE_CONTROL
Definition htp_core.h:348
@ HTP_M_PROPPATCH
Definition htp_core.h:333
@ HTP_M_UPDATE
Definition htp_core.h:343
@ HTP_M_UNLOCK
Definition htp_core.h:338
@ HTP_M_MKWORKSPACE
Definition htp_core.h:346
@ HTP_M_MERGE
Definition htp_core.h:349
@ HTP_M_MOVE
Definition htp_core.h:336
@ HTP_M_MKCOL
Definition htp_core.h:334
@ HTP_M_LOCK
Definition htp_core.h:337
@ HTP_M_DELETE
Definition htp_core.h:327
@ HTP_M_VERSION_CONTROL
Definition htp_core.h:339
htp_file_source_t
Definition htp_core.h:241
@ HTP_FILE_MULTIPART
Definition htp_core.h:243
@ HTP_FILE_PUT
Definition htp_core.h:245
struct htp_header_line_t htp_header_line_t
Definition htp_core.h:105
int htp_status_t
Definition htp_core.h:97
htp_parser_id_t
Definition htp_core.h:354
@ HTP_PARSER_URLENCODED
Definition htp_core.h:356
@ HTP_PARSER_MULTIPART
Definition htp_core.h:359
htp_transfer_coding_t
Definition htp_core.h:224
@ HTP_CODING_INVALID
Definition htp_core.h:238
@ HTP_CODING_IDENTITY
Definition htp_core.h:232
@ HTP_CODING_CHUNKED
Definition htp_core.h:235
@ HTP_CODING_UNKNOWN
Definition htp_core.h:226
@ HTP_CODING_NO_BODY
Definition htp_core.h:229
htp_stream_state_t
Definition htp_core.h:393
@ HTP_STREAM_CLOSED
Definition htp_core.h:396
@ HTP_STREAM_TUNNEL
Definition htp_core.h:398
@ HTP_STREAM_STOP
Definition htp_core.h:400
@ HTP_STREAM_DATA_OTHER
Definition htp_core.h:399
@ HTP_STREAM_OPEN
Definition htp_core.h:395
@ HTP_STREAM_DATA
Definition htp_core.h:401
@ HTP_STREAM_NEW
Definition htp_core.h:394
@ HTP_STREAM_ERROR
Definition htp_core.h:397
htp_log_level_t
Definition htp_core.h:304
@ HTP_LOG_INFO
Definition htp_core.h:309
@ HTP_LOG_NONE
Definition htp_core.h:305
@ HTP_LOG_NOTICE
Definition htp_core.h:308
@ HTP_LOG_DEBUG
Definition htp_core.h:310
@ HTP_LOG_ERROR
Definition htp_core.h:306
@ HTP_LOG_DEBUG2
Definition htp_core.h:311
@ HTP_LOG_WARNING
Definition htp_core.h:307
Definition htp_config_private.h:123
Definition htp.h:67
Definition htp_connection_parser_private.h:51
Definition htp.h:131
Definition htp.h:111
Definition htp.h:171
Definition htp.h:145
Definition htp.h:185
Definition htp.h:563
Definition htp.h:208
Definition htp.h:587