From 564e2566492c1b9cf9bf7fdaede7ea7683dab5dd Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 15 Nov 2013 16:32:18 +0100 Subject: [PATCH] Various fixes to Services Kit * Remove useless dummy protocol loop in UrlRequest * Stop HTTP requests before deleting the socket and other things the loop may still be using * Deletion of items from the authentication map wasn't working * Remove some debug traces --- headers/os/net/UrlRequest.h | 2 +- src/kits/network/libnetapi/HttpRequest.cpp | 6 +++--- src/kits/network/libnetapi/UrlContext.cpp | 18 +++++++++++------- .../network/libnetapi/UrlProtocolRoster.cpp | 3 --- src/kits/network/libnetapi/UrlRequest.cpp | 11 ----------- 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/headers/os/net/UrlRequest.h b/headers/os/net/UrlRequest.h index 870b124a72..b61b963383 100644 --- a/headers/os/net/UrlRequest.h +++ b/headers/os/net/UrlRequest.h @@ -47,7 +47,7 @@ public: protected: static int32 _ThreadEntry(void* arg); - virtual status_t _ProtocolLoop(); + virtual status_t _ProtocolLoop() = 0; virtual void _EmitDebug(BUrlProtocolDebugMessage type, const char* format, ...); protected: diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index 3620d316c2..f382c0425a 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -57,6 +57,8 @@ BHttpRequest::BHttpRequest(const BUrl& url, bool ssl, const char* protocolName, BHttpRequest::~BHttpRequest() { + Stop(); + delete fSocket; delete fOptInputData; @@ -550,7 +552,6 @@ BHttpRequest::_MakeRequest() ssize_t bytesTotal = 0; char* inputTempBuffer = NULL; ssize_t chunkSize = -1; - fQuit = false; while (!fQuit && !(receiveEnd && parseEnd)) { if (!receiveEnd) { @@ -560,8 +561,7 @@ BHttpRequest::_MakeRequest() if (bytesRead < 0) { readError = true; - fQuit = true; - continue; + break; } else if (bytesRead == 0) receiveEnd = true; diff --git a/src/kits/network/libnetapi/UrlContext.cpp b/src/kits/network/libnetapi/UrlContext.cpp index 429eb5918d..8e34e0a931 100644 --- a/src/kits/network/libnetapi/UrlContext.cpp +++ b/src/kits/network/libnetapi/UrlContext.cpp @@ -21,8 +21,7 @@ BUrlContext::BUrlContext() fAuthenticationMap(NULL) { fAuthenticationMap = new(std::nothrow) BHttpAuthenticationMap(); - if(!fAuthenticationMap) - return; + // This is the default authentication, used when nothing else is found. // The empty string used as a key will match all the domain strings, once // we have removed all components. @@ -35,7 +34,7 @@ BUrlContext::~BUrlContext() BHttpAuthenticationMap::Iterator iterator = fAuthenticationMap->GetIterator(); while(iterator.HasNext()) - delete iterator.Remove().value; + delete *iterator.NextValue(); delete fAuthenticationMap; } @@ -59,10 +58,15 @@ BUrlContext::AddAuthentication(const BUrl& url, domain += url.Path(); BPrivate::HashString hostHash(domain.String(), domain.Length()); - delete fAuthenticationMap->Get(hostHash); - // Make sure we don't leak memory by overriding a previous - // authentication for the same domain. - fAuthenticationMap->Put(hostHash, authentication); + BHttpAuthentication* previous = fAuthenticationMap->Get(hostHash); + + // Make sure we don't leak memory by overriding a previous + // authentication for the same domain. + if(authentication != previous) { + fAuthenticationMap->Put(hostHash, authentication); + // replaces the old one + delete previous; + } } diff --git a/src/kits/network/libnetapi/UrlProtocolRoster.cpp b/src/kits/network/libnetapi/UrlProtocolRoster.cpp index 830bd2bafb..c023c9baad 100644 --- a/src/kits/network/libnetapi/UrlProtocolRoster.cpp +++ b/src/kits/network/libnetapi/UrlProtocolRoster.cpp @@ -29,11 +29,8 @@ BUrlProtocolRoster::MakeRequest(const BUrl& url, return new(std::nothrow) BHttpRequest(url, true, "HTTPS", listener, context); } else if (url.Protocol() == "file") { - puts("*** FILE URL"); return new(std::nothrow) BFileRequest(url, listener, context); } - puts("*** UNKNOWN protocol"); - return NULL; } diff --git a/src/kits/network/libnetapi/UrlRequest.cpp b/src/kits/network/libnetapi/UrlRequest.cpp index add73615c0..1d6dbaee09 100644 --- a/src/kits/network/libnetapi/UrlRequest.cpp +++ b/src/kits/network/libnetapi/UrlRequest.cpp @@ -231,17 +231,6 @@ BUrlRequest::_ThreadEntry(void* arg) } -status_t -BUrlRequest::_ProtocolLoop() -{ - // Dummy _ProtocolLoop - while (!fQuit) - snooze(1000); - - return B_PROT_SUCCESS; -} - - void BUrlRequest::_EmitDebug(BUrlProtocolDebugMessage type, const char* format, ...)