Bug 1338086 - Remove useless else blocks in order to reduce complexity in netwerk/ r?dragana
MozReview-Commit-ID: 2TSxhHWmL2H
--- a/netwerk/base/nsURLHelper.cpp
+++ b/netwerk/base/nsURLHelper.cpp
@@ -1091,17 +1091,18 @@ net_IsValidIPv4Addr(const char *addr, in
// invalid octet
return false;
}
octet = -1;
} else if (*p >= '0' && *p <='9') {
if (octet == 0) {
// leading 0 is not allowed
return false;
- } else if (octet == -1) {
+ }
+ if (octet == -1) {
octet = *p - '0';
} else {
octet *= 10;
octet += *p - '0';
if (octet > 255)
return false;
}
} else {
--- a/netwerk/build/nsNetModule.cpp
+++ b/netwerk/build/nsNetModule.cpp
@@ -343,19 +343,18 @@ static BaseWebSocketChannel*
WebSocketChannelConstructor(bool aSecure)
{
if (IsNeckoChild()) {
return new WebSocketChannelChild(aSecure);
}
if (aSecure) {
return new WebSocketSSLChannel;
- } else {
- return new WebSocketChannel;
}
+ return new WebSocketChannel;
}
#define WEB_SOCKET_HANDLER_CONSTRUCTOR(type, secure) \
static nsresult \
type##Constructor(nsISupports *aOuter, REFNSIID aIID, \
void **aResult) \
{ \
nsresult rv; \
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -3580,26 +3580,25 @@ nsCookieService::AddInternal(const nsCoo
if (foundSecureExact) {
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
BLOCKED_DOWNGRADE_SECURE_EXACT);
} else {
Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
BLOCKED_DOWNGRADE_SECURE_INEXACT);
}
return;
+ }
+ // A secure site is allowed to downgrade a secure cookie
+ // but we want to measure anyway.
+ if (foundSecureExact) {
+ Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
+ DOWNGRADE_SECURE_FROM_SECURE_EXACT);
} else {
- // A secure site is allowed to downgrade a secure cookie
- // but we want to measure anyway.
- if (foundSecureExact) {
- Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
- DOWNGRADE_SECURE_FROM_SECURE_EXACT);
- } else {
- Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
- DOWNGRADE_SECURE_FROM_SECURE_INEXACT);
- }
+ Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE,
+ DOWNGRADE_SECURE_FROM_SECURE_INEXACT);
}
}
}
RefPtr<nsCookie> oldCookie;
nsCOMPtr<nsIArray> purgedList;
if (foundCookie) {
oldCookie = exactIter.Cookie();
--- a/netwerk/dns/DNS.cpp
+++ b/netwerk/dns/DNS.cpp
@@ -105,17 +105,17 @@ bool NetAddrToString(const NetAddr *addr
if (addr->raw.family == AF_INET) {
if (bufSize < INET_ADDRSTRLEN) {
return false;
}
struct in_addr nativeAddr = {};
nativeAddr.s_addr = addr->inet.ip;
return !!inet_ntop_internal(AF_INET, &nativeAddr, buf, bufSize);
}
- else if (addr->raw.family == AF_INET6) {
+ if (addr->raw.family == AF_INET6) {
if (bufSize < INET6_ADDRSTRLEN) {
return false;
}
struct in6_addr nativeAddr = {};
memcpy(&nativeAddr.s6_addr, &addr->inet6.ip, sizeof(addr->inet6.ip.u8));
return !!inet_ntop_internal(AF_INET6, &nativeAddr, buf, bufSize);
}
#if defined(XP_UNIX)
@@ -141,38 +141,40 @@ bool NetAddrToString(const NetAddr *addr
return false;
}
bool IsLoopBackAddress(const NetAddr *addr)
{
if (addr->raw.family == AF_INET) {
return (addr->inet.ip == htonl(INADDR_LOOPBACK));
}
- else if (addr->raw.family == AF_INET6) {
+ if (addr->raw.family == AF_INET6) {
if (IPv6ADDR_IS_LOOPBACK(&addr->inet6.ip)) {
return true;
- } else if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) &&
- IPv6ADDR_V4MAPPED_TO_IPADDR(&addr->inet6.ip) == htonl(INADDR_LOOPBACK)) {
+ }
+ if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) &&
+ IPv6ADDR_V4MAPPED_TO_IPADDR(&addr->inet6.ip) == htonl(INADDR_LOOPBACK)) {
return true;
}
}
return false;
}
bool IsIPAddrAny(const NetAddr *addr)
{
if (addr->raw.family == AF_INET) {
if (addr->inet.ip == htonl(INADDR_ANY)) {
return true;
}
}
else if (addr->raw.family == AF_INET6) {
if (IPv6ADDR_IS_UNSPECIFIED(&addr->inet6.ip)) {
return true;
- } else if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) &&
+ }
+ if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) &&
IPv6ADDR_V4MAPPED_TO_IPADDR(&addr->inet6.ip) == htonl(INADDR_ANY)) {
return true;
}
}
return false;
}
bool IsIPAddrV4Mapped(const NetAddr *addr)
@@ -225,55 +227,59 @@ GetPort(const NetAddr *aAddr, uint16_t *
return NS_OK;
}
bool
NetAddr::operator == (const NetAddr& other) const
{
if (this->raw.family != other.raw.family) {
return false;
- } else if (this->raw.family == AF_INET) {
+ }
+ if (this->raw.family == AF_INET) {
return (this->inet.port == other.inet.port) &&
(this->inet.ip == other.inet.ip);
- } else if (this->raw.family == AF_INET6) {
+ }
+ if (this->raw.family == AF_INET6) {
return (this->inet6.port == other.inet6.port) &&
(this->inet6.flowinfo == other.inet6.flowinfo) &&
(memcmp(&this->inet6.ip, &other.inet6.ip,
sizeof(this->inet6.ip)) == 0) &&
(this->inet6.scope_id == other.inet6.scope_id);
#if defined(XP_UNIX)
- } else if (this->raw.family == AF_LOCAL) {
+ }
+ if (this->raw.family == AF_LOCAL) {
return PL_strncmp(this->local.path, other.local.path,
ArrayLength(this->local.path));
#endif
}
return false;
}
bool
NetAddr::operator < (const NetAddr& other) const
{
if (this->raw.family != other.raw.family) {
return this->raw.family < other.raw.family;
- } else if (this->raw.family == AF_INET) {
+ }
+ if (this->raw.family == AF_INET) {
if (this->inet.ip == other.inet.ip) {
return this->inet.port < other.inet.port;
- } else {
- return this->inet.ip < other.inet.ip;
}
- } else if (this->raw.family == AF_INET6) {
+ return this->inet.ip < other.inet.ip;
+ }
+ if (this->raw.family == AF_INET6) {
int cmpResult = memcmp(&this->inet6.ip, &other.inet6.ip,
sizeof(this->inet6.ip));
if (cmpResult) {
return cmpResult < 0;
- } else if (this->inet6.port != other.inet6.port) {
+ }
+ if (this->inet6.port != other.inet6.port) {
return this->inet6.port < other.inet6.port;
- } else {
- return this->inet6.flowinfo < other.inet6.flowinfo;
}
+ return this->inet6.flowinfo < other.inet6.flowinfo;
}
return false;
}
NetAddrElement::NetAddrElement(const PRNetAddr *prNetAddr)
{
PRNetAddrToNetAddr(prNetAddr, &mAddress);
}
--- a/netwerk/dns/nsEffectiveTLDService.cpp
+++ b/netwerk/dns/nsEffectiveTLDService.cpp
@@ -281,29 +281,28 @@ nsEffectiveTLDService::GetBaseDomainInte
// Perform the lookup.
const ETLDEntry* entry = ETLDEntry::GetEntry(currDomain);
if (entry) {
if (entry->IsWild() && prevDomain) {
// wildcard rules imply an eTLD one level inferior to the match.
eTLD = prevDomain;
break;
-
- } else if (entry->IsNormal() || !nextDot) {
+ }
+ if (entry->IsNormal() || !nextDot) {
// specific match, or we've hit the top domain level
eTLD = currDomain;
break;
-
- } else if (entry->IsException()) {
+ }
+ if (entry->IsException()) {
// exception rules imply an eTLD one level superior to the match.
eTLD = nextDot + 1;
break;
}
}
-
if (!nextDot) {
// we've hit the top domain level; use it by default.
eTLD = currDomain;
break;
}
prevDomain = currDomain;
currDomain = nextDot + 1;
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -1,17 +1,17 @@
/* vim:set ts=4 sw=4 sts=4 et cin: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if defined(HAVE_RES_NINIT)
#include <sys/types.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
+#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <resolv.h>
#define RES_RETRY_ON_FAILURE
#endif
#include <stdlib.h>
#include <ctime>
#include "nsHostResolver.h"
@@ -289,17 +289,18 @@ nsHostRecord::ResetBlacklist()
mBlacklistedItems.Clear();
}
nsHostRecord::ExpirationStatus
nsHostRecord::CheckExpiration(const mozilla::TimeStamp& now) const {
if (!mGraceStart.IsNull() && now >= mGraceStart
&& !mValidEnd.IsNull() && now < mValidEnd) {
return nsHostRecord::EXP_GRACE;
- } else if (!mValidEnd.IsNull() && now < mValidEnd) {
+ }
+ if (!mValidEnd.IsNull() && now < mValidEnd) {
return nsHostRecord::EXP_VALID;
}
return nsHostRecord::EXP_EXPIRED;
}
bool
@@ -357,17 +358,18 @@ nsHostRecord::SizeOfIncludingThis(Malloc
return n;
}
nsHostRecord::DnsPriority
nsHostRecord::GetPriority(uint16_t aFlags)
{
if (IsHighPriority(aFlags)){
return nsHostRecord::DNS_PRIORITY_HIGH;
- } else if (IsMediumPriority(aFlags)) {
+ }
+ if (IsMediumPriority(aFlags)) {
return nsHostRecord::DNS_PRIORITY_MEDIUM;
}
return nsHostRecord::DNS_PRIORITY_LOW;
}
// Returns true if the entry can be removed, or false if it should be left.
// Sets mResolveAgain true for entries being resolved right now.
--- a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
+++ b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
@@ -617,17 +617,17 @@ nsHttpChannelAuthProvider::GetCredential
rv = GetCredentialsForChallenge(challenge.get(), authType.get(),
proxyAuth, auth, creds);
if (NS_SUCCEEDED(rv)) {
gotCreds = true;
*currentAuthType = authType;
break;
}
- else if (rv == NS_ERROR_IN_PROGRESS) {
+ if (rv == NS_ERROR_IN_PROGRESS) {
// authentication prompt has been invoked and result is
// expected asynchronously, save current challenge being
// processed and all remaining challenges to use later in
// OnAuthAvailable and now immediately return
mCurrentChallenge = challenge;
mRemainingChallenges = eol ? eol+1 : nullptr;
return rv;
}
@@ -1365,17 +1365,17 @@ NS_IMETHODIMP nsHttpChannelAuthProvider:
rv = GetCredentials(mRemainingChallenges.get(), mProxyAuth, creds);
if (NS_SUCCEEDED(rv)) {
// GetCredentials loaded the credentials from the cache or
// some other way in a synchronous manner, process those
// credentials now
mRemainingChallenges.Truncate();
return ContinueOnAuthAvailable(creds);
}
- else if (rv == NS_ERROR_IN_PROGRESS) {
+ if (rv == NS_ERROR_IN_PROGRESS) {
// GetCredentials successfully queued another authprompt for
// a challenge from the list, we are now waiting for the user
// to provide the credentials
return NS_OK;
}
// otherwise, we failed...
}
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -581,20 +581,19 @@ DataChannelConnection::CompleteConnect(T
LOG(("usrsctp: PMTUD disabled, MTU set to %u", paddrparams.spp_pathmtu));
}
}
}
if (r < 0) {
if (errno == EINPROGRESS) {
// non-blocking
return;
- } else {
- LOG(("usrsctp_connect failed: %d", errno));
- mState = CLOSED;
}
+ LOG(("usrsctp_connect failed: %d", errno));
+ mState = CLOSED;
} else {
// We set Even/Odd and fire ON_CONNECTION via SCTP_COMM_UP when we get that
// This also avoids issues with calling TransportFlow stuff on Mainthread
return;
}
}
// Note: currently this doesn't actually notify the application
NS_DispatchToMainThread(do_AddRef(new DataChannelOnMessageAvailable(
@@ -1778,60 +1777,59 @@ DataChannelConnection::HandleStreamChang
if (strchg->strchange_flags == SCTP_STREAM_CHANGE_DENIED) {
LOG(("*** Failed increasing number of streams from %u (%u/%u)",
mStreams.Length(),
strchg->strchange_instrms,
strchg->strchange_outstrms));
// XXX FIX! notify pending opens of failure
return;
- } else {
- if (strchg->strchange_instrms > mStreams.Length()) {
- LOG(("Other side increased streams from %u to %u",
- mStreams.Length(), strchg->strchange_instrms));
+ }
+ if (strchg->strchange_instrms > mStreams.Length()) {
+ LOG(("Other side increased streams from %u to %u",
+ mStreams.Length(), strchg->strchange_instrms));
+ }
+ if (strchg->strchange_outstrms > mStreams.Length() ||
+ strchg->strchange_instrms > mStreams.Length()) {
+ uint16_t old_len = mStreams.Length();
+ uint16_t new_len = std::max(strchg->strchange_outstrms,
+ strchg->strchange_instrms);
+ LOG(("Increasing number of streams from %u to %u - adding %u (in: %u)",
+ old_len, new_len, new_len - old_len,
+ strchg->strchange_instrms));
+ // make sure both are the same length
+ mStreams.AppendElements(new_len - old_len);
+ LOG(("New length = %d (was %d)", mStreams.Length(), old_len));
+ for (size_t i = old_len; i < mStreams.Length(); ++i) {
+ mStreams[i] = nullptr;
}
- if (strchg->strchange_outstrms > mStreams.Length() ||
- strchg->strchange_instrms > mStreams.Length()) {
- uint16_t old_len = mStreams.Length();
- uint16_t new_len = std::max(strchg->strchange_outstrms,
- strchg->strchange_instrms);
- LOG(("Increasing number of streams from %u to %u - adding %u (in: %u)",
- old_len, new_len, new_len - old_len,
- strchg->strchange_instrms));
- // make sure both are the same length
- mStreams.AppendElements(new_len - old_len);
- LOG(("New length = %d (was %d)", mStreams.Length(), old_len));
- for (size_t i = old_len; i < mStreams.Length(); ++i) {
- mStreams[i] = nullptr;
- }
- // Re-process any channels waiting for streams.
- // Linear search, but we don't increase channels often and
- // the array would only get long in case of an app error normally
+ // Re-process any channels waiting for streams.
+ // Linear search, but we don't increase channels often and
+ // the array would only get long in case of an app error normally
- // Make sure we request enough streams if there's a big jump in streams
- // Could make a more complex API for OpenXxxFinish() and avoid this loop
- size_t num_needed = mPending.GetSize();
- LOG(("%d of %d new streams already needed", num_needed,
- new_len - old_len));
- num_needed -= (new_len - old_len); // number we added
- if (num_needed > 0) {
- if (num_needed < 16)
- num_needed = 16;
- LOG(("Not enough new streams, asking for %d more", num_needed));
- RequestMoreStreams(num_needed);
- } else if (strchg->strchange_outstrms < strchg->strchange_instrms) {
- LOG(("Requesting %d output streams to match partner",
- strchg->strchange_instrms - strchg->strchange_outstrms));
- RequestMoreStreams(strchg->strchange_instrms - strchg->strchange_outstrms);
- }
+ // Make sure we request enough streams if there's a big jump in streams
+ // Could make a more complex API for OpenXxxFinish() and avoid this loop
+ size_t num_needed = mPending.GetSize();
+ LOG(("%d of %d new streams already needed", num_needed,
+ new_len - old_len));
+ num_needed -= (new_len - old_len); // number we added
+ if (num_needed > 0) {
+ if (num_needed < 16)
+ num_needed = 16;
+ LOG(("Not enough new streams, asking for %d more", num_needed));
+ RequestMoreStreams(num_needed);
+ } else if (strchg->strchange_outstrms < strchg->strchange_instrms) {
+ LOG(("Requesting %d output streams to match partner",
+ strchg->strchange_instrms - strchg->strchange_outstrms));
+ RequestMoreStreams(strchg->strchange_instrms - strchg->strchange_outstrms);
+ }
- ProcessQueuedOpens();
- }
- // else probably not a change in # of streams
+ ProcessQueuedOpens();
}
+ // else probably not a change in # of streams
for (uint32_t i = 0; i < mStreams.Length(); ++i) {
channel = mStreams[i];
if (!channel)
continue;
if ((channel->mState == CONNECTING) &&
(channel->mStream == INVALID_STREAM)) {
@@ -2112,32 +2110,31 @@ DataChannelConnection::OpenFinish(alread
!!(channel->mFlags & DATA_CHANNEL_FLAGS_OUT_OF_ORDER_ALLOWED),
channel->mPrPolicy, channel->mPrValue)) {
LOG(("SendOpenRequest failed, errno = %d", errno));
if (errno == EAGAIN || errno == EWOULDBLOCK) {
channel->mFlags |= DATA_CHANNEL_FLAGS_SEND_REQ;
// Note: we're locked, so there's no danger of a race with the
// buffer-threshold callback
return channel.forget();
- } else {
- if (channel->mFlags & DATA_CHANNEL_FLAGS_FINISH_OPEN) {
- // We already returned the channel to the app.
- NS_ERROR("Failed to send open request");
- NS_DispatchToMainThread(do_AddRef(new DataChannelOnMessageAvailable(
- DataChannelOnMessageAvailable::ON_CHANNEL_CLOSED, this,
- channel)));
- }
- // If we haven't returned the channel yet, it will get destroyed when we exit
- // this function.
- mStreams[stream] = nullptr;
- channel->mStream = INVALID_STREAM;
- // we'll be destroying the channel
- channel->mState = CLOSED;
- return nullptr;
+ }
+ if (channel->mFlags & DATA_CHANNEL_FLAGS_FINISH_OPEN) {
+ // We already returned the channel to the app.
+ NS_ERROR("Failed to send open request");
+ NS_DispatchToMainThread(do_AddRef(new DataChannelOnMessageAvailable(
+ DataChannelOnMessageAvailable::ON_CHANNEL_CLOSED, this,
+ channel)));
}
+ // If we haven't returned the channel yet, it will get destroyed when we exit
+ // this function.
+ mStreams[stream] = nullptr;
+ channel->mStream = INVALID_STREAM;
+ // we'll be destroying the channel
+ channel->mState = CLOSED;
+ return nullptr;
/* NOTREACHED */
}
}
// Either externally negotiated or we sent Open
channel->mState = OPEN;
channel->mReady = true;
// FIX? Move into DOMDataChannel? I don't think we can send it yet here
LOG(("%s: sending ON_CHANNEL_OPEN for %p", __FUNCTION__, channel.get()));