]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
writeout_json: Fix data type issues
authorMichael Kaufmann <mail@michael-kaufmann.ch>
Thu, 26 Mar 2020 22:15:37 +0000 (23:15 +0100)
committerMichael Kaufmann <mail@michael-kaufmann.ch>
Fri, 27 Mar 2020 22:32:25 +0000 (23:32 +0100)
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

src/tool_writeout.c
src/tool_writeout.h
src/tool_writeout_json.c
tests/data/test970

index 9fbc8665d0ee67da48ebc71ae9f05529e5c88aba..32c95b45ff2d7f492da28e894ee0bc197acac477 100644 (file)
@@ -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,
index 64d7595751a7786f3444734f93847921b9a46dd4..a21787ab9aa3be69ecd313820669b44a9df33029 100644 (file)
@@ -65,6 +65,7 @@ typedef enum {
   JSON_NONE,
   JSON_STRING,
   JSON_LONG,
+  JSON_OFFSET,
   JSON_TIME,
   JSON_VERSION,
   JSON_FILENAME
index 70235c20912f4b7bdce7f245d5f25a2e0b744432..dfe51b9ffab3a5c857c7940d6c83ccac467867f2 100644 (file)
@@ -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;
index 04a663bc9fa3d166e3ae2cae78a0e37be71606e9..54e34cc5b3ce7e9c6df3e93dd4a1719748bc9f9a 100644 (file)
@@ -60,7 +60,7 @@ Accept: */*
 \r
 </protocol>
 <stdout nonewline="yes">
-{"url_effective":"http://%HOSTIP:%HTTPPORT/970","http_code":200,"response_code":200,"http_connect":0,"time_total":0.000013,"time_namelookup":0.000013,"time_connect":0.000013,"time_appconnect":0.000013,"time_pretransfer":0.000013,"time_starttransfer":0.000013,"size_header":4019,"size_request":4019,"size_download":445,"size_upload":0,"speed_download":0.000013,"speed_upload":0.000013,"content_type":"text/html","num_connects":1,"time_redirect":0.000013,"num_redirects":0,"ssl_verify_result":0,"proxy_ssl_verify_result":0,"filename_effective":"log/out970","remote_ip":"%HOSTIP","remote_port":%HTTPPORT,"local_ip":"127.0.0.1","local_port":13,"http_version":"1.1","scheme":"HTTP","curl_version":"curl-unit-test-fake-version"}
+{"url_effective":"http://%HOSTIP:%HTTPPORT/970","http_code":200,"response_code":200,"http_connect":0,"time_total":0.000013,"time_namelookup":0.000013,"time_connect":0.000013,"time_appconnect":0.000013,"time_pretransfer":0.000013,"time_starttransfer":0.000013,"size_header":4019,"size_request":4019,"size_download":445,"size_upload":0,"speed_download":13,"speed_upload":13,"content_type":"text/html","num_connects":1,"time_redirect":0.000013,"num_redirects":0,"ssl_verify_result":0,"proxy_ssl_verify_result":0,"filename_effective":"log/out970","remote_ip":"%HOSTIP","remote_port":%HTTPPORT,"local_ip":"127.0.0.1","local_port":13,"http_version":"1.1","scheme":"HTTP","curl_version":"curl-unit-test-fake-version"}
 </stdout>
 </verify>
 </testcase>