From 0790644bf8ccfbb1f09f4e7209fc18c2e97f10d8 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 17 May 2006 15:15:20 +0200 Subject: Added http_dorequest_url(). --- protocols/http_client.c | 31 +++++++++++++++++++++++++++++++ protocols/http_client.h | 1 + 2 files changed, 32 insertions(+) (limited to 'protocols') diff --git a/protocols/http_client.c b/protocols/http_client.c index 9417e200..893ba551 100644 --- a/protocols/http_client.c +++ b/protocols/http_client.c @@ -70,6 +70,37 @@ void *http_dorequest( char *host, int port, int ssl, char *request, http_input_f return( req ); } +void *http_dorequest_url( char *url_string, http_input_function func, gpointer data ) +{ + url_t *url = g_new0( url_t, 1 ); + char *request; + void *ret; + + if( !url_set( url, url_string ) ) + { + g_free( url ); + return NULL; + } + + if( url->proto != PROTO_HTTP && url->proto != PROTO_HTTPS ) + { + g_free( url ); + return NULL; + } + + request = g_strdup_printf( "GET %s HTTP/1.0\r\n" + "Host: %s\r\n" + "User-Agent: BitlBee " BITLBEE_VERSION "\r\n" + "\r\n", url->file, url->host ); + + ret = http_dorequest( url->host, url->port, + url->proto == PROTO_HTTPS, request, func, data ); + + g_free( url ); + g_free( request ); + return NULL; +} + /* This one is actually pretty simple... Might get more calls if we can't write the whole request at once. */ static void http_connected( gpointer data, int source, GaimInputCondition cond ) diff --git a/protocols/http_client.h b/protocols/http_client.h index 53c6fcd6..0935b5f6 100644 --- a/protocols/http_client.h +++ b/protocols/http_client.h @@ -52,3 +52,4 @@ struct http_request }; 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 ); -- cgit v1.2.3 From 266fe2fe078833bc5489a3fddd970b9307a7bbfa Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 18 May 2006 09:11:15 +0200 Subject: Fixed return value bug in http_dorequest_url(). --- protocols/http_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/http_client.c b/protocols/http_client.c index 893ba551..46cb8b7b 100644 --- a/protocols/http_client.c +++ b/protocols/http_client.c @@ -98,7 +98,7 @@ void *http_dorequest_url( char *url_string, http_input_function func, gpointer d g_free( url ); g_free( request ); - return NULL; + return ret; } /* This one is actually pretty simple... Might get more calls if we can't write -- cgit v1.2.3 From 0eec3866ac883667045cc028d5f0dac0b4872de7 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 18 May 2006 18:41:18 +0200 Subject: Added a body_size attribute to http_client and fixed a possible NULL dereference bug. --- protocols/http_client.c | 21 ++++++++++++--------- protocols/http_client.h | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'protocols') diff --git a/protocols/http_client.c b/protocols/http_client.c index 46cb8b7b..49e6dd83 100644 --- a/protocols/http_client.c +++ b/protocols/http_client.c @@ -252,21 +252,24 @@ got_reply: end1 = end2 + 1; evil_server = 1; } - else + else if( end1 ) { end1 += 2; } - - if( end1 ) + else { - *end1 = 0; - - if( evil_server ) - req->reply_body = end1 + 1; - else - req->reply_body = end1 + 2; + goto cleanup; } + *end1 = 0; + + if( evil_server ) + req->reply_body = end1 + 1; + else + req->reply_body = end1 + 2; + + req->body_size = req->reply_headers + bytes_read - req->reply_body; + if( ( end1 = strchr( req->reply_headers, ' ' ) ) != NULL ) { if( sscanf( end1 + 1, "%d", &req->status_code ) != 1 ) diff --git a/protocols/http_client.h b/protocols/http_client.h index 0935b5f6..860cdd86 100644 --- a/protocols/http_client.h +++ b/protocols/http_client.h @@ -38,6 +38,7 @@ struct http_request int status_code; char *reply_headers; char *reply_body; + int body_size; int finished; void *ssl; -- cgit v1.2.3 From 41e520279f8633d11f79623574b40af7f8949403 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 18 May 2006 18:50:06 +0200 Subject: Damn typo... --- protocols/http_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/http_client.c b/protocols/http_client.c index 49e6dd83..ead6eb09 100644 --- a/protocols/http_client.c +++ b/protocols/http_client.c @@ -268,7 +268,7 @@ got_reply: else req->reply_body = end1 + 2; - req->body_size = req->reply_headers + bytes_read - req->reply_body; + req->body_size = req->reply_headers + req->bytes_read - req->reply_body; if( ( end1 = strchr( req->reply_headers, ' ' ) ) != NULL ) { -- cgit v1.2.3 From 1b5ab3608488e0cbbc75933a59af1fa7e2ff60b0 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 18 May 2006 19:05:28 +0200 Subject: User-Agent: header. --- protocols/http_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/http_client.c b/protocols/http_client.c index ead6eb09..5db31782 100644 --- a/protocols/http_client.c +++ b/protocols/http_client.c @@ -90,7 +90,7 @@ void *http_dorequest_url( char *url_string, http_input_function func, gpointer d request = g_strdup_printf( "GET %s HTTP/1.0\r\n" "Host: %s\r\n" - "User-Agent: BitlBee " BITLBEE_VERSION "\r\n" + "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n" "\r\n", url->file, url->host ); ret = http_dorequest( url->host, url->port, -- cgit v1.2.3