Index: src/url_canon_ip.cc |
diff --git a/src/url_canon_ip.cc b/src/url_canon_ip.cc |
index 46df72bdbb67858909e64ea1b8357333735fb072..1421e79f44b339f337ceaa6e8b7313e83313739a 100644 |
--- a/src/url_canon_ip.cc |
+++ b/src/url_canon_ip.cc |
@@ -181,26 +181,6 @@ CanonHostInfo::Family IPv4ComponentToNumber( |
return CanonHostInfo::IPV4; |
} |
-// Writes the given address (with each character representing one dotted |
-// part of an IPv4 address) to the output, and updating |*out_host| to |
-// identify the added portion. |
-void AppendIPv4Address(const unsigned char address[4], |
- CanonOutput* output, |
- url_parse::Component* out_host) { |
- out_host->begin = output->length(); |
- for (int i = 0; i < 4; i++) { |
- char str[16]; |
- _itoa_s(address[i], str, 10); |
- |
- for (int ch = 0; str[ch] != 0; ch++) |
- output->push_back(str[ch]); |
- |
- if (i != 3) |
- output->push_back('.'); |
- } |
- out_host->len = output->length() - out_host->begin; |
-} |
- |
// See declaration of IPv4AddressToNumber for documentation. |
template<typename CHAR> |
CanonHostInfo::Family DoIPv4AddressToNumber(const CHAR* spec, |
@@ -281,7 +261,9 @@ bool DoCanonicalizeIPv4Address(const CHAR* spec, |
switch (host_info->family) { |
case CanonHostInfo::IPV4: |
// Definitely an IPv4 address. |
- AppendIPv4Address(host_info->address, output, &host_info->out_host); |
+ host_info->out_host.begin = output->length(); |
+ AppendIPv4Address(host_info->address, output); |
+ host_info->out_host.len = output->length() - host_info->out_host.begin; |
return true; |
case CanonHostInfo::BROKEN: |
// Definitely broken. |
@@ -623,13 +605,36 @@ bool DoCanonicalizeIPv6Address(const CHAR* spec, |
host_info->out_host.begin = output->length(); |
output->push_back('['); |
+ AppendIPv6Address(host_info->address, output); |
+ output->push_back(']'); |
+ host_info->out_host.len = output->length() - host_info->out_host.begin; |
+ |
+ host_info->family = CanonHostInfo::IPV6; |
+ return true; |
+} |
- // We will now output the address according to the rules in: |
+} // namespace |
+ |
+void AppendIPv4Address(const unsigned char address[4], CanonOutput* output) { |
+ for (int i = 0; i < 4; i++) { |
+ char str[16]; |
+ _itoa_s(address[i], str, 10); |
+ |
+ for (int ch = 0; str[ch] != 0; ch++) |
+ output->push_back(str[ch]); |
+ |
+ if (i != 3) |
+ output->push_back('.'); |
+ } |
+} |
+ |
+void AppendIPv6Address(const unsigned char address[16], CanonOutput* output) { |
+ // We will output the address according to the rules in: |
// http://tools.ietf.org/html/draft-kawamura-ipv6-text-representation-01#section-4 |
// Start by finding where to place the "::" contraction (if any). |
url_parse::Component contraction_range; |
- ChooseIPv6ContractionRange(host_info->address, &contraction_range); |
+ ChooseIPv6ContractionRange(address, &contraction_range); |
for (int i = 0; i <= 14;) { |
// We check 2 bytes at a time, from bytes (0, 1) to (14, 15), inclusive. |
@@ -641,8 +646,8 @@ bool DoCanonicalizeIPv6Address(const CHAR* spec, |
output->push_back(':'); |
i = contraction_range.end(); |
} else { |
- // Consume the next 16 bits from |host_info->address|. |
- int x = host_info->address[i] << 8 | host_info->address[i + 1]; |
+ // Consume the next 16 bits from |address|. |
+ int x = address[i] << 8 | address[i + 1]; |
i += 2; |
@@ -657,16 +662,8 @@ bool DoCanonicalizeIPv6Address(const CHAR* spec, |
output->push_back(':'); |
} |
} |
- |
- output->push_back(']'); |
- host_info->out_host.len = output->length() - host_info->out_host.begin; |
- |
- host_info->family = CanonHostInfo::IPV6; |
- return true; |
} |
-} // namespace |
- |
bool FindIPv4Components(const char* spec, |
const url_parse::Component& host, |
url_parse::Component components[4]) { |
@@ -730,5 +727,4 @@ bool IPv6AddressToNumber(const char16* spec, |
return DoIPv6AddressToNumber<char16, char16>(spec, host, address); |
} |
- |
} // namespace url_canon |