mirror of
https://github.com/transmission/transmission
synced 2025-02-03 21:12:05 +00:00
Bencoded dictionaries are now sorted alphabetically, this should fix
compatibility with some clients, incl. BitTornado-based ones. (Reported by roee88 from LH-ABC)
This commit is contained in:
parent
b96a30d7c1
commit
ba5bb320ca
1 changed files with 14 additions and 4 deletions
|
@ -390,14 +390,24 @@ benc_val_t * tr_bencListAdd( benc_val_t * list )
|
|||
benc_val_t * tr_bencDictAdd( benc_val_t * dict, const char * key )
|
||||
{
|
||||
benc_val_t * keyval, * itemval;
|
||||
int i;
|
||||
|
||||
assert( TYPE_DICT == dict->type );
|
||||
assert( dict->val.l.count + 2 <= dict->val.l.alloc );
|
||||
|
||||
keyval = &dict->val.l.vals[dict->val.l.count];
|
||||
dict->val.l.count++;
|
||||
itemval = &dict->val.l.vals[dict->val.l.count];
|
||||
dict->val.l.count++;
|
||||
/* Keep dictionaries sorted by keys alphabetically.
|
||||
BitTornado-based clients (and maybe others) need this. */
|
||||
for( i = 0; i < dict->val.l.count; i += 2 )
|
||||
{
|
||||
assert( TYPE_STR == dict->val.l.vals[i].type );
|
||||
if( strcmp( key, dict->val.l.vals[i].val.s.s ) < 0 )
|
||||
break;
|
||||
}
|
||||
memmove( &dict->val.l.vals[i+2], &dict->val.l.vals[i],
|
||||
( dict->val.l.count - i ) * sizeof(benc_val_t) );
|
||||
keyval = &dict->val.l.vals[i];
|
||||
itemval = &dict->val.l.vals[i+1];
|
||||
dict->val.l.count += 2;
|
||||
|
||||
tr_bencInitStr( keyval, key, -1, 1 );
|
||||
tr_bencInit( itemval, TYPE_INT );
|
||||
|
|
Loading…
Reference in a new issue