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() 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;
} }
+6 -7
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();
@@ -453,7 +453,7 @@ BNetworkCookie::IsValidForDomain(const BString& domain) const
// Otherwise, the domains must match exactly, or the domain must have a dot // Otherwise, the domains must match exactly, or the domain must have a dot
// character just before the common suffix. // character just before the common suffix.
const char* suffix = domain.String() + difference; 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] == '.')) || domain[difference - 1] == '.'))
return true; return true;
@@ -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.
} }
+29 -30
View File
@@ -21,7 +21,7 @@ static const char* kArchivedUrl = "be:url string";
BUrl::BUrl(const char* url) BUrl::BUrl(const char* url)
: :
fUrlString(), fUrlString(),
fProtocol(), fProtocol(),
fUser(), fUser(),
@@ -37,7 +37,7 @@ BUrl::BUrl(const char* url)
BUrl::BUrl(BMessage* archive) BUrl::BUrl(BMessage* archive)
: :
fUrlString(), fUrlString(),
fProtocol(), fProtocol(),
fUser(), fUser(),
@@ -58,7 +58,7 @@ BUrl::BUrl(BMessage* archive)
BUrl::BUrl(const BUrl& other) BUrl::BUrl(const BUrl& other)
: :
BArchivable(), BArchivable(),
fUrlString(), fUrlString(),
fProtocol(), fProtocol(),
@@ -75,7 +75,7 @@ BUrl::BUrl(const BUrl& other)
BUrl::BUrl(const BUrl& base, const BString& location) BUrl::BUrl(const BUrl& base, const BString& location)
: :
fUrlString(), fUrlString(),
fProtocol(), fProtocol(),
fUser(), fUser(),
@@ -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());
@@ -341,7 +341,7 @@ BUrl::Authority() const
if (HasPort()) if (HasPort())
fAuthority << ':' << fPort; fAuthority << ':' << fPort;
fAuthorityValid = true; fAuthorityValid = true;
} }
return fAuthority; return fAuthority;
@@ -502,7 +502,7 @@ BUrl::Archive(BMessage* into, bool deep) const
if (ret == B_OK) if (ret == B_OK)
ret = into->AddString(kArchivedUrl, UrlString()); ret = into->AddString(kArchivedUrl, UrlString());
return ret; return ret;
} }
@@ -524,7 +524,7 @@ BUrl::operator==(BUrl& other) const
{ {
UrlString(); UrlString();
other.UrlString(); other.UrlString();
return fUrlString == other.fUrlString; return fUrlString == other.fUrlString;
} }
@@ -545,15 +545,15 @@ BUrl::operator=(const BUrl& other)
fUrlStringValid = other.fUrlStringValid; fUrlStringValid = other.fUrlStringValid;
if (fUrlStringValid) if (fUrlStringValid)
fUrlString = other.fUrlString; fUrlString = other.fUrlString;
fAuthorityValid = other.fAuthorityValid; fAuthorityValid = other.fAuthorityValid;
if (fAuthorityValid) if (fAuthorityValid)
fAuthority = other.fAuthority; fAuthority = other.fAuthority;
fUserInfoValid = other.fUserInfoValid; fUserInfoValid = other.fUserInfoValid;
if (fUserInfoValid) if (fUserInfoValid)
fUserInfo = other.fUserInfo; fUserInfo = other.fUserInfo;
fProtocol = other.fProtocol; fProtocol = other.fProtocol;
fUser = other.fUser; fUser = other.fUser;
fPassword = other.fPassword; fPassword = other.fPassword;
@@ -562,7 +562,7 @@ BUrl::operator=(const BUrl& other)
fPath = other.fPath; fPath = other.fPath;
fRequest = other.fRequest; fRequest = other.fRequest;
fFragment = other.fFragment; fFragment = other.fFragment;
fHasProtocol = other.fHasProtocol; fHasProtocol = other.fHasProtocol;
fHasUserName = other.fHasUserName; fHasUserName = other.fHasUserName;
fHasPassword = other.fHasPassword; fHasPassword = other.fHasPassword;
@@ -573,7 +573,7 @@ BUrl::operator=(const BUrl& other)
fHasPath = other.fHasPath; fHasPath = other.fHasPath;
fHasRequest = other.fHasRequest; fHasRequest = other.fHasRequest;
fHasFragment = other.fHasFragment; fHasFragment = other.fHasFragment;
return *this; return *this;
} }
@@ -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;
} }
@@ -757,7 +756,7 @@ BUrl::SetAuthority(const BString& authority)
BUrl::_DoUrlEncodeChunk(const BString& chunk, bool strict, bool directory) BUrl::_DoUrlEncodeChunk(const BString& chunk, bool strict, bool directory)
{ {
BString result; BString result;
for (int32 i = 0; i < chunk.Length(); i++) { for (int32 i = 0; i < chunk.Length(); i++) {
if (_IsUnreserved(chunk[i]) if (_IsUnreserved(chunk[i])
|| (directory && (chunk[i] == '/' || chunk[i] == '\\'))) || (directory && (chunk[i] == '/' || chunk[i] == '\\')))
@@ -769,12 +768,12 @@ BUrl::_DoUrlEncodeChunk(const BString& chunk, bool strict, bool directory)
} else { } else {
char hexString[5]; char hexString[5];
snprintf(hexString, 5, "%X", chunk[i]); snprintf(hexString, 5, "%X", chunk[i]);
result << '%' << hexString; result << '%' << hexString;
} }
} }
} }
return result; return result;
} }
@@ -783,7 +782,7 @@ BUrl::_DoUrlEncodeChunk(const BString& chunk, bool strict, bool directory)
BUrl::_DoUrlDecodeChunk(const BString& chunk, bool strict) BUrl::_DoUrlDecodeChunk(const BString& chunk, bool strict)
{ {
BString result; BString result;
for (int32 i = 0; i < chunk.Length(); i++) { for (int32 i = 0; i < chunk.Length(); i++) {
if (chunk[i] == '+' && !strict) if (chunk[i] == '+' && !strict)
result << ' '; result << ' ';
@@ -792,7 +791,7 @@ BUrl::_DoUrlDecodeChunk(const BString& chunk, bool strict)
else { else {
char hexString[] = { chunk[i+1], chunk[i+2], 0 }; char hexString[] = { chunk[i+1], chunk[i+2], 0 };
result << (char)strtol(hexString, NULL, 16); result << (char)strtol(hexString, NULL, 16);
i += 2; i += 2;
} }
} }
@@ -829,7 +828,7 @@ BUrl::_IsUnreserved(char c)
bool bool
BUrl::_IsGenDelim(char c) BUrl::_IsGenDelim(char c)
{ {
if (c == ':' || c == '/' || c == '?' || c == '#' || c == '[' if (c == ':' || c == '/' || c == '?' || c == '#' || c == '['
|| c == ']' || c == '@') || c == ']' || c == '@')
return true; return true;
else else
@@ -840,7 +839,7 @@ BUrl::_IsGenDelim(char c)
bool bool
BUrl::_IsSubDelim(char c) BUrl::_IsSubDelim(char c)
{ {
if (c == '!' || c == '$' || c == '&' || c == '\'' || c == '(' if (c == '!' || c == '$' || c == '&' || c == '\'' || c == '('
|| c == ')' || c == '*' || c == '+' || c == ',' || c == ';' || c == ')' || c == '*' || c == '+' || c == ',' || c == ';'
|| c == '=') || c == '=')
return true; return true;
+4 -4
View File
@@ -16,7 +16,7 @@
BUrlContext::BUrlContext() BUrlContext::BUrlContext()
: :
fCookieJar(), fCookieJar(),
fAuthenticationMap(NULL) fAuthenticationMap(NULL)
{ {
@@ -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;
} }
@@ -17,7 +17,7 @@ extern const char* kUrlProtocolMessageType;
extern const char* kUrlProtocolCaller; extern const char* kUrlProtocolCaller;
BUrlProtocolAsynchronousListener::BUrlProtocolAsynchronousListener( BUrlProtocolAsynchronousListener::BUrlProtocolAsynchronousListener(
bool transparent) bool transparent)
: :
BHandler("UrlProtocolAsynchronousListener"), BHandler("UrlProtocolAsynchronousListener"),
BUrlProtocolListener(), BUrlProtocolListener(),
@@ -29,9 +29,9 @@ BUrlProtocolAsynchronousListener::BUrlProtocolAsynchronousListener(
} }
else else
PRINT(("Cannot lock be_app\n")); PRINT(("Cannot lock be_app\n"));
if (transparent) if (transparent)
fSynchronousListener fSynchronousListener
= new(std::nothrow) BUrlProtocolDispatchingListener(this); = new(std::nothrow) BUrlProtocolDispatchingListener(this);
} }
@@ -63,86 +63,85 @@ BUrlProtocolAsynchronousListener::MessageReceived(BMessage* message)
BHandler::MessageReceived(message); BHandler::MessageReceived(message);
return; return;
} }
BUrlRequest* caller; BUrlRequest* caller;
if (message->FindPointer(kUrlProtocolCaller, if (message->FindPointer(kUrlProtocolCaller,
reinterpret_cast<void**>(&caller)) != B_OK) reinterpret_cast<void**>(&caller)) != B_OK)
return; return;
int8 notification; int8 notification;
if (message->FindInt8(kUrlProtocolMessageType, &notification) if (message->FindInt8(kUrlProtocolMessageType, &notification)
!= B_OK) != B_OK)
return; return;
switch (notification) { switch (notification) {
case B_URL_PROTOCOL_CONNECTION_OPENED: case B_URL_PROTOCOL_CONNECTION_OPENED:
ConnectionOpened(caller); ConnectionOpened(caller);
break; break;
case B_URL_PROTOCOL_HOSTNAME_RESOLVED: case B_URL_PROTOCOL_HOSTNAME_RESOLVED:
{ {
const char* ip; const char* ip;
message->FindString("url:ip", &ip); message->FindString("url:ip", &ip);
HostnameResolved(caller, ip); HostnameResolved(caller, ip);
} }
break; break;
case B_URL_PROTOCOL_RESPONSE_STARTED: case B_URL_PROTOCOL_RESPONSE_STARTED:
ResponseStarted(caller); ResponseStarted(caller);
break; break;
case B_URL_PROTOCOL_HEADERS_RECEIVED: case B_URL_PROTOCOL_HEADERS_RECEIVED:
HeadersReceived(caller); HeadersReceived(caller);
break; break;
case B_URL_PROTOCOL_DATA_RECEIVED: case B_URL_PROTOCOL_DATA_RECEIVED:
{ {
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;
} }
DataReceived(caller, data, size); DataReceived(caller, data, size);
} }
break; break;
case B_URL_PROTOCOL_DOWNLOAD_PROGRESS: case B_URL_PROTOCOL_DOWNLOAD_PROGRESS:
{ {
int32 bytesReceived; int32 bytesReceived;
int32 bytesTotal; int32 bytesTotal;
message->FindInt32("url:bytesReceived", &bytesReceived); message->FindInt32("url:bytesReceived", &bytesReceived);
message->FindInt32("url:bytesTotal", &bytesTotal); message->FindInt32("url:bytesTotal", &bytesTotal);
DownloadProgress(caller, bytesReceived, bytesTotal); DownloadProgress(caller, bytesReceived, bytesTotal);
} }
break; break;
case B_URL_PROTOCOL_UPLOAD_PROGRESS: case B_URL_PROTOCOL_UPLOAD_PROGRESS:
{ {
int32 bytesSent; int32 bytesSent;
int32 bytesTotal; int32 bytesTotal;
message->FindInt32("url:bytesSent", &bytesSent); message->FindInt32("url:bytesSent", &bytesSent);
message->FindInt32("url:bytesTotal", &bytesTotal); message->FindInt32("url:bytesTotal", &bytesTotal);
UploadProgress(caller, bytesSent, bytesTotal); UploadProgress(caller, bytesSent, bytesTotal);
} }
break; break;
case B_URL_PROTOCOL_REQUEST_COMPLETED: case B_URL_PROTOCOL_REQUEST_COMPLETED:
{ {
bool success; bool success;
message->FindBool("url:success", &success); message->FindBool("url:success", &success);
RequestCompleted(caller, success); RequestCompleted(caller, success);
} }
break; break;
default: default:
PRINT(("BUrlProtocolAsynchronousListener: Unknown notification %d\n", PRINT(("BUrlProtocolAsynchronousListener: Unknown notification %d\n",
notification)); notification));
@@ -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