1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, 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_EFFECTIVE_FILENAME,
61 VAR_NUM_OF_VARS /* must be the last */
70 static const struct variable replacements[]={
71 {"url_effective", VAR_EFFECTIVE_URL},
72 {"http_code", VAR_HTTP_CODE},
73 {"response_code", VAR_HTTP_CODE},
74 {"http_connect", VAR_HTTP_CODE_PROXY},
75 {"time_total", VAR_TOTAL_TIME},
76 {"time_namelookup", VAR_NAMELOOKUP_TIME},
77 {"time_connect", VAR_CONNECT_TIME},
78 {"time_appconnect", VAR_APPCONNECT_TIME},
79 {"time_pretransfer", VAR_PRETRANSFER_TIME},
80 {"time_starttransfer", VAR_STARTTRANSFER_TIME},
81 {"size_header", VAR_HEADER_SIZE},
82 {"size_request", VAR_REQUEST_SIZE},
83 {"size_download", VAR_SIZE_DOWNLOAD},
84 {"size_upload", VAR_SIZE_UPLOAD},
85 {"speed_download", VAR_SPEED_DOWNLOAD},
86 {"speed_upload", VAR_SPEED_UPLOAD},
87 {"content_type", VAR_CONTENT_TYPE},
88 {"num_connects", VAR_NUM_CONNECTS},
89 {"time_redirect", VAR_REDIRECT_TIME},
90 {"num_redirects", VAR_REDIRECT_COUNT},
91 {"ftp_entry_path", VAR_FTP_ENTRY_PATH},
92 {"redirect_url", VAR_REDIRECT_URL},
93 {"ssl_verify_result", VAR_SSL_VERIFY_RESULT},
94 {"filename_effective", VAR_EFFECTIVE_FILENAME},
95 {"remote_ip", VAR_PRIMARY_IP},
96 {"remote_port", VAR_PRIMARY_PORT},
97 {"local_ip", VAR_LOCAL_IP},
98 {"local_port", VAR_LOCAL_PORT},
99 {"http_version", VAR_HTTP_VERSION},
103 void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
105 FILE *stream = stdout;
106 const char *ptr = writeinfo;
107 char *stringp = NULL;
114 /* an escaped %-letter */
119 /* this is meant as a variable to output */
123 if(('{' == ptr[1]) && ((end = strchr(ptr, '}')) != NULL)) {
125 ptr += 2; /* pass the % and the { */
127 *end = 0; /* zero terminate */
128 for(i = 0; replacements[i].name; i++) {
129 if(curl_strequal(ptr, replacements[i].name)) {
131 switch(replacements[i].id) {
132 case VAR_EFFECTIVE_URL:
134 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &stringp))
136 fputs(stringp, stream);
140 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo))
141 fprintf(stream, "%03ld", longinfo);
143 case VAR_HTTP_CODE_PROXY:
145 curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE,
147 fprintf(stream, "%03ld", longinfo);
149 case VAR_HEADER_SIZE:
151 curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &longinfo))
152 fprintf(stream, "%ld", longinfo);
154 case VAR_REQUEST_SIZE:
156 curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &longinfo))
157 fprintf(stream, "%ld", longinfo);
159 case VAR_NUM_CONNECTS:
161 curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &longinfo))
162 fprintf(stream, "%ld", longinfo);
164 case VAR_REDIRECT_COUNT:
166 curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &longinfo))
167 fprintf(stream, "%ld", longinfo);
169 case VAR_REDIRECT_TIME:
171 curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME,
173 fprintf(stream, "%.3f", doubleinfo);
177 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &doubleinfo))
178 fprintf(stream, "%.3f", doubleinfo);
180 case VAR_NAMELOOKUP_TIME:
182 curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME,
184 fprintf(stream, "%.3f", doubleinfo);
186 case VAR_CONNECT_TIME:
188 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &doubleinfo))
189 fprintf(stream, "%.3f", doubleinfo);
191 case VAR_APPCONNECT_TIME:
193 curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME,
195 fprintf(stream, "%.3f", doubleinfo);
197 case VAR_PRETRANSFER_TIME:
199 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME,
201 fprintf(stream, "%.3f", doubleinfo);
203 case VAR_STARTTRANSFER_TIME:
205 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME,
207 fprintf(stream, "%.3f", doubleinfo);
209 case VAR_SIZE_UPLOAD:
211 curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &doubleinfo))
212 fprintf(stream, "%.0f", doubleinfo);
214 case VAR_SIZE_DOWNLOAD:
216 curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD,
218 fprintf(stream, "%.0f", doubleinfo);
220 case VAR_SPEED_DOWNLOAD:
222 curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD,
224 fprintf(stream, "%.3f", doubleinfo);
226 case VAR_SPEED_UPLOAD:
228 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &doubleinfo))
229 fprintf(stream, "%.3f", doubleinfo);
231 case VAR_CONTENT_TYPE:
233 curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp))
235 fputs(stringp, stream);
237 case VAR_FTP_ENTRY_PATH:
239 curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp))
241 fputs(stringp, stream);
243 case VAR_REDIRECT_URL:
245 curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp))
247 fputs(stringp, stream);
249 case VAR_SSL_VERIFY_RESULT:
251 curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT,
253 fprintf(stream, "%ld", longinfo);
255 case VAR_EFFECTIVE_FILENAME:
257 fprintf(stream, "%s", outs->filename);
261 curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP,
263 fprintf(stream, "%s", stringp);
265 case VAR_PRIMARY_PORT:
267 curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT,
269 fprintf(stream, "%ld", longinfo);
273 curl_easy_getinfo(curl, CURLINFO_LOCAL_IP,
275 fprintf(stream, "%s", stringp);
279 curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT,
281 fprintf(stream, "%ld", longinfo);
283 case VAR_HTTP_VERSION:
285 curl_easy_getinfo(curl, CURLINFO_HTTP_VERSION,
287 const char *version = "0";
289 case CURL_HTTP_VERSION_1_0:
292 case CURL_HTTP_VERSION_1_1:
295 case CURL_HTTP_VERSION_2_0:
300 fprintf(stream, version);
310 fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr);
312 ptr = end + 1; /* pass the end */
316 /* illegal syntax, then just output the characters that are used */
318 fputc(ptr[1], stream);
323 else if('\\' == *ptr) {
335 /* unknown, just output this */
337 fputc(ptr[1], stream);