]> git.saurik.com Git - apple/configd.git/blobdiff - scutil.tproj/dictionary.c
configd-395.11.tar.gz
[apple/configd.git] / scutil.tproj / dictionary.c
index 5b846c6ff9dbad8178be14960b850dcd9738782b..396e3ab5add00be21c4ce3d29dfe77a86d9a4b7d 100644 (file)
@@ -1,22 +1,23 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004, 2009, 2010 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
- *
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
- *
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
- *
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
  * @APPLE_LICENSE_HEADER_END@
  */
 
  */
 
 #include "scutil.h"
+#include "dictionary.h"
 
 
 //#include <stdlib.h>
 //#include <limits.h>
 
 
+__private_extern__
 void
 do_dictInit(int argc, char **argv)
 {
@@ -54,6 +57,7 @@ do_dictInit(int argc, char **argv)
 }
 
 
+__private_extern__
 void
 do_dictShow(int argc, char **argv)
 {
@@ -68,15 +72,17 @@ do_dictShow(int argc, char **argv)
 }
 
 
+__private_extern__
 void
 do_dictSetKey(int argc, char **argv)
 {
-       CFMutableArrayRef       array     = NULL;
-       Boolean                 doArray   = FALSE;
-       Boolean                 doBoolean = FALSE;
-       Boolean                 doNumeric = FALSE;
+       CFMutableArrayRef       array           = NULL;
+       Boolean                 doArray         = FALSE;
+       Boolean                 doBoolean       = FALSE;
+       Boolean                 doNumeric       = FALSE;
        CFStringRef             key;
-       CFTypeRef               val;
+       CFMutableDictionaryRef  newValue;
+       CFTypeRef               val             = NULL;
 
        if (value == NULL) {
                SCPrint(TRUE, stdout, CFSTR("d.add: dictionary must be initialized.\n"));
@@ -88,11 +94,7 @@ do_dictSetKey(int argc, char **argv)
                return;
        }
 
-       val = CFDictionaryCreateMutableCopy(NULL, 0, value);
-       CFRelease(value);
-       value = val;
-
-       key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
+       key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingUTF8);
        argv++; argc--;
 
        while (argc > 0) {
@@ -118,6 +120,7 @@ do_dictSetKey(int argc, char **argv)
                doArray = TRUE;
        } else if (!doArray && (argc == 0)) {
                SCPrint(TRUE, stdout, CFSTR("d.add: no values.\n"));
+               CFRelease(key);
                return;
        }
 
@@ -141,9 +144,8 @@ do_dictSetKey(int argc, char **argv)
                                val = CFRetain(kCFBooleanFalse);
                        } else {
                                SCPrint(TRUE, stdout, CFSTR("d.add: invalid data.\n"));
-                               if (doArray) {
-                                       CFRelease(array);
-                               }
+                               if (doArray) CFRelease(array);
+                               CFRelease(key);
                                return;
                        }
                } else if (doNumeric) {
@@ -153,34 +155,40 @@ do_dictSetKey(int argc, char **argv)
                                val = CFNumberCreate(NULL, kCFNumberIntType, &intValue);
                        } else {
                                SCPrint(TRUE, stdout, CFSTR("d.add: invalid data.\n"));
-                               if (doArray) {
-                                       CFRelease(array);
-                               }
+                               if (doArray) CFRelease(array);
+                               CFRelease(key);
                                return;
                        }
                } else {
-                       val = (CFPropertyListRef)CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
+                       val = (CFPropertyListRef)CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingUTF8);
                }
 
                if (doArray) {
                        CFArrayAppendValue(array, val);
+                       CFRelease(val);
+                       argv++; argc--;
+               } else {
+                       break;
                }
-
-               argv++; argc--;
        }
 
+       newValue = CFDictionaryCreateMutableCopy(NULL, 0, value);
        if (doArray) {
-               val = array;
+               CFDictionarySetValue(newValue, key, array);
+               CFRelease(array);
+       } else if (val != NULL) {
+               CFDictionarySetValue(newValue, key, val);
+               CFRelease(val);
        }
-
-       CFDictionarySetValue((CFMutableDictionaryRef)value, key, val);
-       CFRelease(val);
        CFRelease(key);
+       CFRelease(value);
+       value = newValue;
 
        return;
 }
 
 
+__private_extern__
 void
 do_dictRemoveKey(int argc, char **argv)
 {
@@ -201,7 +209,7 @@ do_dictRemoveKey(int argc, char **argv)
        CFRelease(value);
        value = val;
 
-       key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
+       key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingUTF8);
        CFDictionaryRemoveValue((CFMutableDictionaryRef)value, key);
        CFRelease(key);