Ignore:
Timestamp:
Aug 21, 2008, 2:57:59 PM (13 years ago)
Author:
charles
Message:

bencode cleanup: remove unused functions and unnecessary #includes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.h

    r6600 r6612  
    1 /******************************************************************************
     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 *
    210 * $Id$
    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  *****************************************************************************/
     11 */
    2412
    2513#ifndef TR_BENCODE_H
     
    2715
    2816#include <inttypes.h> /* for int64_t */
    29 #include <string.h> /* for memset */
    3017
     18enum
     19{
     20    TYPE_INT  = 1,
     21    TYPE_STR  = 2,
     22    TYPE_LIST = 4,
     23    TYPE_DICT = 8
     24};
     25   
    3126typedef struct tr_benc
    3227{
    33 #define TYPE_INT  1
    34 #define TYPE_STR  2
    35 #define TYPE_LIST 4
    36 #define TYPE_DICT 8
    3728    char   type;
    3829    union
     
    4233        {
    4334            int    i;
    44             int    nofree;
    4535            char * s;
    4636        } s;
     
    5444} tr_benc;
    5545
    56 /* backwards compatability */
    57 typedef tr_benc benc_val_t;
     46/***
     47****
     48***/
    5849
    5950int tr_bencParse( const void      * buf,
     
    6758                 char       ** setme_end );
    6859
    69 void      tr_bencPrint( const tr_benc * );
    70 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_bencDictFindFirst( tr_benc * dict, ... );
     60int    tr_bencLoadFile     ( const char * filename, tr_benc * );
     61int    tr_bencLoadJSONFile ( const char * filename, tr_benc * );
    8062
    81 /* convenience functions for building tr_benc    structures */
     63#if 0
     64void  tr_bencPrint( const tr_benc * );
     65#endif
    8266
    83 #define tr_bencInitStr( a, b, c, d ) \
    84     _tr_bencInitStr( (a), ( char * )(b), (c), (d) )
    85 void   _tr_bencInitStr( tr_benc * val, char * str, int len, int nofree );
    86 int    tr_bencInitStrDup( tr_benc * val, const char * str );
    87 void   tr_bencInitRaw( tr_benc * val, const void * src, size_t byteCount );
    88 void   tr_bencInitInt( tr_benc * val, int64_t num );
    89 int   tr_bencInitDict( tr_benc * val, int reserveCount );
    90 int   tr_bencInitList( tr_benc * val, int reserveCount );
    91 int   tr_bencListReserve( tr_benc * list, int count );
    92 /* note that for one key-value pair, count should be 1, not 2 */
    93 int   tr_bencDictReserve( tr_benc * dict, int count );
    94 tr_benc    * tr_bencListAdd( tr_benc  * list );
    95 tr_benc    * tr_bencListAddInt( tr_benc  * list, int64_t val );
    96 tr_benc    * tr_bencListAddStr( tr_benc  * list, const char * val );
    97 tr_benc    * tr_bencListAddList( tr_benc  * list, int reserveCount );
    98 tr_benc    * tr_bencListAddDict( tr_benc  * list, int reserveCount );
    99 tr_benc    * tr_bencDictAdd( tr_benc * dict, const char * key );
    100 tr_benc    * tr_bencDictAddDouble( tr_benc * dict, const char * key, double d );
    101 tr_benc    * tr_bencDictAddInt( tr_benc * dict, const char * key, int64_t val );
    102 tr_benc    * tr_bencDictAddStr( tr_benc * dict, const char * key, const char * val );
    103 tr_benc    * tr_bencDictAddList( tr_benc * dict, const char * key, int reserveCount );
    104 tr_benc    * tr_bencDictAddDict( tr_benc * dict, const char * key, int reserveCount );
    105 tr_benc    * tr_bencDictAddRaw( tr_benc * dict, const char * key, const void *, size_t len );
    106 int          tr_bencDictRemove( tr_benc * dict, const char * key );
     67void  tr_bencFree( tr_benc * );
    10768
    10869char*  tr_bencSave         ( const tr_benc * val, int * len );
     
    11071int    tr_bencSaveFile     ( const char * filename, const tr_benc * );
    11172int    tr_bencSaveJSONFile ( const char * filename, const tr_benc * );
    112 int    tr_bencLoadFile     ( const char * filename, tr_benc * );
    113 int    tr_bencLoadJSONFile ( const char * filename, tr_benc * );
     73
     74void  tr_bencInitStr( tr_benc *, const void * str, int str_len );
     75void  tr_bencInitRaw( tr_benc *, const void * raw, size_t raw_len );
     76void  tr_bencInitInt( tr_benc *, int64_t num );
     77int   tr_bencInitDict( tr_benc *, int reserveCount );
     78int   tr_bencInitList( tr_benc *, int reserveCount );
     79
     80/***
     81****
     82***/
     83
     84int tr_bencListReserve( tr_benc *, int count );
     85tr_benc * tr_bencListAdd( tr_benc * );
     86tr_benc * tr_bencListAddInt( tr_benc *, int64_t val );
     87tr_benc * tr_bencListAddStr( tr_benc *, const char * val );
     88tr_benc * tr_bencListAddList( tr_benc *, int reserveCount );
     89tr_benc * tr_bencListAddDict( tr_benc *, int reserveCount );
     90
     91int tr_bencListSize( const tr_benc * list );
     92tr_benc * tr_bencListChild( tr_benc * list, int n );
     93
     94/***
     95****
     96***/
     97
     98int tr_bencDictReserve( tr_benc *, int count );
     99int tr_bencDictRemove( tr_benc *, const char * key );
     100tr_benc * tr_bencDictAdd( tr_benc *, const char * key );
     101tr_benc * tr_bencDictAddDouble( tr_benc *, const char * key, double d );
     102tr_benc * tr_bencDictAddInt( tr_benc *, const char * key, int64_t val );
     103tr_benc * tr_bencDictAddStr( tr_benc *, const char * key, const char * val );
     104tr_benc * tr_bencDictAddList( tr_benc *, const char * key, int reserveCount );
     105tr_benc * tr_bencDictAddDict( tr_benc *, const char * key, int reserveCount );
     106tr_benc * tr_bencDictAddRaw( tr_benc *, const char * key,
     107                             const void *, size_t len );
     108
     109tr_benc* tr_bencDictFind( tr_benc *, const char * key );
     110int tr_bencDictFindList( tr_benc *, const char * key, tr_benc ** setme );
     111int tr_bencDictFindDict( tr_benc *, const char * key, tr_benc ** setme );
     112int tr_bencDictFindInt( tr_benc *, const char * key, int64_t * setme );
     113int tr_bencDictFindDouble( tr_benc *, const char * key, double * setme );
     114int tr_bencDictFindStr( tr_benc *, const char * key, const char ** setme );
     115int tr_bencDictFindRaw( tr_benc *, const char * key,
     116                          const uint8_t ** setme_raw, size_t * setme_len );
     117
     118/***
     119****
     120***/
    114121
    115122int tr_bencGetInt( const tr_benc * val, int64_t * setme );
    116123int tr_bencGetStr( const tr_benc * val, const char ** setme );
    117 
    118124int tr_bencIsType( const tr_benc *, int type );
    119 #define tr_bencIsInt(b) (tr_bencIsType(b,TYPE_INT))
    120 #define tr_bencIsDict(b) (tr_bencIsType(b,TYPE_DICT))
    121 #define tr_bencIsList(b) (tr_bencIsType(b,TYPE_LIST))
    122 #define tr_bencIsString(b) (tr_bencIsType(b,TYPE_STR))
     125#define tr_bencIsInt( b )    tr_bencIsType( ( b ), TYPE_INT )
     126#define tr_bencIsDict( b )   tr_bencIsType( ( b ), TYPE_DICT )
     127#define tr_bencIsList( b )   tr_bencIsType( ( b ), TYPE_LIST )
     128#define tr_bencIsString( b ) tr_bencIsType( ( b ), TYPE_STR )
    123129
    124130/**
     
    138144                      size_t         * setme_strlen );
    139145
    140 /**
    141 ***
    142 **/
    143 
    144 int       tr_bencListSize( const tr_benc * list );
    145 tr_benc * tr_bencListChild( tr_benc * list, int n );
    146 
    147 
    148146#endif
Note: See TracChangeset for help on using the changeset viewer.