Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/candidate-9.4.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Dec 7, 2023
2 parents d1d5219 + 38b96e9 commit 97476ca
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
10 changes: 5 additions & 5 deletions common/thorhelper/thorsoapcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,9 +1681,9 @@ bool httpHeaderBlockContainsHeader(const char *httpheaders, const char *header)
return false;
VStringBuffer match("\n%s:", header);
const char *matchStart = match.str()+1;
if (!strncmp(httpheaders, matchStart, strlen(matchStart)))
if (!strnicmp(httpheaders, matchStart, strlen(matchStart)))
return true;
if (strstr(httpheaders, match))
if (stristr(httpheaders, match))
return true;
return false;
}
Expand All @@ -1693,7 +1693,7 @@ bool getHTTPHeader(const char *httpheaders, const char *header, StringBuffer& va
if (!httpheaders || !*httpheaders || !header || !*header)
return false;

const char* pHeader = strstr(httpheaders, header);
const char* pHeader = stristr(httpheaders, header);
if (!pHeader)
return false;

Expand Down Expand Up @@ -2026,10 +2026,10 @@ class CWSCAsyncFor : implements IWSCAsyncFor, public CInterface, public CAsyncFo
s = strstr(buffer, " ");
if (s)
rval = atoi(s+1);
if (!strstr(buffer,"Transfer-Encoding: chunked"))
if (!stristr(buffer,"Transfer-Encoding: chunked"))
{
chunked = false;
s = strstr(buffer,CONTENT_LENGTH);
s = stristr(buffer,CONTENT_LENGTH);
if (s) {
s += strlen(CONTENT_LENGTH);
if ((size32_t)(s-buffer) < payloadofs)
Expand Down
60 changes: 60 additions & 0 deletions system/jlib/jstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2842,3 +2842,63 @@ void processOptionString(const char * options, optionCallback callback)
options = comma+1;
}
}

/**
* stristr - Case insensitive strstr()
* @haystack: Where we will search for our @needle
* @needle: Search pattern.
*
* Description:
* This function is an ANSI version of strstr() with case insensitivity.
*
* It is a commodity funciton found on the web, cut'd, 'n', pasted..
* URL: http://www.brokersys.com/snippets/STRISTR.C
*
* Hereby donated to public domain.
*
* Returns: char *pointer if needle is found in haystack, otherwise NULL.
*
* Rev History: 11/30/23 JLibify
* 01/20/05 Joachim Nilsson Cleanups
* 07/04/95 Bob Stout ANSI-fy
* 02/03/94 Fred Cole Original
*/

const char * stristr (const char *haystack, const char *needle)
{
if (isEmptyString(haystack) || isEmptyString(needle))
return nullptr;

const char *pptr = needle; /* Pattern to search for */
const char *start = haystack; /* Start with a bowl of hay */
const char *sptr; /* Substring pointer */
int slen = strlen(haystack); /* Total size of haystack */
int plen = strlen(needle); /* Length of our needle */

/* while string length not shorter than pattern length */
for (; slen >= plen; start++, slen--)
{
/* find start of pattern in string */
while (tolower(*start) != tolower(*needle))
{
start++;
slen--;
/* if pattern longer than string */
if (slen < plen)
return nullptr;
}

sptr = start;
pptr = (char *) needle;
while (tolower(*sptr) == tolower(*pptr))
{
sptr++;
pptr++;
/* if end of pattern then pattern was found */
if (!*pptr)
return start;
}
}

return nullptr;
}
2 changes: 2 additions & 0 deletions system/jlib/jstring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,6 @@ void processLines(const StringBuffer & content, LineProcessor process)
using optionCallback = std::function<void(const char * name, const char * value)>;
extern jlib_decl void processOptionString(const char * options, optionCallback callback);

extern jlib_decl const char * stristr(const char *haystack, const char *needle);

#endif

0 comments on commit 97476ca

Please sign in to comment.