diff options
author | Frank Berghaus <berghaus@cern.ch> | 2022-09-21 16:50:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-21 16:50:17 (GMT) |
commit | 100b22e6c23c44a082fd69b8c05a63c7492083f7 (patch) | |
tree | 744a5409278b46f62765dfe23345d0b6a3c66dfb /src/H5system.c | |
parent | d491c33a72c9e6cabe10a7508c1cc76c1d638479 (diff) | |
download | hdf5-100b22e6c23c44a082fd69b8c05a63c7492083f7.zip hdf5-100b22e6c23c44a082fd69b8c05a63c7492083f7.tar.gz hdf5-100b22e6c23c44a082fd69b8c05a63c7492083f7.tar.bz2 |
Use case-insensitive comparison for headers fix #2100 (#2101)
* Use case-inseneitive comparison for headers
HTTP headers should be case-insensitive. Use case-insensitive string
comparisons when working with HTTP header responses to ensure
compatibility.
* Revert "Use case-inseneitive comparison for headers"
This reverts commit a02f591723506b62b7208449be6eef7122120398
* Ignore case when searching HTTP header responses
Looking up the Content-Length in the header returned by S3 storage
endpoints should ignore case. To guarantee portability implement a
function for case-insensitive string search, because it is non-standard.
* Add an _ after H5 for the strcasestr implementation
It is a private function and should sport that underscore.
* Remove author comment from the doc comment
* Use search function defined by system if available
Check whether the system provides a function implementing case
insensitive string searches. Only use the custom implementation if the
system does not provide the functionality.
* Add tests for case-insensitive search
Basic tests:
- Search for empty string
- Search with exact match
- Search with case-insensitive match
- search with no match
* Enforce clang-format style
Some variable definitions in the th5_system tests did not conform to
clang-format's expectations. Updated the offending lines.
* Correct comment describing test case
* Added some spaces to please clang-format
* Ignore discarding const
Ask the compiler to ignore discarding the const when retunring a match from H5_strcasestr
Co-authored-by: Frank Berghaus <frank.berghaus@mpcdf.mpg.de>
Diffstat (limited to 'src/H5system.c')
-rw-r--r-- | src/H5system.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/H5system.c b/src/H5system.c index 9a19860..a7f2edd 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -1350,3 +1350,42 @@ H5_get_option(int argc, const char *const *argv, const char *opts, const struct /* return the current flag character found */ return optchar; } + +/*------------------------------------------------------------------------- + * Function: H5_strcasestr + * + * Purpose: Find the first occurrence of the substring needle in the + * string haystack ignoring case. + * + * Return: Success: Pointer to the beginning of the located substring + * + * Failure: NULL + * + *------------------------------------------------------------------------- + */ +char * +H5_strcasestr(const char *haystack, const char *needle) +{ + /* Check arguments. */ + HDassert(haystack); + HDassert(needle); + + /* begin once from each character of haystack, until needle is found */ + do { + const char *h = haystack; + const char *n = needle; + /* loop while lowercase strings match, or needle ends */ + while (HDtolower(*h) == HDtolower(*n) && *n) { + h++; + n++; + } + /* if all characters in needle matched we found it */ + if (*n == 0) { + /* must discard const qualifier here, so turn off the warning */ + H5_GCC_CLANG_DIAG_OFF("cast-qual") + return (char *)haystack; + H5_GCC_CLANG_DIAG_ON("cast-qual") + } + } while (*haystack++); + return 0; +} /* end H5_strcasestr() */ |