source: branches/new_api/libtransmission/transmission.h @ 138

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

Adds an error feedback for tr_torrentInit.
Adds tr_torrentInfo along with tr_torrentStat.
Removed now unused tr_setFinished.

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