summaryrefslogtreecommitdiff
path: root/plugins/MirFox/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirFox/src/lib')
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommonsDebug32.libbin0 -> 2286562 bytes
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdbbin0 -> 2510848 bytes
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommonsDebug64.libbin0 -> 2799848 bytes
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdbbin0 -> 2519040 bytes
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommonsRelease32.libbin0 -> 3481610 bytes
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdbbin0 -> 2494464 bytes
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommonsRelease64.libbin0 -> 3507872 bytes
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdbbin0 -> 2510848 bytes
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommons_logger.h58
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h87
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommons_pch.h54
-rw-r--r--plugins/MirFox/src/lib/MirFoxCommons_sharedMemory.h207
12 files changed, 406 insertions, 0 deletions
diff --git a/plugins/MirFox/src/lib/MirFoxCommonsDebug32.lib b/plugins/MirFox/src/lib/MirFoxCommonsDebug32.lib
new file mode 100644
index 0000000000..baf2b0447c
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommonsDebug32.lib
Binary files differ
diff --git a/plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdb b/plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdb
new file mode 100644
index 0000000000..c14655686d
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdb
Binary files differ
diff --git a/plugins/MirFox/src/lib/MirFoxCommonsDebug64.lib b/plugins/MirFox/src/lib/MirFoxCommonsDebug64.lib
new file mode 100644
index 0000000000..94a950db06
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommonsDebug64.lib
Binary files differ
diff --git a/plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdb b/plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdb
new file mode 100644
index 0000000000..f548a1a86f
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdb
Binary files differ
diff --git a/plugins/MirFox/src/lib/MirFoxCommonsRelease32.lib b/plugins/MirFox/src/lib/MirFoxCommonsRelease32.lib
new file mode 100644
index 0000000000..46b3185bff
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommonsRelease32.lib
Binary files differ
diff --git a/plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdb b/plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdb
new file mode 100644
index 0000000000..6cfc177341
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdb
Binary files differ
diff --git a/plugins/MirFox/src/lib/MirFoxCommonsRelease64.lib b/plugins/MirFox/src/lib/MirFoxCommonsRelease64.lib
new file mode 100644
index 0000000000..c0f3f89d7f
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommonsRelease64.lib
Binary files differ
diff --git a/plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdb b/plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdb
new file mode 100644
index 0000000000..e45191307e
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdb
Binary files differ
diff --git a/plugins/MirFox/src/lib/MirFoxCommons_logger.h b/plugins/MirFox/src/lib/MirFoxCommons_logger.h
new file mode 100644
index 0000000000..20a0cc6ccc
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommons_logger.h
@@ -0,0 +1,58 @@
+#ifndef _WSX22_UTILS_LOGGER
+#define _WSX22_UTILS_LOGGER
+
+#define PREFIX_SIZE 6
+typedef void (__cdecl *LogFunction)(const wchar_t* szText);
+
+
+/**
+ * Universal Logger
+ *
+ * Singleton pattern based on
+ * http://www.codeproject.com/KB/threads/SingletonThreadSafety.aspx
+ */
+class MFLogger
+{
+
+public:
+
+ //static method that returns only instance of MFLogger
+ //////no thread safe so use it first time from only one thread (guaranted in mirfox)
+ static MFLogger *
+ getInstance() {
+ //initialized always from one thread
+ if (m_pOnlyOneInstance == NULL) {
+ if (m_pOnlyOneInstance == NULL) {
+ m_pOnlyOneInstance = new MFLogger();
+ }
+ }
+ return m_pOnlyOneInstance;
+ }
+
+ MFLogger();
+
+ void initLogger(LogFunction logFunction_p);
+ void set6CharsPrefix(const wchar_t* prefix);
+ void releaseLogger();
+
+ void log(const wchar_t* szText);
+ void log_p(const wchar_t* szText, ...);
+ void log_d(const wchar_t* szText);
+ void log_dp(const wchar_t* szText, ...);
+
+private:
+
+ void log_int(const wchar_t* szText);
+
+ //holds one and only object of MySingleton
+ static MFLogger* m_pOnlyOneInstance;
+
+ wchar_t m_prefix[PREFIX_SIZE];
+ LogFunction logFunction;
+
+ CRITICAL_SECTION logCs;
+
+};
+
+
+#endif //#ifndef _WSX22_UTILS_LOGGER
diff --git a/plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h b/plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h
new file mode 100644
index 0000000000..513b720ee7
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h
@@ -0,0 +1,87 @@
+#ifndef _WSX22_IPC_MESSAGEQUEUEBYSM
+#define _WSX22_IPC_MESSAGEQUEUEBYSM
+
+
+
+//message queue by shared memory related definitions
+#define MQCONST_MQSM_TEXT_SIZEC 2042 //number of wchar_t chars in message - now used sharedmemory mode
+
+#define MQTHREAD_TICK_TIME 100 // 100ms - check exit every this time
+#define MQTHREAD_FIRSTRUN_TIME 0 // MQTHREAD_FIRSTRUN_TIME * MQTHREAD_TICK_TIME = 0s - time to first run of checking message queue in mq thread (after thread start)
+#define MQTHREAD_NEXTRUN_TIME 1 // MQTHREAD_NEXTRUN_TIME * MQTHREAD_TICK_TIME = 0s - time to next run of checking message queue in mq thread
+
+
+
+#include "MirFoxCommons_logger.h"
+
+
+
+
+
+
+/**
+ * MessageQueue Utils
+ *
+ * based on Boost Shared Memory, beacouse boost message queue doesn't work between 32bit and 64bit processes (at boost 1.46)
+ *
+ * Singleton pattern based on
+ * http://www.codeproject.com/KB/threads/SingletonThreadSafety.aspx
+ */
+class MessageQueueUtils
+{
+
+public:
+
+ //constructor
+ MessageQueueUtils();
+ //destructor
+ ~MessageQueueUtils();
+
+
+
+ std::string getMqName(uint16_t processId);
+
+ //return 0 if success, >0 if error
+ int createMessageQueue(std::string mqName);
+
+ void unloadMessageQueue(uint16_t unloadedMQProcessId);
+
+ //wchar_t*& - pointer by reference
+ bool tryReceiveMessage (char& menuItemType, char& userActionType, char& userButton, uint64_t& targetHandle, wchar_t*& userActionSelection, size_t uasBuffCSize);
+
+ void sendMessage(int clientRecordId, char menuItemType, char userActionType, char userButton, uint64_t targetHandle, std::wstring userActionSelection);
+
+ uint16_t volatile unloadedMQProcessId;
+
+
+ //static method that returns only instance of SharedMemoryUtils
+ static MessageQueueUtils * getInstance()
+ {
+ //initialized always from one thread at a time
+ if (m_pOnlyOneInstance == NULL) {
+ if (m_pOnlyOneInstance == NULL) {
+ m_pOnlyOneInstance = new MessageQueueUtils();
+ }
+ }
+ return m_pOnlyOneInstance;
+ }
+
+
+private:
+
+ boost::interprocess::windows_shared_memory* volatile mqMirSm;
+
+ std::size_t getMqMirSmTotalSize();
+
+ //CRITICAL_SECTION smCs;
+ HANDLE smMutex;
+
+ //holds one and only object of MySingleton
+ static MessageQueueUtils * m_pOnlyOneInstance;
+
+ MFLogger* logger;
+
+};
+
+
+#endif //#ifndef _WSX22_IPC_MESSAGEQUEUEBYSM
diff --git a/plugins/MirFox/src/lib/MirFoxCommons_pch.h b/plugins/MirFox/src/lib/MirFoxCommons_pch.h
new file mode 100644
index 0000000000..d8b53974af
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommons_pch.h
@@ -0,0 +1,54 @@
+
+//used in: all
+
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef WINVER // Allow use of features specific to Windows XP or later.
+#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
+#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
+#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
+#endif
+
+#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
+#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE.
+#endif
+
+#if defined( UNICODE ) && !defined( _UNICODE )
+#define _UNICODE
+#endif
+
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+#include <stdint.h> //for [u]intNN_t types
+#ifdef _X64 // [
+# define SCNoPTR L"%I64o"
+# define SCNuPTR L"%I64u"
+# define SCNxPTR L"%I64x"
+# define SCNXPTR L"%I64X"
+#else // _X64 ][
+# define SCNoPTR L"%lo"
+# define SCNuPTR L"%lu"
+# define SCNxPTR L"%lx"
+# define SCNXPTR L"%lX"
+#endif // _X64 ]
+#include <windows.h> //for NULL
+#include <string> //for std::string, std::wstring, TEXT and _T macros, operator<<
+
+
+//used in: MirFoxCommons_messageQueueBySM.h and MirFoxCommons_sharedMemory.h
+#define BOOST_DATE_TIME_NO_LIB
+#include <boost/interprocess/windows_shared_memory.hpp>
+#include <boost/interprocess/mapped_region.hpp>
+
+//used in: MirFoxCommons_sharedMemory.h
+#include <time.h> //for time
+#include <boost/ptr_container/ptr_list.hpp> //for boost::ptr_list
+#include <boost/tokenizer.hpp> //for boost::tokenizer
+#include <boost/foreach.hpp> //for BOOST_FOREACH
+
+
diff --git a/plugins/MirFox/src/lib/MirFoxCommons_sharedMemory.h b/plugins/MirFox/src/lib/MirFoxCommons_sharedMemory.h
new file mode 100644
index 0000000000..c488268ee6
--- /dev/null
+++ b/plugins/MirFox/src/lib/MirFoxCommons_sharedMemory.h
@@ -0,0 +1,207 @@
+#ifndef _WSX22_IPC_SHAREDMEMORY
+#define _WSX22_IPC_SHAREDMEMORY
+
+
+#include "MirFoxCommons_logger.h"
+
+
+//shared memory related definitions
+#define CSMTHREAD_TICK_TIME 100 // 100ms - check exit every this time
+#define CSMTHREAD_FIRSTRUN_TIME 100 // CSMTHREAD_FIRSTRUN_TIME * CSMTHREAD_TICK_TIME = 10s - time to first run of checking csm state in csm thread (after thread start)
+#define CSMTHREAD_NEXTRUN_TIME 100 // CSMTHREAD_NEXTRUN_TIME * CSMTHREAD_TICK_TIME = 10s - time to next run of checking csm state in csm thread
+
+#define SMUCONST_CSM_RECORD_VISABLETO_SIZEC_DEF 128
+#define SMUCONST_CSM_RECORD_DNAME_SIZEC_DEF 78
+#define SMUCONST_MSM_RECORD_DNAME_SIZEC_DEF 78
+
+
+
+class ClientInstanceClass
+{
+public:
+ std::wstring displayName; //display name
+ uint16_t recordId; //id
+};
+
+class ContactClass
+{
+public:
+ std::wstring displayName; //display name
+ uint64_t handle; //miranda HANDLE to contact (casted pointer)
+};
+
+class AccountClass
+{
+public:
+ std::wstring displayName; //display name
+ uint64_t handle; //miranda HANDLE to account (casted pointer)
+};
+
+
+
+struct OpenOrCreateSMReturnStruct {
+ int errorCode;
+ uint16_t processCsmId;
+};
+
+
+
+/**
+ * SharedMemory Utils
+ *
+ * Singleton pattern based on
+ * http://www.codeproject.com/KB/threads/SingletonThreadSafety.aspx
+ */
+class SharedMemoryUtils
+{
+
+public:
+
+
+ //constructor
+ SharedMemoryUtils();
+ //destructor
+ ~SharedMemoryUtils();
+
+
+ /**
+ * open existing or create new central shared memory
+ *
+ * type - char - 'M' - Miranda, 'F' - Firefox
+ *
+ * return OpenOrCreateSMReturnStruct
+ * .errorCode
+ * 0 - ok, and .processCsmId = id of process record in csm
+ * -2 - no more available (Empty) records in central shared memory
+ * -3 - existing csm version is too high (from checkCsmVersion)
+ * -4 - existing csm version is too low (from checkCsmVersion)
+ */
+ OpenOrCreateSMReturnStruct openOrCreateSM(char type, std::wstring& displayName, std::wstring& visableTo, bool doCommitSM);
+
+
+ int addOptionToSM(int optionID, std::wstring& optionValue);
+
+ int addTranslationToSM(int translationId, std::wstring& translationValue );
+
+ int addAccountToSM(uint64_t mirandaAccountId, std::wstring& displayName);
+
+ // group type: R - root, N - normal
+ int addGroupToSM(uint64_t mirandaGroupHandle, uint64_t parentGroupHandle, char groupType, std::wstring& displayName);
+
+ int addContactToSM(uint64_t mirandaContactHandle, uint64_t mirandaAccountHandle, uint64_t mirandaGroupHandle, std::wstring& displayName);
+
+ //call after openOrCreateSM and after creating sm thread
+ int commitSM();
+
+ //delete returned sm object after use
+ boost::interprocess::windows_shared_memory* getSmById(const char* smName, std::size_t smSize);
+
+ //returns:
+ // 0 - ok
+ // 1 - record error (state != 'W' (working) or wrong displayName)
+ // -3 - existing csm version is too high (from checkCsmVersion)
+ // -4 - existing csm version is too low (from checkCsmVersion)
+ int checkCSM(boost::interprocess::windows_shared_memory* checkedCsm, uint16_t processCsmId, std::wstring& displayNameProfile);
+
+ void updateCsmTimestamp(boost::interprocess::windows_shared_memory& updateCsm, uint16_t processCsmId);
+
+ //dla wszystkich innych rekord�w w csm w statusie W, sprawdza czy rekord w csm nie jest przeterminowany jeli tak to go usuwa
+ void checkAnotherCsm(boost::interprocess::windows_shared_memory& checkedCsm, uint16_t processCsmId);
+
+ //unload and free shared memory records and structures
+ void unloadSharedMemory(uint16_t processCsmId);
+
+ //execute before start creating MSMs
+ void resetMsmParameters();
+
+
+ ////FUNCTIONS FOR FIREFOX
+
+ //return true if any client (miranda instance) is available in csm for current firefox profile
+ bool isAnyMirandaCsmRecordAvailable(std::wstring& forThisProfileName);
+
+ //return number of records in clientInstanceNamesList, empty list as parameter
+ int getClientInstances(boost::ptr_list<ClientInstanceClass> * clientInstancesListPtr, std::wstring& forThisProfileName);
+
+ //return number of records in contactsListPtr, empty list as parameter
+ int getContacts(boost::ptr_list<ContactClass> * contactsListPtr, unsigned short clientRecordNo);
+
+ //return number of records in accountsListPtr, empty list as parameter
+ int getAccounts(boost::ptr_list<AccountClass> * accountsListPtr, unsigned short clientRecordNo);
+
+ ////FUNCTIONS FOR FIREFOX - end
+
+
+
+
+ const char* getCsmName();
+ std::string getMsmName(uint16_t id, int currentNumber);
+ std::size_t getCsmTotalSize();
+ std::size_t getMsmTotalSize();
+
+
+
+ //static method that returns only instance of SharedMemoryUtils
+ static SharedMemoryUtils * getInstance()
+ {
+ //initialized always from one thread at a time
+ if (m_pOnlyOneInstance == NULL) {
+ if (m_pOnlyOneInstance == NULL) {
+ m_pOnlyOneInstance = new SharedMemoryUtils();
+ }
+ }
+ return m_pOnlyOneInstance;
+ }
+
+
+private:
+
+ //holds one and only object of MySingleton
+ static SharedMemoryUtils* m_pOnlyOneInstance;
+
+ MFLogger* logger;
+
+
+ //global variables
+ boost::interprocess::windows_shared_memory* csm;
+ boost::ptr_list<boost::interprocess::windows_shared_memory> msmList;
+
+
+
+ bool isCsmInited(boost::interprocess::windows_shared_memory& csm);
+ void initCsm(boost::interprocess::windows_shared_memory& csm);
+
+ //return:
+ // 0 - versions match,
+ // -3 - existing csm version is too high
+ // -4 - existing csm version is too low
+ int checkCsmVersion(boost::interprocess::windows_shared_memory& csm);
+
+ uint16_t allocateRecordInCsm(boost::interprocess::windows_shared_memory& csm, char type, std::wstring& displayName, std::wstring& visableTo, bool doCommitSM);
+
+ time_t mfGetCurrentTimestamp();
+
+ int addRecordToMsm(char type, uint64_t agcHandle, uint64_t accountHandle, uint64_t groupHandle, char status, std::wstring& value);
+
+ int checkCsmRecord(boost::interprocess::windows_shared_memory& checkedCsm, uint16_t processCsmId, std::wstring& displayNameProfile);
+
+ void freeCsmRecord(boost::interprocess::windows_shared_memory& csm, uint16_t recordNo);
+
+ bool isTokenOnList(std::wstring& token, std::wstring& tokensList);
+
+ //free own record in csm
+ void unloadFromCSM(uint16_t processCsmId);
+
+ //free msm instances
+ void unloadMSMs();
+
+ uint16_t processCsmId;
+ int freeMsmRecordsCount;
+ int nextMsmNumber; //from 1
+
+
+};
+
+
+#endif //#ifndef _WSX22_IPC_SHAREDMEMORY
+