2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
27 #include <sys/cdefs.h>
28 #include <sys/socket.h>
29 #include <sys/syslog.h>
30 #include <mach/message.h>
32 #include <CoreFoundation/CoreFoundation.h>
34 /* SCDynamicStore SPIs */
35 #include <SystemConfiguration/SCDynamicStorePrivate.h>
36 #include <SystemConfiguration/SCDynamicStoreCopySpecificPrivate.h>
37 #include <SystemConfiguration/SCDynamicStoreSetSpecificPrivate.h>
39 /* SCPreferences SPIs */
40 #include <SystemConfiguration/SCPreferencesPrivate.h>
41 #include <SystemConfiguration/SCPreferencesGetSpecificPrivate.h>
42 #include <SystemConfiguration/SCPreferencesSetSpecificPrivate.h>
44 /* [private] Schema Definitions (for SCDynamicStore and SCPreferences) */
45 #include <SystemConfiguration/SCSchemaDefinitionsPrivate.h>
47 /* SCNetworkConfiguration SPIs */
48 #include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
50 /* SCNetworkConnection SPIs */
51 #include <SystemConfiguration/SCNetworkConnectionPrivate.h>
54 #include <SystemConfiguration/SCPreferencesKeychainPrivate.h>
60 /* framework variables */
61 extern Boolean _sc_debug
; /* TRUE if debugging enabled */
62 extern Boolean _sc_verbose
; /* TRUE if verbose logging enabled */
63 extern Boolean _sc_log
; /* TRUE if SCLog() output goes to syslog */
69 @discussion Sets the last SystemConfiguration.framework API error code.
70 @param error The error encountered.
72 void _SCErrorSet (int error
);
75 @function _SCSerialize
76 @discussion Serialize a CFPropertyList object for passing
78 @param obj CFPropertyList object to serialize
79 @param xml A pointer to a CFDataRef, NULL if data should be
81 @param dataRef A pointer to the newly allocated/serialized data
82 @param dataLen A pointer to the length in bytes of the newly
83 allocated/serialized data
85 Boolean
_SCSerialize (CFPropertyListRef obj
,
91 @function _SCUnserialize
92 @discussion Unserialize a stream of bytes passed from/to configd
93 into a CFPropertyList object.
94 @param obj A pointer to memory that will be filled with the CFPropertyList
95 associated with the stream of bytes.
96 @param xml CFDataRef with the serialized data
97 @param dataRef A pointer to the serialized data
98 @param dataLen A pointer to the length of the serialized data
100 Specify either "xml" or "data/dataLen".
102 Boolean
_SCUnserialize (CFPropertyListRef
*obj
,
108 @function _SCSerializeString
109 @discussion Serialize a CFString object for passing
111 @param str CFString key to serialize
112 @param data A pointer to a CFDataRef, NULL if storage should be
114 @param dataRef A pointer to the newly allocated/serialized data
115 @param dataLen A pointer to the length in bytes of the newly
116 allocated/serialized data
118 Boolean
_SCSerializeString (CFStringRef str
,
124 @function _SCUnserializeString
125 @discussion Unserialize a stream of bytes passed from/to configd
126 into a CFString object.
127 @param str A pointer to memory that will be filled with the CFString
128 associated with the stream of bytes.
129 @param utf8 CFDataRef with the serialized data
130 @param dataRef A pointer to the serialized data
131 @param dataLen A pointer to the length of the serialized data
133 Specify either "utf8" or "data/dataLen".
135 Boolean
_SCUnserializeString (CFStringRef
*str
,
141 @function _SCSerializeData
142 @discussion Serialize a CFData object for passing
144 @param data CFData key to serialize
145 @param dataRef A pointer to the newly allocated/serialized data
146 @param dataLen A pointer to the length in bytes of the newly
147 allocated/serialized data
149 Boolean
_SCSerializeData (CFDataRef data
,
154 @function _SCUnserializeData
155 @discussion Unserialize a stream of bytes passed from/to configd
156 into a CFData object.
157 @param data A pointer to memory that will be filled with the CFData
158 associated with the stream of bytes.
159 @param dataRef A pointer to the serialized data
160 @param dataLen A pointer to the length of the serialized data
162 Boolean
_SCUnserializeData (CFDataRef
*data
,
167 @function _SCSerializeMultiple
168 @discussion Convert a CFDictionary containing a set of CFPropertlyList
169 values into a CFDictionary containing a set of serialized CFData
171 @param dict The CFDictionary with CFPropertyList values.
172 @result The serialized CFDictionary with CFData values
174 CFDictionaryRef
_SCSerializeMultiple (CFDictionaryRef dict
);
177 @function _SCUnserializeMultiple
178 @discussion Convert a CFDictionary containing a set of CFData
179 values into a CFDictionary containing a set of serialized
180 CFPropertlyList values.
181 @param dict The CFDictionary with CFData values.
182 @result The serialized CFDictionary with CFPropertyList values
184 CFDictionaryRef
_SCUnserializeMultiple (CFDictionaryRef dict
);
187 @function _SC_cfstring_to_cstring
188 @discussion Extracts a C-string from a CFString.
189 @param cfstr The CFString to extract the data from.
190 @param buf A user provided buffer of the specified length. If NULL,
191 a new buffer will be allocated to contain the C-string. It
192 is the responsiblity of the caller to free an allocated
194 @param bufLen The size of the user provided buffer.
195 @param encoding The string encoding
196 @result If the extraction (conversion) is successful then a pointer
197 to the user provided (or allocated) buffer is returned, NULL
198 if the string could not be extracted.
200 char * _SC_cfstring_to_cstring (CFStringRef cfstr
,
203 CFStringEncoding encoding
);
206 * @function _SC_sockaddr_to_string
207 * @discussion Formats a "struct sockaddr" for reporting
208 * @param address The address to format
209 * @param buf A user provided buffer of the specified length.
210 * @param bufLen The size of the user provided buffer.
212 void _SC_sockaddr_to_string (const struct sockaddr
*address
,
217 @function _SC_sendMachMessage
218 @discussion Sends a trivial mach message (one with just a
219 message ID) to the specified port.
220 @param port The mach port.
221 @param msg_id The message id.
223 void _SC_sendMachMessage (mach_port_t port
,
224 mach_msg_id_t msg_id
);
229 @discussion Conditionally issue a log message.
230 @param condition A boolean value indicating if the message should be logged
231 @param level A syslog(3) logging priority.
232 @param formatString The format string
233 @result The specified message will be written to the system message
234 logger (See syslogd(8)).
236 void SCLog (Boolean condition
,
238 CFStringRef formatString
,
243 @discussion Conditionally issue a debug message.
244 @param condition A boolean value indicating if the message should be written
245 @param stream The output stream for the log message.
246 @param formatString The format string
247 @result The message will be written to the specified stream
250 void SCPrint (Boolean condition
,
252 CFStringRef formatString
,
257 @discussion Conditionally issue a debug message with a time stamp.
258 @param condition A boolean value indicating if the message should be written
259 @param stream The output stream for the log message.
260 @param formatString The format string
261 @result The message will be written to the specified stream
264 void SCTrace (Boolean condition
,
266 CFStringRef formatString
,
270 * DOS encoding/codepage
273 _SC_dos_encoding_and_codepage (CFStringEncoding macEncoding
,
275 CFStringEncoding
*dosEncoding
,
276 UInt32
*dosCodepage
);
279 _SC_dos_copy_string (CFStringRef str
,
280 CFStringEncoding dosEncoding
,
284 * object / CFRunLoop management
287 _SC_signalRunLoop (CFTypeRef obj
,
288 CFRunLoopSourceRef rls
,
292 _SC_isScheduled (CFTypeRef obj
,
293 CFRunLoopRef runLoop
,
294 CFStringRef runLoopMode
,
295 CFMutableArrayRef rlList
);
298 _SC_schedule (CFTypeRef obj
,
299 CFRunLoopRef runLoop
,
300 CFStringRef runLoopMode
,
301 CFMutableArrayRef rlList
);
304 _SC_unschedule (CFTypeRef obj
,
305 CFRunLoopRef runLoop
,
306 CFStringRef runLoopMode
,
307 CFMutableArrayRef rlList
,
314 _SC_CFBundleGet (void);
317 _SC_CFBundleCopyNonLocalizedString (CFBundleRef bundle
,
320 CFStringRef tableName
);
325 static __inline__ Boolean
326 _SC_CFEqual(CFTypeRef val1
, CFTypeRef val2
)
331 if (val1
!= NULL
&& val2
!= NULL
) {
332 return CFEqual(val1
, val2
);
339 #endif /* _SCPRIVATE_H */