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

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

Issue 6500010: HSTS: add net-internals UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 10 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "net/base/dns_util.h" 5 #include "net/base/dns_util.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 namespace net { 9 namespace net {
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 if (namelen + 1 > sizeof name) 51 if (namelen + 1 > sizeof name)
52 return false; 52 return false;
53 name[namelen++] = 0; // This is the root label (of length 0). 53 name[namelen++] = 0; // This is the root label (of length 0).
54 54
55 *out = std::string(name, namelen); 55 *out = std::string(name, namelen);
56 return true; 56 return true;
57 } 57 }
58 58
59 std::string DNSDomainToString(const std::string& domain) {
60 std::string ret;
61
62 for (unsigned i = 0; i < domain.size() && domain[i]; i += domain[i] + 1) {
63 if (domain[i] < 0 || domain[i] > 63)
64 return "";
eroman 2011/02/17 00:48:28 I recommend adding a test case for one of the bad
agl 2011/02/17 17:21:30 Done.
65
66 if (i)
67 ret += ".";
68
69 if (static_cast<unsigned>(domain[i]) + i + 1 > domain.size())
70 return "";
71
72 ret += domain.substr(i + 1, domain[i]);
73 }
74 return ret;
75 }
76
59 bool IsSTD3ASCIIValidCharacter(char c) { 77 bool IsSTD3ASCIIValidCharacter(char c) {
60 if (c <= 0x2c) 78 if (c <= 0x2c)
61 return false; 79 return false;
62 if (c >= 0x7b) 80 if (c >= 0x7b)
63 return false; 81 return false;
64 if (c >= 0x2e && c <= 0x2f) 82 if (c >= 0x2e && c <= 0x2f)
65 return false; 83 return false;
66 if (c >= 0x3a && c <= 0x40) 84 if (c >= 0x3a && c <= 0x40)
67 return false; 85 return false;
68 if (c >= 0x5b && c <= 0x60) 86 if (c >= 0x5b && c <= 0x60)
69 return false; 87 return false;
70 return true; 88 return true;
71 } 89 }
72 90
73 std::string TrimEndingDot(const std::string& host) { 91 std::string TrimEndingDot(const std::string& host) {
74 std::string host_trimmed = host; 92 std::string host_trimmed = host;
75 size_t len = host_trimmed.length(); 93 size_t len = host_trimmed.length();
76 if (len > 1 && host_trimmed[len - 1] == '.') 94 if (len > 1 && host_trimmed[len - 1] == '.')
77 host_trimmed.erase(len - 1); 95 host_trimmed.erase(len - 1);
78 return host_trimmed; 96 return host_trimmed;
79 } 97 }
80 98
81 } // namespace net 99 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698