source: trunk/libtransmission/transmission.h @ 245

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

Fixes warnings

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