]> 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 d1028b2..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-#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;
-}
-