void MTPstring::read(const mtpPrime *&from, const mtpPrime *end, mtpTypeId cons) { if (from + 1 > end) throw mtpErrorInsufficient(); if (cons != mtpc_string) throw mtpErrorUnexpected(cons, "MTPstring"); uint32 l; const uchar *buf = (const uchar*)from; if (buf[0] == 254) { l = (uint32)buf[1] + ((uint32)buf[2] << 8) + ((uint32)buf[3] << 16); buf += 4; from += ((l + 4) >> 2) + (((l + 4) & 0x03) ? 1 : 0); } else {
void execCallback(mtpRequestId requestId, const mtpPrime *from, const mtpPrime *end) { RPCResponseHandler h; { QMutexLocker locker(&parserMapLock); ParserMap::iterator i = parserMap.find(requestId); if (i != parserMap.cend()) { h = i.value(); parserMap.erase(i); DEBUG_LOG(("RPC Info: found parser for request %1, trying to parse response..").arg(requestId)); } } if (h.onDone || h.onFail) { try { if (from >= end) throw mtpErrorInsufficient(); if (*from == mtpc_rpc_error) { RPCError err(MTPRpcError(from, end)); DEBUG_LOG(("RPC Info: error received, code %1, type %2, description: %3").arg(err.code()).arg(err.type()).arg(err.description())); if (!rpcErrorOccured(requestId, h, err)) { QMutexLocker locker(&parserMapLock); parserMap.insert(requestId, h); return; } } else { if (h.onDone) (*h.onDone)(requestId, from, end); } } catch (Exception &e) { if (!rpcErrorOccured(requestId, h, rpcClientError("RESPONSE_PARSE_FAILED", QString("exception text: ") + e.what()))) { QMutexLocker locker(&parserMapLock); parserMap.insert(requestId, h); return; } } } else { DEBUG_LOG(("RPC Info: parser not found for %1").arg(requestId)); } unregisterRequest(requestId); }