]> git.saurik.com Git - apple/configd.git/commitdiff
configd-53.tar.gz mac-os-x-102 mac-os-x-1021 mac-os-x-1022 mac-os-x-1023 v53
authorApple <opensource@apple.com>
Thu, 20 Jun 2002 01:37:08 +0000 (01:37 +0000)
committerApple <opensource@apple.com>
Thu, 20 Jun 2002 01:37:08 +0000 (01:37 +0000)
90 files changed:
Makefile
Makefile.postamble
Makefile.preamble
PB.project
SystemConfiguration.fproj/CustomInfo.plist
SystemConfiguration.fproj/DeviceOnHold.c [new file with mode: 0644]
SystemConfiguration.fproj/DeviceOnHold.h [new file with mode: 0644]
SystemConfiguration.fproj/Makefile
SystemConfiguration.fproj/Makefile.postamble
SystemConfiguration.fproj/Makefile.preamble
SystemConfiguration.fproj/PB.project
SystemConfiguration.fproj/SCD.c
SystemConfiguration.fproj/SCDAdd.c
SystemConfiguration.fproj/SCDAddSession.c
SystemConfiguration.fproj/SCDConsoleUser.c
SystemConfiguration.fproj/SCDGet.c
SystemConfiguration.fproj/SCDHostName.c
SystemConfiguration.fproj/SCDList.c
SystemConfiguration.fproj/SCDNotifierAdd.c
SystemConfiguration.fproj/SCDNotifierCancel.c
SystemConfiguration.fproj/SCDNotifierGetChanges.c
SystemConfiguration.fproj/SCDNotifierInformViaCallback.c
SystemConfiguration.fproj/SCDNotifierList.c
SystemConfiguration.fproj/SCDNotifierRemove.c
SystemConfiguration.fproj/SCDNotify.c
SystemConfiguration.fproj/SCDOpen.c
SystemConfiguration.fproj/SCDPlugin.c [new file with mode: 0644]
SystemConfiguration.fproj/SCDPlugin.h
SystemConfiguration.fproj/SCDPrivate.c
SystemConfiguration.fproj/SCDRemove.c
SystemConfiguration.fproj/SCDSet.c
SystemConfiguration.fproj/SCDTouch.c
SystemConfiguration.fproj/SCDynamicStoreCopyDHCPInfo.h
SystemConfiguration.fproj/SCDynamicStoreCopySpecific.h
SystemConfiguration.fproj/SCDynamicStoreKey.h
SystemConfiguration.fproj/SCLocation.c [new file with mode: 0644]
SystemConfiguration.fproj/SCNetwork.c
SystemConfiguration.fproj/SCPList.c
SystemConfiguration.fproj/SCPLock.c
SystemConfiguration.fproj/SCPOpen.c
SystemConfiguration.fproj/SCPPath.c
SystemConfiguration.fproj/SCPreferencesPath.h
SystemConfiguration.fproj/SCPreferencesSetSpecific.h
SystemConfiguration.fproj/SCPrivate.h
SystemConfiguration.fproj/SCProxies.c
SystemConfiguration.fproj/SCValidation.h
SystemConfiguration.fproj/SystemConfiguration.h
SystemConfiguration.fproj/genSCPreferences.c
SystemConfiguration.fproj/moh.c [new file with mode: 0644]
SystemConfiguration.fproj/moh.h [new file with mode: 0644]
SystemConfiguration.fproj/moh_msg.h [new file with mode: 0644]
SystemConfiguration.fproj/ppp.c
SystemConfiguration.fproj/ppp.h
SystemConfiguration.fproj/ppp_msg.h
configd.tproj/Makefile
configd.tproj/Makefile.preamble
configd.tproj/PB.project
configd.tproj/_SCD.c
configd.tproj/_configadd.c
configd.tproj/_configadd_s.c
configd.tproj/_configclose.c
configd.tproj/_configget.c
configd.tproj/_configlist.c
configd.tproj/_confignotify.c
configd.tproj/_configopen.c
configd.tproj/_configremove.c
configd.tproj/_configset.c
configd.tproj/_configtouch.c
configd.tproj/_configunlock.c
configd.tproj/_notifyadd.c
configd.tproj/_notifychanges.c
configd.tproj/_notifyremove.c
configd.tproj/_notifyviasignal.c
configd.tproj/_snapshot.c
configd.tproj/config.defs
configd.tproj/configd.m
configd.tproj/configd_server.c
configd.tproj/notify.c
configd.tproj/plugin_support.c
preferences.xml [new file with mode: 0644]
scselect.tproj/Makefile
scselect.tproj/PB.project
scselect.tproj/scselect.c
scutil.tproj/Makefile
scutil.tproj/PB.project
scutil.tproj/cache.c
scutil.tproj/dictionary.c
scutil.tproj/notify.c
scutil.tproj/scutil.c
scutil.tproj/scutil.h

index 61c7f5a3e8fde2a837f827ce70d59f8d4e8d7e19..1e2e8c88e76cee835f09ec8517e80a65c33157dd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,8 @@ TOOLS = configd.tproj scselect.tproj scutil.tproj
 
 FRAMEWORK_SUBPROJECTS = SystemConfiguration.fproj
 
-OTHERSRCS = Makefile.preamble Makefile Makefile.postamble
+OTHERSRCS = Makefile.preamble Makefile Makefile.postamble\
+            preferences.xml
 
 MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles
 CODE_GEN_STYLE = DYNAMIC
index b3af8422b79026535d7c45f6fbfdc3af7fbb42cd..05b58f4d7270c1ba03df8ccbe1f4bd2ab16d08cf 100644 (file)
@@ -98,3 +98,7 @@
 # owned by the top-level Makefile API and no context has been set up for where
 # derived files should go.
 #
+SYSCONFIG_PREFS_DIR = /private/var/db/SystemConfiguration
+install_extra:
+       $(MKDIRS) $(DSTROOT)$(SYSCONFIG_PREFS_DIR)
+       install -c -m 644 preferences.xml $(DSTROOT)$(SYSCONFIG_PREFS_DIR)/preferences.xml
index 974c0aca8a9a1bfde76c511c7dcbf0185b313598..480f47f120bbc33f15153d2a6f213de5ae51d01b 100644 (file)
 # standard locations.  NEXT_ROOT defaults to "C:/Apple" on Windows systems
 # and "" on other systems.
 DSTROOT = $(HOME)
+AFTER_INSTALL = install_extra
index 5726c0db98d7b874d5b167d63ce2275c7667e6cb..1be251514f36f0069444d78ae4c2a616cb77318d 100644 (file)
@@ -2,7 +2,7 @@
     DYNAMIC_CODE_GEN = YES; 
     FILESTABLE = {
         H_FILES = (); 
-        OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); 
+        OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, preferences.xml); 
         PRECOMPILED_HEADERS = (); 
         PROJECT_HEADERS = (); 
         PUBLIC_HEADERS = (); 
index 8be4e1f8968dd06d7c0590200abfaf3207528251..1f6eaa326f931af49ebfe4c3b7d4fce90cc779b0 100644 (file)
@@ -1,5 +1,5 @@
 {
        CFBundleName = "SystemConfiguration";
        CFBundleIdentifier = "com.apple.SystemConfiguration";
-       CFBundleShortVersionString = "1.1.0";
+       CFBundleShortVersionString = "1.2.0";
 }
diff --git a/SystemConfiguration.fproj/DeviceOnHold.c b/SystemConfiguration.fproj/DeviceOnHold.c
new file mode 100644 (file)
index 0000000..88079cf
--- /dev/null
@@ -0,0 +1,483 @@
+/*
+ * Copyright (c) 2002 Apple Computer, 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
+ * 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.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * Modification History
+ *
+ * May 29, 2002                Roger Smith <rsmith@apple.com>
+ * - initial revision
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <mach/mach.h>
+#include <mach-o/dyld.h>
+#include <pthread.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreFoundation/CFRuntime.h>
+
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <SystemConfiguration/SCValidation.h>
+#include <SystemConfiguration/SCPrivate.h>
+
+#include <IOKit/IOKitLib.h>
+
+#include "moh_msg.h"
+#include "moh.h"
+#include "DeviceOnHold.h"
+
+
+#define kIODeviceSupportsHoldKey       "DeviceSupportsHold"
+
+
+static void *
+__loadIOKit(void) {
+       static const void *image = NULL;
+       if (NULL == image) {
+               const char      *framework              = "/System/Library/Frameworks/IOKit.framework/IOKit";
+               struct stat     statbuf;
+               const char      *suffix                 = getenv("DYLD_IMAGE_SUFFIX");
+               char            path[MAXPATHLEN];
+
+               strcpy(path, framework);
+               if (suffix) strcat(path, suffix);
+               if (0 <= stat(path, &statbuf)) {
+                       image = NSAddImage(path, NSADDIMAGE_OPTION_NONE);
+               } else {
+                       image = NSAddImage(framework, NSADDIMAGE_OPTION_NONE);
+               }
+       }
+       return (void *)image;
+}
+
+
+static io_object_t
+_IOIteratorNext(io_iterator_t iterator)
+{
+       static io_object_t (*dyfunc)(io_iterator_t) = NULL;
+       if (!dyfunc) {
+               void *image = __loadIOKit();
+               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+       }
+       return dyfunc ? dyfunc(iterator) : 0;
+}
+#define IOIteratorNext _IOIteratorNext
+
+
+static kern_return_t
+_IOMasterPort(mach_port_t bootstrapPort, mach_port_t *masterPort)
+{
+       static kern_return_t (*dyfunc)(mach_port_t, mach_port_t *) = NULL;
+       if (!dyfunc) {
+               void *image = __loadIOKit();
+               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+       }
+       return dyfunc ? dyfunc(bootstrapPort, masterPort) : KERN_FAILURE;
+}
+#define IOMasterPort _IOMasterPort
+
+
+static kern_return_t
+_IOObjectRelease(io_object_t object)
+{
+       static kern_return_t (*dyfunc)(io_object_t) = NULL;
+       if (!dyfunc) {
+               void *image = __loadIOKit();
+               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+       }
+       return dyfunc ? dyfunc(object) : KERN_FAILURE;
+}
+#define IOObjectRelease _IOObjectRelease
+
+
+static kern_return_t
+_IORegistryEntryCreateCFProperties(io_registry_entry_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, IOOptionBits options)
+{
+       static kern_return_t (*dyfunc)(io_registry_entry_t, CFMutableDictionaryRef *, CFAllocatorRef, IOOptionBits) = NULL;
+       if (!dyfunc) {
+               void *image = __loadIOKit();
+               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+       }
+       return dyfunc ? dyfunc(entry, properties, allocator, options) : KERN_FAILURE;
+}
+#define IORegistryEntryCreateCFProperties _IORegistryEntryCreateCFProperties
+
+
+static kern_return_t
+_IORegistryEntryGetPath(io_registry_entry_t entry, const io_name_t plane, io_string_t path)
+{
+       static kern_return_t (*dyfunc)(io_registry_entry_t, const io_name_t, io_string_t) = NULL;
+       if (!dyfunc) {
+               void *image = __loadIOKit();
+               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+       }
+       return dyfunc ? dyfunc(entry, plane, path) : KERN_FAILURE;
+}
+#define IORegistryEntryGetPath _IORegistryEntryGetPath
+
+
+static kern_return_t
+_IOServiceGetMatchingServices(mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t *existing)
+{
+       static kern_return_t (*dyfunc)(mach_port_t, CFDictionaryRef, io_iterator_t *) = NULL;
+       if (!dyfunc) {
+               void *image = __loadIOKit();
+               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+       }
+       return dyfunc ? dyfunc(masterPort, matching, existing) : KERN_FAILURE;
+}
+#define IOServiceGetMatchingServices _IOServiceGetMatchingServices
+
+
+static CFMutableDictionaryRef
+_IOServiceMatching(const char *name)
+{
+       static CFMutableDictionaryRef (*dyfunc)(const char *) = NULL;
+       if (!dyfunc) {
+               void *image = __loadIOKit();
+               if (image) dyfunc = NSAddressOfSymbol(NSLookupSymbolInImage(image, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND));
+       }
+       return dyfunc ? dyfunc(name) : NULL;
+}
+#define IOServiceMatching _IOServiceMatching
+
+
+typedef struct {
+
+       /* base CFType information */
+       CFRuntimeBase   cfBase;
+
+       /* device name (e.g. "modem") */
+       CFStringRef     name;
+
+       int             sock;
+
+} DeviceOnHoldPrivate, *DeviceOnHoldPrivateRef;
+
+
+static CFStringRef
+__DeviceOnHoldCopyDescription(CFTypeRef cf)
+{
+       CFAllocatorRef          allocator       = CFGetAllocator(cf);
+       CFMutableStringRef      result;
+
+       result = CFStringCreateMutable(allocator, 0);
+       CFStringAppendFormat(result, NULL, CFSTR("<DeviceOnHold %p [%p]> {\n"), cf, allocator);
+       CFStringAppendFormat(result, NULL, CFSTR("}"));
+
+       return result;
+}
+
+
+static void
+__DeviceOnHoldDeallocate(CFTypeRef cf)
+{
+       DeviceOnHoldPrivateRef  DeviceOnHoldPrivate     = (DeviceOnHoldPrivateRef)cf;
+
+       SCLog(_sc_verbose, LOG_DEBUG, CFSTR("__DeviceOnHoldDeallocate:"));
+
+       /* release resources */
+       if (DeviceOnHoldPrivate->name)          CFRelease(DeviceOnHoldPrivate->name);
+       if (DeviceOnHoldPrivate->sock != -1) {
+
+       }
+
+       return;
+}
+
+
+static CFTypeID __kDeviceOnHoldTypeID = _kCFRuntimeNotATypeID;
+
+
+static const CFRuntimeClass __DeviceOnHoldClass = {
+       0,                              // version
+       "DeviceOnHold",                 // className
+       NULL,                           // init
+       NULL,                           // copy
+       __DeviceOnHoldDeallocate,       // dealloc
+       NULL,                           // equal
+       NULL,                           // hash
+       NULL,                           // copyFormattingDesc
+       __DeviceOnHoldCopyDescription   // copyDebugDesc
+};
+
+
+static pthread_once_t initialized      = PTHREAD_ONCE_INIT;
+
+
+static void
+__DeviceOnHoldInitialize(void)
+{
+       __kDeviceOnHoldTypeID = _CFRuntimeRegisterClass(&__DeviceOnHoldClass);
+       return;
+}
+
+
+DeviceOnHoldRef
+__DeviceOnHoldCreatePrivate(CFAllocatorRef     allocator)
+{
+       DeviceOnHoldPrivateRef          devicePrivate;
+       UInt32                          size;
+
+       /* initialize runtime */
+       pthread_once(&initialized, __DeviceOnHoldInitialize);
+
+       /* allocate session */
+       size          = sizeof(DeviceOnHoldPrivate) - sizeof(CFRuntimeBase);
+       devicePrivate = (DeviceOnHoldPrivateRef)_CFRuntimeCreateInstance(allocator,
+                                                                        __kDeviceOnHoldTypeID,
+                                                                        size,
+                                                                        NULL);
+       if (!devicePrivate) {
+               return NULL;
+       }
+
+       devicePrivate->name     = NULL;
+       devicePrivate->sock     = -1;
+
+       return (DeviceOnHoldRef)devicePrivate;
+}
+
+
+/*
+ * TBD: We determine whether a device supports on hold capability by looking at
+ * the numeric property DeviceSupportsHold (1 - yes, 0 or no property - no). For
+ * the Apple Dash II internal modem we also use the property V92Modem to track
+ * this same capability.
+ */
+
+Boolean
+IsDeviceOnHoldSupported(CFStringRef    deviceName,     // "modem"
+                       CFDictionaryRef options)
+{
+       CFMutableDictionaryRef  deviceToMatch;
+       u_int32_t               deviceSupportsHoldValue;
+       kern_return_t           kr;
+       mach_port_t             masterPort;
+       io_iterator_t           matchingServices;
+       CFNumberRef             num;
+       CFMutableDictionaryRef  properties;
+       Boolean                 result                          = FALSE;
+       io_service_t            service;
+
+       if (CFStringCompare(deviceName, CFSTR("modem"), NULL) == kCFCompareEqualTo) {
+               kr = IOMasterPort(MACH_PORT_NULL, &masterPort);
+               if (kr != KERN_SUCCESS) {
+                       goto errorExit;
+               }
+
+               deviceToMatch = IOServiceMatching("InternalModemSupport");
+               if (!deviceToMatch) {
+                       goto errorExit;
+               }
+
+               kr = IOServiceGetMatchingServices(masterPort, deviceToMatch, &matchingServices);
+               if (kr != KERN_SUCCESS) {
+                       goto errorExit;
+               }
+
+               for ( ; service = IOIteratorNext(matchingServices) ; IOObjectRelease(service)) {
+                       io_string_t     path;
+
+                       kr = IORegistryEntryGetPath(service, kIOServicePlane, path);
+                       assert( kr == KERN_SUCCESS );
+
+                       // grab a copy of the properties
+                       kr = IORegistryEntryCreateCFProperties(service, &properties, kCFAllocatorDefault, kNilOptions);
+                       assert( kr == KERN_SUCCESS );
+
+                       num = CFDictionaryGetValue(properties, CFSTR(kIODeviceSupportsHoldKey));
+                       if (isA_CFNumber(num)) {
+                               CFNumberGetValue(num, kCFNumberSInt32Type, &deviceSupportsHoldValue);
+                               if (deviceSupportsHoldValue == 1) {
+                                       result = TRUE;
+                               }
+                       }
+
+                       CFRelease(properties);
+               }
+
+               IOObjectRelease(matchingServices);
+       }
+
+       // Note: The issue for the general case is how to go from the SystemConfiguration
+       //       dynamic store to the actual driver. The devicesupportshold property is not
+       //       copied the either of the setup/state descriptions so the caller would need
+       //       to know the exact driver they are searching for.
+
+       return result;
+
+    errorExit:
+
+       return FALSE;
+}
+
+
+DeviceOnHoldRef
+DeviceOnHoldCreate(CFAllocatorRef      allocator,
+                  CFStringRef          deviceName,     // "modem"
+                  CFDictionaryRef      options)
+{
+       DeviceOnHoldRef         device          = NULL;
+       DeviceOnHoldPrivateRef  devicePrivate;
+       int                     status;
+
+       if (CFStringCompare(deviceName, CFSTR("modem"), NULL) != kCFCompareEqualTo) {
+               return NULL;
+       }
+
+       device = __DeviceOnHoldCreatePrivate(allocator);
+       if (!device) {
+               return NULL;
+       }
+
+       devicePrivate = (DeviceOnHoldPrivateRef)device;
+
+       status = MOHInit(&devicePrivate->sock, deviceName);
+       if (status != 0) {
+               CFRelease(device);
+               return NULL;
+       }
+
+       devicePrivate->name = CFRetain(deviceName);
+
+       return device;
+}
+
+
+
+int32_t
+DeviceOnHoldGetStatus(DeviceOnHoldRef  device)
+{
+       DeviceOnHoldPrivateRef  devicePrivate   = (DeviceOnHoldPrivateRef)device;
+       int                     err;
+       u_long                  link            = 1;
+       void                    *replyBuf;
+       u_long                  replyBufLen;
+       int32_t                 result          = -1;
+
+       if (!device) {
+               return -1;
+       }
+
+       if (devicePrivate->sock == -1) {
+               return -1;
+       }
+
+       err = MOHExec(devicePrivate->sock,
+                     link,
+                     MOH_SESSION_GET_STATUS,
+                     NULL,
+                     0,
+                     &replyBuf,
+                     &replyBufLen);
+
+       if (err != 0) {
+               return -1;
+       }
+
+       if (replyBufLen == sizeof(result)) {
+               result = *(int32_t *)replyBuf;
+       }
+
+       if (replyBuf)   CFAllocatorDeallocate(NULL, replyBuf);
+       return result;
+}
+
+
+Boolean
+DeviceOnHoldSuspend(DeviceOnHoldRef    device)
+{
+       DeviceOnHoldPrivateRef  devicePrivate   = (DeviceOnHoldPrivateRef)device;
+       int                     err;
+       u_long                  link            = 1;
+       void                    *replyBuf;
+       u_long                  replyBufLen;
+       Boolean                 result          = FALSE;
+
+       if (!device) {
+               return FALSE;
+       }
+
+       if (devicePrivate->sock == -1) {
+               return FALSE;
+       }
+
+       err = MOHExec(devicePrivate->sock,
+                     link,
+                     MOH_PUT_SESSION_ON_HOLD,
+                     NULL,
+                     0,
+                     &replyBuf,
+                     &replyBufLen);
+
+       if (err != 0) {
+               return -1;
+       }
+
+       if (replyBufLen == sizeof(result)) {
+               result = (*(int32_t *)replyBuf) ? TRUE : FALSE;
+       }
+
+       if (replyBuf)   CFAllocatorDeallocate(NULL, replyBuf);
+       return result;
+}
+
+
+Boolean
+DeviceOnHoldResume(DeviceOnHoldRef     device)
+{
+       DeviceOnHoldPrivateRef  devicePrivate   = (DeviceOnHoldPrivateRef)device;
+       int                     err;
+       u_long                  link            = 1;
+       void                    *replyBuf;
+       u_long                  replyBufLen;
+       Boolean                 result          = FALSE;
+
+       if (!device) {
+               return FALSE;
+       }
+
+       if (devicePrivate->sock == -1) {
+               return FALSE;
+       }
+
+       err = MOHExec(devicePrivate->sock,
+                     link,
+                     MOH_RESUME_SESSION_ON_HOLD,NULL,
+                     0,
+                     &replyBuf,
+                     &replyBufLen);
+
+       if (err != 0) {
+               return -1;
+       }
+
+       if (replyBufLen == sizeof(result)) {
+               result = (*(int32_t *)replyBuf) ? TRUE : FALSE;
+       }
+
+       if (replyBuf)   CFAllocatorDeallocate(NULL, replyBuf);
+       return result;
+}
diff --git a/SystemConfiguration.fproj/DeviceOnHold.h b/SystemConfiguration.fproj/DeviceOnHold.h
new file mode 100644 (file)
index 0000000..effb404
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2002 Apple Computer, 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
+ * 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.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+
+#ifndef _DEVICEONHOLD_H
+#define _DEVICEONHOLD_H
+
+#include <sys/cdefs.h>
+#include <CoreFoundation/CoreFoundation.h>
+
+
+/*!
+       @enum
+       @discussion Returned status codes from DeviceOnHoldGetStatus()
+
+       @constant kDeviceIdle
+       @constant kDeviceConnecting
+       @constant kDeviceDataConnectionActive
+       @constant kDeviceDataConnectionOnHold
+       @constant kDeviceDisconnecting
+*/
+enum
+{
+       kDeviceIdle                     = 0,
+       kDeviceConnecting,
+       kDeviceDataConnectionActive,
+       kDeviceDataConnectionOnHold,
+       kDeviceDisconnecting
+};
+
+
+/*!
+       @typedef DeviceOnHoldRef
+       @discussion This is the handle to a specific device
+               which is used by the DeviceOnHold APIs.
+ */
+typedef const struct __DeviceOnHoldRef * DeviceOnHoldRef;
+
+
+__BEGIN_DECLS
+
+
+/*!
+       @function IsDeviceOnHoldSupported
+       @discussion Determines whether a device has the capability to have
+               a connection placed "on hold".
+
+       This function determines whether the device specified supports
+       the "on hold" capabality.
+
+       @param devname A CFStringRef that represents the device being queried.
+       @param options A CFDictionaryRef of various options for the device.
+       @result TRUE if device supports "on hold".
+
+ */
+Boolean
+IsDeviceOnHoldSupported                        (
+                                       CFStringRef             devname,     // e.g. "modem"
+                                       CFDictionaryRef         options
+                                       );
+
+/*!
+       @function DeviceOnHoldCreate
+       @discussion Creates a DeviceOnHoldRef for the specified device supports.
+
+       This function creates a DeviceOnHoldRef handle which will be used
+               in all subsequent calls to the "on hold" API's.
+
+       @param allocator A CFAllocatorRef.
+       @param devname A CFStringRef that represents the device being queried.
+       @param options A CFDictionaryRef of various options for the device.
+       @result DeviceOnHoldRef to pass to subsequent device hold api's.
+
+ */
+DeviceOnHoldRef
+DeviceOnHoldCreate                     (
+                                       CFAllocatorRef          allocator,
+                                       CFStringRef             devname,     // e.g. "modem"
+                                       CFDictionaryRef         options
+                                       );
+
+
+/*!
+       @function DeviceOnHoldGetStatus
+       @discussion Returns the "on hold" status of the device.
+
+       @param deviceRef A DeviceOnHoldRef.
+       @result The status of device.
+
+ */
+int32_t
+DeviceOnHoldGetStatus                  (
+                                       DeviceOnHoldRef         deviceRef
+                                       );
+
+
+/*!
+       @function DeviceOnHoldSuspend
+       @discussion Tells the device to go "on hold".
+
+       This function will signal the deviceRef to suspend operations
+
+       @param deviceRef A DeviceOnHoldRef.
+       @result Boolean if call succeeded.
+
+ */
+Boolean
+DeviceOnHoldSuspend                    (
+                                       DeviceOnHoldRef         deviceRef
+                                       );
+
+/*!
+       @function DeviceOnHoldResume
+       @discussion Tells the device to resume.
+
+       This function will signal the deviceRef to resume operations
+
+       @param deviceRef A DeviceOnHoldRef.
+       @result Boolean if call succeeded.
+
+ */
+Boolean
+DeviceOnHoldResume                     (
+                                       DeviceOnHoldRef         deviceRef
+                                       );
+
+__END_DECLS
+
+#endif /* _DEVICEONHOLD_H */
+
index 7235655b1fa92d4e07f3c04a7f0e1962c8f3fc12..d7fbd908cca3dd5d5196ca2c40d4baa795b576ab 100644 (file)
@@ -20,20 +20,21 @@ HFILES = SystemConfiguration.h SCPrivate.h SCDPlugin.h config_types.h\
          SCPreferencesPath.h SCPreferencesSetSpecific.h SCNetwork.h\
          SCValidation.h ppp_msg.h ppp.h v1Compatibility.h SCD.h\
          SCDKeys.h SCP.h SCPPath.h SCDConsoleUser.h SCDHostName.h\
-         DHCPClientPreferences.h SCDynamicStoreCopyDHCPInfo.h
-
-CFILES = SCD.c SCDKeys.c SCDPrivate.c SCDOpen.c SCDLock.c SCDUnlock.c\
-         SCDList.c SCDAdd.c SCDAddSession.c SCDGet.c SCDSet.c\
-         SCDRemove.c SCDTouch.c SCDNotify.c SCDNotifierSetKeys.c\
-         SCDNotifierList.c SCDNotifierAdd.c SCDNotifierRemove.c\
-         SCDNotifierGetChanges.c SCDNotifierWait.c\
+         DHCPClientPreferences.h SCDynamicStoreCopyDHCPInfo.h moh_msg.h\
+         moh.h DeviceOnHold.h
+
+CFILES = SCD.c SCDKeys.c SCDPrivate.c SCDPlugin.c SCDOpen.c SCDLock.c\
+         SCDUnlock.c SCDList.c SCDAdd.c SCDAddSession.c SCDGet.c\
+         SCDSet.c SCDRemove.c SCDTouch.c SCDNotify.c\
+         SCDNotifierSetKeys.c SCDNotifierList.c SCDNotifierAdd.c\
+         SCDNotifierRemove.c SCDNotifierGetChanges.c SCDNotifierWait.c\
          SCDNotifierInformViaCallback.c SCDNotifierInformViaMachPort.c\
          SCDNotifierInformViaFD.c SCDNotifierInformViaSignal.c\
          SCDNotifierCancel.c SCDSnapshot.c SCP.c SCPOpen.c SCPLock.c\
          SCPUnlock.c SCPList.c SCPGet.c SCPAdd.c SCPSet.c SCPRemove.c\
          SCPCommit.c SCPApply.c SCPPath.c SCDConsoleUser.c\
-         SCDHostName.c SCNetwork.c SCProxies.c ppp.c v1Compatibility.c\
-         DHCP.c
+         SCDHostName.c SCLocation.c SCNetwork.c SCProxies.c ppp.c\
+         v1Compatibility.c DHCP.c moh.c DeviceOnHold.c
 
 OTHERSRCS = Makefile.preamble Makefile Makefile.postamble m.template\
             h.template config.defs genSCPreferences.c CustomInfo.plist
@@ -52,22 +53,21 @@ DEBUG_LIBS = $(LIBS)
 PROF_LIBS = $(LIBS)
 
 
-NEXTSTEP_PB_CFLAGS = -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS
 FRAMEWORKS = -framework CoreFoundation
 PUBLIC_HEADERS = SystemConfiguration.h SCDynamicStore.h\
                  SCDynamicStoreKey.h SCDynamicStoreCopySpecific.h\
                  SCPreferences.h SCPreferencesPath.h\
-                 SCPreferencesSetSpecific.h SCNetwork.h
+                 SCPreferencesSetSpecific.h SCNetwork.h\
+                 DHCPClientPreferences.h SCDynamicStoreCopyDHCPInfo.h
 
-PROJECT_HEADERS = SystemConfiguration.h SCPrivate.h config_types.h\
-                  SCDynamicStoreInternal.h SCDynamicStore.h\
-                  SCDynamicStorePrivate.h SCDynamicStoreKey.h\
-                  SCDynamicStoreCopySpecific.h\
+PROJECT_HEADERS = SCPrivate.h config_types.h SCDynamicStoreInternal.h\
+                  SCDynamicStore.h SCDynamicStorePrivate.h\
+                  SCDynamicStoreKey.h SCDynamicStoreCopySpecific.h\
                   SCDynamicStoreSetSpecificPrivate.h\
                   SCPreferencesInternal.h SCPreferences.h\
                   SCPreferencesPrivate.h SCPreferencesPath.h\
                   SCPreferencesSetSpecific.h SCNetwork.h SCValidation.h\
-                  v1Compatibility.h
+                  SystemConfiguration.h v1Compatibility.h
 
 
 
index 575e099f4d65a5259404f14781baef2ef6fafde3..cb82712cb98a66304383ba137012c99f4d48f4ff 100644 (file)
@@ -119,4 +119,4 @@ genSCFiles:
        /tmp/genSCFiles cfile  > /tmp/SCSchemaDefinitions.c
 
 dhcp: DHCP.c
-       cc -Wall -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS -DTEST_DHCPCLIENT_PREFERENCES -g -o dhcp DHCP.c -framework CoreFoundation -framework SystemConfiguration
+       cc -Wall -DTEST_DHCPCLIENT_PREFERENCES -g -o dhcp DHCP.c -framework CoreFoundation -framework SystemConfiguration
index ac3fc04331e5ecf30e568bd1c7e254eb1452b643..feba1ec1f3c80cd659cac9ef0f3ec8dd940561ad 100644 (file)
@@ -137,7 +137,7 @@ OTHER_GENERATED_OFILES = $(VERS_OFILE)
 # DSTROOT = $(HOME)
 
 # Additional flags for MiG generated files
-OTHER_PROJECT_HEADERS += config.defs config.h
+OTHER_PRIVATE_HEADERS += config.defs config.h
 
 OTHER_PRIVATE_HEADERS += SCPrivate.h
 OTHER_PRIVATE_HEADERS += SCDynamicStorePrivate.h
@@ -145,8 +145,7 @@ OTHER_PRIVATE_HEADERS += SCDynamicStoreSetSpecificPrivate.h
 OTHER_PRIVATE_HEADERS += SCPreferencesPrivate.h
 OTHER_PRIVATE_HEADERS += SCValidation.h
 OTHER_PRIVATE_HEADERS += SCDPlugin.h
-OTHER_PRIVATE_HEADERS += SCDynamicStoreCopyDHCPInfo.h
-OTHER_PRIVATE_HEADERS += DHCPClientPreferences.h
+OTHER_PRIVATE_HEADERS += DeviceOnHold.h
 
 #  
 # XXX INSTALL V1 COMPATIBILITY HEADERS XXX
index 8c1c394946c8d1221f8c4b54bdf5618400461c30..4b815ad92d5217dc52523159650822cff3a6ee30 100644 (file)
             SCDConsoleUser.h, 
             SCDHostName.h, 
             DHCPClientPreferences.h, 
-            SCDynamicStoreCopyDHCPInfo.h
+            SCDynamicStoreCopyDHCPInfo.h, 
+            moh_msg.h, 
+            moh.h, 
+            DeviceOnHold.h
         ); 
         OTHER_LINKED = (
             SCD.c, 
             SCDKeys.c, 
             SCDPrivate.c, 
+            SCDPlugin.c, 
             SCDOpen.c, 
             SCDLock.c, 
             SCDUnlock.c, 
             SCPPath.c, 
             SCDConsoleUser.c, 
             SCDHostName.c, 
+            SCLocation.c, 
             SCNetwork.c, 
             SCProxies.c, 
             ppp.c, 
             v1Compatibility.c, 
-            DHCP.c
+            DHCP.c, 
+            moh.c, 
+            DeviceOnHold.c
         ); 
         OTHER_SOURCES = (
             Makefile.preamble, 
         ); 
         PRECOMPILED_HEADERS = (); 
         PROJECT_HEADERS = (
-            SystemConfiguration.h, 
             SCPrivate.h, 
             config_types.h, 
             SCDynamicStoreInternal.h, 
             SCPreferencesSetSpecific.h, 
             SCNetwork.h, 
             SCValidation.h, 
+            SystemConfiguration.h, 
             v1Compatibility.h
         ); 
         PUBLIC_HEADERS = (
             SCPreferences.h, 
             SCPreferencesPath.h, 
             SCPreferencesSetSpecific.h, 
-            SCNetwork.h
+            SCNetwork.h, 
+            DHCPClientPreferences.h, 
+            SCDynamicStoreCopyDHCPInfo.h
         ); 
         SUBPROJECTS = (); 
     }; 
     LANGUAGE = English; 
     MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; 
     NEXTSTEP_BUILDTOOL = /usr/bin/gnumake; 
-    NEXTSTEP_COMPILEROPTIONS = "-DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS"; 
     NEXTSTEP_INSTALLDIR = "$(SYSTEM_LIBRARY_DIR)/Frameworks"; 
     NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; 
     NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; 
index 4a480dc6a93b825f9a6ce068e8b16e615cbd0506..b4762110896e946e70d0558aa339b7ebfcb91ffa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -53,6 +53,7 @@ static const struct sc_errmsg {
        { kSCStatusInvalidArgument,     "Invalid argument" },
        { kSCStatusKeyExists,           "Key already defined" },
        { kSCStatusLocked,              "Lock already held" },
+       { kSCStatusMaxLink,             "Maximum link count exceeded" },
        { kSCStatusNeedLock,            "Lock required for this operation" },
        { kSCStatusNoStoreServer,       "Configuration daemon not (no longer) available" },
        { kSCStatusNoStoreSession,      "Configuration daemon session not active" },
@@ -84,7 +85,7 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions)
        CFTypeID                type    = CFGetTypeID(info);
 
        if (!formatOptions ||
-           !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX1"), (void **)&prefix1)) {
+           !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX1"), (const void **)&prefix1)) {
                prefix1 = CFSTR("");
        }
 
@@ -153,7 +154,7 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions)
        }
 
        if (!formatOptions ||
-           !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX2"), (void **)&prefix2)) {
+           !CFDictionaryGetValueIfPresent(formatOptions, CFSTR("PREFIX2"), (const void **)&prefix2)) {
                prefix2 = CFStringCreateCopy(NULL, prefix1);
        }
 
@@ -167,7 +168,7 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions)
        }
 
        if (type == CFArrayGetTypeID()) {
-               void                    **elements;
+               const void              **elements;
                CFIndex                 i;
                CFIndex                 nElements;
                CFMutableStringRef      str;
@@ -176,42 +177,44 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions)
                CFStringAppendFormat(str, formatOptions, CFSTR("%@<array> {"), prefix1);
 
                nElements = CFArrayGetCount(info);
-               elements  = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0);
-               CFArrayGetValues(info, CFRangeMake(0, nElements), elements);
-               for (i=0; i<nElements; i++) {
-                       CFMutableStringRef      nPrefix1;
-                       CFMutableStringRef      nPrefix2;
-                       CFStringRef             nStr;
-                       CFStringRef             vStr;
-
-                       nStr = CFStringCreateWithFormat(NULL, NULL, CFSTR("%u"), i);
-
-                       nPrefix1 = CFStringCreateMutable(NULL, 0);
-                       CFStringAppendFormat(nPrefix1,
-                                            formatOptions,
-                                            CFSTR("%@  %@ : "),
-                                            prefix2,
-                                            nStr);
-                       nPrefix2 = CFStringCreateMutable(NULL, 0);
-                       CFStringAppendFormat(nPrefix2,
-                                            formatOptions,
-                                            CFSTR("%@  "),
-                                            prefix2);
-
-                       CFDictionarySetValue(nFormatOptions, CFSTR("PREFIX1"), nPrefix1);
-                       CFDictionarySetValue(nFormatOptions, CFSTR("PREFIX2"), nPrefix2);
-                       CFRelease(nPrefix1);
-                       CFRelease(nPrefix2);
-                       CFRelease(nStr);
-
-                       vStr = _SCCopyDescription(elements[i], nFormatOptions);
-                       CFStringAppendFormat(str,
-                                            formatOptions,
-                                            CFSTR("\n%@"),
-                                            vStr);
-                       CFRelease(vStr);
+               if (nElements > 0) {
+                       elements  = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0);
+                       CFArrayGetValues(info, CFRangeMake(0, nElements), elements);
+                       for (i=0; i<nElements; i++) {
+                               CFMutableStringRef      nPrefix1;
+                               CFMutableStringRef      nPrefix2;
+                               CFStringRef             nStr;
+                               CFStringRef             vStr;
+
+                               nStr = CFStringCreateWithFormat(NULL, NULL, CFSTR("%u"), i);
+
+                               nPrefix1 = CFStringCreateMutable(NULL, 0);
+                               CFStringAppendFormat(nPrefix1,
+                                                    formatOptions,
+                                                    CFSTR("%@  %@ : "),
+                                                    prefix2,
+                                                    nStr);
+                               nPrefix2 = CFStringCreateMutable(NULL, 0);
+                               CFStringAppendFormat(nPrefix2,
+                                                    formatOptions,
+                                                    CFSTR("%@  "),
+                                                    prefix2);
+
+                               CFDictionarySetValue(nFormatOptions, CFSTR("PREFIX1"), nPrefix1);
+                               CFDictionarySetValue(nFormatOptions, CFSTR("PREFIX2"), nPrefix2);
+                               CFRelease(nPrefix1);
+                               CFRelease(nPrefix2);
+                               CFRelease(nStr);
+
+                               vStr = _SCCopyDescription((void *)elements[i], nFormatOptions);
+                               CFStringAppendFormat(str,
+                                                    formatOptions,
+                                                    CFSTR("\n%@"),
+                                                    vStr);
+                               CFRelease(vStr);
+                       }
+                       CFAllocatorDeallocate(NULL, elements);
                }
-               CFAllocatorDeallocate(NULL, elements);
                CFStringAppendFormat(str, formatOptions, CFSTR("\n%@}"), prefix2);
 
                CFRelease(nFormatOptions);
@@ -219,54 +222,56 @@ _SCCopyDescription(void *info, CFDictionaryRef formatOptions)
        }
 
        if (type == CFDictionaryGetTypeID()) {
-               void                    **keys;
+               const void              **keys;
                CFIndex                 i;
                CFIndex                 nElements;
                CFMutableStringRef      nPrefix1;
                CFMutableStringRef      nPrefix2;
                CFMutableStringRef      str;
-               void                    **values;
+               const void              **values;
 
                str = CFStringCreateMutable(NULL, 0);
                CFStringAppendFormat(str, formatOptions, CFSTR("%@<dictionary> {"), prefix1);
 
                nElements = CFDictionaryGetCount(info);
-               keys      = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0);
-               values    = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0);
-               CFDictionaryGetKeysAndValues(info, keys, values);
-               for (i=0; i<nElements; i++) {
-                       CFStringRef             kStr;
-                       CFStringRef             vStr;
-
-                       kStr = _SCCopyDescription(keys[i], NULL);
-
-                       nPrefix1 = CFStringCreateMutable(NULL, 0);
-                       CFStringAppendFormat(nPrefix1,
-                                            formatOptions,
-                                            CFSTR("%@  %@ : "),
-                                            prefix2,
-                                            kStr);
-                       nPrefix2 = CFStringCreateMutable(NULL, 0);
-                       CFStringAppendFormat(nPrefix2,
-                                            formatOptions,
-                                            CFSTR("%@  "),
-                                            prefix2);
-
-                       CFDictionarySetValue(nFormatOptions, CFSTR("PREFIX1"), nPrefix1);
-                       CFDictionarySetValue(nFormatOptions, CFSTR("PREFIX2"), nPrefix2);
-                       CFRelease(nPrefix1);
-                       CFRelease(nPrefix2);
-                       CFRelease(kStr);
-
-                       vStr = _SCCopyDescription(values[i], nFormatOptions);
-                       CFStringAppendFormat(str,
-                                            formatOptions,
-                                            CFSTR("\n%@"),
-                                            vStr);
-                       CFRelease(vStr);
+               if (nElements > 0) {
+                       keys   = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0);
+                       values = CFAllocatorAllocate(NULL, nElements * sizeof(CFTypeRef), 0);
+                       CFDictionaryGetKeysAndValues(info, keys, values);
+                       for (i=0; i<nElements; i++) {
+                               CFStringRef             kStr;
+                               CFStringRef             vStr;
+
+                               kStr = _SCCopyDescription((void *)keys[i], NULL);
+
+                               nPrefix1 = CFStringCreateMutable(NULL, 0);
+                               CFStringAppendFormat(nPrefix1,
+                                                    formatOptions,
+                                                    CFSTR("%@  %@ : "),
+                                                    prefix2,
+                                                    kStr);
+                               nPrefix2 = CFStringCreateMutable(NULL, 0);
+                               CFStringAppendFormat(nPrefix2,
+                                                    formatOptions,
+                                                    CFSTR("%@  "),
+                                                    prefix2);
+
+                               CFDictionarySetValue(nFormatOptions, CFSTR("PREFIX1"), nPrefix1);
+                               CFDictionarySetValue(nFormatOptions, CFSTR("PREFIX2"), nPrefix2);
+                               CFRelease(nPrefix1);
+                               CFRelease(nPrefix2);
+                               CFRelease(kStr);
+
+                               vStr = _SCCopyDescription((void *)values[i], nFormatOptions);
+                               CFStringAppendFormat(str,
+                                                    formatOptions,
+                                                    CFSTR("\n%@"),
+                                                    vStr);
+                               CFRelease(vStr);
+                       }
+                       CFAllocatorDeallocate(NULL, keys);
+                       CFAllocatorDeallocate(NULL, values);
                }
-               CFAllocatorDeallocate(NULL, keys);
-               CFAllocatorDeallocate(NULL, values);
                CFStringAppendFormat(str, formatOptions, CFSTR("\n%@}"), prefix2);
 
                CFRelease(nFormatOptions);
index c1e5cc3d0c54b41cdf79feac7c28676183f4f514..2c3281273d01fff4fa2b47bbb1f966fc31f7d525 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -68,14 +68,18 @@ SCDynamicStoreAddValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListR
                return FALSE;
        }
 
-       /* serialize the key and data */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+       /* serialize the key */
+       if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
 
-       xmlData = CFPropertyListCreateXMLData(NULL, value);
-       myDataRef = (xmlData_t)CFDataGetBytePtr(xmlData);
-       myDataLen = CFDataGetLength(xmlData);
+       /* serialize the data */
+       if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) {
+               CFRelease(xmlKey);
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
 
        /* send the key & data to the server */
        status = configadd(storePrivate->server,
index d470876c4fae3725f40ebb762c4ed39240956b75..897f67f2fb5b77c8f64ed6cabe1e305c002bb5f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -68,14 +68,18 @@ SCDynamicStoreAddTemporaryValue(SCDynamicStoreRef store, CFStringRef key, CFProp
                return FALSE;
        }
 
-       /* serialize the key and data */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+       /* serialize the key */
+       if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
 
-       xmlData = CFPropertyListCreateXMLData(NULL, value);
-       myDataRef = (xmlData_t)CFDataGetBytePtr(xmlData);
-       myDataLen = CFDataGetLength(xmlData);
+       /* serialize the data */
+       if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) {
+               CFRelease(xmlKey);
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
 
        /* send the key & data to the server */
        status = configadd_s(storePrivate->server,
index 900db519c82baf000154af18b9d39500ceabde1b..1eb518a44d707a30f63ffeb3d7f7b8d91b57aadf 100644 (file)
@@ -31,8 +31,8 @@
  */
 
 #include <SystemConfiguration/SystemConfiguration.h>
-#include <SystemConfiguration/SCPrivate.h>
 #include <SystemConfiguration/SCValidation.h>
+#include <SystemConfiguration/SCPrivate.h>
 
 CFStringRef
 SCDynamicStoreKeyCreateConsoleUser(CFAllocatorRef allocator)
@@ -53,21 +53,22 @@ SCDynamicStoreCopyConsoleUser(SCDynamicStoreRef     store,
        CFStringRef             consoleUser     = NULL;
        CFDictionaryRef         dict            = NULL;
        CFStringRef             key;
-       SCDynamicStoreRef       mySession       = store;
+       Boolean                 tempSession     = FALSE;
 
        if (!store) {
-               mySession = SCDynamicStoreCreate(NULL,
-                                                CFSTR("SCDynamicStoreCopyConsoleUser"),
-                                                NULL,
-                                                NULL);
-               if (!mySession) {
+               store = SCDynamicStoreCreate(NULL,
+                                            CFSTR("SCDynamicStoreCopyConsoleUser"),
+                                            NULL,
+                                            NULL);
+               if (!store) {
                        SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed"));
                        return NULL;
                }
+               tempSession = TRUE;
        }
 
        key  = SCDynamicStoreKeyCreateConsoleUser(NULL);
-       dict = SCDynamicStoreCopyValue(mySession, key);
+       dict = SCDynamicStoreCopyValue(store, key);
        CFRelease(key);
        if (!isA_CFDictionary(dict)) {
                _SCErrorSet(kSCStatusNoKey);
@@ -109,8 +110,8 @@ SCDynamicStoreCopyConsoleUser(SCDynamicStoreRef     store,
 
     done :
 
-       if (!store && mySession)        CFRelease(mySession);
-       if (dict)                       CFRelease(dict);
+       if (tempSession)        CFRelease(store);
+       if (dict)               CFRelease(dict);
        return consoleUser;
 
 }
@@ -125,23 +126,24 @@ SCDynamicStoreSetConsoleUser(SCDynamicStoreRef    store,
        CFStringRef             consoleUser;
        CFMutableDictionaryRef  dict            = NULL;
        CFStringRef             key             = SCDynamicStoreKeyCreateConsoleUser(NULL);
-       SCDynamicStoreRef       mySession       = store;
        CFNumberRef             num;
        Boolean                 ok              = TRUE;
+       Boolean                 tempSession     = FALSE;
 
        if (!store) {
-               mySession = SCDynamicStoreCreate(NULL,
-                                                CFSTR("SCDynamicStoreSetConsoleUser"),
-                                                NULL,
-                                                NULL);
-               if (!mySession) {
+               store = SCDynamicStoreCreate(NULL,
+                                            CFSTR("SCDynamicStoreSetConsoleUser"),
+                                            NULL,
+                                            NULL);
+               if (!store) {
                        SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed"));
                        return FALSE;
                }
+               tempSession = TRUE;
        }
 
        if (user == NULL) {
-               ok = SCDynamicStoreRemoveValue(mySession, key);
+               ok = SCDynamicStoreRemoveValue(store, key);
                goto done;
        }
 
@@ -162,12 +164,12 @@ SCDynamicStoreSetConsoleUser(SCDynamicStoreRef    store,
        CFDictionarySetValue(dict, kSCPropUsersConsoleUserGID, num);
        CFRelease(num);
 
-       ok = SCDynamicStoreSetValue(mySession, key, dict);
+       ok = SCDynamicStoreSetValue(store, key, dict);
 
     done :
 
-       if (dict)                       CFRelease(dict);
-       if (key)                        CFRelease(key);
-       if (!store && mySession)        CFRelease(mySession);
+       if (dict)               CFRelease(dict);
+       if (key)                CFRelease(key);
+       if (tempSession)        CFRelease(store);
        return ok;
 }
index 7cccb61e36fc18072b48d773aa195aed4320d66e..299fd00646431fd57541dcb203f75f20c4b460ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -54,10 +54,8 @@ SCDynamicStoreCopyMultiple(SCDynamicStoreRef store,
        CFIndex                         myPatternsLen   = 0;
        xmlDataOut_t                    xmlDictRef;             /* dict (serialized) */
        CFIndex                         xmlDictLen;
-       CFDataRef                       xmlDict;                /* dict (XML serialized) */
-       CFDictionaryRef                 dict;                   /* dict (un-serialized) */
+       CFDictionaryRef                 dict            = NULL; /* dict (un-serialized) */
        int                             sc_status;
-       CFStringRef                     xmlError;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyMultiple:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  keys     = %@"), keys);
@@ -76,16 +74,19 @@ SCDynamicStoreCopyMultiple(SCDynamicStoreRef        store,
 
        /* serialize the keys */
        if (keys) {
-               xmlKeys = CFPropertyListCreateXMLData(NULL, keys);
-               myKeysRef = (xmlData_t)CFDataGetBytePtr(xmlKeys);
-               myKeysLen = CFDataGetLength(xmlKeys);
+               if (!_SCSerialize(keys, &xmlKeys, (void **)&myKeysRef, &myKeysLen)) {
+                       _SCErrorSet(kSCStatusFailed);
+                       return NULL;
+               }
        }
 
        /* serialize the patterns */
        if (patterns) {
-               xmlPatterns = CFPropertyListCreateXMLData(NULL, patterns);
-               myPatternsRef = (xmlData_t)CFDataGetBytePtr(xmlPatterns);
-               myPatternsLen = CFDataGetLength(xmlPatterns);
+               if (!_SCSerialize(patterns, &xmlPatterns, (void **)&myPatternsRef, &myPatternsLen)) {
+                       CFRelease(xmlKeys);
+                       _SCErrorSet(kSCStatusFailed);
+                       return NULL;
+               }
        }
 
        /* send the keys and patterns, fetch the associated result from the server */
@@ -121,25 +122,8 @@ SCDynamicStoreCopyMultiple(SCDynamicStoreRef       store,
                return NULL;
        }
 
-       /* un-serialize the dict, return a value associated with the key */
-       xmlDict = CFDataCreate(NULL, xmlDictRef, xmlDictLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)xmlDictRef, xmlDictLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       dict = CFPropertyListCreateFromXMLData(NULL,
-                                              xmlDict,
-                                              kCFPropertyListImmutable,
-                                              &xmlError);
-       CFRelease(xmlDict);
-       if (!dict) {
-               if (xmlError) {
-                       SCLog(_sc_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() dict: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       /* un-serialize the dictionary */
+       if (!_SCUnserialize((CFPropertyListRef *)&dict, xmlDictRef, xmlDictLen)) {
                _SCErrorSet(kSCStatusFailed);
                return NULL;
        }
@@ -160,11 +144,9 @@ SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key)
        CFIndex                         myKeyLen;
        xmlDataOut_t                    xmlDataRef;     /* data (serialized) */
        CFIndex                         xmlDataLen;
-       CFDataRef                       xmlData;        /* data (XML serialized) */
        CFPropertyListRef               data;           /* data (un-serialized) */
        int                             newInstance;
        int                             sc_status;
-       CFStringRef                     xmlError;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyValue:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  key      = %@"), key);
@@ -181,9 +163,10 @@ SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key)
        }
 
        /* serialize the key */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+       if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return NULL;
+       }
 
        /* send the key & fetch the associated data from the server */
        status = configget(storePrivate->server,
@@ -216,25 +199,8 @@ SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key)
                return NULL;
        }
 
-       /* un-serialize the data, return a value associated with the key */
-       xmlData = CFDataCreate(NULL, xmlDataRef, xmlDataLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       data = CFPropertyListCreateFromXMLData(NULL,
-                                              xmlData,
-                                              kCFPropertyListImmutable,
-                                              &xmlError);
-       CFRelease(xmlData);
-       if (!data) {
-               if (xmlError) {
-                       SCLog(_sc_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() data: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       /* un-serialize the data */
+       if (!_SCUnserialize(&data, xmlDataRef, xmlDataLen)) {
                _SCErrorSet(kSCStatusFailed);
                return NULL;
        }
index b4ad8264495278d244d77a58e082052069ba9225..23ec5d432131dd633111814c5d46e9e0c55b18e3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -51,21 +51,22 @@ SCDynamicStoreCopyComputerName(SCDynamicStoreRef    store,
        CFDictionaryRef         dict            = NULL;
        CFStringRef             key;
        CFStringRef             name            = NULL;
-       SCDynamicStoreRef       mySession       = store;
+       Boolean                 tempSession     = FALSE;
 
        if (!store) {
-               mySession = SCDynamicStoreCreate(NULL,
-                                                CFSTR("SCDynamicStoreCopyComputerName"),
-                                                NULL,
-                                                NULL);
-               if (!mySession) {
+               store = SCDynamicStoreCreate(NULL,
+                                            CFSTR("SCDynamicStoreCopyComputerName"),
+                                            NULL,
+                                            NULL);
+               if (!store) {
                        SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed"));
                        return NULL;
                }
+               tempSession = TRUE;
        }
 
        key  = SCDynamicStoreKeyCreateComputerName(NULL);
-       dict = SCDynamicStoreCopyValue(mySession, key);
+       dict = SCDynamicStoreCopyValue(store, key);
        CFRelease(key);
        if (!dict) {
                goto done;
@@ -96,8 +97,8 @@ SCDynamicStoreCopyComputerName(SCDynamicStoreRef      store,
 
     done :
 
-       if (!store && mySession)        CFRelease(mySession);
-       if (dict)                       CFRelease(dict);
+       if (tempSession)        CFRelease(store);
+       if (dict)               CFRelease(dict);
        return name;
 }
 
@@ -113,7 +114,7 @@ SCPreferencesSetComputerName(SCPreferencesRef       session,
        Boolean                 ok      = FALSE;
        CFStringRef             path    = NULL;
 
-       if (CFGetTypeID(name) != CFStringGetTypeID()) {
+       if (!isA_CFString(name)) {
                _SCErrorSet(kSCStatusInvalidArgument);
                return FALSE;
        }
@@ -150,3 +151,204 @@ SCPreferencesSetComputerName(SCPreferencesRef     session,
 
        return ok;
 }
+
+
+CFStringRef
+SCDynamicStoreKeyCreateHostNames(CFAllocatorRef allocator)
+{
+       return SCDynamicStoreKeyCreate(allocator,
+                                      CFSTR("%@/%@/%@"),
+                                      kSCDynamicStoreDomainSetup,
+                                      kSCCompNetwork,
+                                      kSCCompHostNames);
+}
+
+
+CFStringRef
+SCDynamicStoreCopyLocalHostName(SCDynamicStoreRef store)
+{
+       CFDictionaryRef         dict            = NULL;
+       CFStringRef             key;
+       CFStringRef             name            = NULL;
+       Boolean                 tempSession     = FALSE;
+
+       if (!store) {
+               store = SCDynamicStoreCreate(NULL,
+                                            CFSTR("SCDynamicStoreCopyLocalHostName"),
+                                            NULL,
+                                            NULL);
+               if (!store) {
+                       SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed"));
+                       return NULL;
+               }
+               tempSession = TRUE;
+       }
+
+       key  = SCDynamicStoreKeyCreateHostNames(NULL);
+       dict = SCDynamicStoreCopyValue(store, key);
+       CFRelease(key);
+       if (!dict) {
+               goto done;
+       }
+       if (!isA_CFDictionary(dict)) {
+               _SCErrorSet(kSCStatusNoKey);
+               goto done;
+       }
+
+       name = isA_CFString(CFDictionaryGetValue(dict, kSCPropNetLocalHostName));
+       if (!name) {
+               _SCErrorSet(kSCStatusNoKey);
+               goto done;
+       }
+       CFRetain(name);
+
+    done :
+
+       if (tempSession)        CFRelease(store);
+       if (dict)               CFRelease(dict);
+       return name;
+}
+
+
+Boolean
+_SC_stringIsValidDNSName(const char *name)
+{
+       int             i;
+       int             len     = strlen(name);
+       char            prev    = '\0';
+       const char      *scan;
+
+       if (len == 0) {
+               return FALSE;
+       }
+
+       for (scan = name, i = 0; i < len; i++, scan++) {
+               char    ch      = *scan;
+               char    next    = *(scan + 1);
+
+               if (prev == '.' || prev == '\0') {
+                       if (isalpha(ch) == 0) {
+                               return FALSE;
+                       }
+               } else if (next == '\0' || next == '.') {
+                       if (isalnum(ch) == 0) {
+                               return FALSE;
+                       }
+               } else if (isalnum(ch) == 0) {
+                       switch (ch) {
+                               case '.':
+                               case '-':
+                                       if (prev == '.' || prev == '-') {
+                                               return FALSE;
+                                       }
+                                       break;
+                               default:
+                                       return FALSE;
+                                       break;
+                       }
+               }
+               prev = ch;
+       }
+
+       return TRUE;
+}
+
+Boolean
+_SC_CFStringIsValidDNSName(CFStringRef name)
+{
+       Boolean clean   = FALSE;
+       CFIndex len;
+       char    *str    = NULL;
+
+       if (!isA_CFString(name)) {
+               goto failed;
+       }
+
+       len = CFStringGetLength(name) + 1;
+       if (len == 0) {
+               goto failed;
+       }
+
+       str = CFAllocatorAllocate(NULL, len, 0);
+       if (str == NULL) {
+               goto failed;
+       }
+
+       if (!CFStringGetCString(name, str, len, kCFStringEncodingASCII)) {
+               goto failed;
+       }
+
+       clean = _SC_stringIsValidDNSName(str);
+
+    failed:
+
+       if (str)        CFAllocatorDeallocate(NULL, str);
+       return clean;
+}
+
+
+Boolean
+SCPreferencesSetLocalHostName(SCPreferencesRef session,
+                            CFStringRef        name)
+{
+       CFDictionaryRef         dict;
+       CFMutableDictionaryRef  newDict = NULL;
+       Boolean                 ok      = FALSE;
+       CFStringRef             path    = NULL;
+
+       if (name) {
+               if (!isA_CFString(name)) {
+                       _SCErrorSet(kSCStatusInvalidArgument);
+                       return FALSE;
+               }
+
+               if (CFStringGetLength(name) == 0) {
+                       name = NULL;
+               }
+       }
+
+       if (name && !_SC_CFStringIsValidDNSName(name)) {
+               _SCErrorSet(kSCStatusInvalidArgument);
+               return FALSE;
+       }
+
+       path = CFStringCreateWithFormat(NULL,
+                                       NULL,
+                                       CFSTR("/%@/%@/%@"),
+                                       kSCPrefSystem,
+                                       kSCCompNetwork,
+                                       kSCCompHostNames);
+
+       dict = SCPreferencesPathGetValue(session, path);
+       if (dict) {
+               newDict = CFDictionaryCreateMutableCopy(NULL, 0, dict);
+       } else {
+               newDict = CFDictionaryCreateMutable(NULL,
+                                                   0,
+                                                   &kCFTypeDictionaryKeyCallBacks,
+                                                   &kCFTypeDictionaryValueCallBacks);
+       }
+
+       if (name) {
+               CFDictionarySetValue(newDict, kSCPropNetLocalHostName, name);
+       } else {
+               CFDictionaryRemoveValue(newDict, kSCPropNetLocalHostName);
+       }
+
+       if (CFDictionaryGetCount(newDict) > 0) {
+               ok = SCPreferencesPathSetValue(session, path, newDict);
+               if (!ok) {
+                       SCLog(_sc_verbose, LOG_ERR, CFSTR("SCPreferencesPathSetValue() failed"));
+               }
+       } else {
+               ok = SCPreferencesPathRemoveValue(session, path);
+               if (!ok) {
+                       SCLog(_sc_verbose, LOG_ERR, CFSTR("SCPreferencesPathRemoveValue() failed"));
+               }
+       }
+
+       if (path)       CFRelease(path);
+       if (newDict)    CFRelease(newDict);
+
+       return ok;
+}
index 85055cd38e3ed46cebcdf84ff0ca49024ded8240..e21798b99d4946ab9c4682be63c9ffb152441db5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -46,12 +46,10 @@ SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef pattern)
        CFDataRef                       xmlPattern;     /* serialized pattern */
        xmlData_t                       myPatternRef;
        CFIndex                         myPatternLen;
-       CFDataRef                       xmlData;        /* data (XML serialized) */
        xmlDataOut_t                    xmlDataRef;     /* serialized data */
        int                             xmlDataLen;
        int                             sc_status;
        CFArrayRef                      allKeys;
-       CFStringRef                     xmlError;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyKeyList:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  pattern = %@"), pattern);
@@ -68,9 +66,10 @@ SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef pattern)
        }
 
        /* serialize the pattern */
-       xmlPattern = CFPropertyListCreateXMLData(NULL, pattern);
-       myPatternRef = (xmlData_t)CFDataGetBytePtr(xmlPattern);
-       myPatternLen = CFDataGetLength(xmlPattern);
+       if (!_SCSerialize(pattern, &xmlPattern, (void **)&myPatternRef, &myPatternLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return NULL;
+       }
 
        /* send the pattern & fetch the associated data from the server */
        status = configlist(storePrivate->server,
@@ -104,24 +103,7 @@ SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef pattern)
        }
 
        /* un-serialize the list of keys */
-       xmlData = CFDataCreate(NULL, xmlDataRef, xmlDataLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       allKeys = CFPropertyListCreateFromXMLData(NULL,
-                                                 xmlData,
-                                                 kCFPropertyListImmutable,
-                                                 &xmlError);
-       CFRelease(xmlData);
-       if (!allKeys) {
-               if (xmlError) {
-                       SCLog(_sc_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() list: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&allKeys, xmlDataRef, xmlDataLen)) {
                _SCErrorSet(kSCStatusFailed);
                return NULL;
        }
index 392ca2748d7491e81f21bcd7d31d0752b8889085..3a8cd55eb48ed770c9b6629b6b5d2befdc67dc74 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -84,11 +84,12 @@ SCDynamicStoreAddWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean is
        }
 
        /* serialize the key */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+       if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
 
-       /* send the key & data to the server */
+       /* send the key to the server */
        status = notifyadd(storePrivate->server,
                           myKeyRef,
                           myKeyLen,
index e1a236b35dee651432df89b8f3de4c636c178bd7..890b089f2af42326e553f446c6788094b25f7c99 100644 (file)
@@ -64,9 +64,8 @@ SCDynamicStoreNotifyCancel(SCDynamicStoreRef store)
                        /* if no notifications have been registered */
                        return TRUE;
                case Using_NotifierInformViaRunLoop :
-                       /* once activated, a RunLoop notifier cannot be cancelled */
-                       _SCErrorSet(kSCStatusNotifierActive);
-                       return FALSE;
+                       CFRunLoopSourceInvalidate(storePrivate->rls);
+                       return TRUE;
                case Using_NotifierInformViaCallback :
                        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  cancel callback runloop source"));
 
index 71ecfb24d91242ea8a04e7dfbe84069c467f3a32..f139ee13c093379b756916210e297c424c4f0e6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -43,12 +43,10 @@ SCDynamicStoreCopyNotifiedKeys(SCDynamicStoreRef store)
 {
        SCDynamicStorePrivateRef        storePrivate = (SCDynamicStorePrivateRef)store;
        kern_return_t                   status;
-       CFDataRef                       xmlData;        /* data (XML serialized) */
        xmlDataOut_t                    xmlDataRef;     /* serialized data */
        int                             xmlDataLen;
        int                             sc_status;
        CFArrayRef                      allKeys;
-       CFStringRef                     xmlError;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyNotifiedKeys:"));
 
@@ -89,24 +87,7 @@ SCDynamicStoreCopyNotifiedKeys(SCDynamicStoreRef store)
        }
 
        /* un-serialize the list of keys which have changed */
-       xmlData = CFDataCreate(NULL, xmlDataRef, xmlDataLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       allKeys = CFPropertyListCreateFromXMLData(NULL,
-                                                 xmlData,
-                                                 kCFPropertyListImmutable,
-                                                 &xmlError);
-       CFRelease(xmlData);
-       if (!allKeys) {
-               if (xmlError) {
-                       SCLog(_sc_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() list: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&allKeys, xmlDataRef, xmlDataLen)) {
                _SCErrorSet(kSCStatusFailed);
                return NULL;
        }
index 9b1cf56f3ad09c5cccd073aee3812249b7988ab7..2a4385eaadc0240dca99c4c00e97aaa64aa6882b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -107,7 +107,12 @@ SCDynamicStoreNotifyCallback(SCDynamicStoreRef             store,
        mach_port_t                     port;
        mach_port_t                     oldNotify;
        int                             sc_status;
-       CFMachPortContext               context = { 0, (void *)store, NULL, NULL, NULL };
+       CFMachPortContext               context = { 0
+                                                 , (void *)store
+                                                 , CFRetain
+                                                 , CFRelease
+                                                 , NULL
+                                                 };
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreNotifyCallback:"));
 
@@ -217,10 +222,12 @@ rlsCallback(CFMachPortRef port, void *msg, CFIndex size, void *info)
                /* remove the run loop source(s) */
                CFRunLoopSourceInvalidate(storePrivate->callbackRunLoopSource);
                CFRelease(storePrivate->callbackRunLoopSource);
+               storePrivate->callbackRunLoopSource = NULL;
 
                /* invalidate port */
                CFMachPortInvalidate(storePrivate->callbackPort);
                CFRelease(storePrivate->callbackPort);
+               storePrivate->callbackPort = NULL;
 
                return;
        }
@@ -231,6 +238,16 @@ rlsCallback(CFMachPortRef port, void *msg, CFIndex size, void *info)
 }
 
 
+static void
+rlsPortInvalidate(CFMachPortRef mp, void *info) {
+       mach_port_t     port    = CFMachPortGetPort(mp);
+
+       // A simple deallocate won't get rid of all the references we've accumulated
+       SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  invalidate = %d"), port);
+       mach_port_destroy(mach_task_self(), port);
+}
+
+
 static void
 rlsSchedule(void *info, CFRunLoopRef rl, CFStringRef mode)
 {
@@ -240,7 +257,12 @@ rlsSchedule(void *info, CFRunLoopRef rl, CFStringRef mode)
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("schedule notifications for mode %@"), mode);
 
        if (storePrivate->rlsRefs++ == 0) {
-               CFMachPortContext       context = { 0, (void *)store, NULL, NULL, NULL };
+               CFMachPortContext       context = { 0
+                                                 , (void *)store
+                                                 , CFRetain
+                                                 , CFRelease
+                                                 , NULL
+                                                 };
                mach_port_t             oldNotify;
                mach_port_t             port;
                int                     sc_status;
@@ -296,6 +318,7 @@ rlsSchedule(void *info, CFRunLoopRef rl, CFStringRef mode)
                }
 
                storePrivate->callbackPort = CFMachPortCreateWithPort(NULL, port, rlsCallback, &context, NULL);
+               CFMachPortSetInvalidationCallBack(storePrivate->callbackPort, rlsPortInvalidate);
                storePrivate->callbackRunLoopSource = CFMachPortCreateRunLoopSource(NULL, storePrivate->callbackPort, 0);
        }
 
@@ -313,6 +336,7 @@ rlsCancel(void *info, CFRunLoopRef rl, CFStringRef mode)
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("cancel notifications for mode %@"), mode);
 
        CFRunLoopRemoveSource(rl, storePrivate->callbackRunLoopSource, mode);
+
        if (--storePrivate->rlsRefs == 0) {
                int             sc_status;
                kern_return_t   status;
@@ -321,10 +345,12 @@ rlsCancel(void *info, CFRunLoopRef rl, CFStringRef mode)
 
                /* remove the run loop source */
                CFRelease(storePrivate->callbackRunLoopSource);
+               storePrivate->callbackRunLoopSource = NULL;
 
                /* invalidate port */
                CFMachPortInvalidate(storePrivate->callbackPort);
                CFRelease(storePrivate->callbackPort);
+               storePrivate->callbackPort = NULL;
 
                status = notifycancel(storePrivate->server, (int *)&sc_status);
                if (status != KERN_SUCCESS) {
@@ -351,6 +377,11 @@ rlsPerform(void *info)
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  executing notifiction function"));
 
        changedKeys = SCDynamicStoreCopyNotifiedKeys(store);
+       if (!changedKeys) {
+               /* something happened to the server */
+               return;
+       }
+
        rlsFunction = storePrivate->rlsFunction;
 
        if (NULL != storePrivate->rlsContext.retain) {
@@ -360,7 +391,7 @@ rlsPerform(void *info)
                context_info    = storePrivate->rlsContext.info;
                context_release = NULL;
        }
-       (*rlsFunction)(store, changedKeys, storePrivate->rlsContext.info);
+       (*rlsFunction)(store, changedKeys, context_info);
        if (context_release) {
                context_release(context_info);
        }
@@ -370,12 +401,45 @@ rlsPerform(void *info)
 }
 
 
+static CFTypeRef
+rlsRetain(CFTypeRef cf)
+{
+       SCDynamicStoreRef               store           = (SCDynamicStoreRef)cf;
+       SCDynamicStorePrivateRef        storePrivate    = (SCDynamicStorePrivateRef)store;
+
+       if (storePrivate->notifyStatus != Using_NotifierInformViaRunLoop) {
+               /* mark RLS active */
+               storePrivate->notifyStatus = Using_NotifierInformViaRunLoop;
+               /* keep a reference to the store */
+               CFRetain(store);
+       }
+
+       return cf;
+}
+
+static void
+rlsRelease(CFTypeRef cf)
+{
+       SCDynamicStoreRef               store           = (SCDynamicStoreRef)cf;
+       SCDynamicStorePrivateRef        storePrivate    = (SCDynamicStorePrivateRef)store;
+
+       /* mark RLS inactive */
+       storePrivate->notifyStatus = NotifierNotRegistered;
+       storePrivate->rls = NULL;
+
+       /* release our reference to the store */
+       CFRelease(store);
+
+       return;
+}
+
+
 CFRunLoopSourceRef
 SCDynamicStoreCreateRunLoopSource(CFAllocatorRef       allocator,
                                  SCDynamicStoreRef     store,
                                  CFIndex               order)
 {
-       SCDynamicStorePrivateRef        storePrivate = (SCDynamicStorePrivateRef)store;
+       SCDynamicStorePrivateRef        storePrivate    = (SCDynamicStorePrivateRef)store;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCreateRunLoopSource:"));
 
@@ -394,8 +458,7 @@ SCDynamicStoreCreateRunLoopSource(CFAllocatorRef    allocator,
        switch (storePrivate->notifyStatus) {
                case NotifierNotRegistered :
                case Using_NotifierInformViaRunLoop :
-                       /* set notifier active */
-                       storePrivate->notifyStatus = Using_NotifierInformViaRunLoop;
+                       /* OK to enable runloop notification */
                        break;
                default :
                        /* sorry, you can only have one notification registered at once */
@@ -403,23 +466,28 @@ SCDynamicStoreCreateRunLoopSource(CFAllocatorRef  allocator,
                        return NULL;
        }
 
-       if (!storePrivate->rls) {
-               CFRunLoopSourceContext context;
-
-               context.version         = 0;
-               context.info            = (void *)store;
-               context.retain          = (const void *(*)(const void *))CFRetain;
-               context.release         = (void (*)(const void *))CFRelease;
-               context.copyDescription = (CFStringRef (*)(const void *))CFCopyDescription;
-               context.equal           = (Boolean (*)(const void *, const void *))CFEqual;
-               context.hash            = (CFHashCode (*)(const void *))CFHash;
-               context.schedule        = rlsSchedule;
-               context.cancel          = rlsCancel;
-               context.perform         = rlsPerform;
+       if (storePrivate->rls) {
+               CFRetain(storePrivate->rls);
+       } else {
+               CFRunLoopSourceContext  context = { 0                   // version
+                                                 , (void *)store       // info
+                                                 , rlsRetain           // retain
+                                                 , rlsRelease          // release
+                                                 , CFCopyDescription   // copyDescription
+                                                 , CFEqual             // equal
+                                                 , CFHash              // hash
+                                                 , rlsSchedule         // schedule
+                                                 , rlsCancel           // cancel
+                                                 , rlsPerform          // perform
+                                                 };
 
                storePrivate->rls = CFRunLoopSourceCreate(allocator, order, &context);
        }
 
-       return (CFRunLoopSourceRef)CFRetain(storePrivate->rls);
-}
+       if (!storePrivate->rls) {
+               _SCErrorSet(kSCStatusFailed);
+               return NULL;
+       }
 
+       return storePrivate->rls;
+}
index 2e006d339a9b77828c6fe65abfc141625f164f78..35fee922bee5ecf72865e2cad4b3a66e8d018e84 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -42,23 +42,21 @@ SCDynamicStoreCopyWatchedKeyList(SCDynamicStoreRef store, Boolean isRegex)
 {
        SCDynamicStorePrivateRef        storePrivate    = (SCDynamicStorePrivateRef)store;
        CFIndex                         keyCnt;
-       void                            **keyRefs;
+       CFSetRef                        keys;
+       const void                      **keyRefs;
        CFArrayRef                      watchedKeys     = NULL;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyWatchedKeyList:"));
 
-       if (isRegex) {
-               keyCnt  = CFSetGetCount(storePrivate->reKeys);
+       keys   = isRegex ? storePrivate->reKeys : storePrivate->keys;
+       keyCnt = CFSetGetCount(keys);
+       if (keyCnt > 0) {
                keyRefs = CFAllocatorAllocate(NULL, keyCnt * sizeof(CFStringRef), 0);
-               CFSetGetValues(storePrivate->reKeys, keyRefs);
+               CFSetGetValues(keys, keyRefs);
                watchedKeys = CFArrayCreate(NULL, keyRefs, keyCnt, &kCFTypeArrayCallBacks);
                CFAllocatorDeallocate(NULL, keyRefs);
        } else {
-               keyCnt  = CFSetGetCount(storePrivate->keys);
-               keyRefs = CFAllocatorAllocate(NULL, keyCnt * sizeof(CFStringRef), 0);
-               CFSetGetValues(storePrivate->keys, keyRefs);
-               watchedKeys = CFArrayCreate(NULL, keyRefs, keyCnt, &kCFTypeArrayCallBacks);
-               CFAllocatorDeallocate(NULL, keyRefs);
+               watchedKeys = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks);
        }
 
        return watchedKeys;
index 7cc92a9ee1b9042567bbde9a9e89bb4fd76e136b..8a56811fa4bcd8c390b7c8ae3b89214b352e4365 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -85,9 +85,10 @@ SCDynamicStoreRemoveWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean
        }
 
        /* serialize the key */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+       if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
 
        /* send the key to the server */
        status = notifyremove(storePrivate->server,
index e16481cd1070b09ff4f9d254dc22271e3fb95863..f63497340bec68dec2b0ebb55228c9cef1bab4a0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -61,10 +61,11 @@ SCDynamicStoreNotifyValue(SCDynamicStoreRef store,
                return FALSE;
        }
 
-       /* serialize the key */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+        /* serialize the key */
+        if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+                _SCErrorSet(kSCStatusFailed);
+                return FALSE;
+        }
 
        /* send the key to the server */
        status = confignotify(storePrivate->server,
index ce71d423a3fe2d26abed2eaa805624bb9d538d5e..d78ac738cbd52e7273b062833797128995e4cd4c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -30,6 +30,7 @@
  * - initial revision
  */
 
+#include <stdlib.h>
 #include <mach/mach.h>
 #include <mach/mach_error.h>
 #include <servers/bootstrap.h>
@@ -67,8 +68,9 @@ __SCDynamicStoreDeallocate(CFTypeRef cf)
        (void) pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldThreadState);
 
        /* Remove notification keys */
-       if ((keyCnt = CFSetGetCount(storePrivate->keys)) > 0) {
-               void            **watchedKeys;
+       keyCnt = CFSetGetCount(storePrivate->keys);
+       if (keyCnt > 0) {
+               const void      **watchedKeys;
                CFArrayRef      keysToRemove;
                CFIndex i;
 
@@ -85,8 +87,9 @@ __SCDynamicStoreDeallocate(CFTypeRef cf)
        }
 
        /* Remove regex notification keys */
-       if ((keyCnt = CFSetGetCount(storePrivate->reKeys)) > 0) {
-               void            **watchedKeys;
+       keyCnt = CFSetGetCount(storePrivate->reKeys);
+       if (keyCnt > 0) {
+               const void      **watchedKeys;
                CFArrayRef      keysToRemove;
                CFIndex i;
 
@@ -141,10 +144,10 @@ static CFTypeID __kSCDynamicStoreTypeID = _kCFRuntimeNotATypeID;
 
 static const CFRuntimeClass __SCDynamicStoreClass = {
        0,                              // version
-       "SCDynamicStore",                       // className
+       "SCDynamicStore",               // className
        NULL,                           // init
        NULL,                           // copy
-       __SCDynamicStoreDeallocate,             // dealloc
+       __SCDynamicStoreDeallocate,     // dealloc
        NULL,                           // equal
        NULL,                           // hash
        NULL,                           // copyFormattingDesc
@@ -246,6 +249,7 @@ SCDynamicStoreCreate(CFAllocatorRef         allocator,
        kern_return_t                   status;
        mach_port_t                     bootstrap_port;
        mach_port_t                     server;
+       char                            *server_name;
        CFDataRef                       xmlName;                /* serialized name */
        xmlData_t                       myNameRef;
        CFIndex                         myNameLen;
@@ -268,7 +272,12 @@ SCDynamicStoreCreate(CFAllocatorRef                allocator,
                return NULL;
        }
 
-       status = bootstrap_look_up(bootstrap_port, SCD_SERVER, &server);
+       server_name = getenv("SCD_SERVER");
+       if (!server_name) {
+               server_name = SCD_SERVER;
+       }
+
+       status = bootstrap_look_up(bootstrap_port, server_name, &server);
        switch (status) {
                case BOOTSTRAP_SUCCESS :
                        /* service currently registered, "a good thing" (tm) */
@@ -289,9 +298,10 @@ SCDynamicStoreCreate(CFAllocatorRef                allocator,
        }
 
        /* serialize the name */
-       xmlName = CFPropertyListCreateXMLData(NULL, name);
-       myNameRef = (xmlData_t)CFDataGetBytePtr(xmlName);
-       myNameLen = CFDataGetLength(xmlName);
+       if (!_SCSerialize(name, &xmlName, (void **)&myNameRef, &myNameLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return NULL;
+       }
 
        /* open a new session with the server */
        status = configopen(server, myNameRef, myNameLen, &storePrivate->server, (int *)&sc_status);
diff --git a/SystemConfiguration.fproj/SCDPlugin.c b/SystemConfiguration.fproj/SCDPlugin.c
new file mode 100644 (file)
index 0000000..419e35b
--- /dev/null
@@ -0,0 +1,343 @@
+/*
+ * Copyright (c) 2001 Apple Computer, 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
+ * 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.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * Modification History
+ *
+ * October 12, 2001            Allan Nathanson <ajn@apple.com>
+ * - initial revision
+ */
+
+#include <fcntl.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <mach/mach.h>
+#include <mach/mach_error.h>
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SCDPlugin.h>
+
+
+
+typedef struct childInfo *childInfoRef;
+
+struct childInfo {
+       pid_t                   pid;
+       SCDPluginExecCallBack   callout;
+       void                    *context;
+       int                     status;
+       struct rusage           rusage;
+       childInfoRef            next;
+};
+
+
+/*
+ * Mach port used to notify runloop when a child process
+ * has been reaped.
+ */
+static CFMachPortRef   childReaped     = NULL;
+
+/*
+ * The following dictionaries contain information about child
+ * processes, reaped processes, and any associated callback
+ * information.
+ *
+ * Important: Access to these dictionaries should only be
+ *            made when in a SIGCHLD handler (or when the
+ *            childLock mutex is held *AND* the signal
+ *            has been blocked).
+ */
+static childInfoRef    activeChildren  = NULL;
+static pthread_mutex_t lock            = PTHREAD_MUTEX_INITIALIZER;
+
+
+static inline void
+blockSignal()
+{
+       sigset_t        mask    = sigmask(SIGCHLD);
+
+       // block SIGCHLD
+       if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) {
+               perror("sigprocmask(SIG_BLOCK)");
+       }
+
+       return;
+}
+
+
+static inline void
+unblockSignal()
+{
+       sigset_t        mask    = sigmask(SIGCHLD);
+
+       // unblock SIGCHLD
+       if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) {
+               perror("sigprocmask(SIG_UNBLOCK)");
+       }
+
+       return;
+}
+
+
+static void
+reaper(int sigraised)
+{
+       mach_msg_empty_send_t   msg;
+       mach_msg_option_t       options;
+       kern_return_t           status;
+
+       /*
+        * block additional SIGCHLD's until current children have
+        * been reaped.
+        */
+       blockSignal();
+
+       /*
+        * send message to indicate that at least one child is ready
+        * to be reaped.
+        */
+       msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
+       msg.header.msgh_size = sizeof(msg);
+       msg.header.msgh_remote_port = CFMachPortGetPort(childReaped);
+       msg.header.msgh_local_port = MACH_PORT_NULL;
+       msg.header.msgh_id = 0;
+       options = MACH_SEND_TIMEOUT;
+       status = mach_msg(&msg.header,                  /* msg */
+                                   MACH_SEND_MSG|options,      /* options */
+                                   msg.header.msgh_size,               /* send_size */
+                                   0,                          /* rcv_size */
+                                   MACH_PORT_NULL,             /* rcv_name */
+                                   0,                          /* timeout */
+                                   MACH_PORT_NULL);            /* notify */
+
+       return;
+}
+
+
+static void
+childrenReaped(CFMachPortRef port, void *msg, CFIndex size, void *info)
+{
+       pid_t           pid             = 0;
+       childInfoRef    reapedChildren  = NULL;
+
+       do {
+               struct rusage   rusage;
+               int             status;
+
+               pid = wait4(-1, &status, WNOHANG, &rusage);
+               switch (pid) {
+                       case -1 :       // if error
+                               if (errno != ECHILD) {
+                                       perror("wait4");
+                               }
+                               break;
+
+                       case  0 :       // if no more children
+                               break;
+
+                       default : {
+                               childInfoRef    last;
+                               childInfoRef    this;
+
+                               // grab the activeChildren mutex
+                               pthread_mutex_lock(&lock);
+
+                               last = NULL;
+                               this = activeChildren;
+                               while (this) {
+                                       if (this->pid == pid) {
+                                               /* save exit status & usage */
+                                               this->status = status;
+                                               this->rusage = rusage;
+
+                                               /* remove from activeChildren */
+                                               if (last) {
+                                                       last->next = this->next;
+                                               } else {
+                                                       activeChildren = this->next;
+                                               }
+
+                                               /* add to reapedChildren */
+                                               this->next = reapedChildren;
+                                               reapedChildren = this;
+
+                                               break;
+                                       } else {
+                                               /* if not this child */
+                                               last = this;
+                                               this = this->next;
+                                       }
+                               }
+
+                               // release the activeChildren mutex
+                               pthread_mutex_unlock(&lock);
+
+                               break;
+                       }
+               }
+       } while (pid > 0);
+
+       /*
+        * we need to know about any new children waiting to be reaped so
+        * re-enable the SIGCHLD handler.
+
+        */
+       unblockSignal();
+
+       while (reapedChildren) {
+               childInfoRef    child = reapedChildren;
+
+               reapedChildren = reapedChildren->next;
+               (*child->callout)(child->pid,
+                                 child->status,
+                                 &child->rusage,
+                                 child->context);
+               CFAllocatorDeallocate(NULL, child);
+       }
+
+       return;
+}
+
+
+void
+_SCDPluginExecInit()
+{
+       struct sigaction        act;
+       CFRunLoopSourceRef      rls;
+
+       // create the "a child has been reaped" notification port
+       childReaped = CFMachPortCreate(NULL, childrenReaped, NULL, NULL);
+
+       // set queue limit
+       {
+               mach_port_limits_t      limits;
+               kern_return_t           status;
+
+               limits.mpl_qlimit = 1;
+               status = mach_port_set_attributes(mach_task_self(),
+                                                 CFMachPortGetPort(childReaped),
+                                                 MACH_PORT_LIMITS_INFO,
+                                                 (mach_port_info_t)&limits,
+                                                 MACH_PORT_LIMITS_INFO_COUNT);
+               if (status != KERN_SUCCESS) {
+                       perror("mach_port_set_attributes");
+               }
+       }
+
+       // add to our runloop
+       rls = CFMachPortCreateRunLoopSource(NULL, childReaped, 0);
+       CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
+       CFRelease(rls);
+
+       // enable signal handler
+       act.sa_handler = reaper;
+       sigemptyset(&act.sa_mask);
+       act.sa_flags = SA_RESTART|SA_NOCLDSTOP;
+       if (sigaction(SIGCHLD, &act, NULL) == -1) {
+               perror("sigaction");
+       }
+
+       return;
+}
+
+
+pid_t
+_SCDPluginExecCommand(SCDPluginExecCallBack    callout,
+                    void                       *context,
+                    uid_t                      uid,
+                    gid_t                      gid,
+                    const char                 *path,
+                    char * const               argv[])
+{
+       pid_t   pid;
+
+       // grab the activeChildren mutex
+       pthread_mutex_lock(&lock);
+
+       pid = fork();
+       switch (pid) {
+               case -1 : {     /* if error */
+
+                       int     status;
+
+                       status = errno;
+                       printf("fork() failed: %s", strerror(status));
+                       errno  = status;
+                       break;
+               }
+
+               case 0 : {      /* if child */
+
+                       uid_t   curUID  = geteuid();
+                       gid_t   curGID  = getegid();
+                       int     i;
+                       int     status;
+
+                       if (curUID != uid) {
+                               (void) setuid(uid);
+                       }
+
+                       if (curGID != gid) {
+                               (void) setgid(gid);
+                       }
+
+                       /* close any open FDs */
+                       for (i = getdtablesize()-1; i>=0; i--) close(i);
+                       open("/dev/null", O_RDWR, 0);
+                       dup(0);
+                       dup(0);
+
+                       /* execute requested command */
+                       (void) execv(path, argv);
+
+                       /* if the execv failed */
+                       status = W_EXITCODE(errno, 0);
+                       _exit (WEXITSTATUS(status));
+               }
+
+               default : {     /* if parent */
+
+                       if (callout) {
+                               childInfoRef    child;
+
+                               // create child process info
+                               child = CFAllocatorAllocate(NULL, sizeof(struct childInfo), 0);
+                               bzero(child, sizeof(struct childInfo));
+                               child->pid     = pid;
+                               child->callout = callout;
+                               child->context = context;
+
+                               // add the new child to the activeChildren list
+                               child->next = activeChildren;
+                               activeChildren = child;
+                       }
+                       break;
+               }
+       }
+
+       // release the activeChildren mutex
+       pthread_mutex_unlock(&lock);
+
+       return pid;
+}
index e0cf53151162dd6f8b78f42b69c3249d62f09ab4..9933eb9ad3177d3cae293504d8cf74b0059203af 100644 (file)
@@ -24,6 +24,9 @@
 #define _SCDPLUGIN_H
 
 #include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 #include <CoreFoundation/CoreFoundation.h>
 
 
@@ -82,8 +85,49 @@ typedef void (*SCDynamicStoreBundleStartFunction)    (const char     *bundleName,
 typedef void   (*SCDynamicStoreBundlePrimeFunction)    ();
 
 
+/*!
+        @typedef SCDPluginExecCallBack
+       @discussion Type of the callback function used when a child process
+               started by a plug-in has exited.
+       @param pid The process id of the child which has exited.
+       @param status The exit status of the child which has exited.
+       @param rusage A summary of the resources used by the child process
+               and all its children.
+       @param context The callback argument specified on the call
+               to _SCDPluginExecCommand(). 
+ */
+typedef void (*SCDPluginExecCallBack)  (pid_t          pid,
+                                         int           status,
+                                         struct rusage *rusage,
+                                         void          *context);
+
+
 __BEGIN_DECLS
 
+/*!
+       @function _SCDPluginExecCommand
+        @discussion Starts a child process.
+        @param callout The function to be called when the child
+               process exits.  A NULL value can be specified if no
+               callouts are desired.
+        @param context A argument which will be passed
+               to the callout function.
+        @param uid The desired user id of the child process.
+       @param gid The desired group id of the child process.
+       @param path The command to be executed.
+       @param argv The arguments to be passed to the child process.
+        @result The process ID of the child.
+ */
+pid_t
+_SCDPluginExecCommand  (
+                        SCDPluginExecCallBack  callout,
+                        void                   *context,
+                        uid_t                  uid,
+                        gid_t                  gid,
+                        const char             *path,
+                        char * const           argv[]
+                        );
+
 __END_DECLS
 
 #endif /* _SCDPLUGIN_H */
index 8e0b6ba4141e903558389ce7ad67e6aa91b1003c..9ce2fd249129396f60678dcbfecef11c0d407800 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
 #include <mach/mach_error.h>
 #include <pthread.h>
 
+Boolean
+_SCSerialize(CFPropertyListRef         obj,
+            CFDataRef                  *xml,
+            void                       **dataRef,
+            CFIndex                    *dataLen)
+{
+       CFDataRef       myXml;
+
+       if (!obj) {
+               /* if no object to serialize */
+               return FALSE;
+       }
+
+       if (!xml && !(dataRef && dataLen)) {
+               /* if not keeping track of allocated space */
+               return FALSE;
+       }
+
+       myXml = CFPropertyListCreateXMLData(NULL, obj);
+       if (!myXml) {
+               SCLog(TRUE, LOG_ERR, CFSTR("CFPropertyListCreateXMLData() failed"));
+               if (xml)        *xml     = NULL;
+               if (dataRef)    *dataRef = NULL;
+               if (dataLen)    *dataLen = 0;
+               return FALSE;
+       }
+
+       if (xml) {
+               *xml = myXml;
+               if (dataRef) {
+                       *dataRef = (void *)CFDataGetBytePtr(myXml);
+               }
+               if (dataLen) {
+                       *dataLen = CFDataGetLength(myXml);
+               }
+       } else {
+               kern_return_t   status;
+
+               *dataLen = CFDataGetLength(myXml);
+               status = vm_allocate(mach_task_self(), (void *)dataRef, *dataLen, TRUE);
+               if (status != KERN_SUCCESS) {
+                       SCLog(TRUE,
+                             LOG_ERR,
+                             CFSTR("vm_allocate(): %s"),
+                             mach_error_string(status));
+                       CFRelease(myXml);
+                       *dataRef = NULL;
+                       *dataLen = 0;
+                       return FALSE;
+               }
+
+               bcopy((char *)CFDataGetBytePtr(myXml), *dataRef, *dataLen);
+               CFRelease(myXml);
+       }
+
+       return TRUE;
+}
+
+
+Boolean
+_SCUnserialize(CFPropertyListRef       *obj,
+              void                     *dataRef,
+              CFIndex                  dataLen)
+{
+       kern_return_t           status;
+       CFDataRef               xml;
+       CFStringRef             xmlError;
+
+       if (!obj) {
+               return FALSE;
+       }
+
+       xml = CFDataCreate(NULL, (void *)dataRef, dataLen);
+       status = vm_deallocate(mach_task_self(), (vm_address_t)dataRef, dataLen);
+       if (status != KERN_SUCCESS) {
+               SCLog(_sc_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
+               /* non-fatal???, proceed */
+       }
+       *obj = CFPropertyListCreateFromXMLData(NULL,
+                                              xml,
+                                              kCFPropertyListImmutable,
+                                              &xmlError);
+       CFRelease(xml);
+
+       if (!obj) {
+               if (xmlError) {
+                       SCLog(TRUE,
+                             LOG_ERR,
+                             CFSTR("CFPropertyListCreateFromXMLData() failed: %@"),
+                             xmlError);
+                       CFRelease(xmlError);
+               }
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+
 void
 __showMachPortStatus()
 {
index 0f08ccc6ee16755033997d359bd4b3e2c25b8e91..1051fee6f4e518ce81ecb1e7a75addc877f05bea 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -64,9 +64,10 @@ SCDynamicStoreRemoveValue(SCDynamicStoreRef store, CFStringRef key)
        }
 
        /* serialize the key */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+       if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
 
        /* send the key to the server */
        status = configremove(storePrivate->server,
index da4fd4c83080f2a318e96c656fb6b5a8c00bd86a..01efa6c788b882d238cfdf637fd3372b8284338b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -75,23 +75,29 @@ SCDynamicStoreSetMultiple(SCDynamicStoreRef store,
 
        /* serialize the key/value pairs to set*/
        if (keysToSet) {
-               xmlSet   = CFPropertyListCreateXMLData(NULL, keysToSet);
-               mySetRef = (xmlData_t)CFDataGetBytePtr(xmlSet);
-               mySetLen = CFDataGetLength(xmlSet);
+               if (!_SCSerialize(keysToSet, &xmlSet, (void **)&mySetRef, &mySetLen)) {
+                       _SCErrorSet(kSCStatusFailed);
+                       return NULL;
+               }
        }
 
        /* serialize the keys to remove */
        if (keysToRemove) {
-               xmlRemove   = CFPropertyListCreateXMLData(NULL, keysToRemove);
-               myRemoveRef = (xmlData_t)CFDataGetBytePtr(xmlRemove);
-               myRemoveLen = CFDataGetLength(xmlRemove);
+               if (!_SCSerialize(keysToRemove, &xmlRemove, (void **)&myRemoveRef, &myRemoveLen)) {
+                       if (xmlSet)     CFRelease(xmlSet);
+                       _SCErrorSet(kSCStatusFailed);
+                       return NULL;
+               }
        }
 
        /* serialize the keys to notify */
        if (keysToNotify) {
-               xmlNotify   = CFPropertyListCreateXMLData(NULL, keysToNotify);
-               myNotifyRef = (xmlData_t)CFDataGetBytePtr(xmlNotify);
-               myNotifyLen = CFDataGetLength(xmlNotify);
+               if (!_SCSerialize(keysToNotify, &xmlNotify, (void **)&myNotifyRef, &myNotifyLen)) {
+                       if (xmlSet)     CFRelease(xmlSet);
+                       if (xmlRemove)  CFRelease(xmlRemove);
+                       _SCErrorSet(kSCStatusFailed);
+                       return NULL;
+               }
        }
 
        /* send the keys and patterns, fetch the associated result from the server */
@@ -156,14 +162,18 @@ SCDynamicStoreSetValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListR
                return FALSE;
        }
 
-       /* serialize the key and data */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+       /* serialize the key */
+       if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return NULL;
+       }
 
-       xmlData = CFPropertyListCreateXMLData(NULL, value);
-       myDataRef = (xmlData_t)CFDataGetBytePtr(xmlData);
-       myDataLen = CFDataGetLength(xmlData);
+       /* serialize the data */
+       if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) {
+               CFRelease(xmlKey);
+               _SCErrorSet(kSCStatusFailed);
+               return NULL;
+       }
 
        /* send the key & data to the server, get new instance id */
        status = configset(storePrivate->server,
index ac3d6c497261f298b8dfa310a418ce2f51143dae..24b1e752ae877e75bffdc601695d131639a35679 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -64,9 +64,10 @@ SCDynamicStoreTouchValue(SCDynamicStoreRef store, CFStringRef key)
        }
 
        /* serialize the key */
-       xmlKey = CFPropertyListCreateXMLData(NULL, key);
-       myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
-       myKeyLen = CFDataGetLength(xmlKey);
+       if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
+               _SCErrorSet(kSCStatusFailed);
+               return FALSE;
+       }
 
        /* send the key to the server */
        status = configtouch(storePrivate->server,
index fa34138002ecc34536c179a4c686d1dc1cd802f0..d40ceb3bfdbfb4ef2be700e8af2bba418d7c1621 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2001-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -67,7 +67,7 @@ SCDynamicStoreCopyDHCPInfo(SCDynamicStoreRef store, CFStringRef serviceID);
                data for.
        @result A non-NULL CFDataRef containing the option data,
                NULL otherwise.
-               
+
                The return value must NOT be released.
  */
 CFDataRef
index 89ab3bf8981513be9de180e95275a8efaeec2172..7c63f27d69a6ad61ea9310446999a22d2aeb4da8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -80,6 +80,40 @@ SCDynamicStoreCopyConsoleUser                (
                                        gid_t                   *gid
                                        );
 
+/*!
+       @function SCDynamicStoreCopyLocalHostName
+       @discussion Gets the current local host name.
+
+               See SCDynamicStoreKeyCreateHostNames() for notification
+               key information.
+       @param store An SCDynamicStoreRef that should be used for communication
+               with the server.
+               If NULL, a temporary session will be used.
+       @result The current local host name;
+               NULL if the name has not been set or if an error was encountered.
+               You must release the returned value.
+ */
+CFStringRef
+SCDynamicStoreCopyLocalHostName                (
+                                       SCDynamicStoreRef       store
+                                       );
+
+/*!
+       @function SCDynamicStoreCopyLocation
+       @discussion Gets the current "location" identifier.
+       @param store An SCDynamicStoreRef that should be used for communication
+               with the server.
+               If NULL, a temporary session will be used.
+       @result A string representing the current "location" identifier;
+               NULL if no "location" identifier has been defined or if an error
+               was encountered.
+               You must release the returned value.
+ */
+CFStringRef
+SCDynamicStoreCopyLocation     (
+                                       SCDynamicStoreRef       store
+                                       );
+
 /*!
        @function SCDynamicStoreCopyProxies
        @discussion Gets the current internet proxy settings.
index aa76284cbe47f042978a771d5c84fe957124217a..f1cb7f68cb002739cf7d248f3a283e9200480368 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -115,6 +115,31 @@ SCDynamicStoreKeyCreateConsoleUser         (
                                                CFAllocatorRef          allocator
                                                );
 
+/*!
+       @function SCDynamicStoreKeyCreateHostNames
+       @discussion Creates a key that can be used in conjunction with
+               SCDynamicStoreSetNotificationKeys() to receive
+               notifications when the HostNames entity changes.  The
+               HostNames entity contains the LocalHostName.
+       @result A notification string for the HostNames entity.
+*/
+CFStringRef
+SCDynamicStoreKeyCreateHostNames               (
+                                               CFAllocatorRef          allocator
+                                               );
+
+/*!
+       @function SCDynamicStoreKeyCreateLocation
+       @discussion Creates a key that can be used in conjunction with
+               SCDynamicStoreSetNotificationKeys() to receive
+               notifications when the "location" identifier changes.
+       @result A notification string for the current "location" identifier.
+*/
+CFStringRef
+SCDynamicStoreKeyCreateLocation                        (
+                                               CFAllocatorRef          allocator
+                                               );
+
 /*!
        @function SCDynamicStoreKeyCreateProxies
        @discussion Creates a key that can be used by the SCDynamicStoreSetNotificationKeys()
diff --git a/SystemConfiguration.fproj/SCLocation.c b/SystemConfiguration.fproj/SCLocation.c
new file mode 100644 (file)
index 0000000..90ec0ac
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2001 Apple Computer, 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
+ * 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.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * Modification History
+ *
+ * Nov 28, 2001                        Allan Nathanson <ajn@apple.com>
+ * - initial revision
+ */
+
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <SystemConfiguration/SCValidation.h>
+#include <SystemConfiguration/SCPrivate.h>
+
+CFStringRef
+SCDynamicStoreKeyCreateLocation(CFAllocatorRef allocator)
+{
+       return CFRetain(kSCDynamicStoreDomainSetup);
+}
+
+
+CFStringRef
+SCDynamicStoreCopyLocation(SCDynamicStoreRef store)
+{
+       CFDictionaryRef         dict            = NULL;
+       CFStringRef             key;
+       CFStringRef             location        = NULL;
+       Boolean                 tempSession     = FALSE;
+
+       if (!store) {
+               store = SCDynamicStoreCreate(NULL,
+                                            CFSTR("SCDynamicStoreCopyLocation"),
+                                            NULL,
+                                            NULL);
+               if (!store) {
+                       SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed"));
+                       return NULL;
+               }
+               tempSession = TRUE;
+       }
+
+       key  = SCDynamicStoreKeyCreateLocation(NULL);
+       dict = SCDynamicStoreCopyValue(store, key);
+       CFRelease(key);
+       if (!isA_CFDictionary(dict)) {
+               _SCErrorSet(kSCStatusNoKey);
+               goto done;
+       }
+
+       location = CFDictionaryGetValue(dict, kSCDynamicStorePropSetupCurrentSet);
+       if (!isA_CFString(location)) {
+               _SCErrorSet(kSCStatusNoKey);
+               goto done;
+       }
+
+       CFRetain(location);
+
+    done :
+
+       if (tempSession)        CFRelease(store);
+       if (dict)               CFRelease(dict);
+
+       return location;
+}
index b413ec80add253193e440d6dbe099b36983d404f..0d3517298cf1f3ca423d2bfe91b16e4a9a389aa3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -817,6 +817,9 @@ checkAddress(SCDynamicStoreRef              store,
                        case PPP_RUNNING :
                                /* if we're really UP and RUNNING */
                                break;
+                       case PPP_ONHOLD :
+                               /* if we're effectively UP and RUNNING */
+                               break;
                        case PPP_IDLE :
                                /* if we're not connected at all */
                                SCLog(_sc_debug, LOG_INFO, CFSTR("  PPP link idle, dial-on-traffic to connect"));
@@ -1160,8 +1163,10 @@ SCNetworkCheckReachabilityByName(const char                      *nodename,
        Boolean                 haveDNS         = FALSE;
        int                     i;
        Boolean                 ok              = TRUE;
+#ifdef CHECK_IPV6_REACHABILITY
        struct addrinfo         *res            = NULL;
        struct addrinfo         *resP;
+#endif /* CHECK_IPV6_REACHABILITY */
        CFArrayRef              serviceOrder    = NULL;
        SCDynamicStoreRef       store           = NULL;
 
@@ -1235,6 +1240,8 @@ SCNetworkCheckReachabilityByName(const char                       *nodename,
        /*
         * resolve the nodename into an address
         */
+
+#ifdef CHECK_IPV6_REACHABILITY
        i = getaddrinfo(nodename, NULL, NULL, &res);
        if (i != 0) {
                SCLog(_sc_verbose, LOG_ERR,
@@ -1297,6 +1304,7 @@ SCNetworkCheckReachabilityByName(const char                       *nodename,
              LOG_INFO,
              CFSTR("getaddrinfo() returned no addresses, try gethostbyname()"));
 #endif /* DEBUG */
+#endif /* CHECK_IPV6_REACHABILITY */
 
        h = gethostbyname(nodename);
        if (h && h->h_length) {
@@ -1403,7 +1411,9 @@ SCNetworkCheckReachabilityByName(const char                       *nodename,
 
        _CheckReachabilityFree(config, active, serviceOrder, defaultRoute);
        if (store)      CFRelease(store);
+#ifdef CHECK_IPV6_REACHABILITY
        if (res)        freeaddrinfo(res);
+#endif /* CHECK_IPV6_REACHABILITY */
 
        return ok;
 }
index d66ed6ea6af0cb60ee48a6844768702a92764292..e0306d9bc25f840a4e3653b39632b2bd7bd7e796 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright(c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -41,15 +41,19 @@ SCPreferencesCopyKeyList(SCPreferencesRef session)
        CFArrayRef              keys;
        SCPreferencesPrivateRef sessionPrivate  = (SCPreferencesPrivateRef)session;
        CFIndex                 prefsCnt;
-       void                    **prefsKeys;
+       const void              **prefsKeys;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesCopyKeyList:"));
 
        prefsCnt  = CFDictionaryGetCount(sessionPrivate->prefs);
-       prefsKeys = CFAllocatorAllocate(allocator, prefsCnt * sizeof(CFStringRef), 0);
-       CFDictionaryGetKeysAndValues(sessionPrivate->prefs, prefsKeys, NULL);
-       keys = CFArrayCreate(allocator, prefsKeys, prefsCnt, &kCFTypeArrayCallBacks);
-       CFAllocatorDeallocate(allocator, prefsKeys);
+       if (prefsCnt > 0) {
+               prefsKeys = CFAllocatorAllocate(allocator, prefsCnt * sizeof(CFStringRef), 0);
+               CFDictionaryGetKeysAndValues(sessionPrivate->prefs, prefsKeys, NULL);
+               keys = CFArrayCreate(allocator, prefsKeys, prefsCnt, &kCFTypeArrayCallBacks);
+               CFAllocatorDeallocate(allocator, prefsKeys);
+       } else {
+               keys = CFArrayCreate(allocator, NULL, 0, &kCFTypeArrayCallBacks);
+       }
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  keys = %@"), keys);
 
index a153f338b7dac0b0bdf65769c22ff61897dfa940..c96d0167834fd51142e7d1dafa604fafbeaba334 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright(c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -197,7 +197,8 @@ SCPreferencesLock(SCPreferencesRef session, Boolean wait)
                        /* synchronize this sessions prefs/signature */
                        newPrivate = (SCPreferencesPrivateRef)newPrefs;
                        CFRelease(sessionPrivate->prefs);
-                       sessionPrivate->prefs = CFRetain(newPrivate->prefs);
+                       sessionPrivate->prefs = newPrivate->prefs;
+                       CFRetain(sessionPrivate->prefs);
                        CFRelease(sessionPrivate->signature);
                        sessionPrivate->signature = CFRetain(newPrivate->signature);
                        CFRelease(newPrefs);
index 6a13925b963bf517d086a42832d3eb713cdb6293..b24a0066d61bbe7dff4a04aa490de7d3513124c5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright(c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -32,6 +32,7 @@
 
 #include <SystemConfiguration/SystemConfiguration.h>
 #include <SystemConfiguration/SCPrivate.h>
+#include <SystemConfiguration/SCValidation.h>
 #include "SCPreferencesInternal.h"
 
 #include <fcntl.h>
@@ -208,6 +209,8 @@ __SCPreferencesCreate(CFAllocatorRef        allocator,
        prefsPrivate->signature = __SCPSignatureFromStatbuf(&statBuf);
 
        if (statBuf.st_size > 0) {
+               CFDictionaryRef dict;
+
                /*
                 * extract property list
                 */
@@ -224,18 +227,17 @@ __SCPreferencesCreate(CFAllocatorRef      allocator,
                /*
                 * load preferences
                 */
-               prefsPrivate->prefs = (CFMutableDictionaryRef)
-                                   CFPropertyListCreateFromXMLData(NULL,
-                                                                   xmlData,
-                                                                   kCFPropertyListMutableContainers,
-                                                                   &xmlError);
+               dict = CFPropertyListCreateFromXMLData(NULL,
+                                                      xmlData,
+                                                      kCFPropertyListImmutable,
+                                                      &xmlError);
                CFRelease(xmlData);
-               if (!prefsPrivate->prefs) {
+               if (!dict) {
                        /* corrupt prefs file, start fresh */
                        if (xmlError) {
-                               SCLog(_sc_verbose, LOG_DEBUG,
-                                      CFSTR("_SCPOpen CFPropertyListCreateFromXMLData(): %@"),
-                                      xmlError);
+                               SCLog(TRUE, LOG_ERR,
+                                     CFSTR("_SCPOpen CFPropertyListCreateFromXMLData(): %@"),
+                                     xmlError);
                                CFRelease(xmlError);
                        }
                        goto create_2;
@@ -244,13 +246,15 @@ __SCPreferencesCreate(CFAllocatorRef      allocator,
                /*
                 * make sure that we've got a dictionary
                 */
-               if (CFGetTypeID(prefsPrivate->prefs) != CFDictionaryGetTypeID()) {
+               if (!isA_CFDictionary(dict)) {
                        /* corrupt prefs file, start fresh */
                        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("_SCPOpen CFGetTypeID(): not a dictionary."));
-                       CFRelease(prefsPrivate->prefs);
-                       prefsPrivate->prefs = NULL;
+                       CFRelease(dict);
                        goto create_2;
                }
+
+               prefsPrivate->prefs = CFDictionaryCreateMutableCopy(NULL, 0, dict);
+               CFRelease(dict);
        }
 
     create_2 :
index ea2c3f4647323688973c7aeecf2ed2686244a79d..40b351f667088cb85ae4709a83c4bdac19ebbb5d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright(c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
  */
 
 #include <SystemConfiguration/SystemConfiguration.h>
+#include <SystemConfiguration/SCValidation.h>
 #include <SystemConfiguration/SCPrivate.h>
+#include "SCPreferencesInternal.h"
+
+#define        MAXLINKS        8
 
 static CFArrayRef
 normalizePath(CFStringRef path)
@@ -71,59 +75,217 @@ normalizePath(CFStringRef path)
 }
 
 
-static int
-getPath(SCPreferencesRef session, CFStringRef path, CFMutableDictionaryRef *entity)
+static Boolean
+getPath(SCPreferencesRef session, CFStringRef path, CFDictionaryRef *entity)
 {
+       CFStringRef             element;
        CFArrayRef              elements;
        CFIndex                 i;
+       CFStringRef             link;
        CFIndex                 nElements;
-       int                     status          = kSCStatusFailed;
-       CFMutableDictionaryRef  value           = NULL;
+       CFIndex                 nLinks          = 0;
+       Boolean                 ok              = FALSE;
+       SCPreferencesPrivateRef sessionPrivate  = (SCPreferencesPrivateRef)session;
+       CFDictionaryRef         value           = NULL;
 
        elements = normalizePath(path);
        if (elements == NULL) {
-               return kSCStatusNoKey;
-       }
-
-       /* get preferences key */
-       value = (CFMutableDictionaryRef)SCPreferencesGetValue(session,
-                                                             CFArrayGetValueAtIndex(elements, 0));
-       if (!value) {
-               status = kSCStatusNoKey;
-               goto done;
+               _SCErrorSet(kSCStatusNoKey);
+               return FALSE;
        }
 
-       if (CFGetTypeID(value) != CFDictionaryGetTypeID()) {
-               status = kSCStatusNoKey;
-               goto done;
-       }
+    restart :
 
        nElements = CFArrayGetCount(elements);
-       for (i=1; i<nElements; i++) {
-               CFStringRef     element;
-
+       for (i=0; i<nElements; i++) {
                element = CFArrayGetValueAtIndex(elements, i);
-               value   = (CFMutableDictionaryRef)CFDictionaryGetValue(value, element);
+               if (i == 0) {
+                       sessionPrivate->accessed = TRUE;
+                       value = CFDictionaryGetValue(sessionPrivate->prefs,
+                                                    CFArrayGetValueAtIndex(elements, 0));
+               } else {
+                       value = CFDictionaryGetValue(value, element);
+               }
                if (value == NULL) {
-                       /* if (parent) path component does not exist */
-                       status = kSCStatusNoKey;
+                       /* if path component does not exist */
+                       _SCErrorSet(kSCStatusNoKey);
                        goto done;
                }
 
-               if (CFGetTypeID(value) != CFDictionaryGetTypeID()) {
-                       status = kSCStatusNoKey;
+               if (!isA_CFDictionary(value)) {
+                       /* if path component not a dictionary */
+                       _SCErrorSet(kSCStatusNoKey);
                        goto done;
                }
 
+               if ((i < nElements-1) &&
+                   CFDictionaryGetValueIfPresent(value, kSCResvLink, (const void **)&link)) {
+                       /*
+                        * if not the last path component and this
+                        * element is a link
+                        */
+                       CFArrayRef              linkElements;
+                       CFMutableArrayRef       newElements;
+
+                       if (++nLinks > MAXLINKS) {
+                               /* if we are chasing our tail */
+                               _SCErrorSet(kSCStatusMaxLink);
+                               goto done;
+                       }
+
+                       linkElements = normalizePath(link);
+                       if (linkElements == NULL) {
+                               /* if the link is bad */
+                               _SCErrorSet(kSCStatusNoKey);
+                               goto done;
+                       }
+
+                       newElements = CFArrayCreateMutableCopy(NULL, 0, linkElements);
+                       CFArrayAppendArray(newElements,
+                                          elements,
+                                          CFRangeMake(i+1, nElements-i-1));
+                       CFRelease(elements);
+                       elements = newElements;
+
+                       goto restart;
+               }
        }
 
        *entity = value;
-       status = kSCStatusOK;
+       ok = TRUE;
 
     done :
 
        CFRelease(elements);
-       return status;
+       return ok;
+}
+
+
+static Boolean
+setPath(SCPreferencesRef session, CFStringRef path, CFDictionaryRef entity)
+{
+       CFStringRef             element;
+       CFArrayRef              elements;
+       CFIndex                 i;
+       CFStringRef             link;
+       CFIndex                 nElements;
+       CFIndex                 nLinks          = 0;
+       CFDictionaryRef         newEntity       = NULL;
+       CFDictionaryRef         node            = NULL;
+       CFMutableArrayRef       nodes;
+       Boolean                 ok              = FALSE;
+       SCPreferencesPrivateRef sessionPrivate  = (SCPreferencesPrivateRef)session;
+
+       elements = normalizePath(path);
+       if (elements == NULL) {
+               _SCErrorSet(kSCStatusNoKey);
+               return FALSE;
+       }
+
+    restart :
+
+       nElements = CFArrayGetCount(elements);
+       nodes     = CFArrayCreateMutable(NULL, nElements-1, &kCFTypeArrayCallBacks);
+       for (i=0; i<nElements-1; i++) {
+               element = CFArrayGetValueAtIndex(elements, i);
+               if (i == 0) {
+                       sessionPrivate->accessed = TRUE;
+                       node = CFDictionaryGetValue(sessionPrivate->prefs, element);
+               } else {
+                       node = CFDictionaryGetValue(node, element);
+
+               }
+
+               if (node) {
+                       /* if path component exists */
+                       CFArrayAppendValue(nodes, node);
+               } else {
+                       /* if path component does not exist */
+                       node = CFDictionaryCreate(NULL,
+                                                 NULL,
+                                                 NULL,
+                                                 0,
+                                                 &kCFTypeDictionaryKeyCallBacks,
+                                                 &kCFTypeDictionaryValueCallBacks);
+                       CFArrayAppendValue(nodes, node);
+                       CFRelease(node);
+               }
+
+               if (!isA_CFDictionary(node)) {
+                       _SCErrorSet(kSCStatusNoKey);
+                       goto done;
+               }
+
+               if ((i < nElements-1) &&
+                   CFDictionaryGetValueIfPresent(node, kSCResvLink, (const void **)&link)) {
+                       /*
+                        * if not the last path component and this
+                        * element is a link
+                        */
+                       CFArrayRef              linkElements;
+                       CFMutableArrayRef       newElements;
+
+                       if (++nLinks > MAXLINKS) {
+                               /* if we are chasing our tail */
+                               _SCErrorSet(kSCStatusMaxLink);
+                               goto done;
+                       }
+
+                       linkElements = normalizePath(link);
+                       if (linkElements == NULL) {
+                               /* if the link is bad */
+                               _SCErrorSet(kSCStatusNoKey);
+                               goto done;
+                       }
+
+                       newElements = CFArrayCreateMutableCopy(NULL, 0, linkElements);
+                       CFArrayAppendArray(newElements,
+                                          elements,
+                                          CFRangeMake(i+1, nElements-i-1));
+                       CFRelease(elements);
+                       elements = newElements;
+
+                       CFRelease(nodes);
+                       goto restart;
+               }
+       }
+
+       if (entity) {
+               newEntity = CFRetain(entity);
+       }
+       for (i=nElements-1; i>=0; i--) {
+               element = CFArrayGetValueAtIndex(elements, i);
+               if (i == 0) {
+                       if (newEntity) {
+                               CFDictionarySetValue(sessionPrivate->prefs, element, newEntity);
+                       } else {
+                               CFDictionaryRemoveValue(sessionPrivate->prefs, element);
+                       }
+                       sessionPrivate->changed  = TRUE;
+                       ok = TRUE;
+               } else {
+                       CFMutableDictionaryRef  newNode;
+
+                       node    = CFArrayGetValueAtIndex(nodes, i-1);
+                       newNode = CFDictionaryCreateMutableCopy(NULL, 0, node);
+                       if (newEntity) {
+                               CFDictionarySetValue(newNode, element, newEntity);
+                               CFRelease(newEntity);
+                       } else {
+                               CFDictionaryRemoveValue(newNode, element);
+                       }
+                       newEntity = newNode;
+               }
+       }
+       if (newEntity) {
+               CFRelease(newEntity);
+       }
+
+    done :
+
+       CFRelease(nodes);
+       CFRelease(elements);
+       return ok;
 }
 
 
@@ -131,84 +293,47 @@ CFStringRef
 SCPreferencesPathCreateUniqueChild(SCPreferencesRef    session,
                                   CFStringRef          prefix)
 {
-       int                     status;
-       CFMutableDictionaryRef  value;
+       CFStringRef             child;
        CFStringRef             newPath         = NULL;
-       Boolean                 newValue        = FALSE;
-       CFIndex                 i;
        CFMutableDictionaryRef  newDict         = NULL;
+       CFUUIDRef               uuid;
+       CFDictionaryRef         entity;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathCreateUniqueChild:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  prefix = %@"), prefix);
 
-       status = getPath(session, prefix, &value);
-       switch (status) {
-               case kSCStatusOK :
-                       break;
-               case kSCStatusNoKey :
-                       value = CFDictionaryCreateMutable(NULL,
-                                                         0,
-                                                         &kCFTypeDictionaryKeyCallBacks,
-                                                         &kCFTypeDictionaryValueCallBacks);
-                       newValue = TRUE;
-                       break;
-               default :
+       if (getPath(session, prefix, &entity)) {
+               // if prefix path exists
+               if (CFDictionaryContainsKey(entity, kSCResvLink)) {
+                       /* the path is a link... */
+                       _SCErrorSet(kSCStatusFailed);
                        return NULL;
-       }
-
-       if (CFGetTypeID(value) != CFDictionaryGetTypeID()) {
-               /* if specified path is not a dictionary */
-               status = kSCStatusNoKey;
-               goto error;
-       }
-
-       if (CFDictionaryContainsKey(value, kSCResvLink)) {
-               /* the path is a link... */
-               status = kSCStatusFailed;
-               goto error;
-       }
-
-       i = 0;
-       while (TRUE) {
-               CFStringRef     pathComponent;
-               Boolean         found;
-
-               pathComponent = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), i);
-               found = CFDictionaryContainsKey(value, pathComponent);
-               CFRelease(pathComponent);
-
-               if (!found) {
-                       /* if we've identified the next unique key */
-                       newPath = CFStringCreateWithFormat(NULL,
-                                                          NULL,
-                                                          CFSTR("%@/%i"),
-                                                          prefix,
-                                                          i);
-                       break;
                }
-               i++;
+       } else if (SCError() != kSCStatusNoKey) {
+               // if any error except for a missing prefix path component
+               return NULL;
        }
 
+       uuid    = CFUUIDCreate(NULL);
+       child   = CFUUIDCreateString(NULL, uuid);
+       newPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@"), prefix, child);
+       CFRelease(child);
+       CFRelease(uuid);
+
        /* save the new dictionary */
        newDict = CFDictionaryCreateMutable(NULL,
                                            0,
                                            &kCFTypeDictionaryKeyCallBacks,
                                            &kCFTypeDictionaryValueCallBacks);
-       if (!SCPreferencesPathSetValue(session, newPath, newDict)) {
-               goto error;
+       if (setPath(session, newPath, newDict)) {
+               SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  child  = %@"), newPath);
+       } else {
+               CFRelease(newPath);
+               newPath = NULL;
        }
        CFRelease(newDict);
 
-       SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  child  = %@"), newPath);
-       if (newValue)   CFRelease(value);
        return newPath;
-
-    error :
-
-       if (newDict)    CFRelease(newDict);
-       if (newValue)   CFRelease(value);
-       if (newPath)    CFRelease(newPath);
-       return NULL;
 }
 
 
@@ -216,28 +341,23 @@ CFDictionaryRef
 SCPreferencesPathGetValue(SCPreferencesRef     session,
                          CFStringRef           path)
 {
-       int                     status;
-       CFMutableDictionaryRef  entity;
-       CFStringRef             entityLink;
+       CFDictionaryRef entity;
+       CFStringRef     entityLink;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathGetValue:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  path  = %@"), path);
 
-       status = getPath(session, path, &entity);
-       if (status != kSCStatusOK) {
+       if (!getPath(session, path, &entity)) {
                return NULL;
        }
 
-/* XXXX Add code here to chase multiple links XXXXX */
-
-       if ((CFGetTypeID(entity) == CFDictionaryGetTypeID()) &&
-           (CFDictionaryGetValueIfPresent(entity, kSCResvLink, (void **)&entityLink))) {
-                   /* if this is a dictionary AND it is a link */
-                   status = getPath(session, entityLink, &entity);
-                   if (status != kSCStatusOK) {
-                           /* if it was a bad link */
-                           return NULL;
-                   }
+       if (isA_CFDictionary(entity) &&
+           (CFDictionaryGetValueIfPresent(entity, kSCResvLink, (const void **)&entityLink))) {
+               /* if this is a dictionary AND it is a link */
+               if (!getPath(session, entityLink, &entity)) {
+                       /* if it was a bad link */
+                       return NULL;
+               }
        }
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  value = %@"), entity);
@@ -249,21 +369,19 @@ CFStringRef
 SCPreferencesPathGetLink(SCPreferencesRef      session,
                         CFStringRef            path)
 {
-       int                     status;
-       CFMutableDictionaryRef  entity;
-       CFStringRef             entityLink;
+       CFDictionaryRef entity;
+       CFStringRef     entityLink;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathGetLink:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  path = %@"), path);
 
-       status = getPath(session, path, &entity);
-       if (status != kSCStatusOK) {
+       if (!getPath(session, path, &entity)) {
                return NULL;
        }
 
-       if ((CFGetTypeID(entity) == CFDictionaryGetTypeID()) &&
-           (CFDictionaryGetValueIfPresent(entity, kSCResvLink, (void **)&entityLink))) {
-                   /* if this is a dictionary AND it is a link */
+       if (isA_CFDictionary(entity) &&
+           (CFDictionaryGetValueIfPresent(entity, kSCResvLink, (const void **)&entityLink))) {
+               /* if this is a dictionary AND it is a link */
                SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  link = %@"), entityLink);
                return entityLink;
        }
@@ -277,72 +395,18 @@ SCPreferencesPathSetValue(SCPreferencesRef        session,
                          CFStringRef           path,
                          CFDictionaryRef       value)
 {
-       CFMutableDictionaryRef  element;
-       CFArrayRef              elements        = NULL;
-       CFIndex                 i;
-       CFIndex                 nElements;
-       Boolean                 newRoot         = FALSE;
        Boolean                 ok;
-       CFMutableDictionaryRef  root            = NULL;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathSetValue:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  path  = %@"), path);
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  value = %@"), value);
 
-       elements = normalizePath(path);
-       if (elements == NULL) {
-               _SCErrorSet(kSCStatusNoKey);
+       if (!value) {
+               _SCErrorSet(kSCStatusInvalidArgument);
                return FALSE;
        }
 
-       /* get preferences key */
-       root = (CFMutableDictionaryRef)SCPreferencesGetValue(session,
-                                                            CFArrayGetValueAtIndex(elements, 0));
-       if (!root) {
-               root = CFDictionaryCreateMutable(NULL,
-                                                 0,
-                                                 &kCFTypeDictionaryKeyCallBacks,
-                                                 &kCFTypeDictionaryValueCallBacks);
-               newRoot = TRUE;
-       }
-
-       nElements = CFArrayGetCount(elements);
-       if (nElements == 1) {
-               /* if we are only updating the data associated with the preference key */
-               if (newRoot) {
-                       CFRelease(root);
-                       newRoot = FALSE;
-               }
-               root = (CFMutableDictionaryRef)value;
-       }
-
-       element = root;
-       for (i=1; i<nElements-1; i++) {
-               CFStringRef             pathComponent;
-               CFMutableDictionaryRef  tmpElement;
-
-               pathComponent = CFArrayGetValueAtIndex(elements, i);
-               tmpElement  = (void *)CFDictionaryGetValue(element, pathComponent);
-               if (tmpElement == NULL) {
-                       /* if (parent) path component does not exist */
-                       tmpElement = CFDictionaryCreateMutable(NULL,
-                                                              0,
-                                                              &kCFTypeDictionaryKeyCallBacks,
-                                                              &kCFTypeDictionaryValueCallBacks);
-                       CFDictionarySetValue(element, pathComponent, tmpElement);
-                       CFRelease(tmpElement);
-               }
-               element = tmpElement;
-       }
-
-       if (nElements > 1) {
-               CFDictionarySetValue(element,
-                                    CFArrayGetValueAtIndex(elements, nElements-1),
-                                    value);
-       }
-       ok = SCPreferencesSetValue(session, CFArrayGetValueAtIndex(elements, 0), root);
-       if (newRoot)    CFRelease(root);
-       CFRelease(elements);
+       ok = setPath(session, path, value);
        return ok;
 }
 
@@ -353,18 +417,29 @@ SCPreferencesPathSetLink(SCPreferencesRef session,
                         CFStringRef            link)
 {
        CFMutableDictionaryRef  dict;
+       CFDictionaryRef         entity;
        Boolean                 ok;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathSetLink:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  path = %@"), path);
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  link = %@"), link);
 
+       if (!link) {
+               _SCErrorSet(kSCStatusInvalidArgument);
+               return FALSE;
+       }
+
+       if (!getPath(session, link, &entity)) {
+               // if bad link
+               return FALSE;
+       }
+
        dict = CFDictionaryCreateMutable(NULL,
                                         0,
                                         &kCFTypeDictionaryKeyCallBacks,
                                         &kCFTypeDictionaryValueCallBacks);
        CFDictionaryAddValue(dict, kSCResvLink, link);
-       ok = SCPreferencesPathSetValue(session, path, dict);
+       ok = setPath(session, path, dict);
        CFRelease(dict);
 
        return ok;
@@ -375,54 +450,25 @@ Boolean
 SCPreferencesPathRemoveValue(SCPreferencesRef  session,
                             CFStringRef        path)
 {
-       CFMutableDictionaryRef  element;
        CFArrayRef              elements        = NULL;
-       CFIndex                 i;
-       CFIndex                 nElements;
        Boolean                 ok              = FALSE;
-       CFMutableDictionaryRef  root            = NULL;
+       CFDictionaryRef         value;
 
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCPreferencesPathRemoveValue:"));
        SCLog(_sc_verbose, LOG_DEBUG, CFSTR("  path = %@"), path);
 
+       if (!getPath(session, path, &value)) {
+               // if no such path
+               return FALSE;
+       }
+
        elements = normalizePath(path);
        if (elements == NULL) {
                _SCErrorSet(kSCStatusNoKey);
                return FALSE;
        }
 
-       /* get preferences key */
-       root = (CFMutableDictionaryRef)SCPreferencesGetValue(session,
-                                                            CFArrayGetValueAtIndex(elements, 0));
-       if (!root) {
-               goto done;
-       }
-
-       nElements = CFArrayGetCount(elements);
-       if (nElements == 1) {
-               /* if we are removing the data associated with the preference key */
-               ok = SCPreferencesRemoveValue(session, CFArrayGetValueAtIndex(elements, 0));
-               goto done;
-       }
-
-       element = root;
-       for (i=1; i<nElements-1; i++) {
-               CFStringRef             pathComponent;
-               CFMutableDictionaryRef  tmpElement;
-
-               pathComponent = CFArrayGetValueAtIndex(elements, i);
-               tmpElement    = (void *)CFDictionaryGetValue(element, pathComponent);
-               if (tmpElement == NULL) {
-                       goto done;
-               }
-               element = tmpElement;
-       }
-
-       CFDictionaryRemoveValue(element,
-                               CFArrayGetValueAtIndex(elements, nElements-1));
-       ok = SCPreferencesSetValue(session, CFArrayGetValueAtIndex(elements, 0), root);
-
-    done :
+       ok = setPath(session, path, NULL);
 
        CFRelease(elements);
        return ok;
index 3cf71dd65d8f9025928eed3e0224ba646d00fcef..21ed419b0e40905a440dfea43b7f0b57d2a3e0f1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -84,8 +84,6 @@ __BEGIN_DECLS
        @param session The SCPreferencesRef handle that should be used to
         communicate with the APIs.
        @param prefix A string that represents the parent path.
-       @param newPath A pointer to memory that will be filled with a
-               string representing the new child path.
        @result A string representing the new (unique) child path; NULL
                if the specified path does not exist.
  */
index a0a6b3dce6b2e3213031dd5b2d091b6c2e052c27..dc22ff28ac13e929f7ba6978ffa41fbe5e605100 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -44,6 +44,8 @@ __BEGIN_DECLS
 
        Note: In order to commit these changes to permanent storage a call
        must be made to SCPreferencesCommitChanges().
+       A call to SCPreferencesApplyChanges() is also required for the new
+       name to become active.
        @param prefs An SCPreferencesRef that should be used for all API calls.
        @param name The computer/host name to be set.
        @param nameEncoding The encoding associated with the computer/host name.
@@ -56,6 +58,27 @@ SCPreferencesSetComputerName         (
                                        CFStringEncoding        nameEncoding
                                        );
 
+/*!
+       @function SCPreferencesSetLocalHostName
+       @discussion Updates the local host name in the system preferences.
+
+       Note: In order to commit these changes to permanent storage a call
+       must be made to SCPreferencesCommitChanges().
+       A call to SCPreferencesApplyChanges() is also required for the new
+       name to become active.
+       @param prefs An SCPreferencesRef that should be used for all API calls.
+       @param name The local host name to be set.
+
+       Note: the string must conform to the naming conventions of a DNS host
+               name as specified in RFC 1034 (section 3.5).
+       @result A boolean indicating the success (or failure) of the call.
+ */
+Boolean
+SCPreferencesSetLocalHostName          (
+                                       SCPreferencesRef        prefs,
+                                       CFStringRef             name
+                                       );
+
 __END_DECLS
 
 #endif /* _SCPREFERENCESSETSPECIFIC_H */
index 57f2e6209e6e0365023238e551ad7f00818e5053..e74d535761fd998e03bf572d04459c767ed114b7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -46,6 +46,35 @@ __BEGIN_DECLS
  */
 void           _SCErrorSet                     (int                    error);
 
+/*
+       @function _SCSerialize
+       @discussion Serialize a CFPropertyList object for passing
+               to/from configd.
+       @param obj CFPropertyList object to serialize
+       @param xml A pointer to a CFDataRef, NULL if data should be
+               vm_allocated.
+       @param data A pointer to the newly allocated/serialized data
+       @param dataLen A pointer to the length in bytes of the newly
+               allocated/serialized data
+ */
+Boolean                _SCSerialize                    (CFPropertyListRef      obj,
+                                                CFDataRef              *xml,
+                                                void                   **dataRef,
+                                                CFIndex                *dataLen);
+
+/*
+       @function _SCUnserialize
+       @discussion Unserialize a stream of bytes passed from/to configd
+               into a CFPropertyList object.
+        @param obj A pointer to memory that will be filled with the CFPropertyList
+                associated with the stream of bytes.
+       @param data A pointer to the serialized data
+       @param dataLen A pointer to the length of the serialized data
+ */
+Boolean                _SCUnserialize                  (CFPropertyListRef      *obj,
+                                                void                   *dataRef,
+                                                CFIndex                dataLen);
+
 /*
        @function SCLog
        @discussion Conditionally issue a log message.
index d31c8266ec12cc717fbec37101c96e68b784c8b6..25745129711d53066a459361a48500a00f5aa6db 100644 (file)
@@ -28,8 +28,8 @@
  */
 
 #include <SystemConfiguration/SystemConfiguration.h>
-#include <SystemConfiguration/SCPrivate.h>
 #include <SystemConfiguration/SCValidation.h>
+#include <SystemConfiguration/SCPrivate.h>
 
 CFStringRef
 SCDynamicStoreKeyCreateProxies(CFAllocatorRef allocator)
@@ -45,22 +45,23 @@ SCDynamicStoreCopyProxies(SCDynamicStoreRef store)
 {
        CFDictionaryRef         dict            = NULL;
        CFStringRef             key;
-       SCDynamicStoreRef       mySession       = store;
        CFDictionaryRef         proxies         = NULL;
+       Boolean                 tempSession     = FALSE;
 
        if (!store) {
-               mySession = SCDynamicStoreCreate(NULL,
-                                                CFSTR("SCDynamicStoreCopyConsoleUser"),
-                                                NULL,
-                                                NULL);
-               if (!mySession) {
+               store = SCDynamicStoreCreate(NULL,
+                                            CFSTR("SCDynamicStoreCopyConsoleUser"),
+                                            NULL,
+                                            NULL);
+               if (!store) {
                        SCLog(_sc_verbose, LOG_INFO, CFSTR("SCDynamicStoreCreate() failed"));
                        return NULL;
                }
+               tempSession = TRUE;
        }
 
        key  = SCDynamicStoreKeyCreateProxies(NULL);
-       dict = SCDynamicStoreCopyValue(mySession, key);
+       dict = SCDynamicStoreCopyValue(store, key);
        CFRelease(key);
        if (!isA_CFDictionary(dict)) {
                _SCErrorSet(kSCStatusNoKey);
@@ -71,7 +72,7 @@ SCDynamicStoreCopyProxies(SCDynamicStoreRef store)
 
     done :
 
-       if (!store && mySession)        CFRelease(mySession);
-       if (dict)                       CFRelease(dict);
+       if (tempSession)        CFRelease(store);
+       if (dict)               CFRelease(dict);
        return proxies;
 }
index 09f1aaf21bb3eefa1adcb8d09ad80ebd163ece4f..272cdc5db3b9dc58e08bf974f7f365461745ee4a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2001-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -104,6 +104,15 @@ isA_CFString(CFTypeRef obj)
        return (isA_CFType(obj, CFStringGetTypeID()));
 }
 
+
+Boolean
+_SC_stringIsValidDNSName       (const char *name);
+
+
+Boolean
+_SC_CFStringIsValidDNSName     (CFStringRef name);
+
+
 __END_DECLS
 
 #endif /* _SCVALIDATION_H */
index 13b85037f13391d6b3e3dadab9ae44cf896360de..3467ba6c7ab70a0916e92516e104f2f7c48aa855 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -65,6 +65,7 @@
        @constant kSCStatusNoConfigFile         Configuration file not found
        @constant kSCStatusNoLink               No such link
        @constant kSCStatusStale                Write attempted on stale version of object
+       @constant kSCStatusMaxLink              Maximum link count exceeded
 
        @constant kSCStatusReachabilityUnknown
                A determination could not be made regarding the reachability
@@ -99,6 +100,7 @@ enum {
        kSCStatusNoConfigFile                   = 3003, /* Configuration file not found */
        kSCStatusNoLink                         = 3004, /* No such link */
        kSCStatusStale                          = 3005, /* Write attempted on stale version of object */
+       kSCStatusMaxLink                        = 3006, /* Maximum link count exceeded */
        /*
         * SCNetwork status codes
         */
index c4eb32f735df336ed420ba346a060be6ba78659d..cc549580b31cdaf8a6f2c4834dc6e90869e01908 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
  */
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <mach/boolean.h>
 
 char copyright_string[] =
 "/*\n"
-" * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.\n"
+" * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.\n"
 " *\n"
 " * @APPLE_LICENSE_HEADER_START@\n"
 " * \n"
@@ -72,7 +73,7 @@ typedef enum {
        COMMENT,
        OBSOLETE,
        REGULAR,
-       DEFINE ,
+       DEFINE,
        FUTURE,
        END
 } controlType;
@@ -99,6 +100,7 @@ typedef enum {
 #define CFARRAY_CFNUMBER       "CFArray[CFNumber]"
 #define CFARRAY_CFSTRING       "CFArray[CFString]"
 #define CFBOOLEAN              "CFBoolean"
+#define CFDATA                 "CFData"
 #define CFDICTIONARY           "CFDictionary"
 #define CFNUMBER               "CFNumber"
 #define CFNUMBER_BOOL          "CFNumber (0 or 1)"
@@ -108,6 +110,7 @@ typedef enum {
 #define ADDRESSES              "Addresses"
 #define AIRPORT                        "AirPort"
 #define ALERT                  "Alert"
+#define ALLOWNETCREATION       "AllowNetCreation"
 #define ALTERNATEREMOTEADDRESS "AlternateRemoteAddress"
 #define ANYREGEX               "AnyRegex"
 #define APPLETALK              "AppleTalk"
@@ -118,6 +121,8 @@ typedef enum {
 #define BROADCAST              "Broadcast"
 #define BROADCASTADDRESSES     "BroadcastAddresses"
 #define BROADCASTSERVERTAG     "BroadcastServerTag"
+#define CALLWAITINGAUDIBLEALERT        "CallWaitingAudibleAlert"
+#define CCP                    "CCP"
 #define CHAP                   "CHAP"
 #define COMM                   "Comm"
 #define COMPRESSIONACFIELD     "CompressionACField"
@@ -127,20 +132,26 @@ typedef enum {
 #define CONFIGMETHOD           "ConfigMethod"
 #define CONNECTDELAY           "ConnectDelay"
 #define CONNECTIONSCRIPT       "ConnectionScript"
+#define CONNECTSPEED           "ConnectSpeed"
+#define CONNECTTIME            "ConnectTime"
 #define CONSOLEUSER            "ConsoleUser"
 #define CURRENTSET             "CurrentSet"
 #define DATACOMPRESSION                "DataCompression"
 #define DEFAULTSERVERTAG       "DefaultServerTag"
 #define DEFAULTZONE            "DefaultZone"
 #define DESTADDRESSES          "DestAddresses"
+#define DETACHING              "Detaching"
+#define DEVICE                 "Device"
 #define DEVICENAME             "DeviceName"
 #define DHCP                   "DHCP"
 #define DHCPCLIENTID           "DHCPClientID"
 #define DIALMODE               "DialMode"
 #define DIALONDEMAND           "DialOnDemand"
+#define DISCONNECTONANSWER     "DisconnectOnAnswer"
 #define DISCONNECTONIDLE       "DisconnectOnIdle"
 #define DISCONNECTONIDLETIMER  "DisconnectOnIdleTimer"
 #define DISCONNECTONLOGOUT     "DisconnectOnLogout"
+#define DISCONNECTONSLEEP      "DisconnectOnSleep"
 #define DISPLAYTERMINALWINDOW  "DisplayTerminalWindow"
 #define DNS                    "DNS"
 #define DOMAIN                         "Domain"
@@ -149,6 +160,7 @@ typedef enum {
 #define ECHOENABLED            "EchoEnabled"
 #define ECHOFAILURE            "EchoFailure"
 #define ECHOINTERVAL           "EchoInterval"
+#define ENABLED                        "Enabled"
 #define ENCODING               "Encoding"
 #define ENCRYPTION             "Encryption"
 #define ERRORCORRECTION                "ErrorCorrection"
@@ -165,6 +177,8 @@ typedef enum {
 #define GOPHERPORT             "GopherPort"
 #define GOPHERPROXY            "GopherProxy"
 #define HARDWARE               "Hardware"
+#define HOLD                   "Hold"
+#define HOSTNAMES              "HostNames"
 #define HTTPENABLE             "HTTPEnable"
 #define HTTPPORT               "HTTPPort"
 #define HTTPPROXY              "HTTPProxy"
@@ -182,9 +196,13 @@ typedef enum {
 #define IPCP                   "IPCP"
 #define IPV4                   "IPv4"
 #define IPV6                   "IPv6"
+#define JOINMODE               "JoinMode"
+#define LASTCAUSE              "LastCause"
 #define LASTUPDATED            "LastUpdated"
 #define LCP                    "LCP"
 #define LINK                   "Link"
+#define LINKLOCAL              "LinkLocal"
+#define LOCALHOSTNAME          "LocalHostName"
 #define LOGFILE                        "Logfile"
 #define MACADDRESS             "MACAddress"
 #define MANUAL                 "Manual"
@@ -196,18 +214,24 @@ typedef enum {
 #define NETINFO                        "NetInfo"
 #define NETWORK                        "Network"
 #define NETWORKID              "NetworkID"
+#define NETWORKRANGE           "NetworkRange"
 #define NETWORKSERVICES                "NetworkServices"
 #define NIS                    "NIS"
 #define NODE                   "Node"
 #define NODEID                 "NodeID"
+#define NOTE                   "Note"
+#define OVERRIDEPRIMARY                "OverridePrimary"
 #define PAP                    "PAP"
 #define PASSWORD               "Password"
 #define PLUGIN                 "Plugin"
+#define PLUGINS                        "Plugins"
 #define POWERENABLED           "PowerEnabled"
 #define PPP                    "PPP"
 #define PPPOE                  "PPPoE"
 #define PPPOVERRIDEPRIMARY     "PPPOverridePrimary"
 #define PPPSERIAL              "PPPSerial"
+#define PPTP                   "PPTP"
+#define PREFERRED              "Preferred"
 #define PREFERREDNETWORK       "PreferredNetwork"
 #define PREFS                  "Prefs"
 #define PRIMARYINTERFACE       "PrimaryInterface"
@@ -216,15 +240,19 @@ typedef enum {
 #define PROXIES                        "Proxies"
 #define PULSEDIAL              "PulseDial"
 #define RECEIVEACCM            "ReceiveACCM"
+#define RECENT                 "Recent"
 #define REDIALCOUNT            "RedialCount"
 #define REDIALENABLED          "RedialEnabled"
 #define REDIALINTERVAL         "RedialInterval"
+#define REMINDER               "Reminder"
+#define REMINDERTIME           "ReminderTime"
 #define REMOTEADDRESS          "RemoteAddress"
 #define ROOTSEPARATOR          "RootSeparator"
 #define ROUTER                 "Router"
 #define RTSPENABLE             "RTSPEnable"
 #define RTSPPORT               "RTSPPort"
 #define RTSPPROXY              "RTSPProxy"
+#define SAVEPASSWORDS          "SavePasswords"
 #define SEARCHDOMAINS          "SearchDomains"
 #define SEEDNETWORKRANGE       "SeedNetworkRange"
 #define SEEDROUTER             "SeedRouter"
@@ -244,14 +272,18 @@ typedef enum {
 #define SPEAKER                        "Speaker"
 #define SPEED                  "Speed"
 #define STATE                  "State"
+#define STATUS                 "Status"
+#define STRONGEST              "Strongest"
 #define SUBNETMASKS            "SubnetMasks"
 #define SUBTYPE                        "SubType"
+#define SUPPORTSMODEMONHOLD    "SupportsModemOnHold"
 #define SYSTEM                 "System"
 #define TERMINALSCRIPT         "TerminalScript"
 #define TRANSMITACCM           "TransmitACCM"
 #define TYPE                   "Type"
 #define UID                    "UID"
 #define USERDEFINEDNAME                "UserDefinedName"
+#define USE                    "Use"
 #define USERS                  "Users"
 #define VERBOSELOGGING         "VerboseLogging"
 #define WAITFORDIALTONE                "WaitForDialTone"
@@ -286,6 +318,7 @@ struct {
     { REGULAR, COMP, NETWORK, NULL, NULL },
     { REGULAR, COMP, SERVICE, NULL, NULL },
     { REGULAR, COMP, GLOBAL, NULL, NULL },
+    { DEFINE , COMP, HOSTNAMES, NULL, NULL },
     { REGULAR, COMP, INTERFACE, NULL, NULL },
     { REGULAR, COMP, SYSTEM, NULL, NULL },
     { REGULAR, COMP, USERS, NULL, NULL },
@@ -314,15 +347,32 @@ struct {
     { COMMENT, "", NULL, NULL, NULL },
 
     { COMMENT, "/*\n * " KEY_PREFIX COMP NETWORK " Properties\n */", NULL },
+    { DEFINE , NETPROP, OVERRIDEPRIMARY, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP, SERVICEORDER, NULL, CFARRAY_CFSTRING },
     { REGULAR, NETPROP, PPPOVERRIDEPRIMARY, NULL, CFNUMBER_BOOL },
     { COMMENT, "", NULL, NULL, NULL },
 
+    { COMMENT, "/*\n * " KEY_PREFIX COMP NETWORK INTERFACE " Properties\n */", NULL },
+    { DEFINE , NETPROP, INTERFACES, NULL, CFARRAY_CFSTRING },
+    { COMMENT, "", NULL, NULL, NULL },
+
+    { COMMENT, "/*\n * " KEY_PREFIX COMP NETWORK HOSTNAMES " Properties\n */", NULL },
+    { DEFINE , NETPROP, LOCALHOSTNAME, NULL, CFSTRING },
+    { COMMENT, "", NULL, NULL, NULL },
+
     { COMMENT, "/*\n * " KEY_PREFIX NETENT AIRPORT " (Hardware) Entity Keys\n */", NULL, NULL, NULL },
-    { REGULAR, NETPROP AIRPORT, POWERENABLED, NULL, CFNUMBER_BOOL },
-    { REGULAR, NETPROP AIRPORT, AUTH PASSWORD, NULL, CFSTRING },
+    { DEFINE , NETPROP AIRPORT, ALLOWNETCREATION, NULL, CFNUMBER_BOOL },
+    { REGULAR, NETPROP AIRPORT, AUTH PASSWORD, NULL, CFDATA },
     { REGULAR, NETPROP AIRPORT, AUTH PASSWORD ENCRYPTION, NULL, CFSTRING },
+    { DEFINE , NETPROP AIRPORT, JOINMODE, NULL, CFSTRING },
+    { REGULAR, NETPROP AIRPORT, POWERENABLED, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP AIRPORT, PREFERREDNETWORK, NULL, CFSTRING },
+    { DEFINE , NETPROP AIRPORT, SAVEPASSWORDS, NULL, CFNUMBER_BOOL },
+    { COMMENT, "", NULL, NULL, NULL },
+    { COMMENT, "/* " KEY_PREFIX NETPROP AIRPORT JOINMODE " values */", NULL, NULL, NULL },
+    { DEFINE , NETVAL AIRPORT JOINMODE, PREFERRED, NULL, NULL },
+    { DEFINE , NETVAL AIRPORT JOINMODE, RECENT, NULL, NULL },
+    { DEFINE , NETVAL AIRPORT JOINMODE, STRONGEST, NULL, NULL },
     { COMMENT, "", NULL, NULL, NULL },
 
     { COMMENT, "/*\n * " KEY_PREFIX NETENT APPLETALK " Entity Keys\n */", NULL, NULL, NULL },
@@ -331,6 +381,7 @@ struct {
     { REGULAR, NETPROP APPLETALK, CONFIGMETHOD, NULL, CFSTRING },
     { REGULAR, NETPROP APPLETALK, DEFAULTZONE, NULL, CFSTRING },
     { REGULAR, NETPROP APPLETALK, NETWORKID, NULL, CFNUMBER },
+    { REGULAR, NETPROP APPLETALK, NETWORKRANGE, NULL, CFARRAY_CFNUMBER },
     { REGULAR, NETPROP APPLETALK, NODEID, NULL, CFNUMBER },
     { REGULAR, NETPROP APPLETALK, SEEDNETWORKRANGE, NULL, CFARRAY_CFNUMBER },
     { REGULAR, NETPROP APPLETALK, SEEDZONES, NULL, CFARRAY_CFSTRING },
@@ -356,6 +407,7 @@ struct {
     { REGULAR, NETPROP INTERFACE, HARDWARE, NULL, CFSTRING },
     { REGULAR, NETPROP INTERFACE, TYPE, NULL, CFSTRING },
     { REGULAR, NETPROP INTERFACE, SUBTYPE, NULL, CFSTRING },
+    { DEFINE , NETPROP INTERFACE, SUPPORTSMODEMONHOLD, NULL, CFNUMBER_BOOL },
     { COMMENT, "", NULL, NULL, NULL },
     { COMMENT, "/* " KEY_PREFIX NETPROP INTERFACE TYPE " values */", NULL, NULL, NULL },
     { REGULAR, NETVAL INTERFACE TYPE, ETHERNET, NULL, NULL },
@@ -364,6 +416,7 @@ struct {
     { COMMENT, "/* " KEY_PREFIX NETPROP SERVICE SUBTYPE " values (for " PPP ") */", NULL, NULL, NULL },
     { REGULAR, NETVAL INTERFACE SUBTYPE, PPPOE, NULL, NULL },
     { REGULAR, NETVAL INTERFACE SUBTYPE, PPPSERIAL, NULL, NULL },
+    { DEFINE , NETVAL INTERFACE SUBTYPE, PPTP, NULL, NULL },
     { COMMENT, "", NULL, NULL, NULL },
 
     { COMMENT, "/*\n * " KEY_PREFIX NETENT IPV4 " Entity Keys\n */", NULL, NULL, NULL },
@@ -379,6 +432,7 @@ struct {
     { REGULAR, NETVAL IPV4 CONFIGMETHOD, BOOTP, NULL, NULL },
     { REGULAR, NETVAL IPV4 CONFIGMETHOD, DHCP, NULL, NULL },
     { REGULAR, NETVAL IPV4 CONFIGMETHOD, INFORM, NULL, NULL },
+    { REGULAR, NETVAL IPV4 CONFIGMETHOD, LINKLOCAL, NULL, NULL },
     { REGULAR, NETVAL IPV4 CONFIGMETHOD, MANUAL, NULL, NULL },
     { REGULAR, NETVAL IPV4 CONFIGMETHOD, PPP, NULL, NULL },
     { COMMENT, "", NULL, NULL, NULL },
@@ -390,13 +444,21 @@ struct {
 
     { COMMENT, "/*\n * " KEY_PREFIX NETENT LINK " Entity Keys\n */", NULL, NULL, NULL },
     { REGULAR, NETPROP LINK, ACTIVE, NULL, CFBOOLEAN },
+    { DEFINE , NETPROP LINK, DETACHING, NULL, CFBOOLEAN },
     { COMMENT, "", NULL, NULL, NULL },
 
     { COMMENT, "/*\n * " KEY_PREFIX NETENT MODEM " (Hardware) Entity Keys\n */", NULL, NULL, NULL },
     { REGULAR, NETPROP MODEM, CONNECTIONSCRIPT, NULL, CFSTRING },
+    { DEFINE , NETPROP MODEM, CONNECTSPEED, NULL, CFNUMBER },
     { DEFINE , NETPROP MODEM, DATACOMPRESSION, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP MODEM, DIALMODE, NULL, CFSTRING },
     { DEFINE , NETPROP MODEM, ERRORCORRECTION, NULL, CFNUMBER_BOOL },
+    { DEFINE , NETPROP MODEM, HOLD CALLWAITINGAUDIBLEALERT, NULL, CFNUMBER_BOOL },
+    { DEFINE , NETPROP MODEM, HOLD DISCONNECTONANSWER, NULL, CFNUMBER_BOOL },
+    { DEFINE , NETPROP MODEM, HOLD ENABLED, NULL, CFNUMBER_BOOL },
+    { DEFINE , NETPROP MODEM, HOLD REMINDER, NULL, CFNUMBER_BOOL },
+    { DEFINE , NETPROP MODEM, HOLD REMINDERTIME, NULL, CFNUMBER },
+    { DEFINE , NETPROP MODEM, NOTE, NULL, CFSTRING },
     { REGULAR, NETPROP MODEM, PULSEDIAL, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP MODEM, SPEAKER, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP MODEM, SPEED, NULL, CFNUMBER },
@@ -427,14 +489,21 @@ struct {
     { COMMENT, "", NULL, NULL, NULL },
 
     { COMMENT, "/*\n * " KEY_PREFIX NETENT PPP " Entity Keys\n */", NULL, NULL, NULL },
+    { DEFINE , NETPROP PPP, CONNECTTIME, NULL, CFNUMBER },
+    { DEFINE , NETPROP PPP, DEVICE LASTCAUSE, NULL, CFNUMBER },
     { REGULAR, NETPROP PPP, DIALONDEMAND, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP PPP, DISCONNECTONIDLE, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP PPP, DISCONNECTONIDLETIMER, NULL, CFNUMBER },
     { REGULAR, NETPROP PPP, DISCONNECTONLOGOUT, NULL, CFNUMBER_BOOL },
+    { DEFINE , NETPROP PPP, DISCONNECTONSLEEP, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP PPP, IDLEREMINDERTIMER, NULL, CFNUMBER },
     { REGULAR, NETPROP PPP, IDLEREMINDER, NULL, CFNUMBER_BOOL },
+    { DEFINE , NETPROP PPP, LASTCAUSE, NULL, CFNUMBER },
     { REGULAR, NETPROP PPP, LOGFILE, NULL, CFSTRING },
+    { DEFINE , NETPROP PPP, PLUGINS, NULL, CFARRAY_CFSTRING },
     { DEFINE , NETPROP PPP, SESSIONTIMER, NULL, CFNUMBER },
+    { DEFINE , NETPROP PPP, STATUS, NULL, CFSTRING },
+    { DEFINE , NETPROP PPP, USE SESSIONTIMER, NULL, CFNUMBER_BOOL },
     { REGULAR, NETPROP PPP, VERBOSELOGGING, NULL, CFNUMBER_BOOL },
     { COMMENT, "", NULL, NULL, NULL },
 
@@ -457,6 +526,10 @@ struct {
     { REGULAR, NETPROP PPP, COMM REDIALINTERVAL, NULL, CFNUMBER },
     { REGULAR, NETPROP PPP, COMM REMOTEADDRESS, NULL, CFSTRING },
     { REGULAR, NETPROP PPP, COMM TERMINALSCRIPT, NULL, CFSTRING },
+    { DEFINE , NETPROP PPP, COMM USE TERMINALSCRIPT, NULL, CFNUMBER_BOOL },
+
+    { COMMENT, "\n/* " CCP ": */", NULL, NULL, NULL },
+    { DEFINE , NETPROP PPP, CCP ENABLED, NULL, CFNUMBER_BOOL },
 
     { COMMENT, "\n/* " IPCP ": */", NULL, NULL, NULL },
     { REGULAR, NETPROP PPP, IPCP COMPRESSIONVJ, NULL, CFNUMBER_BOOL },
diff --git a/SystemConfiguration.fproj/moh.c b/SystemConfiguration.fproj/moh.c
new file mode 100644 (file)
index 0000000..659e470
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2002 Apple Computer, 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
+ * 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.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * Modification History
+ *
+ * May 29, 2002                Roger Smith <rsmith@apple.com>
+ * - initial revision
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <SystemConfiguration/SCPrivate.h>
+
+#include "moh.h"
+#include "moh_msg.h"
+
+// Note: right now we are not currently using the deviceName.  This could be the raw
+//       tty name such as "modem" since this is guaranteed to be unique in the /dev.
+//       We would use this deviceName to differientate between multiple MOH devices
+//       present in the system when we create the socket.
+
+
+static int
+readn(int ref, void *data, int len)
+{
+       int     left    = len;
+       int     n;
+       void    *p      = data;
+
+       while (left > 0) {
+               if ((n = read(ref, p, left)) < 0) {
+                       if (errno != EINTR) {
+                               return -1;
+                       }
+                       n = 0;
+               } else if (n == 0) {
+                       break; /* EOF */
+               }
+
+               left -= n;
+               p += n;
+       }
+       return (len - left);
+}
+
+
+static int
+writen(int ref, void *data, int len)
+{
+       int     left    = len;
+       int     n;
+       void    *p      = data;
+
+       while (left > 0) {
+               if ((n = write(ref, p, left)) <= 0) {
+                       if (errno != EINTR) {
+                               return -1;
+                       }
+                       n = 0;
+               }
+               left -= n;
+               p += n;
+       }
+       return len;
+}
+
+
+__private_extern__
+int
+MOHInit(int *ref, CFStringRef deviceName)
+{
+       int                     sock;
+       int                     status;
+       struct sockaddr_un      sun;
+
+       sock = socket(AF_LOCAL, SOCK_STREAM, 0);
+
+       bzero(&sun, sizeof(sun));
+       sun.sun_family = AF_LOCAL;
+       strncpy(sun.sun_path, MOH_PATH, sizeof(sun.sun_path));
+
+       status = connect(sock, (struct sockaddr *)&sun, sizeof(sun));
+       if (status < 0) {
+               return errno;
+       }
+
+       *ref = sock;
+       return 0;
+}
+
+
+__private_extern__
+int
+MOHDispose(int ref)
+{
+       if (close(ref) < 0) {
+               return errno;
+       }
+       return 0;
+}
+
+
+__private_extern__
+int
+MOHExec(int            ref,
+       u_long          link,
+       u_int32_t       cmd,
+       void            *request,
+       u_long          requestLen,
+       void            **reply,
+       u_long          *replyLen)
+{
+       struct moh_msg_hdr      msg;
+       char                    *buf            = NULL;
+       ssize_t                 n;
+
+       bzero(&msg, sizeof(msg));
+       msg.m_type = cmd;
+       msg.m_link = link;
+       msg.m_len  = ((request != NULL) && (requestLen > 0)) ? requestLen : 0;
+
+       //  send the command
+       n = writen(ref, &msg, sizeof(msg));
+       if (n == -1) {
+               SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec writen() failed: %s"), strerror(errno));
+               return errno;
+       } else if (n != sizeof(msg)) {
+               SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec writen() failed: wrote=%d"), n);
+               return -1;
+       }
+
+       if ((request != NULL) && (requestLen > 0)) {
+               n = writen(ref, request, requestLen);
+               if (n == -1) {
+                       SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec writen() failed: %s"), strerror(errno));
+                       return errno;
+               } else if (n != requestLen) {
+                       SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec writen() failed: wrote=%d"), n);
+                       return -1;
+               }
+       }
+
+       // always expect a reply
+       n = readn(ref, &msg, sizeof(msg));
+       if (n == -1) {
+               SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec readn() failed: error=%s"), strerror(errno));
+               return errno;
+       } else if (n != sizeof(msg)) {
+               SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec readn() failed: insufficent data, read=%d"), n);
+               return -1;
+       }
+
+       if (msg.m_len) {
+               buf = CFAllocatorAllocate(NULL, msg.m_len, 0);
+               if (buf) {
+                       // read reply
+                       n = readn(ref, buf, msg.m_len);
+                       if (n == -1) {
+                               SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec readn() failed: error=%s"), strerror(errno));
+                               CFAllocatorDeallocate(NULL, buf);
+                               return errno;
+                       } else if (n != msg.m_len) {
+                               SCLog(_sc_verbose, LOG_ERR, CFSTR("MOHExec readn() failed: insufficent data, read=%d"), n);
+                               CFAllocatorDeallocate(NULL, buf);
+                               return -1;
+                       }
+               }
+       }
+
+       if (reply && replyLen) {
+               *reply    = buf;
+               *replyLen = msg.m_len;
+       } else if (buf) {
+               // if additional returned data is unwanted
+               CFAllocatorDeallocate(NULL, buf);
+       }
+
+       return msg.m_result;
+}
+
diff --git a/SystemConfiguration.fproj/moh.h b/SystemConfiguration.fproj/moh.h
new file mode 100644 (file)
index 0000000..57ee428
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2002 Apple Computer, 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
+ * 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.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * Modification History
+ *
+ */
+
+#ifndef _MOH_H
+#define _MOH_H
+
+#include <sys/cdefs.h>
+#include <CoreFoundation/CoreFoundation.h>
+
+__BEGIN_DECLS
+
+int
+MOHInit                (
+               int             *ref,
+               CFStringRef     deviceName
+               );
+
+int
+MOHDispose     (
+               int             ref
+               );
+
+int
+MOHExec                (int            ref,
+               u_long          link,
+               u_int32_t       cmd,
+               void            *request,
+               u_long          requestLen,
+               void            **reply,
+               u_long          *replyLen
+               );
+
+__END_DECLS
+
+#endif /* _MOH_H */
diff --git a/SystemConfiguration.fproj/moh_msg.h b/SystemConfiguration.fproj/moh_msg.h
new file mode 100644 (file)
index 0000000..0a3bc0f
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2002 Apple Computer, 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
+ * 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.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _MOH_MSG_H
+#define _MOH_MSG_H
+
+#include <sys/types.h>
+
+/* local socket path */
+#define MOH_PATH               "/tmp/.modemOnHold"
+#define CURRENT_VERSION                1
+
+/* MOH message paquets */
+struct moh_msg_hdr {
+       u_int32_t       m_type;         // type of the message
+       u_int32_t       m_result;       // error code of notification message
+       u_int32_t       m_cookie;       // user param
+       u_int32_t       m_link;         // link for this message
+       u_int32_t       m_len;          // len of the following data
+};
+
+struct moh_msg {
+       u_int32_t       m_type;         // type of the message
+       u_int32_t       m_result;       // error code of notification message
+       u_int32_t       m_cookie;       // user param, or error num for event
+       u_int32_t       m_link;         // link for this message
+       u_int32_t       m_len;          // len of the following data
+       u_char          m_data[1];      // msg data sent or received
+};
+
+/* codes for MOH messages */
+enum {
+       /* API client commands */
+       MOH_VERSION = 1,
+       MOH_DEVICE_SUPPORTS_HOLD,
+       MOH_SESSION_SUPPORTS_HOLD,
+       MOH_PUT_SESSION_ON_HOLD,
+       MOH_RESUME_SESSION_ON_HOLD,
+       MOH_SESSION_IS_ON_HOLD,
+       MOH_SESSION_GET_STATUS
+};
+
+#endif /* _MOH_MSG_H */
+
index f0c109ff6a7b0baf81fb13ee2d3232359c5f3b8b..df0586938b7d409dd44ec90fcddaae804a71bb07 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
  * @APPLE_LICENSE_HEADER_END@
  */
 
+/*
+ * Modification History
+ *
+ * Feb 28, 2002                        Christophe Allie <callie@apple.com>
+ * - socket API fixes
+ *
+ * Feb 10, 2001                        Allan Nathanson <ajn@apple.com>
+ * - cleanup API
+ *
+ * Feb 2000                    Christophe Allie <callie@apple.com>
+ * - initial revision (as ppplib.c)
+ */
+
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include "ppp_msg.h"
 #include "ppp.h"
 
+
+static int
+readn(int ref, void *data, int len)
+{
+       int     left    = len;
+       int     n;
+       void    *p      = data;
+
+       while (left > 0) {
+               if ((n = read(ref, p, left)) < 0) {
+                       if (errno != EINTR) {
+                               return -1;
+                       }
+                       n = 0;
+               } else if (n == 0) {
+                       break; /* EOF */
+               }
+
+               left -= n;
+               p += n;
+       }
+       return (len - left);
+}
+
+
+static int
+writen(int ref, void *data, int len)
+{
+       int     left    = len;
+       int     n;
+       void    *p      = data;
+
+       while (left > 0) {
+               if ((n = write(ref, p, left)) <= 0) {
+                       if (errno != EINTR) {
+                               return -1;
+                       }
+                       n = 0;
+               }
+               left -= n;
+               p += n;
+       }
+       return len;
+}
+
+
 __private_extern__
 int
 PPPInit(int *ref)
@@ -89,33 +148,25 @@ PPPExec(int                ref,
        msg.m_len  = ((request != NULL) && (requestLen > 0)) ? requestLen : 0;
 
        //  send the command
-       n = write(ref, &msg, sizeof(msg));
-       if (n == -1) {
+       if (writen(ref, &msg, sizeof(msg)) < 0) {
                SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec write() failed: %s"), strerror(errno));
                return errno;
-       } else if (n != sizeof(msg)) {
-               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec write() failed: wrote=%d"), n);
-               return -1;
        }
 
        if ((request != NULL) && (requestLen > 0)) {
-               n = write(ref, request, requestLen);
-               if (n == -1) {
+               if (writen(ref, request, requestLen) < 0) {
                        SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec write() failed: %s"), strerror(errno));
                        return errno;
-               } else if (n != requestLen) {
-                       SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec write() failed: wrote=%d"), n);
-                       return -1;
                }
        }
 
        // always expect a reply
-       n = read(ref, &msg, sizeof(msg));
+       n = readn(ref, &msg, sizeof(msg));
        if (n == -1) {
-               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec read() failed: error=%s"), strerror(errno));
+               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec readn() failed: error=%s"), strerror(errno));
                return errno;
        } else if (n != sizeof(msg)) {
-               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec read() failed: insufficent data, read=%d"), n);
+               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec readn() failed: insufficent data, read=%d"), n);
                return -1;
        }
 
@@ -123,13 +174,13 @@ PPPExec(int               ref,
                buf = CFAllocatorAllocate(NULL, msg.m_len, 0);
                if (buf) {
                        // read reply
-                       n = read(ref, buf, msg.m_len);
+                       n = readn(ref, buf, msg.m_len);
                        if (n == -1) {
-                               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec read() failed: error=%s"), strerror(errno));
+                               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec readn() failed: error=%s"), strerror(errno));
                                CFAllocatorDeallocate(NULL, buf);
                                return errno;
                        } else if (n != msg.m_len) {
-                               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec read() failed: insufficent data, read=%d"), n);
+                               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec readn() failed: insufficent data, read=%d"), n);
                                CFAllocatorDeallocate(NULL, buf);
                                return -1;
                        }
@@ -189,48 +240,6 @@ PPPDisconnect(int ref, u_long link)
 
        return status;
 }
-
-
-int
-PPPListen(int ref, u_long link)
-{
-       int     status;
-
-       status = PPPExec(ref,
-                        link,
-                        PPP_LISTEN,
-                        NULL,
-                        0,
-                        NULL,
-                        NULL);
-       if (status != 0) {
-               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec(PPP_LISTEN) failed: status = %d"), status);
-               return status;
-       }
-
-       return status;
-}
-
-
-int
-PPPApply(int ref, u_long link)
-{
-       int     status;
-
-       status = PPPExec(ref,
-                        link,
-                        PPP_APPLY,
-                        NULL,
-                        0,
-                        NULL,
-                        NULL);
-       if (status != 0) {
-               SCLog(_sc_verbose, LOG_ERR, CFSTR("PPPExec(PPP_APPLY) failed: status = %d"), status);
-               return status;
-       }
-
-       return status;
-}
 #endif /* NOT_NEEDED */
 
 
@@ -457,3 +466,31 @@ PPPStatus(int ref, u_long link, struct ppp_status **stat)
 
        return status;
 }
+
+
+#ifdef NOT_NEEDED
+__private_extern__
+int
+PPPEnableEvents(int ref, u_long link, u_char enable)
+{
+       int     status;
+
+       status = PPPExec(ref,
+                        link,
+                        enable ? PPP_ENABLE_EVENT : PPP_DISABLE_EVENT,
+                        NULL,
+                        0,
+                        NULL,
+                        NULL);
+       if (status != 0) {
+               SCLog(_sc_verbose,
+                     LOG_ERR,
+                     CFSTR("PPPExec(%s) failed: status = %d"),
+                     enable ? "PPP_ENABLE_EVENT" : "PPP_DISABLE_EVENT",
+                     status);
+               return status;
+       }
+
+       return status;
+}
+#endif /* NOT_NEEDED */
index 33eee1835372216d513f89753bb4b5b2eb373452..c1d18f800bf1c7c1d330b4547d760ee4c531ab5d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
  * @APPLE_LICENSE_HEADER_END@
  */
 
+/*
+ * Modification History
+ *
+ * Feb 10, 2001                        Allan Nathanson <ajn@apple.com>
+ * - cleanup API
+ *
+ * Feb 2000                    Christophe Allie <callie@apple.com>
+ * - initial revision (as ppplib.h)
+ */
+
 #ifndef _PPP_H
 #define _PPP_H
 
@@ -47,12 +57,6 @@ int          PPPConnect              (int                    ref,
 
 int            PPPDisconnect           (int                    ref,
                                         u_long                 link);
-
-int            PPPListen               (int                    ref,
-                                        u_long                 link);
-
-int            PPPApply                (int                    ref,
-                                        u_long                 link);
 #endif /* NOT_NEEDED */
 
 int            PPPGetNumberOfLinks     (int                    ref,
@@ -84,6 +88,12 @@ int          PPPStatus               (int                    ref,
                                         u_long                 link,
                                         struct ppp_status      **stat);
 
+#ifdef NOT_NEEDED
+int            PPPEnableEvents         (int                    ref,
+                                        u_long                 link,
+                                        u_char                 enable);
+#endif /* NOT_NEEDED */
+
 __END_DECLS
 
 #endif /* _PPP_H */
index 106817d37508a8de7a079ac677cc73202ed23e28..6d6d002ca1968b679aa770d9d6fc760a7fa7429e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -168,7 +168,9 @@ enum {
     PPP_NETWORK,
     PPP_RUNNING,
     PPP_TERMINATE,
-    PPP_DISCONNECTLINK
+    PPP_DISCONNECTLINK,
+    PPP_HOLDOFF,
+    PPP_ONHOLD
 };
 
 // events
index 1579d6fe0bfcedd85caa378d1553ad1c43d4c732..c7e4f8dcfb008527fdcd870aac4beeee3b3ceb11 100644 (file)
@@ -40,7 +40,6 @@ DEBUG_LIBS = $(LIBS)
 PROF_LIBS = $(LIBS)
 
 
-NEXTSTEP_PB_CFLAGS = -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS
 FRAMEWORKS = -framework CoreFoundation -framework SystemConfiguration
 
 
index b5e755703d6eec9e5181d160c6befee2ff41edf4..027ceaaf5f998aa2719d2f796a4ca9986e886b62 100644 (file)
@@ -136,6 +136,7 @@ OTHER_GENERATED_OFILES = $(VERS_OFILE)
 # and "" on other systems.
 # DSTROOT = $(HOME)
 
-# Additional flags (MiG generated files)
+# Additional flags (for MiG generated files)
+ALL_MIGFLAGS = -F$(SYMROOT)
 OTHER_OFILES = configServer.o
 
index 225a4c547cad170100c83cd78452bc4f57514c06..6534995ecbad8481ec8e82e2f0940eceec474f61 100644 (file)
@@ -1,77 +1,76 @@
 {
-    DYNAMIC_CODE_GEN = YES; 
+    "DYNAMIC_CODE_GEN" = YES; 
     FILESTABLE = {
-        FRAMEWORKS = (CoreFoundation.framework, SystemConfiguration.framework); 
+        FRAMEWORKS = ("CoreFoundation.framework", "SystemConfiguration.framework"); 
         FRAMEWORKSEARCH = (); 
         HEADERSEARCH = (); 
-        H_FILES = (
-            configd.h
-            _SCD.h
-            configd_server.h
-            notify_server.h
-            plugin_support.h
-            session.h
-            notify.h
+        "H_FILES" = (
+            "configd.h"
+            "_SCD.h"
+            "configd_server.h"
+            "notify_server.h"
+            "plugin_support.h"
+            "session.h"
+            "notify.h"
         ); 
-        OTHER_LIBS = (objc); 
-        OTHER_LINKED = (
-            configd.m
-            _SCD.c
-            configd_server.c
-            notify_server.c
-            plugin_support.c
-            session.c
-            notify.c
-            _configopen.c
-            _configclose.c
-            _configlock.c
-            _configunlock.c
-            _configlist.c
-            _configadd.c
-            _configadd_s.c
-            _configget.c
-            _configset.c
-            _configremove.c
-            _configtouch.c
-            _confignotify.c
-            _notifyadd.c
-            _notifyremove.c
-            _notifychanges.c
-            _notifyviaport.c
-            _notifyviafd.c
-            _notifyviasignal.c
-            _notifycancel.c
-            _snapshot.c
+        "OTHER_LIBS" = (objc); 
+        "OTHER_LINKED" = (
+            "configd.m"
+            "_SCD.c"
+            "configd_server.c"
+            "notify_server.c"
+            "plugin_support.c"
+            "session.c"
+            "notify.c"
+            "_configopen.c"
+            "_configclose.c"
+            "_configlock.c"
+            "_configunlock.c"
+            "_configlist.c"
+            "_configadd.c"
+            "_configadd_s.c"
+            "_configget.c"
+            "_configset.c"
+            "_configremove.c"
+            "_configtouch.c"
+            "_confignotify.c"
+            "_notifyadd.c"
+            "_notifyremove.c"
+            "_notifychanges.c"
+            "_notifyviaport.c"
+            "_notifyviafd.c"
+            "_notifyviasignal.c"
+            "_notifycancel.c"
+            "_snapshot.c"
         ); 
-        OTHER_SOURCES = (
-            Makefile.preamble
+        "OTHER_SOURCES" = (
+            "Makefile.preamble"
             Makefile, 
-            Makefile.postamble
-            m.template
-            h.template
-            config.defs
+            "Makefile.postamble"
+            "m.template"
+            "h.template"
+            "config.defs"
         ); 
-        PRECOMPILED_HEADERS = (); 
-        PROJECT_HEADERS = (); 
-        PUBLIC_HEADERS = (); 
+        "PRECOMPILED_HEADERS" = (); 
+        "PROJECT_HEADERS" = (); 
+        "PUBLIC_HEADERS" = (); 
         SUBPROJECTS = (); 
     }; 
     LANGUAGE = English; 
     MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; 
-    NEXTSTEP_BUILDTOOL = /usr/bin/gnumake; 
-    NEXTSTEP_COMPILEROPTIONS = "-DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS"; 
-    NEXTSTEP_INSTALLDIR = /usr/sbin; 
-    NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; 
-    NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; 
-    PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; 
-    PDO_UNIX_INSTALLDIR = /bin; 
-    PDO_UNIX_JAVA_COMPILER = "$(JDKBINDIR)/javac"; 
-    PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; 
+    "NEXTSTEP_BUILDTOOL" = "/usr/bin/gnumake"; 
+    "NEXTSTEP_INSTALLDIR" = "/usr/sbin"; 
+    "NEXTSTEP_JAVA_COMPILER" = "/usr/bin/javac"; 
+    "NEXTSTEP_OBJCPLUS_COMPILER" = "/usr/bin/cc"; 
+    "PDO_UNIX_BUILDTOOL" = "$NEXT_ROOT/Developer/bin/make"; 
+    "PDO_UNIX_INSTALLDIR" = "/bin"; 
+    "PDO_UNIX_JAVA_COMPILER" = "$(JDKBINDIR)/javac"; 
+    "PDO_UNIX_OBJCPLUS_COMPILER" = "$(NEXTDEV_BIN)/gcc"; 
     PROJECTNAME = configd; 
     PROJECTTYPE = Tool; 
-    PROJECTVERSION = 2.8
-    WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make
-    WINDOWS_INSTALLDIR = /Library/Executables
-    WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; 
-    WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; 
+    PROJECTVERSION = "2.8"
+    "WINDOWS_BUILDTOOL" = "$NEXT_ROOT/Developer/Executables/make"
+    "WINDOWS_INSTALLDIR" = "/Library/Executables"
+    "WINDOWS_JAVA_COMPILER" = "$(JDKBINDIR)/javac.exe"; 
+    "WINDOWS_OBJCPLUS_COMPILER" = "$(DEVDIR)/gcc"; 
 }
index 5d024af02f210fe7ca0b8527e15ca50bbcaef688..b087f8db31f9fb9e59f6739a0d13a2ea97e13677 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -188,7 +188,7 @@ _addRegexWatcherByKey(const void *key, void *val, void *context)
        char            reErrBuf[256];
        int             reErrStrLen;
 
-       if (CFDictionaryContainsKey(info, kSCDData) == FALSE) {
+       if (!CFDictionaryContainsKey(info, kSCDData)) {
                /* if no data (yet) */
                return;
        }
@@ -228,7 +228,7 @@ _addRegexWatcherByKey(const void *key, void *val, void *context)
  *
  * This is a CFDictionaryApplierFunction which will iterate over each session
  * defined in the "sessionData" dictionary. The arguments are the session
- * key, it's associated session dictionary, and the store key being added.
+ * key, it's associated session dictionary, and the store key being added.
  *
  * If an active session includes any regular expression keys which match the
  * key being added to the "storeData" dictionary then we mark this key as being
@@ -246,11 +246,6 @@ _addRegexWatchersBySession(const void *key, void *val, void *context)
        CFArrayRef      rData;
        CFIndex         i;
 
-       if (info == NULL) {
-               /* if no dictionary for this session */
-               return;
-       }
-
        rKeys = CFDictionaryGetValue(info, kSCDRegexKeys);
        if (rKeys == NULL) {
                /* if no regex keys for this session */
@@ -418,8 +413,8 @@ _removeRegexWatcherByKey(const void *key, void *val, void *context)
        char            reErrBuf[256];
        int             reErrStrLen;
 
-       if ((info == NULL) || (CFDictionaryContainsKey(info, kSCDWatchers) == FALSE)) {
-               /* no dictionary or no watchers */
+       if (CFDictionaryContainsKey(info, kSCDWatchers) == FALSE) {
+               /* if no watchers */
                return;
        }
 
@@ -487,11 +482,6 @@ _removeRegexWatchersBySession(const void *key, void *val, void *context)
        CFArrayRef      rData;
        CFIndex         i;
 
-       if (info == NULL) {
-               /* if no dictionary for this session */
-               return;
-       }
-
        rKeys = CFDictionaryGetValue(info, kSCDRegexKeys);
        if (rKeys == NULL) {
                /* if no regex keys for this session */
index d06abd15468db3f6371f5113f4696c546c39a5b2..df828b7a1fad9cb027389c90eba65e6cea4b94b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -101,13 +101,9 @@ _configadd(mach_port_t                     server,
           int                          *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFDataRef               xmlData;        /* data (XML serialized) */
        CFPropertyListRef       data;           /* data (un-serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Add key to configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
@@ -115,50 +111,20 @@ _configadd(mach_port_t                    server,
        *sc_status = kSCStatusOK;
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
                *sc_status = kSCStatusInvalidArgument;
        }
 
        /* un-serialize the data */
-       xmlData = CFDataCreate(NULL, dataRef, dataLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)dataRef, dataLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       data = CFPropertyListCreateFromXMLData(NULL,
-                                              xmlData,
-                                              kCFPropertyListImmutable,
-                                              &xmlError);
-       CFRelease(xmlData);
-       if (!data) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() data: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&data, (void *)dataRef, dataLen)) {
                *sc_status = kSCStatusFailed;
-       } else if (!isA_CFPropertyList(data)) {
+       }
+
+       if (!isA_CFPropertyList(data)) {
                *sc_status = kSCStatusInvalidArgument;
        }
 
index c09c478f73793fdcebec9b37f7173fcd179a9d6d..8c369b97cc6f5a260dd10bc43653f93c32bbe714 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -120,13 +120,9 @@ _configadd_s(mach_port_t           server,
             int                        *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFDataRef               xmlData;        /* data (XML serialized) */
        CFPropertyListRef       data;           /* data (un-serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Add (session) key to configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
@@ -134,50 +130,20 @@ _configadd_s(mach_port_t          server,
        *sc_status = kSCStatusOK;
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
                *sc_status = kSCStatusInvalidArgument;
        }
 
        /* un-serialize the data */
-       xmlData = CFDataCreate(NULL, dataRef, dataLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)dataRef, dataLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       data = CFPropertyListCreateFromXMLData(NULL,
-                                              xmlData,
-                                              kCFPropertyListImmutable,
-                                              &xmlError);
-       CFRelease(xmlData);
-       if (!data) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() data: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&data, (void *)dataRef, dataLen)) {
                *sc_status = kSCStatusFailed;
-       } else if (!isA_CFPropertyList(data)) {
+       }
+
+       if (!isA_CFPropertyList(data)) {
                *sc_status = kSCStatusInvalidArgument;
        }
 
index d623f85e857a11f1500c2f1d06915f484459a545..810420ccd356cef85d69a4dd15aeb989e659d70f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -79,8 +79,9 @@ __SCDynamicStoreClose(SCDynamicStoreRef *store)
        }
 
        /* Remove notification keys */
-       if ((keyCnt = CFSetGetCount(storePrivate->keys)) > 0) {
-               void            **watchedKeys;
+       keyCnt = CFSetGetCount(storePrivate->keys);
+       if (keyCnt > 0) {
+               const void      **watchedKeys;
                CFArrayRef      keysToRemove;
                CFIndex         i;
 
@@ -97,8 +98,9 @@ __SCDynamicStoreClose(SCDynamicStoreRef *store)
        }
 
        /* Remove regex notification keys */
-       if ((keyCnt = CFSetGetCount(storePrivate->reKeys)) > 0) {
-               void            **watchedKeys;
+       keyCnt = CFSetGetCount(storePrivate->reKeys);
+       if (keyCnt > 0) {
+               const void      **watchedKeys;
                CFArrayRef      keysToRemove;
                CFIndex         i;
 
index 48bab882daf3047305c19ea13efe1c541961a4cf..c51edd33d1b40d545477b97df72c36ef9bbe09d5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -70,39 +70,25 @@ _configget(mach_port_t                      server,
           int                          *sc_status
 )
 {
-       kern_return_t           status;
-       serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFDataRef               xmlData;        /* data (XML serialized) */
+       serverSessionRef        mySession = getSession(server);
+       Boolean                 ok;
        CFPropertyListRef       value;
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Get key from configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
+       *dataRef = NULL;
+       *dataLen = 0;
+
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
+               CFRelease(key);
                *sc_status = kSCStatusInvalidArgument;
                return KERN_SUCCESS;
        }
@@ -110,31 +96,17 @@ _configget(mach_port_t                     server,
        *sc_status = __SCDynamicStoreCopyValue(mySession->store, key, &value);
        CFRelease(key);
        if (*sc_status != kSCStatusOK) {
-               *dataRef = NULL;
-               *dataLen = 0;
                return KERN_SUCCESS;
        }
 
-       /*
-        * serialize the data, copy it into an allocated buffer which will be
-        * released when it is returned as part of a Mach message.
-        */
-       xmlData = CFPropertyListCreateXMLData(NULL, value);
+       /* serialize the data */
+       ok = _SCSerialize(value, NULL, (void **)dataRef, (CFIndex *)dataLen);
        CFRelease(value);
-       *dataLen = CFDataGetLength(xmlData);
-       status = vm_allocate(mach_task_self(), (void *)dataRef, *dataLen, TRUE);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status));
+       if (!ok) {
                *sc_status = kSCStatusFailed;
-               CFRelease(xmlData);
-               *dataRef = NULL;
-               *dataLen = 0;
                return KERN_SUCCESS;
        }
 
-       bcopy((char *)CFDataGetBytePtr(xmlData), *dataRef, *dataLen);
-       CFRelease(xmlData);
-
        /*
         * return the instance number associated with the returned data.
         */
@@ -206,72 +178,37 @@ _configget_m(mach_port_t          server,
             mach_msg_type_number_t     *dataLen,
             int                        *sc_status)
 {
-       kern_return_t           status;
-       serverSessionRef        mySession = getSession(server);
        CFArrayRef              keys            = NULL; /* keys (un-serialized) */
-       CFArrayRef              patterns        = NULL; /* patterns (un-serialized) */
-       CFDataRef               xmlData;                /* data (XML serialized) */
        addSpecific             myContext;
+       serverSessionRef        mySession       = getSession(server);
+       Boolean                 ok;
+       CFArrayRef              patterns        = NULL; /* patterns (un-serialized) */
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Get key from configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
+       *dataRef = NULL;
+       *dataLen = 0;
        *sc_status = kSCStatusOK;
 
        if (keysRef && (keysLen > 0)) {
-               CFDataRef       xmlKeys;                /* keys (XML serialized) */
-               CFStringRef     xmlError;
-
                /* un-serialize the keys */
-               xmlKeys = CFDataCreate(NULL, keysRef, keysLen);
-               status = vm_deallocate(mach_task_self(), (vm_address_t)keysRef, keysLen);
-               if (status != KERN_SUCCESS) {
-                       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-                       /* non-fatal???, proceed */
-               }
-               keys = CFPropertyListCreateFromXMLData(NULL,
-                                                      xmlKeys,
-                                                      kCFPropertyListImmutable,
-                                                      &xmlError);
-               CFRelease(xmlKeys);
-               if (!keys) {
-                       if (xmlError) {
-                               SCLog(_configd_verbose, LOG_DEBUG,
-                                      CFSTR("CFPropertyListCreateFromXMLData() keys: %@"),
-                                      xmlError);
-                               CFRelease(xmlError);
-                       }
+               if (!_SCUnserialize((CFPropertyListRef *)&keys, (void *)keysRef, keysLen)) {
                        *sc_status = kSCStatusFailed;
-               } else if (!isA_CFArray(keys)) {
+               }
+
+               if (!isA_CFArray(keys)) {
                        *sc_status = kSCStatusInvalidArgument;
                }
        }
 
        if (patternsRef && (patternsLen > 0)) {
-               CFDataRef       xmlPatterns;            /* patterns (XML serialized) */
-               CFStringRef     xmlError;
-
                /* un-serialize the patterns */
-               xmlPatterns = CFDataCreate(NULL, patternsRef, patternsLen);
-               status = vm_deallocate(mach_task_self(), (vm_address_t)patternsRef, patternsLen);
-               if (status != KERN_SUCCESS) {
-                       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-                       /* non-fatal???, proceed */
-               }
-               patterns = CFPropertyListCreateFromXMLData(NULL,
-                                                          xmlPatterns,
-                                                          kCFPropertyListImmutable,
-                                                          &xmlError);
-               CFRelease(xmlPatterns);
-               if (!patterns) {
-                       if (xmlError) {
-                               SCLog(_configd_verbose, LOG_DEBUG,
-                                      CFSTR("CFPropertyListCreateFromXMLData() patterns: %@"),
-                                      xmlError);
-                               CFRelease(xmlError);
-                       }
+               if (!_SCUnserialize((CFPropertyListRef *)&patterns, (void *)patternsRef, patternsLen)) {
                        *sc_status = kSCStatusFailed;
-               } else if (!isA_CFArray(patterns)) {
+               }
+
+               if (!isA_CFArray(patterns)) {
                        *sc_status = kSCStatusInvalidArgument;
                }
        }
@@ -279,8 +216,6 @@ _configget_m(mach_port_t            server,
        if (*sc_status != kSCStatusOK) {
                if (keys)       CFRelease(keys);
                if (patterns)   CFRelease(patterns);
-               *dataRef = NULL;
-               *dataLen = 0;
                return KERN_SUCCESS;
        }
 
@@ -306,26 +241,13 @@ _configget_m(mach_port_t          server,
                CFRelease(patterns);
        }
 
-       /*
-        * serialize the dictionary of matching keys/patterns, copy it into an
-        * allocated buffer which will be released when it is returned as part
-        * of a Mach message.
-        */
-       xmlData = CFPropertyListCreateXMLData(NULL, myContext.dict);
+       /* serialize the dictionary of matching keys/patterns */
+       ok = _SCSerialize(myContext.dict, NULL, (void **)dataRef, (CFIndex *)dataLen);
        CFRelease(myContext.dict);
-       *dataLen = CFDataGetLength(xmlData);
-       status = vm_allocate(mach_task_self(), (void *)dataRef, *dataLen, TRUE);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status));
+       if (!ok) {
                *sc_status = kSCStatusFailed;
-               CFRelease(xmlData);
-               *dataRef = NULL;
-               *dataLen = 0;
                return KERN_SUCCESS;
        }
 
-       bcopy((char *)CFDataGetBytePtr(xmlData), *dataRef, *dataLen);
-       CFRelease(xmlData);
-
        return KERN_SUCCESS;
 }
index 6613f8af7dd8e9df4835cde3c448dbe8a2d0b99f..da7a970ac6a9b82b00f373b0a3e89998ae8330e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -38,8 +38,8 @@ __SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef key, Boolean is
 {
        SCDynamicStorePrivateRef        storePrivate = (SCDynamicStorePrivateRef)store;
        CFIndex                         storeCnt;
-       void                            **storeKeys;
-       void                            **storeValues;
+       const void                      **storeKeys;
+       const void                      **storeValues;
        CFMutableArrayRef               keyArray;
        int                             i;
        CFStringRef                     storeStr;
@@ -85,7 +85,7 @@ __SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef key, Boolean is
                 * compile the provided regular expression using the
                 * provided isRegex.
                 */
-               regexBufLen = CFStringGetLength(regexStr)+1;
+               regexBufLen = CFStringGetLength(regexStr) + 1;
                regexBuf    = CFAllocatorAllocate(NULL, regexBufLen, 0);
                ok = CFStringGetCString(regexStr, regexBuf, regexBufLen, kCFStringEncodingMacRoman);
                CFRelease(regexStr);
@@ -108,66 +108,68 @@ __SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef key, Boolean is
                }
        }
 
-       storeKeys   = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0);
-       storeValues = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0);
-       CFDictionaryGetKeysAndValues(storeData, storeKeys, storeValues);
-       for (i=0; i<storeCnt; i++) {
-               storeStr   = (CFStringRef)storeKeys[i];
-               storeValue = (CFDictionaryRef)storeValues[i];
-               if (isRegex) {
-                       /*
-                        * only return those keys which match the regular
-                        * expression specified in the provided key.
-                        */
-
-                       int     storeKeyLen = CFStringGetLength(storeStr) + 1;
-                       char    *storeKey   = CFAllocatorAllocate(NULL, storeKeyLen, 0);
-
-                       if (!CFStringGetCString(storeStr,
-                                               storeKey,
-                                               storeKeyLen,
-                                               kCFStringEncodingMacRoman)) {
-                               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("CFStringGetCString: could not convert store key to C string"));
+       if (storeCnt > 0) {
+               storeKeys   = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0);
+               storeValues = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0);
+               CFDictionaryGetKeysAndValues(storeData, storeKeys, storeValues);
+               for (i=0; i<storeCnt; i++) {
+                       storeStr   = (CFStringRef)storeKeys[i];
+                       storeValue = (CFDictionaryRef)storeValues[i];
+                       if (isRegex) {
+                               /*
+                                * only return those keys which match the regular
+                                * expression specified in the provided key.
+                                */
+
+                               int     storeKeyLen = CFStringGetLength(storeStr) + 1;
+                               char    *storeKey   = CFAllocatorAllocate(NULL, storeKeyLen, 0);
+
+                               if (!CFStringGetCString(storeStr,
+                                                       storeKey,
+                                                       storeKeyLen,
+                                                       kCFStringEncodingMacRoman)) {
+                                       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("CFStringGetCString: could not convert store key to C string"));
+                                       CFAllocatorDeallocate(NULL, storeKey);
+                                       continue;
+                               }
+
+                               reError = regexec(&preg,
+                                                 storeKey,
+                                                 0,
+                                                 NULL,
+                                                 0);
+                               switch (reError) {
+                                       case 0 :
+                                               /* we've got a match */
+                                               if (CFDictionaryContainsKey(storeValue, kSCDData))
+                                                       CFArrayAppendValue(keyArray, storeStr);
+                                               break;
+                                       case REG_NOMATCH :
+                                               /* no match */
+                                               break;
+                                       default :
+                                               reErrStrLen = regerror(reError,
+                                                                      &preg,
+                                                                      reErrBuf,
+                                                                      sizeof(reErrBuf));
+                                               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("regexec(): %s"), reErrBuf);
+                                               break;
+                               }
                                CFAllocatorDeallocate(NULL, storeKey);
-                               continue;
-                       }
-
-                       reError = regexec(&preg,
-                                         storeKey,
-                                         0,
-                                         NULL,
-                                         0);
-                       switch (reError) {
-                               case 0 :
-                                       /* we've got a match */
-                                       if (CFDictionaryContainsKey(storeValue, kSCDData))
-                                               CFArrayAppendValue(keyArray, storeStr);
-                                       break;
-                               case REG_NOMATCH :
-                                       /* no match */
-                                       break;
-                               default :
-                                       reErrStrLen = regerror(reError,
-                                                              &preg,
-                                                              reErrBuf,
-                                                              sizeof(reErrBuf));
-                                       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("regexec(): %s"), reErrBuf);
-                                       break;
-                       }
-                       CFAllocatorDeallocate(NULL, storeKey);
-               } else {
-                       /*
-                        * only return those keys which are prefixed by the
-                        * provided key string and have data.
-                        */
-                       if (((CFStringGetLength(key) == 0) || CFStringHasPrefix(storeStr, key)) &&
-                           CFDictionaryContainsKey(storeValue, kSCDData)) {
-                               CFArrayAppendValue(keyArray, storeStr);
+                       } else {
+                               /*
+                                * only return those keys which are prefixed by the
+                                * provided key string and have data.
+                                */
+                               if (((CFStringGetLength(key) == 0) || CFStringHasPrefix(storeStr, key)) &&
+                                   CFDictionaryContainsKey(storeValue, kSCDData)) {
+                                       CFArrayAppendValue(keyArray, storeStr);
+                               }
                        }
                }
+               CFAllocatorDeallocate(NULL, storeKeys);
+               CFAllocatorDeallocate(NULL, storeValues);
        }
-       CFAllocatorDeallocate(NULL, storeKeys);
-       CFAllocatorDeallocate(NULL, storeValues);
 
        if (isRegex) {
                regfree(&preg);
@@ -190,13 +192,10 @@ _configlist(mach_port_t                   server,
            int                         *sc_status
 )
 {
-       kern_return_t           status;
-       serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
+       serverSessionRef        mySession = getSession(server);
+       Boolean                 ok;
        CFArrayRef              subKeys;        /* array of CFStringRef's */
-       CFDataRef               xmlList;        /* list (XML serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("List keys in configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
@@ -205,27 +204,12 @@ _configlist(mach_port_t                   server,
        *listLen = 0;
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
                CFRelease(key);
                *sc_status = kSCStatusInvalidArgument;
                return KERN_SUCCESS;
@@ -237,24 +221,13 @@ _configlist(mach_port_t                   server,
                return KERN_SUCCESS;
        }
 
-       /*
-        * serialize the array, copy it into an allocated buffer which will be
-        * released when it is returned as part of a Mach message.
-        */
-       xmlList = CFPropertyListCreateXMLData(NULL, subKeys);
+       /* serialize the list of keys */
+       ok = _SCSerialize(subKeys, NULL, (void **)listRef, (CFIndex *)listLen);
        CFRelease(subKeys);
-       *listLen = CFDataGetLength(xmlList);
-       status = vm_allocate(mach_task_self(), (void *)listRef, *listLen, TRUE);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status));
+       if (!ok) {
                *sc_status = kSCStatusFailed;
-               CFRelease(xmlList);
-               *listRef = NULL;
-               *listLen = 0;
                return KERN_SUCCESS;
        }
-       bcopy((char *)CFDataGetBytePtr(xmlList), *listRef, *listLen);
-       CFRelease(xmlList);
 
        return KERN_SUCCESS;
 }
index 8c6e262ad11ca2e87cc3733830196673bd895288..c45b083e25c55b31714900c179b21127470b2eb9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -58,7 +58,7 @@ __SCDynamicStoreNotifyValue(SCDynamicStoreRef store, CFStringRef key)
         * 2. Tickle the value in the dynamic store
         */
        dict = CFDictionaryGetValue(storeData, key);
-       if (!dict || !CFDictionaryGetValueIfPresent(dict, kSCDData, (void **)&value)) {
+       if (!dict || !CFDictionaryGetValueIfPresent(dict, kSCDData, (const void **)&value)) {
                /* key doesn't exist (or data never defined) */
                value = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
                newValue = TRUE;
@@ -89,37 +89,20 @@ _confignotify(mach_port_t           server,
              int                       *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Notify key in configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
-               *sc_status = kSCStatusFailed;
-               return KERN_SUCCESS;
-       } else if (!isA_CFString(key)) {
+        if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
+                *sc_status = kSCStatusFailed;
+                return KERN_SUCCESS;
+        }
+
+       if (!isA_CFString(key)) {
+               CFRelease(key);
                *sc_status = kSCStatusInvalidArgument;
                return KERN_SUCCESS;
        }
index f462ee9cd90ba23b678e1edd45c76d20b549f88b..0b6e6ad92496dca03e43626acc42f5e83cac08e2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -81,9 +81,7 @@ _configopen(mach_port_t                       server,
 {
        kern_return_t           status;
        serverSessionRef        mySession, newSession;
-       CFDataRef               xmlName;        /* name (XML serialized) */
        CFStringRef             name;           /* name (un-serialized) */
-       CFStringRef             xmlError;
        mach_port_t             oldNotify;
        CFStringRef             sessionKey;
        CFDictionaryRef         info;
@@ -94,28 +92,12 @@ _configopen(mach_port_t                     server,
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
        /* un-serialize the name */
-       xmlName = CFDataCreate(NULL, nameRef, nameLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)nameRef, nameLen);
-       if (status != KERN_SUCCESS) {
-               CFRelease(xmlName);
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       name = CFPropertyListCreateFromXMLData(NULL,
-                                              xmlName,
-                                              kCFPropertyListImmutable,
-                                              &xmlError);
-       CFRelease(xmlName);
-       if (!name) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() name: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&name, (void *)nameRef, nameLen)) {
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
-       } else if (!isA_CFString(name)) {
+       }
+
+       if (!isA_CFString(name)) {
                CFRelease(name);
                *sc_status = kSCStatusInvalidArgument;
                return KERN_SUCCESS;
index a496571f77bc8249bc4816cd40e59139cf01674f..c48844cb56dc7aff68b8fed23fa8a8e25dfb7a4b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -130,37 +130,20 @@ _configremove(mach_port_t         server,
              int                       *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Remove key from configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
+               CFRelease(key);
                *sc_status = kSCStatusInvalidArgument;
                return KERN_SUCCESS;
        }
index 0b432608ae0088d78baee416da22cbdd9e4152af..1f80c7997671ae61ba253986e271efb9d6cc00c4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -154,13 +154,9 @@ _configset(mach_port_t                     server,
           int                          *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFDataRef               xmlData;        /* data (XML serialized) */
        CFPropertyListRef       data;           /* data (un-serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Set key to configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
@@ -168,50 +164,20 @@ _configset(mach_port_t                    server,
        *sc_status = kSCStatusOK;
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
                *sc_status = kSCStatusInvalidArgument;
        }
 
        /* un-serialize the data */
-       xmlData = CFDataCreate(NULL, dataRef, dataLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)dataRef, dataLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       data = CFPropertyListCreateFromXMLData(NULL,
-                                              xmlData,
-                                              kCFPropertyListImmutable,
-                                              &xmlError);
-       CFRelease(xmlData);
-       if (!data) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() data: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&data, (void *)dataRef, dataLen)) {
                *sc_status = kSCStatusFailed;
-       } else if (!isA_CFPropertyList(data)) {
+       }
+
+       if (!isA_CFPropertyList(data)) {
                *sc_status = kSCStatusInvalidArgument;
        }
 
@@ -290,7 +256,6 @@ _configset_m(mach_port_t            server,
             mach_msg_type_number_t     notifyLen,
             int                        *sc_status)
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
        CFDictionaryRef         dict    = NULL;         /* key/value dictionary (un-serialized) */
        CFArrayRef              remove  = NULL;         /* keys to remove (un-serialized) */
@@ -302,88 +267,34 @@ _configset_m(mach_port_t          server,
        *sc_status = kSCStatusOK;
 
        if (dictRef && (dictLen > 0)) {
-               CFDataRef       xmlDict;        /* key/value dictionary (XML serialized) */
-               CFStringRef     xmlError;
-
                /* un-serialize the key/value pairs to set */
-               xmlDict = CFDataCreate(NULL, dictRef, dictLen);
-               status = vm_deallocate(mach_task_self(), (vm_address_t)dictRef, dictLen);
-               if (status != KERN_SUCCESS) {
-                       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-                       /* non-fatal???, proceed */
-               }
-               dict = CFPropertyListCreateFromXMLData(NULL,
-                                                      xmlDict,
-                                                      kCFPropertyListImmutable,
-                                                      &xmlError);
-               CFRelease(xmlDict);
-               if (!dict) {
-                       if (xmlError) {
-                               SCLog(_configd_verbose, LOG_DEBUG,
-                                      CFSTR("CFPropertyListCreateFromXMLData() dict: %@"),
-                                      xmlError);
-                               CFRelease(xmlError);
-                       }
+               if (!_SCUnserialize((CFPropertyListRef *)&dict, (void *)dictRef, dictLen)) {
                        *sc_status = kSCStatusFailed;
-               } else if (!isA_CFDictionary(dict)) {
+               }
+
+               if (!isA_CFDictionary(dict)) {
                        *sc_status = kSCStatusInvalidArgument;
                }
        }
 
        if (removeRef && (removeLen > 0)) {
-               CFDataRef       xmlRemove;      /* keys to remove (XML serialized) */
-               CFStringRef     xmlError;
-
                /* un-serialize the keys to remove */
-               xmlRemove = CFDataCreate(NULL, removeRef, removeLen);
-               status = vm_deallocate(mach_task_self(), (vm_address_t)removeRef, removeLen);
-               if (status != KERN_SUCCESS) {
-                       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-                       /* non-fatal???, proceed */
-               }
-               remove = CFPropertyListCreateFromXMLData(NULL,
-                                                        xmlRemove,
-                                                        kCFPropertyListImmutable,
-                                                        &xmlError);
-               CFRelease(xmlRemove);
-               if (!remove) {
-                       if (xmlError) {
-                               SCLog(_configd_verbose, LOG_DEBUG,
-                                      CFSTR("CFPropertyListCreateFromXMLData() remove: %@"),
-                                      xmlError);
-                               CFRelease(xmlError);
-                       }
+               if (!_SCUnserialize((CFPropertyListRef *)&remove, (void *)removeRef, removeLen)) {
                        *sc_status = kSCStatusFailed;
-               } else if (!isA_CFArray(remove)) {
+               }
+
+               if (!isA_CFArray(remove)) {
                        *sc_status = kSCStatusInvalidArgument;
                }
        }
 
        if (notifyRef && (notifyLen > 0)) {
-               CFDataRef       xmlNotify;      /* keys to notify (XML serialized) */
-               CFStringRef     xmlError;
-
                /* un-serialize the keys to notify */
-               xmlNotify = CFDataCreate(NULL, notifyRef, notifyLen);
-               status = vm_deallocate(mach_task_self(), (vm_address_t)notifyRef, notifyLen);
-               if (status != KERN_SUCCESS) {
-                       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-                       /* non-fatal???, proceed */
-               }
-               notify = CFPropertyListCreateFromXMLData(NULL,
-                                                      xmlNotify,
-                                                      kCFPropertyListImmutable,
-                                                      &xmlError);
-               CFRelease(xmlNotify);
-               if (!notify) {
-                       if (xmlError) {
-                               SCLog(_configd_verbose, LOG_DEBUG,
-                                      CFSTR("CFPropertyListCreateFromXMLData() notify: %@"),
-                                      xmlError);
-                               CFRelease(xmlError);
-                       }
+               if (!_SCUnserialize((CFPropertyListRef *)&notify, (void *)notifyRef, notifyLen)) {
                        *sc_status = kSCStatusFailed;
-               } else if (!isA_CFArray(notify)) {
+               }
+
+               if (!isA_CFArray(notify)) {
                        *sc_status = kSCStatusInvalidArgument;
                }
        }
index f241ad839f74f34dd651b2b2f6ef297bd0bf03a0..6835fbe9bdacf37388f0dcb5496520820e61ff5c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -70,7 +70,7 @@ __SCDynamicStoreTouchValue(SCDynamicStoreRef store, CFStringRef key)
 
                case kSCStatusOK :
                        /* store entry exists */
-                       if (CFGetTypeID(value) == CFDateGetTypeID()) {
+                       if (isA_CFDate(value)) {
                                /* the value is a CFDate, update the time stamp */
                                CFRelease(value);
                                value = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
@@ -108,37 +108,20 @@ _configtouch(mach_port_t          server,
             int                        *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Touch key in configuration database."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
+               CFRelease(key);
                *sc_status = kSCStatusInvalidArgument;
                return KERN_SUCCESS;
        }
index 8cf247a6d7a52ab465c6af362b0c9dcaab61d55f..77a1d321eb13b924940a608c40c5f393f3497298 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -40,9 +40,10 @@ static void
 _notifyWatchers()
 {
        CFIndex                 keyCnt;
-       void                    **keys;
+       const void              **keys;
 
-       if ((keyCnt = CFSetGetCount(changedKeys)) == 0)
+       keyCnt = CFSetGetCount(changedKeys);
+       if (keyCnt == 0)
                return;         /* if nothing to do */
 
        keys = CFAllocatorAllocate(NULL, keyCnt * sizeof(CFStringRef), 0);
@@ -51,7 +52,7 @@ _notifyWatchers()
                CFDictionaryRef         dict;
                CFArrayRef              sessionsWatchingKey;
                CFIndex                 watcherCnt;
-               void                    **watchers;
+               const void              **watchers;
                CFDictionaryRef         info;
                CFMutableDictionaryRef  newInfo;
                CFArrayRef              changes;
@@ -69,52 +70,54 @@ _notifyWatchers()
                 */
                sessionsWatchingKey = CFDictionaryGetValue(dict, kSCDWatchers);
                watcherCnt = CFArrayGetCount(sessionsWatchingKey);
-               watchers   = CFAllocatorAllocate(NULL, watcherCnt * sizeof(CFNumberRef), 0);
-               CFArrayGetValues(sessionsWatchingKey,
-                                CFRangeMake(0, CFArrayGetCount(sessionsWatchingKey)),
-                                watchers);
-               while (--watcherCnt >= 0) {
-                       CFStringRef     sessionKey;
-
-                       sessionKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@"), watchers[watcherCnt]);
-                       info = CFDictionaryGetValue(sessionData, sessionKey);
-                       if (info) {
-                               newInfo = CFDictionaryCreateMutableCopy(NULL, 0, info);
-                       } else {
-                               newInfo = CFDictionaryCreateMutable(NULL,
-                                                                   0,
-                                                                   &kCFTypeDictionaryKeyCallBacks,
-                                                                   &kCFTypeDictionaryValueCallBacks);
+               if (watcherCnt > 0) {
+                       watchers   = CFAllocatorAllocate(NULL, watcherCnt * sizeof(CFNumberRef), 0);
+                       CFArrayGetValues(sessionsWatchingKey,
+                                        CFRangeMake(0, CFArrayGetCount(sessionsWatchingKey)),
+                                        watchers);
+                       while (--watcherCnt >= 0) {
+                               CFStringRef     sessionKey;
+
+                               sessionKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@"), watchers[watcherCnt]);
+                               info = CFDictionaryGetValue(sessionData, sessionKey);
+                               if (info) {
+                                       newInfo = CFDictionaryCreateMutableCopy(NULL, 0, info);
+                               } else {
+                                       newInfo = CFDictionaryCreateMutable(NULL,
+                                                                           0,
+                                                                           &kCFTypeDictionaryKeyCallBacks,
+                                                                           &kCFTypeDictionaryValueCallBacks);
+                               }
+
+                               changes = CFDictionaryGetValue(newInfo, kSCDChangedKeys);
+                               if (changes) {
+                                       newChanges = CFArrayCreateMutableCopy(NULL, 0, changes);
+                               } else {
+                                       newChanges = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
+                               }
+
+                               if (CFArrayContainsValue(newChanges,
+                                                        CFRangeMake(0, CFArrayGetCount(newChanges)),
+                                                        (CFStringRef)keys[keyCnt]) == FALSE) {
+                                       CFArrayAppendValue(newChanges, (CFStringRef)keys[keyCnt]);
+                               }
+                               CFDictionarySetValue(newInfo, kSCDChangedKeys, newChanges);
+                               CFRelease(newChanges);
+                               CFDictionarySetValue(sessionData, sessionKey, newInfo);
+                               CFRelease(newInfo);
+                               CFRelease(sessionKey);
+
+                               /*
+                                * flag this session as needing a kick
+                                */
+                               if (needsNotification == NULL)
+                                       needsNotification = CFSetCreateMutable(NULL,
+                                                                              0,
+                                                                              &kCFTypeSetCallBacks);
+                               CFSetAddValue(needsNotification, watchers[watcherCnt]);
                        }
-
-                       changes = CFDictionaryGetValue(newInfo, kSCDChangedKeys);
-                       if (changes) {
-                               newChanges = CFArrayCreateMutableCopy(NULL, 0, changes);
-                       } else {
-                               newChanges = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
-                       }
-
-                       if (CFArrayContainsValue(newChanges,
-                                                CFRangeMake(0, CFArrayGetCount(newChanges)),
-                                                (CFStringRef)keys[keyCnt]) == FALSE) {
-                               CFArrayAppendValue(newChanges, (CFStringRef)keys[keyCnt]);
-                       }
-                       CFDictionarySetValue(newInfo, kSCDChangedKeys, newChanges);
-                       CFRelease(newChanges);
-                       CFDictionarySetValue(sessionData, sessionKey, newInfo);
-                       CFRelease(newInfo);
-                       CFRelease(sessionKey);
-
-                       /*
-                        * flag this session as needing a kick
-                        */
-                       if (needsNotification == NULL)
-                               needsNotification = CFSetCreateMutable(NULL,
-                                                                      0,
-                                                                      &kCFTypeSetCallBacks);
-                       CFSetAddValue(needsNotification, watchers[watcherCnt]);
+                       CFAllocatorDeallocate(NULL, watchers);
                }
-               CFAllocatorDeallocate(NULL, watchers);
        }
        CFAllocatorDeallocate(NULL, keys);
 
@@ -132,9 +135,10 @@ static void
 _processDeferredRemovals()
 {
        CFIndex                 keyCnt;
-       void                    **keys;
+       const void              **keys;
 
-       if ((keyCnt = CFSetGetCount(deferredRemovals)) == 0)
+       keyCnt = CFSetGetCount(deferredRemovals);
+       if (keyCnt == 0)
                return;         /* if nothing to do */
 
        keys = CFAllocatorAllocate(NULL, keyCnt * sizeof(CFStringRef), 0);
@@ -142,7 +146,7 @@ _processDeferredRemovals()
        while (--keyCnt >= 0) {
                CFDictionaryApplyFunction(sessionData,
                                          (CFDictionaryApplierFunction)_removeRegexWatchersBySession,
-                                         keys[keyCnt]);
+                                         (void *)keys[keyCnt]);
        }
        CFAllocatorDeallocate(NULL, keys);
 
index 56210cd50ddf8018048e1a1d62314b2adedefbbf..55b9268e732af31c624dc727629420630813b356 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -179,6 +179,7 @@ __SCDynamicStoreAddWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean
                        CFRelease(newRData);
                        CFDictionarySetValue(sessionData, sessionKey, newInfo);
                }
+               CFRelease(regexData);
                CFRelease(newInfo);
                CFRelease(sessionKey);
        } else {
@@ -205,37 +206,20 @@ _notifyadd(mach_port_t                    server,
           int                          *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Add notification key for this session."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
+               CFRelease(key);
                *sc_status = kSCStatusInvalidArgument;
                return KERN_SUCCESS;
        }
index 0cb0ed8232a3d132338e3f9065f64059e49ed1a7..4d9595afcbd22cf026a56ca900feff18b326d83f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -80,40 +80,28 @@ _notifychanges(mach_port_t                  server,
               int                              *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
        CFArrayRef              notifierKeys;   /* array of CFStringRef's */
-       CFDataRef               xmlList;        /* list (XML serialized) */
+       Boolean                 ok;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("List notification keys which have changed."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
+       *listRef = NULL;
+       *listLen = 0;
+
        *sc_status = __SCDynamicStoreCopyNotifiedKeys(mySession->store, &notifierKeys);
        if (*sc_status != kSCStatusOK) {
-               *listRef = NULL;
-               *listLen = 0;
                return KERN_SUCCESS;
        }
 
-       /*
-        * serialize the array, copy it into an allocated buffer which will be
-        * released when it is returned as part of a Mach message.
-        */
-       xmlList = CFPropertyListCreateXMLData(NULL, notifierKeys);
+       /* serialize the array of keys */
+       ok = _SCSerialize(notifierKeys, NULL, (void **)listRef, (CFIndex *)listLen);
        CFRelease(notifierKeys);
-       *listLen = CFDataGetLength(xmlList);
-       status = vm_allocate(mach_task_self(), (void *)listRef, *listLen, TRUE);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status));
-               CFRelease(xmlList);
-               *listRef = NULL;
-               *listLen = 0;
+       if (!ok) {
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
        }
 
-       bcopy((char *)CFDataGetBytePtr(xmlList), *listRef, *listLen);
-       CFRelease(xmlList);
-
        return KERN_SUCCESS;
 }
index fb746074df8928d5af3f5993850cd91f5a281707..5461ed9f66afdd5526928e9b6c21f1636573d8db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -160,37 +160,20 @@ _notifyremove(mach_port_t         server,
              int                       *sc_status
 )
 {
-       kern_return_t           status;
        serverSessionRef        mySession = getSession(server);
-       CFDataRef               xmlKey;         /* key  (XML serialized) */
        CFStringRef             key;            /* key  (un-serialized) */
-       CFStringRef             xmlError;
 
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Remove notification key for this session."));
        SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
 
        /* un-serialize the key */
-       xmlKey = CFDataCreate(NULL, keyRef, keyLen);
-       status = vm_deallocate(mach_task_self(), (vm_address_t)keyRef, keyLen);
-       if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_deallocate(): %s"), mach_error_string(status));
-               /* non-fatal???, proceed */
-       }
-       key = CFPropertyListCreateFromXMLData(NULL,
-                                             xmlKey,
-                                             kCFPropertyListImmutable,
-                                             &xmlError);
-       CFRelease(xmlKey);
-       if (!key) {
-               if (xmlError) {
-                       SCLog(_configd_verbose, LOG_DEBUG,
-                              CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
-                              xmlError);
-                       CFRelease(xmlError);
-               }
+       if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
-       } else if (!isA_CFString(key)) {
+       }
+
+       if (!isA_CFString(key)) {
+               CFRelease(key);
                *sc_status = kSCStatusInvalidArgument;
                return KERN_SUCCESS;
        }
index bbe43ee44fd93ed21aada7fd440e02cd3efb9961..7c9b35f527d2f3f3bbcc2729c73d398d4f505148 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -54,7 +54,7 @@ __SCDynamicStoreNotifySignal(SCDynamicStoreRef store, pid_t pid, int sig)
 
        if (pid == getpid()) {
                /* sorry, you can't request that configd be signalled */
-               return kSCStatusFailed;
+               return kSCStatusInvalidArgument;
        }
 
        if ((sig <= 0) || (sig > NSIG)) {
index 68e8509cffb32c24f56d1d4c8b1e7c6a250cd5e1..9f6764f1a0f9cd5a340abb5573e783390f76df70 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -69,6 +69,11 @@ __SCDynamicStoreSnapshot(SCDynamicStoreRef store)
        }
 
        xmlData = CFPropertyListCreateXMLData(NULL, storeData);
+       if (!xmlData) {
+               SCLog(TRUE, LOG_ERR, CFSTR("CFPropertyListCreateXMLData() failed"));
+               close(fd);
+               return kSCStatusFailed;
+       }
        (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData));
        (void) close(fd);
        CFRelease(xmlData);
@@ -84,6 +89,11 @@ __SCDynamicStoreSnapshot(SCDynamicStoreRef store)
        /* Save a snapshot of the "session" data */
 
        xmlData = CFPropertyListCreateXMLData(NULL, sessionData);
+       if (!xmlData) {
+               SCLog(TRUE, LOG_ERR, CFSTR("CFPropertyListCreateXMLData() failed"));
+               close(fd);
+               return kSCStatusFailed;
+       }
        (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData));
        (void) close(fd);
        CFRelease(xmlData);
index cc2513a0e9431f0cf0fd271bb88465182c4adacf..0d4056a56d4b3504230771756ccca7a9df98a43c 100644 (file)
@@ -15,4 +15,4 @@
  *   As such... IF YOU CHANGE THE ".defs" FILE, MAKE CLEAN!
  */
 
-#import "../SystemConfiguration.fproj/config.defs"
\ No newline at end of file
+#include <SystemConfiguration/config.defs>
index 55caa0bb798b62be87141b9c69d42b3bae5fa08d..3a4658f0cf5d4dd94f4abb0a379c5f6c63878cf0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -44,8 +44,8 @@
 #include "configd_server.h"
 #include "plugin_support.h"
 
-Boolean        _configd_fork           = TRUE;         /* TRUE if process should be run in the background */
-Boolean        _configd_verbose        = FALSE;        /* TRUE if verbose logging enabled */
+Boolean        _configd_fork                   = TRUE;         /* TRUE if process should be run in the background */
+Boolean        _configd_verbose                = FALSE;        /* TRUE if verbose logging enabled */
 CFMutableSetRef        _plugins_exclude        = NULL;         /* bundle identifiers to exclude from loading */
 CFMutableSetRef        _plugins_verbose        = NULL;         /* bundle identifiers to enable verbose logging */
 
@@ -139,19 +139,47 @@ fork_child()
 
        (void) chdir("/");
 
-       if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+       fd = open(_PATH_DEVNULL, O_RDWR, 0);
+       if (fd != -1) {
+               int     ofd;
+
+               // stdin
                (void) dup2(fd, STDIN_FILENO);
+
+               // stdout, stderr
+               ofd = open("/var/log/configd.log", O_WRONLY|O_APPEND, 0);
+               if (ofd != -1) {
+                       if (fd > STDIN_FILENO) {
+                               (void) close(fd);
+                       }
+                       fd = ofd;
+               }
                (void) dup2(fd, STDOUT_FILENO);
                (void) dup2(fd, STDERR_FILENO);
-               if (fd > 2)
+               if (fd > STDERR_FILENO) {
                        (void) close(fd);
+               }
        }
 
        return 0;
 }
 
+
+static void
+writepid(void)
+{
+       FILE *fp;
+
+       fp = fopen("/var/run/configd.pid", "w");
+       if (fp != NULL) {
+               fprintf(fp, "%d\n", getpid());
+               fclose(fp);
+       }
+}
+
+
 int
-main(int argc, const char *argv[])
+main(int argc, char * const argv[])
 {
        Boolean                 loadBundles = TRUE;
        struct sigaction        nact;
@@ -224,6 +252,11 @@ main(int argc, const char *argv[])
                /* now the child process, parent waits in fork_child */
        }
 
+       /* record process id */
+       if (testBundle == NULL) {
+               writepid();
+       }
+
        /* open syslog() facility */
        if (_configd_fork) {
                int     logopt  = LOG_NDELAY|LOG_PID;
index d589c6931deab38b20d1382a29f967fafc1faa14..c009c55790968244d054c922ad30dc5efa65bec9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -199,9 +199,15 @@ configdCallback(CFMachPortRef port, void *msg, CFIndex size, void *info)
 boolean_t
 server_active()
 {
-       kern_return_t           status;
-       mach_port_t             bootstrap_port;
        boolean_t               active;
+       mach_port_t             bootstrap_port;
+       char                    *server_name;
+       kern_return_t           status;
+
+       server_name = getenv("SCD_SERVER");
+       if (!server_name) {
+               server_name = SCD_SERVER;
+       }
 
        /* Getting bootstrap server port */
        status = task_get_bootstrap_port(mach_task_self(), &bootstrap_port);
@@ -212,12 +218,12 @@ server_active()
        }
 
        /* Check "configd" server status */
-       status = bootstrap_status(bootstrap_port, SCD_SERVER, &active);
+       status = bootstrap_status(bootstrap_port, server_name, &active);
        switch (status) {
                case BOOTSTRAP_SUCCESS :
                        if (active) {
                                fprintf(stderr, "configd: '%s' server already active\n",
-                                       SCD_SERVER);
+                                       server_name);
                                return TRUE;
                        }
                        break;
@@ -234,10 +240,16 @@ server_active()
 void
 server_init()
 {
-       kern_return_t           status;
-       mach_port_t             bootstrap_port;
        boolean_t               active;
+       mach_port_t             bootstrap_port;
        CFRunLoopSourceRef      rls;
+       char                    *server_name;
+       kern_return_t           status;
+
+       server_name = getenv("SCD_SERVER");
+       if (!server_name) {
+               server_name = SCD_SERVER;
+       }
 
        /* Getting bootstrap server port */
        status = task_get_bootstrap_port(mach_task_self(), &bootstrap_port);
@@ -247,11 +259,11 @@ server_init()
        }
 
        /* Check "configd" server status */
-       status = bootstrap_status(bootstrap_port, SCD_SERVER, &active);
+       status = bootstrap_status(bootstrap_port, server_name, &active);
        switch (status) {
                case BOOTSTRAP_SUCCESS :
                        if (active) {
-                               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("\"%s\" is currently active, exiting."), SCD_SERVER);
+                               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("\"%s\" is currently active, exiting."), server_name);
                                exit (EX_UNAVAILABLE);
                        }
                        break;
@@ -281,8 +293,8 @@ server_init()
        /* Create a session for the primary / new connection port */
        (void) addSession(configd_port);
 
-       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Registering service \"%s\""), SCD_SERVER);
-       status = bootstrap_register(bootstrap_port, SCD_SERVER, CFMachPortGetPort(configd_port));
+       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Registering service \"%s\""), server_name);
+       status = bootstrap_register(bootstrap_port, server_name, CFMachPortGetPort(configd_port));
        switch (status) {
                case BOOTSTRAP_SUCCESS :
                        /* service not currently registered, "a good thing" (tm) */
index 3248c92e944b0701875444b68ca55ebbd9c2672b..37a32594fb13189c2eadea173e372966646cbde3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -41,7 +41,7 @@
 void
 pushNotifications()
 {
-       void                            **sessionsToNotify;
+       const void                      **sessionsToNotify;
        CFIndex                         notifyCnt;
        int                             server;
        serverSessionRef                theSession;
index b511a89d999f8bb45ea90ba2e006b898528ecb46..1f927495086b51ea365f57e34d018d3695aeb0c8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -43,6 +43,7 @@
 
 #include "configd.h"
 #include <SystemConfiguration/SCDPlugin.h>
+void   _SCDPluginExecInit();
 
 
 /*
@@ -277,12 +278,12 @@ loadBundle(const void *value, void *context) {
        }
 
        if (!bundleVerbose) {
-       dict = CFBundleGetInfoDictionary(bundle);
-       if (isA_CFDictionary(dict)) {
-               CFBooleanRef    bool;
+               dict = CFBundleGetInfoDictionary(bundle);
+               if (isA_CFDictionary(dict)) {
+                       CFBooleanRef    bVal;
 
-                       bool = CFDictionaryGetValue(dict, kSCBundleVerbose);
-               if (isA_CFBoolean(bool) && CFBooleanGetValue(bool)) {
+                       bVal = CFDictionaryGetValue(dict, kSCBundleVerbose);
+                       if (isA_CFBoolean(bVal) && CFBooleanGetValue(bVal)) {
                                bundleVerbose = TRUE;
                        }
                }
@@ -381,6 +382,8 @@ primeBundle(const void *value, void *context) {
 }
 
 
+#ifdef DEBUG
+
 static void
 timerCallback(CFRunLoopTimerRef timer, void *info)
 {
@@ -390,6 +393,8 @@ timerCallback(CFRunLoopTimerRef timer, void *info)
        return;
 }
 
+#endif /* DEBUG */
+
 
 static void
 sortBundles(CFMutableArrayRef orig)
@@ -402,7 +407,7 @@ sortBundles(CFMutableArrayRef orig)
                Boolean inserted = FALSE;
 
                for (i = 0; i < CFArrayGetCount(orig); i++) {
-                       CFBundleRef     bundle1   = CFArrayGetValueAtIndex(orig, i);
+                       CFBundleRef     bundle1   = (CFBundleRef)CFArrayGetValueAtIndex(orig, i);
                        CFStringRef     bundleID1 = CFBundleGetIdentifier(bundle1);
                        int             count;
                        CFDictionaryRef dict;
@@ -426,7 +431,7 @@ sortBundles(CFMutableArrayRef orig)
                                CFStringRef     r       = CFArrayGetValueAtIndex(requires, j);
 
                                for (k = 0; k < CFArrayGetCount(new); k++) {
-                                       CFBundleRef     bundle2   = CFArrayGetValueAtIndex(new, k);
+                                       CFBundleRef     bundle2   = (CFBundleRef)CFArrayGetValueAtIndex(new, k);
                                        CFStringRef     bundleID2 = CFBundleGetIdentifier(bundle2);
 
                                        if (bundleID2 && CFEqual(bundleID2, r)) {
@@ -471,6 +476,9 @@ plugin_exec(void *arg)
        /* keep track of bundles */
        allBundles = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
 
+        /* allow plug-ins to exec child/helper processes */
+        _SCDPluginExecInit();
+
        if (arg == NULL) {
                char                            path[MAXPATHLEN];
                NSSearchPathEnumerationState    state;
@@ -569,20 +577,22 @@ plugin_exec(void *arg)
                             primeBundle,
                             NULL);
 
+#ifdef DEBUG
        if (arg == NULL && (nLoaded > 0)) {
                CFRunLoopTimerRef       timer;
 
                /* allocate a periodic event (to help show we're not blocking) */
-                       timer = CFRunLoopTimerCreate(NULL,                              /* allocator */
-                                                    CFAbsoluteTimeGetCurrent() + 1.0,  /* fireDate */
-                                                    60.0,                              /* interval */
-                                                    0,                                 /* flags */
-                                                    0,                                 /* order */
-                                                    timerCallback,                     /* callout */
-                                                    NULL);                             /* context */
-                       CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode);
-                       CFRelease(timer);
-               }
+               timer = CFRunLoopTimerCreate(NULL,                              /* allocator */
+                                            CFAbsoluteTimeGetCurrent() + 1.0,  /* fireDate */
+                                            60.0,                              /* interval */
+                                            0,                                 /* flags */
+                                            0,                                 /* order */
+                                            timerCallback,                     /* callout */
+                                            NULL);                             /* context */
+               CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode);
+               CFRelease(timer);
+       }
+#endif /* DEBUG */
 
        if (_configd_fork) {
                /* synchronize with parent process */
diff --git a/preferences.xml b/preferences.xml
new file mode 100644 (file)
index 0000000..9138585
--- /dev/null
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+       <key>CurrentSet</key>
+       <string>/Sets/0</string>
+       <key>NetworkServices</key>
+       <dict>
+               <key>0</key>
+               <dict>
+                       <key>AppleTalk</key>
+                       <dict>
+                               <key>ConfigMethod</key>
+                               <string>Node</string>
+                               <key>__INACTIVE__</key>
+                               <integer>1</integer>
+                       </dict>
+                       <key>DNS</key>
+                       <dict/>
+                       <key>Ethernet</key>
+                       <dict>
+                       </dict>
+                       <key>IPv4</key>
+                       <dict>
+                               <key>ConfigMethod</key>
+                               <string>DHCP</string>
+                       </dict>
+                       <key>Interface</key>
+                       <dict>
+                               <key>DeviceName</key>
+                               <string>en0</string>
+                               <key>Hardware</key>
+                               <string>Ethernet</string>
+                               <key>Type</key>
+                               <string>Ethernet</string>
+                               <key>UserDefinedName</key>
+                               <string>Built-in Ethernet</string>
+                       </dict>
+                       <key>PPP</key>
+                       <dict>
+                               <key>CommDisplayTerminalWindow</key>
+                               <integer>0</integer>
+                               <key>CommRedialCount</key>
+                               <integer>1</integer>
+                               <key>CommRedialEnabled</key>
+                               <integer>1</integer>
+                               <key>CommRedialInterval</key>
+                               <integer>30</integer>
+                               <key>DialOnDemand</key>
+                               <integer>0</integer>
+                               <key>DisconnectOnIdle</key>
+                               <integer>1</integer>
+                               <key>DisconnectOnIdleTimer</key>
+                               <integer>600</integer>
+                               <key>DisconnectOnLogout</key>
+                               <integer>0</integer>
+                               <key>IPCPCompressionVJ</key>
+                               <integer>1</integer>
+                               <key>IdleReminder</key>
+                               <integer>1</integer>
+                               <key>IdleReminderTimer</key>
+                               <integer>900</integer>
+                               <key>LCPEchoEnabled</key>
+                               <integer>1</integer>
+                               <key>LCPEchoFailure</key>
+                               <integer>4</integer>
+                               <key>LCPEchoInterval</key>
+                               <integer>10</integer>
+                               <key>Logfile</key>
+                               <string>/tmp/ppp.log</string>
+                               <key>VerboseLogging</key>
+                               <integer>0</integer>
+                               <key>__INACTIVE__</key>
+                               <integer>1</integer>
+                       </dict>
+                       <key>Proxies</key>
+                       <dict>
+                               <key>FTPEnable</key>
+                               <integer>0</integer>
+                               <key>FTPPassive</key>
+                               <integer>1</integer>
+                               <key>GopherEnable</key>
+                               <integer>0</integer>
+                               <key>HTTPEnable</key>
+                               <integer>0</integer>
+                               <key>HTTPSEnable</key>
+                               <integer>0</integer>
+                               <key>RTSPEnable</key>
+                               <integer>0</integer>
+                               <key>SOCKSEnable</key>
+                               <integer>0</integer>
+                       </dict>
+                       <key>UserDefinedName</key>
+                       <string>Built-in Ethernet</string>
+               </dict>
+       </dict>
+       <key>Sets</key>
+       <dict>
+               <key>0</key>
+               <dict>
+                       <key>Network</key>
+                       <dict>
+                               <key>Global</key>
+                               <dict>
+                                       <key>IPv4</key>
+                                       <dict>
+                                               <key>PPPOverridePrimary</key>
+                                               <integer>0</integer>
+                                               <key>ServiceOrder</key>
+                                               <array>
+                                                       <string>0</string>
+                                               </array>
+                                       </dict>
+                                       <key>NetInfo</key>
+                                       <dict>
+                                               <key>BindingMethods</key>
+                                               <array>
+                                                       <string>DHCP</string>
+                                               </array>
+                                       </dict>
+                               </dict>
+                               <key>Service</key>
+                               <dict>
+                                       <key>0</key>
+                                       <dict>
+                                               <key>__LINK__</key>
+                                               <string>/NetworkServices/0</string>
+                                       </dict>
+                               </dict>
+                       </dict>
+                       <key>UserDefinedName</key>
+                       <string>Automatic</string>
+               </dict>
+       </dict>
+       <key>System</key>
+       <dict>
+       </dict>
+</dict>
+</plist>
index 87fc31cc1ba0b5409b98c43ce7c3586bade9e081..9bf1aa459683a8abed93416c7d43f2750c86d997 100644 (file)
@@ -29,7 +29,6 @@ DEBUG_LIBS = $(LIBS)
 PROF_LIBS = $(LIBS)
 
 
-NEXTSTEP_PB_CFLAGS = -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS
 FRAMEWORKS = -framework CoreFoundation -framework SystemConfiguration
 
 
index 32e4349ec06ba65db0f4e425749f8735b59ea544..75217410f9ca5ca7a8e1e2e2c217a336a3a51c96 100644 (file)
@@ -13,7 +13,6 @@
     LANGUAGE = English; 
     MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; 
     NEXTSTEP_BUILDTOOL = /usr/bin/gnumake; 
-    NEXTSTEP_COMPILEROPTIONS = "-DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS"; 
     NEXTSTEP_INSTALLDIR = /usr/sbin; 
     NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; 
     NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; 
index 7abf11edec5b52326e74d6c7592931af5ad882fe..ec6b6a32c3cbf5490c30d06a1dadacff85c2c352 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -61,8 +61,8 @@ main(int argc, char **argv)
        SCPreferencesRef        session;
        CFDictionaryRef         sets;
        CFIndex                 nSets;
-       void                    **setKeys;
-       void                    **setVals;
+       const void              **setKeys       = NULL;
+       const void              **setVals       = NULL;
        CFIndex                 i;
 
        /* process any arguments */
@@ -139,9 +139,11 @@ main(int argc, char **argv)
        }
 
        nSets = CFDictionaryGetCount(sets);
-       setKeys = CFAllocatorAllocate(NULL, nSets * sizeof(CFStringRef), 0);
-       setVals = CFAllocatorAllocate(NULL, nSets * sizeof(CFDictionaryRef), 0);
-       CFDictionaryGetKeysAndValues(sets, setKeys, setVals);
+       if (nSets > 0) {
+               setKeys = CFAllocatorAllocate(NULL, nSets * sizeof(CFStringRef), 0);
+               setVals = CFAllocatorAllocate(NULL, nSets * sizeof(CFDictionaryRef), 0);
+               CFDictionaryGetKeysAndValues(sets, setKeys, setVals);
+       }
 
        /* check for set with matching name */
        for (i=0; i<nSets; i++) {
index 4daf58e29215a56ecf0c174fd23880a954377487..569a6d574392758c38dadb5916d1d17d8869513f 100644 (file)
@@ -33,7 +33,6 @@ DEBUG_LIBS = $(LIBS)
 PROF_LIBS = $(LIBS)
 
 
-NEXTSTEP_PB_CFLAGS = -DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS
 FRAMEWORKS = -framework CoreFoundation -framework SystemConfiguration
 
 
index e5060626d25d4f8590739c27e87376a2017981d2..2ee78a18ec02e0fdcd142ad1444f8b132c515c5e 100644 (file)
@@ -14,7 +14,6 @@
     LANGUAGE = English; 
     MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; 
     NEXTSTEP_BUILDTOOL = /usr/bin/gnumake; 
-    NEXTSTEP_COMPILEROPTIONS = "-DUSE_SYSTEMCONFIGURATION_PUBLIC_APIS"; 
     NEXTSTEP_INSTALLDIR = /usr/sbin; 
     NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; 
     NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; 
index 3739acb0cfbf650eb655083c59d31bb335ee4190..dafc649cefed1e6a651a2fbed7c08e4feb20cf6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -59,7 +59,11 @@ do_list(int argc, char **argv)
        list = SCDynamicStoreCopyKeyList(store, pattern);
        CFRelease(pattern);
        if (!list) {
-               SCPrint(TRUE, stdout, CFSTR("  %s\n"), SCErrorString(SCError()));
+               if (SCError() != kSCStatusOK) {
+                       SCPrint(TRUE, stdout, CFSTR("  %s\n"), SCErrorString(SCError()));
+               } else {
+                       SCPrint(TRUE, stdout, CFSTR("  no keys.\n"));
+               }
                return;
        }
 
@@ -80,7 +84,7 @@ do_list(int argc, char **argv)
                                CFArrayGetValueAtIndex(sortedList, i));
                }
        } else {
-               SCPrint(TRUE, stdout, CFSTR("  no subKey's.\n"));
+               SCPrint(TRUE, stdout, CFSTR("  no keys.\n"));
        }
        CFRelease(sortedList);
 
index 55f5660581ec65f24aefe1643a861923751ec609..5b846c6ff9dbad8178be14960b850dcd9738782b 100644 (file)
@@ -83,7 +83,7 @@ do_dictSetKey(int argc, char **argv)
                return;
        }
 
-       if (CFGetTypeID(value) != CFDictionaryGetTypeID()) {
+       if (!isA_CFDictionary(value)) {
                SCPrint(TRUE, stdout, CFSTR("d.add: data (fetched from configuration server) is not a dictionary.\n"));
                return;
        }
@@ -192,7 +192,7 @@ do_dictRemoveKey(int argc, char **argv)
                return;
        }
 
-       if (CFGetTypeID(value) != CFDictionaryGetTypeID()) {
+       if (!isA_CFDictionary(value)) {
                SCPrint(TRUE, stdout, CFSTR("d.remove: data (fetched from configuration server) is not a dictionary.\n"));
                return;
        }
index 6629a6b23fd00e2994c766953182ccaec119026e..ec3ec893fa5468f9c76d056083fd7b1cd2c11478 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -66,12 +66,12 @@ storeCallback(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info)
                for (i=0; i<n; i++) {
                        SCPrint(TRUE,
                                stdout,
-                               CFSTR("  changedKey [%d] = %@\n"),
+                               CFSTR("  changed key [%d] = %@\n"),
                                i,
                                CFArrayGetValueAtIndex(changedKeys, i));
                }
        } else {
-               SCPrint(TRUE, stdout, CFSTR("  no changedKey's.\n"));
+               SCPrint(TRUE, stdout, CFSTR("  no changed key's.\n"));
        }
 
        return;
@@ -92,7 +92,14 @@ do_notify_list(int argc, char **argv)
 
        list = SCDynamicStoreCopyWatchedKeyList(store, isRegex);
        if (!list) {
-               SCPrint(TRUE, stdout, CFSTR("  %s\n"), SCErrorString(SCError()));
+               if (SCError() != kSCStatusOK) {
+                       SCPrint(TRUE, stdout, CFSTR("  %s\n"), SCErrorString(SCError()));
+               } else {
+                       SCPrint(TRUE,
+                               stdout,
+                               CFSTR("  no notifier %s.\n"),
+                               isRegex ? "patterns" : "keys");
+               }
                return;
        }
 
@@ -108,12 +115,16 @@ do_notify_list(int argc, char **argv)
                for (i=0; i<listCnt; i++) {
                        SCPrint(TRUE,
                                stdout,
-                               CFSTR("  notifierKey [%d] = %@\n"),
+                               CFSTR("  notifier %s [%d] = %@\n"),
+                               isRegex ? "pattern" : "key",
                                i,
                                CFArrayGetValueAtIndex(sortedList, i));
                }
        } else {
-               SCPrint(TRUE, stdout, CFSTR("  no notifierKey's.\n"));
+               SCPrint(TRUE,
+                       stdout,
+                       CFSTR("  no notifier %s.\n"),
+                       isRegex ? "patterns" : "keys");
        }
        CFRelease(sortedList);
 
@@ -314,21 +325,12 @@ do_notify_file(int argc, char **argv)
 }
 
 
-static char *signames[] = {
-       ""    , "HUP" , "INT"   , "QUIT", "ILL"  , "TRAP", "ABRT", "EMT" ,
-       "FPE" , "KILL", "BUS"   , "SEGV", "SYS"  , "PIPE", "ALRM", "TERM",
-       "URG" , "STOP", "TSTP"  , "CONT", "CHLD" , "TTIN", "TTOU", "IO"  ,
-       "XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "INFO", "USR1",
-       "USR2"
-};
-
-
 static void
 signalCatcher(int signum)
 {
        static int      n = 0;
 
-       SCPrint(TRUE, stdout, CFSTR("Received SIG%s (#%d).\n"), signames[signum], n++);
+       SCPrint(TRUE, stdout, CFSTR("Received sig%s (#%d).\n"), sys_signame[signum], n++);
        return;
 }
 
@@ -348,7 +350,7 @@ do_notify_signal(int argc, char **argv)
                }
        } else {
                for (sig=1; sig<NSIG; sig++) {
-                       if (strcasecmp(argv[0], signames[sig]) == 0)
+                       if (strcasecmp(argv[0], sys_signame[sig]) == 0)
                                break;
                }
                if (sig >= NSIG) {
@@ -358,7 +360,7 @@ do_notify_signal(int argc, char **argv)
 
                        str = CFStringCreateMutable(NULL, 0);
                        for (sig=1; sig<NSIG; sig++) {
-                               CFStringAppendFormat(str, NULL, CFSTR(" %-6s"), signames[sig]);
+                               CFStringAppendFormat(str, NULL, CFSTR(" %-6s"), sys_signame[sig]);
                                if ((sig % 10) == 0) {
                                        CFStringAppendFormat(str, NULL, CFSTR("\n"));
                                }
index fc844b40254c3474548641c4eb38bb43030c8227..69cc760d23880598f25b500a4396726437429f2d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -151,7 +151,7 @@ process_line(FILE *fp)
                return FALSE;
 
        if (nesting > 0) {
-               SCPrint(TRUE, stdout, CFSTR("%d> %s"), nesting, line);
+               SCPrint(TRUE, stdout, CFSTR("%d> %s\n"), nesting, line);
        }
 
        /* if requested, exit */
@@ -246,7 +246,7 @@ usage(const char *command)
 
 
 int
-main(int argc, const char *argv[])
+main(int argc, char * const argv[])
 {
        CFSocketContext         context = { 0, stdin, NULL, NULL, NULL };
        char                    *dest   = NULL;
@@ -285,7 +285,7 @@ main(int argc, const char *argv[])
                case '?':
                default :
                        usage(prog);
-       }
+               }
        argc -= optind;
        argv += optind;
 
index ebeae2e9579e79044f886620e4912d8ed949e8d8..c853556347a4f91a0e76ec8c726e673402fab338 100644 (file)
@@ -36,6 +36,7 @@
 #include <sys/cdefs.h>
 
 #include <SystemConfiguration/SystemConfiguration.h>
+#include <SystemConfiguration/SCValidation.h>
 #include <SystemConfiguration/SCPrivate.h>