GNU libmicrohttpd 1.0.1
|
Functions implementations for string manipulating. More...
Go to the source code of this file.
Macros | |
#define | isasciilower(c) (((char) (c)) >= 'a' && ((char) (c)) <= 'z') |
#define | isasciiupper(c) (((char) (c)) >= 'A' && ((char) (c)) <= 'Z') |
#define | isasciialpha(c) (isasciilower (c) || isasciiupper (c)) |
#define | isasciidigit(c) (((char) (c)) >= '0' && ((char) (c)) <= '9') |
#define | isasciixdigit(c) |
#define | isasciialnum(c) (isasciialpha (c) || isasciidigit (c)) |
#define | toasciilower(c) |
#define | toasciiupper(c) |
#define | todigitvalue(c) |
#define | toxdigitvalue(c) |
#define | charsequalcaseless(c1, c2) |
Functions implementations for string manipulating.
Definition in file mhd_str.c.
Caseless compare two characters.
c1 | the first char to compare |
c2 | the second char to compare |
Definition at line 665 of file mhd_str.c.
Referenced by MHD_str_equal_caseless_(), MHD_str_equal_caseless_bin_n_(), MHD_str_equal_caseless_n_(), MHD_str_has_token_caseless_(), and MHD_str_remove_token_caseless_().
#define isasciialnum | ( | c | ) | (isasciialpha (c) || isasciidigit (c)) |
#define isasciialpha | ( | c | ) | (isasciilower (c) || isasciiupper (c)) |
Check whether character is hexadecimal digit in US-ASCII
c | character to check |
Convert US-ASCII character to lower case. If character is upper case letter in US-ASCII than it's converted to lower case analog. If character is NOT upper case letter than it's returned unmodified.
c | character to convert |
Convert US-ASCII character to upper case. If character is lower case letter in US-ASCII than it's converted to upper case analog. If character is NOT lower case letter than it's returned unmodified.
c | character to convert |
Convert US-ASCII hexadecimal digit to its value.
c | character to convert |
Convert size bytes from input binary data to lower case hexadecimal digits. Result is NOT zero-terminated
bin | the pointer to the binary data to convert | |
size | the size in bytes of the binary data to convert | |
[out] | hex | the output buffer, should be at least 2 * size |
Definition at line 1676 of file mhd_str.c.
References MHD_HTTP_OK.
Referenced by calculate_nonce(), digest_auth_check_all_inner(), and MHD_bin_to_hex_z().
Convert size bytes from input binary data to lower case hexadecimal digits, zero-terminate the result.
bin | the pointer to the binary data to convert | |
size | the size in bytes of the binary data to convert | |
[out] | hex | the output buffer, should be at least 2 * size + 1 |
Definition at line 1696 of file mhd_str.c.
References MHD_bin_to_hex(), and MHD_HTTP_OK.
Referenced by MHD_digest_auth_calc_userhash_hex().
Convert hexadecimal digits to binary data.
The input decoded byte-by-byte (each byte is two hexadecimal digits). If length is an odd number, extra leading zero is assumed.
hex | the input string with hexadecimal digits | |
len | the length of the input string | |
[out] | bin | the output buffer, must be at least len/2 bytes long (or len/2 + 1 if len is not even number) |
Definition at line 1710 of file mhd_str.c.
References mhd_assert, MHD_HTTP_OK, and toxdigitvalue.
Referenced by digest_auth_check_all_inner(), and get_rq_uname().
Check two strings for equality, ignoring case of US-ASCII letters.
str1 | first string to compare |
str2 | second string to compare |
Definition at line 683 of file mhd_str.c.
References charsequalcaseless, and MHD_HTTP_OK.
Check two string for equality, ignoring case of US-ASCII letters and checking not more than len bytes. Compares not more first than len bytes, including binary zero characters. Comparison stops at first unmatched byte.
str1 | first string to compare |
str2 | second string to compare |
len | number of characters to compare |
Definition at line 749 of file mhd_str.c.
References charsequalcaseless, and MHD_HTTP_OK.
Referenced by add_user_headers(), find_auth_rq_header_(), get_no_space_err_status_code(), get_rq_extended_uname_copy_z(), MHD_check_response_header_token_ci(), MHD_del_response_header(), MHD_get_response_element_n_(), MHD_get_response_header(), MHD_lookup_connection_value_n(), MHD_lookup_header_token_ci(), and MHD_str_remove_tokens_caseless_().
Check two string for equality, ignoring case of US-ASCII letters and checking not more than maxlen characters. Compares up to first terminating null character, but not more than first maxlen characters.
str1 | first string to compare |
str2 | second string to compare |
maxlen | maximum number of characters to compare |
Definition at line 717 of file mhd_str.c.
References charsequalcaseless, and MHD_HTTP_OK.
Check whether str has case-insensitive token. Token could be surrounded by spaces and tabs and delimited by comma. Match succeed if substring between start, end (of string) or comma contains only case-insensitive token and optional spaces and tabs.
str | the string to check |
token | the token to find |
token_len | length of token, not including optional terminating null-character. |
Definition at line 782 of file mhd_str.c.
References charsequalcaseless, and MHD_HTTP_OK.
Decode string in-place with percent-encoded characters as defined by RFC 3986 section-2.1.
This function decode string by converting percent-encoded characters to their decoded versions and copying back all other characters without extra processing.
Any invalid percent-encoding sequences ('' symbol not followed by two valid hexadecimal digits) are copied to the output string without decoding.
[in,out] | str | the string to be updated in-place, must be zero-terminated on input, the output is zero-terminated |
[out] | broken_encoding | will be set to true if any '' symbol is not followed by two valid hexadecimal digits, optional, can be NULL |
Definition at line 1984 of file mhd_str.c.
References MHD_HTTP_OK, MHD_str_pct_decode_lenient_n_(), NULL, and toxdigitvalue.
Referenced by MHD_http_unescape(), MHD_str_pct_decode_in_place_strict_(), and unescape_wrapper().
Decode string in-place with percent-encoded characters as defined by RFC 3986 section-2.1.
This function decode string by converting percent-encoded characters to their decoded versions and copying back all other characters without extra processing.
[in,out] | str | the string to be updated in-place, must be zero-terminated on input, the output is zero-terminated; the string is truncated to zero length if broken encoding is found |
Definition at line 1928 of file mhd_str.c.
References MHD_HTTP_OK, MHD_str_pct_decode_in_place_lenient_(), and toxdigitvalue.
Referenced by unescape_wrapper().
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 ) |
Decode string with percent-encoded characters as defined by RFC 3986 section-2.1.
This function decode string by converting percent-encoded characters to their decoded versions and copying all other characters without extra processing.
Any invalid percent-encoding sequences ('' symbol not followed by two valid hexadecimal digits) are copied to the output string without decoding.
pct_encoded | the input string to be decoded | |
pct_encoded_len | the length of the pct_encoded | |
[out] | decoded | the output buffer, NOT zero-terminated, can point to the same buffer as pct_encoded |
buf_size | the size of the output buffer | |
[out] | broken_encoding | will be set to true if any '' symbol is not followed by two valid hexadecimal digits, optional, can be NULL |
Definition at line 1829 of file mhd_str.c.
References MHD_HTTP_OK, NULL, and toxdigitvalue.
Referenced by MHD_str_pct_decode_in_place_lenient_(), and MHD_str_pct_decode_strict_n_().
size_t MHD_str_pct_decode_strict_n_ | ( | const char * | pct_encoded, |
size_t | pct_encoded_len, | ||
char * | decoded, | ||
size_t | buf_size ) |
Decode string with percent-encoded characters as defined by RFC 3986 section-2.1.
This function decode string by converting percent-encoded characters to their decoded versions and copying all other characters without extra processing.
pct_encoded | the input string to be decoded | |
pct_encoded_len | the length of the pct_encoded | |
[out] | decoded | the output buffer, NOT zero-terminated, can point to the same buffer as pct_encoded |
buf_size | the size of the output buffer |
Definition at line 1746 of file mhd_str.c.
References MHD_HTTP_OK, MHD_str_pct_decode_lenient_n_(), and toxdigitvalue.
Referenced by get_rq_extended_uname_copy_z().
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 ) |
Remove case-insensitive token from the str and put result to the output buf.
Tokens in str could be surrounded by spaces and tabs and delimited by comma. The token match succeed if substring between start, end (of string) or comma contains only case-insensitive token and optional spaces and tabs. The quoted strings and comments are not supported by this function.
The output string is normalised: empty tokens and repeated whitespaces are removed, no whitespaces before commas, exactly one space is used after each comma.
str | the string to process | |
str_len | the length of the str, not including optional terminating null-character. | |
token | the token to find | |
token_len | the length of token, not including optional terminating null-character. | |
[out] | buf | the output buffer, not null-terminated. |
[in,out] | buf_size | pointer to the size variable, at input it is the size of allocated buffer, at output it is the size of the resulting string (can be up to 50% larger than input) or negative value if there is not enough space for the result |
< the "input" string / character
< the "output" string / character
< position of matched character in the token
< the first char of current token
Definition at line 857 of file mhd_str.c.
References charsequalcaseless, mhd_assert, MHD_HTTP_OK, NULL, and SSIZE_MAX.
Referenced by add_response_header_connection().
bool MHD_str_remove_tokens_caseless_ | ( | char * | str, |
size_t * | str_len, | ||
const char *const | tokens, | ||
const size_t | tokens_len ) |
Perform in-place case-insensitive removal of tokens from the str.
Token could be surrounded by spaces and tabs and delimited by comma. The token match succeed if substring between start, end (of the string), or comma contains only case-insensitive token and optional spaces and tabs. The quoted strings and comments are not supported by this function.
The input string must be normalised: empty tokens and repeated whitespaces are removed, no whitespaces before commas, exactly one space is used after each comma. The string is updated in-place.
Behavior is undefined is the input string in not normalised.
[in,out] | str | the string to update |
[in,out] | str_len | the length of the str, not including optional terminating null-character, not null-terminated |
tokens | the token to find | |
tokens_len | the length of tokens, not including optional terminating null-character. |
< a short alias for tokens
< position in tokens
< the current token
< the 'read' position in the str
< the 'write' position in the str
Definition at line 1033 of file mhd_str.c.
References mhd_assert, MHD_HTTP_OK, MHD_str_equal_caseless_bin_n_(), and NULL.
Referenced by add_response_header_connection(), and del_response_header_connection().
Convert decimal US-ASCII digits in string to number in uint64_t. Conversion stopped at first non-digit character.
str | string to convert | |
[out] | out_val | pointer to uint64_t to store result of conversion |
Definition at line 1196 of file mhd_str.c.
References isasciidigit, MHD_HTTP_OK, and UINT64_MAX.
Convert not more then maxlen decimal US-ASCII digits in string to number in uint64_t. Conversion stopped at first non-digit character or after maxlen digits.
str | string to convert | |
maxlen | maximum number of characters to process | |
[out] | out_val | pointer to uint64_t to store result of conversion |
Definition at line 1238 of file mhd_str.c.
References isasciidigit, MHD_HTTP_OK, and UINT64_MAX.
Convert hexadecimal US-ASCII digits in string to number in uint32_t. Conversion stopped at first non-digit character.
str | string to convert | |
[out] | out_val | pointer to uint32_t to store result of conversion |
Definition at line 1281 of file mhd_str.c.
References MHD_HTTP_OK, toxdigitvalue, and UINT32_MAX.
Convert not more then maxlen hexadecimal US-ASCII digits in string to number in uint32_t. Conversion stopped at first non-digit character or after maxlen digits.
str | string to convert | |
maxlen | maximum number of characters to process | |
[out] | out_val | pointer to uint32_t to store result of conversion |
Definition at line 1328 of file mhd_str.c.
References MHD_HTTP_OK, toxdigitvalue, and UINT32_MAX.
Convert hexadecimal US-ASCII digits in string to number in uint64_t. Conversion stopped at first non-digit character.
str | string to convert | |
[out] | out_val | pointer to uint64_t to store result of conversion |
Definition at line 1369 of file mhd_str.c.
References MHD_HTTP_OK, toxdigitvalue, and UINT64_MAX.
Convert not more then maxlen hexadecimal US-ASCII digits in string to number in uint64_t. Conversion stopped at first non-digit character or after maxlen digits.
str | string to convert | |
maxlen | maximum number of characters to process | |
[out] | out_val | pointer to uint64_t to store result of conversion |
Definition at line 1415 of file mhd_str.c.
References MHD_HTTP_OK, toxdigitvalue, and UINT64_MAX.
Convert uint16_t value to decimal US-ASCII string.
val | the value to convert |
buf | the buffer to result to |
buf_size | size of the buffer |
< pointer to the current printed digit
Definition at line 1550 of file mhd_str.c.
References mhd_assert, and MHD_HTTP_OK.
Referenced by build_header_response(), and get_date_str().
Convert uint32_t value to hexdecimal US-ASCII string.
val | the value to convert |
buf | the buffer to result to |
buf_size | size of the buffer |
< position of the output character
zero-based, digit position in 'val'
Definition at line 1516 of file mhd_str.c.
References MHD_HTTP_OK.
Referenced by try_ready_chunked_body().
Convert uint64_t value to decimal US-ASCII string.
val | the value to convert |
buf | the buffer to result to |
buf_size | size of the buffer |
< pointer to the current printed digit
Definition at line 1591 of file mhd_str.c.
References mhd_assert, and MHD_HTTP_OK.
Referenced by build_header_response().
Convert uint16_t value to decimal US-ASCII string padded with zeros on the left side.
val | the value to convert |
min_digits | the minimal number of digits to print, output padded with zeros on the left side, 'zero' value is interpreted as 'one', valid values are 3, 2, 1, 0 |
buf | the buffer to result to |
buf_size | size of the buffer |
< the position of the current printed digit
Definition at line 1629 of file mhd_str.c.
References mhd_assert, and MHD_HTTP_OK.
Referenced by get_date_str().