You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2014/09/13 01:15:54 UTC
git commit: replace strtok with thread-safe strtok_r
Repository: trafficserver
Updated Branches:
refs/heads/master fcc4fca7c -> bbadeae60
replace strtok with thread-safe strtok_r
This closes #112
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/bbadeae6
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/bbadeae6
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/bbadeae6
Branch: refs/heads/master
Commit: bbadeae6036bf120ad55f5fa287b8d9e26e4eff3
Parents: fcc4fca
Author: Pavlo Yatsukhnenko <ya...@gmail.com>
Authored: Fri Sep 12 21:24:20 2014 +0300
Committer: James Peach <jp...@apache.org>
Committed: Fri Sep 12 16:15:53 2014 -0700
----------------------------------------------------------------------
example/protocol/TxnSM.c | 4 ++--
example/secure-link/secure-link.c | 6 +++---
proxy/logging/LogFormat.cc | 8 ++++----
3 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bbadeae6/example/protocol/TxnSM.c
----------------------------------------------------------------------
diff --git a/example/protocol/TxnSM.c b/example/protocol/TxnSM.c
index 70fd63f..2eb49b8 100644
--- a/example/protocol/TxnSM.c
+++ b/example/protocol/TxnSM.c
@@ -948,13 +948,13 @@ is_request_end(char *buf)
int
parse_request(char *request, char *server_name, char *file_name)
{
- char *temp = strtok(request, " ");
+ char *saveptr, *temp = strtok_r(request, " ", &saveptr);
if (temp != NULL)
TSstrlcpy(server_name, temp, MAX_SERVER_NAME_LENGTH + 1);
else
return 0;
- temp = strtok(NULL, " ");
+ temp = strtok_r(NULL, " ", &saveptr);
if (temp != NULL)
TSstrlcpy(file_name, temp, MAX_FILE_NAME_LENGTH + 1);
else
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bbadeae6/example/secure-link/secure-link.c
----------------------------------------------------------------------
diff --git a/example/secure-link/secure-link.c b/example/secure-link/secure-link.c
index 1767918..ef1f03e 100644
--- a/example/secure-link/secure-link.c
+++ b/example/secure-link/secure-link.c
@@ -48,10 +48,10 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo* rri)
MD5_CTX ctx;
struct sockaddr_in *in;
const char *qh, *ph, *ip;
- char *s, *ptr, *val, hash[32];
unsigned char md[MD5_DIGEST_LENGTH];
secure_link_info *sli = (secure_link_info *)ih;
char *token = NULL, *expire = NULL, *path = NULL;
+ char *s, *ptr, *saveptr = NULL, *val, hash[32] = "";
in = (struct sockaddr_in *)TSHttpTxnClientAddrGet(rh);
ip = inet_ntoa(in->sin_addr);
@@ -62,7 +62,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo* rri)
qh = TSUrlHttpQueryGet(rri->requestBufp, rri->requestUrl, &len);
if(qh && len > 0) {
s = (char *)TSstrndup(qh, len);
- if((ptr = strtok(s, "&")) != NULL) {
+ if((ptr = strtok_r(s, "&", &saveptr)) != NULL) {
do {
if((val = strchr(ptr, '=')) != NULL) {
*val++ = '\0';
@@ -75,7 +75,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo* rri)
TSError("Invalid parameter [%s]", ptr);
break;
}
- } while((ptr = strtok(NULL, "&")) != NULL);
+ } while((ptr = strtok_r(NULL, "&", &saveptr)) != NULL);
} else {
TSError("strtok didn't find a & in the query string");
/* this is just example, so set fake params to prevent plugin crash */
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bbadeae6/proxy/logging/LogFormat.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogFormat.cc b/proxy/logging/LogFormat.cc
index db371d7..e82accb 100644
--- a/proxy/logging/LogFormat.cc
+++ b/proxy/logging/LogFormat.cc
@@ -432,7 +432,7 @@ LogFormat::parse_symbol_string(const char *symbol_string, LogFieldList *field_li
char *sym_str;
int field_count = 0;
LogField *f;
- char *symbol, *name, *sym;
+ char *symbol, *name, *sym, *saveptr;
LogField::Container container;
LogField::Aggregate aggregate;
@@ -444,10 +444,10 @@ LogFormat::parse_symbol_string(const char *symbol_string, LogFieldList *field_li
*contains_aggregates = false; // we'll change if it does
//
- // strtok will mangle the input string; we'll make a copy for that.
+ // strtok_r will mangle the input string; we'll make a copy for that.
//
sym_str = ats_strdup(symbol_string);
- symbol = strtok(sym_str, ",");
+ symbol = strtok_r(sym_str, ",", &saveptr);
while (symbol != NULL) {
//
@@ -546,7 +546,7 @@ LogFormat::parse_symbol_string(const char *symbol_string, LogFieldList *field_li
//
// Get the next symbol
//
- symbol = strtok(NULL, ",");
+ symbol = strtok_r(NULL, ",", &saveptr);
}
ats_free(sym_str);