2011-06-25 22:11:31 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2011, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libtorrent/error_code.hpp>
|
2015-03-12 06:20:12 +01:00
|
|
|
#include <libtorrent/bdecode.hpp>
|
2014-02-02 04:05:55 +01:00
|
|
|
#include <libtorrent/upnp.hpp>
|
2014-02-02 05:07:36 +01:00
|
|
|
#include <libtorrent/socks5_stream.hpp>
|
2016-07-04 05:30:52 +02:00
|
|
|
|
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
// this fixe mysterious link error on msvc
|
|
|
|
boost::system::error_category const volatile*
|
|
|
|
get_pointer(boost::system::error_category const volatile* p)
|
|
|
|
{
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 01:04:36 +01:00
|
|
|
#include <boost/asio/error.hpp>
|
|
|
|
#if defined TORRENT_USE_OPENSSL
|
|
|
|
#include <boost/asio/ssl/error.hpp>
|
|
|
|
#endif
|
2016-04-08 04:45:23 +02:00
|
|
|
#include "boost_python.hpp"
|
2011-06-25 22:11:31 +02:00
|
|
|
|
|
|
|
using namespace boost::python;
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2014-02-01 05:02:58 +01:00
|
|
|
using boost::system::error_category;
|
2011-06-25 22:11:31 +02:00
|
|
|
|
2017-02-22 01:04:36 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct ec_pickle_suite : boost::python::pickle_suite
|
|
|
|
{
|
|
|
|
static boost::python::tuple
|
|
|
|
getinitargs(error_code const& ec)
|
|
|
|
{
|
|
|
|
return boost::python::tuple();
|
|
|
|
}
|
|
|
|
|
|
|
|
static boost::python::tuple
|
|
|
|
getstate(error_code const& ec)
|
|
|
|
{
|
|
|
|
return boost::python::make_tuple(ec.value(), ec.category().name());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setstate(error_code& ec, boost::python::tuple state)
|
|
|
|
{
|
|
|
|
using namespace boost::python;
|
|
|
|
if (len(state) != 2)
|
|
|
|
{
|
|
|
|
PyErr_SetObject(PyExc_ValueError,
|
|
|
|
("expected 2-item tuple in call to __setstate__; got %s"
|
|
|
|
% state).ptr());
|
|
|
|
throw_error_already_set();
|
|
|
|
}
|
|
|
|
|
|
|
|
int const value = extract<int>(state[0]);
|
|
|
|
std::string const category = extract<std::string>(state[1]);
|
|
|
|
if (category == "system")
|
2017-04-12 20:05:53 +02:00
|
|
|
ec.assign(value, lt::system_category());
|
2017-02-22 01:04:36 +01:00
|
|
|
else if (category == "generic")
|
2017-04-12 20:05:53 +02:00
|
|
|
ec.assign(value, lt::generic_category());
|
2017-02-22 01:04:36 +01:00
|
|
|
else if (category == "libtorrent")
|
2017-04-12 20:05:53 +02:00
|
|
|
ec.assign(value, lt::libtorrent_category());
|
2017-02-22 01:04:36 +01:00
|
|
|
else if (category == "http error")
|
2017-04-12 20:05:53 +02:00
|
|
|
ec.assign(value, lt::http_category());
|
2017-02-22 01:04:36 +01:00
|
|
|
else if (category == "UPnP error")
|
2017-04-12 20:05:53 +02:00
|
|
|
ec.assign(value, lt::upnp_category());
|
2017-02-22 01:04:36 +01:00
|
|
|
else if (category == "bdecode error")
|
2017-04-12 20:05:53 +02:00
|
|
|
ec.assign(value, lt::bdecode_category());
|
2017-02-22 01:04:36 +01:00
|
|
|
else if (category == "asio.netdb")
|
|
|
|
ec.assign(value, boost::asio::error::get_netdb_category());
|
|
|
|
else if (category == "asio.addinfo")
|
|
|
|
ec.assign(value, boost::asio::error::get_addrinfo_category());
|
|
|
|
else if (category == "asio.misc")
|
|
|
|
ec.assign(value, boost::asio::error::get_misc_category());
|
|
|
|
else if (category == "asio.misc")
|
|
|
|
ec.assign(value, boost::asio::error::get_misc_category());
|
|
|
|
#if defined TORRENT_USE_OPENSSL
|
|
|
|
else if (category == "asio.ssl")
|
|
|
|
ec.assign(value, boost::asio::error::get_ssl_category());
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetObject(PyExc_ValueError,
|
|
|
|
("unexpected error_category passed to __setstate__; got '%s'"
|
|
|
|
% object(category)).ptr());
|
|
|
|
throw_error_already_set();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-06-25 22:11:31 +02:00
|
|
|
void bind_error_code()
|
|
|
|
{
|
2016-07-04 05:30:52 +02:00
|
|
|
using boost::noncopyable;
|
|
|
|
|
|
|
|
class_<boost::system::error_category, noncopyable>("error_category", no_init)
|
2014-02-01 05:02:58 +01:00
|
|
|
.def("name", &error_category::name)
|
|
|
|
.def("message", &error_category::message)
|
|
|
|
.def(self == self)
|
|
|
|
.def(self < self)
|
|
|
|
.def(self != self)
|
|
|
|
;
|
|
|
|
|
2011-06-25 22:11:31 +02:00
|
|
|
class_<error_code>("error_code")
|
|
|
|
.def(init<>())
|
|
|
|
.def("message", &error_code::message)
|
|
|
|
.def("value", &error_code::value)
|
|
|
|
.def("clear", &error_code::clear)
|
2014-02-01 05:02:58 +01:00
|
|
|
.def("category", &error_code::category
|
2016-07-04 05:30:52 +02:00
|
|
|
, return_value_policy<reference_existing_object>())
|
2014-02-01 05:02:58 +01:00
|
|
|
.def("assign", &error_code::assign)
|
2017-02-22 01:04:36 +01:00
|
|
|
.def_pickle(ec_pickle_suite())
|
2011-06-25 22:11:31 +02:00
|
|
|
;
|
2014-02-01 05:02:58 +01:00
|
|
|
|
2016-10-02 21:27:50 +02:00
|
|
|
using return_existing = return_value_policy<reference_existing_object>;
|
2014-02-02 05:07:36 +01:00
|
|
|
|
2016-10-02 21:27:50 +02:00
|
|
|
def("libtorrent_category", &libtorrent_category, return_existing());
|
|
|
|
def("upnp_category", &upnp_category, return_existing());
|
|
|
|
def("http_category", &http_category, return_existing());
|
|
|
|
def("socks_category", &socks_category, return_existing());
|
|
|
|
def("bdecode_category", &bdecode_category, return_existing());
|
2014-02-02 05:07:36 +01:00
|
|
|
#if TORRENT_USE_I2P
|
2016-10-02 21:27:50 +02:00
|
|
|
def("i2p_category", &i2p_category, return_existing());
|
2014-02-02 05:07:36 +01:00
|
|
|
#endif
|
|
|
|
|
2016-10-02 21:27:50 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
def("get_libtorrent_category", &libtorrent_category, return_existing());
|
|
|
|
def("get_upnp_category", &upnp_category, return_existing());
|
|
|
|
def("get_http_category", &http_category, return_existing());
|
|
|
|
def("get_socks_category", &socks_category, return_existing());
|
|
|
|
def("get_bdecode_category", &bdecode_category, return_existing());
|
|
|
|
#if TORRENT_USE_I2P
|
|
|
|
def("get_i2p_category", &i2p_category, return_existing());
|
|
|
|
#endif
|
|
|
|
#endif // TORRENT_NO_DEPRECATE
|
2014-02-01 05:02:58 +01:00
|
|
|
|
2016-10-02 21:27:50 +02:00
|
|
|
def("generic_category", &boost::system::generic_category, return_existing());
|
2014-02-01 05:02:58 +01:00
|
|
|
|
2016-10-02 21:27:50 +02:00
|
|
|
def("system_category", &boost::system::system_category, return_existing());
|
2011-06-25 22:11:31 +02:00
|
|
|
}
|
|
|
|
|