diff --git a/.travis.yml b/.travis.yml index 19cd752aa..3dbaaed0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,9 @@ os: env: - variant=test_debug lang=cpp11 sim=1 -# - variant=test_debug lang=cpp11 sim=0 -# - variant=test_debug lang=cpp98 sim=0 -# - variant=test_release lang=cpp11 sim=0 -# - variant=test_barebones lang=cpp11 sim=0 + - variant=test_debug lang=cpp98 sim=0 + - variant=test_release lang=cpp11 sim=0 + - variant=test_barebones lang=cpp11 sim=0 git: submodules: false @@ -43,11 +42,12 @@ before_install: - if [ $TRAVIS_OS_NAME == "osx" ]; then brew install --quiet ccache boost-build boost-python; fi - if [ $TRAVIS_OS_NAME == "osx" ]; then export toolset="darwin-${lang}"; fi - if [ $TRAVIS_OS_NAME == "linux" ]; then export toolset="gcc-${lang}"; fi + - 'echo "using toolset: " ${toolset}' install: - - 'echo "using toolset: " ${toolset}' - 'echo "using gcc : cpp11 : ccache g++-4.8 : -std=c11 -std=c++11 ;" > ~/user-config.jam' - 'echo "using gcc : cpp98 : ccache g++-4.8 : -std=c99 -std=c++98 ;" >> ~/user-config.jam' + # osx builds need to disable the deprecated warning because of the openssl # shipping with the system having marked all functions as deprecated. Since # we're building with -Werror, we can't have those warnings @@ -64,9 +64,9 @@ script: - cd ../bindings/python - bjam --hash -j3 warnings-as-errors=on variant=$variant $toolset stage_module - LD_LIBRARY_PATH=. DYLD_LIBRARY_PATH=. python test.py - - if [ $sim ]; then + - if [ $sim = "1" ]; then cd ../../simulation; - bjam --hash -j3 crypto=built-in $toolset; + bjam --hash -j2 crypto=built-in $toolset; fi - ccache --show-stats diff --git a/Jamfile b/Jamfile index 93ccf158d..ae0197d91 100644 --- a/Jamfile +++ b/Jamfile @@ -186,11 +186,6 @@ rule linking ( properties * ) result += libiconv ; } - if yes in $(properties) - { - result += tcmalloc ; - } - if ( gcc in $(properties) || clang in $(properties) ) && linux in $(properties) @@ -275,6 +270,10 @@ rule warnings ( properties * ) result += -Wno-exit-time-destructors ; result += -Wno-documentation-unknown-command ; result += -Wno-disabled-macro-expansion ; + result += -Wno-unused-command-line-argument ; + result += -Wno-error=implicit-fallthrough ; + result += -Wno-c++11-long-long ; + result += -Wno-variadic-macros ; # in C++98 mode there's no way to silence this warning # in the code (without final) @@ -407,8 +406,6 @@ rule tag ( name : type ? : property-set ) return $(name) ; } -feature tcmalloc : no yes : composite propagated link-incompatible ; - feature ipv6 : on off : composite propagated link-incompatible ; feature.compose off : TORRENT_USE_IPV6=0 ; @@ -584,8 +581,6 @@ lib librt : : rt shared ; lib libsocket : : libnsl socket shared /usr/sfw/lib shared ; lib libnsl : : nsl shared /usr/sfw/lib shared ; -lib tcmalloc : : tcmalloc shared ; - # socket libraries on windows lib wsock32 : : wsock32 shared ; lib ws2_32 : : ws2_32 shared ; diff --git a/bindings/python/Jamfile b/bindings/python/Jamfile index 42dccaeb6..8f389c8b7 100644 --- a/bindings/python/Jamfile +++ b/bindings/python/Jamfile @@ -149,7 +149,7 @@ my-python-extension py_libtorrent src gcc:-Wno-deprecated-declarations darwin:-Wno-deprecated-declarations - darwin:-Wno-deprecated-declarations + darwin:-Wno-unused-command-line-argument @libtorrent_linking : # usage-requirements @libtorrent_linking diff --git a/bindings/python/src/create_torrent.cpp b/bindings/python/src/create_torrent.cpp index 8884c2995..540813b79 100644 --- a/bindings/python/src/create_torrent.cpp +++ b/bindings/python/src/create_torrent.cpp @@ -104,9 +104,6 @@ namespace { return FileIter(self, self.num_files()); } #endif - char const* filestorage_name(file_storage const& fs) - { return fs.name().c_str(); } - bool call_python_object2(boost::python::object& obj, std::string const& i) { return obj(i); diff --git a/bindings/python/src/error_code.cpp b/bindings/python/src/error_code.cpp index 101baa59e..ff5e74cb0 100644 --- a/bindings/python/src/error_code.cpp +++ b/bindings/python/src/error_code.cpp @@ -30,11 +30,11 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include #include #include +#include using namespace boost::python; using namespace libtorrent; diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 2dc2a8386..fd8001a12 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -2,7 +2,6 @@ // subject to the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#include #include #include #include @@ -25,6 +24,8 @@ #include "gil.hpp" #include "bytes.hpp" +#include + using namespace boost::python; using namespace libtorrent; namespace lt = libtorrent; @@ -738,8 +739,8 @@ void bind_session() .def("is_paused", allow_threads(<::session::is_paused)) .def("id", allow_threads(<::session::id)) .def("get_cache_info", &get_cache_info1, (arg("handle") = torrent_handle(), arg("flags") = 0)) - .def("add_port_mapping", allow_threads(&session::add_port_mapping)) - .def("delete_port_mapping", allow_threads(&session::delete_port_mapping)) + .def("add_port_mapping", allow_threads(<::session::add_port_mapping)) + .def("delete_port_mapping", allow_threads(<::session::delete_port_mapping)) #ifndef TORRENT_NO_DEPRECATE .def( @@ -792,9 +793,9 @@ void bind_session() #endif // TORRENT_NO_DEPRECATE ; - enum_("protocol_type") - .value("udp", session::udp) - .value("tcp", session::tcp) + enum_("protocol_type") + .value("udp", lt::session::udp) + .value("tcp", lt::session::tcp) ; enum_("save_state_flags_t") diff --git a/bindings/python/src/torrent_info.cpp b/bindings/python/src/torrent_info.cpp index 91a2868ad..959e2824f 100644 --- a/bindings/python/src/torrent_info.cpp +++ b/bindings/python/src/torrent_info.cpp @@ -84,18 +84,6 @@ namespace ti.set_merkle_tree(h); } -#ifndef TORRENT_NO_DEPRECATE - file_storage::iterator begin_files(torrent_info& i) - { - return i.begin_files(); - } - - file_storage::iterator end_files(torrent_info& i) - { - return i.end_files(); - } -#endif - std::string hash_for_piece(torrent_info const& ti, int i) { return ti.hash_for_piece(i).to_string(); diff --git a/examples/Jamfile b/examples/Jamfile index 28a2cda28..0b6057d47 100644 --- a/examples/Jamfile +++ b/examples/Jamfile @@ -12,6 +12,7 @@ if $(BOOST_ROOT) project client_test : requirements multi /torrent//torrent + darwin:-Wno-unused-command-line-argument : default-build static ; diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index 972abe1fe..67d5b5615 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -78,6 +78,7 @@ nobase_include_HEADERS = \ max.hpp \ natpmp.hpp \ network_thread_pool.hpp \ + openssl.hpp \ operations.hpp \ packet_buffer.hpp \ parse_url.hpp \ diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index e11fe657d..837ce7db7 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -57,17 +57,8 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth = 0); #define TORRENT_WHILE_0 while (0) #endif -#if TORRENT_USE_ASSERTS -#ifdef TORRENT_PRODUCTION_ASSERTS -extern char const* libtorrent_assert_log; -#endif - -#ifndef TORRENT_USE_SYSTEM_ASSERTS - -#if TORRENT_USE_IOSTREAM -#include -#endif +// declarations of the two functions TORRENT_EXPORT void assert_print(char const* fmt, ...) TORRENT_FORMAT(1,2); @@ -78,6 +69,20 @@ TORRENT_NO_RETURN TORRENT_EXPORT void assert_fail(const char* expr, int line , char const* file, char const* function, char const* val, int kind = 0); + + +#if TORRENT_USE_ASSERTS + +#ifdef TORRENT_PRODUCTION_ASSERTS +extern char const* libtorrent_assert_log; +#endif + +#if TORRENT_USE_IOSTREAM +#include +#endif + +#ifndef TORRENT_USE_SYSTEM_ASSERTS + #define TORRENT_ASSERT_PRECOND(x) \ do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, 0, 1); } TORRENT_WHILE_0 diff --git a/include/libtorrent/aux_/alert_manager_variadic_emplace.hpp b/include/libtorrent/aux_/alert_manager_variadic_emplace.hpp index 383eb5d2c..5c360eb40 100644 --- a/include/libtorrent/aux_/alert_manager_variadic_emplace.hpp +++ b/include/libtorrent/aux_/alert_manager_variadic_emplace.hpp @@ -1,5 +1,5 @@ -#if !BOOST_PP_IS_ITERATING +#if !defined BOOST_PP_IS_ITERATING || !BOOST_PP_IS_ITERATING // set-up iteration #include diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 106cc9431..335db19e1 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -439,7 +439,7 @@ int snprintf(char* buf, int len, char const* fmt, ...) #endif #if defined __GNUC__ || defined __clang__ -#define TORRENT_FORMAT(fmt, ellipsis) __attribute__((format(printf, fmt, ellipsis))) +#define TORRENT_FORMAT(fmt, ellipsis) __attribute__((__format__(__printf__, fmt, ellipsis))) #else #define TORRENT_FORMAT(fmt, ellipsis) #endif diff --git a/include/libtorrent/kademlia/observer.hpp b/include/libtorrent/kademlia/observer.hpp index 6ead9d845..e033fc20c 100644 --- a/include/libtorrent/kademlia/observer.hpp +++ b/include/libtorrent/kademlia/observer.hpp @@ -73,7 +73,7 @@ struct observer : boost::noncopyable , flags(0) { TORRENT_ASSERT(a); -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS m_in_constructor = true; m_was_sent = false; m_was_abandoned = false; @@ -164,7 +164,7 @@ private: public: unsigned char flags; -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS bool m_in_constructor:1; bool m_was_sent:1; bool m_was_abandoned:1; diff --git a/include/libtorrent/openssl.hpp b/include/libtorrent/openssl.hpp new file mode 100644 index 000000000..e2fff8408 --- /dev/null +++ b/include/libtorrent/openssl.hpp @@ -0,0 +1,84 @@ +/* + +Copyright (c) 2015, 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_OPENSSL_HPP_INCLUDED +#define TORRENT_OPENSSL_HPP_INCLUDED + +#ifdef TORRENT_USE_OPENSSL + +// all of OpenSSL causes warnings, so we just have to disable them +#include "libtorrent/aux_/disable_warnings_push.hpp" + +#include +#include // for sk_GENERAL_NAME_value +#include // for GENERAL_NAME + +inline void openssl_set_tlsext_hostname(SSL* s, char const* name) +{ +#if OPENSSL_VERSION_NUMBER >= 0x90812f + SSL_set_tlsext_host_name(s, name); +#endif +} + +#if BOOST_VERSION >= 104700 +#if OPENSSL_VERSION_NUMBER >= 0x90812f + +inline void openssl_set_tlsext_servername_callback(SSL_CTX* ctx + , int (*servername_callback)(SSL*, int*, void*)) +{ + SSL_CTX_set_tlsext_servername_callback(ctx, servername_callback); +} + +inline void openssl_set_tlsext_servername_arg(SSL_CTX* ctx, void* userdata) +{ + SSL_CTX_set_tlsext_servername_arg(ctx, userdata); +} + +inline int openssl_num_general_names(GENERAL_NAMES* gens) +{ + return sk_GENERAL_NAME_num(gens); +} + +inline GENERAL_NAME* openssl_general_name_value(GENERAL_NAMES* gens, int i) +{ + return sk_GENERAL_NAME_value(gens, i); +} + +#endif // OPENSSL_VERSION_NUMBER +#endif // BOOST_VERSION + +#include "libtorrent/aux_/disable_warnings_pop.hpp" + +#endif // TORRENT_USE_OPENSSL + +#endif // TORRENT_OPENSSL_HPP_INCLUDED + diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 8dac3e8bd..9532937ac 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -553,7 +553,9 @@ namespace libtorrent #ifndef TORRENT_DISABLE_LOGGING void peer_log(peer_log_alert::direction_t direction - , char const* event, char const* fmt = "", ...) const TORRENT_FORMAT(4,5); + , char const* event, char const* fmt, ...) const TORRENT_FORMAT(4,5); + void peer_log(peer_log_alert::direction_t direction + , char const* event) const; #endif #ifndef TORRENT_DISABLE_LOGGING diff --git a/include/libtorrent/socket_type.hpp b/include/libtorrent/socket_type.hpp index 5c2cd9b5f..8283add41 100644 --- a/include/libtorrent/socket_type.hpp +++ b/include/libtorrent/socket_type.hpp @@ -43,6 +43,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/max.hpp" #include "libtorrent/assert.hpp" +#include "libtorrent/aux_/disable_warnings_push.hpp" + +#include + +#include "libtorrent/aux_/disable_warnings_pop.hpp" + #ifdef TORRENT_USE_OPENSSL #include "libtorrent/ssl_stream.hpp" #endif @@ -282,13 +288,13 @@ namespace libtorrent template S* get() { if (m_type != socket_type_int_impl::value) return 0; - return reinterpret_cast(m_data); + return reinterpret_cast(&m_data); } template S const* get() const { if (m_type != socket_type_int_impl::value) return 0; - return reinterpret_cast(m_data); + return reinterpret_cast(&m_data); } private: @@ -321,10 +327,7 @@ namespace libtorrent >::value }; - // TODO: 2 it would be nice to use aligned_storage here when - // building on c++11 - boost::int64_t m_data[(storage_size + sizeof(boost::int64_t) - 1) - / sizeof(boost::int64_t)]; + boost::aligned_storage::type m_data; }; // returns true if this socket is an SSL socket diff --git a/include/libtorrent/ssl_stream.hpp b/include/libtorrent/ssl_stream.hpp index ed3ce34f8..761c49abe 100644 --- a/include/libtorrent/ssl_stream.hpp +++ b/include/libtorrent/ssl_stream.hpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/io_service.hpp" +#include "libtorrent/openssl.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp" @@ -87,9 +88,7 @@ public: void set_host_name(std::string name) { -#if OPENSSL_VERSION_NUMBER >= 0x90812f - SSL_set_tlsext_host_name(m_sock.native_handle(), name.c_str()); -#endif + openssl_set_tlsext_hostname(m_sock.native_handle(), name.c_str()); } template diff --git a/src/alert.cpp b/src/alert.cpp index 8ef95fb5d..4109ac1fb 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -881,9 +881,10 @@ namespace libtorrent { std::string listen_succeeded_alert::message() const { + char const* type_str[] = { "TCP", "SSL/TCP", "UDP", "SSL/uTP" }; char ret[200]; snprintf(ret, sizeof(ret), "successfully listening on [%s] %s" - , sock_type_str[sock_type], print_endpoint(endpoint).c_str()); + , type_str[sock_type], print_endpoint(endpoint).c_str()); return ret; } diff --git a/src/allocator.cpp b/src/allocator.cpp index 6651b80a3..58a4f7390 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -112,27 +112,26 @@ namespace libtorrent bytes = num_pages * page; #endif - char* ret; + void* ret; #if TORRENT_USE_POSIX_MEMALIGN - if (posix_memalign(reinterpret_cast(&ret), page_size(), bytes) + if (posix_memalign(&ret, page_size(), bytes) != 0) ret = NULL; #elif TORRENT_USE_MEMALIGN - ret = static_cast(memalign(page_size(), bytes)); + ret = memalign(page_size(), bytes); #elif defined TORRENT_WINDOWS - ret = static_cast(_aligned_malloc(bytes, page_size())); + ret = _aligned_malloc(bytes, page_size()); #elif defined TORRENT_BEOS area_id id = create_area("", &ret, B_ANY_ADDRESS , (bytes + page_size() - 1) & (page_size()-1), B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (id < B_OK) return NULL; - ret = static_cast(ret); #else - ret = static_cast(valloc(size_t(bytes))); + ret = valloc(size_t(bytes)); #endif if (ret == NULL) return NULL; #ifdef TORRENT_DEBUG_BUFFERS // make the two surrounding pages non-readable and -writable - alloc_header* h = (alloc_header*)ret; + alloc_header* h = static_cast(ret); h->size = orig_bytes; h->magic = 0x1337; print_backtrace(h->stack, sizeof(h->stack)); @@ -142,7 +141,7 @@ namespace libtorrent #define PROT_READ PAGE_READONLY #endif mprotect(ret, page, PROT_READ); - mprotect(ret + (num_pages-1) * page, page, PROT_READ); + mprotect(static_cast(ret) + (num_pages-1) * page, page, PROT_READ); #ifdef TORRENT_WINDOWS #undef mprotect @@ -150,10 +149,10 @@ namespace libtorrent #endif // fprintf(stderr, "malloc: %p head: %p tail: %p size: %d\n", ret + page, ret, ret + page + bytes, int(bytes)); - return ret + page; + return static_cast(ret) + page; +#else + return static_cast(ret); #endif // TORRENT_DEBUG_BUFFERS - - return ret; } void page_aligned_allocator::free(char* block) @@ -170,7 +169,7 @@ namespace libtorrent const int page = page_size(); // make the two surrounding pages non-readable and -writable mprotect(block - page, page, PROT_READ | PROT_WRITE); - alloc_header* h = (alloc_header*)(block - page); + alloc_header* h = reinterpret_cast(block - page); const int num_pages = (h->size + (page-1)) / page + 2; TORRENT_ASSERT(h->magic == 0x1337); mprotect(block + (num_pages-2) * page, page, PROT_READ | PROT_WRITE); @@ -203,7 +202,7 @@ namespace libtorrent bool page_aligned_allocator::in_use(char const* block) { const int page = page_size(); - alloc_header* h = (alloc_header*)(block - page); + alloc_header const* h = reinterpret_cast(block - page); return h->magic == 0x1337; } #endif diff --git a/src/assert.cpp b/src/assert.cpp index 292062f56..2713b8b9f 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -301,8 +301,11 @@ TORRENT_EXPORT void assert_fail(char const* expr, int line #endif } -#else +#elif !TORRENT_USE_ASSERTS +// these are just here to make it possible for a client that built with debug +// enable to be able to link against a release build (just possible, not +// necessarily supported) TORRENT_FORMAT(1,2) TORRENT_EXPORT void assert_print(char const*, ...) {} TORRENT_EXPORT void assert_fail(char const*, int, char const* diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 456873cff..b9fd0df7e 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -49,12 +49,20 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/random.hpp" #endif +#include "libtorrent/aux_/disable_warnings_push.hpp" + #if TORRENT_USE_PURGABLE_CONTROL #include // see comments at: // http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/vm_object.c + +const vm_purgable_t vm_purgable_set_state = VM_PURGABLE_SET_STATE; +const vm_purgable_t vm_purgable_nonvolatile = VM_PURGABLE_NONVOLATILE; + #endif +#include "libtorrent/aux_/disable_warnings_pop.hpp" + /* The disk cache mimics ARC (adaptive replacement cache). @@ -161,7 +169,7 @@ POSSIBILITY OF SUCH DAMAGE. #define DEBUG_CACHE 0 -#if __cplusplus >= 201103L +#if __cplusplus >= 201103L || defined __clang__ #if DEBUG_CACHE #define DLOG(...) fprintf(__VA_ARGS__) @@ -292,7 +300,8 @@ const char* const job_action_name[] = , int(pe->read_jobs.size()), int(pe->jobs.size())); for (int i = 0; i < pe->piece_log.size(); ++i) { - assert_print(&", %s (%d)"[i==0], job_name(pe->piece_log[i].job), pe->piece_log[i].block); + assert_print("%s %s (%d)", (i==0?"":",") + , job_name(pe->piece_log[i].job), pe->piece_log[i].block); } } assert_print("\n"); @@ -1270,16 +1279,15 @@ void block_cache::insert_blocks(cached_piece_entry* pe, int block, file::iovec_t kern_return_t ret = vm_purgable_control( mach_task_self(), reinterpret_cast(pe->blocks[block].buf), - VM_PURGABLE_SET_STATE, + vm_purgable_set_state, &state); #ifdef TORRENT_DEBUG // if ((random() % 200) == 0) ret = 1; #endif if (ret != KERN_SUCCESS || (state & VM_PURGABLE_EMPTY)) { - fprintf(stderr, "insert_blocks(piece=%d block=%d): - vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %" - PRIx64 "\n" + fprintf(stderr, "insert_blocks(piece=%d block=%d): " + "vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %d\n" , pe->piece, block, ret, state & VM_PURGABLE_EMPTY); free_buffer(pe->blocks[block].buf); pe->blocks[block].buf = NULL; @@ -1317,11 +1325,11 @@ bool block_cache::inc_block_refcount(cached_piece_entry* pe, int block, int reas // its still here. It's only volatile if it's not dirty and has refcount == 0 if (!pe->blocks[block].dirty) { - int state = VM_PURGABLE_NONVOLATILE; + int state = vm_purgable_nonvolatile; kern_return_t ret = vm_purgable_control( mach_task_self(), reinterpret_cast(pe->blocks[block].buf), - VM_PURGABLE_SET_STATE, + vm_purgable_set_state, &state); #ifdef TORRENT_DEBUG // if ((random() % 200) == 0) ret = 1; @@ -1329,8 +1337,7 @@ bool block_cache::inc_block_refcount(cached_piece_entry* pe, int block, int reas if (ret != KERN_SUCCESS || (state & VM_PURGABLE_EMPTY)) { fprintf(stderr, "inc_block_refcount(piece=%d block=%d): " - "vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %" - PRIx64 "\n" + "vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %d\n" , pe->piece, block, ret, state & VM_PURGABLE_EMPTY); free_buffer(pe->blocks[block].buf); @@ -1389,7 +1396,7 @@ void block_cache::dec_block_refcount(cached_piece_entry* pe, int block, int reas kern_return_t ret = vm_purgable_control( mach_task_self(), reinterpret_cast(pe->blocks[block].buf), - VM_PURGABLE_SET_STATE, + vm_purgable_set_state, &state); #ifdef TORRENT_DEBUG // if ((random() % 200) == 0) ret = 1; @@ -1397,8 +1404,7 @@ void block_cache::dec_block_refcount(cached_piece_entry* pe, int block, int reas if (ret != KERN_SUCCESS || (state & VM_PURGABLE_EMPTY)) { fprintf(stderr, "dec_block_refcount(piece=%d block=%d): " - "vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %" - PRIx64 "\n" + "vm_purgable_control failed: %d state & VM_PURGABLE_EMPTY: %d\n" , pe->piece, block, ret, state & VM_PURGABLE_EMPTY); free_buffer(pe->blocks[block].buf); pe->blocks[block].buf = NULL; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index e9c621041..e60f61661 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -401,11 +401,6 @@ namespace libtorrent stats_counters().inc_stats_counter(counters::num_outgoing_suggest); } - namespace { - char random_byte() - { return random() & 0xff; } - } - void bt_peer_connection::get_specific_peer_info(peer_info& p) const { TORRENT_ASSERT(!associated_torrent().expired()); @@ -446,6 +441,11 @@ namespace libtorrent #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) + namespace { + char random_byte() + { return random() & 0xff; } + } + void bt_peer_connection::write_pe1_2_dhkey() { INVARIANT_CHECK; @@ -728,7 +728,6 @@ namespace libtorrent int packet_size = 0; m_rc4->decrypt(vec, consume, produce, packet_size); } -#endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) namespace { void regular_c_free(char* buf, void* /* userdata */ @@ -738,6 +737,8 @@ namespace libtorrent } } +#endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) + void bt_peer_connection::append_const_send_buffer(char const* buffer, int size , chained_buffer::free_buffer_fun destructor, void* userdata , block_cache_reference ref) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index f706990da..bdd0c5ea3 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -61,7 +61,7 @@ POSSIBILITY OF SUCH DAMAGE. #define DEBUG_DISK_THREAD 0 -#if __cplusplus >= 201103L +#if __cplusplus >= 201103L || defined __clang__ #if DEBUG_DISK_THREAD #define DLOG(...) debug_log(__VA_ARGS__) @@ -93,6 +93,11 @@ namespace libtorrent namespace { +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" +#endif + void debug_log(char const* fmt, ...) { #if DEBUG_DISK_THREAD @@ -133,6 +138,10 @@ namespace libtorrent return ret; } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + } // anonymous namespace // ------- disk_io_thread ------ diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 36f240f51..cdc0dde6e 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -232,7 +232,7 @@ namespace libtorrent { namespace } #endif -#if TORRENT_USE_SYSCTL +#if TORRENT_USE_SYSCTL && !defined TORRENT_BUILD_SIMULATOR #ifdef TORRENT_OS2 int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); #endif @@ -285,7 +285,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl } #endif -#if TORRENT_USE_IFADDRS +#if TORRENT_USE_IFADDRS && !defined TORRENT_BUILD_SIMULATOR bool iface_from_ifaddrs(ifaddrs *ifa, ip_interface &rv) { int family = ifa->ifa_addr->sa_family; diff --git a/src/file.cpp b/src/file.cpp index 9d02e7735..94f3842d1 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1300,15 +1300,18 @@ namespace libtorrent } #ifdef TORRENT_DISK_STATS - boost::uint32_t silly_hash(std::string const& str) + namespace { - boost::uint32_t ret = 1; - for (int i = 0; i < str.size(); ++i) + boost::uint32_t silly_hash(std::string const& str) { - if (str[i] == 0) continue; - ret *= int(str[i]); + boost::uint32_t ret = 1; + for (int i = 0; i < str.size(); ++i) + { + if (str[i] == 0) continue; + ret *= int(str[i]); + } + return ret; } - return ret; } #endif diff --git a/src/http_connection.cpp b/src/http_connection.cpp index e7cebbb86..cd033c2ad 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -339,9 +339,13 @@ void http_connection::start(std::string const& hostname, int port if (m_ssl_ctx) { m_own_ssl_context = true; - error_code ec; m_ssl_ctx->set_verify_mode(ssl::context::verify_none, ec); - TORRENT_ASSERT(!ec); + if (ec) + { + m_timer.get_io_service().post(boost::bind(&http_connection::callback + , me, ec, static_cast(NULL), 0)); + return; + } } } userdata = m_ssl_ctx; diff --git a/src/kademlia/find_data.cpp b/src/kademlia/find_data.cpp index 54aabba6c..740ca29d2 100644 --- a/src/kademlia/find_data.cpp +++ b/src/kademlia/find_data.cpp @@ -126,7 +126,7 @@ observer_ptr find_data::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { observer_ptr o(new (ptr) find_data_observer(this, ep, id)); -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS o->m_in_constructor = false; #endif return o; diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index efa74ca47..aae696f7d 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -336,7 +336,7 @@ namespace void* ptr = node.m_rpc.allocate_observer(); if (ptr == 0) return; observer_ptr o(new (ptr) announce_observer(algo, i->first.ep(), i->first.id)); -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS o->m_in_constructor = false; #endif entry e; @@ -422,7 +422,7 @@ void node::direct_request(boost::asio::ip::udp::endpoint ep, entry& e void* ptr = m_rpc.allocate_observer(); if (ptr == 0) return; observer_ptr o(new (ptr) direct_observer(algo, ep, (node_id::min)())); -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS o->m_in_constructor = false; #endif m_rpc.invoke(e, ep, o); @@ -561,7 +561,7 @@ void node::send_single_refresh(udp::endpoint const& ep, int bucket boost::intrusive_ptr algo( new traversal_algorithm(*this, (node_id::min)())); observer_ptr o(new (ptr) ping_observer(algo, ep, id)); -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS o->m_in_constructor = false; #endif entry e; diff --git a/src/kademlia/refresh.cpp b/src/kademlia/refresh.cpp index fee53e6fa..503cab372 100644 --- a/src/kademlia/refresh.cpp +++ b/src/kademlia/refresh.cpp @@ -45,7 +45,7 @@ observer_ptr bootstrap::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { observer_ptr o(new (ptr) get_peers_observer(this, ep, id)); -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS o->m_in_constructor = false; #endif return o; diff --git a/src/lt_trackers.cpp b/src/lt_trackers.cpp index 78f9abc15..673530d9e 100644 --- a/src/lt_trackers.cpp +++ b/src/lt_trackers.cpp @@ -82,7 +82,7 @@ namespace libtorrent { namespace virtual boost::shared_ptr new_connection( peer_connection_handle const& pc); - + virtual void tick() { if (m_2_minutes++ < 120) return; diff --git a/src/metadata_transfer.cpp b/src/metadata_transfer.cpp index b469229cc..2d23c792d 100644 --- a/src/metadata_transfer.cpp +++ b/src/metadata_transfer.cpp @@ -107,9 +107,10 @@ namespace libtorrent { namespace m_requested_metadata.resize(256, 0); } +/* bool need_loaded() { return m_torrent.need_loaded(); } - +*/ virtual void on_unload() { m_metadata.reset(); @@ -225,7 +226,9 @@ namespace libtorrent { namespace metadata(); } +/* int metadata_size() const { return m_metadata_size; } +*/ private: torrent& m_torrent; diff --git a/src/mpi.c b/src/mpi.c index e1c59ee71..56670da61 100644 --- a/src/mpi.c +++ b/src/mpi.c @@ -3678,9 +3678,9 @@ int mp_invmod (mp_int * a, mp_int * b, mp_int * c) #ifdef BN_MP_INVMOD_SLOW_C return mp_invmod_slow(a, b, c); -#endif - +#else return MP_VAL; +#endif } #endif diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index 647a3ed6d..a50428544 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -175,7 +175,7 @@ namespace libtorrent TORRENT_ASSERT(to_process == 0); } -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS to_process = 0; for (std::vector::iterator i = iovec.begin(); i != iovec.end(); ++i) @@ -193,7 +193,7 @@ namespace libtorrent m_send_barriers.pop_front(); } -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS if (next_barrier != INT_MAX) { int overhead = 0; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index a0f536fde..a98b03af5 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -502,6 +502,12 @@ namespace libtorrent } #ifndef TORRENT_DISABLE_LOGGING + void peer_connection::peer_log(peer_log_alert::direction_t direction + , char const* event) const + { + peer_log(direction, event, ""); + } + TORRENT_FORMAT(4,5) void peer_connection::peer_log(peer_log_alert::direction_t direction , char const* event, char const* fmt, ...) const diff --git a/src/peer_connection_handle.cpp b/src/peer_connection_handle.cpp index db27083b2..1d0b8c4ca 100644 --- a/src/peer_connection_handle.cpp +++ b/src/peer_connection_handle.cpp @@ -229,7 +229,14 @@ void peer_connection_handle::peer_log(peer_log_alert::direction_t direction TORRENT_ASSERT(pc); va_list v; va_start(v, fmt); +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif pc->peer_log(direction, event, fmt, v); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif va_end(v); #else TORRENT_UNUSED(direction); diff --git a/src/receive_buffer.cpp b/src/receive_buffer.cpp index 4aa4e8a43..65cc1c641 100644 --- a/src/receive_buffer.cpp +++ b/src/receive_buffer.cpp @@ -221,7 +221,7 @@ void receive_buffer::mutable_buffers(std::vector& v , m_recv_pos - regular_buf_size)); } -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS int vec_bytes = 0; for (std::vector::iterator i = vec.begin(); i != vec.end(); ++i) diff --git a/src/session_handle.cpp b/src/session_handle.cpp index f76bea20a..ab7b67d10 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -503,7 +503,7 @@ namespace libtorrent bencode(std::back_inserter(buf), ses_state); bdecode_node e; error_code ec; -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS || !defined BOOST_NO_EXCEPTIONS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS || !defined BOOST_NO_EXCEPTIONS int ret = #endif bdecode(&buf[0], &buf[0] + buf.size(), e, ec); @@ -528,7 +528,7 @@ namespace libtorrent std::pair buf = ses_state.data_section(); bdecode_node e; error_code ec; -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS || !defined BOOST_NO_EXCEPTIONS +#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS || !defined BOOST_NO_EXCEPTIONS int ret = #endif bdecode(buf.first, buf.first + buf.second, e, ec); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 15d7e800d..bf3de5227 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -67,6 +67,7 @@ const rlim_t rlim_infinity = RLIM_INFINITY; #include "libtorrent/aux_/disable_warnings_pop.hpp" +#include "libtorrent/openssl.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/tracker_manager.hpp" @@ -289,22 +290,23 @@ namespace aux { } #if defined TORRENT_USE_OPENSSL && BOOST_VERSION >= 104700 && OPENSSL_VERSION_NUMBER >= 0x90812f + namespace { // when running bittorrent over SSL, the SNI (server name indication) // extension is used to know which torrent the incoming connection is // trying to connect to. The 40 first bytes in the name is expected to // be the hex encoded info-hash - int servername_callback(SSL *s, int *ad, void *arg) + int servername_callback(SSL* s, int* ad, void* arg) { TORRENT_UNUSED(ad); - session_impl* ses = (session_impl*)arg; + session_impl* ses = reinterpret_cast(arg); const char* servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name); if (!servername || strlen(servername) < 40) return SSL_TLSEXT_ERR_ALERT_FATAL; sha1_hash info_hash; - bool valid = from_hex(servername, 40, (char*)&info_hash[0]); + bool valid = from_hex(servername, 40, info_hash.data()); // the server name is not a valid hex-encoded info-hash if (!valid) @@ -331,6 +333,7 @@ namespace aux { return SSL_TLSEXT_ERR_OK; } + } // anonymous namesoace #endif session_impl::session_impl(io_service& ios) @@ -456,8 +459,9 @@ namespace aux { m_ssl_ctx.set_verify_mode(boost::asio::ssl::context::verify_none, ec); #if BOOST_VERSION >= 104700 #if OPENSSL_VERSION_NUMBER >= 0x90812f - SSL_CTX_set_tlsext_servername_callback(m_ssl_ctx.native_handle(), servername_callback); - SSL_CTX_set_tlsext_servername_arg(m_ssl_ctx.native_handle(), this); + openssl_set_tlsext_servername_callback(m_ssl_ctx.native_handle() + , servername_callback); + openssl_set_tlsext_servername_arg(m_ssl_ctx.native_handle(), this); #endif // OPENSSL_VERSION_NUMBER #endif // BOOST_VERSION #endif @@ -1926,14 +1930,14 @@ retry: #ifdef TORRENT_USE_OPENSSL if (m_settings.get_int(settings_pack::ssl_listen)) { - listen_socket_t s = setup_listener(device, address_family + listen_socket_t ssl_s = setup_listener(device, address_family , m_settings.get_int(settings_pack::ssl_listen) , flags | open_ssl_socket, ec); - if (!ec && s.sock) + if (!ec && ssl_s.sock) { TORRENT_ASSERT(!m_abort); - m_listen_sockets.push_back(s); + m_listen_sockets.push_back(ssl_s); } } #endif diff --git a/src/sha1.cpp b/src/sha1.cpp index 21e852bbc..c75def163 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -31,6 +31,11 @@ namespace #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-member-function" +#endif + // blk0() and blk() perform the initial expand. // I got the idea of expanding during the round function from SSLeay struct little_endian_blk0 @@ -50,9 +55,12 @@ namespace } }; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ - ^block->l[(i+2)&15]^block->l[i&15],1)) + ^block->l[(i+2)&15]^block->l[i&15],1)) // (R0+R1), R2, R3, R4 are the different operations used in SHA1 #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+BlkFun::apply(block, i)+0x5A827999+rol(v,5);w=rol(w,30); diff --git a/src/socket_type.cpp b/src/socket_type.cpp index adf09b08c..f19b5d892 100644 --- a/src/socket_type.cpp +++ b/src/socket_type.cpp @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/socket_type.hpp" +#include "libtorrent/openssl.hpp" #ifdef TORRENT_USE_OPENSSL #include @@ -114,8 +115,8 @@ namespace libtorrent #if OPENSSL_VERSION_NUMBER >= 0x90812f if (ctx) { - SSL_CTX_set_tlsext_servername_callback(ctx, 0); - SSL_CTX_set_tlsext_servername_arg(ctx, 0); + openssl_set_tlsext_servername_callback(ctx, 0); + openssl_set_tlsext_servername_arg(ctx, 0); } #endif // OPENSSL_VERSION_NUMBER #else @@ -227,41 +228,41 @@ namespace libtorrent { case 0: break; case socket_type_int_impl::value: - new (reinterpret_cast(m_data)) tcp::socket(m_io_service); + new (reinterpret_cast(&m_data)) tcp::socket(m_io_service); break; case socket_type_int_impl::value: - new (reinterpret_cast(m_data)) socks5_stream(m_io_service); + new (reinterpret_cast(&m_data)) socks5_stream(m_io_service); break; case socket_type_int_impl::value: - new (reinterpret_cast(m_data)) http_stream(m_io_service); + new (reinterpret_cast(&m_data)) http_stream(m_io_service); break; case socket_type_int_impl::value: - new (reinterpret_cast(m_data)) utp_stream(m_io_service); + new (reinterpret_cast(&m_data)) utp_stream(m_io_service); break; #if TORRENT_USE_I2P case socket_type_int_impl::value: - new (reinterpret_cast(m_data)) i2p_stream(m_io_service); + new (reinterpret_cast(&m_data)) i2p_stream(m_io_service); break; #endif #ifdef TORRENT_USE_OPENSSL case socket_type_int_impl >::value: TORRENT_ASSERT(userdata); - new ((ssl_stream*)m_data) ssl_stream(m_io_service + new (reinterpret_cast*>(&m_data)) ssl_stream(m_io_service , *static_cast(userdata)); break; case socket_type_int_impl >::value: TORRENT_ASSERT(userdata); - new ((ssl_stream*)m_data) ssl_stream(m_io_service + new (reinterpret_cast*>(&m_data)) ssl_stream(m_io_service , *static_cast(userdata)); break; case socket_type_int_impl >::value: TORRENT_ASSERT(userdata); - new ((ssl_stream*)m_data) ssl_stream(m_io_service + new (reinterpret_cast*>(&m_data)) ssl_stream(m_io_service , *static_cast(userdata)); break; case socket_type_int_impl >::value: TORRENT_ASSERT(userdata); - new ((ssl_stream*)m_data) ssl_stream(m_io_service + new (reinterpret_cast*>(&m_data)) ssl_stream(m_io_service , *static_cast(userdata)); break; #endif diff --git a/src/storage.cpp b/src/storage.cpp index a4fc30b9d..9295f8602 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -90,7 +90,7 @@ POSSIBILITY OF SUCH DAMAGE. #define DEBUG_STORAGE 0 #define DEBUG_DELETE_FILES 0 -#if __cplusplus >= 201103L +#if __cplusplus >= 201103L || defined __clang__ #if DEBUG_STORAGE #define DLOG(...) fprintf(__VA_ARGS__) @@ -217,7 +217,7 @@ namespace libtorrent char* ptr = event; detail::write_uint64(timestamp.time_since_epoch().count(), ptr); detail::write_uint64(offset, ptr); - detail::write_uint64((boost::uint64_t)event_id++, ptr); + detail::write_uint64(static_cast(event_id++), ptr); detail::write_uint32(fileid, ptr); detail::write_uint8(flags, ptr); diff --git a/src/torrent.cpp b/src/torrent.cpp index 9aafa1d3b..aa686b31b 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1558,9 +1558,9 @@ namespace libtorrent std::string names; bool match = false; #endif - for (int i = 0; i < sk_GENERAL_NAME_num(gens); ++i) + for (int i = 0; i < openssl_num_general_names(gens); ++i) { - GENERAL_NAME* gen = sk_GENERAL_NAME_value(gens, i); + GENERAL_NAME* gen = openssl_general_name_value(gens, i); if (gen->type != GEN_DNS) continue; ASN1_IA5STRING* domain = gen->d.dNSName; if (domain->type != V_ASN1_IA5STRING || !domain->data || !domain->length) continue; @@ -1579,8 +1579,9 @@ namespace libtorrent // if we're logging, keep looping over all names, // for completeness of the log continue; -#endif +#else return true; +#endif } } @@ -1619,9 +1620,9 @@ namespace libtorrent debug_log("<== incoming SSL CONNECTION [ n: %s | match: %s ]" , names.c_str(), match?"yes":"no"); return match; -#endif - +#else return false; +#endif } #endif // BOOST_VERSION @@ -1686,7 +1687,7 @@ namespace libtorrent X509_STORE* cert_store = X509_STORE_new(); if (!cert_store) { - error_code ec(::ERR_get_error(), + ec.assign(::ERR_get_error(), boost::asio::error::get_ssl_category()); set_error(ec, error_file_ssl_ctx); pause(); @@ -1694,7 +1695,9 @@ namespace libtorrent } // wrap the PEM certificate in a BIO, for openssl to read - BIO* bp = BIO_new_mem_buf((void*)cert.c_str(), cert.size()); + BIO* bp = BIO_new_mem_buf( + const_cast(static_cast(cert.c_str())) + , cert.size()); // parse the certificate into OpenSSL's internal // representation @@ -1704,7 +1707,7 @@ namespace libtorrent if (!certificate) { - error_code ec(::ERR_get_error(), + ec.assign(::ERR_get_error(), boost::asio::error::get_ssl_category()); X509_STORE_free(cert_store); set_error(ec, error_file_ssl_ctx); @@ -5884,13 +5887,15 @@ namespace libtorrent } #ifdef TORRENT_USE_OPENSSL - std::string password_callback(int length, boost::asio::ssl::context::password_purpose p - , std::string pw) - { - TORRENT_UNUSED(length); + namespace { + std::string password_callback(int length, boost::asio::ssl::context::password_purpose p + , std::string pw) + { + TORRENT_UNUSED(length); - if (p != boost::asio::ssl::context::for_reading) return ""; - return pw; + if (p != boost::asio::ssl::context::for_reading) return ""; + return pw; + } } // certificate is a filename to a .pem file which is our @@ -8151,6 +8156,7 @@ namespace libtorrent namespace { +#ifndef TORRENT_DISABLE_LOGGING char const* list_name(int idx) { #define TORRENT_LIST_NAME(n) case aux::session_interface:: n: return #n; @@ -8169,6 +8175,7 @@ namespace libtorrent #undef TORRENT_LIST_NAME return ""; } +#endif // TORRENT_DISABLE_LOGGING } // anonymous namespace diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index bcf8a589a..cbed5578f 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -94,7 +94,7 @@ namespace libtorrent { namespace { ut_metadata_plugin(torrent& t) : m_torrent(t) - , m_metadata_progress(0) +// , m_metadata_progress(0) , m_metadata_size(0) { // initialize m_metadata_size @@ -156,7 +156,7 @@ namespace libtorrent { namespace // we should request. // returns -1 if we should hold off the request int metadata_request(bool has_metadata); - +/* // this is called from the peer_connection for // each piece of metadata it receives void metadata_progress(int total_size, int received) @@ -165,7 +165,7 @@ namespace libtorrent { namespace m_metadata_size = total_size; m_torrent.set_progress_ppm(boost::int64_t(m_metadata_progress) * 1000000 / m_metadata_size); } - +*/ void on_piece_pass(int) { // if we became a seed, copy the metadata from @@ -191,7 +191,7 @@ namespace libtorrent { namespace // it is mutable because it's generated lazily mutable boost::shared_array m_metadata; - int m_metadata_progress; +// int m_metadata_progress; mutable int m_metadata_size; struct metadata_piece diff --git a/src/utf8.cpp b/src/utf8.cpp index b699dd542..c51e0d941 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -40,6 +40,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/utf8.hpp" #include "libtorrent/ConvertUTF.h" + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-member-function" +#endif + namespace libtorrent { namespace @@ -193,5 +199,9 @@ namespace libtorrent } } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + #endif diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 4c0ce9768..661e33a30 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -75,6 +75,7 @@ static struct utp_logger } } log_file_holder; +TORRENT_FORMAT(1, 2) void utp_log(char const* fmt, ...) { if (log_file_holder.utp_log_file == NULL) return; @@ -120,7 +121,7 @@ void set_utp_stream_logging(bool enable) { #else -#if __cplusplus >= 201103L +#if __cplusplus >= 201103L || defined __clang__ #define UTP_LOG(...) do {} while(false) #define UTP_LOGV(...) do {} while(false) diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 0965e1874..39017ea61 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -268,7 +268,7 @@ void web_peer_connection::write_request(peer_request const& r) torrent_info const& info = t->torrent_file(); peer_request req = r; - + std::string request; request.reserve(400); @@ -300,6 +300,8 @@ void web_peer_connection::write_request(peer_request const& r) peer_log(peer_log_alert::info, "RESTART_DATA", "data: %d req: (%d, %d) size: %d" , int(m_piece.size()), int(front.piece), int(front.start) , int (front.start + front.length - 1)); +#else + TORRENT_UNUSED(front); #endif req.start += m_piece.size(); diff --git a/test/Jamfile b/test/Jamfile index 4523cd66c..6f1f331ba 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -69,6 +69,7 @@ lib libtorrent_test ../ed25519/src windows:advapi32 @link_libtorrent + darwin:-Wno-unused-command-line-argument : # default build shared @@ -88,6 +89,7 @@ project : requirements @link_test @link_libtorrent + darwin:-Wno-unused-command-line-argument : default-build multi full diff --git a/test/test_direct_dht.cpp b/test/test_direct_dht.cpp index 14aec8a11..c0887d067 100644 --- a/test/test_direct_dht.cpp +++ b/test/test_direct_dht.cpp @@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_types.hpp" using namespace libtorrent; +namespace lt = libtorrent; namespace { @@ -63,7 +64,7 @@ struct test_plugin : plugin } }; -dht_direct_response_alert* get_direct_response(session& ses) +dht_direct_response_alert* get_direct_response(lt::session& ses) { for (;;) { @@ -95,9 +96,9 @@ TORRENT_TEST(direct_dht_request) sp.set_bool(settings_pack::enable_upnp, false); sp.set_int(settings_pack::max_retry_port_bind, 800); sp.set_str(settings_pack::listen_interfaces, "127.0.0.1:42434"); - session responder(sp, 0); + lt::session responder(sp, 0); sp.set_str(settings_pack::listen_interfaces, "127.0.0.1:45434"); - session requester(sp, 0); + lt::session requester(sp, 0); responder.add_extension(boost::static_pointer_cast(boost::make_shared())); diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index c3841d8ec..44cddf6e2 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -396,7 +396,7 @@ boost::shared_ptr setup_peer(tcp::socket& s, sha1_hash& ih sett.set_bool(settings_pack::enable_natpmp, false); sett.set_bool(settings_pack::enable_lsd, false); sett.set_bool(settings_pack::enable_dht, false); - ses.reset(new lt::session(sett, session::add_default_plugins)); + ses.reset(new lt::session(sett, lt::session::add_default_plugins)); error_code ec; add_torrent_params p; diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 214437f6b..7a1e5f5e3 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" using namespace libtorrent; +namespace lt = libtorrent; boost::shared_ptr generate_torrent() { @@ -52,7 +53,7 @@ boost::shared_ptr generate_torrent() fs.add_file("test_resume/tmp1", 128 * 1024 * 8); fs.add_file("test_resume/tmp2", 128 * 1024); fs.add_file("test_resume/tmp3", 128 * 1024); - libtorrent::create_torrent t(fs, 128 * 1024, 6); + lt::create_torrent t(fs, 128 * 1024, 6); t.add_tracker("http://torrent_file_tracker.com/announce"); @@ -61,7 +62,7 @@ boost::shared_ptr generate_torrent() for (int i = 0; i < num; ++i) { sha1_hash ph; - for (int k = 0; k < 20; ++k) ph[k] = libtorrent::random(); + for (int k = 0; k < 20; ++k) ph[k] = lt::random(); t.set_hash(i, ph); } @@ -131,7 +132,7 @@ std::vector generate_resume_data(torrent_info* ti return ret; } -torrent_handle test_resume_flags(libtorrent::session& ses, int flags +torrent_handle test_resume_flags(lt::session& ses, int flags , char const* file_priorities = "1111", char const* resume_file_prio = "") { boost::shared_ptr ti = generate_torrent(); @@ -191,7 +192,7 @@ void default_tests(torrent_status const& s) TORRENT_TEST(piece_priorities) { - session ses; + lt::session ses; boost::shared_ptr ti = generate_torrent(); add_torrent_params p; p.ti = ti; @@ -237,7 +238,7 @@ TORRENT_TEST(piece_priorities) TORRENT_TEST(file_priorities_default) { - libtorrent::session ses; + lt::session ses; std::vector file_priorities = test_resume_flags(ses, 0, "", "").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -249,7 +250,7 @@ TORRENT_TEST(file_priorities_default) TORRENT_TEST(file_priorities_resume_seed_mode) { // in share mode file priorities should always be 0 - libtorrent::session ses; + lt::session ses; std::vector file_priorities = test_resume_flags(ses, add_torrent_params::flag_share_mode, "", "123").file_priorities(); @@ -262,7 +263,7 @@ TORRENT_TEST(file_priorities_resume_seed_mode) TORRENT_TEST(file_priorities_seed_mode) { // in share mode file priorities should always be 0 - libtorrent::session ses; + lt::session ses; std::vector file_priorities = test_resume_flags(ses, add_torrent_params::flag_share_mode, "123", "").file_priorities(); @@ -276,7 +277,7 @@ TORRENT_TEST(zero_file_prio) { fprintf(stderr, "test_file_prio\n"); - session ses; + lt::session ses; boost::shared_ptr ti = generate_torrent(); add_torrent_params p; p.ti = ti; @@ -315,7 +316,7 @@ void test_seed_mode(bool file_prio, bool pieces_have, bool piece_prio fprintf(stderr, "test_seed_mode file_prio: %d pieces_have: %d piece_prio: %d\n" , file_prio, pieces_have, piece_prio); - session ses; + lt::session ses; boost::shared_ptr ti = generate_torrent(); add_torrent_params p; p.ti = ti; @@ -395,7 +396,7 @@ TORRENT_TEST(seed_mode_preserve) TORRENT_TEST(resume_save_load) { - libtorrent::session ses; + lt::session ses; torrent_handle h = test_resume_flags(ses, 0, "123", ""); h.save_resume_data(); @@ -421,7 +422,7 @@ TORRENT_TEST(resume_save_load) TORRENT_TEST(resume_save_load_resume) { - libtorrent::session ses; + lt::session ses; torrent_handle h = test_resume_flags(ses, 0, "", "123"); h.save_resume_data(); @@ -450,7 +451,7 @@ TORRENT_TEST(file_priorities_resume_override) // make sure that an empty file_priorities vector in add_torrent_params won't // override the resume data file priorities, even when override resume data // flag is set. - libtorrent::session ses; + lt::session ses; std::vector file_priorities = test_resume_flags(ses, add_torrent_params::flag_override_resume_data, "", "123").file_priorities(); @@ -462,7 +463,7 @@ TORRENT_TEST(file_priorities_resume_override) TORRENT_TEST(file_priorities_resume) { - libtorrent::session ses; + lt::session ses; std::vector file_priorities = test_resume_flags(ses, 0, "", "123").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -473,7 +474,7 @@ TORRENT_TEST(file_priorities_resume) TORRENT_TEST(file_priorities1) { - libtorrent::session ses; + lt::session ses; std::vector file_priorities = test_resume_flags(ses, 0, "010").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -486,7 +487,7 @@ TORRENT_TEST(file_priorities1) TORRENT_TEST(file_priorities2) { - libtorrent::session ses; + lt::session ses; std::vector file_priorities = test_resume_flags(ses, 0, "123").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -497,7 +498,7 @@ TORRENT_TEST(file_priorities2) TORRENT_TEST(file_priorities3) { - libtorrent::session ses; + lt::session ses; std::vector file_priorities = test_resume_flags(ses, 0, "4321").file_priorities(); TEST_EQUAL(file_priorities.size(), 3); @@ -508,7 +509,7 @@ TORRENT_TEST(file_priorities3) TORRENT_TEST(plain) { - libtorrent::session ses; + lt::session ses; torrent_status s = test_resume_flags(ses, 0).status(); default_tests(s); @@ -531,7 +532,7 @@ TORRENT_TEST(plain) TORRENT_TEST(use_resume_save_path) { - libtorrent::session ses; + lt::session ses; torrent_status s = test_resume_flags(ses, add_torrent_params::flag_use_resume_save_path).status(); default_tests(s); #ifdef TORRENT_WINDOWS @@ -553,7 +554,7 @@ TORRENT_TEST(use_resume_save_path) TORRENT_TEST(override_resume_data) { - libtorrent::session ses; + lt::session ses; torrent_status s = test_resume_flags(ses , add_torrent_params::flag_override_resume_data | add_torrent_params::flag_paused).status(); @@ -578,7 +579,7 @@ TORRENT_TEST(override_resume_data) TORRENT_TEST(seed_mode) { - libtorrent::session ses; + lt::session ses; torrent_status s = test_resume_flags(ses, add_torrent_params::flag_override_resume_data | add_torrent_params::flag_seed_mode).status(); default_tests(s); @@ -601,7 +602,7 @@ TORRENT_TEST(seed_mode) TORRENT_TEST(upload_mode) { - libtorrent::session ses; + lt::session ses; torrent_status s = test_resume_flags(ses, add_torrent_params::flag_upload_mode).status(); default_tests(s); #ifdef TORRENT_WINDOWS @@ -623,7 +624,7 @@ TORRENT_TEST(upload_mode) TORRENT_TEST(share_mode) { - libtorrent::session ses; + lt::session ses; torrent_status s = test_resume_flags(ses , add_torrent_params::flag_override_resume_data | add_torrent_params::flag_share_mode).status(); @@ -647,7 +648,7 @@ TORRENT_TEST(share_mode) TORRENT_TEST(auto_managed) { - libtorrent::session ses; + lt::session ses; // resume data overrides the auto-managed flag torrent_status s = test_resume_flags(ses, add_torrent_params::flag_auto_managed).status(); default_tests(s); @@ -670,7 +671,7 @@ TORRENT_TEST(auto_managed) TORRENT_TEST(paused) { - libtorrent::session ses; + lt::session ses; // resume data overrides the paused flag torrent_status s = test_resume_flags(ses, add_torrent_params::flag_paused).status(); default_tests(s);