source: trunk/libtransmission/transmission.h @ 815

Last change on this file since 815 was 815, checked in by joshe, 16 years ago

Rework the message stuff again to be easier on the frontend.

  • Property svn:keywords set to Date Rev Author Id
File size: 14.5 KB
Line 
1/******************************************************************************
2 * $Id: transmission.h 815 2006-08-22 02:12:58Z 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_setMessageLevel
65 ***********************************************************************
66 * Set the level of messages to be output or queued
67 **********************************************************************/
68#define TR_MSG_ERR 1
69#define TR_MSG_INF 2
70#define TR_MSG_DBG 3
71void tr_setMessageLevel( int );
72int tr_getMessageLevel( void );
73
74/***********************************************************************
75 * tr_setMessageQueuing
76 ***********************************************************************
77 * Enable or disable message queuing
78 **********************************************************************/
79typedef struct tr_msg_list_s tr_msg_list_t;
80void tr_setMessageQueuing( int );
81
82/***********************************************************************
83 * tr_getQueuedMessages
84 ***********************************************************************
85 * Return a list of queued messages
86 **********************************************************************/
87tr_msg_list_t * tr_getQueuedMessages( void );
88void tr_freeMessageList( tr_msg_list_t * list );
89
90/***********************************************************************
91 * tr_getPrefsDirectory
92 ***********************************************************************
93 * Returns the full path to a directory which can be used to store
94 * preferences. The string belongs to libtransmission, do not free it.
95 **********************************************************************/
96char * tr_getPrefsDirectory();
97
98/***********************************************************************
99 * tr_setBindPort
100 ***********************************************************************
101 * Sets the port to listen for incoming peer connections
102 **********************************************************************/
103void tr_setBindPort( tr_handle_t *, int );
104
105/***********************************************************************
106 * tr_setUploadLimit
107 ***********************************************************************
108 * Sets the total upload rate limit in KB/s
109 **********************************************************************/
110void tr_setUploadLimit( tr_handle_t *, int );
111
112/***********************************************************************
113 * tr_setDownloadLimit
114 ***********************************************************************
115 * Sets the total download rate limit in KB/s
116 **********************************************************************/
117void tr_setDownloadLimit( tr_handle_t *, int );
118
119/***********************************************************************
120 * tr_torrentCount
121 ***********************************************************************
122 * Returns the count of open torrents
123 **********************************************************************/
124int tr_torrentCount( tr_handle_t * h );
125
126/***********************************************************************
127 * tr_torrentIterate
128 ***********************************************************************
129 * Iterates on open torrents
130 **********************************************************************/
131typedef struct tr_torrent_s tr_torrent_t;
132typedef void (*tr_callback_t) ( tr_torrent_t *, void * );
133void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
134
135/***********************************************************************
136 * tr_torrentRates
137 ***********************************************************************
138 * Gets the total download and upload rates
139 **********************************************************************/
140void tr_torrentRates( tr_handle_t *, float *, float * );
141
142/***********************************************************************
143 * tr_close
144 ***********************************************************************
145 * Frees memory allocated by tr_init.
146 **********************************************************************/
147void tr_close( tr_handle_t * );
148
149/***********************************************************************
150 * tr_torrentInit
151 ***********************************************************************
152 * Opens and parses torrent file at 'path'. If the file exists and is a
153 * valid torrent file, returns an handle and adds it to the list of
154 * torrents (but doesn't start it). Returns NULL and sets *error
155 * otherwise.  If the TR_FSAVEPRIVATE flag is passed then a private copy
156 * of the torrent file will be saved.
157 **********************************************************************/
158#define TR_EINVALID     1
159#define TR_EUNSUPPORTED 2
160#define TR_EDUPLICATE   3
161#define TR_EOTHER       666
162tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
163                               int flags, int * error );
164
165/***********************************************************************
166 * tr_torrentInitSaved
167 ***********************************************************************
168 * Opens and parses a torrent file as with tr_torrentInit, only taking
169 * the hash string of a saved torrent file instead of a filename.  There
170 * are currently no valid flags for this function.
171 **********************************************************************/
172tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr,
173                                    int flags, int * error );
174
175typedef struct tr_info_s tr_info_t;
176tr_info_t * tr_torrentInfo( tr_torrent_t * );
177
178/***********************************************************************
179 * tr_torrentScrape
180 ***********************************************************************
181 * Asks the tracker for the count of seeders and leechers. Returns 0
182 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
183 * tracker doesn't support the scrape protocol, is unreachable or
184 * replied with some error. tr_torrentScrape may block up to 20 seconds
185 * before returning.
186 **********************************************************************/
187int tr_torrentScrape( tr_torrent_t *, int * s, int * l );
188
189/***********************************************************************
190 * tr_torrentStart
191 ***********************************************************************
192 * Starts downloading. The download is launched in a seperate thread,
193 * therefore tr_torrentStart returns immediately.
194 **********************************************************************/
195void   tr_torrentSetFolder( tr_torrent_t *, const char * );
196char * tr_torrentGetFolder( tr_torrent_t * );
197void   tr_torrentStart( tr_torrent_t * );
198
199/***********************************************************************
200 * tr_torrentStop
201 ***********************************************************************
202 * Stops downloading and notices the tracker that we are leaving. The
203 * thread keeps running while doing so.
204 * The thread will eventually be joined, either:
205 * - by tr_torrentStat when the tracker has been successfully noticed,
206 * - by tr_torrentStat if the tracker could not be noticed within 60s,
207 * - by tr_torrentClose if you choose to remove the torrent without
208 *   waiting any further.
209 **********************************************************************/
210void tr_torrentStop( tr_torrent_t * );
211
212/***********************************************************************
213 * tr_getFinished
214 ***********************************************************************
215 * The first call after a torrent is completed returns 1. Returns 0
216 * in other cases.
217 **********************************************************************/
218int tr_getFinished( tr_torrent_t * );
219
220/***********************************************************************
221 * tr_torrentStat
222 ***********************************************************************
223 * Returns a pointer to an tr_stat_t structure with updated information
224 * on the torrent. The structure belongs to libtransmission (do not
225 * free it) and is guaranteed to be unchanged until the next call to
226 * tr_torrentStat.
227 * The interface should call this function every second or so in order
228 * to update itself.
229 **********************************************************************/
230typedef struct tr_stat_s tr_stat_t;
231tr_stat_t * tr_torrentStat( tr_torrent_t * );
232
233/***********************************************************************
234 * tr_torrentPeers
235 ***********************************************************************/
236typedef struct tr_peer_stat_s tr_peer_stat_t;
237tr_peer_stat_t * tr_torrentPeers( tr_torrent_t *, int * peerCount );
238void tr_torrentPeersFree( tr_peer_stat_t *, int peerCount );
239
240/***********************************************************************
241 * tr_torrentAvailability
242 ***********************************************************************
243 * Use this to draw an advanced progress bar which is 'size' pixels
244 * wide. Fills 'tab' which you must have allocated: each byte is set
245 * to either -1 if we have the piece, otherwise it is set to the number
246 * of connected peers who have the piece.
247 **********************************************************************/
248void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
249
250/***********************************************************************
251 * tr_torrentRemoveSaved
252 ***********************************************************************
253 * Removes the private saved copy of a torrent file for torrents which
254 * the TR_FSAVEPRIVATE flag is set.
255 **********************************************************************/
256void tr_torrentRemoveSaved( tr_torrent_t * );
257
258/***********************************************************************
259 * tr_torrentClose
260 ***********************************************************************
261 * Frees memory allocated by tr_torrentInit. If the torrent was running,
262 * you must call tr_torrentStop() before closing it.
263 **********************************************************************/
264void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
265
266/***********************************************************************
267 * tr_info_s
268 **********************************************************************/
269typedef struct tr_file_s
270{
271    uint64_t length;                /* Length of the file, in bytes */
272    char     name[MAX_PATH_LENGTH]; /* Path to the file */
273}
274tr_file_t;
275struct tr_info_s
276{
277    /* Path to torrent */
278    char        torrent[MAX_PATH_LENGTH];
279
280    /* General info */
281    uint8_t     hash[SHA_DIGEST_LENGTH];
282    char        hashString[2*SHA_DIGEST_LENGTH+1];
283    char        name[MAX_PATH_LENGTH];
284
285    /* Flags */
286#define TR_FSAVEPRIVATE 0x01    /* save a private copy of the torrent */
287    int         flags;
288
289    /* Tracker info */
290    char        trackerAddress[256];
291    int         trackerPort;
292    char        trackerAnnounce[MAX_PATH_LENGTH];
293
294    /* Pieces info */
295    int         pieceSize;
296    int         pieceCount;
297    uint64_t    totalSize;
298    uint8_t   * pieces;
299
300    /* Files info */
301    int         multifile;
302    int         fileCount;
303    tr_file_t * files;
304};
305
306/***********************************************************************
307 * tr_stat_s
308 **********************************************************************/
309struct tr_stat_s
310{
311#define TR_STATUS_CHECK    0x001 /* Checking files */
312#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
313#define TR_STATUS_SEED     0x004 /* Seeding */
314#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
315#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
316                                    running (for internal use only) */
317#define TR_STATUS_PAUSE    0x020 /* Paused */
318
319#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
320#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
321    int                 status;
322
323#define TR_ETRACKER 1
324#define TR_EINOUT   2
325    int                 error;
326    char                trackerError[128];
327
328    float               progress;
329    float               rateDownload;
330    float               rateUpload;
331    int                 eta;
332    int                 peersTotal;
333    int                 peersUploading;
334    int                 peersDownloading;
335    int                 seeders;
336    int                 leechers;
337
338    uint64_t            downloaded;
339    uint64_t            uploaded;
340    float               swarmspeed;
341};
342
343struct tr_peer_stat_s
344{
345    char    addr[INET_ADDRSTRLEN];
346    char *  client;
347   
348    int     isConnected;
349    int     isDownloading;
350    int     isUploading;
351};
352
353struct tr_msg_list_s
354{
355    int                    level;
356    char                 * message;
357    struct tr_msg_list_s * next;
358};
359
360#ifdef __TRANSMISSION__
361#  include "internal.h"
362#endif
363
364#ifdef __cplusplus
365}
366#endif
367
368#endif
Note: See TracBrowser for help on using the repository browser.