1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
22 #include "tool_setup.h"
23 #define ENABLE_CURLX_PRINTF
24 /* use our own printf() functions */
26 #include "tool_cfgable.h"
27 #include "tool_writeout.h"
29 #include "memdebug.h" /* keep this as LAST include */
32 VAR_NONE, /* must be the first */
38 VAR_STARTTRANSFER_TIME,
54 VAR_SSL_VERIFY_RESULT,
55 VAR_PROXY_SSL_VERIFY_RESULT,
56 VAR_EFFECTIVE_FILENAME,
63 VAR_NUM_OF_VARS /* must be the last */
72 static const struct variable replacements[]={
73 {"url_effective", VAR_EFFECTIVE_URL},
74 {"http_code", VAR_HTTP_CODE},
75 {"response_code", VAR_HTTP_CODE},
76 {"http_connect", VAR_HTTP_CODE_PROXY},
77 {"time_total", VAR_TOTAL_TIME},
78 {"time_namelookup", VAR_NAMELOOKUP_TIME},
79 {"time_connect", VAR_CONNECT_TIME},
80 {"time_appconnect", VAR_APPCONNECT_TIME},
81 {"time_pretransfer", VAR_PRETRANSFER_TIME},
82 {"time_starttransfer", VAR_STARTTRANSFER_TIME},
83 {"size_header", VAR_HEADER_SIZE},
84 {"size_request", VAR_REQUEST_SIZE},
85 {"size_download", VAR_SIZE_DOWNLOAD},
86 {"size_upload", VAR_SIZE_UPLOAD},
87 {"speed_download", VAR_SPEED_DOWNLOAD},
88 {"speed_upload", VAR_SPEED_UPLOAD},
89 {"content_type", VAR_CONTENT_TYPE},
90 {"num_connects", VAR_NUM_CONNECTS},
91 {"time_redirect", VAR_REDIRECT_TIME},
92 {"num_redirects", VAR_REDIRECT_COUNT},
93 {"ftp_entry_path", VAR_FTP_ENTRY_PATH},
94 {"redirect_url", VAR_REDIRECT_URL},
95 {"ssl_verify_result", VAR_SSL_VERIFY_RESULT},
96 {"proxy_ssl_verify_result", VAR_PROXY_SSL_VERIFY_RESULT},
97 {"filename_effective", VAR_EFFECTIVE_FILENAME},
98 {"remote_ip", VAR_PRIMARY_IP},
99 {"remote_port", VAR_PRIMARY_PORT},
100 {"local_ip", VAR_LOCAL_IP},
101 {"local_port", VAR_LOCAL_PORT},
102 {"http_version", VAR_HTTP_VERSION},
103 {"scheme", VAR_SCHEME},
107 void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
109 FILE *stream = stdout;
110 const char *ptr = writeinfo;
111 char *stringp = NULL;
116 if('%' == *ptr && ptr[1]) {
118 /* an escaped %-letter */
123 /* this is meant as a variable to output */
129 end = strchr(ptr, '}');
130 ptr += 2; /* pass the % and the { */
136 *end = 0; /* zero terminate */
137 for(i = 0; replacements[i].name; i++) {
138 if(curl_strequal(ptr, replacements[i].name)) {
140 switch(replacements[i].id) {
141 case VAR_EFFECTIVE_URL:
143 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &stringp))
145 fputs(stringp, stream);
149 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo))
150 fprintf(stream, "%03ld", longinfo);
152 case VAR_HTTP_CODE_PROXY:
154 curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE,
156 fprintf(stream, "%03ld", longinfo);
158 case VAR_HEADER_SIZE:
160 curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &longinfo))
161 fprintf(stream, "%ld", longinfo);
163 case VAR_REQUEST_SIZE:
165 curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &longinfo))
166 fprintf(stream, "%ld", longinfo);
168 case VAR_NUM_CONNECTS:
170 curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &longinfo))
171 fprintf(stream, "%ld", longinfo);
173 case VAR_REDIRECT_COUNT:
175 curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &longinfo))
176 fprintf(stream, "%ld", longinfo);
178 case VAR_REDIRECT_TIME:
180 curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME,
182 fprintf(stream, "%.6f", doubleinfo);
186 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &doubleinfo))
187 fprintf(stream, "%.6f", doubleinfo);
189 case VAR_NAMELOOKUP_TIME:
191 curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME,
193 fprintf(stream, "%.6f", doubleinfo);
195 case VAR_CONNECT_TIME:
197 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &doubleinfo))
198 fprintf(stream, "%.6f", doubleinfo);
200 case VAR_APPCONNECT_TIME:
202 curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME,
204 fprintf(stream, "%.6f", doubleinfo);
206 case VAR_PRETRANSFER_TIME:
208 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME,
210 fprintf(stream, "%.6f", doubleinfo);
212 case VAR_STARTTRANSFER_TIME:
214 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME,
216 fprintf(stream, "%.6f", doubleinfo);
218 case VAR_SIZE_UPLOAD:
220 curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &doubleinfo))
221 fprintf(stream, "%.0f", doubleinfo);
223 case VAR_SIZE_DOWNLOAD:
225 curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD,
227 fprintf(stream, "%.0f", doubleinfo);
229 case VAR_SPEED_DOWNLOAD:
231 curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD,
233 fprintf(stream, "%.3f", doubleinfo);
235 case VAR_SPEED_UPLOAD:
237 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &doubleinfo))
238 fprintf(stream, "%.3f", doubleinfo);
240 case VAR_CONTENT_TYPE:
242 curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp))
244 fputs(stringp, stream);
246 case VAR_FTP_ENTRY_PATH:
248 curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp))
250 fputs(stringp, stream);
252 case VAR_REDIRECT_URL:
254 curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp))
256 fputs(stringp, stream);
258 case VAR_SSL_VERIFY_RESULT:
260 curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT,
262 fprintf(stream, "%ld", longinfo);
264 case VAR_PROXY_SSL_VERIFY_RESULT:
266 curl_easy_getinfo(curl, CURLINFO_PROXY_SSL_VERIFYRESULT,
268 fprintf(stream, "%ld", longinfo);
270 case VAR_EFFECTIVE_FILENAME:
272 fprintf(stream, "%s", outs->filename);
276 curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP,
278 fprintf(stream, "%s", stringp);
280 case VAR_PRIMARY_PORT:
282 curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT,
284 fprintf(stream, "%ld", longinfo);
288 curl_easy_getinfo(curl, CURLINFO_LOCAL_IP,
290 fprintf(stream, "%s", stringp);
294 curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT,
296 fprintf(stream, "%ld", longinfo);
298 case VAR_HTTP_VERSION:
300 curl_easy_getinfo(curl, CURLINFO_HTTP_VERSION,
302 const char *version = "0";
304 case CURL_HTTP_VERSION_1_0:
307 case CURL_HTTP_VERSION_1_1:
310 case CURL_HTTP_VERSION_2_0:
315 fprintf(stream, version);
320 curl_easy_getinfo(curl, CURLINFO_SCHEME,
322 fprintf(stream, "%s", stringp);
331 fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr);
333 ptr = end + 1; /* pass the end */
337 /* illegal syntax, then just output the characters that are used */
339 fputc(ptr[1], stream);
344 else if('\\' == *ptr && ptr[1]) {
356 /* unknown, just output this */
358 fputc(ptr[1], stream);