--- /dev/null
+#!/bin/bash
+
+if [ "$(sysconfig -n "HTTPEnable")" -eq 1 ]; then
+ host="$(sysconfig -s "HTTPProxy")"
+ port="$(sysconfig -n "HTTPPort")"
+ echo "export http_proxy=\"http://${host}:${port}\""
+fi
+if [ "$(sysconfig -n "HTTPSEnable")" -eq 1 ]; then
+ host="$(sysconfig -s "HTTPSProxy")"
+ port="$(sysconfig -n "HTTPSPort")"
+ echo "export https_proxy=\"http://${host}:${port}\""
+fi
+if [ "$(sysconfig -n "FTPEnable")" -eq 1 ]; then
+ host="$(sysconfig -s "FTPProxy")"
+ port="$(sysconfig -n "FTPPort")"
+ echo "export ftp_proxy=\"http://${host}:${port}\""
+fi
--- /dev/null
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SCDynamicStoreCopySpecific.h>
+
+const char* KEYFILE = "/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h";
+
+
+Boolean
+getNumberValue(int* numberVal, const void* numberKey)
+{
+ assert(numberVal != NULL);
+ assert(numberKey != NULL);
+
+ Boolean result;
+ CFDictionaryRef dictRef;
+ CFNumberRef numberRef;
+
+
+ dictRef = SCDynamicStoreCopyProxies((SCDynamicStoreRef)NULL);
+ result = (dictRef != NULL);
+ if(result) {
+ numberRef = (CFNumberRef)CFDictionaryGetValue(dictRef, numberKey);
+ result = (numberRef != NULL &&
+ CFGetTypeID(numberRef) == CFNumberGetTypeID());
+ }
+ if(result) {
+ result = CFNumberGetValue(numberRef, kCFNumberIntType, numberVal);
+ }
+
+
+ if(dictRef != NULL) {
+ CFRelease(dictRef);
+ }
+ if(!result) {
+ *numberVal = 0;
+ }
+ return result;
+}
+
+Boolean
+getStringValue(char* strVal, size_t strSize, const void* strKey)
+{
+ assert(strVal != NULL);
+ assert(strKey != NULL);
+
+ Boolean result;
+ CFDictionaryRef dictRef;
+ CFStringRef strRef;
+
+
+ dictRef = SCDynamicStoreCopyProxies((SCDynamicStoreRef)NULL);
+ result = (dictRef != NULL);
+
+ if(result) {
+ strRef = (CFStringRef)CFDictionaryGetValue(dictRef, strKey);
+ result = (strRef != NULL) &&
+ (CFGetTypeID(strRef) == CFStringGetTypeID());
+ }
+ if(result) {
+ result = CFStringGetCString(strRef, strVal, (CFIndex)strSize,
+ kCFStringEncodingASCII);
+ }
+
+
+ if(dictRef != NULL) {
+ CFRelease(dictRef);
+ }
+ if(!result) {
+ *strVal = 0;
+ }
+ return result;
+}
+
+CFStringRef
+createCFString(const char* str)
+{
+ return CFStringCreateWithCStringNoCopy(NULL, str,
+ kCFStringEncodingASCII,
+ kCFAllocatorNull);
+}
+
+void
+usage(const char* program)
+{
+ fprintf(stderr, "Usage: %s (-n NumberKey) | (-s StringKey)\n", program);
+ fprintf(stderr, "Look in %s for keys. Eg, HTTPProxy\n\n", KEYFILE);
+}
+
+int
+main(int argc, char** argv)
+{
+ if(argc != 3) {
+ usage(argv[0]);
+ return 1;
+ }
+
+ CFStringRef keyRef = createCFString(argv[2]);
+ if(keyRef == NULL) {
+ fprintf(stderr, "Fatal error: Couldn't create CFStringRef from arg2\n");
+ return 1;
+ }
+
+ Boolean result;
+ if(strcmp("-n", argv[1]) == 0) {
+ int var = 0;
+ result = getNumberValue(&var, keyRef);
+ if(result) {
+ printf("%d\n", var);
+ }
+ } else if(strcmp("-s", argv[1]) == 0) {
+ char str[1024];
+ result = getStringValue(str, 1024, keyRef);
+ if(result) {
+ printf("%s\n", str);
+ }
+ }
+ else {
+ usage(argv[0]);
+ return 1;
+ }
+
+ return 0;
+}
+