GNU libmicrohttpd  0.9.29
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), 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 
98 bool
99 MHD_str_has_token_caseless_ (const char * str,
100  const char * const token,
101  size_t token_len);
102 
113 #define MHD_str_has_s_token_caseless_(str,tkn) \
114  MHD_str_has_token_caseless_((str),(tkn),MHD_STATICSTR_LEN_(tkn))
115 
116 #ifndef MHD_FAVOR_SMALL_CODE
117 /* Use individual function for each case to improve speed */
118 
128 size_t
129 MHD_str_to_uint64_ (const char * str,
130  uint64_t * out_val);
131 
144 size_t
145 MHD_str_to_uint64_n_ (const char * str,
146  size_t maxlen,
147  uint64_t * out_val);
148 
149 
159 size_t
160 MHD_strx_to_uint32_ (const char * str,
161  uint32_t * out_val);
162 
163 
176 size_t
177 MHD_strx_to_uint32_n_ (const char * str,
178  size_t maxlen,
179  uint32_t * out_val);
180 
181 
191 size_t
192 MHD_strx_to_uint64_ (const char * str,
193  uint64_t * out_val);
194 
195 
208 size_t
209 MHD_strx_to_uint64_n_ (const char * str,
210  size_t maxlen,
211  uint64_t * out_val);
212 
213 #else /* MHD_FAVOR_SMALL_CODE */
214 /* Use one universal function and macros to reduce size */
215 
232 size_t
233 MHD_str_to_uvalue_n_ (const char * str,
234  size_t maxlen,
235  void * out_val,
236  size_t val_size,
237  uint64_t max_val,
238  int base);
239 
240 #define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
241  sizeof(uint64_t),UINT64_MAX,10)
242 
243 #define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
244  sizeof(uint64_t),UINT64_MAX,10)
245 
246 #define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
247  sizeof(size_t),SIZE_MAX,16)
248 
249 #define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
250  sizeof(size_t),SIZE_MAX,16)
251 
252 #define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
253  sizeof(uint32_t),UINT32_MAX,16)
254 
255 #define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
256  sizeof(uint32_t),UINT32_MAX,16)
257 
258 #define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
259  sizeof(uint64_t),UINT64_MAX,16)
260 
261 #define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
262  sizeof(uint64_t),UINT64_MAX,16)
263 
264 #endif /* MHD_FAVOR_SMALL_CODE */
265 
266 #endif /* MHD_STR_H */
additional automatic macros for MHD_config.h
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
Definition: mhd_str.c:383
int MHD_str_equal_caseless_(const char *str1, const char *str2)
Definition: mhd_str.c:319
size_t MHD_strx_to_uint64_(const char *str, uint64_t *out_val)
Definition: mhd_str.c:611
int MHD_str_equal_caseless_n_(const char *const str1, const char *const str2, size_t maxlen)
Definition: mhd_str.c:349
size_t MHD_str_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
Definition: mhd_str.c:482
limits values definitions
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
Definition: mhd_str.c:656
size_t MHD_str_to_uint64_(const char *str, uint64_t *out_val)
Definition: mhd_str.c:440
size_t MHD_strx_to_uint32_n_(const char *str, size_t maxlen, uint32_t *out_val)
Definition: mhd_str.c:571
size_t MHD_strx_to_uint32_(const char *str, uint32_t *out_val)
Definition: mhd_str.c:525