Changeset 9531


Ignore:
Timestamp:
Nov 20, 2009, 4:38:19 AM (9 years ago)
Author:
charles
Message:

(trunk libT) #2096: add code magnet URL parser and unit tests

Location:
trunk/libtransmission
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Makefile.am

    r9494 r9531  
    2828    JSON_parser.c \
    2929    list.c \
     30    magnet.c \
    3031    makemeta.c \
    3132    metainfo.c \
     
    7475    JSON_parser.h \
    7576    list.h \
     77    magnet.h \
    7678    makemeta.h \
    7779    metainfo.h \
     
    109111    clients-test \
    110112    json-test \
     113    magnet-test \
    111114    peer-msgs-test \
    112115    rpc-test \
     
    147150json_test_LDFLAGS = ${apps_ldflags}
    148151
     152magnet_test_SOURCES = magnet-test.c
     153magnet_test_LDADD = ${apps_ldadd}
     154magnet_test_LDFLAGS = ${apps_ldflags}
     155
    149156rpc_test_SOURCES = rpc-test.c
    150157rpc_test_LDADD = ${apps_ldadd}
  • trunk/libtransmission/utils-test.c

    r9463 r9531  
    99#include "crypto.h"
    1010
     11/* #define VERBOSE */
    1112#undef VERBOSE
    1213#define NUM_LOOPS 1
     
    282283}
    283284
     285static int
     286test_hex( void )
     287{
     288    char hex1[41];
     289    char hex2[41];
     290    uint8_t sha1[20];
     291    /*uint8_t sha2[20];*/
     292
     293    memcpy( hex1, "fb5ef5507427b17e04b69cef31fa3379b456735a", 41 );
     294    tr_hex_to_sha1( sha1, hex1 );
     295    tr_sha1_to_hex( hex2, sha1 );
     296    check( !strcmp( hex1, hex2 ) )
     297
     298    return 0;
     299}
     300
    284301int
    285302main( void )
     
    309326    tr_free( out );
    310327
     328    if( ( i = test_hex( ) ) )
     329        return i;
    311330    if( ( i = test_lowerbound( ) ) )
    312331        return i;
  • trunk/libtransmission/utils.c

    r9497 r9531  
    903903
    904904void
    905 tr_sha1_to_hex( char *          out,
    906                 const uint8_t * sha1 )
    907 {
     905tr_sha1_to_hex( char * out, const uint8_t * sha1 )
     906{
     907    int i;
    908908    static const char hex[] = "0123456789abcdef";
    909     int               i;
    910 
    911     for( i = 0; i < 20; i++ )
    912     {
    913         unsigned int val = *sha1++;
     909
     910    for( i=0; i<20; ++i )
     911    {
     912        const unsigned int val = *sha1++;
    914913        *out++ = hex[val >> 4];
    915914        *out++ = hex[val & 0xf];
    916915    }
     916
    917917    *out = '\0';
     918}
     919
     920void
     921tr_hex_to_sha1( uint8_t * out, const char * in )
     922{
     923    int i;
     924    static const char hex[] = "0123456789abcdef";
     925
     926    for( i=0; i<20; ++i )
     927    {
     928        const int hi = strchr( hex, *in++ ) - hex;
     929        const int lo = strchr( hex, *in++ ) - hex;
     930        *out++ = (uint8_t)( (hi<<4) | lo );
     931    }
    918932}
    919933
  • trunk/libtransmission/utils.h

    r9472 r9531  
    378378                            void * userData );
    379379
    380 void tr_sha1_to_hex( char *          out,
     380void tr_sha1_to_hex( char * out,
    381381                     const uint8_t * sha1 ) TR_GNUC_NONNULL(1,2);
     382
     383void tr_hex_to_sha1( uint8_t * out,
     384                     const char * hex ) TR_GNUC_NONNULL(1,2);
    382385
    383386
  • trunk/libtransmission/web.c

    r9513 r9531  
    685685    }
    686686}
     687
     688char*
     689tr_http_unescape( const char * str, int len )
     690{
     691    char * tmp = curl_unescape( str, len );
     692    char * ret = tr_strdup( tmp );
     693    curl_free( tmp );
     694    return ret;
     695}
  • trunk/libtransmission/web.h

    r9516 r9531  
    4141void tr_http_escape( struct evbuffer *out, const char *str, int len, int noslashes );
    4242
     43char* tr_http_unescape( const char * str, int len );
     44
    4345#endif
Note: See TracChangeset for help on using the changeset viewer.