blob: 4df37a47b0b1a1b43e10056c1a78b58585fa6781 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/proxy/proxy_server.h"
#include <CoreFoundation/CoreFoundation.h>
#include <string>
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/sys_string_conversions.h"
namespace net {
// static
ProxyServer ProxyServer::FromDictionary(Scheme scheme,
CFDictionaryRef dict,
CFStringRef host_key,
CFStringRef port_key) {
if (scheme == SCHEME_INVALID || scheme == SCHEME_DIRECT) {
// No hostname port to extract; we are done.
return ProxyServer(scheme, HostPortPair());
}
CFStringRef host_ref =
(CFStringRef)base::mac::GetValueFromDictionary(dict, host_key,
CFStringGetTypeID());
if (!host_ref) {
LOG(WARNING) << "Could not find expected key "
<< base::SysCFStringRefToUTF8(host_key)
<< " in the proxy dictionary";
return ProxyServer(); // Invalid.
}
std::string host = base::SysCFStringRefToUTF8(host_ref);
CFNumberRef port_ref =
(CFNumberRef)base::mac::GetValueFromDictionary(dict, port_key,
CFNumberGetTypeID());
int port;
if (port_ref) {
CFNumberGetValue(port_ref, kCFNumberIntType, &port);
} else {
port = GetDefaultPortForScheme(scheme);
}
return ProxyServer(scheme, HostPortPair(host, port));
}
} // namespace net
|