Changeset 7deb447


Ignore:
Timestamp:
2006-05-26T18:32:50Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
fe23720
Parents:
6048744
Message:

Added status_string variable to http_client.

Location:
protocols
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/http_client.c

    r6048744 r7deb447  
    157157       
    158158error:
     159        req->status_string = g_strdup( "Error while writing HTTP request" );
     160       
    159161        req->func( req );
    160162       
     
    216218                        if( !sockerr_again() )
    217219                        {
     220                                req->status_string = g_strdup( strerror( errno ) );
    218221                                goto cleanup;
    219222                        }
     
    243246           support... */
    244247        if( req->bytes_read == 0 )
     248        {
     249                req->status_string = g_strdup( "Empty HTTP reply" );
    245250                goto cleanup;
     251        }
    246252       
    247253        /* Zero termination is very convenient. */
     
    264270        else
    265271        {
     272                req->status_string = g_strdup( "Malformed HTTP reply" );
    266273                goto cleanup;
    267274        }
     
    279286        {
    280287                if( sscanf( end1 + 1, "%d", &req->status_code ) != 1 )
     288                {
     289                        req->status_string = g_strdup( "Can't parse status code" );
    281290                        req->status_code = -1;
    282         }
    283         else
    284         {
     291                }
     292                else
     293                {
     294                        char *eol;
     295                       
     296                        if( evil_server )
     297                                eol = strchr( end1, '\n' );
     298                        else
     299                                eol = strchr( end1, '\r' );
     300                       
     301                        req->status_string = g_strndup( end1 + 1, eol - end1 - 1 );
     302                       
     303                        /* Just to be sure... */
     304                        if( ( eol = strchr( req->status_string, '\r' ) ) )
     305                                *eol = 0;
     306                        if( ( eol = strchr( req->status_string, '\n' ) ) )
     307                                *eol = 0;
     308                }
     309        }
     310        else
     311        {
     312                req->status_string = g_strdup( "Can't locate status code" );
    285313                req->status_code = -1;
    286314        }
     
    291319                int error = 0, new_port, new_proto;
    292320               
     321                /* We might fill it again, so let's not leak any memory. */
     322                g_free( req->status_string );
     323                req->status_string = NULL;
     324               
    293325                loc = strstr( req->reply_headers, "\nLocation: " );
    294326                if( loc == NULL ) /* We can't handle this redirect... */
     327                {
     328                        req->status_string = g_strdup( "Can't locate Location: header" );
    295329                        goto cleanup;
     330                }
    296331               
    297332                loc += 11;
     
    310345                           don't need this yet anyway, I won't implement it. */
    311346                       
     347                        req->status_string = g_strdup( "Can't handle recursive redirects" );
     348                       
    312349                        goto cleanup;
    313350                }
     
    327364                        if( !url_set( url, loc ) )
    328365                        {
     366                                req->status_string = g_strdup( "Malformed redirect URL" );
    329367                                g_free( url );
    330368                                goto cleanup;
     
    341379                        if( s == NULL )
    342380                        {
     381                                req->status_string = g_strdup( "Error while rebuilding request string" );
    343382                                g_free( new_request );
    344383                                g_free( url );
     
    353392                        if( s == NULL )
    354393                        {
     394                                req->status_string = g_strdup( "Error while rebuilding request string" );
    355395                                g_free( new_request );
    356396                                g_free( url );
     
    372412               
    373413                req->fd = -1;
    374                 req->ssl = 0;
     414                req->ssl = NULL;
    375415               
    376416                if( new_proto == PROTO_HTTPS )
     
    390430                if( error )
    391431                {
     432                        req->status_string = g_strdup( "Connection problem during redirect" );
    392433                        g_free( new_request );
    393434                        goto cleanup;
     
    418459        g_free( req->request );
    419460        g_free( req->reply_headers );
     461        g_free( req->status_string );
    420462        g_free( req );
    421463}
  • protocols/http_client.h

    r6048744 r7deb447  
    3737        int request_length;
    3838        int status_code;
     39        char *status_string;
    3940        char *reply_headers;
    4041        char *reply_body;
Note: See TracChangeset for help on using the changeset viewer.