Changeset 5356


Ignore:
Timestamp:
Mar 24, 2008, 3:58:06 PM (14 years ago)
Author:
charles
Message:

(#814) require a valid announce URL when creating torrents

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/makemeta-ui.c

    r5314 r5356  
    9393        if( ui->builder->failed )
    9494        {
    95             const char * reason = ui->builder->abortFlag
    96                 ? _("Torrent creation cancelled")
    97                 : _("Torrent creation failed");
    98 
     95            char * reason = ui->builder->abortFlag
     96                ? g_strdup( _( "Torrent creation cancelled" ) )
     97                : g_strdup_printf( _( "Torrent creation failed: %s" ), ui->builder->error );
    9998            gtk_progress_bar_set_text( p, reason );
    10099            gtk_progress_bar_set_fraction( p, 0 );
     100            g_free( reason );
    101101        }
    102102        else
  • trunk/libtransmission/makemeta.c

    r5221 r5356  
    206206    fp = fopen( b->files[fileIndex].filename, "rb" );
    207207    if( !fp ) {
    208         tr_err( _( "Couldn't open \"%s\": %s" ), b->files[fileIndex].filename, tr_strerror( errno ) );
     208        snprintf( b->error, sizeof( b->error ), _( "Couldn't open \"%s\": %s" ), b->files[fileIndex].filename, tr_strerror( errno ) );
     209        tr_err( "%s", b->error );
    209210        tr_free( ret );
    210211        b->failed = 1;
     
    235236                    fp = fopen( b->files[fileIndex].filename, "rb" );
    236237                    if( !fp ) {
    237                         tr_err( _( "Couldn't open \"%s\": %s" ), b->files[fileIndex].filename, tr_strerror( errno ) );
     238                        snprintf( b->error, sizeof( b->error ),
     239                                  _( "Couldn't open \"%s\": %s" ),
     240                                  b->files[fileIndex].filename, tr_strerror( errno ) );
     241                        tr_err( "%s", b->error );
    238242                        tr_free( ret );
    239243                        b->failed = 1;
     
    250254
    251255        if( b->abortFlag ) {
     256            snprintf( b->error, sizeof( b->error ), _( "Torrent creation cancelled" ) );
    252257            b->failed = 1;
    253258            break;
     
    367372}
    368373
    369 static void tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
     374static void
     375tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
    370376{
    371377    int n = 5;
     
    378384    val = tr_bencDictAdd( &top, "announce" );
    379385    tr_bencInitStrDup( val, builder->announce );
     386    if( tr_httpParseUrl( builder->announce, -1, NULL, NULL, NULL ) )
     387    {
     388        snprintf( builder->error, sizeof( builder->error ), _( "Invalid announce URL" ) );
     389        tr_err( "%s", builder->error );
     390        builder->failed = 1;
     391    }
    380392   
    381     if( builder->comment && *builder->comment ) {
    382         val = tr_bencDictAdd( &top, "comment" );
    383         tr_bencInitStrDup( val, builder->comment );
    384     }
    385 
    386     val = tr_bencDictAdd( &top, "created by" );
    387     tr_bencInitStrDup( val, TR_NAME "/" LONG_VERSION_STRING );
    388 
    389     val = tr_bencDictAdd( &top, "creation date" );
    390     tr_bencInitInt( val, time(0) );
    391 
    392     val = tr_bencDictAdd( &top, "encoding" );
    393     tr_bencInitStrDup( val, "UTF-8" );
    394 
    395     val = tr_bencDictAdd( &top, "info" );
    396     tr_bencInit( val, TYPE_DICT );
    397     tr_bencDictReserve( val, 666 );
    398     makeInfoDict( val, builder );
     393    if( !builder->failed && !builder->abortFlag )
     394    {
     395        if( builder->comment && *builder->comment ) {
     396            val = tr_bencDictAdd( &top, "comment" );
     397            tr_bencInitStrDup( val, builder->comment );
     398        }
     399
     400        val = tr_bencDictAdd( &top, "created by" );
     401        tr_bencInitStrDup( val, TR_NAME "/" LONG_VERSION_STRING );
     402
     403        val = tr_bencDictAdd( &top, "creation date" );
     404        tr_bencInitInt( val, time(0) );
     405
     406        val = tr_bencDictAdd( &top, "encoding" );
     407        tr_bencInitStrDup( val, "UTF-8" );
     408
     409        val = tr_bencDictAdd( &top, "info" );
     410        tr_bencInit( val, TYPE_DICT );
     411        tr_bencDictReserve( val, 666 );
     412        makeInfoDict( val, builder );
     413    }
    399414
    400415    /* save the file */
     
    404419        FILE * fp = fopen( builder->outputFile, "wb+" );
    405420        nmemb = n;
    406         if( fp == NULL )
     421        if( fp == NULL ) {
     422            snprintf( builder->error, sizeof( builder->error ), _( "Couldn't open \"%s\": %s" ), builder->outputFile, tr_strerror( errno ) );
     423            tr_err( "%s", builder->error );
    407424            builder->failed = 1;
    408         else if( fwrite( pch, 1, nmemb, fp ) != nmemb )
     425        } else if( fwrite( pch, 1, nmemb, fp ) != nmemb ) {
     426            snprintf( builder->error, sizeof( builder->error ), _( "Couldn't save file \"%s\": %s" ), builder->outputFile, tr_strerror( errno ) );
     427            tr_err( "%s", builder->error );
    409428            builder->failed = 1;
     429            fclose( fp );
     430        }
    410431        tr_free( pch );
    411         fclose( fp );
    412432    }
    413433
  • trunk/libtransmission/makemeta.h

    r4404 r5356  
    5959    int isDone;
    6060    int failed; /* only meaningful if isDone is set */
     61    char error[1024]; /* only meaningful if failed is set */
    6162
    6263    /**
  • trunk/libtransmission/metainfo.c

    r5337 r5356  
    3333#include <unistd.h> /* unlink, stat */
    3434
    35 #include <miniupnp/miniwget.h> /* parseURL */
    36 
    3735#include "transmission.h"
    3836#include "bencode.h"
     
    4240#include "trcompat.h" /* strlcpy */
    4341#include "utils.h"
    44 
    45 
    46 static int
    47 tr_httpParseUrl( const char * url_in, int len,
    48                  char ** setme_host, int * setme_port, char ** setme_path )
    49 {
    50     char * url = tr_strndup( url_in, len );
    51     char * path;
    52     char host[4096+1];
    53     unsigned short port;
    54     int success;
    55 
    56     success = parseURL( url, host, &port, &path );
    57 
    58     if( success ) {
    59         *setme_host = tr_strdup( host );
    60         *setme_port = port;
    61         *setme_path = tr_strdup( path );
    62     }
    63 
    64     tr_free( url );
    65 
    66     return !success;
    67 }
    6842
    6943/***********************************************************************
  • trunk/libtransmission/utils.c

    r5300 r5356  
    4444#endif
    4545
     46#include <miniupnp/miniwget.h> /* parseURL */
     47
    4648#include "transmission.h"
    4749#include "trcompat.h"
     
    974976    *out = '\0';
    975977}
     978
     979/***
     980****
     981***/
     982
     983int
     984tr_httpParseUrl( const char * url_in, int len,
     985                 char ** setme_host,
     986                 int * setme_port,
     987                 char ** setme_path )
     988{
     989    char * url = tr_strndup( url_in, len );
     990    char * path;
     991    char host[4096+1];
     992    unsigned short port;
     993    int success;
     994
     995    success = parseURL( url, host, &port, &path );
     996
     997    if( success ) {
     998        if( setme_host ) *setme_host = tr_strdup( host );
     999        if( setme_port ) *setme_port = port;
     1000        if( setme_path ) *setme_path = tr_strdup( path );
     1001    }
     1002
     1003    tr_free( url );
     1004
     1005    return !success;
     1006}
     1007
  • trunk/libtransmission/utils.h

    r5291 r5356  
    163163void tr_sha1_to_hex( char * out, const uint8_t * sha1 );
    164164
     165
     166int tr_httpParseUrl( const char * url,
     167                     int          url_len,
     168                     char     ** setme_host,
     169                     int       * setme_port,
     170                     char     ** setme_path );
     171
     172
    165173/***
    166174****
Note: See TracChangeset for help on using the changeset viewer.