this repo has no description
at fixPythonPipStalling 237 lines 6.6 kB view raw
1/* 2 * Copyright (c) 2000-2006, 2009-2011, 2013, 2016-2019 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * Modification History 26 * 27 * June 1, 2001 Allan Nathanson <ajn@apple.com> 28 * - public API conversion 29 * 30 * March 24, 2000 Allan Nathanson <ajn@apple.com> 31 * - initial revision 32 */ 33 34#include "SCDynamicStoreInternal.h" 35#include "config.h" /* MiG generated file */ 36 37 38Boolean 39SCDynamicStoreSetMultiple(SCDynamicStoreRef store, 40 CFDictionaryRef keysToSet, 41 CFArrayRef keysToRemove, 42 CFArrayRef keysToNotify) 43{ 44 SCDynamicStorePrivateRef storePrivate; 45 kern_return_t status; 46 CFDataRef xmlSet = NULL; /* key/value pairs to set (XML serialized) */ 47 xmlData_t mySetRef = NULL; /* key/value pairs to set (serialized) */ 48 CFIndex mySetLen = 0; 49 CFDataRef xmlRemove = NULL; /* keys to remove (XML serialized) */ 50 xmlData_t myRemoveRef = NULL; /* keys to remove (serialized) */ 51 CFIndex myRemoveLen = 0; 52 CFDataRef xmlNotify = NULL; /* keys to notify (XML serialized) */ 53 xmlData_t myNotifyRef = NULL; /* keys to notify (serialized) */ 54 CFIndex myNotifyLen = 0; 55 int sc_status; 56 57 if (store == NULL) { 58 store = __SCDynamicStoreNullSession(); 59 if (store == NULL) { 60 /* sorry, you must provide a session */ 61 _SCErrorSet(kSCStatusNoStoreSession); 62 return FALSE; 63 } 64 } 65 66 storePrivate = (SCDynamicStorePrivateRef)store; 67 if (storePrivate->server == MACH_PORT_NULL) { 68 _SCErrorSet(kSCStatusNoStoreServer); 69 return FALSE; /* you must have an open session to play */ 70 } 71 72 /* serialize the key/value pairs to set*/ 73 if (keysToSet != NULL) { 74 CFDictionaryRef newInfo; 75 Boolean ok; 76 77 newInfo = _SCSerializeMultiple(keysToSet); 78 if (newInfo == NULL) { 79 _SCErrorSet(kSCStatusInvalidArgument); 80 return FALSE; 81 } 82 83 ok = _SCSerialize(newInfo, &xmlSet, (void **)&mySetRef, &mySetLen); 84 CFRelease(newInfo); 85 if (!ok) { 86 _SCErrorSet(kSCStatusInvalidArgument); 87 return FALSE; 88 } 89 } 90 91 /* serialize the keys to remove */ 92 if (keysToRemove != NULL) { 93 if (!_SCSerialize(keysToRemove, &xmlRemove, (void **)&myRemoveRef, &myRemoveLen)) { 94 if (xmlSet != NULL) CFRelease(xmlSet); 95 _SCErrorSet(kSCStatusInvalidArgument); 96 return FALSE; 97 } 98 } 99 100 /* serialize the keys to notify */ 101 if (keysToNotify != NULL) { 102 if (!_SCSerialize(keysToNotify, &xmlNotify, (void **)&myNotifyRef, &myNotifyLen)) { 103 if (xmlSet != NULL) CFRelease(xmlSet); 104 if (xmlRemove != NULL) CFRelease(xmlRemove); 105 _SCErrorSet(kSCStatusInvalidArgument); 106 return FALSE; 107 } 108 } 109 110 retry : 111 112 /* send the keys and patterns, fetch the associated result from the server */ 113 status = configset_m(storePrivate->server, 114 mySetRef, 115 (mach_msg_type_number_t)mySetLen, 116 myRemoveRef, 117 (mach_msg_type_number_t)myRemoveLen, 118 myNotifyRef, 119 (mach_msg_type_number_t)myNotifyLen, 120 (int *)&sc_status); 121 122 if (__SCDynamicStoreCheckRetryAndHandleError(store, 123 status, 124 &sc_status, 125 "SCDynamicStoreSetMultiple configset_m()")) { 126 goto retry; 127 } 128 129 /* clean up */ 130 if (xmlSet != NULL) CFRelease(xmlSet); 131 if (xmlRemove != NULL) CFRelease(xmlRemove); 132 if (xmlNotify != NULL) CFRelease(xmlNotify); 133 134 if (sc_status != kSCStatusOK) { 135 _SCErrorSet(sc_status); 136 return FALSE; 137 } 138 139 return TRUE; 140} 141 142Boolean 143SCDynamicStoreSetValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListRef value) 144{ 145 SCDynamicStorePrivateRef storePrivate; 146 kern_return_t status; 147 CFDataRef utfKey; /* serialized key */ 148 xmlData_t myKeyRef; 149 CFIndex myKeyLen; 150 CFDataRef xmlData; /* serialized data */ 151 xmlData_t myDataRef; 152 CFIndex myDataLen; 153 int sc_status; 154 int newInstance; 155 156 if (store == NULL) { 157 store = __SCDynamicStoreNullSession(); 158 if (store == NULL) { 159 /* sorry, you must provide a session */ 160 _SCErrorSet(kSCStatusNoStoreSession); 161 return FALSE; 162 } 163 } 164 165 storePrivate = (SCDynamicStorePrivateRef)store; 166 if (storePrivate->server == MACH_PORT_NULL) { 167 /* sorry, you must have an open session to play */ 168 _SCErrorSet(kSCStatusNoStoreServer); 169 return FALSE; 170 } 171 172 if (storePrivate->cache_active) { 173 if (storePrivate->cached_removals != NULL) { 174 CFIndex i; 175 176 i = CFArrayGetFirstIndexOfValue(storePrivate->cached_removals, 177 CFRangeMake(0, CFArrayGetCount(storePrivate->cached_removals)), 178 key); 179 if (i != kCFNotFound) { 180 // if previously "removed" 181 CFArrayRemoveValueAtIndex(storePrivate->cached_removals, i); 182 } 183 } 184 185 if (storePrivate->cached_set == NULL) { 186 storePrivate->cached_set = CFDictionaryCreateMutable(NULL, 187 0, 188 &kCFTypeDictionaryKeyCallBacks, 189 &kCFTypeDictionaryValueCallBacks); 190 } 191 CFDictionarySetValue(storePrivate->cached_set, key, value); 192 return TRUE; 193 } 194 195 /* serialize the key */ 196 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) { 197 _SCErrorSet(kSCStatusInvalidArgument); 198 return FALSE; 199 } 200 201 /* serialize the data */ 202 if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) { 203 CFRelease(utfKey); 204 _SCErrorSet(kSCStatusInvalidArgument); 205 return FALSE; 206 } 207 208 retry : 209 210 /* send the key & data to the server, get new instance id */ 211 status = configset(storePrivate->server, 212 myKeyRef, 213 (mach_msg_type_number_t)myKeyLen, 214 myDataRef, 215 (mach_msg_type_number_t)myDataLen, 216 0, 217 &newInstance, 218 (int *)&sc_status); 219 220 if (__SCDynamicStoreCheckRetryAndHandleError(store, 221 status, 222 &sc_status, 223 "SCDynamicStoreSetValue configset()")) { 224 goto retry; 225 } 226 227 /* clean up */ 228 CFRelease(utfKey); 229 CFRelease(xmlData); 230 231 if (sc_status != kSCStatusOK) { 232 _SCErrorSet(sc_status); 233 return FALSE; 234 } 235 236 return TRUE; 237}