~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to src/identify_client.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
        {
70
70
                fingerprint ret("..", 0, 0, 0, 0);
71
71
 
72
 
                if (id[0] != '-' || !isprint(id[1]) || (id[2] < '0')
 
72
                if (id[0] != '-' || !is_print(id[1]) || (id[2] < '0')
73
73
                        || (id[3] < '0') || (id[4] < '0')
74
74
                        || (id[5] < '0') || (id[6] < '0')
75
75
                        || id[7] != '-')
131
131
                ret.tag_version = 0;
132
132
                if (sscanf(ids, "%c%d-%d-%d--", &ret.name[0], &ret.major_version, &ret.minor_version
133
133
                        , &ret.revision_version) != 4
134
 
                        || !isprint(ret.name[0]))
 
134
                        || !is_print(ret.name[0]))
135
135
                        return boost::optional<fingerprint>();
136
136
 
137
137
                return boost::optional<fingerprint>(ret);
163
163
                , {"BX", "BittorrentX"}
164
164
                , {"CD", "Enhanced CTorrent"}
165
165
                , {"CT", "CTorrent"}
166
 
                , {"DE", "Deluge Torrent"}
 
166
                , {"DE", "Deluge"}
167
167
                , {"EB", "EBit"}
168
168
                , {"ES", "electric sheep"}
169
169
                , {"HL", "Halite"}
260
260
 
261
261
        std::string lookup(fingerprint const& f)
262
262
        {
263
 
                std::stringstream identity;
 
263
                char identity[200];
264
264
 
265
265
                const int size = sizeof(name_map)/sizeof(name_map[0]);
266
266
                map_entry tmp = {f.name, ""};
268
268
                        std::lower_bound(name_map, name_map + size
269
269
                                , tmp, &compare_id);
270
270
 
271
 
#ifdef TORRENT_DEBUG
 
271
#ifndef NDEBUG
272
272
                for (int i = 1; i < size; ++i)
273
273
                {
274
274
                        TORRENT_ASSERT(compare_id(name_map[i-1]
276
276
                }
277
277
#endif
278
278
 
 
279
                char temp[3];
 
280
                char const* name = 0;
279
281
                if (i < name_map + size && std::equal(f.name, f.name + 2, i->id))
280
 
                        identity << i->name;
 
282
                {
 
283
                        name = i->name;
 
284
                }
281
285
                else
282
286
                {
283
 
                        identity << f.name[0];
284
 
                        if (f.name[1] != 0) identity << f.name[1];
 
287
                        // if we don't have this client in the list
 
288
                        // just use the one or two letter code
 
289
                        memcpy(temp, f.name, 2);
 
290
                        temp[2] = 0;
 
291
                        name = temp;
285
292
                }
286
293
 
287
 
                identity << " " << (int)f.major_version
288
 
                        << "." << (int)f.minor_version
289
 
                        << "." << (int)f.revision_version;
 
294
                int num_chars = snprintf(identity, sizeof(identity), "%s %u.%u.%u", name
 
295
                        , f.major_version, f.minor_version, f.revision_version);
290
296
 
291
297
                if (f.tag_version != 0)
292
 
                        identity << "." << (int)f.tag_version;
 
298
                {
 
299
                        snprintf(identity + num_chars, sizeof(identity) - num_chars
 
300
                                , ".%u", f.tag_version);
 
301
                }
293
302
 
294
 
                return identity.str();
 
303
                return identity;
295
304
        }
296
305
 
297
306
        bool find_string(unsigned char const* id, char const* search)
340
349
                }
341
350
 
342
351
                if (find_string(PID, "-BOW") && PID[7] == '-')
343
 
                        return "Bits on Wheels " + std::string(PID + 4, PID + 7);
 
352
                        return "Bits on Wheels " + std::string((char const*)PID + 4, (char const*)PID + 7);
344
353
                
345
354
 
346
355
                if (find_string(PID, "eX"))
347
356
                {
348
 
                        std::string user(PID + 2, PID + 14);
 
357
                        std::string user((char const*)PID + 2, (char const*)PID + 14);
349
358
                        return std::string("eXeem ('") + user.c_str() + "')"; 
350
359
                }
351
360
 
355
364
                if (std::equal(PID, PID + 13, "\0\0\0\0\0\0\0\0\0\0\0\0\0"))
356
365
                        return "Experimental 3.1";
357
366
 
358
 
                
 
367
 
359
368
                // look for azureus style id
360
369
                f = parse_az_style(p);
361
370
                if (f) return lookup(*f);
367
376
                // look for mainline style id
368
377
                f = parse_mainline_style(p);
369
378
                if (f) return lookup(*f);
370
 
                                                                                                                
371
 
                
 
379
 
 
380
 
372
381
                if (std::equal(PID, PID + 12, "\0\0\0\0\0\0\0\0\0\0\0\0"))
373
382
                        return "Generic";
374
383
 
375
384
                std::string unknown("Unknown [");
376
385
                for (peer_id::const_iterator i = p.begin(); i != p.end(); ++i)
377
386
                {
378
 
                        unknown += isprint(char(*i))?*i:'.';
 
387
                        unknown += is_print(char(*i))?*i:'.';
379
388
                }
380
389
                unknown += "]";
381
390
                return unknown;