mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-10 17:24:29 +00:00
Bug 1338086 - Remove useless else blocks in order to reduce complexity in netwerk/ r=dragana
MozReview-Commit-ID: 2TSxhHWmL2H --HG-- extra : rebase_source : a8a70bfc3aec34b85d20021036bd2c13cdcfe5f3
This commit is contained in:
parent
f30b04c987
commit
0b79b69876
@ -1096,7 +1096,8 @@ net_IsValidIPv4Addr(const char *addr, int32_t addrLen)
|
||||
if (octet == 0) {
|
||||
// leading 0 is not allowed
|
||||
return false;
|
||||
} else if (octet == -1) {
|
||||
}
|
||||
if (octet == -1) {
|
||||
octet = *p - '0';
|
||||
} else {
|
||||
octet *= 10;
|
||||
|
@ -348,9 +348,8 @@ WebSocketChannelConstructor(bool aSecure)
|
||||
|
||||
if (aSecure) {
|
||||
return new WebSocketSSLChannel;
|
||||
} else {
|
||||
return new WebSocketChannel;
|
||||
}
|
||||
return new WebSocketChannel;
|
||||
}
|
||||
|
||||
#define WEB_SOCKET_HANDLER_CONSTRUCTOR(type, secure) \
|
||||
|
@ -3585,16 +3585,15 @@ nsCookieService::AddInternal(const nsCookieKey &aKey,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ bool NetAddrToString(const NetAddr *addr, char *buf, uint32_t bufSize)
|
||||
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;
|
||||
}
|
||||
@ -146,11 +146,12 @@ 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;
|
||||
}
|
||||
}
|
||||
@ -167,7 +168,8 @@ bool IsIPAddrAny(const NetAddr *addr)
|
||||
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;
|
||||
}
|
||||
@ -230,17 +232,20 @@ 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
|
||||
@ -253,22 +258,23 @@ 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) {
|
||||
return this->inet6.port < other.inet6.port;
|
||||
} else {
|
||||
return this->inet6.flowinfo < other.inet6.flowinfo;
|
||||
}
|
||||
if (this->inet6.port != other.inet6.port) {
|
||||
return this->inet6.port < other.inet6.port;
|
||||
}
|
||||
return this->inet6.flowinfo < other.inet6.flowinfo;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -286,19 +286,18 @@ nsEffectiveTLDService::GetBaseDomainInternal(nsCString &aHostname,
|
||||
// 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;
|
||||
|
@ -294,7 +294,8 @@ 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;
|
||||
}
|
||||
|
||||
@ -362,7 +363,8 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -622,7 +622,7 @@ nsHttpChannelAuthProvider::GetCredentials(const char *challenges,
|
||||
|
||||
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
|
||||
@ -1370,7 +1370,7 @@ NS_IMETHODIMP nsHttpChannelAuthProvider::OnAuthCancelled(nsISupports *aContext,
|
||||
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
|
||||
|
@ -586,10 +586,9 @@ DataChannelConnection::CompleteConnect(TransportFlow *flow, TransportLayer::Stat
|
||||
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
|
||||
@ -1783,50 +1782,49 @@ DataChannelConnection::HandleStreamChangeEvent(const struct sctp_stream_change_e
|
||||
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_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
|
||||
|
||||
// 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
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
ProcessQueuedOpens();
|
||||
}
|
||||
// else probably not a change in # of streams
|
||||
|
||||
for (uint32_t i = 0; i < mStreams.Length(); ++i) {
|
||||
channel = mStreams[i];
|
||||
@ -2117,22 +2115,21 @@ DataChannelConnection::OpenFinish(already_AddRefed<DataChannel>&& aChannel)
|
||||
// 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 */
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user