From c628a13d98fde8d2555cc6fa8628e0b575021bd4 Mon Sep 17 00:00:00 2001 From: Szymon Tokarz Date: Mon, 27 May 2013 22:29:01 +0000 Subject: MirFox plugin for Miranda NG added Version 0.5.0.0 Compatible Firefox addon is now available at: https://addons.mozilla.org/pl/firefox/addon/mirfox/versions/0.5.0.0 or http://wsx22.xpdev-hosted.com/ git-svn-id: http://svn.miranda-ng.org/main/trunk@4826 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirFox/src/lib/MirFoxCommonsDebug32.lib | Bin 0 -> 2286562 bytes plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdb | Bin 0 -> 2510848 bytes plugins/MirFox/src/lib/MirFoxCommonsDebug64.lib | Bin 0 -> 2799848 bytes plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdb | Bin 0 -> 2519040 bytes plugins/MirFox/src/lib/MirFoxCommonsRelease32.lib | Bin 0 -> 3481610 bytes plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdb | Bin 0 -> 2494464 bytes plugins/MirFox/src/lib/MirFoxCommonsRelease64.lib | Bin 0 -> 3507872 bytes plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdb | Bin 0 -> 2510848 bytes plugins/MirFox/src/lib/MirFoxCommons_logger.h | 58 ++++++ .../src/lib/MirFoxCommons_messageQueueBySM.h | 87 +++++++++ plugins/MirFox/src/lib/MirFoxCommons_pch.h | 54 ++++++ .../MirFox/src/lib/MirFoxCommons_sharedMemory.h | 207 +++++++++++++++++++++ 12 files changed, 406 insertions(+) create mode 100644 plugins/MirFox/src/lib/MirFoxCommonsDebug32.lib create mode 100644 plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdb create mode 100644 plugins/MirFox/src/lib/MirFoxCommonsDebug64.lib create mode 100644 plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdb create mode 100644 plugins/MirFox/src/lib/MirFoxCommonsRelease32.lib create mode 100644 plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdb create mode 100644 plugins/MirFox/src/lib/MirFoxCommonsRelease64.lib create mode 100644 plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdb create mode 100644 plugins/MirFox/src/lib/MirFoxCommons_logger.h create mode 100644 plugins/MirFox/src/lib/MirFoxCommons_messageQueueBySM.h create mode 100644 plugins/MirFox/src/lib/MirFoxCommons_pch.h create mode 100644 plugins/MirFox/src/lib/MirFoxCommons_sharedMemory.h (limited to 'plugins/MirFox/src/lib') diff --git a/plugins/MirFox/src/lib/MirFoxCommonsDebug32.lib b/plugins/MirFox/src/lib/MirFoxCommonsDebug32.lib new file mode 100644 index 0000000000..baf2b0447c Binary files /dev/null and b/plugins/MirFox/src/lib/MirFoxCommonsDebug32.lib differ diff --git a/plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdb b/plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdb new file mode 100644 index 0000000000..c14655686d Binary files /dev/null and b/plugins/MirFox/src/lib/MirFoxCommonsDebug32.pdb differ diff --git a/plugins/MirFox/src/lib/MirFoxCommonsDebug64.lib b/plugins/MirFox/src/lib/MirFoxCommonsDebug64.lib new file mode 100644 index 0000000000..94a950db06 Binary files /dev/null and b/plugins/MirFox/src/lib/MirFoxCommonsDebug64.lib differ diff --git a/plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdb b/plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdb new file mode 100644 index 0000000000..f548a1a86f Binary files /dev/null and b/plugins/MirFox/src/lib/MirFoxCommonsDebug64.pdb differ diff --git a/plugins/MirFox/src/lib/MirFoxCommonsRelease32.lib b/plugins/MirFox/src/lib/MirFoxCommonsRelease32.lib new file mode 100644 index 0000000000..46b3185bff Binary files /dev/null and b/plugins/MirFox/src/lib/MirFoxCommonsRelease32.lib differ diff --git a/plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdb b/plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdb new file mode 100644 index 0000000000..6cfc177341 Binary files /dev/null and b/plugins/MirFox/src/lib/MirFoxCommonsRelease32.pdb differ diff --git a/plugins/MirFox/src/lib/MirFoxCommonsRelease64.lib b/plugins/MirFox/src/lib/MirFoxCommonsRelease64.lib new file mode 100644 index 0000000000..c0f3f89d7f Binary files /dev/null and b/plugins/MirFox/src/lib/MirFoxCommonsRelease64.lib differ diff --git a/plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdb b/plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdb new file mode 100644 index 0000000000..e45191307e Binary files /dev/null and b/plugins/MirFox/src/lib/MirFoxCommonsRelease64.pdb 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 //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 //for NULL +#include //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 +#include + +//used in: MirFoxCommons_sharedMemory.h +#include //for time +#include //for boost::ptr_list +#include //for boost::tokenizer +#include //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 * clientInstancesListPtr, std::wstring& forThisProfileName); + + //return number of records in contactsListPtr, empty list as parameter + int getContacts(boost::ptr_list * contactsListPtr, unsigned short clientRecordNo); + + //return number of records in accountsListPtr, empty list as parameter + int getAccounts(boost::ptr_list * 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 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 + -- cgit v1.2.3