2006-07-16 19:39:23 +00:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2005-2006 Transmission authors and contributors
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <signal.h>
|
2007-07-18 23:04:26 +00:00
|
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
|
#include <libtransmission/makemeta.h>
|
|
|
|
|
|
2007-08-04 02:44:09 +00:00
|
|
|
|
#ifdef __BEOS__
|
2007-08-02 21:58:34 +00:00
|
|
|
|
#include <kernel/OS.h>
|
2007-08-04 02:44:09 +00:00
|
|
|
|
#define wait_msecs(N) snooze( (N) * 1000 )
|
|
|
|
|
#define wait_secs(N) sleep( (N) )
|
2007-08-02 21:58:34 +00:00
|
|
|
|
#elif defined(WIN32)
|
|
|
|
|
#include <windows.h>
|
2007-08-04 02:44:09 +00:00
|
|
|
|
#define wait_msecs(N) Sleep( (N) )
|
2007-08-04 02:55:06 +00:00
|
|
|
|
#define wait_secs(N) Sleep( (N) * 1000 )
|
2007-08-04 02:44:09 +00:00
|
|
|
|
#else
|
|
|
|
|
#define wait_msecs(N) usleep( (N) * 1000 )
|
|
|
|
|
#define wait_secs(N) sleep( (N) )
|
2006-07-16 19:39:23 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
|
/* macro to shut up "unused parameter" warnings */
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define UNUSED __attribute__((unused))
|
|
|
|
|
#else
|
|
|
|
|
#define UNUSED
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
const char * USAGE =
|
|
|
|
|
"Usage: %s [options] file.torrent [options]\n\n"
|
|
|
|
|
"Options:\n"
|
|
|
|
|
" -c, --create-from <file> Create torrent from the specified source file.\n"
|
|
|
|
|
" -a, --announce <url> Used in conjunction with -c.\n"
|
|
|
|
|
" -r, --private Used in conjunction with -c.\n"
|
|
|
|
|
" -m, --comment <text> Adds an optional comment when creating a torrent.\n"
|
|
|
|
|
" -d, --download <int> Maximum download rate (-1 = no limit, default = -1)\n"
|
|
|
|
|
" -f, --finish <shell script> Command you wish to run on completion\n"
|
|
|
|
|
" -h, --help Print this help and exit\n"
|
|
|
|
|
" -i, --info Print metainfo and exit\n"
|
|
|
|
|
" -n --nat-traversal Attempt NAT traversal using NAT-PMP or UPnP IGD\n"
|
|
|
|
|
" -p, --port <int> Port we should listen on (default = %d)\n"
|
2007-07-15 17:36:56 +00:00
|
|
|
|
#if 0
|
2007-06-18 03:40:41 +00:00
|
|
|
|
" -s, --scrape Print counts of seeders/leechers and exit\n"
|
2007-07-15 17:36:56 +00:00
|
|
|
|
#endif
|
2007-06-18 03:40:41 +00:00
|
|
|
|
" -u, --upload <int> Maximum upload rate (-1 = no limit, default = 20)\n"
|
|
|
|
|
" -v, --verbose <int> Verbose level (0 to 2, default = 0)\n";
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
|
|
static int showHelp = 0;
|
|
|
|
|
static int showInfo = 0;
|
2007-07-15 17:36:56 +00:00
|
|
|
|
#if 0
|
2006-07-16 19:39:23 +00:00
|
|
|
|
static int showScrape = 0;
|
2007-07-15 17:36:56 +00:00
|
|
|
|
#endif
|
2007-06-18 03:40:41 +00:00
|
|
|
|
static int isPrivate = 0;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
static int verboseLevel = 0;
|
|
|
|
|
static int bindPort = TR_DEFAULT_PORT;
|
|
|
|
|
static int uploadLimit = 20;
|
|
|
|
|
static int downloadLimit = -1;
|
|
|
|
|
static char * torrentPath = NULL;
|
2006-09-25 18:37:45 +00:00
|
|
|
|
static int natTraversal = 0;
|
2007-02-13 05:20:52 +00:00
|
|
|
|
static sig_atomic_t gotsig = 0;
|
2007-01-14 12:00:21 +00:00
|
|
|
|
static tr_torrent_t * tor;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
|
|
static char * finishCall = NULL;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
static char * announce = NULL;
|
|
|
|
|
static char * sourceFile = NULL;
|
|
|
|
|
static char * comment = NULL;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
|
|
static int parseCommandLine ( int argc, char ** argv );
|
|
|
|
|
static void sigHandler ( int signal );
|
|
|
|
|
|
2007-02-15 20:56:25 +00:00
|
|
|
|
char * getStringRatio( float ratio )
|
|
|
|
|
{
|
|
|
|
|
static char string[20];
|
|
|
|
|
|
|
|
|
|
if( ratio == TR_RATIO_NA )
|
|
|
|
|
return "n/a";
|
|
|
|
|
snprintf( string, sizeof string, "%.3f", ratio );
|
|
|
|
|
return string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define LINEWIDTH 80
|
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
|
int main( int argc, char ** argv )
|
|
|
|
|
{
|
2007-02-06 04:26:40 +00:00
|
|
|
|
int i, error;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
tr_handle_t * h;
|
2007-07-15 19:12:54 +00:00
|
|
|
|
const tr_stat_t * s;
|
2007-02-06 04:26:40 +00:00
|
|
|
|
tr_handle_status_t * hstat;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2007-07-10 19:40:21 +00:00
|
|
|
|
printf( "Transmission %s - http://transmission.m0k.org/\n\n",
|
|
|
|
|
LONG_VERSION_STRING );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
|
|
/* Get options */
|
|
|
|
|
if( parseCommandLine( argc, argv ) )
|
|
|
|
|
{
|
|
|
|
|
printf( USAGE, argv[0], TR_DEFAULT_PORT );
|
2007-02-06 22:47:55 +00:00
|
|
|
|
return EXIT_FAILURE;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( showHelp )
|
|
|
|
|
{
|
|
|
|
|
printf( USAGE, argv[0], TR_DEFAULT_PORT );
|
2007-02-06 22:47:55 +00:00
|
|
|
|
return EXIT_SUCCESS;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( verboseLevel < 0 )
|
|
|
|
|
{
|
|
|
|
|
verboseLevel = 0;
|
|
|
|
|
}
|
|
|
|
|
else if( verboseLevel > 9 )
|
|
|
|
|
{
|
|
|
|
|
verboseLevel = 9;
|
|
|
|
|
}
|
|
|
|
|
if( verboseLevel )
|
|
|
|
|
{
|
|
|
|
|
static char env[11];
|
2007-03-12 00:04:11 +00:00
|
|
|
|
snprintf( env, sizeof env, "TR_DEBUG=%d", verboseLevel );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
putenv( env );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( bindPort < 1 || bindPort > 65535 )
|
|
|
|
|
{
|
|
|
|
|
printf( "Invalid port '%d'\n", bindPort );
|
2007-02-06 22:47:55 +00:00
|
|
|
|
return EXIT_FAILURE;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize libtransmission */
|
2007-03-13 06:56:50 +00:00
|
|
|
|
h = tr_init( "cli" );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
|
if( sourceFile && *sourceFile ) /* creating a torrent */
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
tr_metainfo_builder_t* builder = tr_metaInfoBuilderCreate( h, sourceFile );
|
|
|
|
|
tr_makeMetaInfo( builder, NULL, announce, comment, isPrivate );
|
|
|
|
|
while( !builder->isDone ) {
|
2007-08-04 02:44:09 +00:00
|
|
|
|
wait_msecs( 1 );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
printf( "." );
|
|
|
|
|
}
|
|
|
|
|
ret = !builder->failed;
|
|
|
|
|
tr_metaInfoBuilderFree( builder );
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
|
/* Open and parse torrent file */
|
2007-06-27 05:14:38 +00:00
|
|
|
|
if( !( tor = tr_torrentInit( h, torrentPath, ".", 0, &error ) ) )
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{
|
|
|
|
|
printf( "Failed opening torrent file `%s'\n", torrentPath );
|
2007-02-06 22:47:55 +00:00
|
|
|
|
tr_close( h );
|
|
|
|
|
return EXIT_FAILURE;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( showInfo )
|
|
|
|
|
{
|
2007-06-30 13:36:58 +00:00
|
|
|
|
const tr_info_t * info = tr_torrentInfo( tor );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2006-12-17 16:36:27 +00:00
|
|
|
|
s = tr_torrentStat( tor );
|
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
|
/* Print torrent info (quite <20> la btshowmetainfo) */
|
|
|
|
|
printf( "hash: " );
|
|
|
|
|
for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
|
|
|
|
|
{
|
|
|
|
|
printf( "%02x", info->hash[i] );
|
|
|
|
|
}
|
|
|
|
|
printf( "\n" );
|
|
|
|
|
printf( "tracker: %s:%d\n",
|
2007-02-27 04:00:38 +00:00
|
|
|
|
s->tracker->address, s->tracker->port );
|
|
|
|
|
printf( "announce: %s\n", s->tracker->announce );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
printf( "size: %"PRIu64" (%"PRIu64" * %d + %"PRIu64")\n",
|
|
|
|
|
info->totalSize, info->totalSize / info->pieceSize,
|
|
|
|
|
info->pieceSize, info->totalSize % info->pieceSize );
|
2006-12-02 05:39:27 +00:00
|
|
|
|
if( info->comment[0] )
|
2006-12-02 05:32:54 +00:00
|
|
|
|
{
|
|
|
|
|
printf( "comment: %s\n", info->comment );
|
|
|
|
|
}
|
2006-12-02 05:39:27 +00:00
|
|
|
|
if( info->creator[0] )
|
|
|
|
|
{
|
|
|
|
|
printf( "creator: %s\n", info->creator );
|
|
|
|
|
}
|
2007-03-06 01:58:14 +00:00
|
|
|
|
if( TR_FLAG_PRIVATE & info->flags )
|
|
|
|
|
{
|
|
|
|
|
printf( "private flag set\n" );
|
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
printf( "file(s):\n" );
|
|
|
|
|
for( i = 0; i < info->fileCount; i++ )
|
|
|
|
|
{
|
|
|
|
|
printf( " %s (%"PRIu64")\n", info->files[i].name,
|
|
|
|
|
info->files[i].length );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-15 17:36:56 +00:00
|
|
|
|
#if 0
|
2006-07-16 19:39:23 +00:00
|
|
|
|
if( showScrape )
|
|
|
|
|
{
|
2006-12-02 01:46:54 +00:00
|
|
|
|
int seeders, leechers, downloaded;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2006-12-02 01:46:54 +00:00
|
|
|
|
if( tr_torrentScrape( tor, &seeders, &leechers, &downloaded ) )
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{
|
|
|
|
|
printf( "Scrape failed.\n" );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-12-02 01:46:54 +00:00
|
|
|
|
printf( "%d seeder(s), %d leecher(s), %d download(s).\n",
|
|
|
|
|
seeders, leechers, downloaded );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
2007-07-15 17:36:56 +00:00
|
|
|
|
#endif
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
|
|
signal( SIGINT, sigHandler );
|
|
|
|
|
|
|
|
|
|
tr_setBindPort( h, bindPort );
|
2007-07-20 08:33:59 +00:00
|
|
|
|
|
|
|
|
|
tr_setGlobalSpeedLimit ( h, TR_UP, uploadLimit );
|
|
|
|
|
tr_setUseGlobalSpeedLimit( h, TR_UP, uploadLimit > 0 );
|
|
|
|
|
tr_setGlobalSpeedLimit ( h, TR_DOWN, downloadLimit );
|
|
|
|
|
tr_setUseGlobalSpeedLimit( h, TR_DOWN, downloadLimit > 0 );
|
2006-09-25 18:37:45 +00:00
|
|
|
|
|
2007-01-19 04:42:31 +00:00
|
|
|
|
tr_natTraversalEnable( h, natTraversal );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
|
|
tr_torrentStart( tor );
|
|
|
|
|
|
2007-01-14 12:00:21 +00:00
|
|
|
|
for( ;; )
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{
|
2007-02-15 20:56:25 +00:00
|
|
|
|
char string[LINEWIDTH];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
int chars = 0;
|
|
|
|
|
int result;
|
|
|
|
|
|
2007-08-04 02:44:09 +00:00
|
|
|
|
wait_secs( 1 );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2007-02-13 05:20:52 +00:00
|
|
|
|
if( gotsig )
|
|
|
|
|
{
|
|
|
|
|
gotsig = 0;
|
|
|
|
|
tr_torrentStop( tor );
|
2007-07-18 17:31:00 +00:00
|
|
|
|
tr_natTraversalEnable( h, 0 );
|
2007-02-13 05:20:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
|
s = tr_torrentStat( tor );
|
|
|
|
|
|
2007-06-26 18:45:03 +00:00
|
|
|
|
if( s->status & TR_STATUS_CHECK_WAIT )
|
2007-05-28 18:37:47 +00:00
|
|
|
|
{
|
|
|
|
|
chars = snprintf( string, sizeof string,
|
2007-06-18 03:40:41 +00:00
|
|
|
|
"Waiting to check files... %.2f %%", 100.0 * s->percentDone );
|
2007-05-28 18:37:47 +00:00
|
|
|
|
}
|
2007-01-14 12:00:21 +00:00
|
|
|
|
else if( s->status & TR_STATUS_CHECK )
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{
|
2007-02-15 20:56:25 +00:00
|
|
|
|
chars = snprintf( string, sizeof string,
|
2007-06-18 03:40:41 +00:00
|
|
|
|
"Checking files... %.2f %%", 100.0 * s->percentDone );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if( s->status & TR_STATUS_DOWNLOAD )
|
|
|
|
|
{
|
2007-02-15 20:56:25 +00:00
|
|
|
|
chars = snprintf( string, sizeof string,
|
2006-07-16 19:39:23 +00:00
|
|
|
|
"Progress: %.2f %%, %d peer%s, dl from %d (%.2f KB/s), "
|
2007-06-18 03:40:41 +00:00
|
|
|
|
"ul to %d (%.2f KB/s) [%s]", 100.0 * s->percentDone,
|
2007-07-15 17:19:07 +00:00
|
|
|
|
s->peersConnected, ( s->peersConnected == 1 ) ? "" : "s",
|
2007-07-16 00:50:43 +00:00
|
|
|
|
s->peersSendingToUs, s->rateDownload,
|
|
|
|
|
s->peersGettingFromUs, s->rateUpload,
|
2007-02-15 20:56:25 +00:00
|
|
|
|
getStringRatio(s->ratio) );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if( s->status & TR_STATUS_SEED )
|
|
|
|
|
{
|
2007-02-15 20:56:25 +00:00
|
|
|
|
chars = snprintf( string, sizeof string,
|
|
|
|
|
"Seeding, uploading to %d of %d peer(s), %.2f KB/s [%s]",
|
2007-07-16 00:50:43 +00:00
|
|
|
|
s->peersGettingFromUs, s->peersTotal,
|
2007-02-15 20:56:25 +00:00
|
|
|
|
s->rateUpload, getStringRatio(s->ratio) );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
2007-02-13 05:20:52 +00:00
|
|
|
|
else if( s->status & TR_STATUS_STOPPING )
|
|
|
|
|
{
|
2007-02-15 20:56:25 +00:00
|
|
|
|
chars = snprintf( string, sizeof string, "Stopping..." );
|
2007-02-13 05:20:52 +00:00
|
|
|
|
}
|
2007-07-18 17:31:00 +00:00
|
|
|
|
else if( s->status & TR_STATUS_INACTIVE )
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-02-15 20:56:25 +00:00
|
|
|
|
if( ( signed )sizeof string > chars )
|
2007-02-13 04:21:29 +00:00
|
|
|
|
{
|
2007-02-15 20:56:25 +00:00
|
|
|
|
memset( &string[chars], ' ', sizeof string - 1 - chars );
|
2007-02-13 04:21:29 +00:00
|
|
|
|
}
|
2007-02-15 20:56:25 +00:00
|
|
|
|
string[sizeof string - 1] = '\0';
|
2006-10-05 18:37:38 +00:00
|
|
|
|
fprintf( stderr, "\r%s", string );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
2007-01-14 12:00:21 +00:00
|
|
|
|
if( s->error )
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{
|
2007-01-14 12:00:21 +00:00
|
|
|
|
fprintf( stderr, "\n%s\n", s->errorString );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
else if( verboseLevel > 0 )
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "\n" );
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
|
if( tr_getDone(tor) || tr_getComplete(tor) )
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{
|
|
|
|
|
result = system(finishCall);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fprintf( stderr, "\n" );
|
|
|
|
|
|
2007-01-14 12:00:21 +00:00
|
|
|
|
/* Try for 5 seconds to delete any port mappings for nat traversal */
|
2007-01-19 04:42:31 +00:00
|
|
|
|
tr_natTraversalEnable( h, 0 );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
for( i = 0; i < 10; i++ )
|
|
|
|
|
{
|
2007-02-06 04:26:40 +00:00
|
|
|
|
hstat = tr_handleStatus( h );
|
|
|
|
|
if( TR_NAT_TRAVERSAL_DISABLED == hstat->natTraversalStatus )
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{
|
2007-01-14 12:00:21 +00:00
|
|
|
|
/* Port mappings were deleted */
|
2006-07-16 19:39:23 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-08-04 02:44:09 +00:00
|
|
|
|
wait_msecs( 500 );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleanup:
|
2007-05-23 04:45:20 +00:00
|
|
|
|
tr_torrentClose( tor );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
tr_close( h );
|
|
|
|
|
|
2007-02-06 22:47:55 +00:00
|
|
|
|
return EXIT_SUCCESS;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int parseCommandLine( int argc, char ** argv )
|
|
|
|
|
{
|
|
|
|
|
for( ;; )
|
|
|
|
|
{
|
|
|
|
|
static struct option long_options[] =
|
|
|
|
|
{ { "help", no_argument, NULL, 'h' },
|
|
|
|
|
{ "info", no_argument, NULL, 'i' },
|
|
|
|
|
{ "scrape", no_argument, NULL, 's' },
|
2007-06-18 03:40:41 +00:00
|
|
|
|
{ "private", no_argument, NULL, 'r' },
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{ "verbose", required_argument, NULL, 'v' },
|
|
|
|
|
{ "port", required_argument, NULL, 'p' },
|
|
|
|
|
{ "upload", required_argument, NULL, 'u' },
|
|
|
|
|
{ "download", required_argument, NULL, 'd' },
|
|
|
|
|
{ "finish", required_argument, NULL, 'f' },
|
2007-06-18 03:40:41 +00:00
|
|
|
|
{ "create", required_argument, NULL, 'c' },
|
|
|
|
|
{ "comment", required_argument, NULL, 'm' },
|
|
|
|
|
{ "announce", required_argument, NULL, 'a' },
|
2006-09-25 18:37:45 +00:00
|
|
|
|
{ "nat-traversal", no_argument, NULL, 'n' },
|
2006-07-16 19:39:23 +00:00
|
|
|
|
{ 0, 0, 0, 0} };
|
|
|
|
|
|
|
|
|
|
int c, optind = 0;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
c = getopt_long( argc, argv, "hisrv:p:u:d:f:c:m:a:n:",
|
|
|
|
|
long_options, &optind );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
if( c < 0 )
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
switch( c )
|
|
|
|
|
{
|
|
|
|
|
case 'h':
|
|
|
|
|
showHelp = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'i':
|
|
|
|
|
showInfo = 1;
|
|
|
|
|
break;
|
2007-07-15 17:36:56 +00:00
|
|
|
|
#if 0
|
2006-07-16 19:39:23 +00:00
|
|
|
|
case 's':
|
|
|
|
|
showScrape = 1;
|
|
|
|
|
break;
|
2007-07-15 17:36:56 +00:00
|
|
|
|
#endif
|
2007-06-18 03:40:41 +00:00
|
|
|
|
case 'r':
|
|
|
|
|
isPrivate = 1;
|
|
|
|
|
break;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
case 'v':
|
|
|
|
|
verboseLevel = atoi( optarg );
|
|
|
|
|
break;
|
|
|
|
|
case 'p':
|
|
|
|
|
bindPort = atoi( optarg );
|
|
|
|
|
break;
|
|
|
|
|
case 'u':
|
|
|
|
|
uploadLimit = atoi( optarg );
|
|
|
|
|
break;
|
|
|
|
|
case 'd':
|
|
|
|
|
downloadLimit = atoi( optarg );
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
finishCall = optarg;
|
|
|
|
|
break;
|
2007-06-18 03:40:41 +00:00
|
|
|
|
case 'c':
|
|
|
|
|
sourceFile = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'm':
|
|
|
|
|
comment = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'a':
|
|
|
|
|
announce = optarg;
|
|
|
|
|
break;
|
2006-09-25 18:37:45 +00:00
|
|
|
|
case 'n':
|
|
|
|
|
natTraversal = 1;
|
|
|
|
|
break;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
default:
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( optind > argc - 1 )
|
|
|
|
|
{
|
|
|
|
|
return !showHelp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
torrentPath = argv[optind];
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sigHandler( int signal )
|
|
|
|
|
{
|
|
|
|
|
switch( signal )
|
|
|
|
|
{
|
|
|
|
|
case SIGINT:
|
2007-02-13 05:20:52 +00:00
|
|
|
|
gotsig = 1;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|