source: trunk/libtransmission/transmission.h @ 1

Last change on this file since 1 was 1, checked in by root, 15 years ago

Import from 2005-10-26

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