From f77e12ac04f93a72383aca213db19194a9594db5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 1 Jan 2015 20:25:39 +0000 Subject: [PATCH] clean up symbol exports --- include/libtorrent/Makefile.am | 1 + include/libtorrent/crc32c.hpp | 6 ++- include/libtorrent/create_torrent.hpp | 55 ++++++--------------------- include/libtorrent/export.hpp | 7 ++++ include/libtorrent/file.hpp | 6 +-- include/libtorrent/file_storage.hpp | 12 ++---- include/libtorrent/hasher.hpp | 17 +-------- include/libtorrent/sha1.hpp | 38 ++++++++++++++++++ include/libtorrent/torrent.hpp | 2 +- include/libtorrent/utf8.hpp | 6 +-- src/create_torrent.cpp | 48 +++++++++++++++++++++++ src/file_storage.cpp | 2 + src/hasher.cpp | 1 + src/instantiate_connection.cpp | 3 +- src/session.cpp | 3 -- src/sha1.cpp | 21 +--------- src/torrent.cpp | 2 +- 17 files changed, 128 insertions(+), 102 deletions(-) create mode 100644 include/libtorrent/sha1.hpp diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index eec38adde..b01142633 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -106,6 +106,7 @@ nobase_include_HEADERS = \ session_settings.hpp \ session_status.hpp \ settings_pack.hpp \ + sha1.hpp \ sha1_hash.hpp \ size_type.hpp \ sliding_average.hpp \ diff --git a/include/libtorrent/crc32c.hpp b/include/libtorrent/crc32c.hpp index 7b786b64a..2d238e0d4 100644 --- a/include/libtorrent/crc32c.hpp +++ b/include/libtorrent/crc32c.hpp @@ -34,13 +34,15 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_CRC32C_HPP_INCLUDE #include +#include "libtorrent/export.hpp" namespace libtorrent { // this is the crc32c (Castagnoli) polynomial - boost::uint32_t crc32c_32(boost::uint32_t v); - boost::uint32_t crc32c(boost::uint64_t const* v, int num_words); + TORRENT_EXTRA_EXPORT boost::uint32_t crc32c_32(boost::uint32_t v); + TORRENT_EXTRA_EXPORT boost::uint32_t crc32c(boost::uint64_t const* v + , int num_words); } #endif diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index e3c8833e7..faa0d4a80 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -354,20 +354,7 @@ namespace libtorrent namespace detail { - inline bool default_pred(std::string const&) { return true; } - - inline bool ignore_subdir(std::string const& leaf) - { return leaf == ".." || leaf == "."; } - inline void nop(int) {} - - int get_file_attributes(std::string const& p); - std::string get_symlink_path(std::string const& p); - - // internal - TORRENT_EXPORT void add_files_impl(file_storage& fs, std::string const& p - , std::string const& l, boost::function pred - , boost::uint32_t flags); } // Adds the file specified by ``path`` to the file_storage object. In case ``path`` @@ -387,15 +374,10 @@ namespace libtorrent // // The ``flags`` argument should be the same as the flags passed to the `create_torrent`_ // constructor. - template void add_files(file_storage& fs, std::string const& file, Pred p, boost::uint32_t flags = 0) - { - detail::add_files_impl(fs, parent_path(complete(file)), filename(file), p, flags); - } - inline void add_files(file_storage& fs, std::string const& file, boost::uint32_t flags = 0) - { - detail::add_files_impl(fs, parent_path(complete(file)), filename(file) - , detail::default_pred, flags); - } + TORRENT_EXPORT void add_files(file_storage& fs, std::string const& file + , boost::function p, boost::uint32_t flags = 0); + TORRENT_EXPORT void add_files(file_storage& fs, std::string const& file + , boost::uint32_t flags = 0); // This function will assume that the files added to the torrent file exists at path // ``p``, read those files and hash the content and set the hashes in the ``create_torrent`` @@ -436,32 +418,17 @@ namespace libtorrent // and pass in utf8 strings #ifndef TORRENT_NO_DEPRECATE - template TORRENT_DEPRECATED_PREFIX - void TORRENT_DEPRECATED add_files(file_storage& fs, std::wstring const& wfile, Pred p, boost::uint32_t flags = 0) - { - std::string utf8; - wchar_utf8(wfile, utf8); - detail::add_files_impl(fs, parent_path(complete(utf8)) - , filename(utf8), p, flags); - } + TORRENT_EXPORT void add_files(file_storage& fs, std::wstring const& wfile + , boost::function p, boost::uint32_t flags = 0) TORRENT_DEPRECATED; TORRENT_DEPRECATED_PREFIX - inline void TORRENT_DEPRECATED add_files(file_storage& fs, std::wstring const& wfile, boost::uint32_t flags = 0) - { - std::string utf8; - wchar_utf8(wfile, utf8); - detail::add_files_impl(fs, parent_path(complete(utf8)) - , filename(utf8), detail::default_pred, flags); - } + TORRENT_EXPORT void add_files(file_storage& fs, std::wstring const& wfile + , boost::uint32_t flags = 0) TORRENT_DEPRECATED; - inline void set_piece_hashes(create_torrent& t, std::wstring const& p, boost::function f - , error_code& ec) - { - std::string utf8; - wchar_utf8(p, utf8); - set_piece_hashes(t, utf8, f, ec); - } + TORRENT_DEPRECATED_PREFIX + TORRENT_EXPORT void set_piece_hashes(create_torrent& t, std::wstring const& p + , boost::function f, error_code& ec) TORRENT_DEPRECATED; #ifndef BOOST_NO_EXCEPTIONS template diff --git a/include/libtorrent/export.hpp b/include/libtorrent/export.hpp index cef3bbef3..6a31c13fb 100644 --- a/include/libtorrent/export.hpp +++ b/include/libtorrent/export.hpp @@ -85,5 +85,12 @@ POSSIBILITY OF SUCH DAMAGE. # define TORRENT_EXTRA_EXPORT #endif +// only export this type if deprecated functions are enabled +#ifdef TORRENT_NO_DEPRECATE +#define TORRENT_DEPRECATED_EXPORT +#else +#define TORRENT_DEPRECATED_EXPORT TORRENT_EXPORT +#endif + #endif diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index 57061ade1..f3ac47f85 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -150,16 +150,16 @@ namespace libtorrent // internal used by create_torrent.hpp - TORRENT_EXPORT std::string parent_path(std::string const& f); + TORRENT_EXTRA_EXPORT std::string parent_path(std::string const& f); TORRENT_EXTRA_EXPORT bool has_parent_path(std::string const& f); TORRENT_EXTRA_EXPORT char const* filename_cstr(char const* f); // internal used by create_torrent.hpp - TORRENT_EXPORT std::string filename(std::string const& f); + TORRENT_EXTRA_EXPORT std::string filename(std::string const& f); TORRENT_EXTRA_EXPORT std::string combine_path(std::string const& lhs , std::string const& rhs); // internal used by create_torrent.hpp - TORRENT_EXPORT std::string complete(std::string const& f); + TORRENT_EXTRA_EXPORT std::string complete(std::string const& f); TORRENT_EXTRA_EXPORT bool is_complete(std::string const& f); TORRENT_EXTRA_EXPORT std::string current_working_directory(); #if TORRENT_USE_UNC_PATHS diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index 04eb6d39d..72ab969e4 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -46,6 +46,9 @@ namespace libtorrent { struct file; + // TODO: 3 the file_entry should be deprecated and add_file() should be + // thought through a bit better + // information about a file in a file_storage struct TORRENT_EXPORT file_entry { @@ -104,13 +107,6 @@ namespace libtorrent bool symlink_attribute:1; }; - // only export this type if deprecated functions are enabled -#ifdef TORRENT_NO_DEPRECATED -#define TORRENT_DEPRECATED_EXPORT -#else -#define TORRENT_DEPRECATED_EXPORT TORRENT_EXPORT -#endif - // internal struct TORRENT_DEPRECATED_EXPORT internal_file_entry { @@ -236,7 +232,7 @@ namespace libtorrent // hidden file_storage(); // hidden - ~file_storage() {} + ~file_storage(); // returns true if the piece length has been initialized // on the file_storage. This is typically taken as a proxy diff --git a/include/libtorrent/hasher.hpp b/include/libtorrent/hasher.hpp index 0aa70c5e4..52f37c018 100644 --- a/include/libtorrent/hasher.hpp +++ b/include/libtorrent/hasher.hpp @@ -54,22 +54,7 @@ extern "C" } #else -// from sha1.cpp -namespace libtorrent -{ - - struct TORRENT_EXTRA_EXPORT sha_ctx - { - boost::uint32_t state[5]; - boost::uint32_t count[2]; - boost::uint8_t buffer[64]; - }; - - TORRENT_EXTRA_EXPORT void SHA1_init(sha_ctx* context); - TORRENT_EXTRA_EXPORT void SHA1_update(sha_ctx* context, boost::uint8_t const* data, boost::uint32_t len); - TORRENT_EXTRA_EXPORT void SHA1_final(boost::uint8_t* digest, sha_ctx* context); -} // namespace libtorrent - +#include "libtorrent/sha1.hpp" #endif namespace libtorrent diff --git a/include/libtorrent/sha1.hpp b/include/libtorrent/sha1.hpp new file mode 100644 index 000000000..a2168fe0a --- /dev/null +++ b/include/libtorrent/sha1.hpp @@ -0,0 +1,38 @@ +/* +SHA-1 C++ conversion + +original version: + +SHA-1 in C +By Steve Reid +100% Public Domain + +changelog at the end of sha1.cpp +*/ + +#ifndef TORRENT_SHA1_HPP_INCLUDED +#define TORRENT_SHA1_HPP_INCLUDED + +#include "libtorrent/config.hpp" +#include + +namespace libtorrent +{ + + struct TORRENT_EXTRA_EXPORT sha_ctx + { + boost::uint32_t state[5]; + boost::uint32_t count[2]; + boost::uint8_t buffer[64]; + }; + + // we don't want these to clash with openssl's libcrypto + TORRENT_EXTRA_EXPORT void SHA1_init(sha_ctx* context); + TORRENT_EXTRA_EXPORT void SHA1_update(sha_ctx* context + , boost::uint8_t const* data + , boost::uint32_t len); + TORRENT_EXTRA_EXPORT void SHA1_final(boost::uint8_t* digest, sha_ctx* context); +} + +#endif + diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 25915ad81..7dbaedd52 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -559,7 +559,7 @@ namespace libtorrent void file_progress(std::vector& fp, int flags = 0); -#ifndef TORRENT_NO_DEPRECATED +#ifndef TORRENT_NO_DEPRECATE void use_interface(std::string net_interface); #endif diff --git a/include/libtorrent/utf8.hpp b/include/libtorrent/utf8.hpp index a89f67729..2a875d6b9 100644 --- a/include/libtorrent/utf8.hpp +++ b/include/libtorrent/utf8.hpp @@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_UTF8_HPP_INCLUDED #define TORRENT_UTF8_HPP_INCLUDED -#include "libtorrent/config.hpp" +#include "libtorrent/export.hpp" // on windows we need these functions for // convert_to_native and convert_from_native @@ -66,9 +66,9 @@ namespace libtorrent // string (``wide``). ``wchar_utf8`` converts a wide character string // (``wide``) to a UTF-8 string (``utf8``). The return value is one of // the enumeration values from utf8_conv_result_t. - TORRENT_EXPORT utf8_conv_result_t utf8_wchar( + TORRENT_EXTRA_EXPORT utf8_conv_result_t utf8_wchar( const std::string &utf8, std::wstring &wide); - TORRENT_EXPORT utf8_conv_result_t wchar_utf8( + TORRENT_EXTRA_EXPORT utf8_conv_result_t wchar_utf8( const std::wstring &wide, std::string &utf8); } #endif // !BOOST_NO_STD_WSTRING diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index cbd4d53e2..10a95f241 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -55,6 +55,11 @@ namespace libtorrent namespace detail { + inline bool default_pred(std::string const&) { return true; } + + inline bool ignore_subdir(std::string const& leaf) + { return leaf == ".." || leaf == "."; } + int get_file_attributes(std::string const& p) { #ifdef TORRENT_WINDOWS @@ -153,6 +158,49 @@ namespace libtorrent } } // detail namespace +#if TORRENT_USE_WSTRING +#ifndef TORRENT_NO_DEPRECATE + + void add_files(file_storage& fs, std::wstring const& wfile + , boost::function p, boost::uint32_t flags) + { + std::string utf8; + wchar_utf8(wfile, utf8); + detail::add_files_impl(fs, parent_path(complete(utf8)) + , filename(utf8), p, flags); + } + + void add_files(file_storage& fs + , std::wstring const& wfile, boost::uint32_t flags) + { + std::string utf8; + wchar_utf8(wfile, utf8); + detail::add_files_impl(fs, parent_path(complete(utf8)) + , filename(utf8), detail::default_pred, flags); + } + + void set_piece_hashes(create_torrent& t, std::wstring const& p + , boost::function f, error_code& ec) + { + std::string utf8; + wchar_utf8(p, utf8); + set_piece_hashes(t, utf8, f, ec); + } +#endif +#endif + + void add_files(file_storage& fs, std::string const& file + , boost::function p, boost::uint32_t flags) + { + detail::add_files_impl(fs, parent_path(complete(file)), filename(file), p, flags); + } + + void add_files(file_storage& fs, std::string const& file, boost::uint32_t flags) + { + detail::add_files_impl(fs, parent_path(complete(file)), filename(file) + , detail::default_pred, flags); + } + void on_hash(disk_io_job const* j, create_torrent* t , boost::shared_ptr storage, disk_io_thread* iothread , int* piece_counter, int* completed_piece diff --git a/src/file_storage.cpp b/src/file_storage.cpp index d0f1e2e6d..e7f657f5e 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -47,6 +47,8 @@ namespace libtorrent , m_num_files(0) {} + file_storage::~file_storage() {} + void file_storage::reserve(int num_files) { m_files.reserve(num_files); diff --git a/src/hasher.cpp b/src/hasher.cpp index a14f342b5..1b1b9ec6c 100644 --- a/src/hasher.cpp +++ b/src/hasher.cpp @@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/hasher.hpp" +#include "libtorrent/sha1.hpp" namespace libtorrent { diff --git a/src/instantiate_connection.cpp b/src/instantiate_connection.cpp index b3289186d..c951bc557 100644 --- a/src/instantiate_connection.cpp +++ b/src/instantiate_connection.cpp @@ -34,12 +34,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session_settings.hpp" #include "libtorrent/socket_type.hpp" #include "libtorrent/utp_socket_manager.hpp" +#include "libtorrent/instantiate_connection.hpp" #include #include namespace libtorrent { - TORRENT_EXPORT bool instantiate_connection(io_service& ios + bool instantiate_connection(io_service& ios , proxy_settings const& ps, socket_type& s , void* ssl_context , utp_socket_manager* sm diff --git a/src/session.cpp b/src/session.cpp index 540e4adc4..1d16356df 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -83,9 +83,6 @@ using libtorrent::aux::session_impl; namespace libtorrent { - - TORRENT_EXPORT void TORRENT_LINK_TEST_NAME() {} - TORRENT_EXPORT void min_memory_usage(settings_pack& set) { // receive data directly into disk buffers diff --git a/src/sha1.cpp b/src/sha1.cpp index a3e64dfbb..f96f526a6 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -13,33 +13,14 @@ changelog at the end of the file. #include #include -// if you don't want boost -// replace with -// #include -// typedef uint32_t u32; -// typedef uint8_t u8; +#include "libtorrent/sha1.hpp" -#include typedef boost::uint32_t u32; typedef boost::uint8_t u8; -#include "libtorrent/config.hpp" - namespace libtorrent { -struct TORRENT_EXPORT sha_ctx -{ - u32 state[5]; - u32 count[2]; - u8 buffer[64]; -}; - -// we don't want these to clash with openssl's libcrypto -TORRENT_EXPORT void SHA1_init(sha_ctx* context); -TORRENT_EXPORT void SHA1_update(sha_ctx* context, u8 const* data, u32 len); -TORRENT_EXPORT void SHA1_final(u8* digest, sha_ctx* context); - namespace { union CHAR64LONG16 diff --git a/src/torrent.cpp b/src/torrent.cpp index 575fd57e9..8ffdd770b 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2679,7 +2679,7 @@ namespace libtorrent m_num_checked_pieces = 0; } -#ifndef TORRENT_NO_DEPRECATED +#ifndef TORRENT_NO_DEPRECATE void torrent::use_interface(std::string net_interfaces) { settings_pack* p = new settings_pack;