tdesktop/Telegram/SourceFiles/mtproto/mtproto_rpc_sender.cpp

54 lines
1.4 KiB
C++
Raw Normal View History

/*
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
*/
2019-11-18 09:28:14 +00:00
#include "mtproto/mtproto_rpc_sender.h"
#include <QtCore/QRegularExpression>
2018-06-02 14:29:21 +00:00
RPCError::RPCError(const MTPrpcError &error)
2019-07-05 13:38:38 +00:00
: _code(error.c_rpc_error().verror_code().v) {
QString text = qs(error.c_rpc_error().verror_message());
2018-06-02 14:29:21 +00:00
if (_code < 0 || _code >= 500) {
2019-11-18 09:28:14 +00:00
_type = "INTERNAL_SERVER_ERROR";
2018-06-02 14:29:21 +00:00
_description = text;
} else {
const auto expression = QRegularExpression(
"^([A-Z0-9_]+)(: .*)?$",
2019-11-18 09:28:14 +00:00
(QRegularExpression::DotMatchesEverythingOption
| QRegularExpression::MultilineOption));
2018-06-02 14:29:21 +00:00
const auto match = expression.match(text);
if (match.hasMatch()) {
_type = match.captured(1);
_description = match.captured(2).mid(2);
} else {
2019-11-18 09:28:14 +00:00
_type = "CLIENT_BAD_RPC_ERROR";
_description = "Bad rpc error received, text = '" + text + '\'';
2018-06-02 14:29:21 +00:00
}
}
}
RPCOwnedDoneHandler::RPCOwnedDoneHandler(RPCSender *owner) : _owner(owner) {
2018-06-02 14:29:21 +00:00
_owner->rpcRegHandler(this);
}
RPCOwnedDoneHandler::~RPCOwnedDoneHandler() {
2018-06-02 14:29:21 +00:00
if (_owner) {
_owner->rpcUnregHandler(this);
}
}
RPCOwnedFailHandler::RPCOwnedFailHandler(RPCSender *owner) : _owner(owner) {
2018-06-02 14:29:21 +00:00
_owner->rpcRegHandler(this);
}
RPCOwnedFailHandler::~RPCOwnedFailHandler() {
2018-06-02 14:29:21 +00:00
if (_owner) {
_owner->rpcUnregHandler(this);
}
}