GNU libmicrohttpd  0.9.72
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_
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
60 int
61 MHD_str_equal_caseless_ (const char *str1,
62  const char *str2);
63 
64 #else /* MHD_FAVOR_SMALL_CODE */
65 /* Reuse MHD_str_equal_caseless_n_() to reduce size */
66 #define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_ ((s1),(s2), \
67  SIZE_MAX)
68 #endif /* MHD_FAVOR_SMALL_CODE */
69 
70 
81 int
82 MHD_str_equal_caseless_n_ (const char *const str1,
83  const char *const str2,
84  size_t maxlen);
85 
86 
100 bool
101 MHD_str_has_token_caseless_ (const char *str,
102  const char *const token,
103  size_t token_len);
104 
115 #define MHD_str_has_s_token_caseless_(str,tkn) \
116  MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
117 
118 #ifndef MHD_FAVOR_SMALL_CODE
119 /* Use individual function for each case to improve speed */
120 
130 size_t
131 MHD_str_to_uint64_ (const char *str,
132  uint64_t *out_val);
133 
146 size_t
147 MHD_str_to_uint64_n_ (const char *str,
148  size_t maxlen,
149  uint64_t *out_val);
150 
151 
161 size_t
162 MHD_strx_to_uint32_ (const char *str,
163  uint32_t *out_val);
164 
165 
178 size_t
179 MHD_strx_to_uint32_n_ (const char *str,
180  size_t maxlen,
181  uint32_t *out_val);
182 
183 
193 size_t
194 MHD_strx_to_uint64_ (const char *str,
195  uint64_t *out_val);
196 
197 
210 size_t
211 MHD_strx_to_uint64_n_ (const char *str,
212  size_t maxlen,
213  uint64_t *out_val);
214 
215 #else /* MHD_FAVOR_SMALL_CODE */
216 /* Use one universal function and macros to reduce size */
217 
234 size_t
235 MHD_str_to_uvalue_n_ (const char *str,
236  size_t maxlen,
237  void *out_val,
238  size_t val_size,
239  uint64_t max_val,
240  int base);
241 
242 #define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
243  sizeof(uint64_t), \
244  UINT64_MAX,10)
245 
246 #define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
247  sizeof(uint64_t), \
248  UINT64_MAX,10)
249 
250 #define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
251  sizeof(size_t),SIZE_MAX, \
252  16)
253 
254 #define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
255  sizeof(size_t), \
256  SIZE_MAX,16)
257 
258 #define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
259  sizeof(uint32_t), \
260  UINT32_MAX,16)
261 
262 #define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
263  sizeof(uint32_t), \
264  UINT32_MAX,16)
265 
266 #define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
267  sizeof(uint64_t), \
268  UINT64_MAX,16)
269 
270 #define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
271  sizeof(uint64_t), \
272  UINT64_MAX,16)
273 
274 #endif /* MHD_FAVOR_SMALL_CODE */
275 
276 #endif /* MHD_STR_H */
int MHD_str_equal_caseless_(const char *str1, const char *str2)
Definition: mhd_str.c:346
size_t MHD_strx_to_uint32_(const char *str, uint32_t *out_val)
Definition: mhd_str.c:558
size_t MHD_str_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
Definition: mhd_str.c:515
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
Definition: mhd_str.c:692
int MHD_str_equal_caseless_n_(const char *const str1, const char *const str2, size_t maxlen)
Definition: mhd_str.c:378
size_t MHD_str_to_uint64_(const char *str, uint64_t *out_val)
Definition: mhd_str.c:473
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
Definition: mhd_str.c:412
size_t MHD_strx_to_uint64_(const char *str, uint64_t *out_val)
Definition: mhd_str.c:646
size_t MHD_strx_to_uint32_n_(const char *str, size_t maxlen, uint32_t *out_val)
Definition: mhd_str.c:605
additional automatic macros for MHD_config.h