Changeset 2898


Ignore:
Timestamp:
Aug 21, 2007, 8:38:34 PM (14 years ago)
Author:
charles
Message:

make upnp's internal structures' naming schemes whallop-like

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r2891 r2898  
    489489            const int i = t->addressIndex;
    490490            const int j = t->tierFronts[i];
    491             if( i != j ) {
    492                 tr_tracker_info_t swap = t->addresses[i];
    493                 t->addresses[i] = t->addresses[j];
    494                 t->addresses[j] = swap;
    495             }
     491            const tr_tracker_info_t swap = t->addresses[i];
     492            t->addresses[i] = t->addresses[j];
     493            t->addresses[j] = swap;
    496494        }
    497495    }
     
    861859
    862860    if( interval > 0 )
    863        t->announceIntervalMsec = interval;
     861        t->announceIntervalMsec = interval;
    864862
    865863    if( t->announceIntervalMsec < t->minAnnounceIntervalMsec )
  • trunk/libtransmission/upnp.c

    r2864 r2898  
    7272#define IGD_NO_DYNAMIC_MAPPING  725
    7373
    74 typedef struct tr_upnp_action_s
     74struct upnp_act
    7575{
    7676    char * name;
    7777    int    len;
    7878    struct { char * name; char * var; char dir; } * args;
    79 } tr_upnp_action_t;
    80 
    81 typedef struct tr_upnp_device_s
     79};
     80
     81struct upnp_dev
    8282{
    8383    char                    * id;
     
    104104    unsigned int              soapretry : 1;
    105105    tr_http_t               * http;
    106     tr_upnp_action_t          getcmd;
    107     tr_upnp_action_t          addcmd;
    108     tr_upnp_action_t          delcmd;
    109     struct tr_upnp_device_s * next;
    110 } tr_upnp_device_t;
     106    struct upnp_act           getcmd;
     107    struct upnp_act           addcmd;
     108    struct upnp_act           delcmd;
     109    struct upnp_dev        * next;
     110};
    111111
    112112struct tr_upnp_s
     
    119119    unsigned int       active : 1;
    120120    unsigned int       discovering : 1;
    121     tr_upnp_device_t * devices;
     121    struct upnp_dev * devices;
    122122};
    123123
     
    125125sendSSDP( int fd );
    126126static int
    127 mcastStart();
     127mcastStart( void );
    128128static void
    129129killSock( int * sock );
     
    131131killHttp( tr_http_t ** http );
    132132static int
    133 watchSSDP( tr_upnp_device_t ** devices, int fd );
     133watchSSDP( struct upnp_dev ** devices, int fd );
    134134static tr_tristate_t
    135135recvSSDP( int fd, char * buf, int * len );
     
    137137parseSSDP( char * buf, int len, tr_http_header_t * headers );
    138138static void
    139 deviceAdd( tr_upnp_device_t ** first, const char * id, int idLen,
     139deviceAdd( struct upnp_dev ** first, const char * id, int idLen,
    140140           const char * url, int urlLen );
    141141static void
    142 deviceRemove( tr_upnp_device_t ** prevptr );
    143 static int
    144 deviceStop( tr_upnp_device_t * dev );
    145 static int
    146 devicePulse( tr_upnp_device_t * dev, int port );
    147 static int
    148 devicePulseHttp( tr_upnp_device_t * dev,
     142deviceRemove( struct upnp_dev ** prevptr );
     143static int
     144deviceStop( struct upnp_dev * dev );
     145static int
     146devicePulse( struct upnp_dev * dev, int port );
     147static int
     148devicePulseHttp( struct upnp_dev * dev,
    149149                 const char ** body, int * len );
    150150static tr_http_t *
    151 devicePulseGetHttp( tr_upnp_device_t * dev );
     151devicePulseGetHttp( struct upnp_dev * dev );
    152152static int
    153153parseRoot( const char * root, const char *buf, int len,
     
    156156addUrlbase( const char * base, char ** path );
    157157static int
    158 parseScpd( const char *buf, int len, tr_upnp_action_t * getcmd,
    159            tr_upnp_action_t * addcmd, tr_upnp_action_t * delcmd );
     158parseScpd( const char *buf, int len, struct upnp_act * getcmd,
     159           struct upnp_act * addcmd, struct upnp_act * delcmd );
    160160static int
    161161parseScpdArgs( const char * buf, const char * end,
    162                tr_upnp_action_t * action, char dir );
    163 static int
    164 parseMapping( tr_upnp_device_t * dev, const char * buf, int len );
     162               struct upnp_act * action, char dir );
     163static int
     164parseMapping( struct upnp_dev * dev, const char * buf, int len );
    165165static char *
    166166joinstrs( const char *, const char *, const char * );
    167167static tr_http_t *
    168168soapRequest( int retry, const char * host, int port, const char * path,
    169              const char * type, tr_upnp_action_t * action, ... );
     169             const char * type, struct upnp_act * action, ... );
    170170static void
    171 actionSetup( tr_upnp_action_t * action, const char * name, int prealloc );
     171actionSetup( struct upnp_act * action, const char * name, int prealloc );
    172172static void
    173 actionFree( tr_upnp_action_t * action );
    174 static int
    175 actionAdd( tr_upnp_action_t * action, char * name, char * var,
     173actionFree( struct upnp_act * action );
     174static int
     175actionAdd( struct upnp_act * action, char * name, char * var,
    176176                      char dir );
    177177#define actionLookupVar( act, nam, len, dir ) \
     
    180180    ( actionLookup( (act), (var), (len), (dir), 1 ) )
    181181static const char *
    182 actionLookup( tr_upnp_action_t * action, const char * key, int len,
     182actionLookup( struct upnp_act * action, const char * key, int len,
    183183              char dir, int getname );
    184184
     
    188188
    189189tr_upnp_t *
    190 tr_upnpInit()
     190tr_upnpInit( void )
    191191{
    192192    tr_upnp_t * upnp;
     
    246246tr_upnpStatus( tr_upnp_t * upnp )
    247247{
    248     tr_upnp_device_t * ii;
    249     int                ret;
     248    struct upnp_dev * ii;
     249    int               ret;
    250250
    251251    if( !upnp->active )
     
    316316tr_upnpPulse( tr_upnp_t * upnp )
    317317{
    318     tr_upnp_device_t ** ii;
     318    struct upnp_dev ** ii;
    319319
    320320    if( upnp->active )
     
    455455
    456456static int
    457 watchSSDP( tr_upnp_device_t ** devices, int fd )
     457watchSSDP( struct upnp_dev ** devices, int fd )
    458458{
    459459    /* XXX what if we get a huge SSDP packet? */
     
    587587
    588588static void
    589 deviceAdd( tr_upnp_device_t ** first, const char * id, int idLen,
     589deviceAdd( struct upnp_dev ** first, const char * id, int idLen,
    590590           const char * url, int urlLen )
    591591{
    592     tr_upnp_device_t * ii;
     592    struct upnp_dev * ii;
    593593
    594594    for( ii = *first; NULL != ii; ii = ii->next )
     
    627627
    628628static void
    629 deviceRemove( tr_upnp_device_t ** prevptr )
    630 {
    631     tr_upnp_device_t * dead;
     629deviceRemove( struct upnp_dev ** prevptr )
     630{
     631    struct upnp_dev * dead;
    632632
    633633    dead = *prevptr;
     
    653653
    654654static int
    655 deviceStop( tr_upnp_device_t * dev )
     655deviceStop( struct upnp_dev * dev )
    656656{
    657657    switch( dev->state )
     
    671671
    672672static int
    673 devicePulse( tr_upnp_device_t * dev, int port )
     673devicePulse( struct upnp_dev * dev, int port )
    674674{
    675675    const char * body;
     
    885885
    886886static tr_http_t *
    887 devicePulseGetHttp( tr_upnp_device_t * dev )
     887devicePulseGetHttp( struct upnp_dev * dev )
    888888{
    889889    tr_http_t  * ret;
     
    972972
    973973static int
    974 devicePulseHttp( tr_upnp_device_t * dev,
     974devicePulseHttp( struct upnp_dev * dev,
    975975                 const char ** body, int * len )
    976976{
     
    11541154
    11551155static int
    1156 parseScpd( const char * buf, int len, tr_upnp_action_t * getcmd,
    1157            tr_upnp_action_t * addcmd, tr_upnp_action_t * delcmd )
     1156parseScpd( const char * buf, int len, struct upnp_act * getcmd,
     1157           struct upnp_act * addcmd, struct upnp_act * delcmd )
    11581158{
    11591159    const char * end, * next, * sub, * name;
     
    12011201static int
    12021202parseScpdArgs( const char * buf, const char * end,
    1203                tr_upnp_action_t * action, char dir )
     1203               struct upnp_act * action, char dir )
    12041204{
    12051205    const char * sub, * which;
     
    12331233
    12341234static int
    1235 parseMapping( tr_upnp_device_t * dev, const char * buf, int len )
     1235parseMapping( struct upnp_dev * dev, const char * buf, int len )
    12361236{
    12371237    const char * end, * down, * next, * var;
     
    13101310static tr_http_t *
    13111311soapRequest( int retry, const char * host, int port, const char * path,
    1312              const char * type, tr_upnp_action_t * action, ... )
     1312             const char * type, struct upnp_act * action, ... )
    13131313{
    13141314    tr_http_t  * http;
     
    13741374
    13751375static void
    1376 actionSetup( tr_upnp_action_t * action, const char * name, int prealloc )
     1376actionSetup( struct upnp_act * action, const char * name, int prealloc )
    13771377{
    13781378    action->name = strdup( name );
     
    13841384
    13851385static void
    1386 actionFree( tr_upnp_action_t * act )
     1386actionFree( struct upnp_act * act )
    13871387{
    13881388    free( act->name );
     
    13971397
    13981398static int
    1399 actionAdd( tr_upnp_action_t * act, char * name, char * var, char dir )
     1399actionAdd( struct upnp_act * act, char * name, char * var, char dir )
    14001400{
    14011401    int    ii;
     
    14291429
    14301430static const char *
    1431 actionLookup( tr_upnp_action_t * act, const char * key, int len,
     1431actionLookup( struct upnp_act * act, const char * key, int len,
    14321432              char dir, int getname )
    14331433{
     
    14641464    return NULL;
    14651465}
    1466 
    1467 #if 0
    1468 /* this code is used for standalone root parsing for debugging purposes */
    1469 /* cc -g -Wall -D__TRANSMISSION__ -o upnp upnp.c xml.c utils.c */
    1470 int
    1471 main( int argc, char * argv[] )
    1472 {
    1473     struct stat sb;
    1474     char      * data, * soap, * scpd;
    1475     int         fd, ppp;
    1476     ssize_t     res;
    1477 
    1478     if( 3 != argc )
    1479     {
    1480         printf( "usage: %s root-url root-file\n", argv[0] );
    1481         return 0;
    1482     }
    1483 
    1484     tr_msgInit();
    1485     tr_setMessageLevel( 9 );
    1486 
    1487     if( 0 > stat( argv[2], &sb ) )
    1488     {
    1489         tr_err( "failed to stat file %s: %s", argv[2], strerror( sockerrno ) );
    1490         return 1;
    1491     }
    1492 
    1493     data = malloc( sb.st_size );
    1494     if( NULL == data )
    1495     {
    1496         tr_err( "failed to malloc %zd bytes", ( size_t )sb.st_size );
    1497         return 1;
    1498     }
    1499 
    1500     fd = open( argv[2], O_RDONLY );
    1501     if( 0 > fd )
    1502     {
    1503         tr_err( "failed to open file %s: %s", argv[2], strerror( sockerrno ) );
    1504         free( data );
    1505         return 1;
    1506     }
    1507 
    1508     res = read( fd, data, sb.st_size );
    1509     if( sb.st_size > res )
    1510     {
    1511         tr_err( "failed to read file %s: %s", argv[2],
    1512                 ( 0 > res ? strerror( sockerrno ) : "short read count" ) );
    1513         close( fd );
    1514         free( data );
    1515         return 1;
    1516     }
    1517 
    1518     close( fd );
    1519 
    1520     if( parseRoot( argv[1], data, sb.st_size, &soap, &scpd, &ppp ) )
    1521     {
    1522         tr_err( "root parsing failed" );
    1523     }
    1524     else
    1525     {
    1526         tr_err( "soap=%s scpd=%s ppp=%s", soap, scpd, ( ppp ? "yes" : "no" ) );
    1527         free( soap );
    1528         free( scpd );
    1529     }
    1530     free( data );
    1531 
    1532     return 0;
    1533 }
    1534 
    1535 int  tr_netMcastOpen( int port, struct in_addr addr ) { assert( 0 ); }
    1536 int  tr_netBind    ( int port, int type ) { assert( 0 ); }
    1537 void tr_netClose   ( int s ) { assert( 0 ); }
    1538 int  tr_netRecvFrom( int s, uint8_t * buf, int size, struct sockaddr_in * sin ) { assert( 0 ); }
    1539 int         tr_httpRequestType( const char * data, int len,
    1540                                 char ** method, char ** uri ) { assert( 0 ); }
    1541 int         tr_httpResponseCode( const char * data, int len ) { assert( 0 ); }
    1542 char *      tr_httpParse( const char * data, int len, tr_http_header_t *headers ) { assert( 0 ); }
    1543 int         tr_httpIsUrl( const char * u, int l ) { assert( 0 ); }
    1544 int         tr_httpParseUrl( const char * u, int l, char ** h, int * p, char ** q ) { assert( 0 ); }
    1545 tr_http_t   * tr_httpClient( int t, const char * h, int p, const char * u, ... ) { assert( 0 ); }
    1546 tr_http_t   * tr_httpClientUrl( int t, const char * u, ... ) { assert( 0 ); }
    1547 void          tr_httpAddHeader( tr_http_t * h, const char * n, const char * v ) { assert( 0 ); }
    1548 void          tr_httpAddBody( tr_http_t * h, const char * b, ... ) { assert( 0 ); }
    1549 tr_tristate_t tr_httpPulse( tr_http_t * h, const char ** b, int * l ) { assert( 0 ); }
    1550 char        * tr_httpWhatsMyAddress( tr_http_t * h ) { assert( 0 ); }
    1551 void          tr_httpClose( tr_http_t * h ) { assert( 0 ); }
    1552 
    1553 void tr_lockInit     ( tr_lock_t * l ) {}
    1554 int  pthread_mutex_lock( pthread_mutex_t * m ) { return 0; }
    1555 int  pthread_mutex_unlock( pthread_mutex_t * m ) { return 0; }
    1556 
    1557 #endif
  • trunk/libtransmission/upnp.h

    r1720 r2898  
    2828typedef struct tr_upnp_s tr_upnp_t;
    2929
    30 tr_upnp_t * tr_upnpInit();
    31 void        tr_upnpStart( tr_upnp_t * );
    32 void        tr_upnpStop( tr_upnp_t * );
    33 int         tr_upnpStatus( tr_upnp_t * );
    34 void        tr_upnpForwardPort( tr_upnp_t *, int );
    35 void        tr_upnpRemoveForwarding( tr_upnp_t * );
    36 void        tr_upnpPulse( tr_upnp_t * );
    37 void        tr_upnpClose( tr_upnp_t * );
     30tr_upnp_t * tr_upnpInit             ( void );
     31void        tr_upnpStart            ( tr_upnp_t * );
     32void        tr_upnpStop             ( tr_upnp_t * );
     33int         tr_upnpStatus           ( tr_upnp_t * );
     34void        tr_upnpForwardPort      ( tr_upnp_t *, int );
     35void        tr_upnpRemoveForwarding ( tr_upnp_t * );
     36void        tr_upnpPulse            ( tr_upnp_t * );
     37void        tr_upnpClose            ( tr_upnp_t * );
    3838
    3939#endif
Note: See TracChangeset for help on using the changeset viewer.