GNU libmicrohttpd 1.0.1
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-2023 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#include "mhd_str_types.h"
42
43#if defined(_MSC_FULL_VER) && ! defined(_SSIZE_T_DEFINED)
44#define _SSIZE_T_DEFINED
45typedef intptr_t ssize_t;
46#endif /* !_SSIZE_T_DEFINED */
47
48#ifdef MHD_FAVOR_SMALL_CODE
49#include "mhd_limits.h"
50#endif /* MHD_FAVOR_SMALL_CODE */
51
52/*
53 * Block of functions/macros that use US-ASCII charset as required by HTTP
54 * standards. Not affected by current locale settings.
55 */
56
57#ifndef MHD_FAVOR_SMALL_CODE
65int
66MHD_str_equal_caseless_ (const char *str1,
67 const char *str2);
68
69#else /* MHD_FAVOR_SMALL_CODE */
70/* Reuse MHD_str_equal_caseless_n_() to reduce size */
71#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_ ((s1),(s2), \
72 SIZE_MAX)
73#endif /* MHD_FAVOR_SMALL_CODE */
74
75
86int
87MHD_str_equal_caseless_n_ (const char *const str1,
88 const char *const str2,
89 size_t maxlen);
90
91
102bool
103MHD_str_equal_caseless_bin_n_ (const char *const str1,
104 const char *const str2,
105 size_t len);
106
107
122#define MHD_str_equal_caseless_s_bin_n_(a,s,l) \
123 ((MHD_STATICSTR_LEN_(a) == (l)) \
124 && MHD_str_equal_caseless_bin_n_(a,s,l))
125
139bool
140MHD_str_has_token_caseless_ (const char *str,
141 const char *const token,
142 size_t token_len);
143
154#define MHD_str_has_s_token_caseless_(str,tkn) \
155 MHD_str_has_token_caseless_ ((str),(tkn),MHD_STATICSTR_LEN_ (tkn))
156
157
186bool
187MHD_str_remove_token_caseless_ (const char *str,
188 size_t str_len,
189 const char *const token,
190 const size_t token_len,
191 char *buf,
192 ssize_t *buf_size);
193
194
218bool
220 size_t *str_len,
221 const char *const tokens,
222 const size_t tokens_len);
223
224
225#ifndef MHD_FAVOR_SMALL_CODE
226/* Use individual function for each case to improve speed */
227
238size_t
239MHD_str_to_uint64_ (const char *str,
240 uint64_t *out_val);
241
255size_t
256MHD_str_to_uint64_n_ (const char *str,
257 size_t maxlen,
258 uint64_t *out_val);
259
260
271size_t
272MHD_strx_to_uint32_ (const char *str,
273 uint32_t *out_val);
274
275
289size_t
290MHD_strx_to_uint32_n_ (const char *str,
291 size_t maxlen,
292 uint32_t *out_val);
293
294
305size_t
306MHD_strx_to_uint64_ (const char *str,
307 uint64_t *out_val);
308
309
323size_t
324MHD_strx_to_uint64_n_ (const char *str,
325 size_t maxlen,
326 uint64_t *out_val);
327
328#else /* MHD_FAVOR_SMALL_CODE */
329/* Use one universal function and macros to reduce size */
330
348size_t
349MHD_str_to_uvalue_n_ (const char *str,
350 size_t maxlen,
351 void *out_val,
352 size_t val_size,
353 uint64_t max_val,
354 unsigned int base);
355
356#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
357 sizeof(uint64_t), \
358 UINT64_MAX,10)
359
360#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
361 sizeof(uint64_t), \
362 UINT64_MAX,10)
363
364#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
365 sizeof(size_t),SIZE_MAX, \
366 16)
367
368#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
369 sizeof(size_t), \
370 SIZE_MAX,16)
371
372#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
373 sizeof(uint32_t), \
374 UINT32_MAX,16)
375
376#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
377 sizeof(uint32_t), \
378 UINT32_MAX,16)
379
380#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_ ((s),SIZE_MAX,(ov), \
381 sizeof(uint64_t), \
382 UINT64_MAX,16)
383
384#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_ ((s),(ml),(ov), \
385 sizeof(uint64_t), \
386 UINT64_MAX,16)
387
388#endif /* MHD_FAVOR_SMALL_CODE */
389
390
400size_t
401MHD_uint32_to_strx (uint32_t val,
402 char *buf,
403 size_t buf_size);
404
405
406#ifndef MHD_FAVOR_SMALL_CODE
416size_t
417MHD_uint16_to_str (uint16_t val,
418 char *buf,
419 size_t buf_size);
420
421#else /* MHD_FAVOR_SMALL_CODE */
422#define MHD_uint16_to_str(v,b,s) MHD_uint64_to_str(v,b,s)
423#endif /* MHD_FAVOR_SMALL_CODE */
424
425
435size_t
436MHD_uint64_to_str (uint64_t val,
437 char *buf,
438 size_t buf_size);
439
440
456size_t
457MHD_uint8_to_str_pad (uint8_t val,
458 uint8_t min_digits,
459 char *buf,
460 size_t buf_size);
461
462
472size_t
473MHD_bin_to_hex (const void *bin,
474 size_t size,
475 char *hex);
476
486size_t
487MHD_bin_to_hex_z (const void *bin,
488 size_t size,
489 char *hex);
490
504size_t
505MHD_hex_to_bin (const char *hex,
506 size_t len,
507 void *bin);
508
527size_t
528MHD_str_pct_decode_strict_n_ (const char *pct_encoded,
529 size_t pct_encoded_len,
530 char *decoded,
531 size_t buf_size);
532
555size_t
556MHD_str_pct_decode_lenient_n_ (const char *pct_encoded,
557 size_t pct_encoded_len,
558 char *decoded,
559 size_t buf_size,
560 bool *broken_encoding);
561
562
576size_t
578
579
598size_t
600 bool *broken_encoding);
601
602#ifdef DAUTH_SUPPORT
622bool
623MHD_str_equal_quoted_bin_n (const char *quoted,
624 size_t quoted_len,
625 const char *unquoted,
626 size_t unquoted_len);
627
644#define MHD_str_equal_quoted_s_bin_n(q,l,u) \
645 MHD_str_equal_quoted_bin_n(q,l,u,MHD_STATICSTR_LEN_(u))
646
667bool
668MHD_str_equal_caseless_quoted_bin_n (const char *quoted,
669 size_t quoted_len,
670 const char *unquoted,
671 size_t unquoted_len);
672
690#define MHD_str_equal_caseless_quoted_s_bin_n(q,l,u) \
691 MHD_str_equal_caseless_quoted_bin_n(q,l,u,MHD_STATICSTR_LEN_(u))
692
708size_t
709MHD_str_unquote (const char *quoted,
710 size_t quoted_len,
711 char *result);
712
713#endif /* DAUTH_SUPPORT */
714
715#if defined(DAUTH_SUPPORT) || defined(BAUTH_SUPPORT)
716
732size_t
733MHD_str_quote (const char *unquoted,
734 size_t unquoted_len,
735 char *result,
736 size_t buf_size);
737
738#endif /* DAUTH_SUPPORT || BAUTH_SUPPORT */
739
740#ifdef BAUTH_SUPPORT
741
750#define MHD_base64_max_dec_size_(enc_size) (((enc_size) / 4) * 3)
751
769size_t
770MHD_base64_to_bin_n (const char *base64,
771 size_t base64_len,
772 void *bin,
773 size_t bin_size);
774
775#endif /* BAUTH_SUPPORT */
776
777#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
Header for string manipulating helpers types.
limits values definitions
size_t MHD_bin_to_hex(const void *bin, size_t size, char *hex)
Definition mhd_str.c:1676
size_t MHD_str_pct_decode_strict_n_(const char *pct_encoded, size_t pct_encoded_len, char *decoded, size_t buf_size)
Definition mhd_str.c:1746
size_t MHD_bin_to_hex_z(const void *bin, size_t size, char *hex)
Definition mhd_str.c:1696
size_t MHD_uint8_to_str_pad(uint8_t val, uint8_t min_digits, char *buf, size_t buf_size)
Definition mhd_str.c:1629
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:1033
size_t MHD_str_pct_decode_lenient_n_(const char *pct_encoded, size_t pct_encoded_len, char *decoded, size_t buf_size, bool *broken_encoding)
Definition mhd_str.c:1829
size_t MHD_uint16_to_str(uint16_t val, char *buf, size_t buf_size)
Definition mhd_str.c:1550
size_t MHD_str_pct_decode_in_place_lenient_(char *str, bool *broken_encoding)
Definition mhd_str.c:1984
size_t MHD_uint64_to_str(uint64_t val, char *buf, size_t buf_size)
Definition mhd_str.c:1591
size_t MHD_str_pct_decode_in_place_strict_(char *str)
Definition mhd_str.c:1928
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:857
bool MHD_str_equal_caseless_bin_n_(const char *const str1, const char *const str2, size_t len)
Definition mhd_str.c:749
size_t MHD_uint32_to_strx(uint32_t val, char *buf, size_t buf_size)
Definition mhd_str.c:1516
size_t MHD_hex_to_bin(const char *hex, size_t len, void *bin)
Definition mhd_str.c:1710