source: trunk/libtransmission/transmission.h @ 10798

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

(trunk) #1521 "memory cache to reduce disk IO" -- commit block-cache-rc1.diff to trunk for the nightlies.

  • Property svn:keywords set to Date Rev Author Id
File size: 64.6 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 10798 2010-06-19 14:25:11Z 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
1277typedef void ( tr_torrent_completeness_func )( tr_torrent       * torrent,
1278                                               tr_completeness    completeness,
1279                                               void             * user_data );
1280
1281typedef void ( tr_torrent_ratio_limit_hit_func )( tr_torrent   * torrent,
1282                                                  void         * user_data );
1283
1284/**
1285 * Register to be notified whenever a torrent's "completeness"
1286 * changes.  This will be called, for example, when a torrent
1287 * finishes downloading and changes from TR_LEECH to
1288 * either TR_SEED or TR_PARTIAL_SEED.
1289 *
1290 * func is invoked FROM LIBTRANSMISSION'S THREAD!
1291 * This means func must be fast (to avoid blocking peers),
1292 * shouldn't call libtransmission functions (to avoid deadlock),
1293 * and shouldn't modify client-level memory without using a mutex!
1294 *
1295 * @see tr_completeness
1296 */
1297void tr_torrentSetCompletenessCallback(
1298         tr_torrent                    * torrent,
1299         tr_torrent_completeness_func    func,
1300         void                          * user_data );
1301
1302void tr_torrentClearCompletenessCallback( tr_torrent * torrent );
1303
1304
1305
1306typedef void ( tr_torrent_metadata_func )( tr_torrent  * torrent,
1307                                           void        * user_data );
1308/**
1309 * Register to be notified whenever a torrent changes from
1310 * having incomplete metadata to having complete metadata.
1311 * This happens when a magnet link finishes downloading
1312 * metadata from its peers.
1313 */
1314void tr_torrentSetMetadataCallback (
1315         tr_torrent                * tor,
1316         tr_torrent_metadata_func     func,
1317         void                      * user_data );
1318
1319/**
1320 * Register to be notified whenever a torrent's ratio limit
1321 * has been hit. This will be called when the torrent's
1322 * ul/dl ratio has met or exceeded the designated ratio limit.
1323 *
1324 * Has the same restrictions as tr_torrentSetCompletenessCallback
1325 */
1326void tr_torrentSetRatioLimitHitCallback(
1327     tr_torrent                     * torrent,
1328     tr_torrent_ratio_limit_hit_func  func,
1329     void                           * user_data );
1330
1331void tr_torrentClearRatioLimitHitCallback( tr_torrent * torrent );
1332
1333
1334/**
1335 * MANUAL ANNOUNCE
1336 *
1337 * Trackers usually set an announce interval of 15 or 30 minutes.
1338 * Users can send one-time announce requests that override this
1339 * interval by calling tr_torrentManualUpdate().
1340 *
1341 * The wait interval for tr_torrentManualUpdate() is much smaller.
1342 * You can test whether or not a manual update is possible
1343 * (for example, to desensitize the button) by calling
1344 * tr_torrentCanManualUpdate().
1345 */
1346
1347void tr_torrentManualUpdate( tr_torrent * torrent );
1348
1349tr_bool tr_torrentCanManualUpdate( const tr_torrent * torrent );
1350
1351/***
1352****  tr_peer_stat
1353***/
1354
1355typedef struct tr_peer_stat
1356{
1357    tr_bool  isEncrypted;
1358    tr_bool  isDownloadingFrom;
1359    tr_bool  isUploadingTo;
1360    tr_bool  isSeed;
1361
1362    tr_bool  peerIsChoked;
1363    tr_bool  peerIsInterested;
1364    tr_bool  clientIsChoked;
1365    tr_bool  clientIsInterested;
1366    tr_bool  isIncoming;
1367
1368    uint8_t  from;
1369    tr_port  port;
1370
1371    char     addr[TR_INET6_ADDRSTRLEN];
1372    char     client[80];
1373    char     flagStr[32];
1374
1375    float    progress;
1376    float    rateToPeer;
1377    float    rateToClient;
1378
1379
1380/***
1381****  THESE NEXT FOUR FIELDS ARE EXPERIMENTAL.
1382****  They're currently being used in the GTK+ client to help tune the new download congestion code
1383****  and probably won't make the cut for 2.0.
1384***/
1385    /* how many blocks we've sent to this peer in the last 120 seconds */
1386    uint32_t  blocksToPeer;
1387    /* how many blocks this client's sent to us in the last 120 seconds */
1388    uint32_t  blocksToClient;
1389    /* how many requests to this peer that we've cancelled in the last 120 seconds */
1390    uint32_t  cancelsToPeer;
1391    /* how many requests this peer made of us, then cancelled, in the last 120 seconds */
1392    uint32_t  cancelsToClient;
1393
1394    /* how many requests the peer has made that we haven't responded to yet */
1395    int      pendingReqsToClient;
1396
1397    /* how many requests we've made and are currently awaiting a response for */
1398    int      pendingReqsToPeer;
1399}
1400tr_peer_stat;
1401
1402tr_peer_stat * tr_torrentPeers( const tr_torrent * torrent,
1403                                int *              peerCount );
1404
1405void           tr_torrentPeersFree( tr_peer_stat * peerStats,
1406                                    int            peerCount );
1407
1408/***
1409****  tr_tracker_stat
1410***/
1411
1412typedef enum
1413{
1414    /* we won't (announce,scrape) this torrent to this tracker because
1415     * the torrent is stopped, or because of an error, or whatever */
1416    TR_TRACKER_INACTIVE,
1417
1418    /* we will (announce,scrape) this torrent to this tracker, and are
1419     * waiting for enough time to pass to satisfy the tracker's interval */
1420    TR_TRACKER_WAITING,
1421
1422    /* it's time to (announce,scrape) this torrent, and we're waiting on a
1423     * a free slot to open up in the announce manager */
1424    TR_TRACKER_QUEUED,
1425
1426    /* we're (announcing,scraping) this torrent right now */
1427    TR_TRACKER_ACTIVE
1428}
1429tr_tracker_state;
1430
1431typedef struct
1432{
1433    /* how many downloads this tracker knows of (-1 means it does not know) */
1434    int downloadCount;
1435
1436    /* whether or not we've ever sent this tracker an announcement */
1437    tr_bool hasAnnounced;
1438
1439    /* whether or not we've ever scraped to this tracker */
1440    tr_bool hasScraped;
1441
1442    /* ex: http://www.legaltorrents.com:7070 */
1443    char host[1024];
1444
1445    /* the full announce URL */
1446    char announce[1024];
1447
1448    /* Transmission uses one tracker per tier,
1449     * and the others are kept as backups */
1450    tr_bool isBackup;
1451
1452    /* is the tracker announcing, waiting, queued, etc */
1453    tr_tracker_state announceState;
1454
1455    /* is the tracker scraping, waiting, queued, etc */
1456    tr_tracker_state scrapeState;
1457
1458    /* number of peers the tracker told us about last time.
1459     * if "lastAnnounceSucceeded" is false, this field is undefined */
1460    int lastAnnouncePeerCount;
1461
1462    /* human-readable string with the result of the last announce.
1463       if "hasAnnounced" is false, this field is undefined */
1464    char lastAnnounceResult[128];
1465
1466    /* when the last announce was sent to the tracker.
1467     * if "hasAnnounced" is false, this field is undefined */
1468    time_t lastAnnounceStartTime;
1469
1470    /* whether or not the last announce was a success.
1471       if "hasAnnounced" is false, this field is undefined */
1472    tr_bool lastAnnounceSucceeded;
1473
1474    /* whether or not the last announce timed out. */
1475    tr_bool lastAnnounceTimedOut;
1476
1477    /* when the last announce was completed.
1478       if "hasAnnounced" is false, this field is undefined */
1479    time_t lastAnnounceTime;
1480
1481    /* human-readable string with the result of the last scrape.
1482     * if "hasScraped" is false, this field is undefined */
1483    char lastScrapeResult[128];
1484
1485    /* when the last scrape was sent to the tracker.
1486     * if "hasScraped" is false, this field is undefined */
1487    time_t lastScrapeStartTime;
1488
1489    /* whether or not the last scrape was a success.
1490       if "hasAnnounced" is false, this field is undefined */
1491    tr_bool lastScrapeSucceeded;
1492
1493    /* whether or not the last scrape timed out. */
1494    tr_bool lastScrapeTimedOut;
1495
1496    /* when the last scrape was completed.
1497       if "hasScraped" is false, this field is undefined */
1498    time_t lastScrapeTime;
1499
1500    /* number of leechers this tracker knows of (-1 means it does not know) */
1501    int leecherCount;
1502
1503    /* when the next periodic announce message will be sent out.
1504       if announceState isn't TR_TRACKER_WAITING, this field is undefined */
1505    time_t nextAnnounceTime;
1506
1507    /* when the next periodic scrape message will be sent out.
1508       if scrapeState isn't TR_TRACKER_WAITING, this field is undefined */
1509    time_t nextScrapeTime;
1510
1511    /* number of seeders this tracker knows of (-1 means it does not know) */
1512    int seederCount;
1513
1514    /* which tier this tracker is in */
1515    int tier;
1516
1517    /* used to match to a tr_tracker_info */
1518    uint32_t id;
1519}
1520tr_tracker_stat;
1521
1522tr_tracker_stat * tr_torrentTrackers( const tr_torrent * torrent,
1523                                      int              * setmeTrackerCount );
1524
1525void tr_torrentTrackersFree( tr_tracker_stat * trackerStats,
1526                             int               trackerCount );
1527
1528
1529
1530/**
1531 * @brief get the download speeds for each of this torrent's webseed sources.
1532 *
1533 * @return an array of tor->info.webseedCount floats giving download speeds.
1534 *         Each speed in the array corresponds to the webseed at the same
1535 *         array index in tor->info.webseeds.
1536 *         To differentiate "idle" and "stalled" status, idle webseeds will
1537 *         return -1 instead of 0 KiB/s.
1538 *         NOTE: always free this array with tr_free() when you're done with it.
1539 */
1540float*         tr_torrentWebSpeeds( const tr_torrent * torrent );
1541
1542typedef struct tr_file_stat
1543{
1544    uint64_t    bytesCompleted;
1545    float       progress;
1546}
1547tr_file_stat;
1548
1549tr_file_stat * tr_torrentFiles( const tr_torrent  * torrent,
1550                                tr_file_index_t   * fileCount );
1551
1552void tr_torrentFilesFree( tr_file_stat     * files,
1553                          tr_file_index_t    fileCount );
1554
1555
1556/***********************************************************************
1557 * tr_torrentAvailability
1558 ***********************************************************************
1559 * Use this to draw an advanced progress bar which is 'size' pixels
1560 * wide. Fills 'tab' which you must have allocated: each byte is set
1561 * to either -1 if we have the piece, otherwise it is set to the number
1562 * of connected peers who have the piece.
1563 **********************************************************************/
1564void tr_torrentAvailability( const tr_torrent  * torrent,
1565                             int8_t            * tab,
1566                             int                  size );
1567
1568void tr_torrentAmountFinished( const tr_torrent  * torrent,
1569                               float *             tab,
1570                               int                 size );
1571
1572void tr_torrentVerify( tr_torrent * torrent );
1573
1574/***********************************************************************
1575 * tr_info
1576 **********************************************************************/
1577
1578/** @brief a part of tr_info that represents a single file of the torrent's content */
1579typedef struct tr_file
1580{
1581    uint64_t            length;    /* Length of the file, in bytes */
1582    char *              name;      /* Path to the file */
1583    int8_t              priority;  /* TR_PRI_HIGH, _NORMAL, or _LOW */
1584    int8_t              dnd;       /* nonzero if the file shouldn't be
1585                                     downloaded */
1586    tr_piece_index_t    firstPiece; /* We need pieces [firstPiece... */
1587    tr_piece_index_t    lastPiece; /* ...lastPiece] to dl this file */
1588    uint64_t            offset;    /* file begins at the torrent's nth byte */
1589}
1590tr_file;
1591
1592/** @brief a part of tr_info that represents a single piece of the torrent's content */
1593typedef struct tr_piece
1594{
1595    uint8_t    hash[SHA_DIGEST_LENGTH]; /* pieces hash */
1596    int8_t     priority;               /* TR_PRI_HIGH, _NORMAL, or _LOW */
1597    int8_t     dnd;                    /* nonzero if the piece shouldn't be
1598                                         downloaded */
1599}
1600tr_piece;
1601
1602/** @brief information about a torrent that comes from its metainfo file */
1603struct tr_info
1604{
1605    /* total size of the torrent, in bytes */
1606    uint64_t           totalSize;
1607
1608    /* the torrent's name */
1609    char             * name;
1610
1611    /* Path to torrent Transmission's internal copy of the .torrent file. */
1612    char             * torrent;
1613
1614    char            ** webseeds;
1615
1616    char             * comment;
1617    char             * creator;
1618    tr_file          * files;
1619    tr_piece         * pieces;
1620
1621    /* these trackers are sorted by tier */
1622    tr_tracker_info  * trackers;
1623
1624    /* Torrent info */
1625    time_t             dateCreated;
1626
1627    int                trackerCount;
1628    int                webseedCount;
1629    tr_file_index_t    fileCount;
1630    uint32_t           pieceSize;
1631    tr_piece_index_t   pieceCount;
1632
1633    /* General info */
1634    uint8_t            hash[SHA_DIGEST_LENGTH];
1635    char               hashString[2 * SHA_DIGEST_LENGTH + 1];
1636
1637    /* hash, escaped as per rfc2396 for tracker announces */
1638    char               hashEscaped[3 * SHA_DIGEST_LENGTH + 1];
1639
1640    /* Flags */
1641    tr_bool            isPrivate;
1642    tr_bool            isMultifile;
1643};
1644
1645static inline tr_bool tr_torrentHasMetadata( const tr_torrent * tor )
1646{
1647    return tr_torrentInfo( tor )->fileCount > 0;
1648}
1649
1650/**
1651 * What the torrent is doing right now.
1652 *
1653 * Note: these values will become a straight enum at some point in the future.
1654 * Do not rely on their current `bitfield' implementation
1655 */
1656typedef enum
1657{
1658    TR_STATUS_CHECK_WAIT   = ( 1 << 0 ), /* Waiting in queue to check files */
1659    TR_STATUS_CHECK        = ( 1 << 1 ), /* Checking files */
1660    TR_STATUS_DOWNLOAD     = ( 1 << 2 ), /* Downloading */
1661    TR_STATUS_SEED         = ( 1 << 3 ), /* Seeding */
1662    TR_STATUS_STOPPED      = ( 1 << 4 )  /* Torrent is stopped */
1663}
1664tr_torrent_activity;
1665
1666enum
1667{
1668    TR_PEER_FROM_INCOMING  = 0, /* connections made to the listening port */
1669    TR_PEER_FROM_LPD,           /* peers found by local announcements */
1670    TR_PEER_FROM_TRACKER,       /* peers found from a tracker */
1671    TR_PEER_FROM_DHT,           /* peers found from the DHT */
1672    TR_PEER_FROM_PEX,           /* peers found from PEX */
1673    TR_PEER_FROM_RESUME,        /* peers found in the .resume file */
1674    TR_PEER_FROM_LTEP,          /* peer address provided in an LTEP handshake */
1675    TR_PEER_FROM__MAX
1676};
1677
1678typedef enum
1679{
1680    /* everything's fine */
1681    TR_STAT_OK               = 0,
1682
1683    /* when we anounced to the tracker, we got a warning in the response */
1684    TR_STAT_TRACKER_WARNING  = 1,
1685
1686    /* when we anounced to the tracker, we got an error in the response */
1687    TR_STAT_TRACKER_ERROR    = 2,
1688
1689    /* local trouble, such as disk full or permissions error */
1690    TR_STAT_LOCAL_ERROR      = 3
1691}
1692tr_stat_errtype;
1693
1694/** @brief Used by tr_torrentStat() to tell clients about a torrent's state and statistics */
1695typedef struct tr_stat
1696{
1697    /** The torrent's unique Id.
1698        @see tr_torrentId() */
1699    int    id;
1700
1701    /** What is this torrent doing right now? */
1702    tr_torrent_activity activity;
1703
1704    /** Defines what kind of text is in errorString.
1705        @see errorString */
1706    tr_stat_errtype error;
1707
1708    /** A warning or error message regarding the torrent.
1709        @see error */
1710    char errorString[128];
1711
1712    /** When tr_stat.status is TR_STATUS_CHECK or TR_STATUS_CHECK_WAIT,
1713        this is the percentage of how much of the files has been
1714        verified.  When it gets to 1, the verify process is done.
1715        Range is [0..1]
1716        @see tr_stat.status */
1717    float    recheckProgress;
1718
1719    /** How much has been downloaded of the entire torrent.
1720        Range is [0..1] */
1721    float    percentComplete;
1722
1723    /** How much of the metadata the torrent has.
1724        For torrents added from a .torrent this will always be 1.
1725        For magnet links, this number will from from 0 to 1 as the metadata is downloaded.
1726        Range is [0..1] */
1727    float    metadataPercentComplete;
1728
1729    /** How much has been downloaded of the files the user wants.  This differs
1730        from percentComplete if the user wants only some of the torrent's files.
1731        Range is [0..1]
1732        @see tr_stat.leftUntilDone */
1733    float    percentDone;
1734
1735    /** How much has been uploaded to satisfy the seed ratio.
1736        This is 1 if the ratio is reached or the torrent is set to seed forever.
1737        Range is [0..1] */
1738    float    seedRatioPercentDone;
1739
1740    /** Speed all data being sent for this torrent. (KiB/s)
1741        This includes piece data, protocol messages, and TCP overhead */
1742    double rawUploadSpeed;
1743
1744    /** Speed all data being received for this torrent. (KiB/s)
1745        This includes piece data, protocol messages, and TCP overhead */
1746    double rawDownloadSpeed;
1747
1748    /** Speed all piece being sent for this torrent. (KiB/s)
1749        This ONLY counts piece data. */
1750    double pieceUploadSpeed;
1751
1752    /** Speed all piece being received for this torrent. (KiB/s)
1753        This ONLY counts piece data. */
1754    double pieceDownloadSpeed;
1755
1756#define TR_ETA_NOT_AVAIL -1
1757#define TR_ETA_UNKNOWN -2
1758    /** If downloading, estimated number of seconds left until the torrent is done.
1759        If seeding, estimated number of seconds left until seed ratio is reached. */
1760    int    eta;
1761
1762    /** Number of peers that the tracker says this torrent has */
1763    int    peersKnown;
1764
1765    /** Number of peers that we're connected to */
1766    int    peersConnected;
1767
1768    /** How many peers we found out about from the tracker, or from pex,
1769        or from incoming connections, or from our resume file. */
1770    int    peersFrom[TR_PEER_FROM__MAX];
1771
1772    /** Number of peers that are sending data to us. */
1773    int    peersSendingToUs;
1774
1775    /** Number of peers that we're sending data to */
1776    int    peersGettingFromUs;
1777
1778    /** Number of webseeds that are sending data to us. */
1779    int    webseedsSendingToUs;
1780
1781    /** Byte count of all the piece data we'll have downloaded when we're done,
1782        whether or not we have it yet.  This may be less than tr_info.totalSize
1783        if only some of the torrent's files are wanted.
1784        [0...tr_info.totalSize] */
1785    uint64_t    sizeWhenDone;
1786
1787    /** Byte count of how much data is left to be downloaded until we've got
1788        all the pieces that we want.  [0...tr_info.sizeWhenDone] */
1789    uint64_t    leftUntilDone;
1790
1791    /** Byte count of all the piece data we want and don't have yet,
1792        but that a connected peer does have. [0...leftUntilDone] */
1793    uint64_t    desiredAvailable;
1794
1795    /** Byte count of all the corrupt data you've ever downloaded for
1796        this torrent.  If you're on a poisoned torrent, this number can
1797        grow very large. */
1798    uint64_t    corruptEver;
1799
1800    /** Byte count of all data you've ever uploaded for this torrent. */
1801    uint64_t    uploadedEver;
1802
1803    /** Byte count of all the non-corrupt data you've ever downloaded
1804        for this torrent.  If you deleted the files and downloaded a second
1805        time, this will be 2*totalSize.. */
1806    uint64_t    downloadedEver;
1807
1808    /** Byte count of all the checksum-verified data we have for this torrent.
1809      */
1810    uint64_t    haveValid;
1811
1812    /** Byte count of all the partial piece data we have for this torrent.
1813        As pieces become complete, this value may decrease as portions of it
1814        are moved to `corrupt' or `haveValid'. */
1815    uint64_t    haveUnchecked;
1816
1817    /** time when one or more of the torrent's trackers will
1818        allow you to manually ask for more peers,
1819        or 0 if you can't */
1820    time_t manualAnnounceTime;
1821
1822#define TR_RATIO_NA  -1
1823#define TR_RATIO_INF -2
1824    /** TR_RATIO_INF, TR_RATIO_NA, or a regular ratio */
1825    float    ratio;
1826
1827    /** When the torrent was first added. */
1828    time_t    addedDate;
1829
1830    /** When the torrent finished downloading. */
1831    time_t    doneDate;
1832
1833    /** When the torrent was last started. */
1834    time_t    startDate;
1835
1836    /** The last time we uploaded or downloaded piece data on this torrent. */
1837    time_t    activityDate;
1838   
1839    /** A torrent is considered finished if it has met its seed ratio.
1840        As a result, only paused torrents can be finished. */
1841    tr_bool   finished;
1842}
1843tr_stat;
1844
1845/** Return a pointer to an tr_stat structure with updated information
1846    on the torrent.  This is typically called by the GUI clients every
1847    second or so to get a new snapshot of the torrent's status. */
1848const tr_stat * tr_torrentStat( tr_torrent * torrent );
1849
1850/** Like tr_torrentStat(), but only recalculates the statistics if it's
1851    been longer than a second since they were last calculated.  This can
1852    reduce the CPU load if you're calling tr_torrentStat() frequently. */
1853const tr_stat * tr_torrentStatCached( tr_torrent * torrent );
1854
1855/** @deprecated */
1856void tr_torrentSetAddedDate( tr_torrent * torrent,
1857                             time_t       addedDate );
1858
1859/** @deprecated */
1860void tr_torrentSetActivityDate( tr_torrent * torrent,
1861                                time_t       activityDate );
1862
1863/** @deprecated */
1864void tr_torrentSetDoneDate( tr_torrent * torrent, time_t doneDate );
1865
1866/** @} */
1867
1868/** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */
1869static inline tr_bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; }
1870
1871/** @brief Sanity checker to test that a bool is TRUE or FALSE */
1872static inline tr_bool tr_isBool( tr_bool b ) { return b==1 || b==0; }
1873
1874#ifdef __cplusplus
1875}
1876#endif
1877
1878#endif
Note: See TracBrowser for help on using the repository browser.