summaryrefslogtreecommitdiff
path: root/protocols/Telegram
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-03-07 15:50:51 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-03-07 15:50:51 +0000
commita704113576cb1f75463c26140e3aad20487ded33 (patch)
tree0da381cd29e85472bb966b3c4d3c8dd2e36dedf2 /protocols/Telegram
parenta4b5a6fb054a30b840aadc8ecbba1cb3afedb8db (diff)
Telegram: initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@16441 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Telegram')
-rw-r--r--protocols/Telegram/res/version.rc38
-rw-r--r--protocols/Telegram/src/main.cpp86
-rw-r--r--protocols/Telegram/src/stdafx.cxx1
-rw-r--r--protocols/Telegram/src/stdafx.h56
-rw-r--r--protocols/Telegram/src/t_accounts.cpp56
-rw-r--r--protocols/Telegram/src/t_proto.cpp101
-rw-r--r--protocols/Telegram/src/t_proto.h103
-rw-r--r--protocols/Telegram/src/version.h14
-rw-r--r--protocols/Telegram/telegram.vcxproj28
-rw-r--r--protocols/Telegram/telegram.vcxproj.filters4
10 files changed, 487 insertions, 0 deletions
diff --git a/protocols/Telegram/res/version.rc b/protocols/Telegram/res/version.rc
new file mode 100644
index 0000000000..5bfbab4754
--- /dev/null
+++ b/protocols/Telegram/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/protocols/Telegram/src/main.cpp b/protocols/Telegram/src/main.cpp
new file mode 100644
index 0000000000..ca4ccacb51
--- /dev/null
+++ b/protocols/Telegram/src/main.cpp
@@ -0,0 +1,86 @@
+/*
+Copyright (c) 2015 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+int hLangpack;
+HINSTANCE g_hInstance;
+CLIST_INTERFACE *pcli;
+char g_szMirVer[100];
+
+PLUGININFOEX pluginInfo =
+{
+ sizeof(PLUGININFOEX),
+ __PLUGIN_NAME,
+ PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
+ __DESCRIPTION,
+ __AUTHOR,
+ __AUTHOREMAIL,
+ __COPYRIGHT,
+ __AUTHORWEB,
+ UNICODE_AWARE,
+ // {43F56D31-CB19-471A-8A8A-91FD6E9A3741}
+ { 0x43f56d31, 0xcb19, 0x471a, { 0x8a, 0x8a, 0x91, 0xfd, 0x6e, 0x9a, 0x37, 0x41 } }
+
+};
+
+DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
+{
+ g_hInstance = hInstance;
+
+ return TRUE;
+}
+
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
+{
+ return &pluginInfo;
+}
+
+extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST };
+
+extern "C" int __declspec(dllexport) Load(void)
+{
+ mir_getLP(&pluginInfo);
+ mir_getCLI();
+
+ CallService(MS_SYSTEM_GETVERSIONTEXT, sizeof(g_szMirVer), LPARAM(g_szMirVer));
+
+ PROTOCOLDESCRIPTOR pd = { 0 };
+ pd.cbSize = sizeof(pd);
+ pd.szName = MODULE;
+ pd.type = PROTOTYPE_PROTOCOL;
+ pd.fnInit = (pfnInitProto)CTelegramProto::InitAccount;
+ pd.fnUninit = (pfnUninitProto)CTelegramProto::UninitAccount;
+ Proto_RegisterModule(&pd);
+
+
+ HookEvent(ME_SYSTEM_MODULESLOADED, &CTelegramProto::OnModulesLoaded);
+
+ return 0;
+}
+
+extern "C" int __declspec(dllexport) Unload(void)
+{
+
+ return 0;
+}
+
+
+int CTelegramProto::OnModulesLoaded(WPARAM, LPARAM)
+{
+ return 0;
+} \ No newline at end of file
diff --git a/protocols/Telegram/src/stdafx.cxx b/protocols/Telegram/src/stdafx.cxx
new file mode 100644
index 0000000000..1577c4e3bc
--- /dev/null
+++ b/protocols/Telegram/src/stdafx.cxx
@@ -0,0 +1 @@
+#include "stdafx.h" \ No newline at end of file
diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h
new file mode 100644
index 0000000000..17bbe157ab
--- /dev/null
+++ b/protocols/Telegram/src/stdafx.h
@@ -0,0 +1,56 @@
+#ifndef _STDAFX_H_
+#define _STDAFX_H_
+
+#pragma comment(lib, "src/tgl.lib")
+
+#define TELEGRAM_APP_ID 17193
+#include "..\..\..\miranda-private-keys\Telegram\secret_key.h"
+
+#include <windows.h>
+#include <time.h>
+#include <string>
+#include <vector>
+#include <regex>
+#include <map>
+
+#include <newpluginapi.h>
+
+#include <m_protoint.h>
+#include <m_protosvc.h>
+
+#include <m_database.h>
+#include <m_langpack.h>
+#include <m_clist.h>
+#include <m_options.h>
+#include <m_netlib.h>
+#include <m_popup.h>
+#include <m_icolib.h>
+#include <m_userinfo.h>
+#include <m_addcontact.h>
+#include <m_message.h>
+#include <m_avatars.h>
+#include <m_skin.h>
+#include <m_chat.h>
+#include <m_genmenu.h>
+#include <m_clc.h>
+#include <m_string.h>
+#include <m_json.h>
+#include <m_gui.h>
+#include <m_imgsrvc.h>
+#include <m_xml.h>
+#include <m_assocmgr.h>
+#include <m_file.h>
+
+#include "tgl/tgl.h"
+
+#include "version.h"
+#include "t_proto.h"
+
+#define MODULE "Telegram"
+
+struct CTelegramProto;
+
+
+
+
+#endif //_STDAFX_H_ \ No newline at end of file
diff --git a/protocols/Telegram/src/t_accounts.cpp b/protocols/Telegram/src/t_accounts.cpp
new file mode 100644
index 0000000000..53b95ad135
--- /dev/null
+++ b/protocols/Telegram/src/t_accounts.cpp
@@ -0,0 +1,56 @@
+/*
+Copyright (c) 2015 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+LIST<CTelegramProto> CTelegramProto::Accounts(1, CTelegramProto::CompareAccounts);
+mir_cs CTelegramProto::accountsLock;
+
+int CTelegramProto::CompareAccounts(const CTelegramProto *p1, const CTelegramProto *p2)
+{
+ return mir_tstrcmp(p1->m_tszUserName, p2->m_tszUserName);
+}
+
+CTelegramProto* CTelegramProto::InitAccount(const char *protoName, const wchar_t *userName)
+{
+ mir_cslock lck(accountsLock);
+ CTelegramProto *proto = new CTelegramProto(protoName, userName);
+ Accounts.insert(proto);
+ return proto;
+}
+
+int CTelegramProto::UninitAccount(CTelegramProto *proto)
+{
+ mir_cslock lck(accountsLock);
+ Accounts.remove(proto);
+ delete proto;
+ return 0;
+}
+
+CTelegramProto* CTelegramProto::GetContactAccount(MCONTACT hContact)
+{
+ mir_cslock lck(accountsLock);
+ for (int i = 0; i < Accounts.getCount(); i++)
+ if (mir_strcmpi(GetContactProto(hContact), Accounts[i]->m_szModuleName) == 0)
+ return Accounts[i];
+ return NULL;
+}
+
+/*INT_PTR CTelegramProto::OnAccountManagerInit(WPARAM, LPARAM lParam)
+{
+// return (INT_PTR)(CTelegramOptionsMain::CreateAccountManagerPage(this, (HWND)lParam))->GetHwnd();
+}*/ \ No newline at end of file
diff --git a/protocols/Telegram/src/t_proto.cpp b/protocols/Telegram/src/t_proto.cpp
new file mode 100644
index 0000000000..49aebc1045
--- /dev/null
+++ b/protocols/Telegram/src/t_proto.cpp
@@ -0,0 +1,101 @@
+/*
+Copyright (c) 2015 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+CTelegramProto::CTelegramProto(const char* protoName, const TCHAR* userName) : PROTO<CTelegramProto>(protoName, userName)
+{
+ tgl_register_app_id(&tgl, TELEGRAM_APP_ID, TELEGRAM_APP_HASH);
+ char version[64];
+ mir_snprintf(version, "Miranda Telegram %d.%d.%d.%d", __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM);
+ tgl_set_app_version(&tgl, version);
+ tgl_init(&tgl);
+
+ tgl_update_callback tgucb = {};
+
+
+}
+
+CTelegramProto::~CTelegramProto()
+{
+}
+
+DWORD_PTR CTelegramProto::GetCaps(int type, MCONTACT)
+{
+ return 0;
+}
+
+MCONTACT CTelegramProto::AddToList(int, PROTOSEARCHRESULT *psr)
+{
+ return 0;
+}
+
+MCONTACT CTelegramProto::AddToListByEvent(int, int, MEVENT hDbEvent)
+{
+ return 0;
+}
+
+int CTelegramProto::Authorize(MEVENT hDbEvent)
+{
+ return 0;
+}
+
+int CTelegramProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
+{
+ return 0;
+
+}
+
+int CTelegramProto::AuthRecv(MCONTACT, PROTORECVEVENT* pre)
+{
+ return 0;
+}
+
+int CTelegramProto::AuthRequest(MCONTACT hContact, const TCHAR *szMessage)
+{
+ return 0;
+}
+
+int CTelegramProto::GetInfo(MCONTACT hContact, int)
+{
+ return 0;
+}
+
+int CTelegramProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
+{
+ return 0;
+}
+
+int CTelegramProto::SetStatus(int iNewStatus)
+{
+ return 0;
+}
+
+int CTelegramProto::UserIsTyping(MCONTACT hContact, int type)
+{
+ return 0;
+}
+
+int CTelegramProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam)
+{
+ return 0;
+}
+
+int CTelegramProto::OnPreShutdown(WPARAM, LPARAM)
+{
+ return 0;
+}
diff --git a/protocols/Telegram/src/t_proto.h b/protocols/Telegram/src/t_proto.h
new file mode 100644
index 0000000000..4b486cafbe
--- /dev/null
+++ b/protocols/Telegram/src/t_proto.h
@@ -0,0 +1,103 @@
+/*
+Copyright (c) 2015 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _T_PROTO_H_
+#define _T_PROTO_H_
+
+
+struct CTelegramProto : public PROTO < CTelegramProto >
+{
+
+public:
+
+ //////////////////////////////////////////////////////////////////////////////////////
+ //Ctors
+
+ CTelegramProto(const char *protoName, const wchar_t *userName);
+ ~CTelegramProto();
+
+ //////////////////////////////////////////////////////////////////////////////////////
+ // Virtual functions
+
+ virtual MCONTACT __cdecl AddToList(int flags, PROTOSEARCHRESULT* psr);
+ virtual MCONTACT __cdecl AddToListByEvent(int flags, int iContact, MEVENT hDbEvent);
+ virtual int __cdecl AuthRequest(MCONTACT hContact, const TCHAR* szMessage);
+ virtual int __cdecl Authorize(MEVENT hDbEvent);
+ virtual int __cdecl AuthDeny(MEVENT hDbEvent, const TCHAR* szReason);
+ virtual int __cdecl AuthRecv(MCONTACT hContact, PROTORECVEVENT*);
+ virtual DWORD_PTR __cdecl GetCaps(int type, MCONTACT hContact = NULL);
+ virtual int __cdecl GetInfo(MCONTACT hContact, int infoType);
+ virtual HANDLE __cdecl SearchBasic(const TCHAR* id);
+ virtual int __cdecl SendMsg(MCONTACT hContact, int flags, const char* msg);
+ virtual int __cdecl SetStatus(int iNewStatus);
+ virtual int __cdecl UserIsTyping(MCONTACT hContact, int type);
+ virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam);
+
+ // accounts
+ static CTelegramProto* InitAccount(const char *protoName, const TCHAR *userName);
+ static int UninitAccount(CTelegramProto *proto);
+
+ // icons
+ static void InitIcons();
+ static void UninitIcons();
+
+ // menus
+ static void InitMenus();
+ static void UninitMenus();
+
+ //popups
+ void InitPopups();
+ void UninitPopups();
+
+ // languages
+ static void InitLanguages();
+
+ // events
+ static int OnModulesLoaded(WPARAM, LPARAM);
+ int __cdecl OnDbEventRead(WPARAM, LPARAM);
+ int __cdecl OnPreShutdown(WPARAM, LPARAM);
+ //search
+ void __cdecl SearchBasicThread(void* id);
+
+ ////////////////////////////////////////////
+ static INT_PTR EventGetIcon(WPARAM wParam, LPARAM lParam);
+ static INT_PTR GetEventText(WPARAM, LPARAM lParam);
+
+private:
+
+ tgl_state tgl;
+ static mir_cs accountsLock;
+
+ //---Accounts
+ static LIST<CTelegramProto> CTelegramProto::Accounts;
+ static int CompareAccounts(const CTelegramProto *p1, const CTelegramProto *p2);
+ static CTelegramProto* GetContactAccount(MCONTACT hContact);
+
+ __forceinline bool IsOnline() const
+ { return (m_iStatus > ID_STATUS_OFFLINE);
+ }
+
+ template<INT_PTR(__cdecl CTelegramProto::*Service)(WPARAM, LPARAM)>
+ static INT_PTR __cdecl GlobalService(WPARAM wParam, LPARAM lParam)
+ {
+ CTelegramProto *proto = GetContactAccount((MCONTACT)wParam);
+ return proto ? (proto->*Service)(wParam, lParam) : 0;
+ }
+
+};
+
+#endif //_Telegram_PROTO_H_ \ No newline at end of file
diff --git a/protocols/Telegram/src/version.h b/protocols/Telegram/src/version.h
new file mode 100644
index 0000000000..adccbd33c6
--- /dev/null
+++ b/protocols/Telegram/src/version.h
@@ -0,0 +1,14 @@
+#define __MAJOR_VERSION 0
+#define __MINOR_VERSION 1
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 0
+
+#include <stdver.h>
+
+#define __PLUGIN_NAME "Telegram protocol"
+#define __FILENAME "Telegram.dll"
+#define __DESCRIPTION ""
+#define __AUTHOR "Miranda NG Team"
+#define __AUTHOREMAIL ""
+#define __AUTHORWEB "http://miranda-ng.org/p/Telegram/"
+#define __COPYRIGHT "© 2015 Miranda NG Team"
diff --git a/protocols/Telegram/telegram.vcxproj b/protocols/Telegram/telegram.vcxproj
new file mode 100644
index 0000000000..ba6ffd0ad7
--- /dev/null
+++ b/protocols/Telegram/telegram.vcxproj
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{8f81f4b8-2b96-447b-8ab8-f203aac6c4eb}</ProjectGuid>
+ <ProjectName>Telegram</ProjectName>
+ </PropertyGroup>
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/protocols/Telegram/telegram.vcxproj.filters b/protocols/Telegram/telegram.vcxproj.filters
new file mode 100644
index 0000000000..de5ad9f66c
--- /dev/null
+++ b/protocols/Telegram/telegram.vcxproj.filters
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(ProjectDir)..\..\build\vc.common\common.filters" />
+</Project> \ No newline at end of file