From 3f61ee0ff37d58b692f6baa0a3f73d5d235a7fa5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 19 Nov 2014 09:23:08 +0000 Subject: [PATCH] merged changes from RC_1_0 --- CMakeLists.txt | 19 ++++++------- bindings/python/client.py | 3 +-- bindings/python/compile_flags.in | 2 +- bindings/python/link_flags.in | 2 +- bindings/python/src/torrent_info.cpp | 26 ++++++++++++++++-- examples/Makefile.am | 2 +- examples/client_test.cpp | 40 +++++++++++++++++++++------- examples/run_cmake.sh.in | 8 ++++++ test/test_resume.cpp | 40 ++++++++++++++++++++++++++++ test/test_torrent_parse.cpp | 8 ++++++ 10 files changed, 122 insertions(+), 28 deletions(-) create mode 100644 examples/run_cmake.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index fcc0ed13c..b7e8cf04c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,7 +152,6 @@ option(exceptions "build with exception support" ON) option(logging "build with logging" OFF) option(verbose-logging "build with verbose logging" OFF) option(build_tests "build tests" OFF) -option(build_examples "build examples" ON) set(CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo) @@ -311,6 +310,10 @@ add_definitions(-D_FILE_OFFSET_BITS=64) add_definitions(-DBOOST_EXCEPTION_DISABLE) add_definitions(-DBOOST_ASIO_ENABLE_CANCELIO) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_definitions(-fcolor-diagnostics) +endif() + if (tcmalloc) target_link_libraries(torrent-rasterbar tcmalloc) endif() @@ -342,16 +345,10 @@ install(DIRECTORY include/libtorrent PATTERN ".svn" EXCLUDE) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libtorrent-rasterbar.pc DESTINATION ${LIBDIR}/pkgconfig) -# === build examples === -if(build_examples) - # this will make some internal functions available in the - # DLL interface, for the examples to access - add_definitions(-DTORRENT_EXPORT_EXTRA) - - # to build the examples, run cmake in this subdirectory - # after libtorrent is built - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples) -endif() +# === set up examples directory as an independent project === +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples) +configure_file(examples/run_cmake.sh.in examples/run_cmake.sh) +# to build the examples, run examples/run_cmake.sh after building libtorrent # === build tests === if(build_tests) diff --git a/bindings/python/client.py b/bindings/python/client.py index 05687cbf5..673b034f5 100755 --- a/bindings/python/client.py +++ b/bindings/python/client.py @@ -229,8 +229,7 @@ def main(): if f.startswith('magnet:') or f.startswith('http://') or f.startswith('https://'): atp["url"] = f else: - e = lt.bdecode(open(f, 'rb').read()) - info = lt.torrent_info(e) + info = lt.torrent_info(f) print('Adding \'%s\'...' % info.name()) try: diff --git a/bindings/python/compile_flags.in b/bindings/python/compile_flags.in index 6e23cdbd4..ae7868d5d 100644 --- a/bindings/python/compile_flags.in +++ b/bindings/python/compile_flags.in @@ -1 +1 @@ -@COMPILETIME_OPTIONS@ @CPPFLAGS@ @LIBS@ @BOOST_SYSTEM_LIB@ @BOOST_PYTHON_LIB@ @PTHREAD_LIBS@ @OPENSSL_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_INCLUDES@ -I@top_srcdir@/include +@COMPILETIME_OPTIONS@ @CPPFLAGS@ @LIBS@ @BOOST_CPPFLAGS@ @BOOST_SYSTEM_LIB@ @BOOST_PYTHON_LIB@ @PTHREAD_LIBS@ @OPENSSL_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_INCLUDES@ -I@top_srcdir@/include diff --git a/bindings/python/link_flags.in b/bindings/python/link_flags.in index 102fc5478..c724d6fea 100644 --- a/bindings/python/link_flags.in +++ b/bindings/python/link_flags.in @@ -1 +1 @@ --L@top_builddir@/src/.libs @LDFLAGS@ +-L@top_builddir@/src/.libs @BOOST_LDFLAGS@ @LDFLAGS@ diff --git a/bindings/python/src/torrent_info.cpp b/bindings/python/src/torrent_info.cpp index 81424836e..358d48d4b 100644 --- a/bindings/python/src/torrent_info.cpp +++ b/bindings/python/src/torrent_info.cpp @@ -177,6 +177,26 @@ namespace } // namespace unnamed +boost::intrusive_ptr buffer_constructor(char const* buf, int len, int flags) +{ + error_code ec; + boost::intrusive_ptr ret(new torrent_info(buf, len, ec, flags)); +#ifndef BOOST_NO_EXCEPTIONS + if (ec) throw libtorrent_exception(ec); +#endif + return ret; +} + +boost::intrusive_ptr file_constructor(std::string const& filename, int flags) +{ + error_code ec; + boost::intrusive_ptr ret(new torrent_info(filename, ec, flags)); +#ifndef BOOST_NO_EXCEPTIONS + if (ec) throw libtorrent_exception(ec); +#endif + return ret; +} + void bind_torrent_info() { return_value_policy copy; @@ -196,10 +216,12 @@ void bind_torrent_info() #ifndef TORRENT_NO_DEPRECATE .def(init(arg("e"))) #endif + .def(init((arg("info_hash"), arg("flags") = 0))) - .def(init((arg("buffer"), arg("length"), arg("flags") = 0))) - .def(init((arg("file"), arg("flags") = 0))) + .def("__init__", make_constructor(&buffer_constructor)) + .def("__init__", make_constructor(&file_constructor)) .def(init((arg("ti")))) + #if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE .def(init((arg("file"), arg("flags") = 0))) #endif diff --git a/examples/Makefile.am b/examples/Makefile.am index 10a2a185a..d757934f8 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -13,7 +13,7 @@ bin_PROGRAMS = $(example_programs) endif EXTRA_PROGRAMS = $(example_programs) -EXTRA_DIST = Jamfile CMakeLists.txt cmake/FindLibtorrentRasterbar.cmake +EXTRA_DIST = Jamfile CMakeLists.txt run_cmake.sh.in cmake/FindLibtorrentRasterbar.cmake client_test_SOURCES = client_test.cpp print.cpp session_view.cpp torrent_view.cpp #client_test_LDADD = $(top_builddir)/src/libtorrent-rasterbar.la diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 9d16e5714..7e4536b6b 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -34,6 +34,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" +#ifdef TORRENT_WINDOWS +#include // for _mkdir +#endif + #ifdef _MSC_VER #pragma warning(push, 1) #endif @@ -634,8 +638,8 @@ std::vector list_dir(std::string path { std::vector ret; #ifdef TORRENT_WINDOWS - if (!f.empty() && f[f.size()-1] != '\\') f += "\\*"; - else f += "*"; + if (!path.empty() && path[path.size()-1] != '\\') path += "\\*"; + else path += "*"; std::wstring wpath; libtorrent::utf8_wchar(path, wpath); @@ -822,24 +826,36 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a if (torrent_need_cert_alert* p = alert_cast(a)) { torrent_handle h = p->handle; - error_code ec; - file_status st; std::string base_name = path_append("certificates", to_hex(h.info_hash().to_string())); std::string cert = base_name + ".pem"; std::string priv = base_name + "_key.pem"; - stat_file(cert, &st, ec); - if (ec) + +#ifdef TORRENT_WINDOWS + struct ::_stat st; + int ret = ::_stat(cert.c_str(), &st); + if (ret < 0 || (st.st_mode & _S_IFREG) == 0) +#else + struct ::stat st; + int ret = ::stat(cert.c_str(), &st); + if (ret < 0 || (st.st_mode & S_IFREG) == 0) +#endif { char msg[256]; - snprintf(msg, sizeof(msg), "ERROR. could not load certificate %s: %s\n", cert.c_str(), ec.message().c_str()); + snprintf(msg, sizeof(msg), "ERROR. could not load certificate %s: %s\n", cert.c_str(), strerror(errno)); if (g_log_file) fprintf(g_log_file, "[%s] %s\n", timestamp(), msg); return true; } - stat_file(priv, &st, ec); - if (ec) + +#ifdef TORRENT_WINDOWS + ret = ::_stat(priv.c_str(), &st); + if (ret < 0 || (st.st_mode & _S_IFREG) == 0) +#else + ret = ::stat(priv.c_str(), &st); + if (ret < 0 || (st.st_mode & S_IFREG) == 0) +#endif { char msg[256]; - snprintf(msg, sizeof(msg), "ERROR. could not load private key %s: %s\n", priv.c_str(), ec.message().c_str()); + snprintf(msg, sizeof(msg), "ERROR. could not load private key %s: %s\n", priv.c_str(), strerror(errno)); if (g_log_file) fprintf(g_log_file, "[%s] %s\n", timestamp(), msg); return true; } @@ -1408,7 +1424,11 @@ int main(int argc, char* argv[]) } // create directory for resume files +#ifdef TORRENT_WINDOWS + int ret = _mkdir(path_append(save_path, ".resume").c_str()); +#else int ret = mkdir(path_append(save_path, ".resume").c_str(), 0777); +#endif if (ret < 0) fprintf(stderr, "failed to create resume file directory: (%d) %s\n" , errno, strerror(errno)); diff --git a/examples/run_cmake.sh.in b/examples/run_cmake.sh.in new file mode 100644 index 000000000..53269e721 --- /dev/null +++ b/examples/run_cmake.sh.in @@ -0,0 +1,8 @@ +#!/bin/sh + +cd ${libtorrent_BINARY_DIR}/examples +cmake \ + -D libtorrent_includes_asio_source=${asio_source} \ + -G "${CMAKE_GENERATOR}" \ + $@ \ + ${libtorrent_SOURCE_DIR}/examples diff --git a/test/test_resume.cpp b/test/test_resume.cpp index 8b702ec5a..343bbc7a3 100644 --- a/test/test_resume.cpp +++ b/test/test_resume.cpp @@ -109,7 +109,11 @@ std::vector generate_resume_data(torrent_info* ti) entry::list_type& httpseeds = rd["httpseeds"].list(); httpseeds.push_back(entry("http://resume_data_http_seed.com")); +#ifdef TORRENT_WINDOWS + rd["save_path"] = "c:\\resume_data save_path"; +#else rd["save_path"] = "/resume_data save_path"; +#endif std::vector ret; bencode(back_inserter(ret), rd); @@ -127,7 +131,11 @@ torrent_status test_resume_flags(int flags) p.ti = ti; p.flags = flags; +#ifdef TORRENT_WINDOWS + p.save_path = "c:\\add_torrent_params save_path"; +#else p.save_path = "/add_torrent_params save_path"; +#endif p.trackers.push_back("http://add_torrent_params_tracker.com/announce"); p.url_seeds.push_back("http://add_torrent_params_url_seed.com"); @@ -165,7 +173,11 @@ int test_main() fprintf(stderr, "flags: 0\n"); s = test_resume_flags(0); default_tests(s); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path"); +#else TEST_EQUAL(s.save_path, "/add_torrent_params save_path"); +#endif TEST_EQUAL(s.sequential_download, false); TEST_EQUAL(s.paused, false); TEST_EQUAL(s.auto_managed, false); @@ -180,7 +192,11 @@ int test_main() fprintf(stderr, "flags: use_resume_save_path\n"); s = test_resume_flags(add_torrent_params::flag_use_resume_save_path); default_tests(s); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(s.save_path, "c:\\resume_data save_path"); +#else TEST_EQUAL(s.save_path, "/resume_data save_path"); +#endif TEST_EQUAL(s.sequential_download, false); TEST_EQUAL(s.paused, false); TEST_EQUAL(s.auto_managed, false); @@ -197,7 +213,11 @@ int test_main() | add_torrent_params::flag_paused); default_tests(s); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path"); +#else TEST_EQUAL(s.save_path, "/add_torrent_params save_path"); +#endif TEST_EQUAL(s.sequential_download, false); TEST_EQUAL(s.paused, true); TEST_EQUAL(s.auto_managed, false); @@ -213,7 +233,11 @@ int test_main() s = test_resume_flags(add_torrent_params::flag_override_resume_data | add_torrent_params::flag_seed_mode); default_tests(s); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path"); +#else TEST_EQUAL(s.save_path, "/add_torrent_params save_path"); +#endif TEST_EQUAL(s.sequential_download, false); TEST_EQUAL(s.paused, false); TEST_EQUAL(s.auto_managed, false); @@ -228,7 +252,11 @@ int test_main() fprintf(stderr, "flags: upload_mode\n"); s = test_resume_flags(add_torrent_params::flag_upload_mode); default_tests(s); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path"); +#else TEST_EQUAL(s.save_path, "/add_torrent_params save_path"); +#endif TEST_EQUAL(s.sequential_download, false); TEST_EQUAL(s.paused, false); TEST_EQUAL(s.auto_managed, false); @@ -244,7 +272,11 @@ int test_main() s = test_resume_flags(add_torrent_params::flag_override_resume_data | add_torrent_params::flag_share_mode); default_tests(s); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path"); +#else TEST_EQUAL(s.save_path, "/add_torrent_params save_path"); +#endif TEST_EQUAL(s.sequential_download, false); TEST_EQUAL(s.paused, false); TEST_EQUAL(s.auto_managed, false); @@ -260,7 +292,11 @@ int test_main() fprintf(stderr, "flags: auto_managed\n"); s = test_resume_flags(add_torrent_params::flag_auto_managed); default_tests(s); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path"); +#else TEST_EQUAL(s.save_path, "/add_torrent_params save_path"); +#endif TEST_EQUAL(s.sequential_download, false); TEST_EQUAL(s.paused, false); TEST_EQUAL(s.auto_managed, false); @@ -276,7 +312,11 @@ int test_main() fprintf(stderr, "flags: paused\n"); s = test_resume_flags(add_torrent_params::flag_paused); default_tests(s); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path"); +#else TEST_EQUAL(s.save_path, "/add_torrent_params save_path"); +#endif TEST_EQUAL(s.sequential_download, false); TEST_EQUAL(s.paused, false); TEST_EQUAL(s.auto_managed, false); diff --git a/test/test_torrent_parse.cpp b/test/test_torrent_parse.cpp index 9a20edc47..ccdb2ac60 100644 --- a/test/test_torrent_parse.cpp +++ b/test/test_torrent_parse.cpp @@ -439,12 +439,20 @@ int test_main() else if (std::string(test_torrents[i].file) == "slash_path.torrent") { TEST_EQUAL(ti->num_files(), 1); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(ti->file_at(0).path, "temp\\bar"); +#else TEST_EQUAL(ti->file_at(0).path, "temp/bar"); +#endif } else if (std::string(test_torrents[i].file) == "slash_path2.torrent") { TEST_EQUAL(ti->num_files(), 1); +#ifdef TORRENT_WINDOWS + TEST_EQUAL(ti->file_at(0).path, "temp\\abc....def\\bar"); +#else TEST_EQUAL(ti->file_at(0).path, "temp/abc....def/bar"); +#endif } else if (std::string(test_torrents[i].file) == "slash_path3.torrent") {