From dbf3e95cd99c1d4ca2cfb620334dc349defce8bf Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 Apr 2008 04:26:04 +0000 Subject: [PATCH] make the tracker response lines more human-readable --- libtransmission/tracker.c | 9 ++--- libtransmission/web.c | 75 ++++++++++++++++++++++++++++++++++++++- libtransmission/web.h | 2 ++ 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index 35265f2bf..9c558bf73 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -997,18 +997,19 @@ void tr_trackerStat( const tr_tracker * t, struct tr_tracker_stat * setme) { - assert( t != NULL ); - assert( setme != NULL ); + assert( t ); + assert( setme ); snprintf( setme->scrapeResponse, sizeof( setme->scrapeResponse ), - "%ld", t->lastScrapeResponse ); + "%s (%ld)", tr_webGetResponseStr( t->lastScrapeResponse ), t->lastScrapeResponse ); + setme->lastScrapeTime = t->lastScrapeTime; setme->nextScrapeTime = t->scrapeAt; snprintf( setme->announceResponse, sizeof( setme->announceResponse ), - "%ld", t->lastAnnounceResponse ); + "%s (%ld)", tr_webGetResponseStr( t->lastAnnounceResponse ), t->lastAnnounceResponse ); setme->lastAnnounceTime = t->lastAnnounceTime; setme->nextAnnounceTime = t->reannounceAt; diff --git a/libtransmission/web.c b/libtransmission/web.c index 75054ec2a..550e42b07 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -9,6 +9,8 @@ * $Id:$ */ +#include /* bsearch */ + #include #include @@ -98,6 +100,7 @@ tr_webRun( tr_session * session, curl_easy_setopt( ch, CURLOPT_WRITEDATA, task ); curl_easy_setopt( ch, CURLOPT_USERAGENT, TR_NAME "/" LONG_VERSION_STRING ); curl_easy_setopt( ch, CURLOPT_SSL_VERIFYPEER, 0 ); + curl_easy_setopt( ch, CURLOPT_TIMEOUT, 30 ); curl_multi_add_handle( web->cm, ch ); @@ -128,7 +131,7 @@ processCompletedTasks( tr_web * web ) if( msg->data.result != CURLE_OK ) tr_err( "%s", curl_easy_strerror( msg->data.result ) ); - + ch = msg->easy_handle; curl_easy_getinfo( ch, CURLINFO_PRIVATE, &task ); curl_easy_getinfo( ch, CURLINFO_RESPONSE_CODE, &response_code ); @@ -291,3 +294,73 @@ tr_webInit( tr_session * session ) return web; } + +/*** +**** +***/ + +static struct http_msg { + long code; + const char * text; +} http_msg[] = { + { 101, "Switching Protocols" }, + { 200, "OK" }, + { 201, "Created" }, + { 202, "Accepted" }, + { 203, "Non-Authoritative Information" }, + { 204, "No Content" }, + { 205, "Reset Content" }, + { 206, "Partial Content" }, + { 300, "Multiple Choices" }, + { 301, "Moved Permanently" }, + { 302, "Found" }, + { 303, "See Other" }, + { 304, "Not Modified" }, + { 305, "Use Proxy" }, + { 306, "(Unused)" }, + { 307, "Temporary Redirect" }, + { 400, "Bad Request" }, + { 401, "Unauthorized" }, + { 402, "Payment Required" }, + { 403, "Forbidden" }, + { 404, "Not Found" }, + { 405, "Method Not Allowed" }, + { 406, "Not Acceptable" }, + { 407, "Proxy Authentication Required" }, + { 408, "Request Timeout" }, + { 409, "Conflict" }, + { 410, "Gone" }, + { 411, "Length Required" }, + { 412, "Precondition Failed" }, + { 413, "Request Entity Too Large" }, + { 414, "Request-URI Too Long" }, + { 415, "Unsupported Media Type" }, + { 416, "Requested Range Not Satisfiable" }, + { 417, "Expectation Failed" }, + { 500, "Internal Server Error" }, + { 501, "Not Implemented" }, + { 502, "Bad Gateway" }, + { 503, "Service Unavailable" }, + { 504, "Gateway Timeout" }, + { 505, "HTTP Version Not Supported" }, + { 0, NULL } +}; + +static int +compareResponseCodes( const void * va, const void * vb ) +{ + const long a = *(const long*) va; + const struct http_msg * b = vb; + return a - b->code; +} + +const char * +tr_webGetResponseStr( long code ) +{ + struct http_msg * msg = bsearch( &code, + http_msg, + sizeof( http_msg ) / sizeof( http_msg[0] ), + sizeof( http_msg[0] ), + compareResponseCodes ); + return msg ? msg->text : "Unknown Error"; +} diff --git a/libtransmission/web.h b/libtransmission/web.h index bb926c9d8..7da79be28 100644 --- a/libtransmission/web.h +++ b/libtransmission/web.h @@ -23,6 +23,8 @@ typedef void (tr_web_done_func)( tr_handle * session, const void * response, size_t response_byte_count, void * user_data ); + +const char * tr_webGetResponseStr( long response_code ); void tr_webRun( tr_handle * session, const char * url, -- 2.40.0