1/* 2 * This file Copyright (C) Mnemosyne LLC 3 * 4 * This file is licensed by the GPL version 2. Works owned by the 5 * Transmission project are granted a special exemption to clause 2(b) 6 * so that the bulk of its code can remain under the MIT license. 7 * This exemption does not extend to derived works not owned by 8 * the Transmission project. 9 * 10 * $Id: makemeta.h 11709 2011-01-19 13:48:47Z jordan $ 11 */ 12 13#ifndef TR_MAKEMETA_H 14#define TR_MAKEMETA_H 1 15 16#ifdef __cplusplus 17extern "C" { 18#endif 19 20typedef struct tr_metainfo_builder_file 21{ 22 char * filename; 23 uint64_t size; 24} 25tr_metainfo_builder_file; 26 27typedef enum 28{ 29 TR_MAKEMETA_OK, 30 TR_MAKEMETA_URL, 31 TR_MAKEMETA_CANCELLED, 32 TR_MAKEMETA_IO_READ, /* see builder.errfile, builder.my_errno */ 33 TR_MAKEMETA_IO_WRITE /* see builder.errfile, builder.my_errno */ 34} 35tr_metainfo_builder_err; 36 37 38typedef struct tr_metainfo_builder 39{ 40 /** 41 *** These are set by tr_makeMetaInfoBuilderCreate() 42 *** and cleaned up by tr_metaInfoBuilderFree() 43 **/ 44 45 char * top; 46 tr_metainfo_builder_file * files; 47 uint64_t totalSize; 48 uint32_t fileCount; 49 uint32_t pieceSize; 50 uint32_t pieceCount; 51 int isSingleFile; 52 53 /** 54 *** These are set inside tr_makeMetaInfo() 55 *** by copying the arguments passed to it, 56 *** and cleaned up by tr_metaInfoBuilderFree() 57 **/ 58 59 tr_tracker_info * trackers; 60 int trackerCount; 61 char * comment; 62 char * outputFile; 63 int isPrivate; 64 65 /** 66 *** These are set inside tr_makeMetaInfo() so the client 67 *** can poll periodically to see what the status is. 68 *** The client can also set abortFlag to nonzero to 69 *** tell tr_makeMetaInfo() to abort and clean up after itself. 70 **/ 71 72 uint32_t pieceIndex; 73 int abortFlag; 74 int isDone; 75 tr_metainfo_builder_err result; 76 77 /* file in use when result was set to _IO_READ or _IO_WRITE, 78 * or the URL in use when the result was set to _URL */ 79 char errfile[2048]; 80 81 /* errno encountered when result was set to _IO_READ or _IO_WRITE */ 82 int my_errno; 83 84 /** 85 *** This is an implementation detail. 86 *** The client should never use these fields. 87 **/ 88 89 struct tr_metainfo_builder * nextBuilder; 90} 91tr_metainfo_builder; 92 93 94tr_metainfo_builder*tr_metaInfoBuilderCreate( const char * topFile ); 95 96void tr_metaInfoBuilderFree( tr_metainfo_builder* ); 97 98/** 99 * @brief create a new .torrent file 100 * 101 * This is actually done in a worker thread, not the main thread! 102 * Otherwise the client's interface would lock up while this runs. 103 * 104 * It is the caller's responsibility to poll builder->isDone 105 * from time to time! When the worker thread sets that flag, 106 * the caller must pass the builder to tr_metaInfoBuilderFree(). 107 * 108 * @param outputFile if NULL, builder->top + ".torrent" will be used. 109 110 * @param trackers An array of trackers, sorted by tier from first to last. 111 * NOTE: only the `tier' and `announce' fields are used. 112 * 113 * @param trackerCount size of the `trackers' array 114 */ 115void tr_makeMetaInfo( tr_metainfo_builder * builder, 116 const char * outputFile, 117 const tr_tracker_info * trackers, 118 int trackerCount, 119 const char * comment, 120 int isPrivate ); 121 122 123#ifdef __cplusplus 124} 125#endif 126 127#endif 128