Index: configure
===================================================================
--- configure	(revision 8a9afe4eaa42052006fb64c6755ac0321b97ab55)
+++ configure	(revision 52b3a9978681da7c3f2cd21cd6987eb158a54a03)
@@ -252,8 +252,8 @@
 	if [ "$ret" = "0" ]; then
 		echo
-		echo 'WARNING: Could not find a suitable SSL library (GnuTLS, libnss or OpenSSL).'
-		echo '         This is necessary for MSN and full Jabber support. To continue,'
-		echo '         install a suitable SSL library or disable MSN support (--msn=0).'
-		echo '         If you want Jabber without SSL support you can try --ssl=bogus.'
+		echo 'ERROR: Could not find a suitable SSL library (GnuTLS, libnss or OpenSSL).'
+		echo '       This is necessary for MSN and full Jabber support. To continue,'
+		echo '       install a suitable SSL library or disable MSN support (--msn=0).'
+		echo '       If you want Jabber without SSL support you can try --ssl=bogus.'
 		
 		exit 1;
@@ -308,5 +308,5 @@
 	echo '#define WITH_MSN' >> config.h
 	protocols=$protocols'msn '
-	protoobjs=$protoobjs'msnn.o '
+	protoobjs=$protoobjs'msn_mod.o '
 fi
 
@@ -316,5 +316,5 @@
 	echo '#define WITH_JABBER' >> config.h
 	protocols=$protocols'jabber '
-	protoobjs=$protoobjs'jabberr.o '
+	protoobjs=$protoobjs'jabber_mod.o '
 fi
 
@@ -324,5 +324,5 @@
 	echo '#define WITH_OSCAR' >> config.h
 	protocols=$protocols'oscar '
-	protoobjs=$protoobjs'oscarr.o '
+	protoobjs=$protoobjs'oscar_mod.o '
 fi
 
@@ -332,5 +332,5 @@
 	echo '#define WITH_YAHOO' >> config.h
 	protocols=$protocols'yahoo '
-	protoobjs=$protoobjs'yahooo.o '
+	protoobjs=$protoobjs'yahoo_mod.o '
 fi
 
Index: protocols/http_client.c
===================================================================
--- protocols/http_client.c	(revision 8a9afe4eaa42052006fb64c6755ac0321b97ab55)
+++ protocols/http_client.c	(revision 52b3a9978681da7c3f2cd21cd6987eb158a54a03)
@@ -5,5 +5,5 @@
   \********************************************************************/
 
-/* HTTP(S) module (actually, it only does HTTPS right now)              */
+/* HTTP(S) module                                                       */
 
 /*
@@ -25,7 +25,9 @@
 
 #include <string.h>
+#include <stdio.h>
 
 #include "sock.h"
 #include "http_client.h"
+#include "url.h"
 
 
@@ -61,4 +63,6 @@
 	}
 	
+	req->func = func;
+	req->data = data;
 	req->request = g_strdup( request );
 	req->request_length = strlen( request );
@@ -103,5 +107,5 @@
 			if( !sockerr_again() )
 			{
-				close( req->fd );
+				closesocket( req->fd );
 				goto error;
 			}
@@ -188,4 +192,5 @@
 		req->reply_headers = g_realloc( req->reply_headers, req->bytes_read + st + 1 );
 		memcpy( req->reply_headers + req->bytes_read, buffer, st );
+		req->bytes_read += st;
 	}
 	
@@ -208,7 +213,11 @@
 	if( end2 && end2 < end1 )
 	{
-		end1 = end2;
+		end1 = end2 + 1;
 		evil_server = 1;
 	}
+	else
+	{
+		end1 += 2;
+	}
 	
 	if( end1 )
@@ -217,7 +226,134 @@
 		
 		if( evil_server )
+			req->reply_body = end1 + 1;
+		else
 			req->reply_body = end1 + 2;
+	}
+	
+	if( ( end1 = strchr( req->reply_headers, ' ' ) ) != NULL )
+	{
+		if( sscanf( end1 + 1, "%d", &req->status_code ) != 1 )
+			req->status_code = -1;
+	}
+	else
+	{
+		req->status_code = -1;
+	}
+	
+	if( req->status_code == 301 || req->status_code == 302 )
+	{
+		char *loc, *new_request, *new_host;
+		int error = 0, new_port, new_proto;
+		
+		loc = strstr( req->reply_headers, "\nLocation: " );
+		if( loc == NULL ) /* We can't handle this redirect... */
+			goto cleanup;
+		
+		loc += 11;
+		while( *loc == ' ' )
+			loc ++;
+		
+		/* TODO/FIXME: Possibly have to handle relative redirections,
+		   and rewrite Host: headers. Not necessary for now, it's
+		   enough for passport authentication like this. */
+		
+		if( *loc == '/' )
+		{
+			/* Just a different pathname... */
+			
+			/* Since we don't cache the servername, and since we
+			   don't need this yet anyway, I won't implement it. */
+			
+			goto cleanup;
+		}
 		else
-			req->reply_body = end1 + 4;
+		{
+			/* A whole URL */
+			url_t *url;
+			char *s;
+			
+			s = strstr( loc, "\r\n" );
+			if( s == NULL )
+				goto cleanup;
+			
+			url = g_new0( url_t, 1 );
+			*s = 0;
+			
+			if( !url_set( url, loc ) )
+			{
+				g_free( url );
+				goto cleanup;
+			}
+			
+			/* Okay, this isn't fun! We have to rebuild the request... :-( */
+			new_request = g_malloc( req->request_length + strlen( url->file ) );
+			
+			/* So, now I just allocated enough memory, so I'm
+			   going to use strcat(), whether you like it or not. :-) */
+			
+			/* First, find the GET/POST/whatever from the original request. */
+			s = strchr( req->request, ' ' );
+			if( s == NULL )
+			{
+				g_free( new_request );
+				g_free( url );
+				goto cleanup;
+			}
+			
+			*s = 0;
+			sprintf( new_request, "%s %s HTTP/1.0\r\n", req->request, url->file );
+			*s = ' ';
+			
+			s = strstr( req->request, "\r\n" );
+			if( s == NULL )
+			{
+				g_free( new_request );
+				g_free( url );
+				goto cleanup;
+			}
+			
+			strcat( new_request, s + 2 );
+			new_host = g_strdup( url->host );
+			new_port = url->port;
+			new_proto = url->proto;
+			
+			g_free( url );
+		}
+		
+		if( req->ssl )
+			ssl_disconnect( req->ssl );
+		else
+			closesocket( req->fd );
+		
+		req->fd = -1;
+		req->ssl = 0;
+		
+		if( new_proto == PROTO_HTTPS )
+		{
+			req->ssl = ssl_connect( new_host, new_port, http_ssl_connected, req );
+			if( req->ssl == NULL )
+				error = 1;
+		}
+		else
+		{
+			req->fd = proxy_connect( new_host, new_port, http_connected, req );
+			if( req->fd < 0 )
+				error = 1;
+		}
+		
+		if( error )
+		{
+			g_free( new_request );
+			goto cleanup;
+		}
+		
+		g_free( req->request );
+		g_free( req->reply_headers );
+		req->request = new_request;
+		req->request_length = strlen( new_request );
+		req->bytes_read = req->bytes_written = req->inpa = 0;
+		req->reply_headers = req->reply_body = NULL;
+		
+		return;
 	}
 	
@@ -230,5 +366,5 @@
 		ssl_disconnect( req->ssl );
 	else
-		close( req->fd );
+		closesocket( req->fd );
 	
 	req->func( req );
Index: protocols/jabber/Makefile
===================================================================
--- protocols/jabber/Makefile	(revision 8a9afe4eaa42052006fb64c6755ac0321b97ab55)
+++ protocols/jabber/Makefile	(revision 52b3a9978681da7c3f2cd21cd6987eb158a54a03)
@@ -16,5 +16,5 @@
 
 # [SH] Phony targets
-all: jabberr.o
+all: jabber_mod.o
 
 .PHONY: all clean distclean
@@ -33,5 +33,5 @@
 	@$(CC) -c $(CFLAGS) $< -o $@
 
-jabberr.o: $(objects)
-	@echo '*' Linking jabberr.o
-	@$(LD) $(LFLAGS) $(objects) -o jabberr.o
+jabber_mod.o: $(objects)
+	@echo '*' Linking jabber_mod.o
+	@$(LD) $(LFLAGS) $(objects) -o jabber_mod.o
Index: protocols/msn/Makefile
===================================================================
--- protocols/msn/Makefile	(revision 8a9afe4eaa42052006fb64c6755ac0321b97ab55)
+++ protocols/msn/Makefile	(revision 52b3a9978681da7c3f2cd21cd6987eb158a54a03)
@@ -16,5 +16,5 @@
 
 # [SH] Phony targets
-all: msnn.o
+all: msn_mod.o
 	
 .PHONY: all clean distclean
@@ -33,7 +33,7 @@
 	@$(CC) -c $(CFLAGS) $< -o $@
 
-msnn.o: $(objects)
-	@echo '*' Linking msnn.o
-	@$(LD) $(LFLAGS) $(objects) -o msnn.o
+msn_mod.o: $(objects)
+	@echo '*' Linking msn_mod.o
+	@$(LD) $(LFLAGS) $(objects) -o msn_mod.o
 	
 
Index: protocols/oscar/Makefile
===================================================================
--- protocols/oscar/Makefile	(revision 8a9afe4eaa42052006fb64c6755ac0321b97ab55)
+++ protocols/oscar/Makefile	(revision 52b3a9978681da7c3f2cd21cd6987eb158a54a03)
@@ -16,5 +16,5 @@
 
 # [SH] Phony targets
-all: oscarr.o
+all: oscar_mod.o
 
 .PHONY: all clean distclean
@@ -33,5 +33,5 @@
 	@$(CC) -c $(CFLAGS) $< -o $@
 
-oscarr.o: $(objects)
-	@echo '*' Linking oscarr.o
-	@$(LD) $(LFLAGS) $(objects) -o oscarr.o
+oscar_mod.o: $(objects)
+	@echo '*' Linking oscar_mod.o
+	@$(LD) $(LFLAGS) $(objects) -o oscar_mod.o
Index: protocols/yahoo/Makefile
===================================================================
--- protocols/yahoo/Makefile	(revision 8a9afe4eaa42052006fb64c6755ac0321b97ab55)
+++ protocols/yahoo/Makefile	(revision 52b3a9978681da7c3f2cd21cd6987eb158a54a03)
@@ -16,5 +16,5 @@
 
 # [SH] Phony targets
-all: yahooo.o
+all: yahoo_mod.o
 
 .PHONY: all clean distclean
@@ -33,5 +33,5 @@
 	@$(CC) -c $(CFLAGS) $< -o $@
 
-yahooo.o: $(objects)
-	@echo '*' Linking yahooo.o
-	@$(LD) $(LFLAGS) $(objects) -o yahooo.o
+yahoo_mod.o: $(objects)
+	@echo '*' Linking yahoo_mod.o
+	@$(LD) $(LFLAGS) $(objects) -o yahoo_mod.o
Index: url.c
===================================================================
--- url.c	(revision 8a9afe4eaa42052006fb64c6755ac0321b97ab55)
+++ url.c	(revision 52b3a9978681da7c3f2cd21cd6987eb158a54a03)
@@ -2,5 +2,5 @@
   * BitlBee -- An IRC to other IM-networks gateway                     *
   *                                                                    *
-  * Copyright 2001-2004 Wilmer van der Gaast and others                *
+  * Copyright 2001-2005 Wilmer van der Gaast and others                *
   \********************************************************************/
 
@@ -30,5 +30,5 @@
 {
 	char s[MAX_STRING];
-	char *i, *j;
+	char *i;
 	
 	/* protocol://							*/
@@ -40,5 +40,7 @@
 	else
 	{
-		if( g_strncasecmp( set_url, "http", i - set_url ) == 0 )
+		if( g_strncasecmp( set_url, "https", i - set_url ) == 0 )
+			url->proto = PROTO_HTTPS;
+		else if( g_strncasecmp( set_url, "http", i - set_url ) == 0 )
 			url->proto = PROTO_HTTP;
 		else if( g_strncasecmp( set_url, "socks4", i - set_url ) == 0 )
@@ -56,31 +58,12 @@
 	if( ( i = strchr( s, '/' ) ) == NULL )
 	{
-		strcpy( url->dir, "/" );
+		strcpy( url->file, "/" );
 	}
 	else
 	{
+		strncpy( url->file, i, MAX_STRING );
 		*i = 0;
-		g_snprintf( url->dir, MAX_STRING, "/%s", i + 1 );
-		if( url->proto == PROTO_HTTP )
-			http_encode( url->dir );
 	}
 	strncpy( url->host, s, MAX_STRING );
-	j = strchr( url->dir, '?' );
-	if( j != NULL )
-		*j = 0;
-	i = strrchr( url->dir, '/' );
-	*i = 0;
-	if( j != NULL )
-		*j = '?';
-	if( i == NULL )
-	{
-		strcpy( url->file, url->dir );
-		strcpy( url->dir, "/" );
-	}
-	else
-	{
-		strcpy( url->file, i + 1 );
-		strcat( url->dir, "/" );
-	}
 	
 	/* Check for username in host field				*/
@@ -96,13 +79,5 @@
 	else
 	{
-		if( url->proto == PROTO_FTP )
-		{
-			strcpy( url->user, "anonymous" );
-			strcpy( url->pass, "-p.artmaps@lintux.cx" );
-		}
-		else
-		{
-			*url->user = *url->pass = 0;
-		}
+		*url->user = *url->pass = 0;
 	}
 	
@@ -117,11 +92,12 @@
 	{
 		*i = 0;
-		sscanf( i + 1, "%i", &url->port );
+		sscanf( i + 1, "%d", &url->port );
 	}
-	/* Take default port numbers from /etc/services			*/
 	else
 	{
 		if( url->proto == PROTO_HTTP )
-			url->port = 8080;
+			url->port = 80;
+		else if( url->proto == PROTO_HTTPS )
+			url->port = 443;
 		else if( url->proto == PROTO_SOCKS4 || url->proto == PROTO_SOCKS4 )
 			url->port = 1080;
Index: url.h
===================================================================
--- url.h	(revision 8a9afe4eaa42052006fb64c6755ac0321b97ab55)
+++ url.h	(revision 52b3a9978681da7c3f2cd21cd6987eb158a54a03)
@@ -26,6 +26,6 @@
 #include "bitlbee.h"
 
-#define PROTO_FTP		1
 #define PROTO_HTTP		2
+#define PROTO_HTTPS		5
 #define PROTO_SOCKS4	3
 #define PROTO_SOCKS5	4
@@ -37,5 +37,4 @@
 	int port;
 	char host[MAX_STRING];
-	char dir[MAX_STRING];
 	char file[MAX_STRING];
 	char user[MAX_STRING];
