GNU libmicrohttpd 0.9.71
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_
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
60int
61MHD_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
81int
82MHD_str_equal_caseless_n_ (const char *const str1,
83 const char *const str2,
84 size_t maxlen);
85
86
96bool
97MHD_str_equal_caseless_bin_n_ (const char *const str1,
98 const char *const str2,
99 size_t len);
100
101
115bool
116MHD_str_has_token_caseless_ (const char *str,
117 const char *const token,
118 size_t token_len);
119
130#define MHD_str_has_s_token_caseless_(str,tkn) \
131 MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
132
133#ifndef MHD_FAVOR_SMALL_CODE
134/* Use individual function for each case to improve speed */
135
145size_t
146MHD_str_to_uint64_ (const char *str,
147 uint64_t *out_val);
148
161size_t
162MHD_str_to_uint64_n_ (const char *str,
163 size_t maxlen,
164 uint64_t *out_val);
165
166
176size_t
177MHD_strx_to_uint32_ (const char *str,
178 uint32_t *out_val);
179
180
193size_t
194MHD_strx_to_uint32_n_ (const char *str,
195 size_t maxlen,
196 uint32_t *out_val);
197
198
208size_t
209MHD_strx_to_uint64_ (const char *str,
210 uint64_t *out_val);
211
212
225size_t
226MHD_strx_to_uint64_n_ (const char *str,
227 size_t maxlen,
228 uint64_t *out_val);
229
230#else /* MHD_FAVOR_SMALL_CODE */
231/* Use one universal function and macros to reduce size */
232
249size_t
250MHD_str_to_uvalue_n_ (const char *str,
251 size_t maxlen,
252 void *out_val,
253 size_t val_size,
254 uint64_t max_val,
255 int base);
256
257#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
258 sizeof(uint64_t), \
259 UINT64_MAX,10)
260
261#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
262 sizeof(uint64_t), \
263 UINT64_MAX,10)
264
265#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
266 sizeof(size_t),SIZE_MAX, \
267 16)
268
269#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
270 sizeof(size_t), \
271 SIZE_MAX,16)
272
273#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
274 sizeof(uint32_t), \
275 UINT32_MAX,16)
276
277#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
278 sizeof(uint32_t), \
279 UINT32_MAX,16)
280
281#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
282 sizeof(uint64_t), \
283 UINT64_MAX,16)
284
285#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
286 sizeof(uint64_t), \
287 UINT64_MAX,16)
288
289#endif /* MHD_FAVOR_SMALL_CODE */
290
291#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
bool MHD_str_equal_caseless_bin_n_(const char *const str1, const char *const str2, size_t len)
Definition: mhd_str.c:408