aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_str.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_str.h')
-rw-r--r--src/microhttpd/mhd_str.h109
1 files changed, 59 insertions, 50 deletions
diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h
index 5c0e0fdc..dd379f52 100644
--- a/src/microhttpd/mhd_str.h
+++ b/src/microhttpd/mhd_str.h
@@ -42,7 +42,7 @@
42/** 42/**
43 * Determine length of static string / macro strings at compile time. 43 * Determine length of static string / macro strings at compile time.
44 */ 44 */
45#define MHD_STATICSTR_LEN_(macro) (sizeof(macro)/sizeof(char) - 1) 45#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
46#endif /* ! MHD_STATICSTR_LEN_ */ 46#endif /* ! MHD_STATICSTR_LEN_ */
47 47
48/* 48/*
@@ -58,11 +58,12 @@
58 * @return non-zero if two strings are equal, zero otherwise. 58 * @return non-zero if two strings are equal, zero otherwise.
59 */ 59 */
60int 60int
61MHD_str_equal_caseless_ (const char * str1, 61MHD_str_equal_caseless_ (const char *str1,
62 const char * str2); 62 const char *str2);
63#else /* MHD_FAVOR_SMALL_CODE */ 63#else /* MHD_FAVOR_SMALL_CODE */
64/* Reuse MHD_str_equal_caseless_n_() to reduce size */ 64/* Reuse MHD_str_equal_caseless_n_() to reduce size */
65#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_((s1),(s2), SIZE_MAX) 65#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_ ((s1),(s2), \
66 SIZE_MAX)
66#endif /* MHD_FAVOR_SMALL_CODE */ 67#endif /* MHD_FAVOR_SMALL_CODE */
67 68
68 69
@@ -77,9 +78,9 @@ MHD_str_equal_caseless_ (const char * str1,
77 * @return non-zero if two strings are equal, zero otherwise. 78 * @return non-zero if two strings are equal, zero otherwise.
78 */ 79 */
79int 80int
80MHD_str_equal_caseless_n_ (const char * const str1, 81MHD_str_equal_caseless_n_ (const char *const str1,
81 const char * const str2, 82 const char *const str2,
82 size_t maxlen); 83 size_t maxlen);
83 84
84 85
85/** 86/**
@@ -92,9 +93,9 @@ MHD_str_equal_caseless_n_ (const char * const str1,
92 * @return non-zero if two strings are equal, zero otherwise. 93 * @return non-zero if two strings are equal, zero otherwise.
93 */ 94 */
94bool 95bool
95MHD_str_equal_caseless_bin_n_ (const char * const str1, 96MHD_str_equal_caseless_bin_n_ (const char *const str1,
96 const char * const str2, 97 const char *const str2,
97 size_t len); 98 size_t len);
98 99
99 100
100/** 101/**
@@ -111,8 +112,8 @@ MHD_str_equal_caseless_bin_n_ (const char * const str1,
111 * @return non-zero if two strings are equal, zero otherwise. 112 * @return non-zero if two strings are equal, zero otherwise.
112 */ 113 */
113bool 114bool
114MHD_str_has_token_caseless_ (const char * str, 115MHD_str_has_token_caseless_ (const char *str,
115 const char * const token, 116 const char *const token,
116 size_t token_len); 117 size_t token_len);
117 118
118/** 119/**
@@ -126,7 +127,7 @@ MHD_str_has_token_caseless_ (const char * str,
126 * @return non-zero if two strings are equal, zero otherwise. 127 * @return non-zero if two strings are equal, zero otherwise.
127 */ 128 */
128#define MHD_str_has_s_token_caseless_(str,tkn) \ 129#define MHD_str_has_s_token_caseless_(str,tkn) \
129 MHD_str_has_token_caseless_((str),(tkn),MHD_STATICSTR_LEN_(tkn)) 130 MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
130 131
131#ifndef MHD_FAVOR_SMALL_CODE 132#ifndef MHD_FAVOR_SMALL_CODE
132/* Use individual function for each case to improve speed */ 133/* Use individual function for each case to improve speed */
@@ -141,13 +142,13 @@ MHD_str_has_token_caseless_ (const char * str,
141 * then possible to store in uint64_t or @a out_val is NULL 142 * then possible to store in uint64_t or @a out_val is NULL
142 */ 143 */
143size_t 144size_t
144MHD_str_to_uint64_ (const char * str, 145MHD_str_to_uint64_ (const char *str,
145 uint64_t * out_val); 146 uint64_t *out_val);
146 147
147/** 148/**
148 * Convert not more then @a maxlen decimal US-ASCII digits in string to 149 * Convert not more then @a maxlen decimal US-ASCII digits in string to
149 * number in uint64_t. 150 * number in uint64_t.
150 * Conversion stopped at first non-digit character or after @a maxlen 151 * Conversion stopped at first non-digit character or after @a maxlen
151 * digits. 152 * digits.
152 * @param str string to convert 153 * @param str string to convert
153 * @param maxlen maximum number of characters to process 154 * @param maxlen maximum number of characters to process
@@ -157,9 +158,9 @@ MHD_str_to_uint64_ (const char * str,
157 * then possible to store in uint64_t or @a out_val is NULL 158 * then possible to store in uint64_t or @a out_val is NULL
158 */ 159 */
159size_t 160size_t
160MHD_str_to_uint64_n_ (const char * str, 161MHD_str_to_uint64_n_ (const char *str,
161 size_t maxlen, 162 size_t maxlen,
162 uint64_t * out_val); 163 uint64_t *out_val);
163 164
164 165
165/** 166/**
@@ -167,19 +168,19 @@ MHD_str_to_uint64_n_ (const char * str,
167 * Conversion stopped at first non-digit character. 168 * Conversion stopped at first non-digit character.
168 * @param str string to convert 169 * @param str string to convert
169 * @param out_val pointer to uint32_t to store result of conversion 170 * @param out_val pointer to uint32_t to store result of conversion
170 * @return non-zero number of characters processed on succeed, 171 * @return non-zero number of characters processed on succeed,
171 * zero if no digit is found, resulting value is larger 172 * zero if no digit is found, resulting value is larger
172 * then possible to store in uint32_t or @a out_val is NULL 173 * then possible to store in uint32_t or @a out_val is NULL
173 */ 174 */
174size_t 175size_t
175MHD_strx_to_uint32_ (const char * str, 176MHD_strx_to_uint32_ (const char *str,
176 uint32_t * out_val); 177 uint32_t *out_val);
177 178
178 179
179/** 180/**
180 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 181 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
181 * to number in uint32_t. 182 * to number in uint32_t.
182 * Conversion stopped at first non-digit character or after @a maxlen 183 * Conversion stopped at first non-digit character or after @a maxlen
183 * digits. 184 * digits.
184 * @param str string to convert 185 * @param str string to convert
185 * @param maxlen maximum number of characters to process 186 * @param maxlen maximum number of characters to process
@@ -189,9 +190,9 @@ MHD_strx_to_uint32_ (const char * str,
189 * then possible to store in uint32_t or @a out_val is NULL 190 * then possible to store in uint32_t or @a out_val is NULL
190 */ 191 */
191size_t 192size_t
192MHD_strx_to_uint32_n_ (const char * str, 193MHD_strx_to_uint32_n_ (const char *str,
193 size_t maxlen, 194 size_t maxlen,
194 uint32_t * out_val); 195 uint32_t *out_val);
195 196
196 197
197/** 198/**
@@ -199,19 +200,19 @@ MHD_strx_to_uint32_n_ (const char * str,
199 * Conversion stopped at first non-digit character. 200 * Conversion stopped at first non-digit character.
200 * @param str string to convert 201 * @param str string to convert
201 * @param out_val pointer to uint64_t to store result of conversion 202 * @param out_val pointer to uint64_t to store result of conversion
202 * @return non-zero number of characters processed on succeed, 203 * @return non-zero number of characters processed on succeed,
203 * zero if no digit is found, resulting value is larger 204 * zero if no digit is found, resulting value is larger
204 * then possible to store in uint64_t or @a out_val is NULL 205 * then possible to store in uint64_t or @a out_val is NULL
205 */ 206 */
206size_t 207size_t
207MHD_strx_to_uint64_ (const char * str, 208MHD_strx_to_uint64_ (const char *str,
208 uint64_t * out_val); 209 uint64_t *out_val);
209 210
210 211
211/** 212/**
212 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string 213 * Convert not more then @a maxlen hexadecimal US-ASCII digits in string
213 * to number in uint64_t. 214 * to number in uint64_t.
214 * Conversion stopped at first non-digit character or after @a maxlen 215 * Conversion stopped at first non-digit character or after @a maxlen
215 * digits. 216 * digits.
216 * @param str string to convert 217 * @param str string to convert
217 * @param maxlen maximum number of characters to process 218 * @param maxlen maximum number of characters to process
@@ -221,9 +222,9 @@ MHD_strx_to_uint64_ (const char * str,
221 * then possible to store in uint64_t or @a out_val is NULL 222 * then possible to store in uint64_t or @a out_val is NULL
222 */ 223 */
223size_t 224size_t
224MHD_strx_to_uint64_n_ (const char * str, 225MHD_strx_to_uint64_n_ (const char *str,
225 size_t maxlen, 226 size_t maxlen,
226 uint64_t * out_val); 227 uint64_t *out_val);
227 228
228#else /* MHD_FAVOR_SMALL_CODE */ 229#else /* MHD_FAVOR_SMALL_CODE */
229/* Use one universal function and macros to reduce size */ 230/* Use one universal function and macros to reduce size */
@@ -231,7 +232,7 @@ MHD_strx_to_uint64_n_ (const char * str,
231/** 232/**
232 * Generic function for converting not more then @a maxlen 233 * Generic function for converting not more then @a maxlen
233 * hexadecimal or decimal US-ASCII digits in string to number. 234 * hexadecimal or decimal US-ASCII digits in string to number.
234 * Conversion stopped at first non-digit character or after @a maxlen 235 * Conversion stopped at first non-digit character or after @a maxlen
235 * digits. 236 * digits.
236 * To be used only within macro. 237 * To be used only within macro.
237 * @param str the string to convert 238 * @param str the string to convert
@@ -245,36 +246,44 @@ MHD_strx_to_uint64_n_ (const char * str,
245 * then @ max_val or @a out_val is NULL 246 * then @ max_val or @a out_val is NULL
246 */ 247 */
247size_t 248size_t
248MHD_str_to_uvalue_n_ (const char * str, 249MHD_str_to_uvalue_n_ (const char *str,
249 size_t maxlen, 250 size_t maxlen,
250 void * out_val, 251 void *out_val,
251 size_t val_size, 252 size_t val_size,
252 uint64_t max_val, 253 uint64_t max_val,
253 int base); 254 int base);
254 255
255#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 256#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
256 sizeof(uint64_t),UINT64_MAX,10) 257 sizeof(uint64_t), \
258 UINT64_MAX,10)
257 259
258#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 260#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
259 sizeof(uint64_t),UINT64_MAX,10) 261 sizeof(uint64_t), \
262 UINT64_MAX,10)
260 263
261#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 264#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
262 sizeof(size_t),SIZE_MAX,16) 265 sizeof(size_t),SIZE_MAX, \
266 16)
263 267
264#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 268#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
265 sizeof(size_t),SIZE_MAX,16) 269 sizeof(size_t), \
270 SIZE_MAX,16)
266 271
267#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 272#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
268 sizeof(uint32_t),UINT32_MAX,16) 273 sizeof(uint32_t), \
274 UINT32_MAX,16)
269 275
270#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 276#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
271 sizeof(uint32_t),UINT32_MAX,16) 277 sizeof(uint32_t), \
278 UINT32_MAX,16)
272 279
273#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\ 280#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
274 sizeof(uint64_t),UINT64_MAX,16) 281 sizeof(uint64_t), \
282 UINT64_MAX,16)
275 283
276#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\ 284#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
277 sizeof(uint64_t),UINT64_MAX,16) 285 sizeof(uint64_t), \
286 UINT64_MAX,16)
278 287
279#endif /* MHD_FAVOR_SMALL_CODE */ 288#endif /* MHD_FAVOR_SMALL_CODE */
280 289