[47194] trunk/base

blb at macports.org blb at macports.org
Sun Feb 22 23:17:43 PST 2009


Revision: 47194
          http://trac.macports.org/changeset/47194
Author:   blb at macports.org
Date:     2009-02-22 23:17:40 -0800 (Sun, 22 Feb 2009)
Log Message:
-----------
Improve port's proxy support for http, https, ftp, and rsync (supporting
System Configuration on Mac OS X and setting proxy values in macports.conf
on all platforms)
Ticket #13158

Modified Paths:
--------------
    trunk/base/doc/macports.conf.in
    trunk/base/src/macports1.0/macports.tcl
    trunk/base/src/pextlib1.0/Makefile
    trunk/base/src/pextlib1.0/Pextlib.c

Added Paths:
-----------
    trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.c
    trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.h

Modified: trunk/base/doc/macports.conf.in
===================================================================
--- trunk/base/doc/macports.conf.in	2009-02-23 05:52:15 UTC (rev 47193)
+++ trunk/base/doc/macports.conf.in	2009-02-23 07:17:40 UTC (rev 47194)
@@ -111,3 +111,29 @@
 # to the list of variables that are not removed from the environment used
 # while processing ports
 # extra_env		KEEP_THIS THIS_TOO
+
+# Proxy support
+# Precedence is: env, macports.conf, System Preferences
+# That is, if it's set in the environment, that will be used instead of
+# anything here or in System Preferences.  Setting proxy_override_env to yes
+# will cause any proxies set here (or in System Preferences if set there but
+# not here) to override what's in the environment.
+# Note that System Preferences doesn't have an rsync proxy definition.
+# Also note, on 10.5, sudo will clear many environment variables including
+# those for proxy support.
+# Equivalent envioronment variables: http_proxy, HTTPS_PROXY, FTP_PROXY,
+# RSYNC_PROXY, NO_PROXY
+#
+#proxy_override_env    yes
+# HTTP proxy:
+#proxy_http            hostname:12345
+# HTTPS proxy:
+#proxy_https       hostname:12345
+# FTP proxy:
+#proxy_ftp         hostname:12345
+# rsync proxy:
+#proxy_rsync       hostname:12345
+# hosts not to go through the proxy (comma-separated, applies to HTTP, HTTPS,
+# and FTP, but not rsync):
+#proxy_skip            internal1, internal2, internal3
+

Modified: trunk/base/src/macports1.0/macports.tcl
===================================================================
--- trunk/base/src/macports1.0/macports.tcl	2009-02-23 05:52:15 UTC (rev 47193)
+++ trunk/base/src/macports1.0/macports.tcl	2009-02-23 07:17:40 UTC (rev 47194)
@@ -46,7 +46,7 @@
         rsync_dir startupitem_type place_worksymlink xcodeversion xcodebuildcmd \
         mp_remote_url mp_remote_submit_url configureccache configuredistcc configurepipe buildnicevalue buildmakejobs \
         applications_dir frameworks_dir universal_target universal_sysroot universal_archs \
-        macportsuser"
+        macportsuser proxy_override_env proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip"
     variable user_options "submitter_name submitter_email submitter_key"
     variable portinterp_options "\
         portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen x11prefix portsharepath \
@@ -711,6 +711,45 @@
         }
     }
     
+    # Proxy handling (done this late since Pextlib is needed)
+    if {![info exists proxy_override_env] } {
+        set proxy_override_env "no"
+    }
+    array set sysConfProxies [get_systemconfiguration_proxies]
+    if {![info exists env(http_proxy)] || $proxy_override_env == "yes" } {
+        if {[info exists proxy_http]} {
+            set env(http_proxy) $proxy_http
+        } elseif {[info exists sysConfProxies(proxy_http)]} {
+            set env(http_proxy) $sysConfProxies(proxy_http)
+        }
+    }
+    if {![info exists env(HTTPS_PROXY)] || $proxy_override_env == "yes" } {
+        if {[info exists proxy_https]} {
+            set env(HTTPS_PROXY) $proxy_https
+        } elseif {[info exists sysConfProxies(proxy_https)]} {
+            set env(HTTPS_PROXY) $sysConfProxies(proxy_https)
+        }
+    }
+    if {![info exists env(FTP_PROXY)] || $proxy_override_env == "yes" } {
+        if {[info exists proxy_ftp]} {
+            set env(FTP_PROXY) $proxy_ftp
+        } elseif {[info exists sysConfProxies(proxy_ftp)]} {
+            set env(FTP_PROXY) $sysConfProxies(proxy_ftp)
+        }
+    }
+    if {![info exists env(RSYNC_PROXY)] || $proxy_override_env == "yes" } {
+        if {[info exists proxy_rsync]} {
+            set env(RSYNC_PROXY) $proxy_rsync
+        }
+    }
+    if {![info exists env(NO_PROXY)] || $proxy_override_env == "yes" } {
+        if {[info exists proxy_skip]} {
+            set env(NO_PROXY) $proxy_skip
+        } elseif {[info exists sysConfProxies(proxy_skip)]} {
+            set env(NO_PROXY) $sysConfProxies(proxy_skip)
+        }
+    }
+
     # load the quick index
     _mports_load_quickindex
 }

Modified: trunk/base/src/pextlib1.0/Makefile
===================================================================
--- trunk/base/src/pextlib1.0/Makefile	2009-02-23 05:52:15 UTC (rev 47193)
+++ trunk/base/src/pextlib1.0/Makefile	2009-02-23 07:17:40 UTC (rev 47194)
@@ -1,7 +1,7 @@
 OBJS=		Pextlib.o strsed.o fgetln.o md5cmd.o setmode.o xinstall.o \
 		fs-traverse.o strcasecmp.o vercomp.o filemap.o \
 		sha1cmd.o compat.o curl.o rmd160cmd.o readline.o uid.o\
-		tracelib.o tty.o
+		tracelib.o tty.o get_systemconfiguration_proxies.o
 SHLIB_NAME=	Pextlib${SHLIB_SUFFIX}
 INSTALLDIR= ${DESTDIR}${datadir}/macports/Tcl/pextlib1.0
 
@@ -10,6 +10,9 @@
 
 CFLAGS+= ${CURL_CFLAGS} ${MD5_CFLAGS} ${READLINE_CFLAGS}
 LIBS+= ${CURL_LIBS} ${MD5_LIBS} ${READLINE_LIBS}
+ifeq ($(OBJC_RUNTIME), APPLE_RUNTIME)
+   LIBS+= -framework CoreFoundation -framework SystemConfiguration
+endif
 
 .PHONY: test
 

Modified: trunk/base/src/pextlib1.0/Pextlib.c
===================================================================
--- trunk/base/src/pextlib1.0/Pextlib.c	2009-02-23 05:52:15 UTC (rev 47193)
+++ trunk/base/src/pextlib1.0/Pextlib.c	2009-02-23 07:17:40 UTC (rev 47194)
@@ -116,6 +116,7 @@
 #include "uid.h"
 #include "tracelib.h"
 #include "tty.h"
+#include "get_systemconfiguration_proxies.h"
 
 #if HAVE_CRT_EXTERNS_H
 #include <crt_externs.h>
@@ -1326,6 +1327,7 @@
 	Tcl_CreateObjCommand(interp, "tracelib", TracelibCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "isatty", IsattyCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "term_get_size", TermGetSizeCmd, NULL, NULL);
+	Tcl_CreateObjCommand(interp, "get_systemconfiguration_proxies", GetSystemConfigurationProxiesCmd, NULL, NULL);
 
 	if (Tcl_PkgProvide(interp, "Pextlib", "1.0") != TCL_OK)
 		return TCL_ERROR;

Added: trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.c
===================================================================
--- trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.c	                        (rev 0)
+++ trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.c	2009-02-23 07:17:40 UTC (rev 47194)
@@ -0,0 +1,175 @@
+/*
+ * get_systemconfiguration_proxies.c
+ * $Id$
+ *
+ * Copyright (c) 2008-2009, The MacPorts Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of MacPorts Team nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include "get_systemconfiguration_proxies.h"
+
+
+#ifdef HAVE_FRAMEWORK_SYSTEMCONFIGURATION
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
+int appendProxyInformationForKeys( CFDictionaryRef proxies, Tcl_Obj *tclList, const char *listKey, const void *proxyEnabledKey, const void *proxyHostKey, const void *proxyPortKey );
+char *cfStringToCStringASCII( CFStringRef cfString );
+
+#endif   /* HAVE_FRAMEWORK_SYSTEMCONFIGURATION */
+
+
+/**
+ *
+ * Query SystemConfiguration for proxy information, returning this
+ * information in a Tcl list ready to be 'array set' (key, name pairs).
+ *
+ * Synopsis: array set someArray get_systemconfiguration_proxies
+ */
+int GetSystemConfigurationProxiesCmd( ClientData clientData UNUSED, Tcl_Interp *interp, int objc UNUSED, Tcl_Obj *CONST objv[] UNUSED )
+{
+    int cmdResult = TCL_OK;
+#ifdef HAVE_FRAMEWORK_SYSTEMCONFIGURATION
+    CFDictionaryRef proxies = SCDynamicStoreCopyProxies( NULL );
+    if( proxies != NULL )
+    {
+        Tcl_Obj *proxyList = Tcl_NewListObj( 0, NULL );
+        if( appendProxyInformationForKeys( proxies, proxyList, "proxy_http", kSCPropNetProxiesHTTPEnable, kSCPropNetProxiesHTTPProxy, kSCPropNetProxiesHTTPPort ) == 0 &&
+            appendProxyInformationForKeys( proxies, proxyList, "proxy_https", kSCPropNetProxiesHTTPSEnable, kSCPropNetProxiesHTTPSProxy, kSCPropNetProxiesHTTPSPort ) == 0 &&
+            appendProxyInformationForKeys( proxies, proxyList, "proxy_ftp", kSCPropNetProxiesFTPEnable, kSCPropNetProxiesFTPProxy, kSCPropNetProxiesFTPPort ) == 0 )
+        {
+            CFArrayRef exceptionsCFArray = CFDictionaryGetValue( proxies, kSCPropNetProxiesExceptionsList );
+            if( exceptionsCFArray != NULL )
+            {
+                CFStringRef exceptionsCFString = CFStringCreateByCombiningStrings( kCFAllocatorDefault, exceptionsCFArray, CFSTR( "," ) );
+                char *exceptionsString = cfStringToCStringASCII( exceptionsCFString );
+                if( exceptionsString != NULL )
+                {
+                    Tcl_Obj *exceptionsKey = Tcl_NewStringObj( "proxy_skip", 10 );
+                    Tcl_Obj *exceptionsTclString = Tcl_NewStringObj( exceptionsString, strlen( exceptionsString ) );
+                    Tcl_ListObjAppendElement( interp, proxyList, exceptionsKey );
+                    Tcl_ListObjAppendElement( interp, proxyList, exceptionsTclString );
+                    free( exceptionsString );
+                }
+                else
+                    cmdResult = TCL_ERROR;
+                CFRelease( exceptionsCFString );
+            }
+            Tcl_SetObjResult( interp, proxyList );
+        }
+        else
+            cmdResult = TCL_ERROR;
+        CFRelease( proxies );
+    }
+    if( cmdResult == TCL_ERROR )
+        Tcl_SetResult( interp, (char *) Tcl_PosixError( interp ), TCL_STATIC );
+#endif
+   return cmdResult;
+}
+
+
+#ifdef HAVE_FRAMEWORK_SYSTEMCONFIGURATION
+/**
+ *
+ * Extract the proxy information (given by proxyEnabledKey, proxyHostKey,
+ * and proxyPortKey) from the proxies dictionary, then append listKey and
+ * the pertinent proxy information to the Tcl list.
+ *
+ * Returns 0 on success; -1 on failure
+ */
+int appendProxyInformationForKeys( CFDictionaryRef proxies, Tcl_Obj *tclList, const char *listKey, const void *proxyEnabledKey, const void *proxyHostKey, const void *proxyPortKey )
+{
+    int result = 0;
+    CFNumberRef proxyEnabledNumber = CFDictionaryGetValue( proxies, proxyEnabledKey );
+    int proxyEnabled = 0;
+    if( proxyEnabledNumber != NULL &&
+        CFNumberGetValue( proxyEnabledNumber, kCFNumberIntType, &proxyEnabled ) &&
+        proxyEnabled )
+    {
+        CFStringRef proxyHostString = CFDictionaryGetValue( proxies, proxyHostKey );
+        char *hostname = NULL;
+        if( proxyHostString != NULL &&
+            ( hostname = cfStringToCStringASCII( proxyHostString ) ) != NULL )
+        {
+            CFNumberRef proxyPortNumber = CFDictionaryGetValue( proxies, proxyPortKey );
+            int proxyPort = 0;
+            if( proxyPortNumber != NULL &&
+                CFNumberGetValue( proxyPortNumber, kCFNumberIntType, &proxyPort ) &&
+                proxyPort > 0 )
+            {
+                /*
+                 * We are adding :<port>\0 to the end, which is up to 7
+                 * bytes additional (up to 5 for the port)
+                 */
+                int newLength = strlen( hostname ) + 7;
+                char *hostnameAndPort = calloc( 1, newLength );
+                if( hostnameAndPort != NULL )
+                {
+                    Tcl_Obj *hostnameAndPortTcl;
+                    Tcl_Obj *listKeyTcl = Tcl_NewStringObj( listKey, strlen( listKey ) );
+                    Tcl_ListObjAppendElement( NULL, tclList, listKeyTcl );
+                    snprintf( hostnameAndPort, newLength, "%s:%d", hostname, proxyPort );
+                    hostnameAndPortTcl = Tcl_NewStringObj( hostnameAndPort, strlen( hostnameAndPort ) );
+                    Tcl_ListObjAppendElement( NULL, tclList, hostnameAndPortTcl );
+                    free( hostnameAndPort );
+                }
+                else
+                    result = -1;
+            }
+            else
+                result = -1;
+        }
+        else
+            result = -1;
+    }
+
+    return result;
+}
+
+
+/**
+ *
+ * Convert a CFStringRef to an ASCII-encoded C string; be sure to free()
+ * the returned string when done with it.
+ */
+char *cfStringToCStringASCII( CFStringRef cfString )
+{
+    int strLen = CFStringGetMaximumSizeForEncoding( CFStringGetLength( cfString ), kCFStringEncodingASCII ) + 1;
+    char *cString = calloc( 1, strLen );
+    if( cString != NULL )
+        CFStringGetCString( cfString, cString, strLen, kCFStringEncodingASCII );
+
+   return cString;
+}
+
+#endif
+


Property changes on: trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.c
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.h
===================================================================
--- trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.h	                        (rev 0)
+++ trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.h	2009-02-23 07:17:40 UTC (rev 47194)
@@ -0,0 +1,41 @@
+/* 
+ * get_systemconfiguration_proxies.h 
+ * $Id$ 
+ * 
+ * Copyright (c) 2008-2009, The MacPorts Project. 
+ * All rights reserved. 
+ * 
+ * Redistribution and use in source and binary forms, with or without 
+ * modification, are permitted provided that the following conditions 
+ * are met: 
+ * 1. Redistributions of source code must retain the above copyright 
+ *    notice, this list of conditions and the following disclaimer. 
+ * 2. Redistributions in binary form must reproduce the above copyright 
+ *    notice, this list of conditions and the following disclaimer in the 
+ *    documentation and/or other materials provided with the distribution. 
+ * 3. Neither the name of MacPorts Team nor the names of its contributors 
+ *    may be used to endorse or promote products derived from this software 
+ *    without specific prior written permission. 
+ *  
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+ * POSSIBILITY OF SUCH DAMAGE. 
+ */ 
+
+#ifndef _GETSYSTEMCONFIGURATIONPROXIES_H
+#define _GETSYSTEMCONFIGURATIONPROXIES_H
+
+#include <tcl.h> 
+
+int GetSystemConfigurationProxiesCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ); 
+
+#endif   /* _GETSYSTEMCONFIGURATIONPROXIES_H */
+


Property changes on: trunk/base/src/pextlib1.0/get_systemconfiguration_proxies.h
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090222/2e1e2a12/attachment-0001.html>


More information about the macports-changes mailing list