~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-updates

« back to all changes in this revision

Viewing changes to libtransmission/json.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2008-11-28 15:33:48 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20081128153348-it70trfnxiroblmc
Tags: 1.40-0ubuntu1
* New upstream release (LP: #302672)
  - Tracker communication uses fewer resources
  - More accurate bandwidth limits
  - Reduce disk fragmentation by preallocating files (LP: #287726)
  - Stability, security and performance improvements to the RPC /
    Web UI server (closes LP: #290423)
  - Support compression when serving Web UI and RPC responses
  - Simplify the RPC whitelist
  - Fix bug that prevented handshakes with encrypted BitComet peers
  - Fix 1.3x bug that could re-download some data unnecessarily
    (LP: #295040)
  - Option to automatically update the blocklist weekly
  - Added off-hour bandwidth scheduling
  - Simplify file/priority selection in the details dialog
  - Fix a couple of crashes
  - New / updated translations
  - Don't inhibit hibernation by default (LP: #292929)
  - Use "close" animation when sending to notification area (LP: #130811)
  - Fix resize problems (LP: #269872)
  - Support "--version" option when launching from command line
    (LP: #292011)
  - Correctly parse announce URLs that have leading or trailing
    spaces (LP: #262411)
  - Display an error when "Open Torrent" fails (LP: #281463)
* Dropped 10_fix_crasher_from_upstream.dpatch: Fix is in this
  upstream release.
* debian/control: Don't just build-depend on libcurl-dev, which is
  a virtual package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * This file is licensed by the GPL version 2.  Works owned by the
5
5
 * Transmission project are granted a special exemption to clause 2(b)
6
 
 * so that the bulk of its code can remain under the MIT license. 
 
6
 * so that the bulk of its code can remain under the MIT license.
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: json.c 6585 2008-08-18 03:55:01Z charles $
 
10
 * $Id: json.c 6875 2008-10-09 20:38:00Z charles $
11
11
 */
12
12
 
13
13
#include <assert.h>
14
14
#include <ctype.h>
 
15
#include <errno.h>
15
16
#include <string.h>
16
17
#include <stdio.h> /* printf */
17
18
 
27
28
 
28
29
struct json_benc_data
29
30
{
30
 
    tr_benc * top;
31
 
    tr_ptrArray * stack;
32
 
    char * key;
 
31
    tr_benc *      top;
 
32
    tr_ptrArray *  stack;
 
33
    char *         key;
33
34
};
34
35
 
35
36
static tr_benc*
40
41
 
41
42
    if( tr_ptrArrayEmpty( data->stack ) )
42
43
        parent = NULL;
43
 
     else
 
44
    else
44
45
        parent = tr_ptrArrayBack( data->stack );
45
46
 
46
47
    if( !parent )
47
48
        node = data->top;
48
49
    else if( tr_bencIsList( parent ) )
49
50
        node = tr_bencListAdd( parent );
50
 
    else if( tr_bencIsDict( parent ) && data->key ) {
 
51
    else if( tr_bencIsDict( parent ) && data->key )
 
52
    {
51
53
        node = tr_bencDictAdd( parent, data->key );
52
54
        tr_free( data->key );
53
55
        data->key = NULL;
57
59
}
58
60
 
59
61
static int
60
 
callback( void * vdata, int type, const JSON_value * value )
 
62
callback( void *             vdata,
 
63
          int                type,
 
64
          const JSON_value * value )
61
65
{
62
66
    struct json_benc_data * data = vdata;
63
 
    tr_benc * node;
 
67
    tr_benc *               node;
64
68
 
65
69
    switch( type )
66
70
    {
67
71
        case JSON_T_ARRAY_BEGIN:
68
72
            node = getNode( data );
69
73
            tr_bencInitList( node, 0 );
70
 
            tr_ptrArrayAppend( data->stack, node ); 
 
74
            tr_ptrArrayAppend( data->stack, node );
71
75
            break;
72
76
 
73
77
        case JSON_T_ARRAY_END:
77
81
        case JSON_T_OBJECT_BEGIN:
78
82
            node = getNode( data );
79
83
            tr_bencInitDict( node, 0 );
80
 
            tr_ptrArrayAppend( data->stack, node ); 
 
84
            tr_ptrArrayAppend( data->stack, node );
81
85
            break;
82
86
 
83
87
        case JSON_T_OBJECT_END:
84
88
            tr_ptrArrayPop( data->stack );
85
89
            break;
86
90
 
87
 
        case JSON_T_FLOAT: {
 
91
        case JSON_T_FLOAT:
 
92
        {
88
93
            char buf[128];
89
 
            tr_snprintf( buf, sizeof( buf ), "%f", (double)value->vu.float_value );
90
 
            tr_bencInitStrDup( getNode( data ), buf );
 
94
            tr_snprintf( buf, sizeof( buf ), "%f",
 
95
                         (double)value->vu.float_value );
 
96
            tr_bencInitStr( getNode( data ), buf, -1 );
91
97
            break;
92
98
        }
93
99
 
94
100
        case JSON_T_NULL:
 
101
            tr_bencInitStr( getNode( data ), "", 0 );
95
102
            break;
96
103
 
97
104
        case JSON_T_INTEGER:
107
114
            break;
108
115
 
109
116
        case JSON_T_STRING:
110
 
            tr_bencInitStrDup( getNode( data ), value->vu.str.value );
 
117
            tr_bencInitStr( getNode( data ),
 
118
                            value->vu.str.value,
 
119
                            value->vu.str.length );
111
120
            break;
112
121
 
113
122
        case JSON_T_KEY:
120
129
}
121
130
 
122
131
int
123
 
tr_jsonParse( const void      * vbuf,
124
 
              size_t            len,
125
 
              tr_benc         * setme_benc,
126
 
              const uint8_t  ** setme_end )
 
132
tr_jsonParse( const void *     vbuf,
 
133
              size_t           len,
 
134
              tr_benc *        setme_benc,
 
135
              const uint8_t ** setme_end )
127
136
{
128
 
    int err = 0;
129
 
    const unsigned char * buf = vbuf;
130
 
    const void * bufend = buf + len;
131
 
    struct JSON_config_struct config;
 
137
    int                         err = 0;
 
138
    const unsigned char *       buf = vbuf;
 
139
    const void *                bufend = buf + len;
 
140
    struct JSON_config_struct   config;
132
141
    struct JSON_parser_struct * checker;
133
 
    struct json_benc_data data;
 
142
    struct json_benc_data       data;
134
143
 
135
144
    init_JSON_config( &config );
136
145
    config.callback = callback;
144
153
    checker = new_JSON_parser( &config );
145
154
    while( ( buf != bufend ) && JSON_parser_char( checker, *buf ) )
146
155
        ++buf;
 
156
 
147
157
    if( buf != bufend )
148
 
        err = TR_ERROR;
 
158
        err = EILSEQ;
149
159
 
150
160
    if( setme_end )
151
161
        *setme_end = (const uint8_t*) buf;
154
164
    tr_ptrArrayFree( data.stack, NULL );
155
165
    return err;
156
166
}
 
167