From 851e7fe6769aee85cde058dfea24111ad70404e1 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Wed, 28 Apr 2021 23:20:55 +0000 Subject: [PATCH] Adjust to ObjFW changes FossilOrigin-Name: 46f67c971bc57abd330349d54d237931079a832baaf20909e77039f6ce4b896d --- src/XMPPConnection.m | 12 +++++------ src/XMPPContactManager.m | 3 +-- src/XMPPDiscoEntity.m | 5 ++--- src/XMPPDiscoIdentity.m | 27 ++++++++++++------------ src/XMPPFileStorage.m | 14 ++++++------- src/XMPPJID.m | 24 +++++++++++----------- src/XMPPPresence.m | 31 ++++++++++++++-------------- src/XMPPSCRAMAuth.m | 37 ++++++++++++++++----------------- src/XMPPStorage.h | 6 +++--- tests/test.m | 44 ++++++++++++++++++++-------------------- 10 files changed, 99 insertions(+), 104 deletions(-) diff --git a/src/XMPPConnection.m b/src/XMPPConnection.m index f7a410b..97513d1 100644 --- a/src/XMPPConnection.m +++ b/src/XMPPConnection.m @@ -1,6 +1,6 @@ /* - * Copyright (c) 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018, 2019 - * Jonathan Schleifer + * Copyright (c) 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2021 + * Jonathan Schleifer * Copyright (c) 2011, 2012, Florian Zeitz * * https://heap.zone/objxmpp/ @@ -344,8 +344,8 @@ stringByPrependingString: @"_xmpp-client._tcp."]; OFDNSQuery *query = [OFDNSQuery queryWithDomainName: SRVDomain - DNSClass: OF_DNS_CLASS_IN - recordType: OF_DNS_RECORD_TYPE_SRV]; + DNSClass: OFDNSClassIN + recordType: OFDNSRecordTypeSRV]; [[OFThread DNSResolver] asyncPerformQuery: query delegate: self]; } @@ -753,7 +753,7 @@ withObject: self]; newSock = [[SSLSocket alloc] initWithSocket: _socket]; - newSock.certificateVerificationEnabled = false; + newSock.verifiesCertificates = false; #if 0 /* FIXME: Not yet implemented by ObjOpenSSL */ [newSock setCertificateFile: _certificateFile]; @@ -1084,7 +1084,7 @@ IQ: (XMPPIQ *)IQ { if (![IQ.type isEqual: @"result"]) - OF_ENSURE(0); + OFEnsure(0); [_delegates broadcastSelector: @selector(connection:wasBoundToJID:) withObject: self diff --git a/src/XMPPContactManager.m b/src/XMPPContactManager.m index 1e56a99..ad257a1 100644 --- a/src/XMPPContactManager.m +++ b/src/XMPPContactManager.m @@ -1,6 +1,6 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, 2021, Jonathan Schleifer * * https://heap.zone/objxmpp/ * @@ -161,7 +161,6 @@ /* Subscription request */ if ([type isEqual: @"subscribe"]) { - of_log(@"ObjXMPP: received subscription request"); [_delegates broadcastSelector: @selector(contactManager: didReceiveSubscriptionRequest:) withObject: self diff --git a/src/XMPPDiscoEntity.m b/src/XMPPDiscoEntity.m index 062d29e..5dfaa3e 100644 --- a/src/XMPPDiscoEntity.m +++ b/src/XMPPDiscoEntity.m @@ -1,6 +1,6 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, 2021, Jonathan Schleifer * * https://heap.zone/objxmpp/ * @@ -114,8 +114,7 @@ - (OFString *)capsHash { OFMutableString *caps = [OFMutableString string]; - OFSHA1Hash *hash = [OFSHA1Hash - cryptoHashWithAllowsSwappableMemory: true]; + OFSHA1Hash *hash = [OFSHA1Hash hashWithAllowsSwappableMemory: true]; OFData *digest; for (XMPPDiscoIdentity *identity in _identities) diff --git a/src/XMPPDiscoIdentity.m b/src/XMPPDiscoIdentity.m index 10177f4..7988066 100644 --- a/src/XMPPDiscoIdentity.m +++ b/src/XMPPDiscoIdentity.m @@ -1,6 +1,6 @@ /* * Copyright (c) 2013, Florian Zeitz - * Copyright (c) 2013, 2016, 2019, Jonathan Schleifer + * Copyright (c) 2013, 2016, 2019, 2021, Jonathan Schleifer * * https://heap.zone/objxmpp/ * @@ -105,29 +105,28 @@ return false; } -- (uint32_t)hash +- (unsigned long)hash { - uint32_t hash; + unsigned long hash; - OF_HASH_INIT(hash); + OFHashInit(&hash); - OF_HASH_ADD_HASH(hash, _category.hash); - OF_HASH_ADD_HASH(hash, _type.hash); - OF_HASH_ADD_HASH(hash, _name.hash); + OFHashAddHash(&hash, _category.hash); + OFHashAddHash(&hash, _type.hash); + OFHashAddHash(&hash, _name.hash); - OF_HASH_FINALIZE(hash); + OFHashFinalize(&hash); return hash; } -- (of_comparison_result_t)compare: (id )object +- (OFComparisonResult)compare: (id )object { XMPPDiscoIdentity *identity; - of_comparison_result_t categoryResult; - of_comparison_result_t typeResult; + OFComparisonResult categoryResult, typeResult; if (object == self) - return OF_ORDERED_SAME; + return OFOrderedSame; if (![(id)object isKindOfClass: [XMPPDiscoIdentity class]]) @throw [OFInvalidArgumentException exception]; @@ -135,11 +134,11 @@ identity = (XMPPDiscoIdentity *)object; categoryResult = [_category compare: identity->_category]; - if (categoryResult != OF_ORDERED_SAME) + if (categoryResult != OFOrderedSame) return categoryResult; typeResult = [_type compare: identity->_type]; - if (typeResult != OF_ORDERED_SAME) + if (typeResult != OFOrderedSame) return typeResult; return [_name compare: identity->_name]; diff --git a/src/XMPPFileStorage.m b/src/XMPPFileStorage.m index ed27952..0422be1 100644 --- a/src/XMPPFileStorage.m +++ b/src/XMPPFileStorage.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Jonathan Schleifer + * Copyright (c) 2012, 2019, 2021, Jonathan Schleifer * * https://heap.zone/objxmpp/ * @@ -50,7 +50,7 @@ _file = [file copy]; @try { _data = [[OFData dataWithContentsOfFile: file] - .messagePackValue copy]; + .objectByParsingMessagePack copy]; } @catch (id e) { _data = [[OFMutableDictionary alloc] init]; } @@ -162,23 +162,23 @@ return boolean; } -- (void)setIntegerValue: (intmax_t)integer +- (void)setIntegerValue: (long long)integer forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - [self xmpp_setObject: [OFNumber numberWithIntMax: integer] + [self xmpp_setObject: [OFNumber numberWithLongLong: integer] forPath: path]; objc_autoreleasePoolPop(pool); } -- (intmax_t)integerValueForPath: (OFString *)path +- (long long)integerValueForPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); - intmax_t integer; + long long integer; - integer = [[self xmpp_objectForPath: path] intMaxValue]; + integer = [[self xmpp_objectForPath: path] longLongValue]; objc_autoreleasePoolPop(pool); diff --git a/src/XMPPJID.m b/src/XMPPJID.m index 6b1b2d3..4e96b8c 100644 --- a/src/XMPPJID.m +++ b/src/XMPPJID.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2019, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2019, 2021, Jonathan Schleifer * Copyright (c) 2011, 2012, 2013, Florian Zeitz * * https://heap.zone/objxmpp/ @@ -59,20 +59,20 @@ if (nodesep == SIZE_MAX) self.node = nil; else - self.node = - [string substringWithRange: of_range(0, nodesep)]; + self.node = [string substringWithRange: + OFRangeMake(0, nodesep)]; if (resourcesep == SIZE_MAX) { self.resource = nil; resourcesep = string.length; } else { - of_range_t range = of_range(resourcesep + 1, + OFRange range = OFRangeMake(resourcesep + 1, string.length - resourcesep - 1); self.resource = [string substringWithRange: range]; } self.domain = [string substringWithRange: - of_range(nodesep + 1, resourcesep - nodesep - 1)]; + OFRangeMake(nodesep + 1, resourcesep - nodesep - 1)]; } @catch (id e) { [self release]; @throw e; @@ -235,17 +235,17 @@ return false; } -- (uint32_t)hash +- (unsigned long)hash { - uint32_t hash; + unsigned long hash; - OF_HASH_INIT(hash); + OFHashInit(&hash); - OF_HASH_ADD_HASH(hash, _node.hash); - OF_HASH_ADD_HASH(hash, _domain.hash); - OF_HASH_ADD_HASH(hash, _resource.hash); + OFHashAddHash(&hash, _node.hash); + OFHashAddHash(&hash, _domain.hash); + OFHashAddHash(&hash, _resource.hash); - OF_HASH_FINALIZE(hash); + OFHashFinalize(&hash); return hash; } diff --git a/src/XMPPPresence.m b/src/XMPPPresence.m index 45b4ee0..1ba8807 100644 --- a/src/XMPPPresence.m +++ b/src/XMPPPresence.m @@ -1,5 +1,6 @@ /* - * Copyright (c) 2011, 2012, 2013, 2016, 2019, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, 2016, 2019, 2021, + * Jonathan Schleifer * Copyright (c) 2011, 2012, 2013, Florian Zeitz * * https://heap.zone/objxmpp/ @@ -43,7 +44,7 @@ showToInt(OFString *show) if ([show isEqual: @"xa"]) return 4; - OF_ENSURE(0); + OFEnsure(0); } @implementation XMPPPresence @@ -114,8 +115,8 @@ showToInt(OFString *show) if ((subElement = [element elementForName: @"priority" namespace: XMPP_NS_CLIENT])) - self.priority = [OFNumber - numberWithIntMax: subElement.decimalValue]; + self.priority = [OFNumber numberWithLongLong: + [subElement longLongValueWithBase: 10]]; } @catch (id e) { [self release]; @throw e; @@ -173,7 +174,7 @@ showToInt(OFString *show) - (void)setPriority: (OFNumber *)priority { - intmax_t prio = priority.intMaxValue; + long long prio = priority.longLongValue; OFNumber *old; if ((prio < -128) || (prio > 127)) @@ -186,7 +187,7 @@ showToInt(OFString *show) [self removeChild: oldPriority]; OFString *priority_s = - [OFString stringWithFormat: @"%" @PRId8, priority.int8Value]; + [OFString stringWithFormat: @"%hhd", priority.charValue]; [self addChild: [OFXMLElement elementWithName: @"priority" namespace: XMPP_NS_CLIENT stringValue: priority_s]]; @@ -196,15 +197,15 @@ showToInt(OFString *show) [old release]; } -- (of_comparison_result_t)compare: (id )object +- (OFComparisonResult)compare: (id )object { XMPPPresence *otherPresence; OFNumber *otherPriority; OFString *otherShow; - of_comparison_result_t priorityOrder; + OFComparisonResult priorityOrder; if (object == self) - return OF_ORDERED_SAME; + return OFOrderedSame; if (![(id)object isKindOfClass: [XMPPPresence class]]) @throw [OFInvalidArgumentException exception]; @@ -212,24 +213,24 @@ showToInt(OFString *show) otherPresence = (XMPPPresence *)object; otherPriority = otherPresence.priority; if (otherPriority == nil) - otherPriority = [OFNumber numberWithInt8: 0]; + otherPriority = [OFNumber numberWithChar: 0]; if (_priority != nil) priorityOrder = [_priority compare: otherPriority]; else priorityOrder = - [[OFNumber numberWithInt8: 0] compare: otherPriority]; + [[OFNumber numberWithChar: 0] compare: otherPriority]; - if (priorityOrder != OF_ORDERED_SAME) + if (priorityOrder != OFOrderedSame) return priorityOrder; otherShow = otherPresence.show; if ([_show isEqual: otherShow]) - return OF_ORDERED_SAME; + return OFOrderedSame; if (showToInt(_show) < showToInt(otherShow)) - return OF_ORDERED_ASCENDING; + return OFOrderedAscending; - return OF_ORDERED_DESCENDING; + return OFOrderedDescending; } @end diff --git a/src/XMPPSCRAMAuth.m b/src/XMPPSCRAMAuth.m index d1befc8..3fa6321 100644 --- a/src/XMPPSCRAMAuth.m +++ b/src/XMPPSCRAMAuth.m @@ -1,6 +1,6 @@ /* * Copyright (c) 2011, Florian Zeitz - * Copyright (c) 2011, 2019, Jonathan Schleifer + * Copyright (c) 2011, 2019, 2021, Jonathan Schleifer * * https://heap.zone/objxmpp/ * @@ -226,8 +226,8 @@ { size_t i; const uint8_t *clientKey, *serverKey, *clientSignature; - intmax_t iterCount = 0; - id hash; + long long iterCount = 0; + id hash; OFMutableData *ret, *authMessage, *tmpArray; OFData *salt = nil, *saltedPassword; OFString *tmpString, *sNonce = nil; @@ -248,7 +248,7 @@ for (OFString *component in [challenge componentsSeparatedByString: @","]) { OFString *entry = [component substringWithRange: - of_range(2, component.length - 2)]; + OFRangeMake(2, component.length - 2)]; if ([component hasPrefix: @"r="]) { if (![entry hasPrefix: _cNonce]) @@ -263,7 +263,7 @@ salt = [OFData dataWithBase64EncodedString: entry]; got |= GOT_SALT; } else if ([component hasPrefix: @"i="]) { - iterCount = entry.decimalValue; + iterCount = [entry longLongValueWithBase: 10]; got |= GOT_ITERCOUNT; } } @@ -397,7 +397,7 @@ mess = [OFString stringWithUTF8String: data.items length: data.count * data.itemSize]; - value = [mess substringWithRange: of_range(2, mess.length - 2)]; + value = [mess substringWithRange: OFRangeMake(2, mess.length - 2)]; if ([mess hasPrefix: @"v="]) { if (![value isEqual: _serverSignature.stringByBase64Encoding]) @@ -430,7 +430,7 @@ } return [OFString stringWithCString: (char *)buf - encoding: OF_STRING_ENCODING_ASCII + encoding: OFStringEncodingASCII length: 64]; } @@ -441,7 +441,7 @@ OFMutableData *k = [OFMutableData data]; size_t i, kSize, blockSize = [_hashType blockSize]; uint8_t *kI = NULL, *kO = NULL; - id hashI, hashO; + id hashI, hashO; if (key.itemSize * key.count > blockSize) { hashI = [[[_hashType alloc] init] autorelease]; @@ -454,8 +454,8 @@ count: key.itemSize * key.count]; @try { - kI = [self allocMemoryWithSize: blockSize]; - kO = [self allocMemoryWithSize: blockSize]; + kI = OFAllocMemory(1, blockSize); + kO = OFAllocMemory(1, blockSize); kSize = k.count; memcpy(kI, k.items, kSize); @@ -468,19 +468,16 @@ } hashI = [[[_hashType alloc] init] autorelease]; - [hashI updateWithBuffer: kI - length: blockSize]; + [hashI updateWithBuffer: kI length: blockSize]; [hashI updateWithBuffer: data.items length: data.itemSize * data.count]; hashO = [[[_hashType alloc] init] autorelease]; - [hashO updateWithBuffer: kO - length: blockSize]; - [hashO updateWithBuffer: hashI.digest - length: hashI.digestSize]; + [hashO updateWithBuffer: kO length: blockSize]; + [hashO updateWithBuffer: hashI.digest length: hashI.digestSize]; } @finally { - [self freeMemory: kI]; - [self freeMemory: kO]; + OFFreeMemory(kI); + OFFreeMemory(kO); } [hashO retain]; @@ -502,7 +499,7 @@ OFMutableData *salty, *tmp; OFData *ret; - result = [self allocMemoryWithSize: digestSize]; + result = OFAllocMemory(1, digestSize); @try { memset(result, 0, digestSize); @@ -539,7 +536,7 @@ ret = [OFData dataWithItems: result count: digestSize]; } @finally { - [self freeMemory: result]; + OFFreeMemory(result); } [ret retain]; diff --git a/src/XMPPStorage.h b/src/XMPPStorage.h index 21db338..807e2ff 100644 --- a/src/XMPPStorage.h +++ b/src/XMPPStorage.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Jonathan Schleifer + * Copyright (c) 2012, 2021, Jonathan Schleifer * * https://heap.zone/objxmpp/ * @@ -36,9 +36,9 @@ OF_ASSUME_NONNULL_BEGIN - (void)setBooleanValue: (bool)boolean forPath: (OFString *)path; - (bool)booleanValueForPath: (OFString *)path; -- (void)setIntegerValue: (intmax_t)integer +- (void)setIntegerValue: (long long)integer forPath: (OFString *)path; -- (intmax_t)integerValueForPath: (OFString *)path; +- (long long)integerValueForPath: (OFString *)path; - (void)setArray: (nullable OFArray *)array forPath: (OFString *)path; - (nullable OFArray *)arrayForPath: (OFString *)path; diff --git a/tests/test.m b/tests/test.m index af948ad..35c868a 100644 --- a/tests/test.m +++ b/tests/test.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, 2019, Jonathan Schleifer + * Copyright (c) 2010, 2011, 2019, 2021, Jonathan Schleifer * Copyright (c) 2011, 2012, Florian Zeitz * * https://heap.zone/objxmpp/ @@ -55,7 +55,7 @@ OF_APPLICATION_DELEGATE(AppDelegate) XMPPPresence *pres = [XMPPPresence presence]; pres.show = @"xa"; pres.status = @"Bored"; - pres.priority = [OFNumber numberWithInt8: 20]; + pres.priority = [OFNumber numberWithChar: 20]; pres.to = [XMPPJID JIDWithString: @"alice@example.com"]; pres.from = [XMPPJID JIDWithString: @"bob@example.org"]; assert([pres.XMLString isEqual: @"