diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-07-17 00:31:55 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-07-17 00:31:55 +0100 |
commit | 4346c3f4343d0cf67a7eefc381c5b10e15011ce8 (patch) | |
tree | c8777657d9beb067fa5e92f2df7b193fa0ae60a1 /lib | |
parent | 3709301b1559aabb3292e8c15bac14a85d8fc31e (diff) | |
parent | ef14a83adbb9036c0006ad460c5e11882a3d7e13 (diff) |
Merging mainline.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/http_client.c | 10 | ||||
-rw-r--r-- | lib/http_client.h | 8 |
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/http_client.c b/lib/http_client.c index e9d3c1bb..69f06ec5 100644 --- a/lib/http_client.c +++ b/lib/http_client.c @@ -34,9 +34,10 @@ static gboolean http_connected( gpointer data, int source, b_input_condition cond ); static gboolean http_ssl_connected( gpointer data, void *source, b_input_condition cond ); static gboolean http_incoming_data( gpointer data, int source, b_input_condition cond ); +static void http_free( struct http_request *req ); -void *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data ) +struct http_request *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data ) { struct http_request *req; int error = 0; @@ -66,11 +67,12 @@ void *http_dorequest( char *host, int port, int ssl, char *request, http_input_f req->data = data; req->request = g_strdup( request ); req->request_length = strlen( request ); + req->redir_ttl = 3; return( req ); } -void *http_dorequest_url( char *url_string, http_input_function func, gpointer data ) +struct http_request *http_dorequest_url( char *url_string, http_input_function func, gpointer data ) { url_t *url = g_new0( url_t, 1 ); char *request; @@ -310,7 +312,7 @@ got_reply: req->status_code = -1; } - if( req->status_code == 301 || req->status_code == 302 ) + if( ( req->status_code == 301 || req->status_code == 302 ) && req->redir_ttl-- > 0 ) { char *loc, *new_request, *new_host; int error = 0, new_port, new_proto; @@ -444,7 +446,7 @@ cleanup: return FALSE; } -void http_free( struct http_request *req ) +static void http_free( struct http_request *req ) { g_free( req->request ); g_free( req->reply_headers ); diff --git a/lib/http_client.h b/lib/http_client.h index d73894a4..27c484ff 100644 --- a/lib/http_client.h +++ b/lib/http_client.h @@ -60,6 +60,8 @@ struct http_request int body_size; /* The number of bytes in reply_body. */ int finished; /* Set to non-0 if the request was completed successfully. */ + int redir_ttl; /* You can set it to 0 if you don't want + http_client to follow them. */ http_input_function func; gpointer data; @@ -78,7 +80,5 @@ struct http_request version is probably only useful if you want to do POST requests or if you want to add some extra headers. As you can see, HTTPS connections are also supported (using ssl_client). */ -void *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data ); -void *http_dorequest_url( char *url_string, http_input_function func, gpointer data ); - -void http_free( struct http_request *req ); +struct http_request *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data ); +struct http_request *http_dorequest_url( char *url_string, http_input_function func, gpointer data ); |