You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2014/12/10 06:33:41 UTC
trafficserver git commit: TS-1570: Minor fix for ats_ip_parse and
additional regression tests.
Repository: trafficserver
Updated Branches:
refs/heads/master 665b442da -> 156b7be9c
TS-1570: Minor fix for ats_ip_parse and additional regression tests.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/156b7be9
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/156b7be9
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/156b7be9
Branch: refs/heads/master
Commit: 156b7be9cb6a3d244efb58dd498b8c3ce5e1a4d9
Parents: 665b442
Author: Alan M. Carroll <so...@yahoo-inc.com>
Authored: Tue Dec 9 21:16:20 2014 -0800
Committer: Alan M. Carroll <so...@yahoo-inc.com>
Committed: Tue Dec 9 21:17:55 2014 -0800
----------------------------------------------------------------------
lib/ts/ink_inet.cc | 59 +++++++++++++++++++++++++++++++------------------
1 file changed, 38 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/156b7be9/lib/ts/ink_inet.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_inet.cc b/lib/ts/ink_inet.cc
index 7922c69..0104981 100644
--- a/lib/ts/ink_inet.cc
+++ b/lib/ts/ink_inet.cc
@@ -230,9 +230,9 @@ ats_ip_parse(ts::ConstBuffer src, ts::ConstBuffer* addr, ts::ConstBuffer* port,
}
} else {
ts::ConstBuffer post = src.after(':');
- if (post && ! post.find(':')) {
- *addr = src.splitOn(post.data()-1);
- colon_p = true;
+ if (post.data() && ! post.find(':')) {
+ *addr = src.splitOn(post.data()-1);
+ colon_p = true;
} else { // presume no port, use everything.
*addr = src;
src.reset();
@@ -547,7 +547,7 @@ ats_ip_check_characters(ts::ConstBuffer text) {
}
// Need to declare this type globally so gcc 4.4 can use it in the countof() template ...
-struct ip_parse_spec { const char * hostspec; const char * host; const char * port; };
+struct ip_parse_spec { char const* hostspec; char const* host; char const* port; char const* rest;};
REGRESSION_TEST(Ink_Inet) (RegressionTest * t, int /* atype */, int * pstatus) {
TestBox box(t, pstatus);
@@ -559,28 +559,47 @@ REGRESSION_TEST(Ink_Inet) (RegressionTest * t, int /* atype */, int * pstatus) {
// Test ats_ip_parse() ...
{
struct ip_parse_spec names[] = {
- { "::", "::", NULL },
- { "[::1]:99", "::1", "99" },
- { "127.0.0.1:8080", "127.0.0.1", "8080" },
- { "foo.example.com", "foo.example.com", NULL },
- { "foo.example.com:99", "foo.example.com", "99" },
+ { "::", "::", NULL, NULL },
+ { "[::1]:99", "::1", "99", NULL },
+ { "127.0.0.1:8080", "127.0.0.1", "8080", NULL },
+ { "127.0.0.1:8080-Bob", "127.0.0.1", "8080", "-Bob" },
+ { "127.0.0.1:", "127.0.0.1", NULL, ":" },
+ { "foo.example.com", "foo.example.com", NULL, NULL },
+ { "foo.example.com:99", "foo.example.com", "99", NULL },
+ { "ffee::24c3:3349:3cee:0143", "ffee::24c3:3349:3cee:0143", NULL },
+ { "fe80:88b5:4a:20c:29ff:feae:1c33:8080", "fe80:88b5:4a:20c:29ff:feae:1c33:8080", NULL, NULL },
+ { "[ffee::24c3:3349:3cee:0143]", "ffee::24c3:3349:3cee:0143", NULL },
+ { "[ffee::24c3:3349:3cee:0143]:80", "ffee::24c3:3349:3cee:0143", "80", NULL },
+ { "[ffee::24c3:3349:3cee:0143]:8080x", "ffee::24c3:3349:3cee:0143", "8080", "x" }
};
for (unsigned i = 0; i < countof(names); ++i) {
- ts::ConstBuffer addr, port;
-
- box.check(ats_ip_parse(ts::ConstBuffer(names[i].hostspec, strlen(names[i].hostspec)), &addr, &port) == 0,
- "ats_ip_parse(%s)", names[i].hostspec);
- box.check(strncmp(addr.data(), names[i].host, addr.size()) == 0,
- "ats_ip_parse(%s) gave addr '%.*s'", names[i].hostspec, (int)addr.size(), addr.data());
- if (names[i].port) {
- box.check(strncmp(port.data(), names[i].port, port.size()) == 0,
- "ats_ip_parse(%s) gave port '%.*s'", names[i].hostspec, (int)port.size(), port.data());
+ ip_parse_spec const& s = names[i];
+ ts::ConstBuffer host, port, rest;
+ size_t len;
+
+ box.check(ats_ip_parse(ts::ConstBuffer(s.hostspec, strlen(s.hostspec)), &host, &port, &rest) == 0,
+ "ats_ip_parse(%s)", s.hostspec);
+ len = strlen(s.host);
+ box.check(len == host.size() && strncmp(host.data(), s.host, host.size()) == 0,
+ "ats_ip_parse(%s) gave addr '%.*s'", s.hostspec, static_cast<int>(host.size()), host.data());
+ if (s.port) {
+ len = strlen(s.port);
+ box.check(len == port.size() && strncmp(port.data(), s.port, port.size()) == 0,
+ "ats_ip_parse(%s) gave port '%.*s'", s.hostspec, static_cast<int>(port.size()), port.data());
} else {
box.check(port.size() == 0,
- "ats_ip_parse(%s) gave port '%.*s'", names[i].hostspec, (int)port.size(), port.data());
+ "ats_ip_parse(%s) gave port '%.*s' instead of empty", s.hostspec, static_cast<int>(port.size()), port.data());
}
+ if (s.rest) {
+ len = strlen(s.rest);
+ box.check(len == rest.size() && strncmp(rest.data(), s.rest, len) == 0
+ , "ats_ip_parse(%s) gave rest '%.*s' instead of '%s'", s.hostspec, static_cast<int>(rest.size()), rest.data(), s.rest);
+ } else {
+ box.check(rest.size() == 0,
+ "ats_ip_parse(%s) gave rest '%.*s' instead of empty", s.hostspec, static_cast<int>(rest.size()), rest.data());
+ }
}
}
@@ -601,6 +620,4 @@ REGRESSION_TEST(Ink_Inet) (RegressionTest * t, int /* atype */, int * pstatus) {
;
}
}
-
-
}