source: trunk/libtransmission/transmission.h @ 14

Last change on this file since 14 was 14, checked in by root, 16 years ago

Update 2005-12-13

File size: 9.7 KB
Line 
1/******************************************************************************
2 * Copyright (c) 2005 Eric Petit
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
32#define SHA_DIGEST_LENGTH    20
33#ifdef SYS_BEOS
34# include <StorageDefs.h>
35# define MAX_PATH_LENGTH B_FILE_NAME_LENGTH
36#else
37# define MAX_PATH_LENGTH      1024
38#endif
39#define TR_MAX_TORRENT_COUNT 50
40
41#define TR_DEFAULT_PORT      9090
42
43/***********************************************************************
44 * tr_init
45 ***********************************************************************
46 * Initializes a libtransmission instance. Returns a obscure handle to
47 * be passed to all functions below.
48 **********************************************************************/
49typedef struct tr_handle_s tr_handle_t;
50
51tr_handle_t * tr_init();
52
53/***********************************************************************
54 * tr_getPrefsDirectory
55 ***********************************************************************
56 * Returns the full path to the directory used by libtransmission to
57 * store the resume files. The string belongs to libtransmission, do
58 * not free it.
59 **********************************************************************/
60char * tr_getPrefsDirectory( tr_handle_t * );
61
62/***********************************************************************
63 * tr_setBindPort
64 ***********************************************************************
65 * Sets a "start" port: everytime we start a torrent, we try to bind
66 * this port, then the next one and so on until we are successful.
67 **********************************************************************/
68void tr_setBindPort( tr_handle_t *, int );
69
70/***********************************************************************
71 * tr_setUploadLimit
72 ***********************************************************************
73 * Sets the total upload rate limit in KB/s
74 **********************************************************************/
75void tr_setUploadLimit( tr_handle_t *, int );
76
77/***********************************************************************
78 * tr_torrentRates
79 ***********************************************************************
80 * Gets the total download and upload rates
81 **********************************************************************/
82void tr_torrentRates( tr_handle_t *, float *, float * );
83
84/***********************************************************************
85 * tr_getFinished
86 ***********************************************************************
87 * Tests to see if torrent is finished
88 **********************************************************************/
89int tr_getFinished( tr_handle_t *, int );
90
91/***********************************************************************
92 * tr_setFinished
93 ***********************************************************************
94 * Sets the boolean value finished in the torrent back to false
95 **********************************************************************/
96void tr_setFinished( tr_handle_t *, int, int );
97
98/***********************************************************************
99 * tr_torrentInit
100 ***********************************************************************
101 * Opens and parses torrent file at 'path'. If the file exists and is a
102 * valid torrent file, returns 0 and adds it to the list of torrents
103 * (but doesn't start it). Returns a non-zero value otherwise.
104 **********************************************************************/
105int tr_torrentInit( tr_handle_t *, const char * path );
106
107/***********************************************************************
108 * tr_torrentScrape
109 ***********************************************************************
110 * Asks the tracker for the count of seeders and leechers. Returns 0
111 * and fills 's' and 'l' if successful. Otherwise returns 1 if the
112 * tracker doesn't support the scrape protocol, is unreachable or
113 * replied with some error. tr_torrentScrape may block up to 20 seconds
114 * before returning.
115 **********************************************************************/
116int tr_torrentScrape( tr_handle_t *, int, int * s, int * l );
117
118/***********************************************************************
119 * tr_torrentStart
120 ***********************************************************************
121 * Starts downloading. The download is launched in a seperate thread,
122 * therefore tr_torrentStart returns immediately.
123 **********************************************************************/
124void   tr_torrentSetFolder( tr_handle_t *, int, const char * );
125char * tr_torrentGetFolder( tr_handle_t *, int );
126void   tr_torrentStart( tr_handle_t *, int );
127
128/***********************************************************************
129 * tr_torrentStop
130 ***********************************************************************
131 * Stops downloading and notices the tracker that we are leaving. The
132 * thread keeps running while doing so.
133 * The thread will eventually be joined, either:
134 * - by tr_torrentStat when the tracker has been successfully noticed,
135 * - by tr_torrentStat if the tracker could not be noticed within 60s,
136 * - by tr_torrentClose if you choose to remove the torrent without
137 *   waiting any further.
138 **********************************************************************/
139void tr_torrentStop( tr_handle_t *, int );
140
141/***********************************************************************
142 * tr_torrentStat
143 ***********************************************************************
144 * Allocates an array of tr_stat_t structures, containing information
145 * about the current status of all open torrents (see the contents
146 * of tr_stat_s below). Returns the count of open torrents and sets
147 * (*s) to the address of the array, or NULL if no torrent is open.
148 * In the former case, the array belongs to the caller who is
149 * responsible of freeing it.
150 * The interface should call this function every 0.5 second or so in
151 * order to update itself.
152 **********************************************************************/
153typedef struct tr_stat_s tr_stat_t;
154
155int tr_torrentCount( tr_handle_t * h );
156int tr_torrentStat( tr_handle_t *, tr_stat_t ** s );
157
158/***********************************************************************
159 * tr_torrentClose
160 ***********************************************************************
161 * Frees memory allocated by tr_torrentInit. If the torrent was running,
162 * you must call tr_torrentStop() before closing it.
163 **********************************************************************/
164void tr_torrentClose( tr_handle_t *, int );
165
166/***********************************************************************
167 * tr_close
168 ***********************************************************************
169 * Frees memory allocated by tr_init.
170 **********************************************************************/
171void tr_close( tr_handle_t * );
172
173
174/***********************************************************************
175 * tr_stat_s
176 **********************************************************************/
177typedef struct tr_file_s
178{
179    uint64_t length;                /* Length of the file, in bytes */
180    char     name[MAX_PATH_LENGTH]; /* Path to the file */
181}
182tr_file_t;
183
184typedef struct tr_info_s
185{
186    /* Path to torrent */
187    char        torrent[MAX_PATH_LENGTH];
188
189    /* General info */
190    uint8_t     hash[SHA_DIGEST_LENGTH];
191    char        name[MAX_PATH_LENGTH];
192
193    /* Tracker info */
194    char        trackerAddress[256];
195    int         trackerPort;
196    char        trackerAnnounce[MAX_PATH_LENGTH];
197
198    /* Pieces info */
199    int         pieceSize;
200    int         pieceCount;
201    uint64_t    totalSize;
202    uint8_t   * pieces;
203
204    /* Files info */
205    int         fileCount;
206    tr_file_t * files;
207}
208tr_info_t;
209
210struct tr_stat_s
211{
212    tr_info_t   info;
213
214#define TR_STATUS_CHECK    0x001 /* Checking files */
215#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
216#define TR_STATUS_SEED     0x004 /* Seeding */
217#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
218#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
219                                    running (for internal use only) */
220#define TR_STATUS_PAUSE    0x020 /* Paused */
221#define TR_TRACKER_ERROR   0x100
222    int         status;
223    char        error[128];
224
225    float       progress;
226    float       rateDownload;
227    float       rateUpload;
228    int         eta;
229    int         peersTotal;
230    int         peersUploading;
231    int         peersDownloading;
232    char        pieces[120];
233    int                 seeders;
234        int                     leechers;
235
236    uint64_t    downloaded;
237    uint64_t    uploaded;
238
239    char      * folder;
240};
241
242#ifdef __TRANSMISSION__
243#  include "internal.h"
244#endif
245
246#ifdef __cplusplus
247}
248#endif
249
250#endif
Note: See TracBrowser for help on using the repository browser.