GNU libmicrohttpd  0.9.68
mhd_str.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2015, 2016 Karlson2k (Evgeny Grin)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
26 #ifndef MHD_STR_H
27 #define MHD_STR_H 1
28 
29 #include "mhd_options.h"
30 
31 #include <stdint.h>
32 #include <stddef.h>
33 #ifdef HAVE_STDBOOL_H
34 #include <stdbool.h>
35 #endif /* HAVE_STDBOOL_H */
36 
37 #ifdef MHD_FAVOR_SMALL_CODE
38 #include "mhd_limits.h"
39 #endif /* MHD_FAVOR_SMALL_CODE */
40 
41 #ifndef MHD_STATICSTR_LEN_
42 
45 #define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
46 #endif /* ! MHD_STATICSTR_LEN_ */
47 
48 /*
49  * Block of functions/macros that use US-ASCII charset as required by HTTP
50  * standards. Not affected by current locale settings.
51  */
52 
53 #ifndef MHD_FAVOR_SMALL_CODE
54 
60 int
61 MHD_str_equal_caseless_ (const char *str1,
62  const char *str2);
63 #else /* MHD_FAVOR_SMALL_CODE */
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), \
66  SIZE_MAX)
67 #endif /* MHD_FAVOR_SMALL_CODE */
68 
69 
80 int
81 MHD_str_equal_caseless_n_ (const char *const str1,
82  const char *const str2,
83  size_t maxlen);
84 
85 
95 bool
96 MHD_str_equal_caseless_bin_n_ (const char *const str1,
97  const char *const str2,
98  size_t len);
99 
100 
114 bool
115 MHD_str_has_token_caseless_ (const char *str,
116  const char *const token,
117  size_t token_len);
118 
129 #define MHD_str_has_s_token_caseless_(str,tkn) \
130  MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
131 
132 #ifndef MHD_FAVOR_SMALL_CODE
133 /* Use individual function for each case to improve speed */
134 
144 size_t
145 MHD_str_to_uint64_ (const char *str,
146  uint64_t *out_val);
147 
160 size_t
161 MHD_str_to_uint64_n_ (const char *str,
162  size_t maxlen,
163  uint64_t *out_val);
164 
165 
175 size_t
176 MHD_strx_to_uint32_ (const char *str,
177  uint32_t *out_val);
178 
179 
192 size_t
193 MHD_strx_to_uint32_n_ (const char *str,
194  size_t maxlen,
195  uint32_t *out_val);
196 
197 
207 size_t
208 MHD_strx_to_uint64_ (const char *str,
209  uint64_t *out_val);
210 
211 
224 size_t
225 MHD_strx_to_uint64_n_ (const char *str,
226  size_t maxlen,
227  uint64_t *out_val);
228 
229 #else /* MHD_FAVOR_SMALL_CODE */
230 /* Use one universal function and macros to reduce size */
231 
248 size_t
249 MHD_str_to_uvalue_n_ (const char *str,
250  size_t maxlen,
251  void *out_val,
252  size_t val_size,
253  uint64_t max_val,
254  int base);
255 
256 #define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
257  sizeof(uint64_t), \
258  UINT64_MAX,10)
259 
260 #define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
261  sizeof(uint64_t), \
262  UINT64_MAX,10)
263 
264 #define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
265  sizeof(size_t),SIZE_MAX, \
266  16)
267 
268 #define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
269  sizeof(size_t), \
270  SIZE_MAX,16)
271 
272 #define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
273  sizeof(uint32_t), \
274  UINT32_MAX,16)
275 
276 #define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
277  sizeof(uint32_t), \
278  UINT32_MAX,16)
279 
280 #define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
281  sizeof(uint64_t), \
282  UINT64_MAX,16)
283 
284 #define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
285  sizeof(uint64_t), \
286  UINT64_MAX,16)
287 
288 #endif /* MHD_FAVOR_SMALL_CODE */
289 
290 #endif /* MHD_STR_H */
bool MHD_str_equal_caseless_bin_n_(const char *const str1, const char *const str2, size_t len)
Definition: mhd_str.c:393
additional automatic macros for MHD_config.h
size_t MHD_str_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
Definition: mhd_str.c:499
size_t MHD_str_to_uint64_(const char *str, uint64_t *out_val)
Definition: mhd_str.c:457
int MHD_str_equal_caseless_n_(const char *const str1, const char *const str2, size_t maxlen)
Definition: mhd_str.c:363
int MHD_str_equal_caseless_(const char *str1, const char *str2)
Definition: mhd_str.c:333
size_t MHD_strx_to_uint32_n_(const char *str, size_t maxlen, uint32_t *out_val)
Definition: mhd_str.c:589
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
Definition: mhd_str.c:676
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
Definition: mhd_str.c:397
size_t MHD_strx_to_uint64_(const char *str, uint64_t *out_val)
Definition: mhd_str.c:630
size_t MHD_strx_to_uint32_(const char *str, uint32_t *out_val)
Definition: mhd_str.c:542