2001-12-17 14:31:42 +00:00
|
|
|
|
/** Implementation for NSFileHandle for GNUStep
|
1997-09-01 21:59:51 +00:00
|
|
|
|
Copyright (C) 1997 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Date: 1997
|
|
|
|
|
|
|
|
|
|
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
|
1999-09-09 02:56:20 +00:00
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
|
|
<title>NSFileHandle class reference</title>
|
|
|
|
|
$Date$ $Revision$
|
1997-09-01 21:59:51 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/preface.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
|
#include <Foundation/NSObject.h>
|
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
|
#include <Foundation/NSFileHandle.h>
|
2001-12-04 14:59:09 +00:00
|
|
|
|
#include <Foundation/NSPathUtilities.h>
|
|
|
|
|
#include <Foundation/NSBundle.h>
|
2002-06-30 09:19:30 +00:00
|
|
|
|
#include <Foundation/GSFileHandle.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
// GNUstep Notification names
|
|
|
|
|
|
|
|
|
|
NSString * const GSFileHandleConnectCompletionNotification
|
|
|
|
|
= @"GSFileHandleConnectCompletionNotification";
|
|
|
|
|
NSString * const GSFileHandleWriteCompletionNotification
|
|
|
|
|
= @"GSFileHandleWriteCompletionNotification";
|
|
|
|
|
|
|
|
|
|
// GNUstep key for getting error message.
|
|
|
|
|
|
|
|
|
|
NSString * const GSFileHandleNotificationError
|
|
|
|
|
= @"GSFileHandleNotificationError";
|
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
|
static Class NSFileHandle_abstract_class = nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
static Class NSFileHandle_concrete_class = nil;
|
2001-12-04 14:59:09 +00:00
|
|
|
|
static Class NSFileHandle_ssl_class = nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
@implementation NSFileHandle
|
|
|
|
|
|
2001-12-04 14:59:09 +00:00
|
|
|
|
+ (void) initialize
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
if (self == [NSFileHandle class])
|
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
NSFileHandle_abstract_class = self;
|
2002-06-30 09:19:30 +00:00
|
|
|
|
NSFileHandle_concrete_class = [GSFileHandle class];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
if (self == NSFileHandle_abstract_class)
|
|
|
|
|
{
|
|
|
|
|
return NSAllocateObject (NSFileHandle_concrete_class, 0, z);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NSAllocateObject (self, 0, z);
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Allocating and Initializing a FileHandle Object
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleForReadingAtPath: (NSString*)path
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initForReadingAtPath: path]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleForWritingAtPath: (NSString*)path
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initForWritingAtPath: path]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleForUpdatingAtPath: (NSString*)path
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initForUpdatingAtPath: path]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleWithStandardError
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initWithStandardError]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleWithStandardInput
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initWithStandardInput]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleWithStandardOutput
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initWithStandardOutput]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleWithNullDevice
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initWithNullDevice]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (id) initWithFileDescriptor: (int)desc
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-06-23 14:52:22 +00:00
|
|
|
|
return [self initWithFileDescriptor: desc closeOnDealloc: NO];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (id) initWithFileDescriptor: (int)desc closeOnDealloc: (BOOL)flag
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (id) initWithNativeHandle: (void*)hdl
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-06-23 14:52:22 +00:00
|
|
|
|
return [self initWithNativeHandle: hdl closeOnDealloc: NO];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is the designated initializer.
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (id) initWithNativeHandle: (void*)hdl closeOnDealloc: (BOOL)flag
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returning file handles
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (int) fileDescriptor
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void*) nativeHandle
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Synchronous I/O operations
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (NSData*) availableData
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (NSData*) readDataToEndOfFile
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (NSData*) readDataOfLength: (unsigned int)len
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) writeData: (NSData*)item
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Asynchronous I/O operations
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) acceptConnectionInBackgroundAndNotify
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2002-06-23 19:53:15 +00:00
|
|
|
|
[self acceptConnectionInBackgroundAndNotifyForModes: nil];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
- (void) acceptConnectionInBackgroundAndNotifyForModes: (NSArray*)modes
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Call -readInBackgroundAndNotifyForModes: with nil modes.
|
|
|
|
|
*/
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) readInBackgroundAndNotify
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2002-06-23 19:53:15 +00:00
|
|
|
|
[self readInBackgroundAndNotifyForModes: nil];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set up an asynchonous read operation which will cause a notification to
|
|
|
|
|
* be sent when any amount of data (or end of file) is read.
|
|
|
|
|
*/
|
|
|
|
|
- (void) readInBackgroundAndNotifyForModes: (NSArray*)modes
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Call -readToEndOfFileInBackgroundAndNotifyForModes: with nil modes.
|
|
|
|
|
*/
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) readToEndOfFileInBackgroundAndNotify
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2002-06-23 19:53:15 +00:00
|
|
|
|
[self readToEndOfFileInBackgroundAndNotifyForModes: nil];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set up an asynchonous read operation which will cause a notification to
|
|
|
|
|
* be sent when end of file is read.
|
|
|
|
|
*/
|
|
|
|
|
- (void) readToEndOfFileInBackgroundAndNotifyForModes: (NSArray*)modes
|
1998-09-10 04:48:50 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1998-09-10 04:48:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Call -waitForDataInBackgroundAndNotifyForModes: with nil modes.
|
|
|
|
|
*/
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) waitForDataInBackgroundAndNotify
|
2002-06-23 19:53:15 +00:00
|
|
|
|
{
|
|
|
|
|
[self waitForDataInBackgroundAndNotifyForModes: nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up to provide a notification when data can be read from the handle.
|
|
|
|
|
*/
|
|
|
|
|
- (void) waitForDataInBackgroundAndNotifyForModes: (NSArray*)modes
|
1998-09-10 04:48:50 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1998-09-10 04:48:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
// Seeking within a file
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (unsigned long long) offsetInFile
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (unsigned long long) seekToEndOfFile
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) seekToFileOffset: (unsigned long long)pos
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Operations on file
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) closeFile
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) synchronizeFile
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (void) truncateFileAtOffset: (unsigned long long)pos
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
// Keys for accessing userInfo dictionary in notification handlers.
|
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
NSString * const NSFileHandleNotificationDataItem
|
|
|
|
|
= @"NSFileHandleNotificationDataItem";
|
|
|
|
|
NSString * const NSFileHandleNotificationFileHandleItem
|
|
|
|
|
= @"NSFileHandleNotificationFileHandleItem";
|
|
|
|
|
NSString * const NSFileHandleNotificationMonitorModes
|
|
|
|
|
= @"NSFileHandleNotificationMonitorModes";
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
// Notification names
|
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
NSString * const NSFileHandleConnectionAcceptedNotification
|
|
|
|
|
= @"NSFileHandleConnectionAcceptedNotification";
|
|
|
|
|
NSString * const NSFileHandleDataAvailableNotification
|
|
|
|
|
= @"NSFileHandleDataAvailableNotification";
|
|
|
|
|
NSString * const NSFileHandleReadCompletionNotification
|
|
|
|
|
= @"NSFileHandleReadCompletionNotification";
|
|
|
|
|
NSString * const NSFileHandleReadToEndOfFileCompletionNotification
|
|
|
|
|
= @"NSFileHandleReadToEndOfFileCompletionNotification";
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
// Exceptions
|
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
NSString * const NSFileHandleOperationException
|
|
|
|
|
= @"NSFileHandleOperationException";
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GNUstep class extensions
|
|
|
|
|
|
|
|
|
|
@implementation NSFileHandle (GNUstepExtensions)
|
|
|
|
|
|
2002-06-12 12:02:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* Opens an outgoing network connection by initiating an asynchronous
|
|
|
|
|
* connection (see
|
|
|
|
|
* [+fileHandleAsClientInBackgroundAtAddress:service:protocol:forModes:])
|
|
|
|
|
* and waiting for it to succeed, fail, or time out.
|
|
|
|
|
*/
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleAsClientAtAddress: (NSString*)address
|
|
|
|
|
service: (NSString*)service
|
|
|
|
|
protocol: (NSString*)protocol
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initAsClientAtAddress: address
|
|
|
|
|
service: service
|
|
|
|
|
protocol: protocol]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-12 12:02:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* Opens an outgoing network connection asynchronously using
|
|
|
|
|
* [+fileHandleAsClientInBackgroundAtAddress:service:protocol:forModes:]
|
|
|
|
|
*/
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleAsClientInBackgroundAtAddress: (NSString*)address
|
|
|
|
|
service: (NSString*)service
|
|
|
|
|
protocol: (NSString*)protocol
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initAsClientInBackgroundAtAddress: address
|
|
|
|
|
service: service
|
|
|
|
|
protocol: protocol
|
|
|
|
|
forModes: nil]);
|
1998-07-15 12:47:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-12 12:02:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* <p>
|
|
|
|
|
* Opens an outgoing network connection asynchronously.
|
|
|
|
|
* </p>
|
|
|
|
|
* <list>
|
|
|
|
|
* <item>
|
|
|
|
|
* The address is the name (or IP dotted quad) of the machine to
|
|
|
|
|
* which the connection should be made.
|
|
|
|
|
* </item>
|
|
|
|
|
* <item>
|
|
|
|
|
* The service is the name (or number) of the port to
|
|
|
|
|
* which the connection should be made.
|
|
|
|
|
* </item>
|
|
|
|
|
* <item>
|
|
|
|
|
* The protocol is provided so support different network protocols,
|
|
|
|
|
* but at present only 'tcp' is supported. However, a protocol
|
|
|
|
|
* specification of the form 'socks-...' can be used to control socks5
|
|
|
|
|
* support.<br />
|
|
|
|
|
* If '...' is empty (ie the string is just 'socks-' then the connection
|
|
|
|
|
* is <em>not</em> made via a socks server.<br />
|
|
|
|
|
* Otherwise, the text '...' must be the name of the host on which the
|
|
|
|
|
* socks5 server is running, with an optional port number separated
|
|
|
|
|
* from the host name by a colon.
|
|
|
|
|
* </item>
|
|
|
|
|
* <item>
|
|
|
|
|
* If modes is nil or empty, uses NSDefaultRunLoopMode.
|
|
|
|
|
* </item>
|
|
|
|
|
* </list>
|
|
|
|
|
* <p>
|
|
|
|
|
* This method supports connection through a firewall via socks5. The
|
|
|
|
|
* socks5 connection may be controlled via the protocol argument, but if
|
|
|
|
|
* no socks infromation is supplied here, the <em>GSSOCKS</em> user default
|
|
|
|
|
* will be used, and failing that, the <em>SOCKS5_SERVER</em> or
|
|
|
|
|
* <em>SOCKS_SERVER</em> environment variables will be used to set the
|
|
|
|
|
* socks server. If none of these mechanisms specify a socks server, the
|
|
|
|
|
* connection will be made directly rather than through socks.
|
|
|
|
|
* </p>
|
|
|
|
|
*/
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleAsClientInBackgroundAtAddress: (NSString*)address
|
|
|
|
|
service: (NSString*)service
|
|
|
|
|
protocol: (NSString*)protocol
|
|
|
|
|
forModes: (NSArray*)modes
|
1998-07-15 12:47:13 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initAsClientInBackgroundAtAddress: address
|
|
|
|
|
service: service
|
|
|
|
|
protocol: protocol
|
|
|
|
|
forModes: modes]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
+ (id) fileHandleAsServerAtAddress: (NSString*)address
|
|
|
|
|
service: (NSString*)service
|
|
|
|
|
protocol: (NSString*)protocol
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
|
id o = [self allocWithZone: NSDefaultMallocZone()];
|
|
|
|
|
|
|
|
|
|
return AUTORELEASE([o initAsServerAtAddress: address
|
|
|
|
|
service: service
|
|
|
|
|
protocol: protocol]);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Call -readDataInBackgroundAndNotifyLength:forModes: with nil modes.
|
|
|
|
|
*/
|
|
|
|
|
- (void) readDataInBackgroundAndNotifyLength: (unsigned)len
|
|
|
|
|
{
|
|
|
|
|
[self readDataInBackgroundAndNotifyLength: len forModes: nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up an asynchonous read operation which will cause a notification to
|
|
|
|
|
* be sent when the specified amount of data (or end of file) is read.
|
|
|
|
|
*/
|
|
|
|
|
- (void) readDataInBackgroundAndNotifyLength: (unsigned)len
|
|
|
|
|
forModes: (NSArray*)modes
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (BOOL) readInProgress
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (NSString*) socketAddress
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
2000-06-23 14:52:22 +00:00
|
|
|
|
return nil;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (NSString*) socketService
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
2000-06-23 14:52:22 +00:00
|
|
|
|
return nil;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (NSString*) socketProtocol
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
2000-06-23 14:52:22 +00:00
|
|
|
|
return nil;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-10 17:31:39 +00:00
|
|
|
|
- (BOOL) useCompression
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Call -writeInBackgroundAndNotify:forModes: with nil modes.
|
|
|
|
|
*/
|
|
|
|
|
- (void) writeInBackgroundAndNotify: (NSData*)item
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2002-06-23 19:53:15 +00:00
|
|
|
|
[self writeInBackgroundAndNotify: item forModes: nil];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-23 19:53:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Write the specified data asynchronously, and notify on completion.
|
|
|
|
|
*/
|
|
|
|
|
- (void) writeInBackgroundAndNotify: (NSData*)item forModes: (NSArray*)modes
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-23 14:52:22 +00:00
|
|
|
|
- (BOOL) writeInProgress
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
@end
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
@implementation NSFileHandle (GNUstepOpenSSL)
|
|
|
|
|
+ (Class) sslClass
|
|
|
|
|
{
|
|
|
|
|
if (NSFileHandle_ssl_class == 0)
|
|
|
|
|
{
|
|
|
|
|
NSBundle *bundle;
|
|
|
|
|
NSString *path;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
|
|
|
|
|
NSSystemDomainMask, NO) lastObject];
|
|
|
|
|
path = [path stringByAppendingPathComponent: @"Bundles"];
|
|
|
|
|
path = [path stringByAppendingPathComponent: @"SSL.bundle"];
|
|
|
|
|
bundle = [NSBundle bundleWithPath: path];
|
|
|
|
|
NSFileHandle_ssl_class = [bundle principalClass];
|
|
|
|
|
}
|
|
|
|
|
return NSFileHandle_ssl_class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) sslConnect
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2002-06-06 14:02:59 +00:00
|
|
|
|
- (void) sslDisconnect
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
- (void) sslSetCertificate: (NSString*)certFile
|
|
|
|
|
privateKey: (NSString*)privateKey
|
|
|
|
|
PEMpasswd: (NSString*)PEMpasswd
|
|
|
|
|
{
|
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@end
|
|
|
|
|
|