transmission/libtransmission/clients.c

254 lines
7.9 KiB
C
Raw Normal View History

2006-07-16 19:39:23 +00:00
/******************************************************************************
* $Id$
*
* Copyright (c) 2005 Transmission authors and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include "transmission.h"
static int charToInt( char character );
2006-12-11 01:25:28 +00:00
static int charToInt( char character )
{
2006-12-16 02:39:12 +00:00
int value;
if( character >= 'A' && character <= 'Z' )
2006-12-16 02:39:12 +00:00
value = 10 + character - 'A';
else
value = character - '0';
return value;
}
2006-07-16 19:39:23 +00:00
char * tr_clientForId( uint8_t * id )
{
char * ret = NULL;
/* Azureus style */
2006-07-16 19:39:23 +00:00
if( id[0] == '-' && id[7] == '-' )
{
if( !memcmp( &id[1], "TR", 2 ) )
{
asprintf( &ret, "Transmission %d.%d",
charToInt( id[3] ) * 10 + charToInt( id[4] ),
charToInt( id[5] ) * 10 + charToInt( id[6] ) );
2006-07-16 19:39:23 +00:00
}
else if( !memcmp( &id[1], "AZ", 2 ) )
{
asprintf( &ret, "Azureus %c.%c.%c.%c",
id[3], id[4], id[5], id[6] );
}
2006-12-23 20:27:24 +00:00
else if( !memcmp( &id[1], "UT", 2 ) )
{
asprintf( &ret, "\xc2\xb5Torrent %c.%d", id[3],
charToInt( id[4] ) * 10 + charToInt( id[5] ) );
}
2006-07-16 19:39:23 +00:00
else if( !memcmp( &id[1], "TS", 2 ) )
{
asprintf( &ret, "TorrentStorm (%c%c%c%c)",
id[3], id[4], id[5], id[6] );
}
else if( !memcmp( &id[1], "BC", 2 ) )
{
asprintf( &ret, "BitComet %d.%c%c",
charToInt( id[3] ) * 10 + charToInt( id[4] ),
2006-07-16 19:39:23 +00:00
id[5], id[6] );
}
else if( !memcmp( &id[1], "SZ", 2 ) )
{
asprintf( &ret, "Shareaza %c.%c.%c.%c",
id[3], id[4], id[5], id[6] );
}
2006-08-14 22:33:41 +00:00
else if( !memcmp( &id[1], "BOW", 3 ) )
{
asprintf( &ret, "Bits on Wheels (%c%c)",
id[5], id[6] );
2006-08-13 21:38:19 +00:00
}
else if( !memcmp( &id[1], "BR", 2 ) )
{
asprintf( &ret, "BitRocket %c.%c (%d)",
id[3], id[4], charToInt( id[5] ) * 10 + charToInt( id[6] ) );
}
2006-12-23 20:27:24 +00:00
else if( !memcmp( &id[1], "XX", 2 ) )
{
2006-12-24 01:08:23 +00:00
asprintf( &ret, "Xtorrent (%d)",
2006-12-23 20:27:24 +00:00
charToInt( id[3] ) * 1000 + charToInt( id[4] ) * 100
+ charToInt( id[5] ) * 10 + charToInt( id[6] ) );
}
else if( !memcmp( &id[1], "KT", 2 ) )
{
asprintf( &ret, "KTorrent %c.%c.%c.%c",
id[3], id[4], id[5], id[6] );
}
else if( !memcmp( &id[1], "lt", 2 ) )
{
asprintf( &ret, "libTorrent %d.%d.%d.%d",
charToInt( id[3] ), charToInt( id[4] ),
charToInt( id[5] ), charToInt( id[6] ) );
}
2006-12-19 15:23:48 +00:00
else if( !memcmp( &id[1], "LT", 2 ) )
{
asprintf( &ret, "libtorrent %d.%d.%d.%d",
charToInt( id[3] ), charToInt( id[4] ),
charToInt( id[5] ), charToInt( id[6] ) );
}
2006-11-19 21:33:49 +00:00
else if( !memcmp( &id[1], "ES", 2 ) )
{
asprintf( &ret, "Electric Sheep %c.%c.%c",
id[3], id[4], id[5] );
}
2006-12-17 21:15:33 +00:00
else if( !memcmp( &id[1], "CD", 2 ) )
{
asprintf( &ret, "CTorrent %d.%d",
charToInt( id[3] ) * 10 + charToInt( id[4] ),
charToInt( id[5] ) * 10 + charToInt( id[6] ) );
}
2006-12-22 16:20:33 +00:00
else if( !memcmp( &id[1], "LP", 2 ) )
{
asprintf( &ret, "Lphant %d.%c%c",
charToInt( id[3] ) * 10 + charToInt( id[4] ),
id[5], id[6] );
}
else if( !memcmp( &id[1], "AR", 2 ) )
{
asprintf( &ret, "Arctic Torrent" );
}
if( ret )
{
return ret;
}
2006-07-16 19:39:23 +00:00
}
2006-12-19 16:30:34 +00:00
/* Tornado-style */
if( !memcmp( &id[4], "----", 4 ) || !memcmp( &id[4], "--00", 4 ) )
2006-07-16 19:39:23 +00:00
{
if( id[0] == 'T' )
{
asprintf( &ret, "BitTornado %d.%d.%d", charToInt( id[1] ),
2006-12-15 17:37:16 +00:00
charToInt( id[2] ), charToInt( id[3] ) );
2006-07-16 19:39:23 +00:00
}
else if( id[0] == 'A' )
{
2006-12-15 17:37:16 +00:00
asprintf( &ret, "ABC %d.%d.%d", charToInt( id[1] ),
charToInt( id[2] ), charToInt( id[3] ) );
2006-07-16 19:39:23 +00:00
}
if( ret )
{
return ret;
}
2006-07-16 19:39:23 +00:00
}
2006-12-19 16:30:34 +00:00
/* Different formatting per client */
if( id[0] == 'M' && id[2] == '-' && id[7] == '-' )
2006-07-16 19:39:23 +00:00
{
2006-12-15 06:16:20 +00:00
if( id[4] == '-' && id[6] == '-' )
{
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] );
}
if( ret )
{
return ret;
}
}
if( id[0] == 'Q' && id[2] == '-' && id[7] == '-' )
2006-12-16 02:27:02 +00:00
{
if( id[4] == '-' && id[6] == '-' )
{
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] );
}
if( ret )
{
return ret;
}
2006-12-16 02:27:02 +00:00
}
/* All versions of each client are formatted the same */
if( !memcmp( id, "exbc", 4 ) )
2006-07-16 19:39:23 +00:00
{
2006-12-15 05:39:06 +00:00
asprintf( &ret, "%s %d.%02d",
!memcmp( &id[6], "LORD", 4 ) ? "BitLord" : "BitComet",
id[4], id[5] );
2006-07-16 19:39:23 +00:00
}
2006-09-12 01:38:57 +00:00
else if( !memcmp( id, "OP", 2 ) )
{
2006-09-12 01:41:17 +00:00
asprintf( &ret, "Opera (%c%c%c%c)", id[2], id[3], id[4], id[5] );
2006-09-12 01:38:57 +00:00
}
else if( !memcmp( id, "-ML", 3 ) )
{
asprintf( &ret, "MLDonkey %c%c%c%c%c",
id[3], id[4], id[5], id[6], id[7] );
}
2006-12-20 17:26:32 +00:00
else if( !memcmp( id, "-FG", 3 ) )
{
asprintf( &ret, "FlashGet %d.%c%c",
charToInt( id[3] ) * 10 + charToInt( id[4] ),
id[5], id[6] );
}
2006-12-22 23:34:35 +00:00
else if( !memcmp( id, "Plus", 4 ) )
{
2006-12-22 23:35:23 +00:00
asprintf( &ret, "Plus! v2 %c.%c%c", id[4], id[5], id[6] );
2006-12-22 23:34:35 +00:00
}
2006-12-15 05:39:06 +00:00
else if( !memcmp( id, "XBT", 3 ) )
{
2006-12-15 06:16:20 +00:00
asprintf( &ret, "XBT Client %c%c%c%s", id[3], id[4], id[5],
2006-12-15 05:39:06 +00:00
id[6] == 'd' ? " (debug)" : "" );
}
2006-12-17 22:11:02 +00:00
else if( !memcmp( id, "LIME", 4 ) )
{
asprintf( &ret, "Limewire (%c%c%c%c)", id[4], id[5], id[6], id[7] );
}
2006-12-19 02:57:36 +00:00
else if( !memcmp( id, "-G3", 3 ) )
{
asprintf( &ret, "G3 Torrent" );
}
2006-12-19 16:30:34 +00:00
else if( !memcmp( id, "10-------", 9 ) )
{
asprintf( &ret, "JVtorrent" );
}
2006-07-16 19:39:23 +00:00
/* No match */
2006-07-16 19:39:23 +00:00
if( !ret )
{
2006-12-16 20:05:20 +00:00
if( id[0] != 0 )
2006-08-14 22:59:30 +00:00
{
asprintf( &ret, "unknown client (%c%c%c%c%c%c%c%c)",
2006-07-16 19:39:23 +00:00
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
2006-08-14 22:59:30 +00:00
}
else
2006-08-14 22:59:30 +00:00
{
asprintf( &ret, "unknown client" );
2006-08-14 22:59:30 +00:00
}
2006-07-16 19:39:23 +00:00
}
return ret;
}