source: trunk/libtransmission/transmission.h @ 1868

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

separate code for determining if there is a download with same name and location

  • Property svn:keywords set to Date Rev Author Id
File size: 20.7 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 1868 2007-05-11 18:56:59Z livings124 $
3 *
4 * Copyright (c) 2005-2007 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 PRId64
36# define PRId64 "lld"
37#endif
38#ifndef PRIu64
39# define PRIu64 "llu"
40#endif
41#include <time.h>
42
43#define SHA_DIGEST_LENGTH 20
44#ifdef __BEOS__
45# include <StorageDefs.h>
46# define MAX_PATH_LENGTH  B_FILE_NAME_LENGTH
47#else
48# define MAX_PATH_LENGTH  1024
49#endif
50
51#ifndef INET_ADDRSTRLEN
52#define INET_ADDRSTRLEN 16
53#endif
54
55#define TR_DEFAULT_PORT   9090
56
57#define TR_PEER_FROM__MAX       4
58#define TR_PEER_FROM_INCOMING   0 /* connections made to the listening port */
59#define TR_PEER_FROM_TRACKER    1 /* peers received from a tracker */
60#define TR_PEER_FROM_CACHE      2 /* peers read from the peer cache */
61#define TR_PEER_FROM_PEX        3 /* peers discovered via PEX */
62
63/***********************************************************************
64 * Error codes
65 **********************************************************************/
66/* General errors */
67#define TR_OK                       0x00000000
68#define TR_ERROR                    0x81000000
69#define TR_ERROR_ASSERT             0x82000000
70/* I/O errors */
71#define TR_ERROR_IO_MASK            0x000000FF
72#define TR_ERROR_IO_PARENT          0x80000001
73#define TR_ERROR_IO_PERMISSIONS     0x80000002
74#define TR_ERROR_IO_SPACE           0x80000004
75#define TR_ERROR_IO_RESOURCES       0x80000008
76#define TR_ERROR_IO_DUP_DOWNLOAD    0x8000000A
77#define TR_ERROR_IO_OTHER           0x80000010
78/* Misc */
79#define TR_ERROR_TC_MASK            0x00000F00
80#define TR_ERROR_TC_ERROR           0x80000100
81#define TR_ERROR_TC_WARNING         0x80000200
82
83#define TR_ERROR_ISSET( num, code ) ( (code) == ( (code) & (num) ) )
84
85/***********************************************************************
86 * tr_init
87 ***********************************************************************
88 * Initializes a libtransmission instance. Returns a obscure handle to
89 * be passed to all functions below. The tag argument is a short string
90 * unique to the program invoking tr_init(), it is currently used as
91 * part of saved torrent files' names to prevent one frontend from
92 * deleting a torrent used by another. The following tags are used:
93 *   beos cli daemon gtk macosx
94 **********************************************************************/
95typedef struct tr_handle_s tr_handle_t;
96tr_handle_t * tr_init( const char * tag );
97
98typedef struct tr_tracker_info_s tr_tracker_info_t;
99
100/***********************************************************************
101 * tr_setMessageLevel
102 ***********************************************************************
103 * Set the level of messages to be output or queued
104 **********************************************************************/
105#define TR_MSG_ERR 1
106#define TR_MSG_INF 2
107#define TR_MSG_DBG 3
108void tr_setMessageLevel( int );
109int tr_getMessageLevel( void );
110
111/***********************************************************************
112 * tr_setMessageQueuing
113 ***********************************************************************
114 * Enable or disable message queuing
115 **********************************************************************/
116typedef struct tr_msg_list_s tr_msg_list_t;
117void tr_setMessageQueuing( int );
118
119/***********************************************************************
120 * tr_getQueuedMessages
121 ***********************************************************************
122 * Return a list of queued messages
123 **********************************************************************/
124tr_msg_list_t * tr_getQueuedMessages( void );
125void tr_freeMessageList( tr_msg_list_t * list );
126
127/***********************************************************************
128 * tr_getPrefsDirectory
129 ***********************************************************************
130 * Returns the full path to a directory which can be used to store
131 * preferences. The string belongs to libtransmission, do not free it.
132 **********************************************************************/
133char * tr_getPrefsDirectory();
134
135/***********************************************************************
136 * tr_setBindPort
137 ***********************************************************************
138 * Sets the port to listen for incoming peer connections.
139 * This can be safely called even with active torrents.
140 **********************************************************************/
141void tr_setBindPort( tr_handle_t *, int );
142
143/***********************************************************************
144 * tr_natTraversalEnable
145 * tr_natTraversalDisable
146 ***********************************************************************
147 * Enable or disable NAT traversal using NAT-PMP or UPnP IGD.
148 **********************************************************************/
149void tr_natTraversalEnable( tr_handle_t *, int enable );
150
151/***********************************************************************
152 * tr_handleStatus
153 ***********************************************************************
154 * Returns some status info for the given handle.
155 **********************************************************************/
156typedef struct tr_handle_status_s tr_handle_status_t;
157tr_handle_status_t * tr_handleStatus( tr_handle_t * );
158
159/***********************************************************************
160 * tr_setGlobalUploadLimit
161 ***********************************************************************
162 * Sets the total upload rate limit in KB/s
163 **********************************************************************/
164void tr_setGlobalUploadLimit( tr_handle_t *, int );
165
166/***********************************************************************
167 * tr_setGlobalDownloadLimit
168 ***********************************************************************
169 * Sets the total download rate limit in KB/s
170 **********************************************************************/
171void tr_setGlobalDownloadLimit( tr_handle_t *, int );
172
173/***********************************************************************
174 * tr_torrentCount
175 ***********************************************************************
176 * Returns the count of open torrents
177 **********************************************************************/
178int tr_torrentCount( tr_handle_t * h );
179
180/***********************************************************************
181 * tr_torrentIterate
182 ***********************************************************************
183 * Iterates on open torrents
184 **********************************************************************/
185typedef struct tr_torrent_s tr_torrent_t;
186typedef void (*tr_callback_t) ( tr_torrent_t *, void * );
187void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
188
189void tr_setUseCustomLimit( tr_torrent_t * tor, int limit );
190void tr_setUploadLimit( tr_torrent_t * tor, int limit );
191void tr_setDownloadLimit( tr_torrent_t * tor, int limit );
192
193/***********************************************************************
194 * tr_torrentRates
195 ***********************************************************************
196 * Gets the total download and upload rates
197 **********************************************************************/
198void tr_torrentRates( tr_handle_t *, float *, float * );
199
200/***********************************************************************
201 * tr_close
202 ***********************************************************************
203 * Frees memory allocated by tr_init.
204 **********************************************************************/
205void tr_close( tr_handle_t * );
206
207/***********************************************************************
208 * tr_torrentInit
209 ***********************************************************************
210 * Opens and parses torrent file at 'path'. If the file exists and is
211 * a valid torrent file, returns an handle and adds it to the list of
212 * torrents (but doesn't start it). Returns NULL and sets *error
213 * otherwise. If hash is not NULL and the torrent is already loaded
214 * then it's 20-byte hash will be copied in. If the TR_FLAG_SAVE flag
215 * is passed then a copy of the torrent file will be saved.
216 **********************************************************************/
217#define TR_EINVALID     1
218#define TR_EUNSUPPORTED 2
219#define TR_EDUPLICATE   3
220#define TR_EOTHER       666
221tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
222                               uint8_t * hash, int flags, int * error );
223
224/***********************************************************************
225 * tr_torrentInitData
226 ***********************************************************************
227 * Like tr_torrentInit, except the actual torrent data is passed in
228 * instead of the filename.
229 **********************************************************************/
230tr_torrent_t * tr_torrentInitData( tr_handle_t *, uint8_t * data,
231                                   size_t size, uint8_t * hash,
232                                   int flags, int * error );
233
234/***********************************************************************
235 * tr_torrentInitSaved
236 ***********************************************************************
237 * Opens and parses a torrent file as with tr_torrentInit, only taking
238 * the hash string of a saved torrent file instead of a filename. There
239 * are currently no valid flags for this function.
240 **********************************************************************/
241tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr,
242                                    int flags, int * error );
243
244/***********************************************************************
245 * tr_torrentDisablePex
246 ***********************************************************************
247 * Disable or enable peer exchange for this torrent. Peer exchange is
248 * enabled by default, except for private torrents where pex is
249 * disabled and cannot be enabled.
250 **********************************************************************/
251void tr_torrentDisablePex( tr_torrent_t *, int disable );
252
253/***********************************************************************
254 * tr_torrentScrape
255 ***********************************************************************
256 * Return torrent metainfo.
257 **********************************************************************/
258typedef struct tr_info_s tr_info_t;
259tr_info_t * tr_torrentInfo( tr_torrent_t * );
260
261/***********************************************************************
262 * tr_torrentScrape
263 ***********************************************************************
264 * Asks the tracker for the count of seeders and leechers. Returns 0
265 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
266 * tracker doesn't support the scrape protocol, is unreachable or
267 * replied with some error. tr_torrentScrape may block up to 20 seconds
268 * before returning.
269 **********************************************************************/
270int tr_torrentScrape( tr_torrent_t *, int * s, int * l, int * d );
271
272void   tr_torrentSetFolder( tr_torrent_t *, const char * );
273char * tr_torrentGetFolder( tr_torrent_t * );
274
275int tr_torrentDuplicateDownload( tr_torrent_t * tor );
276
277/***********************************************************************
278 * tr_torrentStart
279 ***********************************************************************
280 * Starts downloading. The download is launched in a seperate thread,
281 * therefore tr_torrentStart returns immediately.
282 **********************************************************************/
283void   tr_torrentStart( tr_torrent_t * );
284
285/***********************************************************************
286 * tr_torrentStop
287 ***********************************************************************
288 * Stops downloading and notices the tracker that we are leaving. The
289 * thread keeps running while doing so.
290 * The thread will eventually be joined, either:
291 * - by tr_torrentStat when the tracker has been successfully noticed,
292 * - by tr_torrentStat if the tracker could not be noticed within 60s,
293 * - by tr_torrentClose if you choose to remove the torrent without
294 *   waiting any further.
295 **********************************************************************/
296void tr_torrentStop( tr_torrent_t * );
297
298/***********************************************************************
299 * tr_getFinished
300 ***********************************************************************
301 * The first call after a torrent is completed returns 1. Returns 0
302 * in other cases.
303 **********************************************************************/
304int tr_getFinished( tr_torrent_t * );
305
306/***********************************************************************
307 * tr_manualUpdate
308 ***********************************************************************
309 * Reannounce to tracker regardless of wait interval
310 **********************************************************************/
311void tr_manualUpdate( tr_torrent_t * );
312
313/***********************************************************************
314 * tr_torrentStat
315 ***********************************************************************
316 * Returns a pointer to an tr_stat_t structure with updated information
317 * on the torrent. The structure belongs to libtransmission (do not
318 * free it) and is guaranteed to be unchanged until the next call to
319 * tr_torrentStat.
320 * The interface should call this function every second or so in order
321 * to update itself.
322 **********************************************************************/
323typedef struct tr_stat_s tr_stat_t;
324tr_stat_t * tr_torrentStat( tr_torrent_t * );
325
326/***********************************************************************
327 * tr_torrentPeers
328 ***********************************************************************/
329typedef struct tr_peer_stat_s tr_peer_stat_t;
330tr_peer_stat_t * tr_torrentPeers( tr_torrent_t *, int * peerCount );
331void tr_torrentPeersFree( tr_peer_stat_t *, int peerCount );
332
333/***********************************************************************
334 * tr_torrentAvailability
335 ***********************************************************************
336 * Use this to draw an advanced progress bar which is 'size' pixels
337 * wide. Fills 'tab' which you must have allocated: each byte is set
338 * to either -1 if we have the piece, otherwise it is set to the number
339 * of connected peers who have the piece.
340 **********************************************************************/
341void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
342
343void tr_torrentAmountFinished( tr_torrent_t * tor, float * tab, int size );
344
345/***********************************************************************
346 * tr_torrentCompletion
347 ***********************************************************************
348 * Returns the completion progress for each file in the torrent as an
349 * array of floats the same size and order as in tr_info_t. Free the
350 * array when done.
351 **********************************************************************/
352float * tr_torrentCompletion( tr_torrent_t * tor );
353
354/***********************************************************************
355 * tr_torrentRemoveSaved
356 ***********************************************************************
357 * Removes the saved copy of a torrent file for torrents which the
358 * TR_FLAG_SAVE flag is set.
359 **********************************************************************/
360void tr_torrentRemoveSaved( tr_torrent_t * );
361
362void tr_torrentRemoveFastResume( tr_torrent_t * tor );
363
364/***********************************************************************
365 * tr_torrentClose
366 ***********************************************************************
367 * Frees memory allocated by tr_torrentInit. If the torrent was running,
368 * you must call tr_torrentStop() before closing it.
369 **********************************************************************/
370void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
371
372/***********************************************************************
373 * tr_info_s
374 **********************************************************************/
375typedef struct tr_file_s
376{
377    uint64_t length;                /* Length of the file, in bytes */
378    char     name[MAX_PATH_LENGTH]; /* Path to the file */
379}
380tr_file_t;
381struct tr_info_s
382{
383    /* Path to torrent */
384    char                 torrent[MAX_PATH_LENGTH];
385
386    /* General info */
387    uint8_t              hash[SHA_DIGEST_LENGTH];
388    char                 hashString[2*SHA_DIGEST_LENGTH+1];
389    char                 name[MAX_PATH_LENGTH];
390
391    /* Flags */
392#define TR_FLAG_SAVE    0x01 /* save a copy of the torrent file */
393#define TR_FLAG_PRIVATE 0x02 /* do not share information for this torrent */
394    int                  flags;
395
396    /* Tracker info */
397    struct
398    {
399        tr_tracker_info_t * list;
400        int                 count;
401    }                  * trackerList;
402    int                  trackerTiers;
403
404    /* Torrent info */
405    char                 comment[MAX_PATH_LENGTH];
406    char                 creator[MAX_PATH_LENGTH];
407    int                  dateCreated;
408
409    /* Pieces info */
410    int                  pieceSize;
411    int                  pieceCount;
412    uint64_t             totalSize;
413    uint8_t            * pieces;
414
415    /* Files info */
416    int                  multifile;
417    int                  fileCount;
418    tr_file_t          * files;
419};
420
421/***********************************************************************
422 * tr_stat_s
423 **********************************************************************/
424struct tr_stat_s
425{
426#define TR_STATUS_CHECK    0x001 /* Checking files */
427#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
428#define TR_STATUS_SEED     0x004 /* Seeding */
429#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
430#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
431                                    running (for internal use only) */
432#define TR_STATUS_PAUSE    0x020 /* Paused */
433
434#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
435#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
436    int                 status;
437
438    int                 error;
439    char                errorString[128];
440    int                 cannotConnect;
441
442    tr_tracker_info_t * tracker;
443
444    float               progress;
445    float               rateDownload;
446    float               rateUpload;
447    int                 eta;
448    int                 peersTotal;
449    int                 peersFrom[TR_PEER_FROM__MAX];
450    int                 peersUploading;
451    int                 peersDownloading;
452    int                 seeders;
453    int                 leechers;
454    int                 completedFromTracker;
455
456    uint64_t            left;
457    uint64_t            downloaded;
458    uint64_t            uploaded;
459    float               swarmspeed;
460
461#define TR_RATIO_NA  -1
462    float               ratio;
463};
464
465struct tr_peer_stat_s
466{
467    char    addr[INET_ADDRSTRLEN];
468    const char * client;
469   
470    int     isConnected;
471    int     from;
472    float   progress;
473    int     port;
474   
475    int     isDownloading;
476    int     isUploading;
477    float   downloadFromRate;
478    float   uploadToRate;
479};
480
481struct tr_msg_list_s
482{
483    int                    level;
484    time_t                 when;
485    char                 * message;
486    struct tr_msg_list_s * next;
487};
488
489struct tr_tracker_info_s
490{
491    char * address;
492    int    port;
493    char * announce;
494    char * scrape;
495};
496
497struct tr_handle_status_s
498{
499#define TR_NAT_TRAVERSAL_MAPPING        1
500#define TR_NAT_TRAVERSAL_MAPPED         2
501#define TR_NAT_TRAVERSAL_NOTFOUND       3
502#define TR_NAT_TRAVERSAL_ERROR          4
503#define TR_NAT_TRAVERSAL_UNMAPPING      5
504#define TR_NAT_TRAVERSAL_DISABLED       6
505#define TR_NAT_TRAVERSAL_IS_DISABLED( st ) \
506  ( TR_NAT_TRAVERSAL_DISABLED == (st) || TR_NAT_TRAVERSAL_UNMAPPING == (st) )
507    int natTraversalStatus;
508    int publicPort;
509};
510
511#ifdef __TRANSMISSION__
512#  include "internal.h"
513#endif
514
515#ifdef __cplusplus
516}
517#endif
518
519#endif
Note: See TracBrowser for help on using the repository browser.