source: trunk/libtransmission/transmission.h @ 10851

Last change on this file since 10851 was 10851, checked in by charles, 12 years ago

(trunk libT) #3320 "If the seed ratio is already met" -- fix a bug in r10848 reported by BMW

  • Property svn:keywords set to Date Rev Author Id
File size: 64.8 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 10851 2010-06-25 15:39:17Z charles $
3 *
4 * Copyright (c) 2005-2008 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/*
26 * This file defines the public API for the libtransmission library.
27 *
28 * Other headers with a public API are bencode.h and utils.h.
29 * Most of the remaining headers in libtransmission are private.
30 */
31#ifndef TR_TRANSMISSION_H
32#define TR_TRANSMISSION_H 1
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/***
39****
40****  Basic Types
41****
42***/
43
44#include <inttypes.h> /* uintN_t */
45#include <time.h> /* time_t */
46
47#ifndef PRId64
48 #define PRId64 "lld"
49#endif
50#ifndef PRIu64
51 #define PRIu64 "llu"
52#endif
53#ifndef PRIu32
54 #define PRIu32 "lu"
55#endif
56
57#if defined(WIN32) && defined(_MSC_VER)
58 #define inline __inline
59#endif
60
61#define SHA_DIGEST_LENGTH 20
62#define TR_INET6_ADDRSTRLEN 46
63
64typedef uint32_t tr_file_index_t;
65typedef uint32_t tr_piece_index_t;
66typedef uint64_t tr_block_index_t;
67typedef uint16_t tr_port;
68typedef uint8_t tr_bool;
69
70typedef struct tr_ctor tr_ctor;
71typedef struct tr_info tr_info;
72typedef struct tr_torrent tr_torrent;
73typedef struct tr_session tr_session;
74
75struct tr_benc;
76
77typedef int8_t tr_priority_t;
78
79#define TR_RPC_SESSION_ID_HEADER "X-Transmission-Session-Id"
80
81typedef enum
82{
83    TR_PREALLOCATE_NONE   = 0,
84    TR_PREALLOCATE_SPARSE = 1,
85    TR_PREALLOCATE_FULL   = 2
86}
87tr_preallocation_mode;
88
89typedef enum
90{
91    TR_PROXY_HTTP,
92    TR_PROXY_SOCKS4,
93    TR_PROXY_SOCKS5
94}
95tr_proxy_type;
96
97typedef enum
98{
99    TR_CLEAR_PREFERRED,
100    TR_ENCRYPTION_PREFERRED,
101    TR_ENCRYPTION_REQUIRED
102}
103tr_encryption_mode;
104
105
106/***
107****
108****  Startup & Shutdown
109****
110***/
111
112/**
113 * @addtogroup tr_session Session
114 *
115 * A libtransmission session is created by calling tr_sessionInit().
116 * libtransmission creates a thread for itself so that it can operate
117 * independently of the caller's event loop.  The session will continue
118 * until tr_sessionClose() is called.
119 *
120 * @{
121 */
122
123/**
124 * @brief returns Transmission's default configuration file directory.
125 *
126 * The default configuration directory is determined this way:
127 * -# If the TRANSMISSION_HOME environment variable is set, its value is used.
128 * -# On Darwin, "${HOME}/Library/Application Support/${appname}" is used.
129 * -# On Windows, "${CSIDL_APPDATA}/${appname}" is used.
130 * -# If XDG_CONFIG_HOME is set, "${XDG_CONFIG_HOME}/${appname}" is used.
131 * -# ${HOME}/.config/${appname}" is used as a last resort.
132 */
133const char* tr_getDefaultConfigDir( const char * appname );
134
135/**
136 * @brief returns Transmisson's default download directory.
137 *
138 * The default download directory is determined this way:
139 * -# If the HOME environment variable is set, "${HOME}/Downloads" is used.
140 * -# On Windows, "${CSIDL_MYDOCUMENTS}/Downloads" is used.
141 * -# Otherwise, getpwuid(getuid())->pw_dir + "/Downloads" is used.
142 */
143const char* tr_getDefaultDownloadDir( void );
144
145
146#define TR_DEFAULT_BIND_ADDRESS_IPV4        "0.0.0.0"
147#define TR_DEFAULT_BIND_ADDRESS_IPV6             "::"
148#define TR_DEFAULT_OPEN_FILE_LIMIT_STR           "32"
149#define TR_DEFAULT_RPC_WHITELIST          "127.0.0.1"
150#define TR_DEFAULT_RPC_PORT_STR                "9091"
151#define TR_DEFAULT_PEER_PORT_STR              "51413"
152#define TR_DEFAULT_PEER_SOCKET_TOS_STR            "0"
153#define TR_DEFAULT_PEER_LIMIT_GLOBAL_STR        "240"
154#define TR_DEFAULT_PEER_LIMIT_TORRENT_STR        "60"
155
156#define TR_PREFS_KEY_ALT_SPEED_ENABLED             "alt-speed-enabled"
157#define TR_PREFS_KEY_ALT_SPEED_UP                  "alt-speed-up"
158#define TR_PREFS_KEY_ALT_SPEED_DOWN                "alt-speed-down"
159#define TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN          "alt-speed-time-begin"
160#define TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED        "alt-speed-time-enabled"
161#define TR_PREFS_KEY_ALT_SPEED_TIME_END            "alt-speed-time-end"
162#define TR_PREFS_KEY_ALT_SPEED_TIME_DAY            "alt-speed-time-day"
163#define TR_PREFS_KEY_BIND_ADDRESS_IPV4             "bind-address-ipv4"
164#define TR_PREFS_KEY_BIND_ADDRESS_IPV6             "bind-address-ipv6"
165#define TR_PREFS_KEY_BLOCKLIST_ENABLED             "blocklist-enabled"
166#define TR_PREFS_KEY_MAX_CACHE_SIZE_MiB            "cache-size-MiB"
167#define TR_PREFS_KEY_DHT_ENABLED                   "dht-enabled"
168#define TR_PREFS_KEY_LPD_ENABLED                   "lpd-enabled"
169#define TR_PREFS_KEY_DOWNLOAD_DIR                  "download-dir"
170#define TR_PREFS_KEY_ENCRYPTION                    "encryption"
171#define TR_PREFS_KEY_INCOMPLETE_DIR                "incomplete-dir"
172#define TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED        "incomplete-dir-enabled"
173#define TR_PREFS_KEY_LAZY_BITFIELD                 "lazy-bitfield-enabled"
174#define TR_PREFS_KEY_MSGLEVEL                      "message-level"
175#define TR_PREFS_KEY_OPEN_FILE_LIMIT               "open-file-limit"
176#define TR_PREFS_KEY_PEER_LIMIT_GLOBAL             "peer-limit-global"
177#define TR_PREFS_KEY_PEER_LIMIT_TORRENT            "peer-limit-per-torrent"
178#define TR_PREFS_KEY_PEER_PORT                     "peer-port"
179#define TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START     "peer-port-random-on-start"
180#define TR_PREFS_KEY_PEER_PORT_RANDOM_LOW          "peer-port-random-low"
181#define TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH         "peer-port-random-high"
182#define TR_PREFS_KEY_PEER_SOCKET_TOS               "peer-socket-tos"
183#define TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM     "peer-congestion-algorithm"
184#define TR_PREFS_KEY_PEX_ENABLED                   "pex-enabled"
185#define TR_PREFS_KEY_PORT_FORWARDING               "port-forwarding-enabled"
186#define TR_PREFS_KEY_PROXY_AUTH_ENABLED            "proxy-auth-enabled"
187#define TR_PREFS_KEY_PREALLOCATION                 "preallocation"
188#define TR_PREFS_KEY_PROXY_ENABLED                 "proxy-enabled"
189#define TR_PREFS_KEY_PROXY_PASSWORD                "proxy-auth-password"
190#define TR_PREFS_KEY_PROXY_PORT                    "proxy-port"
191#define TR_PREFS_KEY_PROXY                         "proxy"
192#define TR_PREFS_KEY_PROXY_TYPE                    "proxy-type"
193#define TR_PREFS_KEY_PROXY_USERNAME                "proxy-auth-username"
194#define TR_PREFS_KEY_RATIO                         "ratio-limit"
195#define TR_PREFS_KEY_RATIO_ENABLED                 "ratio-limit-enabled"
196#define TR_PREFS_KEY_RENAME_PARTIAL_FILES          "rename-partial-files"
197#define TR_PREFS_KEY_RPC_AUTH_REQUIRED             "rpc-authentication-required"
198#define TR_PREFS_KEY_RPC_BIND_ADDRESS              "rpc-bind-address"
199#define TR_PREFS_KEY_RPC_ENABLED                   "rpc-enabled"
200#define TR_PREFS_KEY_RPC_PASSWORD                  "rpc-password"
201#define TR_PREFS_KEY_RPC_PORT                      "rpc-port"
202#define TR_PREFS_KEY_RPC_USERNAME                  "rpc-username"
203#define TR_PREFS_KEY_RPC_WHITELIST_ENABLED         "rpc-whitelist-enabled"
204#define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME  "script-torrent-done-filename"
205#define TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED   "script-torrent-done-enabled"
206#define TR_PREFS_KEY_RPC_WHITELIST                 "rpc-whitelist"
207#define TR_PREFS_KEY_DSPEED                        "speed-limit-down"
208#define TR_PREFS_KEY_DSPEED_ENABLED                "speed-limit-down-enabled"
209#define TR_PREFS_KEY_USPEED_ENABLED                "speed-limit-up-enabled"
210#define TR_PREFS_KEY_USPEED                        "speed-limit-up"
211#define TR_PREFS_KEY_UMASK                         "umask"
212#define TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT      "upload-slots-per-torrent"
213#define TR_PREFS_KEY_START                         "start-added-torrents"
214#define TR_PREFS_KEY_TRASH_ORIGINAL                "trash-original-torrent-files"
215
216
217/**
218 * Add libtransmission's default settings to the benc dictionary.
219 *
220 * Example:
221 * @code
222 *     tr_benc settings;
223 *     int64_t i;
224 *
225 *     tr_bencInitDict( &settings, 0 );
226 *     tr_sessionGetDefaultSettings( &settings );
227 *     if( tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_PORT, &i ) )
228 *         fprintf( stderr, "the default peer port is %d\n", (int)i );
229 *     tr_bencFree( &settings );
230 * @endcode
231 *
232 * @param initme pointer to a tr_benc dictionary
233 * @see tr_sessionLoadSettings()
234 * @see tr_sessionInit()
235 * @see tr_getDefaultConfigDir()
236 */
237void tr_sessionGetDefaultSettings( const char * configDir, struct tr_benc * dictionary );
238
239/**
240 * Add the session's current configuration settings to the benc dictionary.
241 *
242 * FIXME: this probably belongs in libtransmissionapp
243 *
244 * @param session
245 * @param dictionary
246 * @see tr_sessionGetDefaultSettings()
247 */
248void tr_sessionGetSettings( tr_session *, struct tr_benc * dictionary );
249
250/**
251 * Load settings from the configuration directory's settings.json file,
252 * using libtransmission's default settings as fallbacks for missing keys.
253 *
254 * FIXME: this belongs in libtransmissionapp
255 *
256 * @param dictionary pointer to an uninitialized tr_benc
257 * @param configDir the configuration directory to find settings.json
258 * @param appName if configDir is empty, appName is used to find the default dir.
259 * @return success TRUE if the settings were loaded, FALSE otherwise
260 * @see tr_sessionGetDefaultSettings()
261 * @see tr_sessionInit()
262 * @see tr_sessionSaveSettings()
263 */
264tr_bool tr_sessionLoadSettings( struct tr_benc  * dictionary,
265                                const char      * configDir,
266                                const char      * appName );
267
268/**
269 * Add the session's configuration settings to the benc dictionary
270 * and save it to the configuration directory's settings.json file.
271 *
272 * FIXME: this belongs in libtransmissionapp
273 *
274 * @param session
275 * @param dictionary
276 * @see tr_sessionLoadSettings()
277 */
278void tr_sessionSaveSettings( tr_session           * session,
279                             const char           * configDir,
280                             const struct tr_benc * dictonary );
281
282/**
283 * @brief Initialize a libtransmission session.
284 *
285 * For example, this will instantiate a session with all the default values:
286 * @code
287 *     tr_benc settings;
288 *     tr_session * session;
289 *     const char * configDir;
290 *
291 *     tr_bencInitDict( &settings, 0 );
292 *     tr_sessionGetDefaultSettings( &settings );
293 *     configDir = tr_getDefaultConfigDir( "Transmission" );
294 *     session = tr_sessionInit( "mac", configDir, true, &settings );
295 *
296 *     tr_bencFree( &settings );
297 * @endcode
298 *
299 * @param tag "gtk", "macosx", "daemon", etc... this is only for pre-1.30 resume files
300 * @param configDir where Transmission will look for resume files, blocklists, etc.
301 * @param messageQueueingEnabled if false, messages will be dumped to stderr
302 * @param settings libtransmission settings
303 * @see tr_sessionGetDefaultSettings()
304 * @see tr_sessionLoadSettings()
305 * @see tr_getDefaultConfigDir()
306 */
307tr_session * tr_sessionInit( const char     * tag,
308                             const char     * configDir,
309                             tr_bool          messageQueueingEnabled,
310                             struct tr_benc * settings );
311
312/** @brief Update a session's settings from a benc dictionary like to the one used in tr_sessionInit() */
313void tr_sessionSet( tr_session      * session,
314                    struct tr_benc  * settings );
315
316/** @brief Rescan the blocklists directory and reload whatever blocklist files are found there */
317void tr_sessionReloadBlocklists( tr_session * session );
318
319
320/** @brief End a libtransmission session
321    @see tr_sessionInit() */
322void tr_sessionClose( tr_session * );
323
324/**
325 * @brief Return the session's configuration directory.
326 *
327 * This is where transmission stores its .torrent files, .resume files,
328 * blocklists, etc.  It's set in tr_transmissionInit() and is immutable
329 * during the session.
330 */
331const char * tr_sessionGetConfigDir( const tr_session * );
332
333/**
334 * @brief Set the per-session default download folder for new torrents.
335 * @see tr_sessionInit()
336 * @see tr_sessionGetDownloadDir()
337 * @see tr_ctorSetDownloadDir()
338 */
339void tr_sessionSetDownloadDir( tr_session * session, const char * downloadDir );
340
341/**
342 * @brief Get the default download folder for new torrents.
343 *
344 * This is set by tr_sessionInit() or tr_sessionSetDownloadDir(),
345 * and can be overridden on a per-torrent basis by tr_ctorSetDownloadDir().
346 */
347const char * tr_sessionGetDownloadDir( const tr_session * session );
348
349
350/**
351 * @brief Set the torrent's bandwidth priority.
352 */
353void tr_ctorSetBandwidthPriority( tr_ctor * ctor, tr_priority_t priority );
354
355/**
356 * @brief Get the torrent's bandwidth priority.
357 */
358tr_priority_t tr_ctorGetBandwidthPriority( const tr_ctor * ctor );
359
360
361/**
362 * @brief set the per-session incomplete download folder.
363 *
364 * When you add a new torrent and the session's incomplete directory is enabled,
365 * the new torrent will start downloading into that directory, and then be moved
366 * to tr_torrent.downloadDir when the torrent is finished downloading.
367 *
368 * Torrents are not moved as a result of changing the session's incomplete dir --
369 * it's applied to new torrents, not existing ones.
370 *
371 * tr_torrentSetLocation() overrules the incomplete dir: when a user specifies
372 * a new location, that becomes the torrent's new downloadDir and the torrent
373 * is moved there immediately regardless of whether or not it's complete.
374 *
375 * @see tr_sessionInit()
376 * @see tr_sessionGetIncompleteDir()
377 * @see tr_sessionSetIncompleteDirEnabled()
378 * @see tr_sessionGetIncompleteDirEnabled()
379 */
380void tr_sessionSetIncompleteDir( tr_session * session, const char * dir );
381
382/** @brief get the per-session incomplete download folder */
383const char* tr_sessionGetIncompleteDir( const tr_session * session );
384
385/** @brief enable or disable use of the incomplete download folder */
386void tr_sessionSetIncompleteDirEnabled( tr_session * session, tr_bool );
387
388/** @brief get whether or not the incomplete download folder is enabled */
389tr_bool tr_sessionIsIncompleteDirEnabled( const tr_session * session );
390
391
392/**
393 * @brief When enabled, newly-created files will have ".part" appended
394 *        to their filename until the file is fully downloaded
395 *
396 * This is not retroactive -- toggling this will not rename existing files.
397 * It only applies to new files created by Transmission after this API call.
398 *
399 * @see tr_sessionIsIncompleteFileNamingEnabled()
400 */
401void tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, tr_bool );
402
403/** @brief return whether or filenames will have ".part" at the end until they're complete */
404tr_bool tr_sessionIsIncompleteFileNamingEnabled( const tr_session * session );
405
406/**
407 * @brief Set whether or not RPC calls are allowed in this session.
408 *
409 * @details If true, libtransmission will open a server socket to listen
410 * for incoming http RPC requests as described in docs/rpc-spec.txt.
411 *
412 * This is intially set by tr_sessionInit() and can be
413 * queried by tr_sessionIsRPCEnabled().
414 */
415void tr_sessionSetRPCEnabled( tr_session  * session,
416                              tr_bool       isEnabled );
417
418/** @brief Get whether or not RPC calls are allowed in this session.
419    @see tr_sessionInit()
420    @see tr_sessionSetRPCEnabled() */
421tr_bool tr_sessionIsRPCEnabled( const tr_session * session );
422
423/** @brief Specify which port to listen for RPC requests on.
424    @see tr_sessionInit()
425    @see tr_sessionGetRPCPort */
426void tr_sessionSetRPCPort( tr_session  * session,
427                           tr_port       port );
428
429/** @brief Get which port to listen for RPC requests on.
430    @see tr_sessionInit()
431    @see tr_sessionSetRPCPort */
432tr_port tr_sessionGetRPCPort( const tr_session * session );
433
434/**
435 * @brief Specify a whitelist for remote RPC access
436 *
437 * The whitelist is a comma-separated list of dotted-quad IP addresses
438 * to be allowed.  Wildmat notation is supported, meaning that
439 * '?' is interpreted as a single-character wildcard and
440 * '*' is interprted as a multi-character wildcard.
441 */
442void   tr_sessionSetRPCWhitelist( tr_session * session,
443                                  const char * whitelist );
444
445/** @brief get the Access Control List for allowing/denying RPC requests.
446    @return a comma-separated string of whitelist domains.
447    @see tr_sessionInit
448    @see tr_sessionSetRPCWhitelist */
449const char* tr_sessionGetRPCWhitelist( const tr_session * );
450
451void  tr_sessionSetRPCWhitelistEnabled( tr_session * session,
452                                        tr_bool      isEnabled );
453
454tr_bool tr_sessionGetRPCWhitelistEnabled( const tr_session * session );
455
456void  tr_sessionSetRPCPassword( tr_session * session,
457                                const char * password );
458
459void  tr_sessionSetRPCUsername( tr_session * session,
460                                const char * username );
461
462/** @brief get the password used to restrict RPC requests.
463    @return the password string.
464    @see tr_sessionInit()
465    @see tr_sessionSetRPCPassword() */
466const char* tr_sessionGetRPCPassword( const tr_session * session );
467
468const char* tr_sessionGetRPCUsername( const tr_session * session  );
469
470void  tr_sessionSetRPCPasswordEnabled( tr_session * session,
471                                       tr_bool      isEnabled );
472
473tr_bool tr_sessionIsRPCPasswordEnabled( const tr_session * session );
474
475const char* tr_sessionGetRPCBindAddress( const tr_session * session );
476
477
478typedef enum
479{
480    TR_RPC_TORRENT_ADDED,
481    TR_RPC_TORRENT_STARTED,
482    TR_RPC_TORRENT_STOPPED,
483    TR_RPC_TORRENT_REMOVING,
484    TR_RPC_TORRENT_CHANGED, /* catch-all for the "torrent-set" rpc method */
485    TR_RPC_TORRENT_MOVED,
486    TR_RPC_SESSION_CHANGED
487}
488tr_rpc_callback_type;
489
490typedef enum
491{
492    /* no special handling is needed by the caller */
493    TR_RPC_OK            = 0,
494
495    /* indicates to the caller that the client will take care of
496     * removing the torrent itself.  For example the client may
497     * need to keep the torrent alive long enough to cleanly close
498     * some resources in another thread. */
499    TR_RPC_NOREMOVE   = ( 1 << 1 )
500}
501tr_rpc_callback_status;
502
503typedef tr_rpc_callback_status (*tr_rpc_func)(tr_session          * session,
504                                              tr_rpc_callback_type  type,
505                                              struct tr_torrent   * tor_or_null,
506                                              void                * user_data );
507
508/**
509 * Register to be notified whenever something is changed via RPC,
510 * such as a torrent being added, removed, started, stopped, etc.
511 *
512 * func is invoked FROM LIBTRANSMISSION'S THREAD!
513 * This means func must be fast (to avoid blocking peers),
514 * shouldn't call libtransmission functions (to avoid deadlock),
515 * and shouldn't modify client-level memory without using a mutex!
516 */
517void tr_sessionSetRPCCallback( tr_session   * session,
518                               tr_rpc_func    func,
519                               void         * user_data );
520
521/**
522***
523**/
524
525tr_bool       tr_sessionIsProxyEnabled( const tr_session * );
526
527tr_bool       tr_sessionIsProxyAuthEnabled( const tr_session * );
528
529const char*   tr_sessionGetProxy( const tr_session * );
530
531tr_port       tr_sessionGetProxyPort( const tr_session * );
532
533tr_proxy_type tr_sessionGetProxyType( const tr_session * );
534
535const char*   tr_sessionGetProxyUsername( const tr_session * );
536
537const char*   tr_sessionGetProxyPassword( const tr_session * );
538
539void          tr_sessionSetProxyEnabled( tr_session * session,
540                                         tr_bool      isEnabled );
541
542void          tr_sessionSetProxyAuthEnabled( tr_session * session,
543                                             tr_bool      isEnabled );
544
545void          tr_sessionSetProxy( tr_session * session,
546                                  const char * proxy );
547
548void          tr_sessionSetProxyPort( tr_session * session,
549                                      tr_port      port );
550
551void          tr_sessionSetProxyType( tr_session    * session,
552                                      tr_proxy_type   proxy_type );
553
554void          tr_sessionSetProxyUsername( tr_session * session,
555                                          const char * username );
556
557void          tr_sessionSetProxyPassword( tr_session * session,
558                                          const char * password );
559
560/**
561***
562**/
563
564/** @brief Used by tr_sessionGetStats() and tr_sessionGetCumulativeStats() to give bandwidth statistics */
565typedef struct tr_session_stats
566{
567    float       ratio;        /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */
568    uint64_t    uploadedBytes; /* total up */
569    uint64_t    downloadedBytes; /* total down */
570    uint64_t    filesAdded;   /* number of files added */
571    uint64_t    sessionCount; /* program started N times */
572    uint64_t    secondsActive; /* how long Transmisson's been running */
573}
574tr_session_stats;
575
576/** @brief Get bandwidth use statistics about the current session */
577void tr_sessionGetStats( const tr_session * session, tr_session_stats * setme );
578
579/** @brief Get cumulative bandwidth use statistics for the current and past sessions */
580void tr_sessionGetCumulativeStats( const tr_session * session, tr_session_stats * setme );
581
582void tr_sessionClearStats( tr_session * session );
583
584/**
585 * @brief Set whether or not torrents are allowed to do peer exchanges.
586 *
587 * PEX is always disabled in private torrents regardless of this.
588 * In public torrents, PEX is enabled by default.
589 */
590void     tr_sessionSetPexEnabled( tr_session  * session, tr_bool isEnabled );
591tr_bool  tr_sessionIsPexEnabled( const tr_session * session );
592
593tr_bool  tr_sessionIsDHTEnabled( const tr_session * session );
594void     tr_sessionSetDHTEnabled( tr_session * session, tr_bool );
595
596tr_bool  tr_sessionIsLPDEnabled( const tr_session * session );
597void     tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled );
598
599void     tr_sessionSetCacheLimit( tr_session * session, double MiB );
600double   tr_sessionGetCacheLimit( const tr_session * session );
601
602void     tr_sessionSetLazyBitfieldEnabled( tr_session * session, tr_bool enabled );
603tr_bool  tr_sessionIsLazyBitfieldEnabled( const tr_session * session );
604
605tr_encryption_mode tr_sessionGetEncryption( tr_session * session );
606void               tr_sessionSetEncryption( tr_session * session,
607                                            tr_encryption_mode    mode );
608
609
610/***********************************************************************
611** Incoming Peer Connections Port
612*/
613
614void  tr_sessionSetPortForwardingEnabled( tr_session  * session,
615                                          tr_bool       enabled );
616
617tr_bool tr_sessionIsPortForwardingEnabled( const tr_session  * session );
618
619void  tr_sessionSetPeerPort( tr_session  * session,
620                             tr_port       port);
621
622tr_port tr_sessionGetPeerPort( const tr_session * session );
623
624tr_port tr_sessionSetPeerPortRandom( tr_session  * session );
625
626void  tr_sessionSetPeerPortRandomOnStart( tr_session * session,
627                                          tr_bool random );
628
629tr_bool  tr_sessionGetPeerPortRandomOnStart( tr_session * session );
630
631typedef enum
632{
633    TR_PORT_ERROR,
634    TR_PORT_UNMAPPED,
635    TR_PORT_UNMAPPING,
636    TR_PORT_MAPPING,
637    TR_PORT_MAPPED
638}
639tr_port_forwarding;
640
641tr_port_forwarding tr_sessionGetPortForwarding( const tr_session * session );
642
643typedef enum
644{
645    TR_CLIENT_TO_PEER = 0, TR_UP = 0,
646    TR_PEER_TO_CLIENT = 1, TR_DOWN = 1
647}
648tr_direction;
649
650/***
651****
652***/
653
654/***
655****  Primary session speed limits
656***/
657
658void     tr_sessionSetSpeedLimit      ( tr_session *, tr_direction, int KB_s );
659int      tr_sessionGetSpeedLimit      ( const tr_session *, tr_direction );
660
661void     tr_sessionLimitSpeed         ( tr_session *, tr_direction, tr_bool );
662tr_bool  tr_sessionIsSpeedLimited     ( const tr_session *, tr_direction );
663
664
665/***
666****  Alternative speed limits that are used during scheduled times
667***/
668
669void     tr_sessionSetAltSpeed        ( tr_session *, tr_direction, int KB_s );
670int      tr_sessionGetAltSpeed        ( const tr_session *, tr_direction );
671
672void     tr_sessionUseAltSpeed        ( tr_session *, tr_bool );
673tr_bool  tr_sessionUsesAltSpeed       ( const tr_session * );
674
675void     tr_sessionUseAltSpeedTime    ( tr_session *, tr_bool );
676tr_bool  tr_sessionUsesAltSpeedTime   ( const tr_session * );
677
678void     tr_sessionSetAltSpeedBegin   ( tr_session *, int minsSinceMidnight );
679int      tr_sessionGetAltSpeedBegin   ( const tr_session * );
680
681void     tr_sessionSetAltSpeedEnd     ( tr_session *, int minsSinceMidnight );
682int      tr_sessionGetAltSpeedEnd     ( const tr_session * );
683
684typedef enum
685{
686    TR_SCHED_SUN      = (1<<0),
687    TR_SCHED_MON      = (1<<1),
688    TR_SCHED_TUES     = (1<<2),
689    TR_SCHED_WED      = (1<<3),
690    TR_SCHED_THURS    = (1<<4),
691    TR_SCHED_FRI      = (1<<5),
692    TR_SCHED_SAT      = (1<<6),
693    TR_SCHED_WEEKDAY  = (TR_SCHED_MON|TR_SCHED_TUES|TR_SCHED_WED|TR_SCHED_THURS|TR_SCHED_FRI),
694    TR_SCHED_WEEKEND  = (TR_SCHED_SUN|TR_SCHED_SAT),
695    TR_SCHED_ALL      = (TR_SCHED_WEEKDAY|TR_SCHED_WEEKEND)
696}
697tr_sched_day;
698
699void     tr_sessionSetAltSpeedDay     ( tr_session *, tr_sched_day day );
700tr_sched_day tr_sessionGetAltSpeedDay ( const tr_session * );
701
702typedef void ( tr_altSpeedFunc )      ( tr_session *, tr_bool active, tr_bool userDriven, void * );
703void     tr_sessionClearAltSpeedFunc  ( tr_session * );
704void     tr_sessionSetAltSpeedFunc    ( tr_session *, tr_altSpeedFunc *, void * );
705
706
707tr_bool      tr_sessionGetActiveSpeedLimit( const tr_session  * session,
708                                            tr_direction        dir,
709                                            int               * setme );
710
711
712/***
713****
714***/
715
716double     tr_sessionGetRawSpeed      ( const tr_session *, tr_direction );
717double     tr_sessionGetPieceSpeed    ( const tr_session *, tr_direction );
718
719
720void       tr_sessionSetRatioLimited  ( tr_session *, tr_bool isLimited );
721tr_bool    tr_sessionIsRatioLimited   ( const tr_session * );
722
723void       tr_sessionSetRatioLimit    ( tr_session *, double desiredRatio );
724double     tr_sessionGetRatioLimit    ( const tr_session * );
725
726void       tr_sessionSetPeerLimit( tr_session *, uint16_t maxGlobalPeers );
727uint16_t   tr_sessionGetPeerLimit( const tr_session * );
728
729void       tr_sessionSetPeerLimitPerTorrent( tr_session *, uint16_t maxGlobalPeers );
730uint16_t   tr_sessionGetPeerLimitPerTorrent( const tr_session * );
731
732tr_priority_t   tr_torrentGetPriority( const tr_torrent * );
733void            tr_torrentSetPriority( tr_torrent *, tr_priority_t );
734
735void       tr_sessionSetPaused        ( tr_session *, tr_bool isPaused );
736tr_bool    tr_sessionGetPaused        ( const tr_session * );
737
738void       tr_sessionSetDeleteSource  ( tr_session *, tr_bool deleteSource );
739tr_bool    tr_sessionGetDeleteSource  ( const tr_session * );
740
741/**
742 *  Load all the torrents in tr_getTorrentDir().
743 *  This can be used at startup to kickstart all the torrents
744 *  from the previous session.
745 */
746tr_torrent ** tr_sessionLoadTorrents( tr_session  * session,
747                                      tr_ctor     * ctor,
748                                      int         * setmeCount );
749
750/**
751***
752**/
753
754tr_bool tr_sessionIsTorrentDoneScriptEnabled( const tr_session * );
755
756void tr_sessionSetTorrentDoneScriptEnabled( tr_session *, tr_bool isEnabled );
757
758const char * tr_sessionGetTorrentDoneScript( const tr_session * );
759
760void tr_sessionSetTorrentDoneScript( tr_session *, const char * scriptFilename );
761
762
763/** @} */
764
765/**
766***
767**/
768
769
770/***********************************************************************
771** Message Logging
772*/
773
774enum
775{
776    TR_MSG_ERR = 1,
777    TR_MSG_INF = 2,
778    TR_MSG_DBG = 3
779};
780void tr_setMessageLevel( int );
781
782int  tr_getMessageLevel( void );
783
784typedef struct tr_msg_list
785{
786    /* TR_MSG_ERR, TR_MSG_INF, or TR_MSG_DBG */
787    uint8_t level;
788
789    /* The line number in the source file where this message originated */
790    int line;
791
792    /* Time the message was generated */
793    time_t when;
794
795    /* The torrent associated with this message,
796     * or a module name such as "Port Forwarding" for non-torrent messages,
797     * or NULL. */
798    char *  name;
799
800    /* The message */
801    char *  message;
802
803    /* The source file where this message originated */
804    const char * file;
805
806    /* linked list of messages */
807    struct tr_msg_list * next;
808}
809tr_msg_list;
810
811void          tr_setMessageQueuing( tr_bool isEnabled );
812
813tr_bool       tr_getMessageQueuing( void );
814
815tr_msg_list * tr_getQueuedMessages( void );
816
817void          tr_freeMessageList( tr_msg_list * freeme );
818
819/** @addtogroup Blocklists
820    @{ */
821
822/**
823 * Specify a range of IPs for Transmission to block.
824 *
825 * filename must be an uncompressed ascii file,
826 * using the same format as the bluetack level1 file.
827 *
828 * libtransmission does not keep a handle to `filename'
829 * after this call returns, so the caller is free to
830 * keep or delete `filename' as it wishes.
831 * libtransmission makes its own copy of the file
832 * massaged into a format easier to search.
833 *
834 * The caller only needs to invoke this when the blocklist
835 * has changed.
836 *
837 * Passing NULL for a filename will clear the blocklist.
838 */
839int     tr_blocklistSetContent   ( tr_session       * session,
840                                   const char       * filename );
841
842int     tr_blocklistGetRuleCount ( const tr_session * session );
843
844tr_bool tr_blocklistExists       ( const tr_session * session );
845
846tr_bool tr_blocklistIsEnabled    ( const tr_session * session );
847
848void    tr_blocklistSetEnabled   ( tr_session       * session,
849                                   tr_bool            isEnabled );
850
851
852/** @} */
853
854
855/** @addtogroup tr_ctor Torrent Constructors
856    @{
857
858    Instantiating a tr_torrent had gotten more complicated as features were
859    added.  At one point there were four functions to check metainfo and five
860    to create tr_torrent.
861
862    To remedy this, a Torrent Constructor (struct tr_ctor) has been introduced:
863    - Simplifies the API to two functions: tr_torrentParse() and tr_torrentNew()
864    - You can set the fields you want; the system sets defaults for the rest.
865    - You can specify whether or not your fields should supercede resume's.
866    - We can add new features to tr_ctor without breaking tr_torrentNew()'s API.
867
868    All the tr_ctor{Get,Set}*() functions with a return value return
869    an error number, or zero if no error occurred.
870
871    You must call one of the SetMetainfo() functions before creating
872    a torrent with a tr_ctor.  The other functions are optional.
873
874    You can reuse a single tr_ctor to create a batch of torrents --
875    just call one of the SetMetainfo() functions between each
876    tr_torrentNew() call.
877
878    Every call to tr_ctorSetMetainfo*() frees the previous metainfo.
879 */
880
881typedef enum
882{
883    TR_FALLBACK, /* indicates the ctor value should be used only
884                    in case of missing resume settings */
885
886    TR_FORCE, /* indicates the ctor value should be used
887                 regardless of what's in the resume settings */
888}
889tr_ctorMode;
890
891struct tr_benc;
892
893/** @brief Create a new torrent constructor object used to instantiate a tr_torrent
894    @param session the tr_session.  NULL is allowed if you're only calling tr_torrentParse() rather than tr_torrentNew()
895    @see tr_torrentNew(), tr_torrentParse() */
896tr_ctor* tr_ctorNew( const tr_session * session_or_NULL );
897
898/** @brief Free a torrent constructor object */
899void  tr_ctorFree( tr_ctor * ctor );
900
901/** @brief Set whether or not to delete the source .torrent file when a torrent is added. (Default: False) */
902void  tr_ctorSetDeleteSource( tr_ctor * ctor, tr_bool doDelete );
903
904/** @brief Set the constructor's metainfo from a magnet link */
905int tr_ctorSetMetainfoFromMagnetLink( tr_ctor * ctor, const char * magnet_link );
906
907/** @brief Set the constructor's metainfo from a raw benc already in memory */
908int tr_ctorSetMetainfo( tr_ctor * ctor, const uint8_t * metainfo, size_t len );
909
910/** @brief Set the constructor's metainfo from a local .torrent file */
911int tr_ctorSetMetainfoFromFile( tr_ctor * ctor, const char * filename );
912
913/**
914 * @brief Set the constructor's metainfo from an already-existing file in tr_getTorrentDir().
915 *
916 * This is used by the mac client on startup to pick and choose which existing torrents to load
917 */
918int tr_ctorSetMetainfoFromHash( tr_ctor * ctor, const char * hashString );
919
920/** @brief Set the maximum number of peers this torrent can connect to. (Default: 50) */
921void tr_ctorSetPeerLimit( tr_ctor * ctor, tr_ctorMode mode, uint16_t peerLimit  );
922
923/** @brief Set the download folder for the torrent being added with this ctor.
924    @see tr_ctorSetDownloadDir()
925    @see tr_sessionInit() */
926void        tr_ctorSetDownloadDir( tr_ctor *    ctor,
927                                   tr_ctorMode  mode,
928                                   const char * directory );
929
930/**
931 * @brief Set the incompleteDir for this torrent.
932 *
933 * This is not a supported API call.
934 * It only exists so the mac client can migrate
935 * its older incompleteDir settings, and that's
936 * the only place where it should be used.
937 */
938void tr_ctorSetIncompleteDir( tr_ctor * ctor, const char * directory );
939
940/** Set whether or not the torrent begins downloading/seeding when created.
941    (Default: not paused) */
942void        tr_ctorSetPaused( tr_ctor      * ctor,
943                              tr_ctorMode    mode,
944                              tr_bool        isPaused );
945
946/** @brief Set the priorities for files in a torrent */
947void        tr_ctorSetFilePriorities( tr_ctor                * ctor,
948                                      const tr_file_index_t  * files,
949                                      tr_file_index_t          fileCount,
950                                      tr_priority_t            priority );
951
952/** @brief Set the download flag for files in a torrent */
953void        tr_ctorSetFilesWanted( tr_ctor                * ctor,
954                                   const tr_file_index_t  * fileIndices,
955                                   tr_file_index_t          fileCount,
956                                   tr_bool                  wanted );
957
958
959/** @brief Get this peer constructor's peer limit */
960int         tr_ctorGetPeerLimit( const tr_ctor * ctor,
961                                 tr_ctorMode     mode,
962                                 uint16_t *      setmeCount );
963
964/** @brief Get the "isPaused" flag from this peer constructor */
965int         tr_ctorGetPaused( const tr_ctor * ctor,
966                              tr_ctorMode     mode,
967                              tr_bool       * setmeIsPaused );
968
969/** @brief Get the download path from this peer constructor */
970int         tr_ctorGetDownloadDir( const tr_ctor  * ctor,
971                                   tr_ctorMode      mode,
972                                   const char    ** setmeDownloadDir );
973
974/** @brief Get the incomplete directory from this peer constructor */
975int         tr_ctorGetIncompleteDir( const tr_ctor  * ctor,
976                                     const char    ** setmeIncompleteDir );
977
978/** @brief Get the metainfo from this peer constructor */
979int         tr_ctorGetMetainfo( const tr_ctor         * ctor,
980                                const struct tr_benc ** setme );
981
982/** @brief Get the "delete .torrent file" flag from this peer constructor */
983int         tr_ctorGetDeleteSource( const tr_ctor  * ctor,
984                                    tr_bool        * setmeDoDelete );
985
986/** @brief Get the tr_session poiner from this peer constructor */
987tr_session* tr_ctorGetSession( const tr_ctor * ctor );
988
989/** @brief Get the .torrent file that this ctor's metainfo came from, or NULL if tr_ctorSetMetainfoFromFile() wasn't used */
990const char* tr_ctorGetSourceFile( const tr_ctor * ctor );
991
992typedef enum
993{
994    TR_PARSE_OK,
995    TR_PARSE_ERR,
996    TR_PARSE_DUPLICATE
997}
998tr_parse_result;
999
1000/**
1001 * @brief Parses the specified metainfo
1002 *
1003 * @return TR_PARSE_ERR if parsing failed;
1004 *         TR_PARSE_OK if parsing succeeded and it's not a duplicate;
1005 *         TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
1006 *
1007 * @param setme_info If parsing is successful and setme_info is non-NULL,
1008 *                   the parsed metainfo is stored there and sould be freed
1009 *                   by calling tr_metainfoFree() when no longer needed.
1010 *
1011 * Notes:
1012 *
1013 * 1. tr_torrentParse() won't be able to check for duplicates -- and therefore
1014 *    won't return TR_PARSE_DUPLICATE -- unless ctor's "download-dir" and
1015 *    session variable is set.
1016 *
1017 * 2. setme_info->torrent's value can't be set unless ctor's session variable
1018 *    is set.
1019 */
1020tr_parse_result  tr_torrentParse( const tr_ctor  * ctor,
1021                                  tr_info        * setme_info_or_NULL );
1022
1023/** @brief free a metainfo
1024    @see tr_torrentParse */
1025void tr_metainfoFree( tr_info * inf );
1026
1027
1028/** Instantiate a single torrent.
1029    @return 0 on success,
1030            TR_EINVALID if the torrent couldn't be parsed, or
1031            TR_EDUPLICATE if there's already a matching torrent object. */
1032tr_torrent * tr_torrentNew( const tr_ctor   * ctor,
1033                            int             * setmeError );
1034
1035/** @} */
1036
1037/***********************************************************************
1038 ***
1039 ***  TORRENTS
1040 **/
1041
1042/** @addtogroup tr_torrent Torrents
1043    @{ */
1044
1045/** @brief Frees memory allocated by tr_torrentNew().
1046           Running torrents are stopped first.  */
1047void tr_torrentFree( tr_torrent * torrent );
1048
1049/** @brief Removes our .torrent and .resume files for
1050           this torrent, then calls tr_torrentFree(). */
1051void tr_torrentRemove( tr_torrent * torrent );
1052
1053/** @brief Start a torrent */
1054void tr_torrentStart( tr_torrent * torrent );
1055
1056/** @brief Stop (pause) a torrent */
1057void tr_torrentStop( tr_torrent * torrent );
1058
1059enum
1060{
1061    TR_LOC_MOVING,
1062    TR_LOC_DONE,
1063    TR_LOC_ERROR
1064};
1065
1066/**
1067 * @brief Tell transmsision where to find this torrent's local data.
1068 *
1069 * if move_from_previous_location is `true', the torrent's incompleteDir
1070 * will be clobberred s.t. additional files being added will be saved
1071 * to the torrent's downloadDir.
1072 */
1073void tr_torrentSetLocation( tr_torrent  * torrent,
1074                            const char  * location,
1075                            tr_bool       move_from_previous_location,
1076                            double      * setme_progress,
1077                            int         * setme_state );
1078
1079typedef int tr_fileFunc( const char * filename );
1080
1081/**
1082 * @brief Deletes the torrent's local data.
1083 * @param torrent
1084 * @param fileFunc Pass in "unlink" to destroy the files or, on platforms with
1085 *                 recycle bins, pass in a function that uses it instead.
1086 *                 tr_torrentDeleteLocalData() ignores fileFunc's return value.
1087 */
1088void tr_torrentDeleteLocalData( tr_torrent * torrent, tr_fileFunc fileFunc );
1089
1090uint64_t tr_torrentGetBytesLeftToAllocate( const tr_torrent * torrent );
1091
1092/**
1093 * @brief Returns this torrent's unique ID.
1094 *
1095 * IDs are good as simple lookup keys, but are not persistent
1096 * between sessions.  If you need that, use tr_info.hash or
1097 * tr_info.hashString.
1098 */
1099int tr_torrentId( const tr_torrent * torrent );
1100
1101tr_torrent* tr_torrentFindFromId( tr_session * session, int id );
1102
1103tr_torrent* tr_torrentFindFromHash( tr_session * session, const uint8_t * hash );
1104
1105/** @brief Convenience function similar to tr_torrentFindFromHash() */
1106tr_torrent* tr_torrentFindFromMagnetLink( tr_session * session, const char * link );
1107
1108
1109/**
1110 * @brief find the location of a torrent's file by looking with and without
1111 *        the ".part" suffix, looking in downloadDir and incompleteDir, etc.
1112 * @return a newly-allocated string (that must be tr_freed() by the caller when done)
1113 *         that gives the location of this file on disk, or NULL if no file exists yet.
1114 * @param tor the torrent whose file we're looking for
1115 * @param fileNum the fileIndex, in [0...tr_info.fileCount)
1116 */
1117char* tr_torrentFindFile( const tr_torrent * tor, tr_file_index_t fileNo );
1118
1119
1120/***
1121****  Torrent speed limits
1122****
1123***/
1124
1125void     tr_torrentSetSpeedLimit      ( tr_torrent *, tr_direction, int KB_s );
1126int      tr_torrentGetSpeedLimit      ( const tr_torrent *, tr_direction );
1127
1128void     tr_torrentUseSpeedLimit      ( tr_torrent *, tr_direction, tr_bool );
1129tr_bool  tr_torrentUsesSpeedLimit     ( const tr_torrent *, tr_direction );
1130
1131void     tr_torrentUseSessionLimits   ( tr_torrent *, tr_bool );
1132tr_bool  tr_torrentUsesSessionLimits  ( const tr_torrent * );
1133
1134
1135/****
1136*****  Ratio Limits
1137****/
1138
1139typedef enum
1140{
1141    TR_RATIOLIMIT_GLOBAL    = 0, /* follow the global settings */
1142    TR_RATIOLIMIT_SINGLE    = 1, /* override the global settings, seeding until a certain ratio */
1143    TR_RATIOLIMIT_UNLIMITED = 2  /* override the global settings, seeding regardless of ratio */
1144}
1145tr_ratiolimit;
1146
1147void          tr_torrentSetRatioMode( tr_torrent         * tor,
1148                                      tr_ratiolimit        mode );
1149
1150tr_ratiolimit tr_torrentGetRatioMode( const tr_torrent   * tor );
1151
1152void          tr_torrentSetRatioLimit( tr_torrent        * tor,
1153                                       double              ratio );
1154
1155double        tr_torrentGetRatioLimit( const tr_torrent  * tor );
1156
1157
1158tr_bool       tr_torrentGetSeedRatio( const tr_torrent *, double * ratio );
1159
1160/****
1161*****  Peer Limits
1162****/
1163
1164void          tr_torrentSetPeerLimit( tr_torrent * tor,
1165                                      uint16_t     peerLimit );
1166
1167uint16_t      tr_torrentGetPeerLimit( const tr_torrent * tor );
1168
1169/****
1170*****  File Priorities
1171****/
1172
1173enum
1174{
1175    TR_PRI_LOW    = -1,
1176    TR_PRI_NORMAL =  0, /* since NORMAL is 0, memset initializes nicely */
1177    TR_PRI_HIGH   =  1
1178};
1179
1180/**
1181 * @brief Set a batch of files to a particular priority.
1182 *
1183 * @param priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW
1184 */
1185void tr_torrentSetFilePriorities( tr_torrent             * torrent,
1186                                  const tr_file_index_t  * files,
1187                                  tr_file_index_t          fileCount,
1188                                  tr_priority_t            priority );
1189
1190/**
1191 * @brief Get this torrent's file priorities.
1192 *
1193 * @return A malloc()ed array of tor->info.fileCount items,
1194 *         each holding a TR_PRI_NORMAL, TR_PRI_HIGH, or TR_PRI_LOW.
1195 *         It's the caller's responsibility to free() this.
1196 */
1197tr_priority_t*  tr_torrentGetFilePriorities( const tr_torrent * torrent );
1198
1199/** @brief Set a batch of files to be downloaded or not. */
1200void tr_torrentSetFileDLs( tr_torrent             * torrent,
1201                           const tr_file_index_t  * files,
1202                           tr_file_index_t          fileCount,
1203                           tr_bool                  do_download );
1204
1205
1206const tr_info * tr_torrentInfo( const tr_torrent * torrent );
1207
1208/* Raw function to change the torrent's downloadDir field.
1209   This should only be used by libtransmission or to bootstrap
1210   a newly-instantiated tr_torrent object. */
1211void tr_torrentSetDownloadDir( tr_torrent  * torrent, const char * path );
1212
1213const char * tr_torrentGetDownloadDir( const tr_torrent * torrent );
1214
1215/**
1216 * Returns the root directory of where the torrent is.
1217 *
1218 * This will usually be the downloadDir.  However if the torrent
1219 * has an incompleteDir enabled and hasn't finished downloading
1220 * yet, that will be returned instead.
1221 */
1222const char * tr_torrentGetCurrentDir( const tr_torrent * tor );
1223
1224
1225/**
1226 * Returns a newly-allocated string with a magnet link of the torrent.
1227 * Use tr_free() to free the string when done.
1228 */
1229char* tr_torrentGetMagnetLink( const tr_torrent * tor );
1230
1231/**
1232***
1233**/
1234
1235
1236/** @brief a part of tr_info that represents a single tracker */
1237typedef struct tr_tracker_info
1238{
1239    int      tier;
1240    char *   announce;
1241    char *   scrape;
1242    uint32_t id; /* unique identifier used to match to a tr_tracker_stat */
1243}
1244tr_tracker_info;
1245
1246/**
1247 * @brief Modify a torrent's tracker list.
1248 *
1249 * This updates both the `torrent' object's tracker list
1250 * and the metainfo file in tr_sessionGetConfigDir()'s torrent subdirectory.
1251 *
1252 * @param torrent The torrent whose tracker list is to be modified
1253 * @param trackers An array of trackers, sorted by tier from first to last.
1254 *                 NOTE: only the `tier' and `announce' fields are used.
1255 *                 libtransmission derives `scrape' from `announce'
1256 *                 and reassigns 'id'.
1257 * @param trackerCount size of the `trackers' array
1258 */
1259tr_bool
1260tr_torrentSetAnnounceList( tr_torrent             * torrent,
1261                           const tr_tracker_info  * trackers,
1262                           int                      trackerCount );
1263
1264
1265/**
1266***
1267**/
1268
1269typedef enum
1270{
1271    TR_LEECH,           /* doesn't have all the desired pieces */
1272    TR_SEED,            /* has the entire torrent */
1273    TR_PARTIAL_SEED     /* has the desired pieces, but not the entire torrent */
1274}
1275tr_completeness;
1276
1277/**
1278 * @param wasRunning whether or not the torrent was running when
1279 *                   it changed its completeness state
1280 */
1281typedef void ( tr_torrent_completeness_func )( tr_torrent       * torrent,
1282                                               tr_completeness    completeness,
1283                                               tr_bool            wasRunning,
1284                                               void             * user_data );
1285
1286typedef void ( tr_torrent_ratio_limit_hit_func )( tr_torrent   * torrent,
1287                                                  void         * user_data );
1288
1289/**
1290 * Register to be notified whenever a torrent's "completeness"
1291 * changes.  This will be called, for example, when a torrent
1292 * finishes downloading and changes from TR_LEECH to
1293 * either TR_SEED or TR_PARTIAL_SEED.
1294 *
1295 * func is invoked FROM LIBTRANSMISSION'S THREAD!
1296 * This means func must be fast (to avoid blocking peers),
1297 * shouldn't call libtransmission functions (to avoid deadlock),
1298 * and shouldn't modify client-level memory without using a mutex!
1299 *
1300 * @see tr_completeness
1301 */
1302void tr_torrentSetCompletenessCallback(
1303         tr_torrent                    * torrent,
1304         tr_torrent_completeness_func    func,
1305         void                          * user_data );
1306
1307void tr_torrentClearCompletenessCallback( tr_torrent * torrent );
1308
1309
1310
1311typedef void ( tr_torrent_metadata_func )( tr_torrent  * torrent,
1312                                           void        * user_data );
1313/**
1314 * Register to be notified whenever a torrent changes from
1315 * having incomplete metadata to having complete metadata.
1316 * This happens when a magnet link finishes downloading
1317 * metadata from its peers.
1318 */
1319void tr_torrentSetMetadataCallback (
1320         tr_torrent                * tor,
1321         tr_torrent_metadata_func     func,
1322         void                      * user_data );
1323
1324/**
1325 * Register to be notified whenever a torrent's ratio limit
1326 * has been hit. This will be called when the torrent's
1327 * ul/dl ratio has met or exceeded the designated ratio limit.
1328 *
1329 * Has the same restrictions as tr_torrentSetCompletenessCallback
1330 */
1331void tr_torrentSetRatioLimitHitCallback(
1332     tr_torrent                     * torrent,
1333     tr_torrent_ratio_limit_hit_func  func,
1334     void                           * user_data );
1335
1336void tr_torrentClearRatioLimitHitCallback( tr_torrent * torrent );
1337
1338
1339/**
1340 * MANUAL ANNOUNCE
1341 *
1342 * Trackers usually set an announce interval of 15 or 30 minutes.
1343 * Users can send one-time announce requests that override this
1344 * interval by calling tr_torrentManualUpdate().
1345 *
1346 * The wait interval for tr_torrentManualUpdate() is much smaller.
1347 * You can test whether or not a manual update is possible
1348 * (for example, to desensitize the button) by calling
1349 * tr_torrentCanManualUpdate().
1350 */
1351
1352void tr_torrentManualUpdate( tr_torrent * torrent );
1353
1354tr_bool tr_torrentCanManualUpdate( const tr_torrent * torrent );
1355
1356/***
1357****  tr_peer_stat
1358***/
1359
1360typedef struct tr_peer_stat
1361{
1362    tr_bool  isEncrypted;
1363    tr_bool  isDownloadingFrom;
1364    tr_bool  isUploadingTo;
1365    tr_bool  isSeed;
1366
1367    tr_bool  peerIsChoked;
1368    tr_bool  peerIsInterested;
1369    tr_bool  clientIsChoked;
1370    tr_bool  clientIsInterested;
1371    tr_bool  isIncoming;
1372
1373    uint8_t  from;
1374    tr_port  port;
1375
1376    char     addr[TR_INET6_ADDRSTRLEN];
1377    char     client[80];
1378    char     flagStr[32];
1379
1380    float    progress;
1381    float    rateToPeer;
1382    float    rateToClient;
1383
1384
1385/***
1386****  THESE NEXT FOUR FIELDS ARE EXPERIMENTAL.
1387****  They're currently being used in the GTK+ client to help tune the new download congestion code
1388****  and probably won't make the cut for 2.0.
1389***/
1390    /* how many blocks we've sent to this peer in the last 120 seconds */
1391    uint32_t  blocksToPeer;
1392    /* how many blocks this client's sent to us in the last 120 seconds */
1393    uint32_t  blocksToClient;
1394    /* how many requests to this peer that we've cancelled in the last 120 seconds */
1395    uint32_t  cancelsToPeer;
1396    /* how many requests this peer made of us, then cancelled, in the last 120 seconds */
1397    uint32_t  cancelsToClient;
1398
1399    /* how many requests the peer has made that we haven't responded to yet */
1400    int      pendingReqsToClient;
1401
1402    /* how many requests we've made and are currently awaiting a response for */
1403    int      pendingReqsToPeer;
1404}
1405tr_peer_stat;
1406
1407tr_peer_stat * tr_torrentPeers( const tr_torrent * torrent,
1408                                int *              peerCount );
1409
1410void           tr_torrentPeersFree( tr_peer_stat * peerStats,
1411                                    int            peerCount );
1412
1413/***
1414****  tr_tracker_stat
1415***/
1416
1417typedef enum
1418{
1419    /* we won't (announce,scrape) this torrent to this tracker because
1420     * the torrent is stopped, or because of an error, or whatever */
1421    TR_TRACKER_INACTIVE,
1422
1423    /* we will (announce,scrape) this torrent to this tracker, and are
1424     * waiting for enough time to pass to satisfy the tracker's interval */
1425    TR_TRACKER_WAITING,
1426
1427    /* it's time to (announce,scrape) this torrent, and we're waiting on a
1428     * a free slot to open up in the announce manager */
1429    TR_TRACKER_QUEUED,
1430
1431    /* we're (announcing,scraping) this torrent right now */
1432    TR_TRACKER_ACTIVE
1433}
1434tr_tracker_state;
1435
1436typedef struct
1437{
1438    /* how many downloads this tracker knows of (-1 means it does not know) */
1439    int downloadCount;
1440
1441    /* whether or not we've ever sent this tracker an announcement */
1442    tr_bool hasAnnounced;
1443
1444    /* whether or not we've ever scraped to this tracker */
1445    tr_bool hasScraped;
1446
1447    /* ex: http://www.legaltorrents.com:7070 */
1448    char host[1024];
1449
1450    /* the full announce URL */
1451    char announce[1024];
1452
1453    /* Transmission uses one tracker per tier,
1454     * and the others are kept as backups */
1455    tr_bool isBackup;
1456
1457    /* is the tracker announcing, waiting, queued, etc */
1458    tr_tracker_state announceState;
1459
1460    /* is the tracker scraping, waiting, queued, etc */
1461    tr_tracker_state scrapeState;
1462
1463    /* number of peers the tracker told us about last time.
1464     * if "lastAnnounceSucceeded" is false, this field is undefined */
1465    int lastAnnouncePeerCount;
1466
1467    /* human-readable string with the result of the last announce.
1468       if "hasAnnounced" is false, this field is undefined */
1469    char lastAnnounceResult[128];
1470
1471    /* when the last announce was sent to the tracker.
1472     * if "hasAnnounced" is false, this field is undefined */
1473    time_t lastAnnounceStartTime;
1474
1475    /* whether or not the last announce was a success.
1476       if "hasAnnounced" is false, this field is undefined */
1477    tr_bool lastAnnounceSucceeded;
1478
1479    /* whether or not the last announce timed out. */
1480    tr_bool lastAnnounceTimedOut;
1481
1482    /* when the last announce was completed.
1483       if "hasAnnounced" is false, this field is undefined */
1484    time_t lastAnnounceTime;
1485
1486    /* human-readable string with the result of the last scrape.
1487     * if "hasScraped" is false, this field is undefined */
1488    char lastScrapeResult[128];
1489
1490    /* when the last scrape was sent to the tracker.
1491     * if "hasScraped" is false, this field is undefined */
1492    time_t lastScrapeStartTime;
1493
1494    /* whether or not the last scrape was a success.
1495       if "hasAnnounced" is false, this field is undefined */
1496    tr_bool lastScrapeSucceeded;
1497
1498    /* whether or not the last scrape timed out. */
1499    tr_bool lastScrapeTimedOut;
1500
1501    /* when the last scrape was completed.
1502       if "hasScraped" is false, this field is undefined */
1503    time_t lastScrapeTime;
1504
1505    /* number of leechers this tracker knows of (-1 means it does not know) */
1506    int leecherCount;
1507
1508    /* when the next periodic announce message will be sent out.
1509       if announceState isn't TR_TRACKER_WAITING, this field is undefined */
1510    time_t nextAnnounceTime;
1511
1512    /* when the next periodic scrape message will be sent out.
1513       if scrapeState isn't TR_TRACKER_WAITING, this field is undefined */
1514    time_t nextScrapeTime;
1515
1516    /* number of seeders this tracker knows of (-1 means it does not know) */
1517    int seederCount;
1518
1519    /* which tier this tracker is in */
1520    int tier;
1521
1522    /* used to match to a tr_tracker_info */
1523    uint32_t id;
1524}
1525tr_tracker_stat;
1526
1527tr_tracker_stat * tr_torrentTrackers( const tr_torrent * torrent,
1528                                      int              * setmeTrackerCount );
1529
1530void tr_torrentTrackersFree( tr_tracker_stat * trackerStats,
1531                             int               trackerCount );
1532
1533
1534
1535/**
1536 * @brief get the download speeds for each of this torrent's webseed sources.
1537 *
1538 * @return an array of tor->info.webseedCount floats giving download speeds.
1539 *         Each speed in the array corresponds to the webseed at the same
1540 *         array index in tor->info.webseeds.
1541 *         To differentiate "idle" and "stalled" status, idle webseeds will
1542 *         return -1 instead of 0 KiB/s.
1543 *         NOTE: always free this array with tr_free() when you're done with it.
1544 */
1545float*         tr_torrentWebSpeeds( const tr_torrent * torrent );
1546
1547typedef struct tr_file_stat
1548{
1549    uint64_t    bytesCompleted;
1550    float       progress;
1551}
1552tr_file_stat;
1553
1554tr_file_stat * tr_torrentFiles( const tr_torrent  * torrent,
1555                                tr_file_index_t   * fileCount );
1556
1557void tr_torrentFilesFree( tr_file_stat     * files,
1558                          tr_file_index_t    fileCount );
1559
1560
1561/***********************************************************************
1562 * tr_torrentAvailability
1563 ***********************************************************************
1564 * Use this to draw an advanced progress bar which is 'size' pixels
1565 * wide. Fills 'tab' which you must have allocated: each byte is set
1566 * to either -1 if we have the piece, otherwise it is set to the number
1567 * of connected peers who have the piece.
1568 **********************************************************************/
1569void tr_torrentAvailability( const tr_torrent  * torrent,
1570                             int8_t            * tab,
1571                             int                  size );
1572
1573void tr_torrentAmountFinished( const tr_torrent  * torrent,
1574                               float *             tab,
1575                               int                 size );
1576
1577void tr_torrentVerify( tr_torrent * torrent );
1578
1579/***********************************************************************
1580 * tr_info
1581 **********************************************************************/
1582
1583/** @brief a part of tr_info that represents a single file of the torrent's content */
1584typedef struct tr_file
1585{
1586    uint64_t            length;    /* Length of the file, in bytes */
1587    char *              name;      /* Path to the file */
1588    int8_t              priority;  /* TR_PRI_HIGH, _NORMAL, or _LOW */
1589    int8_t              dnd;       /* nonzero if the file shouldn't be
1590                                     downloaded */
1591    tr_piece_index_t    firstPiece; /* We need pieces [firstPiece... */
1592    tr_piece_index_t    lastPiece; /* ...lastPiece] to dl this file */
1593    uint64_t            offset;    /* file begins at the torrent's nth byte */
1594}
1595tr_file;
1596
1597/** @brief a part of tr_info that represents a single piece of the torrent's content */
1598typedef struct tr_piece
1599{
1600    uint8_t    hash[SHA_DIGEST_LENGTH]; /* pieces hash */
1601    int8_t     priority;               /* TR_PRI_HIGH, _NORMAL, or _LOW */
1602    int8_t     dnd;                    /* nonzero if the piece shouldn't be
1603                                         downloaded */
1604}
1605tr_piece;
1606
1607/** @brief information about a torrent that comes from its metainfo file */
1608struct tr_info
1609{
1610    /* total size of the torrent, in bytes */
1611    uint64_t           totalSize;
1612
1613    /* the torrent's name */
1614    char             * name;
1615
1616    /* Path to torrent Transmission's internal copy of the .torrent file. */
1617    char             * torrent;
1618
1619    char            ** webseeds;
1620
1621    char             * comment;
1622    char             * creator;
1623    tr_file          * files;
1624    tr_piece         * pieces;
1625
1626    /* these trackers are sorted by tier */
1627    tr_tracker_info  * trackers;
1628
1629    /* Torrent info */
1630    time_t             dateCreated;
1631
1632    int                trackerCount;
1633    int                webseedCount;
1634    tr_file_index_t    fileCount;
1635    uint32_t           pieceSize;
1636    tr_piece_index_t   pieceCount;
1637
1638    /* General info */
1639    uint8_t            hash[SHA_DIGEST_LENGTH];
1640    char               hashString[2 * SHA_DIGEST_LENGTH + 1];
1641
1642    /* hash, escaped as per rfc2396 for tracker announces */
1643    char               hashEscaped[3 * SHA_DIGEST_LENGTH + 1];
1644
1645    /* Flags */
1646    tr_bool            isPrivate;
1647    tr_bool            isMultifile;
1648};
1649
1650static inline tr_bool tr_torrentHasMetadata( const tr_torrent * tor )
1651{
1652    return tr_torrentInfo( tor )->fileCount > 0;
1653}
1654
1655/**
1656 * What the torrent is doing right now.
1657 *
1658 * Note: these values will become a straight enum at some point in the future.
1659 * Do not rely on their current `bitfield' implementation
1660 */
1661typedef enum
1662{
1663    TR_STATUS_CHECK_WAIT   = ( 1 << 0 ), /* Waiting in queue to check files */
1664    TR_STATUS_CHECK        = ( 1 << 1 ), /* Checking files */
1665    TR_STATUS_DOWNLOAD     = ( 1 << 2 ), /* Downloading */
1666    TR_STATUS_SEED         = ( 1 << 3 ), /* Seeding */
1667    TR_STATUS_STOPPED      = ( 1 << 4 )  /* Torrent is stopped */
1668}
1669tr_torrent_activity;
1670
1671enum
1672{
1673    TR_PEER_FROM_INCOMING  = 0, /* connections made to the listening port */
1674    TR_PEER_FROM_LPD,           /* peers found by local announcements */
1675    TR_PEER_FROM_TRACKER,       /* peers found from a tracker */
1676    TR_PEER_FROM_DHT,           /* peers found from the DHT */
1677    TR_PEER_FROM_PEX,           /* peers found from PEX */
1678    TR_PEER_FROM_RESUME,        /* peers found in the .resume file */
1679    TR_PEER_FROM_LTEP,          /* peer address provided in an LTEP handshake */
1680    TR_PEER_FROM__MAX
1681};
1682
1683typedef enum
1684{
1685    /* everything's fine */
1686    TR_STAT_OK               = 0,
1687
1688    /* when we anounced to the tracker, we got a warning in the response */
1689    TR_STAT_TRACKER_WARNING  = 1,
1690
1691    /* when we anounced to the tracker, we got an error in the response */
1692    TR_STAT_TRACKER_ERROR    = 2,
1693
1694    /* local trouble, such as disk full or permissions error */
1695    TR_STAT_LOCAL_ERROR      = 3
1696}
1697tr_stat_errtype;
1698
1699/** @brief Used by tr_torrentStat() to tell clients about a torrent's state and statistics */
1700typedef struct tr_stat
1701{
1702    /** The torrent's unique Id.
1703        @see tr_torrentId() */
1704    int    id;
1705
1706    /** What is this torrent doing right now? */
1707    tr_torrent_activity activity;
1708
1709    /** Defines what kind of text is in errorString.
1710        @see errorString */
1711    tr_stat_errtype error;
1712
1713    /** A warning or error message regarding the torrent.
1714        @see error */
1715    char errorString[128];
1716
1717    /** When tr_stat.status is TR_STATUS_CHECK or TR_STATUS_CHECK_WAIT,
1718        this is the percentage of how much of the files has been
1719        verified.  When it gets to 1, the verify process is done.
1720        Range is [0..1]
1721        @see tr_stat.status */
1722    float    recheckProgress;
1723
1724    /** How much has been downloaded of the entire torrent.
1725        Range is [0..1] */
1726    float    percentComplete;
1727
1728    /** How much of the metadata the torrent has.
1729        For torrents added from a .torrent this will always be 1.
1730        For magnet links, this number will from from 0 to 1 as the metadata is downloaded.
1731        Range is [0..1] */
1732    float    metadataPercentComplete;
1733
1734    /** How much has been downloaded of the files the user wants.  This differs
1735        from percentComplete if the user wants only some of the torrent's files.
1736        Range is [0..1]
1737        @see tr_stat.leftUntilDone */
1738    float    percentDone;
1739
1740    /** How much has been uploaded to satisfy the seed ratio.
1741        This is 1 if the ratio is reached or the torrent is set to seed forever.
1742        Range is [0..1] */
1743    float    seedRatioPercentDone;
1744
1745    /** Speed all data being sent for this torrent. (KiB/s)
1746        This includes piece data, protocol messages, and TCP overhead */
1747    double rawUploadSpeed;
1748
1749    /** Speed all data being received for this torrent. (KiB/s)
1750        This includes piece data, protocol messages, and TCP overhead */
1751    double rawDownloadSpeed;
1752
1753    /** Speed all piece being sent for this torrent. (KiB/s)
1754        This ONLY counts piece data. */
1755    double pieceUploadSpeed;
1756
1757    /** Speed all piece being received for this torrent. (KiB/s)
1758        This ONLY counts piece data. */
1759    double pieceDownloadSpeed;
1760
1761#define TR_ETA_NOT_AVAIL -1
1762#define TR_ETA_UNKNOWN -2
1763    /** If downloading, estimated number of seconds left until the torrent is done.
1764        If seeding, estimated number of seconds left until seed ratio is reached. */
1765    int    eta;
1766
1767    /** Number of peers that the tracker says this torrent has */
1768    int    peersKnown;
1769
1770    /** Number of peers that we're connected to */
1771    int    peersConnected;
1772
1773    /** How many peers we found out about from the tracker, or from pex,
1774        or from incoming connections, or from our resume file. */
1775    int    peersFrom[TR_PEER_FROM__MAX];
1776
1777    /** Number of peers that are sending data to us. */
1778    int    peersSendingToUs;
1779
1780    /** Number of peers that we're sending data to */
1781    int    peersGettingFromUs;
1782
1783    /** Number of webseeds that are sending data to us. */
1784    int    webseedsSendingToUs;
1785
1786    /** Byte count of all the piece data we'll have downloaded when we're done,
1787        whether or not we have it yet.  This may be less than tr_info.totalSize
1788        if only some of the torrent's files are wanted.
1789        [0...tr_info.totalSize] */
1790    uint64_t    sizeWhenDone;
1791
1792    /** Byte count of how much data is left to be downloaded until we've got
1793        all the pieces that we want.  [0...tr_info.sizeWhenDone] */
1794    uint64_t    leftUntilDone;
1795
1796    /** Byte count of all the piece data we want and don't have yet,
1797        but that a connected peer does have. [0...leftUntilDone] */
1798    uint64_t    desiredAvailable;
1799
1800    /** Byte count of all the corrupt data you've ever downloaded for
1801        this torrent.  If you're on a poisoned torrent, this number can
1802        grow very large. */
1803    uint64_t    corruptEver;
1804
1805    /** Byte count of all data you've ever uploaded for this torrent. */
1806    uint64_t    uploadedEver;
1807
1808    /** Byte count of all the non-corrupt data you've ever downloaded
1809        for this torrent.  If you deleted the files and downloaded a second
1810        time, this will be 2*totalSize.. */
1811    uint64_t    downloadedEver;
1812
1813    /** Byte count of all the checksum-verified data we have for this torrent.
1814      */
1815    uint64_t    haveValid;
1816
1817    /** Byte count of all the partial piece data we have for this torrent.
1818        As pieces become complete, this value may decrease as portions of it
1819        are moved to `corrupt' or `haveValid'. */
1820    uint64_t    haveUnchecked;
1821
1822    /** time when one or more of the torrent's trackers will
1823        allow you to manually ask for more peers,
1824        or 0 if you can't */
1825    time_t manualAnnounceTime;
1826
1827#define TR_RATIO_NA  -1
1828#define TR_RATIO_INF -2
1829    /** TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */
1830    float    ratio;
1831
1832    /** When the torrent was first added. */
1833    time_t    addedDate;
1834
1835    /** When the torrent finished downloading. */
1836    time_t    doneDate;
1837
1838    /** When the torrent was last started. */
1839    time_t    startDate;
1840
1841    /** The last time we uploaded or downloaded piece data on this torrent. */
1842    time_t    activityDate;
1843   
1844    /** A torrent is considered finished if it has met its seed ratio.
1845        As a result, only paused torrents can be finished. */
1846    tr_bool   finished;
1847}
1848tr_stat;
1849
1850/** Return a pointer to an tr_stat structure with updated information
1851    on the torrent.  This is typically called by the GUI clients every
1852    second or so to get a new snapshot of the torrent's status. */
1853const tr_stat * tr_torrentStat( tr_torrent * torrent );
1854
1855/** Like tr_torrentStat(), but only recalculates the statistics if it's
1856    been longer than a second since they were last calculated.  This can
1857    reduce the CPU load if you're calling tr_torrentStat() frequently. */
1858const tr_stat * tr_torrentStatCached( tr_torrent * torrent );
1859
1860/** @deprecated */
1861void tr_torrentSetAddedDate( tr_torrent * torrent,
1862                             time_t       addedDate );
1863
1864/** @deprecated */
1865void tr_torrentSetActivityDate( tr_torrent * torrent,
1866                                time_t       activityDate );
1867
1868/** @deprecated */
1869void tr_torrentSetDoneDate( tr_torrent * torrent, time_t doneDate );
1870
1871/** @} */
1872
1873/** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */
1874static inline tr_bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; }
1875
1876/** @brief Sanity checker to test that a bool is TRUE or FALSE */
1877static inline tr_bool tr_isBool( tr_bool b ) { return b==1 || b==0; }
1878
1879#ifdef __cplusplus
1880}
1881#endif
1882
1883#endif
Note: See TracBrowser for help on using the repository browser.