From 0b60fcc5772e91c80c52527ab6554ed25a05bab0 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Wed, 23 Mar 2016 15:50:14 +0000 Subject: Telegram: more initial code git-svn-id: http://svn.miranda-ng.org/main/trunk@16528 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Telegram/res/pubkey.txt | 8 ++++ protocols/Telegram/src/stdafx.h | 19 ++++++--- protocols/Telegram/src/t_callback.cpp | 27 +++++++++++++ protocols/Telegram/src/t_callback.h | 1 + protocols/Telegram/src/t_messages.cpp | 6 +++ protocols/Telegram/src/t_messages.h | 0 protocols/Telegram/src/t_network.cpp | 6 +++ protocols/Telegram/src/t_network.h | 0 protocols/Telegram/src/t_proto.cpp | 15 ++++--- protocols/Telegram/src/t_proto.h | 13 +++++- protocols/Telegram/telegram.vcxproj | 5 +++ protocols/Telegram/telegram.vcxproj.filters | 63 ++++++++++++++++++++++++----- 12 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 protocols/Telegram/res/pubkey.txt create mode 100644 protocols/Telegram/src/t_callback.cpp create mode 100644 protocols/Telegram/src/t_callback.h create mode 100644 protocols/Telegram/src/t_messages.cpp create mode 100644 protocols/Telegram/src/t_messages.h create mode 100644 protocols/Telegram/src/t_network.cpp create mode 100644 protocols/Telegram/src/t_network.h (limited to 'protocols') diff --git a/protocols/Telegram/res/pubkey.txt b/protocols/Telegram/res/pubkey.txt new file mode 100644 index 0000000000..a574418604 --- /dev/null +++ b/protocols/Telegram/res/pubkey.txt @@ -0,0 +1,8 @@ +-----BEGIN RSA PUBLIC KEY----- +MIIBCgKCAQEAwVACPi9w23mF3tBkdZz+zwrzKOaaQdr01vAbU4E1pvkfj4sqDsm6 +lyDONS789sVoD/xCS9Y0hkkC3gtL1tSfTlgCMOOul9lcixlEKzwKENj1Yz/s7daS +an9tqw3bfUV/nqgbhGX81v/+7RFAEd+RwFnK7a+XYl9sluzHRyVVaTTveB2GazTw +Efzk2DWgkBluml8OREmvfraX3bkHZJTKX4EQSjBbbdJ2ZXIsRrYOXfaA+xayEGB+ +8hdlLmAjbCVfaigxX0CDqWeR1yFL9kwd9P0NsZRPsmoqVwMbMu7mStFai6aIhc3n +Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB +-----END RSA PUBLIC KEY----- \ No newline at end of file diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h index b6fce8c0ed..6c0c2016cb 100644 --- a/protocols/Telegram/src/stdafx.h +++ b/protocols/Telegram/src/stdafx.h @@ -1,9 +1,6 @@ #ifndef _STDAFX_H_ #define _STDAFX_H_ -//#pragma comment(lib, "$(SolutionDir)$(Configuration)\Obj\tgl\tgl.lib") - -#define TELEGRAM_APP_ID 17193 #include "..\..\..\miranda-private-keys\Telegram\api.h" #include @@ -41,12 +38,24 @@ #include #include -extern "C" { -#include "tgl\tgl.h" +extern "C" +{ + #include "tgl\tgl.h" + #include "tgl\tgl-net.h" + #include "tgl\tgl-timers.h" } +struct MirTLS : public tgl_state, public MZeroedObject +{ + struct CTelegramProto *m_proto; +}; + #include "version.h" #include "t_proto.h" +#include "t_network.h" +#include "t_callback.h" + +extern char g_szMirVer[]; #define MODULE "Telegram" diff --git a/protocols/Telegram/src/t_callback.cpp b/protocols/Telegram/src/t_callback.cpp new file mode 100644 index 0000000000..97d7eb0d1a --- /dev/null +++ b/protocols/Telegram/src/t_callback.cpp @@ -0,0 +1,27 @@ +#include "stdafx.h" + +static void update_message_handler(tgl_state *TLS, tgl_message *msg) +{ + ((MirTLS*)TLS)->m_proto->OnMessage(msg); +} + +static void logprintf(const char *fmt, ...) +{ + CMStringA str("[Telegram]: "); + va_list args; + va_start(fmt, args); + str.AppendFormatV(fmt, args); + va_end(args); + CallService(MS_NETLIB_LOG, 0, (LPARAM)str.GetString()); +} + +void CTelegramProto::InitCallbacks() +{ + tgl_update_callback cb = { 0 }; + cb.new_msg = update_message_handler; + cb.msg_receive = update_message_handler; + cb.logprintf = logprintf; + + tgl_set_callback(TLS, &cb); + +} \ No newline at end of file diff --git a/protocols/Telegram/src/t_callback.h b/protocols/Telegram/src/t_callback.h new file mode 100644 index 0000000000..d3f5a12faa --- /dev/null +++ b/protocols/Telegram/src/t_callback.h @@ -0,0 +1 @@ + diff --git a/protocols/Telegram/src/t_messages.cpp b/protocols/Telegram/src/t_messages.cpp new file mode 100644 index 0000000000..0ba8cfa0bb --- /dev/null +++ b/protocols/Telegram/src/t_messages.cpp @@ -0,0 +1,6 @@ +#include "stdafx.h" + +void CTelegramProto::OnMessage(tgl_message*) +{ + +} \ No newline at end of file diff --git a/protocols/Telegram/src/t_messages.h b/protocols/Telegram/src/t_messages.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/protocols/Telegram/src/t_network.cpp b/protocols/Telegram/src/t_network.cpp new file mode 100644 index 0000000000..3bc7b1089d --- /dev/null +++ b/protocols/Telegram/src/t_network.cpp @@ -0,0 +1,6 @@ +#include "stdafx.h" + +void CTelegramProto::InitNetwork() +{ + tgl_set_net_methods(TLS, &tgl_conn_methods); +} \ No newline at end of file diff --git a/protocols/Telegram/src/t_network.h b/protocols/Telegram/src/t_network.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/protocols/Telegram/src/t_proto.cpp b/protocols/Telegram/src/t_proto.cpp index d87895a0cd..fd495a7f5f 100644 --- a/protocols/Telegram/src/t_proto.cpp +++ b/protocols/Telegram/src/t_proto.cpp @@ -19,15 +19,18 @@ along with this program. If not, see . CTelegramProto::CTelegramProto(const char* protoName, const TCHAR* userName) : PROTO(protoName, userName) { - tgl_register_app_id(&tgl, TELEGRAM_APP_ID, TELEGRAM_API_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); + TLS = new MirTLS; - tgl_update_callback tgucb = {}; + InitNetwork(); + tgl_set_timer_methods(TLS, &tgl_libevent_timers); + tgl_set_rsa_key(TLS, TELEGRAM_PUBLIC_KEY); + tgl_register_app_id(TLS, TELEGRAM_API_ID, TELEGRAM_API_HASH); + tgl_set_app_version(TLS, g_szMirVer); + + + tgl_init(TLS); } CTelegramProto::~CTelegramProto() diff --git a/protocols/Telegram/src/t_proto.h b/protocols/Telegram/src/t_proto.h index 4b486cafbe..927718340e 100644 --- a/protocols/Telegram/src/t_proto.h +++ b/protocols/Telegram/src/t_proto.h @@ -63,6 +63,9 @@ public: void InitPopups(); void UninitPopups(); + void InitNetwork(); + void InitCallbacks(); + // languages static void InitLanguages(); @@ -77,11 +80,19 @@ public: static INT_PTR EventGetIcon(WPARAM wParam, LPARAM lParam); static INT_PTR GetEventText(WPARAM, LPARAM lParam); + + + void OnMessage(tgl_message*); + + + + private: - tgl_state tgl; + MirTLS *TLS; static mir_cs accountsLock; + //---Accounts static LIST CTelegramProto::Accounts; static int CompareAccounts(const CTelegramProto *p1, const CTelegramProto *p2); diff --git a/protocols/Telegram/telegram.vcxproj b/protocols/Telegram/telegram.vcxproj index 8a7797cad4..9fce349772 100644 --- a/protocols/Telegram/telegram.vcxproj +++ b/protocols/Telegram/telegram.vcxproj @@ -27,8 +27,10 @@ + Sync openssl\include;..\..\libs\libevent\include;..\..\libs\libevent\src\WIN32-Code\nmake;%(AdditionalIncludeDirectories) HAVE_CONFIG_H;%(PreprocessorDefinitions) + 4995;4996;4312;4091;4702;4204;4221;4201;4706;4127;%(DisableSpecificWarnings) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @@ -134,4 +136,7 @@ false + + + \ No newline at end of file diff --git a/protocols/Telegram/telegram.vcxproj.filters b/protocols/Telegram/telegram.vcxproj.filters index ee9c1b1e32..75d1ca31df 100644 --- a/protocols/Telegram/telegram.vcxproj.filters +++ b/protocols/Telegram/telegram.vcxproj.filters @@ -10,11 +10,6 @@ - - Source Files - - - Source Files\tgl @@ -126,13 +121,32 @@ + + Source Files + + + + + + Source Files + + + + + + Source Files + + + + + + Source Files + + + + - - Header Files - - - Header Files @@ -243,6 +257,30 @@ + + Header Files + + + + + + Header Files + + + + + + Header Files + + + + + + Header Files + + + + @@ -260,4 +298,9 @@ {0e669e36-12ed-48fb-ac6d-e317126f7380} + + + Resource Files + + \ No newline at end of file -- cgit v1.2.3