]> code.delx.au - osx-proxyconf/blobdiff - sysconfig.c
Moved from a C implementation of the sysconfig program to a cocoa version
[osx-proxyconf] / sysconfig.c
diff --git a/sysconfig.c b/sysconfig.c
deleted file mode 100644 (file)
index 77ad88f..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-#include <CoreFoundation/CoreFoundation.h>
-#include <SystemConfiguration/SCDynamicStoreCopySpecific.h>
-
-const char* KEYFILE = "/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h";
-
-Boolean
-printCFTypeRef(CFTypeRef value);
-
-
-Boolean
-getDictValue(CFTypeRef* value, CFStringRef key)
-{
-       assert(value != NULL);
-       assert(key != NULL);
-
-       Boolean result;
-       CFDictionaryRef dictRef;
-       dictRef = SCDynamicStoreCopyProxies((SCDynamicStoreRef)NULL);
-       result = (dictRef != NULL);
-       if(result) {
-               *value = (CFNumberRef)CFDictionaryGetValue(dictRef, key);
-       }
-       if(*value != NULL) {
-               CFRetain(*value);
-       }
-
-       if(dictRef != NULL) {
-               CFRelease(dictRef);
-       }
-       if(!result) {
-               *value = NULL;
-       }
-       return result;
-}
-
-Boolean
-printNumber(CFNumberRef numberRef)
-{
-       assert(numberRef != NULL);
-
-       int numberVal = 0;
-       if(CFNumberGetValue(numberRef, kCFNumberIntType, &numberVal)) {
-               printf("%d\n", numberVal);
-               return TRUE;
-       }
-       return FALSE;
-}
-
-Boolean
-printString(CFStringRef strRef)
-{
-       assert(strRef != NULL);
-
-       char strVal[1024];
-       if(CFStringGetCString(strRef, strVal, (CFIndex)1024,
-                             kCFStringEncodingASCII))
-       {
-               printf("%s\n", strVal);
-               return TRUE;
-       }
-       return FALSE;
-}
-
-Boolean
-printArray(CFArrayRef arrayRef)
-{
-       assert(arrayRef != NULL);
-
-       int length = CFArrayGetCount(arrayRef);
-       for(int i = 0; i < length; ++i) {
-               if(!printCFTypeRef(CFArrayGetValueAtIndex(arrayRef, i))) {
-                       return FALSE;
-               }
-       }
-
-       return TRUE;
-}
-
-Boolean
-printCFTypeRef(CFTypeRef value)
-{
-       if(value == NULL) {
-               return FALSE;
-       }
-       else if(CFStringGetTypeID() == CFGetTypeID(value)) {
-               return printString((CFStringRef)value);
-       }
-       else if(CFNumberGetTypeID() == CFGetTypeID(value)) {
-               return printNumber((CFNumberRef)value);
-       }
-       else if(CFArrayGetTypeID()  == CFGetTypeID(value)) {
-               return printArray((CFArrayRef)value);
-       }
-       else {
-               return FALSE;
-       }
-}
-
-CFStringRef
-createCFString(const char* str)
-{
-       return CFStringCreateWithCStringNoCopy(NULL, str,
-                                              kCFStringEncodingASCII,
-                                              kCFAllocatorNull);
-}
-
-void
-usage(const char* program)
-{
-       fprintf(stderr, "Usage: %s [-q] key\n", program);
-       fprintf(stderr, "Look in %s for keys. Eg, HTTPProxy\n\n", KEYFILE);
-}
-
-int
-main(int argc, char** argv)
-{
-       int quiet = 0;
-       const char* key;
-       if(argc == 2) {
-               key = argv[1];
-       } else if(argc == 3 && strcmp("-q", argv[1]) == 0) {
-               quiet = 1;
-               key = argv[2];
-       } else {
-               usage(argv[0]);
-               return 1;
-       }
-
-
-       CFStringRef keyRef = createCFString(key);
-       if(keyRef == NULL) {
-               fprintf(stderr, "Fatal error: Couldn't create CFStringRef from arg2\n");
-               return 1;
-       }
-
-       CFTypeRef valueRef = NULL;
-       if(!getDictValue(&valueRef, keyRef)) {
-               fprintf(stderr, "Fatal error: Error accessing dictionary\n");
-               return 1;
-       }
-
-       if(valueRef == NULL) {
-               if(!quiet) {
-                       fprintf(stderr, "No value for that key\n");
-               }
-               return 0;
-       }
-       if(!printCFTypeRef(valueRef)) {
-               fprintf(stderr, "Fatal error: Unsupported value type in dictionary\n");
-               CFRelease(valueRef);
-               return 1;
-       }
-
-       CFRelease(valueRef);
-       return 0;
-}
-