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
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2007-09-20 20:14:13 +00:00
|
|
|
typedef struct tr_metainfo_builder_file
|
2007-06-19 00:08:39 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +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,
|
2010-07-07 22:50:18 +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
|
|
|
{
|
|
|
|
/**
|
2012-12-05 17:29:46 +00:00
|
|
|
*** These are set by tr_makeMetaInfoBuilderCreate ()
|
|
|
|
*** and cleaned up by tr_metaInfoBuilderFree ()
|
2007-06-18 03:40:41 +00:00
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
char * top;
|
|
|
|
tr_metainfo_builder_file * files;
|
|
|
|
uint64_t totalSize;
|
|
|
|
uint32_t fileCount;
|
|
|
|
uint32_t pieceSize;
|
|
|
|
uint32_t pieceCount;
|
2014-06-08 22:16:01 +00:00
|
|
|
bool isFolder;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/**
|
2012-12-05 17:29:46 +00:00
|
|
|
*** These are set inside tr_makeMetaInfo ()
|
2007-06-18 03:40:41 +00:00
|
|
|
*** by copying the arguments passed to it,
|
2012-12-05 17:29:46 +00:00
|
|
|
*** and cleaned up by tr_metaInfoBuilderFree ()
|
2007-06-18 03:40:41 +00:00
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_tracker_info * trackers;
|
|
|
|
int trackerCount;
|
|
|
|
char * comment;
|
|
|
|
char * outputFile;
|
2013-08-24 18:18:38 +00:00
|
|
|
bool isPrivate;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/**
|
2012-12-05 17:29:46 +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
|
2012-12-05 17:29:46 +00:00
|
|
|
*** tell tr_makeMetaInfo () to abort and clean up after itself.
|
2007-06-18 03:40:41 +00:00
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
uint32_t pieceIndex;
|
2013-08-24 18:18:38 +00:00
|
|
|
bool abortFlag;
|
|
|
|
bool isDone;
|
2008-09-23 19:11:04 +00:00
|
|
|
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 */
|
2008-09-23 19:11:04 +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 */
|
2008-09-23 19:11:04 +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.
|
|
|
|
**/
|
|
|
|
|
2007-09-20 20:14:13 +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
|
|
|
|
|
|
|
|
2013-01-17 18:55:51 +00:00
|
|
|
tr_metainfo_builder * tr_metaInfoBuilderCreate (const char * 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
|
|
|
*/
|
2014-06-10 00:43:21 +00:00
|
|
|
bool tr_metaInfoBuilderSetPieceSize (tr_metainfo_builder * builder,
|
2013-01-17 18:55:51 +00:00
|
|
|
uint32_t bytes);
|
|
|
|
|
|
|
|
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,
|
2012-12-05 17:29:46 +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
|
|
|
*/
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_makeMetaInfo (tr_metainfo_builder * builder,
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * outputFile,
|
|
|
|
const tr_tracker_info * trackers,
|
|
|
|
int trackerCount,
|
|
|
|
const char * comment,
|
2013-08-24 18:18:38 +00:00
|
|
|
bool isPrivate);
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
|
2009-04-08 20:57:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|