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

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

Seperates status and error in tr_stat_t.

File size: 10.1 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#define TR_NOERROR        0
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;
50tr_handle_t * tr_init();
51
52/***********************************************************************
53 * tr_getPrefsDirectory
54 ***********************************************************************
55 * Returns the full path to the directory used by libtransmission to
56 * store the resume files. The string belongs to libtransmission, do
57 * not free it.
58 **********************************************************************/
59char * tr_getPrefsDirectory();
60
61/***********************************************************************
62 * tr_setBindPort
63 ***********************************************************************
64 * Sets a "start" port: everytime we start a torrent, we try to bind
65 * this port, then the next one and so on until we are successful.
66 **********************************************************************/
67void tr_setBindPort( tr_handle_t *, int );
68
69/***********************************************************************
70 * tr_setUploadLimit
71 ***********************************************************************
72 * Sets the total upload rate limit in KB/s
73 **********************************************************************/
74void tr_setUploadLimit( tr_handle_t *, int );
75
76/***********************************************************************
77 * tr_torrentCount
78 ***********************************************************************
79 * Returns the count of open torrents
80 **********************************************************************/
81int tr_torrentCount( tr_handle_t * h );
82
83/***********************************************************************
84 * tr_torrentRates
85 ***********************************************************************
86 * Gets the total download and upload rates
87 **********************************************************************/
88void tr_torrentRates( tr_handle_t *, float *, float * );
89
90/***********************************************************************
91 * tr_close
92 ***********************************************************************
93 * Frees memory allocated by tr_init.
94 **********************************************************************/
95void tr_close( tr_handle_t * );
96
97/***********************************************************************
98 * tr_torrentInit
99 ***********************************************************************
100 * Opens and parses torrent file at 'path'. If the file exists and is a
101 * valid torrent file, returns an handle and adds it to the list of
102 * torrents (but doesn't start it). Returns NULL and sets *error
103 * otherwise.
104 **********************************************************************/
105typedef struct tr_torrent_s tr_torrent_t;
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/***********************************************************************
181 * tr_info_s
182 **********************************************************************/
183typedef struct tr_file_s
184{
185    uint64_t length;                /* Length of the file, in bytes */
186    char     name[MAX_PATH_LENGTH]; /* Path to the file */
187}
188tr_file_t;
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
214/***********************************************************************
215 * tr_stat_s
216 **********************************************************************/
217struct tr_stat_s
218{
219#define TR_STATUS_CHECK    0x001 /* Checking files */
220#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
221#define TR_STATUS_SEED     0x004 /* Seeding */
222#define TR_STATUS_ACTIVE   0x007 /* CHECK | DOWNLOAD | SEED */
223#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
224#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
225                                    running (for internal use only) */
226#define TR_STATUS_PAUSE    0x020 /* Paused */
227#define TR_STATUS_INACTIVE 0x038 /* STOPPING | STOPPED | PAUSE */
228    int         status;
229
230#define TR_ETRACKER 1
231#define TR_EINOUT   2
232    int         error;
233    char        trackerError[128];
234
235    float       progress;
236    float       rateDownload;
237    float       rateUpload;
238    int         eta;
239    int         peersTotal;
240    int         peersUploading;
241    int         peersDownloading;
242    char        pieces[120];
243    int         seeders;
244    int         leechers;
245
246    uint64_t    downloaded;
247    uint64_t    uploaded;
248};
249
250#ifdef __TRANSMISSION__
251#  include "internal.h"
252#endif
253
254#ifdef __cplusplus
255}
256#endif
257
258#endif
Note: See TracBrowser for help on using the repository browser.