libnetapi: style cleanup

This commit is contained in:
Jérôme Duval
2013-11-25 18:29:06 +01:00
parent 72086dfe17
commit 97ddf9019d
7 changed files with 68 additions and 73 deletions
+2 -3
View File
@@ -35,7 +35,7 @@ BFileRequest::_ProtocolLoop()
// FIXME error handling (file does not exists, etc.) // FIXME error handling (file does not exists, etc.)
BFile file(fUrl.Path().String(), B_READ_ONLY); BFile file(fUrl.Path().String(), B_READ_ONLY);
if(file.InitCheck() != B_OK || !file.IsFile()) if (file.InitCheck() != B_OK || !file.IsFile())
return B_PROT_CONNECTION_FAILED; return B_PROT_CONNECTION_FAILED;
// Send all notifications to listener, if any // Send all notifications to listener, if any
@@ -47,10 +47,9 @@ BFileRequest::_ProtocolLoop()
ssize_t chunkSize; ssize_t chunkSize;
char chunk[4096]; char chunk[4096];
while((chunkSize = file.Read(chunk, sizeof(chunk))) > 0) while ((chunkSize = file.Read(chunk, sizeof(chunk))) > 0)
fListener->DataReceived(this, chunk, chunkSize); fListener->DataReceived(this, chunk, chunkSize);
} }
return B_PROT_SUCCESS; return B_PROT_SUCCESS;
} }
+5 -6
View File
@@ -203,7 +203,7 @@ BNetworkCookie::SetValue(const BString& value)
status_t status_t
BNetworkCookie::SetPath(const BString& path) BNetworkCookie::SetPath(const BString& path)
{ {
if(path[0] != '/') if (path[0] != '/')
return B_BAD_DATA; return B_BAD_DATA;
// TODO: canonicalize the path // TODO: canonicalize the path
@@ -225,11 +225,11 @@ BNetworkCookie::SetDomain(const BString& domain)
// not specified at all (in this case it has to exactly match the Url of // not specified at all (in this case it has to exactly match the Url of
// the page that set the cookie). In any case, we don't need to handle // the page that set the cookie). In any case, we don't need to handle
// dot-cookies specifically anymore, so just remove the extra dot. // dot-cookies specifically anymore, so just remove the extra dot.
if(newDomain[0] == '.') if (newDomain[0] == '.')
newDomain.Remove(0, 1); newDomain.Remove(0, 1);
// check we're not trying to set a cookie on a TLD or empty domain // check we're not trying to set a cookie on a TLD or empty domain
if(newDomain.FindLast('.') <= 0) if (newDomain.FindLast('.') <= 0)
return B_BAD_DATA; return B_BAD_DATA;
fDomain = newDomain.ToLower(); fDomain = newDomain.ToLower();
@@ -468,7 +468,7 @@ BNetworkCookie::IsValidForPath(const BString& path) const
BString normalizedPath = path; BString normalizedPath = path;
int slashPos = normalizedPath.FindLast('/'); int slashPos = normalizedPath.FindLast('/');
if(slashPos != normalizedPath.Length() - 1) if (slashPos != normalizedPath.Length() - 1)
normalizedPath.Truncate(slashPos + 1); normalizedPath.Truncate(slashPos + 1);
if (normalizedPath.Length() < cookiePath.Length()) if (normalizedPath.Length() < cookiePath.Length())
@@ -745,8 +745,7 @@ BNetworkCookie::_ExtractAttributeValuePair(const BString& cookieString,
value.SetTo(""); value.SetTo("");
// values may (or may not) have quotes around them. // values may (or may not) have quotes around them.
if(value[0] == '"' && value[value.Length() - 1] == '"') if (value[0] == '"' && value[value.Length() - 1] == '"') {
{
value.Remove(0, 1); value.Remove(0, 1);
value.Remove(value.Length() - 1, 1); value.Remove(value.Length() - 1, 1);
} }
@@ -361,7 +361,7 @@ BNetworkCookieJar::Unflatten(type_code, const void* buffer, ssize_t size)
BNetworkCookieJar& BNetworkCookieJar&
BNetworkCookieJar::operator=(const BNetworkCookieJar& other) BNetworkCookieJar::operator=(const BNetworkCookieJar& other)
{ {
if(&other == this) if (&other == this)
return *this; return *this;
BArchivable::operator=(other); BArchivable::operator=(other);
@@ -372,8 +372,7 @@ BNetworkCookieJar::operator=(const BNetworkCookieJar& other)
delete fCookieHashMap; delete fCookieHashMap;
fCookieHashMap = new PrivateHashMap(); fCookieHashMap = new PrivateHashMap();
for (Iterator it = other.GetIterator(); it.HasNext();) for (Iterator it = other.GetIterator(); it.HasNext();) {
{
BNetworkCookie* cookie = it.Next(); BNetworkCookie* cookie = it.Next();
AddCookie(*cookie); // Pass by reference so the cookie is copied. AddCookie(*cookie); // Pass by reference so the cookie is copied.
} }
+10 -11
View File
@@ -89,20 +89,20 @@ BUrl::BUrl(const BUrl& base, const BString& location)
// This implements the algorithm in RFC3986, Section 5.2. // This implements the algorithm in RFC3986, Section 5.2.
BUrl relative(location); BUrl relative(location);
if(relative.HasProtocol()) { if (relative.HasProtocol()) {
SetProtocol(relative.Protocol()); SetProtocol(relative.Protocol());
SetAuthority(relative.Authority()); SetAuthority(relative.Authority());
SetPath(relative.Path()); // TODO _RemoveDotSegments() SetPath(relative.Path()); // TODO _RemoveDotSegments()
SetRequest(relative.Request()); SetRequest(relative.Request());
} else { } else {
if(relative.HasAuthority()) { if (relative.HasAuthority()) {
SetAuthority(relative.Authority()); SetAuthority(relative.Authority());
SetPath(relative.Path()); // TODO _RemoveDotSegments() SetPath(relative.Path()); // TODO _RemoveDotSegments()
SetRequest(relative.Request()); SetRequest(relative.Request());
} else { } else {
if(relative.Path().IsEmpty()) { if (relative.Path().IsEmpty()) {
SetPath(base.Path()); SetPath(base.Path());
if(relative.HasRequest()) if (relative.HasRequest())
SetRequest(relative.Request()); SetRequest(relative.Request());
else else
SetRequest(Request()); SetRequest(Request());
@@ -644,7 +644,7 @@ BUrl::_ExplodeUrlString(const BString& url)
RegExp::MatchResult match = urlMatcher.Match(url.String()); RegExp::MatchResult match = urlMatcher.Match(url.String());
if(!match.HasMatched()) if (!match.HasMatched())
return; // TODO error reporting return; // TODO error reporting
// Scheme/Protocol // Scheme/Protocol
@@ -664,19 +664,19 @@ BUrl::_ExplodeUrlString(const BString& url)
// Path // Path
url.CopyInto(fPath, match.GroupStartOffsetAt(4), url.CopyInto(fPath, match.GroupStartOffsetAt(4),
match.GroupEndOffsetAt(4) - match.GroupStartOffsetAt(4)); match.GroupEndOffsetAt(4) - match.GroupStartOffsetAt(4));
if(!fPath.IsEmpty()) if (!fPath.IsEmpty())
fHasPath = true; fHasPath = true;
// Query // Query
url.CopyInto(fRequest, match.GroupStartOffsetAt(6), url.CopyInto(fRequest, match.GroupStartOffsetAt(6),
match.GroupEndOffsetAt(6) - match.GroupStartOffsetAt(6)); match.GroupEndOffsetAt(6) - match.GroupStartOffsetAt(6));
if(!fRequest.IsEmpty()) if (!fRequest.IsEmpty())
fHasRequest = true; fHasRequest = true;
// Fragment // Fragment
url.CopyInto(fFragment, match.GroupStartOffsetAt(8), url.CopyInto(fFragment, match.GroupStartOffsetAt(8),
match.GroupEndOffsetAt(8) - match.GroupStartOffsetAt(8)); match.GroupEndOffsetAt(8) - match.GroupStartOffsetAt(8));
if(!fFragment.IsEmpty()) if (!fFragment.IsEmpty())
fHasFragment = true; fHasFragment = true;
} }
@@ -690,7 +690,7 @@ BUrl::SetAuthority(const BString& authority)
fHasUserInfo = false; fHasUserInfo = false;
fHasHost = false; fHasHost = false;
if(fAuthority.IsEmpty()) if (fAuthority.IsEmpty())
return; return;
fHasAuthority = true; fHasAuthority = true;
@@ -723,8 +723,7 @@ BUrl::SetAuthority(const BString& authority)
int16 hostEnd = fAuthority.FindFirst(':', userInfoEnd); int16 hostEnd = fAuthority.FindFirst(':', userInfoEnd);
userInfoEnd++; userInfoEnd++;
if(hostEnd < 0) if (hostEnd < 0) {
{
// no ':' found, the host extends to the end of the URL // no ':' found, the host extends to the end of the URL
hostEnd = fAuthority.Length() + 1; hostEnd = fAuthority.Length() + 1;
} }
+3 -3
View File
@@ -33,7 +33,7 @@ BUrlContext::~BUrlContext()
{ {
BHttpAuthenticationMap::Iterator iterator = BHttpAuthenticationMap::Iterator iterator =
fAuthenticationMap->GetIterator(); fAuthenticationMap->GetIterator();
while(iterator.HasNext()) while (iterator.HasNext())
delete *iterator.NextValue(); delete *iterator.NextValue();
delete fAuthenticationMap; delete fAuthenticationMap;
@@ -62,7 +62,7 @@ BUrlContext::AddAuthentication(const BUrl& url,
// Make sure we don't leak memory by overriding a previous // Make sure we don't leak memory by overriding a previous
// authentication for the same domain. // authentication for the same domain.
if(authentication != previous) { if (authentication != previous) {
fAuthenticationMap->Put(hostHash, authentication); fAuthenticationMap->Put(hostHash, authentication);
// replaces the old one // replaces the old one
delete previous; delete previous;
@@ -94,7 +94,7 @@ BUrlContext::GetAuthentication(const BUrl& url)
domain.Truncate(domain.FindLast('/')); domain.Truncate(domain.FindLast('/'));
} while(authentication == NULL); } while (authentication == NULL);
return *authentication; return *authentication;
} }
@@ -100,9 +100,8 @@ BUrlProtocolAsynchronousListener::MessageReceived(BMessage* message)
{ {
const char* data; const char* data;
ssize_t size = 0; ssize_t size = 0;
if(message->FindData("url:data", B_STRING_TYPE, if (message->FindData("url:data", B_STRING_TYPE,
reinterpret_cast<const void**>(&data), &size) != B_OK) reinterpret_cast<const void**>(&data), &size) != B_OK) {
{
printf("BOGUS DATA MESSAGE\n"); printf("BOGUS DATA MESSAGE\n");
message->PrintToStream(); message->PrintToStream();
return; return;
@@ -24,7 +24,7 @@ static BUrlContext gDefaultContext;
BUrlProtocolRoster::MakeRequest(const BUrl& url, BUrlProtocolRoster::MakeRequest(const BUrl& url,
BUrlProtocolListener* listener, BUrlContext* context) BUrlProtocolListener* listener, BUrlContext* context)
{ {
if(context == NULL) if (context == NULL)
context = &gDefaultContext; context = &gDefaultContext;
// TODO: instanciate the correct BUrlProtocol using add-on interface // TODO: instanciate the correct BUrlProtocol using add-on interface