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

« back to all changes in this revision

Viewing changes to libtransmission/bencode.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:
1
 
/******************************************************************************
2
 
 * $Id: bencode.h 6469 2008-08-10 15:15:51Z charles $
3
 
 *
4
 
 * Copyright (c) 2005-2008 Transmission authors and contributors
5
 
 *
6
 
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 
 * copy of this software and associated documentation files (the "Software"),
8
 
 * to deal in the Software without restriction, including without limitation
9
 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 
 * and/or sell copies of the Software, and to permit persons to whom the
11
 
 * Software is furnished to do so, subject to the following conditions:
12
 
 *
13
 
 * The above copyright notice and this permission notice shall be included in
14
 
 * all copies or substantial portions of the Software.
15
 
 *
16
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 
 * DEALINGS IN THE SOFTWARE.
23
 
 *****************************************************************************/
 
1
/*
 
2
 * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
 
3
 *
 
4
 * This file is licensed by the GPL version 2.  Works owned by the
 
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.
 
7
 * This exemption does not extend to derived works not owned by
 
8
 * the Transmission project.
 
9
 *
 
10
 * $Id: bencode.h 6795 2008-09-23 19:11:04Z charles $
 
11
 */
24
12
 
25
13
#ifndef TR_BENCODE_H
26
14
#define TR_BENCODE_H 1
27
15
 
28
16
#include <inttypes.h> /* for int64_t */
29
 
#include <string.h> /* for memset */
 
17
 
 
18
enum
 
19
{
 
20
    TYPE_INT  = 1,
 
21
    TYPE_STR  = 2,
 
22
    TYPE_LIST = 4,
 
23
    TYPE_DICT = 8
 
24
};
30
25
 
31
26
typedef struct tr_benc
32
27
{
33
 
#define TYPE_INT  1
34
 
#define TYPE_STR  2
35
 
#define TYPE_LIST 4
36
 
#define TYPE_DICT 8
37
 
    char   type;
 
28
    char    type;
38
29
    union
39
30
    {
40
31
        int64_t i;
41
32
        struct
42
33
        {
43
 
            int    i;
44
 
            int    nofree;
 
34
            size_t i;
45
35
            char * s;
46
36
        } s;
47
37
        struct
48
38
        {
49
 
            int alloc;
50
 
            int count;
 
39
            size_t alloc;
 
40
            size_t count;
51
41
            struct tr_benc * vals;
52
42
        } l;
53
43
    } val;
54
44
} tr_benc;
55
45
 
56
 
/* backwards compatability */
57
 
typedef tr_benc benc_val_t;
58
 
 
59
 
int tr_bencParse( const void      * buf,
60
 
                  const void      * bufend,
61
 
                  tr_benc         * setme_benc,
62
 
                  const uint8_t  ** setme_end );
63
 
 
64
 
int tr_bencLoad( const void  * buf,
65
 
                 int           buflen,
66
 
                 tr_benc     * setme_benc,
67
 
                 char       ** setme_end );
68
 
 
 
46
/***
 
47
****
 
48
***/
 
49
 
 
50
int       tr_bencParse( const void *     buf,
 
51
                        const void *     bufend,
 
52
                        tr_benc *        setme_benc,
 
53
                        const uint8_t ** setme_end );
 
54
 
 
55
int       tr_bencLoad( const void * buf,
 
56
                       size_t       buflen,
 
57
                       tr_benc *    setme_benc,
 
58
                       char **      setme_end );
 
59
 
 
60
int       tr_bencLoadFile( const char * filename,
 
61
                                        tr_benc * );
 
62
 
 
63
int       tr_bencLoadJSONFile( const char * filename,
 
64
                                            tr_benc * );
 
65
 
 
66
#if 0
69
67
void      tr_bencPrint( const tr_benc * );
 
68
 
 
69
#endif
 
70
 
70
71
void      tr_bencFree( tr_benc * );
71
 
int       tr_bencDictFindInt( tr_benc * dict, const char * key, int64_t * setme );
72
 
int       tr_bencDictFindDouble( tr_benc * dict, const char * key, double * setme );
73
 
int       tr_bencDictFindStr( tr_benc * dict, const char * key, const char ** setme );
74
 
int       tr_bencDictFindRaw( tr_benc * dict, const char * key, const uint8_t ** setme_raw,
75
 
                                                                size_t * setme_len );
76
 
int       tr_bencDictFindList( tr_benc * dict, const char * key, tr_benc ** setme );
77
 
int       tr_bencDictFindDict( tr_benc * dict, const char * key, tr_benc ** setme );
78
 
tr_benc * tr_bencDictFind( tr_benc * dict, const char * key );
79
 
tr_benc * tr_bencDictFindType( tr_benc * dict, const char * key, int type );
80
 
tr_benc * tr_bencDictFindFirst( tr_benc * dict, ... );
81
 
 
82
 
/* convenience functions for building tr_benc    structures */
83
 
 
84
 
#define tr_bencInitStr( a, b, c, d ) \
85
 
    _tr_bencInitStr( (a), ( char * )(b), (c), (d) )
86
 
void   _tr_bencInitStr( tr_benc * val, char * str, int len, int nofree );
87
 
int    tr_bencInitStrDup( tr_benc * val, const char * str );
88
 
void   tr_bencInitRaw( tr_benc * val, const void * src, size_t byteCount );
89
 
void   tr_bencInitInt( tr_benc * val, int64_t num );
90
 
int   tr_bencInitDict( tr_benc * val, int reserveCount );
91
 
int   tr_bencInitList( tr_benc * val, int reserveCount );
92
 
int   tr_bencListReserve( tr_benc * list, int count );
93
 
/* note that for one key-value pair, count should be 1, not 2 */
94
 
int   tr_bencDictReserve( tr_benc * dict, int count );
95
 
tr_benc    * tr_bencListAdd( tr_benc  * list );
96
 
tr_benc    * tr_bencListAddInt( tr_benc  * list, int64_t val );
97
 
tr_benc    * tr_bencListAddStr( tr_benc  * list, const char * val );
98
 
tr_benc    * tr_bencListAddList( tr_benc  * list, int reserveCount );
99
 
tr_benc    * tr_bencListAddDict( tr_benc  * list, int reserveCount );
100
 
tr_benc    * tr_bencDictAdd( tr_benc * dict, const char * key );
101
 
tr_benc    * tr_bencDictAddDouble( tr_benc * dict, const char * key, double d );
102
 
tr_benc    * tr_bencDictAddInt( tr_benc * dict, const char * key, int64_t val );
103
 
tr_benc    * tr_bencDictAddStr( tr_benc * dict, const char * key, const char * val );
104
 
tr_benc    * tr_bencDictAddList( tr_benc * dict, const char * key, int reserveCount );
105
 
tr_benc    * tr_bencDictAddDict( tr_benc * dict, const char * key, int reserveCount );
106
 
tr_benc    * tr_bencDictAddRaw( tr_benc * dict, const char * key, const void *, size_t len );
107
 
int          tr_bencDictRemove( tr_benc * dict, const char * key );
108
 
 
109
 
char*  tr_bencSave         ( const tr_benc * val, int * len );
110
 
char*  tr_bencSaveAsJSON   ( const tr_benc * top, int * len );
111
 
int    tr_bencSaveFile     ( const char * filename, const tr_benc * );
112
 
int    tr_bencSaveJSONFile ( const char * filename, const tr_benc * );
113
 
int    tr_bencLoadFile     ( const char * filename, tr_benc * );
114
 
int    tr_bencLoadJSONFile ( const char * filename, tr_benc * );
115
 
 
116
 
int tr_bencGetInt( const tr_benc * val, int64_t * setme );
117
 
int tr_bencGetStr( const tr_benc * val, const char ** setme );
118
 
 
119
 
int tr_bencIsType( const tr_benc *, int type );
120
 
#define tr_bencIsInt(b) (tr_bencIsType(b,TYPE_INT))
121
 
#define tr_bencIsDict(b) (tr_bencIsType(b,TYPE_DICT))
122
 
#define tr_bencIsList(b) (tr_bencIsType(b,TYPE_LIST))
123
 
#define tr_bencIsString(b) (tr_bencIsType(b,TYPE_STR))
 
72
 
 
73
char*     tr_bencSave( const tr_benc * val,
 
74
                       int *           len );
 
75
 
 
76
char*     tr_bencSaveAsJSON( const tr_benc * top,
 
77
                             int *           len );
 
78
 
 
79
int       tr_bencSaveFile( const char * filename,
 
80
                           const        tr_benc * );
 
81
 
 
82
int       tr_bencSaveJSONFile( const char * filename,
 
83
                               const        tr_benc * );
 
84
 
 
85
void      tr_bencInitStr(                       tr_benc *,
 
86
                                   const void * str,
 
87
                                   int          str_len );
 
88
 
 
89
void      tr_bencInitRaw(                       tr_benc *,
 
90
                                   const void * raw,
 
91
                                   size_t       raw_len );
 
92
 
 
93
void      tr_bencInitInt(             tr_benc *,
 
94
                              int64_t num );
 
95
 
 
96
int       tr_bencInitDict(           tr_benc *,
 
97
                              size_t reserveCount );
 
98
 
 
99
int       tr_bencInitList(           tr_benc *,
 
100
                              size_t reserveCount );
 
101
 
 
102
/***
 
103
****
 
104
***/
 
105
 
 
106
int       tr_bencListReserve(         tr_benc *,
 
107
                               size_t reserveCount );
 
108
 
 
109
tr_benc * tr_bencListAdd( tr_benc * );
 
110
 
 
111
tr_benc * tr_bencListAddInt(                 tr_benc *,
 
112
                                     int64_t val );
 
113
 
 
114
tr_benc * tr_bencListAddStr(                           tr_benc *,
 
115
                                          const char * val );
 
116
 
 
117
tr_benc * tr_bencListAddList(               tr_benc *,
 
118
                                     size_t reserveCount );
 
119
 
 
120
tr_benc * tr_bencListAddDict(               tr_benc *,
 
121
                                     size_t reserveCount );
 
122
 
 
123
size_t    tr_bencListSize( const tr_benc * list );
 
124
 
 
125
tr_benc * tr_bencListChild( tr_benc * list,
 
126
                            size_t    n );
 
127
 
 
128
/***
 
129
****
 
130
***/
 
131
 
 
132
int       tr_bencDictReserve(         tr_benc *,
 
133
                               size_t reserveCount );
 
134
 
 
135
int       tr_bencDictRemove(                     tr_benc *,
 
136
                                    const char * key );
 
137
 
 
138
tr_benc * tr_bencDictAdd(                           tr_benc *,
 
139
                                       const char * key );
 
140
 
 
141
tr_benc * tr_bencDictAddDouble(                           tr_benc *,
 
142
                                             const char * key,
 
143
                                             double       d );
 
144
 
 
145
tr_benc * tr_bencDictAddInt(                           tr_benc *,
 
146
                                          const char * key,
 
147
                                          int64_t      val );
 
148
 
 
149
tr_benc * tr_bencDictAddStr(                           tr_benc *,
 
150
                                          const char * key,
 
151
                                          const char * val );
 
152
 
 
153
tr_benc * tr_bencDictAddList(                           tr_benc *,
 
154
                                           const char * key,
 
155
                                           size_t       reserve );
 
156
 
 
157
tr_benc * tr_bencDictAddDict(                           tr_benc *,
 
158
                                           const char * key,
 
159
                                           size_t       reserve );
 
160
 
 
161
tr_benc * tr_bencDictAddRaw(                           tr_benc *,
 
162
                                          const char * key,
 
163
                                          const        void *,
 
164
                                          size_t       len );
 
165
 
 
166
tr_benc*  tr_bencDictFind(                          tr_benc *,
 
167
                                       const char * key );
 
168
 
 
169
int       tr_bencDictFindList(                     tr_benc *,
 
170
                                      const char * key,
 
171
                                      tr_benc **   setme );
 
172
 
 
173
int       tr_bencDictFindDict(                     tr_benc *,
 
174
                                      const char * key,
 
175
                                      tr_benc **   setme );
 
176
 
 
177
int       tr_bencDictFindInt(                     tr_benc *,
 
178
                                     const char * key,
 
179
                                     int64_t *    setme );
 
180
 
 
181
int       tr_bencDictFindDouble(                     tr_benc *,
 
182
                                        const char * key,
 
183
                                        double *     setme );
 
184
 
 
185
int       tr_bencDictFindStr(                       tr_benc *,
 
186
                                      const char *  key,
 
187
                                      const char ** setme );
 
188
 
 
189
int       tr_bencDictFindRaw(                             tr_benc *,
 
190
                                         const char *     key,
 
191
                                         const uint8_t ** setme_raw,
 
192
                                         size_t *         setme_len );
 
193
 
 
194
/***
 
195
****
 
196
***/
 
197
 
 
198
int       tr_bencGetInt( const tr_benc * val,
 
199
                         int64_t *       setme );
 
200
 
 
201
int       tr_bencGetStr( const tr_benc * val,
 
202
                         const char **   setme );
 
203
 
 
204
int       tr_bencIsType( const tr_benc *,
 
205
                         int   type );
 
206
 
 
207
#define tr_bencIsInt( b )    tr_bencIsType( ( b ), TYPE_INT )
 
208
#define tr_bencIsDict( b )   tr_bencIsType( ( b ), TYPE_DICT )
 
209
#define tr_bencIsList( b )   tr_bencIsType( ( b ), TYPE_LIST )
 
210
#define tr_bencIsString( b ) tr_bencIsType( ( b ), TYPE_STR )
124
211
 
125
212
/**
126
213
***  Treat these as private -- they're only made public here
127
214
***  so that the unit tests can find them
128
215
**/
129
216
 
130
 
int  tr_bencParseInt( const uint8_t  * buf,
131
 
                      const uint8_t  * bufend,
132
 
                      const uint8_t ** setme_end, 
133
 
                      int64_t        * setme_val );
134
 
 
135
 
int  tr_bencParseStr( const uint8_t  * buf,
136
 
                      const uint8_t  * bufend,
137
 
                      const uint8_t ** setme_end, 
138
 
                      uint8_t       ** setme_str,
139
 
                      size_t         * setme_strlen );
140
 
 
141
 
/**
142
 
***
143
 
**/
144
 
 
145
 
int       tr_bencListSize( const tr_benc * list );
146
 
tr_benc * tr_bencListChild( tr_benc * list, int n );
147
 
 
 
217
int tr_bencParseInt( const uint8_t *  buf,
 
218
                     const uint8_t *  bufend,
 
219
                     const uint8_t ** setme_end,
 
220
                     int64_t *        setme_val );
 
221
 
 
222
int tr_bencParseStr( const uint8_t *  buf,
 
223
                     const uint8_t *  bufend,
 
224
                     const uint8_t ** setme_end,
 
225
                     const uint8_t ** setme_str,
 
226
                     size_t *         setme_strlen );
148
227
 
149
228
#endif