void Session::workUpdatesCombined(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workUpdatesCombined: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdatesCombined);
    //updates
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_Vector);
    qint32 n = inboundPkt.fetchInt();
    QList<Update> updates;
    for (qint32 i = 0; i < n; i++) {
        updates.append(inboundPkt.fetchUpdate());
    }
    //users
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_Vector);
    n = inboundPkt.fetchInt();
    QList<User> users;
    for (qint32 i = 0; i < n; i++) {
        users.append(inboundPkt.fetchUser());
    }
    //chats
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_Vector);
    n = inboundPkt.fetchInt();
    QList<Chat> chats;
    for (qint32 i = 0; i < n; i++) {
        chats.append(inboundPkt.fetchChat());
    }
    qint32 date = inboundPkt.fetchInt();
    qint32 seqStart = inboundPkt.fetchInt();
    qint32 seq = inboundPkt.fetchInt();
    Q_EMIT updatesCombined(updates, users, chats, date, seqStart, seq);
}
void Session::workNewDetailedInfo(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workNewDetailedInfo: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_MsgNewDetailedInfo);
    inboundPkt.fetchLong(); // answer_msg_id
    inboundPkt.fetchInt(); // bytes
    inboundPkt.fetchInt(); // status
}
Esempio n. 3
0
void Session::workBadMsgNotification(InboundPkt &inboundPkt, qint64 msgId) {
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadMsgNotification);
    qint64 badMsgId = inboundPkt.fetchLong();
    qint32 badMsgSeqNo = inboundPkt.fetchInt();
    qint32 errorCode = inboundPkt.fetchInt();
    qCWarning(TG_CORE_SESSION) << "workBadMsgNotification: badMsgId =" << QString::number(badMsgId, 16) <<
            ", badMsgSeqNo =" << badMsgSeqNo << ", errorCode =" << errorCode;
    switch (errorCode) {
    case 16:
    case 17:
    case 19:
    case 32:
    case 33:
    case 64:
        // update time sync difference and reset msgIds counter
        qint32 serverTime = msgId >> 32LL;
        mTimeDifference = QDateTime::currentDateTime().toTime_t() - serverTime;

        qint64 nextId = generatePlainNextMsgId();
        if (!m_pendingQueries.contains(nextId)) {
            m_clientLastMsgId = 0;
        }

        // read removing from pending queries, recompose and send the last query
        Query *q = m_pendingQueries.take(badMsgId);
        qint64 newMsgId = recomposeAndSendQuery(q);
        if (newMsgId != 0) {
            Q_EMIT updateMessageId(badMsgId, newMsgId);
        }
        break;
    }
}
void Session::workUpdateShortChatMessage(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workUpdateShortChatMessage: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdateShortChatMessage);
    qint32 flags = inboundPkt.fetchInt();
    qint32 id = inboundPkt.fetchInt();
    qint32 fromId = inboundPkt.fetchInt();
    qint32 chatId = inboundPkt.fetchInt();
    QString message = inboundPkt.fetchQString();
    qint32 pts = inboundPkt.fetchInt();
    qint32 pts_count = inboundPkt.fetchInt();
    qint32 date = inboundPkt.fetchInt();
    qint32 fwd_from_id = 0;
    qint32 fwd_date = 0;
    qint32 reply_to_msg_id = 0;
    bool unread = (flags & 1<<0);
    bool out = (flags & 1<<1);
    if(flags & (1<<2)) {
        fwd_from_id = inboundPkt.fetchInt();
        fwd_date = inboundPkt.fetchInt();
    }
    if(flags & (1<<3)) {
        reply_to_msg_id = inboundPkt.fetchInt();
    }
    Q_EMIT updateShortChatMessage(id, fromId, chatId, message, pts, pts_count, date, fwd_from_id, fwd_date, reply_to_msg_id, unread, out);
}
void Session::workUpdateShort(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workUpdateShort: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdateShort);
    Update update = inboundPkt.fetchUpdate();
    qint32 date = inboundPkt.fetchInt();
    Q_EMIT updateShort(update, date);
}
void Session::workBadServerSalt(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workBadServerSalt: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadServerSalt);
    qint64 badMsgId = inboundPkt.fetchLong();
    inboundPkt.fetchInt(); // badMsgSeqNo
    inboundPkt.fetchInt(); // errorCode
    m_dc->setServerSalt(inboundPkt.fetchLong()); // new server_salt
    // resend the last query
    Query *q = m_pendingQueries.value(badMsgId);
    if(q)
        resendQuery(q);
}
Esempio n. 7
0
void Session::queryOnError(InboundPkt &inboundPkt, qint64 msgId) {
    mAsserter.check(inboundPkt.fetchInt() == TL_RpcError);
    qint32 errorCode = inboundPkt.fetchInt();
    QString errorText = inboundPkt.fetchQString();
    qCDebug(TG_CORE_SESSION) << "error for query" << QString::number(msgId, 16) << " :" << errorCode << " :" << errorText;

    Query *q = m_pendingQueries.take(msgId);
    if (!q) {
        qCWarning(TG_CORE_SESSION) << "No such query";
    } else {
        q->setAcked(true);
        Q_EMIT errorReceived(q, errorCode, errorText);
    }
}
void Session::workMsgsAck(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workMsgsAck: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_MsgsAck);
    mAsserter.check(inboundPkt.fetchInt () == (qint32)TL_Vector);
    qint32 n = inboundPkt.fetchInt();
    for (qint32 i = 0; i < n; i++) {
        qint64 id = inboundPkt.fetchLong ();
        Query *q = m_pendingQueries.value(id);
        if(!q)
            return;

        Q_ASSERT(q);
        q->setAcked(true);
    }
}
Esempio n. 9
0
void Session::workBadServerSalt(InboundPkt &inboundPkt, qint64 msgId) {
    Q_UNUSED(msgId)
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadServerSalt);
    qint64 badMsgId = inboundPkt.fetchLong();
    qint32 badMsgSeqNo = inboundPkt.fetchInt();
    qint32 errorCode = inboundPkt.fetchInt();
    qCDebug(TG_CORE_SESSION) << "workBadServerSalt: badMsgId =" << QString::number(badMsgId, 16)
            << ", badMsgSeqNo =" << badMsgSeqNo << ", errorCode =" << errorCode;
    m_dc->setServerSalt(inboundPkt.fetchLong()); // new server_salt
    Query *q = m_pendingQueries.take(badMsgId);
    qint64 newMsgId = recomposeAndSendQuery(q);
    if (newMsgId != 0) {
        Q_EMIT updateMessageId(badMsgId, newMsgId);
    }
}
void Session::workNewSessionCreated(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workNewSessionCreated: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_NewSessionCreated);
    inboundPkt.fetchLong(); // first_msg_id; //XXX set is as m_clientLastMsgId??
    inboundPkt.fetchLong (); // unique_id
    m_dc->setServerSalt(inboundPkt.fetchLong()); // server_salt
}
Esempio n. 11
0
void Session::queryOnResult(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "result for query" << QString::number(msgId, 16);
    qint32 op = inboundPkt.prefetchInt();
    qint32 *inPtr = 0;
    qint32 *inEnd = 0;
    if (op == (qint32)TL_GZipPacked) {
        inboundPkt.fetchInt();
        qint32 l = inboundPkt.prefetchStrlen();
        char *s = inboundPkt.fetchStr(l);
        static qint32 packedBuffer[MAX_PACKED_SIZE / 4];
        qint32 totalOut = Utils::tinflate (s, l, packedBuffer, MAX_PACKED_SIZE);
        inPtr = inboundPkt.inPtr();
        inEnd = inboundPkt.inEnd();
        inboundPkt.setInPtr(packedBuffer);
        inboundPkt.setInEnd(inboundPkt.inPtr() + totalOut / 4);
        qCDebug(TG_CORE_SESSION) << "unzipped data";
    }

    Query *q = m_pendingQueries.take(msgId);
    if (!q) {
        qCWarning(TG_CORE_SESSION) << "No such query";
        inboundPkt.setInPtr(inboundPkt.inEnd());
    } else {
        qCDebug(TG_CORE_SESSION) << "acked query with msgId" << QString::number(msgId, 16) << ",pendingQueries:" << m_pendingQueries.size();
        q->setAcked(true);
        Q_EMIT resultReceived(q, inboundPkt);
    }

    if (inPtr) {
        inboundPkt.setInPtr(inPtr);
        inboundPkt.setInEnd(inEnd);
    }
}
void Session::workContainer (InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workContainer: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == TL_MsgContainer);
    qint32 n = inboundPkt.fetchInt();
    for (qint32 i = 0; i < n; i++) { // message
        qint64 id = inboundPkt.fetchLong (); // msg_id
        if (id & 1) {
           addToPendingAcks(id);
        }
        inboundPkt.fetchInt (); // seq_no
        qint32 bytes = inboundPkt.fetchInt ();
        qint32 *t = inboundPkt.inEnd();
        inboundPkt.setInEnd(inboundPkt.inPtr() + (bytes / 4));
        rpcExecuteAnswer(inboundPkt, id);
        Q_ASSERT (inboundPkt.inPtr() == inboundPkt.inEnd());
        inboundPkt.setInEnd(t);
    }
}
void Session::workBadMsgNotification(InboundPkt &inboundPkt, qint64 msgId) {
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadMsgNotification);
    qint64 badMsgId = inboundPkt.fetchLong();
    qint32 badMsgSeqNo = inboundPkt.fetchInt();
    qint32 errorCode = inboundPkt.fetchInt();
    qCWarning(TG_CORE_SESSION) << "workBadMsgNotification: msgId =" << badMsgId <<
                  ", seqNo =" << badMsgSeqNo << ", errorCode =" << errorCode;
    switch (errorCode) {
    case 16:
    case 17:
        // update time sync difference and reset msgIds counter
        qint32 serverTime = msgId >> 32LL;
        mTimeDifference = QDateTime::currentDateTime().toTime_t() - serverTime;
        m_clientLastMsgId = 0;
        // read removing from pending queries, recompose and send the last query
        Query *q = m_pendingQueries.take(badMsgId);
        recomposeAndSendQuery(q);
        break;
    }
}
void Session::workRpcResult(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workRpcResult: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_RpcResult);
    qint64 id = inboundPkt.fetchLong();
    qint32 op = inboundPkt.prefetchInt();
    if (op == (qint32)TL_RpcError) {
        queryOnError(inboundPkt, id);
    } else {
        queryOnResult(inboundPkt, id);
    }
}
void Session::workPacked(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workPacked: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_GZipPacked);
    static qint32 buf[MAX_PACKED_SIZE >> 2];
    qint32 l = inboundPkt.prefetchStrlen();
    char *s = inboundPkt.fetchStr(l);

    qint32 totalOut = Utils::tinflate(s, l, buf, MAX_PACKED_SIZE);
    qint32 *inPtr = inboundPkt.inPtr();
    qint32 *inEnd = inboundPkt.inEnd();
    inboundPkt.setInPtr(buf);
    inboundPkt.setInEnd(inboundPkt.inPtr() + totalOut / 4);
    qCDebug(TG_CORE_SESSION) << "Unzipped data";
    rpcExecuteAnswer(inboundPkt, msgId);
    inboundPkt.setInPtr(inPtr); //TODO Not sure about this operations of setting inPtr and inEnd after execute answer completion
    inboundPkt.setInEnd(inEnd);
}
void Session::workUpdatesTooLong(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workUpdatesTooLong: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_UpdatesTooLong);
    Q_EMIT updatesTooLong();
}
void Session::workPong(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workPong: msgId =" << QString::number(msgId, 16);
    mAsserter.check (inboundPkt.fetchInt() == (qint32)TL_Pong);
    inboundPkt.fetchLong(); // msg_id
    inboundPkt.fetchLong(); // ping_id
}