Changeset 5969


Ignore:
Timestamp:
May 29, 2008, 3:24:26 AM (14 years ago)
Author:
charles
Message:

#972: merge upstream version of Jean Gressmann's JSON_parser

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/JSON_parser.c

    r5869 r5969  
    3131   
    3232    For the added features the license above applies also.
     33   
     34    Changelog:
     35   
     36        2008/05/28
     37            - Made JSON_value structure ansi C compliant. This bug was report by
     38              trisk@acm.jhu.edu
     39       
     40        2008/05/20
     41            - Fixed bug reported by Charles.Kerr@noaa.gov where the switching
     42              from static to dynamic parse buffer did not copy the static parse
     43              buffer's content.
    3344*/
    3445
     
    5566#define __   -1     /* the universal error code */
    5667
    57 /* values chosen so that the object approx. fits into a page (4K) */
     68/* values chosen so that the object size is approx equal to one page (4K) */
    5869#ifndef JSON_PARSER_STACK_SIZE
    5970#   define JSON_PARSER_STACK_SIZE 128
     
    453464                    arg = &value;
    454465                    if (jc->handle_floats_manually) {
    455                         value.string_value = jc->parse_buffer;
    456                         value.string_length = jc->parse_buffer_count;
     466                        value.vu.str.value = jc->parse_buffer;
     467                        value.vu.str.length = jc->parse_buffer_count;
    457468                    } else {
    458                         result = sscanf(jc->parse_buffer, "%Lf", &value.float_value);
     469                        result = sscanf(jc->parse_buffer, "%Lf", &value.vu.float_value);
    459470                    }
    460471                    break;
    461472                case JSON_T_INTEGER:
    462473                    arg = &value;
    463                     result = sscanf(jc->parse_buffer, JSON_PARSER_INTEGER_SSCANF_TOKEN, &value.integer_value);
     474                    result = sscanf(jc->parse_buffer, JSON_PARSER_INTEGER_SSCANF_TOKEN, &value.vu.integer_value);
    464475                    break;
    465476                case JSON_T_STRING:
    466477                    arg = &value;
    467                     value.string_value = jc->parse_buffer;
    468                     value.string_length = jc->parse_buffer_count;
     478                    value.vu.str.value = jc->parse_buffer;
     479                    value.vu.str.length = jc->parse_buffer_count;
    469480                    break;
    470481            }
     
    830841                if (jc->callback) {
    831842                    JSON_value value;
    832                     value.string_value = jc->parse_buffer;
    833                     value.string_length = jc->parse_buffer_count;
     843                    value.vu.str.value = jc->parse_buffer;
     844                    value.vu.str.length = jc->parse_buffer_count;
    834845                    if (!(*jc->callback)(jc->ctx, JSON_T_KEY, &value)) {
    835846                        return false;
  • trunk/libtransmission/JSON_parser.h

    r5869 r5969  
    5858       
    5959        struct {
    60             const char* string_value;
    61             size_t string_length;
    62         };
    63     };
     60            const char* value;
     61            size_t length;
     62        } str;
     63    } vu;
    6464} JSON_value;
    6565
     
    8484    \param Pointer to a callback. This parameter may be NULL. In this case the input is merely checked for validity.
    8585    \param Callback context. This parameter may be NULL.
    86     \param allowComments. To allow C style comments in JSON, set to non-zero.
     86    \param depth. Specifies the levels of nested JSON to allow. Negative numbers yield unlimited nesting.
    8787    \param allowComments. To allow C style comments in JSON, set to non-zero.
    8888    \param handleFloatsManually. To decode floating point numbers manually set this parameter to non-zero.
  • trunk/libtransmission/json.c

    r5959 r5969  
    5757
    5858static int
    59 callback( void * vdata, int type, const struct JSON_value_struct * value )
     59callback( void * vdata, int type, const JSON_value * value )
    6060{
    6161    struct json_benc_data * data = vdata;
     
    8686        case JSON_T_FLOAT: {
    8787            char buf[128];
    88             snprintf( buf, sizeof( buf ), "%f", (double)value->float_value );
     88            snprintf( buf, sizeof( buf ), "%f", (double)value->vu.float_value );
    8989            tr_bencInitStrDup( getNode( data ), buf );
    9090            break;
     
    9595
    9696        case JSON_T_INTEGER:
    97             tr_bencInitInt( getNode( data ), value->integer_value );
     97            tr_bencInitInt( getNode( data ), value->vu.integer_value );
    9898            break;
    9999
     
    107107
    108108        case JSON_T_STRING:
    109             tr_bencInitStrDup( getNode( data ), value->string_value );
     109            tr_bencInitStrDup( getNode( data ), value->vu.str.value );
    110110            break;
    111111
    112112        case JSON_T_KEY:
    113113            assert( !data->key );
    114             data->key = tr_strdup( value->string_value );
     114            data->key = tr_strdup( value->vu.str.value );
    115115            break;
    116116    }
  • trunk/libtransmission/transmission.h

    r5933 r5969  
    857857void tr_torrentPeersFree( tr_peer_stat *, int peerCount );
    858858
    859 typedef struct tr_file_stat tr_file_stat;
    860 tr_file_stat * tr_torrentFiles( const tr_torrent *, tr_file_index_t * fileCount );
    861 void tr_torrentFilesFree( tr_file_stat *, tr_file_index_t fileCount );
     859typedef struct tr_file_stat
     860{
     861    uint64_t bytesCompleted;
     862    float progress;
     863}
     864tr_file_stat;
     865
     866tr_file_stat * tr_torrentFiles( const tr_torrent * tor,
     867                                 tr_file_index_t * fileCount );
     868
     869void tr_torrentFilesFree( tr_file_stat    * stat,
     870                          tr_file_index_t   fileCount );
    862871
    863872
     
    11751184};
    11761185
    1177 struct tr_file_stat
    1178 {
    1179     uint64_t bytesCompleted;
    1180     float progress;
    1181 };
    1182 
    11831186struct tr_peer_stat
    11841187{
Note: See TracChangeset for help on using the changeset viewer.