mirror of
https://github.com/transmission/transmission.git
synced 2025-12-25 04:45:56 +00:00
remove libtransmission code that duplicates functionality in libevent
This commit is contained in:
@@ -878,7 +878,7 @@ savestate( void )
|
||||
}
|
||||
}
|
||||
|
||||
buf = ( uint8_t * )tr_bencSaveMalloc( &top, &len );
|
||||
buf = ( uint8_t * )tr_bencSave( &top, &len );
|
||||
SAFEBENCFREE( &top );
|
||||
if( NULL == buf )
|
||||
{
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <event.h>
|
||||
|
||||
#include "transmission.h"
|
||||
#include "bencode.h"
|
||||
#include "utils.h"
|
||||
@@ -390,96 +392,77 @@ benc_val_t * tr_bencDictAdd( benc_val_t * dict, const char * key )
|
||||
return itemval;
|
||||
}
|
||||
|
||||
char * tr_bencSaveMalloc( benc_val_t * val, int * len )
|
||||
{
|
||||
char * buf = NULL;
|
||||
int alloc = 0;
|
||||
|
||||
*len = 0;
|
||||
if( tr_bencSave( val, &buf, len, &alloc ) )
|
||||
{
|
||||
if( NULL != buf )
|
||||
{
|
||||
free(buf);
|
||||
}
|
||||
*len = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
struct KeyIndex
|
||||
{
|
||||
const char * key;
|
||||
int index;
|
||||
}
|
||||
KeyIndex;
|
||||
};
|
||||
|
||||
static int compareKeyIndex( const void * va, const void * vb )
|
||||
{
|
||||
const KeyIndex * a = (const KeyIndex *) va;
|
||||
const KeyIndex * b = (const KeyIndex *) vb;
|
||||
const struct KeyIndex * a = va;
|
||||
const struct KeyIndex * b = vb;
|
||||
return strcmp( a->key, b->key );
|
||||
}
|
||||
|
||||
int tr_bencSave( benc_val_t * val, char ** buf, int * used, int * max )
|
||||
static void
|
||||
saveImpl( struct evbuffer * out, const benc_val_t * val )
|
||||
{
|
||||
int ii;
|
||||
int ii;
|
||||
|
||||
switch( val->type )
|
||||
{
|
||||
case TYPE_INT:
|
||||
if( tr_sprintf( buf, used, max, "i%"PRId64"e", val->val.i ) )
|
||||
return 1;
|
||||
evbuffer_add_printf( out, "i%"PRId64"e", val->val.i );
|
||||
break;
|
||||
|
||||
case TYPE_STR:
|
||||
if( tr_sprintf( buf, used, max, "%i:", val->val.s.i ) ||
|
||||
tr_concat( buf, used, max, val->val.s.s, val->val.s.i ) )
|
||||
return 1;
|
||||
evbuffer_add_printf( out, "i:%*.*s", val->val.i, val->val.i, val->val.i, val->val.s );
|
||||
break;
|
||||
|
||||
case TYPE_LIST:
|
||||
if( tr_sprintf( buf, used, max, "l" ) )
|
||||
return 1;
|
||||
evbuffer_add_printf( out, "l" );
|
||||
for( ii = 0; val->val.l.count > ii; ii++ )
|
||||
if( tr_bencSave( val->val.l.vals + ii, buf, used, max ) )
|
||||
return 1;
|
||||
if( tr_sprintf( buf, used, max, "e" ) )
|
||||
return 1;
|
||||
saveImpl( out, val->val.l.vals + ii );
|
||||
evbuffer_add_printf( out, "e" );
|
||||
break;
|
||||
|
||||
case TYPE_DICT:
|
||||
/* Keys must be strings and appear in sorted order
|
||||
(sorted as raw strings, not alphanumerics). */
|
||||
if( tr_sprintf( buf, used, max, "d" ) )
|
||||
return 1;
|
||||
evbuffer_add_printf( out, "d" );
|
||||
if( 1 ) {
|
||||
int i;
|
||||
KeyIndex * indices = tr_new( KeyIndex, val->val.l.count );
|
||||
struct KeyIndex * indices = tr_new( struct KeyIndex, val->val.l.count );
|
||||
for( ii=i=0; i<val->val.l.count; i+=2 ) {
|
||||
indices[ii].key = val->val.l.vals[i].val.s.s;
|
||||
indices[ii].index = i;
|
||||
ii++;
|
||||
}
|
||||
qsort( indices, ii, sizeof(KeyIndex), compareKeyIndex );
|
||||
qsort( indices, ii, sizeof(struct KeyIndex), compareKeyIndex );
|
||||
for( i=0; i<ii; ++i ) {
|
||||
const int index = indices[i].index;
|
||||
if( tr_bencSave( val->val.l.vals + index, buf, used, max ) ||
|
||||
tr_bencSave( val->val.l.vals + index + 1, buf, used, max ) ) {
|
||||
tr_free( indices );
|
||||
return 1;
|
||||
}
|
||||
saveImpl( out, val->val.l.vals + index );
|
||||
saveImpl( out, val->val.l.vals + index + 1 );
|
||||
}
|
||||
tr_free( indices );
|
||||
}
|
||||
if( tr_sprintf( buf, used, max, "e" ) )
|
||||
return 1;
|
||||
}
|
||||
evbuffer_add_printf( out, "e" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
char*
|
||||
tr_bencSave( const benc_val_t * val, int * len )
|
||||
{
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
char * ret;
|
||||
saveImpl( buf, val );
|
||||
if( len != NULL )
|
||||
*len = EVBUFFER_LENGTH( buf );
|
||||
ret = tr_strndup( (char*) EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) );
|
||||
evbuffer_free( buf );
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,9 +86,7 @@ benc_val_t * tr_bencListAdd( benc_val_t * list );
|
||||
/* note: key must not be freed or modified while val is in use */
|
||||
benc_val_t * tr_bencDictAdd( benc_val_t * dict, const char * key );
|
||||
|
||||
char * tr_bencSaveMalloc( benc_val_t * val, int * len );
|
||||
int tr_bencSave( benc_val_t * val, char ** buf,
|
||||
int * used, int * max );
|
||||
char* tr_bencSave( const benc_val_t * val, int * len );
|
||||
|
||||
int tr_bencIsStr ( const benc_val_t * val );
|
||||
int tr_bencIsInt ( const benc_val_t * val );
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "transmission.h"
|
||||
#include "trcompat.h"
|
||||
#include "utils.h"
|
||||
|
||||
static int charToInt( char character )
|
||||
{
|
||||
@@ -54,195 +54,195 @@ char * tr_clientForId( const uint8_t * id )
|
||||
/* support old-style Transmission id without maintenance number */
|
||||
if ( !memcmp( &id[3], "00", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Transmission 0.%d",
|
||||
tr_asprintf( &ret, "Transmission 0.%d",
|
||||
charToInt( id[5] ) * 10 + charToInt( id[6] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
asprintf( &ret, "Transmission %d.%c%c%s",
|
||||
tr_asprintf( &ret, "Transmission %d.%c%c%s",
|
||||
charToInt( id[3] ), id[4], id[5],
|
||||
id[6] == 'Z' ? "+" : "" );
|
||||
}
|
||||
}
|
||||
else if( !memcmp( &id[1], "AZ", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Azureus %c.%c.%c.%c",
|
||||
tr_asprintf( &ret, "Azureus %c.%c.%c.%c",
|
||||
id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "UT", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "\xc2\xb5Torrent %c.%d", id[3],
|
||||
tr_asprintf( &ret, "\xc2\xb5Torrent %c.%d", id[3],
|
||||
charToInt( id[4] ) * 10 + charToInt( id[5] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "BC", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "BitComet %d.%c%c",
|
||||
tr_asprintf( &ret, "BitComet %d.%c%c",
|
||||
charToInt( id[3] ) * 10 + charToInt( id[4] ),
|
||||
id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "SZ", 2 ) || !memcmp( &id[1], "S~", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Shareaza %c.%c.%c.%c",
|
||||
tr_asprintf( &ret, "Shareaza %c.%c.%c.%c",
|
||||
id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "BOW", 3 ) )
|
||||
{
|
||||
if( !memcmp( &id[4], "A0C", 3 ) )
|
||||
{
|
||||
asprintf( &ret, "Bits on Wheels 1.0.6" );
|
||||
tr_asprintf( &ret, "Bits on Wheels 1.0.6" );
|
||||
}
|
||||
else if( !memcmp( &id[4], "A0B", 3 ) )
|
||||
{
|
||||
asprintf( &ret, "Bits on Wheels 1.0.5" );
|
||||
tr_asprintf( &ret, "Bits on Wheels 1.0.5" );
|
||||
}
|
||||
else
|
||||
{
|
||||
asprintf( &ret, "Bits on Wheels (%c%c%c)",
|
||||
tr_asprintf( &ret, "Bits on Wheels (%c%c%c)",
|
||||
id[4], id[5], id[6] );
|
||||
}
|
||||
}
|
||||
else if( !memcmp( &id[1], "BR", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "BitRocket %c.%c (%d)",
|
||||
tr_asprintf( &ret, "BitRocket %c.%c (%d)",
|
||||
id[3], id[4], charToInt( id[5] ) * 10 + charToInt( id[6] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "XX", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Xtorrent %c.%c (%d)",
|
||||
tr_asprintf( &ret, "Xtorrent %c.%c (%d)",
|
||||
id[3], id[4], charToInt( id[5] ) * 10 + charToInt( id[6] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "TS", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "TorrentStorm %c.%c.%c.%c",
|
||||
tr_asprintf( &ret, "TorrentStorm %c.%c.%c.%c",
|
||||
id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "KT", 2 ) )
|
||||
{
|
||||
if( id[5] == 'R' )
|
||||
{
|
||||
asprintf( &ret, "KTorrent %c.%c RC %c",
|
||||
tr_asprintf( &ret, "KTorrent %c.%c RC %c",
|
||||
id[3], id[4], id[6] );
|
||||
}
|
||||
else if( id[5] == 'D' )
|
||||
{
|
||||
asprintf( &ret, "KTorrent %c.%c Dev",
|
||||
tr_asprintf( &ret, "KTorrent %c.%c Dev",
|
||||
id[3], id[4] );
|
||||
}
|
||||
else
|
||||
{
|
||||
asprintf( &ret, "KTorrent %c.%c.%c",
|
||||
tr_asprintf( &ret, "KTorrent %c.%c.%c",
|
||||
id[3], id[4], id[5] );
|
||||
}
|
||||
}
|
||||
else if( !memcmp( &id[1], "lt", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "libTorrent %d.%d.%d.%d",
|
||||
tr_asprintf( &ret, "libTorrent %d.%d.%d.%d",
|
||||
charToInt( id[3] ), charToInt( id[4] ),
|
||||
charToInt( id[5] ), charToInt( id[6] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "LT", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "libtorrent %d.%d.%d.%d",
|
||||
tr_asprintf( &ret, "libtorrent %d.%d.%d.%d",
|
||||
charToInt( id[3] ), charToInt( id[4] ),
|
||||
charToInt( id[5] ), charToInt( id[6] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "TT", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "TuoTu %c.%c.%c",
|
||||
tr_asprintf( &ret, "TuoTu %c.%c.%c",
|
||||
id[3], id[4], id[5] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "ES", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Electric Sheep %c.%c.%c",
|
||||
tr_asprintf( &ret, "Electric Sheep %c.%c.%c",
|
||||
id[3], id[4], id[5] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "CD", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Enhanced CTorrent %d.%d",
|
||||
tr_asprintf( &ret, "Enhanced CTorrent %d.%d",
|
||||
charToInt( id[3] ) * 10 + charToInt( id[4] ),
|
||||
charToInt( id[5] ) * 10 + charToInt( id[6] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "CT", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "CTorrent %c.%c.%d",
|
||||
tr_asprintf( &ret, "CTorrent %c.%c.%d",
|
||||
id[3], id[4],
|
||||
charToInt( id[5] ) * 10 + charToInt( id[6] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "LP", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Lphant %d.%c%c",
|
||||
tr_asprintf( &ret, "Lphant %d.%c%c",
|
||||
charToInt( id[3] ) * 10 + charToInt( id[4] ),
|
||||
id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "AX", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "BitPump %d.%c%c",
|
||||
tr_asprintf( &ret, "BitPump %d.%c%c",
|
||||
charToInt( id[3] ) * 10 + charToInt( id[4] ),
|
||||
id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "DE", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Deluge %d.%d.%d",
|
||||
tr_asprintf( &ret, "Deluge %d.%d.%d",
|
||||
charToInt( id[3] ), charToInt( id[4] ),
|
||||
charToInt( id[5] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "AG", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Ares Galaxy %d.%d.%d",
|
||||
tr_asprintf( &ret, "Ares Galaxy %d.%d.%d",
|
||||
charToInt( id[3] ), charToInt( id[4] ),
|
||||
charToInt( id[5] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "HL", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Halite %d.%d.%d",
|
||||
tr_asprintf( &ret, "Halite %d.%d.%d",
|
||||
charToInt( id[3] ), charToInt( id[4] ),
|
||||
charToInt( id[5] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "AR", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Arctic Torrent" );
|
||||
tr_asprintf( &ret, "Arctic Torrent" );
|
||||
}
|
||||
else if( !memcmp( &id[1], "BG", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "BTG %c.%c.%c.%c",
|
||||
tr_asprintf( &ret, "BTG %c.%c.%c.%c",
|
||||
id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "BB", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "BitBuddy %c.%c%c%c",
|
||||
tr_asprintf( &ret, "BitBuddy %c.%c%c%c",
|
||||
id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "qB", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "qBittorrent %d.%d.%d",
|
||||
tr_asprintf( &ret, "qBittorrent %d.%d.%d",
|
||||
charToInt( id[3] ), charToInt( id[4] ),
|
||||
charToInt( id[5] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "BF", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Bitflu (%d/%d/%02d)",
|
||||
tr_asprintf( &ret, "Bitflu (%d/%d/%02d)",
|
||||
charToInt( id[6] ),
|
||||
charToInt( id[4] ) * 10 + charToInt( id[5] ),
|
||||
charToInt( id[3] ) );
|
||||
}
|
||||
else if( !memcmp( &id[1], "FT", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "FoxTorrent (%c%c%c%c)",
|
||||
tr_asprintf( &ret, "FoxTorrent (%c%c%c%c)",
|
||||
id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "GR", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "GetRight %c.%c.%c.%c",
|
||||
tr_asprintf( &ret, "GetRight %c.%c.%c.%c",
|
||||
id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "PD", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Pando %c.%c.%c.%c",
|
||||
tr_asprintf( &ret, "Pando %c.%c.%c.%c",
|
||||
id[3], id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( &id[1], "LW", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "LimeWire" );
|
||||
tr_asprintf( &ret, "LimeWire" );
|
||||
}
|
||||
|
||||
if( ret )
|
||||
@@ -256,21 +256,21 @@ char * tr_clientForId( const uint8_t * id )
|
||||
{
|
||||
if( id[0] == 'T' )
|
||||
{
|
||||
asprintf( &ret, "BitTornado %d.%d.%d", charToInt( id[1] ),
|
||||
tr_asprintf( &ret, "BitTornado %d.%d.%d", charToInt( id[1] ),
|
||||
charToInt( id[2] ), charToInt( id[3] ) );
|
||||
}
|
||||
else if( id[0] == 'A' )
|
||||
{
|
||||
asprintf( &ret, "ABC %d.%d.%d", charToInt( id[1] ),
|
||||
tr_asprintf( &ret, "ABC %d.%d.%d", charToInt( id[1] ),
|
||||
charToInt( id[2] ), charToInt( id[3] ) );
|
||||
}
|
||||
else if( id[0] == 'R' )
|
||||
{
|
||||
asprintf( &ret, "Tribler %c.%c", id[1], id[2] );
|
||||
tr_asprintf( &ret, "Tribler %c.%c", id[1], id[2] );
|
||||
}
|
||||
else if( id[0] == 'S' )
|
||||
{
|
||||
asprintf( &ret, "Shad0w's Client %d.%d.%d", charToInt( id[1] ),
|
||||
tr_asprintf( &ret, "Shad0w's Client %d.%d.%d", charToInt( id[1] ),
|
||||
charToInt( id[2] ), charToInt( id[3] ) );
|
||||
}
|
||||
|
||||
@@ -285,11 +285,11 @@ char * tr_clientForId( const uint8_t * id )
|
||||
{
|
||||
if( id[4] == '-' && id[6] == '-' )
|
||||
{
|
||||
asprintf( &ret, "BitTorrent %c.%c.%c", id[1], id[3], id[5] );
|
||||
tr_asprintf( &ret, "BitTorrent %c.%c.%c", id[1], id[3], id[5] );
|
||||
}
|
||||
else if( id[5] == '-' )
|
||||
{
|
||||
asprintf( &ret, "BitTorrent %c.%c%c.%c", id[1], id[3], id[4], id[6] );
|
||||
tr_asprintf( &ret, "BitTorrent %c.%c%c.%c", id[1], id[3], id[4], id[6] );
|
||||
}
|
||||
|
||||
if( ret )
|
||||
@@ -301,11 +301,11 @@ char * tr_clientForId( const uint8_t * id )
|
||||
{
|
||||
if( id[4] == '-' && id[6] == '-' )
|
||||
{
|
||||
asprintf( &ret, "Queen Bee %c.%c.%c", id[1], id[3], id[5] );
|
||||
tr_asprintf( &ret, "Queen Bee %c.%c.%c", id[1], id[3], id[5] );
|
||||
}
|
||||
else if( id[5] == '-' )
|
||||
{
|
||||
asprintf( &ret, "Queen Bee %c.%c%c.%c", id[1], id[3], id[4], id[6] );
|
||||
tr_asprintf( &ret, "Queen Bee %c.%c%c.%c", id[1], id[3], id[4], id[6] );
|
||||
}
|
||||
|
||||
if( ret )
|
||||
@@ -317,88 +317,88 @@ char * tr_clientForId( const uint8_t * id )
|
||||
/* All versions of each client are formatted the same */
|
||||
if( !memcmp( id, "exbc", 4 ) )
|
||||
{
|
||||
asprintf( &ret, "%s %d.%02d",
|
||||
tr_asprintf( &ret, "%s %d.%02d",
|
||||
!memcmp( &id[6], "LORD", 4 ) ? "BitLord" : "BitComet",
|
||||
id[4], id[5] );
|
||||
}
|
||||
else if( !memcmp( id, "OP", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "Opera (%c%c%c%c)", id[2], id[3], id[4], id[5] );
|
||||
tr_asprintf( &ret, "Opera (%c%c%c%c)", id[2], id[3], id[4], id[5] );
|
||||
}
|
||||
else if( !memcmp( id, "-ML", 3 ) )
|
||||
{
|
||||
asprintf( &ret, "MLDonkey %c%c%c%c%c",
|
||||
tr_asprintf( &ret, "MLDonkey %c%c%c%c%c",
|
||||
id[3], id[4], id[5], id[6], id[7] );
|
||||
}
|
||||
else if( !memcmp( id, "AZ", 2 ) && !memcmp( &id[6], "BT", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "BitTyrant %c.%c.%c.%c",
|
||||
tr_asprintf( &ret, "BitTyrant %c.%c.%c.%c",
|
||||
id[2], id[3], id[4], id[5] );
|
||||
}
|
||||
else if( !memcmp( id, "-FG", 3 ) )
|
||||
{
|
||||
asprintf( &ret, "FlashGet %d.%c%c",
|
||||
tr_asprintf( &ret, "FlashGet %d.%c%c",
|
||||
charToInt( id[3] ) * 10 + charToInt( id[4] ),
|
||||
id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( id, "DNA", 3 ) )
|
||||
{
|
||||
asprintf( &ret, "BitTorrent DNA %d.%d.%d", charToInt( id[3] ) * 10 + charToInt( id[4] ),
|
||||
tr_asprintf( &ret, "BitTorrent DNA %d.%d.%d", charToInt( id[3] ) * 10 + charToInt( id[4] ),
|
||||
charToInt( id[5] ) * 10 + charToInt( id[6] ), charToInt( id[7] ) * 10 + charToInt( id[8] ) );
|
||||
}
|
||||
else if( !memcmp( id, "Plus", 4 ) )
|
||||
{
|
||||
asprintf( &ret, "Plus! v2 %c.%c%c", id[4], id[5], id[6] );
|
||||
tr_asprintf( &ret, "Plus! v2 %c.%c%c", id[4], id[5], id[6] );
|
||||
}
|
||||
else if( !memcmp( id, "XBT", 3 ) )
|
||||
{
|
||||
asprintf( &ret, "XBT Client %c%c%c%s", id[3], id[4], id[5],
|
||||
tr_asprintf( &ret, "XBT Client %c%c%c%s", id[3], id[4], id[5],
|
||||
id[6] == 'd' ? " (debug)" : "" );
|
||||
}
|
||||
else if( !memcmp( id, "Mbrst", 5 ) )
|
||||
{
|
||||
asprintf( &ret, "burst! %c.%c.%c", id[5], id[7], id[9] );
|
||||
tr_asprintf( &ret, "burst! %c.%c.%c", id[5], id[7], id[9] );
|
||||
}
|
||||
else if( !memcmp( id, "btpd", 4 ) )
|
||||
{
|
||||
asprintf( &ret, "BT Protocol Daemon %c%c%c", id[5], id[6], id[7] );
|
||||
tr_asprintf( &ret, "BT Protocol Daemon %c%c%c", id[5], id[6], id[7] );
|
||||
}
|
||||
else if( id[0] == 'Q' && !memcmp( &id[4], "--", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "BTQueue %d.%d.%d", charToInt( id[1] ),
|
||||
tr_asprintf( &ret, "BTQueue %d.%d.%d", charToInt( id[1] ),
|
||||
charToInt( id[2] ), charToInt( id[3] ) );
|
||||
}
|
||||
else if( !memcmp( id, "BLZ", 3 ) )
|
||||
{
|
||||
asprintf( &ret, "Blizzard Downloader %d.%d", id[3] + 1, id[4] );
|
||||
tr_asprintf( &ret, "Blizzard Downloader %d.%d", id[3] + 1, id[4] );
|
||||
}
|
||||
else if( !memcmp( id, "-WT-", 4 ) )
|
||||
{
|
||||
asprintf( &ret, "BitLet" );
|
||||
tr_asprintf( &ret, "BitLet" );
|
||||
}
|
||||
else if( !memcmp( id, "LIME", 4 ) )
|
||||
{
|
||||
asprintf( &ret, "LimeWire" );
|
||||
tr_asprintf( &ret, "LimeWire" );
|
||||
}
|
||||
else if( !memcmp( id, "-G3", 3 ) )
|
||||
{
|
||||
asprintf( &ret, "G3 Torrent" );
|
||||
tr_asprintf( &ret, "G3 Torrent" );
|
||||
}
|
||||
else if( !memcmp( id, "10-------", 9 ) )
|
||||
{
|
||||
asprintf( &ret, "JVtorrent" );
|
||||
tr_asprintf( &ret, "JVtorrent" );
|
||||
}
|
||||
else if( !memcmp( id, "346-", 4 ) )
|
||||
{
|
||||
asprintf( &ret, "TorrentTopia" );
|
||||
tr_asprintf( &ret, "TorrentTopia" );
|
||||
}
|
||||
else if( !memcmp( id, "eX", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "eXeem" );
|
||||
tr_asprintf( &ret, "eXeem" );
|
||||
}
|
||||
else if( '\0' == id[0] && !memcmp( &id[1], "BS", 2 ) )
|
||||
{
|
||||
asprintf( &ret, "BitSpirit %u", ( id[1] == 0 ? 1 : id[1] ) );
|
||||
tr_asprintf( &ret, "BitSpirit %u", ( id[1] == 0 ? 1 : id[1] ) );
|
||||
}
|
||||
|
||||
/* No match */
|
||||
@@ -408,12 +408,12 @@ char * tr_clientForId( const uint8_t * id )
|
||||
isprint( id[3] ) && isprint( id[4] ) && isprint( id[5] ) &&
|
||||
isprint( id[6] ) && isprint( id[7] ) )
|
||||
{
|
||||
asprintf( &ret, "unknown client (%c%c%c%c%c%c%c%c)",
|
||||
tr_asprintf( &ret, "unknown client (%c%c%c%c%c%c%c%c)",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
|
||||
}
|
||||
else
|
||||
{
|
||||
asprintf( &ret, "unknown client (0x%02x%02x%02x%02x%02x%02x%02x%02x)",
|
||||
tr_asprintf( &ret, "unknown client (0x%02x%02x%02x%02x%02x%02x%02x%02x)",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,6 @@
|
||||
#include "peer-mgr.h"
|
||||
#include "utils.h"
|
||||
|
||||
struct tr_io
|
||||
{
|
||||
tr_torrent * tor;
|
||||
};
|
||||
|
||||
/****
|
||||
***** Low-level IO functions
|
||||
****/
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "transmission.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "ipcparse.h"
|
||||
#include "bsdtree.h"
|
||||
@@ -363,40 +364,24 @@ ipc_initval( struct ipc_info * info, enum ipc_msg id, int64_t tag,
|
||||
}
|
||||
|
||||
uint8_t *
|
||||
ipc_mkval( benc_val_t * pk, size_t * len )
|
||||
ipc_mkval( benc_val_t * pk, size_t * setmeSize )
|
||||
{
|
||||
char * buf, hex[IPC_MIN_MSG_LEN+1];
|
||||
int used, max;
|
||||
int bencSize = 0;
|
||||
char * benc = tr_bencSave( pk, &bencSize );
|
||||
uint8_t * ret = NULL;
|
||||
|
||||
used = IPC_MIN_MSG_LEN;
|
||||
max = IPC_MIN_MSG_LEN;
|
||||
buf = malloc( IPC_MIN_MSG_LEN );
|
||||
if( NULL == buf )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( tr_bencSave( pk, &buf, &used, &max ) )
|
||||
{
|
||||
SAFEFREE( buf );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ok, this check is pretty laughable */
|
||||
if( IPC_MAX_MSG_LEN < used )
|
||||
{
|
||||
free( buf );
|
||||
if( bencSize > IPC_MAX_MSG_LEN )
|
||||
errno = EFBIG;
|
||||
return NULL;
|
||||
else {
|
||||
const size_t size = IPC_MIN_MSG_LEN + bencSize;
|
||||
ret = tr_new( uint8_t, size );
|
||||
snprintf( (char*)ret, size, "%0*X", IPC_MIN_MSG_LEN, bencSize );
|
||||
memcpy( ret + IPC_MIN_MSG_LEN, benc, bencSize );
|
||||
*setmeSize = size;
|
||||
}
|
||||
|
||||
assert( 0 <= used );
|
||||
snprintf( hex, sizeof hex, "%0*X",
|
||||
IPC_MIN_MSG_LEN, used - IPC_MIN_MSG_LEN );
|
||||
memcpy( buf, hex, IPC_MIN_MSG_LEN );
|
||||
*len = used;
|
||||
|
||||
return ( uint8_t * )buf;
|
||||
tr_free( benc );
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t *
|
||||
|
||||
@@ -385,7 +385,7 @@ static void tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
|
||||
/* save the file */
|
||||
if ( !builder->abortFlag ) {
|
||||
size_t nmemb;
|
||||
char * pch = tr_bencSaveMalloc( &top, &n );
|
||||
char * pch = tr_bencSave( &top, &n );
|
||||
FILE * fp = fopen( builder->outputFile, "wb+" );
|
||||
nmemb = n;
|
||||
if( fp == NULL )
|
||||
|
||||
@@ -697,7 +697,7 @@ sendLtepHandshake( tr_peermsgs * msgs )
|
||||
if( port > 0 )
|
||||
tr_bencInitInt( tr_bencDictAdd( &val, "p" ), port );
|
||||
tr_bencInitStr( tr_bencDictAdd( &val, "v" ), v, 0, 1 );
|
||||
buf = tr_bencSaveMalloc( &val, &len );
|
||||
buf = tr_bencSave( &val, &len );
|
||||
|
||||
tr_peerIoWriteUint32( msgs->io, outbuf, 2*sizeof(uint8_t) + len );
|
||||
tr_peerIoWriteUint8 ( msgs->io, outbuf, BT_LTEP );
|
||||
@@ -1620,7 +1620,7 @@ sendPex( tr_peermsgs * msgs )
|
||||
tr_bencInitStr( dropped, tmp, walk-tmp, FALSE );
|
||||
|
||||
/* write the pex message */
|
||||
benc = tr_bencSaveMalloc( &val, &bencLen );
|
||||
benc = tr_bencSave( &val, &bencLen );
|
||||
tr_peerIoWriteUint32( msgs->io, msgs->outMessages, 2*sizeof(uint8_t) + bencLen );
|
||||
tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, BT_LTEP );
|
||||
tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, OUR_LTEP_PEX );
|
||||
|
||||
@@ -35,9 +35,4 @@ size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ASPRINTF
|
||||
int asprintf( char **, const char *, ... );
|
||||
int vasprintf( char **, const char *, va_list );
|
||||
#endif
|
||||
|
||||
#endif /* TRCOMPAT_H */
|
||||
|
||||
@@ -35,11 +35,12 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h> /* usleep, stat */
|
||||
|
||||
#include "event.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h> /* for Sleep */
|
||||
#elif defined(__BEOS__)
|
||||
#include <kernel/OS.h>
|
||||
extern int vasprintf( char **, const char *, va_list );
|
||||
#endif
|
||||
|
||||
#include "transmission.h"
|
||||
@@ -47,8 +48,6 @@
|
||||
#include "utils.h"
|
||||
#include "platform.h"
|
||||
|
||||
#define SPRINTF_BUFSIZE 100
|
||||
|
||||
static tr_lock * messageLock = NULL;
|
||||
static int messageLevel = 0;
|
||||
static int messageQueuing = FALSE;
|
||||
@@ -160,12 +159,37 @@ void tr_freeMessageList( tr_msg_list * list )
|
||||
}
|
||||
}
|
||||
|
||||
void tr_msg( int level, const char * msg, ... )
|
||||
int
|
||||
tr_vasprintf( char **strp, const char *fmt, va_list ap )
|
||||
{
|
||||
int ret;
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
if( evbuffer_add_vprintf( buf, fmt, ap ) )
|
||||
ret = -1;
|
||||
else {
|
||||
ret = EVBUFFER_LENGTH( buf );
|
||||
*strp = tr_strndup( (char*)EVBUFFER_DATA(buf), ret );
|
||||
}
|
||||
evbuffer_free( buf );
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
tr_asprintf( char **strp, const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
va_start( ap, fmt );
|
||||
ret = tr_vasprintf( strp, fmt, ap );
|
||||
va_end( ap );
|
||||
return ret;
|
||||
}
|
||||
|
||||
void tr_msg( int level, const char * fmt, ... )
|
||||
{
|
||||
va_list args1, args2;
|
||||
tr_msg_list * newmsg;
|
||||
int len1, len2;
|
||||
FILE * fp;
|
||||
FILE * fp;
|
||||
|
||||
assert( NULL != messageLock );
|
||||
tr_lockLock( messageLock );
|
||||
@@ -182,41 +206,32 @@ void tr_msg( int level, const char * msg, ... )
|
||||
|
||||
if( messageLevel >= level )
|
||||
{
|
||||
va_start( args1, msg );
|
||||
va_list ap;
|
||||
char * text;
|
||||
|
||||
/* build the text message */
|
||||
va_start( ap, fmt );
|
||||
tr_vasprintf( &text, fmt, ap );
|
||||
va_end( ap );
|
||||
|
||||
if( messageQueuing )
|
||||
{
|
||||
newmsg = calloc( 1, sizeof( *newmsg ) );
|
||||
if( NULL != newmsg )
|
||||
{
|
||||
newmsg->level = level;
|
||||
newmsg->when = time( NULL );
|
||||
len1 = len2 = 0;
|
||||
va_start( args2, msg );
|
||||
tr_vsprintf( &newmsg->message, &len1, &len2, msg,
|
||||
args1, args2 );
|
||||
va_end( args2 );
|
||||
if( fp != NULL )
|
||||
fprintf( fp, "%s\n", newmsg->message );
|
||||
if( NULL == newmsg->message )
|
||||
{
|
||||
free( newmsg );
|
||||
}
|
||||
else
|
||||
{
|
||||
*messageQueueTail = newmsg;
|
||||
messageQueueTail = &newmsg->next;
|
||||
}
|
||||
}
|
||||
newmsg = tr_new0( tr_msg_list, 1 );
|
||||
newmsg->level = level;
|
||||
newmsg->when = time( NULL );
|
||||
newmsg->message = text;
|
||||
|
||||
*messageQueueTail = newmsg;
|
||||
messageQueueTail = &newmsg->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( fp == NULL )
|
||||
fp = stderr;
|
||||
vfprintf( fp, msg, args1 );
|
||||
fputc( '\n', fp );
|
||||
fprintf( stderr, "%s\n", text );
|
||||
tr_free( text );
|
||||
fflush( fp );
|
||||
}
|
||||
va_end( args1 );
|
||||
}
|
||||
|
||||
tr_lockUnlock( messageLock );
|
||||
@@ -442,106 +457,6 @@ tr_mkdirp( const char * path_in, int permissions )
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tr_sprintf( char ** buf, int * used, int * max, const char * format, ... )
|
||||
{
|
||||
va_list ap1, ap2;
|
||||
int ret;
|
||||
|
||||
va_start( ap1, format );
|
||||
va_start( ap2, format );
|
||||
ret = tr_vsprintf( buf, used, max, format, ap1, ap2 );
|
||||
va_end( ap2 );
|
||||
va_end( ap1 );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int tr_vsprintf( char ** buf, int * used, int * max, const char * fmt,
|
||||
va_list ap1, va_list ap2 )
|
||||
{
|
||||
int want;
|
||||
|
||||
want = vsnprintf( NULL, 0, fmt, ap1 );
|
||||
|
||||
if( tr_concat( buf, used, max, NULL, want ) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
assert( *used + want + 1 <= *max );
|
||||
|
||||
*used += vsnprintf( *buf + *used, *max - *used, fmt, ap2 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef HAVE_ASPRINTF
|
||||
|
||||
int
|
||||
asprintf( char ** buf, const char * format, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start( ap, format );
|
||||
ret = vasprintf( buf, format, ap );
|
||||
va_end( ap );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
vasprintf( char ** buf, const char * format, va_list ap )
|
||||
{
|
||||
va_list ap2;
|
||||
int used, max;
|
||||
|
||||
va_copy( ap2, ap );
|
||||
|
||||
*buf = NULL;
|
||||
used = 0;
|
||||
max = 0;
|
||||
|
||||
if( tr_vsprintf( buf, &used, &max, format, ap, ap2 ) )
|
||||
{
|
||||
free( *buf );
|
||||
return -1;
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
#endif /* HAVE_ASPRINTF */
|
||||
|
||||
int tr_concat( char ** buf, int * used, int * max, const char * data, int len )
|
||||
{
|
||||
int newmax;
|
||||
char * newbuf;
|
||||
|
||||
newmax = *max;
|
||||
while( *used + len + 1 > newmax )
|
||||
{
|
||||
newmax += SPRINTF_BUFSIZE;
|
||||
}
|
||||
if( newmax > *max )
|
||||
{
|
||||
newbuf = realloc( *buf, newmax );
|
||||
if( NULL == newbuf )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
*buf = newbuf;
|
||||
*max = newmax;
|
||||
}
|
||||
|
||||
if( NULL != data )
|
||||
{
|
||||
memcpy( *buf + *used, data, len );
|
||||
*used += len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tr_buildPath ( char *buf, size_t buflen, const char *first_element, ... )
|
||||
{
|
||||
|
||||
@@ -42,31 +42,18 @@ char* tr_getLogTimeStr( char * buf, int buflen );
|
||||
|
||||
int tr_rand ( int );
|
||||
|
||||
/***********************************************************************
|
||||
* tr_mkdirp
|
||||
***********************************************************************
|
||||
* Create a directory and any needed parent directories.
|
||||
* Note that the string passed in must be writable!
|
||||
**********************************************************************/
|
||||
int tr_asprintf(char **strp, const char *fmt, ...);
|
||||
|
||||
int tr_mkdirp( const char * path, int permissions );
|
||||
|
||||
int tr_mkdir( const char * path, int permissions );
|
||||
|
||||
uint8_t* tr_loadFile( const char * filename, size_t * size );
|
||||
|
||||
/***********************************************************************
|
||||
* tr_sprintf
|
||||
***********************************************************************
|
||||
* Appends to the end of a buffer using printf formatting,
|
||||
* growing the buffer if needed
|
||||
**********************************************************************/
|
||||
int tr_sprintf( char ** buf, int * used, int * max,
|
||||
const char * format, ... );
|
||||
/* gee, it sure would be nice if BeOS had va_copy() */
|
||||
int tr_vsprintf( char **, int *, int *, const char *, va_list, va_list );
|
||||
/* this concatenates some binary data onto the end of a buffer */
|
||||
int tr_concat( char ** buf, int * used, int * max,
|
||||
const char * data, int len );
|
||||
int tr_vasprintf( char **strp, const char *fmt, va_list ap );
|
||||
|
||||
int tr_asprintf( char **strp, const char *fmt, ...);
|
||||
|
||||
|
||||
/* creates a filename from a series of elements using the
|
||||
correct separator for filenames. */
|
||||
|
||||
Reference in New Issue
Block a user