Fix FreeBSD build.
[haiku.git] / headers / os / net / HttpAuthentication.h
blob8334f581bf9097bb00aa936f05f3e49f17ed6067
1 /*
2 * Copyright 2010-2014 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _B_HTTP_AUTHENTICATION_H_
6 #define _B_HTTP_AUTHENTICATION_H_
9 #include <Locker.h>
10 #include <String.h>
11 #include <Url.h>
13 // HTTP authentication method
14 enum BHttpAuthenticationMethod {
15 B_HTTP_AUTHENTICATION_NONE = 0,
16 // No authentication
17 B_HTTP_AUTHENTICATION_BASIC = 1,
18 // Basic base64 authentication method (unsecure)
19 B_HTTP_AUTHENTICATION_DIGEST = 2,
20 // Digest authentication
21 B_HTTP_AUTHENTICATION_IE_DIGEST = 4
22 // Slightly modified digest authentication to mimic old IE one
26 enum BHttpAuthenticationAlgorithm {
27 B_HTTP_AUTHENTICATION_ALGORITHM_NONE,
28 B_HTTP_AUTHENTICATION_ALGORITHM_MD5,
29 B_HTTP_AUTHENTICATION_ALGORITHM_MD5_SESS
33 enum BHttpAuthenticationQop {
34 B_HTTP_QOP_NONE,
35 B_HTTP_QOP_AUTH,
36 B_HTTP_QOP_AUTHINT
40 class BHttpAuthentication {
41 public:
42 BHttpAuthentication();
43 BHttpAuthentication(const BString& username,
44 const BString& password);
45 BHttpAuthentication(
46 const BHttpAuthentication& other);
47 BHttpAuthentication& operator=(
48 const BHttpAuthentication& other);
50 // Field modification
51 void SetUserName(const BString& username);
52 void SetPassword(const BString& password);
53 void SetMethod(
54 BHttpAuthenticationMethod type);
55 status_t Initialize(const BString& wwwAuthenticate);
57 // Field access
58 const BString& UserName() const;
59 const BString& Password() const;
60 BHttpAuthenticationMethod Method() const;
62 BString Authorization(const BUrl& url,
63 const BString& method) const;
65 // Base64 encoding
66 // TODO: Move to a common place. We may have multiple implementations
67 // in the Haiku tree...
68 static BString Base64Encode(const BString& string);
69 static BString Base64Decode(const BString& string);
72 private:
73 BString _DigestResponse(const BString& uri,
74 const BString& method) const;
75 // TODO: Rename these? _H seems to return a hash value,
76 // _KD returns a hash value of the "data" prepended by
77 // the "secret" string...
78 BString _H(const BString& value) const;
79 BString _KD(const BString& secret,
80 const BString& data) const;
82 private:
83 BHttpAuthenticationMethod fAuthenticationMethod;
84 BString fUserName;
85 BString fPassword;
87 BString fRealm;
88 BString fDigestNonce;
89 mutable BString fDigestCnonce;
90 mutable int fDigestNc;
91 BString fDigestOpaque;
92 bool fDigestStale;
93 BHttpAuthenticationAlgorithm fDigestAlgorithm;
94 BHttpAuthenticationQop fDigestQop;
96 BString fAuthorizationString;
98 mutable BLocker fLock;
101 #endif // _B_HTTP_AUTHENTICATION_H_