1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, 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 ***************************************************************************/
24 #include <curl/curl.h>
26 #define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */
27 #include <curl/mprintf.h>
29 #include "tool_cfgable.h"
30 #include "tool_writeout.h"
32 #include "memdebug.h" /* keep this as LAST include */
35 VAR_NONE, /* must be the first */
41 VAR_STARTTRANSFER_TIME,
57 VAR_SSL_VERIFY_RESULT,
58 VAR_EFFECTIVE_FILENAME,
59 VAR_NUM_OF_VARS /* must be the last */
68 static const struct variable replacements[]={
69 {"url_effective", VAR_EFFECTIVE_URL},
70 {"http_code", VAR_HTTP_CODE},
71 {"response_code", VAR_HTTP_CODE},
72 {"http_connect", VAR_HTTP_CODE_PROXY},
73 {"time_total", VAR_TOTAL_TIME},
74 {"time_namelookup", VAR_NAMELOOKUP_TIME},
75 {"time_connect", VAR_CONNECT_TIME},
76 {"time_appconnect", VAR_APPCONNECT_TIME},
77 {"time_pretransfer", VAR_PRETRANSFER_TIME},
78 {"time_starttransfer", VAR_STARTTRANSFER_TIME},
79 {"size_header", VAR_HEADER_SIZE},
80 {"size_request", VAR_REQUEST_SIZE},
81 {"size_download", VAR_SIZE_DOWNLOAD},
82 {"size_upload", VAR_SIZE_UPLOAD},
83 {"speed_download", VAR_SPEED_DOWNLOAD},
84 {"speed_upload", VAR_SPEED_UPLOAD},
85 {"content_type", VAR_CONTENT_TYPE},
86 {"num_connects", VAR_NUM_CONNECTS},
87 {"time_redirect", VAR_REDIRECT_TIME},
88 {"num_redirects", VAR_REDIRECT_COUNT},
89 {"ftp_entry_path", VAR_FTP_ENTRY_PATH},
90 {"redirect_url", VAR_REDIRECT_URL},
91 {"ssl_verify_result", VAR_SSL_VERIFY_RESULT},
92 {"filename_effective", VAR_EFFECTIVE_FILENAME},
96 void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
98 FILE *stream = stdout;
99 const char *ptr = writeinfo;
107 /* an escaped %-letter */
112 /* this is meant as a variable to output */
116 if(('{' == ptr[1]) && ((end = strchr(ptr, '}')) != NULL)) {
118 ptr += 2; /* pass the % and the { */
120 *end = 0; /* zero terminate */
121 for(i = 0; replacements[i].name; i++) {
122 if(curl_strequal(ptr, replacements[i].name)) {
124 switch(replacements[i].id) {
125 case VAR_EFFECTIVE_URL:
127 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &stringp))
129 fputs(stringp, stream);
133 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &longinfo))
134 fprintf(stream, "%03ld", longinfo);
136 case VAR_HTTP_CODE_PROXY:
138 curl_easy_getinfo(curl, CURLINFO_HTTP_CONNECTCODE,
140 fprintf(stream, "%03ld", longinfo);
142 case VAR_HEADER_SIZE:
144 curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &longinfo))
145 fprintf(stream, "%ld", longinfo);
147 case VAR_REQUEST_SIZE:
149 curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &longinfo))
150 fprintf(stream, "%ld", longinfo);
152 case VAR_NUM_CONNECTS:
154 curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &longinfo))
155 fprintf(stream, "%ld", longinfo);
157 case VAR_REDIRECT_COUNT:
159 curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &longinfo))
160 fprintf(stream, "%ld", longinfo);
162 case VAR_REDIRECT_TIME:
164 curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME,
166 fprintf(stream, "%.3f", doubleinfo);
170 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &doubleinfo))
171 fprintf(stream, "%.3f", doubleinfo);
173 case VAR_NAMELOOKUP_TIME:
175 curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME,
177 fprintf(stream, "%.3f", doubleinfo);
179 case VAR_CONNECT_TIME:
181 curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &doubleinfo))
182 fprintf(stream, "%.3f", doubleinfo);
184 case VAR_APPCONNECT_TIME:
186 curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME,
188 fprintf(stream, "%.3f", doubleinfo);
190 case VAR_PRETRANSFER_TIME:
192 curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME,
194 fprintf(stream, "%.3f", doubleinfo);
196 case VAR_STARTTRANSFER_TIME:
198 curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME,
200 fprintf(stream, "%.3f", doubleinfo);
202 case VAR_SIZE_UPLOAD:
204 curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &doubleinfo))
205 fprintf(stream, "%.0f", doubleinfo);
207 case VAR_SIZE_DOWNLOAD:
209 curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD,
211 fprintf(stream, "%.0f", doubleinfo);
213 case VAR_SPEED_DOWNLOAD:
215 curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD,
217 fprintf(stream, "%.3f", doubleinfo);
219 case VAR_SPEED_UPLOAD:
221 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &doubleinfo))
222 fprintf(stream, "%.3f", doubleinfo);
224 case VAR_CONTENT_TYPE:
226 curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp))
228 fputs(stringp, stream);
230 case VAR_FTP_ENTRY_PATH:
232 curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp))
234 fputs(stringp, stream);
236 case VAR_REDIRECT_URL:
238 curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp))
240 fputs(stringp, stream);
242 case VAR_SSL_VERIFY_RESULT:
244 curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT,
246 fprintf(stream, "%ld", longinfo);
248 case VAR_EFFECTIVE_FILENAME:
250 fprintf(stream, "%s", outs->filename);
259 fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr);
261 ptr = end + 1; /* pass the end */
265 /* illegal syntax, then just output the characters that are used */
267 fputc(ptr[1], stream);
272 else if('\\' == *ptr) {
284 /* unknown, just output this */
286 fputc(ptr[1], stream);