1/* 2 * Copyright (c) 2000, 2001, 2005, 2010 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/* 25 * Modification History 26 * 27 * June 1, 2001 Allan Nathanson <ajn@apple.com> 28 * - public API conversion 29 * 30 * December 11, 2000 Allan Nathanson <ajn@apple.com> 31 * - initial revision 32 */ 33 34#include <SystemConfiguration/SystemConfiguration.h> 35 36#include <stdarg.h> 37 38/* 39 * SCDynamicStoreKeyCreate* 40 * - convenience routines that create a CFString key for an item in the store 41 */ 42 43/* 44 * Function: SCDynamicStoreKeyCreate 45 * Purpose: 46 * Creates a store key using the given format. 47 */ 48CFStringRef 49SCDynamicStoreKeyCreate(CFAllocatorRef allocator, 50 CFStringRef fmt, 51 ...) 52{ 53 va_list args; 54 CFStringRef result; 55 56 va_start(args, fmt); 57 result = CFStringCreateWithFormatAndArguments(allocator, 58 NULL, 59 fmt, 60 args); 61 va_end(args); 62 63 return result; 64} 65 66CFStringRef 67SCDynamicStoreKeyCreateNetworkGlobalEntity(CFAllocatorRef allocator, 68 CFStringRef domain, 69 CFStringRef entity) 70{ 71 return (CFStringCreateWithFormat(allocator, 72 NULL, 73 CFSTR("%@/%@/%@/%@"), 74 domain, 75 kSCCompNetwork, 76 kSCCompGlobal, 77 entity)); 78} 79 80CFStringRef 81SCDynamicStoreKeyCreateNetworkInterface(CFAllocatorRef allocator, 82 CFStringRef domain) 83{ 84 return (CFStringCreateWithFormat(allocator, 85 NULL, 86 CFSTR("%@/%@/%@"), 87 domain, 88 kSCCompNetwork, 89 kSCCompInterface)); 90} 91 92CFStringRef 93SCDynamicStoreKeyCreateNetworkInterfaceEntity(CFAllocatorRef allocator, 94 CFStringRef domain, 95 CFStringRef ifname, 96 CFStringRef entity) 97{ 98 if (entity == NULL) { 99 return (CFStringCreateWithFormat(allocator, 100 NULL, 101 CFSTR("%@/%@/%@/%@"), 102 domain, 103 kSCCompNetwork, 104 kSCCompInterface, 105 ifname)); 106 } else { 107 return (CFStringCreateWithFormat(allocator, 108 NULL, 109 CFSTR("%@/%@/%@/%@/%@"), 110 domain, 111 kSCCompNetwork, 112 kSCCompInterface, 113 ifname, 114 entity)); 115 } 116} 117 118CFStringRef 119SCDynamicStoreKeyCreateNetworkServiceEntity(CFAllocatorRef allocator, 120 CFStringRef domain, 121 CFStringRef serviceID, 122 CFStringRef entity) 123{ 124 if (entity == NULL) { 125 return (CFStringCreateWithFormat(allocator, 126 NULL, 127 CFSTR("%@/%@/%@/%@"), 128 domain, 129 kSCCompNetwork, 130 kSCCompService, 131 serviceID)); 132 } else { 133 return (CFStringCreateWithFormat(allocator, 134 NULL, 135 CFSTR("%@/%@/%@/%@/%@"), 136 domain, 137 kSCCompNetwork, 138 kSCCompService, 139 serviceID, 140 entity)); 141 } 142} 143