1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2012, 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 http://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"
24 #define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */
25 #include <curl/mprintf.h>
27 #include "tool_cfgable.h"
28 #include "tool_writeout.h"
30 #include "memdebug.h" /* keep this as LAST include */
33 VAR_NONE, /* must be the first */
39 VAR_STARTTRANSFER_TIME,
55 VAR_SSL_VERIFY_RESULT,
56 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},
102 void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
104 FILE *stream = stdout;
105 const char *ptr = writeinfo;
113 /* an escaped %-letter */
118 /* this is meant as a variable to output */
122 if(('{' == ptr[1]) && ((end = strchr(ptr, '}')) != NULL)) {
124 ptr += 2; /* pass the % and the { */
126 *end = 0; /* zero terminate */
127 for(i = 0; replacements[i].name; i++) {
128 if(curl_strequal(ptr, replacements[i].name)) {
130 switch(replacements[i].id) {
131 case VAR_EFFECTIVE_URL:
133 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &stringp))
135 fputs(stringp, stream);
139 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo))
140 fprintf(stream, "%03ld", longinfo);
142 case VAR_HTTP_CODE_PROXY:
144 curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE,
146 fprintf(stream, "%03ld", longinfo);
148 case VAR_HEADER_SIZE:
150 curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &longinfo))
151 fprintf(stream, "%ld", longinfo);
153 case VAR_REQUEST_SIZE:
155 curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &longinfo))
156 fprintf(stream, "%ld", longinfo);
158 case VAR_NUM_CONNECTS:
160 curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &longinfo))
161 fprintf(stream, "%ld", longinfo);
163 case VAR_REDIRECT_COUNT:
165 curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &longinfo))
166 fprintf(stream, "%ld", longinfo);
168 case VAR_REDIRECT_TIME:
170 curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME,
172 fprintf(stream, "%.3f", doubleinfo);
176 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &doubleinfo))
177 fprintf(stream, "%.3f", doubleinfo);
179 case VAR_NAMELOOKUP_TIME:
181 curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME,
183 fprintf(stream, "%.3f", doubleinfo);
185 case VAR_CONNECT_TIME:
187 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &doubleinfo))
188 fprintf(stream, "%.3f", doubleinfo);
190 case VAR_APPCONNECT_TIME:
192 curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME,
194 fprintf(stream, "%.3f", doubleinfo);
196 case VAR_PRETRANSFER_TIME:
198 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME,
200 fprintf(stream, "%.3f", doubleinfo);
202 case VAR_STARTTRANSFER_TIME:
204 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME,
206 fprintf(stream, "%.3f", doubleinfo);
208 case VAR_SIZE_UPLOAD:
210 curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &doubleinfo))
211 fprintf(stream, "%.0f", doubleinfo);
213 case VAR_SIZE_DOWNLOAD:
215 curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD,
217 fprintf(stream, "%.0f", doubleinfo);
219 case VAR_SPEED_DOWNLOAD:
221 curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD,
223 fprintf(stream, "%.3f", doubleinfo);
225 case VAR_SPEED_UPLOAD:
227 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &doubleinfo))
228 fprintf(stream, "%.3f", doubleinfo);
230 case VAR_CONTENT_TYPE:
232 curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp))
234 fputs(stringp, stream);
236 case VAR_FTP_ENTRY_PATH:
238 curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp))
240 fputs(stringp, stream);
242 case VAR_REDIRECT_URL:
244 curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp))
246 fputs(stringp, stream);
248 case VAR_SSL_VERIFY_RESULT:
250 curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT,
252 fprintf(stream, "%ld", longinfo);
254 case VAR_EFFECTIVE_FILENAME:
256 fprintf(stream, "%s", outs->filename);
260 curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP,
262 fprintf(stream, "%s", stringp);
264 case VAR_PRIMARY_PORT:
266 curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT,
268 fprintf(stream, "%ld", longinfo);
272 curl_easy_getinfo(curl, CURLINFO_LOCAL_IP,
274 fprintf(stream, "%s", stringp);
278 curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT,
280 fprintf(stream, "%ld", longinfo);
289 fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr);
291 ptr = end + 1; /* pass the end */
295 /* illegal syntax, then just output the characters that are used */
297 fputc(ptr[1], stream);
302 else if('\\' == *ptr) {
314 /* unknown, just output this */
316 fputc(ptr[1], stream);