Index: src/XMPPConnection.h ================================================================== --- src/XMPPConnection.h +++ src/XMPPConnection.h @@ -145,11 +145,11 @@ /*! * @brief A class which abstracts a connection to an XMPP service. */ @interface XMPPConnection: OFObject { - OF_KINDOF(OFTCPSocket *) _socket; + OFTCPSocket *_socket; char _buffer[XMPP_CONNECTION_BUFFER_LENGTH]; OFXMLParser *_parser, *_oldParser; OFXMLElementBuilder *_elementBuilder, *_oldElementBuilder; OFString *_Nullable _username, *_Nullable _password, *_Nullable _server; OFString *_Nullable _resource; @@ -233,11 +233,11 @@ @property OF_NULLABLE_PROPERTY (nonatomic, assign) id dataStorage; /*! * @brief The socket used for the connection. */ -@property (readonly, nonatomic) OF_KINDOF(OFTCPSocket *) socket; +@property (readonly, nonatomic) OFTCPSocket *socket; /*! * @brief Whether encryption is required. */ @property (nonatomic) bool encryptionRequired; Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018 + * Copyright (c) 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018, 2019 * Jonathan Schleifer * Copyright (c) 2011, 2012, Florian Zeitz * * https://heap.zone/objxmpp/ * @@ -141,11 +141,11 @@ if (username != nil) { char *node; Stringprep_rc rc; - if ((rc = stringprep_profile([username UTF8String], &node, + if ((rc = stringprep_profile(username.UTF8String, &node, "SASLprep", 0)) != STRINGPREP_OK) @throw [XMPPStringPrepFailedException exceptionWithConnection: self profile: @"SASLprep" string: username]; @@ -167,11 +167,11 @@ if (resource != nil) { char *res; Stringprep_rc rc; - if ((rc = stringprep_profile([resource UTF8String], &res, + if ((rc = stringprep_profile(resource.UTF8String, &res, "Resourceprep", 0)) != STRINGPREP_OK) @throw [XMPPStringPrepFailedException exceptionWithConnection: self profile: @"Resourceprep" string: resource]; @@ -206,11 +206,11 @@ if (domain != nil) { char *srv; Stringprep_rc rc; - if ((rc = stringprep_profile([domain UTF8String], &srv, + if ((rc = stringprep_profile(domain.UTF8String, &srv, "Nameprep", 0)) != STRINGPREP_OK) @throw [XMPPStringPrepFailedException exceptionWithConnection: self profile: @"Nameprep" string: domain]; @@ -237,11 +237,11 @@ if (password != nil) { char *pass; Stringprep_rc rc; - if ((rc = stringprep_profile([password UTF8String], &pass, + if ((rc = stringprep_profile(password.UTF8String, &pass, "SASLprep", 0)) != STRINGPREP_OK) @throw [XMPPStringPrepFailedException exceptionWithConnection: self profile: @"SASLprep" string: password]; @@ -255,17 +255,17 @@ _password = nil; [old release]; } -- (void)socket: (OF_KINDOF(OFTCPSocket *))sock +- (void)socket: (OFTCPSocket *)sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { if (exception != nil) { - if ([_nextSRVRecords count] > 0) { + if (_nextSRVRecords.count > 0) { [self xmpp_tryNextSRVRecord]; return; } [_delegates broadcastSelector: @selector(connection: @@ -284,17 +284,17 @@ - (void)xmpp_tryNextSRVRecord { OFSRVDNSResourceRecord *record = [[[_nextSRVRecords objectAtIndex: 0] copy] autorelease]; - if ([_nextSRVRecords count] == 0) { + if (_nextSRVRecords.count == 0) { [_nextSRVRecords release]; _nextSRVRecords = nil; } - [_socket asyncConnectToHost: [record target] - port: [record port]]; + [_socket asyncConnectToHost: record.target + port: record.port]; } - (void)resolver: (OFDNSResolver *)resolver didResolveDomainName: (OFString *)domainName answerRecords: (OFDictionary *)answerRecords @@ -310,19 +310,19 @@ withObject: self withObject: exception]; return; } - for (OF_KINDOF(OFDNSResourceRecord *) record in + for (OFDNSResourceRecord *record in [answerRecords objectForKey: domainName]) if ([record isKindOfClass: [OFSRVDNSResourceRecord class]]) [records addObject: record]; /* TODO: Sort records */ [records makeImmutable]; - if ([records count] == 0) { + if (records.count == 0) { /* Fall back to A / AAAA record. */ [_socket asyncConnectToHost: _domainToASCII port: _port]; return; } @@ -339,11 +339,11 @@ if (_socket != nil) @throw [OFAlreadyConnectedException exception]; _socket = [[OFTCPSocket alloc] init]; - [(OFTCPSocket *)_socket setDelegate: self]; + [_socket setDelegate: self]; if (_server != nil) [_socket asyncConnectToHost: _server port: _port]; else { @@ -360,11 +360,11 @@ } - (bool)xmpp_parseBuffer: (const void *)buffer length: (size_t)length { - if ([_socket isAtEndOfStream]) { + if (_socket.atEndOfStream) { [_delegates broadcastSelector: @selector(connectionWasClosed: error:) withObject: self withObject: nil]; return false; @@ -446,27 +446,28 @@ - (bool)checkCertificateAndGetReason: (OFString **)reason { X509Certificate *cert; OFDictionary *SANs; bool serviceSpecific = false; + SSLSocket *socket = (SSLSocket *)_socket; @try { - [_socket verifyPeerCertificate]; + [socket verifyPeerCertificate]; } @catch (SSLInvalidCertificateException *e) { if (reason != NULL) - *reason = [[[e reason] copy] autorelease]; + *reason = e.reason; return false; } - cert = [_socket peerCertificate]; - SANs = [cert subjectAlternativeName]; + cert = socket.peerCertificate; + SANs = cert.subjectAlternativeName; if ([[SANs objectForKey: @"otherName"] - objectForKey: OID_SRVName] != nil || - [SANs objectForKey: @"dNSName"] != nil || - [SANs objectForKey: @"uniformResourceIdentifier"] != nil) + objectForKey: OID_SRVName] != nil || + [SANs objectForKey: @"dNSName"] != nil || + [SANs objectForKey: @"uniformResourceIdentifier"] != nil) serviceSpecific = true; if ([cert hasSRVNameMatchingDomain: _domainToASCII service: @"xmpp-client"] || [cert hasDNSNameMatchingDomain: _domainToASCII]) @@ -483,11 +484,11 @@ { [_delegates broadcastSelector: @selector(connection:didSendElement:) withObject: self withObject: element]; - [_socket writeString: [element XMLString]]; + [_socket writeString: element.XMLString]; } - (void)sendIQ: (XMPPIQ *)IQ callbackTarget: (id)target selector: (SEL)selector @@ -494,17 +495,17 @@ { void *pool = objc_autoreleasePoolPush(); XMPPCallback *callback; OFString *ID, *key; - if ((ID = [IQ ID]) == nil) { + if ((ID = IQ.ID) == nil) { ID = [self generateStanzaID]; - [IQ setID: ID]; + IQ.ID = ID; } - if ((key = [[IQ to] fullJID]) == nil) - key = [_JID bareJID]; + if ((key = IQ.to.fullJID) == nil) + key = _JID.bareJID; if (key == nil) // Only happens for resource bind key = @"bind"; key = [key stringByAppendingString: ID]; callback = [XMPPCallback callbackWithTarget: target @@ -523,17 +524,17 @@ { void *pool = objc_autoreleasePoolPush(); XMPPCallback *callback; OFString *ID, *key; - if ((ID = [IQ ID]) == nil) { + if ((ID = IQ.ID) == nil) { ID = [self generateStanzaID]; - [IQ setID: ID]; + IQ.ID = ID; } - if ((key = [[IQ to] fullJID]) == nil) - key = [_JID bareJID]; + if ((key = IQ.to.fullJID) == nil) + key = _JID.bareJID; if (key == nil) // Connection not yet bound, can't send stanzas @throw [OFInvalidArgumentException exception]; key = [key stringByAppendingString: ID]; callback = [XMPPCallback callbackWithBlock: block]; @@ -575,52 +576,52 @@ text: nil]; return; } for (OFXMLAttribute *attribute in attributes) { - if ([[attribute name] isEqual: @"from"] && - ![[attribute stringValue] isEqual: _domain]) { + if ([attribute.name isEqual: @"from"] && + ![attribute.stringValue isEqual: _domain]) { [self xmpp_sendStreamError: @"invalid-from" text: nil]; return; } - if ([[attribute name] isEqual: @"version"] && - ![[attribute stringValue] isEqual: @"1.0"]) { + if ([attribute.name isEqual: @"version"] && + ![attribute.stringValue isEqual: @"1.0"]) { [self xmpp_sendStreamError: @"unsupported-version" text: nil]; return; } } - [parser setDelegate: _elementBuilder]; + parser.delegate = _elementBuilder; } - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildElement: (OFXMLElement *)element { /* Ignore whitespace elements */ - if ([element name] == nil) + if (element.name == nil) return; - [element setDefaultNamespace: XMPP_NS_CLIENT]; + element.defaultNamespace = XMPP_NS_CLIENT; [element setPrefix: @"stream" forNamespace: XMPP_NS_STREAM]; [_delegates broadcastSelector: @selector(connection:didReceiveElement:) withObject: self withObject: element]; - if ([[element namespace] isEqual: XMPP_NS_CLIENT]) + if ([element.namespace isEqual: XMPP_NS_CLIENT]) [self xmpp_handleStanza: element]; - if ([[element namespace] isEqual: XMPP_NS_STREAM]) + if ([element.namespace isEqual: XMPP_NS_STREAM]) [self xmpp_handleStream: element]; - if ([[element namespace] isEqual: XMPP_NS_STARTTLS]) + if ([element.namespace isEqual: XMPP_NS_STARTTLS]) [self xmpp_handleTLS: element]; - if ([[element namespace] isEqual: XMPP_NS_SASL]) + if ([element.namespace isEqual: XMPP_NS_SASL]) [self xmpp_handleSASL: element]; } - (void)elementBuilder: (OFXMLElementBuilder *)builder didNotExpectCloseTag: (OFString *)name @@ -628,35 +629,34 @@ namespace: (OFString *)ns { if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] || ![ns isEqual: XMPP_NS_STREAM]) @throw [OFMalformedXMLException exception]; - else { + else [self close]; - } } - (void)xmpp_startStream { OFString *langString = @""; /* Make sure we don't get any old events */ - [_parser setDelegate: nil]; - [_elementBuilder setDelegate: nil]; + _parser.delegate = nil; + _elementBuilder.delegate = nil; /* * We can't release them now, as we are currently inside them. Release * them the next time the parser returns. */ _oldParser = _parser; _oldElementBuilder = _elementBuilder; _parser = [[OFXMLParser alloc] init]; - [_parser setDelegate: self]; + _parser.delegate = self; _elementBuilder = [[XMPPXMLElementBuilder alloc] init]; - [_elementBuilder setDelegate: self]; + _elementBuilder.delegate = self; if (_language != nil) langString = [OFString stringWithFormat: @"xml:lang='%@' ", _language]; @@ -689,22 +689,22 @@ _lastID = 0; } - (void)xmpp_handleStanza: (OFXMLElement *)element { - if ([[element name] isEqual: @"iq"]) { + if ([element.name isEqual: @"iq"]) { [self xmpp_handleIQ: [XMPPIQ stanzaWithElement: element]]; return; } - if ([[element name] isEqual: @"message"]) { + if ([element.name isEqual: @"message"]) { [self xmpp_handleMessage: [XMPPMessage stanzaWithElement: element]]; return; } - if ([[element name] isEqual: @"presence"]) { + if ([element.name isEqual: @"presence"]) { [self xmpp_handlePresence: [XMPPPresence stanzaWithElement: element]]; return; } @@ -713,32 +713,32 @@ } - (void)xmpp_handleStream: (OFXMLElement *)element { - if ([[element name] isEqual: @"features"]) { + if ([element.name isEqual: @"features"]) { [self xmpp_handleFeatures: element]; return; } - if ([[element name] isEqual: @"error"]) { + if ([element.name isEqual: @"error"]) { OFString *condition, *reason; [self close]; [_delegates broadcastSelector: @selector(connectionWasClosed:) withObject: self withObject: element]; - condition = [[[element elementsForNamespace: - XMPP_NS_XMPP_STREAM] firstObject] name]; + condition = [[element elementsForNamespace: + XMPP_NS_XMPP_STREAM].firstObject name]; if (condition == nil) condition = @"undefined"; - reason = [[element + reason = [element elementForName: @"text" - namespace: XMPP_NS_XMPP_STREAM] stringValue]; + namespace: XMPP_NS_XMPP_STREAM].stringValue; @throw [XMPPStreamErrorException exceptionWithConnection: self condition: condition reason: reason]; @@ -748,30 +748,30 @@ assert(0); } - (void)xmpp_handleTLS: (OFXMLElement *)element { - if ([[element name] isEqual: @"proceed"]) { + if ([element.name isEqual: @"proceed"]) { /* FIXME: Catch errors here */ SSLSocket *newSock; [_delegates broadcastSelector: @selector( connectionWillUpgradeToTLS:) withObject: self]; newSock = [[SSLSocket alloc] initWithSocket: _socket]; - [newSock setCertificateVerificationEnabled: false]; + newSock.certificateVerificationEnabled = false; #if 0 /* FIXME: Not yet implemented by ObjOpenSSL */ [newSock setCertificateFile: _certificateFile]; [newSock setPrivateKeyFile: _privateKeyFile]; [newSock setPrivateKeyPassphrase: _privateKeyPassphrase]; #endif [newSock startTLSWithExpectedHost: nil]; [_socket release]; _socket = newSock; - [(OFTCPSocket *)_socket setDelegate: self]; + [_socket setDelegate: self]; _encrypted = true; [_delegates broadcastSelector: @selector( connectionDidUpgradeToTLS:) @@ -781,42 +781,42 @@ [self xmpp_startStream]; return; } - if ([[element name] isEqual: @"failure"]) + if ([element.name isEqual: @"failure"]) /* TODO: Find/create an exception to throw here */ @throw [OFException exception]; assert(0); } - (void)xmpp_handleSASL: (OFXMLElement *)element { - if ([[element name] isEqual: @"challenge"]) { + if ([element.name isEqual: @"challenge"]) { OFXMLElement *responseTag; OFData *challenge = - [OFData dataWithBase64EncodedString: [element stringValue]]; + [OFData dataWithBase64EncodedString: element.stringValue]; OFData *response = [_authModule continueWithData: challenge]; responseTag = [OFXMLElement elementWithName: @"response" namespace: XMPP_NS_SASL]; if (response) { - if ([response count] == 0) - [responseTag setStringValue: @"="]; + if (response.count == 0) + responseTag.stringValue = @"="; else - [responseTag setStringValue: - [response stringByBase64Encoding]]; + responseTag.stringValue = + response.stringByBase64Encoding; } [self sendStanza: responseTag]; return; } - if ([[element name] isEqual: @"success"]) { + if ([element.name isEqual: @"success"]) { [_authModule continueWithData: [OFData - dataWithBase64EncodedString: [element stringValue]]]; + dataWithBase64EncodedString: element.stringValue]]; [_delegates broadcastSelector: @selector( connectionWasAuthenticated:) withObject: self]; @@ -824,15 +824,15 @@ [self xmpp_startStream]; return; } - if ([[element name] isEqual: @"failure"]) { + if ([element.name isEqual: @"failure"]) { /* FIXME: Do more parsing/handling */ @throw [XMPPAuthFailedException exceptionWithConnection: self - reason: [element XMLString]]; + reason: element.XMLString]; } assert(0); } @@ -840,15 +840,15 @@ { bool handled = false; XMPPCallback *callback; OFString *key; - if ((key = [[IQ from] fullJID]) == nil) - key = [_JID bareJID]; + if ((key = IQ.from.fullJID) == nil) + key = _JID.bareJID; if (key == nil) // Only happens for resource bind key = @"bind"; - key = [key stringByAppendingString: [IQ ID]]; + key = [key stringByAppendingString: IQ.ID]; if ((callback = [_callbacks objectForKey: key])) { [callback runWithIQ: IQ connection: self]; [_callbacks removeObjectForKey: key]; @@ -858,12 +858,12 @@ handled = [_delegates broadcastSelector: @selector( connection:didReceiveIQ:) withObject: self withObject: IQ]; - if (!handled && ![[IQ type] isEqual: @"error"] && - ![[IQ type] isEqual: @"result"]) { + if (!handled && ![IQ.type isEqual: @"error"] && + ![IQ.type isEqual: @"result"]) { [self sendStanza: [IQ errorIQWithType: @"cancel" condition: @"service-unavailable"]]; } } @@ -911,12 +911,12 @@ if ([element elementForName: @"sm" namespace: XMPP_NS_SM] != nil) _supportsStreamManagement = true; if (mechs != nil) { - for (OFXMLElement *mech in [mechs children]) - [mechanisms addObject: [mech stringValue]]; + for (OFXMLElement *mech in mechs.children) + [mechanisms addObject: mech.stringValue]; if (_usesAnonymousAuthentication) { if (![mechanisms containsObject: @"ANONYMOUS"]) @throw [XMPPAuthFailedException exceptionWithConnection: self @@ -991,15 +991,15 @@ authTag = [OFXMLElement elementWithName: @"auth" namespace: XMPP_NS_SASL]; [authTag addAttributeWithName: @"mechanism" stringValue: authName]; if (initialMessage != nil) { - if ([initialMessage count] == 0) - [authTag setStringValue: @"="]; + if (initialMessage.count == 0) + authTag.stringValue = @"="; else - [authTag setStringValue: - [initialMessage stringByBase64Encoding]]; + authTag.stringValue = + initialMessage.stringByBase64Encoding; } [self sendStanza: authTag]; } @@ -1036,34 +1036,34 @@ [error setPrefix: @"stream" forNamespace: XMPP_NS_STREAM]; [error addChild: [OFXMLElement elementWithName: condition namespace: XMPP_NS_XMPP_STREAM]]; if (text) - [error addChild: [OFXMLElement + [error addChild: [OFXMLElement elementWithName: @"text" namespace: XMPP_NS_XMPP_STREAM stringValue: text]]; - [_parser setDelegate: nil]; + _parser.delegate = nil; [self sendStanza: error]; [self close]; } - (void)xmpp_handleResourceBindForConnection: (XMPPConnection *)connection IQ: (XMPPIQ *)IQ { OFXMLElement *bindElement, *JIDElement; - assert([[IQ type] isEqual: @"result"]); + assert([IQ.type isEqual: @"result"]); bindElement = [IQ elementForName: @"bind" namespace: XMPP_NS_BIND]; assert(bindElement != nil); JIDElement = [bindElement elementForName: @"jid" namespace: XMPP_NS_BIND]; - _JID = [[XMPPJID alloc] initWithString: [JIDElement stringValue]]; + _JID = [[XMPPJID alloc] initWithString: JIDElement.stringValue]; if (_needsSession) { [self xmpp_sendSession]; return; } @@ -1087,11 +1087,11 @@ } - (void)xmpp_handleSessionForConnection: (XMPPConnection *)connection IQ: (XMPPIQ *)IQ { - if (![[IQ type] isEqual: @"result"]) + if (![IQ.type isEqual: @"result"]) OF_ENSURE(0); [_delegates broadcastSelector: @selector(connection:wasBoundToJID:) withObject: self withObject: _JID]; @@ -1101,11 +1101,11 @@ { OFString *ret; char *cDomain; Idna_rc rc; - if ((rc = idna_to_ascii_8z([domain UTF8String], + if ((rc = idna_to_ascii_8z(domain.UTF8String, &cDomain, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS) @throw [XMPPIDNATranslationFailedException exceptionWithConnection: self operation: @"ToASCII" string: domain]; Index: src/XMPPContact+Private.h ================================================================== --- src/XMPPContact+Private.h +++ src/XMPPContact+Private.h @@ -1,13 +1,15 @@ #import "XMPPContact.h" OF_ASSUME_NONNULL_BEGIN @interface XMPPContact () -- (void)xmpp_setRosterItem: (XMPPRosterItem *)rosterItem; +@property (readwrite, nonatomic, setter=xmpp_setRosterItem:) + XMPPRosterItem *rosterItem; +@property OF_NULLABLE_PROPERTY (retain, nonatomic) XMPPJID *xmpp_lockedOnJID; + - (void)xmpp_setPresence: (XMPPPresence *)presence resource: (OFString *)resource; - (void)xmpp_removePresenceForResource: (OFString *)resource; -- (void)xmpp_setLockedOnJID: (nullable XMPPJID *)JID; @end OF_ASSUME_NONNULL_END Index: src/XMPPContact.m ================================================================== --- src/XMPPContact.m +++ src/XMPPContact.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -55,13 +55,13 @@ - (void)sendMessage: (XMPPMessage *)message connection: (XMPPConnection *)connection { if (_lockedOnJID == nil) - [message setTo: [_rosterItem JID]]; + message.to = _rosterItem.JID; else - [message setTo: _lockedOnJID]; + message.to = _lockedOnJID; [connection sendStanza: message]; } - (void)xmpp_setRosterItem: (XMPPRosterItem *)rosterItem @@ -79,11 +79,11 @@ forKey: resource]; else [_presences setObject: presence forKey: @""]; - [self xmpp_setLockedOnJID: nil]; + self.xmpp_lockedOnJID = nil; } - (void)xmpp_removePresenceForResource: (OFString *)resource { if (resource != nil) { @@ -91,15 +91,15 @@ } else { [_presences release]; _presences = [[OFMutableDictionary alloc] init]; } - [self xmpp_setLockedOnJID: nil]; + self.xmpp_lockedOnJID = nil; } - (void)xmpp_setLockedOnJID: (XMPPJID *)JID; { XMPPJID *old = _lockedOnJID; _lockedOnJID = [JID retain]; [old release]; } @end Index: src/XMPPContactManager.m ================================================================== --- src/XMPPContactManager.m +++ src/XMPPContactManager.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -65,19 +65,19 @@ - (void)sendSubscribedToJID: (XMPPJID *)subscriber { XMPPPresence *presence = [XMPPPresence presenceWithType: @"subscribed"]; - [presence setTo: subscriber]; + presence.to = subscriber; [_connection sendStanza: presence]; } - (void)sendUnsubscribedToJID: (XMPPJID *)subscriber { XMPPPresence *presence = [XMPPPresence presenceWithType: @"unsubscribed"]; - [presence setTo: subscriber]; + presence.to = subscriber; [_connection sendStanza: presence]; } - (void)addDelegate: (id )delegate { @@ -101,15 +101,14 @@ [_contacts release]; _contacts = nil; _contacts = [[OFMutableDictionary alloc] init]; - rosterItems = [roster rosterItems]; + rosterItems = roster.rosterItems; for (OFString *bareJID in rosterItems) { XMPPContact *contact = [[[XMPPContact alloc] init] autorelease]; - [contact xmpp_setRosterItem: - [rosterItems objectForKey: bareJID]]; + contact.rosterItem = [rosterItems objectForKey: bareJID]; [_contacts setObject: contact forKey: bareJID]; [_delegates broadcastSelector: @selector(contactManager: didAddContact:) withObject: self @@ -119,15 +118,15 @@ - (void)roster: (XMPPRoster *)roster didReceiveRosterItem: (XMPPRosterItem *)rosterItem { XMPPContact *contact; - OFString *bareJID = [[rosterItem JID] bareJID]; + OFString *bareJID = rosterItem.JID.bareJID; contact = [_contacts objectForKey: bareJID]; - if ([[rosterItem subscription] isEqual: @"remove"]) { + if ([rosterItem.subscription isEqual: @"remove"]) { if (contact != nil) [_delegates broadcastSelector: @selector(contactManager: didRemoveContact:) withObject: self withObject: contact]; @@ -135,11 +134,11 @@ return; } if (contact == nil) { contact = [[[XMPPContact alloc] init] autorelease]; - [contact xmpp_setRosterItem: rosterItem]; + contact.rosterItem = rosterItem; [_contacts setObject: contact forKey: bareJID]; [_delegates broadcastSelector: @selector(contactManager: didAddContact:) withObject: self @@ -147,20 +146,20 @@ } else { [_delegates broadcastSelector: @selector(contact: willUpdateWithRosterItem:) withObject: contact withObject: rosterItem]; - [contact xmpp_setRosterItem: rosterItem]; + contact.rosterItem = rosterItem; } } - (void)connection: (XMPPConnection *)connection didReceivePresence: (XMPPPresence *)presence { XMPPContact *contact; - XMPPJID *JID = [presence from]; - OFString *type = [presence type]; + XMPPJID *JID = presence.from; + OFString *type = presence.type; /* Subscription request */ if ([type isEqual: @"subscribe"]) { of_log(@"ObjXMPP: received subscription request"); [_delegates broadcastSelector: @selector(contactManager: @@ -168,28 +167,28 @@ withObject: self withObject: presence]; return; } - contact = [_contacts objectForKey: [JID bareJID]]; + contact = [_contacts objectForKey: JID.bareJID]; if (contact == nil) return; /* Available presence */ if ([type isEqual: @"available"]) { [contact xmpp_setPresence: presence - resource: [JID resource]]; + resource: JID.resource]; [_delegates broadcastSelector: @selector(contact: didSendPresence:) withObject: contact withObject: presence]; return; } /* Unavailable presence */ if ([type isEqual: @"unavailable"]) { - [contact xmpp_removePresenceForResource: [JID resource]]; + [contact xmpp_removePresenceForResource: JID.resource]; [_delegates broadcastSelector: @selector(contact: didSendPresence:) withObject: contact withObject: presence]; return; @@ -197,18 +196,18 @@ } - (void)connection: (XMPPConnection *)connection didReceiveMessage: (XMPPMessage *)message { - XMPPJID *JID = [message from]; - XMPPContact *contact = [_contacts objectForKey: [JID bareJID]]; + XMPPJID *JID = message.from; + XMPPContact *contact = [_contacts objectForKey: JID.bareJID]; if (contact == nil) return; - [contact xmpp_setLockedOnJID: JID]; + contact.xmpp_lockedOnJID = JID; [_delegates broadcastSelector: @selector(contact:didSendMessage:) withObject: contact withObject: message]; } @end Index: src/XMPPDiscoEntity.m ================================================================== --- src/XMPPDiscoEntity.m +++ src/XMPPDiscoEntity.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -106,33 +106,33 @@ } - (void)addDiscoNode: (XMPPDiscoNode *)node { [_discoNodes setObject: node - forKey: [node node]]; + forKey: node.node]; } - (OFString *)capsHash { OFMutableString *caps = [OFMutableString string]; OFSHA1Hash *hash = [OFSHA1Hash cryptoHash]; OFData *digest; for (XMPPDiscoIdentity *identity in _identities) - [caps appendFormat: @"%@/%@//%@<", [identity category], - [identity type], [identity name]]; + [caps appendFormat: @"%@/%@//%@<", + identity.category, identity.type, identity.name]; for (OFString *feature in _features) [caps appendFormat: @"%@<", feature]; - [hash updateWithBuffer: [caps UTF8String] - length: [caps UTF8StringLength]]; + [hash updateWithBuffer: caps.UTF8String + length: caps.UTF8StringLength]; - digest = [OFData dataWithItems: [hash digest] - count: [[hash class] digestSize]]; + digest = [OFData dataWithItems: hash.digest + count: hash.digestSize]; - return [digest stringByBase64Encoding]; + return digest.stringByBase64Encoding; } - (void)connection: (XMPPConnection *)connection wasBoundToJID: (XMPPJID *)JID { @@ -140,19 +140,18 @@ } - (bool)connection: (XMPPConnection *)connection didReceiveIQ: (XMPPIQ *)IQ { - if (![[IQ to] isEqual: _JID]) + if (![IQ.to isEqual: _JID]) return false; OFXMLElement *query = [IQ elementForName: @"query" namespace: XMPP_NS_DISCO_ITEMS]; if (query != nil) { - OFString *node = - [[query attributeForName: @"node"] stringValue]; + OFString *node = [query attributeForName: @"node"].stringValue; if (node == nil) return [self xmpp_handleItemsIQ: IQ connection: connection]; XMPPDiscoNode *responder = [_discoNodes objectForKey: node]; @@ -165,19 +164,18 @@ query = [IQ elementForName: @"query" namespace: XMPP_NS_DISCO_INFO]; if (query != nil) { - OFString *node = - [[query attributeForName: @"node"] stringValue]; + OFString *node = [query attributeForName: @"node"].stringValue; if (node == nil) return [self xmpp_handleInfoIQ: IQ connection: connection]; - OFString *capsNode = [_capsNode stringByAppendingFormat: @"#%@", - [self capsHash]]; + OFString *capsNode = + [_capsNode stringByAppendingFormat: @"#%@", self.capsHash]; if ([capsNode isEqual: node]) return [self xmpp_handleInfoIQ: IQ connection: connection]; XMPPDiscoNode *responder = [_discoNodes objectForKey: node]; Index: src/XMPPDiscoIdentity.m ================================================================== --- src/XMPPDiscoIdentity.m +++ src/XMPPDiscoIdentity.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -50,13 +50,13 @@ @try { if (category == nil || type == nil) @throw [OFInvalidArgumentException exception]; - _category = [category copy]; - _name = [name copy]; - _type = [type copy]; + _category = category.copy; + _name = name.copy; + _type = type.copy; } @catch (id e) { [self release]; @throw e; } @@ -109,13 +109,13 @@ { uint32_t hash; OF_HASH_INIT(hash); - OF_HASH_ADD_HASH(hash, [_category hash]); - OF_HASH_ADD_HASH(hash, [_type hash]); - OF_HASH_ADD_HASH(hash, [_name hash]); + OF_HASH_ADD_HASH(hash, _category.hash); + OF_HASH_ADD_HASH(hash, _type.hash); + OF_HASH_ADD_HASH(hash, _name.hash); OF_HASH_FINALIZE(hash); return hash; } Index: src/XMPPDiscoNode.m ================================================================== --- src/XMPPDiscoNode.m +++ src/XMPPDiscoNode.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -115,11 +115,11 @@ } - (void)addChildNode: (XMPPDiscoNode *)node { [_childNodes setObject: node - forKey: [node node]]; + forKey: node.node]; } - (bool)xmpp_handleItemsIQ: (XMPPIQ *)IQ connection: (XMPPConnection *)connection { @@ -141,17 +141,17 @@ OFXMLElement *item = [OFXMLElement elementWithName: @"item" namespace: XMPP_NS_DISCO_ITEMS]; [item addAttributeWithName: @"jid" - stringValue: [[child JID] fullJID]]; - if ([child node] != nil) + stringValue: child.JID.fullJID]; + if (child.node != nil) [item addAttributeWithName: @"node" - stringValue: [child node]]; - if ([child name] != nil) + stringValue: child.node]; + if (child.name != nil) [item addAttributeWithName: @"name" - stringValue: [child name]]; + stringValue: child.name]; [response addChild: item]; } [connection sendStanza: resultIQ]; @@ -174,16 +174,16 @@ OFXMLElement *identityElement = [OFXMLElement elementWithName: @"identity" namespace: XMPP_NS_DISCO_INFO]; [identityElement addAttributeWithName: @"category" - stringValue: [identity category]]; + stringValue: identity.category]; [identityElement addAttributeWithName: @"type" - stringValue: [identity type]]; - if ([identity name] != nil) + stringValue: identity.type]; + if (identity.name != nil) [identityElement addAttributeWithName: @"name" - stringValue: [identity name]]; + stringValue: identity.name]; [response addChild: identityElement]; } for (OFString *feature in _features) { Index: src/XMPPEXTERNALAuth.m ================================================================== --- src/XMPPEXTERNALAuth.m +++ src/XMPPEXTERNALAuth.m @@ -1,7 +1,8 @@ /* * Copyright (c) 2012, Florian Zeitz + * Copyright (c) 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -42,13 +43,13 @@ { OFMutableData *message = [OFMutableData data]; /* authzid */ if (_authzid != nil) - [message addItems: [_authzid UTF8String] - count: [_authzid UTF8StringLength]]; + [message addItems: _authzid.UTF8String + count: _authzid.UTF8StringLength]; [message makeImmutable]; return message; } @end Index: src/XMPPFileStorage.m ================================================================== --- src/XMPPFileStorage.m +++ src/XMPPFileStorage.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2012, Jonathan Schleifer + * Copyright (c) 2012, 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -48,12 +48,12 @@ @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; _file = [file copy]; @try { - _data = [[[OFData dataWithContentsOfFile: file] - messagePackValue] retain]; + _data = [[OFData dataWithContentsOfFile: file] + .messagePackValue copy]; } @catch (id e) { _data = [[OFMutableDictionary alloc] init]; } [pool release]; @@ -73,19 +73,19 @@ [super dealloc]; } - (void)save { - [[_data messagePackRepresentation] writeToFile: _file]; + [_data.messagePackRepresentation writeToFile: _file]; } - (void)xmpp_setObject: (id)object forPath: (OFString *)path { OFArray *pathComponents = [path componentsSeparatedByString: @"."]; OFMutableDictionary *iter = _data; - size_t i = 0, components = [pathComponents count]; + size_t i = 0, components = pathComponents.count; for (OFString *component in pathComponents) { if (i++ == components - 1) continue; @@ -102,11 +102,11 @@ if (object != nil) [iter setObject: object forKey: [pathComponents lastObject]]; else - [iter removeObjectForKey: [pathComponents lastObject]]; + [iter removeObjectForKey: pathComponents.lastObject]; } - (id)xmpp_objectForPath: (OFString *)path { id object = _data; Index: src/XMPPIQ.m ================================================================== --- src/XMPPIQ.m +++ src/XMPPIQ.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, Jonathan Schleifer + * Copyright (c) 2011, 2019, Jonathan Schleifer * Copyright (c) 2011, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -54,22 +54,22 @@ } - (XMPPIQ *)resultIQ { XMPPIQ *ret = [XMPPIQ IQWithType: @"result" - ID: [self ID]]; - [ret setTo: [self from]]; - [ret setFrom: nil]; + ID: self.ID]; + ret.to = self.from; + ret.from = nil; return ret; } - (XMPPIQ *)errorIQWithType: (OFString *)type condition: (OFString *)condition text: (OFString *)text { XMPPIQ *ret = [XMPPIQ IQWithType: @"error" - ID: [self ID]]; + ID: self.ID]; void *pool = objc_autoreleasePoolPush(); OFXMLElement *error = [OFXMLElement elementWithName: @"error" namespace: XMPP_NS_CLIENT]; [error addAttributeWithName: @"type" @@ -79,12 +79,12 @@ if (text) [error addChild: [OFXMLElement elementWithName: @"text" namespace: XMPP_NS_STANZAS stringValue: text]]; [ret addChild: error]; - [ret setTo: [self from]]; - [ret setFrom: nil]; + ret.to = self.from; + ret.from = nil; objc_autoreleasePoolPop(pool); return ret; } Index: src/XMPPJID.m ================================================================== --- src/XMPPJID.m +++ src/XMPPJID.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2012, 2013, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2019, Jonathan Schleifer * Copyright (c) 2011, 2012, 2013, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -43,39 +43,42 @@ return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { - size_t nodesep, resourcesep; - self = [super init]; - if (string == nil) { + @try { + size_t nodesep, resourcesep; + + if (string == nil) + @throw [OFInvalidArgumentException exception]; + + nodesep = [string rangeOfString: @"@"].location; + resourcesep = [string rangeOfString: @"/"].location; + + if (nodesep == SIZE_MAX) + self.node = nil; + else + self.node = + [string substringWithRange: of_range(0, nodesep)]; + + if (resourcesep == SIZE_MAX) { + self.resource = nil; + resourcesep = string.length; + } else { + of_range_t range = of_range(resourcesep + 1, + string.length - resourcesep - 1); + self.resource = [string substringWithRange: range]; + } + + self.domain = [string substringWithRange: + of_range(nodesep + 1, resourcesep - nodesep - 1)]; + } @catch (id e) { [self release]; - return nil; - } - - nodesep = [string rangeOfString: @"@"].location; - resourcesep = [string rangeOfString: @"/"].location; - - if (nodesep == SIZE_MAX) - [self setNode: nil]; - else - [self setNode: - [string substringWithRange: of_range(0, nodesep)]]; - - if (resourcesep == SIZE_MAX) { - [self setResource: nil]; - resourcesep = [string length]; - } else { - of_range_t range = of_range(resourcesep + 1, - [string length] - resourcesep - 1); - [self setResource: [string substringWithRange: range]]; - } - - [self setDomain: [string substringWithRange: - of_range(nodesep + 1, resourcesep - nodesep - 1)]]; + @throw e; + } return self; } - (void)dealloc @@ -113,11 +116,11 @@ [old release]; _node = nil; return; } - if (((rc = stringprep_profile([node UTF8String], &nodepart, + if (((rc = stringprep_profile(node.UTF8String, &nodepart, "Nodeprep", 0)) != STRINGPREP_OK) || (nodepart[0] == '\0') || (strlen(nodepart) > 1023)) @throw [XMPPStringPrepFailedException exceptionWithConnection: nil profile: @"Nodeprep" @@ -136,11 +139,11 @@ { OFString *old = _domain; char *srv; Stringprep_rc rc; - if (((rc = stringprep_profile([domain UTF8String], &srv, + if (((rc = stringprep_profile(domain.UTF8String, &srv, "Nameprep", 0)) != STRINGPREP_OK) || (srv[0] == '\0') || (strlen(srv) > 1023)) @throw [XMPPStringPrepFailedException exceptionWithConnection: nil profile: @"Nameprep" @@ -165,11 +168,11 @@ [old release]; _resource = nil; return; } - if (((rc = stringprep_profile([resource UTF8String], &res, + if (((rc = stringprep_profile(resource.UTF8String, &res, "Resourceprep", 0)) != STRINGPREP_OK) || (res[0] == '\0') || (strlen(res) > 1023)) @throw [XMPPStringPrepFailedException exceptionWithConnection: nil profile: @"Resourceprep" @@ -194,18 +197,18 @@ - (OFString *)fullJID { /* If we don't have a resource, the full JID is equal to the bare JID */ if (_resource == nil) - return [self bareJID]; + return self.bareJID; if (_node != nil) return [OFString stringWithFormat: @"%@@%@/%@", - _node, _domain, _resource]; + _node, _domain, _resource]; else return [OFString stringWithFormat: @"%@/%@", - _domain, _resource]; + _domain, _resource]; } - (OFString *)description { return [self fullJID]; @@ -236,14 +239,14 @@ { uint32_t hash; OF_HASH_INIT(hash); - OF_HASH_ADD_HASH(hash, [_node hash]); - OF_HASH_ADD_HASH(hash, [_domain hash]); - OF_HASH_ADD_HASH(hash, [_resource hash]); + OF_HASH_ADD_HASH(hash, _node.hash); + OF_HASH_ADD_HASH(hash, _domain.hash); + OF_HASH_ADD_HASH(hash, _resource.hash); OF_HASH_FINALIZE(hash); return hash; } @end Index: src/XMPPMessage.m ================================================================== --- src/XMPPMessage.m +++ src/XMPPMessage.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2012, 2013, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2019, Jonathan Schleifer * Copyright (c) 2011, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -89,9 +89,9 @@ stringValue: body]]; } - (OFString *)body { - return [[self elementForName: @"body" - namespace: XMPP_NS_CLIENT] stringValue]; + return [self elementForName: @"body" + namespace: XMPP_NS_CLIENT].stringValue; } @end Index: src/XMPPMulticastDelegate.m ================================================================== --- src/XMPPMulticastDelegate.m +++ src/XMPPMulticastDelegate.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2012, Jonathan Schleifer + * Copyright (c) 2012, 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -55,12 +55,12 @@ [_delegates addItem: &delegate]; } - (void)removeDelegate: (id)delegate { - id *items = [_delegates items]; - size_t i, count = [_delegates count]; + id const *items = _delegates.items; + size_t i, count = _delegates.count; for (i = 0; i < count; i++) { if (items[i] != delegate) continue; @@ -72,12 +72,12 @@ - (bool)broadcastSelector: (SEL)selector withObject: (id)object { void *pool = objc_autoreleasePoolPush(); OFMutableData *currentDelegates = [[_delegates copy] autorelease]; - id *items = [currentDelegates items]; - size_t i, count = [currentDelegates count]; + id const *items = currentDelegates.items; + size_t i, count = currentDelegates.count; bool handled = false; for (i = 0; i < count; i++) { id responder = items[i]; @@ -99,12 +99,12 @@ withObject: (id)object1 withObject: (id)object2 { void *pool = objc_autoreleasePoolPush(); OFMutableData *currentDelegates = [[_delegates copy] autorelease]; - id *items = [currentDelegates items]; - size_t i, count = [currentDelegates count]; + id const *items = currentDelegates.items; + size_t i, count = currentDelegates.count; bool handled = false; for (i = 0; i < count; i++) { id responder = items[i]; Index: src/XMPPPLAINAuth.m ================================================================== --- src/XMPPPLAINAuth.m +++ src/XMPPPLAINAuth.m @@ -1,7 +1,8 @@ /* * Copyright (c) 2011, Florian Zeitz + * Copyright (c) 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -46,27 +47,27 @@ { OFMutableData *message = [OFMutableData data]; /* authzid */ if (_authzid != nil) - [message addItems: [_authzid UTF8String] - count: [_authzid UTF8StringLength]]; + [message addItems: _authzid.UTF8String + count: _authzid.UTF8StringLength]; /* separator */ [message addItem: ""]; /* authcid */ - [message addItems: [_authcid UTF8String] - count: [_authcid UTF8StringLength]]; + [message addItems: _authcid.UTF8String + count: _authcid.UTF8StringLength]; /* separator */ [message addItem: ""]; /* passwd */ - [message addItems: [_password UTF8String] - count: [_password UTF8StringLength]]; + [message addItems: _password.UTF8String + count: _password.UTF8StringLength]; [message makeImmutable]; return message; } @end Index: src/XMPPPresence.m ================================================================== --- src/XMPPPresence.m +++ src/XMPPPresence.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2012, 2013, 2016, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2016, 2019, Jonathan Schleifer * Copyright (c) 2011, 2012, 2013, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -28,11 +28,11 @@ #import "XMPPPresence.h" #import "namespaces.h" /* This provides us with sortable values for show values */ static int -show_to_int(OFString *show) +showToInt(OFString *show) { if ([show isEqual: @"chat"]) return 0; if (show == nil) return 1; /* available */ @@ -104,21 +104,20 @@ @try { OFXMLElement *subElement; if ((subElement = [element elementForName: @"show" namespace: XMPP_NS_CLIENT])) - [self setShow: [subElement stringValue]]; + self.show = subElement.stringValue; if ((subElement = [element elementForName: @"status" namespace: XMPP_NS_CLIENT])) - [self setStatus: [subElement stringValue]]; + self.status = subElement.stringValue; if ((subElement = [element elementForName: @"priority" namespace: XMPP_NS_CLIENT])) - [self setPriority: - [OFNumber numberWithIntMax: - [[subElement stringValue] decimalValue]]]; + self.priority = [OFNumber + numberWithIntMax: subElement.decimalValue]; } @catch (id e) { [self release]; @throw e; } @@ -172,11 +171,11 @@ [old release]; } - (void)setPriority: (OFNumber *)priority { - intmax_t prio = [priority intMaxValue]; + intmax_t prio = priority.intMaxValue; OFNumber *old; if ((prio < -128) || (prio > 127)) @throw [OFInvalidArgumentException exception]; @@ -185,11 +184,11 @@ if (oldPriority != nil) [self removeChild: oldPriority]; OFString *priority_s = - [OFString stringWithFormat: @"%" @PRId8, [priority int8Value]]; + [OFString stringWithFormat: @"%" @PRId8, priority.int8Value]; [self addChild: [OFXMLElement elementWithName: @"priority" namespace: XMPP_NS_CLIENT stringValue: priority_s]]; old = _priority; @@ -209,11 +208,11 @@ if (![(id)object isKindOfClass: [XMPPPresence class]]) @throw [OFInvalidArgumentException exception]; otherPresence = (XMPPPresence *)object; - otherPriority = [otherPresence priority]; + otherPriority = otherPresence.priority; if (otherPriority == nil) otherPriority = [OFNumber numberWithInt8: 0]; if (_priority != nil) priorityOrder = [_priority compare: otherPriority]; @@ -222,15 +221,15 @@ [[OFNumber numberWithInt8: 0] compare: otherPriority]; if (priorityOrder != OF_ORDERED_SAME) return priorityOrder; - otherShow = [otherPresence show]; + otherShow = otherPresence.show; if ([_show isEqual: otherShow]) return OF_ORDERED_SAME; - if (show_to_int(_show) < show_to_int(otherShow)) + if (showToInt(_show) < showToInt(otherShow)) return OF_ORDERED_ASCENDING; return OF_ORDERED_DESCENDING; } @end Index: src/XMPPRoster.m ================================================================== --- src/XMPPRoster.m +++ src/XMPPRoster.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2012, 2013, 2016, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2016, 2019, Jonathan Schleifer * Copyright (c) 2012, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -64,11 +64,11 @@ @try { _rosterItems = [[OFMutableDictionary alloc] init]; _connection = connection; [_connection addDelegate: self]; _delegates = [[XMPPMulticastDelegate alloc] init]; - _dataStorage = [_connection dataStorage]; + _dataStorage = _connection.dataStorage; } @catch (id e) { [self release]; @throw e; } @@ -84,22 +84,22 @@ [super dealloc]; } - (void)requestRoster { - XMPPIQ *iq; + XMPPIQ *IQ; OFXMLElement *query; _rosterRequested = true; - iq = [XMPPIQ IQWithType: @"get" + IQ = [XMPPIQ IQWithType: @"get" ID: [_connection generateStanzaID]]; query = [OFXMLElement elementWithName: @"query" namespace: XMPP_NS_ROSTER]; - if ([_connection supportsRosterVersioning]) { + if (_connection.supportsRosterVersioning) { OFString *ver = [_dataStorage stringValueForPath: @"roster.ver"]; if (ver == nil) ver = @""; @@ -106,13 +106,13 @@ [query addAttributeWithName: @"ver" stringValue: ver]; } - [iq addChild: query]; + [IQ addChild: query]; - [_connection sendIQ: iq + [_connection sendIQ: IQ callbackTarget: self selector: @selector(xmpp_handleInitialRosterForConnection: IQ:)]; } @@ -128,16 +128,16 @@ namespace: XMPP_NS_ROSTER]; if (rosterElement == nil) return false; - if (![[IQ type] isEqual: @"set"]) + if (![IQ.type isEqual: @"set"]) return false; // Ensure the roster push has been sent by the server - origin = [[IQ from] fullJID]; - if (origin != nil && ![origin isEqual: [[connection JID] bareJID]]) + origin = IQ.from.fullJID; + if (origin != nil && ![origin isEqual: connection.JID.bareJID]) return false; element = [rosterElement elementForName: @"item" namespace: XMPP_NS_ROSTER]; @@ -150,13 +150,13 @@ withObject: rosterItem]; [self xmpp_updateRosterItem: rosterItem]; } - if ([_connection supportsRosterVersioning]) { + if (_connection.supportsRosterVersioning) { OFString *ver = - [[rosterElement attributeForName: @"ver"] stringValue]; + [rosterElement attributeForName: @"ver"].stringValue; [_dataStorage setStringValue: ver forPath: @"roster.ver"]; [_dataStorage save]; } @@ -178,16 +178,16 @@ namespace: XMPP_NS_ROSTER]; OFXMLElement *item = [OFXMLElement elementWithName: @"item" namespace: XMPP_NS_ROSTER]; [item addAttributeWithName: @"jid" - stringValue: [[rosterItem JID] bareJID]]; - if ([rosterItem name] != nil) + stringValue: rosterItem.JID.bareJID]; + if (rosterItem.name != nil) [item addAttributeWithName: @"name" - stringValue: [rosterItem name]]; + stringValue: rosterItem.name]; - for (OFString *group in [rosterItem groups]) + for (OFString *group in rosterItem.groups) [item addChild: [OFXMLElement elementWithName: @"group" namespace: XMPP_NS_ROSTER stringValue: group]]; [query addChild: item]; @@ -204,11 +204,11 @@ namespace: XMPP_NS_ROSTER]; OFXMLElement *item = [OFXMLElement elementWithName: @"item" namespace: XMPP_NS_ROSTER]; [item addAttributeWithName: @"jid" - stringValue: [[rosterItem JID] bareJID]]; + stringValue: rosterItem.JID.bareJID]; [item addAttributeWithName: @"subscription" stringValue: @"remove"]; [query addChild: item]; [IQ addChild: query]; @@ -235,77 +235,75 @@ _dataStorage = dataStorage; } - (void)xmpp_updateRosterItem: (XMPPRosterItem *)rosterItem { - if ([_connection supportsRosterVersioning]) { + if (_connection.supportsRosterVersioning) { OFMutableDictionary *items = [[[_dataStorage dictionaryForPath: @"roster.items"] mutableCopy] autorelease]; if (items == nil) items = [OFMutableDictionary dictionary]; - if (![[rosterItem subscription] isEqual: @"remove"]) { + if (![rosterItem.subscription isEqual: @"remove"]) { OFMutableDictionary *item = [OFMutableDictionary dictionaryWithKeysAndObjects: - @"JID", [[rosterItem JID] bareJID], - @"subscription", [rosterItem subscription], + @"JID", rosterItem.JID.bareJID, + @"subscription", rosterItem.subscription, nil]; - if ([rosterItem name] != nil) - [item setObject: [rosterItem name] + if (rosterItem.name != nil) + [item setObject: rosterItem.name forKey: @"name"]; if ([rosterItem groups] != nil) - [item setObject: [rosterItem groups] + [item setObject: rosterItem.groups forKey: @"groups"]; [items setObject: item - forKey: [[rosterItem JID] bareJID]]; + forKey: rosterItem.JID.bareJID]; } else - [items removeObjectForKey: [[rosterItem JID] bareJID]]; + [items removeObjectForKey: rosterItem.JID.bareJID]; [_dataStorage setDictionary: items forPath: @"roster.items"]; } - if (![[rosterItem subscription] isEqual: @"remove"]) + if (![rosterItem.subscription isEqual: @"remove"]) [_rosterItems setObject: rosterItem - forKey: [[rosterItem JID] bareJID]]; + forKey: rosterItem.JID.bareJID]; else - [_rosterItems removeObjectForKey: [[rosterItem JID] bareJID]]; + [_rosterItems removeObjectForKey: rosterItem.JID.bareJID]; } - (XMPPRosterItem *)xmpp_rosterItemWithXMLElement: (OFXMLElement *)element { OFString *subscription; OFMutableArray *groups = [OFMutableArray array]; XMPPRosterItem *rosterItem = [XMPPRosterItem rosterItem]; - [rosterItem setJID: [XMPPJID JIDWithString: - [[element attributeForName: @"jid"] stringValue]]]; - [rosterItem setName: - [[element attributeForName: @"name"] stringValue]]; + rosterItem.JID = [XMPPJID JIDWithString: + [element attributeForName: @"jid"].stringValue]; + rosterItem.name = [element attributeForName: @"name"].stringValue; - subscription = [[element attributeForName: - @"subscription"] stringValue]; + subscription = [element attributeForName: @"subscription"].stringValue; if (![subscription isEqual: @"none"] && ![subscription isEqual: @"to"] && ![subscription isEqual: @"from"] && ![subscription isEqual: @"both"] && ![subscription isEqual: @"remove"]) subscription = @"none"; - [rosterItem setSubscription: subscription]; + rosterItem.subscription = subscription; for (OFXMLElement *groupElement in [element elementsForName: @"group" namespace: XMPP_NS_ROSTER]) - [groups addObject: [groupElement stringValue]]; + [groups addObject: groupElement.stringValue]; - if ([groups count] > 0) - [rosterItem setGroups: groups]; + if (groups.count > 0) + rosterItem.groups = groups; return rosterItem; } - (void)xmpp_handleInitialRosterForConnection: (XMPPConnection *)connection @@ -312,58 +310,57 @@ IQ: (XMPPIQ *)IQ { OFXMLElement *rosterElement = [IQ elementForName: @"query" namespace: XMPP_NS_ROSTER]; - if ([connection supportsRosterVersioning]) { + if (connection.supportsRosterVersioning) { if (rosterElement == nil) { for (OFDictionary *item in [_dataStorage dictionaryForPath: @"roster.items"]) { XMPPRosterItem *rosterItem; XMPPJID *JID; rosterItem = [XMPPRosterItem rosterItem]; JID = [XMPPJID JIDWithString: - [item objectForKey: @"JID"]]; - [rosterItem setJID: JID]; - [rosterItem setName: - [item objectForKey: @"name"]]; - [rosterItem setSubscription: - [item objectForKey: @"subscription"]]; - [rosterItem setGroups: - [item objectForKey: @"groups"]]; + [item objectForKey: @"JID"]]; + rosterItem.JID = JID; + rosterItem.name = [item objectForKey: @"name"]; + rosterItem.subscription = + [item objectForKey: @"subscription"]; + rosterItem.groups = + [item objectForKey: @"groups"]; [_rosterItems setObject: rosterItem - forKey: [JID bareJID]]; + forKey: JID.bareJID]; } } else [_dataStorage setDictionary: nil forPath: @"roster.items"]; } - for (OFXMLElement *element in [rosterElement children]) { + for (OFXMLElement *element in rosterElement.children) { void *pool = objc_autoreleasePoolPush(); XMPPRosterItem *rosterItem; - if (![[element name] isEqual: @"item"] || - ![[element namespace] isEqual: XMPP_NS_ROSTER]) + if (![element.name isEqual: @"item"] || + ![element.namespace isEqual: XMPP_NS_ROSTER]) continue; rosterItem = [self xmpp_rosterItemWithXMLElement: element]; [self xmpp_updateRosterItem: rosterItem]; objc_autoreleasePoolPop(pool); } - if ([connection supportsRosterVersioning] && rosterElement != nil) { + if (connection.supportsRosterVersioning && rosterElement != nil) { OFString *ver = - [[rosterElement attributeForName: @"ver"] stringValue]; + [rosterElement attributeForName: @"ver"].stringValue; [_dataStorage setStringValue: ver forPath: @"roster.ver"]; [_dataStorage save]; } [_delegates broadcastSelector: @selector(rosterWasReceived:) withObject: self]; } @end Index: src/XMPPSCRAMAuth.m ================================================================== --- src/XMPPSCRAMAuth.m +++ src/XMPPSCRAMAuth.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2011, Florian Zeitz - * Copyright (c) 2011, Jonathan Schleifer + * Copyright (c) 2011, 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -139,11 +139,12 @@ OFMutableString *new = [[authzid mutableCopy] autorelease]; [new replaceOccurrencesOfString: @"=" withString: @"=3D"]; [new replaceOccurrencesOfString: @"," withString: @"=2C"]; - _authzid = [new retain]; + [new makeImmutable]; + _authzid = [new copy]; } else _authzid = nil; [old release]; } @@ -156,11 +157,12 @@ OFMutableString *new = [[authcid mutableCopy] autorelease]; [new replaceOccurrencesOfString: @"=" withString: @"=3D"]; [new replaceOccurrencesOfString: @"," withString: @"=2C"]; - _authcid = [new retain]; + [new makeImmutable]; + _authcid = [new copy]; } else _authcid = nil; [old release]; } @@ -191,15 +193,15 @@ [_clientFirstMessageBare release]; _clientFirstMessageBare = nil; _clientFirstMessageBare = [[OFString alloc] initWithFormat: @"n=%@,r=%@", _authcid, _cNonce]; - [ret addItems: [_GS2Header UTF8String] - count: [_GS2Header UTF8StringLength]]; + [ret addItems: _GS2Header.UTF8String + count: _GS2Header.UTF8StringLength]; - [ret addItems: [_clientFirstMessageBare UTF8String] - count: [_clientFirstMessageBare UTF8StringLength]]; + [ret addItems: _clientFirstMessageBare.UTF8String + count: _clientFirstMessageBare.UTF8StringLength]; [ret makeImmutable]; return ret; } @@ -237,18 +239,18 @@ hash = [[[_hashType alloc] init] autorelease]; ret = [OFMutableData data]; authMessage = [OFMutableData data]; - OFString *challenge = [OFString stringWithUTF8String: [data items] - length: [data count] * - [data itemSize]]; + OFString *challenge = [OFString stringWithUTF8String: data.items + length: data.count * + data.itemSize]; for (OFString *component in [challenge componentsSeparatedByString: @","]) { OFString *entry = [component substringWithRange: - of_range(2, [component length] - 2)]; + of_range(2, component.length - 2)]; if ([component hasPrefix: @"r="]) { if (![entry hasPrefix: _cNonce]) @throw [XMPPAuthFailedException exceptionWithConnection: nil @@ -259,46 +261,46 @@ got |= GOT_SNONCE; } else if ([component hasPrefix: @"s="]) { salt = [OFData dataWithBase64EncodedString: entry]; got |= GOT_SALT; } else if ([component hasPrefix: @"i="]) { - iterCount = [entry decimalValue]; + iterCount = entry.decimalValue; got |= GOT_ITERCOUNT; } } if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT)) @throw [OFInvalidServerReplyException exception]; // Add c= - tmpArray = [OFMutableData dataWithItems: [_GS2Header UTF8String] - count: [_GS2Header UTF8StringLength]]; - if (_plusAvailable && [_connection encrypted]) { + tmpArray = [OFMutableData dataWithItems: _GS2Header.UTF8String + count: _GS2Header.UTF8StringLength]; + if (_plusAvailable && _connection.encrypted) { OFData *channelBinding = [((SSLSocket *)[_connection socket]) channelBindingDataWithType: @"tls-unique"]; - [tmpArray addItems: [channelBinding items] - count: [channelBinding count]]; + [tmpArray addItems: channelBinding.items + count: channelBinding.count]; } - tmpString = [tmpArray stringByBase64Encoding]; + tmpString = tmpArray.stringByBase64Encoding; [ret addItems: "c=" count: 2]; - [ret addItems: [tmpString UTF8String] - count: [tmpString UTF8StringLength]]; + [ret addItems: tmpString.UTF8String + count: tmpString.UTF8StringLength]; // Add r= [ret addItem: ","]; [ret addItems: "r=" count: 2]; - [ret addItems: [sNonce UTF8String] - count: [sNonce UTF8StringLength]]; + [ret addItems: sNonce.UTF8String + count: sNonce.UTF8StringLength]; /* * IETF RFC 5802: * SaltedPassword := Hi(Normalize(password), salt, i) */ - tmpArray = [OFMutableData dataWithItems: [_password UTF8String] - count: [_password UTF8StringLength]]; + tmpArray = [OFMutableData dataWithItems: _password.UTF8String + count: _password.UTF8StringLength]; saltedPassword = [self xmpp_hiWithData: tmpArray salt: salt iterationCount: iterCount]; /* @@ -305,18 +307,18 @@ * IETF RFC 5802: * AuthMessage := client-first-message-bare + "," + * server-first-message + "," + * client-final-message-without-proof */ - [authMessage addItems: [_clientFirstMessageBare UTF8String] - count: [_clientFirstMessageBare UTF8StringLength]]; - [authMessage addItem: ","]; - [authMessage addItems: [data items] - count: [data count] * [data itemSize]]; - [authMessage addItem: ","]; - [authMessage addItems: [ret items] - count: [ret count]]; + [authMessage addItems: _clientFirstMessageBare.UTF8String + count: _clientFirstMessageBare.UTF8StringLength]; + [authMessage addItem: ","]; + [authMessage addItems: data.items + count: data.count * data.itemSize]; + [authMessage addItem: ","]; + [authMessage addItems: ret.items + count: ret.count]; /* * IETF RFC 5802: * ClientKey := HMAC(SaltedPassword, "Client Key") */ @@ -334,12 +336,12 @@ /* * IETF RFC 5802: * ClientSignature := HMAC(StoredKey, AuthMessage) */ clientSignature = [self - xmpp_HMACWithKey: [OFData dataWithItems: [hash digest] - count: [_hashType digestSize]] + xmpp_HMACWithKey: [OFData dataWithItems: hash.digest + count: hash.digestSize] data: authMessage]; /* * IETF RFC 5802: * ServerKey := HMAC(SaltedPassword, "Server Key") @@ -373,13 +375,13 @@ // Add p= [ret addItem: ","]; [ret addItems: "p=" count: 2]; - tmpString = [tmpArray stringByBase64Encoding]; - [ret addItems: [tmpString UTF8String] - count: [tmpString UTF8StringLength]]; + tmpString = tmpArray.stringByBase64Encoding; + [ret addItems: tmpString.UTF8String + count: tmpString.UTF8StringLength]; return ret; } - (OFData *)xmpp_parseServerFinalMessage: (OFData *)data @@ -391,16 +393,16 @@ * we were just waiting for the last word from the server */ if (_authenticated) return nil; - mess = [OFString stringWithUTF8String: [data items] - length: [data count] * [data itemSize]]; - value = [mess substringWithRange: of_range(2, [mess length] - 2)]; + mess = [OFString stringWithUTF8String: data.items + length: data.count * data.itemSize]; + value = [mess substringWithRange: of_range(2, mess.length - 2)]; if ([mess hasPrefix: @"v="]) { - if (![value isEqual: [_serverSignature stringByBase64Encoding]]) + if (![value isEqual: _serverSignature.stringByBase64Encoding]) @throw [XMPPAuthFailedException exceptionWithConnection: nil reason: @"Received wrong " @"ServerSignature"]; _authenticated = true; @@ -439,45 +441,45 @@ OFMutableData *k = [OFMutableData data]; size_t i, kSize, blockSize = [_hashType blockSize]; uint8_t *kI = NULL, *kO = NULL; id hashI, hashO; - if ([key itemSize] * [key count] > blockSize) { + if (key.itemSize * key.count > blockSize) { hashI = [[[_hashType alloc] init] autorelease]; - [hashI updateWithBuffer: [key items] - length: [key itemSize] * [key count]]; - [k addItems: [hashI digest] - count: [_hashType digestSize]]; + [hashI updateWithBuffer: key.items + length: key.itemSize * key.count]; + [k addItems: hashI.digest + count: hashI.digestSize]; } else - [k addItems: [key items] - count: [key itemSize] * [key count]]; + [k addItems: key.items + count: key.itemSize * key.count]; @try { kI = [self allocMemoryWithSize: blockSize]; kO = [self allocMemoryWithSize: blockSize]; - kSize = [k count]; - memcpy(kI, [k items], kSize); + kSize = k.count; + memcpy(kI, k.items, kSize); memset(kI + kSize, 0, blockSize - kSize); memcpy(kO, kI, blockSize); for (i = 0; i < blockSize; i++) { kI[i] ^= HMAC_IPAD; kO[i] ^= HMAC_OPAD; } hashI = [[[_hashType alloc] init] autorelease]; - [hashI updateWithBuffer: (char *)kI + [hashI updateWithBuffer: kI length: blockSize]; - [hashI updateWithBuffer: [data items] - length: [data itemSize] * [data count]]; + [hashI updateWithBuffer: data.items + length: data.itemSize * data.count]; hashO = [[[_hashType alloc] init] autorelease]; - [hashO updateWithBuffer: (char *)kO + [hashO updateWithBuffer: kO length: blockSize]; - [hashO updateWithBuffer: (char *)[hashI digest] - length: [_hashType digestSize]]; + [hashO updateWithBuffer: hashI.digest + length: hashI.digestSize]; } @finally { [self freeMemory: kI]; [self freeMemory: kO]; } Index: src/XMPPStanza.m ================================================================== --- src/XMPPStanza.m +++ src/XMPPStanza.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2012, 2013, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2019, Jonathan Schleifer * Copyright (c) 2011, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -127,19 +127,19 @@ @try { if (![name isEqual: @"iq"] && ![name isEqual: @"message"] && ![name isEqual: @"presence"]) @throw [OFInvalidArgumentException exception]; - [self setDefaultNamespace: XMPP_NS_CLIENT]; + self.defaultNamespace = XMPP_NS_CLIENT; [self setPrefix: @"stream" forNamespace: XMPP_NS_STREAM]; if (type != nil) - [self setType: type]; + self.type = type; if (ID != nil) - [self setID: ID]; + self.ID = ID; } @catch (id e) { [self release]; @throw e; } @@ -152,22 +152,22 @@ @try { OFXMLAttribute *attribute; if ((attribute = [element attributeForName: @"from"])) - [self setFrom: - [XMPPJID JIDWithString: [attribute stringValue]]]; + self.from = + [XMPPJID JIDWithString: attribute.stringValue]; if ((attribute = [element attributeForName: @"to"])) - [self setTo: - [XMPPJID JIDWithString: [attribute stringValue]]]; + self.to = + [XMPPJID JIDWithString: attribute.stringValue]; if ((attribute = [element attributeForName: @"type"])) - [self setType: [attribute stringValue]]; + self.type = attribute.stringValue; if ((attribute = [element attributeForName: @"id"])) - [self setID: [attribute stringValue]]; + self.ID = attribute.stringValue; } @catch (id e) { [self release]; @throw e; } @@ -192,11 +192,11 @@ [self removeAttributeForName: @"from"]; if (from != nil) [self addAttributeWithName: @"from" - stringValue: [from fullJID]]; + stringValue: from.fullJID]; } - (void)setTo: (XMPPJID *)to { XMPPJID *old = _to; @@ -205,11 +205,11 @@ [self removeAttributeForName: @"to"]; if (to != nil) [self addAttributeWithName: @"to" - stringValue: [to fullJID]]; + stringValue: to.fullJID]; } - (void)setType: (OFString *)type { OFString *old = _type; Index: src/XMPPStreamManagement.m ================================================================== --- src/XMPPStreamManagement.m +++ src/XMPPStreamManagement.m @@ -1,7 +1,8 @@ /* * Copyright (c) 2012, Florian Zeitz + * Copyright (c) 2019, Jonathan Schleifer * * https://heap.zone/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 @@ -54,12 +55,12 @@ } - (void)connection: (XMPPConnection *)connection didReceiveElement: (OFXMLElement *)element { - OFString *elementName = [element name]; - OFString *elementNS = [element namespace]; + OFString *elementName = element.name; + OFString *elementNS = element.namespace; if ([elementNS isEqual: XMPP_NS_SM]) { if ([elementName isEqual: @"enabled"]) { _receivedCount = 0; return; @@ -97,11 +98,11 @@ */ - (void)connection: (XMPPConnection *)connection wasBoundToJID: (XMPPJID *)JID { - if ([connection supportsStreamManagement]) + if (connection.supportsStreamManagement) [connection sendStanza: [OFXMLElement elementWithName: @"enable" namespace: XMPP_NS_SM]]; } @end Index: tests/test.m ================================================================== --- tests/test.m +++ tests/test.m @@ -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 }