Index: .fossil-settings/clean-glob ================================================================== --- .fossil-settings/clean-glob +++ .fossil-settings/clean-glob @@ -37,11 +37,10 @@ tests/EBOOT.PBP tests/Info.plist tests/PARAM.SFO tests/objc_sync/objc_sync tests/plugin/Info.plist -tests/serialization_xml.m tests/terminal/terminal_tests tests/testfile_bin.m tests/testfile_ini.m tests/tests tests/tests.3dsx Index: .fossil-settings/ignore-glob ================================================================== --- .fossil-settings/ignore-glob +++ .fossil-settings/ignore-glob @@ -42,11 +42,10 @@ tests/iOS.xcodeproj/*.pbxuser tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync tests/plugin/Info.plist -tests/serialization_xml.m tests/terminal/terminal_tests tests/testfile_bin.m tests/testfile_ini.m tests/tests tests/tests.3dsx Index: .gitignore ================================================================== --- .gitignore +++ .gitignore @@ -42,11 +42,10 @@ tests/iOS.xcodeproj/*.pbxuser tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync tests/plugin/Info.plist -tests/serialization_xml.m tests/terminal/terminal_tests tests/testfile_bin.m tests/testfile_ini.m tests/tests tests/tests.3dsx Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -58,11 +58,10 @@ OFNotificationCenter.m \ OFNull.m \ OFNumber.m \ OFObject.m \ OFObject+KeyValueCoding.m \ - OFObject+Serialization.m \ OFOnce.m \ OFOptionsParser.m \ OFPBKDF2.m \ OFPair.m \ OFRIPEMD160Hash.m \ @@ -75,21 +74,19 @@ OFSHA384Or512Hash.m \ OFSHA512Hash.m \ OFScrypt.m \ OFSecureData.m \ OFSeekableStream.m \ - OFSerialization.m \ OFSet.m \ OFSortedList.m \ OFStdIOStream.m \ OFStream.m \ OFString.m \ OFString+CryptographicHashing.m \ OFString+JSONParsing.m \ OFString+PercentEncoding.m \ OFString+PropertyListParsing.m \ - OFString+Serialization.m \ OFString+XMLEscaping.m \ OFString+XMLUnescaping.m \ ${OF_SUBPROCESS_M} \ OFSettings.m \ OFSystemInfo.m \ @@ -103,11 +100,10 @@ OFXMLAttribute.m \ OFXMLCDATA.m \ OFXMLCharacters.m \ OFXMLComment.m \ OFXMLElement.m \ - OFXMLElement+Serialization.m \ OFXMLElementBuilder.m \ OFXMLNode.m \ OFXMLParser.m \ OFXMLProcessingInstruction.m \ OFZIPArchive.m \ Index: src/OFAdjacentArray.m ================================================================== --- src/OFAdjacentArray.m +++ src/OFAdjacentArray.m @@ -20,11 +20,10 @@ #import "OFAdjacentArray.h" #import "OFAdjacentSubarray.h" #import "OFData.h" #import "OFMutableAdjacentArray.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @@ -148,43 +147,10 @@ [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [self init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if ((![element.name isEqual: @"OFArray"] && - ![element.name isEqual: @"OFMutableArray"]) || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - for (OFXMLElement *child in - [element elementsForNamespace: OFSerializationNS]) { - void *pool2 = objc_autoreleasePoolPush(); - id object; - - object = child.objectByDeserializing; - [_array addItem: &object]; - [object retain]; - - objc_autoreleasePoolPop(pool2); - } - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (size_t)count { Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -23,11 +23,10 @@ #include #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" -#import "OFSerialization.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN @@ -100,11 +99,11 @@ * @brief An abstract class for storing objects in an array. * * @note Subclasses must implement @ref count and @ref objectAtIndex:. */ @interface OFArray OF_GENERIC(ObjectType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -23,11 +23,10 @@ #import "OFAdjacentArray.h" #import "OFData.h" #import "OFNull.h" #import "OFString.h" #import "OFSubarray.h" -#import "OFXMLElement.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @@ -85,15 +84,10 @@ { return (id)[[OFAdjacentArray alloc] initWithObjects: objects count: count]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFAdjacentArray alloc] initWithSerialization: element]; -} - - (instancetype)retain { return self; } @@ -212,15 +206,10 @@ } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ OF_INVALID_INIT_METHOD } - (size_t)count { @@ -546,37 +535,10 @@ [ret makeImmutable]; return [ret autorelease]; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - if ([self isKindOfClass: [OFMutableArray class]]) - element = [OFXMLElement elementWithName: @"OFMutableArray" - namespace: OFSerializationNS]; - else - element = [OFXMLElement elementWithName: @"OFArray" - namespace: OFSerializationNS]; - - for (id object in self) { - void *pool2 = objc_autoreleasePoolPush(); - - [element addChild: object.XMLElementBySerializing]; - - objc_autoreleasePoolPop(pool2); - } - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } Index: src/OFCountedMapTableSet.m ================================================================== --- src/OFCountedMapTableSet.m +++ src/OFCountedMapTableSet.m @@ -19,11 +19,10 @@ #import "OFArray.h" #import "OFMapTable.h" #import "OFMutableMapTableSet.h" #import "OFString.h" #import "OFXMLAttribute.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFEnumerationMutationException.h" #import "OFOutOfRangeException.h" @@ -112,56 +111,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [self init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: @"OFCountedSet"] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - for (OFXMLElement *objectElement in - [element elementsForName: @"object" - namespace: OFSerializationNS]) { - void *pool2 = objc_autoreleasePoolPush(); - OFXMLElement *object; - OFXMLAttribute *countAttribute; - unsigned long long count; - - object = [objectElement elementsForNamespace: - OFSerializationNS].firstObject; - countAttribute = - [objectElement attributeForName: @"count"]; - - if (object == nil || countAttribute == nil) - @throw [OFInvalidFormatException exception]; - - count = countAttribute.unsignedLongLongValue; - if (count > SIZE_MAX || count > UINTPTR_MAX) - @throw [OFOutOfRangeException exception]; - - [_mapTable setObject: (void *)(uintptr_t)count - forKey: object.objectByDeserializing]; - - objc_autoreleasePoolPop(pool2); - } - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (size_t)countForObject: (id)object { Index: src/OFCountedSet.m ================================================================== --- src/OFCountedSet.m +++ src/OFCountedSet.m @@ -19,11 +19,10 @@ #import "OFCountedSet.h" #import "OFCountedMapTableSet.h" #import "OFNumber.h" #import "OFString.h" -#import "OFXMLElement.h" static struct { Class isa; } placeholder; @@ -69,16 +68,10 @@ { return (id)[[OFCountedMapTableSet alloc] initWithObject: firstObject arguments: arguments]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFCountedMapTableSet alloc] - initWithSerialization: element]; -} - - (instancetype)retain { return self; } @@ -175,46 +168,10 @@ - (id)mutableCopy { return [[OFCountedSet alloc] initWithSet: self]; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - element = [OFXMLElement elementWithName: @"OFCountedSet" - namespace: OFSerializationNS]; - - for (id object in self) { - void *pool2 = objc_autoreleasePoolPush(); - - OFXMLElement *objectElement; - OFString *count; - - count = - [OFString stringWithFormat: @"%zu", - [self countForObject: object]]; - - objectElement = [OFXMLElement - elementWithName: @"object" - namespace: OFSerializationNS]; - [objectElement addAttributeWithName: @"count" - stringValue: count]; - [objectElement addChild: object.XMLElementBySerializing]; - [element addChild: objectElement]; - - objc_autoreleasePoolPop(pool2); - } - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (OFCountedSetEnumerationBlock)block { [self enumerateObjectsUsingBlock: ^ (id object, bool *stop) { block(object, [self countForObject: object], stop); Index: src/OFData.h ================================================================== --- src/OFData.h +++ src/OFData.h @@ -12,11 +12,10 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFSerialization.h" #import "OFMessagePackRepresentation.h" /*! @file */ OF_ASSUME_NONNULL_BEGIN @@ -36,16 +35,13 @@ /** * @class OFData OFData.h ObjFW/OFData.h * * @brief A class for storing arbitrary data in an array. - * - * For security reasons, serialization and deserialization is only implemented - * for OFData with item size 1. */ @interface OFData: OFObject + OFMessagePackRepresentation> { unsigned char *_Nullable _items; size_t _count, _itemSize; bool _freeWhenDone; @private Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -29,11 +29,10 @@ #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" @@ -335,33 +334,10 @@ [(OFMutableData *)self makeImmutable]; return self; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - void *pool = objc_autoreleasePoolPush(); - OFString *stringValue; - - @try { - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - stringValue = element.stringValue; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithBase64EncodedString: stringValue]; - - objc_autoreleasePoolPop(pool); - - return self; -} - - (void)dealloc { if (_freeWhenDone) OFFreeMemory(_items); @@ -594,32 +570,10 @@ [[OFIRIHandler openItemAtIRI: IRI mode: @"w"] writeData: self]; objc_autoreleasePoolPop(pool); } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool; - OFXMLElement *element; - - if (_itemSize != 1) - @throw [OFNotImplementedException exceptionWithSelector: _cmd - object: self]; - - pool = objc_autoreleasePoolPush(); - element = [OFXMLElement - elementWithName: self.className - namespace: OFSerializationNS - stringValue: OFBase64Encode(_items, _count * _itemSize)]; - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFData *)messagePackRepresentation { OFMutableData *data; if (_itemSize != 1) Index: src/OFDate.h ================================================================== --- src/OFDate.h +++ src/OFDate.h @@ -13,11 +13,10 @@ * file. */ #import "OFObject.h" #import "OFMessagePackRepresentation.h" -#import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFConstantString; @@ -28,11 +27,11 @@ * @brief A class for storing, accessing and comparing dates. */ #ifndef OF_DATE_M OF_SUBCLASSING_RESTRICTED #endif -@interface OFDate: OFObject { OFTimeInterval _seconds; } Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -32,11 +32,10 @@ #endif #import "OFStrPTime.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFXMLAttribute.h" -#import "OFXMLElement.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" @@ -494,43 +493,10 @@ objc_autoreleasePoolPop(pool); return [self initWithTimeIntervalSince1970: seconds]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - OFTimeInterval seconds; - - @try { - void *pool = objc_autoreleasePoolPush(); - unsigned long long value; - - if (![element.name isEqual: @"OFDate"] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - if (![[element attributeForName: @"encoding"].stringValue - isEqual: @"hex"]) - @throw [OFInvalidFormatException exception]; - - value = [element unsignedLongLongValueWithBase: 16]; - - if (value > UINT64_MAX) - @throw [OFOutOfRangeException exception]; - - seconds = OFFromBigEndianDouble(OFRawUInt64ToDouble( - OFToBigEndian64(value))); - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return [self initWithTimeIntervalSince1970: seconds]; -} - - (bool)isEqual: (id)object { OFDate *otherDate; if (object == self) @@ -585,30 +551,10 @@ - (OFString *)description { return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"]; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - element = [OFXMLElement elementWithName: @"OFDate" - namespace: OFSerializationNS]; - - [element addAttributeWithName: @"encoding" stringValue: @"hex"]; - element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, - OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( - self.timeIntervalSince1970)))]; - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFData *)messagePackRepresentation { void *pool = objc_autoreleasePoolPush(); OFTimeInterval timeInterval = self.timeIntervalSince1970; int64_t seconds = (int64_t)timeInterval; Index: src/OFDictionary.h ================================================================== --- src/OFDictionary.h +++ src/OFDictionary.h @@ -23,11 +23,10 @@ #include #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" -#import "OFSerialization.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN @@ -75,11 +74,11 @@ * * @note Subclasses must implement @ref objectForKey:, @ref count and * @ref keyEnumerator. */ @interface OFDictionary OF_GENERIC(KeyType, ObjectType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define KeyType id # define ObjectType id #endif Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -22,11 +22,10 @@ #import "OFCharacterSet.h" #import "OFData.h" #import "OFEnumerator.h" #import "OFMapTableDictionary.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #import "OFUndefinedKeyException.h" @@ -104,16 +103,10 @@ { return (id)[[OFMapTableDictionary alloc] initWithKey: firstKey arguments: arguments]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFMapTableDictionary alloc] - initWithSerialization: element]; -} - - (instancetype)retain { return self; } @@ -261,15 +254,10 @@ return ret; } - (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments { - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ OF_INVALID_INIT_METHOD } - (id)objectForKey: (id)key { @@ -568,54 +556,10 @@ objc_autoreleasePoolPop(pool); return ret; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - OFEnumerator *keyEnumerator, *objectEnumerator; - id key, object; - - if ([self isKindOfClass: [OFMutableDictionary class]]) - element = [OFXMLElement elementWithName: @"OFMutableDictionary" - namespace: OFSerializationNS]; - else - element = [OFXMLElement elementWithName: @"OFDictionary" - namespace: OFSerializationNS]; - - keyEnumerator = [self keyEnumerator]; - objectEnumerator = [self objectEnumerator]; - while ((key = [keyEnumerator nextObject]) != nil && - (object = [objectEnumerator nextObject]) != nil) { - void *pool2 = objc_autoreleasePoolPush(); - OFXMLElement *keyElement, *objectElement; - - keyElement = [OFXMLElement - elementWithName: @"key" - namespace: OFSerializationNS]; - [keyElement addChild: key.XMLElementBySerializing]; - - objectElement = [OFXMLElement - elementWithName: @"object" - namespace: OFSerializationNS]; - [objectElement addChild: object.XMLElementBySerializing]; - - [element addChild: keyElement]; - [element addChild: objectElement]; - - objc_autoreleasePoolPop(pool2); - } - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } Index: src/OFIRI.h ================================================================== --- src/OFIRI.h +++ src/OFIRI.h @@ -13,11 +13,10 @@ * file. */ #import "OFObject.h" #import "OFCharacterSet.h" -#import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); @@ -31,11 +30,11 @@ * @brief A class for representing IRIs, URIs, URLs and URNs, for parsing them * as well as accessing parts of them. * * This class follows RFC 3976 and RFC 3987. */ -@interface OFIRI: OFObject +@interface OFIRI: OFObject { OFString *_scheme; OFString *_Nullable _percentEncodedHost; OFNumber *_Nullable _port; OFString *_Nullable _percentEncodedUser; Index: src/OFIRI.m ================================================================== --- src/OFIRI.m +++ src/OFIRI.m @@ -27,11 +27,10 @@ #endif #import "OFNumber.h" #import "OFOnce.h" #import "OFPair.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" @@ -955,33 +954,10 @@ - (instancetype)of_init { return [super init]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - void *pool = objc_autoreleasePoolPush(); - OFString *stringValue; - - @try { - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - stringValue = element.stringValue; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithString: stringValue]; - - objc_autoreleasePoolPop(pool); - - return self; -} - - (void)dealloc { [_scheme release]; [_percentEncodedHost release]; [_port release]; @@ -1392,22 +1368,6 @@ - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.string]; } - -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - element = [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS - stringValue: self.string]; - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} @end Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -14,11 +14,10 @@ */ #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" -#import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @@ -79,12 +78,11 @@ /** * @class OFList OFList.h ObjFW/OFList.h * * @brief A class which provides easy to use double-linked lists. */ -@interface OFList OF_GENERIC(ObjectType): OFObject +@interface OFList OF_GENERIC(ObjectType): OFObject #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif { OFListItem _Nullable _firstListItem; Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -17,11 +17,10 @@ #include #import "OFList.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFArray.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" @@ -67,39 +66,10 @@ + (instancetype)list { return [[[self alloc] init] autorelease]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [self init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - for (OFXMLElement *child in - [element elementsForNamespace: OFSerializationNS]) { - void *pool2 = objc_autoreleasePoolPush(); - - [self appendObject: child.objectByDeserializing]; - - objc_autoreleasePoolPop(pool2); - } - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - - (void)dealloc { OFListItem next; for (OFListItem iter = _firstListItem; iter != NULL; iter = next) { @@ -371,28 +341,10 @@ [ret makeImmutable]; return ret; } -- (OFXMLElement *)XMLElementBySerializing -{ - OFXMLElement *element = - [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS]; - - for (OFListItem iter = _firstListItem; - iter != NULL; iter = iter->next) { - void *pool = objc_autoreleasePoolPush(); - - [element addChild: [iter->object XMLElementBySerializing]]; - - objc_autoreleasePoolPop(pool); - } - - return element; -} - - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { OFListItem listItem; Index: src/OFMapTableDictionary.m ================================================================== --- src/OFMapTableDictionary.m +++ src/OFMapTableDictionary.m @@ -19,11 +19,10 @@ #import "OFArray.h" #import "OFMapTable+Private.h" #import "OFMapTable.h" #import "OFMutableMapTableDictionary.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @@ -225,63 +224,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - OFArray *keys, *objects; - OFEnumerator *keyEnumerator, *objectEnumerator; - OFXMLElement *keyElement, *objectElement; - - keys = [element elementsForName: @"key" - namespace: OFSerializationNS]; - objects = [element elementsForName: @"object" - namespace: OFSerializationNS]; - - if (keys.count != objects.count) - @throw [OFInvalidFormatException exception]; - - _mapTable = [[OFMapTable alloc] - initWithKeyFunctions: keyFunctions - objectFunctions: objectFunctions - capacity: keys.count]; - - keyEnumerator = [keys objectEnumerator]; - objectEnumerator = [objects objectEnumerator]; - while ((keyElement = [keyEnumerator nextObject]) != nil && - (objectElement = [objectEnumerator nextObject]) != nil) { - void *pool2 = objc_autoreleasePoolPush(); - OFXMLElement *key, *object; - - key = [keyElement elementsForNamespace: - OFSerializationNS].firstObject; - object = [objectElement elementsForNamespace: - OFSerializationNS].firstObject; - - if (key == nil || object == nil) - @throw [OFInvalidFormatException exception]; - - [_mapTable setObject: object.objectByDeserializing - forKey: key.objectByDeserializing]; - - objc_autoreleasePoolPop(pool2); - } - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (void)dealloc { Index: src/OFMapTableSet.m ================================================================== --- src/OFMapTableSet.m +++ src/OFMapTableSet.m @@ -20,11 +20,10 @@ #import "OFCountedMapTableSet.h" #import "OFMapTable.h" #import "OFMapTable+Private.h" #import "OFMutableMapTableSet.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFEnumerationMutationException.h" static void * @@ -176,41 +175,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [self init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if ((![element.name isEqual: @"OFSet"] && - ![element.name isEqual: @"OFMutableSet"]) || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - for (OFXMLElement *child in - [element elementsForNamespace: OFSerializationNS]) { - void *pool2 = objc_autoreleasePoolPush(); - - [_mapTable setObject: (void *)1 - forKey: [child objectByDeserializing]]; - - objc_autoreleasePoolPop(pool2); - } - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (void)dealloc { Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -122,16 +122,10 @@ { return (id)[[OFMutableAdjacentArray alloc] initWithObjects: objects count: count]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFMutableAdjacentArray alloc] - initWithSerialization: element]; -} - - (instancetype)retain { return self; } Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -78,16 +78,10 @@ { return (id)[[OFMutableMapTableDictionary alloc] initWithKey: firstKey arguments: arguments]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFMutableMapTableDictionary alloc] - initWithSerialization: element]; -} - - (instancetype)initWithCapacity: (size_t)capacity { return (id)[[OFMutableMapTableDictionary alloc] initWithCapacity: capacity]; } Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -67,16 +67,10 @@ { return (id)[[OFMutableMapTableSet alloc] initWithObject: firstObject arguments: arguments]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFMutableMapTableSet alloc] - initWithSerialization: element]; -} - - (instancetype)initWithCapacity: (size_t)capacity { return (id)[[OFMutableMapTableSet alloc] initWithCapacity: capacity]; } Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -185,15 +185,10 @@ return (id)[[OFMutableUTF8String alloc] initWithContentsOfIRI: IRI encoding: encoding]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFMutableUTF8String alloc] initWithSerialization: element]; -} - - (instancetype)retain { return self; } Index: src/OFNull.h ================================================================== --- src/OFNull.h +++ src/OFNull.h @@ -14,21 +14,20 @@ */ #import "OFObject.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" -#import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFNull OFNull.h ObjFW/OFNull.h * * @brief A class for representing null values in collections. */ OF_SUBCLASSING_RESTRICTED -@interface OFNull: OFObject /** * @brief Returns an OFNull singleton. * * @return An OFNull singleton Index: src/OFNull.m ================================================================== --- src/OFNull.m +++ src/OFNull.m @@ -14,13 +14,12 @@ */ #include "config.h" #import "OFNull.h" -#import "OFString.h" -#import "OFXMLElement.h" #import "OFData.h" +#import "OFString.h" #import "OFInvalidArgumentException.h" @interface OFNull () - (OFString *) @@ -39,27 +38,10 @@ + (OFNull *)null { return null; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - void *pool; - - [self release]; - - pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - objc_autoreleasePoolPop(pool); - - return [OFNull null]; -} - - (OFString *)description { return @""; } @@ -66,25 +48,10 @@ - (id)copy { return self; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - element = [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS]; - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -26,11 +26,10 @@ # include #endif #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" -#import "OFSerialization.h" #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @@ -41,12 +40,12 @@ * @brief Provides a way to store a number in an object. */ #ifndef OF_NUMBER_M OF_SUBCLASSING_RESTRICTED #endif -@interface OFNumber: OFValue +@interface OFNumber: OFValue { union { double float_; long long signed_; unsigned long long unsigned_; Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -18,14 +18,12 @@ #include "config.h" #include #import "OFNumber.h" -#import "OFString.h" -#import "OFXMLElement.h" -#import "OFXMLAttribute.h" #import "OFData.h" +#import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @@ -375,15 +373,10 @@ return (id)doubleZeroNumber; } return (id)[[OFNumber of_alloc] initWithDouble: value]; } - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFNumber of_alloc] initWithSerialization: element]; -} #ifdef __clang__ # pragma clang diagnostic pop #endif @end @@ -782,58 +775,10 @@ _typeEncoding = @encode(double); return self; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - OFString *typeString; - - if (![element.name isEqual: @"OFNumber"] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - typeString = [element attributeForName: @"type"].stringValue; - - if ([typeString isEqual: @"bool"]) { - OFString *stringValue = element.stringValue; - if ([stringValue isEqual: @"true"]) - self = [self initWithBool: true]; - else if ([stringValue isEqual: @"false"]) - self = [self initWithBool: false]; - else - @throw [OFInvalidArgumentException exception]; - } else if ([typeString isEqual: @"float"]) { - unsigned long long value = - [element unsignedLongLongValueWithBase: 16]; - - if (value > UINT64_MAX) - @throw [OFOutOfRangeException exception]; - - self = [self initWithDouble: OFFromBigEndianDouble( - OFRawUInt64ToDouble(OFToBigEndian64(value)))]; - } else if ([typeString isEqual: @"signed"]) - self = [self initWithLongLong: element.longLongValue]; - else if ([typeString isEqual: @"unsigned"]) - self = [self initWithUnsignedLongLong: - element.unsignedLongLongValue]; - else - @throw [OFInvalidArgumentException exception]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - - (const char *)objCType { return _typeEncoding; } @@ -1077,42 +1022,10 @@ self.unsignedLongLongValue]; @throw [OFInvalidFormatException exception]; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - element = [OFXMLElement elementWithName: @"OFNumber" - namespace: OFSerializationNS - stringValue: self.description]; - - if (*self.objCType == 'B') - [element addAttributeWithName: @"type" stringValue: @"bool"]; - else if (isFloat(self)) { - [element addAttributeWithName: @"type" stringValue: @"float"]; - element.stringValue = [OFString - stringWithFormat: @"%016" PRIx64, - OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( - self.doubleValue)))]; - } else if (isSigned(self)) - [element addAttributeWithName: @"type" stringValue: @"signed"]; - else if (isUnsigned(self)) - [element addAttributeWithName: @"type" - stringValue: @"unsigned"]; - else - @throw [OFInvalidFormatException exception]; - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } DELETED src/OFObject+Serialization.h Index: src/OFObject+Serialization.h ================================================================== --- src/OFObject+Serialization.h +++ src/OFObject+Serialization.h @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFObject.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFString; - -#ifdef __cplusplus -extern "C" { -#endif -extern int _OFObject_Serialization_reference; -#ifdef __cplusplus -} -#endif - -@interface OFObject (OFSerialization) -/** - * @brief The object serialized as a string. - */ -@property (readonly, nonatomic) OFString *stringBySerializing; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFObject+Serialization.m Index: src/OFObject+Serialization.m ================================================================== --- src/OFObject+Serialization.m +++ src/OFObject+Serialization.m @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2008-2023 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. - */ - -#include "config.h" - -#include - -#import "OFObject.h" -#import "OFObject+Serialization.h" -#import "OFSerialization.h" -#import "OFString.h" -#import "OFXMLElement.h" - -int _OFObject_Serialization_reference; - -@implementation OFObject (Serialization) -- (OFString *)stringBySerializing -{ - void *pool; - OFXMLElement *element; - OFXMLElement *root; - OFString *ret; - - if (![self conformsToProtocol: @protocol(OFSerialization)]) { - [self doesNotRecognizeSelector: _cmd]; - abort(); - } - - pool = objc_autoreleasePoolPush(); - element = ((id )self).XMLElementBySerializing; - - root = [OFXMLElement elementWithName: @"serialization" - namespace: OFSerializationNS]; - [root addAttributeWithName: @"version" stringValue: @"1"]; - [root addChild: element]; - - ret = [@"\n" - stringByAppendingString: [root XMLStringWithIndentation: 2]]; - - [ret retain]; - - objc_autoreleasePoolPop(pool); - - return [ret autorelease]; -} -@end Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -1514,9 +1514,8 @@ #include "OFBlock.h" #ifdef __OBJC__ # import "OFObject+KeyValueCoding.h" -# import "OFObject+Serialization.h" #endif #endif Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -385,11 +385,10 @@ /* References for static linking */ void _references_to_categories_of_OFObject(void) { _OFObject_KeyValueCoding_reference = 1; - _OFObject_Serialization_reference = 1; } @implementation OFObject + (void)load { Index: src/OFSecureData.h ================================================================== --- src/OFSecureData.h +++ src/OFSecureData.h @@ -151,11 +151,10 @@ - (instancetype)initWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI OF_UNAVAILABLE; - (instancetype)initWithStringRepresentation: (OFString *)string OF_UNAVAILABLE; - (instancetype)initWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE; -- (instancetype)initWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE; /** * @brief Returns a specific item of the OFSecureData. * * Modifying the returned item directly is allowed and will change the contents @@ -186,10 +185,9 @@ - (OFString *)stringByBase64Encoding OF_UNAVAILABLE; #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path OF_UNAVAILABLE; #endif - (void)writeToIRI: (OFIRI *)IRI OF_UNAVAILABLE; -- (OFXMLElement *)XMLElementBySerializing OF_UNAVAILABLE; - (OFData *)messagePackRepresentation OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END Index: src/OFSecureData.m ================================================================== --- src/OFSecureData.m +++ src/OFSecureData.m @@ -512,15 +512,10 @@ - (instancetype)initWithBase64EncodedString: (OFString *)string { OF_INVALID_INIT_METHOD } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - OF_INVALID_INIT_METHOD -} - - (void)dealloc { [self zero]; #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) @@ -631,18 +626,13 @@ } #endif - (void)writeToIRI: (OFIRI *)IRI { - OF_UNRECOGNIZED_SELECTOR -} - -- (OFXMLElement *)XMLElementBySerializing -{ OF_UNRECOGNIZED_SELECTOR } - (OFData *)messagePackRepresentation { OF_UNRECOGNIZED_SELECTOR } @end DELETED src/OFSerialization.h Index: src/OFSerialization.h ================================================================== --- src/OFSerialization.h +++ src/OFSerialization.h @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFObject.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFConstantString; -@class OFXMLElement; - -/** - * @protocol OFSerialization OFSerialization.h ObjFW/OFSerialization.h - * - * @brief A protocol for serializing objects. - */ -@protocol OFSerialization -/** - * @brief The object serialized into an XML element. - */ -@property (readonly, nonatomic) OFXMLElement *XMLElementBySerializing; - -/** - * @brief Initializes the object with the specified XML element serialization. - * - * @param element An OFXMLElement with the serialized object - * @return An initialized object - * @throw OFInvalidFormatException The specified element is not of the correct - * serialization format - */ -- (instancetype)initWithSerialization: (OFXMLElement *)element; -@end - -#ifdef __cplusplus -extern "C" { -#endif -extern OFConstantString *const OFSerializationNS; -#ifdef __cplusplus -} -#endif - -OF_ASSUME_NONNULL_END DELETED src/OFSerialization.m Index: src/OFSerialization.m ================================================================== --- src/OFSerialization.m +++ src/OFSerialization.m @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2008-2023 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" - -OFConstantString *const OFSerializationNS = - @"https://objfw.nil.im/serialization"; Index: src/OFSet.h ================================================================== --- src/OFSet.h +++ src/OFSet.h @@ -22,11 +22,10 @@ #include #import "OFObject.h" #import "OFCollection.h" -#import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @@ -61,11 +60,11 @@ * * @note Subclasses must implement @ref count, @ref containsObject: and * @ref objectEnumerator. */ @interface OFSet OF_GENERIC(ObjectType): OFObject + OFMutableCopying> #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** * @brief An array of all objects in the set. Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -20,11 +20,10 @@ #import "OFSet.h" #import "OFArray.h" #import "OFMapTableSet.h" #import "OFNull.h" #import "OFString.h" -#import "OFXMLElement.h" static struct { Class isa; } placeholder; @@ -70,15 +69,10 @@ { return (id)[[OFMapTableSet alloc] initWithObject: firstObject arguments: arguments]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFMapTableSet alloc] initWithSerialization: element]; -} - - (instancetype)retain { return self; } @@ -189,15 +183,10 @@ return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ OF_INVALID_INIT_METHOD } - (size_t)count { @@ -360,35 +349,10 @@ return true; return false; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - if ([self isKindOfClass: [OFMutableSet class]]) - element = [OFXMLElement elementWithName: @"OFMutableSet" - namespace: OFSerializationNS]; - else - element = [OFXMLElement elementWithName: @"OFSet" - namespace: OFSerializationNS]; - - for (id object in self) { - void *pool2 = objc_autoreleasePoolPush(); - [element addChild: object.XMLElementBySerializing]; - objc_autoreleasePoolPop(pool2); - } - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFSet *)setByAddingObjectsFromSet: (OFSet *)set { OFMutableSet *new = [[self mutableCopy] autorelease]; [new unionSet: set]; [new makeImmutable]; DELETED src/OFString+Serialization.h Index: src/OFString+Serialization.h ================================================================== --- src/OFString+Serialization.h +++ src/OFString+Serialization.h @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFString.h" - -OF_ASSUME_NONNULL_BEGIN - -#ifdef __cplusplus -extern "C" { -#endif -extern int _OFString_Serialization_reference; -#ifdef __cplusplus -} -#endif - -@interface OFString (Serialization) -/** - * @brief The string interpreted as serialization and parsed as an object. - * - * @throw OFMalformedXMLException The XML was malformed - * @throw OFUnboundNamespaceException A prefix was used that was not bound to - * any namespace - * @throw OFInvalidEncodingException The XML is not in the encoding it specified - * @throw OFUnsupportedVersionException The serialization is in an unsupported - * version - */ -@property (readonly, nonatomic) id objectByDeserializing; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFString+Serialization.m Index: src/OFString+Serialization.m ================================================================== --- src/OFString+Serialization.m +++ src/OFString+Serialization.m @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2008-2023 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. - */ - -#include "config.h" - -#import "OFString.h" -#import "OFString+Serialization.h" -#import "OFSerialization.h" -#import "OFArray.h" -#import "OFXMLElement.h" -#import "OFXMLAttribute.h" - -#import "OFInvalidArgumentException.h" -#import "OFMalformedXMLException.h" -#import "OFUnboundNamespaceException.h" -#import "OFUnsupportedVersionException.h" - -int _OFString_Serialization_reference; - -@implementation OFString (Serialization) -- (id)objectByDeserializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *root; - OFString *version; - OFArray *elements; - id object; - - root = [OFXMLElement elementWithXMLString: self]; - - version = [root attributeForName: @"version"].stringValue; - if (version == nil) - @throw [OFInvalidArgumentException exception]; - - if (version.unsignedLongLongValue != 1) - @throw [OFUnsupportedVersionException - exceptionWithVersion: version]; - - elements = [root elementsForNamespace: OFSerializationNS]; - - if (elements.count != 1) - @throw [OFInvalidArgumentException exception]; - - object = [[elements.firstObject objectByDeserializing] retain]; - - objc_autoreleasePoolPop(pool); - - return [object autorelease]; -} -@end Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -35,11 +35,10 @@ # include #endif #include "OFObject.h" #ifdef __OBJC__ -# import "OFSerialization.h" # import "OFJSONRepresentation.h" # import "OFMessagePackRepresentation.h" #endif OF_ASSUME_NONNULL_BEGIN @@ -142,11 +141,11 @@ * @class OFString OFString.h ObjFW/OFString.h * * @brief A class for handling strings. */ @interface OFString: OFObject + OFJSONRepresentation, OFMessagePackRepresentation> /** * @brief The length of the string in Unicode codepoints. */ @property (readonly, nonatomic) size_t length; @@ -1369,11 +1368,10 @@ # ifdef OF_HAVE_FILES # import "OFString+PathAdditions.h" # endif # import "OFString+PercentEncoding.h" # import "OFString+PropertyListParsing.h" -# import "OFString+Serialization.h" # import "OFString+XMLEscaping.h" # import "OFString+XMLUnescaping.h" #endif #if defined(__OBJC__) && !defined(NSINTEGER_DEFINED) && !__has_feature(modules) Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -44,11 +44,10 @@ #import "OFLocale.h" #import "OFStream.h" #import "OFSystemInfo.h" #import "OFUTF8String.h" #import "OFUTF8String+Private.h" -#import "OFXMLElement.h" #import "OFGetItemAttributesFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @@ -133,11 +132,10 @@ #ifdef OF_HAVE_FILES _OFString_PathAdditions_reference = 1; #endif _OFString_PercentEncoding_reference = 1; _OFString_PropertyListParsing_reference = 1; - _OFString_Serialization_reference = 1; _OFString_XMLEscaping_reference = 1; _OFString_XMLUnescaping_reference = 1; } void @@ -592,15 +590,10 @@ { return (id)[[OFUTF8String alloc] initWithContentsOfIRI: IRI encoding: encoding]; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - return (id)[[OFUTF8String alloc] initWithSerialization: element]; -} - - (instancetype)retain { return self; } @@ -1074,40 +1067,10 @@ self = [self initWithCString: data.items encoding: encoding length: data.count * data.itemSize]; - objc_autoreleasePoolPop(pool); - - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - void *pool = objc_autoreleasePoolPush(); - OFString *stringValue; - - @try { - if (![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - if ([self isKindOfClass: [OFMutableString class]]) { - if (![element.name isEqual: @"OFMutableString"]) - @throw [OFInvalidArgumentException exception]; - } else { - if (![element.name isEqual: @"OFString"]) - @throw [OFInvalidArgumentException exception]; - } - - stringValue = element.stringValue; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithString: stringValue]; - objc_autoreleasePoolPop(pool); return self; } @@ -1680,32 +1643,10 @@ - (OFString *)description { return [[self copy] autorelease]; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - OFString *className; - - if ([self isKindOfClass: [OFMutableString class]]) - className = @"OFMutableString"; - else - className = @"OFString"; - - element = [OFXMLElement elementWithName: className - namespace: OFSerializationNS - stringValue: self]; - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } Index: src/OFUUID.h ================================================================== --- src/OFUUID.h +++ src/OFUUID.h @@ -12,11 +12,10 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @@ -24,11 +23,11 @@ * @class OFUUID OFUUID.h ObjFW/OFUUID.h * * @brief A UUID conforming to RFC 4122. */ OF_SUBCLASSING_RESTRICTED -@interface OFUUID: OFObject +@interface OFUUID: OFObject { unsigned char _bytes[16]; } /** Index: src/OFUUID.m ================================================================== --- src/OFUUID.m +++ src/OFUUID.m @@ -16,11 +16,10 @@ #include "config.h" #import "OFUUID.h" #import "OFArray.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @@ -143,33 +142,10 @@ } return self; } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - void *pool = objc_autoreleasePoolPush(); - OFString *UUIDString; - - @try { - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - UUIDString = element.stringValue; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithUUIDString: UUIDString]; - - objc_autoreleasePoolPop(pool); - - return self; -} - - (bool)isEqual: (id)object { OFUUID *UUID; if (![object isKindOfClass: [OFUUID class]]) @@ -233,20 +209,6 @@ - (OFString *)description { return self.UUIDString; } - -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element = [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS - stringValue: self.UUIDString]; - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} @end Index: src/OFXMLAttribute.h ================================================================== --- src/OFXMLAttribute.h +++ src/OFXMLAttribute.h @@ -90,10 +90,8 @@ * @return An initialized OFXMLAttribute with the specified parameters */ - (instancetype)initWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (OFString *)stringValue OF_DESIGNATED_INITIALIZER; - -- (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END Index: src/OFXMLAttribute.m ================================================================== --- src/OFXMLAttribute.m +++ src/OFXMLAttribute.m @@ -17,11 +17,10 @@ #import "OFXMLAttribute.h" #import "OFXMLNode+Private.h" #import "OFString.h" #import "OFDictionary.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" @implementation OFXMLAttribute @synthesize name = _name, namespace = _namespace; @@ -63,46 +62,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - void *pool; - OFString *name, *namespace, *stringValue; - - @try { - pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - name = [element attributeForName: @"name"].stringValue; - namespace = [element attributeForName: @"namespace"] - .stringValue; - stringValue = [element attributeForName: @"stringValue"] - .stringValue; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithName: name - namespace: namespace - stringValue: stringValue]; - - @try { - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (void)dealloc { @@ -161,36 +124,13 @@ OFHashFinalize(&hash); return hash; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - element = [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS]; - [element addAttributeWithName: @"name" stringValue: _name]; - - if (_namespace != nil) - [element addAttributeWithName: @"namespace" - stringValue: _namespace]; - - [element addAttributeWithName: @"stringValue" - stringValue: _stringValue]; - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (OFString *)description { return [OFString stringWithFormat: @"<%@: name=%@, namespace=%@, " @"stringValue=%@>", self.class, _name, _namespace, _stringValue]; } @end Index: src/OFXMLCDATA.h ================================================================== --- src/OFXMLCDATA.h +++ src/OFXMLCDATA.h @@ -41,10 +41,8 @@ * * @param string The string value for the CDATA * @return An initialized OFXMLCDATA */ - (instancetype)initWithString: (OFString *)string; - -- (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END Index: src/OFXMLCDATA.m ================================================================== --- src/OFXMLCDATA.m +++ src/OFXMLCDATA.m @@ -16,11 +16,10 @@ #include "config.h" #import "OFXMLCDATA.h" #import "OFXMLNode+Private.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" @implementation OFXMLCDATA + (instancetype)CDATAWithString: (OFString *)string @@ -37,32 +36,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [super of_init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - _CDATA = [element.stringValue copy]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (void)dealloc { @@ -118,16 +95,6 @@ - (OFString *)description { return self.XMLString; } - -- (OFXMLElement *)XMLElementBySerializing -{ - OFXMLElement *element = - [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS]; - [element addChild: self]; - - return element; -} @end Index: src/OFXMLCharacters.h ================================================================== --- src/OFXMLCharacters.h +++ src/OFXMLCharacters.h @@ -42,10 +42,8 @@ * * @param string The string value for the characters * @return An initialized OFXMLCharacters */ - (instancetype)initWithString: (OFString *)string; - -- (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END Index: src/OFXMLCharacters.m ================================================================== --- src/OFXMLCharacters.m +++ src/OFXMLCharacters.m @@ -16,11 +16,10 @@ #include "config.h" #import "OFXMLCharacters.h" #import "OFXMLNode+Private.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" @implementation OFXMLCharacters + (instancetype)charactersWithString: (OFString *)string @@ -37,32 +36,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [super of_init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - _characters = [element.stringValue copy]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (void)dealloc { @@ -110,13 +87,6 @@ - (OFString *)description { return self.XMLString; } - -- (OFXMLElement *)XMLElementBySerializing -{ - return [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS - stringValue: _characters]; -} @end Index: src/OFXMLComment.h ================================================================== --- src/OFXMLComment.h +++ src/OFXMLComment.h @@ -47,10 +47,8 @@ * * @param text The text for the comment * @return An initialized OFXMLComment */ - (instancetype)initWithText: (OFString *)text; - -- (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END Index: src/OFXMLComment.m ================================================================== --- src/OFXMLComment.m +++ src/OFXMLComment.m @@ -18,11 +18,10 @@ #include #import "OFXMLComment.h" #import "OFXMLNode+Private.h" #import "OFString.h" -#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" @implementation OFXMLComment @synthesize text = _text; @@ -41,32 +40,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - self = [super of_init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - _text = [element.stringValue copy]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (void)dealloc { @@ -107,13 +84,6 @@ - (OFString *)description { return self.XMLString; } - -- (OFXMLElement *)XMLElementBySerializing -{ - return [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS - stringValue: _text]; -} @end DELETED src/OFXMLElement+Serialization.h Index: src/OFXMLElement+Serialization.h ================================================================== --- src/OFXMLElement+Serialization.h +++ src/OFXMLElement+Serialization.h @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFXMLElement.h" - -OF_ASSUME_NONNULL_BEGIN - -#ifdef __cplusplus -extern "C" { -#endif -extern int _OFXMLElement_Serialization_reference; -#ifdef __cplusplus -} -#endif - -@interface OFXMLElement (OFSerialization) -/** - * @brief The XML element interpreted as serialization and parsed into an - * object. - */ -@property (readonly, nonatomic) id objectByDeserializing; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFXMLElement+Serialization.m Index: src/OFXMLElement+Serialization.m ================================================================== --- src/OFXMLElement+Serialization.m +++ src/OFXMLElement+Serialization.m @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2008-2023 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. - */ - -#include "config.h" - -#import "OFXMLElement.h" -#import "OFXMLElement+Serialization.h" -#import "OFSerialization.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" - -int _OFXMLElement_Serialization_reference; - -@implementation OFXMLElement (Serialization) -- (id)objectByDeserializing -{ - void *pool = objc_autoreleasePoolPush(); - Class class; - id object; - - if ((class = objc_getClass([_name cStringWithEncoding: - OFStringEncodingASCII])) == Nil) - @throw [OFInvalidArgumentException exception]; - - if (![class conformsToProtocol: @protocol(OFSerialization)]) - @throw [OFInvalidArgumentException exception]; - - object = [[class alloc] initWithSerialization: self]; - - objc_autoreleasePoolPop(pool); - - return [object autorelease]; -} -@end Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -432,7 +432,5 @@ - (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS indentation: (unsigned int)indentation; @end OF_ASSUME_NONNULL_END - -#import "OFXMLElement+Serialization.h" Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -36,17 +36,10 @@ #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFUnboundNamespaceException.h" -/* References for static linking */ -void -_references_to_categories_of_OFXMLElement(void) -{ - _OFXMLElement_Serialization_reference = 1; -} - @interface OFXMLElementElementBuilderDelegate: OFObject { @public OFXMLElement *_element; @@ -265,108 +258,10 @@ [_namespaces release]; _namespaces = [element->_namespaces retain]; [_children release]; _children = [element->_children retain]; - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - void *pool; - OFString *name, *namespace; - - @try { - pool = objc_autoreleasePoolPush(); - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - name = [element attributeForName: @"name"].stringValue; - namespace = - [element attributeForName: @"namespace"].stringValue; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithName: name namespace: namespace]; - - @try { - OFXMLElement *attributesElement, *namespacesElement; - OFXMLElement *childrenElement; - OFEnumerator *keyEnumerator, *objectEnumerator; - OFString *key, *object; - - attributesElement = [[element - elementForName: @"attributes" - namespace: OFSerializationNS] - elementsForNamespace: OFSerializationNS].firstObject; - namespacesElement = [[element - elementForName: @"namespaces" - namespace: OFSerializationNS] - elementsForNamespace: OFSerializationNS].firstObject; - childrenElement = [[element - elementForName: @"children" - namespace: OFSerializationNS] - elementsForNamespace: OFSerializationNS].firstObject; - - [_attributes release]; - _attributes = nil; - _attributes = [attributesElement.objectByDeserializing - mutableCopy]; - - [_namespaces release]; - _namespaces = nil; - _namespaces = [namespacesElement.objectByDeserializing - mutableCopy]; - - [_children release]; - _children = nil; - _children = [childrenElement.objectByDeserializing - mutableCopy]; - - /* Sanity checks */ - if ((_attributes != nil && ![_attributes isKindOfClass: - [OFMutableArray class]]) || (_namespaces != nil && - ![_namespaces isKindOfClass: - [OFMutableDictionary class]]) || (_children != nil && - ![_children isKindOfClass: [OFMutableArray class]])) - @throw [OFInvalidArgumentException exception]; - - for (OFXMLAttribute *attribute in _attributes) - if (![attribute isKindOfClass: [OFXMLAttribute class]]) - @throw [OFInvalidArgumentException exception]; - - keyEnumerator = [_namespaces keyEnumerator]; - objectEnumerator = [_namespaces objectEnumerator]; - while ((key = [keyEnumerator nextObject]) != nil && - (object = [objectEnumerator nextObject]) != nil) - if (![key isKindOfClass: [OFString class]] || - ![object isKindOfClass: [OFString class]]) - @throw [OFInvalidArgumentException exception]; - - for (object in _children) - if (![object isKindOfClass: [OFXMLNode class]]) - @throw [OFInvalidArgumentException exception]; - - if (_namespaces == nil) - _namespaces = [[OFMutableDictionary alloc] init]; - - [_namespaces - setObject: @"xml" - forKey: @"http://www.w3.org/XML/1998/namespace"]; - [_namespaces setObject: @"xmlns" - forKey: @"http://www.w3.org/2000/xmlns/"]; - objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -666,73 +561,10 @@ namespaces: nil indentation: indentation level: 0]; } -- (OFXMLElement *)XMLElementBySerializing -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLElement *element; - - element = [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS]; - - if (_name != nil) - [element addAttributeWithName: @"name" stringValue: _name]; - - if (_namespace != nil) - [element addAttributeWithName: @"namespace" - stringValue: _namespace]; - - if (_attributes != nil) { - OFXMLElement *attributesElement; - - attributesElement = - [OFXMLElement elementWithName: @"attributes" - namespace: OFSerializationNS]; - [attributesElement addChild: - _attributes.XMLElementBySerializing]; - [element addChild: attributesElement]; - } - - if (_namespaces != nil) { - OFXMLElement *namespacesElement; - OFMutableDictionary *namespacesCopy = - [[_namespaces mutableCopy] autorelease]; - - [namespacesCopy removeObjectForKey: - @"http://www.w3.org/XML/1998/namespace"]; - [namespacesCopy removeObjectForKey: - @"http://www.w3.org/2000/xmlns/"]; - - if (namespacesCopy.count > 0) { - namespacesElement = - [OFXMLElement elementWithName: @"namespaces" - namespace: OFSerializationNS]; - [namespacesElement addChild: - namespacesCopy.XMLElementBySerializing]; - [element addChild: namespacesElement]; - } - } - - if (_children != nil) { - OFXMLElement *childrenElement; - - childrenElement = - [OFXMLElement elementWithName: @"children" - namespace: OFSerializationNS]; - [childrenElement addChild: _children.XMLElementBySerializing]; - [element addChild: childrenElement]; - } - - [element retain]; - - objc_autoreleasePoolPop(pool); - - return [element autorelease]; -} - - (void)addAttribute: (OFXMLAttribute *)attribute { if (![attribute isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; Index: src/OFXMLNode.h ================================================================== --- src/OFXMLNode.h +++ src/OFXMLNode.h @@ -12,22 +12,19 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN -@class OFXMLElement; - /** * @class OFXMLNode OFXMLNode.h ObjFW/OFXMLNode.h * * @brief A class which stores an XML element. */ -@interface OFXMLNode: OFObject +@interface OFXMLNode: OFObject { OF_RESERVE_IVARS(OFXMLNode, 4) } /** @@ -75,11 +72,10 @@ * needs a prefix */ @property (readonly, nonatomic) OFString *XMLString; - (instancetype)init OF_UNAVAILABLE; -- (instancetype)initWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE; /** * @brief The contents of the receiver as a `long long` value in the specified * base. * Index: src/OFXMLNode.m ================================================================== --- src/OFXMLNode.m +++ src/OFXMLNode.m @@ -27,15 +27,10 @@ - (instancetype)init { OF_INVALID_INIT_METHOD } -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - OF_INVALID_INIT_METHOD -} - - (OFString *)stringValue { OF_UNRECOGNIZED_SELECTOR } @@ -82,15 +77,10 @@ - (OFString *)description { return self.XMLString; } -- (OFXMLElement *)XMLElementBySerializing -{ - OF_UNRECOGNIZED_SELECTOR -} - - (id)copy { return [self retain]; } @end Index: src/OFXMLProcessingInstruction.h ================================================================== --- src/OFXMLProcessingInstruction.h +++ src/OFXMLProcessingInstruction.h @@ -58,10 +58,8 @@ * @param text The text for the processing instruction * @return An initialized OFXMLProcessingInstruction */ - (instancetype)initWithTarget: (OFString *)target text: (OFString *)text OF_DESIGNATED_INITIALIZER; - -- (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END Index: src/OFXMLProcessingInstruction.m ================================================================== --- src/OFXMLProcessingInstruction.m +++ src/OFXMLProcessingInstruction.m @@ -18,11 +18,10 @@ #include #import "OFXMLProcessingInstruction.h" #import "OFString.h" #import "OFXMLAttribute.h" -#import "OFXMLElement.h" #import "OFXMLNode+Private.h" #import "OFInvalidArgumentException.h" @implementation OFXMLProcessingInstruction @@ -46,37 +45,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ - @try { - void *pool = objc_autoreleasePoolPush(); - OFXMLAttribute *targetAttr; - - if (![element.name isEqual: self.className] || - ![element.namespace isEqual: OFSerializationNS]) - @throw [OFInvalidArgumentException exception]; - - targetAttr = [element attributeForName: @"target" - namespace: OFSerializationNS]; - if (targetAttr.stringValue.length == 0) - @throw [OFInvalidArgumentException exception]; - - self = [self initWithTarget: targetAttr.stringValue - text: element.stringValue]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - return self; } - (void)dealloc { @@ -136,21 +108,6 @@ - (OFString *)description { return self.XMLString; } - -- (OFXMLElement *)XMLElementBySerializing -{ - OFXMLElement *ret = [OFXMLElement elementWithName: self.className - namespace: OFSerializationNS - stringValue: _text]; - void *pool = objc_autoreleasePoolPush(); - - [ret addAttribute: [OFXMLAttribute attributeWithName: @"target" - stringValue: _target]]; - - objc_autoreleasePoolPop(pool); - - return ret; -} @end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -8,11 +8,10 @@ boot.dol \ ${PROG_NOINST}.arm9 \ ${PROG_NOINST}.nds \ ${PROG_NOINST}.nro \ ${PROG_NOINST}.rpx \ - serialization_xml.m \ testfile_bin.m \ testfile_ini.m DISTCLEAN = Info.plist PROG_NOINST = tests${PROG_SUFFIX} @@ -46,11 +45,10 @@ OFSHA224HashTests.m \ OFSHA256HashTests.m \ OFSHA384HashTests.m \ OFSHA512HashTests.m \ OFScryptTests.m \ - OFSerializationTests.m \ OFSetTests.m \ OFStreamTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFValueTests.m \ @@ -63,11 +61,10 @@ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} \ - serialization_xml.m \ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ ${OF_HTTP_CLIENT_TESTS_M} \ @@ -92,12 +89,10 @@ IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk -serialization_xml.m: serialization.xml - ${SHELL} ../utils/objfw-embed serialization.xml serialization.xml $@ testfile_bin.m: testfile.bin ${SHELL} ../utils/objfw-embed testfile.bin testfile.bin $@ testfile_ini.m: testfile.ini ${SHELL} ../utils/objfw-embed testfile.ini testfile.ini $@ DELETED tests/OFSerializationTests.m Index: tests/OFSerializationTests.m ================================================================== --- tests/OFSerializationTests.m +++ tests/OFSerializationTests.m @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2008-2023 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. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFSerialization"; - -@implementation TestsAppDelegate (OFSerializationTests) -- (void)serializationTests -{ - void *pool = objc_autoreleasePoolPush(); - OFMutableDictionary *dict = [OFMutableDictionary dictionary]; - OFMutableArray *array = [OFMutableArray array]; - OFList *list = [OFList list]; - OFData *data; - OFString *string; - OFUUID *UUID; - - [array addObject: @"Qu\"xbar\ntest"]; - [array addObject: [OFNumber numberWithInt: 1234]]; - [array addObject: [OFNumber numberWithDouble: 1234.5678]]; - [array addObject: [OFMutableString stringWithString: @"asd"]]; - [array addObject: [OFDate dateWithTimeIntervalSince1970: 1234.5678]]; - - [dict setObject: @"Hello" forKey: array]; - [dict setObject: @"B\"la" forKey: @"Blub"]; - - [list appendObject: @"Hello"]; - [list appendObject: @"Wo\rld!\nHow are you?"]; - [list appendObject: [OFIRI IRIWithString: @"https://objfw.nil.im/"]]; - [list appendObject: - [OFXMLElement elementWithXMLString: @""]]; - [list appendObject: - [OFSet setWithObjects: @"foo", @"foo", @"bar", nil]]; - [list appendObject: - [OFCountedSet setWithObjects: @"foo", @"foo", @"bar", nil]]; - - [dict setObject: @"list" forKey: list]; - - data = [OFData dataWithItems: "0123456789:; - - - - 01234567-89ab-cdef-fedc-ba9876543210 - - - uuid - - - Blub - - - B"la - - - - Hello - Wo ld! -How are you? - https://objfw.nil.im/ - - - - - - - - - - bar - foo - - - - bar - - - foo - - - - - - list - - - MDEyMzQ1Njc4OTo7PEFCQ0RFRkdISklLTE1OT1BRUlNUVVZXWFla - - - data - - - - Qu"xbar -test - 1234 - 40934a456d5cfaad - asd - 40934a456d5cfaad - - - - Hello - - -