source: trunk/libtransmission/transmission.h @ 261

Last change on this file since 261 was 261, checked in by titer, 16 years ago

Updated svn:keywords

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