aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_str.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_str.h')
-rw-r--r--src/microhttpd/mhd_str.h69
1 files changed, 68 insertions, 1 deletions
diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h
index c0649a2f..880970ca 100644
--- a/src/microhttpd/mhd_str.h
+++ b/src/microhttpd/mhd_str.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 Copyright (C) 2015 Karlson2k (Evgeny Grin) 3 Copyright (C) 2015, 2016 Karlson2k (Evgeny Grin)
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
@@ -26,14 +26,21 @@
26#ifndef MHD_STR_H 26#ifndef MHD_STR_H
27#define MHD_STR_H 1 27#define MHD_STR_H 1
28 28
29#include "mhd_options.h"
30
29#include <stdint.h> 31#include <stdint.h>
30#include <stdlib.h> 32#include <stdlib.h>
31 33
34#ifdef MHD_FAVOR_SMALL_CODE
35#include "mhd_limits.h"
36#endif /* MHD_FAVOR_SMALL_CODE */
37
32/* 38/*
33 * Block of functions/macros that use US-ASCII charset as required by HTTP 39 * Block of functions/macros that use US-ASCII charset as required by HTTP
34 * standards. Not affected by current locale settings. 40 * standards. Not affected by current locale settings.
35 */ 41 */
36 42
43#ifndef MHD_FAVOR_SMALL_CODE
37/** 44/**
38 * Check two string for equality, ignoring case of US-ASCII letters. 45 * Check two string for equality, ignoring case of US-ASCII letters.
39 * @param str1 first string to compare 46 * @param str1 first string to compare
@@ -43,6 +50,10 @@
43int 50int
44MHD_str_equal_caseless_ (const char * str1, 51MHD_str_equal_caseless_ (const char * str1,
45 const char * str2); 52 const char * str2);
53#else /* MHD_FAVOR_SMALL_CODE */
54/* Reuse MHD_str_equal_caseless_n_() to reduce size */
55#define MHD_str_equal_caseless_(s1,s2) MHD_str_equal_caseless_n_((s1),(s2), SIZE_MAX)
56#endif /* MHD_FAVOR_SMALL_CODE */
46 57
47 58
48/** 59/**
@@ -60,6 +71,9 @@ MHD_str_equal_caseless_n_ (const char * const str1,
60 const char * const str2, 71 const char * const str2,
61 size_t maxlen); 72 size_t maxlen);
62 73
74#ifndef MHD_FAVOR_SMALL_CODE
75/* Use individual function for each case to improve speed */
76
63/** 77/**
64 * Convert decimal US-ASCII digits in string to number in uint64_t. 78 * Convert decimal US-ASCII digits in string to number in uint64_t.
65 * Conversion stopped at first non-digit character. 79 * Conversion stopped at first non-digit character.
@@ -186,4 +200,57 @@ MHD_strx_to_uint64_n_ (const char * str,
186 size_t maxlen, 200 size_t maxlen,
187 uint64_t * out_val); 201 uint64_t * out_val);
188 202
203#else /* MHD_FAVOR_SMALL_CODE */
204/* Use one universal function and macros to reduce size */
205
206/**
207 * Generic function for converting not more then @a maxlen
208 * hexadecimal or decimal US-ASCII digits in string to number.
209 * Conversion stopped at first non-digit character or after @a maxlen
210 * digits.
211 * To be used only within macro.
212 * @param str the string to convert
213 * @param maxlen the maximum number of characters to process
214 * @param out_val the pointer to uint64_t to store result of conversion
215 * @param val_size the size of variable pointed by @a out_val
216 * @param max_val the maximum decoded number
217 * @param base the numeric base, 10 or 16
218 * @return non-zero number of characters processed on succeed,
219 * zero if no digit is found, resulting value is larger
220 * then @ max_val or @a out_val is NULL
221 */
222size_t
223MHD_str_to_uvalue_n_ (const char * str,
224 size_t maxlen,
225 void * out_val,
226 size_t val_size,
227 uint64_t max_val,
228 int base);
229
230#define MHD_str_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
231 sizeof(uint64_t),UINT64_MAX,10)
232
233#define MHD_str_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
234 sizeof(uint64_t),UINT64_MAX,10)
235
236#define MHD_strx_to_sizet_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
237 sizeof(size_t),SIZE_MAX,16)
238
239#define MHD_strx_to_sizet_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
240 sizeof(size_t),SIZE_MAX,16)
241
242#define MHD_strx_to_uint32_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
243 sizeof(uint32_t),UINT32_MAX,16)
244
245#define MHD_strx_to_uint32_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
246 sizeof(uint32_t),UINT32_MAX,16)
247
248#define MHD_strx_to_uint64_(s,ov) MHD_str_to_uvalue_n_((s),SIZE_MAX,(ov),\
249 sizeof(uint64_t),UINT64_MAX,16)
250
251#define MHD_strx_to_uint64_n_(s,ml,ov) MHD_str_to_uvalue_n_((s),(ml),(ov),\
252 sizeof(uint64_t),UINT64_MAX,16)
253
254#endif /* MHD_FAVOR_SMALL_CODE */
255
189#endif /* MHD_STR_H */ 256#endif /* MHD_STR_H */