mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Use getters in MTP classes.
This commit is contained in:
@@ -199,14 +199,14 @@ void ConfigLoader::specialConfigLoaded(const MTPConfig &result) {
|
||||
Expects(result.type() == mtpc_config);
|
||||
|
||||
auto &data = result.c_config();
|
||||
if (data.vdc_options.v.empty()) {
|
||||
if (data.vdc_options().v.empty()) {
|
||||
LOG(("MTP Error: config with empty dc_options received!"));
|
||||
return;
|
||||
}
|
||||
|
||||
// We use special config only for dc options.
|
||||
// For everything else we wait for normal config from main dc.
|
||||
_instance->dcOptions()->setFromList(data.vdc_options);
|
||||
_instance->dcOptions()->setFromList(data.vdc_options());
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@@ -1681,7 +1681,7 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
case mtpc_msgs_ack: {
|
||||
MTPMsgsAck msg;
|
||||
msg.read(from, end);
|
||||
auto &ids = msg.c_msgs_ack().vmsg_ids.v;
|
||||
auto &ids = msg.c_msgs_ack().vmsg_ids().v;
|
||||
uint32 idsCount = ids.size();
|
||||
|
||||
DEBUG_LOG(("Message Info: acks received, ids: %1").arg(LogIdsVector(ids)));
|
||||
@@ -1701,13 +1701,13 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
MTPBadMsgNotification msg;
|
||||
msg.read(from, end);
|
||||
const auto &data(msg.c_bad_msg_notification());
|
||||
LOG(("Message Info: bad message notification received (error_code %3) for msg_id = %1, seq_no = %2").arg(data.vbad_msg_id.v).arg(data.vbad_msg_seqno.v).arg(data.verror_code.v));
|
||||
LOG(("Message Info: bad message notification received (error_code %3) for msg_id = %1, seq_no = %2").arg(data.vbad_msg_id().v).arg(data.vbad_msg_seqno().v).arg(data.verror_code().v));
|
||||
|
||||
mtpMsgId resendId = data.vbad_msg_id.v;
|
||||
mtpMsgId resendId = data.vbad_msg_id().v;
|
||||
if (resendId == _pingMsgId) {
|
||||
_pingId = 0;
|
||||
}
|
||||
int32 errorCode = data.verror_code.v;
|
||||
int32 errorCode = data.verror_code().v;
|
||||
if (false
|
||||
|| errorCode == 16
|
||||
|| errorCode == 17
|
||||
@@ -1768,11 +1768,11 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
unixtimeSet(serverTime, true);
|
||||
badTime = false;
|
||||
}
|
||||
LOG(("Message Info: bad message notification received, msgId %1, error_code %2").arg(data.vbad_msg_id.v).arg(errorCode));
|
||||
LOG(("Message Info: bad message notification received, msgId %1, error_code %2").arg(data.vbad_msg_id().v).arg(errorCode));
|
||||
return HandleResult::ResetSession;
|
||||
}
|
||||
} else { // fatal (except 48, but it must not get here)
|
||||
const auto badMsgId = mtpMsgId(data.vbad_msg_id.v);
|
||||
const auto badMsgId = mtpMsgId(data.vbad_msg_id().v);
|
||||
const auto requestId = wasSent(resendId);
|
||||
if (requestId) {
|
||||
LOG(("Message Error: "
|
||||
@@ -1798,9 +1798,9 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
MTPBadMsgNotification msg;
|
||||
msg.read(from, end);
|
||||
const auto &data(msg.c_bad_server_salt());
|
||||
DEBUG_LOG(("Message Info: bad server salt received (error_code %4) for msg_id = %1, seq_no = %2, new salt: %3").arg(data.vbad_msg_id.v).arg(data.vbad_msg_seqno.v).arg(data.vnew_server_salt.v).arg(data.verror_code.v));
|
||||
DEBUG_LOG(("Message Info: bad server salt received (error_code %4) for msg_id = %1, seq_no = %2, new salt: %3").arg(data.vbad_msg_id().v).arg(data.vbad_msg_seqno().v).arg(data.vnew_server_salt().v).arg(data.verror_code().v));
|
||||
|
||||
mtpMsgId resendId = data.vbad_msg_id.v;
|
||||
mtpMsgId resendId = data.vbad_msg_id().v;
|
||||
if (resendId == _pingMsgId) {
|
||||
_pingId = 0;
|
||||
} else if (!wasSent(resendId)) {
|
||||
@@ -1808,7 +1808,7 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
return (badTime ? HandleResult::Ignored : HandleResult::Success);
|
||||
}
|
||||
|
||||
uint64 serverSalt = data.vnew_server_salt.v;
|
||||
uint64 serverSalt = data.vnew_server_salt().v;
|
||||
sessionData->setSalt(serverSalt);
|
||||
unixtimeSet(serverTime);
|
||||
|
||||
@@ -1832,7 +1832,7 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
}
|
||||
MTPMsgsStateReq msg;
|
||||
msg.read(from, end);
|
||||
auto &ids = msg.c_msgs_state_req().vmsg_ids.v;
|
||||
auto &ids = msg.c_msgs_state_req().vmsg_ids().v;
|
||||
auto idsCount = ids.size();
|
||||
DEBUG_LOG(("Message Info: msgs_state_req received, ids: %1").arg(LogIdsVector(ids)));
|
||||
if (!idsCount) return HandleResult::Success;
|
||||
@@ -1882,8 +1882,8 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
msg.read(from, end);
|
||||
auto &data = msg.c_msgs_state_info();
|
||||
|
||||
auto reqMsgId = data.vreq_msg_id.v;
|
||||
auto &states = data.vinfo.v;
|
||||
auto reqMsgId = data.vreq_msg_id().v;
|
||||
auto &states = data.vinfo().v;
|
||||
|
||||
DEBUG_LOG(("Message Info: msg state received, msgId %1, reqMsgId: %2, HEX states %3").arg(msgId).arg(reqMsgId).arg(Logs::mb(states.data(), states.length()).str()));
|
||||
SecureRequest requestBuffer;
|
||||
@@ -1917,11 +1917,11 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
if (mtpTypeId(*rFrom) == mtpc_msgs_state_req) {
|
||||
MTPMsgsStateReq request;
|
||||
request.read(rFrom, rEnd);
|
||||
handleMsgsStates(request.c_msgs_state_req().vmsg_ids.v, states, toAck);
|
||||
handleMsgsStates(request.c_msgs_state_req().vmsg_ids().v, states, toAck);
|
||||
} else {
|
||||
MTPMsgResendReq request;
|
||||
request.read(rFrom, rEnd);
|
||||
handleMsgsStates(request.c_msg_resend_req().vmsg_ids.v, states, toAck);
|
||||
handleMsgsStates(request.c_msg_resend_req().vmsg_ids().v, states, toAck);
|
||||
}
|
||||
} catch(Exception &) {
|
||||
LOG(("Message Error: could not parse sent msgs_state_req"));
|
||||
@@ -1940,8 +1940,8 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
MTPMsgsAllInfo msg;
|
||||
msg.read(from, end);
|
||||
auto &data = msg.c_msgs_all_info();
|
||||
auto &ids = data.vmsg_ids.v;
|
||||
auto &states = data.vinfo.v;
|
||||
auto &ids = data.vmsg_ids().v;
|
||||
auto &states = data.vinfo().v;
|
||||
|
||||
QVector<MTPlong> toAck;
|
||||
|
||||
@@ -1956,21 +1956,21 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
msg.read(from, end);
|
||||
const auto &data(msg.c_msg_detailed_info());
|
||||
|
||||
DEBUG_LOG(("Message Info: msg detailed info, sent msgId %1, answerId %2, status %3, bytes %4").arg(data.vmsg_id.v).arg(data.vanswer_msg_id.v).arg(data.vstatus.v).arg(data.vbytes.v));
|
||||
DEBUG_LOG(("Message Info: msg detailed info, sent msgId %1, answerId %2, status %3, bytes %4").arg(data.vmsg_id().v).arg(data.vanswer_msg_id().v).arg(data.vstatus().v).arg(data.vbytes().v));
|
||||
|
||||
QVector<MTPlong> ids(1, data.vmsg_id);
|
||||
QVector<MTPlong> ids(1, data.vmsg_id());
|
||||
if (badTime) {
|
||||
if (requestsFixTimeSalt(ids, serverTime, serverSalt)) {
|
||||
badTime = false;
|
||||
} else {
|
||||
DEBUG_LOG(("Message Info: error, such message was not sent recently %1").arg(data.vmsg_id.v));
|
||||
DEBUG_LOG(("Message Info: error, such message was not sent recently %1").arg(data.vmsg_id().v));
|
||||
return HandleResult::Ignored;
|
||||
}
|
||||
}
|
||||
requestsAcked(ids);
|
||||
|
||||
bool received = false;
|
||||
MTPlong resMsgId = data.vanswer_msg_id;
|
||||
MTPlong resMsgId = data.vanswer_msg_id();
|
||||
{
|
||||
QReadLocker lock(sessionData->receivedIdsMutex());
|
||||
received = (sessionData->receivedIdsSet().lookup(resMsgId.v) != ReceivedMsgIds::State::NotFound);
|
||||
@@ -1992,10 +1992,10 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
msg.read(from, end);
|
||||
const auto &data(msg.c_msg_new_detailed_info());
|
||||
|
||||
DEBUG_LOG(("Message Info: msg new detailed info, answerId %2, status %3, bytes %4").arg(data.vanswer_msg_id.v).arg(data.vstatus.v).arg(data.vbytes.v));
|
||||
DEBUG_LOG(("Message Info: msg new detailed info, answerId %2, status %3, bytes %4").arg(data.vanswer_msg_id().v).arg(data.vstatus().v).arg(data.vbytes().v));
|
||||
|
||||
bool received = false;
|
||||
MTPlong resMsgId = data.vanswer_msg_id;
|
||||
MTPlong resMsgId = data.vanswer_msg_id();
|
||||
{
|
||||
QReadLocker lock(sessionData->receivedIdsMutex());
|
||||
received = (sessionData->receivedIdsSet().lookup(resMsgId.v) != ReceivedMsgIds::State::NotFound);
|
||||
@@ -2011,7 +2011,7 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
case mtpc_msg_resend_req: {
|
||||
MTPMsgResendReq msg;
|
||||
msg.read(from, end);
|
||||
auto &ids = msg.c_msg_resend_req().vmsg_ids.v;
|
||||
auto &ids = msg.c_msg_resend_req().vmsg_ids().v;
|
||||
|
||||
auto idsCount = ids.size();
|
||||
DEBUG_LOG(("Message Info: resend of msgs requested, ids: %1").arg(LogIdsVector(ids)));
|
||||
@@ -2083,18 +2083,18 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
const auto &data(msg.c_new_session_created());
|
||||
|
||||
if (badTime) {
|
||||
if (requestsFixTimeSalt(QVector<MTPlong>(1, data.vfirst_msg_id), serverTime, serverSalt)) {
|
||||
if (requestsFixTimeSalt(QVector<MTPlong>(1, data.vfirst_msg_id()), serverTime, serverSalt)) {
|
||||
badTime = false;
|
||||
} else {
|
||||
DEBUG_LOG(("Message Info: error, such message was not sent recently %1").arg(data.vfirst_msg_id.v));
|
||||
DEBUG_LOG(("Message Info: error, such message was not sent recently %1").arg(data.vfirst_msg_id().v));
|
||||
return HandleResult::Ignored;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(("Message Info: new server session created, unique_id %1, first_msg_id %2, server_salt %3").arg(data.vunique_id.v).arg(data.vfirst_msg_id.v).arg(data.vserver_salt.v));
|
||||
sessionData->setSalt(data.vserver_salt.v);
|
||||
DEBUG_LOG(("Message Info: new server session created, unique_id %1, first_msg_id %2, server_salt %3").arg(data.vunique_id().v).arg(data.vfirst_msg_id().v).arg(data.vserver_salt().v));
|
||||
sessionData->setSalt(data.vserver_salt().v);
|
||||
|
||||
mtpMsgId firstMsgId = data.vfirst_msg_id.v;
|
||||
mtpMsgId firstMsgId = data.vfirst_msg_id().v;
|
||||
QVector<quint64> toResend;
|
||||
{
|
||||
QReadLocker locker(sessionData->haveSentMutex());
|
||||
@@ -2115,33 +2115,23 @@ ConnectionPrivate::HandleResult ConnectionPrivate::handleOneReceived(const mtpPr
|
||||
sessionData->haveReceivedUpdates().push_back(SerializedMessage(update));
|
||||
} return HandleResult::Success;
|
||||
|
||||
case mtpc_ping: {
|
||||
if (badTime) return HandleResult::Ignored;
|
||||
|
||||
MTPPing msg;
|
||||
msg.read(from, end);
|
||||
DEBUG_LOG(("Message Info: ping received, ping_id: %1, sending pong...").arg(msg.vping_id.v));
|
||||
|
||||
emit sendPongAsync(msgId, msg.vping_id.v);
|
||||
} return HandleResult::Success;
|
||||
|
||||
case mtpc_pong: {
|
||||
MTPPong msg;
|
||||
msg.read(from, end);
|
||||
const auto &data(msg.c_pong());
|
||||
DEBUG_LOG(("Message Info: pong received, msg_id: %1, ping_id: %2").arg(data.vmsg_id.v).arg(data.vping_id.v));
|
||||
DEBUG_LOG(("Message Info: pong received, msg_id: %1, ping_id: %2").arg(data.vmsg_id().v).arg(data.vping_id().v));
|
||||
|
||||
if (!wasSent(data.vmsg_id.v)) {
|
||||
DEBUG_LOG(("Message Error: such msg_id %1 ping_id %2 was not sent recently").arg(data.vmsg_id.v).arg(data.vping_id.v));
|
||||
if (!wasSent(data.vmsg_id().v)) {
|
||||
DEBUG_LOG(("Message Error: such msg_id %1 ping_id %2 was not sent recently").arg(data.vmsg_id().v).arg(data.vping_id().v));
|
||||
return HandleResult::Ignored;
|
||||
}
|
||||
if (data.vping_id.v == _pingId) {
|
||||
if (data.vping_id().v == _pingId) {
|
||||
_pingId = 0;
|
||||
} else {
|
||||
DEBUG_LOG(("Message Info: just pong..."));
|
||||
}
|
||||
|
||||
QVector<MTPlong> ids(1, data.vmsg_id);
|
||||
QVector<MTPlong> ids(1, data.vmsg_id());
|
||||
if (badTime) {
|
||||
if (requestsFixTimeSalt(ids, serverTime, serverSalt)) {
|
||||
badTime = false;
|
||||
@@ -2543,10 +2533,7 @@ void ConnectionPrivate::updateAuthKey() {
|
||||
|
||||
_authKeyData = std::make_unique<ConnectionPrivate::AuthKeyCreateData>();
|
||||
_authKeyStrings = std::make_unique<ConnectionPrivate::AuthKeyCreateStrings>();
|
||||
_authKeyData->nonce = rand_value<MTPint128>();
|
||||
|
||||
MTPReq_pq_multi req_pq;
|
||||
req_pq.vnonce = _authKeyData->nonce;
|
||||
const auto nonce = _authKeyData->nonce = rand_value<MTPint128>();
|
||||
|
||||
connect(_connection, &AbstractConnection::receivedData, [=] {
|
||||
pqAnswered();
|
||||
@@ -2554,7 +2541,8 @@ void ConnectionPrivate::updateAuthKey() {
|
||||
|
||||
DEBUG_LOG(("AuthKey Info: sending Req_pq..."));
|
||||
lockFinished.unlock();
|
||||
sendNotSecureRequest(req_pq);
|
||||
|
||||
sendNotSecureRequest(MTPReq_pq_multi(nonce));
|
||||
}
|
||||
|
||||
void ConnectionPrivate::clearMessages() {
|
||||
@@ -2573,14 +2561,14 @@ void ConnectionPrivate::pqAnswered() {
|
||||
}
|
||||
|
||||
auto &res_pq_data = res_pq.c_resPQ();
|
||||
if (res_pq_data.vnonce != _authKeyData->nonce) {
|
||||
if (res_pq_data.vnonce() != _authKeyData->nonce) {
|
||||
LOG(("AuthKey Error: received nonce <> sent nonce (in res_pq)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&res_pq_data.vnonce, 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&res_pq_data.vnonce(), 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
return restart();
|
||||
}
|
||||
|
||||
auto rsaKey = internal::RSAPublicKey();
|
||||
if (!_instance->dcOptions()->getDcRSAKey(BareDcId(_shiftedDcId), res_pq.c_resPQ().vserver_public_key_fingerprints.v, &rsaKey)) {
|
||||
if (!_instance->dcOptions()->getDcRSAKey(BareDcId(_shiftedDcId), res_pq.c_resPQ().vserver_public_key_fingerprints().v, &rsaKey)) {
|
||||
if (_dcType == DcType::Cdn) {
|
||||
LOG(("Warning: CDN public RSA key not found"));
|
||||
requestCDNConfig();
|
||||
@@ -2591,10 +2579,10 @@ void ConnectionPrivate::pqAnswered() {
|
||||
}
|
||||
Assert(rsaKey.isValid());
|
||||
|
||||
_authKeyData->server_nonce = res_pq_data.vserver_nonce;
|
||||
_authKeyData->server_nonce = res_pq_data.vserver_nonce();
|
||||
_authKeyData->new_nonce = rand_value<MTPint256>();
|
||||
|
||||
auto &pq = res_pq_data.vpq.v;
|
||||
auto &pq = res_pq_data.vpq().v;
|
||||
auto p = QByteArray();
|
||||
auto q = QByteArray();
|
||||
if (!internal::parsePQ(pq, p, q)) {
|
||||
@@ -2604,7 +2592,7 @@ void ConnectionPrivate::pqAnswered() {
|
||||
}
|
||||
|
||||
auto p_q_inner = MTP_p_q_inner_data_dc(
|
||||
res_pq_data.vpq,
|
||||
res_pq_data.vpq(),
|
||||
MTP_bytes(std::move(p)),
|
||||
MTP_bytes(std::move(q)),
|
||||
_authKeyData->nonce,
|
||||
@@ -2622,14 +2610,13 @@ void ConnectionPrivate::pqAnswered() {
|
||||
|
||||
DEBUG_LOG(("AuthKey Info: sending Req_DH_params..."));
|
||||
|
||||
MTPReq_DH_params req_DH_params;
|
||||
req_DH_params.vnonce = _authKeyData->nonce;
|
||||
req_DH_params.vserver_nonce = _authKeyData->server_nonce;
|
||||
req_DH_params.vpublic_key_fingerprint = MTP_long(rsaKey.getFingerPrint());
|
||||
req_DH_params.vp = p_q_inner.c_p_q_inner_data_dc().vp;
|
||||
req_DH_params.vq = p_q_inner.c_p_q_inner_data_dc().vq;
|
||||
req_DH_params.vencrypted_data = MTP_bytes(dhEncString);
|
||||
sendNotSecureRequest(req_DH_params);
|
||||
sendNotSecureRequest(MTPReq_DH_params(
|
||||
_authKeyData->nonce,
|
||||
_authKeyData->server_nonce,
|
||||
p_q_inner.c_p_q_inner_data_dc().vp(),
|
||||
p_q_inner.c_p_q_inner_data_dc().vq(),
|
||||
MTP_long(rsaKey.getFingerPrint()),
|
||||
MTP_bytes(dhEncString)));
|
||||
}
|
||||
|
||||
bytes::vector ConnectionPrivate::encryptPQInnerRSA(
|
||||
@@ -2675,18 +2662,18 @@ void ConnectionPrivate::dhParamsAnswered() {
|
||||
switch (res_DH_params.type()) {
|
||||
case mtpc_server_DH_params_ok: {
|
||||
const auto &encDH(res_DH_params.c_server_DH_params_ok());
|
||||
if (encDH.vnonce != _authKeyData->nonce) {
|
||||
if (encDH.vnonce() != _authKeyData->nonce) {
|
||||
LOG(("AuthKey Error: received nonce <> sent nonce (in server_DH_params_ok)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&encDH.vnonce, 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&encDH.vnonce(), 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
return restart();
|
||||
}
|
||||
if (encDH.vserver_nonce != _authKeyData->server_nonce) {
|
||||
if (encDH.vserver_nonce() != _authKeyData->server_nonce) {
|
||||
LOG(("AuthKey Error: received server_nonce <> sent server_nonce (in server_DH_params_ok)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&encDH.vserver_nonce, 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&encDH.vserver_nonce(), 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
return restart();
|
||||
}
|
||||
|
||||
auto &encDHStr = encDH.vencrypted_answer.v;
|
||||
auto &encDHStr = encDH.vencrypted_answer().v;
|
||||
uint32 encDHLen = encDHStr.length(), encDHBufLen = encDHLen >> 2;
|
||||
if ((encDHLen & 0x03) || encDHBufLen < 6) {
|
||||
LOG(("AuthKey Error: bad encrypted data length %1 (in server_DH_params_ok)!").arg(encDHLen));
|
||||
@@ -2719,14 +2706,14 @@ void ConnectionPrivate::dhParamsAnswered() {
|
||||
MTPServer_DH_inner_data dh_inner;
|
||||
dh_inner.read(to, end);
|
||||
const auto &dh_inner_data(dh_inner.c_server_DH_inner_data());
|
||||
if (dh_inner_data.vnonce != _authKeyData->nonce) {
|
||||
if (dh_inner_data.vnonce() != _authKeyData->nonce) {
|
||||
LOG(("AuthKey Error: received nonce <> sent nonce (in server_DH_inner_data)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&dh_inner_data.vnonce, 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&dh_inner_data.vnonce(), 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
return restart();
|
||||
}
|
||||
if (dh_inner_data.vserver_nonce != _authKeyData->server_nonce) {
|
||||
if (dh_inner_data.vserver_nonce() != _authKeyData->server_nonce) {
|
||||
LOG(("AuthKey Error: received server_nonce <> sent server_nonce (in server_DH_inner_data)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&dh_inner_data.vserver_nonce, 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&dh_inner_data.vserver_nonce(), 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
return restart();
|
||||
}
|
||||
uchar sha1Buffer[20];
|
||||
@@ -2735,38 +2722,38 @@ void ConnectionPrivate::dhParamsAnswered() {
|
||||
DEBUG_LOG(("AuthKey Error: sha1 did not match, server_nonce: %1, new_nonce %2, encrypted data %3").arg(Logs::mb(&_authKeyData->server_nonce, 16).str()).arg(Logs::mb(&_authKeyData->new_nonce, 16).str()).arg(Logs::mb(encDHStr.constData(), encDHLen).str()));
|
||||
return restart();
|
||||
}
|
||||
unixtimeSet(dh_inner_data.vserver_time.v);
|
||||
unixtimeSet(dh_inner_data.vserver_time().v);
|
||||
|
||||
// check that dhPrime and (dhPrime - 1) / 2 are really prime
|
||||
if (!IsPrimeAndGood(bytes::make_span(dh_inner_data.vdh_prime.v), dh_inner_data.vg.v)) {
|
||||
if (!IsPrimeAndGood(bytes::make_span(dh_inner_data.vdh_prime().v), dh_inner_data.vg().v)) {
|
||||
LOG(("AuthKey Error: bad dh_prime primality!"));
|
||||
return restart();
|
||||
}
|
||||
|
||||
_authKeyStrings->dh_prime = bytes::make_vector(
|
||||
dh_inner_data.vdh_prime.v);
|
||||
_authKeyData->g = dh_inner_data.vg.v;
|
||||
_authKeyStrings->g_a = bytes::make_vector(dh_inner_data.vg_a.v);
|
||||
dh_inner_data.vdh_prime().v);
|
||||
_authKeyData->g = dh_inner_data.vg().v;
|
||||
_authKeyStrings->g_a = bytes::make_vector(dh_inner_data.vg_a().v);
|
||||
_authKeyData->retry_id = MTP_long(0);
|
||||
_authKeyData->retries = 0;
|
||||
} return dhClientParamsSend();
|
||||
|
||||
case mtpc_server_DH_params_fail: {
|
||||
const auto &encDH(res_DH_params.c_server_DH_params_fail());
|
||||
if (encDH.vnonce != _authKeyData->nonce) {
|
||||
if (encDH.vnonce() != _authKeyData->nonce) {
|
||||
LOG(("AuthKey Error: received nonce <> sent nonce (in server_DH_params_fail)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&encDH.vnonce, 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&encDH.vnonce(), 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
return restart();
|
||||
}
|
||||
if (encDH.vserver_nonce != _authKeyData->server_nonce) {
|
||||
if (encDH.vserver_nonce() != _authKeyData->server_nonce) {
|
||||
LOG(("AuthKey Error: received server_nonce <> sent server_nonce (in server_DH_params_fail)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&encDH.vserver_nonce, 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&encDH.vserver_nonce(), 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
return restart();
|
||||
}
|
||||
uchar sha1Buffer[20];
|
||||
if (encDH.vnew_nonce_hash != *(MTPint128*)(hashSha1(&_authKeyData->new_nonce, 32, sha1Buffer) + 1)) {
|
||||
if (encDH.vnew_nonce_hash() != *(MTPint128*)(hashSha1(&_authKeyData->new_nonce, 32, sha1Buffer) + 1)) {
|
||||
LOG(("AuthKey Error: received new_nonce_hash did not match!"));
|
||||
DEBUG_LOG(("AuthKey Error: received new_nonce_hash: %1, new_nonce: %2").arg(Logs::mb(&encDH.vnew_nonce_hash, 16).str()).arg(Logs::mb(&_authKeyData->new_nonce, 32).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received new_nonce_hash: %1, new_nonce: %2").arg(Logs::mb(&encDH.vnew_nonce_hash(), 16).str()).arg(Logs::mb(&_authKeyData->new_nonce, 32).str()));
|
||||
return restart();
|
||||
}
|
||||
LOG(("AuthKey Error: server_DH_params_fail received!"));
|
||||
@@ -2812,13 +2799,11 @@ void ConnectionPrivate::dhClientParamsSend() {
|
||||
dhClientParamsAnswered();
|
||||
});
|
||||
|
||||
MTPSet_client_DH_params req_client_DH_params;
|
||||
req_client_DH_params.vnonce = _authKeyData->nonce;
|
||||
req_client_DH_params.vserver_nonce = _authKeyData->server_nonce;
|
||||
req_client_DH_params.vencrypted_data = MTP_string(std::move(sdhEncString));
|
||||
|
||||
DEBUG_LOG(("AuthKey Info: sending Req_client_DH_params..."));
|
||||
sendNotSecureRequest(req_client_DH_params);
|
||||
sendNotSecureRequest(MTPSet_client_DH_params(
|
||||
_authKeyData->nonce,
|
||||
_authKeyData->server_nonce,
|
||||
MTP_string(std::move(sdhEncString))));
|
||||
}
|
||||
|
||||
std::string ConnectionPrivate::encryptClientDHInner(const MTPClient_DH_Inner_Data &data) {
|
||||
@@ -2863,25 +2848,25 @@ void ConnectionPrivate::dhClientParamsAnswered() {
|
||||
switch (res_client_DH_params.type()) {
|
||||
case mtpc_dh_gen_ok: {
|
||||
const auto &resDH(res_client_DH_params.c_dh_gen_ok());
|
||||
if (resDH.vnonce != _authKeyData->nonce) {
|
||||
if (resDH.vnonce() != _authKeyData->nonce) {
|
||||
LOG(("AuthKey Error: received nonce <> sent nonce (in dh_gen_ok)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&resDH.vnonce, 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&resDH.vnonce(), 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
}
|
||||
if (resDH.vserver_nonce != _authKeyData->server_nonce) {
|
||||
if (resDH.vserver_nonce() != _authKeyData->server_nonce) {
|
||||
LOG(("AuthKey Error: received server_nonce <> sent server_nonce (in dh_gen_ok)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&resDH.vserver_nonce, 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&resDH.vserver_nonce(), 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
}
|
||||
_authKeyData->new_nonce_buf[32] = 1;
|
||||
uchar sha1Buffer[20];
|
||||
if (resDH.vnew_nonce_hash1 != *(MTPint128*)(hashSha1(_authKeyData->new_nonce_buf, 41, sha1Buffer) + 1)) {
|
||||
if (resDH.vnew_nonce_hash1() != *(MTPint128*)(hashSha1(_authKeyData->new_nonce_buf, 41, sha1Buffer) + 1)) {
|
||||
LOG(("AuthKey Error: received new_nonce_hash1 did not match!"));
|
||||
DEBUG_LOG(("AuthKey Error: received new_nonce_hash1: %1, new_nonce_buf: %2").arg(Logs::mb(&resDH.vnew_nonce_hash1, 16).str()).arg(Logs::mb(_authKeyData->new_nonce_buf, 41).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received new_nonce_hash1: %1, new_nonce_buf: %2").arg(Logs::mb(&resDH.vnew_nonce_hash1(), 16).str()).arg(Logs::mb(_authKeyData->new_nonce_buf, 41).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
@@ -2901,25 +2886,25 @@ void ConnectionPrivate::dhClientParamsAnswered() {
|
||||
|
||||
case mtpc_dh_gen_retry: {
|
||||
const auto &resDH(res_client_DH_params.c_dh_gen_retry());
|
||||
if (resDH.vnonce != _authKeyData->nonce) {
|
||||
if (resDH.vnonce() != _authKeyData->nonce) {
|
||||
LOG(("AuthKey Error: received nonce <> sent nonce (in dh_gen_retry)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&resDH.vnonce, 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&resDH.vnonce(), 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
}
|
||||
if (resDH.vserver_nonce != _authKeyData->server_nonce) {
|
||||
if (resDH.vserver_nonce() != _authKeyData->server_nonce) {
|
||||
LOG(("AuthKey Error: received server_nonce <> sent server_nonce (in dh_gen_retry)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&resDH.vserver_nonce, 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&resDH.vserver_nonce(), 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
}
|
||||
_authKeyData->new_nonce_buf[32] = 2;
|
||||
uchar sha1Buffer[20];
|
||||
if (resDH.vnew_nonce_hash2 != *(MTPint128*)(hashSha1(_authKeyData->new_nonce_buf, 41, sha1Buffer) + 1)) {
|
||||
if (resDH.vnew_nonce_hash2() != *(MTPint128*)(hashSha1(_authKeyData->new_nonce_buf, 41, sha1Buffer) + 1)) {
|
||||
LOG(("AuthKey Error: received new_nonce_hash2 did not match!"));
|
||||
DEBUG_LOG(("AuthKey Error: received new_nonce_hash2: %1, new_nonce_buf: %2").arg(Logs::mb(&resDH.vnew_nonce_hash2, 16).str()).arg(Logs::mb(_authKeyData->new_nonce_buf, 41).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received new_nonce_hash2: %1, new_nonce_buf: %2").arg(Logs::mb(&resDH.vnew_nonce_hash2(), 16).str()).arg(Logs::mb(_authKeyData->new_nonce_buf, 41).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
@@ -2929,25 +2914,25 @@ void ConnectionPrivate::dhClientParamsAnswered() {
|
||||
|
||||
case mtpc_dh_gen_fail: {
|
||||
const auto &resDH(res_client_DH_params.c_dh_gen_fail());
|
||||
if (resDH.vnonce != _authKeyData->nonce) {
|
||||
if (resDH.vnonce() != _authKeyData->nonce) {
|
||||
LOG(("AuthKey Error: received nonce <> sent nonce (in dh_gen_fail)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&resDH.vnonce, 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received nonce: %1, sent nonce: %2").arg(Logs::mb(&resDH.vnonce(), 16).str()).arg(Logs::mb(&_authKeyData->nonce, 16).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
}
|
||||
if (resDH.vserver_nonce != _authKeyData->server_nonce) {
|
||||
if (resDH.vserver_nonce() != _authKeyData->server_nonce) {
|
||||
LOG(("AuthKey Error: received server_nonce <> sent server_nonce (in dh_gen_fail)!"));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&resDH.vserver_nonce, 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received server_nonce: %1, sent server_nonce: %2").arg(Logs::mb(&resDH.vserver_nonce(), 16).str()).arg(Logs::mb(&_authKeyData->server_nonce, 16).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
}
|
||||
_authKeyData->new_nonce_buf[32] = 3;
|
||||
uchar sha1Buffer[20];
|
||||
if (resDH.vnew_nonce_hash3 != *(MTPint128*)(hashSha1(_authKeyData->new_nonce_buf, 41, sha1Buffer) + 1)) {
|
||||
if (resDH.vnew_nonce_hash3() != *(MTPint128*)(hashSha1(_authKeyData->new_nonce_buf, 41, sha1Buffer) + 1)) {
|
||||
LOG(("AuthKey Error: received new_nonce_hash3 did not match!"));
|
||||
DEBUG_LOG(("AuthKey Error: received new_nonce_hash3: %1, new_nonce_buf: %2").arg(Logs::mb(&resDH.vnew_nonce_hash3, 16).str()).arg(Logs::mb(_authKeyData->new_nonce_buf, 41).str()));
|
||||
DEBUG_LOG(("AuthKey Error: received new_nonce_hash3: %1, new_nonce_buf: %2").arg(Logs::mb(&resDH.vnew_nonce_hash3(), 16).str()).arg(Logs::mb(_authKeyData->new_nonce_buf, 41).str()));
|
||||
|
||||
lockFinished.unlock();
|
||||
return restart();
|
||||
|
@@ -171,7 +171,7 @@ void HttpConnection::requestFinished(QNetworkReply *reply) {
|
||||
try {
|
||||
const auto res_pq = readPQFakeReply(data);
|
||||
const auto &data = res_pq.c_resPQ();
|
||||
if (data.vnonce == _checkNonce) {
|
||||
if (data.vnonce() == _checkNonce) {
|
||||
DEBUG_LOG(("Connection Info: "
|
||||
"HTTP-transport to %1 connected by pq-response"
|
||||
).arg(_address));
|
||||
|
@@ -638,7 +638,7 @@ void TcpConnection::socketPacket(bytes::const_span bytes) {
|
||||
try {
|
||||
const auto res_pq = readPQFakeReply(data);
|
||||
const auto &data = res_pq.c_resPQ();
|
||||
if (data.vnonce == _checkNonce) {
|
||||
if (data.vnonce() == _checkNonce) {
|
||||
DEBUG_LOG(("Connection Info: Valid pq response by TCP."));
|
||||
_status = Status::Ready;
|
||||
disconnect(
|
||||
|
@@ -369,6 +369,49 @@ SecureRequest SecureRequest::Serialize(const Request &request) {
|
||||
return serialized;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
struct RepeatHelper {
|
||||
using type = Type;
|
||||
};
|
||||
template <typename Type>
|
||||
using Repeat = typename RepeatHelper<Type>::type;
|
||||
|
||||
template <typename Type>
|
||||
class conditional {
|
||||
public:
|
||||
conditional() = default;
|
||||
conditional(const Type *value) : _value(value) {
|
||||
}
|
||||
|
||||
operator const Type*() const {
|
||||
return _value;
|
||||
}
|
||||
const Type *operator->() const {
|
||||
Expects(_value != nullptr);
|
||||
|
||||
return _value;
|
||||
}
|
||||
const Type &operator*() const {
|
||||
Expects(_value != nullptr);
|
||||
|
||||
return *_value;
|
||||
}
|
||||
|
||||
template <typename Inner = std::decay_t<decltype(std::declval<Type>().v)>>
|
||||
Inner value_or(Repeat<Inner> fallback) const {
|
||||
return _value ? _value->v : fallback;
|
||||
}
|
||||
|
||||
template <typename Inner = std::decay_t<decltype(std::declval<Type>().v)>>
|
||||
Inner value_or_empty() const {
|
||||
return _value ? _value->v : Inner();
|
||||
}
|
||||
|
||||
private:
|
||||
const Type *_value = nullptr;
|
||||
|
||||
};
|
||||
|
||||
} // namespace MTP
|
||||
|
||||
class MTPint {
|
||||
@@ -660,9 +703,11 @@ private:
|
||||
friend MTPstring MTP_string(const std::string &v);
|
||||
friend MTPstring MTP_string(const QString &v);
|
||||
friend MTPstring MTP_string(const char *v);
|
||||
friend MTPstring MTP_string();
|
||||
|
||||
friend MTPbytes MTP_bytes(const QByteArray &v);
|
||||
friend MTPbytes MTP_bytes(QByteArray &&v);
|
||||
friend MTPbytes MTP_bytes();
|
||||
|
||||
};
|
||||
using MTPString = MTPBoxed<MTPstring>;
|
||||
@@ -677,6 +722,9 @@ inline MTPstring MTP_string(const QString &v) {
|
||||
inline MTPstring MTP_string(const char *v) {
|
||||
return MTPstring(QByteArray(v, strlen(v)));
|
||||
}
|
||||
inline MTPstring MTP_string() {
|
||||
return MTPstring(QByteArray());
|
||||
}
|
||||
MTPstring MTP_string(const QByteArray &v) = delete;
|
||||
|
||||
inline MTPbytes MTP_bytes(const QByteArray &v) {
|
||||
@@ -685,6 +733,9 @@ inline MTPbytes MTP_bytes(const QByteArray &v) {
|
||||
inline MTPbytes MTP_bytes(QByteArray &&v) {
|
||||
return MTPbytes(std::move(v));
|
||||
}
|
||||
inline MTPbytes MTP_bytes() {
|
||||
return MTPbytes(QByteArray());
|
||||
}
|
||||
inline MTPbytes MTP_bytes(bytes::const_span buffer) {
|
||||
return MTP_bytes(QByteArray(
|
||||
reinterpret_cast<const char*>(buffer.data()),
|
||||
@@ -705,6 +756,10 @@ inline QString qs(const MTPstring &v) {
|
||||
return QString::fromUtf8(v.v);
|
||||
}
|
||||
|
||||
inline QString qs(const QByteArray &v) {
|
||||
return QString::fromUtf8(v);
|
||||
}
|
||||
|
||||
inline QByteArray qba(const MTPstring &v) {
|
||||
return v.v;
|
||||
}
|
||||
@@ -756,6 +811,8 @@ private:
|
||||
friend MTPvector<U> MTP_vector(const QVector<U> &v);
|
||||
template <typename U>
|
||||
friend MTPvector<U> MTP_vector(QVector<U> &&v);
|
||||
template <typename U>
|
||||
friend MTPvector<U> MTP_vector();
|
||||
|
||||
};
|
||||
template <typename T>
|
||||
@@ -775,6 +832,10 @@ inline MTPvector<T> MTP_vector(QVector<T> &&v) {
|
||||
return MTPvector<T>(std::move(v));
|
||||
}
|
||||
template <typename T>
|
||||
inline MTPvector<T> MTP_vector() {
|
||||
return MTPvector<T>();
|
||||
}
|
||||
template <typename T>
|
||||
using MTPVector = MTPBoxed<MTPvector<T>>;
|
||||
|
||||
template <typename T>
|
||||
|
@@ -146,15 +146,13 @@ void DcOptions::processFromList(
|
||||
}
|
||||
|
||||
auto &option = mtpOption.c_dcOption();
|
||||
auto dcId = option.vid.v;
|
||||
auto flags = option.vflags.v;
|
||||
auto dcId = option.vid().v;
|
||||
auto flags = option.vflags().v;
|
||||
auto ip = std::string(
|
||||
option.vip_address.v.constData(),
|
||||
option.vip_address.v.size());
|
||||
auto port = option.vport.v;
|
||||
auto secret = option.has_secret()
|
||||
? bytes::make_vector(option.vsecret.v)
|
||||
: bytes::vector();
|
||||
option.vip_address().v.constData(),
|
||||
option.vip_address().v.size());
|
||||
auto port = option.vport().v;
|
||||
auto secret = bytes::make_vector(option.vsecret().value_or_empty());
|
||||
ApplyOneOption(data, dcId, flags, ip, port, secret);
|
||||
}
|
||||
|
||||
@@ -537,18 +535,18 @@ DcType DcOptions::dcType(ShiftedDcId shiftedDcId) const {
|
||||
void DcOptions::setCDNConfig(const MTPDcdnConfig &config) {
|
||||
WriteLocker lock(this);
|
||||
_cdnPublicKeys.clear();
|
||||
for_const (auto &publicKey, config.vpublic_keys.v) {
|
||||
for_const (auto &publicKey, config.vpublic_keys().v) {
|
||||
Expects(publicKey.type() == mtpc_cdnPublicKey);
|
||||
const auto &keyData = publicKey.c_cdnPublicKey();
|
||||
const auto keyBytes = bytes::make_span(keyData.vpublic_key.v);
|
||||
const auto keyBytes = bytes::make_span(keyData.vpublic_key().v);
|
||||
auto key = internal::RSAPublicKey(keyBytes);
|
||||
if (key.isValid()) {
|
||||
_cdnPublicKeys[keyData.vdc_id.v].emplace(
|
||||
_cdnPublicKeys[keyData.vdc_id().v].emplace(
|
||||
key.getFingerPrint(),
|
||||
std::move(key));
|
||||
} else {
|
||||
LOG(("MTP Error: could not read this public RSA key:"));
|
||||
LOG((qs(keyData.vpublic_key)));
|
||||
LOG((qs(keyData.vpublic_key())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,14 +17,14 @@ namespace {
|
||||
std::optional<MTPInputChannel> ExtractChannel(
|
||||
const MTPcontacts_ResolvedPeer &result) {
|
||||
const auto &data = result.c_contacts_resolvedPeer();
|
||||
if (const auto peer = peerFromMTP(data.vpeer)) {
|
||||
for (const auto &chat : data.vchats.v) {
|
||||
if (const auto peer = peerFromMTP(data.vpeer())) {
|
||||
for (const auto &chat : data.vchats().v) {
|
||||
if (chat.type() == mtpc_channel) {
|
||||
const auto &channel = chat.c_channel();
|
||||
if (peer == peerFromChannel(channel.vid)) {
|
||||
if (peer == peerFromChannel(channel.vid())) {
|
||||
return MTP_inputChannel(
|
||||
channel.vid,
|
||||
channel.vaccess_hash);
|
||||
channel.vid(),
|
||||
MTP_long(channel.vaccess_hash().value_or_empty()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,23 +40,23 @@ std::optional<DedicatedLoader::File> ParseFile(
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto &data = message->c_message();
|
||||
if (!data.has_media()
|
||||
|| data.vmedia.type() != mtpc_messageMediaDocument) {
|
||||
const auto media = data.vmedia();
|
||||
if (!media || media->type() != mtpc_messageMediaDocument) {
|
||||
LOG(("Update Error: MTP file media not found."));
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto &document = data.vmedia.c_messageMediaDocument();
|
||||
if (!document.has_document()
|
||||
|| document.vdocument.type() != mtpc_document) {
|
||||
const auto &inner = media->c_messageMediaDocument();
|
||||
const auto document = inner.vdocument();
|
||||
if (!document || document->type() != mtpc_document) {
|
||||
LOG(("Update Error: MTP file not found."));
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto &fields = document.vdocument.c_document();
|
||||
const auto &fields = document->c_document();
|
||||
const auto name = [&] {
|
||||
for (const auto &attribute : fields.vattributes.v) {
|
||||
for (const auto &attribute : fields.vattributes().v) {
|
||||
if (attribute.type() == mtpc_documentAttributeFilename) {
|
||||
const auto &data = attribute.c_documentAttributeFilename();
|
||||
return qs(data.vfile_name);
|
||||
return qs(data.vfile_name());
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
@@ -65,17 +65,17 @@ std::optional<DedicatedLoader::File> ParseFile(
|
||||
LOG(("Update Error: MTP file name not found."));
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto size = fields.vsize.v;
|
||||
const auto size = fields.vsize().v;
|
||||
if (size <= 0) {
|
||||
LOG(("Update Error: MTP file size is invalid."));
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto location = MTP_inputDocumentFileLocation(
|
||||
fields.vid,
|
||||
fields.vaccess_hash,
|
||||
fields.vfile_reference,
|
||||
MTP_string(QString()));
|
||||
return DedicatedLoader::File{ name, size, fields.vdc_id.v, location };
|
||||
fields.vid(),
|
||||
fields.vaccess_hash(),
|
||||
fields.vfile_reference(),
|
||||
MTP_string());
|
||||
return DedicatedLoader::File{ name, size, fields.vdc_id().v, location };
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -329,7 +329,7 @@ void DedicatedLoader::gotPart(int offset, const MTPupload_File &result) {
|
||||
return;
|
||||
}
|
||||
const auto &data = result.c_upload_file();
|
||||
if (data.vbytes.v.isEmpty()) {
|
||||
if (data.vbytes().v.isEmpty()) {
|
||||
LOG(("Update Error: MTP empty part received."));
|
||||
threadSafeFailed();
|
||||
return;
|
||||
@@ -341,7 +341,7 @@ void DedicatedLoader::gotPart(int offset, const MTPupload_File &result) {
|
||||
[](const Request &request) { return request.offset; });
|
||||
Assert(i != end(_requests));
|
||||
|
||||
i->bytes = data.vbytes.v;
|
||||
i->bytes = data.vbytes().v;
|
||||
while (!_requests.empty() && !_requests.front().bytes.isEmpty()) {
|
||||
writeChunk(bytes::make_span(_requests.front().bytes), _size);
|
||||
_requests.pop_front();
|
||||
@@ -415,9 +415,9 @@ std::optional<MTPMessage> GetMessagesElement(
|
||||
return list.match([&](const MTPDmessages_messagesNotModified &) {
|
||||
return std::optional<MTPMessage>(std::nullopt);
|
||||
}, [&](const auto &data) {
|
||||
return data.vmessages.v.isEmpty()
|
||||
return data.vmessages().v.isEmpty()
|
||||
? std::nullopt
|
||||
: std::make_optional(data.vmessages.v[0]);
|
||||
: std::make_optional(data.vmessages().v[0]);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -748,71 +748,65 @@ void Instance::Private::configLoadDone(const MTPConfig &result) {
|
||||
_lastConfigLoadedTime = crl::now();
|
||||
|
||||
const auto &data = result.c_config();
|
||||
DEBUG_LOG(("MTP Info: got config, chat_size_max: %1, date: %2, test_mode: %3, this_dc: %4, dc_options.length: %5").arg(data.vchat_size_max.v).arg(data.vdate.v).arg(mtpIsTrue(data.vtest_mode)).arg(data.vthis_dc.v).arg(data.vdc_options.v.size()));
|
||||
if (data.vdc_options.v.empty()) {
|
||||
DEBUG_LOG(("MTP Info: got config, chat_size_max: %1, date: %2, test_mode: %3, this_dc: %4, dc_options.length: %5").arg(data.vchat_size_max().v).arg(data.vdate().v).arg(mtpIsTrue(data.vtest_mode())).arg(data.vthis_dc().v).arg(data.vdc_options().v.size()));
|
||||
if (data.vdc_options().v.empty()) {
|
||||
LOG(("MTP Error: config with empty dc_options received!"));
|
||||
} else {
|
||||
_dcOptions->setFromList(data.vdc_options);
|
||||
_dcOptions->setFromList(data.vdc_options());
|
||||
}
|
||||
|
||||
Global::SetChatSizeMax(data.vchat_size_max.v);
|
||||
Global::SetMegagroupSizeMax(data.vmegagroup_size_max.v);
|
||||
Global::SetForwardedCountMax(data.vforwarded_count_max.v);
|
||||
Global::SetOnlineUpdatePeriod(data.vonline_update_period_ms.v);
|
||||
Global::SetOfflineBlurTimeout(data.voffline_blur_timeout_ms.v);
|
||||
Global::SetOfflineIdleTimeout(data.voffline_idle_timeout_ms.v);
|
||||
Global::SetOnlineCloudTimeout(data.vonline_cloud_timeout_ms.v);
|
||||
Global::SetNotifyCloudDelay(data.vnotify_cloud_delay_ms.v);
|
||||
Global::SetNotifyDefaultDelay(data.vnotify_default_delay_ms.v);
|
||||
Global::SetPushChatPeriod(data.vpush_chat_period_ms.v);
|
||||
Global::SetPushChatLimit(data.vpush_chat_limit.v);
|
||||
Global::SetSavedGifsLimit(data.vsaved_gifs_limit.v);
|
||||
Global::SetEditTimeLimit(data.vedit_time_limit.v);
|
||||
Global::SetRevokeTimeLimit(data.vrevoke_time_limit.v);
|
||||
Global::SetRevokePrivateTimeLimit(data.vrevoke_pm_time_limit.v);
|
||||
Global::SetChatSizeMax(data.vchat_size_max().v);
|
||||
Global::SetMegagroupSizeMax(data.vmegagroup_size_max().v);
|
||||
Global::SetForwardedCountMax(data.vforwarded_count_max().v);
|
||||
Global::SetOnlineUpdatePeriod(data.vonline_update_period_ms().v);
|
||||
Global::SetOfflineBlurTimeout(data.voffline_blur_timeout_ms().v);
|
||||
Global::SetOfflineIdleTimeout(data.voffline_idle_timeout_ms().v);
|
||||
Global::SetOnlineCloudTimeout(data.vonline_cloud_timeout_ms().v);
|
||||
Global::SetNotifyCloudDelay(data.vnotify_cloud_delay_ms().v);
|
||||
Global::SetNotifyDefaultDelay(data.vnotify_default_delay_ms().v);
|
||||
Global::SetPushChatPeriod(data.vpush_chat_period_ms().v);
|
||||
Global::SetPushChatLimit(data.vpush_chat_limit().v);
|
||||
Global::SetSavedGifsLimit(data.vsaved_gifs_limit().v);
|
||||
Global::SetEditTimeLimit(data.vedit_time_limit().v);
|
||||
Global::SetRevokeTimeLimit(data.vrevoke_time_limit().v);
|
||||
Global::SetRevokePrivateTimeLimit(data.vrevoke_pm_time_limit().v);
|
||||
Global::SetRevokePrivateInbox(data.is_revoke_pm_inbox());
|
||||
Global::SetStickersRecentLimit(data.vstickers_recent_limit.v);
|
||||
Global::SetStickersFavedLimit(data.vstickers_faved_limit.v);
|
||||
Global::SetStickersRecentLimit(data.vstickers_recent_limit().v);
|
||||
Global::SetStickersFavedLimit(data.vstickers_faved_limit().v);
|
||||
Global::SetPinnedDialogsCountMax(
|
||||
std::max(data.vpinned_dialogs_count_max.v, 1));
|
||||
std::max(data.vpinned_dialogs_count_max().v, 1));
|
||||
Global::SetPinnedDialogsInFolderMax(
|
||||
std::max(data.vpinned_infolder_count_max.v, 1));
|
||||
Core::App().setInternalLinkDomain(qs(data.vme_url_prefix));
|
||||
Global::SetChannelsReadMediaPeriod(data.vchannels_read_media_period.v);
|
||||
Global::SetWebFileDcId(data.vwebfile_dc_id.v);
|
||||
Global::SetTxtDomainString(qs(data.vdc_txt_domain_name));
|
||||
Global::SetCallReceiveTimeoutMs(data.vcall_receive_timeout_ms.v);
|
||||
Global::SetCallRingTimeoutMs(data.vcall_ring_timeout_ms.v);
|
||||
Global::SetCallConnectTimeoutMs(data.vcall_connect_timeout_ms.v);
|
||||
Global::SetCallPacketTimeoutMs(data.vcall_packet_timeout_ms.v);
|
||||
std::max(data.vpinned_infolder_count_max().v, 1));
|
||||
Core::App().setInternalLinkDomain(qs(data.vme_url_prefix()));
|
||||
Global::SetChannelsReadMediaPeriod(data.vchannels_read_media_period().v);
|
||||
Global::SetWebFileDcId(data.vwebfile_dc_id().v);
|
||||
Global::SetTxtDomainString(qs(data.vdc_txt_domain_name()));
|
||||
Global::SetCallReceiveTimeoutMs(data.vcall_receive_timeout_ms().v);
|
||||
Global::SetCallRingTimeoutMs(data.vcall_ring_timeout_ms().v);
|
||||
Global::SetCallConnectTimeoutMs(data.vcall_connect_timeout_ms().v);
|
||||
Global::SetCallPacketTimeoutMs(data.vcall_packet_timeout_ms().v);
|
||||
if (Global::PhoneCallsEnabled() != data.is_phonecalls_enabled()) {
|
||||
Global::SetPhoneCallsEnabled(data.is_phonecalls_enabled());
|
||||
Global::RefPhoneCallsEnabledChanged().notify();
|
||||
}
|
||||
Global::SetBlockedMode(data.is_blocked_mode());
|
||||
Global::SetCaptionLengthMax(data.vcaption_length_max.v);
|
||||
Global::SetCaptionLengthMax(data.vcaption_length_max().v);
|
||||
|
||||
const auto lang = data.has_suggested_lang_code()
|
||||
? qs(data.vsuggested_lang_code)
|
||||
: QString();
|
||||
const auto lang = qs(data.vsuggested_lang_code().value_or_empty());
|
||||
Lang::CurrentCloudManager().setSuggestedLanguage(lang);
|
||||
Lang::CurrentCloudManager().setCurrentVersions(
|
||||
(data.has_lang_pack_version()
|
||||
? data.vlang_pack_version.v
|
||||
: 0),
|
||||
(data.has_base_lang_pack_version()
|
||||
? data.vbase_lang_pack_version.v
|
||||
: 0));
|
||||
data.vlang_pack_version().value_or_empty(),
|
||||
data.vbase_lang_pack_version().value_or_empty());
|
||||
|
||||
Core::App().configUpdated();
|
||||
|
||||
if (data.has_autoupdate_url_prefix()) {
|
||||
Local::writeAutoupdatePrefix(qs(data.vautoupdate_url_prefix));
|
||||
if (const auto prefix = data.vautoupdate_url_prefix()) {
|
||||
Local::writeAutoupdatePrefix(qs(*prefix));
|
||||
}
|
||||
Local::writeSettings();
|
||||
|
||||
_configExpiresAt = crl::now()
|
||||
+ (data.vexpires.v - unixtime()) * crl::time(1000);
|
||||
+ (data.vexpires().v - unixtime()) * crl::time(1000);
|
||||
requestConfigIfExpired();
|
||||
|
||||
emit _instance->configLoaded();
|
||||
@@ -1198,7 +1192,7 @@ void Instance::Private::exportDone(const MTPauth_ExportedAuthorization &result,
|
||||
}
|
||||
|
||||
auto &data = result.c_auth_exportedAuthorization();
|
||||
_instance->send(MTPauth_ImportAuthorization(data.vid, data.vbytes), rpcDone([this](const MTPauth_Authorization &result, mtpRequestId requestId) {
|
||||
_instance->send(MTPauth_ImportAuthorization(data.vid(), data.vbytes()), rpcDone([this](const MTPauth_Authorization &result, mtpRequestId requestId) {
|
||||
importDone(result, requestId);
|
||||
}), rpcFail([this](const RPCError &error, mtpRequestId requestId) {
|
||||
return importFail(error, requestId);
|
||||
|
@@ -8,8 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "mtproto/rpc_sender.h"
|
||||
|
||||
RPCError::RPCError(const MTPrpcError &error)
|
||||
: _code(error.c_rpc_error().verror_code.v) {
|
||||
QString text = qs(error.c_rpc_error().verror_message);
|
||||
: _code(error.c_rpc_error().verror_code().v) {
|
||||
QString text = qs(error.c_rpc_error().verror_message());
|
||||
if (_code < 0 || _code >= 500) {
|
||||
_type = qsl("INTERNAL_SERVER_ERROR");
|
||||
_description = text;
|
||||
|
@@ -380,24 +380,24 @@ void SpecialConfigRequest::handleResponse(const QByteArray &bytes) {
|
||||
Assert(_simpleConfig.type() == mtpc_help_configSimple);
|
||||
auto &config = _simpleConfig.c_help_configSimple();
|
||||
auto now = unixtime();
|
||||
if (now < config.vdate.v || now > config.vexpires.v) {
|
||||
LOG(("Config Error: Bad date frame for simple config: %1-%2, our time is %3.").arg(config.vdate.v).arg(config.vexpires.v).arg(now));
|
||||
if (now < config.vdate().v || now > config.vexpires().v) {
|
||||
LOG(("Config Error: Bad date frame for simple config: %1-%2, our time is %3.").arg(config.vdate().v).arg(config.vexpires().v).arg(now));
|
||||
return;
|
||||
}
|
||||
if (config.vrules.v.empty()) {
|
||||
if (config.vrules().v.empty()) {
|
||||
LOG(("Config Error: Empty simple config received."));
|
||||
return;
|
||||
}
|
||||
for (auto &rule : config.vrules.v) {
|
||||
for (auto &rule : config.vrules().v) {
|
||||
Assert(rule.type() == mtpc_accessPointRule);
|
||||
auto &data = rule.c_accessPointRule();
|
||||
const auto phoneRules = qs(data.vphone_prefix_rules);
|
||||
const auto phoneRules = qs(data.vphone_prefix_rules());
|
||||
if (!CheckPhoneByPrefixesRules(_phone, phoneRules)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto dcId = data.vdc_id.v;
|
||||
for (const auto &address : data.vips.v) {
|
||||
const auto dcId = data.vdc_id().v;
|
||||
for (const auto &address : data.vips().v) {
|
||||
const auto parseIp = [](const MTPint &ipv4) {
|
||||
const auto ip = *reinterpret_cast<const uint32*>(&ipv4.v);
|
||||
return qsl("%1.%2.%3.%4"
|
||||
@@ -409,15 +409,15 @@ void SpecialConfigRequest::handleResponse(const QByteArray &bytes) {
|
||||
switch (address.type()) {
|
||||
case mtpc_ipPort: {
|
||||
const auto &fields = address.c_ipPort();
|
||||
_callback(dcId, parseIp(fields.vipv4), fields.vport.v, {});
|
||||
_callback(dcId, parseIp(fields.vipv4()), fields.vport().v, {});
|
||||
} break;
|
||||
case mtpc_ipPortSecret: {
|
||||
const auto &fields = address.c_ipPortSecret();
|
||||
_callback(
|
||||
dcId,
|
||||
parseIp(fields.vipv4),
|
||||
fields.vport.v,
|
||||
bytes::make_span(fields.vsecret.v));
|
||||
parseIp(fields.vipv4()),
|
||||
fields.vport().v,
|
||||
bytes::make_span(fields.vsecret().v));
|
||||
} break;
|
||||
default: Unexpected("Type in simpleConfig ips.");
|
||||
}
|
||||
|
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "mtproto/type_utils.h"
|
||||
|
||||
const MTPVector<MTPMessageEntity> MTPnullEntities = MTP_vector<MTPMessageEntity>(0);
|
@@ -136,5 +136,3 @@ enum class MTPDchannel_ClientFlag : uint32 {
|
||||
MIN_FIELD = (1U << 31),
|
||||
};
|
||||
DEFINE_MTP_CLIENT_FLAGS(MTPDchannel)
|
||||
|
||||
extern const MTPVector<MTPMessageEntity> MTPnullEntities;
|
||||
|
Reference in New Issue
Block a user