source: trunk/libtransmission/transmission.h @ 803

Last change on this file since 803 was 803, checked in by joshe, 15 years ago

Make message level available to message handler callback.

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