tool_writeout: refactor write-out and write-out json

- Deduplicate the logic used by write-out and write-out json.

Rather than have separate writeLong, writeString, etc, logic for
each of write-out and write-out json instead have respective shared
functions that can output either format and a 'use_json' parameter to
indicate whether it is json that is output.

This will make it easier to maintain. Rather than have to go through
two sets of logic now we only have to go through one.

- Support write-out %{errormsg} and %{exitcode} in json.

- Clarify in the doc that %{exitcode} is the exit code of the transfer.

Prior to this change it just said "The numerical exitcode" which
implies it's the exit code of the tool, and it's not necessarily that.

Closes https://github.com/curl/curl/pull/6544
This commit is contained in:
Jay Satiro 2021-01-28 18:56:50 -05:00
parent b9f11ae875
commit 65ca229461
7 changed files with 306 additions and 417 deletions

View file

@ -69,25 +69,16 @@ typedef enum {
VAR_NUM_OF_VARS /* must be the last */
} writeoutid;
typedef enum {
JSON_NONE,
JSON_STRING,
JSON_LONG,
JSON_OFFSET,
JSON_TIME,
JSON_VERSION,
JSON_FILENAME
} jsontype;
struct writeoutvar {
const char *name;
writeoutid id;
int is_ctrl;
CURLINFO cinfo;
jsontype jsontype;
CURLINFO ci;
int (*writefunc)(FILE *stream, const struct writeoutvar *wovar,
struct per_transfer *per, CURLcode per_result,
bool use_json);
};
void ourWriteOut(CURL *curl, struct per_transfer *per, const char *writeinfo,
CURLcode exitcode);
void ourWriteOut(const char *writeinfo, struct per_transfer *per,
CURLcode per_result);
#endif /* HEADER_CURL_TOOL_WRITEOUT_H */