| 1 |
|
| /* rhash_torrent.c - functions to make a torrent file. |
| 2 |
|
| * |
| 3 |
|
| * Copyright: 2013-2014 Aleksey Kravchenko <rhash.admin@gmail.com> |
| 4 |
|
| * |
| 5 |
|
| * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
|
| * copy of this software and associated documentation files (the "Software"), |
| 7 |
|
| * to deal in the Software without restriction, including without limitation |
| 8 |
|
| * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
|
| * and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
|
| * Software is furnished to do so. |
| 11 |
|
| * |
| 12 |
|
| * This program is distributed in the hope that it will be useful, but |
| 13 |
|
| * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 |
|
| * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk! |
| 15 |
|
| */ |
| 16 |
|
| #include <assert.h> |
| 17 |
|
| |
| 18 |
|
| /* modifier for Windows DLL */ |
| 19 |
|
| #if (defined(_WIN32) || defined(__CYGWIN__) ) && defined(RHASH_EXPORTS) |
| 20 |
|
| # define RHASH_API __declspec(dllexport) |
| 21 |
|
| #endif |
| 22 |
|
| |
| 23 |
|
| #include "algorithms.h" |
| 24 |
|
| #include "torrent.h" |
| 25 |
|
| #include "rhash_torrent.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); |
| 63 |
|
| } |
| 64 |
|
| |
| 65 |
0 |
| RHASH_API const rhash_str* rhash_torrent_generate_content(rhash ctx) |
| 66 |
|
| { |
| 67 |
0 |
| torrent_ctx *tc = BT_CTX(ctx); |
| 68 |
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 |
|
| 69 |
0 |
| return (rhash_str*)(&tc->content); |
| 70 |
|
| } |