]> git.saurik.com Git - apple/configd.git/blobdiff - SystemConfiguration.fproj/SCNetworkConfigurationInternal.c
configd-137.2.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCNetworkConfigurationInternal.c
index 14266e6beb4c88488c3b466e340fe8764085f6e7..d9f157922068e4deafbef78fa06adcdbf7217ca2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004,2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
@@ -72,20 +72,26 @@ __setPrefsConfiguration(SCPreferencesRef    prefs,
                        CFDictionaryRef         config,
                        Boolean                 keepInactive)
 {
-       CFMutableDictionaryRef  newConfig;
-       Boolean                 ok;
+       CFMutableDictionaryRef  newConfig       = NULL;
+       Boolean                 ok              = FALSE;
 
-       if (!isA_CFDictionary(config)) {
-               _SCErrorSet(kSCStatusInvalidArgument);
-               return FALSE;
+       if (config != NULL) {
+               if (!isA_CFDictionary(config)) {
+                       _SCErrorSet(kSCStatusInvalidArgument);
+                       return FALSE;
+               }
+               newConfig = CFDictionaryCreateMutableCopy(NULL, 0, config);
+       } else {
+               newConfig = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
        }
 
-       newConfig = CFDictionaryCreateMutableCopy(NULL, 0, config);
-
        if (keepInactive) {
                CFDictionaryRef curConfig;
 
-               // preserve enabled/disabled state
+               /*
+                * preserve enabled/disabled state
+                */
+
                curConfig = SCPreferencesPathGetValue(prefs, path);
                if (isA_CFDictionary(curConfig) && CFDictionaryContainsKey(curConfig, kSCResvInactive)) {
                        // if currently disabled
@@ -96,10 +102,22 @@ __setPrefsConfiguration(SCPreferencesRef   prefs,
                }
        }
 
-       // set new configuration
-       ok = SCPreferencesPathSetValue(prefs, path, newConfig);
+       /*
+        * set new configuration
+        */
 
-       CFRelease(newConfig);
+       if (CFDictionaryGetCount(newConfig) == 0) {
+               CFRelease(newConfig);
+               newConfig = NULL;
+       }
+
+       if (newConfig == NULL) {
+               ok = SCPreferencesPathRemoveValue(prefs, path);
+       } else {
+               ok = SCPreferencesPathSetValue(prefs, path, newConfig);
+       }
+
+       if (newConfig != NULL)  CFRelease(newConfig);
        return ok;
 }
 
@@ -127,7 +145,10 @@ __setPrefsEnabled(SCPreferencesRef      prefs,
        CFMutableDictionaryRef  newConfig       = NULL;
        Boolean                 ok              = FALSE;
 
-       // preserve current configuration
+       /*
+        * preserve current configuration
+        */
+
        curConfig = SCPreferencesPathGetValue(prefs, path);
        if (curConfig != NULL) {
                if (!isA_CFDictionary(curConfig)) {
@@ -147,7 +168,10 @@ __setPrefsEnabled(SCPreferencesRef      prefs,
                CFDictionarySetValue(newConfig, kSCResvInactive, kCFBooleanTrue);
        }
 
-       // update configuration
+       /*
+        * update configuration
+        */
+
        if (CFDictionaryGetCount(newConfig) == 0) {
                CFRelease(newConfig);
                newConfig = NULL;
@@ -194,7 +218,7 @@ __copyTemplates()
                return NULL;
        }
 
-       // convert the XML data into a property list
+       /* convert the XML data into a property list */
        templates = CFPropertyListCreateFromXMLData(NULL, xmlTemplates, kCFPropertyListImmutable, &xmlError);
        CFRelease(xmlTemplates);
        if (templates == NULL) {