haiku/headers/private/netservices/HttpAuthentication.h
Niels Sascha Reedijk ce64ffdb90 libnetservices.a: Put the experimental API into BPrivate::Network namespace
In order to prevent classes between libnetapi.so with the legacy API and
applications using the libnetservices.a library, the latter will have the
classes in a distinct namespace.

In the implementation, both libbnetapi.so and libnetservices.a will use the
same header and source files. If LIBNETAPI_DEPRECATED is defined during build,
the headers and source will have binary compatible behavior. Otherwise, the
classes and other objects will be put in the HaikuExt namespace.

In order to build the libbnetapi.so and libnetservices.a with the proper
build configuration, there is a stub `src/kits/net/libnetapi_deprecated` folder
that applies the special configuration to the source files.

Currently HaikuDepot, Webpositive, libshared.a and the http_streamer add on
use the compatible API in libbnetapi.so.

Change-Id: Ic73e9f271ef75749adda46f6f72e9a0b2851b461
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3667
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
2021-01-27 19:53:11 +00:00

115 lines
2.8 KiB
C++

/*
* 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 <Locker.h>
#include <String.h>
#include <Url.h>
#ifndef LIBNETAPI_DEPRECATED
namespace BPrivate {
namespace Network {
#endif
// HTTP authentication method
enum BHttpAuthenticationMethod {
B_HTTP_AUTHENTICATION_NONE = 0,
// No authentication
B_HTTP_AUTHENTICATION_BASIC = 1,
// Basic base64 authentication method (unsecure)
B_HTTP_AUTHENTICATION_DIGEST = 2,
// Digest authentication
B_HTTP_AUTHENTICATION_IE_DIGEST = 4
// Slightly modified digest authentication to mimic old IE one
};
enum BHttpAuthenticationAlgorithm {
B_HTTP_AUTHENTICATION_ALGORITHM_NONE,
B_HTTP_AUTHENTICATION_ALGORITHM_MD5,
B_HTTP_AUTHENTICATION_ALGORITHM_MD5_SESS
};
enum BHttpAuthenticationQop {
B_HTTP_QOP_NONE,
B_HTTP_QOP_AUTH,
B_HTTP_QOP_AUTHINT
};
class BHttpAuthentication {
public:
BHttpAuthentication();
BHttpAuthentication(const BString& username,
const BString& password);
BHttpAuthentication(
const BHttpAuthentication& other);
BHttpAuthentication& operator=(
const BHttpAuthentication& other);
// Field modification
void SetUserName(const BString& username);
void SetPassword(const BString& password);
void SetMethod(
BHttpAuthenticationMethod type);
status_t Initialize(const BString& wwwAuthenticate);
// Field access
const BString& UserName() const;
const BString& Password() const;
BHttpAuthenticationMethod Method() const;
BString Authorization(const BUrl& url,
const BString& method) const;
// Base64 encoding
// TODO: Move to a common place. We may have multiple implementations
// in the Haiku tree...
static BString Base64Encode(const BString& string);
static BString Base64Decode(const BString& string);
private:
BString _DigestResponse(const BString& uri,
const BString& method) const;
// TODO: Rename these? _H seems to return a hash value,
// _KD returns a hash value of the "data" prepended by
// the "secret" string...
BString _H(const BString& value) const;
BString _KD(const BString& secret,
const BString& data) const;
private:
BHttpAuthenticationMethod fAuthenticationMethod;
BString fUserName;
BString fPassword;
BString fRealm;
BString fDigestNonce;
mutable BString fDigestCnonce;
mutable int fDigestNc;
BString fDigestOpaque;
bool fDigestStale;
BHttpAuthenticationAlgorithm fDigestAlgorithm;
BHttpAuthenticationQop fDigestQop;
BString fAuthorizationString;
mutable BLocker fLock;
};
#ifndef LIBNETAPI_DEPRECATED
} // namespace Network
} // namespace BPrivate
#endif
#endif // _B_HTTP_AUTHENTICATION_H_