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
+3 -4
View File
@@ -33,9 +33,9 @@ status_t
BFileRequest::_ProtocolLoop()
{
// 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;
// Send all notifications to listener, if any
@@ -47,10 +47,9 @@ BFileRequest::_ProtocolLoop()
ssize_t chunkSize;
char chunk[4096];
while((chunkSize = file.Read(chunk, sizeof(chunk))) > 0)
while ((chunkSize = file.Read(chunk, sizeof(chunk))) > 0)
fListener->DataReceived(this, chunk, chunkSize);
}
return B_PROT_SUCCESS;
}
+6 -7
View File
@@ -203,7 +203,7 @@ BNetworkCookie::SetValue(const BString& value)
status_t
BNetworkCookie::SetPath(const BString& path)
{
if(path[0] != '/')
if (path[0] != '/')
return B_BAD_DATA;
// 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
// 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.
if(newDomain[0] == '.')
if (newDomain[0] == '.')
newDomain.Remove(0, 1);
// 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;
fDomain = newDomain.ToLower();
@@ -453,7 +453,7 @@ BNetworkCookie::IsValidForDomain(const BString& domain) const
// Otherwise, the domains must match exactly, or the domain must have a dot
// character just before the common suffix.
const char* suffix = domain.String() + difference;
if (strcmp(suffix, cookieDomain.String()) == 0 && (difference == 0
if (strcmp(suffix, cookieDomain.String()) == 0 && (difference == 0
|| domain[difference - 1] == '.'))
return true;
@@ -468,7 +468,7 @@ BNetworkCookie::IsValidForPath(const BString& path) const
BString normalizedPath = path;
int slashPos = normalizedPath.FindLast('/');
if(slashPos != normalizedPath.Length() - 1)
if (slashPos != normalizedPath.Length() - 1)
normalizedPath.Truncate(slashPos + 1);
if (normalizedPath.Length() < cookiePath.Length())
@@ -745,8 +745,7 @@ BNetworkCookie::_ExtractAttributeValuePair(const BString& cookieString,
value.SetTo("");
// 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(value.Length() - 1, 1);
}
@@ -361,7 +361,7 @@ BNetworkCookieJar::Unflatten(type_code, const void* buffer, ssize_t size)
BNetworkCookieJar&
BNetworkCookieJar::operator=(const BNetworkCookieJar& other)
{
if(&other == this)
if (&other == this)
return *this;
BArchivable::operator=(other);
@@ -372,8 +372,7 @@ BNetworkCookieJar::operator=(const BNetworkCookieJar& other)
delete fCookieHashMap;
fCookieHashMap = new PrivateHashMap();
for (Iterator it = other.GetIterator(); it.HasNext();)
{
for (Iterator it = other.GetIterator(); it.HasNext();) {
BNetworkCookie* cookie = it.Next();
AddCookie(*cookie); // Pass by reference so the cookie is copied.
}
+29 -30
View File
@@ -21,7 +21,7 @@ static const char* kArchivedUrl = "be:url string";
BUrl::BUrl(const char* url)
:
:
fUrlString(),
fProtocol(),
fUser(),
@@ -37,7 +37,7 @@ BUrl::BUrl(const char* url)
BUrl::BUrl(BMessage* archive)
:
:
fUrlString(),
fProtocol(),
fUser(),
@@ -58,7 +58,7 @@ BUrl::BUrl(BMessage* archive)
BUrl::BUrl(const BUrl& other)
:
:
BArchivable(),
fUrlString(),
fProtocol(),
@@ -75,7 +75,7 @@ BUrl::BUrl(const BUrl& other)
BUrl::BUrl(const BUrl& base, const BString& location)
:
:
fUrlString(),
fProtocol(),
fUser(),
@@ -89,20 +89,20 @@ BUrl::BUrl(const BUrl& base, const BString& location)
// This implements the algorithm in RFC3986, Section 5.2.
BUrl relative(location);
if(relative.HasProtocol()) {
if (relative.HasProtocol()) {
SetProtocol(relative.Protocol());
SetAuthority(relative.Authority());
SetPath(relative.Path()); // TODO _RemoveDotSegments()
SetRequest(relative.Request());
} else {
if(relative.HasAuthority()) {
if (relative.HasAuthority()) {
SetAuthority(relative.Authority());
SetPath(relative.Path()); // TODO _RemoveDotSegments()
SetRequest(relative.Request());
} else {
if(relative.Path().IsEmpty()) {
if (relative.Path().IsEmpty()) {
SetPath(base.Path());
if(relative.HasRequest())
if (relative.HasRequest())
SetRequest(relative.Request());
else
SetRequest(Request());
@@ -341,7 +341,7 @@ BUrl::Authority() const
if (HasPort())
fAuthority << ':' << fPort;
fAuthorityValid = true;
}
return fAuthority;
@@ -502,7 +502,7 @@ BUrl::Archive(BMessage* into, bool deep) const
if (ret == B_OK)
ret = into->AddString(kArchivedUrl, UrlString());
return ret;
}
@@ -524,7 +524,7 @@ BUrl::operator==(BUrl& other) const
{
UrlString();
other.UrlString();
return fUrlString == other.fUrlString;
}
@@ -545,15 +545,15 @@ BUrl::operator=(const BUrl& other)
fUrlStringValid = other.fUrlStringValid;
if (fUrlStringValid)
fUrlString = other.fUrlString;
fAuthorityValid = other.fAuthorityValid;
if (fAuthorityValid)
fAuthority = other.fAuthority;
fUserInfoValid = other.fUserInfoValid;
if (fUserInfoValid)
fUserInfo = other.fUserInfo;
fProtocol = other.fProtocol;
fUser = other.fUser;
fPassword = other.fPassword;
@@ -562,7 +562,7 @@ BUrl::operator=(const BUrl& other)
fPath = other.fPath;
fRequest = other.fRequest;
fFragment = other.fFragment;
fHasProtocol = other.fHasProtocol;
fHasUserName = other.fHasUserName;
fHasPassword = other.fHasPassword;
@@ -573,7 +573,7 @@ BUrl::operator=(const BUrl& other)
fHasPath = other.fHasPath;
fHasRequest = other.fHasRequest;
fHasFragment = other.fHasFragment;
return *this;
}
@@ -644,7 +644,7 @@ BUrl::_ExplodeUrlString(const BString& url)
RegExp::MatchResult match = urlMatcher.Match(url.String());
if(!match.HasMatched())
if (!match.HasMatched())
return; // TODO error reporting
// Scheme/Protocol
@@ -664,19 +664,19 @@ BUrl::_ExplodeUrlString(const BString& url)
// Path
url.CopyInto(fPath, match.GroupStartOffsetAt(4),
match.GroupEndOffsetAt(4) - match.GroupStartOffsetAt(4));
if(!fPath.IsEmpty())
if (!fPath.IsEmpty())
fHasPath = true;
// Query
url.CopyInto(fRequest, match.GroupStartOffsetAt(6),
match.GroupEndOffsetAt(6) - match.GroupStartOffsetAt(6));
if(!fRequest.IsEmpty())
if (!fRequest.IsEmpty())
fHasRequest = true;
// Fragment
url.CopyInto(fFragment, match.GroupStartOffsetAt(8),
match.GroupEndOffsetAt(8) - match.GroupStartOffsetAt(8));
if(!fFragment.IsEmpty())
if (!fFragment.IsEmpty())
fHasFragment = true;
}
@@ -690,7 +690,7 @@ BUrl::SetAuthority(const BString& authority)
fHasUserInfo = false;
fHasHost = false;
if(fAuthority.IsEmpty())
if (fAuthority.IsEmpty())
return;
fHasAuthority = true;
@@ -723,8 +723,7 @@ BUrl::SetAuthority(const BString& authority)
int16 hostEnd = fAuthority.FindFirst(':', userInfoEnd);
userInfoEnd++;
if(hostEnd < 0)
{
if (hostEnd < 0) {
// no ':' found, the host extends to the end of the URL
hostEnd = fAuthority.Length() + 1;
}
@@ -757,7 +756,7 @@ BUrl::SetAuthority(const BString& authority)
BUrl::_DoUrlEncodeChunk(const BString& chunk, bool strict, bool directory)
{
BString result;
for (int32 i = 0; i < chunk.Length(); i++) {
if (_IsUnreserved(chunk[i])
|| (directory && (chunk[i] == '/' || chunk[i] == '\\')))
@@ -769,12 +768,12 @@ BUrl::_DoUrlEncodeChunk(const BString& chunk, bool strict, bool directory)
} else {
char hexString[5];
snprintf(hexString, 5, "%X", chunk[i]);
result << '%' << hexString;
}
}
}
return result;
}
@@ -783,7 +782,7 @@ BUrl::_DoUrlEncodeChunk(const BString& chunk, bool strict, bool directory)
BUrl::_DoUrlDecodeChunk(const BString& chunk, bool strict)
{
BString result;
for (int32 i = 0; i < chunk.Length(); i++) {
if (chunk[i] == '+' && !strict)
result << ' ';
@@ -792,7 +791,7 @@ BUrl::_DoUrlDecodeChunk(const BString& chunk, bool strict)
else {
char hexString[] = { chunk[i+1], chunk[i+2], 0 };
result << (char)strtol(hexString, NULL, 16);
i += 2;
}
}
@@ -829,7 +828,7 @@ BUrl::_IsUnreserved(char c)
bool
BUrl::_IsGenDelim(char c)
{
if (c == ':' || c == '/' || c == '?' || c == '#' || c == '['
if (c == ':' || c == '/' || c == '?' || c == '#' || c == '['
|| c == ']' || c == '@')
return true;
else
@@ -840,7 +839,7 @@ BUrl::_IsGenDelim(char c)
bool
BUrl::_IsSubDelim(char c)
{
if (c == '!' || c == '$' || c == '&' || c == '\'' || c == '('
if (c == '!' || c == '$' || c == '&' || c == '\'' || c == '('
|| c == ')' || c == '*' || c == '+' || c == ',' || c == ';'
|| c == '=')
return true;
+4 -4
View File
@@ -16,7 +16,7 @@
BUrlContext::BUrlContext()
:
:
fCookieJar(),
fAuthenticationMap(NULL)
{
@@ -33,7 +33,7 @@ BUrlContext::~BUrlContext()
{
BHttpAuthenticationMap::Iterator iterator =
fAuthenticationMap->GetIterator();
while(iterator.HasNext())
while (iterator.HasNext())
delete *iterator.NextValue();
delete fAuthenticationMap;
@@ -62,7 +62,7 @@ BUrlContext::AddAuthentication(const BUrl& url,
// Make sure we don't leak memory by overriding a previous
// authentication for the same domain.
if(authentication != previous) {
if (authentication != previous) {
fAuthenticationMap->Put(hostHash, authentication);
// replaces the old one
delete previous;
@@ -94,7 +94,7 @@ BUrlContext::GetAuthentication(const BUrl& url)
domain.Truncate(domain.FindLast('/'));
} while(authentication == NULL);
} while (authentication == NULL);
return *authentication;
}
@@ -17,7 +17,7 @@ extern const char* kUrlProtocolMessageType;
extern const char* kUrlProtocolCaller;
BUrlProtocolAsynchronousListener::BUrlProtocolAsynchronousListener(
bool transparent)
bool transparent)
:
BHandler("UrlProtocolAsynchronousListener"),
BUrlProtocolListener(),
@@ -29,9 +29,9 @@ BUrlProtocolAsynchronousListener::BUrlProtocolAsynchronousListener(
}
else
PRINT(("Cannot lock be_app\n"));
if (transparent)
fSynchronousListener
if (transparent)
fSynchronousListener
= new(std::nothrow) BUrlProtocolDispatchingListener(this);
}
@@ -63,86 +63,85 @@ BUrlProtocolAsynchronousListener::MessageReceived(BMessage* message)
BHandler::MessageReceived(message);
return;
}
BUrlRequest* caller;
if (message->FindPointer(kUrlProtocolCaller,
reinterpret_cast<void**>(&caller)) != B_OK)
return;
int8 notification;
if (message->FindInt8(kUrlProtocolMessageType, &notification)
if (message->FindInt8(kUrlProtocolMessageType, &notification)
!= B_OK)
return;
switch (notification) {
case B_URL_PROTOCOL_CONNECTION_OPENED:
ConnectionOpened(caller);
break;
case B_URL_PROTOCOL_HOSTNAME_RESOLVED:
{
const char* ip;
message->FindString("url:ip", &ip);
HostnameResolved(caller, ip);
}
break;
case B_URL_PROTOCOL_RESPONSE_STARTED:
ResponseStarted(caller);
break;
case B_URL_PROTOCOL_HEADERS_RECEIVED:
HeadersReceived(caller);
break;
case B_URL_PROTOCOL_DATA_RECEIVED:
{
const char* data;
ssize_t size = 0;
if(message->FindData("url:data", B_STRING_TYPE,
reinterpret_cast<const void**>(&data), &size) != B_OK)
{
if (message->FindData("url:data", B_STRING_TYPE,
reinterpret_cast<const void**>(&data), &size) != B_OK) {
printf("BOGUS DATA MESSAGE\n");
message->PrintToStream();
return;
}
DataReceived(caller, data, size);
}
break;
case B_URL_PROTOCOL_DOWNLOAD_PROGRESS:
{
int32 bytesReceived;
int32 bytesTotal;
message->FindInt32("url:bytesReceived", &bytesReceived);
message->FindInt32("url:bytesTotal", &bytesTotal);
DownloadProgress(caller, bytesReceived, bytesTotal);
}
break;
case B_URL_PROTOCOL_UPLOAD_PROGRESS:
{
int32 bytesSent;
int32 bytesTotal;
message->FindInt32("url:bytesSent", &bytesSent);
message->FindInt32("url:bytesTotal", &bytesTotal);
UploadProgress(caller, bytesSent, bytesTotal);
}
break;
case B_URL_PROTOCOL_REQUEST_COMPLETED:
{
bool success;
message->FindBool("url:success", &success);
RequestCompleted(caller, success);
}
break;
default:
PRINT(("BUrlProtocolAsynchronousListener: Unknown notification %d\n",
notification));
@@ -24,7 +24,7 @@ static BUrlContext gDefaultContext;
BUrlProtocolRoster::MakeRequest(const BUrl& url,
BUrlProtocolListener* listener, BUrlContext* context)
{
if(context == NULL)
if (context == NULL)
context = &gDefaultContext;
// TODO: instanciate the correct BUrlProtocol using add-on interface