Exemple #1
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::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);
}