source: trunk/libtransmission/transmission.h @ 7

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

Update 2005-11-24

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