Make handling of Http Authentication thread safe

* Each BHttpAuthentication object is locked on all field accesses,
* They are owned by the BUrlContext and never deleted, so there is no
need for reference-counting them,
* The BUrlContext itself is now reference counted, and all BUrlRequests
hold a reference to it.

This makes sure using the BHttpAuthentication objects from requests is
thread-safe.
This commit is contained in:
Adrien Destugues
2014-06-11 14:11:01 +02:00
parent 463ffbfde4
commit 895fa41e0b
6 changed files with 50 additions and 27 deletions
+5 -2
View File
@@ -1,13 +1,14 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Copyright 2010-2014 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_HTTP_AUTHENTICATION_H_
#define _B_HTTP_AUTHENTICATION_H_
#include <Url.h>
#include <Locker.h>
#include <String.h>
#include <Url.h>
// HTTP authentication method
enum BHttpAuthenticationMethod {
@@ -89,6 +90,8 @@ private:
BHttpAuthenticationQop fDigestQop;
BString fAuthorizationString;
mutable BLocker fLock;
};
#endif // _B_HTTP_AUTHENTICATION_H_
+6 -5
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Copyright 2010-2014 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_CONTEXT_H_
@@ -8,15 +8,16 @@
#include <HttpAuthentication.h>
#include <NetworkCookieJar.h>
#include <Referenceable.h>
namespace BPrivate {
template <class key, class value> class HashMap;
template <class key, class value> class SynchronizedHashMap;
class HashString;
}
class BUrlContext {
class BUrlContext: public BReferenceable {
public:
BUrlContext();
~BUrlContext();
@@ -25,7 +26,7 @@ public:
void SetCookieJar(
const BNetworkCookieJar& cookieJar);
void AddAuthentication(const BUrl& url,
BHttpAuthentication* const authentication);
const BHttpAuthentication& authentication);
// Context accessors
BNetworkCookieJar& GetCookieJar();
@@ -33,7 +34,7 @@ public:
private:
BNetworkCookieJar fCookieJar;
typedef BPrivate::HashMap<BPrivate::HashString,
typedef BPrivate::SynchronizedHashMap<BPrivate::HashString,
BHttpAuthentication*> BHttpAuthenticationMap;
BHttpAuthenticationMap* fAuthenticationMap;
};
+3 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2010 Haiku Inc. All rights reserved.
* Copyright 2010-2014 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _B_URL_REQUEST_H_
@@ -11,6 +11,7 @@
#include <UrlProtocolListener.h>
#include <UrlResult.h>
#include <OS.h>
#include <Referenceable.h>
class BUrlRequest {
@@ -52,7 +53,7 @@ protected:
const char* format, ...);
protected:
BUrl fUrl;
BUrlContext* fContext;
BReference<BUrlContext> fContext;
BUrlProtocolListener* fListener;
bool fQuit;