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

Side by Side Diff: webrtc/base/proxydetect.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 #define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001 149 #define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001
150 #define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002 150 #define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002
151 #define WINHTTP_AUTOPROXY_RUN_INPROCESS 0x00010000 151 #define WINHTTP_AUTOPROXY_RUN_INPROCESS 0x00010000
152 #define WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY 0x00020000 152 #define WINHTTP_AUTOPROXY_RUN_OUTPROCESS_ONLY 0x00020000
153 #define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001 153 #define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001
154 #define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002 154 #define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002
155 #define WINHTTP_ACCESS_TYPE_DEFAULT_PROXY 0 155 #define WINHTTP_ACCESS_TYPE_DEFAULT_PROXY 0
156 #define WINHTTP_ACCESS_TYPE_NO_PROXY 1 156 #define WINHTTP_ACCESS_TYPE_NO_PROXY 1
157 #define WINHTTP_ACCESS_TYPE_NAMED_PROXY 3 157 #define WINHTTP_ACCESS_TYPE_NAMED_PROXY 3
158 #define WINHTTP_NO_PROXY_NAME NULL 158 #define WINHTTP_NO_PROXY_NAME nullptr
159 #define WINHTTP_NO_PROXY_BYPASS NULL 159 #define WINHTTP_NO_PROXY_BYPASS nullptr
160 160
161 #endif // _TRY_WINHTTP 161 #endif // _TRY_WINHTTP
162 162
163 #if _TRY_JSPROXY 163 #if _TRY_JSPROXY
164 extern "C" { 164 extern "C" {
165 typedef BOOL (STDAPICALLTYPE * pfnInternetGetProxyInfo) 165 typedef BOOL (STDAPICALLTYPE * pfnInternetGetProxyInfo)
166 ( 166 (
167 LPCSTR lpszUrl, 167 LPCSTR lpszUrl,
168 DWORD dwUrlLength, 168 DWORD dwUrlLength,
169 LPSTR lpszUrlHostName, 169 LPSTR lpszUrlHostName,
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 path->SetFolder(ToUtf8(w_path, wcslen(w_path))); 394 path->SetFolder(ToUtf8(w_path, wcslen(w_path)));
395 path->AppendFolder("Mozilla"); 395 path->AppendFolder("Mozilla");
396 path->AppendFolder("Firefox"); 396 path->AppendFolder("Firefox");
397 #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 397 #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
398 rtc::UnixFilesystem filesystem; 398 rtc::UnixFilesystem filesystem;
399 filesystem.SetApplicationName("Firefox"); 399 filesystem.SetApplicationName("Firefox");
400 bool result = filesystem.GetAppDataFolder(path, true); 400 bool result = filesystem.GetAppDataFolder(path, true);
401 return result; 401 return result;
402 #else 402 #else
403 char* user_home = getenv("HOME"); 403 char* user_home = getenv("HOME");
404 if (user_home == NULL) { 404 if (user_home == nullptr) {
405 return false; 405 return false;
406 } 406 }
407 path->SetFolder(std::string(user_home)); 407 path->SetFolder(std::string(user_home));
408 path->AppendFolder(".mozilla"); 408 path->AppendFolder(".mozilla");
409 path->AppendFolder("firefox"); 409 path->AppendFolder("firefox");
410 #endif // WEBRTC_WIN 410 #endif // WEBRTC_WIN
411 return true; 411 return true;
412 } 412 }
413 413
414 bool GetDefaultFirefoxProfile(Pathname* profile_path) { 414 bool GetDefaultFirefoxProfile(Pathname* profile_path) {
415 RTC_DCHECK(NULL != profile_path); 415 RTC_DCHECK(nullptr != profile_path);
416 Pathname path; 416 Pathname path;
417 if (!GetFirefoxProfilePath(&path)) { 417 if (!GetFirefoxProfilePath(&path)) {
418 return false; 418 return false;
419 } 419 }
420 420
421 #if USE_FIREFOX_PROFILES_INI 421 #if USE_FIREFOX_PROFILES_INI
422 // [Profile0] 422 // [Profile0]
423 // Name=default 423 // Name=default
424 // IsRelative=1 424 // IsRelative=1
425 // Path=Profiles/2de53ejb.default 425 // Path=Profiles/2de53ejb.default
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 616
617 bool IsDefaultBrowserFirefox() { 617 bool IsDefaultBrowserFirefox() {
618 HKEY key; 618 HKEY key;
619 LONG result = RegOpenKeyEx(HKEY_CLASSES_ROOT, L"http\\shell\\open\\command", 619 LONG result = RegOpenKeyEx(HKEY_CLASSES_ROOT, L"http\\shell\\open\\command",
620 0, KEY_READ, &key); 620 0, KEY_READ, &key);
621 if (ERROR_SUCCESS != result) 621 if (ERROR_SUCCESS != result)
622 return false; 622 return false;
623 623
624 DWORD size, type; 624 DWORD size, type;
625 bool success = false; 625 bool success = false;
626 result = RegQueryValueEx(key, L"", 0, &type, NULL, &size); 626 result = RegQueryValueEx(key, L"", 0, &type, nullptr, &size);
627 if (result == ERROR_SUCCESS && type == REG_SZ) { 627 if (result == ERROR_SUCCESS && type == REG_SZ) {
628 wchar_t* value = new wchar_t[size+1]; 628 wchar_t* value = new wchar_t[size+1];
629 BYTE* buffer = reinterpret_cast<BYTE*>(value); 629 BYTE* buffer = reinterpret_cast<BYTE*>(value);
630 result = RegQueryValueEx(key, L"", 0, &type, buffer, &size); 630 result = RegQueryValueEx(key, L"", 0, &type, buffer, &size);
631 if (result == ERROR_SUCCESS) { 631 if (result == ERROR_SUCCESS) {
632 // Size returned by RegQueryValueEx is in bytes, convert to number of 632 // Size returned by RegQueryValueEx is in bytes, convert to number of
633 // wchar_t's. 633 // wchar_t's.
634 size /= sizeof(value[0]); 634 size /= sizeof(value[0]);
635 value[size] = L'\0'; 635 value[size] = L'\0';
636 for (size_t i = 0; i < size; ++i) { 636 for (size_t i = 0; i < size; ++i) {
637 value[i] = tolowercase(value[i]); 637 value[i] = tolowercase(value[i]);
638 } 638 }
639 success = (NULL != strstr(value, L"firefox.exe")); 639 success = (nullptr != strstr(value, L"firefox.exe"));
640 } 640 }
641 delete[] value; 641 delete[] value;
642 } 642 }
643 643
644 RegCloseKey(key); 644 RegCloseKey(key);
645 return success; 645 return success;
646 } 646 }
647 647
648 bool GetWinHttpProxySettings(const char* url, ProxyInfo* proxy) { 648 bool GetWinHttpProxySettings(const char* url, ProxyInfo* proxy) {
649 HMODULE winhttp_handle = LoadLibrary(L"winhttp.dll"); 649 HMODULE winhttp_handle = LoadLibrary(L"winhttp.dll");
650 if (winhttp_handle == NULL) { 650 if (winhttp_handle == nullptr) {
651 LOG(LS_ERROR) << "Failed to load winhttp.dll."; 651 LOG(LS_ERROR) << "Failed to load winhttp.dll.";
652 return false; 652 return false;
653 } 653 }
654 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG iecfg; 654 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG iecfg;
655 memset(&iecfg, 0, sizeof(iecfg)); 655 memset(&iecfg, 0, sizeof(iecfg));
656 Url<char> purl(url); 656 Url<char> purl(url);
657 pfnWinHttpGetIEProxyConfig pWHGIEPC = 657 pfnWinHttpGetIEProxyConfig pWHGIEPC =
658 reinterpret_cast<pfnWinHttpGetIEProxyConfig>( 658 reinterpret_cast<pfnWinHttpGetIEProxyConfig>(
659 GetProcAddress(winhttp_handle, 659 GetProcAddress(winhttp_handle,
660 "WinHttpGetIEProxyConfigForCurrentUser")); 660 "WinHttpGetIEProxyConfigForCurrentUser"));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 // fetch the config file first, and if that fails we'll perform an auto 692 // fetch the config file first, and if that fails we'll perform an auto
693 // detection. 693 // detection.
694 // 694 //
695 // Returns true if we successfully performed an auto detection not depending on 695 // Returns true if we successfully performed an auto detection not depending on
696 // whether we found a proxy or not. Returns false on error. 696 // whether we found a proxy or not. Returns false on error.
697 bool WinHttpAutoDetectProxyForUrl(const char* agent, const char* url, 697 bool WinHttpAutoDetectProxyForUrl(const char* agent, const char* url,
698 ProxyInfo* proxy) { 698 ProxyInfo* proxy) {
699 Url<char> purl(url); 699 Url<char> purl(url);
700 bool success = true; 700 bool success = true;
701 HMODULE winhttp_handle = LoadLibrary(L"winhttp.dll"); 701 HMODULE winhttp_handle = LoadLibrary(L"winhttp.dll");
702 if (winhttp_handle == NULL) { 702 if (winhttp_handle == nullptr) {
703 LOG(LS_ERROR) << "Failed to load winhttp.dll."; 703 LOG(LS_ERROR) << "Failed to load winhttp.dll.";
704 return false; 704 return false;
705 } 705 }
706 pfnWinHttpOpen pWHO = 706 pfnWinHttpOpen pWHO =
707 reinterpret_cast<pfnWinHttpOpen>(GetProcAddress(winhttp_handle, 707 reinterpret_cast<pfnWinHttpOpen>(GetProcAddress(winhttp_handle,
708 "WinHttpOpen")); 708 "WinHttpOpen"));
709 pfnWinHttpCloseHandle pWHCH = 709 pfnWinHttpCloseHandle pWHCH =
710 reinterpret_cast<pfnWinHttpCloseHandle>( 710 reinterpret_cast<pfnWinHttpCloseHandle>(
711 GetProcAddress(winhttp_handle, "WinHttpCloseHandle")); 711 GetProcAddress(winhttp_handle, "WinHttpCloseHandle"));
712 pfnWinHttpGetProxyForUrl pWHGPFU = 712 pfnWinHttpGetProxyForUrl pWHGPFU =
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 bool result = false; 954 bool result = false;
955 955
956 // we use this as a scratch variable for determining if operations 956 // we use this as a scratch variable for determining if operations
957 // succeeded. 957 // succeeded.
958 bool converted = false; 958 bool converted = false;
959 959
960 // the data we need to construct the SocketAddress for the proxy. 960 // the data we need to construct the SocketAddress for the proxy.
961 std::string hostname; 961 std::string hostname;
962 int port; 962 int port;
963 963
964 if ((proxyDict != NULL) && 964 if ((proxyDict != nullptr) &&
965 (CFGetTypeID(proxyDict) == CFDictionaryGetTypeID())) { 965 (CFGetTypeID(proxyDict) == CFDictionaryGetTypeID())) {
966 // CoreFoundation stuff that we'll have to get from 966 // CoreFoundation stuff that we'll have to get from
967 // the dictionaries and interpret or convert into more usable formats. 967 // the dictionaries and interpret or convert into more usable formats.
968 CFNumberRef enabledCFNum; 968 CFNumberRef enabledCFNum;
969 CFNumberRef portCFNum; 969 CFNumberRef portCFNum;
970 CFStringRef hostCFStr; 970 CFStringRef hostCFStr;
971 971
972 enabledCFNum = (CFNumberRef)CFDictionaryGetValue(proxyDict, enabledKey); 972 enabledCFNum = (CFNumberRef)CFDictionaryGetValue(proxyDict, enabledKey);
973 973
974 if (p_isCFNumberTrue(enabledCFNum)) { 974 if (p_isCFNumberTrue(enabledCFNum)) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 attributes[1].data = &port; 1070 attributes[1].data = &port;
1071 1071
1072 std::string ip = proxy->address.ipaddr().ToString(); 1072 std::string ip = proxy->address.ipaddr().ToString();
1073 attributes[2].tag = kSecServerItemAttr; 1073 attributes[2].tag = kSecServerItemAttr;
1074 attributes[2].length = ip.length(); 1074 attributes[2].length = ip.length();
1075 attributes[2].data = const_cast<char*>(ip.c_str()); 1075 attributes[2].data = const_cast<char*>(ip.c_str());
1076 1076
1077 if (result) { 1077 if (result) {
1078 LOG(LS_INFO) << "trying to get proxy username/password"; 1078 LOG(LS_INFO) << "trying to get proxy username/password";
1079 SecKeychainSearchRef sref; 1079 SecKeychainSearchRef sref;
1080 oss = SecKeychainSearchCreateFromAttributes(NULL, 1080 oss = SecKeychainSearchCreateFromAttributes(
1081 kSecInternetPasswordItemClass, 1081 nullptr, kSecInternetPasswordItemClass, &attrList, &sref);
1082 &attrList, &sref);
1083 if (0 == oss) { 1082 if (0 == oss) {
1084 LOG(LS_INFO) << "SecKeychainSearchCreateFromAttributes was good"; 1083 LOG(LS_INFO) << "SecKeychainSearchCreateFromAttributes was good";
1085 // Get the first item, if there is one. 1084 // Get the first item, if there is one.
1086 SecKeychainItemRef iref; 1085 SecKeychainItemRef iref;
1087 oss = SecKeychainSearchCopyNext(sref, &iref); 1086 oss = SecKeychainSearchCopyNext(sref, &iref);
1088 if (0 == oss) { 1087 if (0 == oss) {
1089 LOG(LS_INFO) << "...looks like we have the username/password data"; 1088 LOG(LS_INFO) << "...looks like we have the username/password data";
1090 // If there is, get the username and the password. 1089 // If there is, get the username and the password.
1091 1090
1092 SecKeychainAttributeInfo attribsToGet; 1091 SecKeychainAttributeInfo attribsToGet;
1093 attribsToGet.count = 1; 1092 attribsToGet.count = 1;
1094 UInt32 tag = kSecAccountItemAttr; 1093 UInt32 tag = kSecAccountItemAttr;
1095 UInt32 format = CSSM_DB_ATTRIBUTE_FORMAT_STRING; 1094 UInt32 format = CSSM_DB_ATTRIBUTE_FORMAT_STRING;
1096 void *data; 1095 void *data;
1097 UInt32 length; 1096 UInt32 length;
1098 SecKeychainAttributeList *localList; 1097 SecKeychainAttributeList *localList;
1099 1098
1100 attribsToGet.tag = &tag; 1099 attribsToGet.tag = &tag;
1101 attribsToGet.format = &format; 1100 attribsToGet.format = &format;
1102 OSStatus copyres = SecKeychainItemCopyAttributesAndData(iref, 1101 OSStatus copyres = SecKeychainItemCopyAttributesAndData(
1103 &attribsToGet, 1102 iref, &attribsToGet, nullptr, &localList, &length, &data);
1104 NULL,
1105 &localList,
1106 &length,
1107 &data);
1108 if (0 == copyres) { 1103 if (0 == copyres) {
1109 LOG(LS_INFO) << "...and we can pull it out."; 1104 LOG(LS_INFO) << "...and we can pull it out.";
1110 // now, we know from experimentation (sadly not from docs) 1105 // now, we know from experimentation (sadly not from docs)
1111 // that the username is in the local attribute list, 1106 // that the username is in the local attribute list,
1112 // and the password in the data, 1107 // and the password in the data,
1113 // both without null termination but with info on their length. 1108 // both without null termination but with info on their length.
1114 // grab the password from the data. 1109 // grab the password from the data.
1115 std::string password; 1110 std::string password;
1116 password.append(static_cast<const char*>(data), length); 1111 password.append(static_cast<const char*>(data), length);
1117 1112
(...skipping 30 matching lines...) Expand all
1148 result = false; 1143 result = false;
1149 } 1144 }
1150 } 1145 }
1151 1146
1152 return result; 1147 return result;
1153 } 1148 }
1154 1149
1155 bool GetMacProxySettings(ProxyInfo* proxy) { 1150 bool GetMacProxySettings(ProxyInfo* proxy) {
1156 // based on the Apple Technical Q&A QA1234 1151 // based on the Apple Technical Q&A QA1234
1157 // http://developer.apple.com/qa/qa2001/qa1234.html 1152 // http://developer.apple.com/qa/qa2001/qa1234.html
1158 CFDictionaryRef proxyDict = SCDynamicStoreCopyProxies(NULL); 1153 CFDictionaryRef proxyDict = SCDynamicStoreCopyProxies(nullptr);
1159 bool result = false; 1154 bool result = false;
1160 1155
1161 if (proxyDict != NULL) { 1156 if (proxyDict != nullptr) {
1162 // sending it off to another function makes it easier to unit test 1157 // sending it off to another function makes it easier to unit test
1163 // since we can make our own dictionary to hand to that function. 1158 // since we can make our own dictionary to hand to that function.
1164 result = GetMacProxySettingsFromDictionary(proxy, proxyDict); 1159 result = GetMacProxySettingsFromDictionary(proxy, proxyDict);
1165 1160
1166 if (result) { 1161 if (result) {
1167 result = p_putPasswordInProxyInfo(proxy); 1162 result = p_putPasswordInProxyInfo(proxy);
1168 } 1163 }
1169 1164
1170 CFRelease(proxyDict); 1165 CFRelease(proxyDict);
1171 } else { 1166 } else {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 if (!result) { 1278 if (!result) {
1284 // Either auto detection is not supported or we simply didn't 1279 // Either auto detection is not supported or we simply didn't
1285 // find any proxy, reset type. 1280 // find any proxy, reset type.
1286 proxy->type = rtc::PROXY_NONE; 1281 proxy->type = rtc::PROXY_NONE;
1287 } 1282 }
1288 } 1283 }
1289 return result; 1284 return result;
1290 } 1285 }
1291 1286
1292 } // namespace rtc 1287 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698