GNU libmicrohttpd 0.9.77
Loading...
Searching...
No Matches
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#include <stdint.h>
31#ifdef HAVE_STDDEF_H
32#include <stddef.h>
33#endif /* HAVE_STDDEF_H */
34#ifdef HAVE_SYS_TYPES_H
35#include <sys/types.h>
36#endif /* HAVE_SYS_TYPES_H */
37#ifdef HAVE_STDBOOL_H
38#include <stdbool.h>
39#endif /* HAVE_STDBOOL_H */
40
41#if defined(_MSC_FULL_VER) && ! defined(_SSIZE_T_DEFINED)
42#define _SSIZE_T_DEFINED
43typedef intptr_t ssize_t;
44#endif /* !_SSIZE_T_DEFINED */
45
46#ifdef MHD_FAVOR_SMALL_CODE
47#include "mhd_limits.h"
48#endif /* MHD_FAVOR_SMALL_CODE */
49
50#ifndef MHD_STATICSTR_LEN_
54#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1)
55#endif /* ! MHD_STATICSTR_LEN_ */
56
58{
59 const char *str;
60 const size_t len;
61};
62
66#define _MHD_S_STR_W_LEN(str) { str, MHD_STATICSTR_LEN_(str) }
67
68
69/*
70 * Block of functions/macros that use US-ASCII charset as required by HTTP
71 * standards. Not affected by current locale settings.
72 */
73
74#ifndef MHD_FAVOR_SMALL_CODE
81int
82MHD_str_equal_caseless_ (const char *str1,
83 const char *str2);
84
85#else /* MHD_FAVOR_SMALL_CODE */
86/* Reuse MHD_str_equal_caseless_n_() to reduce size */
87#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_ ((s1),(s2), \
88 SIZE_MAX)
89#endif /* MHD_FAVOR_SMALL_CODE */
90
91
102int
103MHD_str_equal_caseless_n_ (const char *const str1,
104 const char *const str2,
105 size_t maxlen);
106
107
117bool
118MHD_str_equal_caseless_bin_n_ (const char *const str1,
119 const char *const str2,
120 size_t len);
121
122
136bool
137MHD_str_has_token_caseless_ (const char *str,
138 const char *const token,
139 size_t token_len);
140
151#define MHD_str_has_s_token_caseless_(str,tkn) \
152 MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
153
154
183bool
184MHD_str_remove_token_caseless_ (const char *str,
185 size_t str_len,
186 const char *const token,
187 const size_t token_len,
188 char *buf,
189 ssize_t *buf_size);
190
191
215bool
217 size_t *str_len,
218 const char *const tokens,
219 const size_t tokens_len);
220
221
222#ifndef MHD_FAVOR_SMALL_CODE
223/* Use individual function for each case to improve speed */
224
234size_t
235MHD_str_to_uint64_ (const char *str,
236 uint64_t *out_val);
237
250size_t
251MHD_str_to_uint64_n_ (const char *str,
252 size_t maxlen,
253 uint64_t *out_val);
254
255
265size_t
266MHD_strx_to_uint32_ (const char *str,
267 uint32_t *out_val);
268
269
282size_t
283MHD_strx_to_uint32_n_ (const char *str,
284 size_t maxlen,
285 uint32_t *out_val);
286
287
297size_t
298MHD_strx_to_uint64_ (const char *str,
299 uint64_t *out_val);
300
301
314size_t
315MHD_strx_to_uint64_n_ (const char *str,
316 size_t maxlen,
317 uint64_t *out_val);
318
319#else /* MHD_FAVOR_SMALL_CODE */
320/* Use one universal function and macros to reduce size */
321
338size_t
339MHD_str_to_uvalue_n_ (const char *str,
340 size_t maxlen,
341 void *out_val,
342 size_t val_size,
343 uint64_t max_val,
344 unsigned int base);
345
346#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
347 sizeof(uint64_t), \
348 UINT64_MAX,10)
349
350#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
351 sizeof(uint64_t), \
352 UINT64_MAX,10)
353
354#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
355 sizeof(size_t),SIZE_MAX, \
356 16)
357
358#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
359 sizeof(size_t), \
360 SIZE_MAX,16)
361
362#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
363 sizeof(uint32_t), \
364 UINT32_MAX,16)
365
366#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
367 sizeof(uint32_t), \
368 UINT32_MAX,16)
369
370#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
371 sizeof(uint64_t), \
372 UINT64_MAX,16)
373
374#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
375 sizeof(uint64_t), \
376 UINT64_MAX,16)
377
378#endif /* MHD_FAVOR_SMALL_CODE */
379
380
390size_t
391MHD_uint32_to_strx (uint32_t val,
392 char *buf,
393 size_t buf_size);
394
395
396#ifndef MHD_FAVOR_SMALL_CODE
406size_t
407MHD_uint16_to_str (uint16_t val,
408 char *buf,
409 size_t buf_size);
410
411#else /* MHD_FAVOR_SMALL_CODE */
412#define MHD_uint16_to_str(v,b,s) MHD_uint64_to_str(v,b,s)
413#endif /* MHD_FAVOR_SMALL_CODE */
414
415
425size_t
426MHD_uint64_to_str (uint64_t val,
427 char *buf,
428 size_t buf_size);
429
430
446size_t
447MHD_uint8_to_str_pad (uint8_t val,
448 uint8_t min_digits,
449 char *buf,
450 size_t buf_size);
451
452
453#ifdef BAUTH_SUPPORT
454
463#define MHD_base64_max_dec_size_(enc_size) (((enc_size) / 4) * 3)
464
482size_t
483MHD_base64_to_bin_n (const char *base64,
484 size_t base64_len,
485 void *bin,
486 size_t bin_size);
487
488#endif /* BAUTH_SUPPORT */
489
490#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
size_t MHD_uint8_to_str_pad(uint8_t val, uint8_t min_digits, char *buf, size_t buf_size)
Definition mhd_str.c:1313
bool MHD_str_remove_tokens_caseless_(char *str, size_t *str_len, const char *const tokens, const size_t tokens_len)
Definition mhd_str.c:720
size_t MHD_uint16_to_str(uint16_t val, char *buf, size_t buf_size)
Definition mhd_str.c:1234
size_t MHD_uint64_to_str(uint64_t val, char *buf, size_t buf_size)
Definition mhd_str.c:1275
bool MHD_str_remove_token_caseless_(const char *str, size_t str_len, const char *const token, const size_t token_len, char *buf, ssize_t *buf_size)
Definition mhd_str.c:553
bool MHD_str_equal_caseless_bin_n_(const char *const str1, const char *const str2, size_t len)
Definition mhd_str.c:445
size_t MHD_uint32_to_strx(uint32_t val, char *buf, size_t buf_size)
Definition mhd_str.c:1202
const size_t len
Definition mhd_str.h:60
const char * str
Definition mhd_str.h:59