Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / HTTP_BasicAuthentication.cpp
blob60bb1655a2e0907c1bc364d8bc75ab74e5819876
1 #include "ace/INet/HTTP_BasicAuthentication.h"
2 #include "ace/Codecs.h"
3 #include <memory>
5 #if !defined (__ACE_INLINE__)
6 #include "ace/INet/HTTP_BasicAuthentication.inl"
7 #endif
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 namespace ACE
14 namespace HTTP
16 const char* BasicAuthentication::SCHEME = "Basic";
18 BasicAuthentication::BasicAuthentication()
22 BasicAuthentication::BasicAuthentication(const ACE_CString& user, const ACE_CString& passwd)
23 : user_ (user), passwd_ (passwd)
27 BasicAuthentication::BasicAuthentication(const Request& request)
29 if (request.has_credentials ())
31 ACE_CString scheme;
32 ACE_CString info;
33 request.get_credentials (scheme, info);
34 if (scheme == SCHEME)
36 size_t out_len = 0;
37 std::unique_ptr<ACE_Byte[]> safe_buf (ACE_Base64::decode ((const ACE_Byte*)info.c_str (),
38 &out_len));
39 ACE_CString credentials ((char*)safe_buf.get (), out_len);
40 ACE_CString::size_type pos = credentials.find (':');
41 if (pos != ACE_CString::npos)
43 this->user_ = credentials.substr (0, pos);
44 this->passwd_ = credentials.substr (pos+1);
50 BasicAuthentication::~BasicAuthentication()
54 void BasicAuthentication::set_credentials (Request& request) const
56 ACE_CString credentials (this->user_);
57 credentials += ':';
58 credentials += this->passwd_;
59 size_t out_len = 0;
60 std::unique_ptr<ACE_Byte[]> safe_buf (
61 ACE_Base64::encode ((const ACE_Byte*)credentials.c_str (),
62 credentials.length (),
63 &out_len,
64 false));
65 ACE_CString enc_cred ((char*)safe_buf.get (), out_len);
66 request.set_credentials (SCHEME, enc_cred);
71 ACE_END_VERSIONED_NAMESPACE_DECL