Overview
Comment: | Use exceptions. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
7b3354d7e043a8ee46103202e336260c |
User & Date: | js on 2011-02-16 22:36:50 |
Other Links: | manifest | tags |
Context
2011-02-16
| ||
22:37 | Add .hgignore. check-in: 176cd44f7d user: js tags: trunk | |
22:36 | Use exceptions. check-in: 7b3354d7e0 user: js tags: trunk | |
20:12 | Add license. check-in: 472d585c4a user: js tags: trunk | |
Changes
Modified src/XMPPConnection.m from [f439b7a834] to [e746d2539e].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <stringprep.h> #import "XMPPConnection.h" #import "XMPPStanza.h" #import "XMPPJID.h" #import "XMPPIQ.h" #define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind" #define NS_CLIENT @"jabber:client" #define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl" #define NS_STREAM @"http://etherx.jabber.org/streams" @implementation XMPPConnection | > | < < < < < < < | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <stringprep.h> #import "XMPPConnection.h" #import "XMPPStanza.h" #import "XMPPJID.h" #import "XMPPIQ.h" #import "XMPPExceptions.h" #define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind" #define NS_CLIENT @"jabber:client" #define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl" #define NS_STREAM @"http://etherx.jabber.org/streams" @implementation XMPPConnection @synthesize username, password, server, resource, JID, port, useTLS, delegate; - init { self = [super init]; sock = [[OFTCPSocket alloc] init]; parser = [[OFXMLParser alloc] init]; |
︙ | ︙ | |||
73 74 75 76 77 78 79 | [super dealloc]; } - (void)setUsername: (OFString*)username_ { OFString *old = username; char *node; | < > | > > | | < < > | | | < > > > < > | > > | | < < > | > > | | < | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | [super dealloc]; } - (void)setUsername: (OFString*)username_ { OFString *old = username; char *node; Stringprep_rc rc; if ((rc = stringprep_profile([username_ cString], &node, "SASLprep", 0)) != STRINGPREP_OK) @throw [XMPPStringPrepFailedException newWithClass: isa connection: self profile: @"SASLprep" string: username_]; @try { username = [[OFString alloc] initWithCString: node]; } @finally { free(node); } [old release]; } - (void)setResource: (OFString*)resource_ { OFString *old = resource; char *res; Stringprep_rc rc; if ((rc = stringprep_profile([resource_ cString], &res, "Resourceprep", 0)) != STRINGPREP_OK) @throw [XMPPStringPrepFailedException newWithClass: isa connection: self profile: @"Resourceprep" string: resource_]; @try { resource = [[OFString alloc] initWithCString: res]; } @finally { free(res); } [old release]; } - (void)setServer: (OFString*)server_ { OFString *old = server; char *srv; Stringprep_rc rc; if ((rc = stringprep_profile([server_ cString], &srv, "Nameprep", 0)) != STRINGPREP_OK) @throw [XMPPStringPrepFailedException newWithClass: isa connection: self profile: @"Nameprep" string: server_]; @try { server = [[OFString alloc] initWithCString: srv]; } @finally { free(srv); } [old release]; } - (void)setPassword: (OFString*)password_ { OFString *old = password; char *pass; Stringprep_rc rc; if ((rc = stringprep_profile([password_ cString], &pass, "SASLprep", 0)) != STRINGPREP_OK) @throw [XMPPStringPrepFailedException newWithClass: isa connection: self profile: @"SASLprep" string: password_]; @try { password = [[OFString alloc] initWithCString: pass]; } @finally { free(pass); } |
︙ | ︙ |
Added src/XMPPExceptions.h version [49bb8b74db].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | /* * Copyright (c) 2011, Jonathan Schleifer <js@webkeks.org> * * https://webkeks.org/hg/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice is present in all copies. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import <ObjFW/ObjFW.h> @class XMPPConnection; @interface XMPPException: OFException { XMPPConnection *connection; } @property (readonly, nonatomic) XMPPConnection *connection; + newWithClass: (Class)class_ connection: (XMPPConnection*)conn; - initWithClass: (Class)class_ connection: (XMPPConnection*)conn; @end @interface XMPPStringPrepFailedException: XMPPException { OFString *profile; OFString *string; } @property (readonly, nonatomic) OFString *profile, *string; + newWithClass: (Class)class_ connection: (XMPPConnection*)conn profile: (OFString*)profile string: (OFString*)string; - initWithClass: (Class)class_ connection: (XMPPConnection*)conn profile: (OFString*)profile string: (OFString*)string; @end |
Added src/XMPPExceptions.m version [e2e85372f3].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /* * Copyright (c) 2011, Jonathan Schleifer <js@webkeks.org> * * https://webkeks.org/hg/objxmpp/ * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice is present in all copies. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import "XMPPExceptions.h" @implementation XMPPException @synthesize connection; + newWithClass: (Class)class_ connection: (XMPPConnection*)conn { return [[self alloc] initWithClass: class_ connection: conn]; } - initWithClass: (Class)class_ { Class c = isa; [self release]; @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ connection: (XMPPConnection*)conn { self = [super initWithClass: class_]; @try { connection = [conn retain]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [connection release]; [super dealloc]; } - (OFString*)description { OFAutoreleasePool *pool; if (description != nil) return description; pool = [[OFAutoreleasePool alloc] init]; description = [[OFString alloc] initWithFormat: @"An exception occurred in class %@!", [self className]]; [pool release]; return description; } @end @implementation XMPPStringPrepFailedException @synthesize profile, string; + newWithClass: (Class)class_ connection: (XMPPConnection*)conn profile: (OFString*)profile string: (OFString*)string { return [[self alloc] initWithClass: class_ connection: conn profile: profile string: string]; } - initWithClass: (Class)class_ connection: (XMPPConnection*)conn { Class c = isa; [self release]; @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ connection: (XMPPConnection*)conn profile: (OFString*)profile_ string: (OFString*)string_ { self = [super initWithClass: class_ connection: conn]; @try { profile = [profile_ copy]; string = [string_ copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [profile release]; [string release]; [super dealloc]; } @end |
Modified src/XMPPIQ.m from [3d81ab950c] to [9adee8b6bc].
︙ | ︙ | |||
30 31 32 33 34 35 36 | return [[[self alloc] initWithType: type_ ID: ID_] autorelease]; } - initWithType: (OFString*)type_ ID: (OFString*)ID_ { | > > > | > | | > | | > > | > | < < | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | return [[[self alloc] initWithType: type_ ID: ID_] autorelease]; } - initWithType: (OFString*)type_ ID: (OFString*)ID_ { self = [super initWithName: @"iq" type: type_ ID: ID_]; @try { if (![type_ isEqual: @"get"] && ![type_ isEqual: @"set"] && ![type_ isEqual: @"result"] && ![type_ isEqual: @"error"]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; } @catch (id e) { [self release]; @throw e; } return self; } @end |
Modified src/XMPPStanza.m from [72643fc0a8] to [e0459a5b73].
︙ | ︙ | |||
53 54 55 56 57 58 59 | ID: (OFString*)ID_ { return [[[self alloc] initWithName: name type: type_ ID: ID_] autorelease]; } | | > | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | ID: (OFString*)ID_ { return [[[self alloc] initWithName: name type: type_ ID: ID_] autorelease]; } + stanzaWithElement: (OFXMLElement*)elem { return [[[self alloc] initWithElement: elem] autorelease]; } - initWithName: (OFString*)name_ { return [self initWithName: name_ type: nil |
︙ | ︙ | |||
84 85 86 87 88 89 90 | ID: ID_]; } - initWithName: (OFString*)name_ type: (OFString*)type_ ID: (OFString*)ID_ { | < < < < < > > > > > | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | ID: ID_]; } - initWithName: (OFString*)name_ type: (OFString*)type_ ID: (OFString*)ID_ { self = [super initWithName: name_]; @try { if (![name_ isEqual: @"iq"] && ![name_ isEqual: @"message"] && ![name_ isEqual: @"presence"]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; [self setDefaultNamespace: @"jabber:client"]; if (type_) [self setType: type_]; if (ID_) [self setID: ID_]; |
︙ | ︙ |