mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 01:31:08 +00:00
Finnaly working NSNetServices via avahi-client.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30956 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
15f33318ea
commit
71b2a1ff73
4 changed files with 49 additions and 43 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2010-07-13 Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
|
|
||||||
|
* Headers/Foundation/NSNetServices.h: Update to a version working with
|
||||||
|
both mDNSResponder and Avahi.
|
||||||
|
* Source/GSAvahiNetService.m: Fix leftover duplicate variables.
|
||||||
|
* Source/GSNetServices.h: Revert to r30954, but add padding ivars to
|
||||||
|
the Avahi classes.
|
||||||
|
Make Avahi-NSNetServices work again.
|
||||||
|
|
||||||
2010-07-13 Niels Grewe <niels.grewe@halbordnung.de>
|
2010-07-13 Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
|
|
||||||
* Source/NSNetServices.m: Replace with the new version.
|
* Source/NSNetServices.m: Replace with the new version.
|
||||||
|
|
|
@ -3,24 +3,24 @@
|
||||||
|
|
||||||
Written by: Chris B. Vetter
|
Written by: Chris B. Vetter
|
||||||
Date: 2006
|
Date: 2006
|
||||||
|
|
||||||
This file is part of the GNUstep Base Library.
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2 of the License, or (at your option) any later version.
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Library General Public License for more details.
|
Library General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free
|
License along with this library; if not, write to the Free
|
||||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
Boston, MA 02111 USA.
|
Boston, MA 02111 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __NSNetServices_h_GNUSTEP_BASE_INCLUDE
|
#ifndef __NSNetServices_h_GNUSTEP_BASE_INCLUDE
|
||||||
#define __NSNetServices_h_GNUSTEP_BASE_INCLUDE
|
#define __NSNetServices_h_GNUSTEP_BASE_INCLUDE
|
||||||
|
@ -127,12 +127,7 @@ GS_EXPORT NSString * const NSNetServicesErrorDomain;
|
||||||
|
|
||||||
@interface NSNetService : NSObject
|
@interface NSNetService : NSObject
|
||||||
{
|
{
|
||||||
#if GS_EXPOSE(NSNetService)
|
|
||||||
@private
|
|
||||||
void *_netService;
|
|
||||||
id _delegate;
|
id _delegate;
|
||||||
void *_reserved;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSData *) dataFromTXTRecordDictionary: (NSDictionary *) txtDictionary;
|
+ (NSData *) dataFromTXTRecordDictionary: (NSDictionary *) txtDictionary;
|
||||||
|
@ -151,7 +146,7 @@ GS_EXPORT NSString * const NSNetServicesErrorDomain;
|
||||||
- (void) scheduleInRunLoop: (NSRunLoop *) aRunLoop
|
- (void) scheduleInRunLoop: (NSRunLoop *) aRunLoop
|
||||||
forMode: (NSString *) mode;
|
forMode: (NSString *) mode;
|
||||||
|
|
||||||
#if OS_API_VERSION(100500,GS_API_LATEST)
|
#if OS_API_VERSION(100500,GS_API_LATEST)
|
||||||
- (NSInteger)port;
|
- (NSInteger)port;
|
||||||
|
|
||||||
- (void) publishWithOptions: (NSNetServiceOptions)options;
|
- (void) publishWithOptions: (NSNetServiceOptions)options;
|
||||||
|
@ -214,12 +209,7 @@ GS_EXPORT NSString * const NSNetServicesErrorDomain;
|
||||||
|
|
||||||
@interface NSNetServiceBrowser : NSObject
|
@interface NSNetServiceBrowser : NSObject
|
||||||
{
|
{
|
||||||
#if GS_EXPOSE(NSNetServiceBrowser)
|
|
||||||
@private
|
|
||||||
void *_netServiceBrowser;
|
|
||||||
id _delegate;
|
id _delegate;
|
||||||
void *_reserved;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) init;
|
- (id) init;
|
||||||
|
|
|
@ -3,24 +3,24 @@
|
||||||
|
|
||||||
Written by: Niels Grewe <niels.grewe@halbordnung.de>
|
Written by: Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
Date: March 2010
|
Date: March 2010
|
||||||
|
|
||||||
This file is part of the GNUstep Base Library.
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2 of the License, or (at your option) any later version.
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Library General Public License for more details.
|
Library General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free
|
License along with this library; if not, write to the Free
|
||||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
Boston, MA 02111 USA.
|
Boston, MA 02111 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "GSNetServices.h"
|
#import "GSNetServices.h"
|
||||||
#import "GSAvahiClient.h"
|
#import "GSAvahiClient.h"
|
||||||
|
@ -406,7 +406,7 @@ GSAvahiServiceResolverEvent(
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AVAHI_RESOLVER_FOUND:
|
case AVAHI_RESOLVER_FOUND:
|
||||||
|
|
||||||
[service avahiResolver: resolver
|
[service avahiResolver: resolver
|
||||||
foundServiceWithName: NSStringIfNotNull(name)
|
foundServiceWithName: NSStringIfNotNull(name)
|
||||||
type: NSStringIfNotNull(type)
|
type: NSStringIfNotNull(type)
|
||||||
|
@ -642,7 +642,6 @@ GSAvahiEntryGroupStateChanged(AvahiEntryGroup *group,
|
||||||
- (void) netService: (NSNetService*)service
|
- (void) netService: (NSNetService*)service
|
||||||
didUpdateAddresses: (NSArray*)addresses
|
didUpdateAddresses: (NSArray*)addresses
|
||||||
{
|
{
|
||||||
id _delegate = [self delegate];
|
|
||||||
if ([_delegate respondsToSelector: @selector(netService:didUpdateAddresses:)])
|
if ([_delegate respondsToSelector: @selector(netService:didUpdateAddresses:)])
|
||||||
{
|
{
|
||||||
[_delegate netService: service
|
[_delegate netService: service
|
||||||
|
@ -655,7 +654,6 @@ didUpdateRecordData: (id)data
|
||||||
forRecordType: (NSString*)rrType
|
forRecordType: (NSString*)rrType
|
||||||
{
|
{
|
||||||
SEL theSelector = NULL;
|
SEL theSelector = NULL;
|
||||||
id _delegate = [self delegate];
|
|
||||||
if ([rrType isEqualToString: @"A"] || [rrType isEqualToString: @"AAAA"])
|
if ([rrType isEqualToString: @"A"] || [rrType isEqualToString: @"AAAA"])
|
||||||
{
|
{
|
||||||
[self netService: service didUpdateAddresses: [self addresses]];
|
[self netService: service didUpdateAddresses: [self addresses]];
|
||||||
|
@ -667,7 +665,7 @@ didUpdateRecordData: (id)data
|
||||||
if (([rrType isEqualToString: @"TXT"])
|
if (([rrType isEqualToString: @"TXT"])
|
||||||
&& [data isKindOfClass: [NSArray class]])
|
&& [data isKindOfClass: [NSArray class]])
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Legacy case for TXT records (user code will always expect NSData,
|
* Legacy case for TXT records (user code will always expect NSData,
|
||||||
* not NSArray).
|
* not NSArray).
|
||||||
*/
|
*/
|
||||||
|
@ -690,7 +688,6 @@ didUpdateRecordData: (id)data
|
||||||
didNotMonitor: (NSDictionary*)errorDict
|
didNotMonitor: (NSDictionary*)errorDict
|
||||||
forRecordType: (NSString*)rrType
|
forRecordType: (NSString*)rrType
|
||||||
{
|
{
|
||||||
id _delegate = [self delegate];
|
|
||||||
SEL theSelector = NSSelectorFromString([NSString stringWithFormat:
|
SEL theSelector = NSSelectorFromString([NSString stringWithFormat:
|
||||||
@"netService:didNotMonitor%@RecordData:", rrType]);
|
@"netService:didNotMonitor%@RecordData:", rrType]);
|
||||||
|
|
||||||
|
@ -981,7 +978,7 @@ didUpdateRecordData: (id)data
|
||||||
[_lock unlock];
|
[_lock unlock];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_entryGroup == NULL)
|
if (_entryGroup == NULL)
|
||||||
{
|
{
|
||||||
if (0 != [self createEntryGroup])
|
if (0 != [self createEntryGroup])
|
||||||
|
@ -994,7 +991,7 @@ didUpdateRecordData: (id)data
|
||||||
/* Try adding the service to the entry group until we find an unused name
|
/* Try adding the service to the entry group until we find an unused name
|
||||||
* for it (but only if NSNetServiceNoAutoRename is not set).
|
* for it (but only if NSNetServiceNoAutoRename is not set).
|
||||||
*/
|
*/
|
||||||
while (AVAHI_ERR_COLLISION == (ret = [self addServiceEntry])
|
while (AVAHI_ERR_COLLISION == (ret = [self addServiceEntry])
|
||||||
&& !(options & NSNetServiceNoAutoRename))
|
&& !(options & NSNetServiceNoAutoRename))
|
||||||
{
|
{
|
||||||
char *newName = avahi_alternative_service_name([[self infoObjectForKey:
|
char *newName = avahi_alternative_service_name([[self infoObjectForKey:
|
||||||
|
@ -1034,7 +1031,7 @@ didUpdateRecordData: (id)data
|
||||||
[self commitEntryGroup];
|
[self commitEntryGroup];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NO == [self addServiceRecordWithOptions: options])
|
if (NO == [self addServiceRecordWithOptions: options])
|
||||||
{
|
{
|
||||||
[self handleError: avahi_client_errno((AvahiClient*)_client)];
|
[self handleError: avahi_client_errno((AvahiClient*)_client)];
|
||||||
|
@ -1057,7 +1054,7 @@ didUpdateRecordData: (id)data
|
||||||
domain = [NSString stringWithUTF8String:
|
domain = [NSString stringWithUTF8String:
|
||||||
avahi_client_get_domain_name((AvahiClient*)_client)];
|
avahi_client_get_domain_name((AvahiClient*)_client)];
|
||||||
}
|
}
|
||||||
full = [NSString stringWithFormat: @"%@.%@.%@", [self name],
|
full = [NSString stringWithFormat: @"%@.%@.%@", [self name],
|
||||||
[self type], domain];
|
[self type], domain];
|
||||||
if ((unichar)'.' != [full characterAtIndex: ([full length] - 1)])
|
if ((unichar)'.' != [full characterAtIndex: ([full length] - 1)])
|
||||||
{
|
{
|
||||||
|
@ -1100,7 +1097,7 @@ didUpdateRecordData: (id)data
|
||||||
0,
|
0,
|
||||||
GSAvahiServiceResolverEvent,
|
GSAvahiServiceResolverEvent,
|
||||||
(void*)self);
|
(void*)self);
|
||||||
|
|
||||||
if (NULL == _resolver)
|
if (NULL == _resolver)
|
||||||
{
|
{
|
||||||
[self handleError: avahi_client_errno((AvahiClient*)_client)];
|
[self handleError: avahi_client_errno((AvahiClient*)_client)];
|
||||||
|
@ -1117,7 +1114,7 @@ didUpdateRecordData: (id)data
|
||||||
selector: @selector(didTimeout:)
|
selector: @selector(didTimeout:)
|
||||||
userInfo: nil
|
userInfo: nil
|
||||||
repeats: NO] retain];
|
repeats: NO] retain];
|
||||||
|
|
||||||
[[ctx runLoop] addTimer: _timer
|
[[ctx runLoop] addTimer: _timer
|
||||||
forMode: [ctx mode]];
|
forMode: [ctx mode]];
|
||||||
}
|
}
|
||||||
|
@ -1133,7 +1130,7 @@ didUpdateRecordData: (id)data
|
||||||
- (void) stopWithError: (BOOL)hadError
|
- (void) stopWithError: (BOOL)hadError
|
||||||
forRRCode: (NSInteger)rrCode
|
forRRCode: (NSInteger)rrCode
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* If an RRCode was set (a value of zero possibly indicating an unknown
|
* If an RRCode was set (a value of zero possibly indicating an unknown
|
||||||
* RRCode, fo which we won't do anything), we only clean up the
|
* RRCode, fo which we won't do anything), we only clean up the
|
||||||
* corresponding browser.
|
* corresponding browser.
|
||||||
|
@ -1264,7 +1261,7 @@ didUpdateRecordData: (id)data
|
||||||
// The browser was successfully created, we add it to the mapTable.
|
// The browser was successfully created, we add it to the mapTable.
|
||||||
NSMapInsert(_browsers, (void*)(uintptr_t)code, browser);
|
NSMapInsert(_browsers, (void*)(uintptr_t)code, browser);
|
||||||
// Set the proper state if the new browser is responsible for a state
|
// Set the proper state if the new browser is responsible for a state
|
||||||
// change.
|
// change.
|
||||||
if (_serviceState == GSNetServiceResolved)
|
if (_serviceState == GSNetServiceResolved)
|
||||||
{
|
{
|
||||||
_serviceState = GSNetServiceRecordBrowsing;
|
_serviceState = GSNetServiceRecordBrowsing;
|
||||||
|
@ -1291,7 +1288,7 @@ didUpdateRecordData: (id)data
|
||||||
}
|
}
|
||||||
if (0 == NSCountMapTable(_browsers))
|
if (0 == NSCountMapTable(_browsers))
|
||||||
{
|
{
|
||||||
_serviceState = GSNetServiceResolved;
|
_serviceState = GSNetServiceResolved;
|
||||||
}
|
}
|
||||||
[_lock unlock];
|
[_lock unlock];
|
||||||
}
|
}
|
||||||
|
@ -1445,7 +1442,7 @@ didUpdateRecordData: (id)data
|
||||||
{
|
{
|
||||||
[self setInfoObject: txtRecord forKey: @"TXT"];
|
[self setInfoObject: txtRecord forKey: @"TXT"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (address)
|
if (address)
|
||||||
{
|
{
|
||||||
[self addAddressData: address];
|
[self addAddressData: address];
|
||||||
|
@ -1782,7 +1779,7 @@ didUpdateRecordData: (id)data
|
||||||
case (GSNetServicePublished):
|
case (GSNetServicePublished):
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ret will still be 0 at this point, so we can reuse the variable:
|
// Ret will still be 0 at this point, so we can reuse the variable:
|
||||||
ret = avahi_entry_group_update_service_txt_strlst(
|
ret = avahi_entry_group_update_service_txt_strlst(
|
||||||
(AvahiEntryGroup*)_entryGroup,
|
(AvahiEntryGroup*)_entryGroup,
|
||||||
|
@ -1820,7 +1817,7 @@ didUpdateRecordData: (id)data
|
||||||
|
|
||||||
- (BOOL) addRecordData: (NSData*)data
|
- (BOOL) addRecordData: (NSData*)data
|
||||||
forRecordType: (NSString*)type
|
forRecordType: (NSString*)type
|
||||||
withTTL: (NSUInteger)ttl
|
withTTL: (NSUInteger)ttl
|
||||||
{
|
{
|
||||||
int rrCode = RRCodeFromNSString(type);
|
int rrCode = RRCodeFromNSString(type);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -1925,19 +1922,19 @@ didUpdateRecordData: (id)data
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Obtain the super-class lock so that nothing fishy can happen while
|
* Obtain the super-class lock so that nothing fishy can happen while
|
||||||
* we clean up:
|
* we clean up:
|
||||||
*/
|
*/
|
||||||
[_lock lock];
|
[_lock lock];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unset the delegate. We might have been gone away because the delegate
|
* Unset the delegate. We might have been gone away because the delegate
|
||||||
* didn't need us anymore, so there's a reasonable chance that it has also
|
* didn't need us anymore, so there's a reasonable chance that it has also
|
||||||
* been deallocated.
|
* been deallocated.
|
||||||
*/
|
*/
|
||||||
[self setDelegate: nil];
|
[self setDelegate: nil];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call -stop to cleanup all avahi-related resources.
|
* Call -stop to cleanup all avahi-related resources.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,24 +3,24 @@
|
||||||
|
|
||||||
Written by: Niels Grewe <niels.grewe@halbordnung.de>
|
Written by: Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
Date: March 2010
|
Date: March 2010
|
||||||
|
|
||||||
This file is part of the GNUstep Base Library.
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2 of the License, or (at your option) any later version.
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Library General Public License for more details.
|
Library General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free
|
License along with this library; if not, write to the Free
|
||||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
Boston, MA 02111 USA.
|
Boston, MA 02111 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "common.h"
|
#import "common.h"
|
||||||
#define EXPOSE_NSNetServices_IVARS 1
|
#define EXPOSE_NSNetServices_IVARS 1
|
||||||
|
@ -33,6 +33,10 @@
|
||||||
* NSNetService using the mDNSResponder API.
|
* NSNetService using the mDNSResponder API.
|
||||||
*/
|
*/
|
||||||
@interface GSMDNSNetService : NSNetService
|
@interface GSMDNSNetService : NSNetService
|
||||||
|
{
|
||||||
|
void *_netService;
|
||||||
|
void *_reserved;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +44,10 @@
|
||||||
* NSNetServiceBrowser using the mDNSResponder API.
|
* NSNetServiceBrowser using the mDNSResponder API.
|
||||||
*/
|
*/
|
||||||
@interface GSMDNSNetServiceBrowser : NSNetServiceBrowser
|
@interface GSMDNSNetServiceBrowser : NSNetServiceBrowser
|
||||||
|
{
|
||||||
|
void *_netServiceBrowser;
|
||||||
|
void *_reserved;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// Subclasses using Avahi:
|
// Subclasses using Avahi:
|
||||||
|
@ -101,6 +109,7 @@ NSString* GSNetServiceDotTerminatedNSStringFromString(const char* string);
|
||||||
NSMapTable *_browsers;
|
NSMapTable *_browsers;
|
||||||
NSMapTable *_browserTimeouts;
|
NSMapTable *_browserTimeouts;
|
||||||
NSTimer *_timer;
|
NSTimer *_timer;
|
||||||
|
id _reserved;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,5 +139,6 @@ NSString* GSNetServiceDotTerminatedNSStringFromString(const char* string);
|
||||||
GSAvahiBrowserType _type;
|
GSAvahiBrowserType _type;
|
||||||
BOOL _hasFirstEvent;
|
BOOL _hasFirstEvent;
|
||||||
NSMutableDictionary *_services;
|
NSMutableDictionary *_services;
|
||||||
|
id _reserved;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue