source: trunk/libtransmission/transmission.h @ 754

Last change on this file since 754 was 754, checked in by livings124, 15 years ago

Some new accessors for libtransmission...I don't see what harm these can do

  • Property svn:keywords set to Date Rev Author Id
File size: 13.6 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 754 2006-08-12 00:38:26Z livings124 $
3 *
4 * Copyright (c) 2005-2006 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef TR_TRANSMISSION_H
26#define TR_TRANSMISSION_H 1
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include "version.h"
33
34#include <inttypes.h>
35#ifndef PRIu64
36# define PRIu64 "lld"
37#endif
38
39#define SHA_DIGEST_LENGTH 20
40#ifdef __BEOS__
41# include <StorageDefs.h>
42# define MAX_PATH_LENGTH  B_FILE_NAME_LENGTH
43#else
44# define MAX_PATH_LENGTH  1024
45#endif
46
47#define TR_DEFAULT_PORT   9090
48#define TR_NOERROR        0
49
50/***********************************************************************
51 * tr_init
52 ***********************************************************************
53 * Initializes a libtransmission instance. Returns a obscure handle to
54 * be passed to all functions below.
55 **********************************************************************/
56typedef struct tr_handle_s tr_handle_t;
57tr_handle_t * tr_init();
58
59/***********************************************************************
60 * tr_setErrorFunction
61 ***********************************************************************
62 * Sets the function used to display libtransmission errors.  A NULL
63 * function means to use the default, which simple prints the message
64 * to stderr.  The function's prototype should look like this:
65 * void myErrFunc( const char * errstr );
66 **********************************************************************/
67void tr_setErrorFunction( void (*func)( const char * ) );
68
69/***********************************************************************
70 * tr_getPrefsDirectory
71 ***********************************************************************
72 * Returns the full path to a directory which can be used to store
73 * preferences. The string belongs to libtransmission, do not free it.
74 **********************************************************************/
75char * tr_getPrefsDirectory();
76
77/***********************************************************************
78 * tr_setBindPort
79 ***********************************************************************
80 * Sets a "start" port: everytime we start a torrent, we try to bind
81 * this port, then the next one and so on until we are successful.
82 **********************************************************************/
83void tr_setBindPort( tr_handle_t *, int );
84
85/***********************************************************************
86 * tr_setUploadLimit
87 ***********************************************************************
88 * Sets the total upload rate limit in KB/s
89 **********************************************************************/
90void tr_setUploadLimit( tr_handle_t *, int );
91
92/***********************************************************************
93 * tr_setDownloadLimit
94 ***********************************************************************
95 * Sets the total download rate limit in KB/s
96 **********************************************************************/
97void tr_setDownloadLimit( tr_handle_t *, int );
98
99/***********************************************************************
100 * tr_torrentCount
101 ***********************************************************************
102 * Returns the count of open torrents
103 **********************************************************************/
104int tr_torrentCount( tr_handle_t * h );
105
106/***********************************************************************
107 * tr_torrentIterate
108 ***********************************************************************
109 * Iterates on open torrents
110 **********************************************************************/
111typedef struct tr_torrent_s tr_torrent_t;
112typedef void (*tr_callback_t) ( tr_torrent_t *, void * );
113void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
114
115/***********************************************************************
116 * tr_torrentRates
117 ***********************************************************************
118 * Gets the total download and upload rates
119 **********************************************************************/
120void tr_torrentRates( tr_handle_t *, float *, float * );
121
122/***********************************************************************
123 * tr_close
124 ***********************************************************************
125 * Frees memory allocated by tr_init.
126 **********************************************************************/
127void tr_close( tr_handle_t * );
128
129/***********************************************************************
130 * tr_torrentInit
131 ***********************************************************************
132 * Opens and parses torrent file at 'path'. If the file exists and is a
133 * valid torrent file, returns an handle and adds it to the list of
134 * torrents (but doesn't start it). Returns NULL and sets *error
135 * otherwise.  If the TR_FSAVEPRIVATE flag is passed then a private copy
136 * of the torrent file will be saved.
137 **********************************************************************/
138#define TR_EINVALID     1
139#define TR_EUNSUPPORTED 2
140#define TR_EDUPLICATE   3
141#define TR_EOTHER       666
142tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
143                               int flags, int * error );
144
145/***********************************************************************
146 * tr_torrentInitSaved
147 ***********************************************************************
148 * Opens and parses a torrent file as with tr_torrentInit, only taking
149 * the hash string of a saved torrent file instead of a filename.  There
150 * are currently no valid flags for this function.
151 **********************************************************************/
152tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr,
153                                    int flags, int * error );
154
155typedef struct tr_info_s tr_info_t;
156tr_info_t * tr_torrentInfo( tr_torrent_t * );
157
158/***********************************************************************
159 * tr_torrentScrape
160 ***********************************************************************
161 * Asks the tracker for the count of seeders and leechers. Returns 0
162 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
163 * tracker doesn't support the scrape protocol, is unreachable or
164 * replied with some error. tr_torrentScrape may block up to 20 seconds
165 * before returning.
166 **********************************************************************/
167int tr_torrentScrape( tr_torrent_t *, int * s, int * l );
168
169/***********************************************************************
170 * tr_torrentStart
171 ***********************************************************************
172 * Starts downloading. The download is launched in a seperate thread,
173 * therefore tr_torrentStart returns immediately.
174 **********************************************************************/
175void   tr_torrentSetFolder( tr_torrent_t *, const char * );
176char * tr_torrentGetFolder( tr_torrent_t * );
177void   tr_torrentStart( tr_torrent_t * );
178
179/***********************************************************************
180 * tr_torrentStop
181 ***********************************************************************
182 * Stops downloading and notices the tracker that we are leaving. The
183 * thread keeps running while doing so.
184 * The thread will eventually be joined, either:
185 * - by tr_torrentStat when the tracker has been successfully noticed,
186 * - by tr_torrentStat if the tracker could not be noticed within 60s,
187 * - by tr_torrentClose if you choose to remove the torrent without
188 *   waiting any further.
189 **********************************************************************/
190void tr_torrentStop( tr_torrent_t * );
191
192/***********************************************************************
193 * tr_getFinished
194 ***********************************************************************
195 * The first call after a torrent is completed returns 1. Returns 0
196 * in other cases.
197 **********************************************************************/
198int tr_getFinished( tr_torrent_t * );
199
200/***********************************************************************
201 * tr_getPeer
202 ***********************************************************************
203 * Returns the peer at peerNum. Returns NULL if peerNum is not greater
204 * than 0 and less than peerCount.
205 **********************************************************************/
206typedef struct tr_peer_s tr_peer_t;
207tr_peer_t * tr_getPeer( tr_torrent_t *, int peerNum );
208
209/***********************************************************************
210 * tr_torrentStat
211 ***********************************************************************
212 * Returns a pointer to an tr_stat_t structure with updated information
213 * on the torrent. The structure belongs to libtransmission (do not
214 * free it) and is guaranteed to be unchanged until the next call to
215 * tr_torrentStat.
216 * The interface should call this function every second or so in order
217 * to update itself.
218 **********************************************************************/
219typedef struct tr_stat_s tr_stat_t;
220tr_stat_t * tr_torrentStat( tr_torrent_t * );
221
222/***********************************************************************
223 * tr_torrentAvailability
224 ***********************************************************************
225 * Use this to draw an advanced progress bar which is 'size' pixels
226 * wide. Fills 'tab' which you must have allocated: each byte is set
227 * to either -1 if we have the piece, otherwise it is set to the number
228 * of connected peers who have the piece.
229 **********************************************************************/
230void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
231
232/***********************************************************************
233 * tr_torrentRemoveSaved
234 ***********************************************************************
235 * Removes the private saved copy of a torrent file for torrents which
236 * the TR_FSAVEPRIVATE flag is set.
237 **********************************************************************/
238void tr_torrentRemoveSaved( tr_torrent_t * );
239
240/***********************************************************************
241 * tr_torrentClose
242 ***********************************************************************
243 * Frees memory allocated by tr_torrentInit. If the torrent was running,
244 * you must call tr_torrentStop() before closing it.
245 **********************************************************************/
246void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
247
248/***********************************************************************
249 * tr_info_s
250 **********************************************************************/
251typedef struct tr_file_s
252{
253    uint64_t length;                /* Length of the file, in bytes */
254    char     name[MAX_PATH_LENGTH]; /* Path to the file */
255}
256tr_file_t;
257struct tr_info_s
258{
259    /* Path to torrent */
260    char        torrent[MAX_PATH_LENGTH];
261
262    /* General info */
263    uint8_t     hash[SHA_DIGEST_LENGTH];
264    char        hashString[2*SHA_DIGEST_LENGTH+1];
265    char        name[MAX_PATH_LENGTH];
266
267    /* Flags */
268#define TR_FSAVEPRIVATE 0x01    /* save a private copy of the torrent */
269    int         flags;
270
271    /* Tracker info */
272    char        trackerAddress[256];
273    int         trackerPort;
274    char        trackerAnnounce[MAX_PATH_LENGTH];
275
276    /* Pieces info */
277    int         pieceSize;
278    int         pieceCount;
279    uint64_t    totalSize;
280    uint8_t   * pieces;
281
282    /* Files info */
283    int         multifile;
284    int         fileCount;
285    tr_file_t * files;
286};
287
288/***********************************************************************
289 * tr_stat_s
290 **********************************************************************/
291struct tr_stat_s
292{
293#define TR_STATUS_CHECK    0x001 /* Checking files */
294#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
295#define TR_STATUS_SEED     0x004 /* Seeding */
296#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
297#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
298                                    running (for internal use only) */
299#define TR_STATUS_PAUSE    0x020 /* Paused */
300
301#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
302#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
303    int         status;
304
305#define TR_ETRACKER 1
306#define TR_EINOUT   2
307    int         error;
308    char        trackerError[128];
309
310    float       progress;
311    float       rateDownload;
312    float       rateUpload;
313    int         eta;
314    int         peersTotal;
315    int         peersUploading;
316    int         peersDownloading;
317    int         seeders;
318    int         leechers;
319
320    uint64_t    downloaded;
321    uint64_t    uploaded;
322};
323
324#ifdef __TRANSMISSION__
325#  include "internal.h"
326#endif
327
328#ifdef __cplusplus
329}
330#endif
331
332#endif
Note: See TracBrowser for help on using the repository browser.