Index: ssl.c
===================================================================
RCS file: /surf1/CVS/squid/src/ssl.c,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -w -u -r1.1.2.12 -r1.1.2.13
--- ssl.c	1996/06/06 22:29:48	1.1.2.12
+++ ssl.c	1996/06/07 17:33:52	1.1.2.13
@@ -1,6 +1,6 @@
 
 /*
- *  $Id: ssl.c,v 1.1.2.12 1996/06/06 22:29:48 wessels Exp $ 
+ *  $Id: ssl.c,v 1.1.2.13 1996/06/07 17:33:52 wessels Exp $ 
  *
  * DEBUG: Section 26                    ssl
  */
@@ -29,6 +29,7 @@
 static void sslWriteServer _PARAMS((int fd, SslStateData * sslState));
 static void sslWriteClient _PARAMS((int fd, SslStateData * sslState));
 static void sslConnected _PARAMS((int fd, SslStateData * sslState));
+static int sslConnect _PARAMS((int fd, struct hostent *, SslStateData *));
 static void sslConnInProgress _PARAMS((int fd, SslStateData * sslState));
 
 static int sslStateFree(fd, sslState)
@@ -302,54 +303,16 @@
     return;
 }
 
-
-int sslStart(fd, url, request, mime_hdr, size_ptr)
+static int sslConnect(fd, hp, sslState)
      int fd;
-     char *url;
-     request_t *request;
-     char *mime_hdr;
-     int *size_ptr;
+	struct hostent *hp;
+	SslStateData *sslState;
 {
-    /* Create state structure. */
-    int sock, status;
-    SslStateData *sslState = NULL;
-
-    debug(26, 3, "sslStart: '%s %s'\n",
-	RequestMethodStr[request->method], url);
-
-    /* Create socket. */
-    sock = comm_open(COMM_NONBLOCKING, getTcpOutgoingAddr(), 0, url);
-    if (sock == COMM_ERROR) {
-	debug(26, 4, "sslStart: Failed because we're out of sockets.\n");
-	squid_error_url(url,
-	    request->method,
-	    ERR_NO_FDS,
-	    fd_table[fd].ipaddr,
-	    500,
-	    xstrerror());
-	return COMM_ERROR;
-    }
-    sslState = xcalloc(1, sizeof(SslStateData));
-    sslState->url = xstrdup(url);
-    sslState->request = requestLink(request);
-    sslState->mime_hdr = mime_hdr;
-    sslState->timeout = getReadTimeout();
-    sslState->size_ptr = size_ptr;
-    sslState->client.fd = fd;
-    sslState->server.fd = sock;
-    sslState->server.buf = xmalloc(SQUID_TCP_SO_RCVBUF);
-    sslState->client.buf = xmalloc(SQUID_TCP_SO_RCVBUF);
-    comm_set_select_handler(sslState->server.fd,
-	COMM_SELECT_CLOSE,
-	(PF) sslStateFree,
-	(void *) sslState);
-
-    /* check if IP is already in cache. It must be. 
-     * It should be done before this route is called. 
-     * Otherwise, we cannot check return code for ssl. */
+    request_t *request = sslState->request;
+    int status;
     if (!ipcache_gethostbyname(request->host, 0)) {
-	debug(26, 4, "sslstart: Called without IP entry in ipcache. OR lookup failed.\n");
-	squid_error_url(url,
+	debug(26, 4, "sslConnect: Unknown host: %s\n", request->host);
+	squid_error_url(sslState->url,
 	    request->method,
 	    ERR_DNS_FAIL,
 	    fd_table[fd].ipaddr,
@@ -357,9 +320,9 @@
 	    dns_error_message);
 	comm_close(sslState->client.fd);
 	comm_close(sslState->server.fd);
-	return COMM_ERROR;
+	return 0;
     }
-    debug(26, 5, "sslStart: client=%d server=%d\n",
+    debug(26, 5, "sslConnect: client=%d server=%d\n",
 	sslState->client.fd,
 	sslState->server.fd);
     /* Install lifetime handler */
@@ -376,9 +339,9 @@
 	(PF) sslLifetimeExpire,
 	(void *) sslState);
     /* Open connection. */
-    if ((status = comm_connect(sock, request->host, request->port))) {
+    if ((status = comm_connect(fd, request->host, request->port))) {
 	if (status != EINPROGRESS) {
-	    squid_error_url(url,
+	    squid_error_url(sslState->url,
 		request->method,
 		ERR_CONNECT_FAIL,
 		fd_table[fd].ipaddr,
@@ -388,7 +351,7 @@
 	    comm_close(sslState->server.fd);
 	    return COMM_ERROR;
 	} else {
-	    debug(26, 5, "sslStart: conn %d EINPROGRESS\n", sock);
+	    debug(26, 5, "sslConnect: conn %d EINPROGRESS\n", fd);
 	    /* The connection is in progress, install ssl handler */
 	    comm_set_select_handler(sslState->server.fd,
 		COMM_SELECT_WRITE,
@@ -397,7 +360,53 @@
 	    return COMM_OK;
 	}
     }
-    /* We got immediately connected. (can this happen?) */
     sslConnected(sslState->server.fd, sslState);
+    return COMM_OK;
+}
+
+int sslStart(fd, url, request, mime_hdr, size_ptr)
+     int fd;
+     char *url;
+     request_t *request;
+     char *mime_hdr;
+     int *size_ptr;
+{
+    /* Create state structure. */
+    SslStateData *sslState = NULL;
+    int sock;
+
+    debug(26, 3, "sslStart: '%s %s'\n",
+	RequestMethodStr[request->method], url);
+
+    /* Create socket. */
+    sock = comm_open(COMM_NONBLOCKING, getTcpOutgoingAddr(), 0, url);
+    if (sock == COMM_ERROR) {
+	debug(26, 4, "sslStart: Failed because we're out of sockets.\n");
+	squid_error_url(url,
+	    request->method,
+	    ERR_NO_FDS,
+	    fd_table[fd].ipaddr,
+	    500,
+	    xstrerror());
+	return COMM_ERROR;
+    }
+    sslState = xcalloc(1, sizeof(SslStateData));
+    sslState->url = xstrdup(url);
+    sslState->request = requestLink(request);
+    sslState->mime_hdr = mime_hdr;
+    sslState->timeout = getReadTimeout();
+    sslState->size_ptr = size_ptr;
+    sslState->client.fd = fd;
+    sslState->server.fd = sock;
+    sslState->server.buf = xmalloc(SQUID_TCP_SO_RCVBUF);
+    sslState->client.buf = xmalloc(SQUID_TCP_SO_RCVBUF);
+    comm_set_select_handler(sslState->server.fd,
+	COMM_SELECT_CLOSE,
+	(PF) sslStateFree,
+	(void *) sslState);
+    ipcache_nbgethostbyname(request->host,
+            sslState->server.fd,
+            (IPH) sslConnect,
+            sslState);
     return COMM_OK;
 }
