Changeset 626 for trunk/libtransmission


Ignore:
Timestamp:
Jul 16, 2006, 11:40:22 PM (15 years ago)
Author:
joshe
Message:

Allow frontend to supply a custom function for displaying libtransmission errors.

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r346 r626  
    266266        {
    267267            /* Node exists but isn't a file */
    268             printf( "Remove %s, it's in the way.\n", path );
     268            /* XXX this should be reported to the frontend somehow */
     269            tr_err( "Remove %s, it's in the way.", path );
    269270            free( path );
    270271            return 1;
  • trunk/libtransmission/metainfo.c

    r609 r626  
    6060    if( stat( path, &sb ) )
    6161    {
    62         fprintf( stderr, "Could not stat file (%s)\n", path );
     62        tr_err( "Could not stat file (%s)", path );
    6363        return 1;
    6464    }
    6565    if( ( sb.st_mode & S_IFMT ) != S_IFREG )
    6666    {
    67         fprintf( stderr, "Not a regular file (%s)\n", path );
     67        tr_err( "Not a regular file (%s)", path );
    6868        return 1;
    6969    }
     
    7878    if( !file )
    7979    {
    80         fprintf( stderr, "Could not open file (%s)\n", path );
     80        tr_err( "Could not open file (%s)", path );
    8181        return 1;
    8282    }
     
    8585    if( fread( buf, sb.st_size, 1, file ) != 1 )
    8686    {
    87         fprintf( stderr, "Read error (%s)\n", path );
     87        tr_err( "Read error (%s)", path );
    8888        free( buf );
    8989        fclose( file );
     
    9595    if( tr_bencLoad( buf, sb.st_size, &meta, NULL ) )
    9696    {
    97         fprintf( stderr, "Error while parsing bencoded data\n" );
     97        tr_err( "Error while parsing bencoded data" );
    9898        free( buf );
    9999        return 1;
     
    103103    if( !( beInfo = tr_bencDictFind( &meta, "info" ) ) )
    104104    {
    105         fprintf( stderr, "Could not find \"info\" dictionary\n" );
     105        tr_err( "Could not find \"info\" dictionary" );
    106106        tr_bencFree( &meta );
    107107        free( buf );
     
    123123        if( !file )
    124124        {
    125             fprintf( stderr, "Could not open file (%s) (%s)\n", inf->torrent, strerror(errno) );
     125            tr_err( "Could not open file (%s) (%s)",
     126                    inf->torrent, strerror(errno) );
    126127            tr_bencFree( &meta );
    127128            free( buf );
     
    131132        if( fwrite( buf, sb.st_size, 1, file ) != 1 )
    132133        {
    133             fprintf( stderr, "Write error (%s)\n", inf->torrent );
     134            tr_err( "Write error (%s)", inf->torrent );
    134135            tr_bencFree( &meta );
    135136            free( buf );
     
    149150    if( !( val = tr_bencDictFind( &meta, "announce" ) ) )
    150151    {
    151         fprintf( stderr, "No \"announce\" entry\n" );
     152        tr_err( "No \"announce\" entry" );
    152153        tr_bencFree( &meta );
    153154        return 1;
     
    164165    if( strncmp( s3, "http://", 7 ) )
    165166    {
    166         fprintf( stderr, "Invalid announce URL (%s)\n",
    167                  inf->trackerAddress );
     167        tr_err( "Invalid announce URL (%s)", inf->trackerAddress );
    168168        tr_bencFree( &meta );
    169169        return 1;
     
    185185    else
    186186    {
    187         fprintf( stderr, "Invalid announce URL (%s)\n",
    188                  inf->trackerAddress );
     187        tr_err( "Invalid announce URL (%s)", inf->trackerAddress );
    189188        tr_bencFree( &meta );
    190189        return 1;
     
    195194    if( !( val = tr_bencDictFind( beInfo, "piece length" ) ) )
    196195    {
    197         fprintf( stderr, "No \"piece length\" entry\n" );
     196        tr_err( "No \"piece length\" entry" );
    198197        tr_bencFree( &meta );
    199198        return 1;
     
    205204    if( val->val.s.i % SHA_DIGEST_LENGTH )
    206205    {
    207         fprintf( stderr, "Invalid \"piece\" string (size is %d)\n",
    208                  val->val.s.i );
     206        tr_err( "Invalid \"piece\" string (size is %d)", val->val.s.i );
    209207        tr_bencFree( &meta );
    210208        return 1;
     
    264262        ( inf->totalSize + inf->pieceSize - 1 ) / inf->pieceSize )
    265263    {
    266         fprintf( stderr, "Size of hashes and files don't match\n" );
     264        tr_err( "Size of hashes and files don't match" );
    267265        free( inf->pieces );
    268266        tr_bencFree( &meta );
  • trunk/libtransmission/tracker.c

    r526 r626  
    636636            ( ret == TR_RESOLVE_WAIT && tr_date() > date + 10000 ) )
    637637        {
    638             fprintf( stderr, "Could not resolve %s\n", inf->trackerAddress );
     638            tr_err( "Could not resolve %s", inf->trackerAddress );
    639639            tr_netResolveClose( resolve );
    640640            return 1;
     
    661661        if( ret & TR_NET_CLOSE )
    662662        {
    663             fprintf( stderr, "Could not connect to tracker\n" );
     663            tr_err( "Could not connect to tracker" );
    664664            tr_netClose( s );
    665665            return 1;
     
    669669            if( tr_date() > date + 10000 )
    670670            {
    671                 fprintf( stderr, "Could not connect to tracker\n" );
     671                tr_err( "Could not connect to tracker" );
    672672                tr_netClose( s );
    673673                return 1;
     
    693693            if( tr_date() > date + 10000 )
    694694            {
    695                 fprintf( stderr, "Could not read from tracker\n" );
     695                tr_err( "Could not read from tracker" );
    696696                tr_netClose( s );
    697697                return 1;
     
    707707    if( pos < 1 )
    708708    {
    709         fprintf( stderr, "Could not read from tracker\n" );
     709        tr_err( "Could not read from tracker" );
    710710        tr_netClose( s );
    711711        return 1;
  • trunk/libtransmission/transmission.h

    r405 r626  
    5858
    5959/***********************************************************************
     60 * tr_setErrorFunction
     61 ***********************************************************************
     62 * Sets the function used to display libtransmission errors.  A NULL
     63 * function means to use the default, which simple prints the message
     64 * to stderr.  The function's prototype should look like this:
     65 * void myErrFunc( const char * errstr );
     66 **********************************************************************/
     67void tr_setErrorFunction( void (*func)( const char * ) );
     68
     69/***********************************************************************
    6070 * tr_getPrefsDirectory
    6171 ***********************************************************************
  • trunk/libtransmission/utils.c

    r310 r626  
    2424
    2525#include "transmission.h"
     26
     27static void (*errorFunc)( const char * );
     28
     29void tr_setErrorFunction( void (*func)( const char * ) )
     30{
     31    errorFunc = func;
     32}
    2633
    2734void tr_msg( int level, char * msg, ... )
     
    5158    vsnprintf( string, sizeof( string ), msg, args );
    5259    va_end( args );
    53     fprintf( stderr, "%s\n", string );
     60
     61    if( NULL == errorFunc )
     62    {
     63        fprintf( stderr, "%s\n", string );
     64    }
     65    else
     66    {
     67        errorFunc( string );
     68    }
    5469}
    5570
Note: See TracChangeset for help on using the changeset viewer.