Adjust to recent ObjFW changes.

This commit is contained in:
Jonathan Schleifer 2011-04-23 21:54:28 +02:00
parent 22d29b2a53
commit 0b7a6fdac0

View file

@ -13,6 +13,7 @@
#import <ObjFW/OFOutOfRangeException.h> #import <ObjFW/OFOutOfRangeException.h>
#import <ObjFW/OFReadFailedException.h> #import <ObjFW/OFReadFailedException.h>
#import <ObjFW/OFWriteFailedException.h> #import <ObjFW/OFWriteFailedException.h>
#import <ObjFW/macros.h>
#ifndef INVALID_SOCKET #ifndef INVALID_SOCKET
# define INVALID_SOCKET -1 # define INVALID_SOCKET -1
@ -113,35 +114,35 @@ static SSL_CTX *ctx;
- (SSLSocket*)accept - (SSLSocket*)accept
{ {
SSLSocket *newsock = (SSLSocket*)[super accept]; SSLSocket *newSocket = (SSLSocket*)[super accept];
if ((newsock->ssl = SSL_new(ctx)) == NULL || if ((newSocket->ssl = SSL_new(ctx)) == NULL ||
!SSL_set_fd(newsock->ssl, newsock->sock)) { !SSL_set_fd(newSocket->ssl, newSocket->sock)) {
/* We only want to close the OFTCPSocket */ /* We only want to close the OFTCPSocket */
newsock->isa = [OFTCPSocket class]; newSocket->isa = [OFTCPSocket class];
[newsock close]; [newSocket close];
newsock->isa = isa; newSocket->isa = isa;
@throw [OFAcceptFailedException newWithClass: isa @throw [OFAcceptFailedException newWithClass: isa
socket: self]; socket: self];
} }
SSL_set_accept_state(newsock->ssl); SSL_set_accept_state(newSocket->ssl);
if (!SSL_use_PrivateKey_file(newsock->ssl, [privateKeyFile cString], if (!SSL_use_PrivateKey_file(newSocket->ssl, [privateKeyFile cString],
SSL_FILETYPE_PEM) || !SSL_use_certificate_file(newsock->ssl, SSL_FILETYPE_PEM) || !SSL_use_certificate_file(newSocket->ssl,
[certificateFile cString], SSL_FILETYPE_PEM) || [certificateFile cString], SSL_FILETYPE_PEM) ||
SSL_accept(newsock->ssl) != 1) { SSL_accept(newSocket->ssl) != 1) {
/* We only want to close the OFTCPSocket */ /* We only want to close the OFTCPSocket */
newsock->isa = [OFTCPSocket class]; newSocket->isa = [OFTCPSocket class];
[newsock close]; [newSocket close];
newsock->isa = isa; newSocket->isa = isa;
@throw [OFAcceptFailedException newWithClass: isa @throw [OFAcceptFailedException newWithClass: isa
socket: self]; socket: self];
} }
return newsock; return newSocket;
} }
- (void)close - (void)close
@ -151,24 +152,24 @@ static SSL_CTX *ctx;
[super close]; [super close];
} }
- (size_t)_readNBytes: (size_t)size - (size_t)_readNBytes: (size_t)length
intoBuffer: (char*)buf intoBuffer: (char*)buffer
{ {
ssize_t ret; ssize_t ret;
if (size > INT_MAX) if (length > INT_MAX)
@throw [OFOutOfRangeException newWithClass: isa]; @throw [OFOutOfRangeException newWithClass: isa];
if (sock == INVALID_SOCKET) if (sock == INVALID_SOCKET)
@throw [OFNotConnectedException newWithClass: isa @throw [OFNotConnectedException newWithClass: isa
socket: self]; socket: self];
if (eos) { if (isAtEndOfStream) {
OFReadFailedException *e; OFReadFailedException *e;
e = [OFReadFailedException newWithClass: isa e = [OFReadFailedException newWithClass: isa
stream: self stream: self
requestedSize: size]; requestedLength: length];
#ifndef _WIN32 #ifndef _WIN32
e->errNo = ENOTCONN; e->errNo = ENOTCONN;
#else #else
@ -178,35 +179,35 @@ static SSL_CTX *ctx;
@throw e; @throw e;
} }
if ((ret = SSL_read(ssl, buf, (int)size)) < 0) if ((ret = SSL_read(ssl, buffer, (int)length)) < 0)
@throw [OFReadFailedException newWithClass: isa @throw [OFReadFailedException newWithClass: isa
stream: self stream: self
requestedSize: size]; requestedLength: length];
if (ret == 0) if (ret == 0)
eos = YES; isAtEndOfStream = YES;
return ret; return ret;
} }
- (size_t)_writeNBytes: (size_t)size - (size_t)_writeNBytes: (size_t)length
fromBuffer: (const char*)buf fromBuffer: (const char*)buffer
{ {
ssize_t ret; ssize_t ret;
if (size > INT_MAX) if (length > INT_MAX)
@throw [OFOutOfRangeException newWithClass: isa]; @throw [OFOutOfRangeException newWithClass: isa];
if (sock == INVALID_SOCKET) if (sock == INVALID_SOCKET)
@throw [OFNotConnectedException newWithClass: isa @throw [OFNotConnectedException newWithClass: isa
socket: self]; socket: self];
if (eos) { if (isAtEndOfStream) {
OFWriteFailedException *e; OFWriteFailedException *e;
e = [OFWriteFailedException newWithClass: isa e = [OFWriteFailedException newWithClass: isa
stream: self stream: self
requestedSize: size]; requestedLength: length];
#ifndef _WIN32 #ifndef _WIN32
e->errNo = ENOTCONN; e->errNo = ENOTCONN;
@ -217,10 +218,10 @@ static SSL_CTX *ctx;
@throw e; @throw e;
} }
if ((ret = SSL_write(ssl, buf, (int)size)) < 1) if ((ret = SSL_write(ssl, buffer, (int)length)) < 1)
@throw [OFWriteFailedException newWithClass: isa @throw [OFWriteFailedException newWithClass: isa
stream: self stream: self
requestedSize: size]; requestedLength: length];
return ret; return ret;
} }
@ -232,25 +233,21 @@ static SSL_CTX *ctx;
- (void)setPrivateKeyFile: (OFString*)file - (void)setPrivateKeyFile: (OFString*)file
{ {
OFString *old = privateKeyFile; OF_SETTER(privateKeyFile, file, YES, YES)
privateKeyFile = [file copy];
[old release];
} }
- (OFString*)privateKeyFile - (OFString*)privateKeyFile
{ {
return [[privateKeyFile copy] autorelease]; OF_GETTER(privateKeyFile, YES)
} }
- (void)setCertificateFile: (OFString*)file - (void)setCertificateFile: (OFString*)file
{ {
OFString *old = certificateFile; OF_SETTER(certificateFile, file, YES, YES)
certificateFile = [file copy];
[old release];
} }
- (OFString*)certificateFile - (OFString*)certificateFile
{ {
return [[certificateFile copy] autorelease]; OF_GETTER(certificateFile, YES)
} }
@end @end