source: trunk/libtransmission/clients.c @ 1267

Last change on this file since 1267 was 1267, checked in by livings124, 16 years ago

add client Bittorrent Plus!

  • Property svn:keywords set to Date Rev Author Id
File size: 7.5 KB
Line 
1/******************************************************************************
2 * $Id: clients.c 1267 2006-12-22 23:34:35Z livings124 $
3 *
4 * Copyright (c) 2005 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#include "transmission.h"
26
27static int charToInt( char character );
28
29static int charToInt( char character )
30{
31    int value;
32    if( character >= 'A' && character <= 'Z' )
33        value = 10 + character - 'A';
34    else
35        value = character - '0';
36   
37    return value;
38}
39
40char * tr_clientForId( uint8_t * id )
41{
42    char * ret = NULL;
43   
44    /* Azureus style */
45    if( id[0] == '-' && id[7] == '-' )
46    {
47        if( !memcmp( &id[1], "TR", 2 ) )
48        {
49            asprintf( &ret, "Transmission %d.%d",
50                      charToInt( id[3] ) * 10 + charToInt( id[4] ),
51                      charToInt( id[5] ) * 10 + charToInt( id[6] ) );
52        }
53        else if( !memcmp( &id[1], "AZ", 2 ) )
54        {
55            asprintf( &ret, "Azureus %c.%c.%c.%c",
56                      id[3], id[4], id[5], id[6] );
57        }
58        else if( !memcmp( &id[1], "TS", 2 ) )
59        {
60            asprintf( &ret, "TorrentStorm (%c%c%c%c)",
61                      id[3], id[4], id[5], id[6] );
62        }
63        else if( !memcmp( &id[1], "BC", 2 ) )
64        {
65            asprintf( &ret, "BitComet %d.%c%c",
66                      charToInt( id[3] ) * 10 + charToInt( id[4] ),
67                      id[5], id[6] );
68        }
69        else if( !memcmp( &id[1], "SZ", 2 ) )
70        {
71            asprintf( &ret, "Shareaza %c.%c.%c.%c",
72                      id[3], id[4], id[5], id[6] );
73        }
74        else if( !memcmp( &id[1], "UT", 2 ) )
75        {
76            asprintf( &ret, "\xc2\xb5Torrent %c.%d", id[3],
77                      charToInt( id[4] ) * 10 + charToInt( id[5] ) );
78        }
79        else if( !memcmp( &id[1], "BOW", 3 ) )
80        {
81            asprintf( &ret, "Bits on Wheels (%c%c)",
82                      id[5], id[6] );
83        }
84        else if( !memcmp( &id[1], "BR", 2 ) )
85        {
86            asprintf( &ret, "BitRocket %c.%c (%d)",
87                      id[3], id[4], charToInt( id[5] ) * 10 + charToInt( id[6] ) );
88        }
89        else if( !memcmp( &id[1], "KT", 2 ) )
90        {
91            asprintf( &ret, "KTorrent %c.%c.%c.%c",
92                      id[3], id[4], id[5], id[6] );
93        }
94        else if( !memcmp( &id[1], "lt", 2 ) )
95        {
96            asprintf( &ret, "libTorrent %d.%d.%d.%d",
97                      charToInt( id[3] ), charToInt( id[4] ),
98                      charToInt( id[5] ), charToInt( id[6] ) );
99        }
100        else if( !memcmp( &id[1], "LT", 2 ) )
101        {
102            asprintf( &ret, "libtorrent %d.%d.%d.%d",
103                      charToInt( id[3] ), charToInt( id[4] ),
104                      charToInt( id[5] ), charToInt( id[6] ) );
105        }
106        else if( !memcmp( &id[1], "ES", 2 ) )
107        {
108            asprintf( &ret, "Electric Sheep %c.%c.%c",
109                      id[3], id[4], id[5] );
110        }
111        else if( !memcmp( &id[1], "CD", 2 ) )
112        {
113            asprintf( &ret, "CTorrent %d.%d",
114                      charToInt( id[3] ) * 10 + charToInt( id[4] ),
115                      charToInt( id[5] ) * 10 + charToInt( id[6] ) );
116        }
117        else if( !memcmp( &id[1], "LP", 2 ) )
118        {
119            asprintf( &ret, "Lphant %d.%c%c",
120                      charToInt( id[3] ) * 10 + charToInt( id[4] ),
121                      id[5], id[6] );
122        }
123       
124        if( ret )
125        {
126            return ret;
127        }
128    }
129   
130    /* Tornado-style */
131    if( !memcmp( &id[4], "----", 4 ) || !memcmp( &id[4], "--00", 4 ) )
132    {
133        if( id[0] == 'T' )
134        {
135            asprintf( &ret, "BitTornado %d.%d.%d", charToInt( id[1] ),
136                        charToInt( id[2] ), charToInt( id[3] ) );
137        }
138        else if( id[0] == 'A' )
139        {
140            asprintf( &ret, "ABC %d.%d.%d", charToInt( id[1] ),
141                        charToInt( id[2] ), charToInt( id[3] ) );
142        }
143       
144        if( ret )
145        {
146            return ret;
147        }
148    }
149   
150    /* Different formatting per client */
151    if( id[0] == 'M' && id[2] == '-' && id[7] == '-' )
152    {
153        if( id[4] == '-' && id[6] == '-' )
154        {
155            asprintf( &ret, "BitTorrent %c.%c.%c", id[1], id[3], id[5] );
156        }
157        else if( id[5] == '-' )
158        {
159            asprintf( &ret, "BitTorrent %c.%c%c.%c", id[1], id[3], id[4], id[6] );
160        }
161       
162        if( ret )
163        {
164            return ret;
165        }
166    }
167    if( id[0] == 'Q' && id[2] == '-' && id[7] == '-' )
168    {
169        if( id[4] == '-' && id[6] == '-' )
170        {
171            asprintf( &ret, "Queen Bee %c.%c.%c", id[1], id[3], id[5] );
172        }
173        else if( id[5] == '-' )
174        {
175            asprintf( &ret, "Queen Bee %c.%c%c.%c", id[1], id[3], id[4], id[6] );
176        }
177       
178        if( ret )
179        {
180            return ret;
181        }
182    }
183   
184    /* All versions of each client are formatted the same */
185    if( !memcmp( id, "exbc", 4 ) )
186    {
187        asprintf( &ret, "%s %d.%02d",
188                    !memcmp( &id[6], "LORD", 4 ) ? "BitLord" : "BitComet",
189                    id[4], id[5] );
190    }
191    else if( !memcmp( id, "OP", 2 ) )
192    {
193        asprintf( &ret, "Opera (%c%c%c%c)", id[2], id[3], id[4], id[5] );
194    }
195    else if( !memcmp( id, "-ML", 3 ) )
196    {
197        asprintf( &ret, "MLDonkey %c%c%c%c%c",
198                  id[3], id[4], id[5], id[6], id[7] );
199    }
200    else if( !memcmp( id, "-FG", 3 ) )
201    {
202        asprintf( &ret, "FlashGet %d.%c%c",
203                  charToInt( id[3] ) * 10 + charToInt( id[4] ),
204                      id[5], id[6] );
205    }
206    else if( !memcmp( id, "Plus", 4 ) )
207    {
208        asprintf( &ret, "Plus! %c.%c%c", id[4], id[5], id[6] );
209    }
210    else if( !memcmp( id, "XBT", 3 ) )
211    {
212        asprintf( &ret, "XBT Client %c%c%c%s", id[3], id[4], id[5],
213                  id[6] == 'd' ? " (debug)" : "" );
214    }
215    else if( !memcmp( id, "LIME", 4 ) )
216    {
217        asprintf( &ret, "Limewire (%c%c%c%c)", id[4], id[5], id[6], id[7] );
218    }
219    else if( !memcmp( id, "-G3", 3 ) )
220    {
221        asprintf( &ret, "G3 Torrent" );
222    }
223    else if( !memcmp( id, "10-------", 9 ) )
224    {
225        asprintf( &ret, "JVtorrent" );
226    }
227
228    /* No match */
229    if( !ret )
230    {
231        if( id[0] != 0 )
232        {
233            asprintf( &ret, "unknown client (%c%c%c%c%c%c%c%c)",
234                  id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
235        }
236        else
237        {
238            asprintf( &ret, "unknown client" );
239        }
240    }
241
242    return ret;
243}
Note: See TracBrowser for help on using the repository browser.