1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00
transmission/libtransmission/transmission.h

277 lines
11 KiB
C
Raw Normal View History

2006-01-12 17:43:21 +00:00
/******************************************************************************
2006-03-23 12:39:39 +00:00
* Copyright (c) 2005-2006 Transmission authors and contributors
2006-01-12 17:43:21 +00:00
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#ifndef TR_TRANSMISSION_H
#define TR_TRANSMISSION_H 1
2006-01-12 18:52:15 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2006-01-12 17:43:21 +00:00
#include <inttypes.h>
2006-03-23 12:39:39 +00:00
#define SHA_DIGEST_LENGTH 20
2006-01-12 18:58:57 +00:00
#ifdef __BEOS__
2006-01-12 18:52:15 +00:00
# include <StorageDefs.h>
2006-03-23 12:39:39 +00:00
# define MAX_PATH_LENGTH B_FILE_NAME_LENGTH
2006-01-12 18:52:15 +00:00
#else
2006-03-23 12:39:39 +00:00
# define MAX_PATH_LENGTH 1024
2006-01-12 18:52:15 +00:00
#endif
2006-01-12 17:43:21 +00:00
2006-03-23 12:39:39 +00:00
#define TR_DEFAULT_PORT 9090
#define TR_NOERROR 0
2006-01-12 18:40:47 +00:00
2006-01-12 17:43:21 +00:00
/***********************************************************************
* tr_init
***********************************************************************
* Initializes a libtransmission instance. Returns a obscure handle to
* be passed to all functions below.
**********************************************************************/
typedef struct tr_handle_s tr_handle_t;
tr_handle_t * tr_init();
2006-01-12 18:20:48 +00:00
/***********************************************************************
* tr_getPrefsDirectory
***********************************************************************
* Returns the full path to the directory used by libtransmission to
* store the resume files. The string belongs to libtransmission, do
* not free it.
**********************************************************************/
2006-01-12 18:58:57 +00:00
char * tr_getPrefsDirectory();
2006-01-12 18:20:48 +00:00
2006-01-12 17:43:21 +00:00
/***********************************************************************
* tr_setBindPort
***********************************************************************
* Sets a "start" port: everytime we start a torrent, we try to bind
* this port, then the next one and so on until we are successful.
**********************************************************************/
void tr_setBindPort( tr_handle_t *, int );
/***********************************************************************
* tr_setUploadLimit
***********************************************************************
* Sets the total upload rate limit in KB/s
**********************************************************************/
void tr_setUploadLimit( tr_handle_t *, int );
/***********************************************************************
2006-03-23 12:39:39 +00:00
* tr_torrentCount
2006-01-12 17:43:21 +00:00
***********************************************************************
2006-03-23 12:39:39 +00:00
* Returns the count of open torrents
2006-01-12 17:43:21 +00:00
**********************************************************************/
2006-03-23 12:39:39 +00:00
int tr_torrentCount( tr_handle_t * h );
2006-01-12 17:43:21 +00:00
2006-01-12 18:33:20 +00:00
/***********************************************************************
2006-03-23 12:39:39 +00:00
* tr_torrentIterate
***********************************************************************
* Iterates on open torrents
**********************************************************************/
typedef struct tr_torrent_s tr_torrent_t;
typedef void (*tr_callback_t) ( tr_torrent_t *, void * );
void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
/***********************************************************************
* tr_torrentRates
2006-01-12 18:33:20 +00:00
***********************************************************************
2006-03-23 12:39:39 +00:00
* Gets the total download and upload rates
2006-01-12 18:33:20 +00:00
**********************************************************************/
2006-03-23 12:39:39 +00:00
void tr_torrentRates( tr_handle_t *, float *, float * );
2006-01-12 18:33:20 +00:00
/***********************************************************************
2006-03-23 12:39:39 +00:00
* tr_close
2006-01-12 18:33:20 +00:00
***********************************************************************
2006-03-23 12:39:39 +00:00
* Frees memory allocated by tr_init.
2006-01-12 18:33:20 +00:00
**********************************************************************/
2006-03-23 12:39:39 +00:00
void tr_close( tr_handle_t * );
2006-01-12 18:33:20 +00:00
2006-01-12 17:43:21 +00:00
/***********************************************************************
* tr_torrentInit
***********************************************************************
* Opens and parses torrent file at 'path'. If the file exists and is a
2006-03-23 12:39:39 +00:00
* valid torrent file, returns an handle and adds it to the list of
* torrents (but doesn't start it). Returns NULL and sets *error
* otherwise.
2006-01-12 17:43:21 +00:00
**********************************************************************/
2006-03-23 12:39:39 +00:00
#define TR_EINVALID 1
#define TR_EUNSUPPORTED 2
#define TR_EDUPLICATE 3
#define TR_EOTHER 666
tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
int * error );
typedef struct tr_info_s tr_info_t;
tr_info_t * tr_torrentInfo( tr_torrent_t * );
2006-01-12 17:43:21 +00:00
/***********************************************************************
* tr_torrentScrape
***********************************************************************
* Asks the tracker for the count of seeders and leechers. Returns 0
* and fills 's' and 'l' if successful. Otherwise returns 1 if the
* tracker doesn't support the scrape protocol, is unreachable or
* replied with some error. tr_torrentScrape may block up to 20 seconds
* before returning.
**********************************************************************/
2006-03-23 12:39:39 +00:00
int tr_torrentScrape( tr_torrent_t *, int * s, int * l );
2006-01-12 17:43:21 +00:00
/***********************************************************************
* tr_torrentStart
***********************************************************************
* Starts downloading. The download is launched in a seperate thread,
* therefore tr_torrentStart returns immediately.
**********************************************************************/
2006-03-23 12:39:39 +00:00
void tr_torrentSetFolder( tr_torrent_t *, const char * );
char * tr_torrentGetFolder( tr_torrent_t * );
void tr_torrentStart( tr_torrent_t * );
2006-01-12 17:43:21 +00:00
/***********************************************************************
* tr_torrentStop
***********************************************************************
* Stops downloading and notices the tracker that we are leaving. The
* thread keeps running while doing so.
* The thread will eventually be joined, either:
* - by tr_torrentStat when the tracker has been successfully noticed,
* - by tr_torrentStat if the tracker could not be noticed within 60s,
* - by tr_torrentClose if you choose to remove the torrent without
* waiting any further.
**********************************************************************/
2006-03-23 12:39:39 +00:00
void tr_torrentStop( tr_torrent_t * );
/***********************************************************************
* tr_getFinished
***********************************************************************
* The first call after a torrent is completed returns 1. Returns 0
* in other cases.
**********************************************************************/
int tr_getFinished( tr_torrent_t * );
2006-01-12 17:43:21 +00:00
/***********************************************************************
* tr_torrentStat
***********************************************************************
2006-03-23 12:39:39 +00:00
* Returns a pointer to an tr_stat_t structure with updated information
* on the torrent. The structure belongs to libtransmission (do not
* free it) and is guaranteed to be unchanged until the next call to
* tr_torrentStat.
* The interface should call this function every second or so in order
* to update itself.
2006-01-12 17:43:21 +00:00
**********************************************************************/
typedef struct tr_stat_s tr_stat_t;
2006-03-23 12:39:39 +00:00
tr_stat_t * tr_torrentStat( tr_torrent_t * );
2006-01-12 17:43:21 +00:00
/***********************************************************************
2006-03-23 12:39:39 +00:00
* tr_torrentAvailability
2006-01-12 17:43:21 +00:00
***********************************************************************
2006-03-23 12:39:39 +00:00
* Use this to draw an advanced progress bar which is 'size' pixels
* wide. Fills 'tab' which you must have allocated: each byte is set
* to either -1 if we have the piece, otherwise it is set to the number
* of connected peers who have the piece.
2006-01-12 17:43:21 +00:00
**********************************************************************/
2006-03-23 12:39:39 +00:00
void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
2006-01-12 17:43:21 +00:00
/***********************************************************************
2006-03-23 12:39:39 +00:00
* tr_torrentClose
2006-01-12 17:43:21 +00:00
***********************************************************************
2006-03-23 12:39:39 +00:00
* Frees memory allocated by tr_torrentInit. If the torrent was running,
* you must call tr_torrentStop() before closing it.
2006-01-12 17:43:21 +00:00
**********************************************************************/
2006-03-23 12:39:39 +00:00
void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
2006-01-12 17:43:21 +00:00
/***********************************************************************
2006-03-23 12:39:39 +00:00
* tr_info_s
2006-01-12 17:43:21 +00:00
**********************************************************************/
typedef struct tr_file_s
{
uint64_t length; /* Length of the file, in bytes */
char name[MAX_PATH_LENGTH]; /* Path to the file */
}
tr_file_t;
2006-03-23 12:39:39 +00:00
struct tr_info_s
2006-01-12 17:43:21 +00:00
{
/* Path to torrent */
char torrent[MAX_PATH_LENGTH];
/* General info */
uint8_t hash[SHA_DIGEST_LENGTH];
char name[MAX_PATH_LENGTH];
/* Tracker info */
char trackerAddress[256];
int trackerPort;
char trackerAnnounce[MAX_PATH_LENGTH];
/* Pieces info */
int pieceSize;
int pieceCount;
uint64_t totalSize;
uint8_t * pieces;
/* Files info */
int fileCount;
tr_file_t * files;
2006-03-23 12:39:39 +00:00
};
2006-01-12 17:43:21 +00:00
2006-03-23 12:39:39 +00:00
/***********************************************************************
* tr_stat_s
**********************************************************************/
2006-01-12 17:43:21 +00:00
struct tr_stat_s
{
#define TR_STATUS_CHECK 0x001 /* Checking files */
#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
#define TR_STATUS_SEED 0x004 /* Seeding */
#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
#define TR_STATUS_STOPPED 0x010 /* Sent 'stopped' but thread still
running (for internal use only) */
#define TR_STATUS_PAUSE 0x020 /* Paused */
2006-03-23 12:39:39 +00:00
#define TR_STATUS_ACTIVE (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
2006-01-12 17:43:21 +00:00
int status;
2006-03-23 12:39:39 +00:00
#define TR_ETRACKER 1
#define TR_EINOUT 2
int error;
char trackerError[128];
2006-01-12 17:43:21 +00:00
float progress;
float rateDownload;
float rateUpload;
int eta;
int peersTotal;
int peersUploading;
int peersDownloading;
2006-01-12 18:58:57 +00:00
int seeders;
int leechers;
2006-01-12 17:43:21 +00:00
uint64_t downloaded;
uint64_t uploaded;
};
#ifdef __TRANSMISSION__
# include "internal.h"
#endif
2006-01-12 18:52:15 +00:00
#ifdef __cplusplus
}
#endif
2006-01-12 17:43:21 +00:00
#endif