]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/Applications/HAAutomounter/HAAutomounter.m
mDNSResponder-58.8.1.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / Applications / HAAutomounter / HAAutomounter.m
1 /*
2 * Copyright (c) 2002-2003 Apple Computer, 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 Change History (most recent first):
24
25 $Log: HAAutomounter.m,v $
26 Revision 1.4 2003/08/12 19:55:08 cheshire
27 Update to APSL 2.0
28
29 */
30
31 #import "HAAutomounter.h"
32
33 #import <AppKit/AppKit.h>
34
35 #include <sys/types.h>
36 #include "arpa/inet.h"
37 #include <netinet/in.h>
38
39 @implementation HAAutomounter
40
41 - (id)init
42 {
43 self = [super init];
44
45 browser = [[NSNetServiceBrowser alloc] init];
46
47 [browser setDelegate:self];
48
49 [browser searchForServicesOfType:@"_mountme._tcp." inDomain:@""];
50
51 [browser scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
52
53 return self;
54 }
55
56 - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
57 {
58 if (resolver) {
59 [resolver release];
60 }
61
62 resolver = [[NSNetService alloc] initWithDomain:[aNetService domain] type:[aNetService type] name:[aNetService name]];
63 [resolver setDelegate:self];
64 [resolver scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
65
66 [resolver resolve];
67 }
68
69
70 - (void)netServiceDidResolveAddress:(NSNetService *)sender;
71 {
72 if ([[sender addresses] count]) {
73
74 // URL mount the volume
75 NSData *addr = [[sender addresses] objectAtIndex:0];
76 struct sockaddr_in *address = CFDataGetBytePtr((CFDataRef)addr);
77 NSString *ipAddr = [NSString stringWithCString:inet_ntoa(((struct in_addr)((struct sockaddr_in *)address)->sin_addr))];
78 int port = ((struct sockaddr_in *)address)->sin_port;
79 NSArray *txtArray = [[sender protocolSpecificInformation] componentsSeparatedByString:@","];
80
81 if ([txtArray count] == 3) {
82 NSString *user = [txtArray objectAtIndex:0];
83 NSString *password = [txtArray objectAtIndex:1];
84 NSString *share = [txtArray objectAtIndex:2];
85
86 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"afp://%@:%@@%@:%d/%@", user, password, ipAddr, port, share]]];
87 } else {
88 NSLog(@"incompatible format for txt record, s/b user,password,share");
89 }
90
91 } else {
92 NSLog(@"No address %@", sender);
93 }
94 }
95
96 - (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing
97 {
98 // unmount the volume
99 }
100
101
102 @end