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