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

This commit is contained in:
Josh Elsasser 2007-06-10 22:26:59 +00:00
parent de7287a829
commit 1315161ae4
5 changed files with 84 additions and 3 deletions

View File

@ -530,6 +530,13 @@ tr_httpAddBody( tr_http_t * http , const char * fmt , ... )
}
}
void
tr_httpGetRequest( tr_http_t * http, const char ** buf, int * len )
{
*buf = http->body.buf;
*len = http->body.used;
}
tr_tristate_t
tr_httpPulse( tr_http_t * http, const char ** data, int * len )
{

View File

@ -65,6 +65,7 @@ tr_http_t * tr_httpClientUrl( int, const char *, ... )
/* only add headers or body before first pulse */
void tr_httpAddHeader( tr_http_t *, const char *, const char * );
void tr_httpAddBody( tr_http_t *, const char *, ... ) PRINTF( 2, 3 );
void tr_httpGetRequest( tr_http_t *, const char **, int * );
tr_tristate_t tr_httpPulse( tr_http_t *, const char **, int * );
char * tr_httpWhatsMyAddress( tr_http_t * );
void tr_httpClose( tr_http_t * );

View File

@ -35,7 +35,8 @@
#include <pwd.h>
static char * tr_getHomeDirectory()
const char *
tr_getHomeDirectory( void )
{
static char homeDirectory[MAX_PATH_LENGTH];
static int init = 0;
@ -65,6 +66,16 @@ static char * tr_getHomeDirectory()
return homeDirectory;
}
#else
const char *
tr_getHomeDirectory( void )
{
/* XXX */
return "";
}
#endif /* !SYS_BEOS && !__AMIGAOS4__ */
static void

View File

@ -44,6 +44,9 @@ typedef struct tr_thread_s
}
tr_thread_t;
/* only for debugging purposes */
const char * tr_getHomeDirectory( void );
char * tr_getCacheDirectory();
char * tr_getTorrentsDirectory();

View File

@ -24,6 +24,9 @@
#include "transmission.h"
/* uncomment this to log requests and responses to ~/transmission-upnp.log */
/* #define VERBOSE_LOG */
#define SSDP_ADDR "239.255.255.250"
#define SSDP_PORT 1900
#define SSDP_TYPE "upnp:rootdevice"
@ -154,6 +157,10 @@ static const char *
actionLookup( tr_upnp_action_t * action, const char * key, int len,
char dir, int getname );
#ifdef VERBOSE_LOG
static FILE * vlog = NULL;
#endif
tr_upnp_t *
tr_upnpInit()
{
@ -168,6 +175,19 @@ tr_upnpInit()
upnp->infd = -1;
upnp->outfd = -1;
#ifdef VERBOSE_LOG
if( NULL == vlog )
{
char path[MAX_PATH_LENGTH];
time_t stupid_api;
snprintf( path, sizeof path, "%s/transmission-upnp.log",
tr_getHomeDirectory());
vlog = fopen( path, "a" );
stupid_api = time( NULL );
fprintf( vlog, "opened log at %s\n\n", ctime( &stupid_api ) );
}
#endif
return upnp;
}
@ -257,6 +277,14 @@ tr_upnpClose( tr_upnp_t * upnp )
}
free( upnp );
#ifdef VERBOSE_LOG
if( NULL != vlog )
{
fflush( vlog );
}
#endif
}
void
@ -346,6 +374,12 @@ sendSSDP( int fd )
sin.sin_addr.s_addr = inet_addr( SSDP_ADDR );
sin.sin_port = htons( SSDP_PORT );
#ifdef VERBOSE_LOG
fprintf( vlog, "send ssdp message, %i bytes:\n", len );
fwrite( buf, 1, len, vlog );
fputs( "\n\n", vlog );
#endif
if( 0 > sendto( fd, buf, len, 0,
(struct sockaddr*) &sin, sizeof( sin ) ) )
{
@ -461,6 +495,11 @@ recvSSDP( int fd, char * buf, int * len )
}
else
{
#ifdef VERBOSE_LOG
fprintf( vlog, "receive ssdp message, %i bytes:\n", *len );
fwrite( buf, 1, *len, vlog );
fputs( "\n\n", vlog );
#endif
return TR_NET_OK;
}
}
@ -809,14 +848,29 @@ devicePulse( tr_upnp_device_t * dev, int port )
static tr_http_t *
makeHttp( int method, const char * host, int port, const char * path )
{
tr_http_t * ret;
#ifdef VERBOSE_LOG
const char * body;
int len;
#endif
if( tr_httpIsUrl( path, -1 ) )
{
return tr_httpClientUrl( method, "%s", path );
ret = tr_httpClientUrl( method, "%s", path );
}
else
{
return tr_httpClient( method, host, port, "%s", path );
ret = tr_httpClient( method, host, port, "%s", path );
}
#ifdef VERBOSE_LOG
tr_httpGetRequest( ret, &body, &len );
fprintf( vlog, "send http message, %i bytes:\n", len );
fwrite( body, 1, len, vlog );
fputs( "\n\n", vlog );
#endif
return ret;
}
static tr_http_t *
@ -922,6 +976,11 @@ devicePulseHttp( tr_upnp_device_t * dev,
switch( tr_httpPulse( dev->http, &headers, &hlen ) )
{
case TR_NET_OK:
#ifdef VERBOSE_LOG
fprintf( vlog, "receive http message, %i bytes:\n", hlen );
fwrite( headers, 1, hlen, vlog );
fputs( "\n\n", vlog );
#endif
code = tr_httpResponseCode( headers, hlen );
if( SOAP_METHOD_NOT_ALLOWED == code && !dev->soapretry )
{