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 <stdlib.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 
99 bool
100 MHD_str_has_token_caseless_ (const char *str,
101  const char *const token,
102  size_t token_len);
103 
114 #define MHD_str_has_s_token_caseless_(str,tkn) \
115  MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
116 
117 #ifndef MHD_FAVOR_SMALL_CODE
118 /* Use individual function for each case to improve speed */
119 
129 size_t
130 MHD_str_to_uint64_ (const char *str,
131  uint64_t *out_val);
132 
145 size_t
146 MHD_str_to_uint64_n_ (const char *str,
147  size_t maxlen,
148  uint64_t *out_val);
149 
150 
160 size_t
161 MHD_strx_to_uint32_ (const char *str,
162  uint32_t *out_val);
163 
164 
177 size_t
178 MHD_strx_to_uint32_n_ (const char *str,
179  size_t maxlen,
180  uint32_t *out_val);
181 
182 
192 size_t
193 MHD_strx_to_uint64_ (const char *str,
194  uint64_t *out_val);
195 
196 
209 size_t
210 MHD_strx_to_uint64_n_ (const char *str,
211  size_t maxlen,
212  uint64_t *out_val);
213 
214 #else /* MHD_FAVOR_SMALL_CODE */
215 /* Use one universal function and macros to reduce size */
216 
233 size_t
234 MHD_str_to_uvalue_n_ (const char *str,
235  size_t maxlen,
236  void *out_val,
237  size_t val_size,
238  uint64_t max_val,
239  int base);
240 
241 #define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
242  sizeof(uint64_t), \
243  UINT64_MAX,10)
244 
245 #define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
246  sizeof(uint64_t), \
247  UINT64_MAX,10)
248 
249 #define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
250  sizeof(size_t),SIZE_MAX, \
251  16)
252 
253 #define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
254  sizeof(size_t), \
255  SIZE_MAX,16)
256 
257 #define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
258  sizeof(uint32_t), \
259  UINT32_MAX,16)
260 
261 #define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
262  sizeof(uint32_t), \
263  UINT32_MAX,16)
264 
265 #define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
266  sizeof(uint64_t), \
267  UINT64_MAX,16)
268 
269 #define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
270  sizeof(uint64_t), \
271  UINT64_MAX,16)
272 
273 #endif /* MHD_FAVOR_SMALL_CODE */
274 
275 #endif /* MHD_STR_H */
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