libtorrent_sys/lib.rs
1// Copyright (c) 2022 Nicolas Chevalier
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in all
11// copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21#[cxx::bridge(namespace = "libtorrent")]
22pub mod ffi {
23 unsafe extern "C++" {
24 include!("src/lt.h");
25
26 type session;
27 type add_torrent_params;
28 type torrent_handle;
29
30 /// This function return a struct of type lt::session
31 pub fn lt_create_session() -> UniquePtr<session>;
32
33 /// This function return a struct of type lt::add_torrent_params
34 ///
35 /// lt::add_torrent_params is return by lt::parse_magnet_uri,
36 /// then it configured with the given magnet string, and the current path
37 pub fn lt_parse_magnet_uri(uri: &str, path: &str) -> UniquePtr<add_torrent_params>;
38
39 /// This function return a struct of type lt::torrent_handle
40 ///
41 /// Call the function add_torrent() using the current session and add_torrent_params
42 /// given in parameters
43 pub fn lt_session_add_torrent(ses: Pin<&mut session>, params: Pin<&mut add_torrent_params>) -> UniquePtr<torrent_handle>;
44
45 /// This function remove the given torrent from session
46 pub fn lt_session_remove_torrent(ses: Pin<&mut session>, hdl: &torrent_handle);
47
48 /// This function call pause() for the given session
49 pub fn lt_session_pause(ses: Pin<&mut session>);
50
51 /// This function return true if torrent has metadata
52 pub fn lt_torrent_has_metadata(hdl: &torrent_handle) -> bool;
53
54 /// This function return the torrent's name
55 ///
56 /// Name is found in torrent_info return by function torrent_file()
57 pub fn lt_torrent_get_name(hdl: &torrent_handle) -> &str;
58
59 /// This function return bencoded data by lt::bencode()
60 pub fn lt_torrent_bencode(hdl: &torrent_handle) -> &[u8];
61
62 /// This function call libtorrent::version() and return libtorrent version
63 pub fn version() -> *const c_char;
64 }
65}