2001-12-17 14:31:42 +00:00
|
|
|
|
/** Implementation of NSPortNameServer class for Distributed Objects
|
2000-02-24 22:45:18 +00:00
|
|
|
|
Copyright (C) 1998,1999,2000 Free Software Foundation, Inc.
|
1998-10-29 12:50:23 +00:00
|
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Created: October 1998
|
|
|
|
|
|
|
|
|
|
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 Library 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 Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
2005-05-22 03:32:16 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
|
|
<title>NSPortNameServer class reference</title>
|
|
|
|
|
$Date$ $Revision$
|
1998-10-29 12:50:23 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "Foundation/NSString.h"
|
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
|
#include "Foundation/NSPortNameServer.h"
|
|
|
|
|
#include "Foundation/NSDebug.h"
|
2004-08-07 00:44:15 +00:00
|
|
|
|
#include "Foundation/NSUserDefaults.h"
|
2004-08-08 14:50:43 +00:00
|
|
|
|
#include "GSPrivate.h"
|
1998-10-29 12:50:23 +00:00
|
|
|
|
|
1999-09-21 19:07:27 +00:00
|
|
|
|
|
2003-07-22 08:52:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* The abstract port name server class. This defines an API for
|
|
|
|
|
* working with port name servers ... objects used to manage access
|
|
|
|
|
* to ports in the distributed objects system (see [NSConnection]).
|
|
|
|
|
*/
|
1999-09-21 19:07:27 +00:00
|
|
|
|
@implementation NSPortNameServer
|
1998-10-29 12:50:23 +00:00
|
|
|
|
|
|
|
|
|
+ (id) allocWithZone: (NSZone*)aZone
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
2005-02-22 11:22:44 +00:00
|
|
|
|
format: @"attempt to create extra port name server"];
|
1998-10-29 12:50:23 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
if (self == [NSPortNameServer class])
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-22 08:52:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the default port name server for the process.<br />
|
|
|
|
|
* The MacOS-X documentation says that this is a nameserver
|
|
|
|
|
* dealing with NSMessagePort objects, but that is incompatible
|
|
|
|
|
* with OpenStep/OPENSTEP/NeXTstep behavior, so GNUstep returns
|
|
|
|
|
* a name server which deals with NSSocketPort objects capable
|
2004-08-17 06:33:07 +00:00
|
|
|
|
* of being used for inter-host communications... unless it
|
|
|
|
|
* is running in compatibility mode.<br />
|
|
|
|
|
* This may change in future releases.
|
2003-07-22 08:52:37 +00:00
|
|
|
|
*/
|
2000-07-04 09:49:31 +00:00
|
|
|
|
+ (id) systemDefaultPortNameServer
|
1998-10-29 12:50:23 +00:00
|
|
|
|
{
|
2004-08-07 00:44:15 +00:00
|
|
|
|
/* Must be kept in sync with [NSPort +initialize]. */
|
2005-04-12 09:48:04 +00:00
|
|
|
|
if (GSUserDefaultsFlag(GSMacOSXCompatible) == YES)
|
2004-08-07 00:44:15 +00:00
|
|
|
|
{
|
2005-10-11 19:09:26 +00:00
|
|
|
|
#ifndef __MINGW32__
|
2004-08-07 00:44:15 +00:00
|
|
|
|
return [NSMessagePortNameServer sharedInstance];
|
2005-04-12 09:48:04 +00:00
|
|
|
|
#else
|
|
|
|
|
return [NSSocketPortNameServer sharedInstance];
|
|
|
|
|
#endif
|
2004-08-07 00:44:15 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-04-12 09:48:04 +00:00
|
|
|
|
NSString *def = [[NSUserDefaults standardUserDefaults]
|
|
|
|
|
stringForKey: @"NSPortIsMessagePort"];
|
|
|
|
|
|
|
|
|
|
if (def == nil)
|
|
|
|
|
{
|
|
|
|
|
GSOnceMLog(
|
|
|
|
|
@"\nWARNING -\n"
|
|
|
|
|
@"while the default nameserver used by NSConnection\n"
|
|
|
|
|
@"currently provides ports which can be used for inter-host\n"
|
|
|
|
|
@"and inter-user communications, this will be changed so that\n"
|
|
|
|
|
@"nsconnections will only work between processes owned by the\n"
|
|
|
|
|
@"same account on the same machine. This change is for\n"
|
|
|
|
|
@"MacOSX compatibility and for increased security.\n"
|
|
|
|
|
@"If your application actually needs to support inter-host\n"
|
|
|
|
|
@"or inter-user communications, you need to alter it to explicity\n"
|
|
|
|
|
@"use an instance of the NSSocketPortNameServer class to provide\n"
|
|
|
|
|
@"name service facilities.\n"
|
|
|
|
|
@"To stop this message appearing, set the NSPortIsMessagePort\n"
|
|
|
|
|
@"user default\n\n");
|
|
|
|
|
return [NSSocketPortNameServer sharedInstance];
|
|
|
|
|
}
|
|
|
|
|
else if ([def boolValue] == NO)
|
|
|
|
|
{
|
|
|
|
|
return [NSSocketPortNameServer sharedInstance];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-10-11 19:09:26 +00:00
|
|
|
|
#ifndef __MINGW32__
|
2005-04-12 09:48:04 +00:00
|
|
|
|
return [NSMessagePortNameServer sharedInstance];
|
2004-08-17 06:33:07 +00:00
|
|
|
|
#else
|
2005-04-12 09:48:04 +00:00
|
|
|
|
return [NSSocketPortNameServer sharedInstance];
|
2004-08-17 06:33:07 +00:00
|
|
|
|
#endif
|
2005-04-12 09:48:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
2005-02-22 11:22:44 +00:00
|
|
|
|
format: @"attempt to deallocate default port name server"];
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-22 08:52:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* Looks up the port with the specified name on the local host and
|
|
|
|
|
* returns it or nil if no port is found with that name.<br />
|
|
|
|
|
* Different nameservers have different namespaces appropriate to the
|
|
|
|
|
* type of port they deal with, so failing to find a named port with one
|
|
|
|
|
* nameserver does not guarantee that a port does with that name does
|
|
|
|
|
* not exist.<br />
|
|
|
|
|
* This is a convenience method calling -portForName:onHost: with a nil
|
|
|
|
|
* host argument.
|
|
|
|
|
*/
|
1998-10-29 12:50:23 +00:00
|
|
|
|
- (NSPort*) portForName: (NSString*)name
|
|
|
|
|
{
|
|
|
|
|
return [self portForName: name onHost: nil];
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-22 08:52:37 +00:00
|
|
|
|
/** <override-subclass />
|
|
|
|
|
* Looks up the port with the specified name on host and returns it
|
|
|
|
|
* or nil if no port is found with that name.<br />
|
|
|
|
|
* Different nameservers have different namespaces appropriate to the
|
|
|
|
|
* type of port they deal with, so failing to find a named port with one
|
|
|
|
|
* nameserver does not guarantee that a port does with that name does
|
|
|
|
|
* not exist.
|
|
|
|
|
*/
|
2002-10-05 17:47:54 +00:00
|
|
|
|
- (NSPort*) portForName: (NSString*)name
|
|
|
|
|
onHost: (NSString*)host
|
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return nil;
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-22 08:52:37 +00:00
|
|
|
|
/** <override-subclass />
|
|
|
|
|
* Registers port with the supplied name, so that other processes can
|
|
|
|
|
* look it up to contact it. A port may be registered with more than
|
|
|
|
|
* one name by making multiple calls to this method.<br />
|
|
|
|
|
* Returns YES on success, NO otherwise.<br />
|
|
|
|
|
* The common cause for failure is that another port is already registered
|
|
|
|
|
* with the name.
|
|
|
|
|
* Raises NSInvalidArgumentException if given bad arguments.
|
|
|
|
|
*/
|
1998-10-29 12:50:23 +00:00
|
|
|
|
- (BOOL) registerPort: (NSPort*)port
|
|
|
|
|
forName: (NSString*)name
|
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return NO;
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-22 08:52:37 +00:00
|
|
|
|
/** <override-subclass />
|
|
|
|
|
* Removes any port registration for the supplied name (whether
|
|
|
|
|
* registered in the current process or another).<br />
|
|
|
|
|
* The common cause for failure is that no port is registered
|
|
|
|
|
* with the name.<br />
|
|
|
|
|
* Raises NSInvalidArgumentException if given bad arguments.
|
|
|
|
|
*/
|
2001-07-15 09:08:27 +00:00
|
|
|
|
- (BOOL) removePortForName: (NSString*)name
|
1998-10-29 12:50:23 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return NO;
|
1998-10-29 12:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2003-07-15 05:21:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* Some extensions to make cleaning up port names easier.
|
|
|
|
|
*/
|
1998-10-30 08:40:03 +00:00
|
|
|
|
@implementation NSPortNameServer (GNUstep)
|
2003-07-22 08:52:37 +00:00
|
|
|
|
/** <override-subclass />
|
|
|
|
|
* Return all names that have been registered with the receiver for port.
|
2000-02-04 18:14:13 +00:00
|
|
|
|
*/
|
|
|
|
|
- (NSArray*) namesForPort: (NSPort*)port
|
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return nil;
|
2000-02-04 18:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-15 05:21:34 +00:00
|
|
|
|
/**
|
2003-07-22 08:52:37 +00:00
|
|
|
|
* Remove all names registered with the receiver for port.
|
|
|
|
|
* Probably inefficient ... subclasses might want to override this.
|
1998-10-30 08:40:03 +00:00
|
|
|
|
*/
|
2001-07-15 09:08:27 +00:00
|
|
|
|
- (BOOL) removePort: (NSPort*)port
|
1998-10-30 08:40:03 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
NSEnumerator *e = [[self namesForPort: port] objectEnumerator];
|
|
|
|
|
NSString *n;
|
|
|
|
|
BOOL removed = NO;
|
1998-10-30 08:40:03 +00:00
|
|
|
|
|
2003-07-15 05:21:34 +00:00
|
|
|
|
while ((n = [e nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([self removePort: port forName: n] == YES)
|
1998-10-30 08:40:03 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
removed = YES;
|
1998-10-30 08:40:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-07-15 05:21:34 +00:00
|
|
|
|
return removed;
|
2000-02-04 18:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-22 08:52:37 +00:00
|
|
|
|
/** <override-subclass />
|
|
|
|
|
* Remove the name if and only if it is registered with the receiver
|
|
|
|
|
* for the given port.
|
2000-02-04 18:14:13 +00:00
|
|
|
|
*/
|
2001-07-15 09:08:27 +00:00
|
|
|
|
- (BOOL) removePort: (NSPort*)port forName: (NSString*)name
|
2000-02-04 18:14:13 +00:00
|
|
|
|
{
|
2003-07-15 05:21:34 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return NO;
|
1998-10-30 08:40:03 +00:00
|
|
|
|
}
|
|
|
|
|
@end
|
1999-09-21 19:07:27 +00:00
|
|
|
|
|