Skip to content

Commit

Permalink
Adjust to ObjFW changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Midar committed Jan 20, 2019
1 parent 625cd67 commit d11a5e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
20 changes: 7 additions & 13 deletions IRCConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
#import "IRCConnection.h"
#import "config.h"

@interface IRCConnection ()
- (bool)socket: (OF_KINDOF(OFTCPSocket *))sock
didReadLine: (OFString *)line
context: (id)context
exception: (id)exception;
@interface IRCConnection () <OFStreamDelegate>
- (void)processLine: (OFString *)line;
- (void)sendLine: (OFConstantString *)format, ...;
- (void)sendStatus: (unsigned short)status
Expand Down Expand Up @@ -76,6 +72,8 @@ - (instancetype)initWithSocket: (OF_KINDOF(OFTCPSocket *))sock
* closed.
*/
[self retain];

[_socket setDelegate: self];
} @catch (id e) {
[self release];
@throw e;
Expand Down Expand Up @@ -124,10 +122,7 @@ - (void)connection: (XMPPConnection *)connection
of_log(@"XMPP connection for %@ has JID %@",
of_socket_address_ip_string([_socket remoteAddress], NULL), JID);

[_socket asyncReadLineWithTarget: self
selector: @selector(socket:didReadLine:context:
exception:)
context: nil];
[_socket asyncReadLine];
}

- (void)connection: (XMPPConnection *)connection
Expand Down Expand Up @@ -206,20 +201,19 @@ - (void)connection: (XMPPConnection *)connection
fromResource, fromNode, line];
}

- (bool)socket: (OF_KINDOF(OFTCPSocket *))sock
- (bool)stream: (OF_KINDOF(OFStream *))stream
didReadLine: (OFString *)line
context: (id)context
exception: (id)exception
{
if (exception != nil) {
of_log(@"Exception in connection from %@",
of_socket_address_ip_string([sock remoteAddress], NULL));
of_socket_address_ip_string([stream remoteAddress], NULL));
return false;
}

if (line == nil) {
of_log(@"Connection from %@ closed",
of_socket_address_ip_string([sock remoteAddress], NULL));
of_socket_address_ip_string([stream remoteAddress], NULL));

[_XMPPConnection close];
return false;
Expand Down
15 changes: 3 additions & 12 deletions MUC2IRC.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

#import "IRCConnection.h"

@interface MUC2IRC: OFObject <OFApplicationDelegate>
@interface MUC2IRC: OFObject <OFApplicationDelegate, OFTCPSocketDelegate>
{
OFTCPSocket *_listeningSocket;
}

- (bool)socket: (OF_KINDOF(OFTCPSocket *))listeningSocket
didAcceptSocket: (OF_KINDOF(OFTCPSocket *))sock
context: (id)context
exception: (id)exception;
@end

OF_APPLICATION_DELEGATE(MUC2IRC)
Expand All @@ -19,19 +14,15 @@ @implementation MUC2IRC
- (void)applicationDidFinishLaunching
{
_listeningSocket = [[OFTCPSocket alloc] init];
[_listeningSocket setDelegate: self];
[_listeningSocket bindToHost: @"::"
port: 6667];
[_listeningSocket listen];
[_listeningSocket asyncAcceptWithTarget: self
selector: @selector(socket:
didAcceptSocket:context:
exception:)
context: nil];
[_listeningSocket asyncAccept];
}

- (bool)socket: (OF_KINDOF(OFTCPSocket *))listeningSocket
didAcceptSocket: (OF_KINDOF(OFTCPSocket *))sock
context: (id)context
exception: (id)exception;
{
if (exception != nil) {
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
all:
@objfw-compile -lobjxmpp -o muc2irc \
IRCConnection.m \
@objfw-compile --package ObjXMPP -o muc2irc \
IRCConnection.m \
MUC2IRC.m

clean:
Expand Down

0 comments on commit d11a5e3

Please sign in to comment.