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/HTTPSessionFactory.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/HTTPSessionFactory.cpp')
-rw-r--r-- | contrib/libs/poco/Net/src/HTTPSessionFactory.cpp | 292 |
1 files changed, 146 insertions, 146 deletions
diff --git a/contrib/libs/poco/Net/src/HTTPSessionFactory.cpp b/contrib/libs/poco/Net/src/HTTPSessionFactory.cpp index 9e12c0a3ff..e4a62da68b 100644 --- a/contrib/libs/poco/Net/src/HTTPSessionFactory.cpp +++ b/contrib/libs/poco/Net/src/HTTPSessionFactory.cpp @@ -1,146 +1,146 @@ -// -// HTTPSessionFactory.cpp -// -// Library: Net -// Package: HTTPClient -// Module: HTTPSessionFactory -// -// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#include "Poco/Net/HTTPSessionFactory.h" -#include "Poco/Net/HTTPSessionInstantiator.h" -#include "Poco/Exception.h" - - -using Poco::SingletonHolder; -using Poco::FastMutex; -using Poco::NotFoundException; -using Poco::ExistsException; - - -namespace Poco { -namespace Net { - - -HTTPSessionFactory::HTTPSessionFactory(): - _proxyPort(0) -{ -} - - -HTTPSessionFactory::HTTPSessionFactory(const std::string& proxyHost, Poco::UInt16 proxyPort): - _proxyHost(proxyHost), - _proxyPort(proxyPort) -{ -} - - -HTTPSessionFactory::~HTTPSessionFactory() -{ - for (Instantiators::iterator it = _instantiators.begin(); it != _instantiators.end(); ++it) - { - delete it->second.pIn; - } -} - - -void HTTPSessionFactory::registerProtocol(const std::string& protocol, HTTPSessionInstantiator* pSessionInstantiator) -{ - poco_assert_dbg(pSessionInstantiator); - - FastMutex::ScopedLock lock(_mutex); - std::pair<Instantiators::iterator, bool> tmp = _instantiators.insert(make_pair(protocol, InstantiatorInfo(pSessionInstantiator))); - if (!tmp.second) - { - ++tmp.first->second.cnt; - delete pSessionInstantiator; - } -} - - -void HTTPSessionFactory::unregisterProtocol(const std::string& protocol) -{ - FastMutex::ScopedLock lock(_mutex); - - Instantiators::iterator it = _instantiators.find(protocol); - if (it != _instantiators.end()) - { - if (it->second.cnt == 1) - { - delete it->second.pIn; - _instantiators.erase(it); - } - else --it->second.cnt; - } - else throw NotFoundException("No HTTPSessionInstantiator registered for", protocol); -} - - -bool HTTPSessionFactory::supportsProtocol(const std::string& protocol) -{ - FastMutex::ScopedLock lock(_mutex); - - Instantiators::iterator it = _instantiators.find(protocol); - return it != _instantiators.end(); -} - - -HTTPClientSession* HTTPSessionFactory::createClientSession(const Poco::URI& uri) -{ - FastMutex::ScopedLock lock(_mutex); - - if (uri.isRelative()) throw Poco::UnknownURISchemeException("Relative URIs are not supported by HTTPSessionFactory."); - - Instantiators::iterator it = _instantiators.find(uri.getScheme()); - if (it != _instantiators.end()) - { - it->second.pIn->setProxy(_proxyHost, _proxyPort); - it->second.pIn->setProxyCredentials(_proxyUsername, _proxyPassword); - return it->second.pIn->createClientSession(uri); - } - else throw Poco::UnknownURISchemeException(uri.getScheme()); -} - - -void HTTPSessionFactory::setProxy(const std::string& host, Poco::UInt16 port) -{ - FastMutex::ScopedLock lock(_mutex); - - _proxyHost = host; - _proxyPort = port; -} - - -void HTTPSessionFactory::setProxyCredentials(const std::string& username, const std::string& password) -{ - FastMutex::ScopedLock lock(_mutex); - - _proxyUsername = username; - _proxyPassword = password; -} - - -namespace -{ - static SingletonHolder<HTTPSessionFactory> singleton; -} - - -HTTPSessionFactory& HTTPSessionFactory::defaultFactory() -{ - return *singleton.get(); -} - - -HTTPSessionFactory::InstantiatorInfo::InstantiatorInfo(HTTPSessionInstantiator* pInst): pIn(pInst), cnt(1) -{ - poco_check_ptr (pIn); -} - - -} } // namespace Poco::Net +// +// HTTPSessionFactory.cpp +// +// Library: Net +// Package: HTTPClient +// Module: HTTPSessionFactory +// +// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/Net/HTTPSessionFactory.h" +#include "Poco/Net/HTTPSessionInstantiator.h" +#include "Poco/Exception.h" + + +using Poco::SingletonHolder; +using Poco::FastMutex; +using Poco::NotFoundException; +using Poco::ExistsException; + + +namespace Poco { +namespace Net { + + +HTTPSessionFactory::HTTPSessionFactory(): + _proxyPort(0) +{ +} + + +HTTPSessionFactory::HTTPSessionFactory(const std::string& proxyHost, Poco::UInt16 proxyPort): + _proxyHost(proxyHost), + _proxyPort(proxyPort) +{ +} + + +HTTPSessionFactory::~HTTPSessionFactory() +{ + for (Instantiators::iterator it = _instantiators.begin(); it != _instantiators.end(); ++it) + { + delete it->second.pIn; + } +} + + +void HTTPSessionFactory::registerProtocol(const std::string& protocol, HTTPSessionInstantiator* pSessionInstantiator) +{ + poco_assert_dbg(pSessionInstantiator); + + FastMutex::ScopedLock lock(_mutex); + std::pair<Instantiators::iterator, bool> tmp = _instantiators.insert(make_pair(protocol, InstantiatorInfo(pSessionInstantiator))); + if (!tmp.second) + { + ++tmp.first->second.cnt; + delete pSessionInstantiator; + } +} + + +void HTTPSessionFactory::unregisterProtocol(const std::string& protocol) +{ + FastMutex::ScopedLock lock(_mutex); + + Instantiators::iterator it = _instantiators.find(protocol); + if (it != _instantiators.end()) + { + if (it->second.cnt == 1) + { + delete it->second.pIn; + _instantiators.erase(it); + } + else --it->second.cnt; + } + else throw NotFoundException("No HTTPSessionInstantiator registered for", protocol); +} + + +bool HTTPSessionFactory::supportsProtocol(const std::string& protocol) +{ + FastMutex::ScopedLock lock(_mutex); + + Instantiators::iterator it = _instantiators.find(protocol); + return it != _instantiators.end(); +} + + +HTTPClientSession* HTTPSessionFactory::createClientSession(const Poco::URI& uri) +{ + FastMutex::ScopedLock lock(_mutex); + + if (uri.isRelative()) throw Poco::UnknownURISchemeException("Relative URIs are not supported by HTTPSessionFactory."); + + Instantiators::iterator it = _instantiators.find(uri.getScheme()); + if (it != _instantiators.end()) + { + it->second.pIn->setProxy(_proxyHost, _proxyPort); + it->second.pIn->setProxyCredentials(_proxyUsername, _proxyPassword); + return it->second.pIn->createClientSession(uri); + } + else throw Poco::UnknownURISchemeException(uri.getScheme()); +} + + +void HTTPSessionFactory::setProxy(const std::string& host, Poco::UInt16 port) +{ + FastMutex::ScopedLock lock(_mutex); + + _proxyHost = host; + _proxyPort = port; +} + + +void HTTPSessionFactory::setProxyCredentials(const std::string& username, const std::string& password) +{ + FastMutex::ScopedLock lock(_mutex); + + _proxyUsername = username; + _proxyPassword = password; +} + + +namespace +{ + static SingletonHolder<HTTPSessionFactory> singleton; +} + + +HTTPSessionFactory& HTTPSessionFactory::defaultFactory() +{ + return *singleton.get(); +} + + +HTTPSessionFactory::InstantiatorInfo::InstantiatorInfo(HTTPSessionInstantiator* pInst): pIn(pInst), cnt(1) +{ + poco_check_ptr (pIn); +} + + +} } // namespace Poco::Net |