2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2007-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2022-04-08 01:50:26 +00:00
|
|
|
#include <cstdint> // uint32_t, uint64_t
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_metainfo_builder_file
|
2007-06-19 00:08:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* filename;
|
|
|
|
uint64_t size;
|
2022-02-23 23:38:07 +00:00
|
|
|
bool is_portable;
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2007-06-19 00:08:39 +00:00
|
|
|
|
2022-02-09 02:25:19 +00:00
|
|
|
enum class TrMakemetaResult
|
2008-03-24 17:18:08 +00:00
|
|
|
{
|
2022-02-09 02:25:19 +00:00
|
|
|
OK,
|
|
|
|
CANCELLED,
|
|
|
|
ERR_URL, // invalid announce URL
|
|
|
|
ERR_IO_READ, // see builder.errfile, builder.my_errno
|
|
|
|
ERR_IO_WRITE // see builder.errfile, builder.my_errno
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2008-03-24 17:18:08 +00:00
|
|
|
|
2021-12-14 20:59:40 +00:00
|
|
|
struct tr_tracker_info
|
|
|
|
{
|
|
|
|
int tier;
|
|
|
|
char* announce;
|
|
|
|
};
|
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_metainfo_builder
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-04-21 07:40:57 +00:00
|
|
|
*** These are set by tr_makeMetaInfoBuilderCreate()
|
|
|
|
*** and cleaned up by tr_metaInfoBuilderFree()
|
2007-06-18 03:40:41 +00:00
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
char* top;
|
|
|
|
tr_metainfo_builder_file* files;
|
|
|
|
uint64_t totalSize;
|
|
|
|
uint32_t fileCount;
|
|
|
|
uint32_t pieceSize;
|
|
|
|
uint32_t pieceCount;
|
|
|
|
bool isFolder;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-21 07:40:57 +00:00
|
|
|
*** These are set inside tr_makeMetaInfo()
|
2007-06-18 03:40:41 +00:00
|
|
|
*** by copying the arguments passed to it,
|
2017-04-21 07:40:57 +00:00
|
|
|
*** and cleaned up by tr_metaInfoBuilderFree()
|
2007-06-18 03:40:41 +00:00
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_tracker_info* trackers;
|
|
|
|
int trackerCount;
|
2022-02-12 18:50:47 +00:00
|
|
|
|
|
|
|
char** webseeds;
|
|
|
|
int webseedCount;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
char* comment;
|
|
|
|
char* outputFile;
|
|
|
|
bool isPrivate;
|
2021-10-18 23:05:39 +00:00
|
|
|
char* source;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-21 07:40:57 +00:00
|
|
|
*** These are set inside tr_makeMetaInfo() so the client
|
2007-06-18 03:40:41 +00:00
|
|
|
*** can poll periodically to see what the status is.
|
|
|
|
*** The client can also set abortFlag to nonzero to
|
2017-04-21 07:40:57 +00:00
|
|
|
*** tell tr_makeMetaInfo() to abort and clean up after itself.
|
2007-06-18 03:40:41 +00:00
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
uint32_t pieceIndex;
|
|
|
|
bool abortFlag;
|
|
|
|
bool isDone;
|
2022-02-09 02:25:19 +00:00
|
|
|
TrMakemetaResult result;
|
2008-03-24 17:18:08 +00:00
|
|
|
|
2009-09-17 01:18:59 +00:00
|
|
|
/* file in use when result was set to _IO_READ or _IO_WRITE,
|
|
|
|
* or the URL in use when the result was set to _URL */
|
2017-04-19 12:04:45 +00:00
|
|
|
char errfile[2048];
|
2008-03-24 17:18:08 +00:00
|
|
|
|
|
|
|
/* errno encountered when result was set to _IO_READ or _IO_WRITE */
|
2017-04-19 12:04:45 +00:00
|
|
|
int my_errno;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** This is an implementation detail.
|
|
|
|
*** The client should never use these fields.
|
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_metainfo_builder* nextBuilder;
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFile);
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2013-01-17 18:55:51 +00:00
|
|
|
/**
|
|
|
|
* Call this before tr_makeMetaInfo() to override the builder.pieceSize
|
|
|
|
* and builder.pieceCount values that were set by tr_metainfoBuilderCreate()
|
2014-06-10 00:43:21 +00:00
|
|
|
*
|
|
|
|
* @return false if the piece size isn't valid; eg, isn't a power of two.
|
2013-01-17 18:55:51 +00:00
|
|
|
*/
|
2017-04-19 12:04:45 +00:00
|
|
|
bool tr_metaInfoBuilderSetPieceSize(tr_metainfo_builder* builder, uint32_t bytes);
|
2013-01-17 18:55:51 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_metaInfoBuilderFree(tr_metainfo_builder*);
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/**
|
2022-03-21 14:15:48 +00:00
|
|
|
* @brief create a new torrent file
|
2007-06-18 03:40:41 +00:00
|
|
|
*
|
|
|
|
* This is actually done in a worker thread, not the main thread!
|
|
|
|
* Otherwise the client's interface would lock up while this runs.
|
|
|
|
*
|
|
|
|
* It is the caller's responsibility to poll builder->isDone
|
|
|
|
* from time to time! When the worker thread sets that flag,
|
2017-04-21 07:40:57 +00:00
|
|
|
* the caller must pass the builder to tr_metaInfoBuilderFree().
|
2008-06-01 05:36:23 +00:00
|
|
|
*
|
2021-10-06 16:32:17 +00:00
|
|
|
* @param outputFile if nullptr, builder->top + ".torrent" will be used.
|
2008-06-01 05:36:23 +00:00
|
|
|
|
|
|
|
* @param trackers An array of trackers, sorted by tier from first to last.
|
|
|
|
* NOTE: only the `tier' and `announce' fields are used.
|
|
|
|
*
|
|
|
|
* @param trackerCount size of the `trackers' array
|
2007-06-18 03:40:41 +00:00
|
|
|
*/
|
2021-08-15 09:41:48 +00:00
|
|
|
void tr_makeMetaInfo(
|
|
|
|
tr_metainfo_builder* builder,
|
2022-02-12 18:50:47 +00:00
|
|
|
char const* output_file,
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_tracker_info const* trackers,
|
2022-02-12 18:50:47 +00:00
|
|
|
int n_trackers,
|
|
|
|
char const** webseeds,
|
|
|
|
int n_webseeds,
|
2021-08-15 09:41:48 +00:00
|
|
|
char const* comment,
|
2022-02-12 18:50:47 +00:00
|
|
|
bool is_private,
|
2021-10-18 23:05:39 +00:00
|
|
|
char const* source);
|