src/lib/net.c 1.70

1.70 2009/03/10 00:31:04 galt
adding https support
Index: src/lib/net.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/net.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -b -B -U 4 -r1.69 -r1.70
--- src/lib/net.c	3 Mar 2009 08:09:46 -0000	1.69
+++ src/lib/net.c	10 Mar 2009 00:31:04 -0000	1.70
@@ -13,8 +13,9 @@
 #include "net.h"
 #include "linefile.h"
 #include "base64.h"
 #include "cheapcgi.h"
+#include "https.h"
 
 static char const rcsid[] = "$Id$";
 
 /* Brought errno in to get more useful error messages */
@@ -309,9 +311,10 @@
 /* Split off user part */
 v = strchr(s, '@');
 if (v == NULL)
     {
-    if (sameWord(parsed->protocol,"http"))
+    if (sameWord(parsed->protocol,"http") ||
+        sameWord(parsed->protocol,"https"))
 	{
 	strcpy(parsed->user, "");
 	strcpy(parsed->password, "");
 	}
@@ -336,8 +339,9 @@
 	*w = 0;
 	strncpy(parsed->user, s, sizeof(parsed->user));
 	strncpy(parsed->password, w+1, sizeof(parsed->password));
 	}
+    
     cgiDecode(parsed->user,parsed->user,strlen(parsed->user));
     cgiDecode(parsed->password,parsed->password,strlen(parsed->password));
     s = v+1;
     }
@@ -348,8 +352,10 @@
 if (t == NULL)
     {
     if (sameWord(parsed->protocol,"http"))
 	strcpy(parsed->port, "80");
+    if (sameWord(parsed->protocol,"https"))
+	strcpy(parsed->port, "443");
     if (sameWord(parsed->protocol,"ftp"))
 	strcpy(parsed->port, "21");
     }
 else
@@ -817,11 +823,19 @@
 int sd;
 
 /* Parse the URL and connect. */
 netParseUrl(url, &npu);
-if (!sameString(npu.protocol, "http"))
+if (sameString(npu.protocol, "http"))
+    sd = netMustConnect(npu.host, atoi(npu.port));
+else if (sameString(npu.protocol, "https"))
+    {
+    sd = netMustConnectHttps(npu.host, atoi(npu.port));
+    }
+else
+    {
     errAbort("Sorry, can only netOpen http's currently");
-sd = netMustConnect(npu.host, atoi(npu.port));
+    return -1;  /* never gets here, fixes compiler complaint */
+    }
 
 /* Ask remote server for a file. */
 dyStringPrintf(dy, "%s %s %s\r\n", method, npu.file, protocol);
 dyStringPrintf(dy, "User-Agent: %s\r\n", agent);
@@ -916,9 +930,9 @@
 int netUrlOpen(char *url)
 /* Return unix low-level file handle for url. 
  * Just close(result) when done. */
 {
-if (startsWith("http://",url) || (stringIn("://", url) == NULL))
+if (startsWith("http://",url) || startsWith("https://",url) || (stringIn("://", url) == NULL))
     return netGetOpenHttp(url);
 else if (startsWith("ftp://",url))
     return netGetOpenFtp(url);
 else