GNU libmicrohttpd  0.9.65
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), SIZE_MAX)
66 #endif /* MHD_FAVOR_SMALL_CODE */
67 
68 
79 int
80 MHD_str_equal_caseless_n_ (const char * const str1,
81  const char * const str2,
82  size_t maxlen);
83 
84 
94 bool
95 MHD_str_equal_caseless_bin_n_ (const char * const str1,
96  const char * const str2,
97  size_t len);
98 
99 
113 bool
114 MHD_str_has_token_caseless_ (const char * str,
115  const char * const token,
116  size_t token_len);
117 
128 #define MHD_str_has_s_token_caseless_(str,tkn) \
129  MHD_str_has_token_caseless_((str),(tkn),MHD_STATICSTR_LEN_(tkn))
130 
131 #ifndef MHD_FAVOR_SMALL_CODE
132 /* Use individual function for each case to improve speed */
133 
143 size_t
144 MHD_str_to_uint64_ (const char * str,
145  uint64_t * out_val);
146 
159 size_t
160 MHD_str_to_uint64_n_ (const char * str,
161  size_t maxlen,
162  uint64_t * out_val);
163 
164 
174 size_t
175 MHD_strx_to_uint32_ (const char * str,
176  uint32_t * out_val);
177 
178 
191 size_t
192 MHD_strx_to_uint32_n_ (const char * str,
193  size_t maxlen,
194  uint32_t * out_val);
195 
196 
206 size_t
207 MHD_strx_to_uint64_ (const char * str,
208  uint64_t * out_val);
209 
210 
223 size_t
224 MHD_strx_to_uint64_n_ (const char * str,
225  size_t maxlen,
226  uint64_t * out_val);
227 
228 #else /* MHD_FAVOR_SMALL_CODE */
229 /* Use one universal function and macros to reduce size */
230 
247 size_t
248 MHD_str_to_uvalue_n_ (const char * str,
249  size_t maxlen,
250  void * out_val,
251  size_t val_size,
252  uint64_t max_val,
253  int base);
254 
255 #define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
256  sizeof(uint64_t),UINT64_MAX,10)
257 
258 #define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
259  sizeof(uint64_t),UINT64_MAX,10)
260 
261 #define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
262  sizeof(size_t),SIZE_MAX,16)
263 
264 #define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
265  sizeof(size_t),SIZE_MAX,16)
266 
267 #define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
268  sizeof(uint32_t),UINT32_MAX,16)
269 
270 #define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
271  sizeof(uint32_t),UINT32_MAX,16)
272 
273 #define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
274  sizeof(uint64_t),UINT64_MAX,16)
275 
276 #define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
277  sizeof(uint64_t),UINT64_MAX,16)
278 
279 #endif /* MHD_FAVOR_SMALL_CODE */
280 
281 #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:389
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:492
size_t MHD_str_to_uint64_(const char *str, uint64_t *out_val)
Definition: mhd_str.c:450
int MHD_str_equal_caseless_n_(const char *const str1, const char *const str2, size_t maxlen)
Definition: mhd_str.c:359
int MHD_str_equal_caseless_(const char *str1, const char *str2)
Definition: mhd_str.c:329
size_t MHD_strx_to_uint32_n_(const char *str, size_t maxlen, uint32_t *out_val)
Definition: mhd_str.c:581
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
Definition: mhd_str.c:666
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
Definition: mhd_str.c:393
size_t MHD_strx_to_uint64_(const char *str, uint64_t *out_val)
Definition: mhd_str.c:621
size_t MHD_strx_to_uint32_(const char *str, uint32_t *out_val)
Definition: mhd_str.c:535