Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1121)

Side by Side Diff: net/base/net_util.cc

Issue 113944: Use the new CanonicalizeHostVerbose() function. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: is_valid -> is_nonempty Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.h ('k') | net/base/registry_controlled_domain.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <unicode/ucnv.h> 6 #include <unicode/ucnv.h>
7 #include <unicode/uidna.h> 7 #include <unicode/uidna.h>
8 #include <unicode/ulocdata.h> 8 #include <unicode/ulocdata.h>
9 #include <unicode/uniset.h> 9 #include <unicode/uniset.h>
10 #include <unicode/uscript.h> 10 #include <unicode/uscript.h>
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 cur_begin = next_dot + 1; 822 cur_begin = next_dot + 1;
823 } 823 }
824 824
825 #if defined(WCHAR_T_IS_UTF32) 825 #if defined(WCHAR_T_IS_UTF32)
826 UTF16ToWide(out16.data(), out16.length(), out); 826 UTF16ToWide(out16.data(), out16.length(), out);
827 #elif defined(WCHAR_T_IS_UTF16) 827 #elif defined(WCHAR_T_IS_UTF16)
828 out->swap(out16); 828 out->swap(out16);
829 #endif 829 #endif
830 } 830 }
831 831
832 std::string CanonicalizeHost(const std::string& host, bool* is_ip_address) { 832 std::string CanonicalizeHost(const std::string& host,
833 url_canon::CanonHostInfo* host_info) {
833 // Try to canonicalize the host. 834 // Try to canonicalize the host.
834 const url_parse::Component raw_host_component(0, 835 const url_parse::Component raw_host_component(
835 static_cast<int>(host.length())); 836 0, static_cast<int>(host.length()));
836 std::string canon_host; 837 std::string canon_host;
837 url_canon::StdStringCanonOutput canon_host_output(&canon_host); 838 url_canon::StdStringCanonOutput canon_host_output(&canon_host);
838 url_parse::Component canon_host_component; 839 url_canon::CanonicalizeHostVerbose(host.c_str(), raw_host_component,
839 if (!url_canon::CanonicalizeHost(host.c_str(), raw_host_component, 840 &canon_host_output, host_info);
840 &canon_host_output, &canon_host_component)) {
841 if (is_ip_address)
842 *is_ip_address = false;
843 return std::string();
844 }
845 canon_host_output.Complete();
846 841
847 if (is_ip_address) { 842 if (host_info->out_host.is_nonempty() &&
848 // See if the host is an IP address. 843 host_info->family != url_canon::CanonHostInfo::BROKEN) {
849 url_canon::RawCanonOutputT<char, 128> ignored_output; 844 // Success! Assert that there's no extra garbage.
850 url_parse::Component ignored_component; 845 canon_host_output.Complete();
851 *is_ip_address = url_canon::CanonicalizeIPAddress(canon_host.c_str(), 846 DCHECK_EQ(host_info->out_host.len, static_cast<int>(canon_host.length()));
852 canon_host_component, 847 } else {
853 &ignored_output, 848 // Empty host, or canonicalization failed. We'll return empty.
854 &ignored_component); 849 canon_host.clear();
855 } 850 }
856 851
857 // Return the host as a string, stripping any unnecessary bits off the ends. 852 return canon_host;
858 if ((canon_host_component.begin == 0) &&
859 (static_cast<size_t>(canon_host_component.len) == canon_host.length()))
860 return canon_host;
861 return canon_host.substr(canon_host_component.begin,
862 canon_host_component.len);
863 } 853 }
864 854
865 std::string CanonicalizeHost(const std::wstring& host, bool* is_ip_address) { 855 std::string CanonicalizeHost(const std::wstring& host,
856 url_canon::CanonHostInfo* host_info) {
866 std::string converted_host; 857 std::string converted_host;
867 WideToUTF8(host.c_str(), host.length(), &converted_host); 858 WideToUTF8(host.c_str(), host.length(), &converted_host);
868 return CanonicalizeHost(converted_host, is_ip_address); 859 return CanonicalizeHost(converted_host, host_info);
869 } 860 }
870 861
871 std::string GetDirectoryListingHeader(const std::string& title) { 862 std::string GetDirectoryListingHeader(const std::string& title) {
872 static const StringPiece header(NetModule::GetResource(IDR_DIR_HEADER_HTML)); 863 static const StringPiece header(NetModule::GetResource(IDR_DIR_HEADER_HTML));
873 if (header.empty()) { 864 if (header.empty()) {
874 NOTREACHED() << "expected resource not found"; 865 NOTREACHED() << "expected resource not found";
875 } 866 }
876 std::string result(header.data(), header.size()); 867 std::string result(header.data(), header.size());
877 868
878 result.append("<script>start("); 869 result.append("<script>start(");
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 url_string.append(UTF8ToWide(std::string(&spec[parsed.ref.begin], 1235 url_string.append(UTF8ToWide(std::string(&spec[parsed.ref.begin],
1245 parsed.ref.len))); 1236 parsed.ref.len)));
1246 new_parsed->ref.begin = begin; 1237 new_parsed->ref.begin = begin;
1247 new_parsed->ref.len = url_string.length() - begin; 1238 new_parsed->ref.len = url_string.length() - begin;
1248 } 1239 }
1249 1240
1250 return url_string; 1241 return url_string;
1251 } 1242 }
1252 1243
1253 } // namespace net 1244 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util.h ('k') | net/base/registry_controlled_domain.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698