Changeset 2024


Ignore:
Timestamp:
Jun 10, 2007, 3:38:58 PM (15 years ago)
Author:
titer
Message:

Bencoded dictionaries are now sorted alphabetically, this should fix
compatibility with some clients, incl. BitTornado?-based ones.
(Reported by roee88 from LH-ABC)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r1857 r2024  
    391391{
    392392    benc_val_t * keyval, * itemval;
     393    int i;
    393394
    394395    assert( TYPE_DICT == dict->type );
    395396    assert( dict->val.l.count + 2 <= dict->val.l.alloc );
    396397
    397     keyval  = &dict->val.l.vals[dict->val.l.count];
    398     dict->val.l.count++;
    399     itemval = &dict->val.l.vals[dict->val.l.count];
    400     dict->val.l.count++;
     398    /* Keep dictionaries sorted by keys alphabetically.
     399       BitTornado-based clients (and maybe others) need this. */
     400    for( i = 0; i < dict->val.l.count; i += 2 )
     401    {
     402        assert( TYPE_STR == dict->val.l.vals[i].type );
     403        if( strcmp( key, dict->val.l.vals[i].val.s.s ) < 0 )
     404            break;
     405    }
     406    memmove( &dict->val.l.vals[i+2], &dict->val.l.vals[i],
     407             ( dict->val.l.count - i ) * sizeof(benc_val_t) );
     408    keyval  = &dict->val.l.vals[i];
     409    itemval = &dict->val.l.vals[i+1];
     410    dict->val.l.count += 2;
    401411
    402412    tr_bencInitStr( keyval, key, -1, 1 );
Note: See TracChangeset for help on using the changeset viewer.