aboutsummaryrefslogtreecommitdiff
path: root/lib/jobs
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-03 20:08:46 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-04 07:52:47 +0900
commitdf164cd856a34d8c1462793a40e56d387389b82f (patch)
tree91e69f92a5ad64b70495bef12fa6449eb32aef3b /lib/jobs
parenteaca25fd5115ab00a29b7d47dfc6e16cbfd5e552 (diff)
downloadlibquotient-df164cd856a34d8c1462793a40e56d387389b82f.tar.gz
libquotient-df164cd856a34d8c1462793a40e56d387389b82f.zip
Connection: Trim raw data in emitted signals
If the payload is too large, an attempt to allocate a QString out of QByteArray may end with qBadAlloc(). So by default the data emitted in case of error are trimmed to 64KiB, and this can be overridden to a different value (or switched off entirely with <n>=0) by adding - DTRIM_RAW_DATA=<n> to CPP_FLAGS.
Diffstat (limited to 'lib/jobs')
-rw-r--r--lib/jobs/basejob.cpp5
-rw-r--r--lib/jobs/basejob.h2
2 files changed, 4 insertions, 3 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp
index 2a6705b8..607a6c04 100644
--- a/lib/jobs/basejob.cpp
+++ b/lib/jobs/basejob.cpp
@@ -509,9 +509,10 @@ BaseJob::Status BaseJob::status() const
return d->status;
}
-QByteArray BaseJob::rawData() const
+QByteArray BaseJob::rawData(int bytesAtMost) const
{
- return d->rawResponse;
+ return bytesAtMost > 0 ?
+ d->rawResponse.left(bytesAtMost) + "...(truncated)" : d->rawResponse;
}
QString BaseJob::statusCaption() const
diff --git a/lib/jobs/basejob.h b/lib/jobs/basejob.h
index c34ba3c3..4ef25ab8 100644
--- a/lib/jobs/basejob.h
+++ b/lib/jobs/basejob.h
@@ -139,7 +139,7 @@ namespace QMatrixClient
/** Short human-friendly message on the job status */
QString statusCaption() const;
/** Raw response body as received from the server */
- QByteArray rawData() const;
+ QByteArray rawData(int bytesAtMost = -1) const;
/** Error (more generally, status) code
* Equivalent to status().code