2 * Copyright (c) 2000-2008 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 */
66 @group SCNetworkReachabilityCreateWithOptions #defines
67 @discussion The following defines the keys and values that can
68 be passed to the SCNetworkReachabilityCreateWithOptions
73 @constant kSCNetworkReachabilityOptionNodeName
74 @discussion A CFString that will be passed to getaddrinfo(3). An acceptable
75 value is either a valid host name or a numeric host address string
76 consisting of a dotted decimal IPv4 address or an IPv6 address.
78 #define kSCNetworkReachabilityOptionNodeName CFSTR("nodename")
81 @constant kSCNetworkReachabilityOptionServName
82 @discussion A CFString that will be passed to getaddrinfo(3). An acceptable
83 value is either a decimal port number or a service name listed in
86 #define kSCNetworkReachabilityOptionServName CFSTR("servname")
89 @constant kSCNetworkReachabilityOptionHints
90 @discussion A CFData wrapping a "struct addrinfo" that will be passed to
91 getaddrinfo(3). The caller can supply any of the ai_family,
92 ai_socktype, ai_protocol, and ai_flags structure elements. All
93 other elements must be 0 or the null pointer.
95 #define kSCNetworkReachabilityOptionHints CFSTR("hints")
104 @function _SCErrorSet
105 @discussion Sets the last SystemConfiguration.framework API error code.
106 @param error The error encountered.
108 void _SCErrorSet (int error
);
111 @function _SCSerialize
112 @discussion Serialize a CFPropertyList object for passing
114 @param obj CFPropertyList object to serialize
115 @param xml A pointer to a CFDataRef, NULL if data should be
117 @param dataRef A pointer to the newly allocated/serialized data
118 @param dataLen A pointer to the length in bytes of the newly
119 allocated/serialized data
121 Boolean
_SCSerialize (CFPropertyListRef obj
,
127 @function _SCUnserialize
128 @discussion Unserialize a stream of bytes passed from/to configd
129 into a CFPropertyList object.
130 @param obj A pointer to memory that will be filled with the CFPropertyList
131 associated with the stream of bytes.
132 @param xml CFDataRef with the serialized data
133 @param dataRef A pointer to the serialized data
134 @param dataLen A pointer to the length of the serialized data
136 Specify either "xml" or "data/dataLen".
138 Boolean
_SCUnserialize (CFPropertyListRef
*obj
,
144 @function _SCSerializeString
145 @discussion Serialize a CFString object for passing
147 @param str CFString key to serialize
148 @param data A pointer to a CFDataRef, NULL if storage should be
150 @param dataRef A pointer to the newly allocated/serialized data
151 @param dataLen A pointer to the length in bytes of the newly
152 allocated/serialized data
154 Boolean
_SCSerializeString (CFStringRef str
,
160 @function _SCUnserializeString
161 @discussion Unserialize a stream of bytes passed from/to configd
162 into a CFString object.
163 @param str A pointer to memory that will be filled with the CFString
164 associated with the stream of bytes.
165 @param utf8 CFDataRef with the serialized data
166 @param dataRef A pointer to the serialized data
167 @param dataLen A pointer to the length of the serialized data
169 Specify either "utf8" or "data/dataLen".
171 Boolean
_SCUnserializeString (CFStringRef
*str
,
177 @function _SCSerializeData
178 @discussion Serialize a CFData object for passing
180 @param data CFData key to serialize
181 @param dataRef A pointer to the newly allocated/serialized data
182 @param dataLen A pointer to the length in bytes of the newly
183 allocated/serialized data
185 Boolean
_SCSerializeData (CFDataRef data
,
190 @function _SCUnserializeData
191 @discussion Unserialize a stream of bytes passed from/to configd
192 into a CFData object.
193 @param data A pointer to memory that will be filled with the CFData
194 associated with the stream of bytes.
195 @param dataRef A pointer to the serialized data
196 @param dataLen A pointer to the length of the serialized data
198 Boolean
_SCUnserializeData (CFDataRef
*data
,
203 @function _SCSerializeMultiple
204 @discussion Convert a CFDictionary containing a set of CFPropertlyList
205 values into a CFDictionary containing a set of serialized CFData
207 @param dict The CFDictionary with CFPropertyList values.
208 @result The serialized CFDictionary with CFData values
210 CFDictionaryRef
_SCSerializeMultiple (CFDictionaryRef dict
);
213 @function _SCUnserializeMultiple
214 @discussion Convert a CFDictionary containing a set of CFData
215 values into a CFDictionary containing a set of serialized
216 CFPropertlyList values.
217 @param dict The CFDictionary with CFData values.
218 @result The serialized CFDictionary with CFPropertyList values
220 CFDictionaryRef
_SCUnserializeMultiple (CFDictionaryRef dict
);
223 @function _SC_cfstring_to_cstring
224 @discussion Extracts a C-string from a CFString.
225 @param cfstr The CFString to extract the data from.
226 @param buf A user provided buffer of the specified length. If NULL,
227 a new buffer will be allocated to contain the C-string. It
228 is the responsiblity of the caller to free an allocated
230 @param bufLen The size of the user provided buffer.
231 @param encoding The string encoding
232 @result If the extraction (conversion) is successful then a pointer
233 to the user provided (or allocated) buffer is returned, NULL
234 if the string could not be extracted.
236 char * _SC_cfstring_to_cstring (CFStringRef cfstr
,
239 CFStringEncoding encoding
);
242 * @function _SC_sockaddr_to_string
243 * @discussion Formats a "struct sockaddr" for reporting
244 * @param address The address to format
245 * @param buf A user provided buffer of the specified length.
246 * @param bufLen The size of the user provided buffer.
248 void _SC_sockaddr_to_string (const struct sockaddr
*address
,
253 @function _SC_sendMachMessage
254 @discussion Sends a trivial mach message (one with just a
255 message ID) to the specified port.
256 @param port The mach port.
257 @param msg_id The message id.
259 void _SC_sendMachMessage (mach_port_t port
,
260 mach_msg_id_t msg_id
);
265 @discussion Conditionally issue a log message.
266 @param condition A boolean value indicating if the message should be logged
267 @param level A syslog(3) logging priority.
268 @param formatString The format string
269 @result The specified message will be written to the system message
270 logger (See syslogd(8)).
272 void SCLog (Boolean condition
,
274 CFStringRef formatString
,
279 @discussion Conditionally issue a debug message.
280 @param condition A boolean value indicating if the message should be written
281 @param stream The output stream for the log message.
282 @param formatString The format string
283 @result The message will be written to the specified stream
286 void SCPrint (Boolean condition
,
288 CFStringRef formatString
,
293 @discussion Conditionally issue a debug message with a time stamp.
294 @param condition A boolean value indicating if the message should be written
295 @param stream The output stream for the log message.
296 @param formatString The format string
297 @result The message will be written to the specified stream
300 void SCTrace (Boolean condition
,
302 CFStringRef formatString
,
306 @function SCNetworkReachabilityCreateWithOptions
307 @discussion Creates a reference to a specified network host. The
308 options allow the caller to specify the node name and/or
309 the service name. This reference can be used later to
310 monitor the reachability of the target host.
311 @param allocator The CFAllocator that should be used to allocate
312 memory for the SCNetworkReachability object.
313 This parameter may be NULL in which case the current
314 default CFAllocator is used. If this reference is not
315 a valid CFAllocator, the behavior is undefined.
316 @param options A CFDictionary containing options specifying the
317 network host. The options reflect the arguments that would
318 be passed to getaddrinfo().
320 SCNetworkReachabilityRef
321 SCNetworkReachabilityCreateWithOptions (CFAllocatorRef allocator
,
322 CFDictionaryRef options
);
325 * DOS encoding/codepage
328 _SC_dos_encoding_and_codepage (CFStringEncoding macEncoding
,
330 CFStringEncoding
*dosEncoding
,
331 UInt32
*dosCodepage
);
334 _SC_dos_copy_string (CFStringRef str
,
335 CFStringEncoding dosEncoding
,
339 * object / CFRunLoop management
342 _SC_signalRunLoop (CFTypeRef obj
,
343 CFRunLoopSourceRef rls
,
347 _SC_isScheduled (CFTypeRef obj
,
348 CFRunLoopRef runLoop
,
349 CFStringRef runLoopMode
,
350 CFMutableArrayRef rlList
);
353 _SC_schedule (CFTypeRef obj
,
354 CFRunLoopRef runLoop
,
355 CFStringRef runLoopMode
,
356 CFMutableArrayRef rlList
);
359 _SC_unschedule (CFTypeRef obj
,
360 CFRunLoopRef runLoop
,
361 CFStringRef runLoopMode
,
362 CFMutableArrayRef rlList
,
369 _SC_CFBundleGet (void);
372 _SC_CFBundleCopyNonLocalizedString (CFBundleRef bundle
,
375 CFStringRef tableName
);
380 static __inline__ Boolean
381 _SC_CFEqual(CFTypeRef val1
, CFTypeRef val2
)
386 if (val1
!= NULL
&& val2
!= NULL
) {
387 return CFEqual(val1
, val2
);
394 #endif /* _SCPRIVATE_H */