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/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 ++++++++++++- 9 files changed, 75 insertions(+), 12 deletions(-) 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/Telegram/src') 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); -- cgit v1.2.3