Something went wrong. Try again.
Cider Isn't Darwin Emulation, Really
Something went wrong. Try again.
6.8 kB · 239 lines
C
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240/* * Copyright (c) 2000-2005, 2009-2011, 2013, 2016-2019 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */
/* * Modification History * * June 1, 2001 Allan Nathanson <ajn@apple.com> * - public API conversion * * March 24, 2000 Allan Nathanson <ajn@apple.com> * - initial revision */
#include "SCDynamicStoreInternal.h"#include "config.h" /* MiG generated file */
CFDictionaryRefSCDynamicStoreCopyMultiple(SCDynamicStoreRef store, CFArrayRef keys, CFArrayRef patterns){ SCDynamicStorePrivateRef storePrivate; kern_return_t status; CFDataRef xmlKeys = NULL; /* keys (XML serialized) */ xmlData_t myKeysRef = NULL; /* keys (serialized) */ CFIndex myKeysLen = 0; CFDataRef xmlPatterns = NULL; /* patterns (XML serialized) */ xmlData_t myPatternsRef = NULL; /* patterns (serialized) */ CFIndex myPatternsLen = 0; xmlDataOut_t xmlDictRef = NULL; /* dict (serialized) */ mach_msg_type_number_t xmlDictLen = 0; CFDictionaryRef dict = NULL; /* dict (un-serialized) */ CFDictionaryRef expDict = NULL; /* dict (un-serialized / expanded) */ int sc_status;
if (store == NULL) { store = __SCDynamicStoreNullSession(); if (store == NULL) { /* sorry, you must provide a session */ _SCErrorSet(kSCStatusNoStoreSession); return NULL; } }
storePrivate = (SCDynamicStorePrivateRef)store; if (storePrivate->server == MACH_PORT_NULL) { _SCErrorSet(kSCStatusNoStoreServer); return NULL; /* you must have an open session to play */ }
/* serialize the keys */ if (keys != NULL) { if (!_SCSerialize(keys, &xmlKeys, (void **)&myKeysRef, &myKeysLen)) { _SCErrorSet(kSCStatusFailed); return NULL; } }
/* serialize the patterns */ if (patterns != NULL) { if (!_SCSerialize(patterns, &xmlPatterns, (void **)&myPatternsRef, &myPatternsLen)) { if (xmlKeys != NULL) CFRelease(xmlKeys); _SCErrorSet(kSCStatusFailed); return NULL; } }
retry :
/* send the keys and patterns, fetch the associated result from the server */ status = configget_m(storePrivate->server, myKeysRef, (mach_msg_type_number_t)myKeysLen, myPatternsRef, (mach_msg_type_number_t)myPatternsLen, &xmlDictRef, &xmlDictLen, (int *)&sc_status);
if (__SCDynamicStoreCheckRetryAndHandleError(store, status, &sc_status, "SCDynamicStoreCopyMultiple configget_m()")) { goto retry; }
if (sc_status != kSCStatusOK) { if (xmlDictRef != NULL) { (void) vm_deallocate(mach_task_self(), (vm_address_t)xmlDictRef, xmlDictLen); } _SCErrorSet(sc_status); goto done; }
/* un-serialize the dictionary */ if (!_SCUnserialize((CFPropertyListRef *)&dict, NULL, xmlDictRef, xmlDictLen)) { _SCErrorSet(kSCStatusFailed); goto done; }
expDict = _SCUnserializeMultiple(dict); CFRelease(dict);
done:
/* clean up */ if (xmlKeys != NULL) CFRelease(xmlKeys); if (xmlPatterns != NULL) CFRelease(xmlPatterns);
return expDict;}
CFPropertyListRefSCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key){ SCDynamicStorePrivateRef storePrivate; kern_return_t status; CFDataRef utfKey; /* key (XML serialized) */ xmlData_t myKeyRef; /* key (serialized) */ CFIndex myKeyLen; xmlDataOut_t xmlDataRef = NULL; /* data (serialized) */ mach_msg_type_number_t xmlDataLen = 0; CFPropertyListRef data; /* data (un-serialized) */ int newInstance; int sc_status;
if (store == NULL) { store = __SCDynamicStoreNullSession(); if (store == NULL) { /* sorry, you must provide a session */ _SCErrorSet(kSCStatusNoStoreSession); return NULL; } }
storePrivate = (SCDynamicStorePrivateRef)store; if (storePrivate->server == MACH_PORT_NULL) { _SCErrorSet(kSCStatusNoStoreServer); return NULL; /* you must have an open session to play */ }
if (storePrivate->cache_active) { if ((storePrivate->cached_set != NULL) && CFDictionaryGetValueIfPresent(storePrivate->cached_set, key, (const void **)&data)) { // if we have "set" a new value return (CFRetain(data)); }
if ((storePrivate->cached_removals != NULL) && CFArrayContainsValue(storePrivate->cached_removals, CFRangeMake(0, CFArrayGetCount(storePrivate->cached_removals)), key)) { // if we have "removed" the key _SCErrorSet(kSCStatusNoKey); return NULL; }
if ((storePrivate->cached_keys != NULL) && CFDictionaryGetValueIfPresent(storePrivate->cached_keys, key, (const void **)&data)) { // if we have a cached value return (CFRetain(data)); } }
/* serialize the key */ if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) { _SCErrorSet(kSCStatusFailed); return NULL; }
retry :
/* send the key & fetch the associated data from the server */ status = configget(storePrivate->server, myKeyRef, (mach_msg_type_number_t)myKeyLen, &xmlDataRef, &xmlDataLen, &newInstance, (int *)&sc_status);
if (__SCDynamicStoreCheckRetryAndHandleError(store, status, &sc_status, "SCDynamicStoreCopyValue configget()")) { goto retry; }
/* clean up */ CFRelease(utfKey);
if (sc_status != kSCStatusOK) { if (xmlDataRef != NULL) { (void) vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen); } _SCErrorSet(sc_status); return NULL; }
/* un-serialize the data */ if (!_SCUnserialize(&data, NULL, xmlDataRef, xmlDataLen)) { _SCErrorSet(kSCStatusFailed); return NULL; }
if (storePrivate->cache_active && (data != NULL)) { if (storePrivate->cached_keys == NULL) { storePrivate->cached_keys = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } CFDictionarySetValue(storePrivate->cached_keys, key, data); }
return data;}