Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Krautz <mikkel@krautz.dk>2017-03-05 21:05:57 +0300
committerMikkel Krautz <mikkel@krautz.dk>2017-03-06 23:27:06 +0300
commit63bf48615133eda2b5bff00f3e72f7d5f6345ec7 (patch)
tree727cc37100ae40532e10b7554ccd7d55e1467039 /src/murmur/MurmurIce.cpp
parent6f41f4b7879af22a8263346c729548f512c5fedb (diff)
MurmurIce: base64-encode MurmurUser::context on the wire to avoid NUL bytes w/o losing data.
We now base64-encode the user's plugin context. It is a binary blob, not generally useful for RPC users. The most important property is the ability to detect that two users are in the same game context -- and that property is preserved. If the exact byte seqeuence is needed, it is possible to base64-decode the returned string to retrieve it. Fixes mumble-voip/mumble#1874
Diffstat (limited to 'src/murmur/MurmurIce.cpp')
-rw-r--r--src/murmur/MurmurIce.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/murmur/MurmurIce.cpp b/src/murmur/MurmurIce.cpp
index 18c566956..dea41ce7f 100644
--- a/src/murmur/MurmurIce.cpp
+++ b/src/murmur/MurmurIce.cpp
@@ -7,6 +7,8 @@
#include "MurmurIce.h"
+#include <limits>
+
#include <Ice/Ice.h>
#include <Ice/SliceChecksums.h>
#include <IceUtil/IceUtil.h>
@@ -64,6 +66,23 @@ static std::string iceString(const QString &s) {
return iceRemoveNul(u8(s));
}
+/// Convert the bytes in std::string to base64 using the
+/// base64 alphabet from RFC 2045.
+///
+/// The size of the string may not exceed sizeof(int).
+/// If the function is passed a string bigger than that,
+/// it will return an empty string.
+static std::string iceBase64(const std::string &s) {
+ if (s.size() > std::numeric_limits<int>::max()) {
+ return std::string();
+ }
+
+ QByteArray ba(s.data(), static_cast<int>(s.size()));
+ QByteArray ba64 = ba.toBase64();
+
+ return std::string(ba64.data(), static_cast<size_t>(ba.size()));
+}
+
static void logToLog(const ServerDB::LogRecord &r, Murmur::LogEntry &le) {
le.timestamp = r.first;
le.txt = iceString(r.second);
@@ -91,7 +110,7 @@ static void userToUser(const ::User *p, Murmur::User &mp) {
mp.os = iceString(u->qsOS);
mp.osversion = iceString(u->qsOSVersion);
mp.identity = iceString(u->qsIdentity);
- mp.context = u->ssContext;
+ mp.context = iceBase64(u->ssContext);
mp.idlesecs = u->bwr.idleSeconds();
mp.udpPing = u->dUDPPingAvg;
mp.tcpPing = u->dTCPPingAvg;