Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -72,10 +72,11 @@ OFSHA384Or512Hash.m \ OFSHA512Hash.m \ OFScrypt.m \ OFSecureData.m \ OFSeekableStream.m \ + OFSerialization.m \ OFSet.m \ OFSortedList.m \ OFStdIOStream.m \ OFStrPTime.m \ OFStream.m \ @@ -165,11 +166,10 @@ OFJSONRepresentation.h \ OFKernelEventObserver.h \ OFKeyValueCoding.h \ OFLocking.h \ OFMessagePackRepresentation.h \ - OFSerialization.h \ OFTLSSocket.h \ ObjFW.h \ macros.h \ objfw-defs.h \ platform.h \ Index: src/OFAdjacentArray.m ================================================================== --- src/OFAdjacentArray.m +++ src/OFAdjacentArray.m @@ -160,15 +160,15 @@ @try { void *pool = objc_autoreleasePoolPush(); if ((![element.name isEqual: @"OFArray"] && ![element.name isEqual: @"OFMutableArray"]) || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; for (OFXMLElement *child in - [element elementsForNamespace: OF_SERIALIZATION_NS]) { + [element elementsForNamespace: OFSerializationNS]) { void *pool2 = objc_autoreleasePoolPush(); id object; object = child.objectByDeserializing; [_array addItem: &object]; Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -552,14 +552,14 @@ void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; if ([self isKindOfClass: [OFMutableArray class]]) element = [OFXMLElement elementWithName: @"OFMutableArray" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; else element = [OFXMLElement elementWithName: @"OFArray" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [element addChild: object.XMLElementBySerializing]; Index: src/OFCountedMapTableSet.m ================================================================== --- src/OFCountedMapTableSet.m +++ src/OFCountedMapTableSet.m @@ -123,23 +123,23 @@ @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: @"OFCountedSet"] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; for (OFXMLElement *objectElement in [element elementsForName: @"object" - namespace: OF_SERIALIZATION_NS]) { + namespace: OFSerializationNS]) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *object; OFXMLAttribute *countAttribute; unsigned long long count; object = [objectElement elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + OFSerializationNS].firstObject; countAttribute = [objectElement attributeForName: @"count"]; if (object == nil || countAttribute == nil) @throw [OFInvalidFormatException exception]; Index: src/OFCountedSet.m ================================================================== --- src/OFCountedSet.m +++ src/OFCountedSet.m @@ -181,11 +181,11 @@ { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFCountedSet" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *objectElement; @@ -195,11 +195,11 @@ [OFString stringWithFormat: @"%zu", [self countForObject: object]]; objectElement = [OFXMLElement elementWithName: @"object" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [objectElement addAttributeWithName: @"count" stringValue: count]; [objectElement addChild: object.XMLElementBySerializing]; [element addChild: objectElement]; Index: src/OFDNSResolver.h ================================================================== --- src/OFDNSResolver.h +++ src/OFDNSResolver.h @@ -20,11 +20,11 @@ #import "OFRunLoop.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN -#define OF_DNS_RESOLVER_BUFFER_LENGTH 512 +#define OFDNSResolverBufferLength 512 @class OFArray OF_GENERIC(ObjectType); @class OFDNSResolver; @class OFDNSResolverContext; @class OFDNSResolverSettings; @@ -127,11 +127,11 @@ OFDNSResolverSettings *_settings; OFUDPSocket *_IPv4Socket; #ifdef OF_HAVE_IPV6 OFUDPSocket *_IPv6Socket; #endif - char _buffer[OF_DNS_RESOLVER_BUFFER_LENGTH]; + char _buffer[OFDNSResolverBufferLength]; OFMutableDictionary OF_GENERIC(OFNumber *, OFDNSResolverContext *) *_queries; OFMutableDictionary OF_GENERIC(OFTCPSocket *, OFDNSResolverContext *) *_TCPQueries; } Index: src/OFDNSResolver.m ================================================================== --- src/OFDNSResolver.m +++ src/OFDNSResolver.m @@ -44,22 +44,20 @@ #ifndef SOCK_DNS # define SOCK_DNS 0 #endif -#define BUFFER_LENGTH OF_DNS_RESOLVER_BUFFER_LENGTH -#define MAX_DNS_RESPONSE_LENGTH 65536 +static const size_t bufferLength = OFDNSResolverBufferLength; +static const size_t maxDNSResponseLength = 65536; /* * RFC 1035 doesn't specify if pointers to pointers are allowed, and if so how * many. Since it's unspecified, we have to assume that it might happen, but we * also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and * immediately rejecting pointers to itself seems like a fair balance. */ -#define MAX_ALLOWED_POINTERS 16 - -#define CNAME_RECURSION 3 +static const uint_fast8_t maxAllowedPointers = 16; @interface OFDNSResolver () - (void)of_contextTimedOut: (OFDNSResolverContext *)context; @end @@ -190,11 +188,11 @@ address: &address TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeNS) { size_t j = i; OFString *authoritativeHost = parseName(buffer, length, &j, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFNSDNSResourceRecord alloc] @@ -203,11 +201,11 @@ authoritativeHost: authoritativeHost TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeCNAME) { size_t j = i; OFString *alias = parseName(buffer, length, &j, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFCNAMEDNSResourceRecord alloc] @@ -216,20 +214,20 @@ alias: alias TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeSOA) { size_t j = i; OFString *primaryNameServer = parseName(buffer, length, &j, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); OFString *responsiblePerson; uint32_t serialNumber, refreshInterval, retryInterval; uint32_t expirationInterval, minTTL; if (j > i + dataLength) @throw [OFInvalidServerReplyException exception]; responsiblePerson = parseName(buffer, length, &j, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); if (dataLength - (j - i) != 20) @throw [OFInvalidServerReplyException exception]; serialNumber = (buffer[j] << 24) | (buffer[j + 1] << 16) | @@ -257,11 +255,11 @@ minTTL: minTTL TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypePTR) { size_t j = i; OFString *domainName = parseName(buffer, length, &j, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFPTRDNSResourceRecord alloc] @@ -298,11 +296,11 @@ preference = (buffer[i] << 8) | buffer[i + 1]; j = i + 2; mailExchange = parseName(buffer, length, &j, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFMXDNSResourceRecord alloc] @@ -338,18 +336,18 @@ textStrings: textStrings TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeRP) { size_t j = i; OFString *mailbox = parseName(buffer, length, &j, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); OFString *TXTDomainName; if (j > i + dataLength) @throw [OFInvalidServerReplyException exception]; TXTDomainName = parseName(buffer, length, &j, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFRPDNSResourceRecord alloc] @@ -392,11 +390,11 @@ priority = (buffer[i] << 8) | buffer[i + 1]; weight = (buffer[i + 2] << 8) | buffer[i + 3]; port = (buffer[i + 4] << 8) | buffer[i + 5]; j = i + 6; - target = parseName(buffer, length, &j, MAX_ALLOWED_POINTERS); + target = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFSRVDNSResourceRecord alloc] @@ -422,11 +420,11 @@ OFEnumerator OF_GENERIC(OFMutableArray *) *objectEnumerator; OFMutableArray *array; for (uint_fast16_t j = 0; j < count; j++) { OFString *name = parseName(buffer, length, i, - MAX_ALLOWED_POINTERS); + maxAllowedPointers); OFDNSClass DNSClass; OFDNSRecordType recordType; uint32_t TTL; uint16_t dataLength; OFDNSResourceRecord *record; @@ -776,11 +774,11 @@ [sock asyncSendData: context->_queryData receiver: &context->_usedNameServer runLoopMode: runLoopMode]; [sock asyncReceiveIntoBuffer: _buffer - length: BUFFER_LENGTH + length: bufferLength runLoopMode: runLoopMode]; } - (void)asyncPerformQuery: (OFDNSQuery *)query delegate: (id )delegate @@ -861,14 +859,14 @@ /* * Cancel any pending queries, to avoid a send being still pending and * trying to access the query once it no longer exists. */ [_IPv4Socket cancelAsyncRequests]; - [_IPv4Socket asyncReceiveIntoBuffer: _buffer length: BUFFER_LENGTH]; + [_IPv4Socket asyncReceiveIntoBuffer: _buffer length: bufferLength]; #ifdef OF_HAVE_IPV6 [_IPv6Socket cancelAsyncRequests]; - [_IPv6Socket asyncReceiveIntoBuffer: _buffer length: BUFFER_LENGTH]; + [_IPv6Socket asyncReceiveIntoBuffer: _buffer length: bufferLength]; #endif exception = [OFDNSQueryFailedException exceptionWithQuery: context->_query errorCode: OFDNSResolverErrorCodeTimeout]; @@ -1009,11 +1007,11 @@ * query. * * TODO: Compare to our query, just in case? */ for (uint_fast16_t j = 0; j < numQuestions; j++) { - parseName(buffer, length, &i, MAX_ALLOWED_POINTERS); + parseName(buffer, length, &i, maxAllowedPointers); i += 4; } answerRecords = parseSection(buffer, length, &i, numAnswers); authorityRecords = parseSection(buffer, length, &i, @@ -1115,11 +1113,11 @@ context->_responseLength = 0; return nil; } if (context->_TCPBuffer == nil) - context->_TCPBuffer = OFAllocMemory(MAX_DNS_RESPONSE_LENGTH, 1); + context->_TCPBuffer = OFAllocMemory(maxDNSResponseLength, 1); [sock asyncReadIntoBuffer: context->_TCPBuffer exactLength: 2]; return nil; } @@ -1146,11 +1144,11 @@ OFEnsure(length == 2); context->_responseLength = (ucBuffer[0] << 8) | ucBuffer[1]; - if (context->_responseLength > MAX_DNS_RESPONSE_LENGTH) + if (context->_responseLength > maxDNSResponseLength) @throw [OFOutOfRangeException exception]; if (context->_responseLength == 0) goto done; Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -353,11 +353,11 @@ void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; stringValue = element.stringValue; } @catch (id e) { [self release]; @@ -620,11 +620,11 @@ @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); element = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS + namespace: OFSerializationNS stringValue: OFBase64Encode(_items, _count * _itemSize)]; [element retain]; objc_autoreleasePoolPop(pool); Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -502,11 +502,11 @@ @try { void *pool = objc_autoreleasePoolPush(); unsigned long long value; if (![element.name isEqual: @"OFDate"] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; value = [element unsignedLongLongValueWithBase: 16]; if (value > UINT64_MAX) @@ -586,11 +586,11 @@ { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFDate" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( self.timeIntervalSince1970)))]; Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -678,14 +678,14 @@ OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; if ([self isKindOfClass: [OFMutableDictionary class]]) element = [OFXMLElement elementWithName: @"OFMutableDictionary" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; else element = [OFXMLElement elementWithName: @"OFDictionary" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { @@ -692,16 +692,16 @@ void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *keyElement, *objectElement; keyElement = [OFXMLElement elementWithName: @"key" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [keyElement addChild: key.XMLElementBySerializing]; objectElement = [OFXMLElement elementWithName: @"object" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [objectElement addChild: object.XMLElementBySerializing]; [element addChild: keyElement]; [element addChild: objectElement]; Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -16,15 +16,15 @@ #import "OFSeekableStream.h" #import "OFKernelEventObserver.h" #ifndef OF_AMIGAOS # define OF_FILE_HANDLE_IS_FD -# define OF_INVALID_FILE_HANDLE (-1) typedef int OFFileHandle; +static const OFFileHandle OFInvalidFileHandle = -1; #else -# define OF_INVALID_FILE_HANDLE NULL typedef struct OFFileHandle *OFFileHandle; +static const OFFileHandle OFInvalidFileHandle = NULL; #endif OF_ASSUME_NONNULL_BEGIN @class OFURL; Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -349,21 +349,21 @@ return self; } - (bool)lowlevelIsAtEndOfStream { - if (_handle == OF_INVALID_FILE_HANDLE) + if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; - if (_handle == OF_INVALID_FILE_HANDLE) + if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #if defined(OF_WINDOWS) if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; @@ -393,11 +393,11 @@ return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { - if (_handle == OF_INVALID_FILE_HANDLE) + if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #if defined(OF_WINDOWS) int bytesWritten; @@ -453,11 +453,11 @@ - (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence { OFFileOffset ret; - if (_handle == OF_INVALID_FILE_HANDLE) + if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_AMIGAOS # if defined(OF_WINDOWS) ret = _lseeki64(_handle, offset, whence); @@ -523,22 +523,22 @@ } #endif - (void)close { - if (_handle == OF_INVALID_FILE_HANDLE) + if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; closeHandle(_handle); - _handle = OF_INVALID_FILE_HANDLE; + _handle = OFInvalidFileHandle; [super close]; } - (void)dealloc { - if (_handle != OF_INVALID_FILE_HANDLE) + if (_handle != OFInvalidFileHandle) [self close]; [super dealloc]; } @end Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -53,15 +53,15 @@ @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; for (OFXMLElement *child in - [element elementsForNamespace: OF_SERIALIZATION_NS]) { + [element elementsForNamespace: OFSerializationNS]) { void *pool2 = objc_autoreleasePoolPush(); [self appendObject: child.objectByDeserializing]; objc_autoreleasePoolPop(pool2); @@ -359,11 +359,11 @@ - (OFXMLElement *)XMLElementBySerializing { OFXMLElement *element = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; for (OFListItem *iter = _firstListItem; iter != NULL; iter = iter->next) { void *pool = objc_autoreleasePoolPush(); Index: src/OFMD5Hash.h ================================================================== --- src/OFMD5Hash.h +++ src/OFMD5Hash.h @@ -29,11 +29,11 @@ { OFSecureData *_iVarsData; struct { uint32_t state[4]; uint64_t bits; - union of_md5_hash_buffer { + union { unsigned char bytes[64]; uint32_t words[16]; } buffer; size_t bufferLength; } *_iVars; Index: src/OFMapTableDictionary.m ================================================================== --- src/OFMapTableDictionary.m +++ src/OFMapTableDictionary.m @@ -241,13 +241,13 @@ OFArray *keys, *objects; OFEnumerator *keyEnumerator, *objectEnumerator; OFXMLElement *keyElement, *objectElement; keys = [element elementsForName: @"key" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; objects = [element elementsForName: @"object" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; if (keys.count != objects.count) @throw [OFInvalidFormatException exception]; _mapTable = [[OFMapTable alloc] @@ -261,13 +261,13 @@ (objectElement = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *key, *object; key = [keyElement elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + OFSerializationNS].firstObject; object = [objectElement elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + OFSerializationNS].firstObject; if (key == nil || object == nil) @throw [OFInvalidFormatException exception]; [_mapTable setObject: object.objectByDeserializing Index: src/OFMapTableSet.m ================================================================== --- src/OFMapTableSet.m +++ src/OFMapTableSet.m @@ -188,15 +188,15 @@ @try { void *pool = objc_autoreleasePoolPush(); if ((![element.name isEqual: @"OFSet"] && ![element.name isEqual: @"OFMutableSet"]) || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; for (OFXMLElement *child in - [element elementsForNamespace: OF_SERIALIZATION_NS]) { + [element elementsForNamespace: OFSerializationNS]) { void *pool2 = objc_autoreleasePoolPush(); [_mapTable setObject: (void *)1 forKey: [child objectByDeserializing]]; Index: src/OFNull.m ================================================================== --- src/OFNull.m +++ src/OFNull.m @@ -48,11 +48,11 @@ [self release]; pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; objc_autoreleasePoolPop(pool); return [OFNull null]; @@ -72,11 +72,11 @@ { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [element retain]; objc_autoreleasePoolPop(pool); Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -44,11 +44,11 @@ OF_SUBCLASSING_RESTRICTED #endif @interface OFNumber: OFValue { - union of_number_value { + union { double float_; long long signed_; unsigned long long unsigned_; } _value; const char *_typeEncoding; Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -749,11 +749,11 @@ @try { void *pool = objc_autoreleasePoolPush(); OFString *typeString; if (![element.name isEqual: @"OFNumber"] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; typeString = [element attributeForName: @"type"].stringValue; if ([typeString isEqual: @"bool"]) { @@ -1041,11 +1041,11 @@ { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFNumber" - namespace: OF_SERIALIZATION_NS + namespace: OFSerializationNS stringValue: self.description]; if (*self.objCType == 'B') [element addAttributeWithName: @"type" stringValue: @"bool"]; else if (isFloat(self)) { Index: src/OFObject+Serialization.m ================================================================== --- src/OFObject+Serialization.m +++ src/OFObject+Serialization.m @@ -40,11 +40,11 @@ pool = objc_autoreleasePoolPush(); element = ((id )self).XMLElementBySerializing; root = [OFXMLElement elementWithName: @"serialization" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [root addAttributeWithName: @"version" stringValue: @"1"]; [root addChild: element]; ret = [@"\n" stringByAppendingString: [root XMLStringWithIndentation: 2]]; Index: src/OFPlainMutex.h ================================================================== --- src/OFPlainMutex.h +++ src/OFPlainMutex.h @@ -38,11 +38,10 @@ #endif #if defined(OF_HAVE_ATOMIC_OPS) # import "OFAtomic.h" typedef volatile int OFSpinlock; -# define OF_SPINCOUNT 10 #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) typedef pthread_spinlock_t OFSpinlock; #else typedef OFPlainMutex OFSpinlock; #endif @@ -125,11 +124,11 @@ OFSpinlockLock(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) size_t i; - for (i = 0; i < OF_SPINCOUNT; i++) + for (i = 0; i < 10; i++) if (OFSpinlockTryLock(spinlock) == 0) return 0; while (OFSpinlockTryLock(spinlock) == EBUSY) OFYieldThread(); Index: src/OFPlugin.h ================================================================== --- src/OFPlugin.h +++ src/OFPlugin.h @@ -17,18 +17,24 @@ @class OFString; #ifndef OF_WINDOWS # include -# define OF_RTLD_LAZY RTLD_LAZY -# define OF_RTLD_NOW RTLD_NOW typedef void *OFPluginHandle; + +typedef enum OFDLOpenFlags { + OFDLOpenFlagLazy = RTLD_LAZY, + OFDLOpenFlagNow = RTLD_NOW +} OFDLOpenFlags; #else # include -# define OF_RTLD_LAZY 0 -# define OF_RTLD_NOW 0 typedef HMODULE OFPluginHandle; + +enum OFDLOpenFlags { + OFDLOpenFlagLazy = 0, + OFDLOpenFlagNow = 0 +}; #endif OF_ASSUME_NONNULL_BEGIN /** @@ -52,14 +58,14 @@ @end #ifdef __cplusplus extern "C" { #endif -extern OFPluginHandle OFDlOpen(OFString *path, int flags); -extern void *OFDlSym(OFPluginHandle handle, const char *symbol); -extern OFString *_Nullable OFDlError(void); -extern void OFDlClose(OFPluginHandle handle); +extern OFPluginHandle OFDLOpen(OFString *path, OFDLOpenFlags flags); +extern void *OFDLSym(OFPluginHandle handle, const char *symbol); +extern OFString *_Nullable OFDLError(void); +extern void OFDLClose(OFPluginHandle handle); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -31,11 +31,11 @@ #import "OFLoadPluginFailedException.h" typedef OFPlugin *(*init_plugin_t)(void); OFPluginHandle -OFDlOpen(OFString *path, int flags) +OFDLOpen(OFString *path, OFDLOpenFlags flags) { #ifndef OF_WINDOWS return dlopen([path cStringWithEncoding: [OFLocale encoding]], flags); #else if (path == nil) @@ -48,31 +48,31 @@ [path cStringWithEncoding: [OFLocale encoding]]); #endif } void * -OFDlSym(OFPluginHandle handle, const char *symbol) +OFDLSym(OFPluginHandle handle, const char *symbol) { #ifndef OF_WINDOWS return dlsym(handle, symbol); #else return (void *)(uintptr_t)GetProcAddress(handle, symbol); #endif } void -OFDlClose(OFPluginHandle handle) +OFDLClose(OFPluginHandle handle) { #ifndef OF_WINDOWS dlclose(handle); #else FreeLibrary(handle); #endif } OFString * -OFDlError(void) +OFDLError(void) { #ifndef OF_WINDOWS return [OFString stringWithCString: dlerror() encoding: [OFLocale encoding]]; #else @@ -96,20 +96,20 @@ path.lastPathComponent]; #else path = [path stringByAppendingString: @PLUGIN_SUFFIX]; #endif - if ((handle = OFDlOpen(path, OF_RTLD_LAZY)) == NULL) + if ((handle = OFDLOpen(path, OFDLOpenFlagLazy)) == NULL) @throw [OFLoadPluginFailedException exceptionWithPath: path - error: OFDlError()]; + error: OFDLError()]; objc_autoreleasePoolPop(pool); - initPlugin = (init_plugin_t)(uintptr_t)OFDlSym(handle, "init_plugin"); + initPlugin = (init_plugin_t)(uintptr_t)OFDLSym(handle, "init_plugin"); if (initPlugin == (init_plugin_t)0 || (plugin = initPlugin()) == nil) { - OFDlClose(handle); + OFDLClose(handle); @throw [OFInitializationFailedException exceptionWithClass: self]; } plugin->_pluginHandle = handle; @@ -136,8 +136,8 @@ { OFPluginHandle h = _pluginHandle; [super dealloc]; - OFDlClose(h); + OFDLClose(h); } @end Index: src/OFRIPEMD160Hash.h ================================================================== --- src/OFRIPEMD160Hash.h +++ src/OFRIPEMD160Hash.h @@ -29,11 +29,11 @@ { OFSecureData *_iVarsData; struct { uint32_t state[5]; uint64_t bits; - union of_ripemd160_hash_buffer { + union { unsigned char bytes[64]; uint32_t words[16]; } buffer; size_t bufferLength; } *_iVars; Index: src/OFSHA1Hash.h ================================================================== --- src/OFSHA1Hash.h +++ src/OFSHA1Hash.h @@ -29,11 +29,11 @@ { OFSecureData *_iVarsData; struct { uint32_t state[5]; uint64_t bits; - union of_sha1_hash_buffer { + union { unsigned char bytes[64]; uint32_t words[80]; } buffer; size_t bufferLength; } *_iVars; Index: src/OFSHA224Or256Hash.h ================================================================== --- src/OFSHA224Or256Hash.h +++ src/OFSHA224Or256Hash.h @@ -30,11 +30,11 @@ OFSecureData *_iVarsData; @protected struct { uint32_t state[8]; uint64_t bits; - union of_sha224_or_256_hash_buffer { + union { unsigned char bytes[64]; uint32_t words[64]; } buffer; size_t bufferLength; } *_iVars; Index: src/OFSHA384Or512Hash.h ================================================================== --- src/OFSHA384Or512Hash.h +++ src/OFSHA384Or512Hash.h @@ -30,11 +30,11 @@ OFSecureData *_iVarsData; @protected struct { uint64_t state[8]; uint64_t bits[2]; - union of_sha384_or_512_hash_buffer { + union { unsigned char bytes[128]; uint64_t words[80]; } buffer; size_t bufferLength; } *_iVars; Index: src/OFSerialization.h ================================================================== --- src/OFSerialization.h +++ src/OFSerialization.h @@ -15,12 +15,10 @@ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN -#define OF_SERIALIZATION_NS @"https://objfw.nil.im/serialization" - @class OFXMLElement; /** * @protocol OFSerialization OFSerialization.h ObjFW/OFSerialization.h * @@ -38,7 +36,15 @@ * @param element An OFXMLElement with the serialized object * @return An initialized object */ - (instancetype)initWithSerialization: (OFXMLElement *)element; @end + +#ifdef __cplusplus +extern "C" { +#endif +extern OFString *const OFSerializationNS; +#ifdef __cplusplus +} +#endif OF_ASSUME_NONNULL_END ADDED src/OFSerialization.m Index: src/OFSerialization.m ================================================================== --- src/OFSerialization.m +++ src/OFSerialization.m @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2008-2021 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFSerialization.h" +#import "OFString.h" + +OFString *const OFSerializationNS = @"https://objfw.nil.im/serialization"; Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -367,14 +367,14 @@ void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; if ([self isKindOfClass: [OFMutableSet class]]) element = [OFXMLElement elementWithName: @"OFMutableSet" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; else element = [OFXMLElement elementWithName: @"OFSet" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); [element addChild: object.XMLElementBySerializing]; objc_autoreleasePoolPop(pool2); Index: src/OFString+PathAdditions.h ================================================================== --- src/OFString+PathAdditions.h +++ src/OFString+PathAdditions.h @@ -15,16 +15,10 @@ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN -#ifdef OF_AMIGAOS -# define OF_PATH_CURRENT_DIRECTORY @"" -#else -# define OF_PATH_CURRENT_DIRECTORY @"." -#endif - #ifdef __cplusplus extern "C" { #endif extern int _OFString_PathAdditions_reference; #ifdef __cplusplus Index: src/OFString+Serialization.m ================================================================== --- src/OFString+Serialization.m +++ src/OFString+Serialization.m @@ -52,11 +52,11 @@ if (version.unsignedLongLongValue != 1) @throw [OFUnsupportedVersionException exceptionWithVersion: version]; - elements = [root elementsForNamespace: OF_SERIALIZATION_NS]; + elements = [root elementsForNamespace: OFSerializationNS]; if (elements.count != 1) @throw [OFInvalidArgumentException exception]; object = [[elements.firstObject objectByDeserializing] retain]; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1088,11 +1088,11 @@ { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { - if (![element.namespace isEqual: OF_SERIALIZATION_NS]) + if (![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; if ([self isKindOfClass: [OFMutableString class]]) { if (![element.name isEqual: @"OFMutableString"]) @throw [OFInvalidArgumentException exception]; @@ -1693,11 +1693,11 @@ className = @"OFMutableString"; else className = @"OFString"; element = [OFXMLElement elementWithName: className - namespace: OF_SERIALIZATION_NS + namespace: OFSerializationNS stringValue: self]; [element retain]; objc_autoreleasePoolPop(pool); Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -772,11 +772,11 @@ void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; stringValue = element.stringValue; } @catch (id e) { [self release]; @@ -1187,15 +1187,15 @@ { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS + namespace: OFSerializationNS stringValue: self.string]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } @end Index: src/OFXMLAttribute.m ================================================================== --- src/OFXMLAttribute.m +++ src/OFXMLAttribute.m @@ -74,11 +74,11 @@ @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _name = [[element attributeForName: @"name"].stringValue copy]; _namespace = [[element attributeForName: @"namespace"] .stringValue copy]; @@ -157,11 +157,11 @@ { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [element addAttributeWithName: @"name" stringValue: _name]; if (_namespace != nil) [element addAttributeWithName: @"namespace" stringValue: _namespace]; Index: src/OFXMLCDATA.m ================================================================== --- src/OFXMLCDATA.m +++ src/OFXMLCDATA.m @@ -48,11 +48,11 @@ @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _CDATA = [element.stringValue copy]; objc_autoreleasePoolPop(pool); @@ -134,11 +134,11 @@ - (OFXMLElement *)XMLElementBySerializing { OFXMLElement *element = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [element addChild: self]; return element; } @end Index: src/OFXMLCharacters.m ================================================================== --- src/OFXMLCharacters.m +++ src/OFXMLCharacters.m @@ -48,11 +48,11 @@ @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _characters = [element.stringValue copy]; objc_autoreleasePoolPop(pool); @@ -125,9 +125,9 @@ } - (OFXMLElement *)XMLElementBySerializing { return [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS + namespace: OFSerializationNS stringValue: _characters]; } @end Index: src/OFXMLComment.m ================================================================== --- src/OFXMLComment.m +++ src/OFXMLComment.m @@ -52,11 +52,11 @@ @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _text = [element.stringValue copy]; objc_autoreleasePoolPop(pool); @@ -138,9 +138,9 @@ } - (OFXMLElement *)XMLElementBySerializing { return [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS + namespace: OFSerializationNS stringValue: _text]; } @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -268,11 +268,11 @@ OFXMLElement *childrenElement; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _name = [[element attributeForName: @"name"].stringValue copy]; _namespace = [[element attributeForName: @"namespace"] .stringValue copy]; @@ -279,20 +279,20 @@ _defaultNamespace = [[element attributeForName: @"defaultNamespace"].stringValue copy]; attributesElement = [[element elementForName: @"attributes" - namespace: OF_SERIALIZATION_NS] elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + namespace: OFSerializationNS] elementsForNamespace: + OFSerializationNS].firstObject; namespacesElement = [[element elementForName: @"namespaces" - namespace: OF_SERIALIZATION_NS] elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + namespace: OFSerializationNS] elementsForNamespace: + OFSerializationNS].firstObject; childrenElement = [[element elementForName: @"children" - namespace: OF_SERIALIZATION_NS] elementsForNamespace: - OF_SERIALIZATION_NS].firstObject; + namespace: OFSerializationNS] elementsForNamespace: + OFSerializationNS].firstObject; _attributes = [attributesElement.objectByDeserializing mutableCopy]; _namespaces = [namespacesElement.objectByDeserializing mutableCopy]; @@ -653,11 +653,11 @@ { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; if (_name != nil) [element addAttributeWithName: @"name" stringValue: _name]; if (_namespace != nil) @@ -671,11 +671,11 @@ if (_attributes != nil) { OFXMLElement *attributesElement; attributesElement = [OFXMLElement elementWithName: @"attributes" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [attributesElement addChild: _attributes.XMLElementBySerializing]; [element addChild: attributesElement]; } @@ -690,11 +690,11 @@ @"http://www.w3.org/2000/xmlns/"]; if (namespacesCopy.count > 0) { namespacesElement = [OFXMLElement elementWithName: @"namespaces" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [namespacesElement addChild: namespacesCopy.XMLElementBySerializing]; [element addChild: namespacesElement]; } } @@ -702,11 +702,11 @@ if (_children != nil) { OFXMLElement *childrenElement; childrenElement = [OFXMLElement elementWithName: @"children" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [childrenElement addChild: _children.XMLElementBySerializing]; [element addChild: childrenElement]; } [element retain]; Index: src/OFXMLProcessingInstruction.m ================================================================== --- src/OFXMLProcessingInstruction.m +++ src/OFXMLProcessingInstruction.m @@ -56,15 +56,15 @@ @try { void *pool = objc_autoreleasePoolPush(); OFXMLAttribute *targetAttr; if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OF_SERIALIZATION_NS]) + ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; targetAttr = [element attributeForName: @"target" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; if (targetAttr.stringValue.length == 0) @throw [OFInvalidArgumentException exception]; self = [self initWithTarget: targetAttr.stringValue data: element.stringValue]; @@ -171,11 +171,11 @@ } - (OFXMLElement *)XMLElementBySerializing { OFXMLElement *ret = [OFXMLElement elementWithName: self.className - namespace: OF_SERIALIZATION_NS + namespace: OFSerializationNS stringValue: _data]; void *pool = objc_autoreleasePoolPush(); [ret addAttribute: [OFXMLAttribute attributeWithName: @"target" stringValue: _target]]; Index: utils/ofarc/OFArc.m ================================================================== --- utils/ofarc/OFArc.m +++ utils/ofarc/OFArc.m @@ -397,12 +397,16 @@ if (files.count > 0) for (OFString *path in files) [sandbox unveilPath: path permissions: @"wc"]; else { - OFString *path = (outputDir != nil - ? outputDir : OF_PATH_CURRENT_DIRECTORY); + OFString *path = outputDir; + + if (path == nil) + path = [[OFFileManager defaultManager] + currentDirectoryPath]; + /* We need 'r' to change the directory to it. */ [sandbox unveilPath: path permissions: @"rwc"]; } sandbox.allowsUnveil = false; Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -283,11 +283,11 @@ { if (self != [OFHTTP class]) return; /* Opportunistically try loading ObjOpenSSL and ignore any errors. */ - OFDlOpen(@LIB_PREFIX @"objopenssl" @LIB_SUFFIX, OF_RTLD_LAZY); + OFDLOpen(@LIB_PREFIX @"objopenssl" @LIB_SUFFIX, OFDLOpenFlagLazy); } #endif - (instancetype)init { @@ -526,13 +526,18 @@ break; } } #ifdef OF_HAVE_SANDBOX - [sandbox unveilPath: (outputPath != nil - ? outputPath : OF_PATH_CURRENT_DIRECTORY) - permissions: (_continue ? @"rwc" : @"wc")]; + if (outputPath != nil) + [sandbox unveilPath: outputPath + permissions: (_continue ? @"rwc" : @"wc")]; + else + [sandbox unveilPath: [[OFFileManger defaultManager] + currentDirectoryPath] + permissions: (_continue ? @"rwc" : @"wc")]; + /* In case we use ObjOpenSSL for https later */ [sandbox unveilPath: @"/etc/ssl" permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox];