[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3' - common/Util.hpp net/Socket.cpp
Michael Meeks
michael.meeks at collabora.com
Thu Apr 26 17:39:00 UTC 2018
common/Util.hpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
net/Socket.cpp | 44 +++-----------------------------------------
2 files changed, 54 insertions(+), 41 deletions(-)
New commits:
commit 373bd69257b993ce507a2c63cfb229d1479dc8ad
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Wed Nov 29 03:23:45 2017 +0000
Introduce Util::dumpHex().
Change-Id: I6232e6e03505a2a5617529f1b11c20cff03be6a3
Reviewed-on: https://gerrit.libreoffice.org/53527
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/common/Util.hpp b/common/Util.hpp
index f90081730..e18c4652d 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -19,6 +19,7 @@
#include <set>
#include <sstream>
#include <string>
+#include <memory.h>
#include <Poco/File.h>
#include <Poco/Path.h>
@@ -140,6 +141,56 @@ namespace Util
// Extract all json entries into a map.
std::map<std::string, std::string> JsonToMap(const std::string& jsonString);
+ /// Dump data as hex and chars to stream
+ inline void dumpHex (std::ostream &os, const char *legend, const char *prefix,
+ const std::vector<char> &buffer, const unsigned int width = 32)
+ {
+ unsigned int i, j;
+ char scratch[64];
+
+ os << legend;
+ for (j = 0; j < buffer.size() + width - 1; j += width)
+ {
+ int skip = 0;
+ while (j >= width && j < buffer.size() - width &&
+ !memcmp(&buffer[j], &buffer[j-width], width))
+ {
+ skip++;
+ j += width;
+ }
+ if (skip > 1)
+ {
+ j -= width;
+ os << "... dup " << skip - 1 << "...\n";
+ }
+
+ sprintf (scratch, "%s0x%.4x ", prefix, j);
+ os << scratch;
+ for (i = 0; i < width; i++)
+ {
+ if (i && (i % 8) == 0)
+ os << " ";
+ if ((j + i) < buffer.size())
+ sprintf (scratch, "%.2x ", (unsigned char)buffer[j+i]);
+ else
+ sprintf (scratch, " ");
+ os << scratch;
+ }
+ os << " | ";
+
+ for (i = 0; i < width; i++)
+ {
+ if ((j + i) < buffer.size() && ::isprint(buffer[j+i]))
+ sprintf (scratch, "%c", buffer[j+i]);
+ else
+ sprintf (scratch, ".");
+ os << scratch;
+ }
+ os << "\n";
+ }
+ os.flush();
+ }
+
/// Trim spaces from the left. Just spaces.
inline std::string& ltrim(std::string& s)
{
diff --git a/net/Socket.cpp b/net/Socket.cpp
index 0ad24d5b2..149fd60b6 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -143,50 +143,12 @@ void SocketDisposition::execute()
_socketMove = nullptr;
}
-namespace {
-
-void dump_hex (std::ostream &os, const char *legend, const char *prefix, std::vector<char> buffer)
-{
- unsigned int i, j;
- char scratch[64];
-
- os << legend;
- for (j = 0; j < buffer.size() + 15; j += 16)
- {
- sprintf (scratch, "%s0x%.4x ", prefix, j);
- os << scratch;
- for (i = 0; i < 16; i++)
- {
- if ((j + i) < buffer.size())
- sprintf (scratch, "%.2x ", (unsigned char)buffer[j+i]);
- else
- sprintf (scratch, " ");
- os << scratch;
- if (i == 8)
- os << " ";
- }
- os << " | ";
-
- for (i = 0; i < 16; i++)
- {
- if ((j + i) < buffer.size() && ::isprint(buffer[j+i]))
- sprintf (scratch, "%c", buffer[j+i]);
- else
- sprintf (scratch, ".");
- os << scratch;
- }
- os << "\n";
- }
-}
-
-} // namespace
-
void WebSocketHandler::dumpState(std::ostream& os)
{
os << (_shuttingDown ? "shutd " : "alive ")
<< std::setw(5) << 1.0*_pingTimeUs/1000 << "ms ";
if (_wsPayload.size() > 0)
- dump_hex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload);
+ Util::dumpHex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload);
os << "\n";
}
@@ -199,9 +161,9 @@ void StreamSocket::dumpState(std::ostream& os)
<< " r: " << _bytesRecvd << "\t w: " << _bytesSent << "\t";
_socketHandler->dumpState(os);
if (_inBuffer.size() > 0)
- dump_hex(os, "\t\tinBuffer:\n", "\t\t", _inBuffer);
+ Util::dumpHex(os, "\t\tinBuffer:\n", "\t\t", _inBuffer);
if (_outBuffer.size() > 0)
- dump_hex(os, "\t\toutBuffer:\n", "\t\t", _inBuffer);
+ Util::dumpHex(os, "\t\toutBuffer:\n", "\t\t", _inBuffer);
}
void StreamSocket::send(Poco::Net::HTTPResponse& response)
More information about the Libreoffice-commits
mailing list