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 2016/07/07 22:59:19 UTC
[trafficserver] branch master updated: TS-3816 : Replace
ptr_len_cmp with memcmp (#783)
This is an automated email from the ASF dual-hosted git repository.
jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new d36cb47 TS-3816 : Replace ptr_len_cmp with memcmp (#783)
d36cb47 is described below
commit d36cb4791a4e42736e4db97100eb8449ad118231
Author: Tyler Stroh <ty...@gmail.com>
AuthorDate: Thu Jul 7 15:59:10 2016 -0700
TS-3816 : Replace ptr_len_cmp with memcmp (#783)
---
lib/ts/ink_string.h | 57 +---------------------------------------------
proxy/StatPages.cc | 2 +-
proxy/http/HttpTransact.cc | 12 ++++++----
proxy/http2/HPACK.cc | 2 +-
4 files changed, 11 insertions(+), 62 deletions(-)
diff --git a/lib/ts/ink_string.h b/lib/ts/ink_string.h
index 56183c4..d84cd64 100644
--- a/lib/ts/ink_string.h
+++ b/lib/ts/ink_string.h
@@ -88,23 +88,7 @@ void ink_utf8_to_latin1(const char *in, int inlen, char *out, int *outlen);
*===========================================================================*/
-// inline int ptr_len_cmp(const char* p1, int l1, const char* p2, int l2)
-//
-// strcmp() functionality for two ptr length pairs
-//
-inline int
-ptr_len_cmp(const char *p1, int l1, const char *p2, int l2)
-{
- if (l1 == l2) {
- return memcmp(p1, p2, l1);
- } else if (l1 < l2) {
- return -1;
- } else {
- return 1;
- }
-}
-
-// inline int ptr_len_cmp(const char* p1, int l1, const char* p2, int l2)
+// inline int ptr_len_casecmp(const char* p1, int l1, const char* p2, int l2)
//
// strcasecmp() functionality for two ptr length pairs
//
@@ -294,45 +278,6 @@ ptr_len_casecmp(const char *p1, int l1, const char *str)
}
}
-// int ptr_len_cmp(const char* p1, int l1, const char* str) {
-//
-// strcmp like functionality for comparing a ptr,len pair with
-// a null terminated string
-//
-inline int
-ptr_len_cmp(const char *p1, int l1, const char *str)
-{
- while (l1 > 0) {
- if (*str == '\0') {
- return 1;
- }
-
- char p1c = *p1;
- char strc = *str;
-
- if (p1c != strc) {
- if (p1c > strc) {
- return 1;
- } else if (p1c < strc) {
- return -1;
- }
- }
-
- p1++;
- l1--;
- str++;
- }
-
- // Since we're out of characters in p1
- // str needs to be finished for the strings
- // to get equal
- if (*str == '\0') {
- return 0;
- } else {
- return -1;
- }
-}
-
// char* ptr_len_pbrk(const char* p1, int l1, const char* str)
//
// strpbrk() like functionality for ptr & len pair strings
diff --git a/proxy/StatPages.cc b/proxy/StatPages.cc
index 0268dfb..966593a 100644
--- a/proxy/StatPages.cc
+++ b/proxy/StatPages.cc
@@ -83,7 +83,7 @@ StatPagesManager::handle_http(Continuation *cont, HTTPHdr *header)
host_len = unescapifyStr(host);
for (i = 0; i < n_stat_pages; i++) {
- if (ptr_len_cmp(host, host_len, stat_pages[i].module) == 0) {
+ if (strlen(host) == strlen(stat_pages[i].module) && strncmp(host, stat_pages[i].module, host_len) == 0) {
return stat_pages[i].func(cont, header);
}
}
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 978c256..e7dde35 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -63,7 +63,12 @@ static char range_type[] = "multipart/byteranges; boundary=RANGE_SEPARATOR";
extern HttpBodyFactory *body_factory;
-static const char local_host_ip_str[] = "127.0.0.1";
+inline static bool
+is_localhost(const char *name, int len)
+{
+ static const char local[] = "127.0.0.1";
+ return (len == (sizeof(local) - 1)) && (memcmp(name, local, len) == 0);
+}
inline static void
simple_or_unavailable_server_retry(HttpTransact::State *s)
@@ -249,7 +254,7 @@ find_server_and_update_current_info(HttpTransact::State *s)
int host_len;
const char *host = s->hdr_info.client_request.host_get(&host_len);
- if (ptr_len_cmp(host, host_len, local_host_ip_str, sizeof(local_host_ip_str) - 1) == 0) {
+ if (is_localhost(host, host_len)) {
// Do not forward requests to local_host onto a parent.
// I just wanted to do this for cop heartbeats, someone else
// wanted it for all requests to local_host.
@@ -762,8 +767,7 @@ HttpTransact::StartRemapRequest(State *s)
const char syntxt[] = "synthetic.txt";
- s->cop_test_page = (ptr_len_cmp(host, host_len, local_host_ip_str, sizeof(local_host_ip_str) - 1) == 0) &&
- (ptr_len_cmp(path, path_len, syntxt, sizeof(syntxt) - 1) == 0) &&
+ s->cop_test_page = is_localhost(host, host_len) && ((path_len == sizeof(syntxt) - 1) && (memcmp(path, syntxt, path_len) == 0)) &&
port == s->http_config_param->synthetic_port && s->method == HTTP_WKSIDX_GET &&
s->orig_scheme == URL_WKSIDX_HTTP && ats_ip4_addr_cast(&s->client_info.dst_addr.sa) == htonl(INADDR_LOOPBACK);
diff --git a/proxy/http2/HPACK.cc b/proxy/http2/HPACK.cc
index e0fe89e..9947170 100644
--- a/proxy/http2/HPACK.cc
+++ b/proxy/http2/HPACK.cc
@@ -236,7 +236,7 @@ HpackIndexingTable::lookup(const char *name, int name_len, const char *value, in
// Check whether name (and value) are matched
if (ptr_len_casecmp(name, name_len, table_name, table_name_len) == 0) {
- if (ptr_len_cmp(value, value_len, table_value, table_value_len) == 0) {
+ if ((value_len == table_value_len) && (memcmp(value, table_value, value_len) == 0)) {
result.index = index;
result.match_type = HPACK_EXACT_MATCH;
break;
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].