~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-security

« back to all changes in this revision

Viewing changes to libtransmission/JSON_parser.h

  • 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:
7
7
#include <stddef.h>
8
8
 
9
9
/* Windows DLL stuff */
10
 
#ifdef _WIN32
11
 
#       ifdef JSON_PARSER_DLL_EXPORTS
12
 
#               define JSON_PARSER_DLL_API __declspec(dllexport)
13
 
#       else
14
 
#               define JSON_PARSER_DLL_API __declspec(dllimport)
15
 
#   endif
16
 
#else
17
 
#       define JSON_PARSER_DLL_API 
18
 
#endif
 
10
/*
 
11
 #ifdef _WIN32
 
12
 #      ifdef JSON_PARSER_DLL_EXPORTS
 
13
 #              define JSON_PARSER_DLL_API __declspec(dllexport)
 
14
 #      else
 
15
 #              define JSON_PARSER_DLL_API __declspec(dllimport)
 
16
 #   endif
 
17
 #else
 
18
 */
 
19
#define JSON_PARSER_DLL_API
 
20
/*
 
21
 #endif
 
22
 */
19
23
 
20
24
#include <inttypes.h>
21
25
typedef int64_t JSON_int_t;
22
 
#define JSON_PARSER_INTEGER_SSCANF_TOKEN "%"PRId64
23
 
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%"PRId64
 
26
#define JSON_PARSER_INTEGER_SSCANF_TOKEN "%" PRId64
 
27
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%" PRId64
24
28
 
25
29
 
26
30
#ifdef __cplusplus
27
31
extern "C" {
28
 
#endif 
 
32
#endif
29
33
 
30
 
typedef enum 
 
34
typedef enum
31
35
{
32
36
    JSON_T_NONE = 0,
33
37
    JSON_T_ARRAY_BEGIN,
44
48
    JSON_T_MAX
45
49
} JSON_type;
46
50
 
47
 
typedef struct JSON_value_struct {
48
 
    union {
49
 
        JSON_int_t integer_value;
50
 
        
 
51
typedef struct JSON_value_struct
 
52
{
 
53
    union
 
54
    {
 
55
        JSON_int_t  integer_value;
 
56
 
51
57
        long double float_value;
52
 
        
53
 
        struct {
 
58
 
 
59
        struct
 
60
        {
54
61
            const char* value;
55
 
            size_t length;
 
62
            size_t      length;
56
63
        } str;
57
64
    } vu;
58
65
} JSON_value;
59
66
 
60
 
/*! \brief JSON parser callback 
 
67
/*! \brief JSON parser callback
61
68
 
62
69
    \param ctx The pointer passed to new_JSON_parser.
63
 
    \param type An element of JSON_type but not JSON_T_NONE.    
64
 
    \param value A representation of the parsed value. This parameter is NULL for
65
 
        JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN, JSON_T_OBJECT_END,
66
 
        JSON_T_NULL, JSON_T_TRUE, and SON_T_FALSE. String values are always returned
 
70
    \param type An element of JSON_type but not JSON_T_NONE.
 
71
    \param value A representation of the parsed value. This parameter is NULL
 
72
   for
 
73
        JSON_T_ARRAY_BEGIN, JSON_T_ARRAY_END, JSON_T_OBJECT_BEGIN,
 
74
   JSON_T_OBJECT_END,
 
75
        JSON_T_NULL, JSON_T_TRUE, and SON_T_FALSE. String values are always
 
76
   returned
67
77
        as zero-terminated C strings.
68
78
 
69
79
    \return Non-zero if parsing should continue, else zero.
70
 
*/    
71
 
typedef int (*JSON_parser_callback)(void* ctx, int type, const struct JSON_value_struct* value);
72
 
 
73
 
 
74
 
/*! \brief The structure used to configure a JSON parser object 
75
 
    
76
 
    \param depth If negative, the parser can parse arbitrary levels of JSON, otherwise
 
80
 */
 
81
typedef int ( *JSON_parser_callback )( void* ctx, int type,
 
82
                                       const struct JSON_value_struct*
 
83
                                       value );
 
84
 
 
85
 
 
86
/*! \brief The structure used to configure a JSON parser object
 
87
 
 
88
    \param depth If negative, the parser can parse arbitrary levels of JSON,
 
89
   otherwise
77
90
        the depth is the limit
78
 
    \param Pointer to a callback. This parameter may be NULL. In this case the input is merely checked for validity.
 
91
    \param Pointer to a callback. This parameter may be NULL. In this case the
 
92
   input is merely checked for validity.
79
93
    \param Callback context. This parameter may be NULL.
80
 
    \param depth. Specifies the levels of nested JSON to allow. Negative numbers yield unlimited nesting.
 
94
    \param depth. Specifies the levels of nested JSON to allow. Negative numbers
 
95
   yield unlimited nesting.
81
96
    \param allowComments. To allow C style comments in JSON, set to non-zero.
82
 
    \param handleFloatsManually. To decode floating point numbers manually set this parameter to non-zero.
83
 
    
 
97
    \param handleFloatsManually. To decode floating point numbers manually set
 
98
   this parameter to non-zero.
 
99
 
84
100
    \return The parser object.
85
 
*/
86
 
typedef struct JSON_config_struct {
87
 
    JSON_parser_callback     callback;
88
 
    void*                    callback_ctx;
89
 
    int                      depth;
90
 
    int                      allow_comments;
91
 
    int                      handle_floats_manually;
 
101
 */
 
102
typedef struct JSON_config_struct
 
103
{
 
104
    JSON_parser_callback    callback;
 
105
    void*                   callback_ctx;
 
106
    int                     depth;
 
107
    int                     allow_comments;
 
108
    int                     handle_floats_manually;
92
109
} JSON_config;
93
110
 
94
111
 
95
 
/*! \brief Initializes the JSON parser configuration structure to default values.
 
112
/*! \brief Initializes the JSON parser configuration structure to default
 
113
   values.
96
114
 
97
115
    The default configuration is
98
 
    - 127 levels of nested JSON (depends on JSON_PARSER_STACK_SIZE, see json_parser.c)
 
116
    - 127 levels of nested JSON (depends on JSON_PARSER_STACK_SIZE, see
 
117
   json_parser.c)
99
118
    - no parsing, just checking for JSON syntax
100
119
    - no comments
101
120
 
102
121
    \param config. Used to configure the parser.
103
 
*/
104
 
JSON_PARSER_DLL_API void init_JSON_config(JSON_config* config);
105
 
 
106
 
/*! \brief Create a JSON parser object 
107
 
    
108
 
    \param config. Used to configure the parser. Set to NULL to use the default configuration. 
 
122
 */
 
123
JSON_PARSER_DLL_API void                              init_JSON_config(
 
124
    JSON_config* config );
 
125
 
 
126
/*! \brief Create a JSON parser object
 
127
 
 
128
    \param config. Used to configure the parser. Set to NULL to use the default
 
129
   configuration.
109
130
        See init_JSON_config
110
 
    
 
131
 
111
132
    \return The parser object.
112
 
*/
113
 
JSON_PARSER_DLL_API extern struct JSON_parser_struct* new_JSON_parser(JSON_config* config);
 
133
 */
 
134
JSON_PARSER_DLL_API extern struct JSON_parser_struct* new_JSON_parser(
 
135
    JSON_config* config );
114
136
 
115
137
/*! \brief Destroy a previously created JSON parser object. */
116
 
JSON_PARSER_DLL_API extern void delete_JSON_parser(struct JSON_parser_struct* jc);
 
138
JSON_PARSER_DLL_API extern void                       delete_JSON_parser(
 
139
    struct JSON_parser_struct* jc );
117
140
 
118
141
/*! \brief Parse a character.
119
142
 
120
 
    \return Non-zero, if all characters passed to this function are part of are valid JSON.
121
 
*/
122
 
JSON_PARSER_DLL_API extern int JSON_parser_char(struct JSON_parser_struct* jc, int next_char);
 
143
    \return Non-zero, if all characters passed to this function are part of are
 
144
   valid JSON.
 
145
 */
 
146
JSON_PARSER_DLL_API extern int                        JSON_parser_char(
 
147
    struct JSON_parser_struct* jc,
 
148
    int
 
149
                               next_char );
123
150
 
124
151
/*! \brief Finalize parsing.
125
152
 
126
153
    Call this method once after all input characters have been consumed.
127
 
    
 
154
 
128
155
    \return Non-zero, if all parsed characters are valid JSON, zero otherwise.
129
 
*/
130
 
JSON_PARSER_DLL_API extern int JSON_parser_done(struct JSON_parser_struct* jc);
 
156
 */
 
157
JSON_PARSER_DLL_API extern int JSON_parser_done(
 
158
    struct JSON_parser_struct* jc );
131
159
 
132
 
/*! \brief Determine if a given string is valid JSON white space 
 
160
/*! \brief Determine if a given string is valid JSON white space
133
161
 
134
162
    \return Non-zero if the string is valid, zero otherwise.
135
 
*/
136
 
JSON_PARSER_DLL_API extern int JSON_parser_is_legal_white_space_string(const char* s);
 
163
 */
 
164
JSON_PARSER_DLL_API extern int
 
165
                               JSON_parser_is_legal_white_space_string(
 
166
    const char* s );
137
167
 
138
168
 
139
169
#ifdef __cplusplus
140
170
}
141
 
#endif 
142
 
    
 
171
#endif
 
172
 
143
173
 
144
174
#endif /* JSON_PARSER_H */