From 71b2a1ff73c138da4c27ce2d709ce1f0b478cd3b Mon Sep 17 00:00:00 2001 From: thebeing Date: Tue, 13 Jul 2010 11:41:54 +0000 Subject: [PATCH] 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 --- ChangeLog | 9 ++++++ Headers/Foundation/NSNetServices.h | 20 ++++--------- Source/GSAvahiNetService.m | 45 ++++++++++++++---------------- Source/GSNetServices.h | 18 +++++++++--- 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a0c55558..4e0a449d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-07-13 Niels Grewe + + * 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 * Source/NSNetServices.m: Replace with the new version. diff --git a/Headers/Foundation/NSNetServices.h b/Headers/Foundation/NSNetServices.h index 2c51b6d81..5ee80d171 100644 --- a/Headers/Foundation/NSNetServices.h +++ b/Headers/Foundation/NSNetServices.h @@ -3,24 +3,24 @@ Written by: Chris B. Vetter Date: 2006 - + This file is part of the GNUstep Base Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. - */ + */ #ifndef __NSNetServices_h_GNUSTEP_BASE_INCLUDE #define __NSNetServices_h_GNUSTEP_BASE_INCLUDE @@ -127,12 +127,7 @@ GS_EXPORT NSString * const NSNetServicesErrorDomain; @interface NSNetService : NSObject { -#if GS_EXPOSE(NSNetService) - @private - void *_netService; id _delegate; - void *_reserved; -#endif } + (NSData *) dataFromTXTRecordDictionary: (NSDictionary *) txtDictionary; @@ -151,7 +146,7 @@ GS_EXPORT NSString * const NSNetServicesErrorDomain; - (void) scheduleInRunLoop: (NSRunLoop *) aRunLoop forMode: (NSString *) mode; -#if OS_API_VERSION(100500,GS_API_LATEST) +#if OS_API_VERSION(100500,GS_API_LATEST) - (NSInteger)port; - (void) publishWithOptions: (NSNetServiceOptions)options; @@ -214,12 +209,7 @@ GS_EXPORT NSString * const NSNetServicesErrorDomain; @interface NSNetServiceBrowser : NSObject { -#if GS_EXPOSE(NSNetServiceBrowser) - @private - void *_netServiceBrowser; id _delegate; - void *_reserved; -#endif } - (id) init; diff --git a/Source/GSAvahiNetService.m b/Source/GSAvahiNetService.m index 31558e8f9..08ec30084 100644 --- a/Source/GSAvahiNetService.m +++ b/Source/GSAvahiNetService.m @@ -3,24 +3,24 @@ Written by: Niels Grewe Date: March 2010 - + This file is part of the GNUstep Base Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. - */ + */ #import "GSNetServices.h" #import "GSAvahiClient.h" @@ -406,7 +406,7 @@ GSAvahiServiceResolverEvent( break; case AVAHI_RESOLVER_FOUND: - + [service avahiResolver: resolver foundServiceWithName: NSStringIfNotNull(name) type: NSStringIfNotNull(type) @@ -642,7 +642,6 @@ GSAvahiEntryGroupStateChanged(AvahiEntryGroup *group, - (void) netService: (NSNetService*)service didUpdateAddresses: (NSArray*)addresses { - id _delegate = [self delegate]; if ([_delegate respondsToSelector: @selector(netService:didUpdateAddresses:)]) { [_delegate netService: service @@ -655,7 +654,6 @@ didUpdateRecordData: (id)data forRecordType: (NSString*)rrType { SEL theSelector = NULL; - id _delegate = [self delegate]; if ([rrType isEqualToString: @"A"] || [rrType isEqualToString: @"AAAA"]) { [self netService: service didUpdateAddresses: [self addresses]]; @@ -667,7 +665,7 @@ didUpdateRecordData: (id)data if (([rrType isEqualToString: @"TXT"]) && [data isKindOfClass: [NSArray class]]) { - /* + /* * Legacy case for TXT records (user code will always expect NSData, * not NSArray). */ @@ -690,7 +688,6 @@ didUpdateRecordData: (id)data didNotMonitor: (NSDictionary*)errorDict forRecordType: (NSString*)rrType { - id _delegate = [self delegate]; SEL theSelector = NSSelectorFromString([NSString stringWithFormat: @"netService:didNotMonitor%@RecordData:", rrType]); @@ -981,7 +978,7 @@ didUpdateRecordData: (id)data [_lock unlock]; return NO; } - + if (_entryGroup == NULL) { 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 * 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)) { char *newName = avahi_alternative_service_name([[self infoObjectForKey: @@ -1034,7 +1031,7 @@ didUpdateRecordData: (id)data [self commitEntryGroup]; return; } - + if (NO == [self addServiceRecordWithOptions: options]) { [self handleError: avahi_client_errno((AvahiClient*)_client)]; @@ -1057,7 +1054,7 @@ didUpdateRecordData: (id)data domain = [NSString stringWithUTF8String: avahi_client_get_domain_name((AvahiClient*)_client)]; } - full = [NSString stringWithFormat: @"%@.%@.%@", [self name], + full = [NSString stringWithFormat: @"%@.%@.%@", [self name], [self type], domain]; if ((unichar)'.' != [full characterAtIndex: ([full length] - 1)]) { @@ -1100,7 +1097,7 @@ didUpdateRecordData: (id)data 0, GSAvahiServiceResolverEvent, (void*)self); - + if (NULL == _resolver) { [self handleError: avahi_client_errno((AvahiClient*)_client)]; @@ -1117,7 +1114,7 @@ didUpdateRecordData: (id)data selector: @selector(didTimeout:) userInfo: nil repeats: NO] retain]; - + [[ctx runLoop] addTimer: _timer forMode: [ctx mode]]; } @@ -1133,7 +1130,7 @@ didUpdateRecordData: (id)data - (void) stopWithError: (BOOL)hadError forRRCode: (NSInteger)rrCode { - /* + /* * 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 * corresponding browser. @@ -1264,7 +1261,7 @@ didUpdateRecordData: (id)data // The browser was successfully created, we add it to the mapTable. NSMapInsert(_browsers, (void*)(uintptr_t)code, browser); // Set the proper state if the new browser is responsible for a state - // change. + // change. if (_serviceState == GSNetServiceResolved) { _serviceState = GSNetServiceRecordBrowsing; @@ -1291,7 +1288,7 @@ didUpdateRecordData: (id)data } if (0 == NSCountMapTable(_browsers)) { - _serviceState = GSNetServiceResolved; + _serviceState = GSNetServiceResolved; } [_lock unlock]; } @@ -1445,7 +1442,7 @@ didUpdateRecordData: (id)data { [self setInfoObject: txtRecord forKey: @"TXT"]; } - + if (address) { [self addAddressData: address]; @@ -1782,7 +1779,7 @@ didUpdateRecordData: (id)data case (GSNetServicePublished): break; } - + // Ret will still be 0 at this point, so we can reuse the variable: ret = avahi_entry_group_update_service_txt_strlst( (AvahiEntryGroup*)_entryGroup, @@ -1820,7 +1817,7 @@ didUpdateRecordData: (id)data - (BOOL) addRecordData: (NSData*)data forRecordType: (NSString*)type - withTTL: (NSUInteger)ttl + withTTL: (NSUInteger)ttl { int rrCode = RRCodeFromNSString(type); int ret = 0; @@ -1925,19 +1922,19 @@ didUpdateRecordData: (id)data - (void) dealloc { - /* + /* * Obtain the super-class lock so that nothing fishy can happen while * we clean up: */ [_lock lock]; - /* + /* * 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 * been deallocated. */ [self setDelegate: nil]; - + /* * Call -stop to cleanup all avahi-related resources. */ diff --git a/Source/GSNetServices.h b/Source/GSNetServices.h index 811a19cf3..612b45fc1 100644 --- a/Source/GSNetServices.h +++ b/Source/GSNetServices.h @@ -3,24 +3,24 @@ Written by: Niels Grewe Date: March 2010 - + This file is part of the GNUstep Base Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. - */ + */ #import "common.h" #define EXPOSE_NSNetServices_IVARS 1 @@ -33,6 +33,10 @@ * NSNetService using the mDNSResponder API. */ @interface GSMDNSNetService : NSNetService +{ + void *_netService; + void *_reserved; +} @end @@ -40,6 +44,10 @@ * NSNetServiceBrowser using the mDNSResponder API. */ @interface GSMDNSNetServiceBrowser : NSNetServiceBrowser +{ + void *_netServiceBrowser; + void *_reserved; +} @end // Subclasses using Avahi: @@ -101,6 +109,7 @@ NSString* GSNetServiceDotTerminatedNSStringFromString(const char* string); NSMapTable *_browsers; NSMapTable *_browserTimeouts; NSTimer *_timer; + id _reserved; } /** @@ -130,5 +139,6 @@ NSString* GSNetServiceDotTerminatedNSStringFromString(const char* string); GSAvahiBrowserType _type; BOOL _hasFirstEvent; NSMutableDictionary *_services; + id _reserved; } @end