| 1 |
|
| /* rhash_torrent.c - functions to make a torrent file. |
| 2 |
|
| * |
| 3 |
|
| * Copyright (c) 2013, Aleksey Kravchenko <rhash.admin@gmail.com> |
| 4 |
|
| * |
| 5 |
|
| * Permission to use, copy, modify, and/or distribute this software for any |
| 6 |
|
| * purpose with or without fee is hereby granted. |
| 7 |
|
| * |
| 8 |
|
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 9 |
|
| * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 10 |
|
| * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 11 |
|
| * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 12 |
|
| * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE |
| 13 |
|
| * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 14 |
|
| * PERFORMANCE OF THIS SOFTWARE. |
| 15 |
|
| */ |
| 16 |
|
| |
| 17 |
|
| /* modifier for Windows DLL */ |
| 18 |
|
| #if (defined(_WIN32) || defined(__CYGWIN__) ) && defined(RHASH_EXPORTS) |
| 19 |
|
| # define RHASH_API __declspec(dllexport) |
| 20 |
|
| #endif |
| 21 |
|
| |
| 22 |
|
| #include "rhash_torrent.h" |
| 23 |
|
| #include "algorithms.h" |
| 24 |
|
| #include "torrent.h" |
| 25 |
|
| #include <assert.h> |
| 26 |
|
| |
| 27 |
|
| /* obtain torrent context from rhash context */ |
| 28 |
|
| #define BT_CTX(rctx) ((torrent_ctx*)(((rhash_context_ext*)rctx)->bt_ctx)) |
| 29 |
|
| |
| 30 |
0 |
| RHASH_API int rhash_torrent_add_file(rhash ctx, const char* filepath, unsigned long long filesize) |
| 31 |
|
| { |
| 32 |
0 |
▶ | if (!BT_CTX(ctx)) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!BT_CTX(ctx)) return 0; |
0 |
0 |
0 |
|
| 33 |
0 |
| return bt_add_file(BT_CTX(ctx), filepath, filesize); |
| 34 |
|
| } |
| 35 |
|
| |
| 36 |
0 |
| RHASH_API void rhash_torrent_set_options(rhash ctx, unsigned options) |
| 37 |
|
| { |
| 38 |
0 |
▶ | if (!BT_CTX(ctx)) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!BT_CTX(ctx)) return; |
0 |
0 |
0 |
|
| 39 |
0 |
| bt_set_options(BT_CTX(ctx), options); |
| 40 |
|
| } |
| 41 |
|
| |
| 42 |
0 |
| RHASH_API int rhash_torrent_add_announce(rhash ctx, const char* announce_url) |
| 43 |
|
| { |
| 44 |
0 |
▶ | if (!BT_CTX(ctx)) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!BT_CTX(ctx)) return 0; |
0 |
0 |
0 |
|
| 45 |
0 |
| return bt_add_announce(BT_CTX(ctx), announce_url); |
| 46 |
|
| } |
| 47 |
|
| |
| 48 |
0 |
| RHASH_API int rhash_torrent_set_program_name(rhash ctx, const char* name) |
| 49 |
|
| { |
| 50 |
0 |
▶ | if (!BT_CTX(ctx)) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!BT_CTX(ctx)) return 0; |
0 |
0 |
0 |
|
| 51 |
0 |
| return bt_set_program_name(BT_CTX(ctx), name); |
| 52 |
|
| } |
| 53 |
|
| |
| 54 |
0 |
| RHASH_API void rhash_torrent_set_piece_length(rhash ctx, size_t piece_length) |
| 55 |
|
| { |
| 56 |
0 |
▶ | if (!BT_CTX(ctx)) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!BT_CTX(ctx)) return; |
0 |
0 |
0 |
|
| 57 |
0 |
| bt_set_piece_length(BT_CTX(ctx), piece_length); |
| 58 |
|
| } |
| 59 |
|
| |
| 60 |
0 |
| RHASH_API size_t rhash_torrent_get_default_piece_length(unsigned long long total_size) |
| 61 |
|
| { |
| 62 |
0 |
| return bt_default_piece_length(total_size, 0); |
| 63 |
|
| } |
| 64 |
|
| |
| 65 |
0 |
| RHASH_API void rhash_torrent_set_batch_size(rhash ctx, unsigned long long total_size) |
| 66 |
|
| { |
| 67 |
0 |
▶ | if (!BT_CTX(ctx)) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!BT_CTX(ctx)) return; |
0 |
0 |
0 |
|
| 68 |
0 |
| bt_set_total_batch_size(BT_CTX(ctx), total_size); |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
0 |
| RHASH_API const rhash_str* rhash_torrent_generate_content(rhash ctx) |
| 72 |
|
| { |
| 73 |
0 |
| torrent_ctx* tc = BT_CTX(ctx); |
| 74 |
0 |
▶ | if (!tc || tc->error || !tc->content.str) return 0; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!tc || tc->error || !tc->content.str) return 0; |
0 |
0 |
0 |
| if (!tc || tc->error || !tc->content.str) return 0; |
0 |
0 |
0 |
| if (!tc || tc->error || !tc->content.str) return 0; |
0 |
0 |
0 |
|
| 75 |
0 |
| return (rhash_str*)(&tc->content); |
| 76 |
|
| } |