Go to the documentation of this file.00001
00002
00003 #include "ace/INet/HTTP_BasicAuthentication.h"
00004 #include "ace/Codecs.h"
00005 #include "ace/Auto_Ptr.h"
00006
00007 #if !defined (__ACE_INLINE__)
00008 #include "ace/INet/HTTP_BasicAuthentication.inl"
00009 #endif
00010
00011 ACE_RCSID(NET_CLIENT,ACE_HTTP_BasicAuthentication,"$Id: HTTP_BasicAuthentication.cpp 91132 2010-07-20 05:28:27Z mcorino $")
00012
00013 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00014
00015 namespace ACE
00016 {
00017 namespace HTTP
00018 {
00019
00020 const char* BasicAuthentication::SCHEME = "Basic";
00021
00022 BasicAuthentication::BasicAuthentication()
00023 {
00024 }
00025
00026 BasicAuthentication::BasicAuthentication(const ACE_CString& user, const ACE_CString& passwd)
00027 : user_ (user), passwd_ (passwd)
00028 {
00029 }
00030
00031 BasicAuthentication::BasicAuthentication(const Request& request)
00032 {
00033 if (request.has_credentials ())
00034 {
00035 ACE_CString scheme;
00036 ACE_CString info;
00037 request.get_credentials (scheme, info);
00038 if (scheme == SCHEME)
00039 {
00040 size_t out_len = 0;
00041 ACE_Auto_Ptr<ACE_Byte> safe_buf (ACE_Base64::decode ((const ACE_Byte*)info.c_str (),
00042 &out_len));
00043 ACE_CString credentials ((char*)safe_buf.get (), out_len);
00044 ACE_CString::size_type pos = credentials.find (':');
00045 if (pos != ACE_CString::npos)
00046 {
00047 this->user_ = credentials.substr (0, pos);
00048 this->passwd_ = credentials.substr (pos+1);
00049 }
00050 }
00051 }
00052 }
00053
00054 BasicAuthentication::~BasicAuthentication()
00055 {
00056 }
00057
00058 void BasicAuthentication::set_credentials (Request& request) const
00059 {
00060 ACE_CString credentials (this->user_);
00061 credentials += ':';
00062 credentials += this->passwd_;
00063 size_t out_len = 0;
00064 ACE_Auto_Ptr<ACE_Byte> safe_buf (
00065 ACE_Base64::encode ((const ACE_Byte*)credentials.c_str (),
00066 credentials.length (),
00067 &out_len,
00068 false));
00069 ACE_CString enc_cred ((char*)safe_buf.get (), out_len);
00070 request.set_credentials (SCHEME, enc_cred);
00071 }
00072 }
00073 }
00074
00075 ACE_END_VERSIONED_NAMESPACE_DECL