Reworked ndpi_strncasestr

This commit is contained in:
Luca Deri
2020-05-31 18:50:25 +02:00
parent b0bf66c436
commit dc5b4cbde0
2 changed files with 14 additions and 20 deletions
+1 -1
View File
@@ -137,7 +137,7 @@ extern "C" {
* NULL if the substring is not found * NULL if the substring is not found
* *
*/ */
char* ndpi_strncasestr(const char *s, const char *find, size_t slen); const char* ndpi_strncasestr(const char *s, const char *find, size_t slen);
/** /**
* Returns the nDPI protocol id for IP-based protocol detection * Returns the nDPI protocol id for IP-based protocol detection
+13 -19
View File
@@ -5906,27 +5906,21 @@ char *ndpi_strnstr(const char *s, const char *find, size_t slen) {
/* /*
* Same as ndpi_strnstr but case-insensitive * Same as ndpi_strnstr but case-insensitive
*/ */
char *ndpi_strncasestr(const char *s, const char *find, size_t slen) { const char * ndpi_strncasestr(const char *str1, const char *str2, size_t len) {
char c; size_t str1_len = strnlen(str1, len);
size_t len; size_t str2_len = strlen(str2);
size_t i;
if((c = *find++) != '\0') { for(i = 0; i < (str1_len - str2_len + 1); i++){
len = strlen(find); if(str1[0] == '\0')
do { return NULL;
char sc; else if(strncasecmp(str1, str2, str2_len) == 0)
return(str1);
do {
if(slen-- < 1 || (sc = *s++) == '\0') str1++;
return(NULL);
} while (sc != c);
if(len > slen)
return(NULL);
} while (strncasecmp(s, find, len) != 0);
s--;
} }
return((char *) s);
return NULL;
} }
/* ****************************************************** */ /* ****************************************************** */