From 0072a0880c077fc0a21fd57214e6c5bf8497402a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 26 Jan 2015 00:17:21 +0000 Subject: first version that logs in git-svn-id: http://svn.miranda-ng.org/main/trunk@11913 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp') diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp index 227857a522..7ec854878a 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp @@ -12,7 +12,7 @@ BinTreeNodeWriter::BinTreeNodeWriter(WAConnection* conn, ISocketConnection* connection, IMutex* mutex) { - this->bLoggedIn = false; + this->bSecure = false; this->mutex = mutex; this->conn = conn; this->out = new ByteArrayOutputStream(2048); @@ -31,25 +31,26 @@ void BinTreeNodeWriter::writeDummyHeader() void BinTreeNodeWriter::processBuffer() { - unsigned int num = 0u; - if (bLoggedIn) { + unsigned char num = 0; + if (bSecure) { long num2 = (long)this->out->getLength() + 4L; this->out->setLength(num2); this->out->setPosition(num2); - num |= 1u; + num = 8; } long num3 = (long)this->out->getLength() - 3L - (long) this->dataBegin; if (num3 >= 1048576L) throw WAException("Buffer too large: " + num3, WAException::CORRUPT_STREAM_EX, 0); - std::vector* buffer = this->out->getBuffer(); - if (bLoggedIn) { + std::vector& buffer = this->out->getBuffer(); + this->realOut->dump(buffer.data(), (int)buffer.size()); + if (bSecure) { int num4 = (int)num3 - 4; - this->conn->outputKey.encodeMessage(buffer->data(), this->dataBegin + 3 + num4, this->dataBegin + 3, num4); + this->conn->outputKey.encodeMessage(buffer.data(), this->dataBegin + 3 + num4, this->dataBegin + 3, num4); } - (*buffer)[this->dataBegin] = (unsigned char)((unsigned long)((unsigned long)num << 4) | (unsigned long)((num3 & 16711680L) >> 16)); - (*buffer)[this->dataBegin + 1] = (unsigned char)((num3 & 65280L) >> 8); - (*buffer)[this->dataBegin + 2] = (unsigned char)(num3 & 255L); + buffer[dataBegin] = (unsigned char)((unsigned long)((unsigned long)num << 4) | (unsigned long)((num3 & 16711680L) >> 16)); + buffer[dataBegin + 1] = (unsigned char)((num3 & 65280L) >> 8); + buffer[dataBegin + 2] = (unsigned char)(num3 & 255L); } void BinTreeNodeWriter::streamStart(std::string domain, std::string resource) @@ -220,17 +221,18 @@ void BinTreeNodeWriter::flushBuffer(bool flushNetwork, int startingOffset) throw ex; } - // _LOGDATA("buffer size %d, buffer position %d, dataBegin %d", this->out->getLength(), this->out->getPosition(), this->dataBegin); - - std::vector buffer(this->out->getBuffer()->begin(), this->out->getBuffer()->end()); + std::vector buffer(this->out->getBuffer().begin(), this->out->getBuffer().end()); int num = (int)(this->out->getLength() - (long)startingOffset); if (flushNetwork && ((long)this->out->getCapacity() - this->out->getLength() < 3L || this->out->getLength() > 4096L)) { delete this->out; this->out = new ByteArrayOutputStream(4096); } - if (flushNetwork) + if (flushNetwork) { this->realOut->write(buffer, startingOffset, num); + this->out->setPosition(0); + this->out->setLength(0); + } } void BinTreeNodeWriter::streamEnd() -- cgit v1.2.3