AuthenticationChallengeSoup.cpp [plain text]
#include "config.h"
#if USE(SOUP)
#include "AuthenticationChallenge.h"
#include "ResourceError.h"
#include <libsoup/soup.h>
namespace WebCore {
static ProtectionSpaceServerType protectionSpaceServerTypeFromURI(SoupURI* uri, bool isForProxy)
{
if (uri->scheme == SOUP_URI_SCHEME_HTTPS)
return isForProxy ? ProtectionSpaceProxyHTTPS : ProtectionSpaceServerHTTPS;
if (uri->scheme == SOUP_URI_SCHEME_HTTP)
return isForProxy ? ProtectionSpaceProxyHTTP : ProtectionSpaceServerHTTP;
if (uri->scheme == SOUP_URI_SCHEME_FTP)
return isForProxy ? ProtectionSpaceProxyFTP : ProtectionSpaceServerFTP;
return isForProxy ? ProtectionSpaceProxyHTTP : ProtectionSpaceServerHTTP;
}
static ProtectionSpace protectionSpaceFromSoupAuthAndMessage(SoupAuth* soupAuth, SoupMessage* message)
{
const char* schemeName = soup_auth_get_scheme_name(soupAuth);
ProtectionSpaceAuthenticationScheme scheme;
if (!g_ascii_strcasecmp(schemeName, "basic"))
scheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
else if (!g_ascii_strcasecmp(schemeName, "digest"))
scheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
else if (!g_ascii_strcasecmp(schemeName, "ntlm"))
scheme = ProtectionSpaceAuthenticationSchemeNTLM;
else if (!g_ascii_strcasecmp(schemeName, "negotiate"))
scheme = ProtectionSpaceAuthenticationSchemeNegotiate;
else
scheme = ProtectionSpaceAuthenticationSchemeUnknown;
SoupURI* soupURI = soup_message_get_uri(message);
return ProtectionSpace(String::fromUTF8(soup_uri_get_host(soupURI)), soup_uri_get_port(soupURI),
protectionSpaceServerTypeFromURI(soupURI, soup_auth_is_for_proxy(soupAuth)),
String::fromUTF8(soup_auth_get_realm(soupAuth)), scheme);
}
AuthenticationChallenge::AuthenticationChallenge(SoupSession* soupSession, SoupMessage* soupMessage, SoupAuth* soupAuth, bool retrying, AuthenticationClient* client)
: AuthenticationChallengeBase(protectionSpaceFromSoupAuthAndMessage(soupAuth, soupMessage),
Credential(), retrying ? 1 : 0, soupMessage, ResourceError::authenticationError(soupMessage))
, m_soupSession(soupSession)
, m_soupMessage(soupMessage)
, m_soupAuth(soupAuth)
, m_authenticationClient(client)
{
}
bool AuthenticationChallenge::platformCompare(const AuthenticationChallenge& a, const AuthenticationChallenge& b)
{
return a.soupSession() == b.soupSession()
&& a.soupMessage() == b.soupMessage()
&& a.soupAuth() == b.soupAuth();
}
}
#endif