1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

Remove tr_bencListIter(), it was a stupid idea.

This commit is contained in:
Josh Elsasser 2007-03-31 17:40:28 +00:00
parent 57e28bd661
commit ebcc73121b
5 changed files with 26 additions and 54 deletions

View file

@ -90,7 +90,7 @@ int _tr_bencLoad( char * buf, int len, benc_val_t * val, char ** end )
}
tr_bencInitInt( val, num );
val->end = p + 1;
*end = p + 1;
}
else if( buf[0] == 'l' || buf[0] == 'd' )
{
@ -133,7 +133,7 @@ int _tr_bencLoad( char * buf, int len, benc_val_t * val, char ** end )
return 1;
}
val->end = cur + 1;
*end = cur + 1;
}
else
{
@ -166,11 +166,11 @@ int _tr_bencLoad( char * buf, int len, benc_val_t * val, char ** end )
sbuf[slen] = '\0';
tr_bencInitStr( val, sbuf, slen, 0 );
val->end = p + 1 + val->val.s.i;
*end = p + 1 + val->val.s.i;
}
val->begin = buf;
*end = val->end;
val->end = *end;
return 0;
}
@ -243,7 +243,7 @@ void tr_bencFree( benc_val_t * val )
benc_val_t * tr_bencDictFind( benc_val_t * val, const char * key )
{
int len, i;
int len, ii;
if( val->type != TYPE_DICT )
{
@ -252,17 +252,15 @@ benc_val_t * tr_bencDictFind( benc_val_t * val, const char * key )
len = strlen( key );
for( i = 0; i < val->val.l.count; i += 2 )
for( ii = 0; ii + 1 < val->val.l.count; ii += 2 )
{
if( TYPE_STR != val->val.l.vals[i].type ||
len != val->val.l.vals[i].val.s.i )
if( TYPE_STR != val->val.l.vals[ii].type ||
len != val->val.l.vals[ii].val.s.i ||
0 != memcmp( val->val.l.vals[ii].val.s.s, key, len ) )
{
continue;
}
if( 0 == memcmp(val->val.l.vals[i].val.s.s, key, len ) )
{
return &val->val.l.vals[i+1];
}
return &val->val.l.vals[ii+1];
}
return NULL;
@ -288,30 +286,6 @@ benc_val_t * tr_bencDictFindFirst( benc_val_t * val, ... )
return ret;
}
benc_val_t * tr_bencListIter( benc_val_t * list, int * pos )
{
assert( TYPE_LIST == list->type );
if( NULL == list->val.l.vals )
{
return NULL;
}
if( 0 > *pos )
{
*pos = 0;
}
if( list->val.l.count <= *pos )
{
return NULL;
}
(*pos)++;
return &list->val.l.vals[ (*pos) - 1 ];
}
char * tr_bencStealStr( benc_val_t * val )
{
assert( TYPE_STR == val->type );

View file

@ -60,8 +60,6 @@ void tr_bencFree( benc_val_t * val );
benc_val_t * tr_bencDictFind( benc_val_t * val, const char * key );
benc_val_t * tr_bencDictFindFirst( benc_val_t * val, ... );
benc_val_t * tr_bencListIter( benc_val_t * list, int * pos );
/* marks a string as 'do not free' and returns it */
char * tr_bencStealStr( benc_val_t * val );

View file

@ -243,9 +243,9 @@ static int getfile( char * buf, int size,
return 1;
}
ii = jj = 0;
while( NULL != ( dir = tr_bencListIter( name, &ii ) ) )
for( ii = jj = 0; name->val.l.count > ii; ii++ )
{
dir = &name->val.l.vals[ii];
if( TYPE_STR != dir->type )
{
continue;
@ -297,9 +297,9 @@ static int getannounce( tr_info_t * inf, benc_val_t * meta )
val->val.l.count );
/* iterate through the announce-list's tiers */
ii = 0;
while( NULL != ( subval = tr_bencListIter( val, &ii ) ) )
for( ii = 0; ii < val->val.l.count; ii++ )
{
subval = &val->val.l.vals[ii];
if( TYPE_LIST != subval->type || 0 >= subval->val.l.count )
{
continue;
@ -308,9 +308,9 @@ static int getannounce( tr_info_t * inf, benc_val_t * meta )
sublist = calloc( sizeof( sublist[0] ), subval->val.l.count );
/* iterate through the tier's items */
jj = 0;
while( NULL != ( urlval = tr_bencListIter( subval, &jj ) ) )
for( jj = 0; jj < subval->val.l.count; jj++ )
{
urlval = &subval->val.l.vals[jj];
if( TYPE_STR != urlval->type ||
tr_httpParseUrl( urlval->val.s.s, urlval->val.s.i,
&address, &port, &announce ) )
@ -608,12 +608,11 @@ parseFiles( tr_info_t * inf, benc_val_t * name,
return 1;
}
item = NULL;
ii = 0;
while( NULL != ( item = tr_bencListIter( files, &ii ) ) )
for( ii = 0; files->val.l.count > ii; ii++ )
{
item = &files->val.l.vals[ii];
path = tr_bencDictFindFirst( item, "path.utf-8", "path", NULL );
if( getfile( inf->files[ii-1].name, sizeof( inf->files[ii-1].name ),
if( getfile( inf->files[ii-1].name, sizeof( inf->files[0].name ),
inf->name, path ) )
{
tr_err( "%s \"path\" entry",

View file

@ -382,9 +382,9 @@ parseAZHandshake( tr_peer_t * peer, uint8_t * buf, int len )
/* fill bitmask with supported message info */
msgs = tr_bitfieldNew( azmsgCount() );
ii = -1;
while( NULL != ( dict = tr_bencListIter( sub, &ii ) ) )
for( ii = 0; ii < sub->val.l.count; ii++ )
{
dict = &sub->val.l.vals[ii];
if( TYPE_DICT != dict->type )
{
continue;
@ -475,9 +475,10 @@ parseAZPex( tr_torrent_t * tor, tr_peer_t * peer, uint8_t * buf, int len )
return TR_OK;
}
ii = used = 0;
while( NULL != ( pair = tr_bencListIter( list, &ii ) ) )
used = 0;
for( ii = 0; ii < list->val.l.count; ii++ )
{
pair = &list->val.l.vals[ii];
if( TYPE_STR == pair->type && 6 == pair->val.s.i )
{
used += tr_torrentAddCompact( tor, TR_PEER_FROM_PEX,

View file

@ -1099,9 +1099,9 @@ parseOriginalPeers( benc_val_t * bePeers, int * peerCount )
return NULL;
}
ii = -1;
while( NULL != ( peer = tr_bencListIter( bePeers, &ii ) ) )
for( ii = 0; bePeers->val.l.count > ii; ii++ )
{
peer = &bePeers->val.l.vals[ii];
addrval = tr_bencDictFind( peer, "ip" );
if( NULL == addrval || TYPE_STR != addrval->type ||
tr_netResolve( addrval->val.s.s, &addr ) )