some changes made to debug tl text serialize
This commit is contained in:
parent
8c668cfa24
commit
ccba1c8c6f
|
@ -1,3 +1,6 @@
|
|||
cd ..\Win32\Deploy
|
||||
Prepare.exe -path Telegram.exe -path Updater.exe
|
||||
call ..\..\..\TelegramPrivate\Sign.bat tsetup.0.6.4.exe
|
||||
call Prepare.exe -path Telegram.exe -path Updater.exe
|
||||
mkdir deploy\0.6.4\Telegram
|
||||
move deploy\0.6.4\Telegram.exe deploy\0.6.4\Telegram\
|
||||
cd ..\..\Telegram
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
cd ..\Win32\Deploy
|
||||
call ..\..\..\TelegramPrivate\Sign.bat tsetup.0.6.4.exe
|
||||
cd ..\..\Telegram
|
|
@ -43,6 +43,8 @@ enum {
|
|||
|
||||
MTPEnumDCTimeout = 4000, // 4 seconds timeout for help_getConfig to work (them move to other dc)
|
||||
|
||||
MTPDebugBufferSize = 1024 * 1024, // 1 mb start size
|
||||
|
||||
MinReceiveDelay = 1000, // 1 seconds
|
||||
MaxSelectedItems = 100,
|
||||
|
||||
|
|
|
@ -49,15 +49,15 @@ inline DebugLogMemoryBuffer mb(const void *ptr, uint32 size) {
|
|||
}
|
||||
|
||||
void debugLogWrite(const char *file, int32 line, const QString &v);
|
||||
#define DEBUG_LOG(msg) (debugLogWrite(__FILE__, __LINE__, QString msg))
|
||||
#define DEBUG_LOG(msg) { if (cDebug()) debugLogWrite(__FILE__, __LINE__, QString msg); }
|
||||
//usage DEBUG_LOG(("log: %1 %2").arg(1).arg(2))
|
||||
|
||||
void tcpLogWrite(const QString &v);
|
||||
#define TCP_LOG(msg) (tcpLogWrite(QString msg))
|
||||
#define TCP_LOG(msg) { if (cDebug()) tcpLogWrite(QString msg); }
|
||||
//usage TCP_LOG(("log: %1 %2").arg(1).arg(2))
|
||||
|
||||
void mtpLogWrite(int32 dc, const QString &v);
|
||||
#define MTP_LOG(dc, msg) (mtpLogWrite(dc, QString msg))
|
||||
#define MTP_LOG(dc, msg) { if (cDebug()) mtpLogWrite(dc, QString msg); }
|
||||
//usage MTP_LOG(dc, ("log: %1 %2").arg(1).arg(2))
|
||||
|
||||
#else
|
||||
|
|
|
@ -256,11 +256,12 @@ def addTextSerialize(dct):
|
|||
if len(result):
|
||||
result += '\n';
|
||||
result += '\t\tcase mtpc_' + name + ':\n';
|
||||
result += '\t\t\tto.add("{ ' + name + '");\n';
|
||||
if (len(prms)):
|
||||
result += '\t\t\tresult += "\\n" + add;\n';
|
||||
result += '\t\t\tto.add("\\n").add(add);\n';
|
||||
for k in prmsList:
|
||||
v = prms[k];
|
||||
result += '\t\t\tresult += " ' + k + ': " + mtpTextSerialize(from, end';
|
||||
result += '\t\t\tto.add(" ' + k + ': "); mtpTextSerializeType(to, from, end';
|
||||
vtypeget = re.match(r'^[Vv]ector<MTP([A-Za-z0-9\._]+)>', v);
|
||||
if (vtypeget):
|
||||
if (not re.match(r'^[A-Z]', v)):
|
||||
|
@ -298,10 +299,10 @@ def addTextSerialize(dct):
|
|||
else:
|
||||
if (not vtypeget):
|
||||
result += ', 0, level + 1';
|
||||
result += ') + ",\\n" + add;\n';
|
||||
result += '); to.add(",\\n").add(add);\n';
|
||||
else:
|
||||
result += '\t\t\tresult = " ";\n';
|
||||
result += '\t\treturn "{ ' + name + '" + result + "}";\n';
|
||||
result += '\t\t\tto.add(" ");\n';
|
||||
result += '\t\t\tto.add("}");\n\t\tbreak;\n';
|
||||
return result;
|
||||
|
||||
textSerialize += addTextSerialize(typesDict) + '\n';
|
||||
|
@ -571,7 +572,7 @@ for restype in typesList:
|
|||
inlineMethods += creatorsText;
|
||||
typesText += 'typedef MTPBoxed<MTP' + restype + '> MTP' + resType + ';\n'; # boxed type definition
|
||||
|
||||
textSerializeFull = '\ninline QString mtpTextSerialize(const mtpPrime *&from, const mtpPrime *end, mtpPrime cons, uint32 level, mtpPrime vcons) {\n';
|
||||
textSerializeFull = '\nvoid mtpTextSerializeType(MTPStringLogger &to, const mtpPrime *&from, const mtpPrime *end, mtpPrime cons, uint32 level, mtpPrime vcons) {\n';
|
||||
textSerializeFull += '\tQString add = QString(" ").repeated(level * 2);\n\n';
|
||||
textSerializeFull += '\tconst mtpPrime *start = from;\n';
|
||||
textSerializeFull += '\ttry {\n';
|
||||
|
@ -583,14 +584,13 @@ textSerializeFull += '\t\t\tcons = *from;\n';
|
|||
textSerializeFull += '\t\t\t++from;\n';
|
||||
textSerializeFull += '\t\t\t++start;\n';
|
||||
textSerializeFull += '\t\t}\n\n';
|
||||
textSerializeFull += '\t\tQString result;\n';
|
||||
textSerializeFull += '\t\tswitch (mtpTypeId(cons)) {\n' + textSerialize + '\t\t}\n\n';
|
||||
textSerializeFull += '\t\treturn mtpTextSerializeCore(from, end, cons, level, vcons);\n';
|
||||
textSerializeFull += '\t\tswitch (mtpTypeId(cons)) {\n' + textSerialize;
|
||||
textSerializeFull += '\n\n\t\tdefault:\n\t\t\tmtpTextSerializeCore(to, from, end, cons, level, vcons);\n\t\tbreak;\n\t\t}\n\n';
|
||||
textSerializeFull += '\t} catch (Exception &e) {\n';
|
||||
textSerializeFull += '\t\tQString result = "(" + QString(e.what()) + QString("), cons: %1").arg(cons);\n';
|
||||
textSerializeFull += '\t\tif (vcons) result += QString(", vcons: %1").arg(vcons);\n';
|
||||
textSerializeFull += '\t\tresult += ", " + mb(start, (end - start) * sizeof(mtpPrime)).str();\n';
|
||||
textSerializeFull += '\t\treturn "[ERROR] " + result;\n';
|
||||
textSerializeFull += '\t\tto.add("[ERROR] ");\n';
|
||||
textSerializeFull += '\t\tto.add("(").add(e.what()).add("), cons: 0x").add(mtpWrapNumber(cons, 16));\n';
|
||||
textSerializeFull += '\t\tif (vcons) to.add(", vcons: 0x").add(mtpWrapNumber(vcons));\n';
|
||||
textSerializeFull += '\t\tto.add(", ").add(mb(start, (end - start) * sizeof(mtpPrime)).str());\n';
|
||||
textSerializeFull += '\t}\n';
|
||||
textSerializeFull += '}\n';
|
||||
|
||||
|
@ -601,6 +601,32 @@ out.write('\n// Type classes definitions\n' + typesText);
|
|||
out.write('\n// Type constructors with data\n' + dataTexts);
|
||||
out.write('\n// RPC methods\n' + funcsText);
|
||||
out.write('\n// Inline methods definition\n' + inlineMethods);
|
||||
out.write('\n// Human-readable text serialization\n#if (defined _DEBUG || defined _WITH_DEBUG)\n' + textSerializeFull + '\n#endif\n');
|
||||
out.write('\n// Human-readable text serialization\n#if (defined _DEBUG || defined _WITH_DEBUG)\n\nvoid mtpTextSerializeType(MTPStringLogger &to, const mtpPrime *&from, const mtpPrime *end, mtpPrime cons, uint32 level, mtpPrime vcons);\n\n#endif\n');
|
||||
|
||||
outCpp = open('mtpScheme.cpp', 'w');
|
||||
outCpp.write('/*\n');
|
||||
outCpp.write('Created from \'/SourceFiles/mtproto/scheme.tl\' by \'/SourceFiles/mtproto/generate.py\' script\n\n');
|
||||
outCpp.write('WARNING! All changes made in this file will be lost!\n\n');
|
||||
outCpp.write('This file is part of Telegram Desktop,\n');
|
||||
outCpp.write('an unofficial desktop messaging app, see https://telegram.org\n');
|
||||
outCpp.write('\n');
|
||||
outCpp.write('Telegram Desktop is free software: you can redistribute it and/or modify\n');
|
||||
outCpp.write('it under the terms of the GNU General Public License as published by\n');
|
||||
outCpp.write('the Free Software Foundation, either version 3 of the License, or\n');
|
||||
outCpp.write('(at your option) any later version.\n');
|
||||
outCpp.write('\n');
|
||||
outCpp.write('It is distributed in the hope that it will be useful,\n');
|
||||
outCpp.write('but WITHOUT ANY WARRANTY; without even the implied warranty of\n');
|
||||
outCpp.write('MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n');
|
||||
outCpp.write('GNU General Public License for more details.\n');
|
||||
outCpp.write('\n');
|
||||
outCpp.write('Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE\n');
|
||||
outCpp.write('Copyright (c) 2014 John Preston, https://tdesktop.com\n');
|
||||
outCpp.write('*/\n');
|
||||
outCpp.write('#include "stdafx.h"\n#include "mtpScheme.h"\n\n');
|
||||
outCpp.write('#if (defined _DEBUG || defined _WITH_DEBUG)\n\n');
|
||||
outCpp.write(textSerializeFull + '\n#endif\n');
|
||||
|
||||
print('Done, written {0} constructors, {1} functions.'.format(consts, funcs));
|
||||
|
||||
print('Done, written {0} constructors, {1} functions.'.format(consts, funcs));
|
||||
|
|
|
@ -1751,9 +1751,7 @@ void MTProtoConnectionPrivate::handleReceived() {
|
|||
int32 res = 1; // if no need to handle, then succeed
|
||||
end = data + 8 + (msgLen >> 2);
|
||||
const mtpPrime *sfrom(data + 4);
|
||||
if (cDebug()) {
|
||||
MTP_LOG(dc, ("Recv: ") + mtpTextSerialize(sfrom, end, mtpc_core_message));
|
||||
}
|
||||
MTP_LOG(dc, ("Recv: ") + mtpTextSerialize(sfrom, end));
|
||||
|
||||
bool needToHandle = false;
|
||||
{
|
||||
|
@ -3110,9 +3108,7 @@ bool MTProtoConnectionPrivate::sendRequest(mtpRequest &request, bool needAnyResp
|
|||
memcpy(request->data() + 2, &session, 2 * sizeof(mtpPrime));
|
||||
|
||||
const mtpPrime *from = request->constData() + 4;
|
||||
if (cDebug()) {
|
||||
MTP_LOG(dc, ("Send: ") + mtpTextSerialize(from, from + messageSize, mtpc_core_message));
|
||||
}
|
||||
MTP_LOG(dc, ("Send: ") + mtpTextSerialize(from, from + messageSize));
|
||||
|
||||
uchar encryptedSHA[20];
|
||||
MTPint128 &msgKey(*(MTPint128*)(encryptedSHA + 4));
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
an unofficial desktop messaging app, see https://telegram.org
|
||||
|
||||
Telegram Desktop is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
||||
Copyright (c) 2014 John Preston, https://tdesktop.com
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "mtpCoreTypes.h"
|
||||
|
||||
QString mtpWrapNumber(float64 number) {
|
||||
return QString::number(number);
|
||||
}
|
||||
|
||||
void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpPrime *end, mtpTypeId cons, uint32 level, mtpPrime vcons) {
|
||||
QString add = QString(" ").repeated(level * 2);
|
||||
|
||||
switch (mtpTypeId(cons)) {
|
||||
case mtpc_int: {
|
||||
MTPint value(from, end, cons);
|
||||
to.add(mtpWrapNumber(value.v)).add(" [INT]");
|
||||
} break;
|
||||
|
||||
case mtpc_long: {
|
||||
MTPlong value(from, end, cons);
|
||||
to.add(mtpWrapNumber(value.v)).add(" [LONG]");
|
||||
} break;
|
||||
|
||||
case mtpc_int128: {
|
||||
MTPint128 value(from, end, cons);
|
||||
to.add(mtpWrapNumber(value.h)).add(" * 2^64 + ").add(mtpWrapNumber(value.l)).add(" [INT128]");
|
||||
} break;
|
||||
|
||||
case mtpc_int256: {
|
||||
MTPint256 value(from, end, cons);
|
||||
to.add(mtpWrapNumber(value.h.h)).add(" * 2^192 + ").add(mtpWrapNumber(value.h.l)).add(" * 2^128 + ").add(mtpWrapNumber(value.l.h)).add(" * 2 ^ 64 + ").add(mtpWrapNumber(value.l.l)).add(" [INT256]");
|
||||
} break;
|
||||
|
||||
case mtpc_double: {
|
||||
MTPdouble value(from, end, cons);
|
||||
to.add(mtpWrapNumber(value.v)).add(" [DOUBLE]");
|
||||
} break;
|
||||
|
||||
case mtpc_string: {
|
||||
MTPstring value(from, end, cons);
|
||||
QByteArray strUtf8(value.c_string().v.c_str(), value.c_string().v.length());
|
||||
QString str = QString::fromUtf8(strUtf8);
|
||||
if (str.toUtf8() == strUtf8) {
|
||||
to.add("\"").add(str.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n")).add("\" [STRING]");
|
||||
} else {
|
||||
to.add(mb(strUtf8.constData(), strUtf8.size()).str()).add(" [").add(mtpWrapNumber(strUtf8.size())).add(" BYTES]");
|
||||
}
|
||||
} break;
|
||||
|
||||
case mtpc_boolTrue:
|
||||
case mtpc_boolFalse: {
|
||||
MTPbool value(from, end, cons);
|
||||
to.add(value.v ? "[TRUE]" : "[FALSE]");
|
||||
} break;
|
||||
|
||||
case mtpc_vector: {
|
||||
if (from >= end) {
|
||||
throw Exception("from >= end in vector");
|
||||
}
|
||||
int32 cnt = *(from++);
|
||||
to.add("[ vector<0x").add(mtpWrapNumber(vcons, 16)).add(">");
|
||||
if (cnt) {
|
||||
to.add("\n").add(add);
|
||||
for (int32 i = 0; i < cnt; ++i) {
|
||||
to.add(" ");
|
||||
mtpTextSerializeType(to, from, end, vcons, level + 1);
|
||||
to.add(",\n").add(add);
|
||||
}
|
||||
} else {
|
||||
to.add(" ");
|
||||
}
|
||||
to.add("]");
|
||||
} break;
|
||||
|
||||
case mtpc_error: {
|
||||
to.add("{ error");
|
||||
to.add("\n").add(add);
|
||||
to.add(" code: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").add(add);
|
||||
to.add(" text: "); mtpTextSerializeType(to, from, end, mtpc_string, level + 1); to.add(",\n").add(add);
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
case mtpc_null: {
|
||||
to.add("{ null");
|
||||
to.add(" ");
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
case mtpc_rpc_result: {
|
||||
to.add("{ rpc_result");
|
||||
to.add("\n").add(add);
|
||||
to.add(" req_msg_id: "); mtpTextSerializeType(to, from, end, mtpc_long, level + 1); to.add(",\n").add(add);
|
||||
to.add(" result: "); mtpTextSerializeType(to, from, end, 0, level + 1); to.add(",\n").add(add);
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
case mtpc_msg_container: {
|
||||
to.add("{ msg_container");
|
||||
to.add("\n").add(add);
|
||||
to.add(" messages: "); mtpTextSerializeType(to, from, end, mtpc_vector, level + 1, mtpc_core_message); to.add(",\n").add(add);
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
case mtpc_core_message: {
|
||||
to.add("{ core_message");
|
||||
to.add("\n").add(add);
|
||||
to.add(" msg_id: "); mtpTextSerializeType(to, from, end, mtpc_long, level + 1); to.add(",\n").add(add);
|
||||
to.add(" seq_no: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").add(add);
|
||||
to.add(" bytes: "); mtpTextSerializeType(to, from, end, mtpc_int, level + 1); to.add(",\n").add(add);
|
||||
to.add(" body: "); mtpTextSerializeType(to, from, end, 0, level + 1); to.add(",\n").add(add);
|
||||
to.add("}");
|
||||
} break;
|
||||
|
||||
case mtpc_gzip_packed: {
|
||||
MTPstring packed(from, end); // read packed string as serialized mtp string type
|
||||
uint32 packedLen = packed.c_string().v.size(), unpackedChunk = packedLen;
|
||||
mtpBuffer result; // * 4 because of mtpPrime type
|
||||
result.resize(0);
|
||||
|
||||
z_stream stream;
|
||||
stream.zalloc = 0;
|
||||
stream.zfree = 0;
|
||||
stream.opaque = 0;
|
||||
stream.avail_in = 0;
|
||||
stream.next_in = 0;
|
||||
int res = inflateInit2(&stream, 16 + MAX_WBITS);
|
||||
if (res != Z_OK) {
|
||||
throw Exception(QString("ungzip init, code: %1").arg(res));
|
||||
}
|
||||
stream.avail_in = packedLen;
|
||||
stream.next_in = (Bytef*)&packed._string().v[0];
|
||||
stream.avail_out = 0;
|
||||
while (!stream.avail_out) {
|
||||
result.resize(result.size() + unpackedChunk);
|
||||
stream.avail_out = unpackedChunk * sizeof(mtpPrime);
|
||||
stream.next_out = (Bytef*)&result[result.size() - unpackedChunk];
|
||||
int res = inflate(&stream, Z_NO_FLUSH);
|
||||
if (res != Z_OK && res != Z_STREAM_END) {
|
||||
inflateEnd(&stream);
|
||||
throw Exception(QString("ungzip unpack, code: %1").arg(res));
|
||||
}
|
||||
}
|
||||
if (stream.avail_out & 0x03) {
|
||||
uint32 badSize = result.size() * sizeof(mtpPrime) - stream.avail_out;
|
||||
throw Exception(QString("ungzip bad length, size: %1").arg(badSize));
|
||||
}
|
||||
result.resize(result.size() - (stream.avail_out >> 2));
|
||||
inflateEnd(&stream);
|
||||
|
||||
if (!result.size()) {
|
||||
throw Exception("ungzip void data");
|
||||
}
|
||||
const mtpPrime *newFrom = result.constData(), *newEnd = result.constData() + result.size();
|
||||
to.add("[GZIPPED] "); mtpTextSerializeType(to, newFrom, newEnd, 0, level);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
for (uint32 i = 1; i < mtpLayerMax; ++i) {
|
||||
if (cons == mtpLayers[i]) {
|
||||
to.add("[LAYER").add(mtpWrapNumber(i + 1)).add("] "); mtpTextSerializeType(to, from, end, 0, level);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw Exception(QString("unknown cons 0x%1").arg(cons, 0, 16));
|
||||
} break;
|
||||
}
|
||||
}
|
|
@ -999,150 +999,52 @@ typedef MTPBoxed<MTPnull> MTPNull;
|
|||
// Human-readable text serialization
|
||||
#if (defined _DEBUG || defined _WITH_DEBUG)
|
||||
|
||||
QString mtpTextSerialize(const mtpPrime *&from, const mtpPrime *end, mtpPrime cons = 0, uint32 level = 0, mtpPrime vcons = 0);
|
||||
template <typename Type>
|
||||
QString mtpWrapNumber(Type number, int32 base = 10) {
|
||||
return QString::number(number, base);
|
||||
}
|
||||
|
||||
inline QString mtpTextSerializeCore(const mtpPrime *&from, const mtpPrime *end, mtpTypeId cons, uint32 level, mtpPrime vcons = 0) {
|
||||
QString add = QString(" ").repeated(level * 2);
|
||||
|
||||
switch (mtpTypeId(cons)) {
|
||||
case mtpc_int: {
|
||||
MTPint value(from, end, cons);
|
||||
return QString("%1 [INT]").arg(value.v); }
|
||||
|
||||
case mtpc_long: {
|
||||
MTPlong value(from, end, cons);
|
||||
return QString("%2 [LONG]").arg(value.v); }
|
||||
|
||||
case mtpc_int128: {
|
||||
MTPint128 value(from, end, cons);
|
||||
return QString("%1 * 2^64 + %2 [INT128]").arg(value.h).arg(value.l); }
|
||||
|
||||
case mtpc_int256: {
|
||||
MTPint256 value(from, end, cons);
|
||||
return QString("%1 * 2^192 + %2 * 2^128 + %3 * 2^64 + %4 [INT256]").arg(value.h.h).arg(value.h.l).arg(value.l.h).arg(value.l.l); }
|
||||
|
||||
case mtpc_double: {
|
||||
MTPdouble value(from, end, cons);
|
||||
return QString("%1 [DOUBLE]").arg(value.v); }
|
||||
|
||||
case mtpc_string: {
|
||||
MTPstring value(from, end, cons);
|
||||
QByteArray strUtf8(value.c_string().v.c_str(), value.c_string().v.length());
|
||||
QString str = QString::fromUtf8(strUtf8);
|
||||
if (str.toUtf8() == strUtf8) {
|
||||
str = QString("\"%1\" [STRING]").arg(str.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n"));
|
||||
} else {
|
||||
str = mb(strUtf8.constData(), strUtf8.size()).str() + QString(" [%1 BYTES]").arg(strUtf8.size());
|
||||
}
|
||||
return str; }
|
||||
|
||||
case mtpc_boolTrue:
|
||||
case mtpc_boolFalse: {
|
||||
MTPbool value(from, end, cons);
|
||||
return (value.v ? "[TRUE]" : "[FALSE]"); }
|
||||
|
||||
case mtpc_vector: {
|
||||
if (from >= end) {
|
||||
throw Exception("from >= end in vector");
|
||||
}
|
||||
int32 cnt = *(from++);
|
||||
QString result;
|
||||
if (cnt) {
|
||||
result += "\n" + add;
|
||||
for (int32 i = 0; i < cnt; ++i) {
|
||||
result += " " + mtpTextSerialize(from, end, vcons, level + 1) + ",\n" + add;
|
||||
}
|
||||
} else {
|
||||
result = " ";
|
||||
}
|
||||
return QString("[ vector<%1>").arg(vcons) + result + "]"; }
|
||||
|
||||
case mtpc_error: {
|
||||
QString result;
|
||||
result += "\n" + add;
|
||||
result += " code: " + mtpTextSerialize(from, end, mtpc_int, level + 1) + ",\n" + add;
|
||||
result += " text: " + mtpTextSerialize(from, end, mtpc_string, level + 1) + ",\n" + add;
|
||||
return "{ error" + result + "}"; }
|
||||
|
||||
case mtpc_null: {
|
||||
QString result;
|
||||
result = " ";
|
||||
return "{ null" + result + "}"; }
|
||||
|
||||
case mtpc_rpc_result: {
|
||||
QString result;
|
||||
result += "\n" + add;
|
||||
result += " req_msg_id: " + mtpTextSerialize(from, end, mtpc_long, level + 1) + ",\n" + add;
|
||||
result += " result: " + mtpTextSerialize(from, end, 0, level + 1) + ",\n" + add;
|
||||
return "{ rpc_result" + result + "}"; }
|
||||
|
||||
case mtpc_msg_container: {
|
||||
QString result;
|
||||
result += "\n" + add;
|
||||
result += " messages: " + mtpTextSerialize(from, end, mtpc_vector, level + 1, mtpc_core_message) + ",\n" + add;
|
||||
return "{ msg_container" + result + "}"; }
|
||||
|
||||
case mtpc_core_message: {
|
||||
QString result;
|
||||
result += "\n" + add;
|
||||
result += " msg_id: " + mtpTextSerialize(from, end, mtpc_long, level + 1) + ",\n" + add;
|
||||
result += " seq_no: " + mtpTextSerialize(from, end, mtpc_int, level + 1) + ",\n" + add;
|
||||
result += " bytes: " + mtpTextSerialize(from, end, mtpc_int, level + 1) + ",\n" + add;
|
||||
result += " body: " + mtpTextSerialize(from, end, 0, level + 1) + ",\n" + add;
|
||||
return "{ core_message" + result + "}"; }
|
||||
|
||||
case mtpc_gzip_packed: {
|
||||
MTPstring packed(from, end); // read packed string as serialized mtp string type
|
||||
uint32 packedLen = packed.c_string().v.size(), unpackedChunk = packedLen;
|
||||
mtpBuffer result; // * 4 because of mtpPrime type
|
||||
result.resize(0);
|
||||
|
||||
z_stream stream;
|
||||
stream.zalloc = 0;
|
||||
stream.zfree = 0;
|
||||
stream.opaque = 0;
|
||||
stream.avail_in = 0;
|
||||
stream.next_in = 0;
|
||||
int res = inflateInit2(&stream, 16 + MAX_WBITS);
|
||||
if (res != Z_OK) {
|
||||
throw Exception(QString("ungzip init, code: %1").arg(res));
|
||||
}
|
||||
stream.avail_in = packedLen;
|
||||
stream.next_in = (Bytef*)&packed._string().v[0];
|
||||
stream.avail_out = 0;
|
||||
while (!stream.avail_out) {
|
||||
result.resize(result.size() + unpackedChunk);
|
||||
stream.avail_out = unpackedChunk * sizeof(mtpPrime);
|
||||
stream.next_out = (Bytef*)&result[result.size() - unpackedChunk];
|
||||
int res = inflate(&stream, Z_NO_FLUSH);
|
||||
if (res != Z_OK && res != Z_STREAM_END) {
|
||||
inflateEnd(&stream);
|
||||
throw Exception(QString("ungzip unpack, code: %1").arg(res));
|
||||
}
|
||||
}
|
||||
if (stream.avail_out & 0x03) {
|
||||
uint32 badSize = result.size() * sizeof(mtpPrime) - stream.avail_out;
|
||||
throw Exception(QString("ungzip bad length, size: %1").arg(badSize));
|
||||
}
|
||||
result.resize(result.size() - (stream.avail_out >> 2));
|
||||
inflateEnd(&stream);
|
||||
|
||||
if (!result.size()) {
|
||||
throw Exception("ungzip void data");
|
||||
}
|
||||
const mtpPrime *newFrom = result.constData(), *newEnd = result.constData() + result.size();
|
||||
return "[GZIPPED] " + mtpTextSerialize(newFrom, newEnd, 0, level); }
|
||||
|
||||
default: {
|
||||
for (uint32 i = 1; i < mtpLayerMax; ++i) {
|
||||
if (cons == mtpLayers[i]) {
|
||||
return QString("[LAYER%1] ").arg(i + 1) + mtpTextSerialize(from, end, 0, level);
|
||||
}
|
||||
}
|
||||
struct MTPStringLogger {
|
||||
MTPStringLogger() : p(new char[MTPDebugBufferSize]), size(0), alloced(MTPDebugBufferSize) {
|
||||
}
|
||||
~MTPStringLogger() {
|
||||
delete[] p;
|
||||
}
|
||||
|
||||
throw Exception(QString("unknown cons %1").arg(cons));
|
||||
MTPStringLogger &add(const QString &data) {
|
||||
QByteArray d = data.toUtf8();
|
||||
return add(d.constData(), d.size());
|
||||
}
|
||||
|
||||
MTPStringLogger &add(const char *data, int32 len = -1) {
|
||||
if (len < 0) len = strlen(data);
|
||||
if (!len) return (*this);
|
||||
|
||||
if (size + len > alloced) {
|
||||
int32 newsize = size + len;
|
||||
if (newsize % MTPDebugBufferSize) newsize += MTPDebugBufferSize - (newsize % MTPDebugBufferSize);
|
||||
char *b = new char[newsize];
|
||||
memcpy(b, p, size);
|
||||
alloced = newsize;
|
||||
delete p;
|
||||
p = b;
|
||||
}
|
||||
memcpy(p + size, data, len);
|
||||
size += len;
|
||||
return (*this);
|
||||
}
|
||||
char *p;
|
||||
int32 size, alloced;
|
||||
};
|
||||
|
||||
void mtpTextSerializeType(MTPStringLogger &to, const mtpPrime *&from, const mtpPrime *end, mtpPrime cons = 0, uint32 level = 0, mtpPrime vcons = 0);
|
||||
|
||||
void mtpTextSerializeCore(MTPStringLogger &to, const mtpPrime *&from, const mtpPrime *end, mtpTypeId cons, uint32 level, mtpPrime vcons = 0);
|
||||
|
||||
inline QString mtpTextSerialize(const mtpPrime *&from, const mtpPrime *end) {
|
||||
MTPStringLogger to;
|
||||
mtpTextSerializeType(to, from, end, mtpc_core_message);
|
||||
return QString::fromUtf8(to.p, to.size);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -821,9 +821,11 @@
|
|||
<ClCompile Include="SourceFiles\mediaview.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtp.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpConnection.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpCoreTypes.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpDC.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpFileLoader.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpRPC.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpScheme.cpp" />
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpSession.cpp" />
|
||||
<ClCompile Include="SourceFiles\overviewwidget.cpp" />
|
||||
<ClCompile Include="SourceFiles\profilewidget.cpp" />
|
||||
|
|
|
@ -716,6 +716,12 @@
|
|||
<ClCompile Include="GeneratedFiles\Release\moc_contextmenu.cpp">
|
||||
<Filter>Generated Files\Release</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpCoreTypes.cpp">
|
||||
<Filter>mtproto</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SourceFiles\mtproto\mtpScheme.cpp">
|
||||
<Filter>mtproto</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="SourceFiles\stdafx.h">
|
||||
|
|
Loading…
Reference in New Issue