]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: use Curl_str_* instead of strtok_r()
authorDaniel Stenberg <daniel@haxx.se>
Mon, 17 Feb 2025 08:43:45 +0000 (09:43 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 17 Feb 2025 12:18:28 +0000 (13:18 +0100)
Helps avoid extra mallocs. Gets rid of the private strtok_r
implementation.

Closes #16360

26 files changed:
CMake/unix-cache.cmake
CMake/win32-cache.cmake
CMakeLists.txt
configure.ac
lib/.checksrc
lib/Makefile.inc
lib/config-os400.h
lib/config-plan9.h
lib/config-riscos.h
lib/config-win32.h
lib/cookie.c
lib/curl_config.h.cmake
lib/curl_sasl.c
lib/curl_setup.h
lib/curl_trc.c
lib/ldap.c
lib/strparse.c
lib/strparse.h
lib/strtok.c [deleted file]
lib/strtok.h [deleted file]
lib/url.c
lib/vauth/cleartext.c
lib/vauth/digest.c
lib/vtls/sectransp.c
m4/curl-functions.m4
m4/curl-reentrant.m4

index 07bfcbe6cd51dbad406ff00b5efdc8761c0f4e84..e0e1d8f9474eecedfed4926f387c15caf9d2c78e 100644 (file)
@@ -250,7 +250,6 @@ if(_CURL_OLD_LINUX)
 else()
   set(HAVE_STROPTS_H 0)  # glibc 2.30 or newer. https://sourceware.org/legacy-ml/libc-alpha/2019-08/msg00029.html
 endif()
-set(HAVE_STRTOK_R 1)
 set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
 set(HAVE_STRUCT_TIMEVAL 1)
 if(ANDROID OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
index 3e242322eccd392fef19f7751dc19410cba6a9c1..5f292a2d70d9060c8456887e87526716f470a0f8 100644 (file)
@@ -44,13 +44,6 @@ if(MINGW)
   set(HAVE_UTIME_H 1)  # wrapper to sys/utime.h
   set(HAVE_DIRENT_H 1)
   set(HAVE_OPENDIR 1)
-  if(MINGW64_VERSION)
-    if(NOT MINGW64_VERSION VERSION_LESS 4.0)
-      set(HAVE_STRTOK_R 1)
-    else()
-      set(HAVE_STRTOK_R 0)
-    endif()
-  endif()
 else()
   set(HAVE_LIBGEN_H 0)
   set(HAVE_FTRUNCATE 0)
@@ -81,7 +74,6 @@ else()
       set(HAVE_SNPRINTF 0)
     endif()
     set(HAVE_BASENAME 0)
-    set(HAVE_STRTOK_R 0)
     set(HAVE_FILE_OFFSET_BITS 0)
   endif()
 endif()
index 3af7844444f4b5d470cae9a45bc6ed71d686878f..929ce2274f7161cc89addb7231e5bfff4a5c73cd 100644 (file)
@@ -1707,7 +1707,6 @@ check_function_exists("sendmsg"       HAVE_SENDMSG)
 check_function_exists("sendmmsg"      HAVE_SENDMMSG)
 check_symbol_exists("select"          "${CURL_INCLUDES}" HAVE_SELECT)  # proto/bsdsocket.h sys/select.h sys/socket.h
 check_symbol_exists("strdup"          "string.h" HAVE_STRDUP)
-check_symbol_exists("strtok_r"        "string.h" HAVE_STRTOK_R)
 check_symbol_exists("memrchr"         "string.h" HAVE_MEMRCHR)
 check_symbol_exists("alarm"           "unistd.h" HAVE_ALARM)
 check_symbol_exists("fcntl"           "fcntl.h" HAVE_FCNTL)
index 2fb2a0b52da08c9227d649d9064b41f8cdbfd646..5f177cab8e70b386400ab51c1e1eb6c7af043ba9 100644 (file)
@@ -4043,7 +4043,6 @@ CURL_CHECK_FUNC_SOCKET
 CURL_CHECK_FUNC_SOCKETPAIR
 CURL_CHECK_FUNC_STRDUP
 CURL_CHECK_FUNC_STRERROR_R
-CURL_CHECK_FUNC_STRTOK_R
 
 case $host in
   *msdosdjgpp)
index 3d4af2313b62c6dd54dcf504b87e2fd8b1326107..3c6aa6920513f8f49544a74218c16cdee2714ed2 100644 (file)
@@ -5,3 +5,4 @@ banfunc snprintf
 banfunc vsnprint
 banfunc strtoul
 banfunc strtol
+banfunc strtok_r
index 0e6724bcdbe074730311e1e004ff1e481ee8c9ab..29615a441c5f79dd2ab26222cd1d98661f94dd44 100644 (file)
@@ -229,7 +229,6 @@ LIB_CFILES =         \
   strequal.c         \
   strerror.c         \
   strparse.c         \
-  strtok.c           \
   strtoofft.c        \
   system_win32.c     \
   telnet.c           \
@@ -367,7 +366,6 @@ LIB_HFILES =         \
   strdup.h           \
   strerror.h         \
   strparse.h         \
-  strtok.h           \
   strtoofft.h        \
   system_win32.h     \
   telnet.h           \
index 48bd3cad5c769bdae6a2e51ba55a1c40470e3853..4316c58acd9cd1e5400e60caefcb5a36df581fb6 100644 (file)
 /* Define if you have the <stropts.h> header file. */
 #undef HAVE_STROPTS_H
 
-/* Define if you have the `strtok_r' function. */
-#define HAVE_STRTOK_R
-
 /* Define if you have the <sys/param.h> header file. */
 #define HAVE_SYS_PARAM_H
 
index c71b08e4e2387f63f67f42743a8c141b45a2d4cb..857b7866489ba88359f1cb0f2dbc81b8615fc6dc 100644 (file)
 #define HAVE_STDBOOL_H 1
 #define HAVE_STRCASECMP 1
 #define HAVE_STRDUP 1
-#define HAVE_STRTOK_R 1
 #define HAVE_STRUCT_TIMEVAL 1
 #define HAVE_SYS_IOCTL_H 1
 #define HAVE_SYS_PARAM_H 1
index 156c5abe2f41edbb6847f6392b283a97f5acae34..b8aaa5d413b370702155a0eab82ce381fad73f81 100644 (file)
 /* Define if you have the <strings.h> header file. */
 #undef HAVE_STRINGS_H
 
-/* Define if you have the `strtok_r' function. */
-#undef HAVE_STRTOK_R
-
 /* Define if you have the <sys/param.h> header file. */
 #undef HAVE_SYS_PARAM_H
 
index 7564e677a37dc8c08fec707f9ebebecd62972710..94dddfd4db902e2e69a402d67e5c0ab642761fd7 100644 (file)
 #define HAVE_BASENAME 1
 #endif
 
-/* Define to 1 if you have the strtok_r function. */
-#if defined(__MINGW32__) && !defined(__MINGW32CE__)
-#define HAVE_STRTOK_R 1
-#endif
-
 /* Define to 1 if you have the signal function. */
 #ifndef UNDER_CE
 #define HAVE_SIGNAL 1
index f523bf5ed093d40b551e18fb50eddc55b7052d87..2cf5a0de1051f781ad115cc0ab044f87af2ce709 100644 (file)
@@ -76,7 +76,6 @@ Example set of cookies:
 #include "urldata.h"
 #include "cookie.h"
 #include "psl.h"
-#include "strtok.h"
 #include "sendf.h"
 #include "slist.h"
 #include "share.h"
index 88d8aa1207b202dc9fed3ee7fc6d8e65f701dabd..fd82e41ca53a20e0d6c2cfb505bb813c4eef1c0a 100644 (file)
 /* Define to 1 if you have the <stropts.h> header file. */
 #cmakedefine HAVE_STROPTS_H 1
 
-/* Define to 1 if you have the strtok_r function. */
-#cmakedefine HAVE_STRTOK_R 1
-
 /* Define to 1 if you have the memrchr function. */
 #cmakedefine HAVE_MEMRCHR 1
 
index 24f8c8c53c19d9309e5874c3c43b0b9e90496dca..7fe1c326a935d087d1e3baa83487ee5a3adadb14 100644 (file)
@@ -50,7 +50,6 @@
 #include "curl_hmac.h"
 #include "curl_sasl.h"
 #include "warnless.h"
-#include "strtok.h"
 #include "sendf.h"
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
index 3879f5933736dc5237753e5b90856f7733871bc9..521200095ef5c0ce461ef8a319f3cdb74824c808 100644 (file)
 
 #  ifdef __minix
      /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
-     extern char *strtok_r(char *s, const char *delim, char **last);
      extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
 #  endif
 
index 07137c1f24e5d1ac40e095daa43517bf65d41b1e..e5f9b517dc5e94bcd2efebce6f726505757b52b8 100644 (file)
@@ -44,7 +44,7 @@
 #include "cf-haproxy.h"
 #include "cf-https-connect.h"
 #include "socks.h"
-#include "strtok.h"
+#include "strparse.h"
 #include "vtls/vtls.h"
 #include "vquic/vquic.h"
 
@@ -341,18 +341,18 @@ static struct trc_cft_def trc_cfts[] = {
 #endif
 };
 
-static void trc_apply_level_by_name(const char * const token, int lvl)
+static void trc_apply_level_by_name(struct Curl_str *token, int lvl)
 {
   size_t i;
 
   for(i = 0; i < CURL_ARRAYSIZE(trc_cfts); ++i) {
-    if(strcasecompare(token, trc_cfts[i].cft->name)) {
+    if(Curl_str_casecompare(token, trc_cfts[i].cft->name)) {
       trc_cfts[i].cft->log_level = lvl;
       break;
     }
   }
   for(i = 0; i < CURL_ARRAYSIZE(trc_feats); ++i) {
-    if(strcasecompare(token, trc_feats[i].feat->name)) {
+    if(Curl_str_casecompare(token, trc_feats[i].feat->name)) {
       trc_feats[i].feat->log_level = lvl;
       break;
     }
@@ -375,42 +375,32 @@ static void trc_apply_level_by_category(int category, int lvl)
 
 static CURLcode trc_opt(const char *config)
 {
-  char *token, *tok_buf, *tmp;
-  int lvl;
-
-  tmp = strdup(config);
-  if(!tmp)
-    return CURLE_OUT_OF_MEMORY;
-
-  token = Curl_strtok_r(tmp, ", ", &tok_buf);
-  while(token) {
-    switch(*token) {
-      case '-':
-        lvl = CURL_LOG_LVL_NONE;
-        ++token;
-        break;
-      case '+':
-        lvl = CURL_LOG_LVL_INFO;
-        ++token;
-        break;
-      default:
-        lvl = CURL_LOG_LVL_INFO;
-        break;
+  struct Curl_str out;
+  while(!Curl_str_until(&config, &out, 32, ',')) {
+    int lvl = CURL_LOG_LVL_INFO;
+    const char *token = out.str;
+
+    if(*token == '-') {
+      lvl = CURL_LOG_LVL_NONE;
+      Curl_str_nudge(&out, 1);
     }
-    if(strcasecompare(token, "all"))
+    else if(*token == '+')
+      Curl_str_nudge(&out, 1);
+
+    if(Curl_str_casecompare(&out, "all"))
       trc_apply_level_by_category(TRC_CT_NONE, lvl);
-    else if(strcasecompare(token, "protocol"))
+    else if(Curl_str_casecompare(&out, "protocol"))
       trc_apply_level_by_category(TRC_CT_PROTOCOL, lvl);
-    else if(strcasecompare(token, "network"))
+    else if(Curl_str_casecompare(&out, "network"))
       trc_apply_level_by_category(TRC_CT_NETWORK, lvl);
-    else if(strcasecompare(token, "proxy"))
+    else if(Curl_str_casecompare(&out, "proxy"))
       trc_apply_level_by_category(TRC_CT_PROXY, lvl);
     else
-      trc_apply_level_by_name(token, lvl);
+      trc_apply_level_by_name(&out, lvl);
 
-    token = Curl_strtok_r(NULL, ", ", &tok_buf);
+    if(Curl_str_single(&config, ','))
+      break;
   }
-  free(tmp);
   return CURLE_OK;
 }
 
index dfabf55d118a4bb7d445340985e3f1866951bd0c..de5be1ee7798be277cb1c842a8cd15c72755859c 100644 (file)
@@ -89,7 +89,7 @@
 #include "progress.h"
 #include "transfer.h"
 #include "strcase.h"
-#include "strtok.h"
+#include "strparse.h"
 #include "curl_ldap.h"
 #include "curl_multibyte.h"
 #include "curl_base64.h"
@@ -761,36 +761,17 @@ static int str2scope(const char *p)
   return -1;
 }
 
-/*
- * Split 'str' into strings separated by commas.
- * Note: out[] points into 'str'.
- */
-static bool split_str(char *str, char ***out, size_t *count)
+/* number of entries in the attributes list */
+static size_t num_entries(const char *s)
 {
-  char **res;
-  char *lasts;
-  char *s;
-  size_t  i;
   size_t items = 1;
 
-  s = strchr(str, ',');
+  s = strchr(s, ',');
   while(s) {
     items++;
-    s = strchr(++s, ',');
+    s = strchr(s + 1, ',');
   }
-
-  res = calloc(items, sizeof(char *));
-  if(!res)
-    return FALSE;
-
-  for(i = 0, s = Curl_strtok_r(str, ",", &lasts); s && i < items;
-      s = Curl_strtok_r(NULL, ",", &lasts), i++)
-    res[i] = s;
-
-  *out = res;
-  *count = items;
-
-  return TRUE;
+  return items;
 }
 
 /*
@@ -884,15 +865,8 @@ static int _ldap_url_parse2(struct Curl_easy *data,
     *q++ = '\0';
 
   if(*p) {
-    char **attributes;
-    size_t count = 0;
-
-    /* Split the string into an array of attributes */
-    if(!split_str(p, &attributes, &count)) {
-      rc = LDAP_NO_MEMORY;
-
-      goto quit;
-    }
+    size_t count = num_entries(p); /* at least one */
+    const char *atp = p;
 
     /* Allocate our array (+1 for the NULL entry) */
 #if defined(USE_WIN32_LDAP)
@@ -901,27 +875,25 @@ static int _ldap_url_parse2(struct Curl_easy *data,
     ludp->lud_attrs = calloc(count + 1, sizeof(char *));
 #endif
     if(!ludp->lud_attrs) {
-      free(attributes);
-
       rc = LDAP_NO_MEMORY;
-
       goto quit;
     }
 
     for(i = 0; i < count; i++) {
       char *unescaped;
       CURLcode result;
+      struct Curl_str out;
 
-      LDAP_TRACE(("attr[%zu] '%s'\n", i, attributes[i]));
+      if(Curl_str_until(&atp, &out, 1024, ','))
+        break;
+
+      LDAP_TRACE(("attr[%zu] '%.*s'\n", i, (int)out.len, out.str));
 
       /* Unescape the attribute */
-      result = Curl_urldecode(attributes[i], 0, &unescaped, NULL,
+      result = Curl_urldecode(out.str, out.len, &unescaped, NULL,
                               REJECT_ZERO);
       if(result) {
-        free(attributes);
-
         rc = LDAP_NO_MEMORY;
-
         goto quit;
       }
 
@@ -933,10 +905,7 @@ static int _ldap_url_parse2(struct Curl_easy *data,
       free(unescaped);
 
       if(!ludp->lud_attrs[i]) {
-        free(attributes);
-
         rc = LDAP_NO_MEMORY;
-
         goto quit;
       }
 #else
@@ -944,9 +913,9 @@ static int _ldap_url_parse2(struct Curl_easy *data,
 #endif
 
       ludp->lud_attrs_dups++;
+      if(Curl_str_single(&atp, ','))
+        break;
     }
-
-    free(attributes);
   }
 
   p = q;
index 6730b96d1b298d920a42f6f75a2e9783d0d890f2..0ba661446e4f64601e91ebbf4a5ff1bd611125d2 100644 (file)
@@ -173,3 +173,23 @@ int Curl_str_newline(const char **linep)
   }
   return STRE_NEWLINE;
 }
+
+/* case insensitive compare that the parsed string matches the
+   given string. Returns non-zero on match. */
+int Curl_str_casecompare(struct Curl_str *str, const char *check)
+{
+  size_t clen = check ? strlen(check) : 0;
+  return ((str->len == clen) && strncasecompare(str->str, check, clen));
+}
+
+/* Trim off 'num' number of bytes from the beginning (left side) of the
+   string. If 'num' is larger than the string, return error. */
+int Curl_str_nudge(struct Curl_str *str, size_t num)
+{
+  if(num <= str->len) {
+    str->str += num;
+    str->len -= num;
+    return STRE_OK;
+  }
+  return STRE_OVERFLOW;
+}
index 7ade183ec22bc7d654d7c721816e9ced421eb3af..946cf5b2ba1a4e5677b0240f67eb89f4abf07eb4 100644 (file)
@@ -75,4 +75,10 @@ int Curl_str_octal(const char **linep, curl_off_t *nump, curl_off_t max);
    return non-zero on error */
 int Curl_str_newline(const char **linep);
 
+/* case insensitive compare that the parsed string matches the
+   given string. */
+int Curl_str_casecompare(struct Curl_str *str, const char *check);
+
+int Curl_str_nudge(struct Curl_str *str, size_t num);
+
 #endif /* HEADER_CURL_STRPARSE_H */
diff --git a/lib/strtok.c b/lib/strtok.c
deleted file mode 100644 (file)
index d2cc71c..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-
-#include "curl_setup.h"
-
-#ifndef HAVE_STRTOK_R
-#include <stddef.h>
-
-#include "strtok.h"
-
-char *
-Curl_strtok_r(char *ptr, const char *sep, char **end)
-{
-  if(!ptr)
-    /* we got NULL input so then we get our last position instead */
-    ptr = *end;
-
-  /* pass all letters that are including in the separator string */
-  while(*ptr && strchr(sep, *ptr))
-    ++ptr;
-
-  if(*ptr) {
-    /* so this is where the next piece of string starts */
-    char *start = ptr;
-
-    /* set the end pointer to the first byte after the start */
-    *end = start + 1;
-
-    /* scan through the string to find where it ends, it ends on a
-       null byte or a character that exists in the separator string */
-    while(**end && !strchr(sep, **end))
-      ++*end;
-
-    if(**end) {
-      /* the end is not a null byte */
-      **end = '\0';  /* null-terminate it! */
-      ++*end;        /* advance the last pointer to beyond the null byte */
-    }
-
-    return start; /* return the position where the string starts */
-  }
-
-  /* we ended up on a null byte, there are no more strings to find! */
-  return NULL;
-}
-
-#endif /* this was only compiled if strtok_r was not present */
diff --git a/lib/strtok.h b/lib/strtok.h
deleted file mode 100644 (file)
index 9b4d062..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef HEADER_CURL_STRTOK_H
-#define HEADER_CURL_STRTOK_H
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-#include "curl_setup.h"
-#include <stddef.h>
-
-#ifdef HAVE_STRTOK_R
-#include <string.h>
-#define Curl_strtok_r strtok_r
-#else
-char *Curl_strtok_r(char *s, const char *delim, char **last);
-#endif
-
-#endif /* HEADER_CURL_STRTOK_H */
index cdca4b707228bbecb293176feec55bbf469acbda..2826fc2a6863d1f0772ae946aa28a162257aa2bc 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -75,7 +75,6 @@
 #include "strcase.h"
 #include "strerror.h"
 #include "escape.h"
-#include "strtok.h"
 #include "share.h"
 #include "content_encoding.h"
 #include "http_digest.h"
index cf8108ac5b6af9c6a9af299cf10c17e4e0dae8e3..9dfefa3afc0c469d0c37a42052fd7c8a529d1ec3 100644 (file)
@@ -36,7 +36,6 @@
 
 #include "vauth/vauth.h"
 #include "warnless.h"
-#include "strtok.h"
 #include "sendf.h"
 #include "curl_printf.h"
 
index 81433663015d55dcce84a4302abf350be05ec04e..024b7bb01ad29b4acfb81bc9dc4f6929319c883b 100644 (file)
@@ -41,7 +41,7 @@
 #include "curl_sha512_256.h"
 #include "vtls/vtls.h"
 #include "warnless.h"
-#include "strtok.h"
+#include "strparse.h"
 #include "strcase.h"
 #include "curl_printf.h"
 #include "rand.h"
@@ -219,33 +219,21 @@ static bool auth_digest_get_key_value(const char *chlg,
 
 static CURLcode auth_digest_get_qop_values(const char *options, int *value)
 {
-  char *tmp;
-  char *token;
-  char *tok_buf = NULL;
-
+  struct Curl_str out;
   /* Initialise the output */
   *value = 0;
 
-  /* Tokenise the list of qop values. Use a temporary clone of the buffer since
-     Curl_strtok_r() ruins it. */
-  tmp = strdup(options);
-  if(!tmp)
-    return CURLE_OUT_OF_MEMORY;
-
-  token = Curl_strtok_r(tmp, ",", &tok_buf);
-  while(token) {
-    if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH))
+  while(!Curl_str_until(&options, &out, 32, ',')) {
+    if(Curl_str_casecompare(&out, DIGEST_QOP_VALUE_STRING_AUTH))
       *value |= DIGEST_QOP_VALUE_AUTH;
-    else if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH_INT))
+    else if(Curl_str_casecompare(&out, DIGEST_QOP_VALUE_STRING_AUTH_INT))
       *value |= DIGEST_QOP_VALUE_AUTH_INT;
-    else if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH_CONF))
+    else if(Curl_str_casecompare(&out, DIGEST_QOP_VALUE_STRING_AUTH_CONF))
       *value |= DIGEST_QOP_VALUE_AUTH_CONF;
-
-    token = Curl_strtok_r(NULL, ",", &tok_buf);
+    if(Curl_str_single(&options, ','))
+      break;
   }
 
-  free(tmp);
-
   return CURLE_OK;
 }
 
@@ -504,10 +492,6 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
                                               struct digestdata *digest)
 {
   bool before = FALSE; /* got a nonce before */
-  bool foundAuth = FALSE;
-  bool foundAuthInt = FALSE;
-  char *token = NULL;
-  char *tmp = NULL;
 
   /* If we already have received a nonce, keep that in mind */
   if(digest->nonce)
@@ -551,29 +535,25 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
           return CURLE_OUT_OF_MEMORY;
       }
       else if(strcasecompare(value, "qop")) {
-        char *tok_buf = NULL;
-        /* Tokenize the list and choose auth if possible, use a temporary
-           clone of the buffer since Curl_strtok_r() ruins it */
-        tmp = strdup(content);
-        if(!tmp)
-          return CURLE_OUT_OF_MEMORY;
-
-        token = Curl_strtok_r(tmp, ",", &tok_buf);
-        while(token) {
-          /* Pass additional spaces here */
-          while(*token && ISBLANK(*token))
-            token++;
-          if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH)) {
+        const char *token = content;
+        struct Curl_str out;
+        bool foundAuth = FALSE;
+        bool foundAuthInt = FALSE;
+        /* Pass leading spaces */
+        while(*token && ISBLANK(*token))
+          token++;
+        while(!Curl_str_until(&token, &out, 32, ',')) {
+          if(Curl_str_casecompare(&out, DIGEST_QOP_VALUE_STRING_AUTH))
             foundAuth = TRUE;
-          }
-          else if(strcasecompare(token, DIGEST_QOP_VALUE_STRING_AUTH_INT)) {
+          else if(Curl_str_casecompare(&out,
+                                       DIGEST_QOP_VALUE_STRING_AUTH_INT))
             foundAuthInt = TRUE;
-          }
-          token = Curl_strtok_r(NULL, ",", &tok_buf);
+          if(Curl_str_single(&token, ','))
+            break;
+          while(*token && ISBLANK(*token))
+            token++;
         }
 
-        free(tmp);
-
         /* Select only auth or auth-int. Otherwise, ignore */
         if(foundAuth) {
           free(digest->qop);
index a0f6dccc28dea6b92ca387af1284f91788e80675..2e72a50296b92196ce26cd8887c70c3960467567 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "urldata.h" /* for the Curl_easy definition */
 #include "curl_base64.h"
-#include "strtok.h"
+#include "strparse.h"
 #include "multiif.h"
 #include "strcase.h"
 #include "x509asn1.h"
@@ -341,30 +341,28 @@ static OSStatus sectransp_bio_cf_out_write(SSLConnectionRef connection,
 CF_INLINE void GetDarwinVersionNumber(int *major, int *minor)
 {
   int mib[2];
-  char *os_version;
   size_t os_version_len;
-  char *os_version_major, *os_version_minor;
-  char *tok_buf;
+  char buf[256];
 
   /* Get the Darwin kernel version from the kernel using sysctl(): */
   mib[0] = CTL_KERN;
   mib[1] = KERN_OSRELEASE;
   if(sysctl(mib, 2, NULL, &os_version_len, NULL, 0) == -1)
     return;
-  os_version = malloc(os_version_len*sizeof(char));
-  if(!os_version)
-    return;
-  if(sysctl(mib, 2, os_version, &os_version_len, NULL, 0) == -1) {
-    free(os_version);
-    return;
+  if(os_version_len < sizeof(buf)) {
+    if(sysctl(mib, 2, buf, &os_version_len, NULL, 0) != -1) {
+      const char *os = buf;
+      curl_off_t fnum;
+      curl_off_t snum;
+      /* Parse the version: */
+      if(!Curl_str_number(&os, &fnum, INT_MAX) &&
+         !Curl_str_single(&os, '.') &&
+         !Curl_str_number(&os, &snum, INT_MAX)) {
+        *major = (int)fnum;
+        *minor = (int)snum;
+      }
+    }
   }
-
-  /* Parse the version: */
-  os_version_major = Curl_strtok_r(os_version, ".", &tok_buf);
-  os_version_minor = Curl_strtok_r(NULL, ".", &tok_buf);
-  *major = atoi(os_version_major);
-  *minor = atoi(os_version_minor);
-  free(os_version);
 }
 #endif /* CURL_BUILD_MAC */
 
index 4daac748f4d397355f2b4c0b560317b4c280ce93..60008b759388fb68ec1b5d831a32b32b1500da79 100644 (file)
@@ -4229,91 +4229,6 @@ AC_DEFUN([CURL_CHECK_FUNC_STRICMP], [
   fi
 ])
 
-
-dnl CURL_CHECK_FUNC_STRTOK_R
-dnl -------------------------------------------------
-dnl Verify if strtok_r is available, prototyped, and
-dnl can be compiled. If all of these are true, and
-dnl usage has not been previously disallowed with
-dnl shell variable curl_disallow_strtok_r, then
-dnl HAVE_STRTOK_R will be defined.
-
-AC_DEFUN([CURL_CHECK_FUNC_STRTOK_R], [
-  AC_REQUIRE([CURL_INCLUDES_STRING])dnl
-  #
-  tst_links_strtok_r="unknown"
-  tst_proto_strtok_r="unknown"
-  tst_compi_strtok_r="unknown"
-  tst_allow_strtok_r="unknown"
-  #
-  AC_MSG_CHECKING([if strtok_r can be linked])
-  AC_LINK_IFELSE([
-    AC_LANG_FUNC_LINK_TRY([strtok_r])
-  ],[
-    AC_MSG_RESULT([yes])
-    tst_links_strtok_r="yes"
-  ],[
-    AC_MSG_RESULT([no])
-    tst_links_strtok_r="no"
-  ])
-  #
-  if test "$tst_links_strtok_r" = "yes"; then
-    AC_MSG_CHECKING([if strtok_r is prototyped])
-    AC_EGREP_CPP([strtok_r],[
-      $curl_includes_string
-    ],[
-      AC_MSG_RESULT([yes])
-      tst_proto_strtok_r="yes"
-    ],[
-      AC_MSG_RESULT([no])
-      tst_proto_strtok_r="no"
-    ])
-  fi
-  #
-  if test "$tst_proto_strtok_r" = "yes"; then
-    AC_MSG_CHECKING([if strtok_r is compilable])
-    AC_COMPILE_IFELSE([
-      AC_LANG_PROGRAM([[
-        $curl_includes_string
-      ]],[[
-        if(0 != strtok_r(0, "", 0))
-          return 1;
-      ]])
-    ],[
-      AC_MSG_RESULT([yes])
-      tst_compi_strtok_r="yes"
-    ],[
-      AC_MSG_RESULT([no])
-      tst_compi_strtok_r="no"
-    ])
-  fi
-  #
-  if test "$tst_compi_strtok_r" = "yes"; then
-    AC_MSG_CHECKING([if strtok_r usage allowed])
-    if test "x$curl_disallow_strtok_r" != "xyes"; then
-      AC_MSG_RESULT([yes])
-      tst_allow_strtok_r="yes"
-    else
-      AC_MSG_RESULT([no])
-      tst_allow_strtok_r="no"
-    fi
-  fi
-  #
-  AC_MSG_CHECKING([if strtok_r might be used])
-  if test "$tst_links_strtok_r" = "yes" &&
-     test "$tst_proto_strtok_r" = "yes" &&
-     test "$tst_compi_strtok_r" = "yes" &&
-     test "$tst_allow_strtok_r" = "yes"; then
-    AC_MSG_RESULT([yes])
-    AC_DEFINE_UNQUOTED(HAVE_STRTOK_R, 1,
-      [Define to 1 if you have the strtok_r function.])
-    curl_cv_func_strtok_r="yes"
-  else
-    AC_MSG_RESULT([no])
-    curl_cv_func_strtok_r="no"
-  fi
-])
-
 dnl CURL_RUN_IFELSE
 dnl -------------------------------------------------
 dnl Wrapper macro to use instead of AC_RUN_IFELSE. It
index 0f989fe8199c11fdde82c6395f56b9b7584365e8..95e539c152e6b99413d4d81ca025d5218cc70be5 100644 (file)
@@ -184,40 +184,6 @@ AC_DEFUN([CURL_CHECK_NEED_REENTRANT_STRERROR_R], [
   fi
 ])
 
-
-dnl CURL_CHECK_NEED_REENTRANT_STRTOK_R
-dnl -------------------------------------------------
-dnl Checks if the preprocessor _REENTRANT definition
-dnl makes function strtok_r compiler visible.
-
-AC_DEFUN([CURL_CHECK_NEED_REENTRANT_STRTOK_R], [
-  AC_LINK_IFELSE([
-    AC_LANG_FUNC_LINK_TRY([strtok_r])
-  ],[
-    tmp_strtok_r="yes"
-  ],[
-    tmp_strtok_r="no"
-  ])
-  if test "$tmp_strtok_r" = "yes"; then
-    AC_EGREP_CPP([strtok_r],[
-      #include <sys/types.h>
-      #include <string.h>
-    ],[
-      tmp_strtok_r="proto_declared"
-    ],[
-      AC_EGREP_CPP([strtok_r],[
-        #define _REENTRANT
-        #include <sys/types.h>
-        #include <string.h>
-      ],[
-        tmp_strtok_r="proto_needs_reentrant"
-        tmp_need_reentrant="yes"
-      ])
-    ])
-  fi
-])
-
-
 dnl CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
 dnl -------------------------------------------------
 dnl Checks if the preprocessor _REENTRANT definition
@@ -300,9 +266,6 @@ AC_DEFUN([CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R], [
   if test "$tmp_need_reentrant" = "no"; then
     CURL_CHECK_NEED_REENTRANT_STRERROR_R
   fi
-  if test "$tmp_need_reentrant" = "no"; then
-    CURL_CHECK_NEED_REENTRANT_STRTOK_R
-  fi
   if test "$tmp_need_reentrant" = "no"; then
     CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
   fi