From af04bf708891fc77ac55c3e193bf52575a0214ed Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Mon, 6 Feb 2012 14:32:20 +0100 Subject: [PATCH] Add storage to the connection and roster. --- src/XMPPConnection.h | 9 ++++++++- src/XMPPConnection.m | 15 +++++++++++++++ src/XMPPRoster.h | 14 ++++++++++++++ src/XMPPRoster.m | 12 ++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/XMPPConnection.h b/src/XMPPConnection.h index a75a1a5..eca20c7 100644 --- a/src/XMPPConnection.h +++ b/src/XMPPConnection.h @@ -24,6 +24,7 @@ #import #import "XMPPCallback.h" +#import "XMPPStorage.h" @class XMPPConnection; @class XMPPJID; @@ -156,6 +157,7 @@ BOOL needsSession; BOOL encryptionRequired, encrypted; unsigned int lastID; + id dataStorage; /// \endcond } @@ -164,7 +166,8 @@ @property (copy) OFString *username; /// \brief The password to use for authentication @property (copy) OFString *password; -/** \brief The server to use for the connection +/** + * \brief The server to use for the connection * * This is useful if the address of the server is different from the domain. */ @@ -189,6 +192,8 @@ @property BOOL encryptionRequired; /// \brief Whether the connection is encrypted @property (readonly) BOOL encrypted; +/// \brief An object for data storage, conforming to the XMPPStorage protocol +@property (assign) id dataStorage; #endif /** @@ -326,6 +331,8 @@ - (XMPPJID*)JID; - (void)setPort: (uint16_t)port; - (uint16_t)port; +- (void)setDataStorage: (id )dataStorage; +- (id )dataStorage; - (void)setLanguage: (OFString*)language; - (OFString*)language; diff --git a/src/XMPPConnection.m b/src/XMPPConnection.m index 901d846..cc97013 100644 --- a/src/XMPPConnection.m +++ b/src/XMPPConnection.m @@ -36,6 +36,8 @@ #import #import +#import + #import "XMPPConnection.h" #import "XMPPCallback.h" #import "XMPPSRVLookup.h" @@ -1056,6 +1058,19 @@ return port; } +- (void)setDataStorage: (id )dataStorage_ +{ + if (streamOpen) + @throw [OFInvalidArgumentException exceptionWithClass: isa]; + + dataStorage = dataStorage_; +} + +- (id )dataStorage +{ + return dataStorage; +} + - (void)setLanguage: (OFString*)language_ { OF_SETTER(language, language_, YES, YES) diff --git a/src/XMPPRoster.h b/src/XMPPRoster.h index 29d3a8c..c05e52f 100644 --- a/src/XMPPRoster.h +++ b/src/XMPPRoster.h @@ -24,6 +24,7 @@ #import #import "XMPPConnection.h" +#import "XMPPStorage.h" @class XMPPRosterItem; @class XMPPIQ; @@ -71,9 +72,19 @@ XMPPConnection *connection; OFMutableDictionary *rosterItems; XMPPMulticastDelegate *delegates; + id dataStorage; /// \endcond } +#ifdef OF_HAVE_PROPERTIES +/** + * \brief An object for data storage, conforming to the XMPPStorage protocol. + * + * Inherited from the connection if not overridden. + */ +@property (assign) id dataStorage; +#endif + /** * \brief Initializes an already allocated XMPPRoster. * @@ -131,6 +142,9 @@ */ - (void)removeDelegate: (id )delegate; +- (void)setDataStorage: (id )dataStorage; +- (id )dataStorage; + /// \cond internal - (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem; - (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem; diff --git a/src/XMPPRoster.m b/src/XMPPRoster.m index 54a01ce..5b52719 100644 --- a/src/XMPPRoster.m +++ b/src/XMPPRoster.m @@ -47,6 +47,7 @@ connection = connection_; [connection addDelegate: self]; delegates = [[XMPPMulticastDelegate alloc] init]; + dataStorage = [connection dataStorage]; } @catch (id e) { [self release]; @throw e; @@ -185,6 +186,17 @@ [delegates removeDelegate: delegate]; } +- (void)setDataStorage: (id )dataStorage_ +{ + /* TODO: Prevent changing it after it has been used */ + dataStorage = dataStorage_; +} + +- (id )dataStorage +{ + return dataStorage; +} + - (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem { return [self XMPP_updateRosterItem: rosterItem];