Adjust to ObjFW changes
FossilOrigin-Name: 42243ac2f70297a6b48b7cd7d0a53b8ee49cc69a430c156d730a335af3bc3ed3
This commit is contained in:
parent
b445394724
commit
e3e8e886a7
3 changed files with 46 additions and 50 deletions
|
@ -37,6 +37,8 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
- (void)connection: (IRCConnection *)connection
|
- (void)connection: (IRCConnection *)connection
|
||||||
didSendLine: (OFString *)line;
|
didSendLine: (OFString *)line;
|
||||||
- (void)connectionWasEstablished: (IRCConnection *)connection;
|
- (void)connectionWasEstablished: (IRCConnection *)connection;
|
||||||
|
- (void)connection: (IRCConnection *)connection
|
||||||
|
didFailToConnectWithException: (id)exception;
|
||||||
- (void)connection: (IRCConnection *)connection
|
- (void)connection: (IRCConnection *)connection
|
||||||
didSeeUser: (IRCUser *)user
|
didSeeUser: (IRCUser *)user
|
||||||
joinChannel: (OFString *)channel;
|
joinChannel: (OFString *)channel;
|
||||||
|
@ -88,6 +90,7 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
of_time_interval_t _pingInterval, _pingTimeout;
|
of_time_interval_t _pingInterval, _pingTimeout;
|
||||||
OFString *_Nullable _pingData;
|
OFString *_Nullable _pingData;
|
||||||
OFTimer *_Nullable _pingTimer;
|
OFTimer *_Nullable _pingTimer;
|
||||||
|
bool _fallbackEncodingUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (readonly, nonatomic) Class socketClass;
|
@property (readonly, nonatomic) Class socketClass;
|
||||||
|
@ -120,8 +123,6 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
channel: (OFString *)channel
|
channel: (OFString *)channel
|
||||||
reason: (nullable OFString *)reason;
|
reason: (nullable OFString *)reason;
|
||||||
- (void)changeNicknameTo: (OFString *)nickname;
|
- (void)changeNicknameTo: (OFString *)nickname;
|
||||||
- (void)processLine: (OFString *)line;
|
|
||||||
- (void)handleConnection;
|
|
||||||
- (nullable OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel;
|
- (nullable OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
#import "IRCConnection.h"
|
#import "IRCConnection.h"
|
||||||
#import "IRCUser.h"
|
#import "IRCUser.h"
|
||||||
|
|
||||||
|
@interface IRCConnection () <OFTCPSocketDelegate>
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation IRCConnection
|
@implementation IRCConnection
|
||||||
@synthesize socketClass = _socketClass;
|
@synthesize socketClass = _socketClass;
|
||||||
@synthesize server = _server, port = _port;
|
@synthesize server = _server, port = _port;
|
||||||
|
@ -91,18 +94,36 @@
|
||||||
@throw [OFAlreadyConnectedException exception];
|
@throw [OFAlreadyConnectedException exception];
|
||||||
|
|
||||||
_socket = [[_socketClass alloc] init];
|
_socket = [[_socketClass alloc] init];
|
||||||
|
[_socket setDelegate: self];
|
||||||
|
[_socket asyncConnectToHost: _server
|
||||||
|
port: _port];
|
||||||
|
|
||||||
|
objc_autoreleasePoolPop(pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)socket: (OF_KINDOF(OFTCPSocket *))socket
|
||||||
|
didConnectToHost: (OFString *)host
|
||||||
|
port: (uint16_t)port
|
||||||
|
exception: (id)exception
|
||||||
|
{
|
||||||
|
if (exception != nil) {
|
||||||
|
if ([_delegate respondsToSelector:
|
||||||
|
@selector(connection:didFailToConnectWithException:)])
|
||||||
|
[_delegate connection: self
|
||||||
|
didFailToConnectWithException: exception];
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ([_delegate respondsToSelector:
|
if ([_delegate respondsToSelector:
|
||||||
@selector(connection:didCreateSocket:)])
|
@selector(connection:didCreateSocket:)])
|
||||||
[_delegate connection: self
|
[_delegate connection: self
|
||||||
didCreateSocket: _socket];
|
didCreateSocket: _socket];
|
||||||
|
|
||||||
[_socket connectToHost: _server
|
|
||||||
port: _port];
|
|
||||||
|
|
||||||
[self sendLineWithFormat: @"NICK %@", _nickname];
|
[self sendLineWithFormat: @"NICK %@", _nickname];
|
||||||
[self sendLineWithFormat: @"USER %@ * 0 :%@", _username, _realname];
|
[self sendLineWithFormat: @"USER %@ * 0 :%@", _username, _realname];
|
||||||
|
|
||||||
objc_autoreleasePoolPop(pool);
|
[socket asyncReadLine];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)disconnect
|
- (void)disconnect
|
||||||
|
@ -575,50 +596,25 @@
|
||||||
_socket = nil;
|
_socket = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)processLine: (OFString *)line
|
- (bool)stream: (OF_KINDOF(OFStream *))stream
|
||||||
{
|
didReadLine: (OFString *)line
|
||||||
void *pool = objc_autoreleasePoolPush();
|
|
||||||
|
|
||||||
[self irc_processLine: line];
|
|
||||||
|
|
||||||
objc_autoreleasePoolPop(pool);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (bool)irc_socket: (OFTCPSocket *)socket
|
|
||||||
didReceiveWronglyEncodedLine: (OFString *)line
|
|
||||||
context: (id)context
|
|
||||||
exception: (OFException *)exception
|
exception: (OFException *)exception
|
||||||
{
|
{
|
||||||
if (line != nil) {
|
if (line != nil) {
|
||||||
[self irc_processLine: line];
|
[self irc_processLine: line];
|
||||||
[socket asyncReadLineWithTarget: self
|
|
||||||
selector: @selector(irc_socket:
|
|
||||||
didReceiveLine:context:
|
|
||||||
exception:)
|
|
||||||
context: nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (_fallbackEncodingUsed) {
|
||||||
|
_fallbackEncodingUsed = false;
|
||||||
|
[stream asyncReadLine];
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (bool)irc_socket: (OFTCPSocket *)socket
|
|
||||||
didReceiveLine: (OFString *)line
|
|
||||||
context: (id)context
|
|
||||||
exception: (OFException *)exception
|
|
||||||
{
|
|
||||||
if (line != nil) {
|
|
||||||
[self irc_processLine: line];
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
|
if ([exception isKindOfClass: [OFInvalidEncodingException class]]) {
|
||||||
[socket
|
_fallbackEncodingUsed = true;
|
||||||
asyncReadLineWithEncoding: _fallbackEncoding
|
[stream asyncReadLineWithEncoding: _fallbackEncoding];
|
||||||
target: self
|
|
||||||
selector: @selector(irc_socket:
|
|
||||||
didReceiveWronglyEncodedLine:
|
|
||||||
context:exception:)
|
|
||||||
context: nil];
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,14 +631,6 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleConnection
|
|
||||||
{
|
|
||||||
[_socket asyncReadLineWithTarget: self
|
|
||||||
selector: @selector(irc_socket:didReceiveLine:
|
|
||||||
context:exception:)
|
|
||||||
context: nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel
|
- (OFSet OF_GENERIC(OFString *) *)usersInChannel: (OFString *)channel
|
||||||
{
|
{
|
||||||
return [[[_channels objectForKey: channel] copy] autorelease];
|
return [[[_channels objectForKey: channel] copy] autorelease];
|
||||||
|
|
|
@ -44,7 +44,6 @@ OF_APPLICATION_DELEGATE(TestApp)
|
||||||
[connection setDelegate: self];
|
[connection setDelegate: self];
|
||||||
|
|
||||||
[connection connect];
|
[connection connect];
|
||||||
[connection handleConnection];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
|
@ -64,6 +63,14 @@ OF_APPLICATION_DELEGATE(TestApp)
|
||||||
[connection joinChannel: @"#objfw"];
|
[connection joinChannel: @"#objfw"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)connection: (IRCConnection *)connection
|
||||||
|
didFailToConnectWithException: (id)exception
|
||||||
|
{
|
||||||
|
[of_stderr writeFormat: @"Failed to connect: %@\n", exception];
|
||||||
|
|
||||||
|
[OFApplication terminateWithStatus: 1];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)connection: (IRCConnection*)connection
|
- (void)connection: (IRCConnection*)connection
|
||||||
didSeeUser: (IRCUser*)user
|
didSeeUser: (IRCUser*)user
|
||||||
joinChannel: (OFString*)channel
|
joinChannel: (OFString*)channel
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue