transmission/libtransmission/clients.c

320 lines
10 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], "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 ) || !memcmp( &id[1], "S~", 2 ) )
2006-07-16 19:39:23 +00:00
{
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%c)",
id[4], 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] ) );
}
2007-02-16 02:56:19 +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], "KT", 2 ) )
{
2007-03-16 14:28:57 +00:00
if( id[5] == 'R' )
{
asprintf( &ret, "KTorrent %c.%c RC %c",
id[3], id[4], id[6] );
}
else if( id[5] == 'D' )
{
asprintf( &ret, "KTorrent %c.%c Dev",
id[3], id[4] );
}
else
{
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",
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] );
}
2007-01-16 15:49:13 +00:00
else if( !memcmp( &id[1], "AX", 2 ) )
{
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",
charToInt( id[3] ), charToInt( id[4] ),
charToInt( id[5] ) );
}
2007-01-31 02:11:18 +00:00
else if( !memcmp( &id[1], "AG", 2 ) )
{
asprintf( &ret, "Ares Galaxy %d.%d.%d",
charToInt( id[3] ), charToInt( id[4] ),
charToInt( id[5] ) );
}
else if( !memcmp( &id[1], "AR", 2 ) )
{
asprintf( &ret, "Arctic Torrent" );
}
2007-03-14 02:08:40 +00:00
else if( !memcmp( &id[1], "BG", 2 ) )
{
asprintf( &ret, "BTG %c.%c.%c.%c",
id[3], id[4], id[5], id[6] );
}
if( ret )
{
return ret;
}
2006-07-16 19:39:23 +00:00
}
2006-12-19 16:30:34 +00:00
/* Tornado-style */
2007-02-14 16:21:59 +00:00
if( !memcmp( &id[4], "----", 4 ) || !memcmp( &id[4], "--0", 3 ) )
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
}
2007-02-14 16:21:59 +00:00
else if( id[0] == 'R' )
{
asprintf( &ret, "Tribler %c.%c", id[1], id[2] );
}
2007-02-14 16:30:11 +00:00
else if( id[0] == 'S' )
{
asprintf( &ret, "Shad0w's Client %d.%d.%d", charToInt( id[1] ),
charToInt( id[2] ), charToInt( id[3] ) );
}
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] );
}
2007-01-08 04:41:18 +00:00
else if( !memcmp( id, "AZ", 2 ) && !memcmp( &id[6], "BT", 2 ) )
{
2007-01-08 15:18:05 +00:00
asprintf( &ret, "BitTyrant %c.%c.%c.%c",
2007-01-08 04:41:18 +00:00
id[2], id[3], id[4], id[5] );
}
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-29 02:09:16 +00:00
else if( !memcmp( id, "Mbrst", 5 ) )
{
asprintf( &ret, "burst! %c.%c.%c", id[5], id[7], id[9] );
}
2007-01-02 03:33:55 +00:00
else if( !memcmp( id, "btpd", 4 ) )
{
asprintf( &ret, "BT Protocol Daemon %c%c%c", id[5], id[6], id[7] );
}
2006-12-17 22:11:02 +00:00
else if( !memcmp( id, "LIME", 4 ) )
{
asprintf( &ret, "Limewire" );
2006-12-17 22:11:02 +00:00
}
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-12-30 18:00:45 +00:00
else if( !memcmp( id, "346-", 4 ) )
{
asprintf( &ret, "TorrentTopia" );
}
2007-01-01 20:03:52 +00:00
else if( !memcmp( id, "eX", 2 ) )
{
asprintf( &ret, "eXeem" );
}
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;
}