Ignore:
Timestamp:
Feb 27, 2008, 4:47:58 PM (14 years ago)
Author:
charles
Message:

make struct ipc_info opaque. const-ify the ipcparse functions where possible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/ipcparse.c

    r5138 r5142  
    6363#define MSGNAME( id )           ( gl_msgs[(id)].name )
    6464#define DICTPAYLOAD( info )     ( 2 > (info)->vers )
     65
     66struct ipc_info
     67{
     68    struct ipc_funcs * funcs;
     69    int                vers;
     70};
     71
     72int
     73ipc_hasvers( const struct ipc_info * inf )
     74{
     75    return inf && ( inf->vers > 0 );
     76}
    6577
    6678struct msg
     
    219231
    220232static int
    221 ipc_havemsg( struct ipc_info * info, enum ipc_msg id )
     233ipc_havemsg( const struct ipc_info * info, enum ipc_msg id )
    222234{
    223235    assert( MSGVALID( id ) );
    224     assert( HASVERS( info ) );
     236    assert( ipc_hasvers( info ) );
    225237
    226238    return gl_msgs[id].minvers <= info->vers;
     
    228240
    229241tr_benc *
    230 ipc_initval( struct ipc_info * info, enum ipc_msg id, int64_t tag,
     242ipc_initval( const struct ipc_info * info, enum ipc_msg id, int64_t tag,
    231243             tr_benc * pk, int type )
    232244{
     
    292304
    293305uint8_t *
    294 ipc_mkempty( struct ipc_info * info, size_t * len, enum ipc_msg id,
     306ipc_mkempty( const struct ipc_info * info, size_t * len, enum ipc_msg id,
    295307             int64_t tag )
    296308{
     
    308320
    309321uint8_t *
    310 ipc_mkint( struct ipc_info * info, size_t * len, enum ipc_msg id, int64_t tag,
    311            int64_t num )
     322ipc_mkint( const struct ipc_info * info, size_t * len, enum ipc_msg id,
     323           int64_t tag, int64_t num )
    312324{
    313325    tr_benc pk, * val;
     
    326338
    327339uint8_t *
    328 ipc_mkstr( struct ipc_info * info, size_t * len, enum ipc_msg id, int64_t tag,
    329            const char * str )
     340ipc_mkstr( const struct ipc_info * info, size_t * len, enum ipc_msg id,
     341           int64_t tag, const char * str )
    330342{
    331343    tr_benc pk, * val;
     
    374386
    375387uint8_t *
    376 ipc_mkgetinfo( struct ipc_info * info, size_t * len, enum ipc_msg id,
     388ipc_mkgetinfo( const struct ipc_info * info, size_t * len, enum ipc_msg id,
    377389               int64_t tag, int types, const int * ids )
    378390{
     
    896908
    897909static int
    898 gotmsg( struct ipc_info * info, tr_benc * name, tr_benc * val,
     910gotmsg( const struct ipc_info * info, tr_benc * name, tr_benc * val,
    899911        tr_benc * tagval, void * arg )
    900912{
     
    941953
    942954static int
    943 handlemsgs( struct ipc_info * info, tr_benc * pay, void * arg )
     955handlemsgs( const struct ipc_info * info, tr_benc * pay, void * arg )
    944956{
    945957    tr_benc * name, * val, * tag;
    946958    int          ii;
    947959
    948     assert( HASVERS( info ) );
     960    assert( ipc_hasvers( info ) );
    949961
    950962    if( DICTPAYLOAD( info ) )
     
    10191031            return -1;
    10201032        }
    1021         if( 0 > ( HASVERS( info ) ? handlemsgs( info, &benc, arg ) :
    1022                                     handlevers( info, &benc ) ) )
     1033        if( 0 > ( ipc_hasvers( info ) ? handlemsgs( info, &benc, arg ) :
     1034                                        handlevers( info, &benc ) ) )
    10231035        {
    10241036            SAFEBENCFREE( &benc );
     
    10321044
    10331045enum ipc_msg
    1034 ipc_msgid( struct ipc_info * info, const char * name )
     1046ipc_msgid( const struct ipc_info * info, const char * name )
    10351047{
    10361048    const struct msg * msg = msglookup( name );
     
    10421054
    10431055int
    1044 ipc_ishandled( struct ipc_info * info, enum ipc_msg id )
     1056ipc_ishandled( const struct ipc_info * info, enum ipc_msg id )
    10451057{
    10461058    assert( MSGVALID( id ) );
     
    10501062
    10511063int
    1052 ipc_havetags( struct ipc_info * info )
     1064ipc_havetags( const struct ipc_info * info )
    10531065{
    10541066    return !DICTPAYLOAD( info );
Note: See TracChangeset for help on using the changeset viewer.