]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCPrivate.h
0741194a7e88069674ec204e322f386aa8850930
[apple/configd.git] / SystemConfiguration.fproj / SCPrivate.h
1 /*
2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _SCPRIVATE_H
25 #define _SCPRIVATE_H
26
27 #include <sys/cdefs.h>
28 #include <sys/socket.h>
29 #include <sys/syslog.h>
30 #include <mach/message.h>
31
32 #include <CoreFoundation/CoreFoundation.h>
33
34 /* SCDynamicStore SPIs */
35 #include <SystemConfiguration/SCDynamicStorePrivate.h>
36 #include <SystemConfiguration/SCDynamicStoreCopySpecificPrivate.h>
37 #include <SystemConfiguration/SCDynamicStoreSetSpecificPrivate.h>
38
39 /* SCPreferences SPIs */
40 #include <SystemConfiguration/SCPreferencesPrivate.h>
41 #include <SystemConfiguration/SCPreferencesGetSpecificPrivate.h>
42 #include <SystemConfiguration/SCPreferencesSetSpecificPrivate.h>
43
44 /* [private] Schema Definitions (for SCDynamicStore and SCPreferences) */
45 #include <SystemConfiguration/SCSchemaDefinitionsPrivate.h>
46
47 /* SCNetworkConfiguration SPIs */
48 #include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
49
50 /* SCNetworkConnection SPIs */
51 #include <SystemConfiguration/SCNetworkConnectionPrivate.h>
52
53 /* Keychain SPIs */
54 #include <SystemConfiguration/SCPreferencesKeychainPrivate.h>
55
56 /*!
57 @header SCPrivate
58 */
59
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 */
64
65 /*!
66 @group SCNetworkReachabilityCreateWithOptions #defines
67 @discussion The following defines the keys and values that can
68 be passed to the SCNetworkReachabilityCreateWithOptions
69 API.
70 */
71
72 /*!
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.
77 */
78 #define kSCNetworkReachabilityOptionNodeName CFSTR("nodename")
79
80 /*!
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
84 services(5).
85 */
86 #define kSCNetworkReachabilityOptionServName CFSTR("servname")
87
88 /*!
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.
94 */
95 #define kSCNetworkReachabilityOptionHints CFSTR("hints")
96
97 /*!
98 @group
99 */
100
101 __BEGIN_DECLS
102
103 /*!
104 @function _SCErrorSet
105 @discussion Sets the last SystemConfiguration.framework API error code.
106 @param error The error encountered.
107 */
108 void _SCErrorSet (int error);
109
110 /*!
111 @function _SCSerialize
112 @discussion Serialize a CFPropertyList object for passing
113 to/from configd.
114 @param obj CFPropertyList object to serialize
115 @param xml A pointer to a CFDataRef, NULL if data should be
116 vm_allocated.
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
120 */
121 Boolean _SCSerialize (CFPropertyListRef obj,
122 CFDataRef *xml,
123 void **dataRef,
124 CFIndex *dataLen);
125
126 /*!
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
135
136 Specify either "xml" or "data/dataLen".
137 */
138 Boolean _SCUnserialize (CFPropertyListRef *obj,
139 CFDataRef xml,
140 void *dataRef,
141 CFIndex dataLen);
142
143 /*!
144 @function _SCSerializeString
145 @discussion Serialize a CFString object for passing
146 to/from configd.
147 @param str CFString key to serialize
148 @param data A pointer to a CFDataRef, NULL if storage should be
149 vm_allocated.
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
153 */
154 Boolean _SCSerializeString (CFStringRef str,
155 CFDataRef *data,
156 void **dataRef,
157 CFIndex *dataLen);
158
159 /*!
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
168
169 Specify either "utf8" or "data/dataLen".
170 */
171 Boolean _SCUnserializeString (CFStringRef *str,
172 CFDataRef utf8,
173 void *dataRef,
174 CFIndex dataLen);
175
176 /*!
177 @function _SCSerializeData
178 @discussion Serialize a CFData object for passing
179 to/from configd.
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
184 */
185 Boolean _SCSerializeData (CFDataRef data,
186 void **dataRef,
187 CFIndex *dataLen);
188
189 /*!
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
197 */
198 Boolean _SCUnserializeData (CFDataRef *data,
199 void *dataRef,
200 CFIndex dataLen);
201
202 /*!
203 @function _SCSerializeMultiple
204 @discussion Convert a CFDictionary containing a set of CFPropertlyList
205 values into a CFDictionary containing a set of serialized CFData
206 values.
207 @param dict The CFDictionary with CFPropertyList values.
208 @result The serialized CFDictionary with CFData values
209 */
210 CFDictionaryRef _SCSerializeMultiple (CFDictionaryRef dict);
211
212 /*!
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
219 */
220 CFDictionaryRef _SCUnserializeMultiple (CFDictionaryRef dict);
221
222 /*!
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
229 buffer.
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.
235 */
236 char * _SC_cfstring_to_cstring (CFStringRef cfstr,
237 char *buf,
238 CFIndex bufLen,
239 CFStringEncoding encoding);
240
241 /*!
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.
247 */
248 void _SC_sockaddr_to_string (const struct sockaddr *address,
249 char *buf,
250 size_t bufLen);
251
252 /*!
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.
258 */
259 void _SC_sendMachMessage (mach_port_t port,
260 mach_msg_id_t msg_id);
261
262
263 /*!
264 @function SCLog
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)).
271 */
272 void SCLog (Boolean condition,
273 int level,
274 CFStringRef formatString,
275 ...);
276
277 /*!
278 @function SCPrint
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
284 stream.
285 */
286 void SCPrint (Boolean condition,
287 FILE *stream,
288 CFStringRef formatString,
289 ...);
290
291 /*!
292 @function SCTrace
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
298 stream.
299 */
300 void SCTrace (Boolean condition,
301 FILE *stream,
302 CFStringRef formatString,
303 ...);
304
305 /*!
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().
319 */
320 SCNetworkReachabilityRef
321 SCNetworkReachabilityCreateWithOptions (CFAllocatorRef allocator,
322 CFDictionaryRef options);
323
324 /*
325 * DOS encoding/codepage
326 */
327 void
328 _SC_dos_encoding_and_codepage (CFStringEncoding macEncoding,
329 UInt32 macRegion,
330 CFStringEncoding *dosEncoding,
331 UInt32 *dosCodepage);
332
333 CFDataRef
334 _SC_dos_copy_string (CFStringRef str,
335 CFStringEncoding dosEncoding,
336 UInt32 dosCodepage);
337
338 /*
339 * object / CFRunLoop management
340 */
341 void
342 _SC_signalRunLoop (CFTypeRef obj,
343 CFRunLoopSourceRef rls,
344 CFArrayRef rlList);
345
346 Boolean
347 _SC_isScheduled (CFTypeRef obj,
348 CFRunLoopRef runLoop,
349 CFStringRef runLoopMode,
350 CFMutableArrayRef rlList);
351
352 void
353 _SC_schedule (CFTypeRef obj,
354 CFRunLoopRef runLoop,
355 CFStringRef runLoopMode,
356 CFMutableArrayRef rlList);
357
358 Boolean
359 _SC_unschedule (CFTypeRef obj,
360 CFRunLoopRef runLoop,
361 CFStringRef runLoopMode,
362 CFMutableArrayRef rlList,
363 Boolean all);
364
365 /*
366 * bundle access
367 */
368 CFBundleRef
369 _SC_CFBundleGet (void);
370
371 CFStringRef
372 _SC_CFBundleCopyNonLocalizedString (CFBundleRef bundle,
373 CFStringRef key,
374 CFStringRef value,
375 CFStringRef tableName);
376
377 /*
378 * misc
379 */
380 static __inline__ Boolean
381 _SC_CFEqual(CFTypeRef val1, CFTypeRef val2)
382 {
383 if (val1 == val2) {
384 return TRUE;
385 }
386 if (val1 != NULL && val2 != NULL) {
387 return CFEqual(val1, val2);
388 }
389 return FALSE;
390 }
391
392 __END_DECLS
393
394 #endif /* _SCPRIVATE_H */