2008-07-18 16:41:08 +02:00
|
|
|
/*
|
|
|
|
|
2012-10-02 05:16:33 +02:00
|
|
|
Copyright (c) 2008-2012, Arvid Norberg
|
2008-07-18 16:41:08 +02:00
|
|
|
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 <boost/version.hpp>
|
|
|
|
|
2009-07-26 04:27:52 +02:00
|
|
|
#include "libtorrent/config.hpp"
|
2008-07-18 16:41:08 +02:00
|
|
|
#include "libtorrent/error_code.hpp"
|
2011-01-16 03:54:59 +01:00
|
|
|
#include "libtorrent/escape_string.hpp" // for to_string()
|
2008-07-18 16:41:08 +02:00
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
2009-03-06 09:57:00 +01:00
|
|
|
#if BOOST_VERSION >= 103500
|
|
|
|
|
2013-06-22 01:00:34 +02:00
|
|
|
const char* libtorrent_error_category::name() const throw()
|
2008-07-18 16:41:08 +02:00
|
|
|
{
|
|
|
|
return "libtorrent error";
|
|
|
|
}
|
|
|
|
|
2013-06-22 01:00:34 +02:00
|
|
|
std::string libtorrent_error_category::message(int ev) const throw()
|
2008-07-18 16:41:08 +02:00
|
|
|
{
|
|
|
|
static char const* msgs[] =
|
2009-02-03 08:46:24 +01:00
|
|
|
{
|
|
|
|
"no error",
|
|
|
|
"torrent file collides with file from another torrent",
|
2009-02-13 20:01:02 +01:00
|
|
|
"hash check failed",
|
|
|
|
"torrent file is not a dictionary",
|
|
|
|
"missing or invalid 'info' section in torrent file",
|
|
|
|
"'info' entry is not a dictionary",
|
|
|
|
"invalid or missing 'piece length' entry in torrent file",
|
|
|
|
"missing name in torrent file",
|
|
|
|
"invalid 'name' of torrent (possible exploit attempt)",
|
|
|
|
"invalid length of torrent",
|
|
|
|
"failed to parse files from torrent file",
|
|
|
|
"invalid or missing 'pieces' entry in torrent file",
|
|
|
|
"incorrect number of piece hashes in torrent file",
|
2009-02-23 02:21:19 +01:00
|
|
|
"too many pieces in torrent",
|
|
|
|
"invalid metadata received from swarm",
|
|
|
|
"invalid bencoding",
|
|
|
|
"no files in torrent",
|
|
|
|
"invalid escaped string",
|
|
|
|
"session is closing",
|
|
|
|
"torrent already exists in session",
|
|
|
|
"invalid torrent handle used",
|
|
|
|
"invalid type requested from entry",
|
2009-02-26 08:09:56 +01:00
|
|
|
"missing info-hash from URI",
|
2009-05-21 18:15:05 +02:00
|
|
|
"file too short",
|
2009-05-30 20:50:38 +02:00
|
|
|
"unsupported URL protocol",
|
|
|
|
"failed to parse URL",
|
2009-06-12 18:40:38 +02:00
|
|
|
"peer sent 0 length piece",
|
|
|
|
"parse failed",
|
|
|
|
"invalid file format tag",
|
|
|
|
"missing info-hash",
|
|
|
|
"mismatching info-hash",
|
|
|
|
"invalid hostname",
|
|
|
|
"invalid port",
|
|
|
|
"port blocked by port-filter",
|
|
|
|
"expected closing ] for address",
|
|
|
|
"destructing torrent",
|
|
|
|
"timed out",
|
2009-06-24 03:49:06 +02:00
|
|
|
"upload to upload connection",
|
2009-06-12 18:40:38 +02:00
|
|
|
"uninteresting upload-only peer",
|
|
|
|
"invalid info-hash",
|
|
|
|
"torrent paused",
|
|
|
|
"'have'-message with higher index than the number of pieces",
|
|
|
|
"bitfield of invalid size",
|
|
|
|
"too many piece requests while choked",
|
|
|
|
"invalid piece packet",
|
|
|
|
"out of memory",
|
|
|
|
"torrent aborted",
|
|
|
|
"connected to ourselves",
|
|
|
|
"invalid piece size",
|
|
|
|
"timed out: no interest",
|
|
|
|
"timed out: inactivity",
|
|
|
|
"timed out: no handshake",
|
|
|
|
"timed out: no request",
|
|
|
|
"invalid choke message",
|
|
|
|
"invalid unchoke message",
|
|
|
|
"invalid interested message",
|
|
|
|
"invalid not-interested message",
|
|
|
|
"invalid request message",
|
|
|
|
"invalid hash list",
|
|
|
|
"invalid hash piece message",
|
|
|
|
"invalid cancel message",
|
|
|
|
"invalid dht-port message",
|
|
|
|
"invalid suggest piece message",
|
|
|
|
"invalid have-all message",
|
|
|
|
"invalid have-none message",
|
|
|
|
"invalid reject message",
|
|
|
|
"invalid allow-fast message",
|
|
|
|
"invalid extended message",
|
|
|
|
"invalid message",
|
|
|
|
"sync hash not found",
|
|
|
|
"unable to verify encryption constant",
|
|
|
|
"plaintext mode not provided",
|
|
|
|
"rc4 mode not provided",
|
|
|
|
"unsupported encryption mode",
|
|
|
|
"peer selected unsupported encryption mode",
|
|
|
|
"invalid encryption pad size",
|
|
|
|
"invalid encryption handshake",
|
|
|
|
"incoming encrypted connections disabled",
|
|
|
|
"incoming regular connections disabled",
|
|
|
|
"duplicate peer-id",
|
|
|
|
"torrent removed",
|
|
|
|
"packet too large",
|
2010-02-23 17:26:24 +01:00
|
|
|
"",
|
2009-06-12 18:40:38 +02:00
|
|
|
"HTTP error",
|
|
|
|
"missing location header",
|
|
|
|
"invalid redirection",
|
|
|
|
"redirecting",
|
|
|
|
"invalid HTTP range",
|
|
|
|
"missing content-length",
|
|
|
|
"banned by IP filter",
|
|
|
|
"too many connections",
|
|
|
|
"peer banned",
|
|
|
|
"stopping torrent",
|
|
|
|
"too many corrupt pieces",
|
|
|
|
"torrent is not ready to accept peers",
|
|
|
|
"peer is not properly constructed",
|
|
|
|
"session is closing",
|
|
|
|
"optimistic disconnect",
|
|
|
|
"torrent finished",
|
|
|
|
"no router found",
|
|
|
|
"metadata too large",
|
|
|
|
"invalid metadata request",
|
|
|
|
"invalid metadata size",
|
|
|
|
"invalid metadata offset",
|
|
|
|
"invalid metadata message",
|
|
|
|
"pex message too large",
|
|
|
|
"invalid pex message",
|
|
|
|
"invalid lt_tracker message",
|
2010-11-29 02:33:05 +01:00
|
|
|
"pex messages sent too frequent (possible attack)",
|
2011-03-04 07:17:55 +01:00
|
|
|
"torrent has no metadata",
|
2011-08-07 02:41:13 +02:00
|
|
|
"invalid dont-have message",
|
2012-01-14 17:04:25 +01:00
|
|
|
"SSL connection required",
|
|
|
|
"invalid SSL certificate",
|
2009-12-06 00:03:48 +01:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2009-06-28 02:36:41 +02:00
|
|
|
// natpmp errors
|
2009-06-12 18:40:38 +02:00
|
|
|
"unsupported protocol version",
|
|
|
|
"not authorized to create port map (enable NAT-PMP on your router)",
|
|
|
|
"network failure",
|
|
|
|
"out of resources",
|
|
|
|
"unsupported opcode",
|
2009-12-06 00:03:48 +01:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2009-06-28 02:36:41 +02:00
|
|
|
// fastresume errors
|
|
|
|
"missing or invalid 'file sizes' entry",
|
|
|
|
"no files in resume data",
|
|
|
|
"missing 'slots' and 'pieces' entry",
|
|
|
|
"mismatching number of files",
|
|
|
|
"mismatching file size",
|
|
|
|
"mismatching file timestamp",
|
|
|
|
"not a dictionary",
|
|
|
|
"invalid 'blocks per piece' entry",
|
|
|
|
"missing slots list",
|
|
|
|
"file has more slots than torrent",
|
|
|
|
"invalid entry type in slot list",
|
|
|
|
"invalid piece index in slot list",
|
|
|
|
"pieces needs to be reordered",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2009-12-06 00:03:48 +01:00
|
|
|
// HTTP errors
|
|
|
|
"Invalid HTTP header",
|
|
|
|
"missing Location header in HTTP redirect",
|
|
|
|
"failed to decompress HTTP response",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2009-06-28 02:36:41 +02:00
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2009-12-06 00:03:48 +01:00
|
|
|
// i2p errors
|
2009-08-20 05:19:12 +02:00
|
|
|
"no i2p router is set up",
|
2010-02-23 22:53:45 +01:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2011-11-13 04:35:03 +01:00
|
|
|
|
2010-02-23 22:53:45 +01:00
|
|
|
// tracker errors
|
|
|
|
"scrape not available on tracker",
|
|
|
|
"invalid tracker response",
|
|
|
|
"invalid peer dictionary entry",
|
|
|
|
"tracker sent a failure message",
|
|
|
|
"missing or invalid 'files' entry",
|
|
|
|
"missing or invalid 'hash' entry",
|
|
|
|
"missing or invalid 'peers' and 'peers6' entry",
|
|
|
|
"udp tracker response packet has invalid size",
|
|
|
|
"invalid transaction id in udp tracker response",
|
|
|
|
"invalid action field in udp tracker response",
|
2010-10-28 06:01:59 +02:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2010-11-25 03:49:50 +01:00
|
|
|
"",
|
2010-10-28 06:01:59 +02:00
|
|
|
|
|
|
|
// bdecode errors
|
2010-11-25 03:49:50 +01:00
|
|
|
"expected string in bencoded string",
|
|
|
|
"expected colon in bencoded string",
|
|
|
|
"unexpected end of file in bencoded string",
|
2010-10-28 06:01:59 +02:00
|
|
|
"expected value (list, dict, int or string) in bencoded string",
|
|
|
|
"bencoded nesting depth exceeded",
|
2010-11-25 03:49:50 +01:00
|
|
|
"bencoded item count limit exceeded",
|
2009-02-03 08:46:24 +01:00
|
|
|
};
|
2011-02-14 02:59:01 +01:00
|
|
|
if (ev < 0 || ev >= int(sizeof(msgs)/sizeof(msgs[0])))
|
2008-07-18 16:41:08 +02:00
|
|
|
return "Unknown error";
|
|
|
|
return msgs[ev];
|
|
|
|
}
|
|
|
|
|
2013-06-24 02:14:17 +02:00
|
|
|
boost::system::error_category& get_libtorrent_category()
|
|
|
|
{
|
|
|
|
static libtorrent_error_category libtorrent_category;
|
|
|
|
return libtorrent_category;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::system::error_category& get_http_category()
|
|
|
|
{
|
|
|
|
static http_error_category http_category;
|
|
|
|
return http_category;
|
|
|
|
}
|
|
|
|
|
2013-06-22 01:00:34 +02:00
|
|
|
const char* http_error_category::name() const throw()
|
2011-01-16 03:54:59 +01:00
|
|
|
{
|
|
|
|
return "http error";
|
|
|
|
}
|
|
|
|
|
2013-06-22 01:00:34 +02:00
|
|
|
std::string http_error_category::message(int ev) const throw()
|
2011-01-16 03:54:59 +01:00
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
ret += to_string(ev).elems;
|
|
|
|
ret += " ";
|
|
|
|
switch (ev)
|
|
|
|
{
|
|
|
|
case errors::cont: ret += "Continue"; break;
|
|
|
|
case errors::ok: ret += "OK"; break;
|
|
|
|
case errors::created: ret += "Created"; break;
|
|
|
|
case errors::accepted: ret += "Accepted"; break;
|
|
|
|
case errors::no_content: ret += "No Content"; break;
|
|
|
|
case errors::multiple_choices: ret += "Multiple Choices"; break;
|
|
|
|
case errors::moved_permanently: ret += "Moved Permanently"; break;
|
|
|
|
case errors::moved_temporarily: ret += "Moved Temporarily"; break;
|
|
|
|
case errors::not_modified: ret += "Not Modified"; break;
|
|
|
|
case errors::bad_request: ret += "Bad Request"; break;
|
|
|
|
case errors::unauthorized: ret += "Unauthorized"; break;
|
|
|
|
case errors::forbidden: ret += "Forbidden"; break;
|
|
|
|
case errors::not_found: ret += "Not Found"; break;
|
|
|
|
case errors::internal_server_error: ret += "Internal Server Error"; break;
|
|
|
|
case errors::not_implemented: ret += "Not Implemented"; break;
|
|
|
|
case errors::bad_gateway: ret += "Bad Gateway"; break;
|
|
|
|
case errors::service_unavailable: ret += "Service Unavailable"; break;
|
|
|
|
default: ret += "(unknown HTTP error)"; break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2008-07-18 16:41:08 +02:00
|
|
|
#endif
|
|
|
|
|
2012-09-30 21:35:08 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
|
|
|
const char* libtorrent_exception::what() const throw()
|
|
|
|
{
|
|
|
|
if (!m_msg)
|
|
|
|
{
|
2013-01-19 07:39:32 +01:00
|
|
|
std::string msg = convert_from_native(m_error.message());
|
2012-09-30 21:35:08 +02:00
|
|
|
m_msg = allocate_string_copy(msg.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
libtorrent_exception::~libtorrent_exception() throw()
|
|
|
|
{
|
|
|
|
free(m_msg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-03-06 09:57:00 +01:00
|
|
|
}
|
|
|
|
|