@@ -1,7 +1,7 @@ /* - * Copyright (c) 2010, 2011, Jonathan Schleifer + * Copyright (c) 2010, 2011, 2019, Jonathan Schleifer * Copyright (c) 2011, 2012, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -51,42 +51,43 @@ - (void)applicationDidFinishLaunching { OFArray *arguments = [OFApplication arguments]; XMPPPresence *pres = [XMPPPresence presence]; - [pres setShow: @"xa"]; - [pres setStatus: @"Bored"]; - [pres setPriority: [OFNumber numberWithInt8: 20]]; - [pres setTo: [XMPPJID JIDWithString: @"alice@example.com"]]; - [pres setFrom: [XMPPJID JIDWithString: @"bob@example.org"]]; - assert([[pres XMLString] isEqual: @"xa" @"Bored20" @""]); XMPPPresence *pres2 = [XMPPPresence presence]; - [pres2 setShow: @"away"]; - [pres2 setStatus: @"Bored"]; - [pres2 setPriority: [OFNumber numberWithInt8: 23]]; - [pres2 setTo: [XMPPJID JIDWithString: @"alice@example.com"]]; - [pres2 setFrom: [XMPPJID JIDWithString: @"bob@example.org"]]; + pres2.show = @"away"; + pres2.status = @"Bored"; + pres2.priority = [OFNumber numberWithInt8: 23]; + pres2.to = [XMPPJID JIDWithString: @"alice@example.com"]; + pres2.from = [XMPPJID JIDWithString: @"bob@example.org"]; assert([pres compare: pres2] == OF_ORDERED_ASCENDING); XMPPMessage *msg = [XMPPMessage messageWithType: @"chat"]; - [msg setBody: @"Hello everyone"]; - [msg setTo: [XMPPJID JIDWithString: @"jdev@conference.jabber.org"]]; - [msg setFrom: [XMPPJID JIDWithString: @"alice@example.com"]]; - assert([[msg XMLString] isEqual: @"Hello everyone" @""]); - XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"]; - [iq setTo: [XMPPJID JIDWithString: @"juliet@capulet.lit"]]; - [iq setFrom: [XMPPJID JIDWithString: @"romeo@montague.lit"]]; - assert([[iq XMLString] isEqual: @""]); OFXMLElement *elem = [OFXMLElement elementWithName: @"iq"]; [elem addAttributeWithName: @"from" @@ -96,37 +97,37 @@ [elem addAttributeWithName: @"type" stringValue: @"get"]; [elem addAttributeWithName: @"id" stringValue: @"42"]; XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem]; - assert([[elem XMLString] isEqual: [stanza XMLString]]); + assert([elem.XMLString isEqual: [stanza XMLString]]); assert(([[OFString stringWithFormat: @"%@, %@, %@, %@", - [[stanza from] fullJID], [[stanza to] fullJID], [stanza type], - [stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"])); + stanza.from.fullJID, stanza.to.fullJID, stanza.type, stanza.ID] + isEqual: @"bob@localhost, alice@localhost, get, 42"])); conn = [[XMPPConnection alloc] init]; [conn addDelegate: self]; XMPPFileStorage *storage = [[XMPPFileStorage alloc] initWithFile: @"storage.binarypack"]; - [conn setDataStorage: storage]; + conn.dataStorage = storage; roster = [[XMPPRoster alloc] initWithConnection: conn]; [roster addDelegate: self]; [[XMPPStreamManagement alloc] initWithConnection: conn]; - if ([arguments count] != 3) { + if (arguments.count != 3) { of_log(@"Invalid count of command line arguments!"); [OFApplication terminateWithStatus: 1]; } - [conn setDomain: [arguments objectAtIndex: 0]]; - [conn setUsername: [arguments objectAtIndex: 1]]; - [conn setPassword: [arguments objectAtIndex: 2]]; - [conn setResource: @"ObjXMPP"]; + conn.domain = [arguments objectAtIndex: 0]; + conn.username = [arguments objectAtIndex: 1]; + conn.password = [arguments objectAtIndex: 2]; + conn.resource = @"ObjXMPP"; [conn asyncConnect]; } - (void)connection: (XMPPConnection *)conn @@ -145,15 +146,15 @@ { of_log(@"Auth successful"); } - (void)connection: (XMPPConnection *)conn_ - wasBoundToJID: (XMPPJID *)jid + wasBoundToJID: (XMPPJID *)JID { - of_log(@"Bound to JID: %@", [jid fullJID]); + of_log(@"Bound to JID: %@", JID.fullJID); of_log(@"Supports SM: %@", - [conn_ supportsStreamManagement] ? @"true" : @"false"); + conn_.supportsStreamManagement ? @"true" : @"false"); XMPPDiscoEntity *discoEntity = [[XMPPDiscoEntity alloc] initWithConnection: conn]; [discoEntity addIdentity: @@ -160,33 +161,33 @@ [XMPPDiscoIdentity identityWithCategory: @"client" type: @"pc" name: @"ObjXMPP"]]; XMPPDiscoNode *nodeMusic = - [XMPPDiscoNode discoNodeWithJID: jid + [XMPPDiscoNode discoNodeWithJID: JID node: @"music" name: @"My music"]; [discoEntity addChildNode: nodeMusic]; XMPPDiscoNode *nodeRHCP = - [XMPPDiscoNode discoNodeWithJID: jid + [XMPPDiscoNode discoNodeWithJID: JID node: @"fa3b6" name: @"Red Hot Chili Peppers"]; [nodeMusic addChildNode: nodeRHCP]; XMPPDiscoNode *nodeStop = - [XMPPDiscoNode discoNodeWithJID: jid + [XMPPDiscoNode discoNodeWithJID: JID node: @"qwe87" name: @"Can't Stop"]; [nodeRHCP addChildNode: nodeStop]; - XMPPDiscoNode *nodeClueso = [XMPPDiscoNode discoNodeWithJID: jid + XMPPDiscoNode *nodeClueso = [XMPPDiscoNode discoNodeWithJID: JID node: @"ea386" name: @"Clueso"]; [nodeMusic addChildNode: nodeClueso]; - XMPPDiscoNode *nodeChicago = [XMPPDiscoNode discoNodeWithJID: jid + XMPPDiscoNode *nodeChicago = [XMPPDiscoNode discoNodeWithJID: JID node: @"qwr87" name: @"Chicago"]; [nodeClueso addChildNode: nodeChicago]; [discoEntity addDiscoNode: nodeMusic]; @@ -200,24 +201,24 @@ - (void)rosterWasReceived: (XMPPRoster *)roster_ { XMPPPresence *pres; - of_log(@"Got roster: %@", [roster_ rosterItems]); + of_log(@"Got roster: %@", roster_.rosterItems); pres = [XMPPPresence presence]; - [pres setPriority: [OFNumber numberWithInt8: 10]]; - [pres setStatus: @"ObjXMPP test is working!"]; + pres.priority = [OFNumber numberWithInt8: 10]; + pres.status = @"ObjXMPP test is working!"; [conn sendStanza: pres]; #ifdef OF_HAVE_BLOCKS - XMPPIQ *iq = [XMPPIQ IQWithType: @"get" + XMPPIQ *IQ = [XMPPIQ IQWithType: @"get" ID: [conn generateStanzaID]]; - [iq addChild: [OFXMLElement elementWithName: @"ping" + [IQ addChild: [OFXMLElement elementWithName: @"ping" namespace: @"urn:xmpp:ping"]]; - [conn sendIQ: iq + [conn sendIQ: IQ callbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) { of_log(@"Ping response: %@", resp); }]; #endif }