mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
(trunk libT) tweak the ABI of tr_bencToBuf() to match the way it's being used
This commit is contained in:
parent
6e99c6cd69
commit
c9b54799e3
6 changed files with 24 additions and 24 deletions
|
@ -211,8 +211,7 @@ on_announce_done( tr_session * session,
|
|||
|
||||
if( getenv( "TR_CURL_VERBOSE" ) != NULL )
|
||||
{
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
tr_bencToBuf( &benc, TR_FMT_JSON, buf );
|
||||
struct evbuffer * buf = tr_bencToBuf( &benc, TR_FMT_JSON );
|
||||
fprintf( stderr, "Announce response:\n< %s\n", evbuffer_pullup( buf, -1 ) );
|
||||
tr_free( buf );
|
||||
}
|
||||
|
|
|
@ -323,7 +323,7 @@ testJSONSnippet( const char * benc_str,
|
|||
char * serialized;
|
||||
|
||||
tr_bencLoad( benc_str, strlen( benc_str ), &top, NULL );
|
||||
tr_bencToBuf( &top, TR_FMT_JSON, buf );
|
||||
buf = tr_bencToBuf( &top, TR_FMT_JSON );
|
||||
serialized = (char*) evbuffer_pullup( buf, -1 );
|
||||
stripWhitespace( serialized );
|
||||
#if 0
|
||||
|
|
|
@ -1606,10 +1606,11 @@ tr_bencMergeDicts( tr_benc * target, const tr_benc * source )
|
|||
****
|
||||
***/
|
||||
|
||||
void
|
||||
tr_bencToBuf( const tr_benc * top, tr_fmt_mode mode, struct evbuffer * buf )
|
||||
struct evbuffer *
|
||||
tr_bencToBuf( const tr_benc * top, tr_fmt_mode mode )
|
||||
{
|
||||
evbuffer_drain( buf, evbuffer_get_length( buf ) );
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
|
||||
evbuffer_expand( buf, 4096 ); /* alloc a little memory to start off with */
|
||||
|
||||
switch( mode )
|
||||
|
@ -1630,17 +1631,16 @@ tr_bencToBuf( const tr_benc * top, tr_fmt_mode mode, struct evbuffer * buf )
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
char*
|
||||
tr_bencToStr( const tr_benc * top, tr_fmt_mode mode, int * len )
|
||||
{
|
||||
char * ret;
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
size_t n;
|
||||
tr_bencToBuf( top, mode, buf );
|
||||
n = evbuffer_get_length( buf );
|
||||
ret = evbuffer_free_to_str( buf );
|
||||
struct evbuffer * buf = tr_bencToBuf( top, mode );
|
||||
const size_t n = evbuffer_get_length( buf );
|
||||
char * ret = evbuffer_free_to_str( buf );
|
||||
if( len != NULL )
|
||||
*len = (int) n;
|
||||
return ret;
|
||||
|
|
|
@ -125,7 +125,7 @@ int tr_bencToFile( const tr_benc *, tr_fmt_mode, const char * filename );
|
|||
|
||||
char* tr_bencToStr( const tr_benc *, tr_fmt_mode, int * len );
|
||||
|
||||
void tr_bencToBuf( const tr_benc *, tr_fmt_mode, struct evbuffer * );
|
||||
struct evbuffer * tr_bencToBuf( const tr_benc *, tr_fmt_mode );
|
||||
|
||||
/* TR_FMT_JSON_LEAN and TR_FMT_JSON are equivalent in this function. */
|
||||
int tr_bencLoadFile( tr_benc * setme, tr_fmt_mode, const char * filename );
|
||||
|
|
|
@ -270,8 +270,7 @@ handle_upload( struct evhttp_request * req,
|
|||
|
||||
if( have_source )
|
||||
{
|
||||
struct evbuffer * json = evbuffer_new( );
|
||||
tr_bencToBuf( &top, TR_FMT_JSON, json );
|
||||
struct evbuffer * json = tr_bencToBuf( &top, TR_FMT_JSON );
|
||||
tr_rpc_request_exec_json( server->session,
|
||||
evbuffer_pullup( json, -1 ),
|
||||
evbuffer_get_length( json ),
|
||||
|
|
|
@ -94,16 +94,16 @@ struct tr_rpc_idle_data
|
|||
static void
|
||||
tr_idle_function_done( struct tr_rpc_idle_data * data, const char * result )
|
||||
{
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
struct evbuffer * buf;
|
||||
|
||||
if( result == NULL )
|
||||
result = "success";
|
||||
tr_bencDictAddStr( data->response, "result", result );
|
||||
|
||||
tr_bencToBuf( data->response, TR_FMT_JSON_LEAN, buf );
|
||||
buf = tr_bencToBuf( data->response, TR_FMT_JSON_LEAN );
|
||||
(*data->callback)( data->session, buf, data->callback_user_data );
|
||||
|
||||
evbuffer_free( buf );
|
||||
|
||||
tr_bencFree( data->response );
|
||||
tr_free( data->response );
|
||||
tr_free( data );
|
||||
|
@ -1715,17 +1715,18 @@ request_exec( tr_session * session,
|
|||
{
|
||||
int64_t tag;
|
||||
tr_benc response;
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
struct evbuffer * buf;
|
||||
|
||||
tr_bencInitDict( &response, 3 );
|
||||
tr_bencDictAddDict( &response, "arguments", 0 );
|
||||
tr_bencDictAddStr( &response, "result", result );
|
||||
if( tr_bencDictFindInt( request, "tag", &tag ) )
|
||||
tr_bencDictAddInt( &response, "tag", tag );
|
||||
tr_bencToBuf( &response, TR_FMT_JSON_LEAN, buf );
|
||||
(*callback)( session, buf, callback_user_data );
|
||||
|
||||
buf = tr_bencToBuf( &response, TR_FMT_JSON_LEAN );
|
||||
(*callback)( session, buf, callback_user_data );
|
||||
evbuffer_free( buf );
|
||||
|
||||
tr_bencFree( &response );
|
||||
}
|
||||
else if( methods[i].immediate )
|
||||
|
@ -1733,7 +1734,7 @@ request_exec( tr_session * session,
|
|||
int64_t tag;
|
||||
tr_benc response;
|
||||
tr_benc * args_out;
|
||||
struct evbuffer * buf = evbuffer_new( );
|
||||
struct evbuffer * buf;
|
||||
|
||||
tr_bencInitDict( &response, 3 );
|
||||
args_out = tr_bencDictAddDict( &response, "arguments", 0 );
|
||||
|
@ -1743,10 +1744,11 @@ request_exec( tr_session * session,
|
|||
tr_bencDictAddStr( &response, "result", result );
|
||||
if( tr_bencDictFindInt( request, "tag", &tag ) )
|
||||
tr_bencDictAddInt( &response, "tag", tag );
|
||||
tr_bencToBuf( &response, TR_FMT_JSON_LEAN, buf );
|
||||
(*callback)( session, buf, callback_user_data );
|
||||
|
||||
buf = tr_bencToBuf( &response, TR_FMT_JSON_LEAN );
|
||||
(*callback)( session, buf, callback_user_data );
|
||||
evbuffer_free( buf );
|
||||
|
||||
tr_bencFree( &response );
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue