source: trunk/libtransmission/makemeta.h

Last change on this file was 14724, checked in by jordan, 5 years ago

use '#pragma once' instead of #ifndef..#define..#endif guards

  • Property svn:keywords set to Date Rev Author Id
File size: 3.7 KB
Line 
1/*
2 * This file Copyright (C) 2007-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: makemeta.h 14724 2016-03-29 16:37:21Z mikedld $
8 */
9
10#pragma once
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16typedef struct tr_metainfo_builder_file
17{
18    char *      filename;
19    uint64_t    size;
20}
21tr_metainfo_builder_file;
22
23typedef enum
24{
25    TR_MAKEMETA_OK,
26    TR_MAKEMETA_URL,
27    TR_MAKEMETA_CANCELLED,
28    TR_MAKEMETA_IO_READ,   /* see builder.errfile, builder.my_errno */
29    TR_MAKEMETA_IO_WRITE   /* see builder.errfile, builder.my_errno */
30}
31tr_metainfo_builder_err;
32
33
34typedef struct tr_metainfo_builder
35{
36    /**
37    ***  These are set by tr_makeMetaInfoBuilderCreate ()
38    ***  and cleaned up by tr_metaInfoBuilderFree ()
39    **/
40
41    char *                      top;
42    tr_metainfo_builder_file *  files;
43    uint64_t                    totalSize;
44    uint32_t                    fileCount;
45    uint32_t                    pieceSize;
46    uint32_t                    pieceCount;
47    bool                        isFolder;
48
49    /**
50    ***  These are set inside tr_makeMetaInfo ()
51    ***  by copying the arguments passed to it,
52    ***  and cleaned up by tr_metaInfoBuilderFree ()
53    **/
54
55    tr_tracker_info *  trackers;
56    int                trackerCount;
57    char *             comment;
58    char *             outputFile;
59    bool               isPrivate;
60
61    /**
62    ***  These are set inside tr_makeMetaInfo () so the client
63    ***  can poll periodically to see what the status is.
64    ***  The client can also set abortFlag to nonzero to
65    ***  tell tr_makeMetaInfo () to abort and clean up after itself.
66    **/
67
68    uint32_t                   pieceIndex;
69    bool                       abortFlag;
70    bool                       isDone;
71    tr_metainfo_builder_err    result;
72
73    /* file in use when result was set to _IO_READ or _IO_WRITE,
74     * or the URL in use when the result was set to _URL */
75    char    errfile[2048];
76
77    /* errno encountered when result was set to _IO_READ or _IO_WRITE */
78    int    my_errno;
79
80    /**
81    ***  This is an implementation detail.
82    ***  The client should never use these fields.
83    **/
84
85    struct tr_metainfo_builder * nextBuilder;
86}
87tr_metainfo_builder;
88
89
90tr_metainfo_builder * tr_metaInfoBuilderCreate (const char * topFile);
91
92/**
93 * Call this before tr_makeMetaInfo() to override the builder.pieceSize
94 * and builder.pieceCount values that were set by tr_metainfoBuilderCreate()
95 *
96 * @return false if the piece size isn't valid; eg, isn't a power of two.
97 */
98bool tr_metaInfoBuilderSetPieceSize (tr_metainfo_builder * builder,
99                                     uint32_t              bytes);
100
101void tr_metaInfoBuilderFree (tr_metainfo_builder*);
102
103/**
104 * @brief create a new .torrent file
105 *
106 * This is actually done in a worker thread, not the main thread!
107 * Otherwise the client's interface would lock up while this runs.
108 *
109 * It is the caller's responsibility to poll builder->isDone
110 * from time to time!  When the worker thread sets that flag,
111 * the caller must pass the builder to tr_metaInfoBuilderFree ().
112 *
113 * @param outputFile if NULL, builder->top + ".torrent" will be used.
114
115 * @param trackers An array of trackers, sorted by tier from first to last.
116 *                 NOTE: only the `tier' and `announce' fields are used.
117 *
118 * @param trackerCount size of the `trackers' array
119 */
120void tr_makeMetaInfo (tr_metainfo_builder *   builder,
121                      const char *            outputFile,
122                      const tr_tracker_info * trackers,
123                      int                     trackerCount,
124                      const char *            comment,
125                      bool                    isPrivate);
126
127
128#ifdef __cplusplus
129}
130#endif
131
Note: See TracBrowser for help on using the repository browser.