Add storage to the connection and roster.

This commit is contained in:
Jonathan Schleifer 2012-02-06 14:32:20 +01:00
parent f777a11d7f
commit af04bf7088
4 changed files with 49 additions and 1 deletions

View file

@ -24,6 +24,7 @@
#import <ObjFW/ObjFW.h> #import <ObjFW/ObjFW.h>
#import "XMPPCallback.h" #import "XMPPCallback.h"
#import "XMPPStorage.h"
@class XMPPConnection; @class XMPPConnection;
@class XMPPJID; @class XMPPJID;
@ -156,6 +157,7 @@
BOOL needsSession; BOOL needsSession;
BOOL encryptionRequired, encrypted; BOOL encryptionRequired, encrypted;
unsigned int lastID; unsigned int lastID;
id <XMPPStorage> dataStorage;
/// \endcond /// \endcond
} }
@ -164,7 +166,8 @@
@property (copy) OFString *username; @property (copy) OFString *username;
/// \brief The password to use for authentication /// \brief The password to use for authentication
@property (copy) OFString *password; @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. * This is useful if the address of the server is different from the domain.
*/ */
@ -189,6 +192,8 @@
@property BOOL encryptionRequired; @property BOOL encryptionRequired;
/// \brief Whether the connection is encrypted /// \brief Whether the connection is encrypted
@property (readonly) BOOL encrypted; @property (readonly) BOOL encrypted;
/// \brief An object for data storage, conforming to the XMPPStorage protocol
@property (assign) id <XMPPStorage> dataStorage;
#endif #endif
/** /**
@ -326,6 +331,8 @@
- (XMPPJID*)JID; - (XMPPJID*)JID;
- (void)setPort: (uint16_t)port; - (void)setPort: (uint16_t)port;
- (uint16_t)port; - (uint16_t)port;
- (void)setDataStorage: (id <XMPPStorage>)dataStorage;
- (id <XMPPStorage>)dataStorage;
- (void)setLanguage: (OFString*)language; - (void)setLanguage: (OFString*)language;
- (OFString*)language; - (OFString*)language;

View file

@ -36,6 +36,8 @@
#import <ObjOpenSSL/SSLInvalidCertificateException.h> #import <ObjOpenSSL/SSLInvalidCertificateException.h>
#import <ObjOpenSSL/X509Certificate.h> #import <ObjOpenSSL/X509Certificate.h>
#import <ObjFW/OFInvalidArgumentException.h>
#import "XMPPConnection.h" #import "XMPPConnection.h"
#import "XMPPCallback.h" #import "XMPPCallback.h"
#import "XMPPSRVLookup.h" #import "XMPPSRVLookup.h"
@ -1056,6 +1058,19 @@
return port; return port;
} }
- (void)setDataStorage: (id <XMPPStorage>)dataStorage_
{
if (streamOpen)
@throw [OFInvalidArgumentException exceptionWithClass: isa];
dataStorage = dataStorage_;
}
- (id <XMPPStorage>)dataStorage
{
return dataStorage;
}
- (void)setLanguage: (OFString*)language_ - (void)setLanguage: (OFString*)language_
{ {
OF_SETTER(language, language_, YES, YES) OF_SETTER(language, language_, YES, YES)

View file

@ -24,6 +24,7 @@
#import <ObjFW/ObjFW.h> #import <ObjFW/ObjFW.h>
#import "XMPPConnection.h" #import "XMPPConnection.h"
#import "XMPPStorage.h"
@class XMPPRosterItem; @class XMPPRosterItem;
@class XMPPIQ; @class XMPPIQ;
@ -71,9 +72,19 @@
XMPPConnection *connection; XMPPConnection *connection;
OFMutableDictionary *rosterItems; OFMutableDictionary *rosterItems;
XMPPMulticastDelegate *delegates; XMPPMulticastDelegate *delegates;
id <XMPPStorage> dataStorage;
/// \endcond /// \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 <XMPPStorage> dataStorage;
#endif
/** /**
* \brief Initializes an already allocated XMPPRoster. * \brief Initializes an already allocated XMPPRoster.
* *
@ -131,6 +142,9 @@
*/ */
- (void)removeDelegate: (id <XMPPRosterDelegate>)delegate; - (void)removeDelegate: (id <XMPPRosterDelegate>)delegate;
- (void)setDataStorage: (id <XMPPStorage>)dataStorage;
- (id <XMPPStorage>)dataStorage;
/// \cond internal /// \cond internal
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem; - (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem;
- (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem; - (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem;

View file

@ -47,6 +47,7 @@
connection = connection_; connection = connection_;
[connection addDelegate: self]; [connection addDelegate: self];
delegates = [[XMPPMulticastDelegate alloc] init]; delegates = [[XMPPMulticastDelegate alloc] init];
dataStorage = [connection dataStorage];
} @catch (id e) { } @catch (id e) {
[self release]; [self release];
@throw e; @throw e;
@ -185,6 +186,17 @@
[delegates removeDelegate: delegate]; [delegates removeDelegate: delegate];
} }
- (void)setDataStorage: (id <XMPPStorage>)dataStorage_
{
/* TODO: Prevent changing it after it has been used */
dataStorage = dataStorage_;
}
- (id <XMPPStorage>)dataStorage
{
return dataStorage;
}
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem - (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem
{ {
return [self XMPP_updateRosterItem: rosterItem]; return [self XMPP_updateRosterItem: rosterItem];