2007-06-18 03:40:41 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2007-2014 Mnemosyne LLC
|
2007-06-18 03:40:41 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2007-08-18 17:05:51 +00:00
|
|
|
*
|
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
|
|
|
|
2009-04-08 20:57:47 +00:00
|
|
|
#ifdef __cplusplus
|
2017-04-19 12:04:45 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2009-04-08 20:57:47 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-20 20:14:13 +00:00
|
|
|
typedef 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;
|
2007-06-19 00:08:39 +00:00
|
|
|
}
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_metainfo_builder_file;
|
2007-06-19 00:08:39 +00:00
|
|
|
|
2008-03-24 17:18:08 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TR_MAKEMETA_OK,
|
|
|
|
TR_MAKEMETA_URL,
|
|
|
|
TR_MAKEMETA_CANCELLED,
|
2017-04-19 12:04:45 +00:00
|
|
|
TR_MAKEMETA_IO_READ, /* see builder.errfile, builder.my_errno */
|
|
|
|
TR_MAKEMETA_IO_WRITE /* see builder.errfile, builder.my_errno */
|
2008-03-24 17:18:08 +00:00
|
|
|
}
|
|
|
|
tr_metainfo_builder_err;
|
|
|
|
|
2007-09-20 20:14:13 +00:00
|
|
|
typedef 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;
|
|
|
|
char* comment;
|
|
|
|
char* outputFile;
|
|
|
|
bool isPrivate;
|
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;
|
|
|
|
tr_metainfo_builder_err 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;
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
2007-09-20 20:14:13 +00:00
|
|
|
tr_metainfo_builder;
|
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
|
|
|
|
|
|
|
/**
|
2008-06-01 05:36:23 +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
|
|
|
*
|
|
|
|
* @param outputFile if NULL, builder->top + ".torrent" will be used.
|
|
|
|
|
|
|
|
* @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
|
|
|
*/
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_makeMetaInfo(tr_metainfo_builder* builder, char const* outputFile, tr_tracker_info const* trackers, int trackerCount,
|
|
|
|
char const* comment, bool isPrivate);
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2009-04-08 20:57:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|