aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Kaufmann <mail@michael-kaufmann.ch>2020-03-26 23:15:37 +0100
committerMichael Kaufmann <mail@michael-kaufmann.ch>2020-03-27 23:32:25 +0100
commit884de1a763af186984cbcbe7b35b551c06025284 (patch)
tree44278ea099d5565e87378d0b4d9c88e1e65db26e /src
parentd973bdf88175ea16ea2e3045a724c1df4f9dd507 (diff)
writeout_json: Fix data type issues
Load long values correctly (e.g. for http_code). Use curl_off_t (not long) for: - size_download (CURLINFO_SIZE_DOWNLOAD_T) - size_upload (CURLINFO_SIZE_UPLOAD_T) The unit for these values is bytes/second, not microseconds: - speed_download (CURLINFO_SPEED_DOWNLOAD_T) - speed_upload (CURLINFO_SPEED_UPLOAD_T) Fixes #5131 Closes #5152
Diffstat (limited to 'src')
-rw-r--r--src/tool_writeout.c8
-rw-r--r--src/tool_writeout.h1
-rw-r--r--src/tool_writeout_json.c15
3 files changed, 19 insertions, 5 deletions
diff --git a/src/tool_writeout.c b/src/tool_writeout.c
index 9fbc8665d..32c95b45f 100644
--- a/src/tool_writeout.c
+++ b/src/tool_writeout.c
@@ -55,13 +55,13 @@ static const struct writeoutvar variables[] = {
{"size_request", VAR_REQUEST_SIZE, 0,
CURLINFO_REQUEST_SIZE, JSON_LONG},
{"size_download", VAR_SIZE_DOWNLOAD, 0,
- CURLINFO_SIZE_DOWNLOAD_T, JSON_LONG},
+ CURLINFO_SIZE_DOWNLOAD_T, JSON_OFFSET},
{"size_upload", VAR_SIZE_UPLOAD, 0,
- CURLINFO_SIZE_UPLOAD_T, JSON_LONG},
+ CURLINFO_SIZE_UPLOAD_T, JSON_OFFSET},
{"speed_download", VAR_SPEED_DOWNLOAD, 0,
- CURLINFO_SPEED_DOWNLOAD_T, JSON_TIME},
+ CURLINFO_SPEED_DOWNLOAD_T, JSON_OFFSET},
{"speed_upload", VAR_SPEED_UPLOAD, 0,
- CURLINFO_SPEED_UPLOAD_T, JSON_TIME},
+ CURLINFO_SPEED_UPLOAD_T, JSON_OFFSET},
{"content_type", VAR_CONTENT_TYPE, 0,
CURLINFO_CONTENT_TYPE, JSON_STRING},
{"num_connects", VAR_NUM_CONNECTS, 0,
diff --git a/src/tool_writeout.h b/src/tool_writeout.h
index 64d759575..a21787ab9 100644
--- a/src/tool_writeout.h
+++ b/src/tool_writeout.h
@@ -65,6 +65,7 @@ typedef enum {
JSON_NONE,
JSON_STRING,
JSON_LONG,
+ JSON_OFFSET,
JSON_TIME,
JSON_VERSION,
JSON_FILENAME
diff --git a/src/tool_writeout_json.c b/src/tool_writeout_json.c
index 70235c209..dfe51b9ff 100644
--- a/src/tool_writeout_json.c
+++ b/src/tool_writeout_json.c
@@ -105,7 +105,7 @@ static int writeString(FILE *str, CURL *curl, const char *key, CURLINFO ci)
static int writeLong(FILE *str, CURL *curl, const char *key, CURLINFO ci)
{
- curl_off_t val = 0;
+ long val = 0;
if(CURLE_OK == curl_easy_getinfo(curl, ci, &val)) {
fprintf(str, "\"%s\":%ld", key, val);
return 1;
@@ -113,6 +113,16 @@ static int writeLong(FILE *str, CURL *curl, const char *key, CURLINFO ci)
return 0;
}
+static int writeOffset(FILE *str, CURL *curl, const char *key, CURLINFO ci)
+{
+ curl_off_t val = 0;
+ if(CURLE_OK == curl_easy_getinfo(curl, ci, &val)) {
+ fprintf(str, "\"%s\":%" CURL_FORMAT_CURL_OFF_T, key, val);
+ return 1;
+ }
+ return 0;
+}
+
static int writeFilename(FILE *str, const char *key, const char *filename)
{
if(filename) {
@@ -160,6 +170,9 @@ void ourWriteOutJSON(const struct writeoutvar mappings[], CURL *curl,
case JSON_LONG:
ok = writeLong(stream, curl, name, cinfo);
break;
+ case JSON_OFFSET:
+ ok = writeOffset(stream, curl, name, cinfo);
+ break;
case JSON_TIME:
ok = writeTime(stream, curl, name, cinfo);
break;