Changeset 5690


Ignore:
Timestamp:
Apr 25, 2008, 4:26:04 AM (14 years ago)
Author:
charles
Message:

make the tracker response lines more human-readable

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r5689 r5690  
    998998                struct tr_tracker_stat * setme)
    999999{
    1000     assert( t != NULL );
    1001     assert( setme != NULL );
     1000    assert( t );
     1001    assert( setme );
    10021002
    10031003    snprintf( setme->scrapeResponse,
    10041004              sizeof( setme->scrapeResponse ),
    1005               "%ld", t->lastScrapeResponse );
     1005              "%s (%ld)", tr_webGetResponseStr( t->lastScrapeResponse ), t->lastScrapeResponse );
     1006
    10061007    setme->lastScrapeTime = t->lastScrapeTime;
    10071008    setme->nextScrapeTime = t->scrapeAt;
     
    10091010    snprintf( setme->announceResponse,
    10101011              sizeof( setme->announceResponse ),
    1011               "%ld", t->lastAnnounceResponse );
     1012              "%s (%ld)", tr_webGetResponseStr( t->lastAnnounceResponse ), t->lastAnnounceResponse );
    10121013
    10131014    setme->lastAnnounceTime = t->lastAnnounceTime;
  • trunk/libtransmission/web.c

    r5689 r5690  
    1010 */
    1111
     12#include <stdlib.h> /* bsearch */
     13
    1214#include <event.h>
    1315#include <curl/curl.h>
     
    99101    curl_easy_setopt( ch, CURLOPT_USERAGENT, TR_NAME "/" LONG_VERSION_STRING );
    100102    curl_easy_setopt( ch, CURLOPT_SSL_VERIFYPEER, 0 );
     103    curl_easy_setopt( ch, CURLOPT_TIMEOUT, 30 );
    101104
    102105    curl_multi_add_handle( web->cm, ch );
     
    129132            if( msg->data.result != CURLE_OK )
    130133                tr_err( "%s", curl_easy_strerror( msg->data.result ) );
    131                        
     134           
    132135            ch = msg->easy_handle;
    133136            curl_easy_getinfo( ch, CURLINFO_PRIVATE, &task );
     
    292295    return web;
    293296}
     297
     298/***
     299****
     300***/
     301
     302static struct http_msg {
     303    long code;
     304    const char * text;
     305} http_msg[] = {
     306    { 101, "Switching Protocols" },
     307    { 200, "OK" },
     308    { 201, "Created" },
     309    { 202, "Accepted" },
     310    { 203, "Non-Authoritative Information" },
     311    { 204, "No Content" },
     312    { 205, "Reset Content" },
     313    { 206, "Partial Content" },
     314    { 300, "Multiple Choices" },
     315    { 301, "Moved Permanently" },
     316    { 302, "Found" },
     317    { 303, "See Other" },
     318    { 304, "Not Modified" },
     319    { 305, "Use Proxy" },
     320    { 306, "(Unused)" },
     321    { 307, "Temporary Redirect" },
     322    { 400, "Bad Request" },
     323    { 401, "Unauthorized" },
     324    { 402, "Payment Required" },
     325    { 403, "Forbidden" },
     326    { 404, "Not Found" },
     327    { 405, "Method Not Allowed" },
     328    { 406, "Not Acceptable" },
     329    { 407, "Proxy Authentication Required" },
     330    { 408, "Request Timeout" },
     331    { 409, "Conflict" },
     332    { 410, "Gone" },
     333    { 411, "Length Required" },
     334    { 412, "Precondition Failed" },
     335    { 413, "Request Entity Too Large" },
     336    { 414, "Request-URI Too Long" },
     337    { 415, "Unsupported Media Type" },
     338    { 416, "Requested Range Not Satisfiable" },
     339    { 417, "Expectation Failed" },
     340    { 500, "Internal Server Error" },
     341    { 501, "Not Implemented" },
     342    { 502, "Bad Gateway" },
     343    { 503, "Service Unavailable" },
     344    { 504, "Gateway Timeout" },
     345    { 505, "HTTP Version Not Supported" },
     346    { 0, NULL }
     347};
     348
     349static int
     350compareResponseCodes( const void * va, const void * vb )
     351{
     352    const long a = *(const long*) va;
     353    const struct http_msg * b = vb;
     354    return a - b->code;
     355}
     356
     357const char *
     358tr_webGetResponseStr( long code )
     359{
     360    struct http_msg * msg = bsearch( &code,
     361                                     http_msg,
     362                                     sizeof( http_msg ) / sizeof( http_msg[0] ),
     363                                     sizeof( http_msg[0] ),
     364                                     compareResponseCodes );
     365    return msg ? msg->text : "Unknown Error";
     366}
  • trunk/libtransmission/web.h

    r5673 r5690  
    2424                                  size_t        response_byte_count,
    2525                                  void        * user_data );
     26
     27const char * tr_webGetResponseStr( long response_code );
    2628                               
    2729void tr_webRun( tr_handle          * session,
Note: See TracChangeset for help on using the changeset viewer.