From fbcc2024d5adcf4ed4aedc3ee86d7e1ce4e756d5 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 29 Aug 2010 03:32:07 +0300 Subject: dos2unix --- init.cpp | 484 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 242 insertions(+), 242 deletions(-) (limited to 'init.cpp') diff --git a/init.cpp b/init.cpp index 85acbee..88af0d3 100644 --- a/init.cpp +++ b/init.cpp @@ -1,242 +1,242 @@ -// Copyright © 2010 sss -// -// 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 option) 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include "commonheaders.h" - -//global variables -bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bIsMiranda09 = false, bMetaContacts = false; -TCHAR *inopentag = NULL, *inclosetag = NULL, *outopentag = NULL, *outclosetag = NULL, *password = NULL; - -list Accounts; - -HINSTANCE hInst; -HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL, hSendKey = NULL, g_hCLIcon = NULL; -PLUGINLINK *pluginLink; -IconExtraColumn g_IEC = {0}; -static int OnModulesLoaded(WPARAM wParam,LPARAM lParam); -extern char *date(); -MM_INTERFACE mmi = {0}; -UTF8_INTERFACE utfi = {0}; -XML_API xi = {0}; -fstream debuglog; - - -#define MIID_GPG { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } } - -PLUGININFOEX pluginInfo={ - sizeof(PLUGININFOEX), - 0, - PLUGIN_MAKE_VERSION(0,0,0,4), - "new GPG encryption support plugin, used code from http://addons.miranda-im.org/details.php?action=viewfile&id=3485", - "sss", - "sss123next@list.ru", - "© 2010 sss", - "http://sss.chaoslab.ru/tracker/mim_plugs/", - 1, //unicode - 0, //doesn't replace anything built-in - MIID_GPG -}; - -BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) -{ - hInst=hinstDLL; - return TRUE; -} - - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) -{ - static char plugname[52]; - strcpy(plugname, szGPGModuleName" ["); - strcat(plugname, date()); - strcat(plugname, " "); - strcat(plugname, __TIME__); - strcat(plugname, "]"); - pluginInfo.shortName = plugname; - return &pluginInfo; -} - -static const MUUID interfaces[] = {MIID_GPG, MIID_LAST}; -extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) -{ - return interfaces; -} - -int LoadKey(WPARAM w, LPARAM l); -int ToggleEncryption(WPARAM w, LPARAM l); -int SendKey(WPARAM w, LPARAM l); - -void init_vars() -{ - bAppendTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bAppendTags", 0); - inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", _T("")); - inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("")); - outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("")); - outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("")); - bDebugLog = DBGetContactSettingByte(NULL, szGPGModuleName, "bDebugLog", 0); - bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", 1); - if(bDebugLog) - { - TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("C:\\gpglog.txt")); - debuglog.open(tmp, std::ios::app |std::ios::ate |std::ios::binary); -// mir_free(tmp); - } -} - -extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) -{ - pluginLink=link; - init_vars(); - HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); - mir_getMMI(&mmi); - mir_getUTFI(&utfi); - mir_getXI(&xi); //TODO: check if we have access to api - CreateServiceFunction("/LoadPubKey",LoadKey); - CreateServiceFunction("/ToggleEncryption",ToggleEncryption); - CreateServiceFunction("/SendKey",SendKey); - CLISTMENUITEM mi = {0}; - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFF; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Load GPG public key"; - mi.pszService="/LoadPubKey"; - hLoadPubKey = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi); - ZeroMemory(&mi,sizeof(mi)); - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFe; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Toggle GPG encryption"; - mi.pszService="/ToggleEncryption"; - hToggleEncryption = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi); - ZeroMemory(&mi,sizeof(mi)); - mi.cbSize=sizeof(mi); - mi.position=-0x7FFFFFFe; - mi.flags=0; - mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); - mi.pszName="Send public key"; - mi.pszService="/SendKey"; - hSendKey = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi); - return 0; -} - -int AddContact(WPARAM w, LPARAM l) -{ - CallService(MS_PROTO_ADDTOCONTACT,w,(LPARAM)szGPGModuleName); - return 0; -} - - -static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) -{ - - int GpgOptInit(WPARAM wParam,LPARAM lParam); - int OnPreBuildContactMenu(WPARAM w, LPARAM l); - int RecvMsgSvc(WPARAM w, LPARAM l); - int SendMsgSvc(WPARAM w, LPARAM l); - int HookSendMsg(WPARAM w, LPARAM l); -// int TestHook(WPARAM w, LPARAM l); - int GetJabberInterface(WPARAM w, LPARAM l); - int onWindowEvent(WPARAM wParam, LPARAM lParam); - int onIconPressed(WPARAM wParam, LPARAM lParam); - int onExtraImageListRebuilding(WPARAM, LPARAM); - int onExtraImageApplying(WPARAM wParam, LPARAM); - void InitIconLib(); - - void InitCheck(); - void FirstRun(); - FirstRun(); - InitCheck(); - InitIconLib(); - if(ServiceExists(MS_MSG_ADDICON)) - { - HICON IconLibGetIcon(const char* ident); - StatusIconData sid = {0}; - sid.cbSize = sizeof(sid); - sid.szModule = szGPGModuleName; - sid.flags = MBF_HIDDEN; - sid.dwId = 0x00000001; - sid.hIcon = IconLibGetIcon("secured"); - sid.szTooltip = Translate("GPG Turn off encryption"); - CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); - ZeroMemory(&sid, sizeof(sid)); - sid.cbSize = sizeof(sid); - sid.szModule = szGPGModuleName; - sid.flags = MBF_HIDDEN; - sid.dwId = 0x00000002; - sid.hIcon = IconLibGetIcon("unsecured"); - sid.szTooltip = Translate("GPG Turn on encryption"); - CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); - } - - - bIsMiranda09 = (DWORD)CallService(MS_SYSTEM_GETVERSION, 0, 0) >= 0x00090001?true:false; - bMetaContacts = ServiceExists(MS_MC_GETMETACONTACT); - - if(bJabberAPI && bIsMiranda09) - GetJabberInterface(0,0); - - HookEvent(ME_OPT_INITIALISE, GpgOptInit); - HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg); - if(bJabberAPI && bIsMiranda09) - HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface); - - HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu); - - HookEvent(ME_MSG_WINDOWEVENT, onWindowEvent); - HookEvent(ME_MSG_ICONPRESSED, onIconPressed); - - if(ServiceExists(MS_EXTRAICON_REGISTER)) - g_hCLIcon = ExtraIcon_Register(szGPGModuleName, Translate("GPG encryption status"), "secured", (MIRANDAHOOK)onExtraImageListRebuilding, (MIRANDAHOOK)onExtraImageApplying); - - - - PROTOCOLDESCRIPTOR pd = {0}; - pd.cbSize=sizeof(PROTOCOLDESCRIPTOR); - pd.szName=szGPGModuleName; - pd.type=PROTOTYPE_ENCRYPTION; - CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd); - - CreateProtoServiceFunction(szGPGModuleName,PSR_MESSAGE,RecvMsgSvc); - CreateProtoServiceFunction(szGPGModuleName,PSS_MESSAGE,SendMsgSvc); - CreateProtoServiceFunction(szGPGModuleName,PSR_MESSAGE"W",RecvMsgSvc); - CreateProtoServiceFunction(szGPGModuleName,PSS_MESSAGE"W",SendMsgSvc); - - for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) - if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName)) - CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName); - - HookEvent(ME_DB_CONTACT_ADDED,AddContact); - - - - return 0; -} - - -extern "C" int __declspec(dllexport) Unload(void) -{ - mir_free(inopentag); - mir_free(inclosetag); - mir_free(outopentag); - mir_free(outclosetag); - if(password) - delete [] password; - if(debuglog.is_open()) - debuglog.close(); - return 0; -} +// Copyright © 2010 sss +// +// 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 option) 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "commonheaders.h" + +//global variables +bool bAppendTags = false, bDebugLog = false, bJabberAPI = false, bIsMiranda09 = false, bMetaContacts = false; +TCHAR *inopentag = NULL, *inclosetag = NULL, *outopentag = NULL, *outclosetag = NULL, *password = NULL; + +list Accounts; + +HINSTANCE hInst; +HANDLE hLoadPubKey = NULL, hToggleEncryption = NULL, hOnPreBuildContactMenu = NULL, hSendKey = NULL, g_hCLIcon = NULL; +PLUGINLINK *pluginLink; +IconExtraColumn g_IEC = {0}; +static int OnModulesLoaded(WPARAM wParam,LPARAM lParam); +extern char *date(); +MM_INTERFACE mmi = {0}; +UTF8_INTERFACE utfi = {0}; +XML_API xi = {0}; +fstream debuglog; + + +#define MIID_GPG { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } } + +PLUGININFOEX pluginInfo={ + sizeof(PLUGININFOEX), + 0, + PLUGIN_MAKE_VERSION(0,0,0,4), + "new GPG encryption support plugin, used code from http://addons.miranda-im.org/details.php?action=viewfile&id=3485", + "sss", + "sss123next@list.ru", + "© 2010 sss", + "http://sss.chaoslab.ru/tracker/mim_plugs/", + 1, //unicode + 0, //doesn't replace anything built-in + MIID_GPG +}; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst=hinstDLL; + return TRUE; +} + + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + static char plugname[52]; + strcpy(plugname, szGPGModuleName" ["); + strcat(plugname, date()); + strcat(plugname, " "); + strcat(plugname, __TIME__); + strcat(plugname, "]"); + pluginInfo.shortName = plugname; + return &pluginInfo; +} + +static const MUUID interfaces[] = {MIID_GPG, MIID_LAST}; +extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) +{ + return interfaces; +} + +int LoadKey(WPARAM w, LPARAM l); +int ToggleEncryption(WPARAM w, LPARAM l); +int SendKey(WPARAM w, LPARAM l); + +void init_vars() +{ + bAppendTags = DBGetContactSettingByte(NULL, szGPGModuleName, "bAppendTags", 0); + inopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInOpenTag", _T("")); + inclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szInCloseTag", _T("")); + outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("")); + outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("")); + bDebugLog = DBGetContactSettingByte(NULL, szGPGModuleName, "bDebugLog", 0); + bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", 1); + if(bDebugLog) + { + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("C:\\gpglog.txt")); + debuglog.open(tmp, std::ios::app |std::ios::ate |std::ios::binary); +// mir_free(tmp); + } +} + +extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) +{ + pluginLink=link; + init_vars(); + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + mir_getMMI(&mmi); + mir_getUTFI(&utfi); + mir_getXI(&xi); //TODO: check if we have access to api + CreateServiceFunction("/LoadPubKey",LoadKey); + CreateServiceFunction("/ToggleEncryption",ToggleEncryption); + CreateServiceFunction("/SendKey",SendKey); + CLISTMENUITEM mi = {0}; + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFF; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Load GPG public key"; + mi.pszService="/LoadPubKey"; + hLoadPubKey = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFe; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Toggle GPG encryption"; + mi.pszService="/ToggleEncryption"; + hToggleEncryption = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFe; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName="Send public key"; + mi.pszService="/SendKey"; + hSendKey = (HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi); + return 0; +} + +int AddContact(WPARAM w, LPARAM l) +{ + CallService(MS_PROTO_ADDTOCONTACT,w,(LPARAM)szGPGModuleName); + return 0; +} + + +static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) +{ + + int GpgOptInit(WPARAM wParam,LPARAM lParam); + int OnPreBuildContactMenu(WPARAM w, LPARAM l); + int RecvMsgSvc(WPARAM w, LPARAM l); + int SendMsgSvc(WPARAM w, LPARAM l); + int HookSendMsg(WPARAM w, LPARAM l); +// int TestHook(WPARAM w, LPARAM l); + int GetJabberInterface(WPARAM w, LPARAM l); + int onWindowEvent(WPARAM wParam, LPARAM lParam); + int onIconPressed(WPARAM wParam, LPARAM lParam); + int onExtraImageListRebuilding(WPARAM, LPARAM); + int onExtraImageApplying(WPARAM wParam, LPARAM); + void InitIconLib(); + + void InitCheck(); + void FirstRun(); + FirstRun(); + InitCheck(); + InitIconLib(); + if(ServiceExists(MS_MSG_ADDICON)) + { + HICON IconLibGetIcon(const char* ident); + StatusIconData sid = {0}; + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.flags = MBF_HIDDEN; + sid.dwId = 0x00000001; + sid.hIcon = IconLibGetIcon("secured"); + sid.szTooltip = Translate("GPG Turn off encryption"); + CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); + ZeroMemory(&sid, sizeof(sid)); + sid.cbSize = sizeof(sid); + sid.szModule = szGPGModuleName; + sid.flags = MBF_HIDDEN; + sid.dwId = 0x00000002; + sid.hIcon = IconLibGetIcon("unsecured"); + sid.szTooltip = Translate("GPG Turn on encryption"); + CallService(MS_MSG_ADDICON, 0, (LPARAM)&sid); + } + + + bIsMiranda09 = (DWORD)CallService(MS_SYSTEM_GETVERSION, 0, 0) >= 0x00090001?true:false; + bMetaContacts = ServiceExists(MS_MC_GETMETACONTACT); + + if(bJabberAPI && bIsMiranda09) + GetJabberInterface(0,0); + + HookEvent(ME_OPT_INITIALISE, GpgOptInit); + HookEvent(ME_DB_EVENT_FILTER_ADD, HookSendMsg); + if(bJabberAPI && bIsMiranda09) + HookEvent(ME_PROTO_ACCLISTCHANGED, GetJabberInterface); + + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, OnPreBuildContactMenu); + + HookEvent(ME_MSG_WINDOWEVENT, onWindowEvent); + HookEvent(ME_MSG_ICONPRESSED, onIconPressed); + + if(ServiceExists(MS_EXTRAICON_REGISTER)) + g_hCLIcon = ExtraIcon_Register(szGPGModuleName, Translate("GPG encryption status"), "secured", (MIRANDAHOOK)onExtraImageListRebuilding, (MIRANDAHOOK)onExtraImageApplying); + + + + PROTOCOLDESCRIPTOR pd = {0}; + pd.cbSize=sizeof(PROTOCOLDESCRIPTOR); + pd.szName=szGPGModuleName; + pd.type=PROTOTYPE_ENCRYPTION; + CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd); + + CreateProtoServiceFunction(szGPGModuleName,PSR_MESSAGE,RecvMsgSvc); + CreateProtoServiceFunction(szGPGModuleName,PSS_MESSAGE,SendMsgSvc); + CreateProtoServiceFunction(szGPGModuleName,PSR_MESSAGE"W",RecvMsgSvc); + CreateProtoServiceFunction(szGPGModuleName,PSS_MESSAGE"W",SendMsgSvc); + + for (HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) + if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName)) + CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szGPGModuleName); + + HookEvent(ME_DB_CONTACT_ADDED,AddContact); + + + + return 0; +} + + +extern "C" int __declspec(dllexport) Unload(void) +{ + mir_free(inopentag); + mir_free(inclosetag); + mir_free(outopentag); + mir_free(outclosetag); + if(password) + delete [] password; + if(debuglog.is_open()) + debuglog.close(); + return 0; +} -- cgit v1.2.3