2007-06-18 03:40:41 +00:00
|
|
|
/*
|
2009-01-10 23:09:07 +00:00
|
|
|
* This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com>
|
2007-06-18 03:40:41 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2007-06-18 03:40:41 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2007-08-18 17:05:51 +00:00
|
|
|
*
|
2007-08-18 17:19:49 +00:00
|
|
|
* $Id$
|
2007-06-18 03:40:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TR_MAKEMETA_H
|
|
|
|
#define TR_MAKEMETA_H 1
|
|
|
|
|
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,
|
|
|
|
TR_MAKEMETA_IO_READ, /* see builder.errfile, builder.errno */
|
|
|
|
TR_MAKEMETA_IO_WRITE /* see builder.errfile, builder.errno */
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
|
|
|
/**
|
2007-06-22 04:30:39 +00:00
|
|
|
*** These are set by tr_makeMetaInfoBuilderCreate()
|
2007-06-18 03:40:41 +00:00
|
|
|
*** and cleaned up by tr_metaInfoBuilderFree()
|
|
|
|
**/
|
|
|
|
|
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;
|
|
|
|
int isSingleFile;
|
2008-12-14 11:21:11 +00:00
|
|
|
tr_session * handle;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** These are set inside tr_makeMetaInfo()
|
|
|
|
*** by copying the arguments passed to it,
|
|
|
|
*** and cleaned up by tr_metaInfoBuilderFree()
|
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_tracker_info * trackers;
|
|
|
|
int trackerCount;
|
|
|
|
char * comment;
|
|
|
|
char * outputFile;
|
|
|
|
int isPrivate;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** These are set inside tr_makeMetaInfo() so the client
|
|
|
|
*** can poll periodically to see what the status is.
|
|
|
|
*** The client can also set abortFlag to nonzero to
|
|
|
|
*** tell tr_makeMetaInfo() to abort and clean up after itself.
|
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
uint32_t pieceIndex;
|
|
|
|
int abortFlag;
|
|
|
|
int isDone;
|
|
|
|
tr_metainfo_builder_err result;
|
2008-03-24 17:18:08 +00:00
|
|
|
|
|
|
|
/* file in use when result was set to _IO_READ or _IO_WRITE */
|
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
|
|
|
|
|
|
|
|
2008-12-14 11:21:11 +00:00
|
|
|
tr_metainfo_builder*tr_metaInfoBuilderCreate( tr_session * session,
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * topFile );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-23 19:11:04 +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,
|
|
|
|
* 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
|
|
|
*/
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_makeMetaInfo( tr_metainfo_builder * builder,
|
|
|
|
const char * outputFile,
|
|
|
|
const tr_tracker_info * trackers,
|
|
|
|
int trackerCount,
|
|
|
|
const char * comment,
|
|
|
|
int isPrivate );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|