summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-03-23 15:50:14 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-03-23 15:50:14 +0000
commit0b60fcc5772e91c80c52527ab6554ed25a05bab0 (patch)
tree5e93c63fce34c4b6e90559e7062da6313760af4c
parentc49db60246165780c37b86ba8a084d31c5cc5446 (diff)
Telegram: more initial code
git-svn-id: http://svn.miranda-ng.org/main/trunk@16528 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/Telegram/res/pubkey.txt8
-rw-r--r--protocols/Telegram/src/stdafx.h19
-rw-r--r--protocols/Telegram/src/t_callback.cpp27
-rw-r--r--protocols/Telegram/src/t_callback.h1
-rw-r--r--protocols/Telegram/src/t_messages.cpp6
-rw-r--r--protocols/Telegram/src/t_messages.h0
-rw-r--r--protocols/Telegram/src/t_network.cpp6
-rw-r--r--protocols/Telegram/src/t_network.h0
-rw-r--r--protocols/Telegram/src/t_proto.cpp15
-rw-r--r--protocols/Telegram/src/t_proto.h13
-rw-r--r--protocols/Telegram/telegram.vcxproj5
-rw-r--r--protocols/Telegram/telegram.vcxproj.filters63
12 files changed, 141 insertions, 22 deletions
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 <windows.h>
@@ -41,12 +38,24 @@
#include <m_assocmgr.h>
#include <m_file.h>
-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
--- /dev/null
+++ b/protocols/Telegram/src/t_messages.h
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
--- /dev/null
+++ b/protocols/Telegram/src/t_network.h
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 <http://www.gnu.org/licenses/>.
CTelegramProto::CTelegramProto(const char* protoName, const TCHAR* userName) : PROTO<CTelegramProto>(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> 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 @@
</ImportGroup>
<ItemDefinitionGroup>
<ClCompile>
+ <ExceptionHandling>Sync</ExceptionHandling>
<AdditionalIncludeDirectories>openssl\include;..\..\libs\libevent\include;..\..\libs\libevent\src\WIN32-Code\nmake;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>HAVE_CONFIG_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <DisableSpecificWarnings>4995;4996;4312;4091;4702;4204;4221;4201;4706;4127;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalDependencies>libeay32.lib;ssleay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -134,4 +136,7 @@
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Text Include="res\pubkey.txt" />
+ </ItemGroup>
</Project> \ 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 @@
</ClCompile>
<ClCompile Include="src\t_accounts.cpp" />
<ClCompile Include="src\t_proto.cpp" />
- <ClCompile Include="src\main.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="src\t_accounts.cpp" />
- <ClCompile Include="src\t_proto.cpp" />
<ClCompile Include="src\tgl\binlog.c">
<Filter>Source Files\tgl</Filter>
</ClCompile>
@@ -126,6 +121,30 @@
</ClCompile>
<ClCompile Include="src\t_accounts.cpp" />
<ClCompile Include="src\t_proto.cpp" />
+ <ClCompile Include="src\main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\t_accounts.cpp" />
+ <ClCompile Include="src\t_network.cpp" />
+ <ClCompile Include="src\t_proto.cpp" />
+ <ClCompile Include="src\main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\t_accounts.cpp" />
+ <ClCompile Include="src\t_network.cpp" />
+ <ClCompile Include="src\t_proto.cpp" />
+ <ClCompile Include="src\main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\t_accounts.cpp" />
+ <ClCompile Include="src\t_network.cpp" />
+ <ClCompile Include="src\t_proto.cpp" />
+ <ClCompile Include="src\main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\t_accounts.cpp" />
+ <ClCompile Include="src\t_network.cpp" />
+ <ClCompile Include="src\t_proto.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\stdafx.h">
@@ -133,11 +152,6 @@
</ClInclude>
<ClInclude Include="src\t_proto.h" />
<ClInclude Include="src\version.h" />
- <ClInclude Include="src\stdafx.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="src\t_proto.h" />
- <ClInclude Include="src\version.h" />
<ClInclude Include="src\tgl\auto.h">
<Filter>Header Files\tgl</Filter>
</ClInclude>
@@ -243,6 +257,30 @@
</ClInclude>
<ClInclude Include="src\t_proto.h" />
<ClInclude Include="src\version.h" />
+ <ClInclude Include="src\stdafx.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\t_network.h" />
+ <ClInclude Include="src\t_proto.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\stdafx.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\t_network.h" />
+ <ClInclude Include="src\t_proto.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\stdafx.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\t_network.h" />
+ <ClInclude Include="src\t_proto.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\stdafx.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\t_network.h" />
+ <ClInclude Include="src\t_proto.h" />
+ <ClInclude Include="src\version.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\*.rc">
@@ -260,4 +298,9 @@
<UniqueIdentifier>{0e669e36-12ed-48fb-ac6d-e317126f7380}</UniqueIdentifier>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <Text Include="res\pubkey.txt">
+ <Filter>Resource Files</Filter>
+ </Text>
+ </ItemGroup>
</Project> \ No newline at end of file