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

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

Issue 201033: ForceTLS: hash hostnames, handle subdomains, canonicalise. (Closed)
Patch Set: ... Created 11 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/base/dns_util.h"
6
7 namespace net {
8
9 // Based on DJB's public domain code.
10 bool DNSDomainFromDot(const std::string& dotted, std::string* out) {
11 const char* buf = dotted.data();
12 unsigned n = dotted.size();
13 char label[63];
14 unsigned int labellen = 0; /* <= sizeof label */
15 char name[255];
16 unsigned int namelen = 0; /* <= sizeof name */
17 char ch;
18
19 for (;;) {
20 if (!n)
21 break;
22 ch = *buf++;
23 --n;
24 if (ch == '.') {
25 if (labellen) {
26 if (namelen + labellen + 1 > sizeof name)
27 return false;
28 name[namelen++] = labellen;
29 memcpy(name + namelen, label, labellen);
30 namelen += labellen;
31 labellen = 0;
32 }
33 continue;
34 }
35 if (labellen >= sizeof label)
36 return false;
37 label[labellen++] = ch;
38 }
39
40 if (labellen) {
41 if (namelen + labellen + 1 > sizeof name)
42 return false;
43 name[namelen++] = labellen;
44 memcpy(name + namelen, label, labellen);
45 namelen += labellen;
46 labellen = 0;
47 }
48
49 if (namelen + 1 > sizeof name)
50 return false;
51 name[namelen++] = 0;
52
53 *out = name;
54 return true;
55 }
56
57 bool IsSTD3ASCIIValidCharacter(char c) {
58 if (c <= 0x2c)
59 return false;
60 if (c >= 0x7b)
61 return false;
62 if (c >= 0x2e && c <= 0x2f)
63 return false;
64 if (c >= 0x3a && c <= 0x40)
65 return false;
66 if (c >= 0x5b && c <= 0x60)
67 return false;
68 return true;
69 }
70
71 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698