From 3f36dd039539086a0082023a2fa7b49891476a9f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 1 Nov 2005 18:30:39 +0000 Subject: [PATCH] added the ability to build libtorrent as a shared library. Fixed bugs with deleting of incomplete types (replaced auto_ptr with scoped_ptr). Made the string converter fall back on windows local code page if utf-8 decoding failed. --- ChangeLog | 5 +- Jamfile | 3 +- docs/manual.html | 94 ++++++++++-- docs/manual.rst | 45 +++++- docs/udp_tracker_protocol.html | 141 ++++++++++-------- docs/udp_tracker_protocol.rst | 33 ++-- include/libtorrent/alert.hpp | 9 +- include/libtorrent/alert_types.hpp | 31 ++-- include/libtorrent/bencode.hpp | 5 +- include/libtorrent/config.hpp | 62 ++++++++ include/libtorrent/entry.hpp | 5 +- include/libtorrent/escape_string.hpp | 5 +- include/libtorrent/file.hpp | 5 +- include/libtorrent/hasher.hpp | 9 +- .../libtorrent/http_tracker_connection.hpp | 3 +- include/libtorrent/identify_client.hpp | 3 +- include/libtorrent/ip_filter.hpp | 3 +- include/libtorrent/peer.hpp | 2 +- include/libtorrent/peer_connection.hpp | 5 +- include/libtorrent/peer_id.hpp | 4 +- include/libtorrent/peer_info.hpp | 3 +- include/libtorrent/peer_request.hpp | 2 +- include/libtorrent/piece_block_progress.hpp | 4 +- include/libtorrent/piece_picker.hpp | 6 +- include/libtorrent/policy.hpp | 4 +- include/libtorrent/resource_request.hpp | 4 +- include/libtorrent/session.hpp | 6 +- include/libtorrent/socket.hpp | 10 +- include/libtorrent/stat.hpp | 3 +- include/libtorrent/storage.hpp | 14 +- include/libtorrent/torrent.hpp | 8 +- include/libtorrent/torrent_handle.hpp | 11 +- include/libtorrent/torrent_info.hpp | 10 +- include/libtorrent/tracker_manager.hpp | 15 +- include/libtorrent/udp_tracker_connection.hpp | 4 +- include/libtorrent/utf8.hpp | 15 -- src/entry.cpp | 3 +- src/sha1.cpp | 10 +- src/storage.cpp | 11 +- src/torrent.cpp | 4 +- 40 files changed, 409 insertions(+), 210 deletions(-) create mode 100755 include/libtorrent/config.hpp diff --git a/ChangeLog b/ChangeLog index 63af7f11f..515ea6777 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,12 @@ + * strings that are invalid utf-8 strings are now decoded with the + local codepage on windows + * added the ability to build libtorrent both as a shared library * client_test can now monitor a directory for torrent files and automatically start and stop downloads while running * fixed problem with file_size() when building on windows with unicode support * added a new torrent state, allocating * added a new alert, metadata_failed_alert - * changed the interface to session::add_torrent for soem speed optimizations. + * changed the interface to session::add_torrent for some speed optimizations. * greatly improved the command line control of the example client_test. * fixed bug where upload rate limit was not being applied. * files that are being checked will no longer stall files that don't need diff --git a/Jamfile b/Jamfile index 575e141f9..b203ba0e8 100755 --- a/Jamfile +++ b/Jamfile @@ -32,10 +32,10 @@ project torrent /boost/thread//boost_thread/static /boost/filesystem//boost_filesystem/static /boost/date_time//boost_date_time/static - static multi msvc:/Zc:wchar_t msvc:/Zc:forScope + shared:TORRENT_BUILDING_SHARED : usage-requirements @@ -43,6 +43,7 @@ project torrent $(BOOST_ROOT) release:NDEBUG BOOST_ALL_NO_LIB + shared:TORRENT_LINKING_SHARED ; diff --git a/docs/manual.html b/docs/manual.html index 095b3879e..900408fca 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -1,14 +1,41 @@ - - - + + + - - -libtorrent manual - - +Rasterbar Software | Products | libtorrent + + + + + + + +
+
+ +
+ + +
+

libtorrent manual

@@ -198,7 +225,7 @@ to the other party.
  • fast resume support, a way to get rid of the costly piece check at the start of a resumed torrent. Saves the storage state, piece_picker state as well as all local peers in a separate fast-resume file.
  • -
  • supports the extension protocol specified by Nolar. See extensions.
  • +
  • supports an extension protocol. See extensions.
  • supports files > 2 gigabytes.
  • supports the no_peer_id=1 extension that will ease the load off trackers.
  • supports the udp-tracker protocol by Olaf van der Spek.
  • @@ -322,8 +349,9 @@ files found. So, set this to c:\b a specific toolset to use (compiler) you can just add that to the commandline. For example:

    -bjam msvc-7.1
    -bjam gcc-3.3
    +bjam msvc-7.1 link=static
    +bjam gcc-3.3 link=static
    +bjam darwin-4.0 link=static
     

    To build different versions you can also just add the name of the build variant. Some default build variants in BBv2 are release, debug, @@ -331,6 +359,13 @@ variant. Some default build variants in BBv2 are If you're building on a platform where dlls share the same heap, you can build libtorrent as a dll too, by typing link=shared, or link=static to explicitly build a static library.

    +

    If you want to explicitly say how to link against the runtime library, you +can set the runtime-link feature on the commandline, either to shared +or static. Most operating systems will only allow linking shared against +the runtime, but on windows you can do both. Example:

    +
    +bjam msvc-7.1 link=static runtime-link=staitc
    +

    The build targets are put in a directory called bin, and under it they are sorted in directories depending on the toolset and build variant used.

    To build the examples, just change directory to the examples directory and @@ -346,7 +381,7 @@ windows format (c:/boost_1_33_0The Jamfile will define NDEBUG when it's building a release build. There are two other build variants available in the Jamfile. debug_log and release_log, these two variants inherits from the debug and release -variants respectively, but adds extra logging (TORRENT_VERBOSE_LOGGIN). +variants respectively, but adds extra logging (TORRENT_VERBOSE_LOGGING). For more build configuration flags see Build configurations.

    The Jamfile has the following build variants:

    @@ -506,6 +541,25 @@ GCC) both little-endian and big-endian versions will be built and the correct code will be chosen at run-time. +
    + + + + +
    TORRENT_LINKING_SHAREDIf this is defined when including the +libtorrent headers, the classes and functions +will be tagged with __declspec(dllimport) +on msvc and default visibility on GCC 4 and +later. Set this in your project if you're +linking against libtorrent as a shared library. +(This is set by the Jamfile when +link=shared is set).
    TORRENT_BUILDING_SHAREDIf this is defined, the functions and classes +in libtorrent are marked with +__declspec(dllexport) on msvc, or with +default visibility on GCC 4 and later. This +should be defined when building libtorrent as +a shared library. (This is set by the Jamfile +when link=shared is set).

    If you experience that libtorrent uses unreasonable amounts of cpu, it will @@ -1795,7 +1849,7 @@ any combination of the enums above. The following table describes each flag:

    support_extensions means that this peer supports the -extension protocol. +extension protocol. local_connection The connection was initiated by us, the peer has a @@ -2964,6 +3018,8 @@ drawbacks of this mode are:

  • It will take longer to start the torrent, since it will need to fill the files with zeroes. This delay is linearly dependent on the size of the download.
  • The download will occupy unnecessary disk space between download sessions.
  • +
  • Disk caches usually perform extremely poorly with random access to large files +and may slow down a download considerably.
  • The benefit of thise mode are:

    @@ -2993,6 +3049,8 @@ download has all its pieces in the correct place). So, the main drawbacks are:
  • No startup delay, since the files doesn't need allocating.
  • The download will not use unnecessary disk space.
  • +
  • Disk caches perform much better than in full allocation and raises the download +speed limit imposed by the disk.
  • The algorithm that is used when allocating pieces and slots isn't very complicated. @@ -3023,7 +3081,7 @@ contain any piece), return that slot index.

    extensions

    -

    These extensions all operates within the extension protocol. The +

    These extensions all operates within the extension protocol. The name of the extension is the name used in the extension-list packets, and the payload is the data in the extended message (not counting the length-prefix, message-id nor extension-id).

    @@ -3208,5 +3266,13 @@ scripts.

    sf_logo

    +
    + + + + + diff --git a/docs/manual.rst b/docs/manual.rst index 2826b27c0..0652f4b50 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -47,7 +47,7 @@ following features: * fast resume support, a way to get rid of the costly piece check at the start of a resumed torrent. Saves the storage state, piece_picker state as well as all local peers in a separate fast-resume file. - * supports the extension protocol `specified by Nolar`__. See extensions_. + * supports an `extension protocol`__. See extensions_. * supports files > 2 gigabytes. * supports the ``no_peer_id=1`` extension that will ease the load off trackers. * supports the `udp-tracker protocol`__ by Olaf van der Spek. @@ -65,7 +65,7 @@ following features: __ http://home.elp.rr.com/tur/multitracker-spec.txt .. _Azureus: http://azureus.sourceforge.net -__ http://nolar.com/azureus/extended.htm +__ extension_protocol.html __ udp_tracker_protocol.html @@ -200,8 +200,9 @@ Then the only thing left is simply to invoke ``bjam``. If you want to specify a specific toolset to use (compiler) you can just add that to the commandline. For example:: - bjam msvc-7.1 - bjam gcc-3.3 + bjam msvc-7.1 link=static + bjam gcc-3.3 link=static + bjam darwin-4.0 link=static To build different versions you can also just add the name of the build variant. Some default build variants in BBv2 are ``release``, ``debug``, @@ -211,6 +212,13 @@ If you're building on a platform where dlls share the same heap, you can build libtorrent as a dll too, by typing ``link=shared``, or ``link=static`` to explicitly build a static library. +If you want to explicitly say how to link against the runtime library, you +can set the ``runtime-link`` feature on the commandline, either to ``shared`` +or ``static``. Most operating systems will only allow linking shared against +the runtime, but on windows you can do both. Example:: + + bjam msvc-7.1 link=static runtime-link=staitc + The build targets are put in a directory called bin, and under it they are sorted in directories depending on the toolset and build variant used. @@ -229,7 +237,7 @@ windows format (``c:/boost_1_33_0``). The ``Jamfile`` will define ``NDEBUG`` when it's building a release build. There are two other build variants available in the ``Jamfile``. debug_log and release_log, these two variants inherits from the debug and release -variants respectively, but adds extra logging (``TORRENT_VERBOSE_LOGGIN``). +variants respectively, but adds extra logging (``TORRENT_VERBOSE_LOGGING``). For more build configuration flags see `Build configurations`_. The ``Jamfile`` has the following build variants: @@ -386,6 +394,23 @@ defines you can use to control the build. | | will be built and the correct code will be | | | chosen at run-time. | +--------------------------------+-------------------------------------------------+ +| ``TORRENT_LINKING_SHARED`` | If this is defined when including the | +| | libtorrent headers, the classes and functions | +| | will be tagged with ``__declspec(dllimport)`` | +| | on msvc and default visibility on GCC 4 and | +| | later. Set this in your project if you're | +| | linking against libtorrent as a shared library. | +| | (This is set by the Jamfile when | +| | ``link=shared`` is set). | ++--------------------------------+-------------------------------------------------+ +| ``TORRENT_BUILDING_SHARED`` | If this is defined, the functions and classes | +| | in libtorrent are marked with | +| | ``__declspec(dllexport)`` on msvc, or with | +| | default visibility on GCC 4 and later. This | +| | should be defined when building libtorrent as | +| | a shared library. (This is set by the Jamfile | +| | when ``link=shared`` is set). | ++--------------------------------+-------------------------------------------------+ If you experience that libtorrent uses unreasonable amounts of cpu, it will @@ -1768,7 +1793,7 @@ any combination of the enums above. The following table describes each flag: | | us. | +-------------------------+-------------------------------------------------------+ -__ http://nolar.com/azureus/extended.htm +__ extension_protocol.html The ``ip`` field is the IP-address to this peer. Its type is a wrapper around the actual address and the port number. See address_ class. @@ -3035,6 +3060,9 @@ drawbacks of this mode are: * The download will occupy unnecessary disk space between download sessions. + * Disk caches usually perform extremely poorly with random access to large files + and may slow down a download considerably. + The benefit of thise mode are: * Downloaded pieces are written directly to their final place in the files and the @@ -3062,6 +3090,9 @@ The benefits though, are: * The download will not use unnecessary disk space. + * Disk caches perform much better than in full allocation and raises the download + speed limit imposed by the disk. + The algorithm that is used when allocating pieces and slots isn't very complicated. For the interested, a description follows. @@ -3096,7 +3127,7 @@ name of the extension is the name used in the extension-list packets, and the payload is the data in the extended message (not counting the length-prefix, message-id nor extension-id). -__ http://nolar.com/azureus/extended.html +__ extension_protocol.html Note that since this protocol relies on one of the reserved bits in the handshake, it may be incompatible with future versions of the mainline diff --git a/docs/udp_tracker_protocol.html b/docs/udp_tracker_protocol.html index 794fc8350..d51831766 100644 --- a/docs/udp_tracker_protocol.html +++ b/docs/udp_tracker_protocol.html @@ -1,48 +1,69 @@ - - - + + + - - -Bittorrent udp-tracker protocol extension - +Rasterbar Software | Products | libtorrent + + + + + + + +
    +
    + +
    + + +
    +

    Bittorrent udp-tracker protocol extension

    -
    -

    Contents

    + +++ + + + +
    Author:Arvid Norberg, arvid@rasterbar.com
    +
    -

    introduction

    +

    introduction

    A tracker with the protocol "udp://" in its URI is supposed to be contacted using this protocol.

    This protocol is supported by @@ -57,9 +78,8 @@ the request. If no reply has been received after 60 seconds, stop retrying.

    -

    connecting

    -
    -

    Client sends packet:

    +

    connecting

    +

    Client sends packet:

    @@ -89,9 +109,7 @@ identify the protocol.
    -
    -
    -

    Server replies with packet:

    +

    Server replies with packet:

    @@ -129,11 +147,9 @@ anymore.
    -
    -

    announcing

    -
    -

    Client sends packet:

    +

    announcing

    +

    Client sends packet:

    @@ -224,9 +240,7 @@ in the reply. Use -1 for default.
    -
    -
    -

    Server replies with packet:

    +

    Server replies with packet:

    @@ -295,11 +309,9 @@ seeding.
    -
    -

    scraping

    -
    -

    Client sends packet:

    +

    scraping

    +

    Client sends packet:

    @@ -358,9 +370,7 @@ follow.
    -
    -
    -

    Server replies with packet:

    +

    Server replies with packet:

    @@ -418,12 +428,10 @@ leechers.
    -
    -

    errors

    +

    errors

    In case of a tracker error,

    -
    -

    server replies packet:

    +

    server replies packet:

    @@ -455,9 +463,8 @@ describing the error.
    -
    -

    actions

    +

    actions

    The action fields has the following encoding:

      @@ -469,7 +476,7 @@ describing the error.
    -

    extensions

    +

    extensions

    The extensions field is a bitmask. The following bits are assigned:

    @@ -478,7 +485,7 @@ bits are assigned:

    -

    authentication

    +

    authentication

    The packet will have an authentication part appended to it. It has the following format:

    @@ -518,9 +525,17 @@ from the 20 bytes hash calculated.
    -

    credits

    +

    credits

    Protocol designed by Olaf van der Spek

    + + + + + + diff --git a/docs/udp_tracker_protocol.rst b/docs/udp_tracker_protocol.rst index f1682799d..768c6e492 100755 --- a/docs/udp_tracker_protocol.rst +++ b/docs/udp_tracker_protocol.rst @@ -1,12 +1,15 @@ -========================================= Bittorrent udp-tracker protocol extension ========================================= -.. contents:: +:Author: Arvid Norberg, arvid@rasterbar.com + +.. contents:: Table of contents + :depth: 2 + :backlinks: none introduction -++++++++++++ +------------ A tracker with the protocol "udp://" in its URI is supposed to be contacted using this protocol. @@ -32,10 +35,9 @@ retrying. connecting -++++++++++ +---------- Client sends packet: --------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -50,7 +52,6 @@ Client sends packet: +-------------+---------------------+----------------------------------------+ Server replies with packet: ---------------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -73,10 +74,9 @@ Server replies with packet: announcing -++++++++++ +---------- Client sends packet: --------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -127,7 +127,6 @@ Client sends packet: Server replies with packet: ---------------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -163,11 +162,9 @@ The rest of the server reply is a variable number of the following structure: scraping -++++++++ - +-------- Client sends packet: --------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -196,7 +193,6 @@ The following structure is repeated ``num_info_hashes`` times: Server replies with packet: ---------------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -225,12 +221,11 @@ you asked in the scrape request. errors -++++++ +------ In case of a tracker error, server replies packet: ----------------------- +-------------+---------------------+----------------------------------------+ | size | name | description | @@ -247,7 +242,7 @@ server replies packet: actions -+++++++ +------- The action fields has the following encoding: @@ -258,7 +253,7 @@ The action fields has the following encoding: extensions -++++++++++ +---------- The extensions field is a bitmask. The following bits are assigned: @@ -268,7 +263,7 @@ bits are assigned: authentication --------------- +~~~~~~~~~~~~~~ The packet will have an authentication part appended to it. It has the following format: @@ -292,7 +287,7 @@ appended to it. It has the following format: credits -+++++++ +------- Protocol designed by Olaf van der Spek diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp index 3fec24a19..50b24bc0d 100755 --- a/include/libtorrent/alert.hpp +++ b/include/libtorrent/alert.hpp @@ -55,10 +55,11 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(pop) #endif +#include "libtorrent/config.hpp" namespace libtorrent { - class alert + class TORRENT_EXPORT alert { public: enum severity_t { debug, info, warning, critical, fatal, none }; @@ -81,7 +82,7 @@ namespace libtorrent { boost::posix_time::ptime m_timestamp; }; - class alert_manager + class TORRENT_EXPORT alert_manager { public: alert_manager(); @@ -100,7 +101,7 @@ namespace libtorrent { mutable boost::mutex m_mutex; }; - struct unhandled_alert : std::exception + struct TORRENT_EXPORT unhandled_alert : std::exception { unhandled_alert() {} }; @@ -145,7 +146,7 @@ namespace libtorrent { template< BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(5, class T, detail::void_) > - struct handle_alert + struct TORRENT_EXPORT handle_alert { template handle_alert( diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index c6d85f141..2a91d8d79 100755 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -37,10 +37,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/torrent_handle.hpp" #include "libtorrent/socket.hpp" #include "libtorrent/peer_connection.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { - struct tracker_alert: alert + struct TORRENT_EXPORT tracker_alert: alert { tracker_alert(torrent_handle const& h , int times @@ -60,7 +61,7 @@ namespace libtorrent int status_code; }; - struct tracker_warning_alert: alert + struct TORRENT_EXPORT tracker_warning_alert: alert { tracker_warning_alert(torrent_handle const& h , std::string const& msg) @@ -76,7 +77,7 @@ namespace libtorrent - struct tracker_reply_alert: alert + struct TORRENT_EXPORT tracker_reply_alert: alert { tracker_reply_alert(torrent_handle const& h , std::string const& msg) @@ -90,7 +91,7 @@ namespace libtorrent torrent_handle handle; }; - struct tracker_announce_alert: alert + struct TORRENT_EXPORT tracker_announce_alert: alert { tracker_announce_alert(torrent_handle const& h, std::string const& msg) : alert(alert::info, msg) @@ -103,7 +104,7 @@ namespace libtorrent torrent_handle handle; }; - struct hash_failed_alert: alert + struct TORRENT_EXPORT hash_failed_alert: alert { hash_failed_alert( torrent_handle const& h @@ -121,7 +122,7 @@ namespace libtorrent int piece_index; }; - struct peer_ban_alert: alert + struct TORRENT_EXPORT peer_ban_alert: alert { peer_ban_alert(address const& pip, torrent_handle h, std::string const& msg) : alert(alert::info, msg) @@ -136,7 +137,7 @@ namespace libtorrent torrent_handle handle; }; - struct peer_error_alert: alert + struct TORRENT_EXPORT peer_error_alert: alert { peer_error_alert(address const& pip, peer_id const& pid, std::string const& msg) : alert(alert::debug, msg) @@ -151,7 +152,7 @@ namespace libtorrent peer_id id; }; - struct chat_message_alert: alert + struct TORRENT_EXPORT chat_message_alert: alert { chat_message_alert( const torrent_handle& h @@ -169,7 +170,7 @@ namespace libtorrent address ip; }; - struct invalid_request_alert: alert + struct TORRENT_EXPORT invalid_request_alert: alert { invalid_request_alert( peer_request const& r @@ -193,7 +194,7 @@ namespace libtorrent peer_id id; }; - struct torrent_finished_alert: alert + struct TORRENT_EXPORT torrent_finished_alert: alert { torrent_finished_alert( const torrent_handle& h @@ -208,7 +209,7 @@ namespace libtorrent torrent_handle handle; }; - struct file_error_alert: alert + struct TORRENT_EXPORT file_error_alert: alert { file_error_alert( const torrent_handle& h @@ -223,7 +224,7 @@ namespace libtorrent torrent_handle handle; }; - struct metadata_failed_alert: alert + struct TORRENT_EXPORT metadata_failed_alert: alert { metadata_failed_alert( const torrent_handle& h @@ -238,7 +239,7 @@ namespace libtorrent torrent_handle handle; }; - struct metadata_received_alert: alert + struct TORRENT_EXPORT metadata_received_alert: alert { metadata_received_alert( const torrent_handle& h @@ -253,7 +254,7 @@ namespace libtorrent torrent_handle handle; }; - struct listen_failed_alert: alert + struct TORRENT_EXPORT listen_failed_alert: alert { listen_failed_alert( const std::string& msg) @@ -264,7 +265,7 @@ namespace libtorrent { return std::auto_ptr(new listen_failed_alert(*this)); } }; - struct fastresume_rejected_alert: alert + struct TORRENT_EXPORT fastresume_rejected_alert: alert { fastresume_rejected_alert(torrent_handle const& h , std::string const& msg) diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index 972a6e4c1..ed52a1c76 100755 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -77,6 +77,7 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include "libtorrent/entry.hpp" +#include "libtorrent/config.hpp" #if defined(_MSC_VER) namespace std @@ -92,7 +93,7 @@ namespace std namespace libtorrent { - struct invalid_encoding: std::exception + struct TORRENT_EXPORT invalid_encoding: std::exception { virtual const char* what() const throw() { return "invalid bencoding"; } }; @@ -106,7 +107,7 @@ namespace libtorrent std::copy(val.begin(), end, out); } - char const* integer_to_str(char* buf, int size, entry::integer_type val); + TORRENT_EXPORT char const* integer_to_str(char* buf, int size, entry::integer_type val); template void write_integer(OutIt& out, entry::integer_type val) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp new file mode 100755 index 000000000..864a2a2b5 --- /dev/null +++ b/include/libtorrent/config.hpp @@ -0,0 +1,62 @@ +/* + +Copyright (c) 2005, 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. + +*/ + +#ifndef TORRENT_CONFIG_HPP_INCLUDED +#define TORRENT_CONFIG_HPP_INCLUDED + +#include + +#if defined(__GNUC__) && __GNUC__ >= 4 + +# if defined(TORRENT_BUILDING_SHARED) || defined(TORRENT_LINKING_SHARED) +# define TORRENT_EXPORT __attribute__ ((visibility("default"))) +# else +# define TORRENT_EXPORT +# endif + +#elif defined(BOOST_MSVC) + +# if defined(TORRENT_BUILDING_SHARED) +# define TORRENT_EXPORT __declspec(dllexport) +# elif defined(TORRENT_LINKING_SHARED) +# define TORRENT_EXPORT __declspec(dllimport) +# else +# define TORRENT_EXPORT +# endif + +#else +# define TORRENT_EXPORT +#endif + + +#endif // TORRENT_CONFIG_HPP_INCLUDED + diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index 7d8af88fd..85c5462a2 100755 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -67,11 +67,12 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/size_type.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { - struct type_error: std::runtime_error + struct TORRENT_EXPORT type_error: std::runtime_error { type_error(const char* error): std::runtime_error(error) {} }; @@ -104,7 +105,7 @@ namespace libtorrent class entry; - class entry + class TORRENT_EXPORT entry { public: diff --git a/include/libtorrent/escape_string.hpp b/include/libtorrent/escape_string.hpp index 6c766c89f..1f30f744c 100755 --- a/include/libtorrent/escape_string.hpp +++ b/include/libtorrent/escape_string.hpp @@ -34,11 +34,12 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_ESCAPE_STRING_HPP_INCLUDED #include +#include "libtorrent/config.hpp" namespace libtorrent { - std::string unescape_string(std::string const& s); - std::string escape_string(const char* str, int len); + std::string TORRENT_EXPORT unescape_string(std::string const& s); + std::string TORRENT_EXPORT escape_string(const char* str, int len); } #endif // TORRENT_ESCAPE_STRING_HPP_INCLUDED diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index 2f8b841a3..4c7a78982 100755 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -48,16 +48,17 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include "libtorrent/size_type.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { - struct file_error: std::runtime_error + struct TORRENT_EXPORT file_error: std::runtime_error { file_error(std::string const& msg): std::runtime_error(msg) {} }; - class file: public boost::noncopyable + class TORRENT_EXPORT file: public boost::noncopyable { public: diff --git a/include/libtorrent/hasher.hpp b/include/libtorrent/hasher.hpp index 0de45b770..803b758eb 100755 --- a/include/libtorrent/hasher.hpp +++ b/include/libtorrent/hasher.hpp @@ -37,18 +37,19 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/peer_id.hpp" +#include "libtorrent/config.hpp" // from sha1.cpp -struct SHA1_CTX +struct TORRENT_EXPORT SHA1_CTX { boost::uint32_t state[5]; boost::uint32_t count[2]; boost::uint8_t buffer[64]; }; -void SHA1Init(SHA1_CTX* context); -void SHA1Update(SHA1_CTX* context, boost::uint8_t const* data, boost::uint32_t len); -void SHA1Final(SHA1_CTX* context, boost::uint8_t* digest); +TORRENT_EXPORT void SHA1Init(SHA1_CTX* context); +TORRENT_EXPORT void SHA1Update(SHA1_CTX* context, boost::uint8_t const* data, boost::uint32_t len); +TORRENT_EXPORT void SHA1Final(SHA1_CTX* context, boost::uint8_t* digest); extern "C" { diff --git a/include/libtorrent/http_tracker_connection.hpp b/include/libtorrent/http_tracker_connection.hpp index 6a3293a37..26629a9c5 100755 --- a/include/libtorrent/http_tracker_connection.hpp +++ b/include/libtorrent/http_tracker_connection.hpp @@ -57,11 +57,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer.hpp" #include "libtorrent/tracker_manager.hpp" #include "libtorrent/async_gethostbyname.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { - class http_tracker_connection: public tracker_connection + class TORRENT_EXPORT http_tracker_connection: public tracker_connection { friend class tracker_manager; public: diff --git a/include/libtorrent/identify_client.hpp b/include/libtorrent/identify_client.hpp index d4a5c60f9..4a676ae4b 100755 --- a/include/libtorrent/identify_client.hpp +++ b/include/libtorrent/identify_client.hpp @@ -34,11 +34,12 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_IDENTIFY_CLIENT_HPP_INCLUDED #include "libtorrent/peer_id.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { - std::string identify_client(const peer_id& p); + TORRENT_EXPORT std::string identify_client(const peer_id& p); } diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index e68299976..0d7dc3b5d 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -34,13 +34,14 @@ POSSIBILITY OF SUCH DAMAGE. #define IP_FILTER_HPP #include "libtorrent/socket.hpp" +#include "libtorrent/config.hpp" #include #include namespace libtorrent { -class ip_filter +class TORRENT_EXPORT ip_filter { public: diff --git a/include/libtorrent/peer.hpp b/include/libtorrent/peer.hpp index 1e9cc7765..842cf59f9 100755 --- a/include/libtorrent/peer.hpp +++ b/include/libtorrent/peer.hpp @@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct peer_entry + struct TORRENT_EXPORT peer_entry { std::string ip; int port; diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 38a4a8d64..0f3b65f97 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -66,6 +66,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/allocate_resources.hpp" #include "libtorrent/peer_request.hpp" #include "libtorrent/piece_block_progress.hpp" +#include "libtorrent/config.hpp" // TODO: each time a block is 'taken over' // from another peer. That peer must be given @@ -80,12 +81,12 @@ namespace libtorrent struct session_impl; } - struct protocol_error: std::runtime_error + struct TORRENT_EXPORT protocol_error: std::runtime_error { protocol_error(const std::string& msg): std::runtime_error(msg) {}; }; - class peer_connection: public boost::noncopyable + class TORRENT_EXPORT peer_connection: public boost::noncopyable { friend class invariant_access; public: diff --git a/include/libtorrent/peer_id.hpp b/include/libtorrent/peer_id.hpp index 9ce88bd4b..ad72a15c2 100755 --- a/include/libtorrent/peer_id.hpp +++ b/include/libtorrent/peer_id.hpp @@ -39,10 +39,12 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include "libtorrent/config.hpp" + namespace libtorrent { - class big_number + class TORRENT_EXPORT big_number { // private type struct private_pointer {}; diff --git a/include/libtorrent/peer_info.hpp b/include/libtorrent/peer_info.hpp index c10638020..ae6e31d0b 100755 --- a/include/libtorrent/peer_info.hpp +++ b/include/libtorrent/peer_info.hpp @@ -38,10 +38,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/size_type.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { - struct peer_info + struct TORRENT_EXPORT peer_info { enum { diff --git a/include/libtorrent/peer_request.hpp b/include/libtorrent/peer_request.hpp index 6d12548c2..ff4033ad3 100644 --- a/include/libtorrent/peer_request.hpp +++ b/include/libtorrent/peer_request.hpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct peer_request + struct TORRENT_EXPORT peer_request { int piece; int start; diff --git a/include/libtorrent/piece_block_progress.hpp b/include/libtorrent/piece_block_progress.hpp index 4f5b3ce4c..481ffc971 100644 --- a/include/libtorrent/piece_block_progress.hpp +++ b/include/libtorrent/piece_block_progress.hpp @@ -33,9 +33,11 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_PIECE_BLOCK_PROGRESS_HPP_INCLUDED #define TORRENT_PIECE_BLOCK_PROGRESS_HPP_INCLUDED +#include "libtorrent/config.hpp" + namespace libtorrent { - struct piece_block_progress + struct TORRENT_EXPORT piece_block_progress { // the piece and block index // determines exactly which diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index b178aa6cd..74a6d142c 100755 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_id.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { @@ -57,7 +58,7 @@ namespace libtorrent class address; class peer_connection; - struct piece_block + struct TORRENT_EXPORT piece_block { piece_block(int p_index, int b_index) : piece_index(p_index) @@ -81,7 +82,7 @@ namespace libtorrent }; - class piece_picker + class TORRENT_EXPORT piece_picker { public: @@ -335,3 +336,4 @@ namespace libtorrent } #endif // TORRENT_PIECE_PICKER_HPP_INCLUDED + diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index c980b292f..a677b5523 100755 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/size_type.hpp" #include "libtorrent/invariant_check.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { @@ -71,7 +72,7 @@ namespace libtorrent }; - class policy + class TORRENT_EXPORT policy { public: @@ -239,3 +240,4 @@ namespace libtorrent } #endif // TORRENT_POLICY_HPP_INCLUDED + diff --git a/include/libtorrent/resource_request.hpp b/include/libtorrent/resource_request.hpp index d4e898454..76856596a 100755 --- a/include/libtorrent/resource_request.hpp +++ b/include/libtorrent/resource_request.hpp @@ -43,9 +43,11 @@ POSSIBILITY OF SUCH DAMAGE. #undef max #endif +#include "libtorrent/config.hpp" + namespace libtorrent { - struct resource_request + struct TORRENT_EXPORT resource_request { resource_request() : used(0) diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 908502228..21cd2d18e 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -68,6 +68,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_request.hpp" #include "libtorrent/piece_block_progress.hpp" #include "libtorrent/ip_filter.hpp" +#include "libtorrent/config.hpp" #if !defined(NDEBUG) && defined(_MSC_VER) # include @@ -281,7 +282,7 @@ namespace libtorrent struct http_settings; - struct session_status + struct TORRENT_EXPORT session_status { bool has_incoming_connections; @@ -300,7 +301,7 @@ namespace libtorrent int num_peers; }; - class session: public boost::noncopyable, detail::eh_initializer + class TORRENT_EXPORT session: public boost::noncopyable, detail::eh_initializer { public: @@ -403,3 +404,4 @@ namespace libtorrent } #endif // TORRENT_SESSION_HPP_INCLUDED + diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index 1b7bf9602..babd1004b 100755 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -51,12 +51,12 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -// TODO: support ToS +#include "libtorrent/config.hpp" namespace libtorrent { - class network_error : public std::exception + class TORRENT_EXPORT network_error : public std::exception { public: network_error(int error_code): m_error_code(error_code) {} @@ -69,7 +69,7 @@ namespace libtorrent class socket; - class address + class TORRENT_EXPORT address { friend class socket; public: @@ -109,7 +109,7 @@ namespace libtorrent unsigned int m_ip; }; - class socket: public boost::noncopyable + class TORRENT_EXPORT socket: public boost::noncopyable { friend class address; friend class selector; @@ -228,7 +228,7 @@ namespace libtorrent - class selector + class TORRENT_EXPORT selector { public: diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index 35371d7f1..36c54634c 100755 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -39,11 +39,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/size_type.hpp" #include "libtorrent/invariant_check.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { - class stat + class TORRENT_EXPORT stat { friend class invariant_access; enum { history = 10 }; diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index c74496db0..61bd3c6cb 100755 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/torrent_info.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { @@ -61,17 +62,20 @@ namespace libtorrent class session; - std::vector > get_filesizes( + + TORRENT_EXPORT std::wstring safe_convert(std::string const& s); + + TORRENT_EXPORT std::vector > get_filesizes( torrent_info const& t , boost::filesystem::path p); - bool match_filesizes( + TORRENT_EXPORT bool match_filesizes( torrent_info const& t , boost::filesystem::path p , std::vector > const& sizes , std::string* error = 0); - struct file_allocation_failed: std::exception + struct TORRENT_EXPORT file_allocation_failed: std::exception { file_allocation_failed(const char* error_msg): m_msg(error_msg) {} virtual const char* what() const throw() { return m_msg.c_str(); } @@ -79,7 +83,7 @@ namespace libtorrent std::string m_msg; }; - class storage + class TORRENT_EXPORT storage { public: storage( @@ -112,7 +116,7 @@ namespace libtorrent boost::shared_ptr m_pimpl; }; - class piece_manager : boost::noncopyable + class TORRENT_EXPORT piece_manager : boost::noncopyable { public: diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index bf9907715..f928d5aa5 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -48,6 +48,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #ifdef _MSC_VER #pragma warning(pop) @@ -63,6 +64,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert.hpp" #include "libtorrent/resource_request.hpp" #include "libtorrent/piece_picker.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { @@ -89,7 +91,7 @@ namespace libtorrent // a torrent is a class that holds information // for a specific download. It updates itself against // the tracker - class torrent: public request_callback + class TORRENT_EXPORT torrent: public request_callback , public boost::enable_shared_from_this { public: @@ -435,7 +437,7 @@ namespace libtorrent // if this pointer is 0, the torrent is in // a state where the metadata hasn't been // received yet. - std::auto_ptr m_storage; + boost::scoped_ptr m_storage; // the time of next tracker request boost::posix_time::ptime m_next_request; @@ -473,7 +475,7 @@ namespace libtorrent detail::session_impl& m_ses; detail::checker_impl& m_checker; - std::auto_ptr m_picker; + boost::scoped_ptr m_picker; std::vector m_trackers; // this is an index into m_torrent_file.trackers() diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index ae40ba037..c67034d6a 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_info.hpp" #include "libtorrent/piece_picker.hpp" #include "libtorrent/torrent_info.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { @@ -58,19 +59,19 @@ namespace libtorrent struct checker_impl; } - struct duplicate_torrent: std::exception + struct TORRENT_EXPORT duplicate_torrent: std::exception { virtual const char* what() const throw() { return "torrent already exists in session"; } }; - struct invalid_handle: std::exception + struct TORRENT_EXPORT invalid_handle: std::exception { virtual const char* what() const throw() { return "invalid torrent handle used"; } }; - struct torrent_status + struct TORRENT_EXPORT torrent_status { torrent_status() : state(queued_for_checking) @@ -188,7 +189,7 @@ namespace libtorrent int block_size; }; - struct partial_piece_info + struct TORRENT_EXPORT partial_piece_info { enum { max_blocks_per_piece = piece_picker::max_blocks_per_piece }; int piece_index; @@ -199,7 +200,7 @@ namespace libtorrent int num_downloads[max_blocks_per_piece]; }; - struct torrent_handle + struct TORRENT_EXPORT torrent_handle { friend class invariant_access; friend class session; diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 7d0d7192c..e9be8e17a 100755 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -54,25 +54,25 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/size_type.hpp" - +#include "libtorrent/config.hpp" namespace libtorrent { - struct file_entry + struct TORRENT_EXPORT file_entry { boost::filesystem::path path; size_type size; }; - struct announce_entry + struct TORRENT_EXPORT announce_entry { announce_entry(std::string const& u): url(u), tier(0) {} std::string url; int tier; }; - struct invalid_torrent_file: std::exception + struct TORRENT_EXPORT invalid_torrent_file: std::exception { virtual const char* what() const throw() { return "invalid torrent file"; } }; @@ -82,7 +82,7 @@ namespace libtorrent // also add a filename converter function that will transform // invalid filenames to valid filenames on the current platform - class torrent_info + class TORRENT_EXPORT torrent_info { public: diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 91352e127..9acc5567a 100755 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/http_settings.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/peer.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { @@ -65,12 +66,12 @@ namespace libtorrent // address parse_url(std::string const& url); // encodes a string using the base64 scheme - std::string base64encode(const std::string& s); + TORRENT_EXPORT std::string base64encode(const std::string& s); // returns -1 if gzip header is invalid or the header size in bytes - int gzip_header(const char* buf, int size); + TORRENT_EXPORT int gzip_header(const char* buf, int size); - struct tracker_request + struct TORRENT_EXPORT tracker_request { tracker_request() : kind(announce_request) @@ -105,7 +106,7 @@ namespace libtorrent int num_want; }; - struct request_callback + struct TORRENT_EXPORT request_callback { friend class tracker_manager; request_callback(): m_manager(0) {} @@ -133,13 +134,13 @@ namespace libtorrent tracker_manager* m_manager; }; - bool inflate_gzip( + TORRENT_EXPORT bool inflate_gzip( std::vector& buffer , tracker_request const& req , request_callback* requester , int maximum_tracker_response_length); - struct tracker_connection: boost::noncopyable + struct TORRENT_EXPORT tracker_connection: boost::noncopyable { tracker_connection(boost::weak_ptr r) : m_requester(r) @@ -158,7 +159,7 @@ namespace libtorrent }; - class tracker_manager: boost::noncopyable + class TORRENT_EXPORT tracker_manager: boost::noncopyable { public: diff --git a/include/libtorrent/udp_tracker_connection.hpp b/include/libtorrent/udp_tracker_connection.hpp index 9e1c93670..c986799da 100755 --- a/include/libtorrent/udp_tracker_connection.hpp +++ b/include/libtorrent/udp_tracker_connection.hpp @@ -57,10 +57,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer.hpp" #include "libtorrent/tracker_manager.hpp" #include "libtorrent/async_gethostbyname.hpp" +#include "libtorrent/config.hpp" namespace libtorrent { - class udp_tracker_connection: public tracker_connection + class TORRENT_EXPORT udp_tracker_connection: public tracker_connection { friend class tracker_manager; public: @@ -110,3 +111,4 @@ namespace libtorrent } #endif // TORRENT_UDP_TRACKER_CONNECTION_HPP_INCLUDED + diff --git a/include/libtorrent/utf8.hpp b/include/libtorrent/utf8.hpp index 5587e9cfe..7a31af804 100644 --- a/include/libtorrent/utf8.hpp +++ b/include/libtorrent/utf8.hpp @@ -155,21 +155,6 @@ inline std::string wchar_utf8(const std::wstring &str) return ret; } -inline std::wstring safe_convert(std::string const& s) -{ - try - { - return utf8_wchar(s); - } - catch (std::exception) - { - std::wstring ret; - for (const char* i = &*s.begin(); i < &*s.end(); ++i) - ret += *i; - return ret; - } -} - } #endif diff --git a/src/entry.cpp b/src/entry.cpp index 677071628..84bc5d0ec 100755 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/entry.hpp" +#include "libtorrent/config.hpp" #include #include @@ -70,7 +71,7 @@ namespace libtorrent { namespace detail { - char const* integer_to_str(char* buf, int size, entry::integer_type val) + TORRENT_EXPORT char const* integer_to_str(char* buf, int size, entry::integer_type val) { int sign = 0; if (val < 0) diff --git a/src/sha1.cpp b/src/sha1.cpp index afcce6345..1d04b4a17 100755 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -21,16 +21,18 @@ changelog at the end of the file. using boost::uint32_t; using boost::uint8_t; -struct SHA1_CTX +#include "libtorrent/config.hpp" + +struct TORRENT_EXPORT SHA1_CTX { uint32_t state[5]; uint32_t count[2]; uint8_t buffer[64]; }; -void SHA1Init(SHA1_CTX* context); -void SHA1Update(SHA1_CTX* context, uint8_t const* data, uint32_t len); -void SHA1Final(SHA1_CTX* context, uint8_t* digest); +TORRENT_EXPORT void SHA1Init(SHA1_CTX* context); +TORRENT_EXPORT void SHA1Update(SHA1_CTX* context, uint8_t const* data, uint32_t len); +TORRENT_EXPORT void SHA1Final(SHA1_CTX* context, uint8_t* digest); namespace { diff --git a/src/storage.cpp b/src/storage.cpp index 6ec7aa0e2..497cb5751 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -79,7 +79,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/utf8.hpp" -namespace +namespace libtorrent { std::wstring safe_convert(std::string const& s) { @@ -100,7 +100,11 @@ namespace return ret; } } +} +namespace +{ + using libtorrent::safe_convert; using namespace boost::filesystem; // based on code from Boost.Fileystem @@ -1223,8 +1227,7 @@ namespace libtorrent // that hasn't already been assigned int other_piece = -1; for (std::vector::iterator i = matching_pieces.begin(); - i != matching_pieces.end(); - ++i) + i != matching_pieces.end(); ++i) { if (have_pieces[*i] || *i == piece_index) continue; other_piece = *i; @@ -1412,7 +1415,7 @@ namespace libtorrent // first, create all missing directories path last_path; for (torrent_info::file_iterator file_iter = m_info.begin_files(), - end_iter = m_info.end_files(); file_iter != end_iter; ++file_iter) + end_iter = m_info.end_files(); file_iter != end_iter; ++file_iter) { path dir = (m_save_path / file_iter->path).branch_path(); if (dir == last_path) continue; diff --git a/src/torrent.cpp b/src/torrent.cpp index 27c1b5be5..37a9e62e4 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -354,9 +354,9 @@ namespace libtorrent assert(m_torrent_file.total_size() >= 0); m_have_pieces.resize(m_torrent_file.num_pieces(), false); - m_storage = std::auto_ptr(new piece_manager(m_torrent_file, m_save_path)); + m_storage.reset(new piece_manager(m_torrent_file, m_save_path)); m_block_size = calculate_block_size(m_torrent_file, m_default_block_size); - m_picker = std::auto_ptr(new piece_picker( + m_picker.reset(new piece_picker( static_cast(m_torrent_file.piece_length() / m_block_size) , static_cast((m_torrent_file.total_size()+m_block_size-1)/m_block_size))); }