OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/dns/dns_transaction.h" | 5 #include "net/dns/dns_transaction.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
22 #include "base/threading/non_thread_safe.h" | 22 #include "base/threading/non_thread_safe.h" |
23 #include "base/timer/timer.h" | 23 #include "base/timer/timer.h" |
24 #include "base/values.h" | 24 #include "base/values.h" |
25 #include "net/base/completion_callback.h" | 25 #include "net/base/completion_callback.h" |
26 #include "net/base/dns_util.h" | 26 #include "net/base/dns_util.h" |
27 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
28 #include "net/base/ip_endpoint.h" | 28 #include "net/base/ip_endpoint.h" |
29 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
30 #include "net/base/net_log.h" | 30 #include "net/base/net_log.h" |
31 #include "net/base/net_util.h" | |
31 #include "net/dns/dns_protocol.h" | 32 #include "net/dns/dns_protocol.h" |
32 #include "net/dns/dns_query.h" | 33 #include "net/dns/dns_query.h" |
33 #include "net/dns/dns_response.h" | 34 #include "net/dns/dns_response.h" |
34 #include "net/dns/dns_session.h" | 35 #include "net/dns/dns_session.h" |
35 #include "net/socket/stream_socket.h" | 36 #include "net/socket/stream_socket.h" |
36 #include "net/udp/datagram_client_socket.h" | 37 #include "net/udp/datagram_client_socket.h" |
37 | 38 |
38 namespace net { | 39 namespace net { |
39 | 40 |
40 namespace { | 41 namespace { |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 AttemptResult(int rv, const DnsAttempt* attempt) | 610 AttemptResult(int rv, const DnsAttempt* attempt) |
610 : rv(rv), attempt(attempt) {} | 611 : rv(rv), attempt(attempt) {} |
611 | 612 |
612 int rv; | 613 int rv; |
613 const DnsAttempt* attempt; | 614 const DnsAttempt* attempt; |
614 }; | 615 }; |
615 | 616 |
616 // Prepares |qnames_| according to the DnsConfig. | 617 // Prepares |qnames_| according to the DnsConfig. |
617 int PrepareSearch() { | 618 int PrepareSearch() { |
618 const DnsConfig& config = session_->config(); | 619 const DnsConfig& config = session_->config(); |
620 // Redirect .localhost queries to localhost to make sure that they are | |
Deprecated (see juliatuttle)
2015/02/24 16:39:23
Nit: "to localhost.", since you're including the t
estark
2015/02/26 07:58:53
fixed in the place where this comment has been rel
| |
621 // never sent out on the network, per RFC 6761. | |
622 const std::string hostname = | |
623 (IsLocalhostTLD(hostname_) ? "localhost." : hostname_); | |
619 | 624 |
620 std::string labeled_hostname; | 625 std::string labeled_hostname; |
621 if (!DNSDomainFromDot(hostname_, &labeled_hostname)) | 626 if (!DNSDomainFromDot(hostname, &labeled_hostname)) |
622 return ERR_INVALID_ARGUMENT; | 627 return ERR_INVALID_ARGUMENT; |
623 | 628 |
624 if (hostname_[hostname_.size() - 1] == '.') { | 629 if (hostname[hostname.size() - 1] == '.') { |
625 // It's a fully-qualified name, no suffix search. | 630 // It's a fully-qualified name, no suffix search. |
626 qnames_.push_back(labeled_hostname); | 631 qnames_.push_back(labeled_hostname); |
627 return OK; | 632 return OK; |
628 } | 633 } |
629 | 634 |
630 int ndots = CountLabels(labeled_hostname) - 1; | 635 int ndots = CountLabels(labeled_hostname) - 1; |
631 | 636 |
632 if (ndots > 0 && !config.append_to_multi_label_name) { | 637 if (ndots > 0 && !config.append_to_multi_label_name) { |
633 qnames_.push_back(labeled_hostname); | 638 qnames_.push_back(labeled_hostname); |
634 return OK; | 639 return OK; |
635 } | 640 } |
636 | 641 |
637 // Set true when |labeled_hostname| is put on the list. | 642 // Set true when |labeled_hostname| is put on the list. |
638 bool had_hostname = false; | 643 bool had_hostname = false; |
639 | 644 |
640 if (ndots >= config.ndots) { | 645 if (ndots >= config.ndots) { |
641 qnames_.push_back(labeled_hostname); | 646 qnames_.push_back(labeled_hostname); |
642 had_hostname = true; | 647 had_hostname = true; |
643 } | 648 } |
644 | 649 |
645 std::string qname; | 650 std::string qname; |
646 for (size_t i = 0; i < config.search.size(); ++i) { | 651 for (size_t i = 0; i < config.search.size(); ++i) { |
647 // Ignore invalid (too long) combinations. | 652 // Ignore invalid (too long) combinations. |
648 if (!DNSDomainFromDot(hostname_ + "." + config.search[i], &qname)) | 653 if (!DNSDomainFromDot(hostname + "." + config.search[i], &qname)) |
649 continue; | 654 continue; |
650 if (qname.size() == labeled_hostname.size()) { | 655 if (qname.size() == labeled_hostname.size()) { |
651 if (had_hostname) | 656 if (had_hostname) |
652 continue; | 657 continue; |
653 had_hostname = true; | 658 had_hostname = true; |
654 } | 659 } |
655 qnames_.push_back(qname); | 660 qnames_.push_back(qname); |
656 } | 661 } |
657 | 662 |
658 if (ndots > 0 && !had_hostname) | 663 if (ndots > 0 && !had_hostname) |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 } // namespace | 987 } // namespace |
983 | 988 |
984 // static | 989 // static |
985 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( | 990 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( |
986 DnsSession* session) { | 991 DnsSession* session) { |
987 return scoped_ptr<DnsTransactionFactory>( | 992 return scoped_ptr<DnsTransactionFactory>( |
988 new DnsTransactionFactoryImpl(session)); | 993 new DnsTransactionFactoryImpl(session)); |
989 } | 994 } |
990 | 995 |
991 } // namespace net | 996 } // namespace net |
OLD | NEW |