tdlight/td/telegram/AuthManager.hpp
levlam a72494d721 Support Terms of Service.
GitOrigin-RevId: 389c4ba590a4feb34ac6d801f9097291e87423d8
2018-06-07 21:42:17 +03:00

129 lines
3.3 KiB
C++

//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// 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/AuthManager.h"
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class T>
void SendCodeHelper::AuthenticationCodeInfo::store(T &storer) const {
using td::store;
store(type, storer);
store(length, storer);
store(pattern, storer);
}
template <class T>
void SendCodeHelper::AuthenticationCodeInfo::parse(T &parser) {
using td::parse;
parse(type, parser);
parse(length, parser);
parse(pattern, parser);
}
template <class T>
void SendCodeHelper::store(T &storer) const {
using td::store;
store(phone_number_, storer);
store(phone_registered_, storer);
store(phone_code_hash_, storer);
store(sent_code_info_, storer);
store(next_code_info_, storer);
store(next_code_timestamp_, storer);
}
template <class T>
void SendCodeHelper::parse(T &parser) {
using td::parse;
parse(phone_number_, parser);
parse(phone_registered_, parser);
parse(phone_code_hash_, parser);
parse(sent_code_info_, parser);
parse(next_code_info_, parser);
parse(next_code_timestamp_, parser);
}
template <class T>
void AuthManager::WaitPasswordState::store(T &storer) const {
using td::store;
store(current_salt_, storer);
store(new_salt_, storer);
store(hint_, storer);
store(has_recovery_, storer);
store(email_address_pattern_, storer);
}
template <class T>
void AuthManager::WaitPasswordState::parse(T &parser) {
using td::parse;
parse(current_salt_, parser);
parse(new_salt_, parser);
parse(hint_, parser);
parse(has_recovery_, parser);
parse(email_address_pattern_, parser);
}
template <class T>
void AuthManager::DbState::store(T &storer) const {
using td::store;
bool has_terms_of_service = !terms_of_service_.get_id().empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_terms_of_service);
END_STORE_FLAGS();
store(state_, storer);
store(api_id_, storer);
store(api_hash_, storer);
store(state_timestamp_, storer);
if (has_terms_of_service) {
store(terms_of_service_, storer);
}
if (state_ == State::WaitCode) {
store(send_code_helper_, storer);
} else if (state_ == State::WaitPassword) {
store(wait_password_state_, storer);
} else {
UNREACHABLE();
}
}
template <class T>
void AuthManager::DbState::parse(T &parser) {
using td::parse;
bool has_terms_of_service = false;
if (parser.version() >= static_cast<int32>(Version::AddTermsOfService)) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_terms_of_service);
END_PARSE_FLAGS();
}
parse(state_, parser);
parse(api_id_, parser);
parse(api_hash_, parser);
parse(state_timestamp_, parser);
if (has_terms_of_service) {
parse(terms_of_service_, parser);
}
if (state_ == State::WaitCode) {
parse(send_code_helper_, parser);
if (parser.version() < static_cast<int32>(Version::AddTermsOfService)) {
parser.set_error("Have no terms of service");
}
} else if (state_ == State::WaitPassword) {
parse(wait_password_state_, parser);
} else {
parser.set_error(PSTRING() << "Unexpected " << tag("state", static_cast<int32>(state_)));
}
}
} // namespace td