2018-12-31 20:04:05 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
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)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2019-07-09 04:13:10 +02:00
|
|
|
#include "td/telegram/net/Proxy.h"
|
2018-05-08 14:50:33 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
|
|
|
|
namespace td {
|
2018-04-24 18:21:47 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class MtprotoHeader {
|
|
|
|
public:
|
|
|
|
struct Options {
|
2021-11-11 15:39:09 +01:00
|
|
|
int32 api_id = -1;
|
2018-12-31 20:04:05 +01:00
|
|
|
string system_language_code;
|
|
|
|
string device_model;
|
|
|
|
string system_version;
|
|
|
|
string application_version;
|
2018-07-02 22:36:45 +02:00
|
|
|
string language_pack;
|
|
|
|
string language_code;
|
2019-07-15 20:37:45 +02:00
|
|
|
string parameters;
|
2021-11-01 20:32:49 +01:00
|
|
|
int32 tz_offset = 0;
|
2018-07-02 22:36:45 +02:00
|
|
|
bool is_emulator = false;
|
2018-05-08 14:50:33 +02:00
|
|
|
Proxy proxy;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2018-05-08 22:02:15 +02:00
|
|
|
explicit MtprotoHeader(const Options &options) : options_(options) {
|
|
|
|
gen_headers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_proxy(Proxy proxy) {
|
2021-10-19 17:11:16 +02:00
|
|
|
options_.proxy = std::move(proxy);
|
2018-05-08 22:02:15 +02:00
|
|
|
default_header_ = gen_header(options_, false);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-07-15 20:37:45 +02:00
|
|
|
bool set_parameters(string parameters) {
|
|
|
|
if (options_.parameters == parameters) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
options_.parameters = std::move(parameters);
|
2019-07-15 20:37:45 +02:00
|
|
|
default_header_ = gen_header(options_, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-02 22:36:45 +02:00
|
|
|
bool set_is_emulator(bool is_emulator) {
|
|
|
|
if (options_.is_emulator == is_emulator) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-22 13:09:58 +02:00
|
|
|
options_.is_emulator = is_emulator;
|
|
|
|
default_header_ = gen_header(options_, false);
|
2018-07-02 22:36:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set_language_pack(string language_pack) {
|
|
|
|
if (options_.language_pack == language_pack) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
options_.language_pack = std::move(language_pack);
|
|
|
|
default_header_ = gen_header(options_, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool set_language_code(string language_code) {
|
|
|
|
if (options_.language_code == language_code) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
options_.language_code = std::move(language_code);
|
|
|
|
default_header_ = gen_header(options_, false);
|
|
|
|
return true;
|
2018-05-22 13:09:58 +02:00
|
|
|
}
|
|
|
|
|
2021-11-01 20:42:33 +01:00
|
|
|
bool set_tz_offset(int32 tz_offset) {
|
|
|
|
if (options_.tz_offset == tz_offset) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
options_.tz_offset = tz_offset;
|
|
|
|
default_header_ = gen_header(options_, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
Slice get_default_header() const {
|
|
|
|
return default_header_;
|
|
|
|
}
|
|
|
|
Slice get_anonymous_header() const {
|
|
|
|
return anonymous_header_;
|
|
|
|
}
|
|
|
|
|
2019-05-21 17:48:35 +02:00
|
|
|
string get_system_language_code() const {
|
|
|
|
return options_.system_language_code;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
private:
|
2018-05-08 22:02:15 +02:00
|
|
|
Options options_;
|
2018-12-31 20:04:05 +01:00
|
|
|
string default_header_;
|
|
|
|
string anonymous_header_;
|
|
|
|
|
2018-05-08 22:02:15 +02:00
|
|
|
void gen_headers() {
|
|
|
|
default_header_ = gen_header(options_, false);
|
|
|
|
anonymous_header_ = gen_header(options_, true);
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
static string gen_header(const Options &options, bool is_anonymous);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|