Reformat the WebRTC code base
Running clang-format with chromium's style guide.
The goal is n-fold:
* providing consistency and readability (that's what code guidelines are for)
* preventing noise with presubmit checks and git cl format
* building on the previous point: making it easier to automatically fix format issues
* you name it
Please consider using git-hyper-blame to ignore this commit.
Bug: webrtc:9340
Change-Id: I694567c4cdf8cee2860958cfe82bfaf25848bb87
Reviewed-on: https://webrtc-review.googlesource.com/81185
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23660}
diff --git a/rtc_base/httpcommon.cc b/rtc_base/httpcommon.cc
index f23cb63..5ac1e42 100644
--- a/rtc_base/httpcommon.cc
+++ b/rtc_base/httpcommon.cc
@@ -47,7 +47,10 @@
// int err = LibraryFunc();
// LOG(LS_ERROR) << "LibraryFunc returned: "
// << GetErrorName(err, LIBRARY_ERRORS);
-struct ConstantToLabel { int value; const char * label; };
+struct ConstantToLabel {
+ int value;
+ const char* label;
+};
const char* LookupLabel(int value, const ConstantToLabel entries[]) {
for (int i = 0; entries[i].label; ++i) {
@@ -72,35 +75,36 @@
return buffer;
}
-#define KLABEL(x) { x, #x }
-#define LASTLABEL { 0, 0 }
+#define KLABEL(x) \
+ { x, #x }
+#define LASTLABEL \
+ { 0, 0 }
const ConstantToLabel SECURITY_ERRORS[] = {
- KLABEL(SEC_I_COMPLETE_AND_CONTINUE),
- KLABEL(SEC_I_COMPLETE_NEEDED),
- KLABEL(SEC_I_CONTEXT_EXPIRED),
- KLABEL(SEC_I_CONTINUE_NEEDED),
- KLABEL(SEC_I_INCOMPLETE_CREDENTIALS),
- KLABEL(SEC_I_RENEGOTIATE),
- KLABEL(SEC_E_CERT_EXPIRED),
- KLABEL(SEC_E_INCOMPLETE_MESSAGE),
- KLABEL(SEC_E_INSUFFICIENT_MEMORY),
- KLABEL(SEC_E_INTERNAL_ERROR),
- KLABEL(SEC_E_INVALID_HANDLE),
- KLABEL(SEC_E_INVALID_TOKEN),
- KLABEL(SEC_E_LOGON_DENIED),
- KLABEL(SEC_E_NO_AUTHENTICATING_AUTHORITY),
- KLABEL(SEC_E_NO_CREDENTIALS),
- KLABEL(SEC_E_NOT_OWNER),
- KLABEL(SEC_E_OK),
- KLABEL(SEC_E_SECPKG_NOT_FOUND),
- KLABEL(SEC_E_TARGET_UNKNOWN),
- KLABEL(SEC_E_UNKNOWN_CREDENTIALS),
- KLABEL(SEC_E_UNSUPPORTED_FUNCTION),
- KLABEL(SEC_E_UNTRUSTED_ROOT),
- KLABEL(SEC_E_WRONG_PRINCIPAL),
- LASTLABEL
-};
+ KLABEL(SEC_I_COMPLETE_AND_CONTINUE),
+ KLABEL(SEC_I_COMPLETE_NEEDED),
+ KLABEL(SEC_I_CONTEXT_EXPIRED),
+ KLABEL(SEC_I_CONTINUE_NEEDED),
+ KLABEL(SEC_I_INCOMPLETE_CREDENTIALS),
+ KLABEL(SEC_I_RENEGOTIATE),
+ KLABEL(SEC_E_CERT_EXPIRED),
+ KLABEL(SEC_E_INCOMPLETE_MESSAGE),
+ KLABEL(SEC_E_INSUFFICIENT_MEMORY),
+ KLABEL(SEC_E_INTERNAL_ERROR),
+ KLABEL(SEC_E_INVALID_HANDLE),
+ KLABEL(SEC_E_INVALID_TOKEN),
+ KLABEL(SEC_E_LOGON_DENIED),
+ KLABEL(SEC_E_NO_AUTHENTICATING_AUTHORITY),
+ KLABEL(SEC_E_NO_CREDENTIALS),
+ KLABEL(SEC_E_NOT_OWNER),
+ KLABEL(SEC_E_OK),
+ KLABEL(SEC_E_SECPKG_NOT_FOUND),
+ KLABEL(SEC_E_TARGET_UNKNOWN),
+ KLABEL(SEC_E_UNKNOWN_CREDENTIALS),
+ KLABEL(SEC_E_UNSUPPORTED_FUNCTION),
+ KLABEL(SEC_E_UNTRUSTED_ROOT),
+ KLABEL(SEC_E_WRONG_PRINCIPAL),
+ LASTLABEL};
#undef KLABEL
#undef LASTLABEL
#endif // defined(WEBRTC_WIN)
@@ -110,9 +114,11 @@
// Enum - TODO: expose globally later?
//////////////////////////////////////////////////////////////////////
-bool find_string(size_t& index, const std::string& needle,
- const char* const haystack[], size_t max_index) {
- for (index=0; index<max_index; ++index) {
+bool find_string(size_t& index,
+ const std::string& needle,
+ const char* const haystack[],
+ size_t max_index) {
+ for (index = 0; index < max_index; ++index) {
if (_stricmp(needle.c_str(), haystack[index]) == 0) {
return true;
}
@@ -120,7 +126,7 @@
return false;
}
-template<class E>
+template <class E>
struct Enum {
static const char** Names;
static size_t Size;
@@ -137,60 +143,65 @@
E val;
inline operator E&() { return val; }
- inline Enum& operator=(E rhs) { val = rhs; return *this; }
+ inline Enum& operator=(E rhs) {
+ val = rhs;
+ return *this;
+ }
inline const char* name() const { return Name(val); }
inline bool assign(const std::string& name) { return Parse(val, name); }
- inline Enum& operator=(const std::string& rhs) { assign(rhs); return *this; }
+ inline Enum& operator=(const std::string& rhs) {
+ assign(rhs);
+ return *this;
+ }
};
-#define ENUM(e,n) \
- template<> const char** Enum<e>::Names = n; \
- template<> size_t Enum<e>::Size = sizeof(n)/sizeof(n[0])
+#define ENUM(e, n) \
+ template <> \
+ const char** Enum<e>::Names = n; \
+ template <> \
+ size_t Enum<e>::Size = sizeof(n) / sizeof(n[0])
//////////////////////////////////////////////////////////////////////
// HttpCommon
//////////////////////////////////////////////////////////////////////
-static const char* kHttpVersions[HVER_LAST+1] = {
- "1.0", "1.1", "Unknown"
-};
+static const char* kHttpVersions[HVER_LAST + 1] = {"1.0", "1.1", "Unknown"};
ENUM(HttpVersion, kHttpVersions);
-static const char* kHttpVerbs[HV_LAST+1] = {
- "GET", "POST", "PUT", "DELETE", "CONNECT", "HEAD"
-};
+static const char* kHttpVerbs[HV_LAST + 1] = {"GET", "POST", "PUT",
+ "DELETE", "CONNECT", "HEAD"};
ENUM(HttpVerb, kHttpVerbs);
-static const char* kHttpHeaders[HH_LAST+1] = {
- "Age",
- "Cache-Control",
- "Connection",
- "Content-Disposition",
- "Content-Length",
- "Content-Range",
- "Content-Type",
- "Cookie",
- "Date",
- "ETag",
- "Expires",
- "Host",
- "If-Modified-Since",
- "If-None-Match",
- "Keep-Alive",
- "Last-Modified",
- "Location",
- "Proxy-Authenticate",
- "Proxy-Authorization",
- "Proxy-Connection",
- "Range",
- "Set-Cookie",
- "TE",
- "Trailers",
- "Transfer-Encoding",
- "Upgrade",
- "User-Agent",
- "WWW-Authenticate",
+static const char* kHttpHeaders[HH_LAST + 1] = {
+ "Age",
+ "Cache-Control",
+ "Connection",
+ "Content-Disposition",
+ "Content-Length",
+ "Content-Range",
+ "Content-Type",
+ "Cookie",
+ "Date",
+ "ETag",
+ "Expires",
+ "Host",
+ "If-Modified-Since",
+ "If-None-Match",
+ "Keep-Alive",
+ "Last-Modified",
+ "Location",
+ "Proxy-Authenticate",
+ "Proxy-Authorization",
+ "Proxy-Connection",
+ "Range",
+ "Set-Cookie",
+ "TE",
+ "Trailers",
+ "Transfer-Encoding",
+ "Upgrade",
+ "User-Agent",
+ "WWW-Authenticate",
};
ENUM(HttpHeader, kHttpHeaders);
@@ -219,56 +230,57 @@
}
bool HttpCodeHasBody(uint32_t code) {
- return !HttpCodeIsInformational(code)
- && (code != HC_NO_CONTENT) && (code != HC_NOT_MODIFIED);
+ return !HttpCodeIsInformational(code) && (code != HC_NO_CONTENT) &&
+ (code != HC_NOT_MODIFIED);
}
bool HttpCodeIsCacheable(uint32_t code) {
switch (code) {
- case HC_OK:
- case HC_NON_AUTHORITATIVE:
- case HC_PARTIAL_CONTENT:
- case HC_MULTIPLE_CHOICES:
- case HC_MOVED_PERMANENTLY:
- case HC_GONE:
- return true;
- default:
- return false;
+ case HC_OK:
+ case HC_NON_AUTHORITATIVE:
+ case HC_PARTIAL_CONTENT:
+ case HC_MULTIPLE_CHOICES:
+ case HC_MOVED_PERMANENTLY:
+ case HC_GONE:
+ return true;
+ default:
+ return false;
}
}
bool HttpHeaderIsEndToEnd(HttpHeader header) {
switch (header) {
- case HH_CONNECTION:
- case HH_KEEP_ALIVE:
- case HH_PROXY_AUTHENTICATE:
- case HH_PROXY_AUTHORIZATION:
- case HH_PROXY_CONNECTION: // Note part of RFC... this is non-standard header
- case HH_TE:
- case HH_TRAILERS:
- case HH_TRANSFER_ENCODING:
- case HH_UPGRADE:
- return false;
- default:
- return true;
+ case HH_CONNECTION:
+ case HH_KEEP_ALIVE:
+ case HH_PROXY_AUTHENTICATE:
+ case HH_PROXY_AUTHORIZATION:
+ case HH_PROXY_CONNECTION: // Note part of RFC... this is non-standard
+ // header
+ case HH_TE:
+ case HH_TRAILERS:
+ case HH_TRANSFER_ENCODING:
+ case HH_UPGRADE:
+ return false;
+ default:
+ return true;
}
}
bool HttpHeaderIsCollapsible(HttpHeader header) {
switch (header) {
- case HH_SET_COOKIE:
- case HH_PROXY_AUTHENTICATE:
- case HH_WWW_AUTHENTICATE:
- return false;
- default:
- return true;
+ case HH_SET_COOKIE:
+ case HH_PROXY_AUTHENTICATE:
+ case HH_WWW_AUTHENTICATE:
+ return false;
+ default:
+ return true;
}
}
bool HttpShouldKeepAlive(const HttpData& data) {
std::string connection;
- if ((data.hasHeader(HH_PROXY_CONNECTION, &connection)
- || data.hasHeader(HH_CONNECTION, &connection))) {
+ if ((data.hasHeader(HH_PROXY_CONNECTION, &connection) ||
+ data.hasHeader(HH_CONNECTION, &connection))) {
return (_stricmp(connection.c_str(), "Keep-Alive") == 0);
}
return (data.version >= HVER_1_1);
@@ -276,16 +288,16 @@
namespace {
-inline bool IsEndOfAttributeName(size_t pos, size_t len, const char * data) {
+inline bool IsEndOfAttributeName(size_t pos, size_t len, const char* data) {
if (pos >= len)
return true;
if (isspace(static_cast<unsigned char>(data[pos])))
return true;
// The reason for this complexity is that some attributes may contain trailing
// equal signs (like base64 tokens in Negotiate auth headers)
- if ((pos+1 < len) && (data[pos] == '=') &&
- !isspace(static_cast<unsigned char>(data[pos+1])) &&
- (data[pos+1] != '=')) {
+ if ((pos + 1 < len) && (data[pos] == '=') &&
+ !isspace(static_cast<unsigned char>(data[pos + 1])) &&
+ (data[pos + 1] != '=')) {
return true;
}
return false;
@@ -293,7 +305,8 @@
} // anonymous namespace
-void HttpParseAttributes(const char * data, size_t len,
+void HttpParseAttributes(const char* data,
+ size_t len,
HttpAttributeList& attributes) {
size_t pos = 0;
while (true) {
@@ -317,7 +330,7 @@
// Attribute has value?
if ((pos < len) && (data[pos] == '=')) {
- ++pos; // Skip '='
+ ++pos; // Skip '='
// Check if quoted value
if ((pos < len) && (data[pos] == '"')) {
while (++pos < len) {
@@ -330,16 +343,16 @@
attribute.second.append(1, data[pos]);
}
} else {
- while ((pos < len) &&
- !isspace(static_cast<unsigned char>(data[pos])) &&
- (data[pos] != ',')) {
+ while ((pos < len) && !isspace(static_cast<unsigned char>(data[pos])) &&
+ (data[pos] != ',')) {
attribute.second.append(1, data[pos++]);
}
}
}
attributes.push_back(attribute);
- if ((pos < len) && (data[pos] == ',')) ++pos; // Skip ','
+ if ((pos < len) && (data[pos] == ','))
+ ++pos; // Skip ','
}
}
@@ -374,15 +387,13 @@
bool HttpDateToSeconds(const std::string& date, time_t* seconds) {
const char* const kTimeZones[] = {
- "UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT",
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M",
- "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y"
- };
+ "UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST",
+ "PDT", "A", "B", "C", "D", "E", "F", "G", "H",
+ "I", "K", "L", "M", "N", "O", "P", "Q", "R",
+ "S", "T", "U", "V", "W", "X", "Y"};
const int kTimeZoneOffsets[] = {
- 0, 0, -5, -4, -6, -5, -7, -6, -8, -7,
- -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12,
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
- };
+ 0, 0, -5, -4, -6, -5, -7, -6, -8, -7, -1, -2, -3, -4, -5, -6, -7,
+ -8, -9, -10, -11, -12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
RTC_DCHECK(nullptr != seconds);
struct tm tval;
@@ -391,28 +402,48 @@
memset(month, 0, sizeof(month));
memset(zone, 0, sizeof(zone));
- if (7 != sscanf(date.c_str(), "%*3s, %d %3s %d %d:%d:%d %5c",
- &tval.tm_mday, month, &tval.tm_year,
- &tval.tm_hour, &tval.tm_min, &tval.tm_sec, zone)) {
+ if (7 != sscanf(date.c_str(), "%*3s, %d %3s %d %d:%d:%d %5c", &tval.tm_mday,
+ month, &tval.tm_year, &tval.tm_hour, &tval.tm_min,
+ &tval.tm_sec, zone)) {
return false;
}
switch (toupper(month[2])) {
- case 'N': tval.tm_mon = (month[1] == 'A') ? 0 : 5; break;
- case 'B': tval.tm_mon = 1; break;
- case 'R': tval.tm_mon = (month[0] == 'M') ? 2 : 3; break;
- case 'Y': tval.tm_mon = 4; break;
- case 'L': tval.tm_mon = 6; break;
- case 'G': tval.tm_mon = 7; break;
- case 'P': tval.tm_mon = 8; break;
- case 'T': tval.tm_mon = 9; break;
- case 'V': tval.tm_mon = 10; break;
- case 'C': tval.tm_mon = 11; break;
+ case 'N':
+ tval.tm_mon = (month[1] == 'A') ? 0 : 5;
+ break;
+ case 'B':
+ tval.tm_mon = 1;
+ break;
+ case 'R':
+ tval.tm_mon = (month[0] == 'M') ? 2 : 3;
+ break;
+ case 'Y':
+ tval.tm_mon = 4;
+ break;
+ case 'L':
+ tval.tm_mon = 6;
+ break;
+ case 'G':
+ tval.tm_mon = 7;
+ break;
+ case 'P':
+ tval.tm_mon = 8;
+ break;
+ case 'T':
+ tval.tm_mon = 9;
+ break;
+ case 'V':
+ tval.tm_mon = 10;
+ break;
+ case 'C':
+ tval.tm_mon = 11;
+ break;
}
tval.tm_year -= 1900;
time_t gmt, non_gmt = mktime(&tval);
if ((zone[0] == '+') || (zone[0] == '-')) {
- if (!isdigit(zone[1]) || !isdigit(zone[2])
- || !isdigit(zone[3]) || !isdigit(zone[4])) {
+ if (!isdigit(zone[1]) || !isdigit(zone[2]) || !isdigit(zone[3]) ||
+ !isdigit(zone[4])) {
return false;
}
int hours = (zone[1] - '0') * 10 + (zone[2] - '0');
@@ -426,9 +457,10 @@
}
gmt = non_gmt + kTimeZoneOffsets[zindex] * 60 * 60;
}
- // TODO: Android should support timezone, see b/2441195
-#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID) || defined(BSD)
- tm *tm_for_timezone = localtime(&gmt);
+// TODO: Android should support timezone, see b/2441195
+#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID) || \
+ defined(BSD)
+ tm* tm_for_timezone = localtime(&gmt);
*seconds = gmt + tm_for_timezone->tm_gmtoff;
#else
#if defined(_MSC_VER) && _MSC_VER >= 1900
@@ -441,21 +473,19 @@
}
std::string HttpAddress(const SocketAddress& address, bool secure) {
- return (address.port() == HttpDefaultPort(secure))
- ? address.hostname() : address.ToString();
+ return (address.port() == HttpDefaultPort(secure)) ? address.hostname()
+ : address.ToString();
}
//////////////////////////////////////////////////////////////////////
// HttpData
//////////////////////////////////////////////////////////////////////
-HttpData::HttpData() : version(HVER_1_1) {
-}
+HttpData::HttpData() : version(HVER_1_1) {}
HttpData::~HttpData() = default;
-void
-HttpData::clear(bool release_document) {
+void HttpData::clear(bool release_document) {
// Clear headers first, since releasing a document may have far-reaching
// effects.
headers_.clear();
@@ -464,19 +494,19 @@
}
}
-void
-HttpData::copy(const HttpData& src) {
+void HttpData::copy(const HttpData& src) {
headers_ = src.headers_;
}
-void
-HttpData::changeHeader(const std::string& name, const std::string& value,
- HeaderCombine combine) {
+void HttpData::changeHeader(const std::string& name,
+ const std::string& value,
+ HeaderCombine combine) {
if (combine == HC_AUTO) {
HttpHeader header;
// Unrecognized headers are collapsible
combine = !FromString(header, name) || HttpHeaderIsCollapsible(header)
- ? HC_YES : HC_NO;
+ ? HC_YES
+ : HC_NO;
} else if (combine == HC_REPLACE) {
headers_.erase(name);
combine = HC_NO;
@@ -505,8 +535,7 @@
return header;
}
-bool
-HttpData::hasHeader(const std::string& name, std::string* value) const {
+bool HttpData::hasHeader(const std::string& name, std::string* value) const {
HeaderMap::const_iterator it = headers_.find(name);
if (it == headers_.end()) {
return false;
@@ -542,38 +571,34 @@
// HttpRequestData
//
-void
-HttpRequestData::clear(bool release_document) {
+void HttpRequestData::clear(bool release_document) {
verb = HV_GET;
path.clear();
HttpData::clear(release_document);
}
-void
-HttpRequestData::copy(const HttpRequestData& src) {
+void HttpRequestData::copy(const HttpRequestData& src) {
verb = src.verb;
path = src.path;
HttpData::copy(src);
}
-size_t
-HttpRequestData::formatLeader(char* buffer, size_t size) const {
+size_t HttpRequestData::formatLeader(char* buffer, size_t size) const {
RTC_DCHECK(path.find(' ') == std::string::npos);
return sprintfn(buffer, size, "%s %.*s HTTP/%s", ToString(verb), path.size(),
path.data(), ToString(version));
}
-HttpError
-HttpRequestData::parseLeader(const char* line, size_t len) {
+HttpError HttpRequestData::parseLeader(const char* line, size_t len) {
unsigned int vmajor, vminor;
int vend, dstart, dend;
// sscanf isn't safe with strings that aren't null-terminated, and there is
// no guarantee that |line| is. Create a local copy that is null-terminated.
std::string line_str(line, len);
line = line_str.c_str();
- if ((sscanf(line, "%*s%n %n%*s%n HTTP/%u.%u",
- &vend, &dstart, &dend, &vmajor, &vminor) != 2)
- || (vmajor != 1)) {
+ if ((sscanf(line, "%*s%n %n%*s%n HTTP/%u.%u", &vend, &dstart, &dend, &vmajor,
+ &vminor) != 2) ||
+ (vmajor != 1)) {
return HE_PROTOCOL;
}
if (vminor == 0) {
@@ -585,7 +610,7 @@
}
std::string sverb(line, vend);
if (!FromString(verb, sverb.c_str())) {
- return HE_PROTOCOL; // !?! HC_METHOD_NOT_SUPPORTED?
+ return HE_PROTOCOL; // !?! HC_METHOD_NOT_SUPPORTED?
}
path.assign(line + dstart, line + dend);
return HE_NONE;
@@ -609,8 +634,7 @@
}
bool HttpRequestData::getRelativeUri(std::string* host,
- std::string* path) const
-{
+ std::string* path) const {
if (HV_CONNECT == verb)
return false;
Url<char> url(this->path);
@@ -629,15 +653,13 @@
// HttpResponseData
//
-void
-HttpResponseData::clear(bool release_document) {
+void HttpResponseData::clear(bool release_document) {
scode = HC_INTERNAL_SERVER_ERROR;
message.clear();
HttpData::clear(release_document);
}
-void
-HttpResponseData::copy(const HttpResponseData& src) {
+void HttpResponseData::copy(const HttpResponseData& src) {
scode = src.scode;
message = src.message;
HttpData::copy(src);
@@ -671,18 +693,16 @@
setHeader(HH_CONTENT_LENGTH, "0", false);
}
-size_t
-HttpResponseData::formatLeader(char* buffer, size_t size) const {
+size_t HttpResponseData::formatLeader(char* buffer, size_t size) const {
size_t len = sprintfn(buffer, size, "HTTP/%s %lu", ToString(version), scode);
if (!message.empty()) {
- len += sprintfn(buffer + len, size - len, " %.*s",
- message.size(), message.data());
+ len += sprintfn(buffer + len, size - len, " %.*s", message.size(),
+ message.data());
}
return len;
}
-HttpError
-HttpResponseData::parseLeader(const char* line, size_t len) {
+HttpError HttpResponseData::parseLeader(const char* line, size_t len) {
size_t pos = 0;
unsigned int vmajor, vminor, temp_scode;
int temp_pos;
@@ -690,16 +710,15 @@
// no guarantee that |line| is. Create a local copy that is null-terminated.
std::string line_str(line, len);
line = line_str.c_str();
- if (sscanf(line, "HTTP %u%n",
- &temp_scode, &temp_pos) == 1) {
+ if (sscanf(line, "HTTP %u%n", &temp_scode, &temp_pos) == 1) {
// This server's response has no version. :( NOTE: This happens for every
// response to requests made from Chrome plugins, regardless of the server's
// behaviour.
RTC_LOG(LS_VERBOSE) << "HTTP version missing from response";
version = HVER_UNKNOWN;
- } else if ((sscanf(line, "HTTP/%u.%u %u%n",
- &vmajor, &vminor, &temp_scode, &temp_pos) == 3)
- && (vmajor == 1)) {
+ } else if ((sscanf(line, "HTTP/%u.%u %u%n", &vmajor, &vminor, &temp_scode,
+ &temp_pos) == 3) &&
+ (vmajor == 1)) {
// This server's response does have a version.
if (vminor == 0) {
version = HVER_1_0;
@@ -713,7 +732,8 @@
}
scode = temp_scode;
pos = static_cast<size_t>(temp_pos);
- while ((pos < len) && isspace(static_cast<unsigned char>(line[pos]))) ++pos;
+ while ((pos < len) && isspace(static_cast<unsigned char>(line[pos])))
+ ++pos;
message.assign(line + pos, len - pos);
return HE_NONE;
}
@@ -725,7 +745,7 @@
std::string quote(const std::string& str) {
std::string result;
result.push_back('"');
- for (size_t i=0; i<str.size(); ++i) {
+ for (size_t i = 0; i < str.size(); ++i) {
if ((str[i] == '"') || (str[i] == '\\'))
result.push_back('\\');
result.push_back(str[i]);
@@ -742,24 +762,29 @@
bool specified_credentials;
NegotiateAuthContext(const std::string& auth, CredHandle c1, CtxtHandle c2)
- : HttpAuthContext(auth), cred(c1), ctx(c2), steps(0),
- specified_credentials(false)
- { }
+ : HttpAuthContext(auth),
+ cred(c1),
+ ctx(c2),
+ steps(0),
+ specified_credentials(false) {}
~NegotiateAuthContext() override {
DeleteSecurityContext(&ctx);
FreeCredentialsHandle(&cred);
}
};
-#endif // WEBRTC_WIN
+#endif // WEBRTC_WIN
-HttpAuthResult HttpAuthenticate(
- const char * challenge, size_t len,
- const SocketAddress& server,
- const std::string& method, const std::string& uri,
- const std::string& username, const CryptString& password,
- HttpAuthContext *& context, std::string& response, std::string& auth_method)
-{
+HttpAuthResult HttpAuthenticate(const char* challenge,
+ size_t len,
+ const SocketAddress& server,
+ const std::string& method,
+ const std::string& uri,
+ const std::string& username,
+ const CryptString& password,
+ HttpAuthContext*& context,
+ std::string& response,
+ std::string& auth_method) {
HttpAttributeList args;
HttpParseAttributes(challenge, len, args);
HttpHasNthAttribute(args, 0, &auth_method, nullptr);
@@ -770,9 +795,9 @@
// BASIC
if (_stricmp(auth_method.c_str(), "basic") == 0) {
if (context)
- return HAR_CREDENTIALS; // Bad credentials
+ return HAR_CREDENTIALS; // Bad credentials
if (username.empty())
- return HAR_CREDENTIALS; // Missing credentials
+ return HAR_CREDENTIALS; // Missing credentials
context = new HttpAuthContext(auth_method);
@@ -781,7 +806,7 @@
// automatically.
// std::string decoded = username + ":" + password;
size_t len = username.size() + password.GetLength() + 2;
- char * sensitive = new char[len];
+ char* sensitive = new char[len];
size_t pos = strcpyn(sensitive, len, username.data(), username.size());
pos += strcpyn(sensitive + pos, len - pos, ":");
password.CopyTo(sensitive + pos, true);
@@ -791,16 +816,16 @@
// TODO: create a sensitive-source version of Base64::encode
response.append(Base64::Encode(sensitive));
ExplicitZeroMemory(sensitive, len);
- delete [] sensitive;
+ delete[] sensitive;
return HAR_RESPONSE;
}
// DIGEST
if (_stricmp(auth_method.c_str(), "digest") == 0) {
if (context)
- return HAR_CREDENTIALS; // Bad credentials
+ return HAR_CREDENTIALS; // Bad credentials
if (username.empty())
- return HAR_CREDENTIALS; // Missing credentials
+ return HAR_CREDENTIALS; // Missing credentials
context = new HttpAuthContext(auth_method);
@@ -821,7 +846,7 @@
// automatically.
// std::string A1 = username + ":" + realm + ":" + password;
size_t len = username.size() + realm.size() + password.GetLength() + 3;
- char * sensitive = new char[len]; // A1
+ char* sensitive = new char[len]; // A1
size_t pos = strcpyn(sensitive, len, username.data(), username.size());
pos += strcpyn(sensitive + pos, len - pos, ":");
pos += strcpyn(sensitive + pos, len - pos, realm.c_str());
@@ -838,7 +863,7 @@
}
std::string HA1 = MD5(sensitive);
ExplicitZeroMemory(sensitive, len);
- delete [] sensitive;
+ delete[] sensitive;
std::string HA2 = MD5(A2);
std::string dig_response = MD5(HA1 + ":" + middle + ":" + HA2);
@@ -850,7 +875,7 @@
ss << ", uri=" << quote(uri);
if (has_qop) {
ss << ", qop=" << qop;
- ss << ", nc=" << ncount;
+ ss << ", nc=" << ncount;
ss << ", cnonce=" << quote(cnonce);
}
ss << ", response=\"" << dig_response << "\"";
@@ -870,7 +895,7 @@
const size_t MAX_MESSAGE = 12000, MAX_SPN = 256;
char out_buf[MAX_MESSAGE], spn[MAX_SPN];
-#if 0 // Requires funky windows versions
+#if 0 // Requires funky windows versions
DWORD len = MAX_SPN;
if (DsMakeSpn("HTTP", server.HostAsURIString().c_str(), nullptr,
server.port(),
@@ -883,25 +908,24 @@
#endif
SecBuffer out_sec;
- out_sec.pvBuffer = out_buf;
- out_sec.cbBuffer = sizeof(out_buf);
+ out_sec.pvBuffer = out_buf;
+ out_sec.cbBuffer = sizeof(out_buf);
out_sec.BufferType = SECBUFFER_TOKEN;
SecBufferDesc out_buf_desc;
out_buf_desc.ulVersion = 0;
- out_buf_desc.cBuffers = 1;
- out_buf_desc.pBuffers = &out_sec;
+ out_buf_desc.cBuffers = 1;
+ out_buf_desc.pBuffers = &out_sec;
const ULONG NEG_FLAGS_DEFAULT =
- //ISC_REQ_ALLOCATE_MEMORY
- ISC_REQ_CONFIDENTIALITY
- //| ISC_REQ_EXTENDED_ERROR
- //| ISC_REQ_INTEGRITY
- | ISC_REQ_REPLAY_DETECT
- | ISC_REQ_SEQUENCE_DETECT
- //| ISC_REQ_STREAM
- //| ISC_REQ_USE_SUPPLIED_CREDS
- ;
+ // ISC_REQ_ALLOCATE_MEMORY
+ ISC_REQ_CONFIDENTIALITY
+ //| ISC_REQ_EXTENDED_ERROR
+ //| ISC_REQ_INTEGRITY
+ | ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT
+ //| ISC_REQ_STREAM
+ //| ISC_REQ_USE_SUPPLIED_CREDS
+ ;
::TimeStamp lifetime;
SECURITY_STATUS ret = S_OK;
@@ -912,7 +936,7 @@
// uint32_t now = Time();
- NegotiateAuthContext * neg = static_cast<NegotiateAuthContext *>(context);
+ NegotiateAuthContext* neg = static_cast<NegotiateAuthContext*>(context);
if (neg) {
const size_t max_steps = 10;
if (++neg->steps >= max_steps) {
@@ -927,16 +951,18 @@
Base64::Decode(challenge, Base64::DO_STRICT, &decoded_challenge,
nullptr)) {
SecBuffer in_sec;
- in_sec.pvBuffer = const_cast<char *>(decoded_challenge.data());
- in_sec.cbBuffer = static_cast<unsigned long>(decoded_challenge.size());
+ in_sec.pvBuffer = const_cast<char*>(decoded_challenge.data());
+ in_sec.cbBuffer = static_cast<unsigned long>(decoded_challenge.size());
in_sec.BufferType = SECBUFFER_TOKEN;
SecBufferDesc in_buf_desc;
in_buf_desc.ulVersion = 0;
- in_buf_desc.cBuffers = 1;
- in_buf_desc.pBuffers = &in_sec;
+ in_buf_desc.cBuffers = 1;
+ in_buf_desc.pBuffers = &in_sec;
- ret = InitializeSecurityContextA(&neg->cred, &neg->ctx, spn, flags, 0, SECURITY_NATIVE_DREP, &in_buf_desc, 0, &neg->ctx, &out_buf_desc, &ret_flags, &lifetime);
+ ret = InitializeSecurityContextA(
+ &neg->cred, &neg->ctx, spn, flags, 0, SECURITY_NATIVE_DREP,
+ &in_buf_desc, 0, &neg->ctx, &out_buf_desc, &ret_flags, &lifetime);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << "InitializeSecurityContext returned: "
<< GetErrorName(ret, SECURITY_ERRORS);
@@ -954,11 +980,11 @@
if (!neg) {
unsigned char userbuf[256], passbuf[256], domainbuf[16];
- SEC_WINNT_AUTH_IDENTITY_A auth_id, * pauth_id = 0;
+ SEC_WINNT_AUTH_IDENTITY_A auth_id, *pauth_id = 0;
if (specify_credentials) {
memset(&auth_id, 0, sizeof(auth_id));
- size_t len = password.GetLength()+1;
- char * sensitive = new char[len];
+ size_t len = password.GetLength() + 1;
+ char* sensitive = new char[len];
password.CopyTo(sensitive, true);
std::string::size_type pos = username.find('\\');
if (pos == std::string::npos) {
@@ -987,7 +1013,7 @@
passbuf[auth_id.PasswordLength] = 0;
}
ExplicitZeroMemory(sensitive, len);
- delete [] sensitive;
+ delete[] sensitive;
auth_id.User = userbuf;
auth_id.Domain = domainbuf;
auth_id.Password = passbuf;
@@ -1009,10 +1035,12 @@
return HAR_IGNORE;
}
- //CSecBufferBundle<5, CSecBufferBase::FreeSSPI> sb_out;
+ // CSecBufferBundle<5, CSecBufferBase::FreeSSPI> sb_out;
CtxtHandle ctx;
- ret = InitializeSecurityContextA(&cred, 0, spn, flags, 0, SECURITY_NATIVE_DREP, 0, 0, &ctx, &out_buf_desc, &ret_flags, &lifetime);
+ ret = InitializeSecurityContextA(&cred, 0, spn, flags, 0,
+ SECURITY_NATIVE_DREP, 0, 0, &ctx,
+ &out_buf_desc, &ret_flags, &lifetime);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << "InitializeSecurityContext returned: "
<< GetErrorName(ret, SECURITY_ERRORS);
@@ -1026,7 +1054,8 @@
neg->steps = steps;
}
- if ((ret == SEC_I_COMPLETE_NEEDED) || (ret == SEC_I_COMPLETE_AND_CONTINUE)) {
+ if ((ret == SEC_I_COMPLETE_NEEDED) ||
+ (ret == SEC_I_COMPLETE_AND_CONTINUE)) {
ret = CompleteAuthToken(&neg->ctx, &out_buf_desc);
RTC_LOG(LS_VERBOSE) << "CompleteAuthToken returned: "
<< GetErrorName(ret, SECURITY_ERRORS);
@@ -1042,11 +1071,11 @@
return HAR_RESPONSE;
}
#endif
-#endif // WEBRTC_WIN
+#endif // WEBRTC_WIN
return HAR_IGNORE;
}
//////////////////////////////////////////////////////////////////////
-} // namespace rtc
+} // namespace rtc