Abstract: System Preference Pane for Dynamic DNS and Wide-Area DNS Service Discovery
- Copyright: (c) Copyright 2005 Apple Computer, Inc. All rights reserved.
+ Copyright: (c) Copyright 2005-2011 Apple Inc. All rights reserved.
- Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
+ Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
- Apple Computer, Inc. may be used to endorse or promote products derived from the
+ Apple Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
- Change History (most recent first):
-
-$Log: DNSServiceDiscoveryPref.m,v $
-Revision 1.16 2008/09/15 23:52:30 cheshire
-<rdar://problem/6218902> mDNSResponder-177 fails to compile on Linux with .desc pseudo-op
-Made __crashreporter_info__ symbol conditional, so we only use it for OS X build
-
-Revision 1.15 2008/08/18 17:57:04 mcguire
-<rdar://problem/6156209> build error
-
-Revision 1.14 2008/07/18 17:39:14 cheshire
-If NSInteger is not defined (indicated by lack of definition for NSINTEGER_DEFINED)
-then #define "NSInteger" to be "int" like it used to be
-
-Revision 1.13 2008/07/01 01:40:01 mcguire
-<rdar://problem/5823010> 64-bit fixes
-
-Revision 1.12 2008/05/08 00:46:38 cheshire
-<rdar://problem/5919272> GetNextLabel insufficiently defensive
-User shared copy of GetNextLabel in ClientCommon.c instead of having a local copy here
-
-Revision 1.11 2007/11/30 23:42:09 cheshire
-Fixed compile warning: declaration of 'index' shadows a global declaration
-
-Revision 1.10 2007/09/18 19:09:02 cheshire
-<rdar://problem/5489549> mDNSResponderHelper (and other binaries) missing SCCS version strings
-
-Revision 1.9 2007/02/09 00:39:06 cheshire
-Fix compile warnings
-
-Revision 1.8 2006/08/14 23:15:47 cheshire
-Tidy up Change History comment
-
-Revision 1.7 2006/07/14 03:59:14 cheshire
-Fix compile warnings: 'sortUsingFunction:context:' comparison function needs to return int
-
-Revision 1.6 2005/02/26 00:44:24 cheshire
-Restore default reg domain if user deletes text and clicks "apply"
-
-Revision 1.5 2005/02/25 02:29:28 cheshire
-Show yellow dot for "update in progress"
-
-Revision 1.4 2005/02/16 00:18:33 cheshire
-Bunch o' fixes
-
-Revision 1.3 2005/02/10 22:35:20 cheshire
-<rdar://problem/3727944> Update name
+#import "DNSServiceDiscoveryPref.h"
+#import "CNDomainBrowserView.h"
+#import "BonjourSCStore.h"
+#import "BonjourPrefTool.h"
+#import <Foundation/NSXPCConnection_Private.h>
-Revision 1.2 2005/02/08 01:32:05 cheshire
-Add trimCharactersFromDomain routine to strip leading and trailing
-white space and punctuation from user-entered fields.
+#include "../../Clients/ClientCommon.h"
-Revision 1.1 2005/02/05 01:59:19 cheshire
-Add Preference Pane to facilitate testing of DDNS & wide-area features
+#pragma mark - BonjourPrefTool
-*/
+static OSStatus
+DNSPrefTool_SetKeychainEntry(NSDictionary * secretDictionary)
+{
+ __block OSStatus result;
+ BonjourPrefTool * prefTool;
+
+ NSXPCConnection * _connectionToTool = [[NSXPCConnection alloc] initWithServiceName:@"com.apple.preference.bonjour.tool"];
+ _connectionToTool.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(BonjourPrefToolProtocol)];
+ [_connectionToTool resume];
+
+#if 0
+ prefTool = [_connectionToTool remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
+ NSLog( @"Cannot connect to BonjourPrefTool: %@.", error);
+ result = error.code;
+ }];
+#else
+ prefTool = [_connectionToTool synchronousRemoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
+ NSLog( @"Cannot connect to BonjourPrefTool: %@.", error);
+ result = error.code;
+ }];
+#endif
+ [prefTool setKeychainEntry: secretDictionary withStatus: ^(OSStatus status){
+ result = status;
+ }];
-#import "DNSServiceDiscoveryPref.h"
-#import "ConfigurationAuthority.h"
-#import "PrivilegedOperations.h"
-#import <unistd.h>
+ [_connectionToTool invalidate];
-#include "../../Clients/ClientCommon.h"
+ return (result);
+}
-#ifndef NSINTEGER_DEFINED
-#define NSInteger int
-#endif
+#pragma mark -
@implementation DNSServiceDiscoveryPref
-static NSComparisonResult
+static NSInteger
MyArrayCompareFunction(id val1, id val2, void *context)
{
(void)context; // Unused
return CFStringCompare((CFStringRef)val1, (CFStringRef)val2, kCFCompareCaseInsensitive);
}
-
-static NSComparisonResult
+static NSInteger
MyDomainArrayCompareFunction(id val1, id val2, void *context)
{
(void)context; // Unused
{
(void)store; // Unused
(void)changedKeys; // Unused
- DNSServiceDiscoveryPref * me = (DNSServiceDiscoveryPref *)context;
+ DNSServiceDiscoveryPref * me = (__bridge DNSServiceDiscoveryPref *)context;
assert(me != NULL);
[me setupInitialValues];
}
-static void ServiceDomainEnumReply( DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *replyDomain, void *context, DNSServiceFlags enumType)
-{
- (void)sdRef; // Unused
- (void)interfaceIndex; // Unused
- (void)errorCode; // Unused
- if (strcmp(replyDomain, "local.") == 0) return; // local domain is not interesting
-
- DNSServiceDiscoveryPref * me = (DNSServiceDiscoveryPref *)context;
- BOOL moreComing = (BOOL)(flags & kDNSServiceFlagsMoreComing);
- NSMutableArray * domainArray;
- NSMutableArray * defaultBrowseDomainsArray = nil;
- NSComboBox * domainComboBox;
- NSString * domainString;
- NSString * currentDomain = nil;
- char decodedDomainString[kDNSServiceMaxDomainName] = "\0";
- char nextLabel[256] = "\0";
- char * buffer = (char *)replyDomain;
-
- while (*buffer) {
- buffer = (char *)GetNextLabel(buffer, nextLabel);
- strcat(decodedDomainString, nextLabel);
- strcat(decodedDomainString, ".");
- }
-
- // Remove trailing dot from domain name.
- decodedDomainString[strlen(decodedDomainString)-1] = '\0';
-
- domainString = [[[NSString alloc] initWithUTF8String:(const char *)decodedDomainString] autorelease];
-
- if (enumType & kDNSServiceFlagsRegistrationDomains) {
- domainArray = [me registrationDataSource];
- domainComboBox = [me regDomainsComboBox];
- currentDomain = [me currentRegDomain];
- } else {
- domainArray = [me browseDataSource];
- domainComboBox = [me browseDomainsComboBox];
- defaultBrowseDomainsArray = [me defaultBrowseDomainsArray];
- }
-
- if (flags & kDNSServiceFlagsAdd) {
- [domainArray removeObject:domainString]; // How can I check if an object is in the array?
- [domainArray addObject:domainString];
- if ((flags & kDNSServiceFlagsDefault) && (enumType & kDNSServiceFlagsRegistrationDomains)) {
- [me setDefaultRegDomain:domainString];
- if ([[domainComboBox stringValue] length] == 0) [domainComboBox setStringValue:domainString];
- } else if ((flags & kDNSServiceFlagsDefault) && !(enumType & kDNSServiceFlagsRegistrationDomains)) {
- [defaultBrowseDomainsArray removeObject:domainString];
- [defaultBrowseDomainsArray addObject:domainString];
- }
- }
-
- if (moreComing == NO) {
- [domainArray sortUsingFunction:MyArrayCompareFunction context:nil];
- [domainComboBox reloadData];
- }
-}
-
-
-static void
-browseDomainReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *replyDomain, void *context)
-{
- ServiceDomainEnumReply(sdRef, flags, interfaceIndex, errorCode, replyDomain, context, kDNSServiceFlagsBrowseDomains);
-}
-
-
-static void
-registrationDomainReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
- DNSServiceErrorType errorCode, const char *replyDomain, void *context)
-{
- ServiceDomainEnumReply(sdRef, flags, interfaceIndex, errorCode, replyDomain, context, kDNSServiceFlagsRegistrationDomains);
-}
-
-
-
-static void
-MyDNSServiceCleanUp(MyDNSServiceState * query)
-{
- /* Remove the CFRunLoopSource from the current run loop. */
- CFRunLoopRemoveSource(CFRunLoopGetCurrent(), query->source, kCFRunLoopCommonModes);
- CFRelease(query->source);
-
- /* Invalidate the CFSocket. */
- CFSocketInvalidate(query->socket);
- CFRelease(query->socket);
-
- /* Workaround that gives time to CFSocket's select thread so it can remove the socket from its FD set
- before we close the socket by calling DNSServiceRefDeallocate. <rdar://problem/3585273> */
- usleep(1000);
-
- /* Terminate the connection with the mDNSResponder daemon, which cancels the query. */
- DNSServiceRefDeallocate(query->service);
-}
-
-
-
-static void
-MySocketReadCallback(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void * data, void * info)
-{
- #pragma unused(s)
- #pragma unused(type)
- #pragma unused(address)
- #pragma unused(data)
-
- DNSServiceErrorType err;
-
- MyDNSServiceState * query = (MyDNSServiceState *)info; // context passed in to CFSocketCreateWithNative().
- assert(query != NULL);
-
- /* Read a reply from the mDNSResponder. */
- err= DNSServiceProcessResult(query->service);
- if (err != kDNSServiceErr_NoError) {
- fprintf(stderr, "DNSServiceProcessResult returned %d\n", err);
-
- /* Terminate the query operation and release the CFRunLoopSource and CFSocket. */
- MyDNSServiceCleanUp(query);
- }
-}
-
-
-
-static void
-MyDNSServiceAddServiceToRunLoop(MyDNSServiceState * query)
-{
- CFSocketNativeHandle sock;
- CFOptionFlags sockFlags;
- CFSocketContext context = { 0, query, NULL, NULL, NULL }; // Use MyDNSServiceState as context data.
-
- /* Access the underlying Unix domain socket to communicate with the mDNSResponder daemon. */
- sock = DNSServiceRefSockFD(query->service);
- assert(sock != -1);
-
- /* Create a CFSocket using the Unix domain socket. */
- query->socket = CFSocketCreateWithNative(NULL, sock, kCFSocketReadCallBack, MySocketReadCallback, &context);
- assert(query->socket != NULL);
-
- /* Prevent CFSocketInvalidate from closing DNSServiceRef's socket. */
- sockFlags = CFSocketGetSocketFlags(query->socket);
- CFSocketSetSocketFlags(query->socket, sockFlags & (~kCFSocketCloseOnInvalidate));
-
- /* Create a CFRunLoopSource from the CFSocket. */
- query->source = CFSocketCreateRunLoopSource(NULL, query->socket, 0);
- assert(query->source != NULL);
-
- /* Add the CFRunLoopSource to the current run loop. */
- CFRunLoopAddSource(CFRunLoopGetCurrent(), query->source, kCFRunLoopCommonModes);
-}
-
-
-
-(void)updateStatusImageView
{
int value = [self statusForHostName:currentHostName];
- (void)watchForPreferenceChanges
{
- SCDynamicStoreContext context = { 0, self, NULL, NULL, NULL };
+ SCDynamicStoreContext context = { 0, (__bridge void * _Nullable)(self), NULL, NULL, NULL };
SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("watchForPreferenceChanges"), NetworkChanged, &context);
CFMutableArrayRef keys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
CFRunLoopSourceRef rls;
assert(rls != NULL);
CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopCommonModes);
+ CFRelease(rls);
CFRelease(keys);
CFRelease(store);
assert(store != NULL);
- NSDictionary *dynamicDNS = (NSDictionary *)SCDynamicStoreCopyValue(store, SC_DYNDNS_STATE_KEY);
+ NSDictionary *dynamicDNS = (NSDictionary *)CFBridgingRelease(SCDynamicStoreCopyValue(store, SC_DYNDNS_STATE_KEY));
if (dynamicDNS) {
NSDictionary *hostNames = [dynamicDNS objectForKey:(NSString *)SC_DYNDNS_HOSTNAMES_KEY];
NSDictionary *infoDict = [hostNames objectForKey:lowercaseDomain];
if (infoDict) status = [[infoDict objectForKey:(NSString*)SC_DYNDNS_STATUS_KEY] intValue];
- CFRelease(dynamicDNS);
}
CFRelease(store);
}
-- (void)startDomainBrowsing
-{
- DNSServiceFlags flags;
- OSStatus err = noErr;
-
- flags = kDNSServiceFlagsRegistrationDomains;
- err = DNSServiceEnumerateDomains(®Query.service, flags, 0, registrationDomainReply, (void *)self);
- if (err == kDNSServiceErr_NoError) MyDNSServiceAddServiceToRunLoop(®Query);
-
- flags = kDNSServiceFlagsBrowseDomains;
- err = DNSServiceEnumerateDomains(&browseQuery.service, flags, 0, browseDomainReply, (void *)self);
- if (err == kDNSServiceErr_NoError) MyDNSServiceAddServiceToRunLoop(&browseQuery);
-}
-
-
-(void)readPreferences
{
NSDictionary *origDict;
NSArray *regDomainArray;
NSArray *hostArray;
- if (currentRegDomain) [currentRegDomain release];
- if (currentBrowseDomainsArray) [currentBrowseDomainsArray release];
- if (currentHostName) [currentHostName release];
+ if (currentRegDomain) currentRegDomain = nil;
+ if (currentBrowseDomainsArray) currentBrowseDomainsArray = nil;
+ if (currentHostName) currentHostName = nil;
SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("com.apple.preference.bonjour"), NULL, NULL);
- origDict = (NSDictionary *)SCDynamicStoreCopyValue(store, SC_DYNDNS_SETUP_KEY);
+ origDict = (NSDictionary *)CFBridgingRelease(SCDynamicStoreCopyValue(store, SC_DYNDNS_SETUP_KEY));
regDomainArray = [origDict objectForKey:(NSString *)SC_DYNDNS_REGDOMAINS_KEY];
if (regDomainArray && [regDomainArray count] > 0) {
currentRegDomain = [[[regDomainArray objectAtIndex:0] objectForKey:(NSString *)SC_DYNDNS_DOMAIN_KEY] copy];
currentWideAreaState = [[[regDomainArray objectAtIndex:0] objectForKey:(NSString *)SC_DYNDNS_ENABLED_KEY] intValue];
} else {
- currentRegDomain = [[NSString alloc] initWithString:@""];
+ currentRegDomain = @"";
currentWideAreaState = NO;
}
- currentBrowseDomainsArray = [[origDict objectForKey:(NSString *)SC_DYNDNS_BROWSEDOMAINS_KEY] retain];
+ currentBrowseDomainsArray = [origDict objectForKey:(NSString *)SC_DYNDNS_BROWSEDOMAINS_KEY];
hostArray = [origDict objectForKey:(NSString *)SC_DYNDNS_HOSTNAMES_KEY];
if (hostArray && [hostArray count] > 0) {
currentHostName = [[[hostArray objectAtIndex:0] objectForKey:(NSString *)SC_DYNDNS_DOMAIN_KEY] copy];
} else {
- currentHostName = [[NSString alloc] initWithString:@""];
+ currentHostName = @"";
}
- [origDict release];
- CFRelease(store);
+ if (store) CFRelease(store);
}
-- (void)tableViewSelectionDidChange:(NSNotification *)notification;
+- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
[removeBrowseDomainButton setEnabled:[[notification object] numberOfSelectedRows]];
}
-- (void)setBrowseDomainsComboBox;
+- (IBAction)addBrowseDomainClicked:(id)sender
{
- NSString * domain = nil;
-
- if ([defaultBrowseDomainsArray count] > 0) {
- NSEnumerator * arrayEnumerator = [defaultBrowseDomainsArray objectEnumerator];
- while ((domain = [arrayEnumerator nextObject]) != NULL) {
- if ([self domainAlreadyInList:domain] == NO) break;
- }
- }
- if (domain) [browseDomainsComboBox setStringValue:domain];
- else [browseDomainsComboBox setStringValue:@""];
-}
-
+ NSWindow * window = (([NSEvent modifierFlags] & NSAlternateKeyMask) == NSAlternateKeyMask) ? addBrowseDomainManualWindow : addBrowseDomainWindow;
+ [browseDomainTextField setStringValue: [NSString string]];
-- (IBAction)addBrowseDomainClicked:(id)sender;
-{
- [self setBrowseDomainsComboBox];
-
- [NSApp beginSheet:addBrowseDomainWindow modalForWindow:mainWindow modalDelegate:self
- didEndSelector:@selector(addBrowseDomainSheetDidEnd:returnCode:contextInfo:) contextInfo:sender];
+ [self disableControls];
+ [NSApp beginSheet:window modalForWindow:mainWindow modalDelegate:self
+ didEndSelector:@selector(addBrowseDomainSheetDidEnd:returnCode:contextInfo:) contextInfo:(__bridge void * _Null_unspecified)(sender)];
[browseDomainList deselectAll:sender];
[self updateApplyButtonState];
}
-- (IBAction)removeBrowseDomainClicked:(id)sender;
+- (IBAction)removeBrowseDomainClicked:(id)sender
{
(void)sender; // Unused
int selectedBrowseDomain = [browseDomainList selectedRow];
}
-- (IBAction)enableBrowseDomainClicked:(id)sender;
+- (IBAction)enableBrowseDomainClicked:(id)sender
{
NSTableView *tableView = sender;
NSMutableDictionary *browseDomainDict;
- int value;
+ NSInteger value;
browseDomainDict = [[browseDomainsArray objectAtIndex:[tableView clickedRow]] mutableCopy];
value = [[browseDomainDict objectForKey:(NSString *)SC_DYNDNS_ENABLED_KEY] intValue];
- [browseDomainDict setObject:[[[NSNumber alloc] initWithInt:(!value)] autorelease] forKey:(NSString *)SC_DYNDNS_ENABLED_KEY];
+ [browseDomainDict setObject:[NSNumber numberWithInt:(!value)] forKey:(NSString *)SC_DYNDNS_ENABLED_KEY];
[browseDomainsArray replaceObjectAtIndex:[tableView clickedRow] withObject:browseDomainDict];
[tableView reloadData];
[self updateApplyButtonState];
-- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView;
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
(void)tableView; // Unused
int numberOfRows = 0;
}
-- (void)tabView:(NSTabView *)xtabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem;
+- (void)tabView:(NSTabView *)xtabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
(void)xtabView; // Unused
(void)tabViewItem; // Unused
}
-- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
+- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
(void)tableView; // Unused
NSDictionary *browseDomainDict;
if ([[tableColumn identifier] isEqualTo:(NSString *)SC_DYNDNS_ENABLED_KEY]) {
value = [browseDomainDict objectForKey:(NSString *)SC_DYNDNS_ENABLED_KEY];
} else if ([[tableColumn identifier] isEqualTo:(NSString *)SC_DYNDNS_DOMAIN_KEY]) {
- value = [browseDomainDict objectForKey:(NSString *)SC_DYNDNS_DOMAIN_KEY];
+ value = [browseDomainDict objectForKey:(NSString *)SC_DYNDNS_DOMAIN_KEY];
}
}
}
}
if (browseDomainsArray) {
- [browseDomainsArray release];
browseDomainsArray = nil;
}
if (browseDomainsArray) {
[browseDomainsArray sortUsingFunction:MyDomainArrayCompareFunction context:nil];
if ([browseDomainsArray isEqualToArray:currentBrowseDomainsArray] == NO) {
- OSStatus err = WriteBrowseDomain((CFDataRef)[self dataForDomainArray:browseDomainsArray]);
- if (err != noErr) NSLog(@"WriteBrowseDomain returned %d\n", err);
- [currentBrowseDomainsArray release];
+ [BonjourSCStore setObject: browseDomainsArray forKey: (NSString *)SC_DYNDNS_BROWSEDOMAINS_KEY];
currentBrowseDomainsArray = [browseDomainsArray copy];
}
}
[browseDomainList reloadData];
if (currentRegDomain && ([currentRegDomain length] > 0)) {
- [regDomainsComboBox setStringValue:currentRegDomain];
- [registrationDataSource removeObject:currentRegDomain];
- [registrationDataSource addObject:currentRegDomain];
- [registrationDataSource sortUsingFunction:MyArrayCompareFunction context:nil];
- [regDomainsComboBox reloadData];
+ regDomainView.domain = currentRegDomain;
}
if (currentWideAreaState) {
}
if (hostNameSharedSecretValue) {
- [hostNameSharedSecretValue release];
hostNameSharedSecretValue = nil;
}
if (regSharedSecretValue) {
- [regSharedSecretValue release];
regSharedSecretValue = nil;
}
- (void)awakeFromNib
-{
- OSStatus err;
-
+{
prefsNeedUpdating = NO;
- toolInstalled = NO;
browseDomainListEnabled = NO;
defaultRegDomain = nil;
currentRegDomain = nil;
hostNameSharedSecretValue = nil;
regSharedSecretValue = nil;
browseDomainsArray = nil;
- justStartedEditing = YES;
currentWideAreaState = NO;
NSString *successPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"success" ofType:@"tiff"];
NSString *inprogressPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"inprogress" ofType:@"tiff"];
NSString *failurePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"failure" ofType:@"tiff"];
registrationDataSource = [[NSMutableArray alloc] init];
- browseDataSource = [[NSMutableArray alloc] init];
- defaultBrowseDomainsArray = [[NSMutableArray alloc] init];
successImage = [[NSImage alloc] initWithContentsOfFile:successPath];
inprogressImage = [[NSImage alloc] initWithContentsOfFile:inprogressPath];
failureImage = [[NSImage alloc] initWithContentsOfFile:failurePath];
[tabView selectFirstTabViewItem:self];
[self setupInitialValues];
- [self startDomainBrowsing];
[self watchForPreferenceChanges];
-
- InitConfigAuthority();
- err = EnsureToolInstalled();
- if (err == noErr) toolInstalled = YES;
- else { long int tmp = err; fprintf(stderr, "EnsureToolInstalled returned %ld\n", tmp); }
}
+- (void)willSelect
+{
+ [super willSelect];
+ [bonjourBrowserView startBrowse];
+ [registrationBrowserView startBrowse];
+
+}
+
+- (void)willUnselect
+{
+ [super willUnselect];
+ [bonjourBrowserView stopBrowse];
+ [registrationBrowserView stopBrowse];
+}
- (IBAction)closeMyCustomSheet:(id)sender
{
- BOOL result = [sender isEqualTo:browseOKButton] || [sender isEqualTo:secretOKButton];
+ BOOL result = [sender tag];
if (result) [NSApp endSheet:[sender window] returnCode:NSOKButton];
else [NSApp endSheet:[sender window] returnCode:NSCancelButton];
- (void)sharedSecretSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
- NSButton * button = (NSButton *)contextInfo;
+ NSButton * button = (__bridge NSButton *)contextInfo;
[sheet orderOut:self];
[self enableControls];
- (NSString *)trimCharactersFromDomain:(NSString *)domain
{
- NSMutableCharacterSet * trimSet = [[[NSCharacterSet whitespaceCharacterSet] mutableCopy] autorelease];
+ NSMutableCharacterSet * trimSet = [NSMutableCharacterSet whitespaceCharacterSet];
[trimSet formUnionWithCharacterSet:[NSCharacterSet punctuationCharacterSet]];
return [domain stringByTrimmingCharactersInSet:trimSet];
}
[self enableControls];
if (returnCode == NSOKButton) {
- NSString * newBrowseDomainString = [self trimCharactersFromDomain:[browseDomainsComboBox stringValue]];
+ NSString * newBrowseDomainString;
+ if(sheet == addBrowseDomainManualWindow) newBrowseDomainString = [self trimCharactersFromDomain:[browseDomainTextField stringValue]];
+ else newBrowseDomainString = [self trimCharactersFromDomain:bonjourBrowserView.selectedDNSDomain];
NSMutableDictionary *newBrowseDomainDict;
-
if (browseDomainsArray == nil) browseDomainsArray = [[NSMutableArray alloc] initWithCapacity:0];
if ([self domainAlreadyInList:newBrowseDomainString] == NO) {
- newBrowseDomainDict = [[[NSMutableDictionary alloc] initWithCapacity:2] autorelease];
+ newBrowseDomainDict = [[NSMutableDictionary alloc] initWithCapacity:2];
[newBrowseDomainDict setObject:newBrowseDomainString forKey:(NSString *)SC_DYNDNS_DOMAIN_KEY];
- [newBrowseDomainDict setObject:[[[NSNumber alloc] initWithBool:YES] autorelease] forKey:(NSString *)SC_DYNDNS_ENABLED_KEY];
+ [newBrowseDomainDict setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)SC_DYNDNS_ENABLED_KEY];
[browseDomainsArray addObject:newBrowseDomainDict];
[browseDomainsArray sortUsingFunction:MyDomainArrayCompareFunction context:nil];
}
}
-
-(void)validateTextFields
{
[hostName validateEditing];
- [browseDomainsComboBox validateEditing];
- [regDomainsComboBox validateEditing];
+ [browseDomainTextField validateEditing];
}
} else {
if (regSharedSecretValue) {
[sharedSecretValue setStringValue:regSharedSecretValue];
- } else if ((keyName = [self sharedSecretKeyName:[regDomainsComboBox stringValue]]) != NULL) {
+ } else if ((keyName = [self sharedSecretKeyName:regDomainView.domain]) != NULL) {
[sharedSecretName setStringValue:keyName];
[sharedSecretValue setStringValue:@"****************"];
} else {
- [sharedSecretName setStringValue:[regDomainsComboBox stringValue]];
+ [sharedSecretName setStringValue:regDomainView.domain];
[sharedSecretValue setStringValue:@""];
}
}
else [sharedSecretWindow makeFirstResponder:sharedSecretName];
[NSApp beginSheet:sharedSecretWindow modalForWindow:mainWindow modalDelegate:self
- didEndSelector:@selector(sharedSecretSheetDidEnd:returnCode:contextInfo:) contextInfo:sender];
+ didEndSelector:@selector(sharedSecretSheetDidEnd:returnCode:contextInfo:) contextInfo:(__bridge void * _Null_unspecified)(sender)];
}
+- (IBAction)selectWideAreaDomainButtonPressed:(id)sender
+{
+ NSWindow * window = (([NSEvent modifierFlags] & NSAlternateKeyMask) == NSAlternateKeyMask) ? selectRegistrationDomainManualWindow : selectRegistrationDomainWindow;
+ regDomainTextField.stringValue = regDomainView.domain;
+
+ [self disableControls];
+ [NSApp beginSheet:window modalForWindow:mainWindow modalDelegate:self
+ didEndSelector:@selector(selectWideAreaDomainSheetDidEnd:returnCode:contextInfo:) contextInfo:(__bridge void * _Null_unspecified)(sender)];
+
+ [self updateApplyButtonState];
+}
+
+- (void)selectWideAreaDomainSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
+{
+ (void)contextInfo; // Unused
+ [sheet orderOut:self];
+ [self enableControls];
+
+ if (returnCode == NSOKButton) {
+ NSString * newRegDomainString;
+ if(sheet == selectRegistrationDomainManualWindow) newRegDomainString = [self trimCharactersFromDomain:[regDomainTextField stringValue]];
+ else newRegDomainString = [self trimCharactersFromDomain:registrationBrowserView.selectedDNSDomain];
+ regDomainView.domain = newRegDomainString;
+ [self updateApplyButtonState];
+ }
+}
+
- (IBAction)wideAreaCheckBoxChanged:(id)sender
{
[self toggleWideAreaBonjour:[sender state]];
}
+
- (void)updateApplyButtonState
{
NSString *hostNameString = [hostName stringValue];
- NSString *regDomainString = [regDomainsComboBox stringValue];
-
- NSComparisonResult hostNameResult = [hostNameString compare:currentHostName];
- NSComparisonResult regDomainResult = [regDomainString compare:currentRegDomain];
-
- if ((currentHostName && (hostNameResult != NSOrderedSame)) ||
- (currentRegDomain && (regDomainResult != NSOrderedSame) && ([wideAreaCheckBox state])) ||
+ NSString *regDomainString = regDomainView.domain;
+ if ((currentHostName && ([hostNameString compare:currentHostName] != NSOrderedSame)) ||
+ (currentRegDomain && ([regDomainString compare:currentRegDomain] != NSOrderedSame) && ([wideAreaCheckBox state])) ||
(currentHostName == nil && ([hostNameString length]) > 0) ||
(currentRegDomain == nil && ([regDomainString length]) > 0) ||
(currentWideAreaState != [wideAreaCheckBox state]) ||
}
-
-- (void)controlTextDidChange:(NSNotification *)notification;
+- (void)controlTextDidChange:(NSNotification *)notification
{
(void)notification; // Unused
[self updateApplyButtonState];
}
-
-- (IBAction)comboAction:(id)sender;
-{
- (void)sender; // Unused
- [self updateApplyButtonState];
-}
-
-
-- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)ind
-{
- NSString *domain = nil;
- if ([aComboBox isEqualTo:browseDomainsComboBox]) domain = [browseDataSource objectAtIndex:ind];
- else if ([aComboBox isEqualTo:regDomainsComboBox]) domain = [registrationDataSource objectAtIndex:ind];
- return domain;
-}
-
-
-
-- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
-{
- int count = 0;
- if ([aComboBox isEqualTo:browseDomainsComboBox]) count = [browseDataSource count];
- else if ([aComboBox isEqualTo:regDomainsComboBox]) count = [registrationDataSource count];
- return count;
-}
-
-
-- (NSMutableArray *)browseDataSource
-{
- return browseDataSource;
-}
-
-
- (NSMutableArray *)registrationDataSource
{
return registrationDataSource;
}
-- (NSComboBox *)browseDomainsComboBox
-{
- return browseDomainsComboBox;
-}
-
-
-- (NSComboBox *)regDomainsComboBox
-{
- return regDomainsComboBox;
-}
-
-
- (NSString *)currentRegDomain
{
return currentRegDomain;
}
-- (NSMutableArray *)defaultBrowseDomainsArray
-{
- return defaultBrowseDomainsArray;
-}
-
-
- (NSArray *)currentBrowseDomainsArray
{
return currentBrowseDomainsArray;
- (void)setDefaultRegDomain:(NSString *)domain
{
- [defaultRegDomain release];
defaultRegDomain = domain;
- [defaultRegDomain retain];
}
mainWindow = [[self mainView] window];
}
-
- (void)mainViewDidLoad
-{
+{
[comboAuthButton setString:"system.preferences"];
[comboAuthButton setDelegate:self];
- [comboAuthButton updateStatus:nil];
[comboAuthButton setAutoupdate:YES];
+ [super mainViewDidLoad];
}
- (void)applyCurrentState
{
[self validateTextFields];
-
- if (toolInstalled == YES) {
- [self savePreferences];
- [self disableApplyButton];
- [mainWindow makeFirstResponder:nil];
- }
+ [self savePreferences];
+ [self disableApplyButton];
+ [mainWindow makeFirstResponder:nil];
}
- (void)toggleWideAreaBonjour:(BOOL)state
{
[wideAreaCheckBox setState:state];
- [regDomainsComboBox setEnabled:state];
+ [registrationSelectButton setEnabled:state];
[registrationSharedSecretButton setEnabled:state];
}
-- (IBAction)revertClicked:(id)sender;
+- (IBAction)revertClicked:(id)sender
{
[self restorePreferences];
[browseDomainList deselectAll:sender];
- (void)savePanelWillClose:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
(void)sheet; // Unused
- DNSServiceDiscoveryPref * me = (DNSServiceDiscoveryPref *)contextInfo;
+ DNSServiceDiscoveryPref * me = (__bridge DNSServiceDiscoveryPref *)contextInfo;
if (returnCode == NSAlertDefaultReturn) {
[me applyCurrentState];
ptr = (char *)GetNextLabel(ptr, text);
domainName = [[NSString alloc] initWithUTF8String:(const char *)ptr];
}
- return ([domainName autorelease]);
+ return (domainName);
}
NSMutableDictionary *domainDict = nil;
if (domainName && [domainName length] > 0) {
- domainDict= [[[NSMutableDictionary alloc] initWithCapacity:2] autorelease];
+ domainDict= [NSMutableDictionary dictionaryWithCapacity:2];
[domainDict setObject:domainName forKey:(NSString *)SC_DYNDNS_DOMAIN_KEY];
- [domainDict setObject:[[[NSNumber alloc] initWithBool:enabled] autorelease] forKey:(NSString *)SC_DYNDNS_ENABLED_KEY];
+ [domainDict setObject:[NSNumber numberWithBool:enabled] forKey:(NSString *)SC_DYNDNS_ENABLED_KEY];
}
- domainsArray = [[[NSMutableArray alloc] initWithCapacity:1] autorelease];
+ domainsArray = [NSMutableArray arrayWithCapacity:1];
if (domainDict) [domainsArray addObject:domainDict];
return [NSArchiver archivedDataWithRootObject:domainsArray];
}
}
-- (NSData *)dataForSharedSecret:(NSString *)secret domain:(NSString *)domainName key:(NSString *)keyName
+- (NSDictionary *)dictionaryForSharedSecret:(NSString *)secret domain:(NSString *)domainName key:(NSString *)keyName
{
- NSMutableDictionary *sharedSecretDict = [[[NSMutableDictionary alloc] initWithCapacity:3] autorelease];
+ NSMutableDictionary *sharedSecretDict = [NSMutableDictionary dictionaryWithCapacity:3];
[sharedSecretDict setObject:secret forKey:(NSString *)SC_DYNDNS_SECRET_KEY];
[sharedSecretDict setObject:[domainName lowercaseString] forKey:(NSString *)SC_DYNDNS_DOMAIN_KEY];
[sharedSecretDict setObject:keyName forKey:(NSString *)SC_DYNDNS_KEYNAME_KEY];
- return [NSArchiver archivedDataWithRootObject:sharedSecretDict];
+ return sharedSecretDict;
}
-(void)savePreferences
{
NSString *hostNameString = [hostName stringValue];
- NSString *browseDomainString = [browseDomainsComboBox stringValue];
- NSString *regDomainString = [regDomainsComboBox stringValue];
+ NSString *regDomainString = regDomainView.domain;
NSString *tempHostNameSharedSecretName = hostNameSharedSecretName;
NSString *tempRegSharedSecretName = regSharedSecretName;
- NSData *browseDomainData = nil;
BOOL regSecretWasSet = NO;
BOOL hostSecretWasSet = NO;
- OSStatus err = noErr;
+ BOOL updateHostname = NO;
hostNameString = [self trimCharactersFromDomain:hostNameString];
- browseDomainString = [self trimCharactersFromDomain:browseDomainString];
regDomainString = [self trimCharactersFromDomain:regDomainString];
tempHostNameSharedSecretName = [self trimCharactersFromDomain:tempHostNameSharedSecretName];
tempRegSharedSecretName = [self trimCharactersFromDomain:tempRegSharedSecretName];
[hostName setStringValue:hostNameString];
- [regDomainsComboBox setStringValue:regDomainString];
+ regDomainView.domain = regDomainString;
// Convert Shared Secret account names to lowercase.
tempHostNameSharedSecretName = [tempHostNameSharedSecretName lowercaseString];
// Save hostname shared secret.
if ([hostNameSharedSecretName length] > 0 && ([hostNameSharedSecretValue length] > 0)) {
- SetKeyForDomain((CFDataRef)[self dataForSharedSecret:hostNameSharedSecretValue domain:hostNameString key:tempHostNameSharedSecretName]);
- [hostNameSharedSecretValue release];
+ DNSPrefTool_SetKeychainEntry([self dictionaryForSharedSecret:hostNameSharedSecretValue domain:hostNameString key:tempHostNameSharedSecretName]);
hostNameSharedSecretValue = nil;
hostSecretWasSet = YES;
}
// Save registration domain shared secret.
if (([regSharedSecretName length] > 0) && ([regSharedSecretValue length] > 0)) {
- SetKeyForDomain((CFDataRef)[self dataForSharedSecret:regSharedSecretValue domain:regDomainString key:tempRegSharedSecretName]);
- [regSharedSecretValue release];
+ DNSPrefTool_SetKeychainEntry([self dictionaryForSharedSecret:regSharedSecretValue domain:regDomainString key:tempRegSharedSecretName]);
regSharedSecretValue = nil;
regSecretWasSet = YES;
}
// Save hostname.
if ((currentHostName == NULL) || [currentHostName compare:hostNameString] != NSOrderedSame) {
- err = WriteHostname((CFDataRef)[self dataForDomain:hostNameString isEnabled:YES]);
- if (err != noErr) NSLog(@"WriteHostname returned %d\n", err);
currentHostName = [hostNameString copy];
+ updateHostname = YES;
} else if (hostSecretWasSet) {
- WriteHostname((CFDataRef)[self dataForDomain:@"" isEnabled:NO]);
- usleep(200000); // Temporary hack
- if ([currentHostName length] > 0) WriteHostname((CFDataRef)[self dataForDomain:(NSString *)currentHostName isEnabled:YES]);
+ currentHostName = @"";
+ updateHostname = YES;
+ }
+
+ if (updateHostname) {
+ [BonjourSCStore setObject: currentHostName.length ? @[@{
+ (NSString *)SC_DYNDNS_DOMAIN_KEY : currentHostName,
+ (NSString *)SC_DYNDNS_ENABLED_KEY : @YES
+ }] : nil
+ forKey: (NSString *)SC_DYNDNS_HOSTNAMES_KEY];
}
// Save browse domain.
if (browseDomainsArray && [browseDomainsArray isEqualToArray:currentBrowseDomainsArray] == NO) {
- browseDomainData = [self dataForDomainArray:browseDomainsArray];
- err = WriteBrowseDomain((CFDataRef)browseDomainData);
- if (err != noErr) NSLog(@"WriteBrowseDomain returned %d\n", err);
+ [BonjourSCStore setObject: browseDomainsArray forKey: (NSString *)SC_DYNDNS_BROWSEDOMAINS_KEY];
currentBrowseDomainsArray = [browseDomainsArray copy];
}
// Save registration domain.
if ((currentRegDomain == NULL) || ([currentRegDomain compare:regDomainString] != NSOrderedSame) || (currentWideAreaState != [wideAreaCheckBox state])) {
-
- err = WriteRegistrationDomain((CFDataRef)[self dataForDomain:regDomainString isEnabled:[wideAreaCheckBox state]]);
- if (err != noErr) NSLog(@"WriteRegistrationDomain returned %d\n", err);
-
- if (currentRegDomain) CFRelease(currentRegDomain);
+ [BonjourSCStore setObject: @[@{
+ (NSString *)SC_DYNDNS_DOMAIN_KEY : regDomainString,
+ (NSString *)SC_DYNDNS_ENABLED_KEY : [wideAreaCheckBox state] ? @YES : @NO
+ }]
+ forKey: (NSString *)SC_DYNDNS_REGDOMAINS_KEY];
currentRegDomain = [regDomainString copy];
if ([currentRegDomain length] > 0) {
[registrationDataSource removeObject:regDomainString];
[registrationDataSource addObject:currentRegDomain];
[registrationDataSource sortUsingFunction:MyArrayCompareFunction context:nil];
- [regDomainsComboBox reloadData];
+ // [regDomainsComboBox reloadData];
} else {
currentWideAreaState = NO;
[self toggleWideAreaBonjour:NO];
- if (defaultRegDomain != nil) [regDomainsComboBox setStringValue:defaultRegDomain];
+ if (defaultRegDomain != nil) regDomainView.domain = defaultRegDomain;
}
} else if (regSecretWasSet) {
- WriteRegistrationDomain((CFDataRef)[self dataForDomain:@"" isEnabled:NO]);
- usleep(200000); // Temporary hack
- if ([currentRegDomain length] > 0) WriteRegistrationDomain((CFDataRef)[self dataForDomain:currentRegDomain isEnabled:currentWideAreaState]);
+ [BonjourSCStore setObject: @[@{
+ (NSString *)SC_DYNDNS_DOMAIN_KEY : @"",
+ (NSString *)SC_DYNDNS_ENABLED_KEY : @NO
+ }]
+ forKey: (NSString *)SC_DYNDNS_REGDOMAINS_KEY];
+ if ([currentRegDomain length] > 0) {
+ [BonjourSCStore setObject: @[@{
+ (NSString *)SC_DYNDNS_DOMAIN_KEY : currentRegDomain,
+ (NSString *)SC_DYNDNS_ENABLED_KEY : currentWideAreaState ? @YES : @NO
+ }]
+ forKey: (NSString *)SC_DYNDNS_REGDOMAINS_KEY];
+ }
}
}
self,
@selector( savePanelWillClose:returnCode:contextInfo: ),
NULL,
- (void *) self, // sender,
+ (__bridge void *) self, // sender,
@"" );
return NSUnselectLater;
}
{
[hostName setEnabled:NO];
[hostNameSharedSecretButton setEnabled:NO];
- [browseDomainsComboBox setEnabled:NO];
[applyButton setEnabled:NO];
[revertButton setEnabled:NO];
[wideAreaCheckBox setEnabled:NO];
- [regDomainsComboBox setEnabled:NO];
+ [registrationSelectButton setEnabled: NO];
[registrationSharedSecretButton setEnabled:NO];
[statusImageView setEnabled:NO];
}
-- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row;
+- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row
{
(void)row; // Unused
(void)tableView; // Unused
{
[hostName setEnabled:YES];
[hostNameSharedSecretButton setEnabled:YES];
- [browseDomainsComboBox setEnabled:YES];
[wideAreaCheckBox setEnabled:YES];
+ [registrationSelectButton setEnabled: YES];
[registrationSharedSecretButton setEnabled:YES];
[self toggleWideAreaBonjour:[wideAreaCheckBox state]];
[statusImageView setEnabled:YES];
- (void)authorizationViewDidAuthorize:(SFAuthorizationView *)view
{
- (void)view; // Unused
+ (void)view; // unused
[self enableControls];
}
- (void)authorizationViewDidDeauthorize:(SFAuthorizationView *)view
{
- (void)view; // Unused
+ (void)view; // unused
[self disableControls];
}