2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-01-02 14:42:31 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/telegram/net/MtprotoHeader.h"
|
|
|
|
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class HeaderStorer {
|
|
|
|
public:
|
|
|
|
HeaderStorer(const MtprotoHeader::Options &options, bool is_anonymous)
|
|
|
|
: options(options), is_anonymous(is_anonymous) {
|
|
|
|
}
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
2018-05-21 06:18:39 +02:00
|
|
|
constexpr int32 LAYER = 80;
|
2018-01-09 22:04:18 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::store;
|
|
|
|
// invokeWithLayer#da9b0d0d {X:Type} layer:int query:!X = X;
|
|
|
|
store(static_cast<int32>(0xda9b0d0d), storer);
|
|
|
|
store(LAYER, storer);
|
2018-05-08 14:50:33 +02:00
|
|
|
// initConnection#785188b8 {X:Type} flags:# api_id:int device_model:string system_version:string app_version:string
|
|
|
|
// system_lang_code:string lang_pack:string lang_code:string proxy:flags.0?InputClientProxy query:!X = X;
|
|
|
|
store(static_cast<int32>(0x785188b8), storer);
|
|
|
|
int32 flags = 0;
|
2018-05-22 13:09:58 +02:00
|
|
|
bool have_proxy = !is_anonymous && options.proxy.type() == Proxy::Type::Mtproto;
|
|
|
|
if (have_proxy) {
|
2018-05-08 14:50:33 +02:00
|
|
|
flags |= 1 << 0;
|
|
|
|
}
|
2018-05-22 13:09:58 +02:00
|
|
|
if (options.is_emulator) {
|
|
|
|
flags |= 1 << 10;
|
|
|
|
}
|
2018-05-08 14:50:33 +02:00
|
|
|
store(flags, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
store(options.api_id, storer);
|
|
|
|
if (is_anonymous) {
|
|
|
|
store(Slice("n/a"), storer);
|
|
|
|
store(Slice("n/a"), storer);
|
|
|
|
} else {
|
|
|
|
store(options.device_model, storer);
|
|
|
|
store(options.system_version, storer);
|
|
|
|
}
|
|
|
|
store(options.application_version, storer);
|
|
|
|
store(options.system_language_code, storer);
|
|
|
|
store(string(), storer);
|
|
|
|
store(string(), storer);
|
2018-05-22 13:09:58 +02:00
|
|
|
if (have_proxy) {
|
2018-05-08 16:48:30 +02:00
|
|
|
// inputClientProxy#75588b3f address:string port:int = InputClientProxy;
|
|
|
|
store(static_cast<int32>(0x75588b3f), storer);
|
|
|
|
store(Slice(options.proxy.server()), storer);
|
|
|
|
store(options.proxy.port(), storer);
|
2018-05-08 14:50:33 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const MtprotoHeader::Options &options;
|
|
|
|
bool is_anonymous;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
string MtprotoHeader::gen_header(const MtprotoHeader::Options &options, bool is_anonymous) {
|
|
|
|
HeaderStorer storer(options, is_anonymous);
|
|
|
|
return serialize(storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|