Ignore:
Timestamp:
Dec 5, 2012, 5:29:46 PM (9 years ago)
Author:
jordan
Message:

Follow more common whitespace style conventions in the C code (libtransmission, daemon, utils, cli, gtk).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/port-forwarding.c

    r13199 r13625  
    33 *
    44 * 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)
     5 * Transmission project are granted a special exemption to clause 2 (b)
    66 * so that the bulk of its code can remain under the MIT license.
    77 * This exemption does not extend to derived works not owned by
     
    2929
    3030static const char *
    31 getKey( void ) { return _( "Port Forwarding" ); }
     31getKey (void) { return _ ("Port Forwarding"); }
    3232
    3333struct tr_shared
     
    5252
    5353static const char*
    54 getNatStateStr( int state )
    55 {
    56     switch( state )
    57     {
    58         case TR_PORT_MAPPING:   return _( "Starting" );
    59         case TR_PORT_MAPPED:    return _( "Forwarded" );
    60         case TR_PORT_UNMAPPING: return _( "Stopping" );
    61         case TR_PORT_UNMAPPED:  return _( "Not forwarded" );
     54getNatStateStr (int state)
     55{
     56    switch (state)
     57    {
     58        case TR_PORT_MAPPING:   return _ ("Starting");
     59        case TR_PORT_MAPPED:    return _ ("Forwarded");
     60        case TR_PORT_UNMAPPING: return _ ("Stopping");
     61        case TR_PORT_UNMAPPED:  return _ ("Not forwarded");
    6262        default:                return "???";
    6363    }
     
    6565
    6666static void
    67 natPulse( tr_shared * s, bool do_check )
     67natPulse (tr_shared * s, bool do_check)
    6868{
    6969    const tr_port private_peer_port = s->session->private_peer_port;
     
    7373    int newStatus;
    7474
    75     if( s->natpmp == NULL )
    76         s->natpmp = tr_natpmpInit( );
    77     if( s->upnp == NULL )
    78         s->upnp = tr_upnpInit( );
    79 
    80     oldStatus = tr_sharedTraversalStatus( s );
    81 
    82     s->natpmpStatus = tr_natpmpPulse( s->natpmp, private_peer_port, is_enabled, &public_peer_port );
    83     if( s->natpmpStatus == TR_PORT_MAPPED )
     75    if (s->natpmp == NULL)
     76        s->natpmp = tr_natpmpInit ();
     77    if (s->upnp == NULL)
     78        s->upnp = tr_upnpInit ();
     79
     80    oldStatus = tr_sharedTraversalStatus (s);
     81
     82    s->natpmpStatus = tr_natpmpPulse (s->natpmp, private_peer_port, is_enabled, &public_peer_port);
     83    if (s->natpmpStatus == TR_PORT_MAPPED)
    8484        s->session->public_peer_port = public_peer_port;
    8585
    86     s->upnpStatus = tr_upnpPulse( s->upnp, private_peer_port, is_enabled, do_check );
    87 
    88     newStatus = tr_sharedTraversalStatus( s );
    89 
    90     if( newStatus != oldStatus )
    91         tr_ninf( getKey( ), _( "State changed from \"%1$s\" to \"%2$s\"" ),
    92                 getNatStateStr( oldStatus ),
    93                 getNatStateStr( newStatus ) );
    94 }
    95 
    96 static void
    97 set_evtimer_from_status( tr_shared * s )
     86    s->upnpStatus = tr_upnpPulse (s->upnp, private_peer_port, is_enabled, do_check);
     87
     88    newStatus = tr_sharedTraversalStatus (s);
     89
     90    if (newStatus != oldStatus)
     91        tr_ninf (getKey (), _ ("State changed from \"%1$s\" to \"%2$s\""),
     92                getNatStateStr (oldStatus),
     93                getNatStateStr (newStatus));
     94}
     95
     96static void
     97set_evtimer_from_status (tr_shared * s)
    9898{
    9999    int sec=0, msec=0;
    100100
    101101    /* when to wake up again */
    102     switch( tr_sharedTraversalStatus( s ) )
     102    switch (tr_sharedTraversalStatus (s))
    103103    {
    104104        case TR_PORT_MAPPED:
     
    120120    }
    121121
    122     if( s->timer != NULL )
    123         tr_timerAdd( s->timer, sec, msec );
    124 }
    125 
    126 static void
    127 onTimer( int fd UNUSED, short what UNUSED, void * vshared )
     122    if (s->timer != NULL)
     123        tr_timerAdd (s->timer, sec, msec);
     124}
     125
     126static void
     127onTimer (int fd UNUSED, short what UNUSED, void * vshared)
    128128{
    129129    tr_shared * s = vshared;
    130130
    131     assert( s );
    132     assert( s->timer );
     131    assert (s);
     132    assert (s->timer);
    133133
    134134    /* do something */
    135     natPulse( s, s->doPortCheck );
     135    natPulse (s, s->doPortCheck);
    136136    s->doPortCheck = false;
    137137
    138138    /* set up the timer for the next pulse */
    139     set_evtimer_from_status( s );
     139    set_evtimer_from_status (s);
    140140}
    141141
     
    145145
    146146tr_shared *
    147 tr_sharedInit( tr_session  * session )
    148 {
    149     tr_shared * s = tr_new0( tr_shared, 1 );
     147tr_sharedInit (tr_session  * session)
     148{
     149    tr_shared * s = tr_new0 (tr_shared, 1);
    150150
    151151    s->session      = session;
     
    155155
    156156#if 0
    157     if( isEnabled )
    158     {
    159         s->timer = tr_new0( struct event, 1 );
    160         evtimer_set( s->timer, onTimer, s );
    161         tr_timerAdd( s->timer, 0, 333000 );
     157    if (isEnabled)
     158    {
     159        s->timer = tr_new0 (struct event, 1);
     160        evtimer_set (s->timer, onTimer, s);
     161        tr_timerAdd (s->timer, 0, 333000);
    162162    }
    163163#endif
     
    167167
    168168static void
    169 stop_timer( tr_shared * s )
    170 {
    171     if( s->timer != NULL )
    172     {
    173         event_free( s->timer );
     169stop_timer (tr_shared * s)
     170{
     171    if (s->timer != NULL)
     172    {
     173        event_free (s->timer);
    174174        s->timer = NULL;
    175175    }
     
    177177
    178178static void
    179 stop_forwarding( tr_shared * s )
    180 {
    181     tr_ninf( getKey( ), "%s", _( "Stopped" ) );
    182     natPulse( s, false );
    183 
    184     tr_natpmpClose( s->natpmp );
     179stop_forwarding (tr_shared * s)
     180{
     181    tr_ninf (getKey (), "%s", _ ("Stopped"));
     182    natPulse (s, false);
     183
     184    tr_natpmpClose (s->natpmp);
    185185    s->natpmp = NULL;
    186186    s->natpmpStatus = TR_PORT_UNMAPPED;
    187187
    188     tr_upnpClose( s->upnp );
     188    tr_upnpClose (s->upnp);
    189189    s->upnp = NULL;
    190190    s->upnpStatus = TR_PORT_UNMAPPED;
    191191
    192     stop_timer( s );
     192    stop_timer (s);
    193193}
    194194
    195195void
    196 tr_sharedClose( tr_session * session )
     196tr_sharedClose (tr_session * session)
    197197{
    198198    tr_shared * s = session->shared;
    199199
    200200    s->isShuttingDown = true;
    201     stop_forwarding( s );
     201    stop_forwarding (s);
    202202    s->session->shared = NULL;
    203     tr_free( s );
    204 }
    205 
    206 static void
    207 start_timer( tr_shared * s )
    208 {
    209     s->timer = evtimer_new( s->session->event_base, onTimer, s );
    210     set_evtimer_from_status( s );
     203    tr_free (s);
     204}
     205
     206static void
     207start_timer (tr_shared * s)
     208{
     209    s->timer = evtimer_new (s->session->event_base, onTimer, s);
     210    set_evtimer_from_status (s);
    211211}
    212212
    213213void
    214 tr_sharedTraversalEnable( tr_shared * s, bool isEnabled )
    215 {
    216     if(( s->isEnabled = isEnabled ))
    217         start_timer( s );
     214tr_sharedTraversalEnable (tr_shared * s, bool isEnabled)
     215{
     216    if ((s->isEnabled = isEnabled))
     217        start_timer (s);
    218218    else
    219         stop_forwarding( s );
     219        stop_forwarding (s);
    220220}
    221221
    222222void
    223 tr_sharedPortChanged( tr_session * session )
     223tr_sharedPortChanged (tr_session * session)
    224224{
    225225    tr_shared * s = session->shared;
    226226
    227     if( s->isEnabled )
    228     {
    229         stop_timer( s );
    230         natPulse( s, false );
    231         start_timer( s );
     227    if (s->isEnabled)
     228    {
     229        stop_timer (s);
     230        natPulse (s, false);
     231        start_timer (s);
    232232    }
    233233}
    234234
    235235bool
    236 tr_sharedTraversalIsEnabled( const tr_shared * s )
     236tr_sharedTraversalIsEnabled (const tr_shared * s)
    237237{
    238238    return s->isEnabled;
     
    240240
    241241int
    242 tr_sharedTraversalStatus( const tr_shared * s )
    243 {
    244     return MAX( s->natpmpStatus, s->upnpStatus );
    245 }
     242tr_sharedTraversalStatus (const tr_shared * s)
     243{
     244    return MAX (s->natpmpStatus, s->upnpStatus);
     245}
Note: See TracChangeset for help on using the changeset viewer.