1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2015, 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,
60 VAR_NUM_OF_VARS /* must be the last */
69 static const struct variable replacements[]={
70 {"url_effective", VAR_EFFECTIVE_URL},
71 {"http_code", VAR_HTTP_CODE},
72 {"response_code", VAR_HTTP_CODE},
73 {"http_connect", VAR_HTTP_CODE_PROXY},
74 {"time_total", VAR_TOTAL_TIME},
75 {"time_namelookup", VAR_NAMELOOKUP_TIME},
76 {"time_connect", VAR_CONNECT_TIME},
77 {"time_appconnect", VAR_APPCONNECT_TIME},
78 {"time_pretransfer", VAR_PRETRANSFER_TIME},
79 {"time_starttransfer", VAR_STARTTRANSFER_TIME},
80 {"size_header", VAR_HEADER_SIZE},
81 {"size_request", VAR_REQUEST_SIZE},
82 {"size_download", VAR_SIZE_DOWNLOAD},
83 {"size_upload", VAR_SIZE_UPLOAD},
84 {"speed_download", VAR_SPEED_DOWNLOAD},
85 {"speed_upload", VAR_SPEED_UPLOAD},
86 {"content_type", VAR_CONTENT_TYPE},
87 {"num_connects", VAR_NUM_CONNECTS},
88 {"time_redirect", VAR_REDIRECT_TIME},
89 {"num_redirects", VAR_REDIRECT_COUNT},
90 {"ftp_entry_path", VAR_FTP_ENTRY_PATH},
91 {"redirect_url", VAR_REDIRECT_URL},
92 {"ssl_verify_result", VAR_SSL_VERIFY_RESULT},
93 {"filename_effective", VAR_EFFECTIVE_FILENAME},
94 {"remote_ip", VAR_PRIMARY_IP},
95 {"remote_port", VAR_PRIMARY_PORT},
96 {"local_ip", VAR_LOCAL_IP},
97 {"local_port", VAR_LOCAL_PORT},
101 void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
103 FILE *stream = stdout;
104 const char *ptr = writeinfo;
105 char *stringp = NULL;
112 /* an escaped %-letter */
117 /* this is meant as a variable to output */
121 if(('{' == ptr[1]) && ((end = strchr(ptr, '}')) != NULL)) {
123 ptr += 2; /* pass the % and the { */
125 *end = 0; /* zero terminate */
126 for(i = 0; replacements[i].name; i++) {
127 if(curl_strequal(ptr, replacements[i].name)) {
129 switch(replacements[i].id) {
130 case VAR_EFFECTIVE_URL:
132 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &stringp))
134 fputs(stringp, stream);
138 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo))
139 fprintf(stream, "%03ld", longinfo);
141 case VAR_HTTP_CODE_PROXY:
143 curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE,
145 fprintf(stream, "%03ld", longinfo);
147 case VAR_HEADER_SIZE:
149 curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &longinfo))
150 fprintf(stream, "%ld", longinfo);
152 case VAR_REQUEST_SIZE:
154 curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &longinfo))
155 fprintf(stream, "%ld", longinfo);
157 case VAR_NUM_CONNECTS:
159 curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &longinfo))
160 fprintf(stream, "%ld", longinfo);
162 case VAR_REDIRECT_COUNT:
164 curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &longinfo))
165 fprintf(stream, "%ld", longinfo);
167 case VAR_REDIRECT_TIME:
169 curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME,
171 fprintf(stream, "%.3f", doubleinfo);
175 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &doubleinfo))
176 fprintf(stream, "%.3f", doubleinfo);
178 case VAR_NAMELOOKUP_TIME:
180 curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME,
182 fprintf(stream, "%.3f", doubleinfo);
184 case VAR_CONNECT_TIME:
186 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &doubleinfo))
187 fprintf(stream, "%.3f", doubleinfo);
189 case VAR_APPCONNECT_TIME:
191 curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME,
193 fprintf(stream, "%.3f", doubleinfo);
195 case VAR_PRETRANSFER_TIME:
197 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME,
199 fprintf(stream, "%.3f", doubleinfo);
201 case VAR_STARTTRANSFER_TIME:
203 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME,
205 fprintf(stream, "%.3f", doubleinfo);
207 case VAR_SIZE_UPLOAD:
209 curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &doubleinfo))
210 fprintf(stream, "%.0f", doubleinfo);
212 case VAR_SIZE_DOWNLOAD:
214 curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD,
216 fprintf(stream, "%.0f", doubleinfo);
218 case VAR_SPEED_DOWNLOAD:
220 curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD,
222 fprintf(stream, "%.3f", doubleinfo);
224 case VAR_SPEED_UPLOAD:
226 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &doubleinfo))
227 fprintf(stream, "%.3f", doubleinfo);
229 case VAR_CONTENT_TYPE:
231 curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp))
233 fputs(stringp, stream);
235 case VAR_FTP_ENTRY_PATH:
237 curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp))
239 fputs(stringp, stream);
241 case VAR_REDIRECT_URL:
243 curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp))
245 fputs(stringp, stream);
247 case VAR_SSL_VERIFY_RESULT:
249 curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT,
251 fprintf(stream, "%ld", longinfo);
253 case VAR_EFFECTIVE_FILENAME:
255 fprintf(stream, "%s", outs->filename);
259 curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP,
261 fprintf(stream, "%s", stringp);
263 case VAR_PRIMARY_PORT:
265 curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT,
267 fprintf(stream, "%ld", longinfo);
271 curl_easy_getinfo(curl, CURLINFO_LOCAL_IP,
273 fprintf(stream, "%s", stringp);
277 curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT,
279 fprintf(stream, "%ld", longinfo);
288 fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr);
290 ptr = end + 1; /* pass the end */
294 /* illegal syntax, then just output the characters that are used */
296 fputc(ptr[1], stream);
301 else if('\\' == *ptr) {
313 /* unknown, just output this */
315 fputc(ptr[1], stream);