2 * Copyright (c) 2000-2009 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>
30 #include <sys/syslog.h>
31 #include <mach/message.h>
33 #include <CoreFoundation/CoreFoundation.h>
35 /* SCDynamicStore SPIs */
36 #include <SystemConfiguration/SCDynamicStorePrivate.h>
37 #include <SystemConfiguration/SCDynamicStoreCopySpecificPrivate.h>
38 #include <SystemConfiguration/SCDynamicStoreSetSpecificPrivate.h>
40 /* SCPreferences SPIs */
41 #include <SystemConfiguration/SCPreferencesPrivate.h>
42 #include <SystemConfiguration/SCPreferencesGetSpecificPrivate.h>
43 #include <SystemConfiguration/SCPreferencesSetSpecificPrivate.h>
45 /* [private] Schema Definitions (for SCDynamicStore and SCPreferences) */
46 #include <SystemConfiguration/SCSchemaDefinitionsPrivate.h>
48 /* SCNetworkConfiguration SPIs */
49 #include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
51 /* SCNetworkConnection SPIs */
52 #include <SystemConfiguration/SCNetworkConnectionPrivate.h>
55 #include <SystemConfiguration/SCPreferencesKeychainPrivate.h>
61 /* framework variables */
62 extern int _sc_debug
; /* non-zero if debugging enabled */
63 extern int _sc_verbose
; /* non-zero if verbose logging enabled */
64 extern int _sc_log
; /* 0 if SC messages should be written to stdout/stderr,
65 1 if SC messages should be logged w/asl(3),
66 2 if SC messages should be written to stdout/stderr AND logged */
69 @group SCNetworkReachabilityCreateWithOptions #defines
70 @discussion The following defines the keys and values that can
71 be passed to the SCNetworkReachabilityCreateWithOptions
76 @constant kSCNetworkReachabilityOptionNodeName
77 @discussion A CFString that will be passed to getaddrinfo(3). An acceptable
78 value is either a valid host name or a numeric host address string
79 consisting of a dotted decimal IPv4 address or an IPv6 address.
81 #define kSCNetworkReachabilityOptionNodeName CFSTR("nodename")
84 @constant kSCNetworkReachabilityOptionServName
85 @discussion A CFString that will be passed to getaddrinfo(3). An acceptable
86 value is either a decimal port number or a service name listed in
89 #define kSCNetworkReachabilityOptionServName CFSTR("servname")
92 @constant kSCNetworkReachabilityOptionHints
93 @discussion A CFData wrapping a "struct addrinfo" that will be passed to
94 getaddrinfo(3). The caller can supply any of the ai_family,
95 ai_socktype, ai_protocol, and ai_flags structure elements. All
96 other elements must be 0 or the null pointer.
98 #define kSCNetworkReachabilityOptionHints CFSTR("hints")
101 @constant kSCNetworkReachabilityOptionConnectionOnDemandByPass
102 @discussion A CFBoolean that indicates if we should bypass the VPNOnDemand
103 checks for this target.
105 #define kSCNetworkReachabilityOptionConnectionOnDemandByPass CFSTR("ConnectionOnDemandByPass")
114 @function _SCErrorSet
115 @discussion Sets the last SystemConfiguration.framework API error code.
116 @param error The error encountered.
118 void _SCErrorSet (int error
);
121 @function _SCSerialize
122 @discussion Serialize a CFPropertyList object for passing
124 @param obj CFPropertyList object to serialize
125 @param xml A pointer to a CFDataRef, NULL if data should be
127 @param dataRef A pointer to the newly allocated/serialized data
128 @param dataLen A pointer to the length in bytes of the newly
129 allocated/serialized data
131 Boolean
_SCSerialize (CFPropertyListRef obj
,
137 @function _SCUnserialize
138 @discussion Unserialize a stream of bytes passed from/to configd
139 into a CFPropertyList object.
140 @param obj A pointer to memory that will be filled with the CFPropertyList
141 associated with the stream of bytes.
142 @param xml CFDataRef with the serialized data
143 @param dataRef A pointer to the serialized data
144 @param dataLen A pointer to the length of the serialized data
146 Specify either "xml" or "data/dataLen".
148 Boolean
_SCUnserialize (CFPropertyListRef
*obj
,
154 @function _SCSerializeString
155 @discussion Serialize a CFString object for passing
157 @param str CFString key to serialize
158 @param data A pointer to a CFDataRef, NULL if storage should be
160 @param dataRef A pointer to the newly allocated/serialized data
161 @param dataLen A pointer to the length in bytes of the newly
162 allocated/serialized data
164 Boolean
_SCSerializeString (CFStringRef str
,
170 @function _SCUnserializeString
171 @discussion Unserialize a stream of bytes passed from/to configd
172 into a CFString object.
173 @param str A pointer to memory that will be filled with the CFString
174 associated with the stream of bytes.
175 @param utf8 CFDataRef with the serialized data
176 @param dataRef A pointer to the serialized data
177 @param dataLen A pointer to the length of the serialized data
179 Specify either "utf8" or "data/dataLen".
181 Boolean
_SCUnserializeString (CFStringRef
*str
,
187 @function _SCSerializeData
188 @discussion Serialize a CFData object for passing
190 @param data CFData key to serialize
191 @param dataRef A pointer to the newly allocated/serialized data
192 @param dataLen A pointer to the length in bytes of the newly
193 allocated/serialized data
195 Boolean
_SCSerializeData (CFDataRef data
,
200 @function _SCUnserializeData
201 @discussion Unserialize a stream of bytes passed from/to configd
202 into a CFData object.
203 @param data A pointer to memory that will be filled with the CFData
204 associated with the stream of bytes.
205 @param dataRef A pointer to the serialized data
206 @param dataLen A pointer to the length of the serialized data
208 Boolean
_SCUnserializeData (CFDataRef
*data
,
213 @function _SCSerializeMultiple
214 @discussion Convert a CFDictionary containing a set of CFPropertlyList
215 values into a CFDictionary containing a set of serialized CFData
217 @param dict The CFDictionary with CFPropertyList values.
218 @result The serialized CFDictionary with CFData values
220 CFDictionaryRef
_SCSerializeMultiple (CFDictionaryRef dict
);
223 @function _SCUnserializeMultiple
224 @discussion Convert a CFDictionary containing a set of CFData
225 values into a CFDictionary containing a set of serialized
226 CFPropertlyList values.
227 @param dict The CFDictionary with CFData values.
228 @result The serialized CFDictionary with CFPropertyList values
230 CFDictionaryRef
_SCUnserializeMultiple (CFDictionaryRef dict
);
233 @function _SC_cfstring_to_cstring
234 @discussion Extracts a C-string from a CFString.
235 @param cfstr The CFString to extract the data from.
236 @param buf A user provided buffer of the specified length. If NULL,
237 a new buffer will be allocated to contain the C-string. It
238 is the responsiblity of the caller to free an allocated
240 @param bufLen The size of the user provided buffer.
241 @param encoding The string encoding
242 @result If the extraction (conversion) is successful then a pointer
243 to the user provided (or allocated) buffer is returned, NULL
244 if the string could not be extracted.
246 char * _SC_cfstring_to_cstring (CFStringRef cfstr
,
249 CFStringEncoding encoding
);
252 * @function _SC_sockaddr_to_string
253 * @discussion Formats a "struct sockaddr" for reporting
254 * @param address The address to format
255 * @param buf A user provided buffer of the specified length.
256 * @param bufLen The size of the user provided buffer.
258 void _SC_sockaddr_to_string (const struct sockaddr
*address
,
263 @function _SC_sendMachMessage
264 @discussion Sends a trivial mach message (one with just a
265 message ID) to the specified port.
266 @param port The mach port.
267 @param msg_id The message id.
269 void _SC_sendMachMessage (mach_port_t port
,
270 mach_msg_id_t msg_id
);
274 @function _SCCopyDescription
275 @discussion Returns a formatted textual description of a CF object.
276 @param cf The CFType object (a generic reference of type CFTypeRef) from
277 which to derive a description.
278 @param formatOptions A dictionary containing formatting options for the object.
279 @result A string that contains a formatted description of cf.
281 CFStringRef
_SCCopyDescription (CFTypeRef cf
,
282 CFDictionaryRef formatOptions
);
287 @discussion Conditionally issue a log message.
288 @param condition A boolean value indicating if the message should be logged
289 @param level A syslog(3) logging priority.
290 @param formatString The format string
291 @result The specified message will be written to the system message
292 logger (See syslogd(8)).
294 void SCLog (Boolean condition
,
296 CFStringRef formatString
,
302 @discussion Issue a log message.
303 @param asl An asl client handle to be used for logging. If NULL, a shared
305 @param msg An asl msg structure to be used for logging. If NULL, a default
306 asl msg will be used.
307 @param level A asl(3) logging priority. Passing the complement of a logging
308 priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
309 NOT being split by a "\n".
310 @param formatString The format string
311 @result The specified message will be written to the system message
312 logger (See syslogd(8)).
314 void SCLOG (aslclient asl
,
317 CFStringRef formatString
,
323 @discussion Conditionally issue a debug message.
324 @param condition A boolean value indicating if the message should be written
325 @param stream The output stream for the log message.
326 @param formatString The format string
327 @result The message will be written to the specified stream
330 void SCPrint (Boolean condition
,
332 CFStringRef formatString
,
337 @discussion Conditionally issue a debug message with a time stamp.
338 @param condition A boolean value indicating if the message should be written
339 @param stream The output stream for the log message.
340 @param formatString The format string
341 @result The message will be written to the specified stream
344 void SCTrace (Boolean condition
,
346 CFStringRef formatString
,
350 @function SCNetworkReachabilityCopyOnDemandService
351 @discussion For target hosts that require an OnDemand connection, returns
352 the SCNetworkService associated with the connection and user
353 options to use with SCNetworkConnectionStart.
354 @result The SCNetworkService for the target; NULL if there is
355 no associated OnDemand service.
358 SCNetworkReachabilityCopyOnDemandService (SCNetworkReachabilityRef target
,
359 CFDictionaryRef
*userOptions
);
362 @function SCNetworkReachabilityCopyResolvedAddress
363 @discussion Return the resolved addresses associated with the
365 @result A CFArray[CFData], where each CFData is a (struct sockaddr)
368 SCNetworkReachabilityCopyResolvedAddress (SCNetworkReachabilityRef target
,
372 @function SCNetworkReachabilityCreateWithOptions
373 @discussion Creates a reference to a specified network host. The
374 options allow the caller to specify the node name and/or
375 the service name. This reference can be used later to
376 monitor the reachability of the target host.
377 @param allocator The CFAllocator that should be used to allocate
378 memory for the SCNetworkReachability object.
379 This parameter may be NULL in which case the current
380 default CFAllocator is used. If this reference is not
381 a valid CFAllocator, the behavior is undefined.
382 @param options A CFDictionary containing options specifying the
383 network host. The options reflect the arguments that would
384 be passed to getaddrinfo().
386 SCNetworkReachabilityRef
387 SCNetworkReachabilityCreateWithOptions (CFAllocatorRef allocator
,
388 CFDictionaryRef options
);
391 @function _SC_checkResolverReachabilityByAddress
392 @discussion Check the reachability of a reverse DNS query
395 _SC_checkResolverReachabilityByAddress (SCDynamicStoreRef
*storeP
,
396 SCNetworkReachabilityFlags
*flags
,
398 struct sockaddr
*sa
);
400 #if !TARGET_OS_IPHONE
402 * DOS encoding/codepage
405 _SC_dos_encoding_and_codepage (CFStringEncoding macEncoding
,
407 CFStringEncoding
*dosEncoding
,
408 UInt32
*dosCodepage
);
409 #endif // !TARGET_OS_IPHONE
412 * object / CFRunLoop management
415 _SC_signalRunLoop (CFTypeRef obj
,
416 CFRunLoopSourceRef rls
,
420 _SC_isScheduled (CFTypeRef obj
,
421 CFRunLoopRef runLoop
,
422 CFStringRef runLoopMode
,
423 CFMutableArrayRef rlList
);
426 _SC_schedule (CFTypeRef obj
,
427 CFRunLoopRef runLoop
,
428 CFStringRef runLoopMode
,
429 CFMutableArrayRef rlList
);
432 _SC_unschedule (CFTypeRef obj
,
433 CFRunLoopRef runLoop
,
434 CFStringRef runLoopMode
,
435 CFMutableArrayRef rlList
,
442 _SC_CFBundleGet (void);
445 _SC_CFBundleCopyNonLocalizedString (CFBundleRef bundle
,
448 CFStringRef tableName
);
453 static __inline__ Boolean
454 _SC_CFEqual(CFTypeRef val1
, CFTypeRef val2
)
459 if (val1
!= NULL
&& val2
!= NULL
) {
460 return CFEqual(val1
, val2
);
469 #ifdef DEBUG_MACH_PORT_ALLOCATIONS
470 #define __MACH_PORT_DEBUG(cond, str, port) \
472 if (cond) _SC_logMachPortReferences(str, port); \
474 #else // DEBUG_MACH_PORT_ALLOCATIONS
475 #define __MACH_PORT_DEBUG(cond, str, port)
476 #endif // DEBUG_MACH_PORT_ALLOCATIONS
479 _SC_logMachPortStatus (void);
482 _SC_logMachPortReferences (const char *str
,
486 _SC_copyBacktrace (void);
490 #endif /* _SCPRIVATE_H */