Index: src/XMPPAuthenticator.m ================================================================== --- src/XMPPAuthenticator.m +++ src/XMPPAuthenticator.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2011, Florian Zeitz - * Copyright (c) 2016, Jonathan Schleifer + * Copyright (c) 2016, 2021, 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 @@ -29,13 +29,11 @@ @synthesize authzid = _authzid, authcid = _authcid, password = _password; - (instancetype)initWithAuthcid: (OFString *)authcid password: (OFString *)password { - return [self initWithAuthzid: nil - authcid: authcid - password: password]; + return [self initWithAuthzid: nil authcid: authcid password: password]; } - (instancetype)initWithAuthzid: (OFString *)authzid authcid: (OFString *)authcid password: (OFString *)password Index: src/XMPPCallback.h ================================================================== --- src/XMPPCallback.h +++ src/XMPPCallback.h @@ -1,7 +1,8 @@ /* * Copyright (c) 2011, Florian Zeitz + * Copyright (c) 2021, 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 @@ -26,33 +27,29 @@ @class XMPPConnection; @class XMPPIQ; #ifdef OF_HAVE_BLOCKS -typedef void (^xmpp_callback_block_t)(XMPPConnection *_Nonnull, - XMPPIQ *_Nonnull); +typedef void (^XMPPCallbackBlock)(XMPPConnection *_Nonnull, XMPPIQ *_Nonnull); #endif @interface XMPPCallback: OFObject { id _target; SEL _selector; #ifdef OF_HAVE_BLOCKS - xmpp_callback_block_t _block; + XMPPCallbackBlock _block; #endif } #ifdef OF_HAVE_BLOCKS -+ (instancetype)callbackWithBlock: (xmpp_callback_block_t)callback; -- (instancetype)initWithBlock: (xmpp_callback_block_t)callback; ++ (instancetype)callbackWithBlock: (XMPPCallbackBlock)callback; +- (instancetype)initWithBlock: (XMPPCallbackBlock)callback; #endif -+ (instancetype)callbackWithTarget: (id)target - selector: (SEL)selector; -- (instancetype)initWithTarget: (id)target - selector: (SEL)selector; ++ (instancetype)callbackWithTarget: (id)target selector: (SEL)selector; +- (instancetype)initWithTarget: (id)target selector: (SEL)selector; -- (void)runWithIQ: (XMPPIQ *)iq - connection: (XMPPConnection *)connection; +- (void)runWithIQ: (XMPPIQ *)iq connection: (XMPPConnection *)connection; @end OF_ASSUME_NONNULL_END Index: src/XMPPCallback.m ================================================================== --- src/XMPPCallback.m +++ src/XMPPCallback.m @@ -1,7 +1,8 @@ /* * Copyright (c) 2011, Florian Zeitz + * Copyright (c) 2021, 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 @@ -24,17 +25,17 @@ #import "XMPPCallback.h" @implementation XMPPCallback #ifdef OF_HAVE_BLOCKS -+ (instancetype)callbackWithBlock: (xmpp_callback_block_t)block ++ (instancetype)callbackWithBlock: (XMPPCallbackBlock)block { return [[(XMPPCallback *)[self alloc] initWithBlock: block] autorelease]; } -- (instancetype)initWithBlock: (xmpp_callback_block_t)block +- (instancetype)initWithBlock: (XMPPCallbackBlock)block { self = [super init]; @try { _block = [block copy]; @@ -45,19 +46,17 @@ return self; } #endif -+ (instancetype)callbackWithTarget: (id)target - selector: (SEL)selector ++ (instancetype)callbackWithTarget: (id)target selector: (SEL)selector { return [[[self alloc] initWithTarget: target selector: selector] autorelease]; } -- (instancetype)initWithTarget: (id)target - selector: (SEL)selector +- (instancetype)initWithTarget: (id)target selector: (SEL)selector { self = [super init]; _target = [target retain]; _selector = selector; @@ -73,12 +72,11 @@ #endif [super dealloc]; } -- (void)runWithIQ: (XMPPIQ *)IQ - connection: (XMPPConnection *)connection +- (void)runWithIQ: (XMPPIQ *)IQ connection: (XMPPConnection *)connection { #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(connection, IQ); else Index: src/XMPPConnection.h ================================================================== --- src/XMPPConnection.h +++ src/XMPPConnection.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2010, 2011, 2012, 2013, 2016, 2017, 2018 + * Copyright (c) 2010, 2011, 2012, 2013, 2016, 2017, 2018, 2021 * Jonathan Schleifer * Copyright (c) 2011, 2012, Florian Zeitz * * https://heap.zone/objxmpp/ * @@ -27,11 +27,11 @@ #import "XMPPCallback.h" #import "XMPPStorage.h" OF_ASSUME_NONNULL_BEGIN -#define XMPP_CONNECTION_BUFFER_LENGTH 512 +#define XMPPConnectionBufferLength 512 @class XMPPConnection; @class XMPPJID; @class XMPPIQ; @class XMPPMessage; @@ -75,21 +75,19 @@ * @brief This callback is called when the connection was bound to a JID. * * @param connection The connection that was bound to a JID * @param JID The JID the conecction was bound to */ -- (void)connection: (XMPPConnection *)connection - wasBoundToJID: (XMPPJID *)JID; +- (void)connection: (XMPPConnection *)connection wasBoundToJID: (XMPPJID *)JID; /*! * @brief This callback is called when the connection received an IQ stanza. * * @param connection The connection that received the stanza - * @param iq The IQ stanza that was received + * @param IQ The IQ stanza that was received */ -- (bool)connection: (XMPPConnection *)connection - didReceiveIQ: (XMPPIQ *)iq; +- (bool)connection: (XMPPConnection *)connection didReceiveIQ: (XMPPIQ *)IQ; /*! * @brief This callback is called when the connection received a presence * stanza. * @@ -146,11 +144,11 @@ * @brief A class which abstracts a connection to an XMPP service. */ @interface XMPPConnection: OFObject { OFTCPSocket *_socket; - char _buffer[XMPP_CONNECTION_BUFFER_LENGTH]; + char _buffer[XMPPConnectionBufferLength]; OFXMLParser *_parser, *_oldParser; OFXMLElementBuilder *_elementBuilder, *_oldElementBuilder; OFString *_Nullable _username, *_Nullable _password, *_Nullable _server; OFString *_Nullable _resource; bool _usesAnonymousAuthentication; @@ -307,12 +305,11 @@ * * @param buffer The buffer to parse * @param length The length of the buffer. If length is 0, it is assumed that * the connection was closed. */ -- (void)parseBuffer: (const void *)buffer - length: (size_t)length; +- (void)parseBuffer: (const void *)buffer length: (size_t)length; /*! * @brief Sends an OFXMLElement, usually an XMPPStanza. * * @param element The element to send @@ -336,12 +333,11 @@ * @brief Sends an XMPPIQ, registering a callback block. * * @param IQ The IQ to send * @param block The callback block */ -- (void)sendIQ: (XMPPIQ *)IQ - callbackBlock: (xmpp_callback_block_t)block; +- (void)sendIQ: (XMPPIQ *)IQ callbackBlock: (XMPPCallbackBlock)block; #endif /*! * @brief Generates a new, unique stanza ID. * Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -57,12 +57,11 @@ #import @interface XMPPConnection () - (void)xmpp_tryNextSRVRecord; -- (bool)xmpp_parseBuffer: (const void *)buffer - length: (size_t)length; +- (bool)xmpp_parseBuffer: (const void *)buffer length: (size_t)length; - (void)xmpp_startStream; - (void)xmpp_handleStanza: (OFXMLElement *)element; - (void)xmpp_handleStream: (OFXMLElement *)element; - (void)xmpp_handleTLS: (OFXMLElement *)element; - (void)xmpp_handleSASL: (OFXMLElement *)element; @@ -70,12 +69,11 @@ - (void)xmpp_handleMessage: (XMPPMessage *)message; - (void)xmpp_handlePresence: (XMPPPresence *)presence; - (void)xmpp_handleFeatures: (OFXMLElement *)element; - (void)xmpp_sendAuth: (OFString *)authName; - (void)xmpp_sendResourceBind; -- (void)xmpp_sendStreamError: (OFString *)condition - text: (OFString *)text; +- (void)xmpp_sendStreamError: (OFString *)condition text: (OFString *)text; - (void)xmpp_handleResourceBindForConnection: (XMPPConnection *)connection IQ: (XMPPIQ *)IQ; - (void)xmpp_sendSession; - (void)xmpp_handleSessionForConnection: (XMPPConnection *)connection IQ: (XMPPIQ *)IQ; @@ -276,11 +274,11 @@ } [self xmpp_startStream]; [_socket asyncReadIntoBuffer: _buffer - length: XMPP_CONNECTION_BUFFER_LENGTH]; + length: XMPPConnectionBufferLength]; } - (void)xmpp_tryNextSRVRecord { OFSRVDNSResourceRecord *record = @@ -289,12 +287,11 @@ 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 didPerformQuery: (OFString *)domainName response: (OFDNSResponse *)response @@ -313,12 +310,11 @@ /* TODO: Sort records */ [records makeImmutable]; if (records.count == 0) { /* Fall back to A / AAAA record. */ - [_socket asyncConnectToHost: _domainToASCII - port: _port]; + [_socket asyncConnectToHost: _domainToASCII port: _port]; return; } [_nextSRVRecords release]; _nextSRVRecords = nil; @@ -335,12 +331,11 @@ _socket = [[OFTCPSocket alloc] init]; [_socket setDelegate: self]; if (_server != nil) - [_socket asyncConnectToHost: _server - port: _port]; + [_socket asyncConnectToHost: _server port: _port]; else { OFString *SRVDomain = [_domainToASCII stringByPrependingString: @"_xmpp-client._tcp."]; OFDNSQuery *query = [OFDNSQuery queryWithDomainName: SRVDomain @@ -363,27 +358,23 @@ withObject: nil]; return false; } @try { - [_parser parseBuffer: buffer - length: length]; + [_parser parseBuffer: buffer length: length]; } @catch (OFMalformedXMLException *e) { - [self xmpp_sendStreamError: @"bad-format" - text: nil]; + [self xmpp_sendStreamError: @"bad-format" text: nil]; [self close]; return false; } return true; } -- (void)parseBuffer: (const void *)buffer - length: (size_t)length +- (void)parseBuffer: (const void *)buffer length: (size_t)length { - [self xmpp_parseBuffer: buffer - length: length]; + [self xmpp_parseBuffer: buffer length: length]; [_oldParser release]; [_oldElementBuilder release]; _oldParser = nil; @@ -403,12 +394,11 @@ [self close]; return false; } @try { - if (![self xmpp_parseBuffer: buffer - length: length]) + if (![self xmpp_parseBuffer: buffer length: length]) return false; } @catch (id e) { [_delegates broadcastSelector: @selector(connection: didThrowException:) withObject: self @@ -423,11 +413,11 @@ _oldParser = nil; _oldElementBuilder = nil; [_socket asyncReadIntoBuffer: _buffer - length: XMPP_CONNECTION_BUFFER_LENGTH]; + length: XMPPConnectionBufferLength]; return false; } return true; } @@ -500,23 +490,20 @@ key = _JID.bareJID; if (key == nil) // Only happens for resource bind key = @"bind"; key = [key stringByAppendingString: ID]; - callback = [XMPPCallback callbackWithTarget: target - selector: selector]; - [_callbacks setObject: callback - forKey: key]; + callback = [XMPPCallback callbackWithTarget: target selector: selector]; + [_callbacks setObject: callback forKey: key]; objc_autoreleasePoolPop(pool); [self sendStanza: IQ]; } #ifdef OF_HAVE_BLOCKS -- (void)sendIQ: (XMPPIQ *)IQ - callbackBlock: (xmpp_callback_block_t)block +- (void)sendIQ: (XMPPIQ *)IQ callbackBlock: (XMPPCallbackBlock)block { void *pool = objc_autoreleasePoolPush(); XMPPCallback *callback; OFString *ID, *key; @@ -530,12 +517,11 @@ if (key == nil) // Connection not yet bound, can't send stanzas @throw [OFInvalidArgumentException exception]; key = [key stringByAppendingString: ID]; callback = [XMPPCallback callbackWithBlock: block]; - [_callbacks setObject: callback - forKey: key]; + [_callbacks setObject: callback forKey: key]; objc_autoreleasePoolPop(pool); [self sendStanza: IQ]; } @@ -558,26 +544,23 @@ [_socket close]; return; } if (![prefix isEqual: @"stream"]) { - [self xmpp_sendStreamError: @"bad-namespace-prefix" - text: nil]; + [self xmpp_sendStreamError: @"bad-namespace-prefix" text: nil]; return; } - if (![namespace isEqual: XMPP_NS_STREAM]) { - [self xmpp_sendStreamError: @"invalid-namespace" - text: nil]; + if (![namespace isEqual: XMPPStreamNS]) { + [self xmpp_sendStreamError: @"invalid-namespace" text: nil]; return; } for (OFXMLAttribute *attribute in attributes) { if ([attribute.name isEqual: @"from"] && ![attribute.stringValue isEqual: _domain]) { - [self xmpp_sendStreamError: @"invalid-from" - text: nil]; + [self xmpp_sendStreamError: @"invalid-from" text: nil]; return; } if ([attribute.name isEqual: @"version"] && ![attribute.stringValue isEqual: @"1.0"]) { [self xmpp_sendStreamError: @"unsupported-version" @@ -594,38 +577,37 @@ { /* Ignore whitespace elements */ if (element.name == nil) return; - element.defaultNamespace = XMPP_NS_CLIENT; - [element setPrefix: @"stream" - forNamespace: XMPP_NS_STREAM]; + element.defaultNamespace = XMPPClientNS; + [element setPrefix: @"stream" forNamespace: XMPPStreamNS]; [_delegates broadcastSelector: @selector(connection:didReceiveElement:) withObject: self withObject: element]; - if ([element.namespace isEqual: XMPP_NS_CLIENT]) + if ([element.namespace isEqual: XMPPClientNS]) [self xmpp_handleStanza: element]; - if ([element.namespace isEqual: XMPP_NS_STREAM]) + if ([element.namespace isEqual: XMPPStreamNS]) [self xmpp_handleStream: element]; - if ([element.namespace isEqual: XMPP_NS_STARTTLS]) + if ([element.namespace isEqual: XMPPStartTLSNS]) [self xmpp_handleTLS: element]; - if ([element.namespace isEqual: XMPP_NS_SASL]) + if ([element.namespace isEqual: XMPPSASLNS]) [self xmpp_handleSASL: element]; } - (void)elementBuilder: (OFXMLElementBuilder *)builder didNotExpectCloseTag: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)ns { if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] || - ![ns isEqual: XMPP_NS_STREAM]) + ![ns isEqual: XMPPStreamNS]) @throw [OFMalformedXMLException exception]; else [self close]; } @@ -654,12 +636,12 @@ langString = [OFString stringWithFormat: @"xml:lang='%@' ", _language]; [_socket writeFormat: @"\n" @"", _domain, langString]; _streamOpen = true; } @@ -700,12 +682,11 @@ [self xmpp_handlePresence: [XMPPPresence stanzaWithElement: element]]; return; } - [self xmpp_sendStreamError: @"unsupported-stanza-type" - text: nil]; + [self xmpp_sendStreamError: @"unsupported-stanza-type" text: nil]; } - (void)xmpp_handleStream: (OFXMLElement *)element { @@ -720,19 +701,18 @@ [_delegates broadcastSelector: @selector(connectionWasClosed:) withObject: self withObject: element]; - condition = [[element elementsForNamespace: - XMPP_NS_XMPP_STREAM].firstObject name]; + condition = [[element elementsForNamespace: XMPPXMPPStreamNS] + .firstObject name]; if (condition == nil) condition = @"undefined"; - reason = [element - elementForName: @"text" - namespace: XMPP_NS_XMPP_STREAM].stringValue; + reason = [element elementForName: @"text" + namespace: XMPPXMPPStreamNS].stringValue; @throw [XMPPStreamErrorException exceptionWithConnection: self condition: condition reason: reason]; @@ -791,11 +771,11 @@ OFData *challenge = [OFData dataWithBase64EncodedString: element.stringValue]; OFData *response = [_authModule continueWithData: challenge]; responseTag = [OFXMLElement elementWithName: @"response" - namespace: XMPP_NS_SASL]; + namespace: XMPPSASLNS]; if (response) { if (response.count == 0) responseTag.stringValue = @"="; else responseTag.stringValue = @@ -841,12 +821,11 @@ if (key == nil) // Only happens for resource bind key = @"bind"; key = [key stringByAppendingString: IQ.ID]; if ((callback = [_callbacks objectForKey: key])) { - [callback runWithIQ: IQ - connection: self]; + [callback runWithIQ: IQ connection: self]; [_callbacks removeObjectForKey: key]; return; } handled = [_delegates broadcastSelector: @selector( @@ -876,36 +855,34 @@ } - (void)xmpp_handleFeatures: (OFXMLElement *)element { OFXMLElement *startTLS = [element elementForName: @"starttls" - namespace: XMPP_NS_STARTTLS]; + namespace: XMPPStartTLSNS]; OFXMLElement *bind = [element elementForName: @"bind" - namespace: XMPP_NS_BIND]; + namespace: XMPPBindNS]; OFXMLElement *session = [element elementForName: @"session" - namespace: XMPP_NS_SESSION]; + namespace: XMPPSessionNS]; OFXMLElement *mechs = [element elementForName: @"mechanisms" - namespace: XMPP_NS_SASL]; + namespace: XMPPSASLNS]; OFMutableSet *mechanisms = [OFMutableSet set]; if (!_encrypted && startTLS != nil) { [self sendStanza: [OFXMLElement elementWithName: @"starttls" - namespace: XMPP_NS_STARTTLS]]; + namespace: XMPPStartTLSNS]]; return; } if (_encryptionRequired && !_encrypted) /* TODO: Find/create an exception to throw here */ @throw [OFException exception]; - if ([element elementForName: @"ver" - namespace: XMPP_NS_ROSTERVER] != nil) + if ([element elementForName: @"ver" namespace: XMPPRosterVerNS] != nil) _supportsRosterVersioning = true; - if ([element elementForName: @"sm" - namespace: XMPP_NS_SM] != nil) + if ([element elementForName: @"sm" namespace: XMPPSMNS] != nil) _supportsStreamManagement = true; if (mechs != nil) { for (OFXMLElement *mech in mechs.children) [mechanisms addObject: mech.stringValue]; @@ -964,11 +941,11 @@ reason: @"No supported auth mechanism"]; } if (session != nil && [session elementForName: @"optional" - namespace: XMPP_NS_SESSION] == nil) + namespace: XMPPSessionNS] == nil) _needsSession = true; if (bind != nil) { [self xmpp_sendResourceBind]; return; @@ -980,14 +957,12 @@ - (void)xmpp_sendAuth: (OFString *)authName { OFXMLElement *authTag; OFData *initialMessage = [_authModule initialMessage]; - authTag = [OFXMLElement elementWithName: @"auth" - namespace: XMPP_NS_SASL]; - [authTag addAttributeWithName: @"mechanism" - stringValue: authName]; + authTag = [OFXMLElement elementWithName: @"auth" namespace: XMPPSASLNS]; + [authTag addAttributeWithName: @"mechanism" stringValue: authName]; if (initialMessage != nil) { if (initialMessage.count == 0) authTag.stringValue = @"="; else authTag.stringValue = @@ -1000,19 +975,17 @@ - (void)xmpp_sendResourceBind { XMPPIQ *IQ; OFXMLElement *bind; - IQ = [XMPPIQ IQWithType: @"set" - ID: [self generateStanzaID]]; + IQ = [XMPPIQ IQWithType: @"set" ID: [self generateStanzaID]]; - bind = [OFXMLElement elementWithName: @"bind" - namespace: XMPP_NS_BIND]; + bind = [OFXMLElement elementWithName: @"bind" namespace: XMPPBindNS]; if (_resource != nil) [bind addChild: [OFXMLElement elementWithName: @"resource" - namespace: XMPP_NS_BIND + namespace: XMPPBindNS stringValue: _resource]]; [IQ addChild: bind]; [self sendIQ: IQ @@ -1024,19 +997,18 @@ - (void)xmpp_sendStreamError: (OFString *)condition text: (OFString *)text { OFXMLElement *error = [OFXMLElement elementWithName: @"error" - namespace: XMPP_NS_STREAM]; - [error setPrefix: @"stream" - forNamespace: XMPP_NS_STREAM]; + namespace: XMPPStreamNS]; + [error setPrefix: @"stream" forNamespace: XMPPStreamNS]; [error addChild: [OFXMLElement elementWithName: condition - namespace: XMPP_NS_XMPP_STREAM]]; + namespace: XMPPXMPPStreamNS]]; if (text) [error addChild: [OFXMLElement elementWithName: @"text" - namespace: XMPP_NS_XMPP_STREAM + namespace: XMPPXMPPStreamNS stringValue: text]]; _parser.delegate = nil; [self sendStanza: error]; [self close]; } @@ -1046,17 +1018,15 @@ { OFXMLElement *bindElement, *JIDElement; assert([IQ.type isEqual: @"result"]); - bindElement = [IQ elementForName: @"bind" - namespace: XMPP_NS_BIND]; + bindElement = [IQ elementForName: @"bind" namespace: XMPPBindNS]; assert(bindElement != nil); - JIDElement = [bindElement elementForName: @"jid" - namespace: XMPP_NS_BIND]; + JIDElement = [bindElement elementForName: @"jid" namespace: XMPPBindNS]; _JID = [[XMPPJID alloc] initWithString: JIDElement.stringValue]; if (_needsSession) { [self xmpp_sendSession]; return; @@ -1067,15 +1037,14 @@ withObject: _JID]; } - (void)xmpp_sendSession { - XMPPIQ *IQ = [XMPPIQ IQWithType: @"set" - ID: [self generateStanzaID]]; + XMPPIQ *IQ = [XMPPIQ IQWithType: @"set" ID: [self generateStanzaID]]; [IQ addChild: [OFXMLElement elementWithName: @"session" - namespace: XMPP_NS_SESSION]]; + namespace: XMPPSessionNS]]; [self sendIQ: IQ callbackTarget: self selector: @selector(xmpp_handleSessionForConnection:IQ:)]; } Index: src/XMPPContact.m ================================================================== --- src/XMPPContact.m +++ src/XMPPContact.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, 2021, 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 @@ -73,15 +73,13 @@ - (void)xmpp_setPresence: (XMPPPresence *)presence resource: (OFString *)resource { if (resource != nil) - [_presences setObject: presence - forKey: resource]; + [_presences setObject: presence forKey: resource]; else - [_presences setObject: presence - forKey: @""]; + [_presences setObject: presence forKey: @""]; self.xmpp_lockedOnJID = nil; } - (void)xmpp_removePresenceForResource: (OFString *)resource Index: src/XMPPContactManager.h ================================================================== --- src/XMPPContactManager.h +++ src/XMPPContactManager.h @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2021, 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 @@ -90,12 +90,11 @@ * @brief This callback is called whenever a contact send a message stanza * * @param contact The contact that send the message * @param message The message which was send by the contact */ -- (void)contact: (XMPPContact *)contact - didSendMessage: (XMPPMessage *)message; +- (void)contact: (XMPPContact *)contact didSendMessage: (XMPPMessage *)message; @end /*! * @brief A class tracking a XMPPContact instance for each contact in the roster * Index: src/XMPPContactManager.m ================================================================== --- src/XMPPContactManager.m +++ src/XMPPContactManager.m @@ -105,12 +105,11 @@ rosterItems = roster.rosterItems; for (OFString *bareJID in rosterItems) { XMPPContact *contact = [[[XMPPContact alloc] init] autorelease]; contact.rosterItem = [rosterItems objectForKey: bareJID]; - [_contacts setObject: contact - forKey: bareJID]; + [_contacts setObject: contact forKey: bareJID]; [_delegates broadcastSelector: @selector(contactManager: didAddContact:) withObject: self withObject: contact]; } @@ -135,12 +134,11 @@ } if (contact == nil) { contact = [[[XMPPContact alloc] init] autorelease]; contact.rosterItem = rosterItem; - [_contacts setObject: contact - forKey: bareJID]; + [_contacts setObject: contact forKey: bareJID]; [_delegates broadcastSelector: @selector(contactManager: didAddContact:) withObject: self withObject: contact]; } else { @@ -172,12 +170,11 @@ if (contact == nil) return; /* Available presence */ if ([type isEqual: @"available"]) { - [contact xmpp_setPresence: presence - resource: JID.resource]; + [contact xmpp_setPresence: presence resource: JID.resource]; [_delegates broadcastSelector: @selector(contact: didSendPresence:) withObject: contact withObject: presence]; return; Index: src/XMPPDiscoEntity.m ================================================================== --- src/XMPPDiscoEntity.m +++ src/XMPPDiscoEntity.m @@ -30,12 +30,11 @@ #import "namespaces.h" @implementation XMPPDiscoEntity @synthesize discoNodes = _discoNodes, capsNode = _capsNode; -+ (instancetype)discoNodeWithJID: (XMPPJID *)JID - node: (OFString *)node ++ (instancetype)discoNodeWithJID: (XMPPJID *)JID node: (OFString *)node { OF_UNRECOGNIZED_SELECTOR } + (instancetype)discoNodeWithJID: (XMPPJID *)JID @@ -55,12 +54,11 @@ { return [[[self alloc] initWithConnection: connection capsNode: capsNode] autorelease]; } -- (instancetype)initWithJID: (XMPPJID *)JID - node: (nullable OFString *)node +- (instancetype)initWithJID: (XMPPJID *)JID node: (nullable OFString *)node { OF_INVALID_INIT_METHOD } - (instancetype)initWithJID: (XMPPJID *)JID @@ -77,13 +75,11 @@ } - (instancetype)initWithConnection: (XMPPConnection *)connection capsNode: (OFString *)capsNode { - self = [super initWithJID: [connection JID] - node: nil - name: nil]; + self = [super initWithJID: [connection JID] node: nil name: nil]; @try { _discoNodes = [[OFMutableDictionary alloc] init]; _connection = connection; _capsNode = [capsNode copy]; @@ -105,12 +101,11 @@ [super dealloc]; } - (void)addDiscoNode: (XMPPDiscoNode *)node { - [_discoNodes setObject: node - forKey: node.node]; + [_discoNodes setObject: node forKey: node.node]; } - (OFString *)capsHash { OFMutableString *caps = [OFMutableString string]; @@ -122,15 +117,13 @@ 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.digestSize]; + digest = [OFData dataWithItems: hash.digest count: hash.digestSize]; return digest.stringByBase64Encoding; } - (void)connection: (XMPPConnection *)connection @@ -144,11 +137,11 @@ { if (![IQ.to isEqual: _JID]) return false; OFXMLElement *query = [IQ elementForName: @"query" - namespace: XMPP_NS_DISCO_ITEMS]; + namespace: XMPPDiscoItemsNS]; if (query != nil) { OFString *node = [query attributeForName: @"node"].stringValue; if (node == nil) return [self xmpp_handleItemsIQ: IQ @@ -160,12 +153,11 @@ connection: connection]; return false; } - query = [IQ elementForName: @"query" - namespace: XMPP_NS_DISCO_INFO]; + query = [IQ elementForName: @"query" namespace: XMPPDiscoInfoNS]; if (query != nil) { OFString *node = [query attributeForName: @"node"].stringValue; if (node == nil) Index: src/XMPPDiscoIdentity.h ================================================================== --- src/XMPPDiscoIdentity.h +++ src/XMPPDiscoIdentity.h @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2021, 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 @@ -94,10 +94,9 @@ * * @param category The category of the identity * @param type The type of the identity * @return An initialized XMPPDiscoIdentity */ -- (instancetype)initWithCategory: (OFString *)category - type: (OFString *)type; +- (instancetype)initWithCategory: (OFString *)category type: (OFString *)type; @end OF_ASSUME_NONNULL_END Index: src/XMPPDiscoIdentity.m ================================================================== --- src/XMPPDiscoIdentity.m +++ src/XMPPDiscoIdentity.m @@ -61,16 +61,13 @@ } return self; } -- (instancetype)initWithCategory: (OFString *)category - type: (OFString *)type +- (instancetype)initWithCategory: (OFString *)category type: (OFString *)type { - return [self initWithCategory: category - type: type - name: nil]; + return [self initWithCategory: category type: type name: nil]; } - (instancetype)init { OF_INVALID_INIT_METHOD Index: src/XMPPDiscoNode.h ================================================================== --- src/XMPPDiscoNode.h +++ src/XMPPDiscoNode.h @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2021, 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 @@ -101,12 +101,11 @@ * * @param JID The JID this node lives on * @param node The node's opaque name * @return An initialized XMPPDiscoNode */ -- (instancetype)initWithJID: (XMPPJID *)JID - node: (nullable OFString *)node; +- (instancetype)initWithJID: (XMPPJID *)JID node: (nullable OFString *)node; /*! * @brief Initializes an already allocated XMPPDiscoNode with the specified * JID, node and name * Index: src/XMPPDiscoNode.m ================================================================== --- src/XMPPDiscoNode.m +++ src/XMPPDiscoNode.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, 2021, 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 @@ -33,15 +33,13 @@ @implementation XMPPDiscoNode @synthesize JID = _JID, node = _node, name = _name, identities = _identities; @synthesize features = _features, childNodes = _childNodes; -+ (instancetype)discoNodeWithJID: (XMPPJID *)JID - node: (OFString *)node; ++ (instancetype)discoNodeWithJID: (XMPPJID *)JID node: (OFString *)node; { - return [[[self alloc] initWithJID: JID - node: node] autorelease]; + return [[[self alloc] initWithJID: JID node: node] autorelease]; } + (instancetype)discoNodeWithJID: (XMPPJID *)JID node: (OFString *)node name: (OFString *)name @@ -49,16 +47,13 @@ return [[[self alloc] initWithJID: JID node: node name: name] autorelease]; } -- (instancetype)initWithJID: (XMPPJID *)JID - node: (OFString *)node +- (instancetype)initWithJID: (XMPPJID *)JID node: (OFString *)node { - return [self initWithJID: JID - node: node - name: nil]; + return [self initWithJID: JID node: node name: nil]; } - (instancetype)initWithJID: (XMPPJID *)JID node: (OFString *)node name: (OFString *)name @@ -75,12 +70,12 @@ _name = [name copy]; _identities = [[OFSortedList alloc] init]; _features = [[OFSortedList alloc] init]; _childNodes = [[OFMutableDictionary alloc] init]; - [self addFeature: XMPP_NS_DISCO_ITEMS]; - [self addFeature: XMPP_NS_DISCO_INFO]; + [self addFeature: XMPPDiscoItemsNS]; + [self addFeature: XMPPDiscoInfoNS]; } @catch (id e) { [self release]; @throw e; } @@ -124,25 +119,25 @@ connection: (XMPPConnection *)connection { XMPPIQ *resultIQ; OFXMLElement *response; OFXMLElement *query = [IQ elementForName: @"query" - namespace: XMPP_NS_DISCO_ITEMS]; + namespace: XMPPDiscoItemsNS]; OFString *node = [[query attributeForName: @"node"] stringValue]; if (!(node == _node) && ![node isEqual: _node]) return false; resultIQ = [IQ resultIQ]; response = [OFXMLElement elementWithName: @"query" - namespace: XMPP_NS_DISCO_ITEMS]; + namespace: XMPPDiscoItemsNS]; [resultIQ addChild: response]; for (XMPPDiscoNode *child in _childNodes) { OFXMLElement *item = [OFXMLElement elementWithName: @"item" - namespace: XMPP_NS_DISCO_ITEMS]; + namespace: XMPPDiscoItemsNS]; [item addAttributeWithName: @"jid" stringValue: child.JID.fullJID]; if (child.node != nil) [item addAttributeWithName: @"node" @@ -157,25 +152,24 @@ [connection sendStanza: resultIQ]; return true; } -- (bool)xmpp_handleInfoIQ: (XMPPIQ *)IQ - connection: (XMPPConnection *)connection +- (bool)xmpp_handleInfoIQ: (XMPPIQ *)IQ connection: (XMPPConnection *)connection { XMPPIQ *resultIQ; OFXMLElement *response; resultIQ = [IQ resultIQ]; response = [OFXMLElement elementWithName: @"query" - namespace: XMPP_NS_DISCO_INFO]; + namespace: XMPPDiscoInfoNS]; [resultIQ addChild: response]; for (XMPPDiscoIdentity *identity in _identities) { OFXMLElement *identityElement = [OFXMLElement elementWithName: @"identity" - namespace: XMPP_NS_DISCO_INFO]; + namespace: XMPPDiscoInfoNS]; [identityElement addAttributeWithName: @"category" stringValue: identity.category]; [identityElement addAttributeWithName: @"type" stringValue: identity.type]; @@ -187,11 +181,11 @@ } for (OFString *feature in _features) { OFXMLElement *featureElement = [OFXMLElement elementWithName: @"feature" - namespace: XMPP_NS_DISCO_INFO]; + namespace: XMPPDiscoInfoNS]; [featureElement addAttributeWithName: @"var" stringValue: feature]; [response addChild: featureElement]; } Index: src/XMPPEXTERNALAuth.m ================================================================== --- src/XMPPEXTERNALAuth.m +++ src/XMPPEXTERNALAuth.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2012, Florian Zeitz - * Copyright (c) 2019, Jonathan Schleifer + * Copyright (c) 2019, 2021, 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 @@ -26,12 +26,11 @@ #import "XMPPEXTERNALAuth.h" @implementation XMPPEXTERNALAuth: XMPPAuthenticator + (instancetype)EXTERNALAuth { - return [[[self alloc] initWithAuthcid: nil - password: nil] autorelease]; + return [[[self alloc] initWithAuthcid: nil password: nil] autorelease]; } + (instancetype)EXTERNALAuthWithAuthzid: (OFString *)authzid { return [[[self alloc] initWithAuthzid: authzid Index: src/XMPPFileStorage.m ================================================================== --- src/XMPPFileStorage.m +++ src/XMPPFileStorage.m @@ -90,20 +90,18 @@ OFMutableDictionary *iter2 = [iter objectForKey: component]; if (iter2 == nil) { iter2 = [OFMutableDictionary dictionary]; - [iter setObject: iter2 - forKey: component]; + [iter setObject: iter2 forKey: component]; } iter = iter2; } if (object != nil) - [iter setObject: object - forKey: [pathComponents lastObject]]; + [iter setObject: object forKey: [pathComponents lastObject]]; else [iter removeObjectForKey: pathComponents.lastObject]; } - (id)xmpp_objectForPath: (OFString *)path @@ -119,12 +117,11 @@ - (void)setStringValue: (OFString *)string forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - [self xmpp_setObject: string - forPath: path]; + [self xmpp_setObject: string forPath: path]; objc_autoreleasePoolPop(pool); } - (OFString *)stringValueForPath: (OFString *)path @@ -137,17 +134,15 @@ objc_autoreleasePoolPop(pool); return string; } -- (void)setBooleanValue: (bool)boolean - forPath: (OFString *)path +- (void)setBooleanValue: (bool)boolean forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - [self xmpp_setObject: [OFNumber numberWithBool: boolean] - forPath: path]; + [self xmpp_setObject: [OFNumber numberWithBool: boolean] forPath: path]; objc_autoreleasePoolPop(pool); } - (bool)booleanValueForPath: (OFString *)path @@ -160,12 +155,11 @@ objc_autoreleasePoolPop(pool); return boolean; } -- (void)setIntegerValue: (long long)integer - forPath: (OFString *)path +- (void)setIntegerValue: (long long)integer forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self xmpp_setObject: [OFNumber numberWithLongLong: integer] forPath: path]; @@ -183,17 +177,15 @@ objc_autoreleasePoolPop(pool); return integer; } -- (void)setArray: (OFArray *)array - forPath: (OFString *)path +- (void)setArray: (OFArray *)array forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - [self xmpp_setObject: array - forPath: path]; + [self xmpp_setObject: array forPath: path]; objc_autoreleasePoolPop(pool); } - (OFArray *)arrayForPath: (OFString *)path @@ -206,17 +198,15 @@ objc_autoreleasePoolPop(pool); return array; } -- (void)setDictionary: (OFDictionary *)dictionary - forPath: (OFString *)path +- (void)setDictionary: (OFDictionary *)dictionary forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - [self xmpp_setObject: dictionary - forPath: path]; + [self xmpp_setObject: dictionary forPath: path]; objc_autoreleasePoolPop(pool); } - (OFDictionary *)dictionaryForPath: (OFString *)path Index: src/XMPPIQ.h ================================================================== --- src/XMPPIQ.h +++ src/XMPPIQ.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, Jonathan Schleifer + * Copyright (c) 2011, 2021, Jonathan Schleifer * Copyright (c) 2011, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -34,23 +34,21 @@ * * @param type The value for the stanza's type attribute * @param ID The value for the stanza's id attribute * @return A new autoreleased XMPPIQ */ -+ (instancetype)IQWithType: (OFString *)type - ID: (OFString *)ID; ++ (instancetype)IQWithType: (OFString *)type ID: (OFString *)ID; /*! * @brief Initializes an already allocated XMPPIQ with the specified type and * ID. * * @param type The value for the stanza's type attribute * @param ID The value for the stanza's id attribute * @return An initialized XMPPIQ */ -- (instancetype)initWithType: (OFString *)type - ID: (OFString *)ID; +- (instancetype)initWithType: (OFString *)type ID: (OFString *)ID; /*! * @brief Generates a result IQ for the receiving object. * * @return A new autoreleased XMPPIQ @@ -74,10 +72,9 @@ * * @param type An error type as defined by RFC 6120 * @param condition A defined conditions from RFC 6120 * @return A new autoreleased XMPPIQ */ -- (XMPPIQ *)errorIQWithType: (OFString *)type - condition: (OFString *)condition; +- (XMPPIQ *)errorIQWithType: (OFString *)type condition: (OFString *)condition; @end OF_ASSUME_NONNULL_END Index: src/XMPPIQ.m ================================================================== --- src/XMPPIQ.m +++ src/XMPPIQ.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2019, Jonathan Schleifer + * Copyright (c) 2011, 2019, 2021, Jonathan Schleifer * Copyright (c) 2011, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -25,23 +25,18 @@ #import "namespaces.h" #import "XMPPIQ.h" @implementation XMPPIQ -+ (instancetype)IQWithType: (OFString *)type - ID: (OFString *)ID ++ (instancetype)IQWithType: (OFString *)type ID: (OFString *)ID { - return [[[self alloc] initWithType: type - ID: ID] autorelease]; + return [[[self alloc] initWithType: type ID: ID] autorelease]; } -- (instancetype)initWithType: (OFString *)type - ID: (OFString *)ID +- (instancetype)initWithType: (OFString *)type ID: (OFString *)ID { - self = [super initWithName: @"iq" - type: type - ID: ID]; + self = [super initWithName: @"iq" type: type ID: ID]; @try { if (![type isEqual: @"get"] && ![type isEqual: @"set"] && ![type isEqual: @"result"] && ![type isEqual: @"error"]) @throw [OFInvalidArgumentException exception]; @@ -68,19 +63,18 @@ { XMPPIQ *ret = [XMPPIQ IQWithType: @"error" ID: self.ID]; void *pool = objc_autoreleasePoolPush(); OFXMLElement *error = [OFXMLElement elementWithName: @"error" - namespace: XMPP_NS_CLIENT]; + namespace: XMPPClientNS]; - [error addAttributeWithName: @"type" - stringValue: type]; + [error addAttributeWithName: @"type" stringValue: type]; [error addChild: [OFXMLElement elementWithName: condition - namespace: XMPP_NS_STANZAS]]; + namespace: XMPPStanzasNS]]; if (text) [error addChild: [OFXMLElement elementWithName: @"text" - namespace: XMPP_NS_STANZAS + namespace: XMPPStanzasNS stringValue: text]]; [ret addChild: error]; ret.to = self.from; ret.from = nil; @@ -87,13 +81,10 @@ objc_autoreleasePoolPop(pool); return ret; } -- (XMPPIQ *)errorIQWithType: (OFString *)type - condition: (OFString *)condition +- (XMPPIQ *)errorIQWithType: (OFString *)type condition: (OFString *)condition { - return [self errorIQWithType: type - condition: condition - text: nil]; + return [self errorIQWithType: type condition: condition text: nil]; } @end Index: src/XMPPMessage.m ================================================================== --- src/XMPPMessage.m +++ src/XMPPMessage.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2012, 2013, 2019, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2019, 2021, Jonathan Schleifer * Copyright (c) 2011, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -40,58 +40,50 @@ + (instancetype)messageWithType: (OFString *)type { return [[[self alloc] initWithType: type] autorelease]; } -+ (instancetype)messageWithType: (OFString *)type - ID: (OFString *)ID ++ (instancetype)messageWithType: (OFString *)type ID: (OFString *)ID { - return [[[self alloc] initWithType: type - ID: ID] autorelease]; + return [[[self alloc] initWithType: type ID: ID] autorelease]; } - (instancetype)init { - return [self initWithType: nil - ID: nil]; + return [self initWithType: nil ID: nil]; } - (instancetype)initWithID: (OFString *)ID { - return [self initWithType: nil - ID: ID]; + return [self initWithType: nil ID: ID]; } - (instancetype)initWithType: (OFString *)type { - return [self initWithType: type - ID: nil]; + return [self initWithType: type ID: nil]; } -- (instancetype)initWithType: (OFString *)type - ID: (OFString *)ID +- (instancetype)initWithType: (OFString *)type ID: (OFString *)ID { - return [super initWithName: @"message" - type: type - ID: ID]; + return [super initWithName: @"message" type: type ID: ID]; } - (void)setBody: (OFString *)body { OFXMLElement *oldBody = [self elementForName: @"body" - namespace: XMPP_NS_CLIENT]; + namespace: XMPPClientNS]; if (oldBody != nil) [self removeChild: oldBody]; if (body != nil) [self addChild: [OFXMLElement elementWithName: @"body" - namespace: XMPP_NS_CLIENT + namespace: XMPPClientNS stringValue: body]]; } - (OFString *)body { return [self elementForName: @"body" - namespace: XMPP_NS_CLIENT].stringValue; + namespace: XMPPClientNS].stringValue; } @end Index: src/XMPPMulticastDelegate.h ================================================================== --- src/XMPPMulticastDelegate.h +++ src/XMPPMulticastDelegate.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2012, Jonathan Schleifer + * Copyright (c) 2012, 2021, 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 @@ -52,12 +52,11 @@ * @brief Broadcasts a selector with an object to all registered delegates. * * @param selector The selector to broadcast * @param object The object to broadcast */ -- (bool)broadcastSelector: (SEL)selector - withObject: (nullable id)object; +- (bool)broadcastSelector: (SEL)selector withObject: (nullable id)object; /*! * @brief Broadcasts a selector with two objects to all registered delegates. * * @param selector The selector to broadcast Index: src/XMPPMulticastDelegate.m ================================================================== --- src/XMPPMulticastDelegate.m +++ src/XMPPMulticastDelegate.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2012, 2019, Jonathan Schleifer + * Copyright (c) 2012, 2019, 2021, 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 @@ -67,12 +67,11 @@ [_delegates removeItemAtIndex: i]; return; } } -- (bool)broadcastSelector: (SEL)selector - withObject: (id)object +- (bool)broadcastSelector: (SEL)selector withObject: (id)object { void *pool = objc_autoreleasePoolPush(); OFMutableData *currentDelegates = [[_delegates copy] autorelease]; id const *items = currentDelegates.items; size_t i, count = currentDelegates.count; Index: src/XMPPPresence.m ================================================================== --- src/XMPPPresence.m +++ src/XMPPPresence.m @@ -63,41 +63,33 @@ + (instancetype)presenceWithType: (OFString *)type { return [[[self alloc] initWithType: type] autorelease]; } -+ (instancetype)presenceWithType: (OFString *)type - ID: (OFString *)ID ++ (instancetype)presenceWithType: (OFString *)type ID: (OFString *)ID { - return [[[self alloc] initWithType: type - ID: ID] autorelease]; + return [[[self alloc] initWithType: type ID: ID] autorelease]; } - (instancetype)init { - return [self initWithType: nil - ID: nil]; + return [self initWithType: nil ID: nil]; } - (instancetype)initWithID: (OFString *)ID { - return [self initWithType: nil - ID: ID]; + return [self initWithType: nil ID: ID]; } - (instancetype)initWithType: (OFString *)type { - return [self initWithType: type - ID: nil]; + return [self initWithType: type ID: nil]; } -- (instancetype)initWithType: (OFString *)type - ID: (OFString *)ID +- (instancetype)initWithType: (OFString *)type ID: (OFString *)ID { - return [super initWithName: @"presence" - type: type - ID: ID]; + return [super initWithName: @"presence" type: type ID: ID]; } - (instancetype)initWithElement: (OFXMLElement *)element { self = [super initWithElement: element]; @@ -104,19 +96,19 @@ @try { OFXMLElement *subElement; if ((subElement = [element elementForName: @"show" - namespace: XMPP_NS_CLIENT])) + namespace: XMPPClientNS])) self.show = subElement.stringValue; if ((subElement = [element elementForName: @"status" - namespace: XMPP_NS_CLIENT])) + namespace: XMPPClientNS])) self.status = subElement.stringValue; if ((subElement = [element elementForName: @"priority" - namespace: XMPP_NS_CLIENT])) + namespace: XMPPClientNS])) self.priority = [OFNumber numberWithLongLong: [subElement longLongValueWithBase: 10]]; } @catch (id e) { [self release]; @throw e; @@ -135,19 +127,19 @@ } - (void)setShow: (OFString *)show { OFXMLElement *oldShow = [self elementForName: @"show" - namespace: XMPP_NS_CLIENT]; + namespace: XMPPClientNS]; OFString *old; if (oldShow != nil) [self removeChild: oldShow]; if (show != nil) [self addChild: [OFXMLElement elementWithName: @"show" - namespace: XMPP_NS_CLIENT + namespace: XMPPClientNS stringValue: show]]; old = _show; _show = [show copy]; [old release]; @@ -154,19 +146,19 @@ } - (void)setStatus: (OFString *)status { OFXMLElement *oldStatus = [self elementForName: @"status" - namespace: XMPP_NS_CLIENT]; + namespace: XMPPClientNS]; OFString *old; if (oldStatus != nil) [self removeChild: oldStatus]; if (status != nil) [self addChild: [OFXMLElement elementWithName: @"status" - namespace: XMPP_NS_CLIENT + namespace: XMPPClientNS stringValue: status]]; old = _status; _status = [status copy]; [old release]; @@ -179,19 +171,19 @@ if ((prio < -128) || (prio > 127)) @throw [OFInvalidArgumentException exception]; OFXMLElement *oldPriority = [self elementForName: @"priority" - namespace: XMPP_NS_CLIENT]; + namespace: XMPPClientNS]; if (oldPriority != nil) [self removeChild: oldPriority]; OFString *priority_s = [OFString stringWithFormat: @"%hhd", priority.charValue]; [self addChild: [OFXMLElement elementWithName: @"priority" - namespace: XMPP_NS_CLIENT + namespace: XMPPClientNS stringValue: priority_s]]; old = _priority; _priority = [priority copy]; [old release]; Index: src/XMPPRoster.m ================================================================== --- src/XMPPRoster.m +++ src/XMPPRoster.m @@ -1,7 +1,8 @@ /* - * Copyright (c) 2011, 2012, 2013, 2016, 2019, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2016, 2019, 2021, + * Jonathan Schleifer * Copyright (c) 2012, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -89,25 +90,23 @@ XMPPIQ *IQ; OFXMLElement *query; _rosterRequested = true; - IQ = [XMPPIQ IQWithType: @"get" - ID: [_connection generateStanzaID]]; + IQ = [XMPPIQ IQWithType: @"get" ID: [_connection generateStanzaID]]; query = [OFXMLElement elementWithName: @"query" - namespace: XMPP_NS_ROSTER]; + namespace: XMPPRosterNS]; if (_connection.supportsRosterVersioning) { OFString *ver = [_dataStorage stringValueForPath: @"roster.ver"]; if (ver == nil) ver = @""; - [query addAttributeWithName: @"ver" - stringValue: ver]; + [query addAttributeWithName: @"ver" stringValue: ver]; } [IQ addChild: query]; [_connection sendIQ: IQ @@ -114,20 +113,18 @@ callbackTarget: self selector: @selector(xmpp_handleInitialRosterForConnection: IQ:)]; } -- (bool)connection: (XMPPConnection *)connection - didReceiveIQ: (XMPPIQ *)IQ +- (bool)connection: (XMPPConnection *)connection didReceiveIQ: (XMPPIQ *)IQ { OFXMLElement *rosterElement; OFXMLElement *element; XMPPRosterItem *rosterItem; OFString *origin; - rosterElement = [IQ elementForName: @"query" - namespace: XMPP_NS_ROSTER]; + rosterElement = [IQ elementForName: @"query" namespace: XMPPRosterNS]; if (rosterElement == nil) return false; if (![IQ.type isEqual: @"set"]) @@ -137,11 +134,11 @@ origin = IQ.from.fullJID; if (origin != nil && ![origin isEqual: connection.JID.bareJID]) return false; element = [rosterElement elementForName: @"item" - namespace: XMPP_NS_ROSTER]; + namespace: XMPPRosterNS]; if (element != nil) { rosterItem = [self xmpp_rosterItemWithXMLElement: element]; [_delegates broadcastSelector: @selector( @@ -153,12 +150,11 @@ } if (_connection.supportsRosterVersioning) { OFString *ver = [rosterElement attributeForName: @"ver"].stringValue; - [_dataStorage setStringValue: ver - forPath: @"roster.ver"]; + [_dataStorage setStringValue: ver forPath: @"roster.ver"]; [_dataStorage save]; } [connection sendStanza: [IQ resultIQ]]; @@ -173,23 +169,22 @@ - (void)updateRosterItem: (XMPPRosterItem *)rosterItem { XMPPIQ *IQ = [XMPPIQ IQWithType: @"set" ID: [_connection generateStanzaID]]; OFXMLElement *query = [OFXMLElement elementWithName: @"query" - namespace: XMPP_NS_ROSTER]; + namespace: XMPPRosterNS]; OFXMLElement *item = [OFXMLElement elementWithName: @"item" - namespace: XMPP_NS_ROSTER]; + namespace: XMPPRosterNS]; - [item addAttributeWithName: @"jid" - stringValue: rosterItem.JID.bareJID]; + [item addAttributeWithName: @"jid" stringValue: rosterItem.JID.bareJID]; if (rosterItem.name != nil) [item addAttributeWithName: @"name" stringValue: rosterItem.name]; for (OFString *group in rosterItem.groups) [item addChild: [OFXMLElement elementWithName: @"group" - namespace: XMPP_NS_ROSTER + namespace: XMPPRosterNS stringValue: group]]; [query addChild: item]; [IQ addChild: query]; @@ -199,18 +194,16 @@ - (void)deleteRosterItem: (XMPPRosterItem *)rosterItem { XMPPIQ *IQ = [XMPPIQ IQWithType: @"set" ID: [_connection generateStanzaID]]; OFXMLElement *query = [OFXMLElement elementWithName: @"query" - namespace: XMPP_NS_ROSTER]; + namespace: XMPPRosterNS]; OFXMLElement *item = [OFXMLElement elementWithName: @"item" - namespace: XMPP_NS_ROSTER]; + namespace: XMPPRosterNS]; - [item addAttributeWithName: @"jid" - stringValue: rosterItem.JID.bareJID]; - [item addAttributeWithName: @"subscription" - stringValue: @"remove"]; + [item addAttributeWithName: @"jid" stringValue: rosterItem.JID.bareJID]; + [item addAttributeWithName: @"subscription" stringValue: @"remove"]; [query addChild: item]; [IQ addChild: query]; [_connection sendStanza: IQ]; @@ -257,17 +250,15 @@ if ([rosterItem groups] != nil) [item setObject: rosterItem.groups forKey: @"groups"]; - [items setObject: item - forKey: rosterItem.JID.bareJID]; + [items setObject: item forKey: rosterItem.JID.bareJID]; } else [items removeObjectForKey: rosterItem.JID.bareJID]; - [_dataStorage setDictionary: items - forPath: @"roster.items"]; + [_dataStorage setDictionary: items forPath: @"roster.items"]; } if (![rosterItem.subscription isEqual: @"remove"]) [_rosterItems setObject: rosterItem forKey: rosterItem.JID.bareJID]; @@ -294,12 +285,11 @@ subscription = @"none"; rosterItem.subscription = subscription; for (OFXMLElement *groupElement in - [element elementsForName: @"group" - namespace: XMPP_NS_ROSTER]) + [element elementsForName: @"group" namespace: XMPPRosterNS]) [groups addObject: groupElement.stringValue]; if (groups.count > 0) rosterItem.groups = groups; @@ -308,11 +298,11 @@ - (void)xmpp_handleInitialRosterForConnection: (XMPPConnection *)connection IQ: (XMPPIQ *)IQ { OFXMLElement *rosterElement = [IQ elementForName: @"query" - namespace: XMPP_NS_ROSTER]; + namespace: XMPPRosterNS]; if (connection.supportsRosterVersioning) { if (rosterElement == nil) { for (OFDictionary *item in [_dataStorage dictionaryForPath: @"roster.items"]) { @@ -340,11 +330,11 @@ for (OFXMLElement *element in rosterElement.children) { void *pool = objc_autoreleasePoolPush(); XMPPRosterItem *rosterItem; if (![element.name isEqual: @"item"] || - ![element.namespace isEqual: XMPP_NS_ROSTER]) + ![element.namespace isEqual: XMPPRosterNS]) continue; rosterItem = [self xmpp_rosterItemWithXMLElement: element]; [self xmpp_updateRosterItem: rosterItem]; @@ -353,14 +343,13 @@ } if (connection.supportsRosterVersioning && rosterElement != nil) { OFString *ver = [rosterElement attributeForName: @"ver"].stringValue; - [_dataStorage setStringValue: ver - forPath: @"roster.ver"]; + [_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 @@ -35,12 +35,11 @@ #define HMAC_IPAD 0x36 #define HMAC_OPAD 0x5c @interface XMPPSCRAMAuth () - (OFString *)xmpp_genNonce; -- (const uint8_t *)xmpp_HMACWithKey: (OFData *)key - data: (OFData *)data; +- (const uint8_t *)xmpp_HMACWithKey: (OFData *)key data: (OFData *)data; - (OFData *)xmpp_hiWithData: (OFData *)str salt: (OFData *)salt iterationCount: (intmax_t)i; - (OFData *)xmpp_parseServerFirstMessage: (OFData *)data; - (OFData *)xmpp_parseServerFinalMessage: (OFData *)data; @@ -135,14 +134,12 @@ { OFString *old = _authzid; if (authzid) { OFMutableString *new = [[authzid mutableCopy] autorelease]; - [new replaceOccurrencesOfString: @"=" - withString: @"=3D"]; - [new replaceOccurrencesOfString: @"," - withString: @"=2C"]; + [new replaceOccurrencesOfString: @"=" withString: @"=3D"]; + [new replaceOccurrencesOfString: @"," withString: @"=2C"]; [new makeImmutable]; _authzid = [new copy]; } else _authzid = nil; @@ -153,14 +150,12 @@ { OFString *old = _authcid; if (authcid) { OFMutableString *new = [[authcid mutableCopy] autorelease]; - [new replaceOccurrencesOfString: @"=" - withString: @"=3D"]; - [new replaceOccurrencesOfString: @"," - withString: @"=2C"]; + [new replaceOccurrencesOfString: @"=" withString: @"=3D"]; + [new replaceOccurrencesOfString: @"," withString: @"=2C"]; [new makeImmutable]; _authcid = [new copy]; } else _authcid = nil; @@ -279,21 +274,17 @@ channelBindingDataWithType: @"tls-unique"]; [tmpArray addItems: channelBinding.items count: channelBinding.count]; } tmpString = tmpArray.stringByBase64Encoding; - [ret addItems: "c=" - count: 2]; - [ret addItems: tmpString.UTF8String - count: tmpString.UTF8StringLength]; + [ret addItems: "c=" count: 2]; + [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: "r=" count: 2]; + [ret addItems: sNonce.UTF8String count: sNonce.UTF8StringLength]; /* * IETF RFC 5802: * SaltedPassword := Hi(Normalize(password), salt, i) */ @@ -310,23 +301,21 @@ * client-final-message-without-proof */ [authMessage addItems: _clientFirstMessageBare.UTF8String count: _clientFirstMessageBare.UTF8StringLength]; [authMessage addItem: ","]; - [authMessage addItems: data.items - count: data.count * data.itemSize]; + [authMessage addItems: data.items count: data.count * data.itemSize]; [authMessage addItem: ","]; - [authMessage addItems: ret.items - count: ret.count]; + [authMessage addItems: ret.items count: ret.count]; /* * IETF RFC 5802: * ClientKey := HMAC(SaltedPassword, "Client Key") */ - clientKey = [self xmpp_HMACWithKey: saltedPassword - data: [OFData dataWithItems: "Client Key" - count: 10]]; + clientKey = [self + xmpp_HMACWithKey: saltedPassword + data: [OFData dataWithItems: "Client Key" count: 10]]; /* * IETF RFC 5802: * StoredKey := H(ClientKey) */ @@ -344,13 +333,13 @@ /* * IETF RFC 5802: * ServerKey := HMAC(SaltedPassword, "Server Key") */ - serverKey = [self xmpp_HMACWithKey: saltedPassword - data: [OFData dataWithItems: "Server Key" - count: 10]]; + serverKey = [self + xmpp_HMACWithKey: saltedPassword + data: [OFData dataWithItems: "Server Key" count: 10]]; /* * IETF RFC 5802: * ServerSignature := HMAC(ServerKey, AuthMessage) */ @@ -357,12 +346,11 @@ tmpArray = [OFMutableData dataWithItems: serverKey count: [_hashType digestSize]]; [_serverSignature release]; _serverSignature = [[OFData alloc] - initWithItems: [self xmpp_HMACWithKey: tmpArray - data: authMessage] + initWithItems: [self xmpp_HMACWithKey: tmpArray data: authMessage] count: [_hashType digestSize]]; /* * IETF RFC 5802: * ClientProof := ClientKey XOR ClientSignature @@ -373,15 +361,13 @@ [tmpArray addItem: &c]; } // Add p= [ret addItem: ","]; - [ret addItems: "p=" - count: 2]; + [ret addItems: "p=" count: 2]; tmpString = tmpArray.stringByBase64Encoding; - [ret addItems: tmpString.UTF8String - count: tmpString.UTF8StringLength]; + [ret addItems: tmpString.UTF8String count: tmpString.UTF8StringLength]; return ret; } - (OFData *)xmpp_parseServerFinalMessage: (OFData *)data @@ -445,15 +431,13 @@ 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: hashI.digestSize]; + [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 = OFAllocMemory(1, blockSize); kO = OFAllocMemory(1, blockSize); @@ -506,37 +490,33 @@ salty = [[salt mutableCopy] autorelease]; [salty addItems: "\0\0\0\1" count: 4]; - uOld = [self xmpp_HMACWithKey: str - data: salty]; + uOld = [self xmpp_HMACWithKey: str data: salty]; for (j = 0; j < digestSize; j++) result[j] ^= uOld[j]; for (j = 0; j < i - 1; j++) { tmp = [[OFMutableData alloc] init]; - [tmp addItems: uOld - count: digestSize]; + [tmp addItems: uOld count: digestSize]; /* releases uOld and previous tmp */ objc_autoreleasePoolPop(pool); pool = objc_autoreleasePoolPush(); [tmp autorelease]; - u = [self xmpp_HMACWithKey: str - data: tmp]; + u = [self xmpp_HMACWithKey: str data: tmp]; for (k = 0; k < digestSize; k++) result[k] ^= u[k]; uOld = u; } - ret = [OFData dataWithItems: result - count: digestSize]; + ret = [OFData dataWithItems: result count: digestSize]; } @finally { OFFreeMemory(result); } [ret retain]; Index: src/XMPPStanza.h ================================================================== --- src/XMPPStanza.h +++ src/XMPPStanza.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2012, 2013, 2016, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2016, 2021, Jonathan Schleifer * Copyright (c) 2011, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -85,12 +85,11 @@ * * @param name The stanza's name (one of iq, message or presence) * @param ID The value for the stanza's id attribute * @return A new autoreleased XMPPStanza */ -+ (instancetype)stanzaWithName: (OFString *)name - ID: (nullable OFString *)ID; ++ (instancetype)stanzaWithName: (OFString *)name ID: (nullable OFString *)ID; /*! * @brief Creates a new autoreleased XMPPStanza with the specified name, type * and ID. * @@ -135,23 +134,21 @@ * * @param name The stanza's name (one of iq, message or presence) * @param type The value for the stanza's type attribute * @return A initialized XMPPStanza */ -- (instancetype)initWithName: (OFString *)name - type: (nullable OFString *)type; +- (instancetype)initWithName: (OFString *)name type: (nullable OFString *)type; /*! * @brief Initializes an already allocated XMPPStanza with the specified name * and ID. * * @param name The stanza's name (one of iq, message or presence) * @param ID The value for the stanza's id attribute * @return A initialized XMPPStanza */ -- (instancetype)initWithName: (OFString *)name - ID: (nullable OFString *)ID; +- (instancetype)initWithName: (OFString *)name ID: (nullable OFString *)ID; /*! * @brief Initializes an already allocated XMPPStanza with the specified name, * type and ID. * Index: src/XMPPStanza.m ================================================================== --- src/XMPPStanza.m +++ src/XMPPStanza.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, 2012, 2013, 2019, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2019, 2021, Jonathan Schleifer * Copyright (c) 2011, Florian Zeitz * * https://heap.zone/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any @@ -34,22 +34,18 @@ + (instancetype)stanzaWithName: (OFString *)name { return [[[self alloc] initWithName: name] autorelease]; } -+ (instancetype)stanzaWithName: (OFString *)name - type: (OFString *)type ++ (instancetype)stanzaWithName: (OFString *)name type: (OFString *)type { - return [[[self alloc] initWithName: name - type: type] autorelease]; + return [[[self alloc] initWithName: name type: type] autorelease]; } -+ (instancetype)stanzaWithName: (OFString *)name - ID: (OFString *)ID ++ (instancetype)stanzaWithName: (OFString *)name ID: (OFString *)ID { - return [[[self alloc] initWithName: name - ID: ID] autorelease]; + return [[[self alloc] initWithName: name ID: ID] autorelease]; } + (instancetype)stanzaWithName: (OFString *)name type: (OFString *)type ID: (OFString *)ID @@ -68,12 +64,11 @@ stringValue: (OFString *)stringValue { OF_INVALID_INIT_METHOD } -- (instancetype)initWithName: (OFString *)name - namespace: (OFString *)namespace +- (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name @@ -93,47 +88,39 @@ OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name { - return [self initWithName: name - type: nil - ID: nil]; + return [self initWithName: name type: nil ID: nil]; } -- (instancetype)initWithName: (OFString *)name - type: (OFString *)type +- (instancetype)initWithName: (OFString *)name type: (OFString *)type { - return [self initWithName: name - type: type - ID: nil]; + return [self initWithName: name type: type ID: nil]; } - (instancetype)initWithName: (OFString *)name ID: (OFString *)ID { - return [self initWithName: name - type: nil - ID: ID]; + return [self initWithName: name type: nil ID: ID]; } - (instancetype)initWithName: (OFString *)name type: (OFString *)type ID: (OFString *)ID { self = [super initWithName: name - namespace: XMPP_NS_CLIENT + namespace: XMPPClientNS stringValue: nil]; @try { if (![name isEqual: @"iq"] && ![name isEqual: @"message"] && ![name isEqual: @"presence"]) @throw [OFInvalidArgumentException exception]; - self.defaultNamespace = XMPP_NS_CLIENT; - [self setPrefix: @"stream" - forNamespace: XMPP_NS_STREAM]; + self.defaultNamespace = XMPPClientNS; + [self setPrefix: @"stream" forNamespace: XMPPStreamNS]; if (type != nil) self.type = type; if (ID != nil) @@ -191,12 +178,11 @@ [old release]; [self removeAttributeForName: @"from"]; if (from != nil) - [self addAttributeWithName: @"from" - stringValue: from.fullJID]; + [self addAttributeWithName: @"from" stringValue: from.fullJID]; } - (void)setTo: (XMPPJID *)to { XMPPJID *old = _to; @@ -204,12 +190,11 @@ [old release]; [self removeAttributeForName: @"to"]; if (to != nil) - [self addAttributeWithName: @"to" - stringValue: to.fullJID]; + [self addAttributeWithName: @"to" stringValue: to.fullJID]; } - (void)setType: (OFString *)type { OFString *old = _type; @@ -217,12 +202,11 @@ [old release]; [self removeAttributeForName: @"type"]; if (type != nil) - [self addAttributeWithName: @"type" - stringValue: type]; + [self addAttributeWithName: @"type" stringValue: type]; } - (void)setID: (OFString *)ID { OFString *old = _ID; @@ -230,12 +214,11 @@ [old release]; [self removeAttributeForName: @"id"]; if (ID != nil) - [self addAttributeWithName: @"id" - stringValue: ID]; + [self addAttributeWithName: @"id" stringValue: ID]; } - (void)setLanguage: (OFString *)language { OFString *old = _language; Index: src/XMPPStorage.h ================================================================== --- src/XMPPStorage.h +++ src/XMPPStorage.h @@ -28,21 +28,17 @@ @class OFArray; @class OFDictionary; @protocol XMPPStorage - (void)save; -- (void)setStringValue: (nullable OFString *)string - forPath: (OFString *)path; +- (void)setStringValue: (nullable OFString *)string forPath: (OFString *)path; - (nullable OFString *)stringValueForPath: (OFString *)path; -- (void)setBooleanValue: (bool)boolean - forPath: (OFString *)path; +- (void)setBooleanValue: (bool)boolean forPath: (OFString *)path; - (bool)booleanValueForPath: (OFString *)path; -- (void)setIntegerValue: (long long)integer - forPath: (OFString *)path; +- (void)setIntegerValue: (long long)integer forPath: (OFString *)path; - (long long)integerValueForPath: (OFString *)path; -- (void)setArray: (nullable OFArray *)array - forPath: (OFString *)path; +- (void)setArray: (nullable OFArray *)array forPath: (OFString *)path; - (nullable OFArray *)arrayForPath: (OFString *)path; - (void)setDictionary: (nullable OFDictionary *)dictionary forPath: (OFString *)path; - (nullable OFDictionary *)dictionaryForPath: (OFString *)path; @end Index: src/XMPPStreamManagement.m ================================================================== --- src/XMPPStreamManagement.m +++ src/XMPPStreamManagement.m @@ -1,8 +1,8 @@ /* * Copyright (c) 2012, Florian Zeitz - * Copyright (c) 2019, Jonathan Schleifer + * Copyright (c) 2019, 2021, 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 @@ -58,11 +58,11 @@ didReceiveElement: (OFXMLElement *)element { OFString *elementName = element.name; OFString *elementNS = element.namespace; - if ([elementNS isEqual: XMPP_NS_SM]) { + if ([elementNS isEqual: XMPPSMNS]) { if ([elementName isEqual: @"enabled"]) { _receivedCount = 0; return; } @@ -72,20 +72,20 @@ } if ([elementName isEqual: @"r"]) { OFXMLElement *ack = [OFXMLElement elementWithName: @"a" - namespace: XMPP_NS_SM]; + namespace: XMPPSMNS]; OFString *stringValue = [OFString stringWithFormat: @"%" PRIu32, _receivedCount]; [ack addAttributeWithName: @"h" stringValue: stringValue]; [connection sendStanza: ack]; } } - if ([elementNS isEqual: XMPP_NS_CLIENT] && + if ([elementNS isEqual: XMPPClientNS] && ([elementName isEqual: @"iq"] || [elementName isEqual: @"presence"] || [elementName isEqual: @"message"])) _receivedCount++; } @@ -95,14 +95,13 @@ didSendElement: (OFXMLElement *)element { } */ -- (void)connection: (XMPPConnection *)connection - wasBoundToJID: (XMPPJID *)JID +- (void)connection: (XMPPConnection *)connection wasBoundToJID: (XMPPJID *)JID { if (connection.supportsStreamManagement) [connection sendStanza: [OFXMLElement elementWithName: @"enable" - namespace: XMPP_NS_SM]]; + namespace: XMPPSMNS]]; } @end Index: src/XMPPXMLElementBuilder.m ================================================================== --- src/XMPPXMLElementBuilder.m +++ src/XMPPXMLElementBuilder.m @@ -1,7 +1,7 @@ /* - * Copyright (c) 2012, Jonathan Schleifer + * Copyright (c) 2012, 2021, 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 @@ -31,11 +31,10 @@ foundProcessingInstructions: (OFString *)pi { @throw [OFMalformedXMLException exception]; } -- (void)parser: (OFXMLParser *)parser - foundComment: (OFString *)comment +- (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment { @throw [OFMalformedXMLException exception]; } @end Index: src/namespaces.h ================================================================== --- src/namespaces.h +++ src/namespaces.h @@ -1,7 +1,7 @@ /* - * Copyright (c) 2011, Jonathan Schleifer + * Copyright (c) 2011, 2021, 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 @@ -18,20 +18,20 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#define XMPP_NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind" -#define XMPP_NS_CAPS @"http://jabber.org/protocol/caps" -#define XMPP_NS_CLIENT @"jabber:client" -#define XMPP_NS_DISCO_INFO @"http://jabber.org/protocol/disco#info" -#define XMPP_NS_DISCO_ITEMS @"http://jabber.org/protocol/disco#items" -#define XMPP_NS_MUC @"http://jabber.org/protocol/muc" -#define XMPP_NS_ROSTER @"jabber:iq:roster" -#define XMPP_NS_ROSTERVER @"urn:xmpp:features:rosterver" -#define XMPP_NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl" -#define XMPP_NS_SESSION @"urn:ietf:params:xml:ns:xmpp-session" -#define XMPP_NS_SM @"urn:xmpp:sm:3" -#define XMPP_NS_STANZAS @"urn:ietf:params:xml:ns:xmpp-stanzas" -#define XMPP_NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls" -#define XMPP_NS_STREAM @"http://etherx.jabber.org/streams" -#define XMPP_NS_XMPP_STREAM @"urn:ietf:params:xml:ns:xmpp-streams" +#define XMPPBindNS @"urn:ietf:params:xml:ns:xmpp-bind" +#define XMPPCapsNS @"http://jabber.org/protocol/caps" +#define XMPPClientNS @"jabber:client" +#define XMPPDiscoInfoNS @"http://jabber.org/protocol/disco#info" +#define XMPPDiscoItemsNS @"http://jabber.org/protocol/disco#items" +#define XMPPMUCNS @"http://jabber.org/protocol/muc" +#define XMPPRosterNS @"jabber:iq:roster" +#define XMPPRosterVerNS @"urn:xmpp:features:rosterver" +#define XMPPSASLNS @"urn:ietf:params:xml:ns:xmpp-sasl" +#define XMPPSessionNS @"urn:ietf:params:xml:ns:xmpp-session" +#define XMPPSMNS @"urn:xmpp:sm:3" +#define XMPPStanzasNS @"urn:ietf:params:xml:ns:xmpp-stanzas" +#define XMPPStartTLSNS @"urn:ietf:params:xml:ns:xmpp-tls" +#define XMPPStreamNS @"http://etherx.jabber.org/streams" +#define XMPPXMPPStreamNS @"urn:ietf:params:xml:ns:xmpp-streams" Index: tests/test.m ================================================================== --- tests/test.m +++ tests/test.m @@ -79,27 +79,22 @@ assert([msg.XMLString isEqual: @"Hello everyone" @""]); - XMPPIQ *IQ = [XMPPIQ IQWithType: @"set" - ID: @"128"]; + XMPPIQ *IQ = [XMPPIQ IQWithType: @"set" ID: @"128"]; IQ.to = [XMPPJID JIDWithString: @"juliet@capulet.lit"]; IQ.from = [XMPPJID JIDWithString: @"romeo@montague.lit"]; assert([IQ.XMLString isEqual: @""]); OFXMLElement *elem = [OFXMLElement elementWithName: @"iq"]; - [elem addAttributeWithName: @"from" - stringValue: @"bob@localhost"]; - [elem addAttributeWithName: @"to" - stringValue: @"alice@localhost"]; - [elem addAttributeWithName: @"type" - stringValue: @"get"]; - [elem addAttributeWithName: @"id" - stringValue: @"42"]; + [elem addAttributeWithName: @"from" stringValue: @"bob@localhost"]; + [elem addAttributeWithName: @"to" stringValue: @"alice@localhost"]; + [elem addAttributeWithName: @"type" stringValue: @"get"]; + [elem addAttributeWithName: @"id" stringValue: @"42"]; XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem]; 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"])); @@ -145,12 +140,11 @@ - (void)connectionWasAuthenticated: (XMPPConnection *)conn { OFLog(@"Auth successful"); } -- (void)connection: (XMPPConnection *)conn_ - wasBoundToJID: (XMPPJID *)JID +- (void)connection: (XMPPConnection *)conn_ wasBoundToJID: (XMPPJID *)JID { OFLog(@"Bound to JID: %@", JID.fullJID); OFLog(@"Supports SM: %@", conn_.supportsStreamManagement ? @"true" : @"false"); @@ -210,16 +204,14 @@ pres.status = @"ObjXMPP test is working!"; [conn sendStanza: pres]; #ifdef OF_HAVE_BLOCKS - XMPPIQ *IQ = [XMPPIQ IQWithType: @"get" - ID: [conn generateStanzaID]]; + XMPPIQ *IQ = [XMPPIQ IQWithType: @"get" ID: [conn generateStanzaID]]; [IQ addChild: [OFXMLElement elementWithName: @"ping" namespace: @"urn:xmpp:ping"]]; - [conn sendIQ: IQ - callbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) { + [conn sendIQ: IQ callbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) { OFLog(@"Ping response: %@", resp); }]; #endif } @@ -241,20 +233,18 @@ didReceiveRosterItem: (XMPPRosterItem *)rosterItem { OFLog(@"Got roster push: %@", rosterItem); } -- (bool)connection: (XMPPConnection *)conn - didReceiveIQ: (XMPPIQ *)iq +- (bool)connection: (XMPPConnection *)conn didReceiveIQ: (XMPPIQ *)iq { OFLog(@"IQ: %@", iq); return NO; } -- (void)connection: (XMPPConnection *)conn - didReceiveMessage: (XMPPMessage *)msg +- (void)connection: (XMPPConnection *)conn didReceiveMessage: (XMPPMessage *)msg { OFLog(@"Message: %@", msg); } - (void)connection: (XMPPConnection *)conn @@ -261,17 +251,15 @@ didReceivePresence: (XMPPPresence *)pres { OFLog(@"Presence: %@", pres); } -- (void)connection: (XMPPConnection *)conn - didThrowException: (id)e +- (void)connection: (XMPPConnection *)conn didThrowException: (id)e { @throw e; } -- (void)connectionWasClosed: (XMPPConnection *)conn - error: (OFXMLElement *)error +- (void)connectionWasClosed: (XMPPConnection *)conn error: (OFXMLElement *)error { OFLog(@"Connection was closed: %@", error); } @end