xref: /php-src/ext/filter/filter_private.h (revision d8fc05c0)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | https://www.php.net/license/3_01.txt                                 |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Authors: Derick Rethans <derick@php.net>                             |
14   +----------------------------------------------------------------------+
15 */
16 
17 #ifndef FILTER_PRIVATE_H
18 #define FILTER_PRIVATE_H
19 
20 #define FILTER_FLAG_NONE                    0x0000
21 
22 #define FILTER_REQUIRE_ARRAY			0x1000000
23 #define FILTER_REQUIRE_SCALAR			0x2000000
24 
25 #define FILTER_FORCE_ARRAY			0x4000000
26 #define FILTER_NULL_ON_FAILURE			0x8000000
27 
28 #define FILTER_FLAG_ALLOW_OCTAL             0x0001
29 #define FILTER_FLAG_ALLOW_HEX               0x0002
30 
31 #define FILTER_FLAG_STRIP_LOW               0x0004
32 #define FILTER_FLAG_STRIP_HIGH              0x0008
33 #define FILTER_FLAG_ENCODE_LOW              0x0010
34 #define FILTER_FLAG_ENCODE_HIGH             0x0020
35 #define FILTER_FLAG_ENCODE_AMP              0x0040
36 #define FILTER_FLAG_NO_ENCODE_QUOTES        0x0080
37 #define FILTER_FLAG_EMPTY_STRING_NULL       0x0100
38 #define FILTER_FLAG_STRIP_BACKTICK          0x0200
39 
40 #define FILTER_FLAG_ALLOW_FRACTION          0x1000
41 #define FILTER_FLAG_ALLOW_THOUSAND          0x2000
42 #define FILTER_FLAG_ALLOW_SCIENTIFIC        0x4000
43 
44 #define FILTER_FLAG_SCHEME_REQUIRED         0x010000
45 #define FILTER_FLAG_HOST_REQUIRED           0x020000
46 #define FILTER_FLAG_PATH_REQUIRED           0x040000
47 #define FILTER_FLAG_QUERY_REQUIRED          0x080000
48 
49 #define FILTER_FLAG_IPV4                    0x00100000
50 #define FILTER_FLAG_IPV6                    0x00200000
51 #define FILTER_FLAG_NO_RES_RANGE            0x00400000
52 #define FILTER_FLAG_NO_PRIV_RANGE           0x00800000
53 #define FILTER_FLAG_GLOBAL_RANGE            0x10000000
54 
55 #define FILTER_FLAG_HOSTNAME               0x100000
56 
57 #define FILTER_FLAG_EMAIL_UNICODE          0x100000
58 
59 #define FILTER_VALIDATE_INT           0x0101
60 #define FILTER_VALIDATE_BOOL          0x0102
61 #define FILTER_VALIDATE_FLOAT         0x0103
62 
63 #define FILTER_VALIDATE_REGEXP        0x0110
64 #define FILTER_VALIDATE_URL           0x0111
65 #define FILTER_VALIDATE_EMAIL         0x0112
66 #define FILTER_VALIDATE_IP            0x0113
67 #define FILTER_VALIDATE_MAC           0x0114
68 #define FILTER_VALIDATE_DOMAIN        0x0115
69 #define FILTER_VALIDATE_LAST          0x0115
70 
71 #define FILTER_VALIDATE_ALL           0x0100
72 
73 #define FILTER_DEFAULT                0x0204
74 #define FILTER_UNSAFE_RAW             0x0204
75 
76 #define FILTER_SANITIZE_STRING        0x0201
77 #define FILTER_SANITIZE_ENCODED       0x0202
78 #define FILTER_SANITIZE_SPECIAL_CHARS 0x0203
79 #define FILTER_SANITIZE_EMAIL         0x0205
80 #define FILTER_SANITIZE_URL           0x0206
81 #define FILTER_SANITIZE_NUMBER_INT    0x0207
82 #define FILTER_SANITIZE_NUMBER_FLOAT  0x0208
83 #define FILTER_SANITIZE_FULL_SPECIAL_CHARS 0x020a
84 #define FILTER_SANITIZE_ADD_SLASHES   0x020b
85 #define FILTER_SANITIZE_LAST          0x020b
86 
87 #define FILTER_SANITIZE_ALL           0x0200
88 
89 #define FILTER_CALLBACK               0x0400
90 
91 #define PHP_FILTER_ID_EXISTS(id) \
92 ((id >= FILTER_SANITIZE_ALL && id <= FILTER_SANITIZE_LAST) \
93 || (id >= FILTER_VALIDATE_ALL && id <= FILTER_VALIDATE_LAST) \
94 || id == FILTER_CALLBACK)
95 
96 #define RETURN_VALIDATION_FAILED \
97 	if (EG(exception)) { \
98 		return; \
99 	} else if (flags & FILTER_NULL_ON_FAILURE) { \
100 		zval_ptr_dtor(value); \
101 		ZVAL_NULL(value); \
102 	} else { \
103 		zval_ptr_dtor(value); \
104 		ZVAL_FALSE(value); \
105 	}	\
106 	return;	\
107 
108 #define PHP_FILTER_TRIM_DEFAULT(p, len) PHP_FILTER_TRIM_DEFAULT_EX(p, len, 1);
109 
110 #define PHP_FILTER_TRIM_DEFAULT_EX(p, len, return_if_empty) { \
111 	while ((len > 0)  && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\v' || *p == '\n')) { \
112 		p++; \
113 		len--; \
114 	} \
115 	if (len < 1 && return_if_empty) { \
116 		RETURN_VALIDATION_FAILED \
117 	} \
118 	if (len > 0) { \
119 		while (p[len-1] == ' ' || p[len-1] == '\t' || p[len-1] == '\r' || p[len-1] == '\v' || p[len-1] == '\n') { \
120 			len--; \
121 		} \
122 	} \
123 }
124 
125 #endif /* FILTER_PRIVATE_H */
126