Changeset 6584


Ignore:
Timestamp:
Aug 18, 2008, 3:44:09 AM (13 years ago)
Author:
charles
Message:

roll back the last two diffs (r6582 and r6583) in favor of a simpler/cleaner/better fix

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/remote.c

    r6583 r6584  
    762762                 (int)len, (int)len, (const char*) response );
    763763
    764     if( tr_jsonParse( response, len, &top ) )
     764    if( tr_jsonParse( response, len, &top, NULL ) )
    765765       tr_nerr( MY_NAME, "Unable to parse response \"%*.*s\"", (int)len, (int)len, (char*)response );
    766766    else
  • trunk/libtransmission/bencode.c

    r6582 r6584  
    13151315    size_t contentLen;
    13161316    uint8_t * content = tr_loadFile( filename, &contentLen );
    1317     ret = content ? tr_jsonParse( content, contentLen, b )
     1317    ret = content ? tr_jsonParse( content, contentLen, b, NULL )
    13181318                  : TR_ERROR_IO_OTHER;
    13191319    tr_free( content );
  • trunk/libtransmission/json-test.c

    r6582 r6584  
    1515            fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
    1616    } else { \
    17         if( VERBOSE ) \
    18             fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
     17        fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \
    1918        return test; \
    2019    } \
     
    2625    const char * in = "{ \"key\": \"Letöltések\" }";
    2726    tr_benc top;
    28     const int err = tr_jsonParse( in, strlen(in), &top );
     27    const char * str;
     28    const int err = tr_jsonParse( in, strlen(in), &top, NULL );
    2929
    3030    check( !err );
    3131    check( tr_bencIsDict( &top ) );
     32    check( tr_bencDictFindStr( &top, "key", &str ) );
     33    check( !strcmp( str, "Letöltések" ) );
    3234
    3335    if( !err )
     
    5658    const char * str;
    5759    int64_t i;
    58     const int err = tr_jsonParse( in, strlen(in), &top );
     60    const int err = tr_jsonParse( in, strlen(in), &top, NULL );
    5961
    6062    check( !err );
     
    9193        return i;
    9294
     95    if(( i = test_utf8( )))
     96        return i;
     97
    9398    if(( i = test1( )))
    9499        return i;
  • trunk/libtransmission/json.c

    r6582 r6584  
    1818#include <event.h> /* evbuffer */
    1919
    20 #include "ConvertUTF.h"
    2120#include "JSON_parser.h"
    2221
     
    109108
    110109        case JSON_T_STRING:
    111             tr_bencInitRaw( getNode( data ), value->vu.str.value, value->vu.str.length );
     110            tr_bencInitStrDup( getNode( data ), value->vu.str.value );
    112111            break;
    113112
    114113        case JSON_T_KEY:
    115114            assert( !data->key );
    116             data->key = tr_strndup( value->vu.str.value, value->vu.str.length );
     115            data->key = tr_strdup( value->vu.str.value );
    117116            break;
    118117    }
     
    124123tr_jsonParse( const void      * vbuf,
    125124              size_t            len,
    126               tr_benc         * setme_benc )
     125              tr_benc         * setme_benc,
     126              const uint8_t  ** setme_end )
    127127{
     128    int err = 0;
     129    const unsigned char * buf = vbuf;
     130    const void * bufend = buf + len;
    128131    struct JSON_config_struct config;
    129132    struct JSON_parser_struct * checker;
    130133    struct json_benc_data data;
    131     const UTF8 * utf8_begin;
    132     const UTF8 * utf8_end;
    133     UTF32 * utf32_begin;
    134     UTF32 * utf32_end;
    135     UTF32 * utf32_walk;
    136     int err = 0;
    137134
    138135    init_JSON_config( &config );
     
    145142    data.stack = tr_ptrArrayNew( );
    146143
    147     /* convert the utf8 that was passed in, into utf32 so that
    148      * we can be certain that each call to JSON_parser_char()
    149      * passes through a complete character */
    150     utf8_begin = vbuf;
    151     utf8_end = utf8_begin; /* inout argument */
    152     utf32_begin = tr_new0( UTF32, len );   
    153     utf32_end = utf32_begin; /* inout argument */
    154     ConvertUTF8toUTF32( &utf8_end, utf8_begin+len,
    155                         &utf32_end, utf32_begin+len, 0 );
     144    checker = new_JSON_parser( &config );
     145    while( ( buf != bufend ) && JSON_parser_char( checker, *buf ) )
     146        ++buf;
     147    if( buf != bufend )
     148        err = TR_ERROR;
    156149
    157     checker = new_JSON_parser( &config );
    158     utf32_walk = utf32_begin;
    159     while( ( utf32_walk != utf32_end ) && JSON_parser_char( checker, *utf32_walk ) )
    160         ++utf32_walk;
    161     if( utf32_walk != utf32_end )
    162         err = TR_ERROR;
     150    if( setme_end )
     151        *setme_end = (const uint8_t*) buf;
    163152
    164153    delete_JSON_parser( checker );
    165154    tr_ptrArrayFree( data.stack, NULL );
    166     tr_free( utf32_begin );
    167155    return err;
    168156}
  • trunk/libtransmission/json.h

    r6582 r6584  
    1515int tr_jsonParse( const void       * vbuf,
    1616                  size_t             len,
    17                   struct tr_benc   * setme_benc );
     17                  struct tr_benc   * setme_benc,
     18                  const uint8_t   ** setme_end );
    1819
    1920#endif
  • trunk/libtransmission/rpc.c

    r6582 r6584  
    718718        request_len = strlen( request_json );
    719719
    720     have_content = !tr_jsonParse( request_json, request_len, &top );
     720    have_content = !tr_jsonParse( request_json, request_len, &top, NULL );
    721721    ret = request_exec( handle, have_content ? &top : NULL, response_len );
    722722
Note: See TracChangeset for help on using the changeset viewer.