mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
(#814) require a valid announce URL when creating torrents
This commit is contained in:
parent
363a583391
commit
910d77ae12
6 changed files with 85 additions and 50 deletions
|
@ -92,12 +92,12 @@ refresh_cb ( gpointer user_data )
|
||||||
{
|
{
|
||||||
if( ui->builder->failed )
|
if( ui->builder->failed )
|
||||||
{
|
{
|
||||||
const char * reason = ui->builder->abortFlag
|
char * reason = ui->builder->abortFlag
|
||||||
? _("Torrent creation cancelled")
|
? g_strdup( _( "Torrent creation cancelled" ) )
|
||||||
: _("Torrent creation failed");
|
: g_strdup_printf( _( "Torrent creation failed: %s" ), ui->builder->error );
|
||||||
|
|
||||||
gtk_progress_bar_set_text( p, reason );
|
gtk_progress_bar_set_text( p, reason );
|
||||||
gtk_progress_bar_set_fraction( p, 0 );
|
gtk_progress_bar_set_fraction( p, 0 );
|
||||||
|
g_free( reason );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -205,7 +205,8 @@ getHashInfo ( tr_metainfo_builder * b )
|
||||||
totalRemain = b->totalSize;
|
totalRemain = b->totalSize;
|
||||||
fp = fopen( b->files[fileIndex].filename, "rb" );
|
fp = fopen( b->files[fileIndex].filename, "rb" );
|
||||||
if( !fp ) {
|
if( !fp ) {
|
||||||
tr_err( _( "Couldn't open \"%s\": %s" ), b->files[fileIndex].filename, tr_strerror( errno ) );
|
snprintf( b->error, sizeof( b->error ), _( "Couldn't open \"%s\": %s" ), b->files[fileIndex].filename, tr_strerror( errno ) );
|
||||||
|
tr_err( "%s", b->error );
|
||||||
tr_free( ret );
|
tr_free( ret );
|
||||||
b->failed = 1;
|
b->failed = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -234,7 +235,10 @@ getHashInfo ( tr_metainfo_builder * b )
|
||||||
if( ++fileIndex < b->fileCount ) {
|
if( ++fileIndex < b->fileCount ) {
|
||||||
fp = fopen( b->files[fileIndex].filename, "rb" );
|
fp = fopen( b->files[fileIndex].filename, "rb" );
|
||||||
if( !fp ) {
|
if( !fp ) {
|
||||||
tr_err( _( "Couldn't open \"%s\": %s" ), b->files[fileIndex].filename, tr_strerror( errno ) );
|
snprintf( b->error, sizeof( b->error ),
|
||||||
|
_( "Couldn't open \"%s\": %s" ),
|
||||||
|
b->files[fileIndex].filename, tr_strerror( errno ) );
|
||||||
|
tr_err( "%s", b->error );
|
||||||
tr_free( ret );
|
tr_free( ret );
|
||||||
b->failed = 1;
|
b->failed = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -249,6 +253,7 @@ getHashInfo ( tr_metainfo_builder * b )
|
||||||
walk += SHA_DIGEST_LENGTH;
|
walk += SHA_DIGEST_LENGTH;
|
||||||
|
|
||||||
if( b->abortFlag ) {
|
if( b->abortFlag ) {
|
||||||
|
snprintf( b->error, sizeof( b->error ), _( "Torrent creation cancelled" ) );
|
||||||
b->failed = 1;
|
b->failed = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -366,7 +371,8 @@ makeInfoDict ( tr_benc * dict,
|
||||||
tr_bencInitInt( val, builder->isPrivate ? 1 : 0 );
|
tr_bencInitInt( val, builder->isPrivate ? 1 : 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
|
static void
|
||||||
|
tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
|
||||||
{
|
{
|
||||||
int n = 5;
|
int n = 5;
|
||||||
tr_benc top, *val;
|
tr_benc top, *val;
|
||||||
|
@ -377,25 +383,34 @@ static void tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
|
||||||
|
|
||||||
val = tr_bencDictAdd( &top, "announce" );
|
val = tr_bencDictAdd( &top, "announce" );
|
||||||
tr_bencInitStrDup( val, builder->announce );
|
tr_bencInitStrDup( val, builder->announce );
|
||||||
|
if( tr_httpParseUrl( builder->announce, -1, NULL, NULL, NULL ) )
|
||||||
if( builder->comment && *builder->comment ) {
|
{
|
||||||
val = tr_bencDictAdd( &top, "comment" );
|
snprintf( builder->error, sizeof( builder->error ), _( "Invalid announce URL" ) );
|
||||||
tr_bencInitStrDup( val, builder->comment );
|
tr_err( "%s", builder->error );
|
||||||
|
builder->failed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( !builder->failed && !builder->abortFlag )
|
||||||
|
{
|
||||||
|
if( builder->comment && *builder->comment ) {
|
||||||
|
val = tr_bencDictAdd( &top, "comment" );
|
||||||
|
tr_bencInitStrDup( val, builder->comment );
|
||||||
|
}
|
||||||
|
|
||||||
val = tr_bencDictAdd( &top, "created by" );
|
val = tr_bencDictAdd( &top, "created by" );
|
||||||
tr_bencInitStrDup( val, TR_NAME "/" LONG_VERSION_STRING );
|
tr_bencInitStrDup( val, TR_NAME "/" LONG_VERSION_STRING );
|
||||||
|
|
||||||
val = tr_bencDictAdd( &top, "creation date" );
|
val = tr_bencDictAdd( &top, "creation date" );
|
||||||
tr_bencInitInt( val, time(0) );
|
tr_bencInitInt( val, time(0) );
|
||||||
|
|
||||||
val = tr_bencDictAdd( &top, "encoding" );
|
val = tr_bencDictAdd( &top, "encoding" );
|
||||||
tr_bencInitStrDup( val, "UTF-8" );
|
tr_bencInitStrDup( val, "UTF-8" );
|
||||||
|
|
||||||
val = tr_bencDictAdd( &top, "info" );
|
val = tr_bencDictAdd( &top, "info" );
|
||||||
tr_bencInit( val, TYPE_DICT );
|
tr_bencInit( val, TYPE_DICT );
|
||||||
tr_bencDictReserve( val, 666 );
|
tr_bencDictReserve( val, 666 );
|
||||||
makeInfoDict( val, builder );
|
makeInfoDict( val, builder );
|
||||||
|
}
|
||||||
|
|
||||||
/* save the file */
|
/* save the file */
|
||||||
if ( !builder->failed && !builder->abortFlag ) {
|
if ( !builder->failed && !builder->abortFlag ) {
|
||||||
|
@ -403,12 +418,17 @@ static void tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
|
||||||
char * pch = tr_bencSave( &top, &n );
|
char * pch = tr_bencSave( &top, &n );
|
||||||
FILE * fp = fopen( builder->outputFile, "wb+" );
|
FILE * fp = fopen( builder->outputFile, "wb+" );
|
||||||
nmemb = n;
|
nmemb = n;
|
||||||
if( fp == NULL )
|
if( fp == NULL ) {
|
||||||
|
snprintf( builder->error, sizeof( builder->error ), _( "Couldn't open \"%s\": %s" ), builder->outputFile, tr_strerror( errno ) );
|
||||||
|
tr_err( "%s", builder->error );
|
||||||
builder->failed = 1;
|
builder->failed = 1;
|
||||||
else if( fwrite( pch, 1, nmemb, fp ) != nmemb )
|
} else if( fwrite( pch, 1, nmemb, fp ) != nmemb ) {
|
||||||
|
snprintf( builder->error, sizeof( builder->error ), _( "Couldn't save file \"%s\": %s" ), builder->outputFile, tr_strerror( errno ) );
|
||||||
|
tr_err( "%s", builder->error );
|
||||||
builder->failed = 1;
|
builder->failed = 1;
|
||||||
|
fclose( fp );
|
||||||
|
}
|
||||||
tr_free( pch );
|
tr_free( pch );
|
||||||
fclose( fp );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
|
|
|
@ -58,6 +58,7 @@ typedef struct tr_metainfo_builder
|
||||||
int abortFlag;
|
int abortFlag;
|
||||||
int isDone;
|
int isDone;
|
||||||
int failed; /* only meaningful if isDone is set */
|
int failed; /* only meaningful if isDone is set */
|
||||||
|
char error[1024]; /* only meaningful if failed is set */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*** This is an implementation detail.
|
*** This is an implementation detail.
|
||||||
|
|
|
@ -32,8 +32,6 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h> /* unlink, stat */
|
#include <unistd.h> /* unlink, stat */
|
||||||
|
|
||||||
#include <miniupnp/miniwget.h> /* parseURL */
|
|
||||||
|
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
#include "bencode.h"
|
#include "bencode.h"
|
||||||
#include "crypto.h" /* tr_sha1 */
|
#include "crypto.h" /* tr_sha1 */
|
||||||
|
@ -42,30 +40,6 @@
|
||||||
#include "trcompat.h" /* strlcpy */
|
#include "trcompat.h" /* strlcpy */
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
tr_httpParseUrl( const char * url_in, int len,
|
|
||||||
char ** setme_host, int * setme_port, char ** setme_path )
|
|
||||||
{
|
|
||||||
char * url = tr_strndup( url_in, len );
|
|
||||||
char * path;
|
|
||||||
char host[4096+1];
|
|
||||||
unsigned short port;
|
|
||||||
int success;
|
|
||||||
|
|
||||||
success = parseURL( url, host, &port, &path );
|
|
||||||
|
|
||||||
if( success ) {
|
|
||||||
*setme_host = tr_strdup( host );
|
|
||||||
*setme_port = port;
|
|
||||||
*setme_path = tr_strdup( path );
|
|
||||||
}
|
|
||||||
|
|
||||||
tr_free( url );
|
|
||||||
|
|
||||||
return !success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Local prototypes
|
* Local prototypes
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
|
@ -43,6 +43,8 @@
|
||||||
#include <kernel/OS.h>
|
#include <kernel/OS.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <miniupnp/miniwget.h> /* parseURL */
|
||||||
|
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
#include "trcompat.h"
|
#include "trcompat.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -973,3 +975,33 @@ tr_sha1_to_hex( char * out, const uint8_t * sha1 )
|
||||||
}
|
}
|
||||||
*out = '\0';
|
*out = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
****
|
||||||
|
***/
|
||||||
|
|
||||||
|
int
|
||||||
|
tr_httpParseUrl( const char * url_in, int len,
|
||||||
|
char ** setme_host,
|
||||||
|
int * setme_port,
|
||||||
|
char ** setme_path )
|
||||||
|
{
|
||||||
|
char * url = tr_strndup( url_in, len );
|
||||||
|
char * path;
|
||||||
|
char host[4096+1];
|
||||||
|
unsigned short port;
|
||||||
|
int success;
|
||||||
|
|
||||||
|
success = parseURL( url, host, &port, &path );
|
||||||
|
|
||||||
|
if( success ) {
|
||||||
|
if( setme_host ) *setme_host = tr_strdup( host );
|
||||||
|
if( setme_port ) *setme_port = port;
|
||||||
|
if( setme_path ) *setme_path = tr_strdup( path );
|
||||||
|
}
|
||||||
|
|
||||||
|
tr_free( url );
|
||||||
|
|
||||||
|
return !success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,14 @@ int tr_compareUint32( uint32_t a, uint32_t b );
|
||||||
|
|
||||||
void tr_sha1_to_hex( char * out, const uint8_t * sha1 );
|
void tr_sha1_to_hex( char * out, const uint8_t * sha1 );
|
||||||
|
|
||||||
|
|
||||||
|
int tr_httpParseUrl( const char * url,
|
||||||
|
int url_len,
|
||||||
|
char ** setme_host,
|
||||||
|
int * setme_port,
|
||||||
|
char ** setme_path );
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
****
|
****
|
||||||
***/
|
***/
|
||||||
|
|
Loading…
Reference in a new issue