1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaUserAuth.cc
14 #include <boost/format.hpp>
16 #include "zypp/base/Gettext.h"
17 #include "zypp/base/String.h"
19 #include "zypp/media/MediaException.h"
20 #include "zypp/media/MediaUserAuth.h"
27 bool AuthData::valid() const
29 return username().size() && password().size();
32 std::ostream & AuthData::dumpOn( std::ostream & str ) const
34 str << "username: '" << _username << "'" << std::endl
35 << "password: " << (_password.empty() ? "<empty>" : "<non-empty>")
41 bool CurlAuthData::valid() const
43 return username().size() && password().size() && _auth_type != CURLAUTH_NONE;
47 std::ostream & CurlAuthData::dumpOn( std::ostream & str ) const
49 AuthData::dumpOn(str) << " auth_type: " << _auth_type_str
50 << " (" << _auth_type << ")" << std::endl;
54 long CurlAuthData::auth_type_str2long(std::string & auth_type_str)
56 curl_version_info_data *curl_info = curl_version_info(CURLVERSION_NOW);
58 std::vector<std::string> list;
59 std::vector<std::string>::const_iterator it;
60 long auth_type = CURLAUTH_NONE;
62 zypp::str::split(auth_type_str, std::back_inserter(list), ",");
64 for(it = list.begin(); it != list.end(); ++it)
68 auth_type |= CURLAUTH_BASIC;
73 auth_type |= CURLAUTH_DIGEST;
76 if((curl_info && (curl_info->features & CURL_VERSION_NTLM)) &&
79 auth_type |= CURLAUTH_NTLM;
82 if((curl_info && (curl_info->features & CURL_VERSION_SPNEGO)) &&
83 (*it == "spnego" || *it == "negotiate"))
85 // there is no separate spnego flag for this auth type
86 auth_type |= CURLAUTH_GSSNEGOTIATE;
89 if((curl_info && (curl_info->features & CURL_VERSION_GSSNEGOTIATE)) &&
90 (*it == "gssnego" || *it == "negotiate"))
92 auth_type |= CURLAUTH_GSSNEGOTIATE;
96 std::string msg = boost::str(
97 boost::format (_("Unsupported HTTP authentication method '%s'")) % *it);
99 ZYPP_THROW(MediaException(msg));
106 std::string CurlAuthData::auth_type_long2str(long auth_type)
108 std::list<std::string> auth_list;
110 if(auth_type & CURLAUTH_GSSNEGOTIATE)
111 auth_list.push_back("negotiate");
113 if(auth_type & CURLAUTH_NTLM)
114 auth_list.push_back("ntlm");
116 if(auth_type & CURLAUTH_DIGEST)
117 auth_list.push_back("digest");
119 if(auth_type & CURLAUTH_BASIC)
120 auth_list.push_back("basic");
122 return str::join(auth_list, ",");
126 std::ostream & operator << (std::ostream & str, AuthData & auth_data)
128 auth_data.dumpOn(str);
132 std::ostream & operator << (std::ostream & str, CurlAuthData & auth_data)
134 auth_data.dumpOn(str);