Changeset 2034


Ignore:
Timestamp:
Jun 10, 2007, 10:26:59 PM (15 years ago)
Author:
joshe
Message:

Add some code for verbose UPnP logging which can be enabled at compile-time.

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/http.c

    r1773 r2034  
    529529        assert( HTTP_STATE_ERROR == http->state );
    530530    }
     531}
     532
     533void
     534tr_httpGetRequest( tr_http_t * http, const char ** buf, int * len )
     535{
     536    *buf = http->body.buf;
     537    *len = http->body.used;
    531538}
    532539
  • trunk/libtransmission/http.h

    r1293 r2034  
    6666void          tr_httpAddHeader( tr_http_t *, const char *, const char * );
    6767void          tr_httpAddBody( tr_http_t *, const char *, ... ) PRINTF( 2, 3 );
     68void          tr_httpGetRequest( tr_http_t *, const char **, int * );
    6869tr_tristate_t tr_httpPulse( tr_http_t *, const char **, int * );
    6970char        * tr_httpWhatsMyAddress( tr_http_t * );
  • trunk/libtransmission/platform.c

    r1998 r2034  
    3636#include <pwd.h>
    3737
    38 static char * tr_getHomeDirectory()
     38const char *
     39tr_getHomeDirectory( void )
    3940{
    4041    static char     homeDirectory[MAX_PATH_LENGTH];
     
    6667    return homeDirectory;
    6768}
     69
     70#else
     71
     72const char *
     73tr_getHomeDirectory( void )
     74{
     75    /* XXX */
     76    return "";
     77}
     78
    6879#endif /* !SYS_BEOS && !__AMIGAOS4__ */
    6980
  • trunk/libtransmission/platform.h

    r1998 r2034  
    4545tr_thread_t;
    4646
     47/* only for debugging purposes */
     48const char * tr_getHomeDirectory( void );
     49
    4750char * tr_getCacheDirectory();
    4851char * tr_getTorrentsDirectory();
  • trunk/libtransmission/upnp.c

    r2032 r2034  
    2424
    2525#include "transmission.h"
     26
     27/* uncomment this to log requests and responses to ~/transmission-upnp.log */
     28/* #define VERBOSE_LOG */
    2629
    2730#define SSDP_ADDR               "239.255.255.250"
     
    155158              char dir, int getname );
    156159
     160#ifdef VERBOSE_LOG
     161static FILE * vlog = NULL;
     162#endif
     163
    157164tr_upnp_t *
    158165tr_upnpInit()
     
    168175    upnp->infd     = -1;
    169176    upnp->outfd    = -1;
     177
     178#ifdef VERBOSE_LOG
     179    if( NULL == vlog )
     180    {
     181        char path[MAX_PATH_LENGTH];
     182        time_t stupid_api;
     183        snprintf( path, sizeof path, "%s/transmission-upnp.log",
     184                  tr_getHomeDirectory());
     185        vlog = fopen( path, "a" );
     186        stupid_api = time( NULL );
     187        fprintf( vlog, "opened log at %s\n\n", ctime( &stupid_api ) );
     188    }
     189#endif
    170190
    171191    return upnp;
     
    258278
    259279    free( upnp );
     280
     281#ifdef VERBOSE_LOG
     282    if( NULL != vlog )
     283    {
     284        fflush( vlog );
     285    }
     286#endif
     287
    260288}
    261289
     
    346374    sin.sin_addr.s_addr = inet_addr( SSDP_ADDR );
    347375    sin.sin_port        = htons( SSDP_PORT );
     376
     377#ifdef VERBOSE_LOG
     378    fprintf( vlog, "send ssdp message, %i bytes:\n", len );
     379    fwrite( buf, 1, len, vlog );
     380    fputs( "\n\n", vlog );
     381#endif
    348382
    349383    if( 0 > sendto( fd, buf, len, 0,
     
    462496    else
    463497    {
     498#ifdef VERBOSE_LOG
     499        fprintf( vlog, "receive ssdp message, %i bytes:\n", *len );
     500        fwrite( buf, 1, *len, vlog );
     501        fputs( "\n\n", vlog );
     502#endif
    464503        return TR_NET_OK;
    465504    }
     
    810849makeHttp( int method, const char * host, int port, const char * path )
    811850{
     851    tr_http_t  * ret;
     852#ifdef VERBOSE_LOG
     853    const char * body;
     854    int          len;
     855#endif
     856
    812857    if( tr_httpIsUrl( path, -1 ) )
    813858    {
    814         return tr_httpClientUrl( method, "%s", path );
     859        ret = tr_httpClientUrl( method, "%s", path );
    815860    }
    816861    else
    817862    {
    818         return tr_httpClient( method, host, port, "%s", path );
    819     }
     863        ret = tr_httpClient( method, host, port, "%s", path );
     864    }
     865
     866#ifdef VERBOSE_LOG
     867    tr_httpGetRequest( ret, &body, &len );
     868    fprintf( vlog, "send http message, %i bytes:\n", len );
     869    fwrite( body, 1, len, vlog );
     870    fputs( "\n\n", vlog );
     871#endif
     872
     873    return ret;
    820874}
    821875
     
    923977    {
    924978        case TR_NET_OK:
     979#ifdef VERBOSE_LOG
     980    fprintf( vlog, "receive http message, %i bytes:\n", hlen );
     981    fwrite( headers, 1, hlen, vlog );
     982    fputs( "\n\n", vlog );
     983#endif
    925984            code = tr_httpResponseCode( headers, hlen );
    926985            if( SOAP_METHOD_NOT_ALLOWED == code && !dev->soapretry )
Note: See TracChangeset for help on using the changeset viewer.