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}
This commit is contained in:
@ -36,21 +36,21 @@
|
||||
// TODO(benwright): Use a nicer abstraction for mutex.
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
#define MUTEX_TYPE HANDLE
|
||||
#define MUTEX_TYPE HANDLE
|
||||
#define MUTEX_SETUP(x) (x) = CreateMutex(nullptr, FALSE, nullptr)
|
||||
#define MUTEX_CLEANUP(x) CloseHandle(x)
|
||||
#define MUTEX_LOCK(x) WaitForSingleObject((x), INFINITE)
|
||||
#define MUTEX_UNLOCK(x) ReleaseMutex(x)
|
||||
#define THREAD_ID GetCurrentThreadId()
|
||||
#elif defined(WEBRTC_POSIX)
|
||||
#define MUTEX_TYPE pthread_mutex_t
|
||||
#define MUTEX_SETUP(x) pthread_mutex_init(&(x), nullptr)
|
||||
#define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x))
|
||||
#define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
|
||||
#define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
|
||||
#define THREAD_ID pthread_self()
|
||||
#define MUTEX_TYPE pthread_mutex_t
|
||||
#define MUTEX_SETUP(x) pthread_mutex_init(&(x), nullptr)
|
||||
#define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x))
|
||||
#define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
|
||||
#define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
|
||||
#define THREAD_ID pthread_self()
|
||||
#else
|
||||
#error You must define mutex operations appropriate for your platform!
|
||||
#error You must define mutex operations appropriate for your platform!
|
||||
#endif
|
||||
|
||||
struct CRYPTO_dynlock_value {
|
||||
@ -140,20 +140,20 @@ static int socket_puts(BIO* b, const char* str) {
|
||||
|
||||
static long socket_ctrl(BIO* b, int cmd, long num, void* ptr) { // NOLINT
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
return 0;
|
||||
case BIO_CTRL_EOF: {
|
||||
rtc::AsyncSocket* socket = static_cast<rtc::AsyncSocket*>(ptr);
|
||||
// 1 means socket closed.
|
||||
return (socket->GetState() == rtc::AsyncSocket::CS_CLOSED) ? 1 : 0;
|
||||
}
|
||||
case BIO_CTRL_WPENDING:
|
||||
case BIO_CTRL_PENDING:
|
||||
return 0;
|
||||
case BIO_CTRL_FLUSH:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
case BIO_CTRL_RESET:
|
||||
return 0;
|
||||
case BIO_CTRL_EOF: {
|
||||
rtc::AsyncSocket* socket = static_cast<rtc::AsyncSocket*>(ptr);
|
||||
// 1 means socket closed.
|
||||
return (socket->GetState() == rtc::AsyncSocket::CS_CLOSED) ? 1 : 0;
|
||||
}
|
||||
case BIO_CTRL_WPENDING:
|
||||
case BIO_CTRL_PENDING:
|
||||
return 0;
|
||||
case BIO_CTRL_FLUSH:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,7 +344,7 @@ int OpenSSLAdapter::BeginSSL() {
|
||||
// appear Send handles partial writes properly, though maybe we never notice
|
||||
// since we never send more than 16KB at once..
|
||||
SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE |
|
||||
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
||||
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
||||
|
||||
// Enable SNI, if a hostname is supplied.
|
||||
if (!ssl_host_name_.empty()) {
|
||||
@ -413,17 +413,17 @@ int OpenSSLAdapter::ContinueSSL() {
|
||||
|
||||
int code = (role_ == SSL_CLIENT) ? SSL_connect(ssl_) : SSL_accept(ssl_);
|
||||
switch (SSL_get_error(ssl_, code)) {
|
||||
case SSL_ERROR_NONE:
|
||||
if (!SSLPostConnectionCheck(ssl_, ssl_host_name_)) {
|
||||
RTC_LOG(LS_ERROR) << "TLS post connection check failed";
|
||||
// make sure we close the socket
|
||||
Cleanup();
|
||||
// The connect failed so return -1 to shut down the socket
|
||||
return -1;
|
||||
}
|
||||
case SSL_ERROR_NONE:
|
||||
if (!SSLPostConnectionCheck(ssl_, ssl_host_name_)) {
|
||||
RTC_LOG(LS_ERROR) << "TLS post connection check failed";
|
||||
// make sure we close the socket
|
||||
Cleanup();
|
||||
// The connect failed so return -1 to shut down the socket
|
||||
return -1;
|
||||
}
|
||||
|
||||
state_ = SSL_CONNECTED;
|
||||
AsyncSocketAdapter::OnConnectEvent(this);
|
||||
state_ = SSL_CONNECTED;
|
||||
AsyncSocketAdapter::OnConnectEvent(this);
|
||||
#if 0 // TODO(benwright): worry about this
|
||||
// Don't let ourselves go away during the callbacks
|
||||
PRefPtr<OpenSSLAdapter> lock(this);
|
||||
@ -432,26 +432,26 @@ int OpenSSLAdapter::ContinueSSL() {
|
||||
RTC_LOG(LS_INFO) << " -- onStreamWriteable";
|
||||
AsyncSocketAdapter::OnWriteEvent(this);
|
||||
#endif
|
||||
break;
|
||||
break;
|
||||
|
||||
case SSL_ERROR_WANT_READ:
|
||||
RTC_LOG(LS_VERBOSE) << " -- error want read";
|
||||
struct timeval timeout;
|
||||
if (DTLSv1_get_timeout(ssl_, &timeout)) {
|
||||
int delay = timeout.tv_sec * 1000 + timeout.tv_usec/1000;
|
||||
case SSL_ERROR_WANT_READ:
|
||||
RTC_LOG(LS_VERBOSE) << " -- error want read";
|
||||
struct timeval timeout;
|
||||
if (DTLSv1_get_timeout(ssl_, &timeout)) {
|
||||
int delay = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
|
||||
|
||||
Thread::Current()->PostDelayed(RTC_FROM_HERE, delay, this, MSG_TIMEOUT,
|
||||
0);
|
||||
}
|
||||
break;
|
||||
Thread::Current()->PostDelayed(RTC_FROM_HERE, delay, this, MSG_TIMEOUT,
|
||||
0);
|
||||
}
|
||||
break;
|
||||
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
break;
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
break;
|
||||
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
default:
|
||||
RTC_LOG(LS_WARNING) << "ContinueSSL -- error " << code;
|
||||
return (code != 0) ? code : -1;
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
default:
|
||||
RTC_LOG(LS_WARNING) << "ContinueSSL -- error " << code;
|
||||
return (code != 0) ? code : -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -534,20 +534,20 @@ int OpenSSLAdapter::DoSslWrite(const void* pv, size_t cb, int* error) {
|
||||
|
||||
int OpenSSLAdapter::Send(const void* pv, size_t cb) {
|
||||
switch (state_) {
|
||||
case SSL_NONE:
|
||||
return AsyncSocketAdapter::Send(pv, cb);
|
||||
case SSL_NONE:
|
||||
return AsyncSocketAdapter::Send(pv, cb);
|
||||
|
||||
case SSL_WAIT:
|
||||
case SSL_CONNECTING:
|
||||
SetError(ENOTCONN);
|
||||
return SOCKET_ERROR;
|
||||
case SSL_WAIT:
|
||||
case SSL_CONNECTING:
|
||||
SetError(ENOTCONN);
|
||||
return SOCKET_ERROR;
|
||||
|
||||
case SSL_CONNECTED:
|
||||
break;
|
||||
case SSL_CONNECTED:
|
||||
break;
|
||||
|
||||
case SSL_ERROR:
|
||||
default:
|
||||
return SOCKET_ERROR;
|
||||
case SSL_ERROR:
|
||||
default:
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
int ret;
|
||||
@ -614,20 +614,20 @@ int OpenSSLAdapter::SendTo(const void* pv,
|
||||
|
||||
int OpenSSLAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) {
|
||||
switch (state_) {
|
||||
case SSL_NONE:
|
||||
return AsyncSocketAdapter::Recv(pv, cb, timestamp);
|
||||
case SSL_NONE:
|
||||
return AsyncSocketAdapter::Recv(pv, cb, timestamp);
|
||||
|
||||
case SSL_WAIT:
|
||||
case SSL_CONNECTING:
|
||||
SetError(ENOTCONN);
|
||||
return SOCKET_ERROR;
|
||||
case SSL_WAIT:
|
||||
case SSL_CONNECTING:
|
||||
SetError(ENOTCONN);
|
||||
return SOCKET_ERROR;
|
||||
|
||||
case SSL_CONNECTED:
|
||||
break;
|
||||
case SSL_CONNECTED:
|
||||
break;
|
||||
|
||||
case SSL_ERROR:
|
||||
default:
|
||||
return SOCKET_ERROR;
|
||||
case SSL_ERROR:
|
||||
default:
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
// Don't trust OpenSSL with zero byte reads
|
||||
@ -691,8 +691,8 @@ Socket::ConnState OpenSSLAdapter::GetState() const {
|
||||
// if (signal_close_)
|
||||
// return CS_CONNECTED;
|
||||
ConnState state = socket_->GetState();
|
||||
if ((state == CS_CONNECTED)
|
||||
&& ((state_ == SSL_WAIT) || (state_ == SSL_CONNECTING)))
|
||||
if ((state == CS_CONNECTED) &&
|
||||
((state_ == SSL_WAIT) || (state_ == SSL_CONNECTING)))
|
||||
state = CS_CONNECTING;
|
||||
return state;
|
||||
}
|
||||
@ -741,7 +741,7 @@ void OpenSSLAdapter::OnReadEvent(AsyncSocket* socket) {
|
||||
|
||||
// Don't let ourselves go away during the callbacks
|
||||
// PRefPtr<OpenSSLAdapter> lock(this); // TODO(benwright): fix this
|
||||
if (ssl_write_needs_read_) {
|
||||
if (ssl_write_needs_read_) {
|
||||
AsyncSocketAdapter::OnWriteEvent(socket);
|
||||
}
|
||||
|
||||
@ -767,7 +767,7 @@ void OpenSSLAdapter::OnWriteEvent(AsyncSocket* socket) {
|
||||
// Don't let ourselves go away during the callbacks
|
||||
// PRefPtr<OpenSSLAdapter> lock(this); // TODO(benwright): fix this
|
||||
|
||||
if (ssl_read_needs_write_) {
|
||||
if (ssl_read_needs_write_) {
|
||||
AsyncSocketAdapter::OnReadEvent(socket);
|
||||
}
|
||||
|
||||
@ -852,11 +852,10 @@ int OpenSSLAdapter::SSLVerifyCallback(int ok, X509_STORE_CTX* store) {
|
||||
#endif
|
||||
// Get our stream pointer from the store
|
||||
SSL* ssl = reinterpret_cast<SSL*>(
|
||||
X509_STORE_CTX_get_ex_data(store,
|
||||
SSL_get_ex_data_X509_STORE_CTX_idx()));
|
||||
X509_STORE_CTX_get_ex_data(store, SSL_get_ex_data_X509_STORE_CTX_idx()));
|
||||
|
||||
OpenSSLAdapter* stream =
|
||||
reinterpret_cast<OpenSSLAdapter*>(SSL_get_app_data(ssl));
|
||||
reinterpret_cast<OpenSSLAdapter*>(SSL_get_app_data(ssl));
|
||||
|
||||
if (!ok && stream->ssl_cert_verifier_ != nullptr) {
|
||||
RTC_LOG(LS_INFO) << "Invoking SSL Verify Callback.";
|
||||
|
||||
Reference in New Issue
Block a user