You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
4.0 KiB
162 lines
4.0 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
*
|
||
|
* Copyright (C) 2001-2004 George Staikos <staikos@kde.org>
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
|
||
|
#ifndef _KWALLETBACKEND_H
|
||
|
#define _KWALLETBACKEND_H
|
||
|
|
||
|
#include <kmdcodec.h>
|
||
|
|
||
14 years ago
|
#include <tqstring.h>
|
||
|
#include <tqstringlist.h>
|
||
|
#include <tqmap.h>
|
||
12 years ago
|
#include "tdewalletentry.h"
|
||
15 years ago
|
|
||
|
|
||
|
namespace KWallet {
|
||
|
|
||
|
class MD5Digest;
|
||
|
|
||
|
/* @internal
|
||
|
*/
|
||
|
class KDE_EXPORT Backend {
|
||
|
public:
|
||
14 years ago
|
Backend(const TQString& name = "kdewallet", bool isPath = false);
|
||
15 years ago
|
~Backend();
|
||
|
|
||
|
// Open and unlock the wallet.
|
||
14 years ago
|
int open(const TQByteArray& password);
|
||
15 years ago
|
|
||
|
// Close and lock the wallet (saving changes).
|
||
14 years ago
|
int close(const TQByteArray& password);
|
||
15 years ago
|
|
||
|
// Close the wallet, losing any changes.
|
||
|
int close();
|
||
|
|
||
|
// Write the wallet to disk
|
||
14 years ago
|
int sync(const TQByteArray& password);
|
||
15 years ago
|
|
||
|
// Returns true if the current wallet is open.
|
||
|
bool isOpen() const;
|
||
|
|
||
|
// Returns the current wallet name.
|
||
14 years ago
|
const TQString& walletName() const;
|
||
15 years ago
|
|
||
|
// The list of folders.
|
||
14 years ago
|
TQStringList folderList() const;
|
||
15 years ago
|
|
||
|
// Force creation of a folder.
|
||
14 years ago
|
bool createFolder(const TQString& f);
|
||
15 years ago
|
|
||
|
// Change the folder.
|
||
14 years ago
|
void setFolder(const TQString& f) { _folder = f; }
|
||
15 years ago
|
|
||
|
// Current folder. If empty, it's the global folder.
|
||
14 years ago
|
const TQString& folder() const { return _folder; }
|
||
15 years ago
|
|
||
|
// Does it have this folder?
|
||
13 years ago
|
bool hasFolder(const TQString& f) const { return _entries.contains(f); }
|
||
15 years ago
|
|
||
|
// Look up an entry. Returns null if it doesn't exist.
|
||
14 years ago
|
Entry *readEntry(const TQString& key);
|
||
15 years ago
|
|
||
|
// Look up a list of entries. Supports wildcards.
|
||
|
// You delete the list.
|
||
14 years ago
|
TQPtrList<Entry> readEntryList(const TQString& key);
|
||
15 years ago
|
|
||
|
// Store an entry.
|
||
|
void writeEntry(Entry *e);
|
||
|
|
||
|
// Does this folder contain this entry?
|
||
14 years ago
|
bool hasEntry(const TQString& key) const;
|
||
15 years ago
|
|
||
|
// Returns true if the entry was removed
|
||
14 years ago
|
bool removeEntry(const TQString& key);
|
||
15 years ago
|
|
||
|
// Returns true if the folder was removed
|
||
14 years ago
|
bool removeFolder(const TQString& f);
|
||
15 years ago
|
|
||
|
// The list of entries in this folder.
|
||
14 years ago
|
TQStringList entryList() const;
|
||
15 years ago
|
|
||
|
// Rename an entry in this folder.
|
||
14 years ago
|
int renameEntry(const TQString& oldName, const TQString& newName);
|
||
15 years ago
|
|
||
|
int ref() { return ++_ref; }
|
||
|
|
||
|
int deref() { return --_ref; }
|
||
|
|
||
|
int refCount() const { return _ref; }
|
||
|
|
||
14 years ago
|
static bool exists(const TQString& wallet);
|
||
15 years ago
|
|
||
14 years ago
|
bool folderDoesNotExist(const TQString& folder) const;
|
||
15 years ago
|
|
||
14 years ago
|
bool entryDoesNotExist(const TQString& folder, const TQString& entry) const;
|
||
15 years ago
|
|
||
14 years ago
|
static TQString openRCToString(int rc);
|
||
15 years ago
|
|
||
|
private:
|
||
|
class BackendPrivate;
|
||
|
BackendPrivate *d;
|
||
14 years ago
|
TQString _name;
|
||
|
TQString _path;
|
||
15 years ago
|
bool _open;
|
||
14 years ago
|
TQString _folder;
|
||
15 years ago
|
int _ref;
|
||
|
// Map Folder->Entries
|
||
14 years ago
|
typedef TQMap< TQString, Entry* > EntryMap;
|
||
|
typedef TQMap< TQString, EntryMap > FolderMap;
|
||
15 years ago
|
FolderMap _entries;
|
||
14 years ago
|
typedef TQMap<MD5Digest, TQValueList<MD5Digest> > HashMap;
|
||
15 years ago
|
HashMap _hashes;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* @internal
|
||
|
*/
|
||
14 years ago
|
class MD5Digest : public TQByteArray {
|
||
15 years ago
|
public:
|
||
14 years ago
|
MD5Digest() : TQByteArray(16) {}
|
||
|
MD5Digest(const KMD5::Digest d) : TQByteArray() { duplicate(reinterpret_cast<const char *>(d), 16); }
|
||
15 years ago
|
virtual ~MD5Digest() {}
|
||
|
|
||
|
int operator<(const MD5Digest& r) const {
|
||
|
int i = 0;
|
||
|
char x, y;
|
||
|
for (; i < 16; ++i) {
|
||
|
x = at(i);
|
||
13 years ago
|
y = const_cast<MD5Digest&>(r).at(i);
|
||
15 years ago
|
if (x != y) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (i < 16 && x < y) {
|
||
|
return 1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
|