void ContactsRpcOperation::runGetContacts() { TLContactsContacts result; result.tlType = TLValue::ContactsContacts; LocalUser *self = layer()->getUser(); const QVector<UserContact> importedContacts = self->importedContacts(); result.contacts.reserve(importedContacts.size()); result.users.reserve(importedContacts.size()); TLUser userInfo; TLContact outputContact; for (const UserContact &contact : importedContacts) { if (contact.id) { const AbstractUser *contactUser = api()->getAbstractUser(contact.id); Utils::setupTLUser(&userInfo, contactUser, self); result.users.append(userInfo); outputContact.userId = contact.id; outputContact.mutual = userInfo.flags & TLUser::MutualContact; result.contacts.append(outputContact); } else { ++result.savedCount; } } sendRpcReply(result); }
void ContactsRpcOperation::runImportContacts() { qDebug() << Q_FUNC_INFO; TLContactsImportedContacts result; LocalUser *self = layer()->getUser(); for (const TLInputContact &c : m_importContacts.contacts) { UserContact contact; contact.phone = api()->normalizeIdentifier(c.phone); contact.firstName = c.firstName; contact.lastName = c.lastName; AbstractUser *registeredUser = api()->getAbstractUser(contact.phone); if (registeredUser) { contact.id = registeredUser->id(); } else { result.retryContacts.append(c.clientId); } self->importContact(contact); if (registeredUser) { result.users.append(TLUser()); Utils::setupTLUser(&result.users.last(), registeredUser, self); TLImportedContact imported; imported.clientId = c.clientId; imported.userId = contact.id; result.imported.append(imported); } } sendRpcReply(result); }
void PhoneRpcOperation::runGetCallConfig() { if (processNotImplementedMethod(TLValue::PhoneGetCallConfig)) { return; } TLDataJSON result; sendRpcReply(result); }
void ContactsRpcOperation::runGetStatuses() { if (processNotImplementedMethod(TLValue::ContactsGetStatuses)) { return; } TLVector<TLContactStatus> result; sendRpcReply(result); }
void ContactsRpcOperation::runExportCard() { if (processNotImplementedMethod(TLValue::ContactsExportCard)) { return; } TLVector<quint32> result; sendRpcReply(result); }
void LangpackRpcOperation::runGetLanguages() { if (processNotImplementedMethod(TLValue::LangpackGetLanguages)) { return; } TLVector<TLLangPackLanguage> result; sendRpcReply(result); }
void ContactsRpcOperation::runResetSaved() { if (processNotImplementedMethod(TLValue::ContactsResetSaved)) { return; } bool result; sendRpcReply(result); }
void LangpackRpcOperation::runGetLangPack() { // TLFunctions::TLLangpackGetLangPack &arguments = m_getLangPack; if (processNotImplementedMethod(TLValue::LangpackGetLangPack)) { return; } TLLangPackDifference result; sendRpcReply(result); }
void LangpackRpcOperation::runGetStrings() { // TLFunctions::TLLangpackGetStrings &arguments = m_getStrings; if (processNotImplementedMethod(TLValue::LangpackGetStrings)) { return; } TLVector<TLLangPackString> result; sendRpcReply(result); }
void ContactsRpcOperation::runUnblock() { // TLFunctions::TLContactsUnblock &arguments = m_unblock; if (processNotImplementedMethod(TLValue::ContactsUnblock)) { return; } bool result; sendRpcReply(result); }
void ContactsRpcOperation::runDeleteContacts() { // TLFunctions::TLContactsDeleteContacts &arguments = m_deleteContacts; if (processNotImplementedMethod(TLValue::ContactsDeleteContacts)) { return; } bool result; sendRpcReply(result); }
// Generated run methods void PhoneRpcOperation::runAcceptCall() { // TLFunctions::TLPhoneAcceptCall &arguments = m_acceptCall; if (processNotImplementedMethod(TLValue::PhoneAcceptCall)) { return; } TLPhonePhoneCall result; sendRpcReply(result); }
void PhoneRpcOperation::runSaveCallDebug() { // TLFunctions::TLPhoneSaveCallDebug &arguments = m_saveCallDebug; if (processNotImplementedMethod(TLValue::PhoneSaveCallDebug)) { return; } bool result; sendRpcReply(result); }
void ContactsRpcOperation::runImportCard() { // TLFunctions::TLContactsImportCard &arguments = m_importCard; if (processNotImplementedMethod(TLValue::ContactsImportCard)) { return; } TLUser result; sendRpcReply(result); }
void ContactsRpcOperation::runGetTopPeers() { // TLFunctions::TLContactsGetTopPeers &arguments = m_getTopPeers; if (processNotImplementedMethod(TLValue::ContactsGetTopPeers)) { return; } TLContactsTopPeers result; sendRpcReply(result); }
void ContactsRpcOperation::runGetBlocked() { // TLFunctions::TLContactsGetBlocked &arguments = m_getBlocked; if (processNotImplementedMethod(TLValue::ContactsGetBlocked)) { return; } TLContactsBlocked result; sendRpcReply(result); }
void PhoneRpcOperation::runDiscardCall() { // TLFunctions::TLPhoneDiscardCall &arguments = m_discardCall; if (processNotImplementedMethod(TLValue::PhoneDiscardCall)) { return; } TLUpdates result; sendRpcReply(result); }
void ContactsRpcOperation::runResetTopPeerRating() { // TLFunctions::TLContactsResetTopPeerRating &arguments = m_resetTopPeerRating; if (processNotImplementedMethod(TLValue::ContactsResetTopPeerRating)) { return; } bool result; sendRpcReply(result); }
void PhoneRpcOperation::runReceivedCall() { // TLFunctions::TLPhoneReceivedCall &arguments = m_receivedCall; if (processNotImplementedMethod(TLValue::PhoneReceivedCall)) { return; } bool result; sendRpcReply(result); }
void ContactsRpcOperation::runResolveUsername() { TLFunctions::TLContactsResolveUsername &arguments = m_resolveUsername; TLContactsResolvedPeer result; const Peer peer = api()->getPeerByUserName(arguments.username); result.peer = Telegram::Utils::toTLPeer(peer); Utils::setupTLPeers(&result, { peer }, api(), layer()->getUser()); sendRpcReply(result); }
void PhoneRpcOperation::runSetCallRating() { // TLFunctions::TLPhoneSetCallRating &arguments = m_setCallRating; if (processNotImplementedMethod(TLValue::PhoneSetCallRating)) { return; } TLUpdates result; sendRpcReply(result); }
void ContactsRpcOperation::runSearch() { // TLFunctions::TLContactsSearch &arguments = m_search; if (processNotImplementedMethod(TLValue::ContactsSearch)) { return; } TLContactsFound result; sendRpcReply(result); }
void RpcConnection::on_clientSock_dataAvail() { uchar msg[PB_HDR_SIZE]; int msgLen; quint16 type, method; quint32 len; const ::google::protobuf::MethodDescriptor *methodDesc; ::google::protobuf::Message *req, *resp; PbRpcController *controller; QString error; bool disconnect = false; // Do we have enough bytes for a msg header? // If yes, peek into the header and get msg length if (clientSock->bytesAvailable() < PB_HDR_SIZE) return; msgLen = clientSock->peek((char*)msg, PB_HDR_SIZE); if (msgLen != PB_HDR_SIZE) { qWarning("asked to peek %d bytes, was given only %d bytes", PB_HDR_SIZE, msgLen); return; } len = qFromBigEndian<quint32>(&msg[4]); // Is the full msg available to read? If not, wait till such time if (clientSock->bytesAvailable() < (PB_HDR_SIZE+len)) return; msgLen = clientSock->read((char*)msg, PB_HDR_SIZE); Q_ASSERT(msgLen == PB_HDR_SIZE); type = qFromBigEndian<quint16>(&msg[0]); method = qFromBigEndian<quint16>(&msg[2]); len = qFromBigEndian<quint32>(&msg[4]); //qDebug("type = %d, method = %d, len = %d", type, method, len); if (type != PB_MSG_TYPE_REQUEST) { qDebug("server(%s): unexpected msg type %d (expected %d)", __FUNCTION__, type, PB_MSG_TYPE_REQUEST); error = QString("unexpected msg type %1; expected %2") .arg(type).arg(PB_MSG_TYPE_REQUEST); goto _error_exit; } // If RPC is not checkVersion, ensure compat check is already done if (!isCompatCheckDone && method != 15) { qDebug("server(%s): version compatibility check pending", __FUNCTION__); error = "version compatibility check pending"; disconnect = true; goto _error_exit; } if (method >= service->GetDescriptor()->method_count()) { qDebug("server(%s): invalid method id %d", __FUNCTION__, method); error = QString("invalid RPC method %1").arg(method); goto _error_exit; } methodDesc = service->GetDescriptor()->method(method); if (!methodDesc) { qDebug("server(%s): invalid method id %d", __FUNCTION__, method); error = QString("invalid RPC method %1").arg(method); goto _error_exit; } if (isPending) { qDebug("server(%s): rpc pending, try again", __FUNCTION__); error = QString("RPC %1() is pending; only one RPC allowed at a time; " "try again!").arg(QString::fromStdString( service->GetDescriptor()->method( pendingMethodId)->name())); goto _error_exit; } pendingMethodId = method; isPending = true; req = service->GetRequestPrototype(methodDesc).New(); resp = service->GetResponsePrototype(methodDesc).New(); if (len) { bool ok = req->ParseFromBoundedZeroCopyStream(inStream, len); if (!ok) qWarning("ParseFromBoundedZeroCopyStream fail " "for method %d and len %d", method, len); } if (!req->IsInitialized()) { qWarning("Missing required fields in request <----"); qDebug("method = %d\n" "req = \n%s" "missing = \n%s----->", method, req->DebugString().c_str(), req->InitializationErrorString().c_str()); error = QString("RPC %1() missing required fields in request - %2") .arg(QString::fromStdString( service->GetDescriptor()->method( pendingMethodId)->name()), QString(req->InitializationErrorString().c_str())); delete req; delete resp; goto _error_exit2; } if (method != 13) { qDebug("Server(%s): successfully received/parsed msg <----", __FUNCTION__); qDebug("method = %d\n" "req = \n%s---->", method, req->DebugString().c_str()); } controller = new PbRpcController(req, resp); //qDebug("before service->callmethod()"); service->CallMethod(methodDesc, controller, req, resp, google::protobuf::NewCallback(this, &RpcConnection::sendRpcReply, controller)); return; _error_exit: inStream->Skip(len); _error_exit2: qDebug("server(%s): return error %s for msg from client", __FUNCTION__, qPrintable(error)); pendingMethodId = method; isPending = true; controller = new PbRpcController(NULL, NULL); controller->SetFailed(error); if (disconnect) controller->TriggerDisconnect(); sendRpcReply(controller); return; }
void ContactsRpcOperation::runDeleteContact() { qWarning() << Q_FUNC_INFO << "The method implemented!"; TLContactsLink result; sendRpcReply(result); }