Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
Storage Class Reference

#include </tmp/quassel/src/core/storage.h>

Inheritance diagram for Storage:

Public Types

enum  State { IsReady, NeedsSetup, NotAvailable }
enum  HashVersion { Sha1, Sha2_512, Latest = Sha2_512 }

Public Slots

virtual bool isAvailable () const =0
 Check if the storage type is available.
virtual QString displayName () const =0
 Returns the display name of the storage backend.
virtual QString description () const =0
 Returns a description of this storage backend.
virtual QStringList setupKeys () const =0
 Returns a list of properties required to use the storage backend.
virtual QVariantMap setupDefaults () const =0
 Returns a map where the keys are are properties to use the storage backend.
virtual bool setup (const QVariantMap &settings=QVariantMap())=0
 Setup the storage provider.
virtual State init (const QVariantMap &settings=QVariantMap())=0
 Initialize the storage provider.
virtual void sync ()=0
 Makes temp data persistent.
virtual UserId addUser (const QString &user, const QString &password)=0
 Add a new core user to the storage.
virtual bool updateUser (UserId user, const QString &password)=0
 Update a core user's password.
virtual void renameUser (UserId user, const QString &newName)=0
 Rename a user.
virtual UserId validateUser (const QString &user, const QString &password)=0
 Validate a username with a given password.
virtual UserId getUserId (const QString &username)=0
 Check if a user with given username exists. Do not use for login purposes!
virtual UserId internalUser ()=0
 Determine the UserId of the internal user.
virtual void delUser (UserId user)=0
 Remove a core user from storage.
virtual void setUserSetting (UserId userId, const QString &settingName, const QVariant &data)=0
 Store a user setting persistently.
virtual QVariant getUserSetting (UserId userId, const QString &settingName, const QVariant &data=QVariant())=0
 Retrieve a persistent user setting.
virtual IdentityId createIdentity (UserId user, CoreIdentity &identity)=0
virtual bool updateIdentity (UserId user, const CoreIdentity &identity)=0
virtual void removeIdentity (UserId user, IdentityId identityId)=0
virtual QList< CoreIdentityidentities (UserId user)=0
virtual NetworkId createNetwork (UserId user, const NetworkInfo &info)=0
 Create a new Network in the storage backend and return it unique Id.
virtual bool updateNetwork (UserId user, const NetworkInfo &info)=0
 Apply the changes to NetworkInfo info to the storage engine.
virtual bool removeNetwork (UserId user, const NetworkId &networkId)=0
 Permanently remove a Network and all the data associated with it.
virtual QList< NetworkInfonetworks (UserId user)=0
 Returns a list of all NetworkInfos for the given UserId user.
virtual QList< NetworkIdconnectedNetworks (UserId user)=0
 Get a list of Networks to restore.
virtual void setNetworkConnected (UserId user, const NetworkId &networkId, bool isConnected)=0
 Update the connected state of a network.
virtual QHash< QString, QString > persistentChannels (UserId user, const NetworkId &networkId)=0
 Get a hash of channels with their channel keys for a given network.
virtual void setChannelPersistent (UserId user, const NetworkId &networkId, const QString &channel, bool isJoined)=0
 Update the connected state of a channel.
virtual void setPersistentChannelKey (UserId user, const NetworkId &networkId, const QString &channel, const QString &key)=0
 Update the key of a channel.
virtual QString awayMessage (UserId user, NetworkId networkId)=0
 retrieve last known away message for session restore
virtual void setAwayMessage (UserId user, NetworkId networkId, const QString &awayMsg)=0
 Make away message persistent for session restore.
virtual QString userModes (UserId user, NetworkId networkId)=0
 retrieve last known user mode for session restore
virtual void setUserModes (UserId user, NetworkId networkId, const QString &userModes)=0
 Make our user modes persistent for session restore.
virtual BufferInfo bufferInfo (UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer="", bool create=true)=0
 Get the unique BufferInfo for the given combination of network and buffername for a user.
virtual BufferInfo getBufferInfo (UserId user, const BufferId &bufferId)=0
 Get the unique BufferInfo for a bufferId.
virtual QList< BufferInforequestBuffers (UserId user)=0
 Request a list of all buffers known to a user.
virtual QList< BufferIdrequestBufferIdsForNetwork (UserId user, NetworkId networkId)=0
 Request a list of BufferIds for a given NetworkId.
virtual bool removeBuffer (const UserId &user, const BufferId &bufferId)=0
 Remove permanently a buffer and it's content from the storage backend.
virtual bool renameBuffer (const UserId &user, const BufferId &bufferId, const QString &newName)=0
 Rename a Buffer.
virtual bool mergeBuffersPermanently (const UserId &user, const BufferId &bufferId1, const BufferId &bufferId2)=0
 Merge the content of two Buffers permanently. This cannot be reversed!
virtual void setBufferLastSeenMsg (UserId user, const BufferId &bufferId, const MsgId &msgId)=0
 Update the LastSeenDate for a Buffer.
virtual QHash< BufferId, MsgIdbufferLastSeenMsgIds (UserId user)=0
 Get a Hash of all last seen message ids.
virtual void setBufferMarkerLineMsg (UserId user, const BufferId &bufferId, const MsgId &msgId)=0
 Update the MarkerLineMsgId for a Buffer.
virtual QHash< BufferId, MsgIdbufferMarkerLineMsgIds (UserId user)=0
 Get a Hash of all marker line message ids.
virtual bool logMessage (Message &msg)=0
 Store a Message in the storage backend and set its unique Id.
virtual bool logMessages (MessageList &msgs)=0
 Store a list of Messages in the storage backend and set their unique Id.
virtual QList< MessagerequestMsgs (UserId user, BufferId bufferId, MsgId first=-1, MsgId last=-1, int limit=-1)=0
 Request a certain number messages stored in a given buffer.
virtual QList< MessagerequestAllMsgs (UserId user, MsgId first=-1, MsgId last=-1, int limit=-1)=0
 Request a certain number of messages across all buffers.

Signals

void bufferInfoUpdated (UserId user, const BufferInfo &)
 Sent when a new BufferInfo is created, or an existing one changed somehow.
void bufferRenamed (const QString &newName, const QString &oldName)
 Sent when a Buffer was renamed.
void userAdded (UserId, const QString &username)
 Sent when a new user has been added.
void userRenamed (UserId, const QString &newname)
 Sent when a user has been renamed.
void userRemoved (UserId)
 Sent when a user has been removed.

Public Member Functions

 Storage (QObject *parent=0)
virtual ~Storage ()

Protected Member Functions

QString hashPassword (const QString &password)
bool checkHashedPassword (const UserId user, const QString &password, const QString &hashedPassword, const Storage::HashVersion version)

Private Member Functions

QString hashPasswordSha1 (const QString &password)
bool checkHashedPasswordSha1 (const QString &password, const QString &hashedPassword)
QString hashPasswordSha2_512 (const QString &password)
bool checkHashedPasswordSha2_512 (const QString &password, const QString &hashedPassword)
QString sha2_512 (const QString &input)

Detailed Description

Definition at line 31 of file storage.h.

Member Enumeration Documentation

enum State
Enumerator:
IsReady 
NeedsSetup 
NotAvailable 

Definition at line 39 of file storage.h.

Enumerator:
Sha1 
Sha2_512 
Latest 

Definition at line 45 of file storage.h.

Constructor & Destructor Documentation

Storage ( QObject *  parent = 0)

Definition at line 30 of file storage.cpp.

virtual ~Storage ( )
inlinevirtual

Definition at line 37 of file storage.h.

Member Function Documentation

virtual bool isAvailable ( ) const
pure virtualslot

Check if the storage type is available.

A storage subclass should return true if it can be successfully used, i.e. if all prerequisites are in place (e.g. we have an appropriate DB driver etc.).

Returns
True if and only if the storage class can be successfully used.

Referenced by Core::registerStorageBackend().

virtual QString displayName ( ) const
pure virtualslot
virtual QString description ( ) const
pure virtualslot

Returns a description of this storage backend.

Returns
A string that can be displayed by the client to describe the storage backend

Referenced by Core::backendInfo().

virtual QStringList setupKeys ( ) const
pure virtualslot

Returns a list of properties required to use the storage backend.

Referenced by Core::backendInfo(), and Core::promptForSettings().

virtual QVariantMap setupDefaults ( ) const
pure virtualslot

Returns a map where the keys are are properties to use the storage backend.

Referenced by Core::backendInfo(), and Core::promptForSettings().

virtual bool setup ( const QVariantMap &  settings = QVariantMap())
pure virtualslot

Setup the storage provider.

This prepares the storage provider (e.g. create tables, etc.) for use within Quassel.

Parameters
settingsHostname, port, username, password, ...
Returns
True if and only if the storage provider was initialized successfully.

Referenced by Core::initStorage(), and Core::selectBackend().

virtual State init ( const QVariantMap &  settings = QVariantMap())
pure virtualslot

Initialize the storage provider.

Parameters
settingsHostname, port, username, password, ...
Returns
the State the storage backend is now in (see Storage::State)

Referenced by Core::initStorage(), and Core::selectBackend().

virtual void sync ( )
pure virtualslot

Makes temp data persistent.

This Method is periodically called by the Quassel Core to make temporary data persistant. This reduces the data loss drastically in the unlikely case of a Core crash.

Implemented in AbstractSqlStorage.

Referenced by Core::syncStorage().

virtual UserId addUser ( const QString &  user,
const QString &  password 
)
pure virtualslot

Add a new core user to the storage.

Parameters
userThe username of the new user
passwordThe cleartext password for the new user
Returns
The new user's UserId

Referenced by Core::createUser(), and Core::setupCore().

virtual bool updateUser ( UserId  user,
const QString &  password 
)
pure virtualslot

Update a core user's password.

Parameters
userThe user's id
passwordThe user's new password
Returns
true on success.

Referenced by Core::changeUserPass(), Core::changeUserPassword(), and checkHashedPassword().

virtual void renameUser ( UserId  user,
const QString &  newName 
)
pure virtualslot

Rename a user.

Parameters
userThe user's id
newNameThe user's new name
virtual UserId validateUser ( const QString &  user,
const QString &  password 
)
pure virtualslot

Validate a username with a given password.

Parameters
userThe username to validate
passwordThe user's alleged password
Returns
A valid UserId if the password matches the username; 0 else

Referenced by Core::validateUser().

virtual UserId getUserId ( const QString &  username)
pure virtualslot

Check if a user with given username exists. Do not use for login purposes!

Parameters
usernameThe username to validate
Returns
A valid UserId if the user exists; 0 else

Referenced by Core::changeUserPass().

virtual UserId internalUser ( )
pure virtualslot

Determine the UserId of the internal user.

Returns
A valid UserId if the password matches the username; 0 else

Referenced by Core::setupInternalClientSession().

virtual void delUser ( UserId  user)
pure virtualslot

Remove a core user from storage.

Parameters
userThe userid to delete
virtual void setUserSetting ( UserId  userId,
const QString &  settingName,
const QVariant &  data 
)
pure virtualslot

Store a user setting persistently.

Parameters
userIdThe users Id
settingNameThe Name of the Setting
dataThe Value

Referenced by Core::setUserSetting().

virtual QVariant getUserSetting ( UserId  userId,
const QString &  settingName,
const QVariant &  data = QVariant() 
)
pure virtualslot

Retrieve a persistent user setting.

Parameters
userIdThe users Id
settingNameThe Name of the Setting
defaultValue to return in case it's unset.
Returns
the Value of the Setting or the default value if it is unset.

Referenced by Core::getUserSetting().

virtual IdentityId createIdentity ( UserId  user,
CoreIdentity identity 
)
pure virtualslot

Referenced by Core::createIdentity().

virtual bool updateIdentity ( UserId  user,
const CoreIdentity identity 
)
pure virtualslot

Referenced by Core::updateIdentity().

virtual void removeIdentity ( UserId  user,
IdentityId  identityId 
)
pure virtualslot

Referenced by Core::removeIdentity().

virtual QList<CoreIdentity> identities ( UserId  user)
pure virtualslot

Referenced by Core::identities().

virtual NetworkId createNetwork ( UserId  user,
const NetworkInfo info 
)
pure virtualslot

Create a new Network in the storage backend and return it unique Id.

Parameters
userThe core user who owns this network
networkInfoThe networkInfo holding the network definition
Returns
the NetworkId of the newly created Network. Possibly invalid.

Referenced by Core::createNetwork().

virtual bool updateNetwork ( UserId  user,
const NetworkInfo info 
)
pure virtualslot

Apply the changes to NetworkInfo info to the storage engine.

Parameters
userThe core user
networkInfoThe Updated NetworkInfo
Returns
true if successfull.

Referenced by Core::updateNetwork().

virtual bool removeNetwork ( UserId  user,
const NetworkId networkId 
)
pure virtualslot

Permanently remove a Network and all the data associated with it.

Note
This method is thredsafe.
Parameters
userThe core user
networkIdThe network to delete
Returns
true if successfull.

Referenced by Core::removeNetwork().

virtual QList<NetworkInfo> networks ( UserId  user)
pure virtualslot

Returns a list of all NetworkInfos for the given UserId user.

Note
This method is thredsafe.
Parameters
userThe core user
Returns
QList<NetworkInfo>.

Referenced by Core::networks().

virtual QList<NetworkId> connectedNetworks ( UserId  user)
pure virtualslot

Get a list of Networks to restore.

Return a list of networks the user was connected at the time of core shutdown

Note
This method is threadsafe.
Parameters
userThe User Id in question

Referenced by Core::connectedNetworks().

virtual void setNetworkConnected ( UserId  user,
const NetworkId networkId,
bool  isConnected 
)
pure virtualslot

Update the connected state of a network.

Note
This method is threadsafe
Parameters
userThe Id of the networks owner
networkIdThe Id of the network
isConnectedwhether the network is connected or not

Referenced by Core::setNetworkConnected().

virtual QHash<QString, QString> persistentChannels ( UserId  user,
const NetworkId networkId 
)
pure virtualslot

Get a hash of channels with their channel keys for a given network.

The keys are channel names and values are passwords (possibly empty)

Note
This method is threadsafe
Parameters
userThe id of the networks owner
networkIdThe Id of the network

Referenced by Core::persistentChannels().

virtual void setChannelPersistent ( UserId  user,
const NetworkId networkId,
const QString &  channel,
bool  isJoined 
)
pure virtualslot

Update the connected state of a channel.

Note
This method is threadsafe
Parameters
userThe Id of the networks owner
networkIdThe Id of the network
channelThe name of the channel
isJoinedwhether the channel is connected or not

Referenced by Core::setChannelPersistent().

virtual void setPersistentChannelKey ( UserId  user,
const NetworkId networkId,
const QString &  channel,
const QString &  key 
)
pure virtualslot

Update the key of a channel.

Note
This method is threadsafe
Parameters
userThe Id of the networks owner
networkIdThe Id of the network
channelThe name of the channel
keyThe key of the channel (possibly empty)

Referenced by Core::setPersistentChannelKey().

virtual QString awayMessage ( UserId  user,
NetworkId  networkId 
)
pure virtualslot

retrieve last known away message for session restore

Note
This method is threadsafe
Parameters
userThe Id of the networks owner
networkIdThe Id of the network

Referenced by Core::awayMessage().

virtual void setAwayMessage ( UserId  user,
NetworkId  networkId,
const QString &  awayMsg 
)
pure virtualslot

Make away message persistent for session restore.

Note
This method is threadsafe
Parameters
userThe Id of the networks owner
networkIdThe Id of the network
awayMsgThe current away message of own user

Referenced by Core::setAwayMessage().

virtual QString userModes ( UserId  user,
NetworkId  networkId 
)
pure virtualslot

retrieve last known user mode for session restore

Note
This method is threadsafe
Parameters
userThe Id of the networks owner
networkIdThe Id of the network

Referenced by Core::userModes().

virtual void setUserModes ( UserId  user,
NetworkId  networkId,
const QString &  userModes 
)
pure virtualslot

Make our user modes persistent for session restore.

Note
This method is threadsafe
Parameters
userThe Id of the networks owner
networkIdThe Id of the network
userModesThe current user modes of own user

Referenced by Core::setUserModes().

virtual BufferInfo bufferInfo ( UserId  user,
const NetworkId networkId,
BufferInfo::Type  type,
const QString &  buffer = "",
bool  create = true 
)
pure virtualslot

Get the unique BufferInfo for the given combination of network and buffername for a user.

Parameters
userThe core user who owns this buffername
networkIdThe network id
typeThe type of the buffer (StatusBuffer, Channel, etc.)
bufferThe buffer name (if empty, the net's status buffer is returned)
createWhether or not the buffer should be created if it doesnt exist
Returns
The BufferInfo corresponding to the given network and buffer name, or an invalid BufferInfo if not found

Referenced by Core::bufferInfo().

virtual BufferInfo getBufferInfo ( UserId  user,
const BufferId bufferId 
)
pure virtualslot

Get the unique BufferInfo for a bufferId.

Parameters
userThe core user who owns this buffername
bufferIdThe id of the buffer
Returns
The BufferInfo corresponding to the given buffer id, or an invalid BufferInfo if not found.

Referenced by Core::getBufferInfo().

virtual QList<BufferInfo> requestBuffers ( UserId  user)
pure virtualslot

Request a list of all buffers known to a user.

This method is used to get a list of all buffers we have stored a backlog from.

Parameters
userThe user whose buffers we request
Returns
A list of the BufferInfos for all buffers as requested

Referenced by Core::requestBuffers().

virtual QList<BufferId> requestBufferIdsForNetwork ( UserId  user,
NetworkId  networkId 
)
pure virtualslot

Request a list of BufferIds for a given NetworkId.

Note
This method is threadsafe.
Parameters
userThe user whose buffers we request
networkIdThe NetworkId of the network in question
Returns
List of BufferIds belonging to the Network

Referenced by Core::requestBufferIdsForNetwork().

virtual bool removeBuffer ( const UserId user,
const BufferId bufferId 
)
pure virtualslot

Remove permanently a buffer and it's content from the storage backend.

This call cannot be reverted!

Parameters
userThe user who is the owner of the buffer
bufferIdThe bufferId
Returns
true if successfull

Referenced by Core::removeBuffer().

virtual bool renameBuffer ( const UserId user,
const BufferId bufferId,
const QString &  newName 
)
pure virtualslot

Rename a Buffer.

Note
This method is threadsafe.
Parameters
userThe id of the buffer owner
bufferIdThe bufferId
newNameThe new name of the buffer
Returns
true if successfull

Referenced by Core::renameBuffer().

virtual bool mergeBuffersPermanently ( const UserId user,
const BufferId bufferId1,
const BufferId bufferId2 
)
pure virtualslot

Merge the content of two Buffers permanently. This cannot be reversed!

Note
This method is threadsafe.
Parameters
userThe id of the buffer owner
bufferId1The bufferId of the remaining buffer
bufferId2The buffer that is about to be removed
Returns
true if successfull

Referenced by Core::mergeBuffersPermanently().

virtual void setBufferLastSeenMsg ( UserId  user,
const BufferId bufferId,
const MsgId msgId 
)
pure virtualslot

Update the LastSeenDate for a Buffer.

This Method is used to make the LastSeenDate of a Buffer persistent

Parameters
userThe Owner of that Buffer
bufferIdThe buffer id
MsgIdThe Message id of the message that has been just seen

Referenced by Core::setBufferLastSeenMsg().

virtual QHash<BufferId, MsgId> bufferLastSeenMsgIds ( UserId  user)
pure virtualslot

Get a Hash of all last seen message ids.

This Method is called when the Quassel Core is started to restore the lastSeenMsgIds

Parameters
userThe Owner of the buffers

Referenced by Core::bufferLastSeenMsgIds().

virtual void setBufferMarkerLineMsg ( UserId  user,
const BufferId bufferId,
const MsgId msgId 
)
pure virtualslot

Update the MarkerLineMsgId for a Buffer.

This Method is used to make the marker line position of a Buffer persistent

Note
This method is threadsafe.
Parameters
userThe Owner of that Buffer
bufferIdThe buffer id
MsgIdThe Message id where the marker line should be placed

Referenced by Core::setBufferMarkerLineMsg().

virtual QHash<BufferId, MsgId> bufferMarkerLineMsgIds ( UserId  user)
pure virtualslot

Get a Hash of all marker line message ids.

This Method is called when the Quassel Core is started to restore the MarkerLineMsgIds

Note
This method is threadsafe.
Parameters
userThe Owner of the buffers

Referenced by Core::bufferMarkerLineMsgIds().

virtual bool logMessage ( Message msg)
pure virtualslot

Store a Message in the storage backend and set its unique Id.

Parameters
msgThe message object to be stored
Returns
true on success

Referenced by Core::storeMessage().

virtual bool logMessages ( MessageList msgs)
pure virtualslot

Store a list of Messages in the storage backend and set their unique Id.

Parameters
msgsThe list message objects to be stored
Returns
true on success

Referenced by Core::storeMessages().

virtual QList<Message> requestMsgs ( UserId  user,
BufferId  bufferId,
MsgId  first = -1,
MsgId  last = -1,
int  limit = -1 
)
pure virtualslot

Request a certain number messages stored in a given buffer.

Parameters
bufferThe buffer we request messages from
firstif != -1 return only messages with a MsgId >= first
lastif != -1 return only messages with a MsgId < last
limitif != -1 limit the returned list to a max of entries
Returns
The requested list of messages

Referenced by Core::requestMsgs().

virtual QList<Message> requestAllMsgs ( UserId  user,
MsgId  first = -1,
MsgId  last = -1,
int  limit = -1 
)
pure virtualslot

Request a certain number of messages across all buffers.

Parameters
firstif != -1 return only messages with a MsgId >= first
lastif != -1 return only messages with a MsgId < last
limitMax amount of messages
Returns
The requested list of messages

Referenced by Core::requestAllMsgs().

void bufferInfoUpdated ( UserId  user,
const BufferInfo  
)
signal

Sent when a new BufferInfo is created, or an existing one changed somehow.

void bufferRenamed ( const QString &  newName,
const QString &  oldName 
)
signal

Sent when a Buffer was renamed.

void userAdded ( UserId  ,
const QString &  username 
)
signal

Sent when a new user has been added.

Referenced by PostgreSqlStorage::addUser(), and SqliteStorage::addUser().

void userRenamed ( UserId  ,
const QString &  newname 
)
signal

Sent when a user has been renamed.

Referenced by PostgreSqlStorage::renameUser(), and SqliteStorage::renameUser().

void userRemoved ( UserId  )
signal

Sent when a user has been removed.

Referenced by PostgreSqlStorage::delUser(), and SqliteStorage::delUser().

QString hashPassword ( const QString &  password)
protected
bool checkHashedPassword ( const UserId  user,
const QString &  password,
const QString &  hashedPassword,
const Storage::HashVersion  version 
)
protected
QString hashPasswordSha1 ( const QString &  password)
private

Definition at line 64 of file storage.cpp.

References Sha1.

Referenced by checkHashedPasswordSha1().

bool checkHashedPasswordSha1 ( const QString &  password,
const QString &  hashedPassword 
)
private

Definition at line 69 of file storage.cpp.

References hashPasswordSha1().

Referenced by checkHashedPassword().

QString hashPasswordSha2_512 ( const QString &  password)
private

Definition at line 74 of file storage.cpp.

References sha2_512().

Referenced by hashPassword().

bool checkHashedPasswordSha2_512 ( const QString &  password,
const QString &  hashedPassword 
)
private

Definition at line 91 of file storage.cpp.

References sha2_512().

Referenced by checkHashedPassword().

QString sha2_512 ( const QString &  input)
private

Definition at line 105 of file storage.cpp.

Referenced by checkHashedPasswordSha2_512(), and hashPasswordSha2_512().


The documentation for this class was generated from the following files: