@@ -1,8 +1,8 @@ /* * Copyright (c) 2010, 2011, Jonathan Schleifer - * Copyright (c) 2011, Florian Zeitz + * Copyright (c) 2011, 2012, Florian Zeitz * * https://webkeks.org/hg/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -34,20 +34,23 @@ #import "XMPPPresence.h" #import "XMPPRoster.h" @interface AppDelegate: OFObject #ifdef OF_HAVE_OPTIONAL_PROTOCOLS - + #endif +{ + XMPPConnection * conn; + XMPPRoster *roster; +} @end OF_APPLICATION_DELEGATE(AppDelegate) @implementation AppDelegate - (void)applicationDidFinishLaunching { - XMPPConnection *conn; OFArray *arguments = [OFApplication arguments]; XMPPPresence *pres = [XMPPPresence presence]; [pres addShow: @"chat"]; [pres addStatus: @"Bored"]; @@ -89,11 +92,14 @@ assert(([[OFString stringWithFormat: @"%@, %@, %@, %@", [[stanza from] fullJID], [[stanza to] fullJID], [stanza type], [stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"])); conn = [[XMPPConnection alloc] init]; + roster = [[XMPPRoster alloc] initWithConnection: conn]; + [conn addDelegate: self]; + [roster setDelegate: self]; if ([arguments count] != 3) { of_log(@"Invalid count of command line arguments!"); [OFApplication terminateWithStatus: 1]; } @@ -131,18 +137,18 @@ - (void)connection: (XMPPConnection*)conn wasBoundToJID: (XMPPJID*)jid { of_log(@"Bound to JID: %@", [jid fullJID]); - [[conn roster] requestRoster]; + [roster requestRoster]; } -- (void)connectionDidReceiveRoster: (XMPPConnection*)conn +- (void)rosterWasReceived: (XMPPRoster*)roster_ { XMPPPresence *pres; - of_log(@"Got roster: %@", [[conn roster] rosterItems]); + of_log(@"Got roster: %@", [roster_ rosterItems]); pres = [XMPPPresence presence]; [pres addPriority: 10]; [pres addStatus: @"ObjXMPP test is working!"]; @@ -158,14 +164,14 @@ of_log(@"Ping response: %@", resp); }]; #endif } -- (void)connectionDidUpgradeToTLS: (XMPPConnection*)conn +- (void)connectionDidUpgradeToTLS: (XMPPConnection*)conn_ { @try { - [conn checkCertificate]; + [conn_ checkCertificate]; } @catch (SSLInvalidCertificateException *e) { OFString *answer; [of_stdout writeString: @"Couldn't verify certificate: "]; [of_stdout writeFormat: @"%@\n", e]; [of_stdout writeString: @"Do you want to continue [y/N]? "]; @@ -173,11 +179,11 @@ if (![answer hasPrefix: @"y"]) @throw e; } } -- (void)connection: (XMPPConnection*)conn +- (void)roster: (XMPPRoster*)roster_ didReceiveRosterItem: (XMPPRosterItem*)rosterItem { of_log(@"Got roster push: %@", rosterItem); }