aboutsummaryrefslogtreecommitdiffstats
path: root/src/kvilib
diff options
context:
space:
mode:
Diffstat (limited to 'src/kvilib')
-rw-r--r--src/kvilib/CMakeLists.txt1
-rw-r--r--src/kvilib/ext/KviCryptEngine.cpp58
-rw-r--r--src/kvilib/ext/KviCryptEngine.h81
-rw-r--r--src/kvilib/ext/KviCryptEngineDescription.h51
-rw-r--r--src/kvilib/ext/KviCryptEngineManager.cpp87
-rw-r--r--src/kvilib/ext/KviCryptEngineManager.h60
6 files changed, 226 insertions, 112 deletions
diff --git a/src/kvilib/CMakeLists.txt b/src/kvilib/CMakeLists.txt
index 98271a4ab..fb6d67a8f 100644
--- a/src/kvilib/CMakeLists.txt
+++ b/src/kvilib/CMakeLists.txt
@@ -64,6 +64,7 @@ SET(kvilib_SRCS
ext/KviCommandFormatter.cpp
ext/KviConfigurationFile.cpp
ext/KviCryptEngine.cpp
+ ext/KviCryptEngineManager.cpp
ext/KviDataBuffer.cpp
ext/KviDbusAdaptor.cpp
ext/KviDebugContext.cpp
diff --git a/src/kvilib/ext/KviCryptEngine.cpp b/src/kvilib/ext/KviCryptEngine.cpp
index dc5cccc07..b52b6565c 100644
--- a/src/kvilib/ext/KviCryptEngine.cpp
+++ b/src/kvilib/ext/KviCryptEngine.cpp
@@ -25,6 +25,7 @@
#include "KviCryptEngine.h"
#include "KviLocale.h"
+#include "KviCString.h"
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
#include "KviMemory.h"
@@ -185,61 +186,4 @@
return DecryptError;
}
-
- KviCryptEngineManager::KviCryptEngineManager()
- {
- m_pEngineDict = new KviPointerHashTable<QString,KviCryptEngineDescription>;
- m_pEngineDict->setAutoDelete(true);
- }
-
- KviCryptEngineManager::~KviCryptEngineManager()
- {
- delete m_pEngineDict;
- }
-
- void KviCryptEngineManager::registerEngine(KviCryptEngineDescription * pDesc)
- {
- m_pEngineDict->replace(pDesc->m_szName,pDesc);
- }
-
- void KviCryptEngineManager::unregisterEngine(const QString & szName)
- {
- m_pEngineDict->remove(szName);
- }
-
- void KviCryptEngineManager::unregisterEngines(void * providerHandle)
- {
- KviPointerList<QString> lEnginesToRemove;
- lEnginesToRemove.setAutoDelete(true);
-
- for(KviPointerHashTableEntry<QString,KviCryptEngineDescription> * pDesc = m_pEngineDict->firstEntry();pDesc;pDesc = m_pEngineDict->nextEntry())
- {
- if(pDesc->data()->m_providerHandle == providerHandle)
- lEnginesToRemove.append(new QString(pDesc->key()));
- }
-
- for(QString * pszEngineName = lEnginesToRemove.first();pszEngineName;pszEngineName = lEnginesToRemove.next())
- m_pEngineDict->remove(*pszEngineName);
- }
-
- KviCryptEngine * KviCryptEngineManager::allocateEngine(const QString & szName)
- {
- KviCryptEngineDescription * pDesc = m_pEngineDict->find(szName);
- if(!pDesc)
- return 0;
- KviCryptEngine * pEngine = pDesc->m_allocFunc();
- if(!pEngine)
- return 0;
- pEngine->m_deallocFunc = pDesc->m_deallocFunc; // remember the dealloc func from now on
- return pEngine;
- }
-
- void KviCryptEngineManager::deallocateEngine(KviCryptEngine * pEngine)
- {
- if(!pEngine)
- return;
- crypt_engine_deallocator_func deallocFunc = pEngine->m_deallocFunc;
- deallocFunc(pEngine);
- }
-
#endif //COMPILE_CRYPT_SUPPORT
diff --git a/src/kvilib/ext/KviCryptEngine.h b/src/kvilib/ext/KviCryptEngine.h
index feef20538..5b01b4de5 100644
--- a/src/kvilib/ext/KviCryptEngine.h
+++ b/src/kvilib/ext/KviCryptEngine.h
@@ -1,5 +1,5 @@
-#ifndef _KVI_CRYPT_H_
-#define _KVI_CRYPT_H_
+#ifndef _KVI_CRYPT_ENGINE_H_
+#define _KVI_CRYPT_ENGINE_H_
//=============================================================================
//
@@ -37,13 +37,12 @@
//
-#include "KviQString.h"
-#include "KviCString.h"
#include "KviHeapObject.h"
-#include "KviPointerHashTable.h"
#include <QObject>
+class KviCString;
+
#ifdef COMPILE_CRYPT_SUPPORT
class KviCryptEngine;
@@ -59,6 +58,26 @@
Q_OBJECT
friend class KviCryptEngineManager;
public:
+ enum EngineFlag {
+ CanEncrypt = 1,
+ CanDecrypt = 2,
+ WantEncryptKey = 4,
+ WantDecryptKey = 8
+ };
+
+ enum EncryptResult {
+ Encrypted,
+ Encoded,
+ EncryptError
+ };
+
+ enum DecryptResult {
+ DecryptOkWasEncrypted,
+ DecryptOkWasEncoded,
+ DecryptOkWasPlainText,
+ DecryptError
+ };
+
KviCryptEngine();
virtual ~KviCryptEngine();
@@ -85,7 +104,6 @@
// Theoretically we could allow NULLs in plainText
// but this is not the case of KVIrc.
//
- enum EncryptResult { Encrypted, Encoded, EncryptError };
virtual EncryptResult encrypt(const char * plainText,KviCString &outBuffer);
//
// Decrypts the utf8 data in inBuffer and puts the decrypted utf8
@@ -94,14 +112,13 @@
// follows the same rules.
// Should return false in case of error.
//
- enum DecryptResult { DecryptOkWasEncrypted, DecryptOkWasEncoded, DecryptOkWasPlainText, DecryptError };
virtual DecryptResult decrypt(const char * inBuffer,KviCString &plainText);
//
// Returns the string containing the description
// of the last error or an empty string if there
// was no error after the last init() call.
//
- const QString &lastError(){ return m_szLastError; };
+ const QString & lastError(){ return m_szLastError; };
protected:
//
// The following two should have clear meaning
@@ -111,50 +128,4 @@
#endif //COMPILE_CRYPT_SUPPORT
};
-#ifdef COMPILE_CRYPT_SUPPORT
- #define KVI_CRYPTENGINE_CAN_ENCRYPT 1
- #define KVI_CRYPTENGINE_CAN_DECRYPT 2
- #define KVI_CRYPTENGINE_WANT_ENCRYPT_KEY 4
- #define KVI_CRYPTENGINE_WANT_DECRYPT_KEY 8
-
- class KVILIB_API KviCryptEngineDescription : public KviHeapObject
- {
- public:
- KviCryptEngineDescription(){};
- virtual ~KviCryptEngineDescription(){};
- public:
- QString m_szName; // engine name
- QString m_szDescription; // details
- QString m_szAuthor; // algorithm author
- int m_iFlags; // properties
- crypt_engine_allocator_func m_allocFunc; // engine allocator
- crypt_engine_deallocator_func m_deallocFunc; // deallocation function (if called from outside the origin module)
- void * m_providerHandle; // used to identify the provider module
- };
-
-
- class KVILIB_API KviCryptEngineManager
- {
- public:
- KviCryptEngineManager();
- virtual ~KviCryptEngineManager();
- private:
- KviPointerHashTable<QString,KviCryptEngineDescription> * m_pEngineDict;
- public:
- const KviPointerHashTable<QString,KviCryptEngineDescription> * engineDict(){ return m_pEngineDict; };
- void registerEngine(KviCryptEngineDescription * d);
- void unregisterEngine(const QString &szName);
- void unregisterEngines(void * providerHandle);
- //
- // Allocates a crypt engine
- // Please note that the engine may be deleted from outside
- // so you'd better connect the "destroyed" signal
- //
- KviCryptEngine * allocateEngine(const QString &szName);
- void deallocateEngine(KviCryptEngine * e);
- };
-
-#endif //COMPILE_CRYPT_SUPPORT
-
-
-#endif //!_KVI_CRYPT_H_
+#endif // _KVI_CRYPT_ENGINE_H_
diff --git a/src/kvilib/ext/KviCryptEngineDescription.h b/src/kvilib/ext/KviCryptEngineDescription.h
new file mode 100644
index 000000000..f5a6e7ee6
--- /dev/null
+++ b/src/kvilib/ext/KviCryptEngineDescription.h
@@ -0,0 +1,51 @@
+#ifndef _KVI_CRYPT_ENGINE_DESC_H_
+#define _KVI_CRYPT_ENGINE_DESC_H_
+
+//=============================================================================
+//
+// File : KviCryptEngineManager.h
+// Creation date : Wed Dec 29 2010 22:10:05 CEST by Elvio Basello
+//
+// This file is part of the KVIrc irc client distribution
+// Copyright (C) 2010 Elvio Basello (hellvis69 at gmail dot com)
+//
+// This program is FREE software. You can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your opinion) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, write to the Free Software Foundation,
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+// this file was originally part of KviCryptEngine.h
+
+#include "kvi_settings.h"
+#include "KviHeapObject.h"
+
+#ifdef COMPILE_CRYPT_SUPPORT
+
+ class KVILIB_API KviCryptEngineDescription : public KviHeapObject
+ {
+ public:
+ KviCryptEngineDescription(){};
+ virtual ~KviCryptEngineDescription(){};
+ public:
+ QString m_szName; /**< engine name */
+ QString m_szDescription; /**< details */
+ QString m_szAuthor; /**< algorithm author */
+ int m_iFlags; /**< properties */
+ crypt_engine_allocator_func m_allocFunc; /**< engine allocator */
+ crypt_engine_deallocator_func m_deallocFunc; /**< deallocation function (if called from outside the origin module) */
+ void * m_providerHandle; /**< used to identify the provider module */
+ };
+
+#endif //COMPILE_CRYPT_SUPPORT
+#endif // _KVI_CRYPT_ENGINE_DESC_H_
diff --git a/src/kvilib/ext/KviCryptEngineManager.cpp b/src/kvilib/ext/KviCryptEngineManager.cpp
new file mode 100644
index 000000000..6c9640665
--- /dev/null
+++ b/src/kvilib/ext/KviCryptEngineManager.cpp
@@ -0,0 +1,87 @@
+//=============================================================================
+//
+// File : KviCryptEngineManager.cpp
+// Creation date : Wed Dec 29 2010 22:10:05 CEST by Elvio Basello
+//
+// This file is part of the KVIrc irc client distribution
+// Copyright (C) 2010 Elvio Basello (hellvis69 at gmail dot com)
+//
+// This program is FREE software. You can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your opinion) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, write to the Free Software Foundation,
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+#include "KviCryptEngineManager.h"
+#include "KviCryptEngine.h"
+#include "KviCryptEngineDescription.h"
+
+#ifdef COMPILE_CRYPT_SUPPORT
+
+ KviCryptEngineManager::KviCryptEngineManager()
+ {
+ m_pEngineDict = new KviPointerHashTable<QString,KviCryptEngineDescription>;
+ m_pEngineDict->setAutoDelete(true);
+ }
+
+ KviCryptEngineManager::~KviCryptEngineManager()
+ {
+ delete m_pEngineDict;
+ }
+
+ void KviCryptEngineManager::registerEngine(KviCryptEngineDescription * pDesc)
+ {
+ m_pEngineDict->replace(pDesc->m_szName,pDesc);
+ }
+
+ void KviCryptEngineManager::unregisterEngine(const QString & szName)
+ {
+ m_pEngineDict->remove(szName);
+ }
+
+ void KviCryptEngineManager::unregisterEngines(void * providerHandle)
+ {
+ KviPointerList<QString> lEnginesToRemove;
+ lEnginesToRemove.setAutoDelete(true);
+
+ for(KviPointerHashTableEntry<QString,KviCryptEngineDescription> * pDesc = m_pEngineDict->firstEntry();pDesc;pDesc = m_pEngineDict->nextEntry())
+ {
+ if(pDesc->data()->m_providerHandle == providerHandle)
+ lEnginesToRemove.append(new QString(pDesc->key()));
+ }
+
+ for(QString * pszEngineName = lEnginesToRemove.first();pszEngineName;pszEngineName = lEnginesToRemove.next())
+ m_pEngineDict->remove(*pszEngineName);
+ }
+
+ KviCryptEngine * KviCryptEngineManager::allocateEngine(const QString & szName)
+ {
+ KviCryptEngineDescription * pDesc = m_pEngineDict->find(szName);
+ if(!pDesc)
+ return 0;
+ KviCryptEngine * pEngine = pDesc->m_allocFunc();
+ if(!pEngine)
+ return 0;
+ pEngine->m_deallocFunc = pDesc->m_deallocFunc; // remember the dealloc func from now on
+ return pEngine;
+ }
+
+ void KviCryptEngineManager::deallocateEngine(KviCryptEngine * pEngine)
+ {
+ if(!pEngine)
+ return;
+ crypt_engine_deallocator_func deallocFunc = pEngine->m_deallocFunc;
+ deallocFunc(pEngine);
+ }
+
+#endif // COMPILE_CRYPT_SUPPORT
diff --git a/src/kvilib/ext/KviCryptEngineManager.h b/src/kvilib/ext/KviCryptEngineManager.h
new file mode 100644
index 000000000..2541e6782
--- /dev/null
+++ b/src/kvilib/ext/KviCryptEngineManager.h
@@ -0,0 +1,60 @@
+#ifndef _KVI_CRYPT_ENGINE_MANAGER_H_
+#define _KVI_CRYPT_ENGINE_MANAGER_H_
+
+//=============================================================================
+//
+// File : KviCryptEngineManager.h
+// Creation date : Wed Dec 29 2010 22:10:05 CEST by Elvio Basello
+//
+// This file is part of the KVIrc irc client distribution
+// Copyright (C) 2010 Elvio Basello (hellvis69 at gmail dot com)
+//
+// This program is FREE software. You can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your opinion) any later version.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, write to the Free Software Foundation,
+// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//=============================================================================
+
+// this file was originally part of KviCryptEngine.h
+
+#include "kvi_settings.h"
+#include "KviPointerHashTable.h"
+
+class KviCryptEngine;
+class KviCryptEngineDescription;
+
+#ifdef COMPILE_CRYPT_SUPPORT
+
+ class KVILIB_API KviCryptEngineManager
+ {
+ public:
+ KviCryptEngineManager();
+ virtual ~KviCryptEngineManager();
+ private:
+ KviPointerHashTable<QString,KviCryptEngineDescription> * m_pEngineDict;
+ public:
+ const KviPointerHashTable<QString,KviCryptEngineDescription> * engineDict(){ return m_pEngineDict; };
+ void registerEngine(KviCryptEngineDescription * pDesc);
+ void unregisterEngine(const QString & szName);
+ void unregisterEngines(void * providerHandle);
+ //
+ // Allocates a crypt engine
+ // Please note that the engine may be deleted from outside
+ // so you'd better connect the "destroyed" signal
+ //
+ KviCryptEngine * allocateEngine(const QString & szName);
+ void deallocateEngine(KviCryptEngine * pEngine);
+ };
+
+#endif // COMPILE_CRYPT_SUPPORT
+#endif // _KVI_CRYPT_ENGINE_MANAGER_H_ \ No newline at end of file