]>
Commit | Line | Data |
---|---|---|
5958d7c0 | 1 | /* |
a5f60add | 2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. |
5958d7c0 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | ||
0fae82ee A |
23 | /* |
24 | * Modification History | |
25 | * | |
26 | * June 1, 2001 Allan Nathanson <ajn@apple.com> | |
27 | * - public API conversion | |
28 | * | |
29 | * March 24, 2000 Allan Nathanson <ajn@apple.com> | |
30 | * - initial revision | |
31 | */ | |
32 | ||
5958d7c0 A |
33 | #include "configd.h" |
34 | #include "session.h" | |
35 | ||
0fae82ee A |
36 | int |
37 | __SCDynamicStoreAddValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListRef value) | |
5958d7c0 | 38 | { |
0fae82ee A |
39 | SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; |
40 | int sc_status = kSCStatusOK; | |
41 | CFPropertyListRef tempValue; | |
5958d7c0 | 42 | |
0fae82ee A |
43 | SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreAddValue:")); |
44 | SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" key = %@"), key); | |
45 | SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" value = %@"), value); | |
5958d7c0 | 46 | |
0fae82ee A |
47 | if (!store || (storePrivate->server == MACH_PORT_NULL)) { |
48 | return kSCStatusNoStoreSession; /* you must have an open session to play */ | |
5958d7c0 A |
49 | } |
50 | ||
51 | /* | |
0fae82ee | 52 | * 1. Ensure that we hold the lock. |
5958d7c0 | 53 | */ |
0fae82ee A |
54 | sc_status = __SCDynamicStoreLock(store, TRUE); |
55 | if (sc_status != kSCStatusOK) { | |
56 | return sc_status; | |
5958d7c0 A |
57 | } |
58 | ||
59 | /* | |
60 | * 2. Ensure that this is a new key. | |
61 | */ | |
0fae82ee A |
62 | sc_status = __SCDynamicStoreCopyValue(store, key, &tempValue); |
63 | switch (sc_status) { | |
64 | case kSCStatusNoKey : | |
65 | /* store key does not exist, proceed */ | |
5958d7c0 A |
66 | break; |
67 | ||
0fae82ee A |
68 | case kSCStatusOK : |
69 | /* store key exists, sorry */ | |
70 | CFRelease(tempValue); | |
71 | sc_status = kSCStatusKeyExists; | |
5958d7c0 A |
72 | goto done; |
73 | ||
74 | default : | |
0fae82ee | 75 | SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" _SCDGet(): %s"), SCErrorString(sc_status)); |
5958d7c0 A |
76 | goto done; |
77 | } | |
78 | ||
79 | /* | |
80 | * 3. Save the new key. | |
81 | */ | |
0fae82ee | 82 | sc_status = __SCDynamicStoreSetValue(store, key, value); |
5958d7c0 A |
83 | |
84 | /* | |
0fae82ee | 85 | * 4. Release our lock. |
5958d7c0 A |
86 | */ |
87 | done: | |
0fae82ee | 88 | __SCDynamicStoreUnlock(store, TRUE); |
5958d7c0 | 89 | |
0fae82ee | 90 | return sc_status; |
5958d7c0 A |
91 | } |
92 | ||
93 | ||
94 | kern_return_t | |
95 | _configadd(mach_port_t server, | |
96 | xmlData_t keyRef, /* raw XML bytes */ | |
97 | mach_msg_type_number_t keyLen, | |
98 | xmlData_t dataRef, /* raw XML bytes */ | |
99 | mach_msg_type_number_t dataLen, | |
100 | int *newInstance, | |
0fae82ee | 101 | int *sc_status |
5958d7c0 A |
102 | ) |
103 | { | |
5958d7c0 | 104 | serverSessionRef mySession = getSession(server); |
5958d7c0 | 105 | CFStringRef key; /* key (un-serialized) */ |
5958d7c0 | 106 | CFPropertyListRef data; /* data (un-serialized) */ |
5958d7c0 | 107 | |
0fae82ee A |
108 | SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Add key to configuration database.")); |
109 | SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server); | |
110 | ||
111 | *sc_status = kSCStatusOK; | |
5958d7c0 A |
112 | |
113 | /* un-serialize the key */ | |
a5f60add | 114 | if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) { |
0fae82ee | 115 | *sc_status = kSCStatusFailed; |
a5f60add A |
116 | } |
117 | ||
118 | if (!isA_CFString(key)) { | |
0fae82ee | 119 | *sc_status = kSCStatusInvalidArgument; |
5958d7c0 A |
120 | } |
121 | ||
122 | /* un-serialize the data */ | |
a5f60add | 123 | if (!_SCUnserialize((CFPropertyListRef *)&data, (void *)dataRef, dataLen)) { |
0fae82ee | 124 | *sc_status = kSCStatusFailed; |
a5f60add A |
125 | } |
126 | ||
127 | if (!isA_CFPropertyList(data)) { | |
0fae82ee | 128 | *sc_status = kSCStatusInvalidArgument; |
5958d7c0 A |
129 | } |
130 | ||
0fae82ee A |
131 | if (*sc_status != kSCStatusOK) { |
132 | if (key) CFRelease(key); | |
133 | if (data) CFRelease(data); | |
134 | return KERN_SUCCESS; | |
5958d7c0 | 135 | } |
0fae82ee A |
136 | |
137 | *sc_status = __SCDynamicStoreAddValue(mySession->store, key, data); | |
138 | *newInstance = 0; | |
139 | ||
5958d7c0 A |
140 | CFRelease(key); |
141 | CFRelease(data); | |
142 | ||
143 | return KERN_SUCCESS; | |
144 | } |