Changeset 8871


Ignore:
Timestamp:
Aug 5, 2009, 1:59:16 AM (13 years ago)
Author:
charles
Message:

(trunk) clean up the return value of tr_torrentParse()

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r8867 r8871  
    892892    switch( code )
    893893    {
    894         case TR_EINVALID:
     894        case TR_PARSE_ERR:
    895895            c->errqueue =
    896896                g_slist_append( c->errqueue, g_path_get_basename( msg ) );
    897897            break;
    898898
    899         case TR_EDUPLICATE:
     899        case TR_PARSE_DUPLICATE:
    900900            c->dupqueue = g_slist_append( c->dupqueue, g_strdup( msg ) );
    901901            break;
  • trunk/gtk/tr-core.c

    r8846 r8871  
    827827    switch( err )
    828828    {
    829         case TR_EINVALID:
     829        case TR_PARSE_ERR:
    830830            break;
    831831
    832         case TR_EDUPLICATE:
    833             g_message( "it's a duplicate" );
     832        case TR_PARSE_DUPLICATE:
    834833            /* don't complain about .torrent files in the watch directory
    835834             * that have already been added... that gets annoying and we
     
    911910
    912911        err = add_ctor( core, ctor, doPrompt, doNotify );
    913         if( err == TR_EINVALID )
    914             tr_core_errsig( core, TR_EINVALID, filename );
     912        if( err == TR_PARSE_ERR )
     913            tr_core_errsig( core, TR_PARSE_ERR, filename );
    915914    }
    916915}
  • trunk/gtk/tr-core.h

    r8846 r8871  
    8686enum tr_core_err
    8787{
    88     TR_CORE_ERR_ADD_TORRENT_ERR  = TR_EINVALID,
    89     TR_CORE_ERR_ADD_TORRENT_DUP  = TR_EDUPLICATE,
    90     TR_CORE_ERR_NO_MORE_TORRENTS /* finished adding a batch */
     88    TR_CORE_ERR_ADD_TORRENT_ERR  = TR_PARSE_ERR,
     89    TR_CORE_ERR_ADD_TORRENT_DUP  = TR_PARSE_DUPLICATE,
     90    TR_CORE_ERR_NO_MORE_TORRENTS = 1000 /* finished adding a batch */
    9191};
    9292
  • trunk/gtk/util.c

    r8847 r8871  
    306306    switch( err )
    307307    {
    308         case TR_EINVALID:
    309             fmt = _( "The torrent file \"%s\" contains invalid data." );
    310             break;
    311 
    312         case TR_EDUPLICATE:
    313             fmt = _( "The torrent file \"%s\" is already in use." ); break;
    314 
    315         default:
    316             fmt = _(
    317                 "The torrent file \"%s\" encountered an unknown error." );
    318             break;
     308        case TR_PARSE_ERR: fmt = _( "The torrent file \"%s\" contains invalid data." ); break;
     309        case TR_PARSE_DUPLICATE: fmt = _( "The torrent file \"%s\" is already in use." ); break;
     310        default: fmt = _( "The torrent file \"%s\" encountered an unknown error." ); break;
    319311    }
    320312    secondary = g_strdup_printf( fmt, filename );
  • trunk/libtransmission/metainfo.c

    r8776 r8871  
    136136***/
    137137
    138 static int
     138static tr_bool
    139139getfile( char        ** setme,
    140140         const char   * root,
    141141         tr_benc      * path )
    142142{
    143     int err;
    144 
    145     if( !tr_bencIsList( path ) )
    146     {
    147         err = TR_EINVALID;
    148     }
    149     else
     143    tr_bool success = FALSE;
     144
     145    if( tr_bencIsList( path ) )
    150146    {
    151147        struct evbuffer * buf = evbuffer_new( );
     
    168164        /* fprintf( stderr, "[%s]\n", *setme ); */
    169165        evbuffer_free( buf );
    170         err = 0;
    171     }
    172 
    173     return err;
     166        success = TRUE;
     167    }
     168
     169    return success;
    174170}
    175171
     
    204200                    return "path";
    205201
    206             if( getfile( &inf->files[i].name, inf->name, path ) )
     202            if( !getfile( &inf->files[i].name, inf->name, path ) )
    207203                return "path";
    208204
     
    462458}
    463459
    464 int
     460tr_bool
    465461tr_metainfoParse( const tr_session * session,
    466                   tr_info *        inf,
    467                   const tr_benc meta_in )
     462                  tr_info          * inf,
     463                  const tr_benc    * meta_in )
    468464{
    469465    const char * badTag = tr_metainfoParseImpl( session, inf, meta_in );
     466    const tr_bool success = badTag == NULL;
    470467
    471468    if( badTag )
     
    473470        tr_nerr( inf->name, _( "Invalid metadata entry \"%s\"" ), badTag );
    474471        tr_metainfoFree( inf );
    475         return TR_EINVALID;
    476     }
    477     return 0;
     472    }
     473
     474    return success;
    478475}
    479476
  • trunk/libtransmission/metainfo.h

    r8637 r8871  
    3434struct tr_benc;
    3535
    36 int  tr_metainfoParse( const tr_session     * session,
    37                        tr_info              * info,
    38                        const struct tr_benc * benc );
     36tr_bool  tr_metainfoParse( const tr_session     * session,
     37                           tr_info              * info,
     38                           const struct tr_benc * benc );
    3939
    4040void tr_metainfoRemoveSaved( const tr_session * session,
  • trunk/libtransmission/rpcimpl.c

    r8747 r8871  
    927927        tr_bencFree( &fields );
    928928    }
    929     else if( err == TR_EDUPLICATE )
     929    else if( err == TR_PARSE_DUPLICATE )
    930930    {
    931931        result = "duplicate torrent";
    932932    }
    933     else if( err == TR_EINVALID )
     933    else if( err == TR_PARSE_ERR )
    934934    {
    935935        result = "invalid or corrupt torrent file";
  • trunk/libtransmission/torrent.c

    r8869 r8871  
    671671}
    672672
    673 int
    674 tr_torrentParse( const tr_ctor     * ctor,
    675                  tr_info           * setmeInfo )
    676 {
    677     int             err = 0;
     673tr_parse_result
     674tr_torrentParse( const tr_ctor * ctor, tr_info * setmeInfo )
     675{
    678676    int             doFree;
     677    tr_bool         didParse;
     678    tr_parse_result result;
    679679    tr_info         tmp;
    680680    const tr_benc * metainfo;
     
    685685    memset( setmeInfo, 0, sizeof( tr_info ) );
    686686
    687     if( !err && tr_ctorGetMetainfo( ctor, &metainfo ) )
    688         return TR_EINVALID;
    689 
    690     err = tr_metainfoParse( session, setmeInfo, metainfo );
    691     doFree = !err && ( setmeInfo == &tmp );
    692 
    693     if( !err && !getBlockSize( setmeInfo->pieceSize ) )
    694         err = TR_EINVALID;
    695 
    696     if( !err && session && tr_torrentExists( session, setmeInfo->hash ) )
    697         err = TR_EDUPLICATE;
     687    if( tr_ctorGetMetainfo( ctor, &metainfo ) )
     688        return TR_PARSE_ERR;
     689
     690    didParse = tr_metainfoParse( session, setmeInfo, metainfo );
     691    doFree = didParse && ( setmeInfo == &tmp );
     692
     693    if( didParse && !getBlockSize( setmeInfo->pieceSize ) )
     694        result = TR_PARSE_ERR;
     695
     696    if( didParse && session && tr_torrentExists( session, setmeInfo->hash ) )
     697        result = TR_PARSE_DUPLICATE;
    698698
    699699    if( doFree )
    700700        tr_metainfoFree( setmeInfo );
    701701
    702     return err;
     702    return result;
    703703}
    704704
     
    19611961        /* try to parse it back again, to make sure it's good */
    19621962        memset( &tmpInfo, 0, sizeof( tr_info ) );
    1963         if( !tr_metainfoParse( tor->session, &tmpInfo, &metainfo ) )
     1963        if( tr_metainfoParse( tor->session, &tmpInfo, &metainfo ) )
    19641964        {
    19651965            /* it's good, so keep these new trackers and free the old ones */
  • trunk/libtransmission/transmission.h

    r8869 r8871  
    874874const char* tr_ctorGetSourceFile( const tr_ctor * ctor );
    875875
    876 #define TR_EINVALID     1
    877 #define TR_EDUPLICATE   2
    878 
    879 /**
    880  * Parses the specified metainfo.
    881  * Returns 0 if it parsed successfully and can be added to Transmission.
    882  * Returns TR_EINVALID if it couldn't be parsed.
    883  * Returns TR_EDUPLICATE if it parsed but can't be added.
    884  *     "download-dir" must be set to test for TR_EDUPLICATE.
    885  *
    886  * If setme_info is non-NULL and parsing is successful
    887  * (that is, if TR_EINVALID is not returned), then the parsed
    888  * metainfo is stored in setme_info and should be freed by the
    889  * caller via tr_metainfoFree().
    890  *
    891  * If the constructor's session variable is NULL,
    892  * info.torrent will be NULL and the duplicate check will not be performed.
    893  */
    894 int tr_torrentParse( const tr_ctor * ctor,
    895                      tr_info       * setme_info_or_NULL );
     876typedef enum
     877{
     878    TR_PARSE_OK,
     879    TR_PARSE_ERR,
     880    TR_PARSE_DUPLICATE
     881}
     882tr_parse_result;
     883
     884/**
     885 * @brief Parses the specified metainfo
     886 *
     887 * @return TR_PARSE_ERR if parsing failed;
     888 *         TR_PARSE_OK if parsing succeeded and it's not a duplicate;
     889 *         TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate.
     890 *
     891 * @param setme_info If parsing is successful and setme_info is non-NULL,
     892 *                   the parsed metainfo is stored there and sould be freed
     893 *                   by calling tr_metainfoFree() when no longer needed.
     894 *
     895 * Notes:
     896 *
     897 * 1. tr_torrentParse() won't be able to check for duplicates -- and therefore
     898 *    won't return TR_PARSE_DUPLICATE -- unless ctor's "download-dir" and
     899 *    session variable is set.
     900 *
     901 * 2. setme_info->torrent's value can't be set unless ctor's session variable
     902 *    is set.
     903 */
     904tr_parse_result  tr_torrentParse( const tr_ctor  * ctor,
     905                                  tr_info        * setme_info_or_NULL );
    896906
    897907/** @brief free a metainfo
  • trunk/macosx/Controller.m

    r8866 r8871  
    800800        if (result != TR_OK)
    801801        {
    802             if (result == TR_EDUPLICATE)
     802            if (result == TR_PARSE_DUPLICATE)
    803803                [self duplicateOpenAlert: [NSString stringWithUTF8String: info.name]];
    804             else if (result == TR_EINVALID)
     804            else if (result == TR_PARSE_ERR)
    805805            {
    806806                if (type != ADD_AUTO)
Note: See TracChangeset for help on using the changeset viewer.