]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDNotify.c
fafcea090296784111403778ef8852386f23b5eb
[apple/configd.git] / SystemConfiguration.fproj / SCDNotify.c
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26 /*
27 * Modification History
28 *
29 * May 19, 2001 Allan Nathanson <ajn@apple.com>
30 * - initial revision
31 */
32
33 #include <mach/mach.h>
34 #include <mach/mach_error.h>
35
36 #include <SystemConfiguration/SystemConfiguration.h>
37 #include <SystemConfiguration/SCPrivate.h>
38 #include "SCDynamicStoreInternal.h"
39 #include "config.h" /* MiG generated file */
40
41 Boolean
42 SCDynamicStoreNotifyValue(SCDynamicStoreRef store,
43 CFStringRef key)
44 {
45 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
46 kern_return_t status;
47 CFDataRef utfKey; /* serialized key */
48 xmlData_t myKeyRef;
49 CFIndex myKeyLen;
50 int sc_status;
51
52 if (_sc_verbose) {
53 SCLog(TRUE, LOG_DEBUG, CFSTR("SCDynamicStoreNotifyValue:"));
54 SCLog(TRUE, LOG_DEBUG, CFSTR(" key = %@"), key);
55 }
56
57 if (!store) {
58 /* sorry, you must provide a session */
59 _SCErrorSet(kSCStatusNoStoreSession);
60 return FALSE;
61 }
62
63 if (storePrivate->server == MACH_PORT_NULL) {
64 /* sorry, you must have an open session to play */
65 _SCErrorSet(kSCStatusNoStoreServer);
66 return FALSE;
67 }
68
69 /* serialize the key */
70 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
71 _SCErrorSet(kSCStatusFailed);
72 return FALSE;
73 }
74
75 /* send the key to the server */
76 status = confignotify(storePrivate->server,
77 myKeyRef,
78 myKeyLen,
79 (int *)&sc_status);
80
81 /* clean up */
82 CFRelease(utfKey);
83
84 if (status != KERN_SUCCESS) {
85 if (status != MACH_SEND_INVALID_DEST)
86 SCLog(_sc_verbose, LOG_DEBUG, CFSTR("confignotify(): %s"), mach_error_string(status));
87 (void) mach_port_destroy(mach_task_self(), storePrivate->server);
88 storePrivate->server = MACH_PORT_NULL;
89 _SCErrorSet(status);
90 return FALSE;
91 }
92
93 if (sc_status != kSCStatusOK) {
94 _SCErrorSet(sc_status);
95 return FALSE;
96 }
97
98 return TRUE;
99 }