diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/poco/Net/src/HTTPCredentials.cpp | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/poco/Net/src/HTTPCredentials.cpp')
-rw-r--r-- | contrib/libs/poco/Net/src/HTTPCredentials.cpp | 406 |
1 files changed, 203 insertions, 203 deletions
diff --git a/contrib/libs/poco/Net/src/HTTPCredentials.cpp b/contrib/libs/poco/Net/src/HTTPCredentials.cpp index 36a314f246..ae1d6ea0b6 100644 --- a/contrib/libs/poco/Net/src/HTTPCredentials.cpp +++ b/contrib/libs/poco/Net/src/HTTPCredentials.cpp @@ -1,208 +1,208 @@ -// -// HTTPCredentials.cpp -// -// Library: Net -// Package: HTTP -// Module: HTTPCredentials -// -// Copyright (c) 2011, Anton V. Yabchinskiy (arn at bestmx dot ru). -// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#include "Poco/Net/HTTPAuthenticationParams.h" -#include "Poco/Net/HTTPBasicCredentials.h" -#include "Poco/Net/HTTPCredentials.h" -#include "Poco/Net/HTTPRequest.h" -#include "Poco/Net/HTTPResponse.h" -#include "Poco/Net/NetException.h" -#include "Poco/String.h" -#include "Poco/Ascii.h" -#include "Poco/URI.h" - - -using Poco::icompare; - - -namespace Poco { -namespace Net { - - -HTTPCredentials::HTTPCredentials() -{ -} - - -HTTPCredentials::HTTPCredentials(const std::string& username, const std::string& password): - _digest(username, password) -{ -} - - -HTTPCredentials::~HTTPCredentials() -{ -} - - -void HTTPCredentials::fromUserInfo(const std::string& userInfo) -{ - std::string username; - std::string password; - - extractCredentials(userInfo, username, password); - setUsername(username); - setPassword(password); - _digest.reset(); -} - - -void HTTPCredentials::fromURI(const URI& uri) -{ - std::string username; - std::string password; - - extractCredentials(uri, username, password); - setUsername(username); - setPassword(password); - _digest.reset(); -} - - -void HTTPCredentials::authenticate(HTTPRequest& request, const HTTPResponse& response) -{ - for (HTTPResponse::ConstIterator iter = response.find(HTTPAuthenticationParams::WWW_AUTHENTICATE); iter != response.end(); ++iter) - { - if (isBasicCredentials(iter->second)) - { - HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request); - return; - } - else if (isDigestCredentials(iter->second)) - { - _digest.authenticate(request, HTTPAuthenticationParams(iter->second.substr(7))); - return; +// +// HTTPCredentials.cpp +// +// Library: Net +// Package: HTTP +// Module: HTTPCredentials +// +// Copyright (c) 2011, Anton V. Yabchinskiy (arn at bestmx dot ru). +// Copyright (c) 2012, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/Net/HTTPAuthenticationParams.h" +#include "Poco/Net/HTTPBasicCredentials.h" +#include "Poco/Net/HTTPCredentials.h" +#include "Poco/Net/HTTPRequest.h" +#include "Poco/Net/HTTPResponse.h" +#include "Poco/Net/NetException.h" +#include "Poco/String.h" +#include "Poco/Ascii.h" +#include "Poco/URI.h" + + +using Poco::icompare; + + +namespace Poco { +namespace Net { + + +HTTPCredentials::HTTPCredentials() +{ +} + + +HTTPCredentials::HTTPCredentials(const std::string& username, const std::string& password): + _digest(username, password) +{ +} + + +HTTPCredentials::~HTTPCredentials() +{ +} + + +void HTTPCredentials::fromUserInfo(const std::string& userInfo) +{ + std::string username; + std::string password; + + extractCredentials(userInfo, username, password); + setUsername(username); + setPassword(password); + _digest.reset(); +} + + +void HTTPCredentials::fromURI(const URI& uri) +{ + std::string username; + std::string password; + + extractCredentials(uri, username, password); + setUsername(username); + setPassword(password); + _digest.reset(); +} + + +void HTTPCredentials::authenticate(HTTPRequest& request, const HTTPResponse& response) +{ + for (HTTPResponse::ConstIterator iter = response.find(HTTPAuthenticationParams::WWW_AUTHENTICATE); iter != response.end(); ++iter) + { + if (isBasicCredentials(iter->second)) + { + HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request); + return; } - } -} - - -void HTTPCredentials::updateAuthInfo(HTTPRequest& request) -{ - if (request.has(HTTPRequest::AUTHORIZATION)) - { - const std::string& authorization = request.get(HTTPRequest::AUTHORIZATION); - - if (isBasicCredentials(authorization)) - { - HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request); - } - else if (isDigestCredentials(authorization)) - { - _digest.updateAuthInfo(request); + else if (isDigestCredentials(iter->second)) + { + _digest.authenticate(request, HTTPAuthenticationParams(iter->second.substr(7))); + return; + } + } +} + + +void HTTPCredentials::updateAuthInfo(HTTPRequest& request) +{ + if (request.has(HTTPRequest::AUTHORIZATION)) + { + const std::string& authorization = request.get(HTTPRequest::AUTHORIZATION); + + if (isBasicCredentials(authorization)) + { + HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request); } - } -} - - -void HTTPCredentials::proxyAuthenticate(HTTPRequest& request, const HTTPResponse& response) -{ - for (HTTPResponse::ConstIterator iter = response.find(HTTPAuthenticationParams::PROXY_AUTHENTICATE); iter != response.end(); ++iter) - { - if (isBasicCredentials(iter->second)) - { - HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).proxyAuthenticate(request); - return; - } - else if (isDigestCredentials(iter->second)) - { - _digest.proxyAuthenticate(request, HTTPAuthenticationParams(iter->second.substr(7))); - return; + else if (isDigestCredentials(authorization)) + { + _digest.updateAuthInfo(request); + } + } +} + + +void HTTPCredentials::proxyAuthenticate(HTTPRequest& request, const HTTPResponse& response) +{ + for (HTTPResponse::ConstIterator iter = response.find(HTTPAuthenticationParams::PROXY_AUTHENTICATE); iter != response.end(); ++iter) + { + if (isBasicCredentials(iter->second)) + { + HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).proxyAuthenticate(request); + return; } - } -} - - -void HTTPCredentials::updateProxyAuthInfo(HTTPRequest& request) -{ - if (request.has(HTTPRequest::PROXY_AUTHORIZATION)) - { - const std::string& authorization = request.get(HTTPRequest::PROXY_AUTHORIZATION); - - if (isBasicCredentials(authorization)) - { - HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).proxyAuthenticate(request); - } - else if (isDigestCredentials(authorization)) - { - _digest.updateProxyAuthInfo(request); + else if (isDigestCredentials(iter->second)) + { + _digest.proxyAuthenticate(request, HTTPAuthenticationParams(iter->second.substr(7))); + return; + } + } +} + + +void HTTPCredentials::updateProxyAuthInfo(HTTPRequest& request) +{ + if (request.has(HTTPRequest::PROXY_AUTHORIZATION)) + { + const std::string& authorization = request.get(HTTPRequest::PROXY_AUTHORIZATION); + + if (isBasicCredentials(authorization)) + { + HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).proxyAuthenticate(request); } + else if (isDigestCredentials(authorization)) + { + _digest.updateProxyAuthInfo(request); + } + } +} + + +bool HTTPCredentials::isBasicCredentials(const std::string& header) +{ + return icompare(header, 0, 5, "Basic") == 0 && (header.size() > 5 ? Poco::Ascii::isSpace(header[5]) : true); +} + + +bool HTTPCredentials::isDigestCredentials(const std::string& header) +{ + return icompare(header, 0, 6, "Digest") == 0 && (header.size() > 6 ? Poco::Ascii::isSpace(header[6]) : true); +} + + +bool HTTPCredentials::hasBasicCredentials(const HTTPRequest& request) +{ + return request.has(HTTPRequest::AUTHORIZATION) && isBasicCredentials(request.get(HTTPRequest::AUTHORIZATION)); +} + + +bool HTTPCredentials::hasDigestCredentials(const HTTPRequest& request) +{ + return request.has(HTTPRequest::AUTHORIZATION) && isDigestCredentials(request.get(HTTPRequest::AUTHORIZATION)); +} + + +bool HTTPCredentials::hasProxyBasicCredentials(const HTTPRequest& request) +{ + return request.has(HTTPRequest::PROXY_AUTHORIZATION) && isBasicCredentials(request.get(HTTPRequest::PROXY_AUTHORIZATION)); +} + + +bool HTTPCredentials::hasProxyDigestCredentials(const HTTPRequest& request) +{ + return request.has(HTTPRequest::PROXY_AUTHORIZATION) && isDigestCredentials(request.get(HTTPRequest::PROXY_AUTHORIZATION)); +} + + +void HTTPCredentials::extractCredentials(const std::string& userInfo, std::string& username, std::string& password) +{ + const std::string::size_type p = userInfo.find(':'); + + if (p != std::string::npos) + { + username.assign(userInfo, 0, p); + password.assign(userInfo, p + 1, std::string::npos); } -} - - -bool HTTPCredentials::isBasicCredentials(const std::string& header) -{ - return icompare(header, 0, 5, "Basic") == 0 && (header.size() > 5 ? Poco::Ascii::isSpace(header[5]) : true); -} - - -bool HTTPCredentials::isDigestCredentials(const std::string& header) -{ - return icompare(header, 0, 6, "Digest") == 0 && (header.size() > 6 ? Poco::Ascii::isSpace(header[6]) : true); -} - - -bool HTTPCredentials::hasBasicCredentials(const HTTPRequest& request) -{ - return request.has(HTTPRequest::AUTHORIZATION) && isBasicCredentials(request.get(HTTPRequest::AUTHORIZATION)); -} - - -bool HTTPCredentials::hasDigestCredentials(const HTTPRequest& request) -{ - return request.has(HTTPRequest::AUTHORIZATION) && isDigestCredentials(request.get(HTTPRequest::AUTHORIZATION)); -} - - -bool HTTPCredentials::hasProxyBasicCredentials(const HTTPRequest& request) -{ - return request.has(HTTPRequest::PROXY_AUTHORIZATION) && isBasicCredentials(request.get(HTTPRequest::PROXY_AUTHORIZATION)); -} - - -bool HTTPCredentials::hasProxyDigestCredentials(const HTTPRequest& request) -{ - return request.has(HTTPRequest::PROXY_AUTHORIZATION) && isDigestCredentials(request.get(HTTPRequest::PROXY_AUTHORIZATION)); -} - - -void HTTPCredentials::extractCredentials(const std::string& userInfo, std::string& username, std::string& password) -{ - const std::string::size_type p = userInfo.find(':'); - - if (p != std::string::npos) - { - username.assign(userInfo, 0, p); - password.assign(userInfo, p + 1, std::string::npos); - } - else - { - username.assign(userInfo); - password.clear(); - } -} - - -void HTTPCredentials::extractCredentials(const Poco::URI& uri, std::string& username, std::string& password) -{ - if (!uri.getUserInfo().empty()) - { - extractCredentials(uri.getUserInfo(), username, password); - } -} - - -} } // namespace Poco::Net + else + { + username.assign(userInfo); + password.clear(); + } +} + + +void HTTPCredentials::extractCredentials(const Poco::URI& uri, std::string& username, std::string& password) +{ + if (!uri.getUserInfo().empty()) + { + extractCredentials(uri.getUserInfo(), username, password); + } +} + + +} } // namespace Poco::Net |