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 13800 2013-01-17 18:55:51Z jordan $ |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef TR_MAKEMETA_H |
---|
14 | #define TR_MAKEMETA_H 1 |
---|
15 | |
---|
16 | #ifdef __cplusplus |
---|
17 | extern "C" { |
---|
18 | #endif |
---|
19 | |
---|
20 | typedef struct tr_metainfo_builder_file |
---|
21 | { |
---|
22 | char * filename; |
---|
23 | uint64_t size; |
---|
24 | } |
---|
25 | tr_metainfo_builder_file; |
---|
26 | |
---|
27 | typedef 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 | } |
---|
35 | tr_metainfo_builder_err; |
---|
36 | |
---|
37 | |
---|
38 | typedef 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 | } |
---|
91 | tr_metainfo_builder; |
---|
92 | |
---|
93 | |
---|
94 | tr_metainfo_builder * tr_metaInfoBuilderCreate (const char * topFile); |
---|
95 | |
---|
96 | /** |
---|
97 | * Call this before tr_makeMetaInfo() to override the builder.pieceSize |
---|
98 | * and builder.pieceCount values that were set by tr_metainfoBuilderCreate() |
---|
99 | */ |
---|
100 | void tr_metaInfoBuilderSetPieceSize (tr_metainfo_builder * builder, |
---|
101 | uint32_t bytes); |
---|
102 | |
---|
103 | void tr_metaInfoBuilderFree (tr_metainfo_builder*); |
---|
104 | |
---|
105 | /** |
---|
106 | * @brief create a new .torrent file |
---|
107 | * |
---|
108 | * This is actually done in a worker thread, not the main thread! |
---|
109 | * Otherwise the client's interface would lock up while this runs. |
---|
110 | * |
---|
111 | * It is the caller's responsibility to poll builder->isDone |
---|
112 | * from time to time! When the worker thread sets that flag, |
---|
113 | * the caller must pass the builder to tr_metaInfoBuilderFree (). |
---|
114 | * |
---|
115 | * @param outputFile if NULL, builder->top + ".torrent" will be used. |
---|
116 | |
---|
117 | * @param trackers An array of trackers, sorted by tier from first to last. |
---|
118 | * NOTE: only the `tier' and `announce' fields are used. |
---|
119 | * |
---|
120 | * @param trackerCount size of the `trackers' array |
---|
121 | */ |
---|
122 | void tr_makeMetaInfo (tr_metainfo_builder * builder, |
---|
123 | const char * outputFile, |
---|
124 | const tr_tracker_info * trackers, |
---|
125 | int trackerCount, |
---|
126 | const char * comment, |
---|
127 | int isPrivate); |
---|
128 | |
---|
129 | |
---|
130 | #ifdef __cplusplus |
---|
131 | } |
---|
132 | #endif |
---|
133 | |
---|
134 | #endif |
---|