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/natpmp.c

    r13263 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
     
    1515#include <inttypes.h>
    1616
    17 #include <event2/util.h> /* evutil_inet_ntop() */
     17#include <event2/util.h> /* evutil_inet_ntop () */
    1818
    1919#define ENABLE_STRNATPMPERR
     
    3030
    3131static const char *
    32 getKey( void ) { return _( "Port Forwarding (NAT-PMP)" ); }
     32getKey (void) { return _ ("Port Forwarding (NAT-PMP)"); }
    3333
    3434typedef enum
     
    6464
    6565static void
    66 logVal( const char * func,
    67         int          ret )
    68 {
    69     if( ret == NATPMP_TRYAGAIN )
     66logVal (const char * func,
     67        int          ret)
     68{
     69    if (ret == NATPMP_TRYAGAIN)
    7070        return;
    71     if( ret >= 0 )
    72         tr_ninf( getKey( ), _( "%s succeeded (%d)" ), func, ret );
     71    if (ret >= 0)
     72        tr_ninf (getKey (), _ ("%s succeeded (%d)"), func, ret);
    7373    else
    74         tr_ndbg(
    75              getKey( ),
     74        tr_ndbg (
     75             getKey (),
    7676            "%s failed. Natpmp returned %d (%s); errno is %d (%s)",
    77             func, ret, strnatpmperr( ret ), errno, tr_strerror( errno ) );
     77            func, ret, strnatpmperr (ret), errno, tr_strerror (errno));
    7878}
    7979
    8080struct tr_natpmp*
    81 tr_natpmpInit( void )
     81tr_natpmpInit (void)
    8282{
    8383    struct tr_natpmp * nat;
    8484
    85     nat = tr_new0( struct tr_natpmp, 1 );
     85    nat = tr_new0 (struct tr_natpmp, 1);
    8686    nat->state = TR_NATPMP_DISCOVER;
    8787    nat->public_port = 0;
     
    9292
    9393void
    94 tr_natpmpClose( tr_natpmp * nat )
    95 {
    96     if( nat )
    97     {
    98         if( nat->natpmp.s >= 0 )
    99             tr_netCloseSocket( nat->natpmp.s );
    100         tr_free( nat );
     94tr_natpmpClose (tr_natpmp * nat)
     95{
     96    if (nat)
     97    {
     98        if (nat->natpmp.s >= 0)
     99            tr_netCloseSocket (nat->natpmp.s);
     100        tr_free (nat);
    101101    }
    102102}
    103103
    104104static int
    105 canSendCommand( const struct tr_natpmp * nat )
    106 {
    107     return tr_time( ) >= nat->command_time;
     105canSendCommand (const struct tr_natpmp * nat)
     106{
     107    return tr_time () >= nat->command_time;
    108108}
    109109
    110110static void
    111 setCommandTime( struct tr_natpmp * nat )
    112 {
    113     nat->command_time = tr_time( ) + COMMAND_WAIT_SECS;
     111setCommandTime (struct tr_natpmp * nat)
     112{
     113    nat->command_time = tr_time () + COMMAND_WAIT_SECS;
    114114}
    115115
    116116int
    117 tr_natpmpPulse( struct tr_natpmp * nat, tr_port private_port, bool is_enabled, tr_port * public_port )
     117tr_natpmpPulse (struct tr_natpmp * nat, tr_port private_port, bool is_enabled, tr_port * public_port)
    118118{
    119119    int ret;
    120120
    121     if( is_enabled && ( nat->state == TR_NATPMP_DISCOVER ) )
    122     {
    123         int val = initnatpmp( &nat->natpmp, 0, 0 );
    124         logVal( "initnatpmp", val );
    125         val = sendpublicaddressrequest( &nat->natpmp );
    126         logVal( "sendpublicaddressrequest", val );
     121    if (is_enabled && (nat->state == TR_NATPMP_DISCOVER))
     122    {
     123        int val = initnatpmp (&nat->natpmp, 0, 0);
     124        logVal ("initnatpmp", val);
     125        val = sendpublicaddressrequest (&nat->natpmp);
     126        logVal ("sendpublicaddressrequest", val);
    127127        nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_PUB;
    128128        nat->has_discovered = true;
    129         setCommandTime( nat );
    130     }
    131 
    132     if( ( nat->state == TR_NATPMP_RECV_PUB ) && canSendCommand( nat ) )
     129        setCommandTime (nat);
     130    }
     131
     132    if ((nat->state == TR_NATPMP_RECV_PUB) && canSendCommand (nat))
    133133    {
    134134        natpmpresp_t response;
    135         const int val = readnatpmpresponseorretry( &nat->natpmp, &response );
    136         logVal( "readnatpmpresponseorretry", val );
    137         if( val >= 0 )
     135        const int val = readnatpmpresponseorretry (&nat->natpmp, &response);
     136        logVal ("readnatpmpresponseorretry", val);
     137        if (val >= 0)
    138138        {
    139139            char str[128];
    140             evutil_inet_ntop( AF_INET, &response.pnu.publicaddress.addr, str, sizeof( str ) );
    141             tr_ninf( getKey( ), _( "Found public address \"%s\"" ), str );
     140            evutil_inet_ntop (AF_INET, &response.pnu.publicaddress.addr, str, sizeof (str));
     141            tr_ninf (getKey (), _ ("Found public address \"%s\""), str);
    142142            nat->state = TR_NATPMP_IDLE;
    143143        }
    144         else if( val != NATPMP_TRYAGAIN )
     144        else if (val != NATPMP_TRYAGAIN)
    145145        {
    146146            nat->state = TR_NATPMP_ERR;
     
    148148    }
    149149
    150     if( ( nat->state == TR_NATPMP_IDLE ) || ( nat->state == TR_NATPMP_ERR ) )
    151     {
    152         if( nat->is_mapped && ( !is_enabled || ( nat->private_port != private_port ) ) )
     150    if ((nat->state == TR_NATPMP_IDLE) || (nat->state == TR_NATPMP_ERR))
     151    {
     152        if (nat->is_mapped && (!is_enabled || (nat->private_port != private_port)))
    153153            nat->state = TR_NATPMP_SEND_UNMAP;
    154154    }
    155155
    156     if( ( nat->state == TR_NATPMP_SEND_UNMAP ) && canSendCommand( nat ) )
    157     {
    158         const int val = sendnewportmappingrequest( &nat->natpmp, NATPMP_PROTOCOL_TCP,
     156    if ((nat->state == TR_NATPMP_SEND_UNMAP) && canSendCommand (nat))
     157    {
     158        const int val = sendnewportmappingrequest (&nat->natpmp, NATPMP_PROTOCOL_TCP,
    159159                                                   nat->private_port,
    160160                                                   nat->public_port,
    161                                                    0 );
    162         logVal( "sendnewportmappingrequest", val );
     161                                                   0);
     162        logVal ("sendnewportmappingrequest", val);
    163163        nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_UNMAP;
    164         setCommandTime( nat );
    165     }
    166 
    167     if( nat->state == TR_NATPMP_RECV_UNMAP )
     164        setCommandTime (nat);
     165    }
     166
     167    if (nat->state == TR_NATPMP_RECV_UNMAP)
    168168    {
    169169        natpmpresp_t resp;
    170         const int val = readnatpmpresponseorretry( &nat->natpmp, &resp );
    171         logVal( "readnatpmpresponseorretry", val );
    172         if( val >= 0 )
     170        const int val = readnatpmpresponseorretry (&nat->natpmp, &resp);
     171        logVal ("readnatpmpresponseorretry", val);
     172        if (val >= 0)
    173173        {
    174174            const int private_port = resp.pnu.newportmapping.privateport;
    175175
    176             tr_ninf( getKey( ), _( "no longer forwarding port %d" ), private_port );
    177 
    178             if( nat->private_port == private_port )
     176            tr_ninf (getKey (), _ ("no longer forwarding port %d"), private_port);
     177
     178            if (nat->private_port == private_port)
    179179            {
    180180                nat->private_port = 0;
     
    184184            }
    185185        }
    186         else if( val != NATPMP_TRYAGAIN )
     186        else if (val != NATPMP_TRYAGAIN)
    187187        {
    188188            nat->state = TR_NATPMP_ERR;
     
    190190    }
    191191
    192     if( nat->state == TR_NATPMP_IDLE )
    193     {
    194         if( is_enabled && !nat->is_mapped && nat->has_discovered )
     192    if (nat->state == TR_NATPMP_IDLE)
     193    {
     194        if (is_enabled && !nat->is_mapped && nat->has_discovered)
    195195            nat->state = TR_NATPMP_SEND_MAP;
    196196
    197         else if( nat->is_mapped && tr_time( ) >= nat->renew_time )
     197        else if (nat->is_mapped && tr_time () >= nat->renew_time)
    198198            nat->state = TR_NATPMP_SEND_MAP;
    199199    }
    200200
    201     if( ( nat->state == TR_NATPMP_SEND_MAP ) && canSendCommand( nat ) )
    202     {
    203         const int val = sendnewportmappingrequest( &nat->natpmp, NATPMP_PROTOCOL_TCP, private_port, private_port, LIFETIME_SECS );
    204         logVal( "sendnewportmappingrequest", val );
     201    if ((nat->state == TR_NATPMP_SEND_MAP) && canSendCommand (nat))
     202    {
     203        const int val = sendnewportmappingrequest (&nat->natpmp, NATPMP_PROTOCOL_TCP, private_port, private_port, LIFETIME_SECS);
     204        logVal ("sendnewportmappingrequest", val);
    205205        nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_MAP;
    206         setCommandTime( nat );
    207     }
    208 
    209     if( nat->state == TR_NATPMP_RECV_MAP )
     206        setCommandTime (nat);
     207    }
     208
     209    if (nat->state == TR_NATPMP_RECV_MAP)
    210210    {
    211211        natpmpresp_t resp;
    212         const int    val = readnatpmpresponseorretry( &nat->natpmp, &resp );
    213         logVal( "readnatpmpresponseorretry", val );
    214         if( val >= 0 )
     212        const int    val = readnatpmpresponseorretry (&nat->natpmp, &resp);
     213        logVal ("readnatpmpresponseorretry", val);
     214        if (val >= 0)
    215215        {
    216216            nat->state = TR_NATPMP_IDLE;
    217217            nat->is_mapped = true;
    218             nat->renew_time = tr_time( ) + ( resp.pnu.newportmapping.lifetime / 2 );
     218            nat->renew_time = tr_time () + (resp.pnu.newportmapping.lifetime / 2);
    219219            nat->private_port = resp.pnu.newportmapping.privateport;
    220220            nat->public_port = resp.pnu.newportmapping.mappedpublicport;
    221             tr_ninf( getKey( ), _( "Port %d forwarded successfully" ), nat->private_port );
    222         }
    223         else if( val != NATPMP_TRYAGAIN )
     221            tr_ninf (getKey (), _ ("Port %d forwarded successfully"), nat->private_port);
     222        }
     223        else if (val != NATPMP_TRYAGAIN)
    224224        {
    225225            nat->state = TR_NATPMP_ERR;
     
    227227    }
    228228
    229     switch( nat->state )
     229    switch (nat->state)
    230230    {
    231231        case TR_NATPMP_IDLE:
Note: See TracChangeset for help on using the changeset viewer.