mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
roll back the last two diffs (r6582 and r6583) in favor of a simpler/cleaner/better fix
This commit is contained in:
@@ -761,7 +761,7 @@ processResponse( const char * host, int port,
|
||||
fprintf( stderr, "got response: [%*.*s]\n",
|
||||
(int)len, (int)len, (const char*) response );
|
||||
|
||||
if( tr_jsonParse( response, len, &top ) )
|
||||
if( tr_jsonParse( response, len, &top, NULL ) )
|
||||
tr_nerr( MY_NAME, "Unable to parse response \"%*.*s\"", (int)len, (int)len, (char*)response );
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1314,7 +1314,7 @@ tr_bencLoadJSONFile( const char * filename, tr_benc * b )
|
||||
int ret;
|
||||
size_t contentLen;
|
||||
uint8_t * content = tr_loadFile( filename, &contentLen );
|
||||
ret = content ? tr_jsonParse( content, contentLen, b )
|
||||
ret = content ? tr_jsonParse( content, contentLen, b, NULL )
|
||||
: TR_ERROR_IO_OTHER;
|
||||
tr_free( content );
|
||||
return ret;
|
||||
|
||||
@@ -14,8 +14,7 @@ static int test = 0;
|
||||
if( VERBOSE ) \
|
||||
fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
||||
} else { \
|
||||
if( VERBOSE ) \
|
||||
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
||||
fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
|
||||
return test; \
|
||||
} \
|
||||
}
|
||||
@@ -25,10 +24,13 @@ test_utf8( void )
|
||||
{
|
||||
const char * in = "{ \"key\": \"Letöltések\" }";
|
||||
tr_benc top;
|
||||
const int err = tr_jsonParse( in, strlen(in), &top );
|
||||
const char * str;
|
||||
const int err = tr_jsonParse( in, strlen(in), &top, NULL );
|
||||
|
||||
check( !err );
|
||||
check( tr_bencIsDict( &top ) );
|
||||
check( tr_bencDictFindStr( &top, "key", &str ) );
|
||||
check( !strcmp( str, "Letöltések" ) );
|
||||
|
||||
if( !err )
|
||||
tr_bencFree( &top );
|
||||
@@ -55,7 +57,7 @@ test1( void )
|
||||
tr_benc top, *headers, *body, *args, *ids;
|
||||
const char * str;
|
||||
int64_t i;
|
||||
const int err = tr_jsonParse( in, strlen(in), &top );
|
||||
const int err = tr_jsonParse( in, strlen(in), &top, NULL );
|
||||
|
||||
check( !err );
|
||||
check( tr_bencIsDict( &top ) );
|
||||
@@ -87,6 +89,9 @@ main( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
if(( i = test_utf8( )))
|
||||
return i;
|
||||
|
||||
if(( i = test_utf8( )))
|
||||
return i;
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <event.h> /* evbuffer */
|
||||
|
||||
#include "ConvertUTF.h"
|
||||
#include "JSON_parser.h"
|
||||
|
||||
#include "transmission.h"
|
||||
@@ -108,12 +107,12 @@ callback( void * vdata, int type, const JSON_value * value )
|
||||
break;
|
||||
|
||||
case JSON_T_STRING:
|
||||
tr_bencInitRaw( getNode( data ), value->vu.str.value, value->vu.str.length );
|
||||
tr_bencInitStrDup( getNode( data ), value->vu.str.value );
|
||||
break;
|
||||
|
||||
case JSON_T_KEY:
|
||||
assert( !data->key );
|
||||
data->key = tr_strndup( value->vu.str.value, value->vu.str.length );
|
||||
data->key = tr_strdup( value->vu.str.value );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -123,17 +122,15 @@ callback( void * vdata, int type, const JSON_value * value )
|
||||
int
|
||||
tr_jsonParse( const void * vbuf,
|
||||
size_t len,
|
||||
tr_benc * setme_benc )
|
||||
tr_benc * setme_benc,
|
||||
const uint8_t ** setme_end )
|
||||
{
|
||||
int err = 0;
|
||||
const unsigned char * buf = vbuf;
|
||||
const void * bufend = buf + len;
|
||||
struct JSON_config_struct config;
|
||||
struct JSON_parser_struct * checker;
|
||||
struct json_benc_data data;
|
||||
const UTF8 * utf8_begin;
|
||||
const UTF8 * utf8_end;
|
||||
UTF32 * utf32_begin;
|
||||
UTF32 * utf32_end;
|
||||
UTF32 * utf32_walk;
|
||||
int err = 0;
|
||||
|
||||
init_JSON_config( &config );
|
||||
config.callback = callback;
|
||||
@@ -144,25 +141,16 @@ tr_jsonParse( const void * vbuf,
|
||||
data.top = setme_benc;
|
||||
data.stack = tr_ptrArrayNew( );
|
||||
|
||||
/* convert the utf8 that was passed in, into utf32 so that
|
||||
* we can be certain that each call to JSON_parser_char()
|
||||
* passes through a complete character */
|
||||
utf8_begin = vbuf;
|
||||
utf8_end = utf8_begin; /* inout argument */
|
||||
utf32_begin = tr_new0( UTF32, len );
|
||||
utf32_end = utf32_begin; /* inout argument */
|
||||
ConvertUTF8toUTF32( &utf8_end, utf8_begin+len,
|
||||
&utf32_end, utf32_begin+len, 0 );
|
||||
|
||||
checker = new_JSON_parser( &config );
|
||||
utf32_walk = utf32_begin;
|
||||
while( ( utf32_walk != utf32_end ) && JSON_parser_char( checker, *utf32_walk ) )
|
||||
++utf32_walk;
|
||||
if( utf32_walk != utf32_end )
|
||||
while( ( buf != bufend ) && JSON_parser_char( checker, *buf ) )
|
||||
++buf;
|
||||
if( buf != bufend )
|
||||
err = TR_ERROR;
|
||||
|
||||
if( setme_end )
|
||||
*setme_end = (const uint8_t*) buf;
|
||||
|
||||
delete_JSON_parser( checker );
|
||||
tr_ptrArrayFree( data.stack, NULL );
|
||||
tr_free( utf32_begin );
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
int tr_jsonParse( const void * vbuf,
|
||||
size_t len,
|
||||
struct tr_benc * setme_benc );
|
||||
struct tr_benc * setme_benc,
|
||||
const uint8_t ** setme_end );
|
||||
|
||||
#endif
|
||||
|
||||
@@ -717,7 +717,7 @@ tr_rpc_request_exec_json( struct tr_handle * handle,
|
||||
if( request_len < 0 )
|
||||
request_len = strlen( request_json );
|
||||
|
||||
have_content = !tr_jsonParse( request_json, request_len, &top );
|
||||
have_content = !tr_jsonParse( request_json, request_len, &top, NULL );
|
||||
ret = request_exec( handle, have_content ? &top : NULL, response_len );
|
||||
|
||||
if( have_content )
|
||||
|
||||
Reference in New Issue
Block a user