From 89edcbf870653ff219eb57565383ce708d14783b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 7 Apr 2013 15:49:14 +0000 Subject: port of yaRelay plugin under NG git-svn-id: http://svn.miranda-ng.org/main/trunk@4366 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/YARelay/YARelay_10.vcxproj | 203 ++++++++++++++++++++++ plugins/YARelay/YARelay_10.vcxproj.filters | 44 +++++ plugins/YARelay/YARelay_11.vcxproj | 205 ++++++++++++++++++++++ plugins/YARelay/YARelay_11.vcxproj.filters | 47 +++++ plugins/YARelay/docs/yaRelay.txt | 14 ++ plugins/YARelay/res/Version.rc | 38 ++++ plugins/YARelay/res/yaRelay.rc | 149 ++++++++++++++++ plugins/YARelay/src/Version.h | 14 ++ plugins/YARelay/src/main.cpp | 267 +++++++++++++++++++++++++++++ plugins/YARelay/src/options.cpp | 201 ++++++++++++++++++++++ plugins/YARelay/src/resource.h | 36 ++++ plugins/YARelay/src/stdafx.cpp | 18 ++ plugins/YARelay/src/stdafx.h | 64 +++++++ 13 files changed, 1300 insertions(+) create mode 100644 plugins/YARelay/YARelay_10.vcxproj create mode 100644 plugins/YARelay/YARelay_10.vcxproj.filters create mode 100644 plugins/YARelay/YARelay_11.vcxproj create mode 100644 plugins/YARelay/YARelay_11.vcxproj.filters create mode 100644 plugins/YARelay/docs/yaRelay.txt create mode 100644 plugins/YARelay/res/Version.rc create mode 100644 plugins/YARelay/res/yaRelay.rc create mode 100644 plugins/YARelay/src/Version.h create mode 100644 plugins/YARelay/src/main.cpp create mode 100644 plugins/YARelay/src/options.cpp create mode 100644 plugins/YARelay/src/resource.h create mode 100644 plugins/YARelay/src/stdafx.cpp create mode 100644 plugins/YARelay/src/stdafx.h (limited to 'plugins') diff --git a/plugins/YARelay/YARelay_10.vcxproj b/plugins/YARelay/YARelay_10.vcxproj new file mode 100644 index 0000000000..bd6c661871 --- /dev/null +++ b/plugins/YARelay/YARelay_10.vcxproj @@ -0,0 +1,203 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + YARelay + {00037ACC-F32D-4B5F-93A8-3CF0E277E377} + + + + DynamicLibrary + Unicode + true + + + DynamicLibrary + Unicode + + + DynamicLibrary + Unicode + true + + + DynamicLibrary + Unicode + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(Configuration)\Plugins\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)\Plugins\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)64\Plugins\ + $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)64\Plugins\ + $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ + true + + + + false + Full + Level3 + true + ..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + OnlyExplicitInline + false + Size + false + autorun.h + Use + + + NDEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + true + true + Windows + $(IntDir)$(TargetName).lib + true + true + false + $(ProfileDir)..\..\bin10\lib + /PDBALTPATH:%_PDB% + + + + + MultiThreadedDebugDLL + false + Disabled + Level3 + true + EditAndContinue + ..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + EnableFastChecks + false + autorun.h + Use + + + _DEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + true + true + Windows + $(IntDir)$(TargetName).lib + false + $(ProfileDir)..\..\bin10\lib + + + + + false + Full + Level3 + ..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories) + WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + Default + OnlyExplicitInline + Size + false + autorun.h + Use + + + NDEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + true + true + Windows + $(IntDir)$(TargetName).lib + false + $(ProfileDir)..\..\bin10\lib + /PDBALTPATH:%_PDB% + + + + + MultiThreadedDebugDLL + false + Disabled + Level3 + ..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories) + WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + EnableFastChecks + false + autorun.h + Use + + + _DEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + true + true + Windows + $(IntDir)$(TargetName).lib + false + $(ProfileDir)..\..\bin10\lib + + + + + + + + + + + + + + + Create + + + + + + \ No newline at end of file diff --git a/plugins/YARelay/YARelay_10.vcxproj.filters b/plugins/YARelay/YARelay_10.vcxproj.filters new file mode 100644 index 0000000000..8d0561f6f0 --- /dev/null +++ b/plugins/YARelay/YARelay_10.vcxproj.filters @@ -0,0 +1,44 @@ + + + + + {08a21636-368d-4feb-8d0d-0a27f237e1a2} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {9e6f20dc-3391-4299-9f74-e91d4f984ad3} + h;hpp;hxx;hm;inl + + + {18fd6180-ebb2-4558-b945-c4dac823f11b} + ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Header Files + + + Header Files + + + Header Files + + + + + Resource Files + + + Resource Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/plugins/YARelay/YARelay_11.vcxproj b/plugins/YARelay/YARelay_11.vcxproj new file mode 100644 index 0000000000..c768ae8545 --- /dev/null +++ b/plugins/YARelay/YARelay_11.vcxproj @@ -0,0 +1,205 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + YARelay + {00037ACC-F32D-4B5F-93A8-3CF0E277E377} + + + + DynamicLibrary + Unicode + true + v110_xp + + + DynamicLibrary + Unicode + v110_xp + + + DynamicLibrary + Unicode + true + v110_xp + + + DynamicLibrary + Unicode + v110_xp + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(Configuration)\Plugins\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)\Plugins\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)64\Plugins\ + $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)64\Plugins\ + $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ + true + + + + false + Full + Level3 + true + ..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + OnlyExplicitInline + false + Size + false + Use + + + NDEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + true + true + Windows + $(IntDir)$(TargetName).lib + true + true + false + $(ProfileDir)..\..\bin11\lib + /PDBALTPATH:%_PDB% + + + + + MultiThreadedDebugDLL + false + Disabled + Level3 + true + EditAndContinue + ..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + EnableFastChecks + false + Use + + + _DEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + true + true + Windows + $(IntDir)$(TargetName).lib + false + $(ProfileDir)..\..\bin11\lib + false + + + + + false + Full + Level3 + ..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories) + WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + Default + OnlyExplicitInline + Size + false + Use + + + NDEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + true + true + Windows + $(IntDir)$(TargetName).lib + false + $(ProfileDir)..\..\bin11\lib + /PDBALTPATH:%_PDB% + + + + + MultiThreadedDebugDLL + false + Disabled + Level3 + ..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories) + WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + EnableFastChecks + false + Use + + + _DEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + true + true + Windows + $(IntDir)$(TargetName).lib + false + $(ProfileDir)..\..\bin11\lib + + + + + + + + + + + + + + + + Create + + + + + + \ No newline at end of file diff --git a/plugins/YARelay/YARelay_11.vcxproj.filters b/plugins/YARelay/YARelay_11.vcxproj.filters new file mode 100644 index 0000000000..c98606c1ea --- /dev/null +++ b/plugins/YARelay/YARelay_11.vcxproj.filters @@ -0,0 +1,47 @@ + + + + + {08a21636-368d-4feb-8d0d-0a27f237e1a2} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {9e6f20dc-3391-4299-9f74-e91d4f984ad3} + h;hpp;hxx;hm;inl + + + {18fd6180-ebb2-4558-b945-c4dac823f11b} + ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + + + Header Files + + + Header Files + + + Header Files + + + + + Resource Files + + + Resource Files + + + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/plugins/YARelay/docs/yaRelay.txt b/plugins/YARelay/docs/yaRelay.txt new file mode 100644 index 0000000000..989c929468 --- /dev/null +++ b/plugins/YARelay/docs/yaRelay.txt @@ -0,0 +1,14 @@ +Yet Another Relay plugin. v.0.0.0.3 +This plugin forwards all incoming messages to any contact. + +Features: + - Forwards all messages from any specified contact (or from all contacts) + - Works only if your status is equals to specified (of set of statuses) + - Could be specified any template for sent messages + - Original message could be split up (by size) + - Could be specified number of split parts to send + - Incoming message could be marked as 'read' (optional) + - Outgoing messages could be saved in history (optional) + +(c) Anar Ibragimoff +ai91@mail.ru \ No newline at end of file diff --git a/plugins/YARelay/res/Version.rc b/plugins/YARelay/res/Version.rc new file mode 100644 index 0000000000..5bfbab4754 --- /dev/null +++ b/plugins/YARelay/res/Version.rc @@ -0,0 +1,38 @@ +// Microsoft Visual C++ generated resource script. +// +#ifdef APSTUDIO_INVOKED +#error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + +#include "afxres.h" +#include "..\src\version.h" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION __FILEVERSION_STRING + PRODUCTVERSION __FILEVERSION_STRING + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "FileDescription", __DESCRIPTION + VALUE "InternalName", __PLUGIN_NAME + VALUE "LegalCopyright", __COPYRIGHT + VALUE "OriginalFilename", __FILENAME + VALUE "ProductName", __PLUGIN_NAME + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/plugins/YARelay/res/yaRelay.rc b/plugins/YARelay/res/yaRelay.rc new file mode 100644 index 0000000000..4da7b25f1c --- /dev/null +++ b/plugins/YARelay/res/yaRelay.rc @@ -0,0 +1,149 @@ +//Microsoft Developer Studio generated resource script. +// +#include "..\src\resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_SETTINGS DIALOG DISCARDABLE 0, 0, 308, 187 +STYLE WS_CHILD +FONT 8, "MS Sans Serif" +BEGIN + GROUPBOX "Forward messages from...",IDC_STATIC,3,3,147,45 + CONTROL "Everyone",IDC_RADIO_ALL,"Button",BS_AUTORADIOBUTTON | + WS_GROUP | WS_TABSTOP,8,14,132,10 + CONTROL "Contact",IDC_RADIO_CUSTOM,"Button",BS_AUTORADIOBUTTON | + WS_TABSTOP,8,30,46,10 + COMBOBOX IDC_COMBO_FROM,57,28,87,137,CBS_DROPDOWNLIST | CBS_SORT | + WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_COMBO_TO,213,14,87,142,CBS_DROPDOWNLIST | CBS_SORT | + WS_VSCROLL | WS_TABSTOP + GROUPBOX "Forward when your status is...",IDC_STATIC,3,51,147,61 + CONTROL "Offline",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,8,64,67,10 + CONTROL "Online",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,8,75,67,10 + CONTROL "Away",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, + 8,86,67,10 + CONTROL "NA",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8, + 97,67,10 + CONTROL "Occupied",IDC_CHECK5,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,78,64,67,10 + CONTROL "DND",IDC_CHECK6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, + 78,75,67,10 + CONTROL "Free for chat",IDC_CHECK7,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,78,86,67,10 + CONTROL "Invisible",IDC_CHECK8,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,78,97,67,10 + GROUPBOX "Forward messages to...",IDC_STATIC,158,3,147,45 + GROUPBOX "Template",IDC_STATIC,158,51,147,61 + EDITTEXT IDC_EDIT_TEMPLATE,163,62,138,27,ES_MULTILINE | + ES_AUTOVSCROLL | WS_VSCROLL + LTEXT "%u - user nick; %i - uin; %t - time; \r%d - date; %m - message", + IDC_STATIC,163,91,138,18 + GROUPBOX "Forwarding options",IDC_STATIC,3,115,302,69 + CONTROL "Split message (%m)",IDC_CHECK_SPLIT,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,8,125,136,10 + LTEXT "Send only first",IDC_STATIC,151,125,57,8,WS_TABSTOP + LTEXT "Max size of split part (chars)",IDC_STATIC,8,138,101,8, + WS_TABSTOP + CONTROL "Mark received messages as 'read'",IDC_CHECK_MARKREAD, + "Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | + WS_TABSTOP,8,156,134,21 + CONTROL "Save sent messages in recipient's history", + IDC_CHECK_SAVEHISTORY,"Button",BS_AUTOCHECKBOX | BS_TOP | + BS_MULTILINE | WS_TABSTOP,151,156,144,21 + EDITTEXT IDC_EDIT_MAXSIZE,114,134,22,14,ES_AUTOHSCROLL | + WS_DISABLED + EDITTEXT IDC_EDIT_SENDPARTS,211,122,16,14,ES_AUTOHSCROLL | + WS_DISABLED + LTEXT "split parts (0 = all)",IDC_STATIC,229,125,72,8, + WS_TABSTOP + LTEXT "Note: Max size - it's a size of %m parameter", + IDC_STATIC,151,138,146,17,WS_TABSTOP + LTEXT "Contact",IDC_STATIC,163,17,48,8 + LTEXT "Note: messages from this contact will not be forwarded", + IDC_STATIC,163,28,138,18 +END + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_SETTINGS, DIALOG + BEGIN + LEFTMARGIN, 3 + RIGHTMARGIN, 305 + TOPMARGIN, 3 + BOTTOMMARGIN, 184 + END +END +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/plugins/YARelay/src/Version.h b/plugins/YARelay/src/Version.h new file mode 100644 index 0000000000..91273cc872 --- /dev/null +++ b/plugins/YARelay/src/Version.h @@ -0,0 +1,14 @@ +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 1 +#define __RELEASE_NUM 0 +#define __BUILD_NUM 1 + +#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM + +#define __PLUGIN_NAME "yaRelay" +#define __FILENAME "yaRelay.dll" +#define __DESCRIPTION "Forwards messages to some contact when you are not available." +#define __AUTHOR "Anar Ibragimoff" +#define __AUTHOREMAIL "ai91@mail.ru" +#define __AUTHORWEB "http://miranda-ng.org/" +#define __COPYRIGHT "© 2005 Anar Ibragimoff" diff --git a/plugins/YARelay/src/main.cpp b/plugins/YARelay/src/main.cpp new file mode 100644 index 0000000000..3386c792da --- /dev/null +++ b/plugins/YARelay/src/main.cpp @@ -0,0 +1,267 @@ +/* +yaRelay.cpp + +Yet Another Relay plugin. v.0.0.0.3 +This plugin forwards all incoming messages to any contact. + +Features: + - Forwards all messages from any specified contact (or from all contacts) + - Works only if your status is equals to specified (of set of statuses) + - Could be specified any template for sent messages + - Original message could be split up (by size) + - Could be specified number of split parts to send + - Incoming message could be marked as 'read' (optional) + - Outgoing messages could be saved in history (optional) + +(c)2005 Anar Ibragimoff (ai91@mail.ru) + +*/ + +#include "stdafx.h" +#include "Version.h" + +#include "..\Utils\mir_buffer.h" + +CLIST_INTERFACE *pcli; +HINSTANCE hInst; +int hLangpack; + +HANDLE hForwardFrom, hForwardTo; +TCHAR tszForwardTemplate[MAXTEMPLATESIZE]; +int iSplit, iSplitMaxSize, iSendParts, iMarkRead, iSendAndHistory, iForwardOnStatus; + +LIST arMessageProcs(10, LIST::FTSortFunc(HandleKeySort)); + +PLUGININFOEX pluginInfoEx = { + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + // {01202E6A-C1B3-42E5-838A-3E497B31F38E} + {0x1202e6a, 0xc1b3, 0x42e5, {0x83, 0x8a, 0x3e, 0x49, 0x7b, 0x31, 0xf3, 0x8e}} +}; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst=hinstDLL; + return TRUE; +} + +/** +* Protocols àcknowledgement +*/ +int ProtoAck(WPARAM wparam,LPARAM lparam) +{ + ACKDATA *pAck = (ACKDATA *)lparam; + if (pAck->type != ACKTYPE_MESSAGE || pAck->result != ACKRESULT_SUCCESS) + return 0; + + MESSAGE_PROC* p = arMessageProcs.find((MESSAGE_PROC*)&pAck->hProcess); + if (p == NULL) + return 0; + + if (iSendAndHistory > 0){ + time_t ltime; + time(<ime); + + DBEVENTINFO dbei = { sizeof(dbei) }; + dbei.szModule = "yaRelay"; + dbei.timestamp = ltime; + dbei.flags = DBEF_SENT | DBEF_UTF; + dbei.eventType = EVENTTYPE_MESSAGE; + dbei.cbBlob = (DWORD)strlen(p->msgText) + 1; + dbei.pBlob = (PBYTE)p->msgText; + CallService(MS_DB_EVENT_ADD, (WPARAM)hForwardTo, (LPARAM)&dbei); + } + + mir_free(p->msgText); + arMessageProcs.remove(p); + mir_free(p); + return 0; +} + +/** +* New event was added into DB. +*/ +static int MessageEventAdded(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = (HANDLE)wParam, hDBEvent = (HANDLE)lParam; + + // is the message sender accepted for forwarding + if (hForwardFrom != 0 && hForwardFrom != hContact) + return 0; + + // is receiver specified + if (hForwardTo == 0) + return 0; + + // don't reply to receiver + if (hForwardTo == hContact) + return 0; + + // is current status acceptable + int statMask; + switch(CallService(MS_CLIST_GETSTATUSMODE, 0, 0)){ + case ID_STATUS_OFFLINE: statMask = STATUS_OFFLINE ;break; + case ID_STATUS_ONLINE: statMask = STATUS_ONLINE ;break; + case ID_STATUS_AWAY: statMask = STATUS_AWAY ;break; + case ID_STATUS_NA: statMask = STATUS_NA ;break; + case ID_STATUS_OCCUPIED: statMask = STATUS_OCCUPIED ;break; + case ID_STATUS_DND: statMask = STATUS_DND ;break; + case ID_STATUS_FREECHAT: statMask = STATUS_FREECHAT ;break; + case ID_STATUS_INVISIBLE:statMask = STATUS_INVISIBLE;break; + } + if ((iForwardOnStatus & statMask) == 0) + return 0; + + // receive message from DB + DBEVENTINFO dbei = { sizeof(dbei) }; + dbei.cbBlob = db_event_getBlobSize(hDBEvent); + if (dbei.cbBlob == -1) + return 0; + + dbei.pBlob = (unsigned char*)alloca(dbei.cbBlob); + db_event_get(hDBEvent, &dbei); + if (dbei.flags & DBEF_SENT || dbei.flags & DBEF_READ || (dbei.eventType != EVENTTYPE_MESSAGE)) + return 0; + + // get time and date + time_t tTime = dbei.timestamp; + tm *tm_time = gmtime(&tTime); + + // build a message + Buffer szUtfMsg; + mir_ptr szTemplate( mir_utf8encodeT(tszForwardTemplate)); + for (char *p = szTemplate; *p; p++) { + if (*p != '%') { + szUtfMsg.append(*p); + continue; + } + + TCHAR buf[100]; + switch(*++p) { + case 'u': + case 'U': + szUtfMsg.append( mir_ptr(mir_utf8encodeT(pcli->pfnGetContactDisplayName(hContact, 0)))); + break; + + case 'i': + case 'I': + { + // get sender's uin + CONTACTINFO ci = { sizeof(ci) }; + ci.dwFlag = CNF_UNIQUEID; + if (CallService(MS_CONTACT_GETCONTACTINFO, 0, (long)&ci) == 0){ + if (ci.type == CNFT_ASCIIZ) + _tcsncpy_s(buf, ci.pszVal, SIZEOF(buf)); + else if (ci.type == CNFT_BYTE) + mir_sntprintf(buf, SIZEOF(buf), _T("%u"), ci.bVal); + else if (ci.type == CNFT_WORD) + mir_sntprintf(buf, SIZEOF(buf), _T("%u"), ci.wVal); + else if (ci.type == CNFT_DWORD) + mir_sntprintf(buf, SIZEOF(buf), _T("%u"), ci.dVal); + } + else mir_sntprintf(buf, SIZEOF(buf), _T("%p"), hContact); + } + szUtfMsg.append( mir_ptr(mir_utf8encodeT(buf))); + break; + + case 't': + case 'T': + _tcsftime(buf, 10, _T("%H:%M"), tm_time); + szUtfMsg.append( mir_ptr(mir_utf8encodeT(buf))); + break; + + case 'd': + case 'D': + _tcsftime(buf, 12, _T("%d/%m/%Y"), tm_time); + szUtfMsg.append( mir_ptr(mir_utf8encodeT(buf))); + break; + + case 'm': + case 'M': + if (dbei.flags & DBEF_UTF) + szUtfMsg.append((char*)dbei.pBlob, dbei.cbBlob); + else + szUtfMsg.append( mir_ptr(mir_utf8encode((char*)dbei.pBlob))); + break; + + case '%': + szUtfMsg.append('%'); + break; + } + } + + int iPartCount = 1; + size_t cbMsgSize = szUtfMsg.len, cbPortion = cbMsgSize; + if (iSplit > 0) { + iPartCount = min(iSendParts, int((szUtfMsg.len + iSplitMaxSize) / iSplitMaxSize)); + cbPortion = iSplitMaxSize; + } + + char *szBuf = szUtfMsg.str; + for (int i=0; i < iPartCount; i++, szBuf += cbPortion) { + char *szMsgPart = (char*)mir_alloc(cbPortion+1); + strncpy(szMsgPart, szBuf, cbPortion); + szMsgPart[cbPortion] = 0; + + HANDLE hMsgProc = (HANDLE)CallContactService((HANDLE)hForwardTo, PSS_MESSAGE, PREF_UTF, (LPARAM)szMsgPart); + + MESSAGE_PROC* msgProc = (MESSAGE_PROC*)mir_alloc(sizeof(MESSAGE_PROC)); + msgProc->hProcess = hMsgProc; + msgProc->msgText = szMsgPart; + msgProc->retryCount = 0; + arMessageProcs.insert(msgProc); + } + + // mark message as 'read' + if (iMarkRead > 0) + CallService(MS_DB_EVENT_MARKREAD, wParam, lParam); + return 0; +} + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfoEx; +} + +extern "C" int __declspec(dllexport) Load() +{ + mir_getLP(&pluginInfoEx); + pcli = mir_getCLI(); + + // Load plugin options from DB + hForwardFrom = (HANDLE)db_get_dw(NULL, "yaRelay", "ForwardFrom", 0); + hForwardTo = (HANDLE)db_get_dw(NULL, "yaRelay", "ForwardTo", 0); + + iForwardOnStatus = db_get_dw(NULL, "yaRelay", "ForwardOnStatus", STATUS_OFFLINE | STATUS_AWAY | STATUS_NA); + + DBVARIANT dbv; + if (!db_get_ts(NULL, "yaRelay", "ForwardTemplate", &dbv)){ + _tcsncpy(tszForwardTemplate, dbv.ptszVal, SIZEOF(tszForwardTemplate)); + db_free(&dbv); + } + else _tcsncpy(tszForwardTemplate, _T("%u: %m"), MAXTEMPLATESIZE-1); + + iSplit = db_get_dw(NULL, "yaRelay", "Split", 0); + iSplitMaxSize = db_get_dw(NULL, "yaRelay", "SplitMaxSize", 100); + iSendParts = db_get_dw(NULL, "yaRelay", "SendParts", 0); + iMarkRead = db_get_dw(NULL, "yaRelay", "MarkRead", 0); + iSendAndHistory = db_get_dw(NULL, "yaRelay", "SendAndHistory", 1); + + // hook events + HookEvent(ME_DB_EVENT_ADDED, MessageEventAdded); + HookEvent(ME_OPT_INITIALISE, OptionsInit); + HookEvent(ME_PROTO_ACK, ProtoAck); + return 0; +} + +extern "C" int __declspec(dllexport) Unload(void) +{ + return 0; +} diff --git a/plugins/YARelay/src/options.cpp b/plugins/YARelay/src/options.cpp new file mode 100644 index 0000000000..dbfb88afde --- /dev/null +++ b/plugins/YARelay/src/options.cpp @@ -0,0 +1,201 @@ +/* +yaRelay.cpp + +Yet Another Relay plugin. v.0.0.0.3 +This plugin forwards all incoming messages to any contact. + +Features: + - Forwards all messages from any specified contact (or from all contacts) + - Works only if your status is equals to specified (of set of statuses) + - Could be specified any template for sent messages + - Original message could be split up (by size) + - Could be specified number of split parts to send + - Incoming message could be marked as 'read' (optional) + - Outgoing messages could be saved in history (optional) + +(c)2005 Anar Ibragimoff (ai91@mail.ru) + +*/ + +#include "stdafx.h" + +/** +* Enable/disable some controls (depends on selected check/radio buttons) +*/ +static void OptionsFrameEnableControls(HWND hwndDlg) +{ + HWND fromRadioAll = GetDlgItem(hwndDlg, IDC_RADIO_ALL); + HWND fromCombo = GetDlgItem(hwndDlg, IDC_COMBO_FROM); + HWND splitChk = GetDlgItem(hwndDlg, IDC_CHECK_SPLIT); + HWND splitMaxSize = GetDlgItem(hwndDlg, IDC_EDIT_MAXSIZE); + HWND splitSendParts = GetDlgItem(hwndDlg, IDC_EDIT_SENDPARTS); + + if ((SendMessage(fromRadioAll, BM_GETCHECK, 0, 0) & BST_CHECKED) == 0) + EnableWindow(fromCombo, TRUE); + else + EnableWindow(fromCombo, FALSE); + + if (SendMessage(splitChk, BM_GETCHECK, 0, 0) != BST_CHECKED){ + EnableWindow(splitMaxSize, FALSE); + EnableWindow(splitSendParts, FALSE); + } + else{ + EnableWindow(splitMaxSize, TRUE); + EnableWindow(splitSendParts, TRUE); + } +} + +/** +* Options panel function +*/ +static INT_PTR CALLBACK OptionsFrameProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact; + int idx; + switch (uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + + // fill FROM and TO comboboxes + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_RESETCONTENT, 0, 0); + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_RESETCONTENT, 0, 0); + + idx = SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_ADDSTRING, 0, (LPARAM) TranslateT("!EVERYONE!")); + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_SETITEMDATA, (WPARAM)idx, (LPARAM)0); + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_SETCURSEL, (WPARAM)idx, (LPARAM)0); + + idx = SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_ADDSTRING, 0, (LPARAM) TranslateT("!DON'T FORWARD!")); + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_SETITEMDATA, (WPARAM)idx, (LPARAM)0); + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_SETCURSEL, (WPARAM)idx, (LPARAM)0); + + for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + TCHAR *ptszNick = pcli->pfnGetContactDisplayName(hContact, 0); + if (ptszNick){ + idx = SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_ADDSTRING, 0, (LPARAM)ptszNick); + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_SETITEMDATA, (WPARAM)idx, (LPARAM)hContact); + + idx = SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_ADDSTRING, 0, (LPARAM)ptszNick); + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_SETITEMDATA, (WPARAM)idx, (LPARAM)hContact); + + if (hContact == hForwardTo) + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_SETCURSEL, (WPARAM)idx, (LPARAM)0); + if (hContact == hForwardFrom) + SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_SETCURSEL, (WPARAM)idx, (LPARAM)0); + } + } + + if (hForwardFrom == 0) + SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_ALL), BM_SETCHECK, BST_CHECKED, 0); + else + SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_CUSTOM), BM_SETCHECK, BST_CHECKED, 0); + + // forward on statuses + if (iForwardOnStatus & STATUS_OFFLINE ) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK1), BM_SETCHECK, BST_CHECKED, 0); + if (iForwardOnStatus & STATUS_ONLINE ) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK2), BM_SETCHECK, BST_CHECKED, 0); + if (iForwardOnStatus & STATUS_AWAY ) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK3), BM_SETCHECK, BST_CHECKED, 0); + if (iForwardOnStatus & STATUS_NA ) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK4), BM_SETCHECK, BST_CHECKED, 0); + if (iForwardOnStatus & STATUS_OCCUPIED ) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK5), BM_SETCHECK, BST_CHECKED, 0); + if (iForwardOnStatus & STATUS_DND ) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK6), BM_SETCHECK, BST_CHECKED, 0); + if (iForwardOnStatus & STATUS_FREECHAT ) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK7), BM_SETCHECK, BST_CHECKED, 0); + if (iForwardOnStatus & STATUS_INVISIBLE) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK8), BM_SETCHECK, BST_CHECKED, 0); + + // template + SetDlgItemText(hwndDlg, IDC_EDIT_TEMPLATE, tszForwardTemplate); + + // split + if (iSplit>0) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK_SPLIT), BM_SETCHECK, BST_CHECKED, 0); + + // max size + SetDlgItemInt(hwndDlg, IDC_EDIT_MAXSIZE, iSplitMaxSize, FALSE); + + // send parts num + SetDlgItemInt(hwndDlg, IDC_EDIT_SENDPARTS, iSendParts, FALSE); + + // mark 'read' + if (iMarkRead>0) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK_MARKREAD), BM_SETCHECK, BST_CHECKED, 0); + + // send and save + if (iSendAndHistory>0) SendMessage(GetDlgItem(hwndDlg, IDC_CHECK_SAVEHISTORY), BM_SETCHECK, BST_CHECKED, 0); + + // enable/disable controls + OptionsFrameEnableControls(hwndDlg); + return TRUE; + + case WM_COMMAND: + if (HIWORD(wParam) == BN_CLICKED){ + SendMessage(GetParent(hwndDlg),PSM_CHANGED,0,0); + switch(LOWORD(wParam)){ + case IDC_RADIO_ALL: + case IDC_RADIO_CUSTOM: + case IDC_CHECK_SPLIT: + OptionsFrameEnableControls(hwndDlg); + break; + } + } + break; + case WM_NOTIFY: + { + NMHDR* nmhdr = (NMHDR*)lParam; + switch (nmhdr->code) { + case PSN_APPLY: + case PSN_KILLACTIVE: + + // read all data from options frame + if (SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_ALL), BM_GETCHECK, 0, 0) == BST_CHECKED) + hForwardFrom = 0; + else + hForwardFrom = (HANDLE)SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_GETITEMDATA, SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_FROM), CB_GETCURSEL, 0, 0), 0); + + hForwardTo = (HANDLE)SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_GETITEMDATA, SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_TO), CB_GETCURSEL, 0, 0), 0); + iForwardOnStatus = 0; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK1), BM_GETCHECK, 0, 0) == BST_CHECKED) iForwardOnStatus |= STATUS_OFFLINE; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK2), BM_GETCHECK, 0, 0) == BST_CHECKED) iForwardOnStatus |= STATUS_ONLINE; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK3), BM_GETCHECK, 0, 0) == BST_CHECKED) iForwardOnStatus |= STATUS_AWAY; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK4), BM_GETCHECK, 0, 0) == BST_CHECKED) iForwardOnStatus |= STATUS_NA; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK5), BM_GETCHECK, 0, 0) == BST_CHECKED) iForwardOnStatus |= STATUS_OCCUPIED; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK6), BM_GETCHECK, 0, 0) == BST_CHECKED) iForwardOnStatus |= STATUS_DND; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK7), BM_GETCHECK, 0, 0) == BST_CHECKED) iForwardOnStatus |= STATUS_FREECHAT; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK8), BM_GETCHECK, 0, 0) == BST_CHECKED) iForwardOnStatus |= STATUS_INVISIBLE; + GetDlgItemText(hwndDlg, IDC_EDIT_TEMPLATE, tszForwardTemplate, MAXTEMPLATESIZE); + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK_SPLIT), BM_GETCHECK, 0, 0) == BST_CHECKED) iSplit = 1; else iSplit = 0; + iSplitMaxSize = GetDlgItemInt(hwndDlg, IDC_EDIT_MAXSIZE, NULL, FALSE); + iSendParts = GetDlgItemInt(hwndDlg, IDC_EDIT_SENDPARTS, NULL, FALSE); + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK_MARKREAD), BM_GETCHECK, 0, 0) == BST_CHECKED) iMarkRead = 1; else iMarkRead = 0; + if (SendMessage(GetDlgItem(hwndDlg, IDC_CHECK_SAVEHISTORY), BM_GETCHECK, 0, 0) == BST_CHECKED) iSendAndHistory = 1; else iSendAndHistory = 0; + if (iSplitMaxSize <= 0) + iSplitMaxSize = 1; + + // write to database + db_set_dw(NULL, "yaRelay", "ForwardFrom", (DWORD)hForwardFrom); + db_set_dw(NULL, "yaRelay", "ForwardTo", (DWORD)hForwardTo); + db_set_dw(NULL, "yaRelay", "ForwardOnStatus", iForwardOnStatus); + db_set_ts(NULL, "yaRelay", "ForwardTemplate", tszForwardTemplate); + db_set_dw(NULL, "yaRelay", "Split", iSplit); + db_set_dw(NULL, "yaRelay", "SplitMaxSize", iSplitMaxSize); + db_set_dw(NULL, "yaRelay", "SendParts", iSendParts); + db_set_dw(NULL, "yaRelay", "MarkRead", iMarkRead); + db_set_dw(NULL, "yaRelay", "SendAndHistory", iSendAndHistory); + return TRUE; + } + break; + } + } + return FALSE; +} + +/** +* Init options panel +*/ +int OptionsInit(WPARAM wParam, LPARAM lParam) +{ + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.hInstance = hInst; + odp.position = -1; + odp.pszGroup = LPGEN("Plugins"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_SETTINGS); + odp.pszTitle = LPGEN("yaRelay"); + odp.pfnDlgProc = OptionsFrameProc; + odp.flags = ODPF_BOLDGROUPS; + Options_AddPage(wParam, &odp); + return 0; +} diff --git a/plugins/YARelay/src/resource.h b/plugins/YARelay/src/resource.h new file mode 100644 index 0000000000..b9104ff1a1 --- /dev/null +++ b/plugins/YARelay/src/resource.h @@ -0,0 +1,36 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by frame.rc +// +#define IDD_FORMVIEW 101 +#define IDD_SETTINGS 101 +#define IDI_ICON_ARROW 101 +#define IDC_RADIO_ALL 1000 +#define IDC_RADIO_CUSTOM 1001 +#define IDC_COMBO_FROM 1002 +#define IDC_COMBO_TO 1003 +#define IDC_CHECK1 1004 +#define IDC_CHECK2 1005 +#define IDC_CHECK3 1006 +#define IDC_CHECK4 1007 +#define IDC_CHECK5 1008 +#define IDC_CHECK6 1009 +#define IDC_CHECK7 1010 +#define IDC_CHECK8 1011 +#define IDC_EDIT_TEMPLATE 1012 +#define IDC_CHECK_SPLIT 1013 +#define IDC_EDIT_MAXSIZE 1014 +#define IDC_EDIT_SENDPARTS 1015 +#define IDC_CHECK_SAVEHISTORY 1016 +#define IDC_CHECK_MARKREAD 1017 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1018 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/YARelay/src/stdafx.cpp b/plugins/YARelay/src/stdafx.cpp new file mode 100644 index 0000000000..1ddfafbbbd --- /dev/null +++ b/plugins/YARelay/src/stdafx.cpp @@ -0,0 +1,18 @@ +/* +Copyright (C) 2012-13 Miranda NG Project (http://miranda-ng.org) + +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 version 2 +of the License. + +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, see . +*/ + +#include "stdafx.h" \ No newline at end of file diff --git a/plugins/YARelay/src/stdafx.h b/plugins/YARelay/src/stdafx.h new file mode 100644 index 0000000000..fc4057b92f --- /dev/null +++ b/plugins/YARelay/src/stdafx.h @@ -0,0 +1,64 @@ +/* +yaRelay.cpp + +Yet Another Relay plugin. v.0.0.0.3 +This plugin forwards all incoming messages to any contact. + +Features: + - Forwards all messages from any specified contact (or from all contacts) + - Works only if your status is equals to specified (of set of statuses) + - Could be specified any template for sent messages + - Original message could be split up (by size) + - Could be specified number of split parts to send + - Incoming message could be marked as 'read' (optional) + - Outgoing messages could be saved in history (optional) + +(c)2005 Anar Ibragimoff (ai91@mail.ru) + +*/ + +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include +#include +#include "resource.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define STATUS_OFFLINE 0x1 +#define STATUS_ONLINE 0x2 +#define STATUS_AWAY 0x4 +#define STATUS_NA 0x8 +#define STATUS_OCCUPIED 0x10 +#define STATUS_DND 0x20 +#define STATUS_FREECHAT 0x40 +#define STATUS_INVISIBLE 0x80 + +#define MAXTEMPLATESIZE 1024 + +extern HINSTANCE hInst; + +extern HANDLE hForwardFrom, hForwardTo; +extern TCHAR tszForwardTemplate[MAXTEMPLATESIZE]; +extern int iSplit, iSplitMaxSize, iSendParts, iMarkRead, iSendAndHistory, iForwardOnStatus; + +struct MESSAGE_PROC +{ + HANDLE hProcess; + char *msgText; + int retryCount; +}; + +extern LIST arMessageProcs; + +int OptionsInit(WPARAM wParam, LPARAM lParam); -- cgit v1.2.3