2005-11-05 05:58:43 +00:00
|
|
|
/* Implementation of message port subclass of NSPortNameServer
|
|
|
|
|
|
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2005-11-05 05:58:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2005-11-05 05:58:43 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2005-11-05 05:58:43 +00:00
|
|
|
License along with this library; if not, write to the
|
|
|
|
Free Software Foundation,
|
|
|
|
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
|
|
|
|
|
|
|
<title>NSMessagePortNameServer class reference</title>
|
|
|
|
$Date$ $Revision$
|
|
|
|
*/
|
|
|
|
|
2010-02-19 08:12:46 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2005-11-05 05:58:43 +00:00
|
|
|
#include "Foundation/NSPortNameServer.h"
|
|
|
|
|
|
|
|
#include "Foundation/NSAutoreleasePool.h"
|
|
|
|
#include "Foundation/NSDebug.h"
|
2006-10-23 15:16:26 +00:00
|
|
|
#include "Foundation/NSError.h"
|
2005-11-05 05:58:43 +00:00
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
#include "Foundation/NSLock.h"
|
|
|
|
#include "Foundation/NSMapTable.h"
|
|
|
|
#include "Foundation/NSPathUtilities.h"
|
|
|
|
#include "Foundation/NSPort.h"
|
|
|
|
#include "Foundation/NSFileManager.h"
|
|
|
|
#include "Foundation/NSValue.h"
|
|
|
|
#include "Foundation/NSThread.h"
|
2006-01-15 11:31:37 +00:00
|
|
|
#include "Foundation/NSUserDefaults.h"
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2006-05-11 14:32:44 +00:00
|
|
|
#include "GNUstepBase/GSMime.h"
|
|
|
|
|
2006-10-23 15:16:26 +00:00
|
|
|
#include "../GSPrivate.h"
|
2008-01-10 20:05:38 +00:00
|
|
|
#include "../GSPortPrivate.h"
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2005-11-08 20:42:45 +00:00
|
|
|
#define UNISTR(X) \
|
|
|
|
((const unichar*)[(X) cStringUsingEncoding: NSUnicodeStringEncoding])
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2008-11-17 13:45:32 +00:00
|
|
|
extern __declspec(dllimport) int errno;
|
2005-11-09 09:39:25 +00:00
|
|
|
|
2005-11-05 05:58:43 +00:00
|
|
|
static NSRecursiveLock *serverLock = nil;
|
|
|
|
static NSMessagePortNameServer *defaultServer = nil;
|
2009-03-18 08:50:32 +00:00
|
|
|
static NSMapTable *portToNamesMap;
|
2005-11-08 20:42:45 +00:00
|
|
|
static NSString *registry;
|
|
|
|
static HKEY key;
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2006-01-15 13:13:36 +00:00
|
|
|
static SECURITY_ATTRIBUTES security;
|
|
|
|
|
2005-11-05 05:58:43 +00:00
|
|
|
@interface NSMessagePortNameServer (private)
|
2005-11-08 20:42:45 +00:00
|
|
|
+ (NSString *) _query: (NSString *)name;
|
|
|
|
+ (NSString *) _translate: (NSString *)name;
|
2005-11-05 05:58:43 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
static void clean_up_names(void)
|
|
|
|
{
|
|
|
|
NSMapEnumerator mEnum;
|
|
|
|
NSMessagePort *port;
|
|
|
|
NSString *name;
|
|
|
|
BOOL unknownThread = GSRegisterCurrentThread();
|
|
|
|
CREATE_AUTORELEASE_POOL(arp);
|
|
|
|
|
|
|
|
mEnum = NSEnumerateMapTable(portToNamesMap);
|
|
|
|
while (NSNextMapEnumeratorPair(&mEnum, (void *)&port, (void *)&name))
|
|
|
|
{
|
|
|
|
[defaultServer removePort: port];
|
|
|
|
}
|
|
|
|
NSEndMapTableEnumeration(&mEnum);
|
2009-02-10 11:48:37 +00:00
|
|
|
IF_NO_GC([arp release]);
|
2005-11-09 09:39:25 +00:00
|
|
|
RegCloseKey(key);
|
2005-11-05 05:58:43 +00:00
|
|
|
if (unknownThread == YES)
|
|
|
|
{
|
|
|
|
GSUnregisterCurrentThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subclass of [NSPortNameServer] taking/returning instances of [NSMessagePort].
|
|
|
|
* Port removal functionality is not supported; if you want to cancel a service,
|
|
|
|
* you have to destroy the port (invalidate the [NSMessagePort] given to
|
|
|
|
* [NSPortNameServer-registerPort:forName:]).
|
|
|
|
*/
|
|
|
|
@implementation NSMessagePortNameServer
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSMessagePortNameServer class])
|
|
|
|
{
|
2005-11-08 20:42:45 +00:00
|
|
|
int rc;
|
|
|
|
|
2005-11-05 05:58:43 +00:00
|
|
|
serverLock = [NSRecursiveLock new];
|
|
|
|
portToNamesMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks,
|
2005-11-08 20:42:45 +00:00
|
|
|
NSObjectMapValueCallBacks, 0);
|
2005-11-05 05:58:43 +00:00
|
|
|
atexit(clean_up_names);
|
2005-11-08 20:42:45 +00:00
|
|
|
|
2006-01-15 13:13:36 +00:00
|
|
|
security.nLength = sizeof(SECURITY_ATTRIBUTES);
|
|
|
|
security.lpSecurityDescriptor = 0; // Default
|
2009-09-27 16:07:50 +00:00
|
|
|
security.bInheritHandle = FALSE;
|
2006-01-15 13:13:36 +00:00
|
|
|
|
2005-11-09 09:39:25 +00:00
|
|
|
registry = @"Software\\GNUstepNSMessagePort";
|
|
|
|
rc = RegCreateKeyExW(
|
|
|
|
HKEY_CURRENT_USER,
|
2005-11-08 20:42:45 +00:00
|
|
|
UNISTR(registry),
|
|
|
|
0,
|
2008-11-17 13:45:32 +00:00
|
|
|
(LPWSTR) L"",
|
2005-11-20 11:17:42 +00:00
|
|
|
REG_OPTION_VOLATILE,
|
2005-11-08 20:42:45 +00:00
|
|
|
STANDARD_RIGHTS_WRITE|STANDARD_RIGHTS_READ|KEY_SET_VALUE
|
2006-01-15 11:31:37 +00:00
|
|
|
|KEY_QUERY_VALUE|KEY_NOTIFY,
|
2006-01-15 13:13:36 +00:00
|
|
|
&security,
|
2005-11-08 20:42:45 +00:00
|
|
|
&key,
|
|
|
|
NULL);
|
2005-11-09 09:39:25 +00:00
|
|
|
if (rc == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
rc = RegFlushKey(key);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
NSLog(@"Failed to flush registry HKEY_CURRENT_USER\\%@ (%x)",
|
|
|
|
registry, rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2005-11-08 20:42:45 +00:00
|
|
|
{
|
|
|
|
NSLog(@"Failed to create registry HKEY_CURRENT_USER\\%@ (%x)",
|
|
|
|
registry, rc);
|
|
|
|
}
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain single instance for this host.
|
|
|
|
*/
|
|
|
|
+ (id) sharedInstance
|
|
|
|
{
|
|
|
|
if (defaultServer == nil)
|
|
|
|
{
|
|
|
|
[serverLock lock];
|
|
|
|
if (defaultServer == nil)
|
|
|
|
{
|
|
|
|
defaultServer = (NSMessagePortNameServer *)NSAllocateObject(self,
|
|
|
|
0, NSDefaultMallocZone());
|
|
|
|
}
|
|
|
|
[serverLock unlock];
|
|
|
|
}
|
|
|
|
return defaultServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-08 20:42:45 +00:00
|
|
|
+ (NSString *) _query: (NSString *)name
|
2005-11-05 05:58:43 +00:00
|
|
|
{
|
2007-01-23 16:04:32 +00:00
|
|
|
NSString *mailslotName;
|
|
|
|
NSString *translatedName;
|
|
|
|
NSString *mailslotPath;
|
2007-01-23 11:29:50 +00:00
|
|
|
unsigned char buf[1024];
|
|
|
|
unsigned char *ptr = buf;
|
|
|
|
DWORD max = 1024;
|
|
|
|
DWORD len = 1024;
|
2005-11-09 09:39:25 +00:00
|
|
|
DWORD type;
|
|
|
|
HANDLE h;
|
2005-11-08 20:42:45 +00:00
|
|
|
int rc;
|
|
|
|
|
2007-01-23 16:04:32 +00:00
|
|
|
translatedName = [[self class] _translate: name];
|
2005-11-08 20:42:45 +00:00
|
|
|
|
2007-01-23 16:09:01 +00:00
|
|
|
#if 1
|
2006-01-15 11:31:37 +00:00
|
|
|
/* FIXME ... wierd hack.
|
|
|
|
* It appears that RegQueryValueExW does not always read from the registry,
|
|
|
|
* but will in fact return cached results (even if you close and re-open the
|
|
|
|
* registry key between the calls to RegQueryValueExW). This is a problem
|
|
|
|
* if we look up a server which is not running, and then try to look it up
|
|
|
|
* again when it is running, or if we have one address recorded but the server
|
|
|
|
* has been restarted and is using a new address.
|
|
|
|
* I couldn't find any mention of this behavior ... but accidentally discovered
|
|
|
|
* that a call to OutputDebugStringW stops it ... presumably something in the
|
|
|
|
* debug system invalidates whatever registry caching is being done.
|
|
|
|
* Anyway, on my XP SP2 system, this next line is needed to fix things.
|
|
|
|
*
|
|
|
|
* You can test this by running a GNUstep application without starting
|
|
|
|
* gdnc beforehand. If the bug is occurring, the app will try to start gdnc
|
|
|
|
* then poll to connect to it, and after 5 seconds will abort because it
|
|
|
|
* hasn't seen the gdnc port registered even though gdnc did start.
|
|
|
|
* If the hack has fixed the bug, the app will just pause briefly during
|
|
|
|
* startup (as it starts gdnc) and then continue when it finds the server
|
|
|
|
* port.
|
|
|
|
*/
|
|
|
|
OutputDebugStringW(L"");
|
2007-01-23 16:04:32 +00:00
|
|
|
#endif
|
2006-01-15 11:31:37 +00:00
|
|
|
|
2005-11-09 09:39:25 +00:00
|
|
|
rc = RegQueryValueExW(
|
|
|
|
key,
|
2007-01-23 16:04:32 +00:00
|
|
|
UNISTR(translatedName),
|
2005-11-08 20:42:45 +00:00
|
|
|
(LPDWORD)0,
|
2005-11-09 09:39:25 +00:00
|
|
|
&type,
|
2007-01-23 11:29:50 +00:00
|
|
|
(LPBYTE)ptr,
|
2005-11-08 20:42:45 +00:00
|
|
|
&len);
|
2007-01-23 11:29:50 +00:00
|
|
|
while (rc == ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
if (ptr != buf)
|
|
|
|
{
|
2011-02-19 19:42:42 +00:00
|
|
|
free(ptr);
|
2007-01-23 11:29:50 +00:00
|
|
|
}
|
|
|
|
max += 1024;
|
2011-02-19 19:42:42 +00:00
|
|
|
ptr = malloc(max);
|
2007-01-23 11:29:50 +00:00
|
|
|
len = max;
|
|
|
|
rc = RegQueryValueExW(
|
|
|
|
key,
|
2007-01-23 16:04:32 +00:00
|
|
|
UNISTR(translatedName),
|
2007-01-23 11:29:50 +00:00
|
|
|
(LPDWORD)0,
|
|
|
|
&type,
|
|
|
|
(LPBYTE)ptr,
|
|
|
|
&len);
|
|
|
|
}
|
2005-11-08 20:42:45 +00:00
|
|
|
if (rc != ERROR_SUCCESS)
|
2005-11-05 05:58:43 +00:00
|
|
|
{
|
2007-01-23 11:29:50 +00:00
|
|
|
if (ptr != buf)
|
|
|
|
{
|
2011-02-19 19:42:42 +00:00
|
|
|
free(ptr);
|
2007-01-23 11:29:50 +00:00
|
|
|
}
|
2005-11-08 20:42:45 +00:00
|
|
|
return nil;
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
|
|
|
|
2008-11-17 13:45:32 +00:00
|
|
|
mailslotName = [NSString stringWithUTF8String: (const char *) ptr];
|
2007-01-23 11:29:50 +00:00
|
|
|
if (ptr != buf)
|
|
|
|
{
|
2011-02-19 19:42:42 +00:00
|
|
|
free(ptr);
|
2007-01-23 11:29:50 +00:00
|
|
|
}
|
2005-11-09 09:39:25 +00:00
|
|
|
|
|
|
|
/*
|
2007-01-23 11:29:50 +00:00
|
|
|
* See if we can open the port mailslot ... if not, the query returned
|
2005-11-09 09:39:25 +00:00
|
|
|
* an old name, and we can remove it.
|
|
|
|
*/
|
2007-01-23 16:04:32 +00:00
|
|
|
mailslotPath = [NSString stringWithFormat:
|
|
|
|
@"\\\\.\\mailslot\\GNUstep\\NSMessagePort\\%@", mailslotName];
|
2005-11-09 09:39:25 +00:00
|
|
|
h = CreateFileW(
|
2007-01-23 16:04:32 +00:00
|
|
|
UNISTR(mailslotPath),
|
2005-11-09 09:39:25 +00:00
|
|
|
GENERIC_WRITE,
|
2005-11-09 16:30:57 +00:00
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE,
|
2006-01-15 13:13:36 +00:00
|
|
|
&security,
|
2005-11-09 09:39:25 +00:00
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
(HANDLE)0);
|
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2007-01-23 16:04:32 +00:00
|
|
|
NSDebugLLog(@"NSMessagePortNameServer",
|
|
|
|
@"Failed to open mailslot (%@) for write on port named %@ - %@",
|
|
|
|
mailslotPath, name, [NSError _last]);
|
|
|
|
//RegDeleteValueW(key, UNISTR(n));
|
2005-11-09 09:39:25 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CloseHandle(h); // OK
|
2007-01-23 16:04:32 +00:00
|
|
|
return mailslotName;
|
2005-11-09 09:39:25 +00:00
|
|
|
}
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
|
|
|
|
2005-11-08 20:42:45 +00:00
|
|
|
+ (NSString *) _translate: (NSString *)name
|
2005-11-05 05:58:43 +00:00
|
|
|
{
|
2006-05-11 14:26:54 +00:00
|
|
|
NSData *data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure name is representable in the registry ...
|
|
|
|
* assume base64 encoded strings are valid.
|
|
|
|
*/
|
|
|
|
data = [name dataUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
data = [GSMimeDocument encodeBase64: data];
|
|
|
|
name = [[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding];
|
|
|
|
AUTORELEASE(name);
|
2005-11-08 20:42:45 +00:00
|
|
|
return name;
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
|
|
|
|
2006-10-23 15:16:26 +00:00
|
|
|
- (NSPort*) portForName: (NSString *)name
|
|
|
|
{
|
|
|
|
return [self portForName: name onHost: @""];
|
|
|
|
}
|
|
|
|
|
2005-11-05 05:58:43 +00:00
|
|
|
- (NSPort*) portForName: (NSString *)name
|
|
|
|
onHost: (NSString *)host
|
|
|
|
{
|
2005-11-08 20:42:45 +00:00
|
|
|
NSString *n;
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2005-11-11 10:07:03 +00:00
|
|
|
NSDebugLLog(@"NSMessagePortNameServer",
|
|
|
|
@"portForName: %@ host: %@", name, host);
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2006-10-23 15:16:26 +00:00
|
|
|
if ([host length] != 0)
|
2005-11-05 05:58:43 +00:00
|
|
|
{
|
2006-10-23 15:16:26 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Attempt to contact a named host using a "
|
|
|
|
@"message port name server. This name server can only be used "
|
|
|
|
@"to contact processes owned by the same user on the local host "
|
|
|
|
@"(host name must be an empty string). To contact processes "
|
|
|
|
@"owned by other users or on other hosts you must use an instance "
|
|
|
|
@"of the NSSocketPortNameServer class."];
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
|
|
|
|
2005-11-08 20:42:45 +00:00
|
|
|
n = [[self class] _query: name];
|
2005-11-11 10:07:03 +00:00
|
|
|
if (n == nil)
|
|
|
|
{
|
|
|
|
NSDebugLLog(@"NSMessagePortNameServer", @"got no port for %@", name);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSDebugLLog(@"NSMessagePortNameServer", @"got %@ for %@", n, name);
|
|
|
|
return AUTORELEASE([NSMessagePort newWithName: n]);
|
|
|
|
}
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) registerPort: (NSPort *)port
|
|
|
|
forName: (NSString *)name
|
|
|
|
{
|
|
|
|
NSMutableArray *a;
|
2005-11-08 20:42:45 +00:00
|
|
|
NSString *n;
|
|
|
|
int rc;
|
2007-01-23 11:29:50 +00:00
|
|
|
const unsigned char *str;
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2005-11-11 10:07:03 +00:00
|
|
|
NSDebugLLog(@"NSMessagePortNameServer", @"register %@ as %@\n", port, name);
|
2005-11-05 05:58:43 +00:00
|
|
|
if ([port isKindOfClass: [NSMessagePort class]] == NO)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Attempted to register a non-NSMessagePort (%@)",
|
|
|
|
port];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2005-11-08 20:42:45 +00:00
|
|
|
if ([[self class] _query: name] != nil)
|
2005-11-05 05:58:43 +00:00
|
|
|
{
|
2005-11-11 10:07:03 +00:00
|
|
|
NSDebugLLog(@"NSMessagePortNameServer", @"fail, is a live port");
|
2005-11-05 05:58:43 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2005-11-08 20:42:45 +00:00
|
|
|
n = [[self class] _translate: name];
|
2008-11-17 13:45:32 +00:00
|
|
|
str = (const unsigned char *) [[(NSMessagePort*)port name] UTF8String];
|
2005-11-08 20:42:45 +00:00
|
|
|
|
2005-11-09 09:39:25 +00:00
|
|
|
rc = RegSetValueExW(
|
|
|
|
key,
|
2005-11-08 20:42:45 +00:00
|
|
|
UNISTR(n),
|
|
|
|
0,
|
2005-11-09 09:39:25 +00:00
|
|
|
REG_BINARY,
|
2007-01-23 11:29:50 +00:00
|
|
|
str,
|
2008-11-17 13:45:32 +00:00
|
|
|
strlen((const char*) str)+1);
|
2007-01-23 16:04:32 +00:00
|
|
|
NSDebugLLog(@"NSMessagePortNameServer", @"Set port '%s' for %@", str, n);
|
2005-11-09 09:39:25 +00:00
|
|
|
if (rc == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
rc = RegFlushKey(key);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
NSLog(@"Failed to flush registry HKEY_CURRENT_USER\\%@\\%@ (%x)",
|
|
|
|
registry, n, rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2005-11-05 05:58:43 +00:00
|
|
|
{
|
2006-10-09 14:00:01 +00:00
|
|
|
NSLog(@"Failed to insert HKEY_CURRENT_USER\\%@\\%@ (%x) %@",
|
2006-10-23 15:16:26 +00:00
|
|
|
registry, n, rc, [NSError _last]);
|
2005-11-05 05:58:43 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
[serverLock lock];
|
|
|
|
a = NSMapGet(portToNamesMap, port);
|
2005-11-08 20:42:45 +00:00
|
|
|
if (a != nil)
|
2005-11-05 05:58:43 +00:00
|
|
|
{
|
|
|
|
a = [[NSMutableArray alloc] init];
|
|
|
|
NSMapInsert(portToNamesMap, port, a);
|
|
|
|
RELEASE(a);
|
|
|
|
}
|
|
|
|
[a addObject: [name copy]];
|
|
|
|
[serverLock unlock];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) removePortForName: (NSString *)name
|
|
|
|
{
|
2005-11-08 20:42:45 +00:00
|
|
|
NSString *n;
|
|
|
|
int rc;
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2005-11-11 10:07:03 +00:00
|
|
|
NSDebugLLog(@"NSMessagePortNameServer", @"removePortForName: %@", name);
|
2005-11-08 20:42:45 +00:00
|
|
|
n = [[self class] _translate: name];
|
|
|
|
rc = RegDeleteValueW(key, UNISTR(n));
|
|
|
|
|
2005-11-05 05:58:43 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) namesForPort: (NSPort *)port
|
|
|
|
{
|
|
|
|
NSMutableArray *a;
|
|
|
|
|
|
|
|
[serverLock lock];
|
|
|
|
a = NSMapGet(portToNamesMap, port);
|
|
|
|
a = [a copy];
|
|
|
|
[serverLock unlock];
|
2005-11-08 20:42:45 +00:00
|
|
|
return AUTORELEASE(a);
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) removePort: (NSPort *)port
|
|
|
|
{
|
|
|
|
NSMutableArray *a;
|
|
|
|
int i;
|
|
|
|
|
2005-11-11 10:07:03 +00:00
|
|
|
NSDebugLLog(@"NSMessagePortNameServer", @"removePort: %@", port);
|
2005-11-05 05:58:43 +00:00
|
|
|
|
|
|
|
[serverLock lock];
|
|
|
|
a = NSMapGet(portToNamesMap, port);
|
|
|
|
|
|
|
|
for (i = 0; i < [a count]; i++)
|
|
|
|
{
|
|
|
|
[self removePort: port forName: [a objectAtIndex: i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMapRemove(portToNamesMap, port);
|
|
|
|
[serverLock unlock];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) removePort: (NSPort*)port forName: (NSString*)name
|
|
|
|
{
|
2005-11-11 10:07:03 +00:00
|
|
|
NSDebugLLog(@"NSMessagePortNameServer",
|
|
|
|
@"removePort: %@ forName: %@", port, name);
|
2005-11-05 05:58:43 +00:00
|
|
|
|
2005-11-08 20:42:45 +00:00
|
|
|
if ([self portForName: name onHost: @""] == port)
|
2005-11-05 05:58:43 +00:00
|
|
|
{
|
2005-11-08 20:42:45 +00:00
|
|
|
return [self removePortForName: name];
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
2005-11-08 20:42:45 +00:00
|
|
|
return NO;
|
2005-11-05 05:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|