Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -362,10 +362,12 @@ 4BB61D4916DA2AB700986DE1 /* OFBinaryPackRepresentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BB61D4816DA2AB700986DE1 /* OFBinaryPackRepresentation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BC090441584F6760040640F /* OFInvalidJSONException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BC090421584F6760040640F /* OFInvalidJSONException.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BC090451584F6760040640F /* OFInvalidJSONException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC090431584F6760040640F /* OFInvalidJSONException.m */; }; 4BD653C5143B8489006182F0 /* OFTCPSocket+SOCKS5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD653C3143B8489006182F0 /* OFTCPSocket+SOCKS5.h */; settings = {ATTRIBUTES = (); }; }; 4BD653C6143B8489006182F0 /* OFTCPSocket+SOCKS5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD653C4143B8489006182F0 /* OFTCPSocket+SOCKS5.m */; }; + 4BD77FDE176E4BC40031C497 /* OFUnboundPrefixException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD77FDC176E4BC40031C497 /* OFUnboundPrefixException.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4BD77FDF176E4BC40031C497 /* OFUnboundPrefixException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD77FDD176E4BC40031C497 /* OFUnboundPrefixException.m */; }; 4BD98C03133814220048DD5B /* objfw-defs.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BD98C011338140B0048DD5B /* objfw-defs.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BDF37B51338055600F9A81A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDF37B41338055600F9A81A /* config.h */; }; 4BF33AFB133807590059CEF7 /* ObjFW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B3D23761337FBC800DD29B8 /* ObjFW.framework */; }; 4BF33AFC133807A20059CEF7 /* OFArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6EF66E1235358D0076B512 /* OFArrayTests.m */; }; 4BF33AFD133807A20059CEF7 /* OFBlockTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE5F0E412DF4259005C7A0C /* OFBlockTests.m */; }; @@ -788,10 +790,12 @@ 4BBA36C511406AB700CBA3AC /* macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = macros.h; path = src/macros.h; sourceTree = ""; }; 4BC090421584F6760040640F /* OFInvalidJSONException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFInvalidJSONException.h; path = src/exceptions/OFInvalidJSONException.h; sourceTree = ""; }; 4BC090431584F6760040640F /* OFInvalidJSONException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFInvalidJSONException.m; path = src/exceptions/OFInvalidJSONException.m; sourceTree = ""; }; 4BD653C3143B8489006182F0 /* OFTCPSocket+SOCKS5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFTCPSocket+SOCKS5.h"; path = "src/OFTCPSocket+SOCKS5.h"; sourceTree = ""; }; 4BD653C4143B8489006182F0 /* OFTCPSocket+SOCKS5.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFTCPSocket+SOCKS5.m"; path = "src/OFTCPSocket+SOCKS5.m"; sourceTree = ""; }; + 4BD77FDC176E4BC40031C497 /* OFUnboundPrefixException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFUnboundPrefixException.h; path = src/exceptions/OFUnboundPrefixException.h; sourceTree = ""; }; + 4BD77FDD176E4BC40031C497 /* OFUnboundPrefixException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFUnboundPrefixException.m; path = src/exceptions/OFUnboundPrefixException.m; sourceTree = ""; }; 4BD86D801237A6C600ED9912 /* OFBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFBlock.h; path = src/OFBlock.h; sourceTree = SOURCE_ROOT; }; 4BD86D811237A6C600ED9912 /* OFBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFBlock.m; path = src/OFBlock.m; sourceTree = SOURCE_ROOT; }; 4BD98C011338140B0048DD5B /* objfw-defs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "objfw-defs.h"; path = "src/objfw-defs.h"; sourceTree = SOURCE_ROOT; }; 4BDF37B41338055600F9A81A /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = SOURCE_ROOT; }; 4BE17AD812FD744C002CEB0B /* foundation-compat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "foundation-compat.m"; path = "src/foundation-compat.m"; sourceTree = SOURCE_ROOT; }; @@ -975,10 +979,12 @@ 4B55A0FE133ABEA900B58A93 /* OFThreadStillRunningException.m */, 4B17FFA7133A34DF003E6DCD /* OFTruncatedDataException.h */, 4B17FFA8133A34E1003E6DCD /* OFTruncatedDataException.m */, 4B17FFB3133A374C003E6DCD /* OFUnboundNamespaceException.h */, 4B17FFB4133A3750003E6DCD /* OFUnboundNamespaceException.m */, + 4BD77FDC176E4BC40031C497 /* OFUnboundPrefixException.h */, + 4BD77FDD176E4BC40031C497 /* OFUnboundPrefixException.m */, 4B6743EF163C384A00EB1E59 /* OFUnlockFailedException.h */, 4B6743F0163C384A00EB1E59 /* OFUnlockFailedException.m */, 4B17FFAF133A3658003E6DCD /* OFUnsupportedProtocolException.h */, 4B17FFB0133A365C003E6DCD /* OFUnsupportedProtocolException.m */, 4BA4846015CC9F1E00D75360 /* OFUnsupportedVersionException.h */, @@ -1506,10 +1512,11 @@ 4B17FFA9133A34E7003E6DCD /* OFTruncatedDataException.h in Headers */, 4B55A0FF133ABEA900B58A93 /* OFThreadJoinFailedException.h in Headers */, 4B55A101133ABEA900B58A93 /* OFThreadStartFailedException.h in Headers */, 4B55A103133ABEA900B58A93 /* OFThreadStillRunningException.h in Headers */, 4B17FFB5133A375B003E6DCD /* OFUnboundNamespaceException.h in Headers */, + 4BD77FDE176E4BC40031C497 /* OFUnboundPrefixException.h in Headers */, 4B6743F5163C384A00EB1E59 /* OFUnlockFailedException.h in Headers */, 4B17FFB1133A3664003E6DCD /* OFUnsupportedProtocolException.h in Headers */, 4BA4846215CC9F1E00D75360 /* OFUnsupportedVersionException.h in Headers */, 4B55A116133AC24600B58A93 /* OFWriteFailedException.h in Headers */, 4B55A109133AC05100B58A93 /* common.h in Headers */, @@ -1838,10 +1845,11 @@ 4B17FF9E133A32BA003E6DCD /* OFInvalidFormatException.m in Sources */, 4BC090451584F6760040640F /* OFInvalidJSONException.m in Sources */, 4B17FFBA133A381D003E6DCD /* OFInvalidServerReplyException.m in Sources */, 4B29BC62133AC9CB0004B236 /* OFLinkFailedException.m in Sources */, 4B90B7A7133AD87D00BD33CB /* OFListenFailedException.m in Sources */, + 4B6743F2163C384A00EB1E59 /* OFLockFailedException.m in Sources */, 4B17FFA2133A3335003E6DCD /* OFMalformedXMLException.m in Sources */, 4B17FF90133A3036003E6DCD /* OFMemoryNotPartOfObjectException.m in Sources */, 4B90B790133AD46700BD33CB /* OFNotConnectedException.m in Sources */, 4B17FF78133A2B18003E6DCD /* OFNotImplementedException.m in Sources */, 4B55A10B133AC05100B58A93 /* OFOpenFileFailedException.m in Sources */, @@ -1850,22 +1858,22 @@ 4B55A113133AC24600B58A93 /* OFReadFailedException.m in Sources */, 4B55A115133AC24600B58A93 /* OFReadOrWriteFailedException.m in Sources */, 4B29BC57133AC8420004B236 /* OFRenameFileFailedException.m in Sources */, 4B29BC42133AC4E80004B236 /* OFSeekFailedException.m in Sources */, 4B90B792133AD46700BD33CB /* OFSetOptionFailedException.m in Sources */, + 4B6743F4163C384A00EB1E59 /* OFStillLockedException.m in Sources */, 4B29BC64133AC9CB0004B236 /* OFSymlinkFailedException.m in Sources */, 4B55A100133ABEA900B58A93 /* OFThreadJoinFailedException.m in Sources */, 4B55A102133ABEA900B58A93 /* OFThreadStartFailedException.m in Sources */, 4B55A104133ABEA900B58A93 /* OFThreadStillRunningException.m in Sources */, 4B17FFAA133A34E7003E6DCD /* OFTruncatedDataException.m in Sources */, 4B17FFB6133A375B003E6DCD /* OFUnboundNamespaceException.m in Sources */, + 4BD77FDF176E4BC40031C497 /* OFUnboundPrefixException.m in Sources */, + 4B6743F6163C384A00EB1E59 /* OFUnlockFailedException.m in Sources */, 4B17FFB2133A3664003E6DCD /* OFUnsupportedProtocolException.m in Sources */, 4BA4846315CC9F1E00D75360 /* OFUnsupportedVersionException.m in Sources */, 4B55A117133AC24600B58A93 /* OFWriteFailedException.m in Sources */, - 4B6743F2163C384A00EB1E59 /* OFLockFailedException.m in Sources */, - 4B6743F4163C384A00EB1E59 /* OFStillLockedException.m in Sources */, - 4B6743F6163C384A00EB1E59 /* OFUnlockFailedException.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 4BF33AEC133807310059CEF7 /* Sources */ = { isa = PBXSourcesBuildPhase; Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -585,11 +585,12 @@ (attributePrefix = [allNamespaces objectForKey: [attributesObjects[j] namespace]]) == nil) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] namespace: [attributesObjects[j] - namespace]]; + namespace] + element: self]; length += [attributeName UTF8StringLength] + (attributePrefix != nil ? [attributePrefix UTF8StringLength] + 1 : 0) + [tmp UTF8StringLength] + 4; Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -30,11 +30,11 @@ #import "OFFile.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFMalformedXMLException.h" -#import "OFUnboundNamespaceException.h" +#import "OFUnboundPrefixException.h" #import "autorelease.h" #import "macros.h" typedef void (*state_function)(id, SEL); @@ -124,13 +124,14 @@ return; attributeNS = namespace_for_prefix(attributePrefix, namespaces); if ((attributePrefix != nil && attributeNS == nil)) - @throw [OFUnboundNamespaceException + @throw [OFUnboundPrefixException exceptionWithClass: [self class] - prefix: attributePrefix]; + prefix: attributePrefix + parser: self]; [attribute->_namespace release]; attribute->_namespace = [attributeNS retain]; } @@ -580,13 +581,14 @@ OFString *namespace; namespace = namespace_for_prefix(_prefix, _namespaces); if (_prefix != nil && namespace == nil) - @throw [OFUnboundNamespaceException + @throw [OFUnboundPrefixException exceptionWithClass: [self class] - prefix: _prefix]; + prefix: _prefix + parser: self]; if ([_delegate respondsToSelector: @selector(parser: didStartElement:prefix:namespace:attributes:)]) [_delegate parser: self didStartElement: _name @@ -669,13 +671,14 @@ [_buffer removeAllItems]; namespace = namespace_for_prefix(_prefix, _namespaces); if (_prefix != nil && namespace == nil) - @throw [OFUnboundNamespaceException + @throw [OFUnboundPrefixException exceptionWithClass: [self class] - prefix: _prefix]; + prefix: _prefix + parser: self]; if ([_delegate respondsToSelector: @selector(parser:didEndElement:prefix:namespace:)]) [_delegate parser: self didEndElement: _name @@ -721,13 +724,14 @@ attributesCount = [_attributes count]; namespace = namespace_for_prefix(_prefix, _namespaces); if (_prefix != nil && namespace == nil) - @throw [OFUnboundNamespaceException + @throw [OFUnboundPrefixException exceptionWithClass: [self class] - prefix: _prefix]; + prefix: _prefix + parser: self]; for (j = 0; j < attributesCount; j++) resolve_attribute_namespace(attributesObjects[j], _namespaces, self); Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -35,10 +35,11 @@ OFSetOptionFailedException.m \ OFStillLockedException.m \ OFSymlinkFailedException.m \ OFTruncatedDataException.m \ OFUnboundNamespaceException.m \ + OFUnboundPrefixException.m \ OFUnlockFailedException.m \ OFUnsupportedProtocolException.m \ OFUnsupportedVersionException.m \ OFWriteFailedException.m \ ${USE_SRCS_SOCKETS} \ Index: src/exceptions/OFUnboundNamespaceException.h ================================================================== --- src/exceptions/OFUnboundNamespaceException.h +++ src/exceptions/OFUnboundNamespaceException.h @@ -14,76 +14,63 @@ * file. */ #import "OFException.h" +@class OFXMLElement; + /*! * @brief An exception indicating an attempt to use an unbound namespace. */ @interface OFUnboundNamespaceException: OFException { - OFString *_namespace, *_prefix; + OFString *_namespace; + OFXMLElement *_element; } #ifdef OF_HAVE_PROPERTIES # ifdef __cplusplus @property (readonly, copy, nonatomic, getter=namespace) OFString *namespace_; # else @property (readonly, copy, nonatomic) OFString *namespace; # endif -@property (readonly, copy, nonatomic) OFString *prefix; +@property (readonly, retain, nonatomic) OFXMLElement *element; #endif /*! * @brief Creates a new, autoreleased unbound namespace exception. * * @param class_ The class of the object which caused the exception * @param namespace_ The namespace which is unbound + * @param element The element in which the namespace was not bound * @return A new, autoreleased unbound namespace exception */ + (instancetype)exceptionWithClass: (Class)class_ - namespace: (OFString*)namespace_; - -/*! - * @brief Creates a new, autoreleased unbound namespace exception. - * - * @param class_ The class of the object which caused the exception - * @param prefix The prefix which is unbound - * @return A new, autoreleased unbound namespace exception - */ -+ (instancetype)exceptionWithClass: (Class)class_ - prefix: (OFString*)prefix; + namespace: (OFString*)namespace_ + element: (OFXMLElement*)element; /*! * @brief Initializes an already allocated unbound namespace exception. * * @param class_ The class of the object which caused the exception * @param namespace_ The namespace which is unbound + * @param element The element in which the namespace was not bound * @return An initialized unbound namespace exception */ - initWithClass: (Class)class_ - namespace: (OFString*)namespace_; - -/*! - * @brief Initializes an already allocated unbound namespace exception. - * - * @param class_ The class of the object which caused the exception - * @param prefix The prefix which is unbound - * @return An initialized unbound namespace exception - */ -- initWithClass: (Class)class_ - prefix: (OFString*)prefix; + namespace: (OFString*)namespace_ + element: (OFXMLElement*)element; /*! * @brief Returns the unbound namespace. * * @return The unbound namespace */ - (OFString*)namespace; /*! - * @brief Returns the unbound prefix. + * @brief Returns the element in which the namespace was not bound. * - * @return The unbound prefix + * @return The element in which the namespace was not bound */ -- (OFString*)prefix; +- (OFXMLElement*)element; @end Index: src/exceptions/OFUnboundNamespaceException.m ================================================================== --- src/exceptions/OFUnboundNamespaceException.m +++ src/exceptions/OFUnboundNamespaceException.m @@ -18,26 +18,22 @@ #include #import "OFUnboundNamespaceException.h" #import "OFString.h" +#import "OFXMLElement.h" #import "common.h" @implementation OFUnboundNamespaceException + (instancetype)exceptionWithClass: (Class)class namespace: (OFString*)namespace + element: (OFXMLElement*)element { return [[[self alloc] initWithClass: class - namespace: namespace] autorelease]; -} - -+ (instancetype)exceptionWithClass: (Class)class - prefix: (OFString*)prefix -{ - return [[[self alloc] initWithClass: class - prefix: prefix] autorelease]; + namespace: namespace + element: element] autorelease]; } - initWithClass: (Class)class { @try { @@ -50,30 +46,17 @@ abort(); } - initWithClass: (Class)class namespace: (OFString*)namespace + element: (OFXMLElement*)element { self = [super initWithClass: class]; @try { _namespace = [namespace copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- initWithClass: (Class)class - prefix: (OFString*)prefix -{ - self = [super initWithClass: class]; - - @try { - _prefix = [prefix copy]; + _element = [element retain]; } @catch (id e) { [self release]; @throw e; } @@ -81,36 +64,26 @@ } - (void)dealloc { [_namespace release]; - [_prefix release]; + [_element release]; [super dealloc]; } - (OFString*)description { - if (_namespace != nil) - return [OFString stringWithFormat: - @"The namespace %@ is not bound in class %@", _namespace, - _inClass]; - else if (_prefix != nil) - return [OFString stringWithFormat: - @"The prefix %@ is not bound to any namespace in class %@", - _prefix, _inClass]; - else - return [OFString stringWithFormat: - @"A namespace or prefix is not bound in class %@", - _inClass]; + return [OFString stringWithFormat: + @"The namespace %@ is not bound in class %@", _namespace, _inClass]; } - (OFString*)namespace { OF_GETTER(_namespace, false) } -- (OFString*)prefix +- (OFXMLElement*)element { - OF_GETTER(_prefix, false) + OF_GETTER(_element, false) } @end ADDED src/exceptions/OFUnboundPrefixException.h Index: src/exceptions/OFUnboundPrefixException.h ================================================================== --- src/exceptions/OFUnboundPrefixException.h +++ src/exceptions/OFUnboundPrefixException.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 + * 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 "OFException.h" + +@class OFXMLParser; + +/*! + * @brief An exception indicating an attempt to use an unbound prefix. + */ +@interface OFUnboundPrefixException: OFException +{ + OFString *_prefix; + OFXMLParser *_parser; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, copy, nonatomic) OFString *prefix; +@property (readonly, retain, nonatomic) OFXMLParser *parser; +#endif + +/*! + * @brief Creates a new, autoreleased unbound prefix exception. + * + * @param class_ The class of the object which caused the exception + * @param prefix The prefix which is unbound + * @param parser The parser which encountered the unbound prefix + * @return A new, autoreleased unbound prefix exception + */ ++ (instancetype)exceptionWithClass: (Class)class_ + prefix: (OFString*)prefix + parser: (OFXMLParser*)parser; + +/*! + * @brief Initializes an already allocated unbound prefix exception. + * + * @param class_ The class of the object which caused the exception + * @param prefix The prefix which is unbound + * @param parser The parser which encountered the unbound prefix + * @return An initialized unbound prefix exception + */ +- initWithClass: (Class)class_ + prefix: (OFString*)prefix + parser: (OFXMLParser*)parser; + +/*! + * @brief Returns the unbound prefix. + * + * @return The unbound prefix + */ +- (OFString*)prefix; + +/*! + * @brief Returns the parser which encountered the unbound prefix. + * + * @return The parser which encountered the unbound prefix + */ +- (OFXMLParser*)parser; +@end ADDED src/exceptions/OFUnboundPrefixException.m Index: src/exceptions/OFUnboundPrefixException.m ================================================================== --- src/exceptions/OFUnboundPrefixException.m +++ src/exceptions/OFUnboundPrefixException.m @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 + * 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 "OFUnboundPrefixException.h" +#import "OFString.h" +#import "OFXMLParser.h" + +#import "common.h" + +@implementation OFUnboundPrefixException ++ (instancetype)exceptionWithClass: (Class)class + prefix: (OFString*)prefix + parser: (OFXMLParser*)parser +{ + return [[[self alloc] initWithClass: class + prefix: prefix + parser: parser] autorelease]; +} + +- initWithClass: (Class)class +{ + @try { + [self doesNotRecognizeSelector: _cmd]; + } @catch (id e) { + [self release]; + @throw e; + } + + abort(); +} + +- initWithClass: (Class)class + prefix: (OFString*)prefix + parser: (OFXMLParser*)parser +{ + self = [super initWithClass: class]; + + @try { + _prefix = [prefix copy]; + _parser = [parser retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_prefix release]; + [_parser release]; + + [super dealloc]; +} + +- (OFString*)description +{ + return [OFString stringWithFormat: + @"The XML parser in class %@ encountered the unbound prefix %@ in " + @"line %zd!", _inClass, _prefix, [_parser lineNumber]]; +} + +- (OFString*)prefix +{ + OF_GETTER(_prefix, false) +} + +- (OFXMLParser*)parser +{ + OF_GETTER(_parser, false) +} +@end